50 #include "TreeModelObjectSelection.hh" 53 #include "../OpenFlipper/BasePlugin/PluginFunctions.hh" 101 if (!index.isValid())
108 std::cerr <<
"Root" << std::endl;
112 if ( role == Qt::BackgroundRole ) {
114 return QVariant (QBrush (QColor (192, 192, 192)));
118 if (role == Qt::DisplayRole)
120 switch (index.column ())
123 return QVariant(item->
id());
125 return QVariant(item->
name());
144 if (!index.isValid())
147 Qt::ItemFlags
flags = 0;
150 if ( index.column() == 0 || index.column() == 1 )
151 flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
153 flags = Qt::ItemIsEnabled;
171 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
174 return QVariant(
"ID");
175 else if (section == 1)
176 return QVariant(
"Name");
198 if (!_parent.isValid())
205 return createIndex(row, column, childItem);
207 return QModelIndex();
220 if (!index.isValid())
221 return QModelIndex();
227 return QModelIndex();
229 return createIndex(parentItem->
row(), 0, parentItem);
243 if (_parent.column() > 0)
246 if (!_parent.isValid())
271 if (obj != 0 && item != 0){
278 if ( index.isValid() )
279 emit dataChanged( index, index);
290 if ( index0.isValid() && index1.isValid() ){
292 emit dataChanged( index0, index1);
369 if ( item != 0 && !
isRoot(item) ){
372 QModelIndex parentIndex = itemIndex.parent();
374 beginRemoveRows( parentIndex, itemIndex.row(), itemIndex.row() );
395 QModelIndex oldParentIndex = itemIndex.parent();
399 beginRemoveRows( oldParentIndex, itemIndex.row(), itemIndex.row() );
411 emit layoutChanged();
423 if (index.isValid()) {
425 if (item)
return item;
440 if (index.isValid()) {
457 if (index.isValid()) {
479 return QModelIndex();
481 QModelIndex
index = createIndex(_object->
row(), _column, _object);
503 return QModelIndex();
517 if (
isRoot(_item) || (!_item->isGroup()) )
527 emit dataChanged( index0, index1);
532 emit dataChanged(index, index);
551 bool changed =
false;
570 emit dataChanged(index, index);
573 if ( current->isGroup() )
583 emit dataChangedInside(
itemId(index), index.column(), value );
TreeItemObjectSelection * rootItem_
Rootitem of the tree.
void moveItem(TreeItemObjectSelection *_item, TreeItemObjectSelection *_parent)
move the item to a new parent
TreeItemObjectSelection * child(int row)
return a child
int columnCount(const QModelIndex &_parent=QModelIndex()) const
Return the number of columns.
Qt::ItemFlags flags(const QModelIndex &index) const
return the types of the corresponding entry
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
BaseObject *& objectRoot()
Get the root of the object structure.
int childCount() const
get the number of children
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
void setParent(TreeItemObjectSelection *_parent)
Set the parent pointer.
QModelIndex parent(const QModelIndex &index) const
Get the parent ModelIndex.
void objectDeleted(int id_)
The object with the given id has been deleted. delete it from the internal tree.
~TreeModelObjectSelection()
Destructor.
bool dataType(DataType _type) const
bool setData(const QModelIndex &index, const QVariant &value, int role)
Set Data at 'index' to 'value'.
bool isRoot(TreeItemObjectSelection *_item)
Check if the given item is the root item.
TreeItemObjectSelection * parent()
Get the parent item ( 0 if rootitem )
TreeModelObjectSelection(QObject *_parent=0)
Constructor.
void deleteSubtree()
delete the whole subtree below this item ( The item itself is not touched )
BaseObject * parent()
Get the parent item ( 0 if rootitem )
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
return the header data of the model
QModelIndex getModelIndex(TreeItemObjectSelection *_object, int _column)
Return the ModelIndex corresponding to a given TreeItemObjectSelection and Column.
TreeItemObjectSelection * childExists(int _objectId)
Check if the element exists in the subtree of this element.
void objectChanged(int id_)
The object with the given id has been changed. Check if model also has to be changed.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
int row() const
get the row of this item from the parent
bool isGroup() const
Check if object is a group.
int rowCount(const QModelIndex &parent=QModelIndex()) const
get the number of rows
virtual bool visible()
return if object is visible
TreeItemObjectSelection * getItem(const QModelIndex &index) const
Get the TreeItemObjectSelection corresponding to a given ModelIndex.
int itemId(const QModelIndex &index) const
Get the id of a TreeItemObjectSelection corresponding to a given ModelIndex.
void propagateDownwards(TreeItemObjectSelection *_obj, int _column)
Recursively update a column up to the root of the tree.
void appendChild(TreeItemObjectSelection *child)
add a child to this node
void propagateUpwards(TreeItemObjectSelection *_obj, int _column, bool _value)
Recursively update a column up to the root of the tree.
QVariant data(const QModelIndex &index, int role) const
Get the data of the corresponding entry.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Get the ModelIndex at given row,column.
void removeChild(TreeItemObjectSelection *_item)
Remove a child from this object.
QString itemName(const QModelIndex &index) const
Get the name of a TreeItemObjectSelection corresponding to a given ModelIndex.
const DataType DATA_UNKNOWN(0)
None of the other Objects.