From: nds Date: Wed, 6 Apr 2016 16:01:55 +0000 (+0300) Subject: Issue #1348 Creation of a Qt panel: providing additional sample for ModuleBase_ModelW... X-Git-Tag: V_2.3.0~281 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=706ab0fe659d7a00bed37ca5ddf44b037723ddba;p=modules%2Fshaper.git Issue #1348 Creation of a Qt panel: providing additional sample for ModuleBase_ModelWidget using. --- diff --git a/src/SamplePanelPlugin/CMakeLists.txt b/src/SamplePanelPlugin/CMakeLists.txt index ab48f6073..ac37f294e 100755 --- a/src/SamplePanelPlugin/CMakeLists.txt +++ b/src/SamplePanelPlugin/CMakeLists.txt @@ -6,6 +6,8 @@ SET(CMAKE_AUTOMOC ON) SET(PROJECT_HEADERS SamplePanelPlugin.h SamplePanelPlugin_Feature.h + SamplePanelPlugin_ModelWidget.h + SamplePanelPlugin_ModelWidgetCreator.h SamplePanelPlugin_Panel.h SamplePanelPlugin_Plugin.h SamplePanelPlugin_WidgetCreator.h @@ -13,6 +15,8 @@ SET(PROJECT_HEADERS SET(PROJECT_SOURCES SamplePanelPlugin_Feature.cpp + SamplePanelPlugin_ModelWidget.cpp + SamplePanelPlugin_ModelWidgetCreator.cpp SamplePanelPlugin_Panel.cpp SamplePanelPlugin_Plugin.cpp SamplePanelPlugin_WidgetCreator.cpp diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidget.cpp b/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidget.cpp new file mode 100755 index 000000000..a5cf68391 --- /dev/null +++ b/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidget.cpp @@ -0,0 +1,73 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SamplePanelPlugin_PageGroupBox.h +// Created: 29 Mar 2015 +// Author: Natalia ERMOLAEVA + +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + +SamplePanelPlugin_ModelWidget::SamplePanelPlugin_ModelWidget(QWidget* theParent, + const Config_WidgetAPI* theData) +: ModuleBase_ModelWidget(theParent, theData), myDefaultValue(0) +{ + QVBoxLayout* aLay = new QVBoxLayout(this); + aLay->setContentsMargins(0, 0, 0, 0); + + myMainWidget = new QWidget(this); + aLay->addWidget(myMainWidget); + + QGridLayout* aLayout = new QGridLayout(myMainWidget); + aLayout->addWidget(new QLabel("Values:"), 0, 0); + + myComboBox = new QComboBox(myMainWidget); + myComboBox->addItem("Value_1"); + myComboBox->addItem("Value_2"); + myComboBox->addItem("Value_3"); + + connect(myComboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(valuesChanged())); + aLayout->addWidget(myComboBox, 0, 1); +} + +QList SamplePanelPlugin_ModelWidget::getControls() const +{ + QList aControls; + // this control will accept focus and will be highlighted in the Property Panel + aControls.push_back(myComboBox); + return aControls; +} + +bool SamplePanelPlugin_ModelWidget::storeValueCustom() const +{ + AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID()); + AttributeIntegerPtr aValueAttribute = + std::dynamic_pointer_cast(anAttribute); + aValueAttribute->setValue(myComboBox->currentIndex()); + updateObject(myFeature); + return true; +} + +bool SamplePanelPlugin_ModelWidget::restoreValueCustom() +{ + AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID()); + AttributeIntegerPtr aValueAttribute = + std::dynamic_pointer_cast(anAttribute); + + bool isBlocked = myComboBox->blockSignals(true); + myComboBox->setCurrentIndex(aValueAttribute->value()); + myComboBox->blockSignals(isBlocked); + + return true; +} + diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidget.h b/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidget.h new file mode 100755 index 000000000..dfee20d53 --- /dev/null +++ b/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidget.h @@ -0,0 +1,50 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SamplePanelPlugin_PageGroupBox.h +// Created: 29 Mar 2015 +// Author: Natalia ERMOLAEVA + +#ifndef SamplePanelPlugin_ModelWidget_H_ +#define SamplePanelPlugin_ModelWidget_H_ + +#include + +#include + +class Config_WidgetAPI; + +class QWidget; +class QComboBox; + +/*! + * \ingroup GUI + * Represent a content of the property panel to show/modify parameters of some feature. + */ +class SamplePanelPlugin_ModelWidget : public ModuleBase_ModelWidget +{ + Q_OBJECT +public: + /// Constructs a model widget + SamplePanelPlugin_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData); + /// Destructs the model widget + virtual ~SamplePanelPlugin_ModelWidget() {} + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + +protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValueCustom() const; + + /// Restore value from attribute data to the widget's control + virtual bool restoreValueCustom(); + +private: + QWidget* myMainWidget; // parent control for all widget controls + QComboBox* myComboBox; // control for value attribute of the current feature + int myDefaultValue; /// the default combo box value +}; + +#endif /* SamplePanelPlugin_ModelWidget_H_ */ diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidgetCreator.cpp b/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidgetCreator.cpp new file mode 100755 index 000000000..e2509d1a8 --- /dev/null +++ b/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidgetCreator.cpp @@ -0,0 +1,37 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SamplePanelPlugin_ModelWidgetCreator.cpp +// Created: 29 Mar 2015 +// Author: Natalia ERMOLAEVA + +#include "SamplePanelPlugin_ModelWidgetCreator.h" +#include "SamplePanelPlugin_ModelWidget.h" + +#include + +SamplePanelPlugin_ModelWidgetCreator::SamplePanelPlugin_ModelWidgetCreator() +: ModuleBase_IWidgetCreator() +{ + myModelWidgetTypes.insert("QtModelWidget"); +} + +void SamplePanelPlugin_ModelWidgetCreator::widgetTypes(std::set& theTypes) +{ + theTypes = myModelWidgetTypes; +} + +ModuleBase_ModelWidget* SamplePanelPlugin_ModelWidgetCreator::createWidgetByType(const std::string& theType, + QWidget* theParent, + Config_WidgetAPI* theWidgetApi, + ModuleBase_IWorkshop* /*theWorkshop*/) +{ + ModuleBase_ModelWidget* aModelWidget = 0; + if (myModelWidgetTypes.find(theType) == myModelWidgetTypes.end()) + return aModelWidget; + + if (theType == "QtModelWidget") { + aModelWidget = new SamplePanelPlugin_ModelWidget(theParent, theWidgetApi); + } + + return aModelWidget; +} diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidgetCreator.h b/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidgetCreator.h new file mode 100755 index 000000000..23d1deae5 --- /dev/null +++ b/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidgetCreator.h @@ -0,0 +1,53 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SamplePanelPlugin_ModelWidgetCreator.h +// Created: 29 Mar 2015 +// Author: Natalia ERMOLAEVA + +#ifndef SamplePanelPlugin_ModelWidgetCreator_H +#define SamplePanelPlugin_ModelWidgetCreator_H + +#include "SamplePanelPlugin.h" + +#include + +#include +#include + +class ModuleBase_IWorkshop; +class Config_WidgetAPI; +class QWidget; + +/** +* \ingroup GUI +* Interface to WidgetCreator which can create specific widgets by type +*/ +class SamplePanelPlugin_ModelWidgetCreator : public ModuleBase_IWidgetCreator +{ +public: + /// Default constructor + SamplePanelPlugin_ModelWidgetCreator(); + + /// Virtual destructor + ~SamplePanelPlugin_ModelWidgetCreator() {} + + /// Returns a container of possible widget types, which this creator can process + /// \param a list of type names + virtual void widgetTypes(std::set& theTypes); + + /// Create widget by its type + /// The default implementation is empty + /// \param theType a type + /// \param theParent a parent widget + /// \param theData a low-level API for reading xml definitions of widgets + /// \param theWorkshop a current workshop + /// \return a created model widget or null + virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, + QWidget* theParent, + Config_WidgetAPI* theWidgetApi, + ModuleBase_IWorkshop* /*theWorkshop*/); +private: + std::set myModelWidgetTypes; /// types of widgets +}; + +#endif diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_Plugin.cpp b/src/SamplePanelPlugin/SamplePanelPlugin_Plugin.cpp index cc59adb70..88a9221b9 100755 --- a/src/SamplePanelPlugin/SamplePanelPlugin_Plugin.cpp +++ b/src/SamplePanelPlugin/SamplePanelPlugin_Plugin.cpp @@ -12,6 +12,7 @@ #include #include +#include // the only created instance of this plugin static SamplePanelPlugin_Plugin* MY_SAMPLE_PANEL_PLUGIN_INSTANCE = new SamplePanelPlugin_Plugin(); @@ -23,6 +24,8 @@ SamplePanelPlugin_Plugin::SamplePanelPlugin_Plugin() WidgetCreatorFactoryPtr aWidgetCreatorFactory = ModuleBase_WidgetCreatorFactory::get(); aWidgetCreatorFactory->registerCreator( std::shared_ptr(new SamplePanelPlugin_WidgetCreator())); + aWidgetCreatorFactory->registerCreator( + std::shared_ptr(new SamplePanelPlugin_ModelWidgetCreator())); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.h b/src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.h index 548cbba1a..5d1b09293 100755 --- a/src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.h +++ b/src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.h @@ -45,6 +45,4 @@ private: std::set myPanelTypes; /// types of panels }; -typedef std::shared_ptr SamplePanelWidgetCreatorPtr; - #endif diff --git a/src/SamplePanelPlugin/plugin-SamplePanel.xml b/src/SamplePanelPlugin/plugin-SamplePanel.xml index f58e08149..2682a3d6b 100755 --- a/src/SamplePanelPlugin/plugin-SamplePanel.xml +++ b/src/SamplePanelPlugin/plugin-SamplePanel.xml @@ -3,7 +3,10 @@ - + + + +