50 #include "TreeModel.hh" 52 #if QT_VERSION >= 0x050000 62 #include <ObjectTypes/Light/LightWidget.hh> 109 if (!_index.isValid())
116 std::cerr <<
"Root" << std::endl;
120 if ( _role == Qt::BackgroundRole ) {
122 return QVariant( QBrush(QColor(100,100,100) ) );
128 switch (_index.column() ) {
133 if ( _role == Qt::DecorationRole ) {
139 return QVariant (QIcon (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"LightOff.png"));
145 if (_role != Qt::DisplayRole && _role != Qt::EditRole )
148 return QVariant(item->
name());
153 if (_role == Qt::CheckStateRole ) {
154 bool visible =
false;
156 if (item->isGroup() && item->
childCount() > 0)
158 QList< TreeItem* > children = item->
getLeafs();
160 visible = children[0]->visible();
161 for (
int i=0; i < children.size() ; ++i)
163 if (visible != children[i]->visible())
164 return QVariant(Qt::PartiallyChecked);
169 return (visible) ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
174 if (_role == Qt::CheckStateRole ) {
177 if (item->isGroup() && item->
childCount() > 0)
179 QList< TreeItem* > children = item->
getLeafs();
181 source = children[0]->source();
182 for (
int i=0; i < children.size() ; ++i)
184 if (source != children[i]->source())
185 return QVariant(Qt::PartiallyChecked);
190 return (source) ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
196 if (_role == Qt::CheckStateRole ) {
199 if (item->isGroup() && item->
childCount() > 0)
201 QList< TreeItem* > children = item->
getLeafs();
203 target = children[0]->target();
204 for (
int i=0; i < children.size() ; ++i)
206 if (target != children[i]->target())
207 return QVariant(Qt::PartiallyChecked);
212 return (target) ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
233 if (!_index.isValid())
236 Qt::ItemFlags
flags = 0;
239 if ( ( _index.column() == 1 ) ||
240 ( _index.column() == 2 ) ||
241 ( _index.column() == 3 ) )
242 flags = Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
244 if ( _index.column() == 0 )
245 flags = Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
247 flags = Qt::ItemIsEnabled;
252 if ( item->isGroup() )
253 return flags | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
255 return flags | Qt::ItemIsDragEnabled;
271 if (_orientation == Qt::Horizontal && _role == Qt::DisplayRole) {
274 case 0 :
return QVariant(
"Name");
275 case 1 :
return QVariant(
"Show");
276 case 2 :
return QVariant(
"Source");
277 case 3 :
return QVariant(
"Target");
302 if (!_parent.isValid())
305 parentItem =
static_cast<TreeItem*
>(_parent.internalPointer());
309 return createIndex(_row, _column, childItem);
311 return QModelIndex();
324 if (!_index.isValid())
325 return QModelIndex();
331 return QModelIndex();
333 return createIndex(parentItem->
row(), 0, parentItem);
347 if (_parent.column() > 0)
350 if (!_parent.isValid())
353 parentItem =
static_cast<TreeItem*
>(_parent.internalPointer());
373 if (obj != 0 && item != 0){
375 bool updateRow =
false;
408 if ( index0.isValid() && index1.isValid() ){
410 emit dataChanged( index0, index1);
475 if ( item != 0 && !
isRoot(item) ){
478 QModelIndex parentIndex = itemIndex.parent();
480 beginRemoveRows( parentIndex, itemIndex.row(), itemIndex.row() );
501 QModelIndex oldParentIndex = itemIndex.parent();
504 beginMoveRows ( oldParentIndex, itemIndex.row(), itemIndex.row(), newParentIndex,0 );
520 if (_index.isValid()) {
522 if (item)
return item;
537 if (_index.isValid()) {
554 if (_index.isValid()) {
576 return QModelIndex();
578 QModelIndex
index = createIndex(_object->
row(), _column, _object);
588 emit dataChangedInside(
itemId(_index), _index.column(), _value );
616 return Qt::MoveAction;
629 types <<
"DataControl/dragDrop";
643 QMimeData *
mimeData =
new QMimeData();
644 QByteArray encodedData;
646 QDataStream stream(&encodedData, QIODevice::WriteOnly);
650 foreach (QModelIndex
index, _indexes) {
651 if (index.isValid()) {
653 if (!rows.contains( index.row() ) ){
655 stream << item->
id();
657 rows.push_back( index.row() );
662 mimeData->setData(
"DataControl/dragDrop", encodedData);
670 Qt::DropAction _action,
673 const QModelIndex &_parent)
675 if (_action == Qt::IgnoreAction)
678 if (!_data->hasFormat(
"DataControl/dragDrop"))
681 QByteArray encodedData = _data->data(
"DataControl/dragDrop");
682 QDataStream stream(&encodedData, QIODevice::ReadOnly);
686 while (!stream.atEnd()) {
693 if (ids.count() == 0)
699 if ( newParent == 0 || !newParent->isGroup() )
703 for (
int i = 0; i < ids.count(); i++){
705 emit moveBaseObject( ids[i], newParent->
id() );
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.
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)
LightSource * lightSource()
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.
QStringList mimeTypes() const
stores the mimeType for Drag & Drop
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.
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.
QList< TreeItem * > getLeafs()
get all leafes of the tree below this object ( These will be all visible objects ) ...
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.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
This is called when mimeData is dropped.
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.
Qt::DropActions supportedDropActions() const
supported drag & Drop actions
QVariant headerData(int _section, Qt::Orientation _orientation, int _role=Qt::DisplayRole) const
return the header data of the model
DLLEXPORT QIcon & typeIcon(DataType _id)
Get an QIcon associated with the given DataType.
bool setData(const QModelIndex &_index, const QVariant &_value, int _role)
Set Data at 'index' to 'value'.
bool enabled() const
Get light source status.
QMimeData * mimeData(const QModelIndexList &indexes) const
get the mimeData for a given ModelIndex
DataType dataType()
dataType