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 QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
145 if (!
index.isValid())
148 Qt::ItemFlags
flags = 0;
150 if (!
index.isValid())
151 return Qt::ItemFlags();
153 Qt::ItemFlags
flags = Qt::ItemFlags();
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");
205 if (!_parent.isValid())
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())
278 if (obj != 0 && item != 0){
285 if (
index.isValid() )
297 if ( index0.isValid() && index1.isValid() ){
299 emit dataChanged( index0, index1);
357 beginInsertRows(parentIndex,
parent->childCount(),
parent->childCount());
361 parent->appendChild( item );
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);
558 bool changed =
false;
580 if ( current->isGroup() )
const DataType DATA_UNKNOWN(0)
None of the other Objects.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
bool dataType(DataType _type) const
bool isGroup() const
Check if object is a group.
virtual bool visible()
return if object is visible
void removeChild(TreeItemObjectSelection *_item)
Remove a child from this object.
void deleteSubtree()
delete the whole subtree below this item ( The item itself is not touched )
void setParent(TreeItemObjectSelection *_parent)
Set the parent pointer.
TreeItemObjectSelection * childExists(int _objectId)
Check if the element exists in the subtree of this element.
void appendChild(TreeItemObjectSelection *child)
add a child to this node
TreeItemObjectSelection * parent()
Get the parent item ( 0 if rootitem )
int row() const
get the row of this item from the parent
int childCount() const
get the number of children
TreeItemObjectSelection * child(int row)
return a child
void objectChanged(int id_)
The object with the given id has been changed. Check if model also has to be changed.
void moveItem(TreeItemObjectSelection *_item, TreeItemObjectSelection *_parent)
move the item to a new parent
TreeItemObjectSelection * rootItem_
Rootitem of the tree.
QVariant data(const QModelIndex &index, int role) const
Get the data of the corresponding entry.
int columnCount(const QModelIndex &_parent=QModelIndex()) const
Return the number of columns.
bool isRoot(TreeItemObjectSelection *_item)
Check if the given item is the root item.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
return the header data of the model
~TreeModelObjectSelection()
Destructor.
int itemId(const QModelIndex &index) const
Get the id of a TreeItemObjectSelection corresponding to a given ModelIndex.
void objectDeleted(int id_)
The object with the given id has been deleted. delete it from the internal tree.
bool setData(const QModelIndex &index, const QVariant &value, int role)
Set Data at 'index' to 'value'.
QModelIndex parent(const QModelIndex &index) const
Get the parent ModelIndex.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Get the ModelIndex at given row,column.
int rowCount(const QModelIndex &parent=QModelIndex()) const
get the number of rows
QModelIndex getModelIndex(TreeItemObjectSelection *_object, int _column)
Return the ModelIndex corresponding to a given TreeItemObjectSelection and Column.
TreeModelObjectSelection(QObject *_parent=0)
Constructor.
Qt::ItemFlags flags(const QModelIndex &index) const
return the types of the corresponding entry
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
void propagateDownwards(TreeItemObjectSelection *_obj, int _column)
Recursively update a column up to the root of the tree.
void propagateUpwards(TreeItemObjectSelection *_obj, int _column, bool _value)
Recursively update a column up to the root of the tree.
TreeItemObjectSelection * getItem(const QModelIndex &index) const
Get the TreeItemObjectSelection corresponding to a given ModelIndex.
QString itemName(const QModelIndex &index) const
Get the name of a TreeItemObjectSelection corresponding to a given ModelIndex.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
BaseObject *& objectRoot()
Get the root of the object structure.