Salome HOME
Rebuild data tree in case of inconsistence with data model. Correct warning with...
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 20 Apr 2016 14:42:12 +0000 (17:42 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 20 Apr 2016 14:42:26 +0000 (17:42 +0300)
src/XGUI/XGUI_DataModel.cpp
src/XGUI/XGUI_DataModel.h
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_ObjectsBrowser.h
src/XGUI/XGUI_Tools.cpp
src/XGUI/XGUI_Workshop.cpp

index 3e7b0e7967c38f7e2e2127e5d4dfd97429daeda1..6bcee6721de6fa76695059449142564676891b4f 100644 (file)
@@ -150,11 +150,8 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
               }
             }
           }
-        } 
-#ifdef _DEBUG
-        else
-          Events_Error::send("Problem with Data Model definition of sub-document");
-#endif
+        } else
+          rebuildDataTree();
       }
     }
     // Deleted object event ***********************
@@ -233,9 +230,14 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
     std::string aObjType;
     for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
       ObjectPtr aObject = (*aIt);
-      QModelIndex aIndex = objectIndex(aObject);
-      if (aIndex.isValid())
-        emit dataChanged(aIndex, aIndex);
+      if (aObject->data()->isValid()) {
+        QModelIndex aIndex = objectIndex(aObject);
+        if (aIndex.isValid())
+          emit dataChanged(aIndex, aIndex);
+      } else {
+        rebuildDataTree();
+        break;
+      }
     }
   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_ORDER_UPDATED)) {
     std::shared_ptr<ModelAPI_OrderUpdatedMessage> aUpdMsg =
@@ -272,10 +274,6 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
       else 
         // We have got a new document
         rebuildDataTree();
-//#ifdef _DEBUG
-//      else
-//        Events_Error::send("Problem with Data Model definition of sub-document");
-//#endif
     }
   } 
 }
@@ -291,6 +289,7 @@ void XGUI_DataModel::rebuildDataTree()
 {
   beginResetModel();
   endResetModel();
+  emit treeRebuilt();
 }
 
 //******************************************************
index 47b0f7b6b487355cf4bcec3fc22f0d8b17d13bae..b43edd8a86739fbe6125bed18003505a505dd6a7 100644 (file)
@@ -123,6 +123,9 @@ public:
   /// Initialises XML data model reader. It must be initialised before DataModel using.
   void setXMLReader(Config_DataModelReader* theReader) { myXMLReader = theReader; }
 
+signals:
+  void treeRebuilt();
+
 private:
   /// Find a root index which contains objects of the given document
   /// \param theDoc the document object
index 9ff3f6e00a36ffb2759457165642c6e76e7b6401..be2ff3db825f7a27fa3a3e0a70f1d9a8421c75fd 100644 (file)
@@ -361,6 +361,8 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
   aLabelWgt->setPalette(aPalet);
 
   myDocModel = new XGUI_DataModel(this);
+  connect(myDocModel, SIGNAL(modelAboutToBeReset()), SLOT(onBeforeReset()));
+  connect(myDocModel, SIGNAL(treeRebuilt()), SLOT(onAfterModelReset()));
 
   connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
           SLOT(onContextMenuRequested(QContextMenuEvent*)));
@@ -470,11 +472,7 @@ QModelIndexList XGUI_ObjectsBrowser::expandedItems(const QModelIndex& theParent)
 //***************************************************
 void XGUI_ObjectsBrowser::rebuildDataTree()
 {
-  QModelIndexList aIndexList = expandedItems();
   myDocModel->rebuildDataTree();
-  foreach(QModelIndex aIndex, aIndexList) {
-    myTreeView->setExpanded(aIndex, true);
-  }
   update();
 }
 
@@ -523,4 +521,16 @@ QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes)
     }
   }
   return aList;
-}
\ No newline at end of file
+}
+
+void XGUI_ObjectsBrowser::onBeforeReset()
+{
+  myExpandedItems = expandedItems();
+}
+
+void XGUI_ObjectsBrowser::onAfterModelReset()
+{
+  foreach(QModelIndex aIndex, myExpandedItems) {
+    myTreeView->setExpanded(aIndex, true);
+  }
+}
index c71206dcc0e884810ae1c65f407dcd8c068eac72..eff2ffc1091a402077579384272a907d80cba1eb 100644 (file)
@@ -209,6 +209,10 @@ signals:
   //! Called when selection in Data Tree is changed
   void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
 
+  void onBeforeReset();
+
+  void onAfterModelReset();
+
  private:
   QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
 
@@ -216,6 +220,9 @@ signals:
   XGUI_DataModel* myDocModel;
   XGUI_ActiveDocLbl* myActiveDocLbl;
   XGUI_DataTree* myTreeView;
+
+  /// A field to store expanded items before model reset
+  QModelIndexList myExpandedItems;
 };
 
 #endif
index 6d4009a4a9d72ad11fdf0a98b3555a49bdf212f9..e9000eff1706022682256dc45322a2e3845c244b 100644 (file)
@@ -66,11 +66,14 @@ QString unionOfObjectNames(const QObjectPtrList& theObjects, const QString& theS
 {
   QStringList aObjectNames;
   foreach (ObjectPtr aObj, theObjects) {
-    if (!aObj->data()->isValid())
-      continue;
-    aObjectNames << QString::fromStdString(aObj->data()->name());
+    if (aObj->data()->isValid())
+      aObjectNames << QString::fromStdString(aObj->data()->name());
   }
-  return aObjectNames.join(", ");
+  if (aObjectNames.count() == 0)
+    return QString();
+  if (aObjectNames.count() == 1)
+    return aObjectNames.first();
+  return aObjectNames.join(theSeparator);
 }
 
 //******************************************************************
index fd0fc2d81e600fad8906d67e2b7291acb33ea1bf..45240ddb7ccddbdba16d013894a4c3c0af4edb5a 100755 (executable)
@@ -1290,8 +1290,8 @@ void XGUI_Workshop::deleteObjects()
   if (ModuleBase_Tools::isDeleteFeatureWithReferences(anObjects, aDirectRefFeatures, 
       aIndirectRefFeatures, desktop(), doDeleteReferences)) {
     // start operation
-    QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
-    aDescription += " " + aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
+    QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
+    aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
     ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
     operationMgr()->startOperation(anOpAction);