]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1348 Creation of a Qt panel: providing additional sample for ModuleBase_ModelW...
authornds <nds@opencascade.com>
Wed, 6 Apr 2016 16:01:55 +0000 (19:01 +0300)
committernds <nds@opencascade.com>
Wed, 6 Apr 2016 16:01:55 +0000 (19:01 +0300)
src/SamplePanelPlugin/CMakeLists.txt
src/SamplePanelPlugin/SamplePanelPlugin_ModelWidget.cpp [new file with mode: 0755]
src/SamplePanelPlugin/SamplePanelPlugin_ModelWidget.h [new file with mode: 0755]
src/SamplePanelPlugin/SamplePanelPlugin_ModelWidgetCreator.cpp [new file with mode: 0755]
src/SamplePanelPlugin/SamplePanelPlugin_ModelWidgetCreator.h [new file with mode: 0755]
src/SamplePanelPlugin/SamplePanelPlugin_Plugin.cpp
src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.h
src/SamplePanelPlugin/plugin-SamplePanel.xml

index ab48f60733b9cef6089f16c57c6a39d25264b70c..ac37f294e6bfcd8530dde3a50afe84b927fd5311 100755 (executable)
@@ -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 (executable)
index 0000000..a5cf683
--- /dev/null
@@ -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 <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;
+}
+
diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidget.h b/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidget.h
new file mode 100755 (executable)
index 0000000..dfee20d
--- /dev/null
@@ -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 <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_ */
diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidgetCreator.cpp b/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidgetCreator.cpp
new file mode 100755 (executable)
index 0000000..e2509d1
--- /dev/null
@@ -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 <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;
+}
diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidgetCreator.h b/src/SamplePanelPlugin/SamplePanelPlugin_ModelWidgetCreator.h
new file mode 100755 (executable)
index 0000000..23d1dea
--- /dev/null
@@ -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 <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
index cc59adb701f66b340a61f858ea3d1620debed33e..88a9221b9a1c830c5e93f7217e24b7920deff5c0 100755 (executable)
@@ -12,6 +12,7 @@
 
 #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();
@@ -23,6 +24,8 @@ SamplePanelPlugin_Plugin::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);
index 548cbba1aa1cecd02fe0fe7f7a3d6df2fbd9bf98..5d1b09293590f120d1c9b46a77a1bea986222a6b 100755 (executable)
@@ -45,6 +45,4 @@ private:
   std::set<std::string> myPanelTypes; /// types of panels
 };
 
-typedef std::shared_ptr<SamplePanelPlugin_WidgetCreator> SamplePanelWidgetCreatorPtr;
-
 #endif
index f58e081494e27948309ee94c1dcc540ac0d73eb8..2682a3d6b208108a35b3f2aa6891d6f31ef63c30 100755 (executable)
@@ -3,7 +3,10 @@
 <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>