Example #1
0
void GroupUngroupGraphicObjects::group()
{
   GraphicLayer* pLayer = dynamic_cast<GraphicLayer*>(getSessionItem());
   if (pLayer != NULL)
   {
      list<GraphicObject*> selectedObjects;
      pLayer->getSelectedObjects(selectedObjects);
      pLayer->deselectAllObjects();

      for (list<string>::const_iterator iter = mObjectIds.begin(); iter != mObjectIds.end(); ++iter)
      {
         string objectId = *iter;
         if (objectId.empty() == false)
         {
            string viewId;

            View* pView = pLayer->getView();
            if (pView != NULL)
            {
               viewId = pView->getId();
            }

            GraphicObject* pObject = GraphicUndoUtilities::getObject(viewId, pLayer->getId(), objectId);
            if (pObject != NULL)
            {
               pLayer->selectObject(pObject);
            }
         }
      }

      pLayer->groupSelection();

      list<GraphicObject*> newSelectedObjects;
      pLayer->getSelectedObjects(newSelectedObjects);
      VERIFYNRV(newSelectedObjects.size() == 1);

      GraphicGroup* pGroup = dynamic_cast<GraphicGroup*>(newSelectedObjects.front());
      VERIFYNRV(pGroup != NULL);

      for (list<GraphicObject*>::iterator iter = selectedObjects.begin(); iter != selectedObjects.end(); ++iter)
      {
         GraphicObject* pObject = *iter;
         if ((pObject != NULL) && (pGroup->hasObject(pObject) == false))
         {
            pLayer->selectObject(pObject);
         }
      }

      string oldGroupId = mGroupId;
      mGroupId = pGroup->getId();
      emit sessionItemChanged(oldGroupId, mGroupId);
   }
}
Example #2
0
void GroupUngroupGraphicObjects::ungroup()
{
   GraphicLayer* pLayer = dynamic_cast<GraphicLayer*>(getSessionItem());
   if ((pLayer != NULL) && (mGroupId.empty() == false))
   {
      string viewId;

      View* pView = pLayer->getView();
      if (pView != NULL)
      {
         viewId = pView->getId();
      }

      GraphicGroup* pGroup = dynamic_cast<GraphicGroup*>(GraphicUndoUtilities::getObject(viewId,
         pLayer->getId(), mGroupId));
      if (pGroup != NULL)
      {
         list<GraphicObject*> selectedObjects;
         pLayer->getSelectedObjects(selectedObjects);

         pLayer->deselectAllObjects();
         pLayer->selectObject(pGroup);
         pLayer->ungroupSelection();

         list<GraphicObject*> objects;
         pLayer->getSelectedObjects(objects);

         mObjectIds.clear();
         for (list<GraphicObject*>::iterator iter = objects.begin(); iter != objects.end(); ++iter)
         {
            GraphicObject* pObject = *iter;
            if (pObject != NULL)
            {
               string objectId = pObject->getId();
               if (objectId.empty() == false)
               {
                  mObjectIds.push_back(objectId);
               }
            }
         }

         for (list<GraphicObject*>::iterator iter = selectedObjects.begin(); iter != selectedObjects.end(); ++iter)
         {
            GraphicObject* pObject = *iter;
            if ((pObject != NULL) && (pObject != pGroup))
            {
               pLayer->selectObject(pObject);
            }
         }
      }
   }
}