From dcc3de2b3137a37fc2ecbc3bc856079877a1c1c7 Mon Sep 17 00:00:00 2001 From: sbh Date: Fri, 18 Apr 2014 19:04:44 +0400 Subject: [PATCH] Issue #21: set title of property panel from xml description --- src/Config/Config_WidgetReader.cpp | 8 +- src/Config/Config_WidgetReader.h | 4 +- src/ModuleBase/CMakeLists.txt | 2 + .../ModuleBase_PropPanelOperation.cpp | 32 ++++++++ .../ModuleBase_PropPanelOperation.h | 79 +++++++++++++++++++ src/PartSet/PartSet_Module.cpp | 6 +- src/XGUI/XGUI_MainWindow.cpp | 6 ++ src/XGUI/XGUI_MainWindow.h | 1 + src/XGUI/XGUI_WidgetFactory.cpp | 4 +- src/XGUI/XGUI_WidgetFactory.h | 6 +- src/XGUI/XGUI_Workshop.cpp | 8 +- src/XGUI/XGUI_Workshop.h | 3 +- 12 files changed, 146 insertions(+), 13 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_PropPanelOperation.cpp create mode 100644 src/ModuleBase/ModuleBase_PropPanelOperation.h diff --git a/src/Config/Config_WidgetReader.cpp b/src/Config/Config_WidgetReader.cpp index d78539982..8f47a6200 100644 --- a/src/Config/Config_WidgetReader.cpp +++ b/src/Config/Config_WidgetReader.cpp @@ -29,11 +29,16 @@ Config_WidgetReader::~Config_WidgetReader() { } -std::string Config_WidgetReader::featureWidgetCfg(std::string theFeatureName) +std::string Config_WidgetReader::featureWidgetCfg(const std::string& theFeatureName) { return myWidgetCache[theFeatureName]; } +std::string Config_WidgetReader::featureDescription(const std::string& theFeatureName) +{ + return myDescriptionCache[theFeatureName]; +} + void Config_WidgetReader::processNode(xmlNodePtr theNode) { if (isNode(theNode, NODE_FEATURE, NULL)) { @@ -45,6 +50,7 @@ void Config_WidgetReader::processNode(xmlNodePtr theNode) result = std::string((char*) buffer->content); } myWidgetCache[aNodeName] = result; + myDescriptionCache[aNodeName] = getProperty(theNode, FEATURE_TEXT); } } diff --git a/src/Config/Config_WidgetReader.h b/src/Config/Config_WidgetReader.h index 7b5aa86f4..ae76cc996 100644 --- a/src/Config/Config_WidgetReader.h +++ b/src/Config/Config_WidgetReader.h @@ -21,7 +21,8 @@ public: CONFIG_EXPORT Config_WidgetReader(const std::string& theXmlFile); CONFIG_EXPORT virtual ~Config_WidgetReader(); - CONFIG_EXPORT std::string featureWidgetCfg(std::string theFeatureName); + CONFIG_EXPORT std::string featureWidgetCfg(const std::string& theFeatureName); + CONFIG_EXPORT std::string featureDescription(const std::string& theFeatureName); protected: void processNode(xmlNodePtr theNode); @@ -29,6 +30,7 @@ protected: private: std::map myWidgetCache; + std::map myDescriptionCache; }; diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index efd8db9c1..fcd731c9e 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -4,10 +4,12 @@ SET(CMAKE_AUTOMOC ON) SET(PROJECT_HEADERS ModuleBase.h ModuleBase_Operation.h + ModuleBase_PropPanelOperation.h ) SET(PROJECT_SOURCES ModuleBase_Operation.cpp + ModuleBase_PropPanelOperation.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModuleBase/ModuleBase_PropPanelOperation.cpp b/src/ModuleBase/ModuleBase_PropPanelOperation.cpp new file mode 100644 index 000000000..a35aaf75f --- /dev/null +++ b/src/ModuleBase/ModuleBase_PropPanelOperation.cpp @@ -0,0 +1,32 @@ +/* + * ModuleBase_PropPanelOperation.cpp + * + * Created on: Apr 2, 2014 + * Author: sbh + */ + +#include +#include + +/*! + \brief Constructor + \param XGUI_Workshop - workshop for this operation + + Constructs an empty operation. Constructor should work very fast because many + operators may be created after starting workshop but only several from them + may be used. As result this constructor stores given workshop in myApp field + and set Waiting status. + */ +ModuleBase_PropPanelOperation::ModuleBase_PropPanelOperation(const QString& theId, QObject* parent) +: ModuleBase_Operation(theId, parent) +{ +} + +/*! + * \brief Destructor + */ +ModuleBase_PropPanelOperation::~ModuleBase_PropPanelOperation() +{ + +} + diff --git a/src/ModuleBase/ModuleBase_PropPanelOperation.h b/src/ModuleBase/ModuleBase_PropPanelOperation.h new file mode 100644 index 000000000..c6dc06814 --- /dev/null +++ b/src/ModuleBase/ModuleBase_PropPanelOperation.h @@ -0,0 +1,79 @@ +/* + * ModuleBase_PropPanelOperation.h + * + * Created on: Apr 2, 2014 + * Author: sbh + */ + +#ifndef MODULEBASE_PROPPANELOPERATION_H +#define MODULEBASE_PROPPANELOPERATION_H + +#include +#include + +#include +#include + +#include + +/*! + * \class ModuleBase_PropPanelOperation + * + */ +class MODULEBASE_EXPORT ModuleBase_PropPanelOperation: public ModuleBase_Operation +{ + + Q_OBJECT + +public: + ModuleBase_PropPanelOperation(const QString& theId = "", QObject* parent = 0); + virtual ~ModuleBase_PropPanelOperation(); + + /*! + * \brief Returns XML representation of the operation's widget. + * \return XML QString + * + * Returns XML representation of the operation's widget. + */ + const QString& xmlRepresentation() const + { + return myXmlRepr; + } + + /*! + * \brief Sets XML representation of the operation's widget. + * \param xmlRepr - XML QString + * + * Sets XML representation of the operation's widget. + */ + void setXmlRepresentation(const QString& xmlRepr) + { + this->myXmlRepr = xmlRepr; + } + + + /* + * Returns a short description of operation (will be + * inserted in title of property panel) + */ + const QString& description() const + { + return myDescription; + } + + /* + * Sets a short description of operation (will be + * inserted in title of property panel) + */ + void setDescription(const QString& theDescription) + { + this->myDescription = theDescription; + } + +private: + //!< Next fields could be extracted into a subclass; + QString myXmlRepr; + QString myDescription; +}; + +#endif //MODULEBASE_PROPPANELOPERATION_H diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 3a24568f4..fb437c5ba 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -55,11 +55,13 @@ void PartSet_Module::onFeatureTriggered() XGUI_Command* aCmd = dynamic_cast(sender()); QString aCmdId = aCmd->id(); std::string aXmlCfg = aWdgReader.featureWidgetCfg(aCmdId.toStdString()); + std::string aDescription = aWdgReader.featureDescription(aCmdId.toStdString()); //TODO(sbh): Implement static method to extract event id [SEID] static Event_ID aModuleEvent = Event_Loop::eventByName("PartSetModuleEvent"); Config_PointerMessage aMessage(aModuleEvent, this); - ModuleBase_Operation* aPartSetOp = new ModuleBase_Operation(aCmdId, this); + ModuleBase_PropPanelOperation* aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this); aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg)); + aPartSetOp->setDescription(QString::fromStdString(aDescription)); aMessage.setPointer(aPartSetOp); Event_Loop::loop()->send(aMessage); } diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index b648d59ce..fdaaf16f0 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -121,11 +121,17 @@ void XGUI_MainWindow::createDockWidgets() tabifyDockWidget(aObjDock, myPropertyPanelDock); } +void XGUI_MainWindow::setPropertyPannelTitle(const QString& theTitle) +{ + myPropertyPanelDock->setWindowTitle(theTitle); +} + QDockWidget* XGUI_MainWindow::createPropertyPanel() { QDockWidget* aPropPanel = new QDockWidget(this); aPropPanel->setWindowTitle(tr("Property Panel")); + QAction* aViewAct = aPropPanel->toggleViewAction(); aPropPanel->setObjectName(XGUI::PROP_PANEL); QWidget* aContent = new QWidget(aPropPanel); diff --git a/src/XGUI/XGUI_MainWindow.h b/src/XGUI/XGUI_MainWindow.h index 186b3b87d..2a71a876a 100644 --- a/src/XGUI/XGUI_MainWindow.h +++ b/src/XGUI/XGUI_MainWindow.h @@ -46,6 +46,7 @@ public: // Creates Dock widgets: Object broewser and Property panel void createDockWidgets(); + void setPropertyPannelTitle(const QString& theTitle); public slots: void showPythonConsole(); diff --git a/src/XGUI/XGUI_WidgetFactory.cpp b/src/XGUI/XGUI_WidgetFactory.cpp index 4c5223324..929f71771 100644 --- a/src/XGUI/XGUI_WidgetFactory.cpp +++ b/src/XGUI/XGUI_WidgetFactory.cpp @@ -9,7 +9,7 @@ #include -#include +#include #include #include @@ -29,7 +29,7 @@ #include #include -XGUI_WidgetFactory::XGUI_WidgetFactory(ModuleBase_Operation* theOperation) +XGUI_WidgetFactory::XGUI_WidgetFactory(ModuleBase_PropPanelOperation* theOperation) : myOperation(theOperation) { QString aXml = myOperation->xmlRepresentation(); diff --git a/src/XGUI/XGUI_WidgetFactory.h b/src/XGUI/XGUI_WidgetFactory.h index 27a65fa43..ed0ba16c6 100644 --- a/src/XGUI/XGUI_WidgetFactory.h +++ b/src/XGUI/XGUI_WidgetFactory.h @@ -13,12 +13,12 @@ class QWidget; class Config_WidgetAPI; -class ModuleBase_Operation; +class ModuleBase_PropPanelOperation; class XGUI_EXPORT XGUI_WidgetFactory { public: - XGUI_WidgetFactory(ModuleBase_Operation*); + XGUI_WidgetFactory(ModuleBase_PropPanelOperation*); virtual ~XGUI_WidgetFactory(); void createWidget(QWidget* theParent); @@ -34,7 +34,7 @@ protected: private: Config_WidgetAPI* myWidgetApi; - ModuleBase_Operation* myOperation; + ModuleBase_PropPanelOperation* myOperation; }; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 58d5a87c1..48e3770ce 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include @@ -147,7 +147,8 @@ void XGUI_Workshop::processEvent(const Event_Message* theMessage) const Config_PointerMessage* aPartSetMsg = dynamic_cast(theMessage); if (aPartSetMsg) { - ModuleBase_Operation* aOperation = (ModuleBase_Operation*)(aPartSetMsg->pointer()); + ModuleBase_PropPanelOperation* aOperation = + (ModuleBase_PropPanelOperation*)(aPartSetMsg->pointer()); setCurrentOperation(aOperation); if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel myCurrentOperation->start(); @@ -204,7 +205,7 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) /* * */ -void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation) +void XGUI_Workshop::fillPropertyPanel(ModuleBase_PropPanelOperation* theOperation) { connectToPropertyPanel(theOperation); QWidget* aPropWidget = myMainWindow->findChild(XGUI::PROP_PANEL_WDG); @@ -212,6 +213,7 @@ void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation) theOperation->start(); XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(theOperation); aFactory.createWidget(aPropWidget); + myMainWindow->setPropertyPannelTitle(theOperation->description()); } void XGUI_Workshop::setCurrentOperation(ModuleBase_Operation* theOperation) diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 371fbb366..aff5c239b 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -15,6 +15,7 @@ class XGUI_Module; class XGUI_Workbench; class XGUI_SelectionMgr; class ModuleBase_Operation; +class ModuleBase_PropPanelOperation; class Config_FeatureMessage; class Config_PointerMessage; @@ -63,7 +64,7 @@ public slots: protected: //Event-loop processing methods: void addFeature(const Config_FeatureMessage*); - void fillPropertyPanel(ModuleBase_Operation* theOperation); + void fillPropertyPanel(ModuleBase_PropPanelOperation* theOperation); void connectToPropertyPanel(ModuleBase_Operation* theOperation); void setCurrentOperation(ModuleBase_Operation* theOperation); -- 2.39.2