52 #include "TreeModel.hh" 57 #if QT_VERSION >= 0x050000 108 if (!_index.isValid())
115 std::cerr <<
"Root" << std::endl;
119 if ( _role == Qt::BackgroundRole ) {
121 return QVariant (QBrush (QColor (192, 192, 192)));
125 if (_role == Qt::DisplayRole)
127 switch (_index.column ())
130 return QVariant(item->
id());
132 return QVariant(item->
name());
151 if (!_index.isValid())
154 Qt::ItemFlags
flags = 0;
157 if ( _index.column() == 0 || _index.column() == 1 )
158 flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
160 flags = Qt::ItemIsEnabled;
178 if (_orientation == Qt::Horizontal && _role == Qt::DisplayRole) {
181 return QVariant(
"ID");
182 else if (_section == 1)
183 return QVariant(
"Name");
201 QModelIndex
TreeModel::index(
int _row,
int _column,
const QModelIndex &_parent)
const 205 if (!_parent.isValid())
208 parentItem =
static_cast<TreeItem*
>(_parent.internalPointer());
212 return createIndex(_row, _column, childItem);
214 return QModelIndex();
227 if (!_index.isValid())
228 return QModelIndex();
234 return QModelIndex();
236 return createIndex(parentItem->
row(), 0, parentItem);
250 if (_parent.column() > 0)
253 if (!_parent.isValid())
256 parentItem =
static_cast<TreeItem*
>(_parent.internalPointer());
278 if (obj != 0 && item != 0){
285 if ( index.isValid() )
286 emit dataChanged( index, index);
297 if ( index0.isValid() && index1.isValid() ){
299 emit dataChanged( index0, index1);
376 if ( item != 0 && !
isRoot(item) ){
379 QModelIndex parentIndex = itemIndex.parent();
381 beginRemoveRows( parentIndex, itemIndex.row(), itemIndex.row() );
402 QModelIndex oldParentIndex = itemIndex.parent();
406 beginRemoveRows( oldParentIndex, itemIndex.row(), itemIndex.row() );
418 emit layoutChanged();
430 if (_index.isValid()) {
432 if (item)
return item;
447 if (_index.isValid()) {
464 if (_index.isValid()) {
486 return QModelIndex();
488 QModelIndex index = createIndex(_object->
row(), _column, _object);
510 return QModelIndex();
524 if (
isRoot(_item) || (!_item->isGroup()) )
534 emit dataChanged( index0, index1);
539 emit dataChanged(index, index);
558 bool changed =
false;
577 emit dataChanged(index, index);
580 if ( current->isGroup() )
590 emit dataChangedInside(
itemId(_index), _index.column(), _value );
BaseObject *& objectRoot()
Get the root of the object structure.
int itemId(const QModelIndex &_index) const
Get the id of a TreeItem corresponding to a given ModelIndex.
int columnCount(const QModelIndex &_parent=QModelIndex()) const
Return the number of columns.
int rowCount(const QModelIndex &_parent=QModelIndex()) const
get the number of rows
void deleteSubtree()
delete the whole subtree below this item ( The item itself is not touched )
QModelIndex getModelIndex(TreeItem *_object, int _column)
Return the ModelIndex corresponding to a given TreeItem and Column.
void objectChanged(int _id)
The object with the given id has been changed. Check if model also has to be changed.
void propagateDownwards(TreeItem *_obj, int _column)
Recursively update a column up to the root of the tree.
virtual bool visible()
return if object is visible
QString itemName(const QModelIndex &_index) const
Get the name of a TreeItem corresponding to a given ModelIndex.
TreeModel(QObject *_parent=0)
Constructor.
TreeItem * parent()
Get the parent item ( 0 if root item )
bool getObject(int _identifier, BSplineCurveObject *&_object)
bool dataType(DataType _type) const
const DataType DATA_UNKNOWN(0)
None of the other Objects.
TreeItem * childExists(int _objectId)
Check if the element exists in the subtree of this element.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
Qt::ItemFlags flags(const QModelIndex &_index) const
return the types of the corresponding entry
void setParent(TreeItem *_parent)
Set the parent pointer.
void appendChild(TreeItem *child)
add a child to this node
TreeItem * rootItem_
Root item of the tree.
int row() const
get the row of this item from the parent
TreeItem * child(int row)
return a child
void removeChild(TreeItem *_item)
Remove a child from this object.
void propagateUpwards(TreeItem *_obj, int _column, bool _value)
Recursively update a column up to the root of the tree.
int childCount() const
get the number of children
QVariant data(const QModelIndex &_index, int _role) const
Get the data of the corresponding entry.
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
bool isGroup() const
Check if object is a group.
QModelIndex parent(const QModelIndex &_index) const
Get the parent ModelIndex.
void moveItem(TreeItem *_item, TreeItem *_parent)
move the item to a new parent
QString name() const
return the name of the object. The name defaults to NONAME if unset.
bool isRoot(TreeItem *_item)
Check if the given item is the root item.
TreeItem * getItem(const QModelIndex &_index) const
Get the TreeItem corresponding to a given ModelIndex.
QModelIndex index(int _row, int _column, const QModelIndex &_parent=QModelIndex()) const
Get the ModelIndex at given row,column.
void objectDeleted(int _id)
The object with the given id has been deleted. delete it from the internal tree.
QVariant headerData(int _section, Qt::Orientation _orientation, int _role=Qt::DisplayRole) const
return the header data of the model
bool setData(const QModelIndex &_index, const QVariant &_value, int _role)
Set Data at 'index' to 'value'.