From: vsv Date: Fri, 8 May 2015 09:19:33 +0000 (+0300) Subject: Using mouse double click for history line change X-Git-Tag: V_1.2.0~166^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=03421c138afb385f1bb8d11f290ccb1663f3fbb8;p=modules%2Fshaper.git Using mouse double click for history line change --- diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index ef8daaecd..1b3081dd9 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -126,7 +126,11 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// Returns a list of modes, where the AIS objects should be activated /// \param theModes a list of modes - virtual void activeSelectionModes(QIntList& theModes) {}; + virtual void activeSelectionModes(QIntList& theModes) {} + + /// This method is called on object browser creation for customisation of module specific features + /// \param theObjectBrowser a pinter on Object Browser widget + virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {} public slots: /// Called on call of command corresponded to a feature diff --git a/src/PartSet/PartSet_DocumentDataModel.cpp b/src/PartSet/PartSet_DocumentDataModel.cpp index 3205baedd..fcf37a140 100644 --- a/src/PartSet/PartSet_DocumentDataModel.cpp +++ b/src/PartSet/PartSet_DocumentDataModel.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -659,33 +660,28 @@ void PartSet_DocumentDataModel::deactivatePart() Qt::ItemFlags PartSet_DocumentDataModel::flags(const QModelIndex& theIndex) const { - Qt::ItemFlags aFlags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; //QAbstractItemModel::flags(theIndex); - if (object(theIndex)) { - aFlags |= Qt::ItemIsEditable; + if ((theIndex.internalId() >= PartsFolder) && (theIndex.internalId() <= PartResult)) { + Qt::ItemFlags aFlags = Qt::ItemIsSelectable; + if (object(theIndex)) { + aFlags |= Qt::ItemIsEditable; + } + // Disable items which are below of last history row + // Do not disable second column + if (theIndex.internalId() == HistoryNode) { + if (theIndex.row() <= lastHistoryRow() || (theIndex.column() == 1)) + aFlags |= Qt::ItemIsEnabled; + } else + aFlags |= Qt::ItemIsEnabled; + return aFlags; + } else { + QModelIndex* aIndex = toSourceModelIndex(theIndex); + const QAbstractItemModel* aModel = aIndex->model(); + return aModel->flags(*aIndex); } - // Disable items which are below of last history row - // Do not disable second column - //if (theIndex.row() <= lastHistoryRow() || theIndex.column() == 1) { - // aFlags |= Qt::ItemIsEnabled; - //} - return aFlags; } QModelIndex PartSet_DocumentDataModel::partIndex(const ResultPartPtr& theObject) const { - //int aRow = -1; - //PartSet_PartModel* aModel = 0; - //foreach (PartSet_PartModel* aPartModel, myPartModels) - //{ - // aRow++; - // if (aPartModel->part() == theObject) { - // aModel = aPartModel; - // break; - // } - //} - //if (aModel) { - // return createIndex(aRow, 0, (void*) getModelIndex(aModel->index(0, 0, QModelIndex()))); - //} DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); int aNb = aRootDoc->size(ModelAPI_ResultPart::group()); for (int aId = 0; aId < aNb; aId++) { @@ -754,9 +750,7 @@ int PartSet_DocumentDataModel::lastHistoryRow() const void PartSet_DocumentDataModel::setLastHistoryItem(const QModelIndex& theIndex) { - if (theIndex.internalId() == HistoryNode) { - myHistoryBackOffset = rowCount() - 1 - theIndex.row(); - } + myHistoryBackOffset = rowCount() - 1 - theIndex.row(); } QModelIndex PartSet_DocumentDataModel::lastHistoryItem() const @@ -801,3 +795,38 @@ QIcon PartSet_DocumentDataModel::featureIcon(const FeaturePtr& theFeature) return anIcon; } +void PartSet_DocumentDataModel::onMouseDoubleClick(const QModelIndex& theIndex) +{ + 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)); + } + } + } else { + QModelIndex* aIndex = toSourceModelIndex(theIndex); + const QAbstractItemModel* aModel = aIndex->model(); + if (isPartSubModel(aModel)) { + PartSet_PartDataModel* aPartModel = (PartSet_PartDataModel*)aModel; + QModelIndex aOldItem = aPartModel->lastHistoryItem(); + aPartModel->setLastHistoryItem(*aIndex); + QModelIndex aOldIndex = createIndex(aOldItem.row(), aOldItem.column(), (void*) getModelIndex(aOldItem)); + int aStartRow = std::min(aOldItem.row(), aIndex->row()); + int aEndRow = std::max(aOldItem.row(), aIndex->row()); + for (int i = aStartRow; i <= aEndRow; i++) { + QModelIndex aInd1 = aPartModel->index(i, 0); + QModelIndex aInd2 = createIndex(i, 0, (void*) getModelIndex(aInd1)); + aTreeView->update(aInd2); + aInd1 = aPartModel->index(i, 1); + aInd2 = createIndex(i, 1, (void*) getModelIndex(aInd1)); + aTreeView->update(aInd2); + } + } + } +} diff --git a/src/PartSet/PartSet_DocumentDataModel.h b/src/PartSet/PartSet_DocumentDataModel.h index 3631f7985..6ab69bf3c 100644 --- a/src/PartSet/PartSet_DocumentDataModel.h +++ b/src/PartSet/PartSet_DocumentDataModel.h @@ -133,11 +133,15 @@ Q_OBJECT //! \param theIndex a last index for history void setLastHistoryItem(const QModelIndex& theIndex); + //! Returns last history item QModelIndex lastHistoryItem() const; //! Returns icon name according to feature static QIcon featureIcon(const FeaturePtr& theFeature); + public slots: + void onMouseDoubleClick(const QModelIndex& theIndex); + private: enum diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 2091e3c26..860ca9e37 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -641,6 +641,20 @@ void PartSet_Module::onViewTransformed(int theTrsfType) } +void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser) +{ + XGUI_ObjectsBrowser* aOB = dynamic_cast(theObjectBrowser); + if (aOB) { + QLineEdit* aLabel = aOB->activeDocLabel(); + QPalette aPalet = aLabel->palette(); + aPalet.setColor(QPalette::Text, QColor(0, 72, 140)); + aLabel->setPalette(aPalet); + connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)), + myDataModel, SLOT(onMouseDoubleClick(const QModelIndex&))); + } +} + + void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const { QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects(); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 3902138cb..cc5e97ae0 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -128,6 +128,10 @@ public: /// \param theMessage an event message virtual void processEvent(const std::shared_ptr& theMessage); + /// This method is called on object browser creation for customisation of module specific features + /// \param theObjectBrowser a pinter on Object Browser widget + virtual void customizeObjectBrowser(QWidget* theObjectBrowser); + public slots: /// SLOT, that is called by no more widget signal emitted by property panel /// Set a specific flag to restart the sketcher operation diff --git a/src/PartSet/PartSet_PartDataModel.cpp b/src/PartSet/PartSet_PartDataModel.cpp index 1f30ed2b2..ec4dabffa 100644 --- a/src/PartSet/PartSet_PartDataModel.cpp +++ b/src/PartSet/PartSet_PartDataModel.cpp @@ -361,8 +361,11 @@ QVariant PartSet_PartDataModel::data(const QModelIndex& theIndex, int theRole) c // return Tooltip break; case Qt::ForegroundRole: + if (theIndex.internalId() == HistoryObject) { + if (theIndex.row() > lastHistoryRow()) + return QBrush(Qt::lightGray); + } return QBrush(myItemsColor); - break; } return QVariant(); } @@ -571,3 +574,29 @@ int PartSet_PartDataModel::lastHistoryRow() const { return rowCount() - 1 - myHistoryBackOffset; } + +void PartSet_PartDataModel::setLastHistoryItem(const QModelIndex& theIndex) +{ + if (theIndex.internalId() == HistoryObject) { + myHistoryBackOffset = rowCount() - 1 - theIndex.row(); + } +} + +QModelIndex PartSet_PartDataModel::lastHistoryItem() const +{ + return index(lastHistoryRow(), 1); +} + +Qt::ItemFlags PartSet_PartDataModel::flags(const QModelIndex& theIndex) const +{ + Qt::ItemFlags aFlags = Qt::ItemIsSelectable; + if (object(theIndex)) { + aFlags |= Qt::ItemIsEditable; + } + if (theIndex.internalId() == HistoryObject) { + if (theIndex.row() <= lastHistoryRow() || (theIndex.column() == 1)) + aFlags |= Qt::ItemIsEnabled; + } else + aFlags |= Qt::ItemIsEnabled; + return aFlags; +} diff --git a/src/PartSet/PartSet_PartDataModel.h b/src/PartSet/PartSet_PartDataModel.h index 6e6e47a76..c821b4b50 100644 --- a/src/PartSet/PartSet_PartDataModel.h +++ b/src/PartSet/PartSet_PartDataModel.h @@ -127,6 +127,10 @@ Q_OBJECT /// \param theParent a parent model index virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const; + /// Returns the item flags for the given index. + /// \param theIndex a model index + virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const; + /// Returns the index of the item in the model specified by the given row, column and parent index. /// \param theRow a row /// \param theColumn a column @@ -163,6 +167,13 @@ Q_OBJECT //! Return a Part object virtual ResultPartPtr part() const; + //! Set an Index which will be considered as a last history index + //! \param theIndex a last index for history + void setLastHistoryItem(const QModelIndex& theIndex); + + //! Returns last history item + QModelIndex lastHistoryItem() const; + private: //! Returns document of the current part diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 20d21f791..d726e86b2 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1139,6 +1139,7 @@ QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent) "::title { position: relative; padding-left: 5px; text-align: left center }"); myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock); myObjectBrowser->setDataModel(myModule->dataModel()); + myModule->customizeObjectBrowser(myObjectBrowser); aObjDock->setWidget(myObjectBrowser); myContextMenuMgr->connectObjectBrowser();