SET(PROJECT_HEADERS
SamplePanelPlugin.h
SamplePanelPlugin_Feature.h
+ SamplePanelPlugin_ModelWidget.h
+ SamplePanelPlugin_ModelWidgetCreator.h
SamplePanelPlugin_Panel.h
SamplePanelPlugin_Plugin.h
SamplePanelPlugin_WidgetCreator.h
SET(PROJECT_SOURCES
SamplePanelPlugin_Feature.cpp
+ SamplePanelPlugin_ModelWidget.cpp
+ SamplePanelPlugin_ModelWidgetCreator.cpp
SamplePanelPlugin_Panel.cpp
SamplePanelPlugin_Plugin.cpp
SamplePanelPlugin_WidgetCreator.cpp
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: SamplePanelPlugin_PageGroupBox.h
+// Created: 29 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#include <SamplePanelPlugin_ModelWidget.h>
+#include <SamplePanelPlugin_Feature.h>
+
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_Events.h>
+
+#include <Config_WidgetAPI.h>
+#include <Events_Loop.h>
+
+#include <QVBoxLayout>
+#include <QGridLayout>
+#include <QLabel>
+#include <QComboBox>
+
+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<QWidget*> SamplePanelPlugin_ModelWidget::getControls() const
+{
+ QList<QWidget*> 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<ModelAPI_AttributeInteger>(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<ModelAPI_AttributeInteger>(anAttribute);
+
+ bool isBlocked = myComboBox->blockSignals(true);
+ myComboBox->setCurrentIndex(aValueAttribute->value());
+ myComboBox->blockSignals(isBlocked);
+
+ return true;
+}
+
--- /dev/null
+// 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 <ModuleBase_ModelWidget.h>
+
+#include <ModelAPI_Feature.h>
+
+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<QWidget*> 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_ */
--- /dev/null
+// 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 <Config_WidgetAPI.h>
+
+SamplePanelPlugin_ModelWidgetCreator::SamplePanelPlugin_ModelWidgetCreator()
+: ModuleBase_IWidgetCreator()
+{
+ myModelWidgetTypes.insert("QtModelWidget");
+}
+
+void SamplePanelPlugin_ModelWidgetCreator::widgetTypes(std::set<std::string>& 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;
+}
--- /dev/null
+// 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 <ModuleBase_IWidgetCreator.h>
+
+#include <string>
+#include <set>
+
+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<std::string>& 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<std::string> myModelWidgetTypes; /// types of widgets
+};
+
+#endif
#include <ModuleBase_WidgetCreatorFactory.h>
#include <SamplePanelPlugin_WidgetCreator.h>
+#include <SamplePanelPlugin_ModelWidgetCreator.h>
// the only created instance of this plugin
static SamplePanelPlugin_Plugin* MY_SAMPLE_PANEL_PLUGIN_INSTANCE = new SamplePanelPlugin_Plugin();
WidgetCreatorFactoryPtr aWidgetCreatorFactory = ModuleBase_WidgetCreatorFactory::get();
aWidgetCreatorFactory->registerCreator(
std::shared_ptr<SamplePanelPlugin_WidgetCreator>(new SamplePanelPlugin_WidgetCreator()));
+ aWidgetCreatorFactory->registerCreator(
+ std::shared_ptr<SamplePanelPlugin_ModelWidgetCreator>(new SamplePanelPlugin_ModelWidgetCreator()));
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
std::set<std::string> myPanelTypes; /// types of panels
};
-typedef std::shared_ptr<SamplePanelPlugin_WidgetCreator> SamplePanelWidgetCreatorPtr;
-
#endif
<plugin>
<workbench id="Sample">
<group id="Features">
- <feature id="QtPanelFeature" property_panel_id="QtPanel" title="Qt Panel Feature"/>
+ <!--<feature id="QtPanelFeature" property_panel_id="QtPanel" title="Qt Panel Feature"/>-->
+ <feature id="QtPanelFeature" title="Qt Panel Feature">
+ <QtModelWidget/>
+ </feature>
</group>
</workbench>
</plugin>