Salome HOME
Merge branch 'master' of newgeom:newgeom.git into BR_PORTING_CENTOS_6_3
[modules/shaper.git] / src / XGUI / XGUI_PartDataModel.cpp
index 1e79322ca2afcd871885938b10fc4c86051268dc..40f4671db277b9c204dc6da0ad184043f3f83b8f 100644 (file)
@@ -30,14 +30,16 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
     case ParamObject:
       {
         std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row());
-        return aFeature->data()->getName().c_str();
+        if (aFeature)
+          return aFeature->data()->getName().c_str();
       } 
     case ConstructFolder:
         return tr("Constructions");
     case ConstructObject:
       {
         std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
-        return aFeature->data()->getName().c_str();
+        if (aFeature)
+          return aFeature->data()->getName().c_str();
       }
     }
     break;
@@ -139,6 +141,27 @@ FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const
 }
 
 
+QModelIndex XGUI_TopDataModel::findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
+{
+  QString aGroup(theFeature->getGroup().c_str());
+
+  if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
+    return createIndex(0, 0, (quintptr) ParamsFolder);
+  if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
+    return createIndex(1, 0, (quintptr) ConstructFolder);
+  return QModelIndex();
+}
+
+QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const
+{
+  if (theGroup.compare(PARAMETERS_GROUP) == 0)
+    return createIndex(0, 0, (quintptr) ParamsFolder);
+  if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+    return createIndex(1, 0, (quintptr) ConstructFolder);
+  return QModelIndex();
+}
+
+
 //******************************************************************
 //******************************************************************
 //******************************************************************
@@ -161,7 +184,8 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
     case MyRoot:
       {
         std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
-        return aFeature->data()->getName().c_str();
+        if (aFeature)
+          return aFeature->data()->getName().c_str();
       }
     case ParamsFolder:
       return tr("Parameters");
@@ -171,13 +195,15 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
       {
         std::shared_ptr<ModelAPI_Feature> aFeature = 
           featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
-        return aFeature->data()->getName().c_str();
+        if (aFeature)
+          return aFeature->data()->getName().c_str();
       }
     case ConstructObject:
       {
         std::shared_ptr<ModelAPI_Feature> aFeature = 
           featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
-        return aFeature->data()->getName().c_str();
+        if (aFeature)
+          return aFeature->data()->getName().c_str();
       }
     }
     break;
@@ -294,3 +320,29 @@ FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const
   }
   return FeaturePtr();
 }
+
+bool XGUI_PartDataModel::hasDocument(const std::shared_ptr<ModelAPI_Document>& theDoc) const
+{
+  return (featureDocument() == theDoc);
+}
+
+
+QModelIndex XGUI_PartDataModel::findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
+{
+  QString aGroup(theFeature->getGroup().c_str());
+
+  if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
+    return createIndex(0, 0, (quintptr) ParamsFolder);
+  if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
+    return createIndex(1, 0, (quintptr) ConstructFolder);
+  return QModelIndex();
+}
+
+QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
+{
+  if (theGroup.compare(PARAMETERS_GROUP) == 0)
+    return createIndex(0, 0, (quintptr) ParamsFolder);
+  if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+    return createIndex(1, 0, (quintptr) ConstructFolder);
+  return QModelIndex();
+}