From: vsv Date: Tue, 12 May 2015 12:24:06 +0000 (+0300) Subject: Provide possibility to make last static object as a last history object when there... X-Git-Tag: V_1.2.0~159 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e38bf7c796c7007b365ca3aa6c927aa9e10c18f2;p=modules%2Fshaper.git Provide possibility to make last static object as a last history object when there is no features created --- diff --git a/src/PartSet/PartSet_DocumentDataModel.cpp b/src/PartSet/PartSet_DocumentDataModel.cpp index 64ac554c2..5ca4aef65 100644 --- a/src/PartSet/PartSet_DocumentDataModel.cpp +++ b/src/PartSet/PartSet_DocumentDataModel.cpp @@ -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(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(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(); diff --git a/src/PartSet/PartSet_PartDataModel.cpp b/src/PartSet/PartSet_PartDataModel.cpp index 1398e5957..1ad039559 100644 --- a/src/PartSet/PartSet_PartDataModel.cpp +++ b/src/PartSet/PartSet_PartDataModel.cpp @@ -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(aObject)); aMgr->finishOperation(); + } else { + aMgr->startOperation(aOpName); + aDoc->setCurrentFeature(FeaturePtr()); + aMgr->finishOperation(); } }