From: vsv Date: Fri, 16 May 2014 15:24:49 +0000 (+0400) Subject: Issue #23: Last discussed scenario (#14) for document activation was implemented. X-Git-Tag: V_0.2~49^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c23358fff93a754447d421ca606ae6f570e5c7a5;p=modules%2Fshaper.git Issue #23: Last discussed scenario (#14) for document activation was implemented. --- diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index b191e7fa3..2a8fe108b 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -22,6 +22,12 @@ void XGUI_ContextMenuMgr::createActions() { QAction* aAction = new QAction(QIcon(":pictures/edit.png"), tr("Edit..."), this); addAction("EDIT_CMD", aAction); + + aAction = new QAction(QIcon(":pictures/activate.png"), tr("Activate"), this); + addAction("ACTIVATE_PART_CMD", aAction); + + aAction = new QAction(QIcon(":pictures/assembly.png"), tr("Deactivate"), this); + addAction("DEACTIVATE_PART_CMD", aAction); } void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction) @@ -73,11 +79,14 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const QFeatureList aFeatures = aSelMgr->selectedFeatures(); if (aFeatures.size() == 1) { FeaturePtr aFeature = aFeatures.first(); - if (aFeature->getKind() != "Part") { - QMenu* aMenu = new QMenu(); + QMenu* aMenu = new QMenu(); + if (aFeature->getKind() == "Part") { + //TODO: Check that feature is active + aMenu->addAction(action("ACTIVATE_PART_CMD")); + } else { aMenu->addAction(action("EDIT_CMD")); - return aMenu; } + return aMenu; } return 0; } diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index c5b0cbd9b..2c4470cce 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -431,7 +431,15 @@ bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex) // if this is root node (Part item index) if (!aIndex->parent().isValid()) { if (myActivePart) myActivePart->setItemsColor(PASSIVE_COLOR); - myActivePart = (myActivePart == aModel)? 0 : (XGUI_PartModel*)aModel; + + if (myActivePart == aModel) { + myActivePart = 0; + myActivePartIndex = QModelIndex(); + } else { + myActivePart = (XGUI_PartModel*)aModel; + myActivePartIndex = theIndex; + } + if (myActivePart) { myActivePart->setItemsColor(ACTIVE_COLOR); myModel->setItemsColor(PASSIVE_COLOR); @@ -448,4 +456,12 @@ FeaturePtr XGUI_DocumentDataModel::activePart() const if (myActivePart) return myActivePart->part(); return FeaturePtr(); -} \ No newline at end of file +} + +void XGUI_DocumentDataModel::deactivatePart() +{ + if (myActivePart) + myActivePart->setItemsColor(PASSIVE_COLOR); + myActivePart = 0; + myModel->setItemsColor(ACTIVE_COLOR); +} diff --git a/src/XGUI/XGUI_DocumentDataModel.h b/src/XGUI/XGUI_DocumentDataModel.h index 68bfa4062..f6ce80eac 100644 --- a/src/XGUI/XGUI_DocumentDataModel.h +++ b/src/XGUI/XGUI_DocumentDataModel.h @@ -60,6 +60,11 @@ public: FeaturePtr activePart() const; + QModelIndex activePartIndex() const { return myActivePartIndex; } + + //! Deactivates a Part + void deactivatePart(); + private: enum {PartsFolder, HistoryNode}; @@ -104,6 +109,8 @@ private: //! Active part in part editing mode XGUI_PartModel* myActivePart; + QModelIndex myActivePartIndex; + //! List of saved QModelIndexes created by sub-models QList myIndexes; diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 21530908e..cf0e8577d 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -1,49 +1,176 @@ #include "XGUI_ObjectsBrowser.h" #include "XGUI_DocumentDataModel.h" -XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) +#include + +#include +#include +#include +#include +#include + + + +XGUI_DataTree::XGUI_DataTree(QWidget* theParent) : QTreeView(theParent) { setHeaderHidden(true); - myDocModel = new XGUI_DocumentDataModel(this); - setModel(myDocModel); + setModel(new XGUI_DocumentDataModel(this)); connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), - this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&))); + this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&))); } - -XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser() +XGUI_DataTree::~XGUI_DataTree() { } +XGUI_DocumentDataModel* XGUI_DataTree::dataModel() const +{ + return static_cast(model()); +} -void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected, +void XGUI_DataTree::onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected) { mySelectedData.clear(); QModelIndexList aIndexes = selectionModel()->selectedIndexes(); + XGUI_DocumentDataModel* aModel = dataModel(); QModelIndexList::const_iterator aIt; for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) { - FeaturePtr aFeature = myDocModel->feature(*aIt); + FeaturePtr aFeature = aModel->feature(*aIt); if (aFeature) mySelectedData.append(aFeature); } emit selectionChanged(); } -void XGUI_ObjectsBrowser::mouseDoubleClickEvent(QMouseEvent* theEvent) +void XGUI_DataTree::mouseDoubleClickEvent(QMouseEvent* theEvent) { - QModelIndex aIndex = currentIndex(); - bool isChanged = myDocModel->activatedIndex(aIndex); - QTreeView::mouseDoubleClickEvent(theEvent); - if (isChanged) { - emit activePartChanged(myDocModel->activePart()); - } + if (theEvent->button() == Qt::LeftButton) { + QModelIndex aIndex = currentIndex(); + XGUI_DocumentDataModel* aModel = dataModel(); + + if ((aModel->activePartIndex() != aIndex) && aModel->activePartIndex().isValid()) { + setExpanded(aModel->activePartIndex(), false); + } + bool isChanged = aModel->activatedIndex(aIndex); + QTreeView::mouseDoubleClickEvent(theEvent); + if (isChanged) { + if (aModel->activePartIndex().isValid()) + setExpanded(aIndex, true); + emit activePartChanged(aModel->activePart()); + } + } else + QTreeView::mouseDoubleClickEvent(theEvent); } -void XGUI_ObjectsBrowser::contextMenuEvent(QContextMenuEvent* theEvent) +void XGUI_DataTree::contextMenuEvent(QContextMenuEvent* theEvent) { emit contextMenuRequested(theEvent); +} + +//******************************************************************** +//******************************************************************** +//******************************************************************** +XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) + : QWidget(theParent) +{ + QVBoxLayout* aLayout = new QVBoxLayout(this); + aLayout->setContentsMargins(0, 0, 0, 0); + aLayout->setSpacing(0); + + QWidget* aLabelWgt = new QWidget(this); + aLayout->addWidget(aLabelWgt); + QHBoxLayout* aLabelLay = new QHBoxLayout(aLabelWgt); + aLabelLay->setContentsMargins(3, 3, 3, 3); + + QLabel* aLbl = new QLabel(aLabelWgt); + aLbl->setPixmap(QPixmap(":pictures/assembly.png")); + aLabelLay->addWidget(aLbl); + + myActiveDocLbl = new QLabel("", aLabelWgt); + myActiveDocLbl->setAlignment(Qt::AlignHCenter); + + QFont aFnt = myActiveDocLbl->font(); + aFnt.setBold(true); + myActiveDocLbl->setFont(aFnt); + + myActiveDocLbl->installEventFilter(this); + + aLabelLay->addWidget(myActiveDocLbl); + aLabelLay->setStretch(1,1); + + myTreeView = new XGUI_DataTree(this); + aLayout->addWidget(myTreeView); + + myDocModel = myTreeView->dataModel(); + + connect(myTreeView, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged())); + connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(onActivePartChanged(FeaturePtr))); + connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SIGNAL(activePartChanged(FeaturePtr))); + connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), + this, SIGNAL(contextMenuRequested(QContextMenuEvent*))); + + onActivePartChanged(FeaturePtr()); +} + + +XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser() +{ +} + + +void XGUI_ObjectsBrowser::onActivePartChanged(FeaturePtr thePart) +{ + QPalette aPalet = myActiveDocLbl->palette(); + if (thePart) { + myActiveDocLbl->setText(tr("Activate Part set")); + aPalet.setColor(QPalette::Foreground, Qt::black); + myActiveDocLbl->setCursor(Qt::PointingHandCursor); + } else { + myActiveDocLbl->setText(tr("Part set is active")); + aPalet.setColor(QPalette::Foreground, QColor(0, 72, 140)); + myActiveDocLbl->unsetCursor(); + } + myActiveDocLbl->setPalette(aPalet); +} + +bool XGUI_ObjectsBrowser::eventFilter(QObject* obj, QEvent* theEvent) +{ + if (obj == myActiveDocLbl) { + if (theEvent->type() == QEvent::MouseButtonDblClick) { + if (myDocModel->activePartIndex().isValid()) { + myTreeView->setExpanded(myDocModel->activePartIndex(), false); + } + myDocModel->deactivatePart(); + onActivePartChanged(FeaturePtr()); + emit activePartChanged(FeaturePtr()); + } + } + return QWidget::eventFilter(obj, theEvent); +} + +void XGUI_ObjectsBrowser::activateCurrentPart(bool toActivate) +{ + if (toActivate) { + QModelIndex aIndex = myTreeView->currentIndex(); + + if ((myDocModel->activePartIndex() != aIndex) && myDocModel->activePartIndex().isValid()) { + myTreeView->setExpanded(myDocModel->activePartIndex(), false); + } + bool isChanged = myDocModel->activatedIndex(aIndex); + if ((isChanged) && (myDocModel->activePartIndex().isValid())) { + myTreeView->setExpanded(aIndex, true); + onActivePartChanged(myDocModel->feature(aIndex)); + } + } else { + QModelIndex aIndex = myDocModel->activePartIndex(); + if (aIndex.isValid()) { + myDocModel->activatedIndex(aIndex); + myTreeView->setExpanded(aIndex, false); + onActivePartChanged(FeaturePtr()); + } + } } \ No newline at end of file diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index fd1adbed8..18c03d2cc 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -5,15 +5,52 @@ #include "XGUI.h" #include "XGUI_Constants.h" +#include #include class XGUI_DocumentDataModel; +class QLabel; + + +class XGUI_DataTree: public QTreeView +{ + Q_OBJECT +public: + XGUI_DataTree(QWidget* theParent); + virtual ~XGUI_DataTree(); + + //! Returns list of currently selected features + QFeatureList selectedFeatures() const { return mySelectedData; } + + XGUI_DocumentDataModel* dataModel() const; + +signals: + //! Emited when selection is changed + void selectionChanged(); + void activePartChanged(FeaturePtr thePart); + + //! Emited on context menu request + void contextMenuRequested(QContextMenuEvent* theEvent); + +protected: + virtual void mouseDoubleClickEvent(QMouseEvent* theEvent); + virtual void contextMenuEvent(QContextMenuEvent* theEvent); + +private slots: + //! Called when selection in Data Tree is changed + void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected); + +private: + //! List of currently selected data + QFeatureList mySelectedData; +}; + /**\class XGUI_ObjectsBrowser * \ingroup GUI * \brief Object browser window object. Represents data tree of current data structure */ - class XGUI_EXPORT XGUI_ObjectsBrowser : public QTreeView + class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget { Q_OBJECT public: @@ -24,32 +61,39 @@ public: XGUI_DocumentDataModel* dataModel() const { return myDocModel; } //! Returns list of currently selected features - QFeatureList selectedFeatures() const { return mySelectedData; } + QFeatureList selectedFeatures() const { return myTreeView->selectedFeatures(); } + + //! Returns currently selected indexes + QModelIndexList selectedIndexes() const { return myTreeView->selectionModel()->selectedIndexes(); } + + //! Returns TreeView widget + XGUI_DataTree* treeView() const { return myTreeView; } + + //! Activates currently selected part. Signal activePartChanged will not be sent + void activateCurrentPart(bool toActivate); signals: //! Emited when selection is changed void selectionChanged(); + + //! Emited when current active document is changed void activePartChanged(FeaturePtr thePart); //! Emited on context menu request void contextMenuRequested(QContextMenuEvent* theEvent); protected: - virtual void mouseDoubleClickEvent(QMouseEvent* theEvent); - virtual void contextMenuEvent(QContextMenuEvent* theEvent); + virtual bool eventFilter(QObject* obj, QEvent* theEvent); private slots: - //! Called when selection in Data Tree is changed - void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected); + void onActivePartChanged(FeaturePtr thePart); private: //! Internal model XGUI_DocumentDataModel* myDocModel; - //! List of currently selected data - QFeatureList mySelectedData; - - //QModelIndex myActivePartIndex; + QLabel* myActiveDocLbl; + XGUI_DataTree* myTreeView; }; #endif \ No newline at end of file diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index 8365772e7..f949c782a 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -63,7 +63,7 @@ QFeatureList XGUI_SelectionMgr::selectedFeatures() const //************************************************************** QModelIndexList XGUI_SelectionMgr::selectedIndexes() const { - return myWorkshop->objectBrowser()->selectionModel()->selectedIndexes(); + return myWorkshop->objectBrowser()->selectedIndexes(); } //************************************************************** diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 9b391a44e..a935975d2 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -85,6 +85,8 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) myActionsMgr = new XGUI_ActionsMgr(this); myErrorDlg = new XGUI_ErrorDialog(myMainWindow); myContextMenuMgr = new XGUI_ContextMenuMgr(this); + connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), + this, SLOT(onContextMenuCommand(const QString&, bool))); myViewerProxy = new XGUI_ViewerProxy(this); @@ -470,7 +472,7 @@ void XGUI_Workshop::onSaveAs() //****************************************************** void XGUI_Workshop::onUndo() { - objectBrowser()->setCurrentIndex(QModelIndex()); + objectBrowser()->treeView()->setCurrentIndex(QModelIndex()); boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); boost::shared_ptr aDoc = aMgr->rootDocument(); if (aDoc->isOperation()) @@ -482,7 +484,7 @@ void XGUI_Workshop::onUndo() //****************************************************** void XGUI_Workshop::onRedo() { - objectBrowser()->setCurrentIndex(QModelIndex()); + objectBrowser()->treeView()->setCurrentIndex(QModelIndex()); boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); boost::shared_ptr aDoc = aMgr->rootDocument(); aDoc->redo(); @@ -698,3 +700,29 @@ XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const { return mySalomeConnector->viewer(); } + +//************************************************************** +void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) +{ + if (theId == "ACTIVATE_PART_CMD") + activatePart(true); + else if (theId == "DEACTIVATE_PART_CMD") + activatePart(false); + +} + +//************************************************************** +void XGUI_Workshop::activatePart(bool toActivate) +{ + if (toActivate) { + QFeatureList aFeatures = mySelector->selectedFeatures(); + if (aFeatures.size() > 0) { + changeCurrentDocument(aFeatures.first()); + myObjectBrowser->activateCurrentPart(true); + } + } else { + changeCurrentDocument(FeaturePtr()); + myObjectBrowser->activateCurrentPart(false); + } +} + diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index f0121474b..cd77d3b13 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -139,6 +139,8 @@ protected slots: /// \param theOpertion a stopped operation void onOperationStopped(ModuleBase_Operation* theOperation); + void onContextMenuCommand(const QString& theId, bool isChecked); + private: void initMenu(); @@ -151,6 +153,9 @@ private: // Creates Dock widgets: Object browser and Property panel void createDockWidgets(); + //! Activates or deactivates currently selected part + void activatePart(bool toActivate); + QString myCurrentFile; XGUI_MainWindow* myMainWindow; XGUI_Module* myPartSetModule; diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index 893d8d7b6..30d9ba286 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -52,5 +52,7 @@ pictures/tile_views.png pictures/new_view.png pictures/edit.png + pictures/assembly.png + pictures/activate.png diff --git a/src/XGUI/pictures/activate.png b/src/XGUI/pictures/activate.png new file mode 100644 index 000000000..f82917927 Binary files /dev/null and b/src/XGUI/pictures/activate.png differ diff --git a/src/XGUI/pictures/assembly.png b/src/XGUI/pictures/assembly.png new file mode 100644 index 000000000..1b1c71aaa Binary files /dev/null and b/src/XGUI/pictures/assembly.png differ