Commit 7280cbb8 authored by Dirk Wilden's avatar Dirk Wilden
Browse files

fixed last version

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5347 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ce55b9ef
...@@ -129,8 +129,8 @@ bool DataControlPlugin::initializeToolbox(QWidget*& _widget) ...@@ -129,8 +129,8 @@ bool DataControlPlugin::initializeToolbox(QWidget*& _widget)
view_->setSelectionMode(QAbstractItemView::ExtendedSelection); view_->setSelectionMode(QAbstractItemView::ExtendedSelection);
connect( model_,SIGNAL(dataChangedInside( const QModelIndex&) ), connect( model_,SIGNAL(dataChangedInside(BaseObject*,int) ),
this, SLOT( slotDataChanged( const QModelIndex& )) ); this, SLOT( slotDataChanged(BaseObject*,int)) );
connect( model_ , SIGNAL( modelAboutToBeReset() ), connect( model_ , SIGNAL( modelAboutToBeReset() ),
this , SLOT(slotModelAboutToReset() ) ); this , SLOT(slotModelAboutToReset() ) );
...@@ -228,18 +228,33 @@ void DataControlPlugin::slotObjectPropertiesChanged( int _identifier ){ ...@@ -228,18 +228,33 @@ void DataControlPlugin::slotObjectPropertiesChanged( int _identifier ){
*/ */
void DataControlPlugin::slotObjectUpdated( int _identifier ){ void DataControlPlugin::slotObjectUpdated( int _identifier ){
if (_identifier != -1){ if (_identifier == -1)
//abort if the object is already in the model model_->objectChanged( _identifier );
BaseObject* obj; }
if ( PluginFunctions::getObject( _identifier, obj) )
if ( (model_->getModelIndex(obj, 0)).isValid() )
return;
}
model_->objectChanged( -1 ); //******************************************************************************
/** \brief Update the model if a file has been opened
*
* @param _id id of an object
*/
void DataControlPlugin::fileOpened(int){
model_->objectChanged(-1);
}
//******************************************************************************
/** \brief Update the model if an empty object has been added
*
* @param _id id of an object
*/
void DataControlPlugin::addedEmptyObject(int){
model_->objectChanged(-1);
} }
//****************************************************************************** //******************************************************************************
/** \brief a key event occurred /** \brief a key event occurred
...@@ -277,36 +292,37 @@ void DataControlPlugin::slotKeyEvent( QKeyEvent* _event ) ...@@ -277,36 +292,37 @@ void DataControlPlugin::slotKeyEvent( QKeyEvent* _event )
* @param topLeft index in the model * @param topLeft index in the model
* @param * @param
*/ */
void DataControlPlugin::slotDataChanged ( const QModelIndex& _index) void DataControlPlugin::slotDataChanged ( BaseObject* _obj, int _column)
{ {
BaseObject* obj = model_->getItem(_index); if (_obj != 0){
// std::cerr << "slotDataChanged obj " << _obj->id() << " column " << _column << std::endl;
switch (_index.column()) { switch ( _column ) {
// Name // Name
case 0: case 0:
emit objectPropertiesChanged( obj->id() ); emit objectPropertiesChanged( _obj->id() );
view_->expandToDepth(0); view_->expandToDepth(0);
break; break;
// show/hide // show/hide
case 1: case 1:
emit visibilityChanged( obj->id() ); emit visibilityChanged( _obj->id() );
emit updateView(); emit updateView();
break; break;
// source
case 2:
emit objectSelectionChanged( _obj->id() );
break;
// target
case 3:
emit objectSelectionChanged( _obj->id() );
break;
// source default:
case 2: break;
emit objectSelectionChanged( obj->id() ); }
break;
// target
case 3:
emit objectSelectionChanged( obj->id() );
break;
default:
break;
} }
} }
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh> #include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh> #include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/INIInterface.hh> #include <OpenFlipper/BasePlugin/INIInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/common/Types.hh> #include <OpenFlipper/common/Types.hh>
#include "Toolbox.hh" #include "Toolbox.hh"
...@@ -51,7 +52,7 @@ ...@@ -51,7 +52,7 @@
/** Plugin for controlling the Object data structures (Show,hide Object, Target, Source selection /** Plugin for controlling the Object data structures (Show,hide Object, Target, Source selection
*/ */
class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyInterface , LoggingInterface, INIInterface, ContextMenuInterface, ScriptInterface class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyInterface , LoggingInterface, INIInterface, ContextMenuInterface, ScriptInterface, LoadSaveInterface
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(BaseInterface) Q_INTERFACES(BaseInterface)
...@@ -61,6 +62,7 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn ...@@ -61,6 +62,7 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
Q_INTERFACES(INIInterface) Q_INTERFACES(INIInterface)
Q_INTERFACES(ContextMenuInterface) Q_INTERFACES(ContextMenuInterface)
Q_INTERFACES(ScriptInterface) Q_INTERFACES(ScriptInterface)
Q_INTERFACES(LoadSaveInterface)
signals: signals:
// BaseInterface // BaseInterface
...@@ -95,6 +97,10 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn ...@@ -95,6 +97,10 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
void loadIniFileOptionsLast( INIFile& _ini ); void loadIniFileOptionsLast( INIFile& _ini );
void saveIniFileOptions( INIFile& _ini ); void saveIniFileOptions( INIFile& _ini );
// LoadSaveInterface
void fileOpened(int _id);
void addedEmptyObject(int _id);
public : public :
/// Destructor /// Destructor
~DataControlPlugin() {}; ~DataControlPlugin() {};
...@@ -139,7 +145,7 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn ...@@ -139,7 +145,7 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
private slots: private slots:
/// Gets called when the data in the table has changed /// Gets called when the data in the table has changed
void slotDataChanged ( const QModelIndex & _index ); void slotDataChanged ( BaseObject* _obj, int _column );
void slotModelAboutToReset(); void slotModelAboutToReset();
......
...@@ -359,14 +359,15 @@ void TreeModel::objectChanged(int _id) { ...@@ -359,14 +359,15 @@ void TreeModel::objectChanged(int _id) {
if (obj != 0 ){ if (obj != 0 ){
if ( name.isValid() ) // if ( name.isValid() )
emit dataChanged( name, name); // emit dataChanged( name, name);
if ( visible.isValid() ) // if ( visible.isValid() )
emit dataChanged( visible, visible); // emit dataChanged( visible, visible);
if ( source.isValid() ) // if ( source.isValid() )
emit dataChanged( source, source); // emit dataChanged( source, source);
if ( target.isValid() ) // if ( target.isValid() )
emit dataChanged( target, target); // emit dataChanged( target, target);
emit dataChanged( QModelIndex(), QModelIndex() );
} }
return; return;
...@@ -397,7 +398,9 @@ BaseObject* TreeModel::getItem(const QModelIndex &index) const ...@@ -397,7 +398,9 @@ BaseObject* TreeModel::getItem(const QModelIndex &index) const
//****************************************************************************** //******************************************************************************
/** \brief Return index of given item /** \brief Return index of given item
* *
* Warning: Only use this function if you know that all ModelIndices are created
*
* @param _object an object * @param _object an object
* @param _column a column * @param _column a column
* @return index of object and column * @return index of object and column
...@@ -436,10 +439,9 @@ void TreeModel::propagateUpwards(BaseObject* _obj, int _column ){ ...@@ -436,10 +439,9 @@ void TreeModel::propagateUpwards(BaseObject* _obj, int _column ){
for (int i=0; i < children.size(); i++) for (int i=0; i < children.size(); i++)
value |= children[i]->visible(); value |= children[i]->visible();
if ( true /*_obj->visible() != value*/){ _obj->visible( value );
_obj->visible( value ); changed = true;
changed = true;
}
break; break;
case 2: //SOURCE case 2: //SOURCE
...@@ -470,12 +472,8 @@ void TreeModel::propagateUpwards(BaseObject* _obj, int _column ){ ...@@ -470,12 +472,8 @@ void TreeModel::propagateUpwards(BaseObject* _obj, int _column ){
break; break;
} }
//if (changed){ if (changed && (!_obj->isGroup()) )
emit dataChangedInside(_obj, _column );
QModelIndex index = getModelIndex(_obj, _column);
emit dataChanged(index, index);
emit dataChangedInside(index);
//}
propagateUpwards( _obj->parent(), _column ); propagateUpwards( _obj->parent(), _column );
} }
...@@ -499,6 +497,7 @@ void TreeModel::propagateDownwards(BaseObject* _obj, int _column ){ ...@@ -499,6 +497,7 @@ void TreeModel::propagateDownwards(BaseObject* _obj, int _column ){
case 1: //VISIBILTY case 1: //VISIBILTY
if ( current->visible() != _obj->visible() ){ if ( current->visible() != _obj->visible() ){
current->visible( _obj->visible() ); current->visible( _obj->visible() );
changed = true; changed = true;
} }
...@@ -526,15 +525,11 @@ void TreeModel::propagateDownwards(BaseObject* _obj, int _column ){ ...@@ -526,15 +525,11 @@ void TreeModel::propagateDownwards(BaseObject* _obj, int _column ){
break; break;
} }
if ( current->isGroup() ) if ( current->isGroup() ){
propagateDownwards(current, _column); propagateDownwards(current, _column);
//if (changed){ } else if (changed)
emit dataChangedInside(current, _column );
QModelIndex index = getModelIndex(current, _column);
emit dataChanged(index, index);
emit dataChangedInside(index);
//}
} }
} }
...@@ -555,7 +550,6 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*r ...@@ -555,7 +550,6 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*r
bool newValue; bool newValue;
if ( item->isGroup() ) { if ( item->isGroup() ) {
int childCount = 0;
// Decide on column what to do with the value // Decide on column what to do with the value
switch ( index.column() ) { switch ( index.column() ) {
...@@ -572,79 +566,31 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*r ...@@ -572,79 +566,31 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*r
// visible // visible
case 1 : case 1 :
newValue = value.toBool(); item->visible( value.toBool() );
changed = true;
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());
}
propagateDownwards( item, index.column() );
break; break;
// source // source
case 2 : case 2 :
newValue = value.toBool(); item->source( value.toBool() );
changed = true;
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() != newValue){
children[i]->source( newValue );
QModelIndex childIndex = createIndex((children[i])->row(), index.column(), children[i]);
emit dataChanged( childIndex, childIndex );
emit dataChangedInside(childIndex);
}
}
}
propagateDownwards(item, index.column());
break; break;
//target //target
case 3 : case 3 :
newValue = value.toBool(); item->target( value.toBool() );
changed = 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() != newValue){
children[i]->target( newValue );
QModelIndex childIndex = createIndex((children[i])->row(), index.column(), children[i]);
emit dataChanged( childIndex, childIndex );
emit dataChangedInside(childIndex);
}
}
}
propagateDownwards(item, index.column());
break; break;
} }
if (changed){ if (changed)
emit dataChanged( index, index ); emit dataChangedInside(item, index.column() );
emit dataChangedInside(index);
}
return true; return true;
} }
...@@ -717,10 +663,8 @@ std::cerr << "changed visibilty :" << item->visible() << " to " << newValue << s ...@@ -717,10 +663,8 @@ std::cerr << "changed visibilty :" << item->visible() << " to " << newValue << s
break; break;
} }
if (changed){ if (changed)
emit dataChanged(index,index); emit dataChangedInside(item, index.column() );
emit dataChangedInside(index);
}
return true; return true;
} }
......
...@@ -48,7 +48,7 @@ class TreeModel : public QAbstractItemModel ...@@ -48,7 +48,7 @@ class TreeModel : public QAbstractItemModel
Q_OBJECT Q_OBJECT
signals: signals:
void dataChangedInside(const QModelIndex& _index); void dataChangedInside(BaseObject* _obj, int _column);
public: public:
......
Supports Markdown
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