Commit b07373b3 authored by Matthias Möller's avatar Matthias Möller

- fix treeview after layout of the tree changed (e.g. ungrouping objects)

- removed redundant functions
- "ungroup" scriptfunction ungroups again

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16229 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 8666ae66
......@@ -157,7 +157,8 @@ void DataControlPlugin::pluginsInitialized() {
PluginFunctions::setViewObjectMarker (&objectMarker);
connect(tool_->lightSources, SIGNAL(stateChanged(int)), this, SLOT(slotShowLightSources(int)));
slotShowLightSources(tool_->lightSources->checkState());
//update light visibility, if layout was changed
connect(model_, SIGNAL(layoutChanged ()), this, SLOT(slotShowLightSources()) );
}
......@@ -498,15 +499,23 @@ void DataControlPlugin::slotMoveBaseObject(int _id, int _newParentId){
void DataControlPlugin::slotShowLightSources( int _state ) {
int rows = model_->rowCount();
for(int i = 0; i < rows; ++i) {
TreeItem* item = model_->getItem(model_->index(i,0));
if(item->dataType() == DATA_LIGHT) {
view_->setRowHidden(i, model_->parent(model_->index(i,0)), !(_state == Qt::Checked));
view_->setRowHidden(i, model_->parent(model_->index(i,0)), !(_state == Qt::Checked));
}else{
//always show, if it is not a light
view_->setRowHidden(i, model_->parent(model_->index(i,0)), false);
}
}
}
void DataControlPlugin::slotShowLightSources()
{
slotShowLightSources( tool_->lightSources->checkState() );
}
//******************************************************************************
/** \brief Load Groups from ini file
......
......@@ -235,6 +235,7 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
/// Hide/Show all light sources if checkbox has been checked
void slotShowLightSources( int _state );
void slotShowLightSources();
private :
/// Index where a popup has been opened
......
......@@ -356,15 +356,28 @@ int DataControlPlugin::groupObjects(IdList _objectIDs, QString _groupName) {
}
bool DataControlPlugin::unGroupObject(int _id) {
BaseObject* obj = 0;
BaseObject* group = 0;
PluginFunctions::getObject(_id,obj);
PluginFunctions::getObject(_id,group);
if ( obj ) {
obj->setParent( PluginFunctions::objectRoot() );
if ( group && group->isGroup())
{
//iterate over children
for (int i=group->childCount()-1; i >= 0; --i){
BaseObject* child = group->child(i);
// then change the parent
child->setParent(group->parent());
}
//delete the group
emit deleteObject( group->id() );
return true;
} else {
emit log( LOGERR, tr( "Unable to get Object with id %1 for ungrouping").arg(_id) );
if (group)
emit log( LOGERR, tr("Cannot Ungroup. Object with id %1 is not a group").arg(_id));
else
emit log( LOGERR, tr( "Unable to get Object with id %1 for ungrouping").arg(_id) );
return false;
}
......
......@@ -113,20 +113,7 @@ void DataControlPlugin::slotUngroup ( ) {
//get the object
int id = model_->itemId( indexList[0] );
BaseObject* group = 0;
if ( id > 0 && PluginFunctions::getObject(id, group ) ){
//iterate over children
for (int i=group->childCount()-1; i >= 0; i--){
BaseObject* child = group->child(i);
// then change the parent
child->setParent(group->parent());
}
//delete the group
emit deleteObject( group->id() );
}
unGroupObject(id);
}
......@@ -172,57 +159,14 @@ void DataControlPlugin::slotGroup() {
// Get all selected rows
QModelIndexList indexList = selection->selectedRows ( 0 );
//check if all objects have the same parent
//abort if the parents differ
int id = model_->itemId( indexList[0] );
BaseObject* obj0 = 0;
if (id == -1 || !PluginFunctions::getObject(id, obj0) ){
std::cerr << "Group Objects: Unable to get object" << std::endl;
return;
}
BaseObject* parent = obj0->parent();
for ( int i = 1 ; i < indexList.size() ; ++i) {
//get an object
id = model_->itemId( indexList[i] );
BaseObject* item = 0;
PluginFunctions::getObject(id, item );
//compare parent
if ( parent != item->parent() ){
emit log(tr("Cannot group Objects with different parents"));
return;
}
}
//create new group
if (parent == 0)
parent = PluginFunctions::objectRoot();
GroupObject* groupItem = new GroupObject( tr("newGroup"), dynamic_cast< GroupObject* >(parent));
groupItem->setName(tr("newGroup ") + QString::number(groupItem->id()));
groupItem->setParent( parent );
emit emptyObjectAdded( groupItem->id() );
//append new children to group
for ( int i = 0 ; i < indexList.size() ; ++i) {
//get an object
id = model_->itemId( indexList[i] );
BaseObject* item = 0;
PluginFunctions::getObject(id, item );
//and move it into the group
item->setParent( dynamic_cast< BaseObject* >( groupItem ) );
}
//get object ids
IdList ids;
for (int i = 0; i < indexList.size(); ++i)
ids.push_back( model_->itemId(indexList[i]) );
//group all objects
groupObjects(ids);
}
......
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