]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Provide possibility to make last static object as a last history object when there...
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 12 May 2015 12:24:06 +0000 (15:24 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 12 May 2015 12:24:06 +0000 (15:24 +0300)
src/PartSet/PartSet_DocumentDataModel.cpp
src/PartSet/PartSet_PartDataModel.cpp

index 64ac554c25c40f504a760d5d02b8960bbb29411f..5ca4aef6547973b42b75ee6fd5c0081ac67e69e9 100644 (file)
@@ -243,7 +243,7 @@ QVariant PartSet_DocumentDataModel::data(const QModelIndex& theIndex, int theRol
   if ((theIndex.column() == 1) ) {
     if ((theIndex.internalId() >= PartsFolder) && (theIndex.internalId() <= PartResult)) {
       if (ModelAPI_Session::get()->activeDocument() == aRootDoc) {
-        if ((theIndex.internalId() == HistoryNode) && (!aParent.isValid())) {
+        if (!aParent.isValid()) {
           switch (theRole) {
           case Qt::DecorationRole:
             if (theIndex.row() == lastHistoryRow())
@@ -719,18 +719,26 @@ int PartSet_DocumentDataModel::lastHistoryRow() const
 {
   DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
   FeaturePtr aFeature = aRootDoc->currentFeature();
-  return historyOffset() + aRootDoc->index(aFeature);
+  if (aFeature.get())
+    return historyOffset() + aRootDoc->index(aFeature);
+  else 
+    return historyOffset() - 1;
 }
 
 void PartSet_DocumentDataModel::setLastHistoryItem(const QModelIndex& theIndex)
 {
+  SessionPtr aMgr = ModelAPI_Session::get();
+  DocumentPtr aRootDoc = aMgr->moduleDocument();
+  std::string aOpName = tr("History change").toStdString();
   if (theIndex.internalId() == HistoryNode) {
     ObjectPtr aObject = object(theIndex);
-    SessionPtr aMgr = ModelAPI_Session::get();
-    DocumentPtr aRootDoc = aMgr->moduleDocument();
-    aMgr->startOperation(tr("History change").toStdString());
+    aMgr->startOperation(aOpName);
     aRootDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject));
     aMgr->finishOperation();
+  } else {
+    aMgr->startOperation(aOpName);
+    aRootDoc->setCurrentFeature(FeaturePtr());
+    aMgr->finishOperation();
   }
 }
 
@@ -778,18 +786,22 @@ QIcon PartSet_DocumentDataModel::featureIcon(const FeaturePtr& theFeature)
 
 void PartSet_DocumentDataModel::onMouseDoubleClick(const QModelIndex& theIndex)
 {
+  if (theIndex.column() != 1)
+    return;
   QTreeView* aTreeView = dynamic_cast<QTreeView*>(sender());
   if ((theIndex.internalId() >= PartsFolder) && (theIndex.internalId() <= PartResult)) {
-    if ((theIndex.column() == 1) && (theIndex.internalId() == HistoryNode)) {
-      int aOldId = lastHistoryRow();
-      setLastHistoryItem(theIndex);
-      int aStartRow = std::min(aOldId, theIndex.row());
-      int aEndRow = std::max(aOldId, theIndex.row());
-      for (int i = aStartRow; i <= aEndRow; i++) {
-        aTreeView->update(createIndex(i, 0, HistoryNode));
-        aTreeView->update(createIndex(i, 1, HistoryNode));
-      }
+    QModelIndex aNewIndex;
+    if (theIndex.internalId() == HistoryNode) 
+      aNewIndex = theIndex;
+    int aOldId = lastHistoryRow();
+    setLastHistoryItem(theIndex);
+    int aStartRow = std::min(aOldId, theIndex.row());
+    int aEndRow = std::max(aOldId, theIndex.row());
+    for (int i = aStartRow; i <= aEndRow; i++) {
+      aTreeView->update(createIndex(i, 0, HistoryNode));
+      aTreeView->update(createIndex(i, 1, HistoryNode));
     }
+    
   } else {
     QModelIndex* aIndex = toSourceModelIndex(theIndex);
     const QAbstractItemModel* aModel = aIndex->model();
index 1398e59575c4a3378e6d08e4bb8462e4a5b47e1b..1ad039559bc62c4dbb2b65b00f71acfd027d6641 100644 (file)
@@ -261,7 +261,7 @@ QVariant PartSet_PartDataModel::data(const QModelIndex& theIndex, int theRole) c
     DocumentPtr aActiveDoc = ModelAPI_Session::get()->activeDocument();
     QModelIndex aParent = theIndex.parent();
     if (aActiveDoc == aPartDoc) {
-      if ((theIndex.internalId() == HistoryObject) && (!aParent.isValid())) {
+      if (!aParent.isValid()) {
         switch (theRole) {
         case Qt::DecorationRole:
           if (theIndex.row() == lastHistoryRow())
@@ -574,18 +574,26 @@ int PartSet_PartDataModel::lastHistoryRow() const
 {
   DocumentPtr aDoc = partDocument();
   FeaturePtr aFeature = aDoc->currentFeature();
-  return getRowsNumber() + aDoc->index(aFeature);
+  if (aFeature.get())
+    return getRowsNumber() + aDoc->index(aFeature);
+  else
+    return getRowsNumber() - 1;
 }
 
 void PartSet_PartDataModel::setLastHistoryItem(const QModelIndex& theIndex)
 {
+  SessionPtr aMgr = ModelAPI_Session::get();
+  DocumentPtr aDoc = partDocument();
+  std::string aOpName = tr("History change").toStdString();
   if (theIndex.internalId() == HistoryObject) {
-    SessionPtr aMgr = ModelAPI_Session::get();
     ObjectPtr aObject = object(theIndex);
-    DocumentPtr aDoc = partDocument();
-    aMgr->startOperation(tr("History change").toStdString());
+    aMgr->startOperation(aOpName);
     aDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject));
     aMgr->finishOperation();
+  } else {
+    aMgr->startOperation(aOpName);
+    aDoc->setCurrentFeature(FeaturePtr());
+    aMgr->finishOperation();
   }
 }