diff --git a/ContextMenuDataControl.cc b/ContextMenuDataControl.cc index 2432d27c8c0d2007b74b5089341cf2cde061af80..26d28b51a349364d3da4694293f48b1947de8ec9 100644 --- a/ContextMenuDataControl.cc +++ b/ContextMenuDataControl.cc @@ -48,8 +48,7 @@ void DataControlPlugin::slotContextMenuTarget( ) { object->target( targetAction_->isChecked() ); - emit activeObjectChanged(); - emit updatedObject(objectId); + emit objectSelectionChanged(objectId); } void DataControlPlugin::slotContextMenuHide( ) { @@ -65,8 +64,8 @@ void DataControlPlugin::slotContextMenuHide( ) { object->hide(); + emit visibilityChanged(objectId); emit updateView(); - emit updatedObject(objectId); } @@ -83,7 +82,7 @@ void DataControlPlugin::slotContextMenuSource( ) { object->source( sourceAction_->isChecked() ); - emit updatedObject(objectId); + emit objectSelectionChanged(objectId); } void DataControlPlugin::slotUpdateContextMenu( int _objectId) { diff --git a/DataControlPlugin.cc b/DataControlPlugin.cc index 821c4748f49bcf164d55c50ec9b58e51c1017fac..c27d3e61380607fa74ad448c51aad35fe4e4b9a6 100644 --- a/DataControlPlugin.cc +++ b/DataControlPlugin.cc @@ -128,8 +128,9 @@ bool DataControlPlugin::initializeToolbox(QWidget*& _widget) view_->setSelectionBehavior(QAbstractItemView::SelectRows); view_->setSelectionMode(QAbstractItemView::ExtendedSelection); - connect( model_,SIGNAL(dataChanged( const QModelIndex&, const QModelIndex& ) ), - this,SLOT(slotDataChanged( const QModelIndex&, const QModelIndex& ))); + + connect( model_,SIGNAL(dataChangedInside( const QModelIndex&) ), + this, SLOT( slotDataChanged( const QModelIndex& )) ); connect( model_ , SIGNAL( modelAboutToBeReset() ), this , SLOT(slotModelAboutToReset() ) ); @@ -156,55 +157,89 @@ bool DataControlPlugin::initializeToolbox(QWidget*& _widget) //****************************************************************************** -/** \brief inform the model that it has to reset when an object changes +/** \brief update drawing of objects when the active object changed * + */ +void DataControlPlugin::slotObjectSelectionChanged( int _identifier ) +{ + + BaseObjectData* obj = 0; + + if ( PluginFunctions::getObject( _identifier, obj) ){ + + if ( obj->target() ) { + obj->materialNode()->disable_blending(); + OpenMesh::Vec4f base_color = obj->materialNode()->base_color(); + base_color[3] = 1.0; + obj->materialNode()->set_base_color(base_color); + OpenMesh::Vec4f ambient_color = obj->materialNode()->ambient_color(); + ambient_color[3] = 1.0; + obj->materialNode()->set_ambient_color(ambient_color); + OpenMesh::Vec4f diffuse_color = obj->materialNode()->diffuse_color(); + diffuse_color[3] = 1.0; + obj->materialNode()->set_diffuse_color(diffuse_color); + } else { + obj->materialNode()->enable_blending(); + OpenMesh::Vec4f base_color = obj->materialNode()->base_color(); + base_color[3] = 0.4; + obj->materialNode()->set_base_color(base_color); + OpenMesh::Vec4f ambient_color = obj->materialNode()->ambient_color(); + ambient_color[3] = 0.4; + obj->materialNode()->set_ambient_color(ambient_color); + OpenMesh::Vec4f diffuse_color = obj->materialNode()->diffuse_color(); + diffuse_color[3] = 0.4; + obj->materialNode()->set_diffuse_color(diffuse_color); + } + } + + model_->objectChanged( _identifier ); + + emit updateView(); +} + + +//****************************************************************************** + +/** \brief Update the model if the visibility of an object changed + * * @param _identifier id of an object */ -void DataControlPlugin::slotObjectUpdated( int _identifier ) { - model_->updatedObject( _identifier ); +void DataControlPlugin::slotVisibilityChanged( int _identifier ){ + model_->objectChanged( _identifier ); } //****************************************************************************** -/** \brief update drawing of objects when the active object changed - * +/** \brief Update the model if properties of an object changed + * + * @param _identifier id of an object */ -void DataControlPlugin::slotActiveObjectChanged() -{ +void DataControlPlugin::slotObjectPropertiesChanged( int _identifier ){ + model_->objectChanged( _identifier ); +} - // find changed manipulator - for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; - o_it != PluginFunctions::objectsEnd(); ++o_it) { - if ( o_it->target() ) { - o_it->materialNode()->disable_blending(); - OpenMesh::Vec4f base_color = o_it->materialNode()->base_color(); - base_color[3] = 1.0; - o_it->materialNode()->set_base_color(base_color); - OpenMesh::Vec4f ambient_color = o_it->materialNode()->ambient_color(); - ambient_color[3] = 1.0; - o_it->materialNode()->set_ambient_color(ambient_color); - OpenMesh::Vec4f diffuse_color = o_it->materialNode()->diffuse_color(); - diffuse_color[3] = 1.0; - o_it->materialNode()->set_diffuse_color(diffuse_color); - } else { - o_it->materialNode()->enable_blending(); - OpenMesh::Vec4f base_color = o_it->materialNode()->base_color(); - base_color[3] = 0.4; - o_it->materialNode()->set_base_color(base_color); - OpenMesh::Vec4f ambient_color = o_it->materialNode()->ambient_color(); - ambient_color[3] = 0.4; - o_it->materialNode()->set_ambient_color(ambient_color); - OpenMesh::Vec4f diffuse_color = o_it->materialNode()->diffuse_color(); - diffuse_color[3] = 0.4; - o_it->materialNode()->set_diffuse_color(diffuse_color); - } + +//****************************************************************************** + +/** \brief Update the model if an object was created/deleted + * + * @param _identifier id of an object + */ +void DataControlPlugin::slotObjectUpdated( int _identifier ){ + + if (_identifier != -1){ + //abort if the object is already in the model + BaseObject* obj; + + if ( PluginFunctions::getObject( _identifier, obj) ) + if ( (model_->getModelIndex(obj, 0)).isValid() ) + return; } - emit updateView(); + model_->objectChanged( -1 ); } - //****************************************************************************** /** \brief a key event occurred @@ -242,29 +277,32 @@ void DataControlPlugin::slotKeyEvent( QKeyEvent* _event ) * @param topLeft index in the model * @param */ -void DataControlPlugin::slotDataChanged ( const QModelIndex & topLeft, - const QModelIndex & /*bottomRight*/ ) +void DataControlPlugin::slotDataChanged ( const QModelIndex& _index) { - switch (topLeft.column()) { + BaseObject* obj = model_->getItem(_index); + + switch (_index.column()) { // Name case 0: + emit objectPropertiesChanged( obj->id() ); view_->expandToDepth(0); break; // show/hide case 1: - emit visibilityChanged( ); - emit updateView(); + emit visibilityChanged( obj->id() ); + emit updateView(); break; // source case 2: + emit objectSelectionChanged( obj->id() ); break; // target case 3: - emit activeObjectChanged(); + emit objectSelectionChanged( obj->id() ); break; default: diff --git a/DataControlPlugin.hh b/DataControlPlugin.hh index 7185413d31f6ac1f96d00dff06f750935125eaf6..c249491b82d3ef9ff6c5e39e98bcaebdb137cd9e 100644 --- a/DataControlPlugin.hh +++ b/DataControlPlugin.hh @@ -66,8 +66,9 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn // BaseInterface void updateView(); void updatedObject(int); - void visibilityChanged(); - void activeObjectChanged(); + void visibilityChanged(int); + void objectSelectionChanged(int); + void objectPropertiesChanged(int); void setSlotDescription(QString _slotName, QString _slotDescription, QStringList _parameters, QStringList _descriptions); @@ -82,8 +83,10 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn private slots : // BaseInterface void pluginsInitialized(); - void slotObjectUpdated( int _identifier ); - void slotActiveObjectChanged(); + void slotObjectUpdated ( int _identifier ); + void slotVisibilityChanged ( int _identifier ); + void slotObjectSelectionChanged ( int _identifier ); + void slotObjectPropertiesChanged( int _identifier ); // KeyInterface void slotKeyEvent( QKeyEvent* _event ); @@ -127,6 +130,7 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn /// Pointer to the header to the view widget QHeaderView * viewHeader_; + //=========================================================================== /** @name Slots which are called if data changed * @{ */ @@ -135,7 +139,7 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn private slots: /// Gets called when the data in the table has changed - void slotDataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ); + void slotDataChanged ( const QModelIndex & _index ); void slotModelAboutToReset(); diff --git a/DataControlPluginScripting.cc b/DataControlPluginScripting.cc index 9972a91e8f591347e7b42674af89d50d4c58674b..36404d7b40d1a19f56be5ea5c5da3a9fcc131f78 100644 --- a/DataControlPluginScripting.cc +++ b/DataControlPluginScripting.cc @@ -164,17 +164,11 @@ QString DataControlPlugin::getObjectName( int objectId ) { void DataControlPlugin::hideObject( int objectId ) { BaseObjectData* object; - if ( ! PluginFunctions::getObject(objectId,object) ) - return; + if ( PluginFunctions::getObject(objectId,object) ){ + object->hide(); - if ( object == 0) - return; - - object->hide(); - - //get a modelIndex for the visible column (1) and update the treeModel - QModelIndex index = model_->getModelIndex( dynamic_cast< BaseObject* > (object), 1 ); - model_->setData( index, false, 0 ); + emit visibilityChanged( object->id() ); + } } @@ -188,18 +182,11 @@ void DataControlPlugin::hideObject( int objectId ) { void DataControlPlugin::setTarget( int objectId, bool _target ) { BaseObjectData* object; - if ( ! PluginFunctions::getObject(objectId,object) ) - return; - - if ( object == 0) - return; - - object->target( _target ); - - //get a modelIndex for the target column (3) and update the treeModel - QModelIndex index = model_->getModelIndex( dynamic_cast< BaseObject* > (object), 3 ); - model_->setData( index, _target, 0 ); + if ( PluginFunctions::getObject(objectId,object) ){ + object->target( _target ); + emit objectSelectionChanged( object->id() ); + } } @@ -213,17 +200,12 @@ void DataControlPlugin::setTarget( int objectId, bool _target ) { void DataControlPlugin::setSource( int objectId, bool _source ) { BaseObjectData* object; - if ( ! PluginFunctions::getObject(objectId,object) ) - return; - - if ( object == 0) - return; + if ( PluginFunctions::getObject(objectId,object) ){ + object->source( _source ); - object->source( _source ); + emit objectSelectionChanged( object->id() ); + } - //get a modelIndex for the source column (2) and update the treeModel - QModelIndex index = model_->getModelIndex( dynamic_cast< BaseObject* > (object), 2 ); - model_->setData( index, _source, 0 ); } @@ -237,17 +219,11 @@ void DataControlPlugin::setSource( int objectId, bool _source ) { void DataControlPlugin::setObjectName( int objectId, QString _name ) { BaseObjectData* object; - if ( ! PluginFunctions::getObject(objectId,object) ) - return; - - if ( object == 0) - return; + if ( PluginFunctions::getObject(objectId,object) ){ + object->setName( _name ); - object->setName( _name ); - - //get a modelIndex for the name column (0) and update the treeModel - QModelIndex index = model_->getModelIndex( dynamic_cast< BaseObject* > (object), 0 ); - model_->setData( index, _name, 0 ); + emit objectPropertiesChanged( object->id() ); + } } @@ -279,17 +255,11 @@ void DataControlPlugin::deleteObject( int objectId ) { void DataControlPlugin::showObject( int objectId ) { BaseObjectData* object; - if ( ! PluginFunctions::getObject(objectId,object) ) - return; - - if ( object == 0) - return; + if ( PluginFunctions::getObject(objectId,object) ){ + object->show(); - object->show(); - - //get a modelIndex for the visible column (1) and update the treeModel - QModelIndex index = model_->getModelIndex( dynamic_cast< BaseObject* > (object), 1 ); - model_->setData( index, true, 0 ); + emit visibilityChanged( object->id() ); + } } @@ -353,21 +323,17 @@ void DataControlPlugin::groupObjects(idList _objectIDs, QString _groupName) { groupItem->target(target); groupItem->source(source); - //get a modelIndex for the source column (2) and update the treeModel - QModelIndex index = model_->getModelIndex( dynamic_cast< BaseObject* > (groupItem), 2 ); - model_->setData( index, source, 0 ); - - //get a modelIndex for the target column (3) and update the treeModel - index = model_->getModelIndex( dynamic_cast< BaseObject* > (groupItem), 3 ); - model_->setData( index, target, 0 ); + emit objectPropertiesChanged( groupItem->id() ); + emit objectSelectionChanged ( groupItem->id() ); - emit updatedObject(-1); + //because the parent of all items in the group changed + emit objectPropertiesChanged( -1 ); } //****************************************************************************** -/** \brief Set Traget Selection for all objects +/** \brief Set Target Selection for all objects * */ void DataControlPlugin::setAllTarget() { @@ -375,18 +341,8 @@ void DataControlPlugin::setAllTarget() { o_it != PluginFunctions::objectsEnd(); ++o_it){ o_it->target(true); - BaseObject* obj = 0; - PluginFunctions::getObject(o_it->id(), obj); - - //get a modelIndex for the target column (3) and update the treeModel - if (obj != 0){ - QModelIndex index = model_->getModelIndex( obj, 3 ); - model_->setData( index, true, 0 ); - } + emit objectSelectionChanged( o_it->id() ); } - - emit activeObjectChanged(); - emit updatedObject(-1); } @@ -400,17 +356,8 @@ void DataControlPlugin::setAllSource() { o_it != PluginFunctions::objectsEnd(); ++o_it){ o_it->source(true); - //get a modelIndex for the source column (2) and update the treeModel - BaseObject* obj = 0; - PluginFunctions::getObject(o_it->id(), obj); - - if (obj != 0){ - QModelIndex index = model_->getModelIndex( obj, 2 ); - model_->setData( index, true, 0 ); - } + emit objectSelectionChanged( o_it->id() ); } - - emit updatedObject(-1); } @@ -424,18 +371,8 @@ void DataControlPlugin::clearAllTarget() { o_it != PluginFunctions::objectsEnd(); ++o_it){ o_it->target(false); - //get a modelIndex for the target column (3) and update the treeModel - BaseObject* obj = 0; - PluginFunctions::getObject(o_it->id(), obj); - - if (obj != 0){ - QModelIndex index = model_->getModelIndex( obj, 3 ); - model_->setData( index, false, 0 ); - } + emit objectSelectionChanged( o_it->id() ); } - - emit activeObjectChanged(); - emit updatedObject(-1); } @@ -449,17 +386,8 @@ void DataControlPlugin::clearAllSource() { o_it != PluginFunctions::objectsEnd(); ++o_it){ o_it->source(false); - //get a modelIndex for the source column (2) and update the treeModel - BaseObject* obj = 0; - PluginFunctions::getObject(o_it->id(), obj); - - if (obj != 0){ - QModelIndex index = model_->getModelIndex( obj, 2 ); - model_->setData( index, false, 0 ); - } + emit objectSelectionChanged( o_it->id() ); } - - emit updatedObject(-1); } @@ -473,14 +401,7 @@ void DataControlPlugin::hideAll() { o_it != PluginFunctions::objectsEnd(); ++o_it){ o_it->hide(); - //get a modelIndex for the visible column (1) and update the treeModel - BaseObject* obj = 0; - PluginFunctions::getObject(o_it->id(), obj); - - if (obj != 0){ - QModelIndex index = model_->getModelIndex( obj, 1 ); - model_->setData( index, false, 0 ); - } + emit visibilityChanged( o_it->id() ); } emit updateView(); @@ -497,14 +418,7 @@ void DataControlPlugin::showAll() { o_it != PluginFunctions::objectsEnd(); ++o_it){ o_it->show(); - //get a modelIndex for the visible column (1) and update the treeModel - BaseObject* obj = 0; - PluginFunctions::getObject(o_it->id(), obj); - - if (obj != 0){ - QModelIndex index = model_->getModelIndex( obj, 1 ); - model_->setData( index, true, 0 ); - } + visibilityChanged( o_it->id() ); } emit updateView(); diff --git a/Popup.cc b/Popup.cc index 1ca5d5092b0a23082992468a4802e53ff5019989..3580a6fe56438c6a8d051b399a0c6754275dee27 100644 --- a/Popup.cc +++ b/Popup.cc @@ -120,7 +120,8 @@ void DataControlPlugin::slotUngroup ( ) { delete group; - emit updatedObject(-1); + //because the parent of all items in the group changed + emit objectPropertiesChanged( -1 ); } @@ -146,8 +147,6 @@ void DataControlPlugin::slotCopy() { emit log(LOGERR, "Unable to copy object" ); continue; } - - emit updatedObject(copyItem->id()); } emit updateView(); @@ -167,8 +166,9 @@ void DataControlPlugin::slotGroup() { //check if all objects have the same parent //abort if the parents differ - bool target = (model_->getItem( indexList[0]))->target(); - bool source = (model_->getItem( indexList[0]))->source(); + bool visible = (model_->getItem( indexList[0]))->visible(); + bool target = (model_->getItem( indexList[0]))->target(); + bool source = (model_->getItem( indexList[0]))->source(); BaseObject* parent = (model_->getItem( indexList[0]))->parent(); for ( int i = 1 ; i < indexList.size() ; ++i) { @@ -179,8 +179,9 @@ void DataControlPlugin::slotGroup() { } //remember if at least on child was target/source - target |= (model_->getItem( indexList[i]))->target(); - source |= (model_->getItem( indexList[i]))->source(); + visible |= (model_->getItem( indexList[i]))->visible(); + target |= (model_->getItem( indexList[i]))->target(); + source |= (model_->getItem( indexList[i]))->source(); } //create new group @@ -200,18 +201,16 @@ void DataControlPlugin::slotGroup() { } //update target/source state + groupItem->visible(visible); groupItem->target(target); groupItem->source(source); - //get a modelIndex for the source column (2) and update the treeModel - QModelIndex index = model_->getModelIndex( dynamic_cast< BaseObject* > (groupItem), 2 ); - model_->setData( index, source, 0 ); - - //get a modelIndex for the target column (3) and update the treeModel - index = model_->getModelIndex( dynamic_cast< BaseObject* > (groupItem), 3 ); - model_->setData( index, target, 0 ); + emit visibilityChanged( groupItem->id() ); + emit objectPropertiesChanged( groupItem->id() ); + emit objectSelectionChanged ( groupItem->id() ); - emit updatedObject(-1); + //because the parent of all items in the group changed + emit objectPropertiesChanged( -1 ); } @@ -350,8 +349,10 @@ void DataControlPlugin::slotRename(){ QString newName = QInputDialog::getText(0, tr("Rename"), tr("Enter a new name:"), QLineEdit::Normal, item->name(), &ok); - if (ok && !newName.isEmpty()) + if (ok && !newName.isEmpty()){ item->setName(newName); + emit objectPropertiesChanged( item->id() ); + } } } diff --git a/TreeModel.cc b/TreeModel.cc index bb909b024679016bc54f42a4da193d97d7fef85f..914df7219aa9898f9fab7705005070b1e3096de3 100644 --- a/TreeModel.cc +++ b/TreeModel.cc @@ -341,32 +341,35 @@ int TreeModel::rowCount(const QModelIndex &_parent) const //****************************************************************************** -/** \brief The object with the given id has been updated. Update the model. +/** \brief The object with the given id has been changed. Update the model. * * @param _id id of an object */ -void TreeModel::updatedObject(int _id) { +void TreeModel::objectChanged(int _id) { if ( _id != -1 ){ BaseObject* obj = 0; PluginFunctions::getObject(_id, obj); - if (obj != 0 && getModelIndex(obj,0).isValid() ){ - -// //set new values for the object -// QVector< QVariant > values; -// -// values.push_back( obj->name() ); -// values.push_back( obj->visible() ); -// values.push_back( obj->source() ); -// values.push_back( obj->target() ); -// -// for(int i=0; i < 4; i++) -// setData( getModelIndex(obj,i), values[i], 0); -// - return; + QModelIndex name = getModelIndex(obj,0); + QModelIndex visible = getModelIndex(obj,1); + QModelIndex source = getModelIndex(obj,2); + QModelIndex target = getModelIndex(obj,3); + + if (obj != 0 ){ + + if ( name.isValid() ) + emit dataChanged( name, name); + if ( visible.isValid() ) + emit dataChanged( visible, visible); + if ( source.isValid() ) + emit dataChanged( source, source); + if ( target.isValid() ) + emit dataChanged( target, target); } + + return; } //otherwise reset the model @@ -413,49 +416,127 @@ QModelIndex TreeModel::getModelIndex(BaseObject* _object, int _column ){ //****************************************************************************** -/** \brief Recursively update source selection up to the root of the tree +/** \brief Recursively update a column up to the root of the tree * - * @param _obj object to start with + * @param _obj object to start with */ -void TreeModel::updateSourceSelection(BaseObject* _obj ){ +void TreeModel::propagateUpwards(BaseObject* _obj, int _column ){ if ( isRoot(_obj) || (!_obj->isGroup()) ) return; QList< BaseObject* > children = _obj->getLeafs(); + bool changed = false; + bool value = false; - bool source = false; - for (int i=0; i < children.size(); i++) - source |= children[i]->source(); + switch ( _column ){ - _obj->source( source ); + case 1: //VISIBILTY - updateSourceSelection( _obj->parent() ); -} + for (int i=0; i < children.size(); i++) + value |= children[i]->visible(); + + if ( true /*_obj->visible() != value*/){ + _obj->visible( value ); + changed = true; + } + break; + + case 2: //SOURCE + + for (int i=0; i < children.size(); i++) + value |= children[i]->source(); + + if (_obj->source() != value){ + + _obj->source( value ); + changed = true; + } + break; + + case 3: //TARGET + + for (int i=0; i < children.size(); i++) + value |= children[i]->target(); + if (_obj->target() != value){ + + _obj->target( value ); + changed = true; + } + break; + + default: + break; + } + + //if (changed){ + + QModelIndex index = getModelIndex(_obj, _column); + emit dataChanged(index, index); + emit dataChangedInside(index); + //} + + propagateUpwards( _obj->parent(), _column ); +} //****************************************************************************** -/** \brief Recursively update target selection up to the root of the tree +/** \brief Recursively update a column up to the root of the tree * * @param _obj object to start with */ -void TreeModel::updateTargetSelection(BaseObject* _obj ){ +void TreeModel::propagateDownwards(BaseObject* _obj, int _column ){ - if ( isRoot(_obj) || (!_obj->isGroup()) ) - return; + for (int i=0; i < _obj->childCount(); i++){ - QList< BaseObject* > children = _obj->getLeafs(); + BaseObject* current = _obj->child(i); - bool target = false; - for (int i=0; i < children.size(); i++) - target |= children[i]->target(); + bool changed = false; - _obj->target( target ); + switch ( _column ){ - updateTargetSelection( _obj->parent() ); -} + case 1: //VISIBILTY + + if ( current->visible() != _obj->visible() ){ + current->visible( _obj->visible() ); + changed = true; + } + break; + + case 2: //SOURCE + if ( current->source() != _obj->source() ){ + + current->source( _obj->source() ); + changed = true; + } + break; + + case 3: //TARGET + + if ( current->target() != _obj->target() ){ + + current->target( _obj->target() ); + changed = true; + } + break; + + default: + break; + } + + if ( current->isGroup() ) + propagateDownwards(current, _column); + + //if (changed){ + + QModelIndex index = getModelIndex(current, _column); + emit dataChanged(index, index); + emit dataChangedInside(index); + //} + } +} //****************************************************************************** @@ -469,191 +550,178 @@ void TreeModel::updateTargetSelection(BaseObject* _obj ){ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*role*/) { BaseObject *item = getItem(index); - + + bool changed = false; + bool newValue; + if ( item->isGroup() ) { int childCount = 0; // Decide on column what to do with the value switch ( index.column() ) { + // Name case 0 : if ( value.toString() == "" ) return false; - - item->setName( value.toString() ); + + if (item->name() != value.toString() ){ + item->setName( value.toString() ); + changed = true; + } break; - + // visible - case 1 : - if ( value.toInt() == Qt::Unchecked ) { - - QList< BaseObject* > children = item->getLeafs(); - - childCount = children.size(); + case 1 : + newValue = value.toBool(); - for (int i=0; i < children.size(); i++){ - BaseObjectData* child = dynamic_cast< BaseObjectData* > (children[i]); - if (child) - child->hide(); - } - } - - if ( value.toInt() == Qt::Checked ) { - - QList< BaseObject* > children = item->getLeafs(); - - childCount = children.size(); +std::cerr << "change visibilty :" << item->visible() << " to " << newValue << std::endl; + + if ( true /*item->visible() != newValue*/){ + + item->visible(newValue); + changed = true; +std::cerr << "changed visibilty :" << item->visible() << " to " << newValue << std::endl; + + propagateDownwards(item, index.row()); - for (int i=0; i < children.size(); i++){ - BaseObjectData* child = dynamic_cast< BaseObjectData* > (children[i]); - if (child) - child->show(); - } } - - break; - + + break; + // source case 2 : - if ( value.toInt() == Qt::Unchecked ) { + newValue = value.toBool(); - item->source(false); - - QList< BaseObject* > children = item->getLeafs(); + if (item->source() != newValue){ + item->source( newValue ); + changed = true; + + QList< BaseObject* > children = item->getLeafs(); + childCount = children.size(); - + for (int i=0; i < children.size(); i++){ - if (children[i]) - children[i]->source(false); + if (children[i] && children[i]->source() != newValue){ + children[i]->source( newValue ); + + QModelIndex childIndex = createIndex((children[i])->row(), index.column(), children[i]); + emit dataChanged( childIndex, childIndex ); + emit dataChangedInside(childIndex); + } } } - - if ( value.toInt() == Qt::Checked ) { - - item->source(true); - - QList< BaseObject* > children = item->getLeafs(); - - childCount = children.size(); - for (int i=0; i < children.size(); i++){ - if (children[i]) - children[i]->source(true); - } - } break; - + //target case 3 : - if ( value.toInt() == Qt::Unchecked ) { - - item->target(false); + newValue = value.toBool(); - QList< BaseObject* > children = item->getLeafs(); - - childCount = children.size(); - - for (int i=0; i < children.size(); i++){ - if (children[i]) - children[i]->target(false); - } - } - - if ( value.toInt() == Qt::Checked ) { - - item->target(true); + if (item->target() != newValue){ + item->target( newValue ); + changed = true; + QList< BaseObject* > children = item->getLeafs(); - + childCount = children.size(); - + for (int i=0; i < children.size(); i++){ - if (children[i]) - children[i]->target(true); + if (children[i] && children[i]->target() != newValue){ + children[i]->target( newValue ); + + QModelIndex childIndex = createIndex((children[i])->row(), index.column(), children[i]); + emit dataChanged( childIndex, childIndex ); + emit dataChangedInside(childIndex); + } } } + break; } - if (childCount > 0){ - BaseObject* obj = item->getLeafs()[childCount-1]; - - QModelIndex childIndex = createIndex(obj->row(),index.column() , obj); - - emit dataChanged( index,childIndex ); - }else + if (changed){ emit dataChanged( index, index ); + emit dataChangedInside(index); + } return true; } // <- Item is not a group - bool checked; + BaseObjectData* baseObject = 0; // Decide on column what to do with the value ( abort if anything goes wrong) switch ( index.column() ) { - // Name : + + // Name case 0 : if ( value.toString() == "" ) return false; - item->setName(value.toString()); + + if (item->name() != value.toString() ){ + item->setName( value.toString() ); + changed = true; + } break; - + // visible case 1 : - if ( value.toInt() == Qt::Unchecked ) { - - BaseObjectData* baseObject = dynamic_cast< BaseObjectData* >(item); - - if ( baseObject ) - baseObject->hide(); - else - std::cerr << " Trying to hide invisible object e.g. Group " << std::endl; - } - - if ( value.toInt() == Qt::Checked ) { - BaseObjectData* baseObject = dynamic_cast< BaseObjectData* >(item); - - if ( baseObject ) - baseObject->show(); - else - std::cerr << " Trying to show invisible object e.g. Group " << std::endl; - } - - break; - + + newValue = value.toBool(); + + baseObject = dynamic_cast< BaseObjectData* >(item); + + if ( baseObject ) + if ( item->visible() != newValue ){ + + baseObject->visible(newValue); + changed = true; + + propagateUpwards( item->parent(), index.column() ); + } + + break; + // source case 2 : - checked = value.toBool(); + newValue = value.toBool(); - item->source( checked ); + if (item->source() != newValue){ - updateSourceSelection( item->parent() ); + item->source( newValue ); + changed = true; + propagateUpwards( item->parent(), index.column() ); + } break; //target case 3 : - checked = value.toBool(); + newValue = value.toBool(); - item->target( checked ); + if (item->target() != newValue){ - updateTargetSelection( item->parent() ); + item->target( newValue ); + changed = true; + propagateUpwards( item->parent(), index.column() ); + } break; - + default: - break; - } - - emit dataChanged(index,index); - //force everything to be updated (needed to updated parent groups) - emit dataChanged(QModelIndex(),QModelIndex()); + + if (changed){ + emit dataChanged(index,index); + emit dataChangedInside(index); + } + return true; } diff --git a/TreeModel.hh b/TreeModel.hh index 9de5f66a83c4aa21f3e458b925dc44303326d97a..0eaf9c2184573b317040ee636341f06661bfb395 100644 --- a/TreeModel.hh +++ b/TreeModel.hh @@ -47,6 +47,9 @@ class TreeModel : public QAbstractItemModel { Q_OBJECT +signals: + void dataChangedInside(const QModelIndex& _index); + public: /// Constructor @@ -107,8 +110,8 @@ public: /// Get the name of a given object bool getObjectName(BaseObject* _object , QString& _name); - /// The object with the given id has been updated. Check if model has to be changed - void updatedObject(int id_); + /// The object with the given id has been changed. Check if model also has to be changed + void objectChanged(int id_); /// Get the BaseObject corresponding to a given ModelIndex BaseObject *getItem(const QModelIndex &index) const; @@ -124,9 +127,9 @@ private: */ std::map< int, TreeItem* > map_; - /// Recursively update source,target selection up to the root of the tree - void updateSourceSelection(BaseObject* _obj ); - void updateTargetSelection(BaseObject* _obj ); + + void propagateUpwards(BaseObject* _obj, int _column ); + void propagateDownwards(BaseObject* _obj, int _column ); /** @} */