Commit 99f57dfc authored by Matthias Möller's avatar Matthias Möller

seperates target/source selection

refs #1375

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16265 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4169cc20
......@@ -87,6 +87,7 @@ DataControlPlugin::DataControlPlugin() :
viewHeader_(0),
onlyDown_(0),
onlyUp_(0),
columnFromGUI_(-1),
headerPopupType_(0),
targetAction_(0),
sourceAction_(0),
......@@ -240,36 +241,48 @@ void DataControlPlugin::slotObjectSelectionChanged( int _identifier )
if ( PluginFunctions::getObject( _identifier, obj) )
updateBoundingBox (obj);
model_->objectChanged( _identifier );
//check for changes in the tree
BaseObject* object = 0;
if ( !PluginFunctions::getObject( _identifier, object) )
return;
if ( PluginFunctions::getObject( _identifier, object) ){
//check for changes
int column = columnFromGUI_;//if GUI has set the column, use this information
if (column == -1)//otherwise, try to get the column
{
TreeItem* item = model_->getItem(_identifier);
if ( !item )
return;
// if we are allowed to propagate down
if ( onlyUp_ == 0 ){
if (item->source() != object->source())
column = 2;
else if (item->target() != object->target())
column = 3;
else
return;//could not decide, which column needs a update, discard
}
onlyDown_++;
if ( object->isGroup() )
propagateDownwards(object, 2); // 2 = source-target
model_->objectChanged( _identifier );
onlyDown_--;
}
// if we are allowed to propagate down
if ( onlyUp_ == 0 ){
// if we are allowed to propagate up
if ( onlyDown_ == 0 ){
onlyDown_++;
onlyUp_++;
if ( object->isGroup() )
propagateDownwards(object, column); // 2: source 3: target
propagateUpwards(object->parent(), 2); // 2 = source-target
onlyDown_--;
}
onlyUp_--;
}
// if we are allowed to propagate up
if ( onlyDown_ == 0 ){
onlyUp_++;
propagateUpwards(object->parent(), column); // 2: source 3: target
onlyUp_--;
}
}
......@@ -450,12 +463,16 @@ void DataControlPlugin::slotDataChanged ( int _id, int _column, const QVariant&
// source
case 2:
columnFromGUI_ = 2;//set information, which information will be changed
obj->source( _value.toBool() );
columnFromGUI_ = -1;
break;
// target
case 3:
columnFromGUI_ = 3;//set information, which information will be changed
obj->target( _value.toBool() );
columnFromGUI_ = -1;
break;
default:
......@@ -696,7 +713,6 @@ void DataControlPlugin::propagateUpwards(BaseObject* _obj, int _column ){
QList< BaseObject* > children = _obj->getLeafs();
bool changed = false;
bool value = false;
bool value2 = false;
switch ( _column ){
......@@ -712,20 +728,26 @@ void DataControlPlugin::propagateUpwards(BaseObject* _obj, int _column ){
break;
case 2: //SOURCE-TARGET
case 2: //SOURCE
for (int i=0; i < children.size(); i++){
value |= children[i]->source();
value2 |= children[i]->target();
}
if (_obj->source() != value){
_obj->source( value );
changed = true;
}
break;
if (_obj->target() != value2){
_obj->target( value2 );
case 3: //TARGET
for (int i=0; i < children.size(); i++){
value |= children[i]->target();
}
if (_obj->target() != value){
_obj->target( value );
changed = true;
}
......@@ -761,21 +783,20 @@ void DataControlPlugin::propagateDownwards(BaseObject* _obj, int _column ){
if ( current->visible() != _obj->visible() ){
current->visible( _obj->visible() );
changed = true;
}
break;
case 2: //SOURCE-TARGET
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;
......@@ -784,7 +805,7 @@ void DataControlPlugin::propagateDownwards(BaseObject* _obj, int _column ){
break;
}
if ( changed || current->isGroup() ){
if ( current->isGroup() ){
propagateDownwards(current, _column);
}
......
......@@ -186,7 +186,10 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
//variables to restrict propagation direction
int onlyDown_;
int onlyUp_;
//defines, which selection column needs an update if not -1
// 2: source 3: target
int columnFromGUI_;
/** @} */
//===========================================================================
......
......@@ -120,96 +120,95 @@ QVariant TreeModel::data(const QModelIndex &_index, int _role) const
switch (_index.column() ) {
// Name
case 0 :
// If we are setting the name, also add the icon
if ( _role == Qt::DecorationRole ) {
if (item->dataType() == DATA_LIGHT)
{
LightObject* light = 0;
if (item->id() != -1 && PluginFunctions::getObject( item->id(), light ) ) {
if (light != 0 && !light->lightSource()->enabled())
return QVariant (QIcon (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"LightOff.png"));
}
}
return QVariant( typeIcon(item->dataType()) );
// Name
case 0 :
// If we are setting the name, also add the icon
if ( _role == Qt::DecorationRole ) {
if (item->dataType() == DATA_LIGHT)
{
LightObject* light = 0;
if (item->id() != -1 && PluginFunctions::getObject( item->id(), light ) ) {
if (light != 0 && !light->lightSource()->enabled())
return QVariant (QIcon (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"LightOff.png"));
}
}
return QVariant( typeIcon(item->dataType()) );
}
if (_role != Qt::DisplayRole && _role != Qt::EditRole )
return QVariant();
if (_role != Qt::DisplayRole && _role != Qt::EditRole )
return QVariant();
return QVariant(item->name());
return QVariant(item->name());
break;
break;
// Visible
case 1 :
if (_role == Qt::CheckStateRole ) {
bool visible = false;
// target group
if (item->isGroup() && item->childCount() > 0)
{
QList< TreeItem* > children = item->getLeafs();
case 1 :
if (_role == Qt::CheckStateRole ) {
bool visible = false;
// target group
if (item->isGroup() && item->childCount() > 0)
{
QList< TreeItem* > children = item->getLeafs();
visible = children[0]->visible();
for (int i=0; i < children.size() ; ++i)
{
if (visible != children[i]->visible())
return QVariant(Qt::PartiallyChecked);
}
visible = children[0]->visible();
for (int i=0; i < children.size() ; ++i)
{
if (visible != children[i]->visible())
return QVariant(Qt::PartiallyChecked);
}
else
visible = item->visible();
return (visible) ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
}
return QVariant();
else
visible = item->visible();
return (visible) ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
}
return QVariant();
// Source
case 2 :
if (_role == Qt::CheckStateRole ) {
bool source = false;
// target group
if (item->isGroup() && item->childCount() > 0)
{
QList< TreeItem* > children = item->getLeafs();
case 2 :
if (_role == Qt::CheckStateRole ) {
bool source = false;
// target group
if (item->isGroup() && item->childCount() > 0)
{
QList< TreeItem* > children = item->getLeafs();
source = children[0]->source();
for (int i=0; i < children.size() ; ++i)
{
if (source != children[i]->source())
return QVariant(Qt::PartiallyChecked);
}
source = children[0]->source();
for (int i=0; i < children.size() ; ++i)
{
if (source != children[i]->source())
return QVariant(Qt::PartiallyChecked);
}
else
source = item->source();
return (source) ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
}
return QVariant();
else
source = item->source();
return (source) ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
}
return QVariant();
// Target
case 3 :
if (_role == Qt::CheckStateRole ) {
bool target = false;
// target group
if (item->isGroup() && item->childCount() > 0)
{
QList< TreeItem* > children = item->getLeafs();
case 3 :
if (_role == Qt::CheckStateRole ) {
bool target = false;
// target group
if (item->isGroup() && item->childCount() > 0)
{
QList< TreeItem* > children = item->getLeafs();
target = children[0]->target();
for (int i=0; i < children.size() ; ++i)
{
if (target != children[i]->target())
return QVariant(Qt::PartiallyChecked);
}
target = children[0]->target();
for (int i=0; i < children.size() ; ++i)
{
if (target != children[i]->target())
return QVariant(Qt::PartiallyChecked);
}
else
target = item->target();
return (target) ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
}
return QVariant();
else
target = item->target();
return (target) ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
}
return QVariant();
default:
return QVariant();
default:
return QVariant();
}
return QVariant();
......@@ -703,3 +702,8 @@ bool TreeModel::dropMimeData( const QMimeData *_data,
return true;
}
//******************************************************************************
TreeItem *TreeModel::getItem(const int _id) const
{
return rootItem_->childExists(_id);
}
......@@ -132,6 +132,9 @@ public:
/// Get the TreeItem corresponding to a given ModelIndex
TreeItem *getItem(const QModelIndex &_index) const;
/// Get the TreeItem corresponding to a given OpenFlipper ObjectID
TreeItem *getItem(const int _id) const;
/// Get the name of a TreeItem corresponding to a given ModelIndex
QString itemName(const QModelIndex &_index) const;
......
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