46 #include "TreeModel.hh" 99 if (!_index.isValid())
106 std::cerr <<
"Root" << std::endl;
110 if ( _role == Qt::BackgroundRole ) {
112 return QVariant (QBrush (QColor (192, 192, 192)));
116 if (_role == Qt::DisplayRole)
118 switch (_index.column ())
121 return QVariant(item->
id());
123 return QVariant(item->
name());
142 if (!_index.isValid())
145 Qt::ItemFlags
flags = 0;
148 if ( _index.column() == 0 || _index.column() == 1 )
149 flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
151 flags = Qt::ItemIsEnabled;
169 if (_orientation == Qt::Horizontal && _role == Qt::DisplayRole) {
172 return QVariant(
"ID");
173 else if (_section == 1)
174 return QVariant(
"Name");
192 QModelIndex
TreeModel::index(
int _row,
int _column,
const QModelIndex &_parent)
const 196 if (!_parent.isValid())
199 parentItem =
static_cast<TreeItem*
>(_parent.internalPointer());
203 return createIndex(_row, _column, childItem);
205 return QModelIndex();
218 if (!_index.isValid())
219 return QModelIndex();
225 return QModelIndex();
227 return createIndex(parentItem->
row(), 0, parentItem);
241 if (_parent.column() > 0)
244 if (!_parent.isValid())
247 parentItem =
static_cast<TreeItem*
>(_parent.internalPointer());
269 if (obj != 0 && item != 0){
276 if ( index.isValid() )
277 emit dataChanged( index, index);
288 if ( index0.isValid() && index1.isValid() ){
290 emit dataChanged( index0, index1);
367 if ( item != 0 && !
isRoot(item) ){
370 QModelIndex parentIndex = itemIndex.parent();
372 beginRemoveRows( parentIndex, itemIndex.row(), itemIndex.row() );
393 QModelIndex oldParentIndex = itemIndex.parent();
397 beginRemoveRows( oldParentIndex, itemIndex.row(), itemIndex.row() );
409 emit layoutChanged();
421 if (_index.isValid()) {
423 if (item)
return item;
438 if (_index.isValid()) {
455 if (_index.isValid()) {
477 return QModelIndex();
479 QModelIndex index = createIndex(_object->
row(), _column, _object);
501 return QModelIndex();
515 if (
isRoot(_item) || (!_item->isGroup()) )
525 emit dataChanged( index0, index1);
530 emit dataChanged(index, index);
549 bool changed =
false;
568 emit dataChanged(index, index);
571 if ( current->isGroup() )
581 emit dataChangedInside(
itemId(_index), _index.column(), _value );
int row() const
get the row of this item from the parent
bool isGroup() const
Check if object is a group.
void removeChild(TreeItem *_item)
Remove a child from this object.
void objectDeleted(int _id)
The object with the given id has been deleted. delete it from the internal tree.
QModelIndex index(int _row, int _column, const QModelIndex &_parent=QModelIndex()) const
Get the ModelIndex at given row,column.
QString itemName(const QModelIndex &_index) const
Get the name of a TreeItem corresponding to a given ModelIndex.
void appendChild(TreeItem *child)
add a child to this node
void setParent(TreeItem *_parent)
Set the parent pointer.
Qt::ItemFlags flags(const QModelIndex &_index) const
return the types of the corresponding entry
void moveItem(TreeItem *_item, TreeItem *_parent)
move the item to a new parent
TreeItem * getItem(const QModelIndex &_index) const
Get the TreeItem corresponding to a given ModelIndex.
bool dataType(DataType _type) const
int childCount() const
get the number of children
TreeItem * rootItem_
Root item of the tree.
int columnCount(const QModelIndex &_parent=QModelIndex()) const
Return the number of columns.
int itemId(const QModelIndex &_index) const
Get the id of a TreeItem corresponding to a given ModelIndex.
QModelIndex getModelIndex(TreeItem *_object, int _column)
Return the ModelIndex corresponding to a given TreeItem and Column.
const DataType DATA_UNKNOWN(0)
None of the other Objects.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
QVariant data(const QModelIndex &_index, int _role) const
Get the data of the corresponding entry.
BaseObject *& objectRoot()
Get the root of the object structure.
virtual bool visible()
return if object is visible
QModelIndex parent(const QModelIndex &_index) const
Get the parent ModelIndex.
bool isRoot(TreeItem *_item)
Check if the given item is the root item.
void objectChanged(int _id)
The object with the given id has been changed. Check if model also has to be changed.
TreeItem * childExists(int _objectId)
Check if the element exists in the subtree of this element.
void propagateUpwards(TreeItem *_obj, int _column, bool _value)
Recursively update a column up to the root of the tree.
TreeItem * parent()
Get the parent item ( 0 if root item )
QVariant headerData(int _section, Qt::Orientation _orientation, int _role=Qt::DisplayRole) const
return the header data of the model
void propagateDownwards(TreeItem *_obj, int _column)
Recursively update a column up to the root of the tree.
int rowCount(const QModelIndex &_parent=QModelIndex()) const
get the number of rows
TreeModel(QObject *_parent=0)
Constructor.
TreeItem * child(int row)
return a child
bool setData(const QModelIndex &_index, const QVariant &_value, int _role)
Set Data at 'index' to 'value'.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
void deleteSubtree()
delete the whole subtree below this item ( The item itself is not touched )
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.