Commit ce55b9ef authored by Dirk Wilden's avatar Dirk Wilden

buggy TreeModel update

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5340 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 230b746b
......@@ -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) {
......
......@@ -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:
......
......@@ -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();
......
......@@ -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();
......
......@@ -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() );
}
}
}
......
This diff is collapsed.
......@@ -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 );
/** @} */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment