52 #if QT_VERSION >= 0x050000
58 #include "TreeModelObjectSelection.hh"
61 #include "../OpenFlipper/BasePlugin/PluginFunctions.hh"
109 if (!index.isValid())
116 std::cerr <<
"Root" << std::endl;
120 if ( role == Qt::BackgroundRole ) {
122 return QVariant (QBrush (QColor (192, 192, 192)));
126 if (role == Qt::DisplayRole)
128 switch (index.column ())
131 return QVariant(item->
id());
133 return QVariant(item->
name());
152 if (!index.isValid())
155 Qt::ItemFlags
flags = 0;
158 if ( index.column() == 0 || index.column() == 1 )
159 flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
161 flags = Qt::ItemIsEnabled;
179 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
182 return QVariant(
"ID");
183 else if (section == 1)
184 return QVariant(
"Name");
206 if (!_parent.isValid())
213 return createIndex(row, column, childItem);
215 return QModelIndex();
228 if (!index.isValid())
229 return QModelIndex();
235 return QModelIndex();
237 return createIndex(parentItem->
row(), 0, parentItem);
251 if (_parent.column() > 0)
254 if (!_parent.isValid())
279 if (obj != 0 && item != 0){
286 if ( index.isValid() )
287 emit dataChanged( index, index);
298 if ( index0.isValid() && index1.isValid() ){
300 emit dataChanged( index0, index1);
377 if ( item != 0 && !
isRoot(item) ){
380 QModelIndex parentIndex = itemIndex.parent();
382 beginRemoveRows( parentIndex, itemIndex.row(), itemIndex.row() );
403 QModelIndex oldParentIndex = itemIndex.parent();
407 beginRemoveRows( oldParentIndex, itemIndex.row(), itemIndex.row() );
419 emit layoutChanged();
431 if (index.isValid()) {
433 if (item)
return item;
448 if (index.isValid()) {
465 if (index.isValid()) {
487 return QModelIndex();
489 QModelIndex
index = createIndex(_object->
row(), _column, _object);
511 return QModelIndex();
525 if (
isRoot(_item) || (!_item->isGroup()) )
535 emit dataChanged( index0, index1);
540 emit dataChanged(index, index);
559 bool changed =
false;
578 emit dataChanged(index, index);
581 if ( current->isGroup() )
591 emit dataChangedInside(
itemId(index), index.column(), value );
void propagateUpwards(TreeItemObjectSelection *_obj, int _column, bool _value)
Recursively update a column up to the root of the tree.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
int childCount() const
get the number of children
int row() const
get the row of this item from the parent
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
return the header data of the model
QString name() const
return the name of the object. The name defaults to NONAME if unset.
const DataType DATA_UNKNOWN(0)
None of the other Objects.
bool getObject(int _identifier, BSplineCurveObject *&_object)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Get the ModelIndex at given row,column.
TreeItemObjectSelection * child(int row)
return a child
int itemId(const QModelIndex &index) const
Get the id of a TreeItemObjectSelection corresponding to a given ModelIndex.
virtual bool visible()
return if object is visible
TreeItemObjectSelection * rootItem_
Rootitem of the tree.
void objectChanged(int id_)
The object with the given id has been changed. Check if model also has to be changed.
~TreeModelObjectSelection()
Destructor.
bool isGroup() const
Check if object is a group.
bool dataType(DataType _type) const
void appendChild(TreeItemObjectSelection *child)
add a child to this node
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
TreeItemObjectSelection * parent()
Get the parent item ( 0 if rootitem )
bool setData(const QModelIndex &index, const QVariant &value, int role)
Set Data at 'index' to 'value'.
void moveItem(TreeItemObjectSelection *_item, TreeItemObjectSelection *_parent)
move the item to a new parent
void removeChild(TreeItemObjectSelection *_item)
Remove a child from this object.
QModelIndex getModelIndex(TreeItemObjectSelection *_object, int _column)
Return the ModelIndex corresponding to a given TreeItemObjectSelection and Column.
BaseObject *& objectRoot()
Get the root of the object structure.
bool isRoot(TreeItemObjectSelection *_item)
Check if the given item is the root item.
void objectDeleted(int id_)
The object with the given id has been deleted. delete it from the internal tree.
QVariant data(const QModelIndex &index, int role) const
Get the data of the corresponding entry.
int rowCount(const QModelIndex &parent=QModelIndex()) const
get the number of rows
QString itemName(const QModelIndex &index) const
Get the name of a TreeItemObjectSelection corresponding to a given ModelIndex.
int columnCount(const QModelIndex &_parent=QModelIndex()) const
Return the number of columns.
void propagateDownwards(TreeItemObjectSelection *_obj, int _column)
Recursively update a column up to the root of the tree.
TreeModelObjectSelection(QObject *_parent=0)
Constructor.
QModelIndex parent(const QModelIndex &index) const
Get the parent ModelIndex.
TreeItemObjectSelection * childExists(int _objectId)
Check if the element exists in the subtree of this element.
void setParent(TreeItemObjectSelection *_parent)
Set the parent pointer.
Qt::ItemFlags flags(const QModelIndex &index) const
return the types of the corresponding entry
void deleteSubtree()
delete the whole subtree below this item ( The item itself is not touched )
TreeItemObjectSelection * getItem(const QModelIndex &index) const
Get the TreeItemObjectSelection corresponding to a given ModelIndex.