]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Use ModelWidgets for filters GUI
authorvsv <vsv@opencascade.com>
Tue, 4 Jun 2019 13:06:48 +0000 (16:06 +0300)
committervsv <vsv@opencascade.com>
Tue, 4 Jun 2019 13:06:48 +0000 (16:06 +0300)
src/FiltersPlugin/CMakeLists.txt
src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp
src/FiltersPlugin/FiltersPlugin_Plugin.cpp
src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp
src/ModuleBase/ModuleBase_WidgetSelectionFilter.h

index 7587c49806c2b6e8804c1533c79055392f6a8cfa..17303eda7fe566d63a02fb02a5dec36f975f10ec 100644 (file)
@@ -25,6 +25,7 @@ SET(PROJECT_HEADERS
     FiltersPlugin_Selection.h
     FiltersPlugin_HorizontalFace.h
     FiltersPlugin_VerticalFace.h
+       FiltersPlugin_BelongsTo.h
 )
 
 SET(PROJECT_SOURCES
@@ -32,6 +33,7 @@ SET(PROJECT_SOURCES
     FiltersPlugin_Selection.cpp
     FiltersPlugin_HorizontalFace.cpp
     FiltersPlugin_VerticalFace.cpp
+       FiltersPlugin_BelongsTo.cpp
 )
 
 SET(PROJECT_LIBRARIES
index 0f4f9b58ab7a3b44a5d6f0d2a7621d234bbca1a3..854fc26c9c030dff5d6866a3c4af58a0cdae2b1a 100644 (file)
@@ -31,11 +31,11 @@ bool FiltersPlugin_BelongsTo::isOk(const GeomShapePtr& theShape,
 }
 
 static std::string XMLRepresentation =
-"<filter id = \"Belongs to\""
+"<filter id = \"Belongs to\">"
 " <multi_selector id=\"Belongs to\""
 "   label = \"Objects:\""
 "   tooltip = \"Select objects to limit selection.\""
-"   type_choice = \"objects\""
+"   type_choice = \"objects\">"
 " </multi_selector>"
 "</filter>";
 
index a5183c5330ae0db1f166cbd7e5abb819932124c0..d1e5f1063b7543789732837068e61faef6e009a2 100644 (file)
@@ -21,6 +21,7 @@
 #include "FiltersPlugin_Selection.h"
 #include "FiltersPlugin_HorizontalFace.h"
 #include "FiltersPlugin_VerticalFace.h"
+#include "FiltersPlugin_BelongsTo.h"
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Filter.h>
@@ -35,6 +36,7 @@ FiltersPlugin_Plugin::FiltersPlugin_Plugin()
   ModelAPI_FiltersFactory* aFactory = aMgr->filters();
   aFactory->registerFilter("HorizontalFaces", new FiltersPlugin_HorizontalFace);
   aFactory->registerFilter("VerticalFaces", new FiltersPlugin_VerticalFace);
+  aFactory->registerFilter("BelongsTo", new FiltersPlugin_BelongsTo);
 
   ModelAPI_Session::get()->registerPlugin(this);
 }
index d8b9233c8fb1ba1d8ec86dd5906ba7e8aadf1522..bccb9032b8a1f90bda986ca375bd0356625f64c5 100644 (file)
@@ -26,6 +26,7 @@
 #include "ModuleBase_PageWidget.h"
 #include "ModuleBase_WidgetMultiSelector.h"
 #include "ModuleBase_ResultPrs.h"
+#include "ModuleBase_WidgetFactory.h"
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_AttributeSelectionList.h>
@@ -124,17 +125,40 @@ void ModuleBase_FilterStarter::onFiltersLaunch()
 //*****************************************************************************
 //*****************************************************************************
 ModuleBase_FilterItem::ModuleBase_FilterItem(
-  const std::string& theFilter, FeaturePtr theSelection, QWidget* theParent)
-  : QWidget(theParent), myFilterID(theFilter),
-    mySelection(std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(theSelection))
+  const std::string& theFilter, ModuleBase_WidgetSelectionFilter* theParent)
+  : QWidget(theParent->filtersWidget()), myFilterID(theFilter),
+    mySelection(std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(theParent->feature()))
 {
   std::string aXmlString = ModelAPI_Session::get()->filters()->filter(theFilter)->xmlRepresentation();
+  if (aXmlString.length() == 0)
+    addItemRow(this);
+  else {
+    ModuleBase_WidgetFactory aFactory(aXmlString, theParent->workshop());
+    QVBoxLayout* aLayout = new QVBoxLayout(this);
+    ModuleBase_Tools::zeroMargins(aLayout);
+
+    QWidget* aItemRow = new QWidget(this);
+    addItemRow(aItemRow);
+    aLayout->addWidget(aItemRow);
+
+    ModuleBase_PageWidget* aParamsWgt = new ModuleBase_PageWidget(this);
+    aFactory.createWidget(aParamsWgt);
+    ModuleBase_Tools::zeroMargins(aParamsWgt->layout());
+    QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
+    foreach(ModuleBase_ModelWidget* aWidget, aWidgets) {
+      aWidget->setFeature(theParent->feature());
+    }
+    aLayout->addWidget(aParamsWgt);
+  }
+}
 
-  QHBoxLayout* aLayout = new QHBoxLayout(this);
+void ModuleBase_FilterItem::addItemRow(QWidget* theParent)
+{
+  QHBoxLayout* aLayout = new QHBoxLayout(theParent);
   ModuleBase_Tools::zeroMargins(aLayout);
 
   // Reverse filter button
-  myRevBtn = new QToolButton(this);
+  myRevBtn = new QToolButton(theParent);
   myRevBtn->setCheckable(true);
   myRevBtn->setChecked(false);
   myRevBtn->setAutoRaise(true);
@@ -144,9 +168,9 @@ ModuleBase_FilterItem::ModuleBase_FilterItem(
   aLayout->addWidget(myRevBtn);
 
   const std::string& aFilterName = ModelAPI_Session::get()->filters()->filter(myFilterID)->name();
-  aLayout->addWidget(new QLabel(aFilterName.c_str(), this), 1);
+  aLayout->addWidget(new QLabel(aFilterName.c_str(), theParent), 1);
 
-  QToolButton* aDelBtn = new QToolButton(this);
+  QToolButton* aDelBtn = new QToolButton(theParent);
   aDelBtn->setIcon(QIcon(":pictures/delete.png"));
   aDelBtn->setAutoRaise(true);
   aDelBtn->setToolTip(tr("Delete the filter"));
@@ -154,7 +178,6 @@ ModuleBase_FilterItem::ModuleBase_FilterItem(
   aLayout->addWidget(aDelBtn);
 }
 
-
 void ModuleBase_FilterItem::onReverse(bool theCheck)
 {
   mySelection->setReversed(myFilterID, theCheck);
@@ -294,8 +317,7 @@ void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex)
   }
   if (!aFilter.empty()) {
     myUseFilters.push_back(aFilter);
-    ModuleBase_FilterItem* aItem =
-      new ModuleBase_FilterItem(aFilter, myFeature, myFiltersWgt);
+    ModuleBase_FilterItem* aItem = new ModuleBase_FilterItem(aFilter, this);
     connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)),
       SLOT(onDeleteItem(ModuleBase_FilterItem*)));
     connect(aItem, SIGNAL(reversedItem(ModuleBase_FilterItem*)),
index 381ed5f4b9a4fb62acbd3def120b818c8d7c92bd..8753d12909042065b64be38a75032b6a599e95d3 100644 (file)
@@ -64,11 +64,13 @@ private:
 };
 
 
+class ModuleBase_WidgetSelectionFilter;
+
 class ModuleBase_FilterItem : public QWidget
 {
   Q_OBJECT
 public:
-  ModuleBase_FilterItem(const std::string& theFilter, FeaturePtr theSelection, QWidget* theParent);
+  ModuleBase_FilterItem(const std::string& theFilter, ModuleBase_WidgetSelectionFilter* theParent);
 
   std::string filter() const { return myFilterID; }
 
@@ -81,6 +83,8 @@ private slots:
   void onDelete();
 
 private:
+  void addItemRow(QWidget* theParent);
+
   std::string myFilterID;
   FiltersFeaturePtr mySelection;
   QToolButton* myRevBtn;
@@ -103,6 +107,10 @@ public:
   /// By default this slot does nothing
   virtual void onFeatureAccepted();
 
+  ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
+
+  QWidget* filtersWidget() const { return myFiltersWgt; }
+
 protected:
   /// Saves the internal parameters to the given feature (not ussed for this widget)
   /// \return True in success