Commit b12050a4 authored by Dirk Wilden's avatar Dirk Wilden

added groupObjects

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@3008 383ad7c9-94d9-4d36-a494-682f7c89f535
parent f601c25b
......@@ -272,6 +272,9 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, Globa
/// Hides all objects
void hideAll();
/// Group objects together
void groupObjects(idList _objectIDs, QString _groupName = "");
/** @} */
public slots:
......
......@@ -82,4 +82,49 @@ void DataControlPlugin::showObject( int objectId ) {
object->show();
}
void DataControlPlugin::groupObjects(idList _objectIDs, QString _groupName) {
QVector< BaseObject* > objs;
for (uint i=0; i < _objectIDs.size(); i++){
BaseObject* obj;
if ( PluginFunctions::get_object(_objectIDs[i],obj) )
objs.push_back(obj);
}
if (objs.size() == 0){
emit log("No objects to group.");
return;
}
//check if all objects have the same parent
//abort if the parents differ
BaseObject* parent = (objs[0])->parent();
for ( int i = 1 ; i < objs.size() ; ++i)
if ( parent != (objs[i])->parent() ){
emit log("Cannot group Objects with different parents");
return;
}
//create new group
if (parent == 0)
parent = PluginFunctions::objectRoot();
GroupObject* groupItem = new GroupObject( "newGroup", dynamic_cast< GroupObject* >(parent));
//set groupName
if (_groupName == "")
groupItem->setName("newGroup " + QString::number(groupItem->id()));
else
groupItem->setName( _groupName );
parent->appendChild( dynamic_cast< BaseObject* >( groupItem ) );
groupItem->setParent( parent );
//append new children to group
for ( int i = 0 ; i < objs.size() ; ++i) {
(objs[i])->parent()->removeChild( objs[i] );
(objs[i])->setParent( dynamic_cast< BaseObject* >( groupItem ) );
groupItem->appendChild( objs[i] );
}
emit updated_objects(-1);
}
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