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())
{
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();
}
}
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();
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())
{
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();
}
}