From: vsv Date: Wed, 29 Jul 2015 16:28:58 +0000 (+0300) Subject: Process history pointer X-Git-Tag: V_1.4.0_beta4~443 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=21e765709ef191519dc14463ce5ce90c2d62cc04;p=modules%2Fshaper.git Process history pointer --- diff --git a/src/ModuleBase/ModuleBase_IDocumentDataModel.h b/src/ModuleBase/ModuleBase_IDocumentDataModel.h index a5e3d95c8..aecb0152f 100644 --- a/src/ModuleBase/ModuleBase_IDocumentDataModel.h +++ b/src/ModuleBase/ModuleBase_IDocumentDataModel.h @@ -31,6 +31,10 @@ public: //! Rebuild data tree virtual void rebuildDataTree(); + + /// Returns last history object index + virtual QModelIndex lastHistoryIndex() const { return QModelIndex(); } + }; #endif \ No newline at end of file diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 2a30656d4..873f394a1 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -115,9 +116,11 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess insertRow(aRow + aNbSubFolders, aDocRoot); } else { // List of objects under a folder - int aFolderId = myXMLReader.subFolderId(aObjType); - if (aFolderId != -1) { - insertRow(aRow, createIndex(aFolderId, 0, aDoc.get())); + if (aRow != -1) { + int aFolderId = myXMLReader.subFolderId(aObjType); + if (aFolderId != -1) { + insertRow(aRow, createIndex(aFolderId, 0, aDoc.get())); + } } } } @@ -253,14 +256,11 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const int aNbFolders = foldersCount(); int theIndexRow = theIndex.row(); - if ((theIndex.column() == 1) ) { - //if (theIndexRow >= aNbFolders) { - // if (theRole == Qt::DecorationRole) { - // return QIcon(":pictures/arrow.png"); - // } - //} + if ((theRole == Qt::DecorationRole) && (theIndex == lastHistoryIndex())) + return QIcon(":pictures/arrow.png"); + + if (theIndex.column() == 1) return QVariant(); - } int aParentId = theIndex.internalId(); if (aParentId == -1) { // root folders @@ -271,21 +271,23 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const case Qt::DecorationRole: return QIcon(myXMLReader.rootFolderIcon(theIndexRow).c_str()); case Qt::ForegroundRole: - if (aRootDoc->isActive()) + if (aSession->activeDocument() == aRootDoc) return QBrush(ACTIVE_COLOR); else return QBrush(PASSIVE_COLOR); } - } else { + } else { // an object or sub-document ModelAPI_Document* aSubDoc = getSubDocument(theIndex.internalPointer()); if (theRole == Qt::ForegroundRole) { bool aIsActive = false; if (aSubDoc) - aIsActive = aSubDoc->isActive(); + aIsActive = (aSession->activeDocument().get() == aSubDoc); else { ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer(); - aIsActive = aObj->document()->isActive(); + if (aObj->isDisabled()) + return QBrush(Qt::lightGray); + aIsActive = (aSession->activeDocument() == aObj->document()); } if (aIsActive) return QBrush(ACTIVE_COLOR); @@ -550,10 +552,20 @@ bool XGUI_DataModel::removeRows(int theRow, int theCount, const QModelIndex& the //****************************************************** Qt::ItemFlags XGUI_DataModel::flags(const QModelIndex& theIndex) const { - Qt::ItemFlags aFlags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; - if (theIndex.internalId() > -1) { - aFlags |= Qt::ItemIsEditable; + Qt::ItemFlags aFlags = Qt::ItemIsSelectable; + + ModelAPI_Object* aObj = 0; + if (theIndex.internalId() != -1) { + if (!getSubDocument(theIndex.internalPointer())) + aObj = (ModelAPI_Object*) theIndex.internalPointer(); } + if (aObj) { + aFlags |= Qt::ItemIsEditable; + + if (!aObj->isDisabled()) + aFlags |= Qt::ItemIsEnabled; + } else + aFlags |= Qt::ItemIsEnabled; return aFlags; } @@ -649,4 +661,21 @@ QStringList XGUI_DataModel::listOfShowNotEmptyFolders(bool fromRoot) const } } return aResult; +} + +//****************************************************** +QModelIndex XGUI_DataModel::lastHistoryIndex() const +{ + SessionPtr aSession = ModelAPI_Session::get(); + DocumentPtr aCurDoc = aSession->activeDocument(); + FeaturePtr aFeature = aCurDoc->currentFeature(true); + if (aFeature.get()) { + QModelIndex aInd = objectIndex(aFeature); + return createIndex(aInd.row(), 1, aInd.internalPointer()); + } else { + if (aCurDoc == aSession->moduleDocument()) + return createIndex(foldersCount() - 1, 1, -1); + else + return createIndex(foldersCount(aCurDoc.get()) - 1, 1, aCurDoc.get()); + } } \ No newline at end of file diff --git a/src/XGUI/XGUI_DataModel.h b/src/XGUI/XGUI_DataModel.h index eb47d9ffb..b1c3935c2 100644 --- a/src/XGUI/XGUI_DataModel.h +++ b/src/XGUI/XGUI_DataModel.h @@ -110,6 +110,9 @@ public: /// \param theDoc a document QModelIndex documentRootIndex(DocumentPtr theDoc) const; + /// Returns last history object index + virtual QModelIndex lastHistoryIndex() const; + private: /// Find a root index which contains objects of the given document /// \param theDoc the document object diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 641de07f7..acdd5e5fb 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -68,6 +68,11 @@ XGUI_DataTree::XGUI_DataTree(QWidget* theParent) setSelectionMode(QAbstractItemView::ExtendedSelection); setItemDelegateForColumn(0, new XGUI_TreeViewItemDelegate(this)); + +#ifndef ModuleDataModel + connect(this, SIGNAL(doubleClicked(const QModelIndex&)), + SLOT(onDoubleClick(const QModelIndex&))); +#endif } XGUI_DataTree::~XGUI_DataTree() @@ -121,6 +126,50 @@ void XGUI_DataTree::resizeEvent(QResizeEvent* theEvent) } } +void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex) +{ + if (theIndex.column() != 1) + return; + ModuleBase_IDocumentDataModel* aModel = dataModel(); + if (aModel->flags(theIndex) == 0) + return; + ObjectPtr aObj = aModel->object(theIndex); + + SessionPtr aMgr = ModelAPI_Session::get(); + DocumentPtr aDoc = aMgr->activeDocument(); + + QModelIndex aOldIndex = aModel->lastHistoryIndex(); + + std::string aOpName = tr("History change").toStdString(); + if (aObj.get()) { + if (aObj->document() != aDoc) + return; + aMgr->startOperation(aOpName); + aDoc->setCurrentFeature(std::dynamic_pointer_cast(aObj), true); + aMgr->finishOperation(); + } else { + // Ignore clicks on folders outside current document + if ((theIndex.internalId() == -1) && (aDoc != aMgr->moduleDocument())) + // Clicked folder under root but active document is another + return; + if ((theIndex.internalId() != -1) && (aDoc.get() != theIndex.internalPointer())) + // Cliced not on active document folder + return; + + aMgr->startOperation(aOpName); + aDoc->setCurrentFeature(FeaturePtr(), true); + aMgr->finishOperation(); + } + QModelIndex aNewIndex = aModel->lastHistoryIndex(); + QModelIndex aParent = theIndex.parent(); + int aStartRow = std::min(aOldIndex.row(), aNewIndex.row()); + int aEndRow = std::max(aOldIndex.row(), aNewIndex.row()); + for (int i = aStartRow; i <= aEndRow; i++) { + update(aModel->index(i, 0, aParent)); + } + update(aOldIndex); + update(aNewIndex); +} //******************************************************************** //******************************************************************** diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index de53db913..5352ffe58 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -47,6 +47,8 @@ public slots: /// Commit modified data (used for renaming of objects) virtual void commitData(QWidget* theEditor); + void onDoubleClick(const QModelIndex&); + protected: /// Redefinition of virtual method virtual void contextMenuEvent(QContextMenuEvent* theEvent);