Salome HOME
Provide possibility to make last static object as a last history object when there...
[modules/shaper.git] / src / PartSet / PartSet_PartDataModel.cpp
index ec4dabffaccfbcc66badffccf4f7229e11279f2f..1ad039559bc62c4dbb2b65b00f71acfd027d6641 100644 (file)
@@ -246,7 +246,7 @@ QModelIndex PartSet_TopDataModel::objectIndex(const ObjectPtr& theObject) const
 //******************************************************************
 //******************************************************************
 PartSet_PartDataModel::PartSet_PartDataModel(QObject* theParent)
-    : PartSet_PartModel(theParent), myHistoryBackOffset(0)
+    : PartSet_PartModel(theParent)
 {
 }
 
@@ -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())
@@ -572,13 +572,28 @@ int PartSet_PartDataModel::getRowsNumber() const
 
 int PartSet_PartDataModel::lastHistoryRow() const
 {
-  return rowCount() - 1 - myHistoryBackOffset;
+  DocumentPtr aDoc = partDocument();
+  FeaturePtr aFeature = aDoc->currentFeature();
+  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) {
-    myHistoryBackOffset = rowCount() - 1 - theIndex.row();
+    ObjectPtr aObject = object(theIndex);
+    aMgr->startOperation(aOpName);
+    aDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject));
+    aMgr->finishOperation();
+  } else {
+    aMgr->startOperation(aOpName);
+    aDoc->setCurrentFeature(FeaturePtr());
+    aMgr->finishOperation();
   }
 }