From f418c935cc129eccc1e640b5c27f0589ad6acec5 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 4 Jun 2019 16:06:48 +0300 Subject: [PATCH] Use ModelWidgets for filters GUI --- src/FiltersPlugin/CMakeLists.txt | 2 + src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp | 4 +- src/FiltersPlugin/FiltersPlugin_Plugin.cpp | 2 + .../ModuleBase_WidgetSelectionFilter.cpp | 42 ++++++++++++++----- .../ModuleBase_WidgetSelectionFilter.h | 10 ++++- 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/FiltersPlugin/CMakeLists.txt b/src/FiltersPlugin/CMakeLists.txt index 7587c4980..17303eda7 100644 --- a/src/FiltersPlugin/CMakeLists.txt +++ b/src/FiltersPlugin/CMakeLists.txt @@ -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 diff --git a/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp b/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp index 0f4f9b58a..854fc26c9 100644 --- a/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp +++ b/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp @@ -31,11 +31,11 @@ bool FiltersPlugin_BelongsTo::isOk(const GeomShapePtr& theShape, } static std::string XMLRepresentation = -"" " " " " ""; diff --git a/src/FiltersPlugin/FiltersPlugin_Plugin.cpp b/src/FiltersPlugin/FiltersPlugin_Plugin.cpp index a5183c533..d1e5f1063 100644 --- a/src/FiltersPlugin/FiltersPlugin_Plugin.cpp +++ b/src/FiltersPlugin/FiltersPlugin_Plugin.cpp @@ -21,6 +21,7 @@ #include "FiltersPlugin_Selection.h" #include "FiltersPlugin_HorizontalFace.h" #include "FiltersPlugin_VerticalFace.h" +#include "FiltersPlugin_BelongsTo.h" #include #include @@ -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); } diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp index d8b9233c8..bccb9032b 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp @@ -26,6 +26,7 @@ #include "ModuleBase_PageWidget.h" #include "ModuleBase_WidgetMultiSelector.h" #include "ModuleBase_ResultPrs.h" +#include "ModuleBase_WidgetFactory.h" #include #include @@ -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(theSelection)) + const std::string& theFilter, ModuleBase_WidgetSelectionFilter* theParent) + : QWidget(theParent->filtersWidget()), myFilterID(theFilter), + mySelection(std::dynamic_pointer_cast(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 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*)), diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h index 381ed5f4b..8753d1290 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h @@ -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 -- 2.39.2