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

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 ...@@ -329,8 +329,11 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
/// Hides all objects /// Hides all objects
void hideAll(); void hideAll();
/// Group objects together /** Group objects together
void groupObjects(idList _objectIDs, QString _groupName = ""); *
* @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 ) { ...@@ -272,18 +272,20 @@ void DataControlPlugin::showObject( int objectId ) {
* @param _objectIDs list of object ids * @param _objectIDs list of object ids
* @param _groupName the name of the new group * @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; QVector< BaseObject* > objs;
// Try to get all objects given in list
for (uint i=0; i < _objectIDs.size(); i++){ for (uint i=0; i < _objectIDs.size(); i++){
BaseObject* obj; BaseObject* obj;
if ( PluginFunctions::getObject(_objectIDs[i],obj) ) if ( PluginFunctions::getObject(_objectIDs[i],obj) )
objs.push_back(obj); objs.push_back(obj);
} }
// If all of them fail, stop here.
if (objs.size() == 0){ if (objs.size() == 0){
emit log(tr("No objects to group.")); emit log(tr("No objects to group."));
return; return -1;
} }
//check if all objects have the same parent //check if all objects have the same parent
...@@ -292,11 +294,12 @@ void DataControlPlugin::groupObjects(idList _objectIDs, QString _groupName) { ...@@ -292,11 +294,12 @@ void DataControlPlugin::groupObjects(idList _objectIDs, QString _groupName) {
bool target = (objs[0])->target(); bool target = (objs[0])->target();
bool source = (objs[0])->source(); bool source = (objs[0])->source();
// Check if all objects have the same parent
BaseObject* parent = (objs[0])->parent(); BaseObject* parent = (objs[0])->parent();
for ( int i = 1 ; i < objs.size() ; ++i){ for ( int i = 1 ; i < objs.size() ; ++i){
if ( parent != (objs[i])->parent() ){ if ( parent != (objs[i])->parent() ){
emit log(tr("Cannot group Objects with different parents")); emit log(tr("Cannot group Objects with different parents"));
return; return -1;
} }
visible |= (objs[i])->visible(); visible |= (objs[i])->visible();
...@@ -315,9 +318,8 @@ void DataControlPlugin::groupObjects(idList _objectIDs, QString _groupName) { ...@@ -315,9 +318,8 @@ void DataControlPlugin::groupObjects(idList _objectIDs, QString _groupName) {
groupItem->setName(tr("newGroup ") + QString::number(groupItem->id())); groupItem->setName(tr("newGroup ") + QString::number(groupItem->id()));
else else
groupItem->setName( _groupName ); 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() ); emit emptyObjectAdded( groupItem->id() );
//append new children to group //append new children to group
...@@ -336,6 +338,8 @@ void DataControlPlugin::groupObjects(idList _objectIDs, QString _groupName) { ...@@ -336,6 +338,8 @@ void DataControlPlugin::groupObjects(idList _objectIDs, QString _groupName) {
groupItem->source(source); groupItem->source(source);
emit objectPropertiesChanged( groupItem->id() ); 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