Commit fb6ea3b5 authored by Jan Möbius's avatar Jan Möbius

Let grouping return the id of the new group

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@7868 383ad7c9-94d9-4d36-a494-682f7c89f535
parent bfea5dcb
......@@ -329,8 +329,11 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
/// Hides all objects
void hideAll();
/// Group objects together
void groupObjects(idList _objectIDs, QString _groupName = "");
/** Group objects together
*
* @return object id of new group or -1 if failed
*/
int groupObjects(idList _objectIDs, QString _groupName = "");
/** @} */
......
......@@ -272,18 +272,20 @@ void DataControlPlugin::showObject( int objectId ) {
* @param _objectIDs list of object ids
* @param _groupName the name of the new group
*/
void DataControlPlugin::groupObjects(idList _objectIDs, QString _groupName) {
int DataControlPlugin::groupObjects(idList _objectIDs, QString _groupName) {
QVector< BaseObject* > objs;
// Try to get all objects given in list
for (uint i=0; i < _objectIDs.size(); i++){
BaseObject* obj;
if ( PluginFunctions::getObject(_objectIDs[i],obj) )
objs.push_back(obj);
}
// If all of them fail, stop here.
if (objs.size() == 0){
emit log(tr("No objects to group."));
return;
return -1;
}
//check if all objects have the same parent
......@@ -292,11 +294,12 @@ void DataControlPlugin::groupObjects(idList _objectIDs, QString _groupName) {
bool target = (objs[0])->target();
bool source = (objs[0])->source();
// Check if all objects have the same parent
BaseObject* parent = (objs[0])->parent();
for ( int i = 1 ; i < objs.size() ; ++i){
if ( parent != (objs[i])->parent() ){
emit log(tr("Cannot group Objects with different parents"));
return;
return -1;
}
visible |= (objs[i])->visible();
......@@ -315,9 +318,8 @@ void DataControlPlugin::groupObjects(idList _objectIDs, QString _groupName) {
groupItem->setName(tr("newGroup ") + QString::number(groupItem->id()));
else
groupItem->setName( _groupName );
parent->appendChild( dynamic_cast< BaseObject* >( groupItem ) );
groupItem->setParent( parent );
// Tell core that a new group has been added
emit emptyObjectAdded( groupItem->id() );
//append new children to group
......@@ -336,6 +338,8 @@ void DataControlPlugin::groupObjects(idList _objectIDs, QString _groupName) {
groupItem->source(source);
emit objectPropertiesChanged( groupItem->id() );
return groupItem->id();
}
......
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