Commit b07406f8 authored by Dirk Wilden's avatar Dirk Wilden

source target for groupObjects fixed

fixed treeModel update for scripting functions

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5055 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4ad9b0dc
......@@ -147,6 +147,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();
BaseObject* parent = (model_->getItem( indexList[0]))->parent();
for ( int i = 1 ; i < indexList.size() ; ++i) {
BaseObject* item = model_->getItem( indexList[i] );
......@@ -154,6 +157,10 @@ void DataControlPlugin::slotGroup ( ) {
emit log("Cannot group Objects with different parents");
return;
}
//remember if at least on child was target/source
target |= (model_->getItem( indexList[i]))->target();
source |= (model_->getItem( indexList[i]))->source();
}
//create new group
......@@ -172,6 +179,18 @@ void DataControlPlugin::slotGroup ( ) {
groupItem->appendChild(item);
}
//update target/source state
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 updatedObject(-1);
}
......
......@@ -155,7 +155,7 @@ QVariant TreeModel::data(const QModelIndex &index, int role) const
// target group
if (item->isGroup()){
QList< BaseObject* > children = item->getLeafs();
bool initRound = true;
for (int i=0; i < children.size(); i++){
if (initRound){
......@@ -432,6 +432,51 @@ BaseObject *TreeModel::getItem(const QModelIndex &index) const
return rootItem_;
}
/// Return index of given item
QModelIndex TreeModel::getModelIndex(BaseObject* _object, int _column ){
for (int i=0; i < persistentIndexList().count(); i++){
BaseObject* tmp = static_cast<BaseObject*>(persistentIndexList().at(i).internalPointer());
if ( tmp == _object && persistentIndexList().at(i).column() == _column )
return persistentIndexList().at(i);
}
return QModelIndex();
}
void TreeModel::updateSourceSelection(BaseObject* _obj ){
if ( isRoot(_obj) || (!_obj->isGroup()) )
return;
QList< BaseObject* > children = _obj->getLeafs();
bool source = false;
for (int i=0; i < children.size(); i++)
source |= children[i]->source();
_obj->source( source );
updateSourceSelection( _obj->parent() );
}
void TreeModel::updateTargetSelection(BaseObject* _obj ){
if ( isRoot(_obj) || (!_obj->isGroup()) )
return;
QList< BaseObject* > children = _obj->getLeafs();
bool target = false;
for (int i=0; i < children.size(); i++)
target |= children[i]->target();
_obj->target( target );
updateTargetSelection( _obj->parent() );
}
/// Set Data at 'index' to 'value'
bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*role*/)
{
......@@ -482,6 +527,8 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*r
// source
case 2 :
if ( value.toInt() == Qt::Unchecked ) {
item->source(false);
QList< BaseObject* > children = item->getLeafs();
......@@ -494,6 +541,8 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*r
}
if ( value.toInt() == Qt::Checked ) {
item->source(true);
QList< BaseObject* > children = item->getLeafs();
......@@ -510,6 +559,8 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*r
case 3 :
if ( value.toInt() == Qt::Unchecked ) {
item->target(false);
QList< BaseObject* > children = item->getLeafs();
childCount = children.size();
......@@ -521,7 +572,9 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*r
}
if ( value.toInt() == Qt::Checked ) {
item->target(true);
QList< BaseObject* > children = item->getLeafs();
childCount = children.size();
......@@ -581,7 +634,8 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*r
break;
// source
case 2 :
case 2 :
if ( value.toInt() == Qt::Unchecked ) {
item->source(false);
}
......@@ -590,6 +644,8 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*r
item->source(true);
}
updateSourceSelection( item->parent() );
break;
//target
......@@ -601,6 +657,8 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*r
if ( value.toInt() == Qt::Checked ) {
item->target(true);
}
updateTargetSelection( item->parent() );
break;
......
......@@ -78,6 +78,8 @@ public:
bool setData(const QModelIndex &index, const QVariant &value , int role);
BaseObject *getItem(const QModelIndex &index) const;
QModelIndex getModelIndex(BaseObject* _object, int _column );
/// Check if the given item is the root item
bool isRoot(BaseObject * _item);
......@@ -104,6 +106,11 @@ 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 );
};
///@todo : Save group names on exit
......
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