From 2734393c7c19899fca7e7c36577b31317887a9c9 Mon Sep 17 00:00:00 2001 From: sbh Date: Fri, 6 Mar 2015 11:23:59 +0300 Subject: [PATCH] Property pannel refactoring: focus processing in paged widgets --- src/Config/Config_WidgetAPI.cpp | 6 +- src/Config/Config_WidgetAPI.h | 2 +- src/ModuleBase/CMakeLists.txt | 6 + src/ModuleBase/ModuleBase_IModule.h | 5 +- src/ModuleBase/ModuleBase_PageBase.cpp | 54 +++++ src/ModuleBase/ModuleBase_PageBase.h | 44 ++++ src/ModuleBase/ModuleBase_PageGroupBox.cpp | 50 +++++ src/ModuleBase/ModuleBase_PageGroupBox.h | 39 ++++ src/ModuleBase/ModuleBase_PageWidget.cpp | 50 +++++ src/ModuleBase/ModuleBase_PageWidget.h | 38 ++++ src/ModuleBase/ModuleBase_WidgetFactory.cpp | 235 +++++++------------- src/ModuleBase/ModuleBase_WidgetFactory.h | 55 +---- src/ModuleBase/ModuleBase_WidgetSwitch.cpp | 17 +- src/ModuleBase/ModuleBase_WidgetSwitch.h | 25 ++- src/ModuleBase/ModuleBase_WidgetToolbox.cpp | 6 + src/ModuleBase/ModuleBase_WidgetToolbox.h | 3 + src/PartSet/PartSet_Module.cpp | 7 +- src/PartSet/PartSet_Module.h | 5 +- src/XGUI/XGUI_PropertyPanel.cpp | 33 ++- src/XGUI/XGUI_PropertyPanel.h | 10 +- src/XGUI/XGUI_Workshop.cpp | 1 - 21 files changed, 441 insertions(+), 250 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_PageBase.cpp create mode 100644 src/ModuleBase/ModuleBase_PageBase.h create mode 100644 src/ModuleBase/ModuleBase_PageGroupBox.cpp create mode 100644 src/ModuleBase/ModuleBase_PageGroupBox.h create mode 100644 src/ModuleBase/ModuleBase_PageWidget.cpp create mode 100644 src/ModuleBase/ModuleBase_PageWidget.h diff --git a/src/Config/Config_WidgetAPI.cpp b/src/Config/Config_WidgetAPI.cpp index bcf543bd1..1249f9ab8 100644 --- a/src/Config/Config_WidgetAPI.cpp +++ b/src/Config/Config_WidgetAPI.cpp @@ -72,16 +72,16 @@ std::string Config_WidgetAPI::widgetType() const return result; } -bool Config_WidgetAPI::isContainerWidget() const +bool Config_WidgetAPI::isGroupBoxWidget() const { return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP, - NULL); + NULL); } bool Config_WidgetAPI::isPagedWidget() const { return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH, - NULL); + NULL); } std::string Config_WidgetAPI::getProperty(const char* thePropName) const diff --git a/src/Config/Config_WidgetAPI.h b/src/Config/Config_WidgetAPI.h index a44ce55a4..e9531e49f 100644 --- a/src/Config/Config_WidgetAPI.h +++ b/src/Config/Config_WidgetAPI.h @@ -40,7 +40,7 @@ class CONFIG_EXPORT Config_WidgetAPI //! Returns name of widget's node (attribute) std::string widgetType() const; //! Returns true if widget has container type, which means it able to contain other widgets - bool isContainerWidget() const; + bool isGroupBoxWidget() const; //! Returns true if widget has page type; //! Page is container widget with combo box control to switch between pages bool isPagedWidget() const; diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 810481853..ea3235e19 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -45,6 +45,9 @@ SET(PROJECT_HEADERS ModuleBase_Preferences.h ModuleBase_ActionInfo.h ModuleBase_WidgetToolbox.h + ModuleBase_PageBase.h + ModuleBase_PageWidget.h + ModuleBase_PageGroupBox.h ) SET(PROJECT_SOURCES @@ -80,6 +83,9 @@ SET(PROJECT_SOURCES ModuleBase_Preferences.cpp ModuleBase_ActionInfo.cpp ModuleBase_WidgetToolbox.cpp + ModuleBase_PageBase.cpp + ModuleBase_PageWidget.cpp + ModuleBase_PageGroupBox.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 3c3d33878..9d59e0ffe 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -86,9 +86,8 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \param theWidgetApi the widget configuation. The attribute of the model widget is obtained from /// \param theParentId is Id of a parent of the current attribute /// \param theModelWidgets list of widget objects - virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent, - Config_WidgetAPI* theWidgetApi, std::string theParentId, - QList& theModelWidgets) + virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent, + Config_WidgetAPI* theWidgetApi, std::string theParentId) { return 0; } diff --git a/src/ModuleBase/ModuleBase_PageBase.cpp b/src/ModuleBase/ModuleBase_PageBase.cpp new file mode 100644 index 000000000..5adaebf34 --- /dev/null +++ b/src/ModuleBase/ModuleBase_PageBase.cpp @@ -0,0 +1,54 @@ +/* + * ModuleBase_PageBase.cpp + * + * Created on: Mar 4, 2015 + * Author: sbh + */ + +#include +#include + +#include + +class QWidget; + +ModuleBase_PageBase::ModuleBase_PageBase() +{ + +} + +ModuleBase_PageBase::~ModuleBase_PageBase() +{ + +} + +void ModuleBase_PageBase::addModelWidget(ModuleBase_ModelWidget* theWidget) +{ + placeModelWidget(theWidget); + myWidgetList.append(theWidget); +} + +void ModuleBase_PageBase::addPageWidget(ModuleBase_PageBase* thePage) +{ + placePageWidget(thePage); +} + +void ModuleBase_PageBase::clearPage() +{ + qDeleteAll(pageLayout()->children()); + myWidgetList.clear(); +} + + +void ModuleBase_PageBase::takeFocus() +{ + if(myWidgetList.isEmpty()) + return; + + myWidgetList.first()->focusTo(); +} + +QList ModuleBase_PageBase::modelWidgets() +{ + return myWidgetList; +} diff --git a/src/ModuleBase/ModuleBase_PageBase.h b/src/ModuleBase/ModuleBase_PageBase.h new file mode 100644 index 000000000..3b8bdf352 --- /dev/null +++ b/src/ModuleBase/ModuleBase_PageBase.h @@ -0,0 +1,44 @@ +/* + * ModuleBase_PageBase.h + * + * Created on: Mar 4, 2015 + * Author: sbh + */ + +#ifndef MODULEBASE_PAGEBASE_H_ +#define MODULEBASE_PAGEBASE_H_ + +#include +#include + +class ModuleBase_ModelWidget; +class QLayout; +class QWidget; + +/*! + * Represent a property panel's list of ModuleBase_ModelWidgets. + */ +class MODULEBASE_EXPORT ModuleBase_PageBase +{ + public: + ModuleBase_PageBase(); + virtual ~ModuleBase_PageBase(); + + void addModelWidget(ModuleBase_ModelWidget* theWidget); + void addPageWidget(ModuleBase_PageBase* theWidget); + + void clearPage(); + void takeFocus(); + QList modelWidgets(); + + protected: + virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget) = 0; + virtual void placePageWidget(ModuleBase_PageBase* theWidget) = 0; + virtual QLayout* pageLayout() = 0; + + private: + QList myWidgetList; + +}; + +#endif /* MODULEBASE_PAGEBASE_H_ */ diff --git a/src/ModuleBase/ModuleBase_PageGroupBox.cpp b/src/ModuleBase/ModuleBase_PageGroupBox.cpp new file mode 100644 index 000000000..1043a02fb --- /dev/null +++ b/src/ModuleBase/ModuleBase_PageGroupBox.cpp @@ -0,0 +1,50 @@ +/* + * ModuleBase_PageGroupBox.cpp + * + * Created on: Mar 4, 2015 + * Author: sbh + */ + +#include +#include +#include + +#include + +ModuleBase_PageGroupBox::ModuleBase_PageGroupBox(QWidget* theParent) +: QGroupBox(theParent) +{ + myMainLayout = new QGridLayout(this); + ModuleBase_Tools::adjustMargins(myMainLayout); + setLayout(myMainLayout); +} + +ModuleBase_PageGroupBox::~ModuleBase_PageGroupBox() +{ +} + +void ModuleBase_PageGroupBox::placeModelWidget(ModuleBase_ModelWidget* theWidget) +{ + const int kCol = 0; + const int kRow = myMainLayout->count(); + myMainLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft); +} + +void ModuleBase_PageGroupBox::placePageWidget(ModuleBase_PageBase* theWidget) +{ + QWidget* aWidget = dynamic_cast(theWidget); + if (!aWidget) { + #ifdef _DEBUG + std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl; + #endif + return; + } + const int kCol = 0; + const int kRow = myMainLayout->count(); + myMainLayout->addWidget(aWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft); +} + +QLayout* ModuleBase_PageGroupBox::pageLayout() +{ + return myMainLayout; +} diff --git a/src/ModuleBase/ModuleBase_PageGroupBox.h b/src/ModuleBase/ModuleBase_PageGroupBox.h new file mode 100644 index 000000000..dfc1adae1 --- /dev/null +++ b/src/ModuleBase/ModuleBase_PageGroupBox.h @@ -0,0 +1,39 @@ +/* + * ModuleBase_PageGroupBox.h + * + * Created on: Mar 4, 2015 + * Author: sbh + */ + +#ifndef MODULEBASE_PAGEGROUPBOX_H_ +#define MODULEBASE_PAGEGROUPBOX_H_ + +#include +#include + +#include +#include + +class ModuleBase_ModelWidget; +class QGridLayout; + + +/*! + * Represent a property panel's list of ModuleBase_ModelWidgets. + */ +class MODULEBASE_EXPORT ModuleBase_PageGroupBox : public QGroupBox, public ModuleBase_PageBase +{ + public: + explicit ModuleBase_PageGroupBox(QWidget* theParent = 0); + virtual ~ModuleBase_PageGroupBox(); + + protected: + virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget); + virtual void placePageWidget(ModuleBase_PageBase* theWidget); + virtual QLayout* pageLayout(); + + private: + QGridLayout* myMainLayout; +}; + +#endif /* MODULEBASE_PAGEGROUPBOX_H_ */ diff --git a/src/ModuleBase/ModuleBase_PageWidget.cpp b/src/ModuleBase/ModuleBase_PageWidget.cpp new file mode 100644 index 000000000..a75a6cfba --- /dev/null +++ b/src/ModuleBase/ModuleBase_PageWidget.cpp @@ -0,0 +1,50 @@ +/* + * ModuleBase_PageWidget.cpp + * + * Created on: Mar 4, 2015 + * Author: sbh + */ + +#include +#include +#include + +#include + +ModuleBase_PageWidget::ModuleBase_PageWidget(QWidget* theParent) +: QFrame(theParent) +{ + myMainLayout = new QGridLayout(this); + ModuleBase_Tools::adjustMargins(myMainLayout); + setLayout(myMainLayout); +} + +ModuleBase_PageWidget::~ModuleBase_PageWidget() +{ +} + +void ModuleBase_PageWidget::placeModelWidget(ModuleBase_ModelWidget* theWidget) +{ + const int kCol = 0; + const int kRow = myMainLayout->count(); + myMainLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft); +} + +void ModuleBase_PageWidget::placePageWidget(ModuleBase_PageBase* theWidget) +{ + QWidget* aWidget = dynamic_cast(theWidget); + if (!aWidget) { + #ifdef _DEBUG + std::cout << "ModuleBase_PageWidget::placePageWidget: can not cast page" << std::endl; + #endif + return; + } + const int kCol = 0; + const int kRow = myMainLayout->count(); + myMainLayout->addWidget(aWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft); +} + +QLayout* ModuleBase_PageWidget::pageLayout() +{ + return myMainLayout; +} diff --git a/src/ModuleBase/ModuleBase_PageWidget.h b/src/ModuleBase/ModuleBase_PageWidget.h new file mode 100644 index 000000000..a39d66021 --- /dev/null +++ b/src/ModuleBase/ModuleBase_PageWidget.h @@ -0,0 +1,38 @@ +/* + * ModuleBase_PageWidget.h + * + * Created on: Mar 4, 2015 + * Author: sbh + */ + +#ifndef MODULEBASE_PAGEWIDGET_H_ +#define MODULEBASE_PAGEWIDGET_H_ + +#include +#include + +#include +#include + +class ModuleBase_ModelWidget; +class QGridLayout; + +/*! + * Represent a property panel's list of ModuleBase_ModelWidgets. + */ +class MODULEBASE_EXPORT ModuleBase_PageWidget : public QFrame, public ModuleBase_PageBase +{ + public: + explicit ModuleBase_PageWidget(QWidget* theParent = 0); + virtual ~ModuleBase_PageWidget(); + + protected: + virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget); + virtual void placePageWidget(ModuleBase_PageBase* theWidget); + virtual QLayout* pageLayout(); + + private: + QGridLayout* myMainLayout; +}; + +#endif /* MODULEBASE_PAGEWIDGET_H_ */ diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index c5e6e58e8..25f3c1979 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -28,6 +28,9 @@ #include #include #include +#include +#include +#include #include #include @@ -64,60 +67,67 @@ ModuleBase_WidgetFactory::~ModuleBase_WidgetFactory() delete myWidgetApi; } -void ModuleBase_WidgetFactory::createWidget(QWidget* theParent) +void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage) { myParentId = myWidgetApi->widgetId(); if (!myWidgetApi->toChildWidget()) return; - QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent); - bool isStretchLayout = false; + //bool isStretchLayout = false; + QWidget* aPageWidget = dynamic_cast(thePage); + if(!aPageWidget) { + #ifdef _DEBUG + std::cout << "ModuleBase_WidgetFactory::createWidget: can not reinterpret_cast thePage" << std::endl; + #endif + } do { //Iterate over each node std::string aWdgType = myWidgetApi->widgetType(); - //Create a widget (doublevalue, groupbox, toolbox, etc. - QWidget* aWidget = createWidgetByType(aWdgType, theParent); - if (aWidget) { - if (!myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) { - aWidgetLay->addWidget(aWidget); - } else { - aWidget->setVisible(false); - } - } - if (myWidgetApi->isContainerWidget()) { + // Create PageGroup TODO: extract + if (myWidgetApi->isGroupBoxWidget()) { //if current widget is groupbox (container) process it's children recursively QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)); - createWidget(aWidget); - ModuleBase_Tools::adjustMargins(aWidget); - QGroupBox* aGrBox = qobject_cast(aWidget); - aGrBox->setTitle(aGroupName); - } - if (myWidgetApi->isPagedWidget()) { - //If current widget is toolbox or switch-casebox then fetch all - //it's pages recursively and setup into the widget. - myWidgetApi->toChildWidget(); - do { - QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)); - QString aCaseId = qs(myWidgetApi->getProperty(_ID)); - QWidget* aPage = new QWidget(aWidget); - createWidget(aPage); - ModuleBase_Tools::adjustMargins(aPage); - if (aWdgType == WDG_SWITCH) { - ModuleBase_WidgetSwitch* aSwitch = qobject_cast(aWidget); - aSwitch->addPage(aPage, aPageName); - } else if (aWdgType == WDG_TOOLBOX) { - ModuleBase_WidgetToolbox* aToolbox = qobject_cast(aWidget); - aToolbox->addPage(aPage, aPageName, aCaseId); + ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(aPageWidget); + aPage->setTitle(aGroupName); + createWidget(aPage); + thePage->addPageWidget(aPage); + } else { + // Create a ModelWidget + ModuleBase_ModelWidget* aWidget = createWidgetByType(aWdgType, aPageWidget); + if (aWidget) { + if (!myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) { + thePage->addModelWidget(aWidget); + } else { + aWidget->setVisible(false); } - } while (myWidgetApi->toNextWidget()); - } - if (aWidget && !isStretchLayout) { - isStretchLayout = !hasExpandingControls(aWidget); + } + // Create PagedContainer TODO: extract + if (myWidgetApi->isPagedWidget()) { + //If current widget is toolbox or switch-casebox then fetch all + //it's pages recursively and setup into the widget. + myWidgetApi->toChildWidget(); + do { + QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)); + QString aCaseId = qs(myWidgetApi->getProperty(_ID)); + ModuleBase_PageBase* aPage = new ModuleBase_PageWidget(aWidget); + createWidget(aPage); + QWidget* aCasePageWidget = dynamic_cast(aPage); + if (aWdgType == WDG_SWITCH) { + ModuleBase_WidgetSwitch* aSwitch = qobject_cast(aWidget); + aSwitch->addPage(aCasePageWidget, aPageName); + } else if (aWdgType == WDG_TOOLBOX) { + ModuleBase_WidgetToolbox* aToolbox = qobject_cast(aWidget); + aToolbox->addPage(aCasePageWidget, aPageName, aCaseId); + } + } while (myWidgetApi->toNextWidget()); + } } +// if (aWidget && !isStretchLayout) { +// isStretchLayout = !hasExpandingControls(aWidget); +// } } while (myWidgetApi->toNextWidget()); - if (isStretchLayout) { - aWidgetLay->addStretch(1); - } - theParent->setLayout(aWidgetLay); +// if (isStretchLayout) { +// aWidgetLay->addStretch(1); +// } } bool ModuleBase_WidgetFactory::hasExpandingControls(QWidget* theParent) @@ -138,142 +148,59 @@ bool ModuleBase_WidgetFactory::hasExpandingControls(QWidget* theParent) return result; } -QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType, - QWidget* theParent) +ModuleBase_ModelWidget* ModuleBase_WidgetFactory +::createWidgetByType(const std::string& theType, QWidget* theParent) { - QWidget* result = NULL; - if (theType == WDG_DOUBLEVALUE) { - result = doubleSpinBoxControl(theParent); + ModuleBase_ModelWidget* result = NULL; + + if (theType == WDG_INFO) { + result = new ModuleBase_WidgetLabel(theParent, myWidgetApi, myParentId); - } else if (theType == WDG_INFO) { - result = labelControl(theParent); + } else if (theType == WDG_DOUBLEVALUE) { + result = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId); } else if (theType == WDG_SHAPE_SELECTOR) { - result = shapeSelectorControl(theParent); + result = new ModuleBase_WidgetShapeSelector(theParent, myWorkshop, myWidgetApi, myParentId); } else if (theType == WDG_BOOLVALUE) { - result = booleanControl(theParent); + result = new ModuleBase_WidgetBoolValue(theParent, myWidgetApi, myParentId); } else if (theType == WDG_DOUBLEVALUE_EDITOR) { - result = doubleValueEditor(theParent); + result = new ModuleBase_WidgetEditor(theParent, myWidgetApi, myParentId); } else if (theType == WDG_FILE_SELECTOR) { - result = fileSelectorControl(theParent); + result = new ModuleBase_WidgetFileSelector(theParent, myWidgetApi, myParentId); } else if (theType == WDG_CHOICE) { - result = choiceControl(theParent); + result = new ModuleBase_WidgetChoice(theParent, myWidgetApi,myParentId); } else if (theType == WDG_STRINGVALUE) { - result = lineEditControl(theParent); + result = new ModuleBase_WidgetLineEdit(theParent, myWidgetApi,myParentId); } else if (theType == WDG_MULTISELECTOR) { - result = multiSelectorControl(theParent); + result = new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi,myParentId); + + } else if (theType == WDG_TOOLBOX) { + result = new ModuleBase_WidgetToolbox(theParent, myWidgetApi, myParentId); - } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) { - result = createContainer(theType, theParent); + } else if (theType == WDG_SWITCH) { + result = new ModuleBase_WidgetSwitch(theParent, myWidgetApi, myParentId); + return result; + + } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) { + // Do nothing for "box" and "case" + result = NULL; } else { result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi, - myParentId, myModelWidgets); + myParentId); #ifdef _DEBUG if (!result) {qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type");} #endif } - return result; -} - -QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, QWidget* theParent) -{ - QWidget* aResult = NULL; - if (theType == WDG_GROUP || theType == WDG_CHECK_GROUP) { - QGroupBox* aGroupBox = new QGroupBox(theParent); - aGroupBox->setCheckable(theType == WDG_CHECK_GROUP); - aResult = aGroupBox; - } else if (theType == WDG_TOOLBOX) { - ModuleBase_WidgetToolbox* aWdg = new ModuleBase_WidgetToolbox(theParent, myWidgetApi, myParentId); - myModelWidgets.append(aWdg); - aResult = aWdg; - } else if (theType == WDG_SWITCH) { - aResult = new ModuleBase_WidgetSwitch(theParent); - } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) { - // Do nothing for "box" and "case" - aResult = NULL; + if (result) { + myModelWidgets.append(result); } -#ifdef _DEBUG - else {qDebug() << "ModuleBase_WidgetFactory::fillWidget: find bad container type";} -#endif - return aResult; -} - -QWidget* ModuleBase_WidgetFactory::labelControl(QWidget* theParent) -{ - ModuleBase_WidgetLabel* aWgt = - new ModuleBase_WidgetLabel(theParent, myWidgetApi, myParentId); - myModelWidgets.append(aWgt); - return aWgt; -} - -QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl(QWidget* theParent) -{ - ModuleBase_WidgetDoubleValue* aDblWgt = - new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId); - myModelWidgets.append(aDblWgt); - return aDblWgt; -} - -QWidget* ModuleBase_WidgetFactory::doubleValueEditor(QWidget* theParent) -{ - ModuleBase_WidgetEditor* aWidget = - new ModuleBase_WidgetEditor(theParent, myWidgetApi, myParentId); - myModelWidgets.append(aWidget); - return aWidget; -} - -QWidget* ModuleBase_WidgetFactory::shapeSelectorControl(QWidget* theParent) -{ - ModuleBase_WidgetShapeSelector* aSelector = - new ModuleBase_WidgetShapeSelector(theParent, myWorkshop, myWidgetApi, myParentId); - myModelWidgets.append(aSelector); - return aSelector; -} - -QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent) -{ - ModuleBase_WidgetBoolValue* aBoolWgt = - new ModuleBase_WidgetBoolValue(theParent, myWidgetApi, myParentId); - myModelWidgets.append(aBoolWgt); - return aBoolWgt; -} - -QWidget* ModuleBase_WidgetFactory::fileSelectorControl(QWidget* theParent) -{ - ModuleBase_WidgetFileSelector* aFileSelectorWgt = - new ModuleBase_WidgetFileSelector(theParent, myWidgetApi, myParentId); - myModelWidgets.append(aFileSelectorWgt); - return aFileSelectorWgt; -} - -QWidget* ModuleBase_WidgetFactory::choiceControl(QWidget* theParent) -{ - ModuleBase_WidgetChoice* aChoiceWgt = - new ModuleBase_WidgetChoice(theParent, myWidgetApi,myParentId); - myModelWidgets.append(aChoiceWgt); - return aChoiceWgt; -} - -QWidget* ModuleBase_WidgetFactory::lineEditControl(QWidget* theParent) -{ - ModuleBase_WidgetLineEdit* aLineEditWgt = - new ModuleBase_WidgetLineEdit(theParent, myWidgetApi,myParentId); - myModelWidgets.append(aLineEditWgt); - return aLineEditWgt; -} - -QWidget* ModuleBase_WidgetFactory::multiSelectorControl(QWidget* theParent) -{ - ModuleBase_WidgetMultiSelector* aMultiselectorWgt = - new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi,myParentId); - myModelWidgets.append(aMultiselectorWgt); - return aMultiselectorWgt; + return result; } QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index 71834e86d..1e1f29fa7 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -7,11 +7,11 @@ * Author: sbh */ -#ifndef ModuleBase_WidgetFactory_H_ -#define ModuleBase_WidgetFactory_H_ +#ifndef MODULEBASE_WIDGETFACTORY_H_ +#define MODULEBASE_WIDGETFACTORY_H_ -#include "ModuleBase.h" -#include "ModuleBase_ModelWidget.h" +#include +#include #include #include @@ -20,6 +20,7 @@ class QObject; class QWidget; class Config_WidgetAPI; class ModuleBase_IWorkshop; +class ModuleBase_PageBase; /** * \ingroup GUI @@ -38,7 +39,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory /// Creates content widget for property panel /// \param theParent a parent widget - void createWidget(QWidget* theParent); + void createWidget(ModuleBase_PageBase* theParent); /// Returns list of model widgets @@ -53,48 +54,8 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory /// Create widget by its type /// \param theType a type /// \param theParent a parent widget - QWidget* createWidgetByType(const std::string& theType, QWidget* theParent = NULL); - - /// Create a widget of container type - /// \param theType a type - /// \param theParent a parent widget - QWidget* createContainer(const std::string& theType, QWidget* theParent); - - /// Create label widget - /// \param theParent a parent widget - QWidget* labelControl(QWidget* theParent); - - /// Create double spin box widget - /// \param theParent a parent widget - QWidget* doubleSpinBoxControl(QWidget* theParent); - - /// Create double value editor widget - /// \param theParent a parent widget - QWidget* doubleValueEditor(QWidget* theParent); - - /// Create shape selector widget - /// \param theParent a parent widget - QWidget* shapeSelectorControl(QWidget* theParent); - - /// Create boolean input widget - /// \param theParent a parent widget - QWidget* booleanControl(QWidget* theParent); - - /// Create file selector widget - /// \param theParent a parent widget - QWidget* fileSelectorControl(QWidget* theParent); - - /// Create choice widget (combo box) - /// \param theParent a parent widget - QWidget* choiceControl(QWidget* theParent); - - /// Create line edit widget - /// \param theParent a parent widget - QWidget* lineEditControl(QWidget* theParent); - - /// Create multi selector widget - /// \param theParent a parent widget - QWidget* multiSelectorControl(QWidget* theParent); + ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, + QWidget* theParent = NULL); /// Convert STD string to QT string /// \param theStdString is STD string diff --git a/src/ModuleBase/ModuleBase_WidgetSwitch.cpp b/src/ModuleBase/ModuleBase_WidgetSwitch.cpp index e1571cab1..aec77a6b9 100644 --- a/src/ModuleBase/ModuleBase_WidgetSwitch.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSwitch.cpp @@ -8,20 +8,24 @@ */ #include +#include +#include #include #include #include -ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* parent) - : QFrame(parent) + +ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* theParent, const Config_WidgetAPI* theData, + const std::string& theParentId) +: ModuleBase_ModelWidget(theParent, theData, theParentId) { myMainLay = new QVBoxLayout(this); myMainLay->setContentsMargins(2, 4, 2, 2); myCombo = new QComboBox(this); myCombo->hide(); myMainLay->addWidget(myCombo); - this->setFrameShape(QFrame::StyledPanel); + //this->setFrameShape(QFrame::StyledPanel); connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setCurrentIndex(int))); connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(currentPageChanged(int))); @@ -31,6 +35,13 @@ ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch() { } +QList ModuleBase_WidgetSwitch::getControls() const +{ + QList aList; + aList << myCombo; + return aList; +} + int ModuleBase_WidgetSwitch::addPage(QWidget* theWidget, const QString& theName) { return insertPage(count(), theWidget, theName); diff --git a/src/ModuleBase/ModuleBase_WidgetSwitch.h b/src/ModuleBase/ModuleBase_WidgetSwitch.h index f105bc6fd..1f10c2eea 100644 --- a/src/ModuleBase/ModuleBase_WidgetSwitch.h +++ b/src/ModuleBase/ModuleBase_WidgetSwitch.h @@ -11,7 +11,7 @@ #define ModuleBase_WidgetSwitch_H_ #include -#include +#include class QComboBox; class QVBoxLayout; @@ -20,19 +20,31 @@ class QVBoxLayout; * \ingroup GUI * Implements a model widget for swithch as a container widget. It can be defined in XML with "switch" keyword */ -class MODULEBASE_EXPORT ModuleBase_WidgetSwitch : public QFrame +class MODULEBASE_EXPORT ModuleBase_WidgetSwitch : public ModuleBase_ModelWidget { -Q_OBJECT + Q_OBJECT public: /// Constructor /// \param parent a parent widget - ModuleBase_WidgetSwitch(QWidget* parent = NULL); + ModuleBase_WidgetSwitch(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId); virtual ~ModuleBase_WidgetSwitch(); + virtual bool restoreValue() { + return false; + } + + virtual QList getControls() const; + + virtual bool focusTo() { + return false; + } + /// Add a page to the widget /// \param theWidget a page widget /// \param theName a name of page - int addPage(QWidget * theWidget, const QString & theName); + int addPage(QWidget* theWidget, const QString & theName); /// Returns count of pages int count() const; @@ -94,6 +106,9 @@ signals: void currentPageChanged(int); protected: + virtual bool storeValueCustom() const { + return false; + } /// Update widget void refresh(); diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.cpp b/src/ModuleBase/ModuleBase_WidgetToolbox.cpp index 220be9b70..aeab11bbb 100644 --- a/src/ModuleBase/ModuleBase_WidgetToolbox.cpp +++ b/src/ModuleBase/ModuleBase_WidgetToolbox.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include @@ -71,6 +72,11 @@ QList ModuleBase_WidgetToolbox::getControls() const return aList; } +bool ModuleBase_WidgetToolbox::focusTo() +{ + return false; +} + bool ModuleBase_WidgetToolbox::storeValueCustom() const { // A rare case when plugin was not loaded. diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.h b/src/ModuleBase/ModuleBase_WidgetToolbox.h index c57c75e02..867623105 100644 --- a/src/ModuleBase/ModuleBase_WidgetToolbox.h +++ b/src/ModuleBase/ModuleBase_WidgetToolbox.h @@ -12,6 +12,8 @@ #include +class ModuleBase_PageBase; + class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget { Q_OBJECT @@ -22,6 +24,7 @@ class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget virtual bool restoreValue(); virtual QList getControls() const; + virtual bool focusTo(); int addPage(QWidget* theWidget, const QString& theName, const QString& theCaseId); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index d31bf8f7c..44accc6cc 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -436,9 +436,8 @@ void PartSet_Module::onVertexSelected() } } -QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent, - Config_WidgetAPI* theWidgetApi, std::string theParentId, - QList& theModelWidgets) +ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent, + Config_WidgetAPI* theWidgetApi, std::string theParentId) { XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); XGUI_Workshop* aWorkshop = aConnector->workshop(); @@ -471,8 +470,6 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch()); aWgt = aConstraintShapeSelectorWgt; } - if(aWgt) - theModelWidgets.append(aWgt); return aWgt; } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 2bf2f44b0..aa5215e75 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -52,9 +52,8 @@ public: virtual ~PartSet_Module(); /// Creates custom widgets for property panel - virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent, - Config_WidgetAPI* theWidgetApi, std::string theParentId, - QList& theModelWidgets); + virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent, + Config_WidgetAPI* theWidgetApi, std::string theParentId); /// Call back forlast tuning of property panel before operation performance virtual void propertyPanelDefined(ModuleBase_Operation* theOperation); diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 1779431f5..0f02c5d93 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -12,6 +12,8 @@ //#include #include #include +#include +#include #include #include @@ -31,7 +33,8 @@ XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent) : ModuleBase_IPropertyPanel(theParent), - myActiveWidget(NULL) + myActiveWidget(NULL), + myPanelPage(NULL) { this->setWindowTitle(tr("Property Panel")); QAction* aViewAct = this->toggleViewAction(); @@ -39,10 +42,10 @@ XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent) setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }"); QWidget* aContent = new QWidget(this); - myMainLayout = new QGridLayout(aContent); + QGridLayout* aMainLayout = new QGridLayout(aContent); const int kPanelColumn = 0; int aPanelRow = 0; - myMainLayout->setContentsMargins(3, 3, 3, 3); + aMainLayout->setContentsMargins(3, 3, 3, 3); this->setWidget(aContent); QFrame* aFrm = new QFrame(aContent); @@ -50,7 +53,7 @@ XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent) aFrm->setFrameShape(QFrame::Panel); QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm); ModuleBase_Tools::zeroMargins(aBtnLay); - myMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn); + aMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn); QStringList aBtnNames; aBtnNames << QString(PROP_PANEL_HELP) @@ -64,10 +67,9 @@ XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent) } aBtnLay->insertStretch(1, 1); - myCustomWidget = new QWidget(aContent); - myCustomWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); - myMainLayout->addWidget(myCustomWidget, aPanelRow, kPanelColumn); - setStretchEnabled(true); + myPanelPage = new ModuleBase_PageWidget(aContent); + myPanelPage->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); + aMainLayout->addWidget(myPanelPage, aPanelRow, kPanelColumn); } XGUI_PropertyPanel::~XGUI_PropertyPanel() @@ -79,7 +81,7 @@ void XGUI_PropertyPanel::cleanContent() if (myActiveWidget) myActiveWidget->deactivate(); myWidgets.clear(); - qDeleteAll(myCustomWidget->children()); + myPanelPage->clearPage(); myActiveWidget = NULL; setWindowTitle(tr("Property Panel")); } @@ -116,9 +118,10 @@ const QList& XGUI_PropertyPanel::modelWidgets() const return myWidgets; } -QWidget* XGUI_PropertyPanel::contentWidget() +ModuleBase_PageBase* XGUI_PropertyPanel::contentWidget() { - return myCustomWidget; + + return static_cast(myPanelPage); } void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature) @@ -162,14 +165,6 @@ void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget) //} } -void XGUI_PropertyPanel::setStretchEnabled(bool isEnabled) -{ - int aStretchIdx = myMainLayout->rowCount() - 1; - if (aStretchIdx < 0) - return; - myMainLayout->setRowStretch(aStretchIdx, isEnabled ? 1 : 0); -} - void XGUI_PropertyPanel::activateNextWidget() { activateNextWidget(myActiveWidget); diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index 5d1706042..cc9ba8aeb 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -20,6 +20,8 @@ class XGUI_ActionsMgr; class QKeyEvent; class QGridLayout; +class ModuleBase_PageBase; +class ModuleBase_PageWidget; /// Internal name of property panel widget const static char* PROP_PANEL = "property_panel_dock"; @@ -50,7 +52,7 @@ Q_OBJECT /// Returns main widget of the property panel, which children will be created /// by WidgetFactory using the XML definition - QWidget* contentWidget(); + ModuleBase_PageBase* contentWidget(); /// Brings back all widget created by widget factory for signal/slot /// connections and further processing @@ -72,9 +74,6 @@ Q_OBJECT /// Activate the next from current widget in the property panel virtual void activateNextWidget(); - /// \brief Enable/Disable stretch area in the panel - void setStretchEnabled(bool isEnabled); - /// Set Enable/Disable state of Cancel button /// \param theEnabled Enable/Disable state of Cancel button virtual void setCancelEnabled(bool theEnabled); @@ -104,9 +103,8 @@ Q_OBJECT virtual void activateWidget(ModuleBase_ModelWidget* theWidget); private: - QWidget* myCustomWidget; + ModuleBase_PageWidget* myPanelPage; QList myWidgets; - QGridLayout* myMainLayout; /// Currently active widget ModuleBase_ModelWidget* myActiveWidget; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 99311b558..ff3347b02 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -646,7 +646,6 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation) myPropertyPanel->cleanContent(); aFactory.createWidget(myPropertyPanel->contentWidget()); - ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget()); QList aWidgets = aFactory.getModelWidgets(); foreach (ModuleBase_ModelWidget* aWidget, aWidgets) { -- 2.30.2