Salome HOME
1. Compound selection choice is provided for sketch selection in Extrusion operation...
[modules/shaper.git] / src / PartSet / PartSet_DocumentDataModel.cpp
index cd12d6ed9871a9d295f7dc08d6ed28fa2b70df21..26668d6e782e0b54882a7dce5ff27ce2c9ca30b0 100644 (file)
@@ -136,6 +136,9 @@ void PartSet_DocumentDataModel::processEvent(const std::shared_ptr<Events_Messag
             removeSubModel(aDelPartModel);
             removeRow(aStart, partFolderNode(0));
           }
+        } if (aGroup == ModelAPI_Feature::group()) { // Update History node
+          int aRow = historyOffset() + aRootDoc->size(ModelAPI_Feature::group());
+          removeRow(aRow);
         } else {  // Update top groups (other except parts
           QModelIndex aIndex = myModel->findGroup(aGroup);
           int aStart = myModel->rowCount(aIndex);
@@ -152,9 +155,15 @@ void PartSet_DocumentDataModel::processEvent(const std::shared_ptr<Events_Messag
         }
         if (aPartModel) {
           QModelIndex aIndex = aPartModel->findGroup(aGroup);
-          int aStart = aPartModel->rowCount(aIndex);
-          aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex));
-          removeRow(aStart, aIndex);
+          if (aIndex.isValid()) {
+            int aStart = aPartModel->rowCount(aIndex);
+            aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex));
+            removeRow(aStart, aIndex);
+          } else {
+            int aRow = aPartModel->rowCount();
+            aIndex = createIndex(aPartModel->position() + historyOffset(), 0, HistoryNode);
+            removeRow(aRow, aIndex);
+          }
         }
       }
     }
@@ -333,7 +342,10 @@ QVariant PartSet_DocumentDataModel::headerData(int theSection, Qt::Orientation t
 
 int PartSet_DocumentDataModel::rowCount(const QModelIndex& theParent) const
 {
-  DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+  SessionPtr aSession = ModelAPI_Session::get();
+  if (!aSession->hasModuleDocument())
+    return 0;
+  DocumentPtr aRootDoc = aSession->moduleDocument();
   if (!theParent.isValid()) {
     // Size of external models
     int aVal = historyOffset();
@@ -480,6 +492,7 @@ void PartSet_DocumentDataModel::clearSubModels()
   foreach (PartSet_PartModel* aPart, myPartModels) 
     delete aPart;
   myPartModels.clear();
+  myActivePartModel = 0;
 }
 
 ObjectPtr PartSet_DocumentDataModel::object(const QModelIndex& theIndex) const
@@ -543,8 +556,10 @@ void PartSet_DocumentDataModel::removeSubModel(PartSet_PartModel* theModel)
     myIndexes.removeAt(aId);
     aToRemove.removeLast();
   }
-  delete theModel;
+  if (theModel == myActivePartModel)
+    myActivePartModel = 0;
   myPartModels.removeAll(theModel);
+  delete theModel;
 }
 
 
@@ -627,7 +642,7 @@ Qt::ItemFlags PartSet_DocumentDataModel::flags(const QModelIndex& theIndex) cons
 {
   if ((theIndex.internalId() >= PartsFolder) && (theIndex.internalId() <= PartResult)) {
     Qt::ItemFlags aFlags = Qt::ItemIsSelectable;
-    if (object(theIndex)) {
+    if (object(theIndex).get()) {
       aFlags |= Qt::ItemIsEditable;
     }
     // Disable items which are below of last history row
@@ -641,7 +656,12 @@ Qt::ItemFlags PartSet_DocumentDataModel::flags(const QModelIndex& theIndex) cons
   } else {
     QModelIndex* aIndex = toSourceModelIndex(theIndex);
     const QAbstractItemModel* aModel = aIndex->model();
-    return aModel->flags(*aIndex);
+    Qt::ItemFlags aFlags = aModel->flags(*aIndex);
+    if (aModel == myModel) {
+      if (myModel->object(*aIndex).get())
+        aFlags |= Qt::ItemIsEditable;
+    }
+    return aFlags;
   }
 }