From 759a12660edd93a3c402e36c67409d391ca04ad2 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 6 Jun 2014 16:32:01 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc Code correction to set the focus widget for all ModelWidget children. --- src/ModuleBase/CMakeLists.txt | 16 ++-- src/ModuleBase/ModuleBase_MetaWidget.cpp | 54 ------------- src/ModuleBase/ModuleBase_MetaWidget.h | 42 ---------- src/ModuleBase/ModuleBase_WidgetBoolValue.cpp | 76 ++++++++++++++++++ src/ModuleBase/ModuleBase_WidgetBoolValue.h | 45 +++++++++++ ...s.cpp => ModuleBase_WidgetDoubleValue.cpp} | 69 ++-------------- src/ModuleBase/ModuleBase_WidgetDoubleValue.h | 47 +++++++++++ src/ModuleBase/ModuleBase_WidgetFactory.cpp | 7 +- src/ModuleBase/ModuleBase_Widgets.h | 78 ------------------- 9 files changed, 186 insertions(+), 248 deletions(-) delete mode 100644 src/ModuleBase/ModuleBase_MetaWidget.cpp delete mode 100644 src/ModuleBase/ModuleBase_MetaWidget.h create mode 100644 src/ModuleBase/ModuleBase_WidgetBoolValue.cpp create mode 100644 src/ModuleBase/ModuleBase_WidgetBoolValue.h rename src/ModuleBase/{ModuleBase_Widgets.cpp => ModuleBase_WidgetDoubleValue.cpp} (58%) create mode 100644 src/ModuleBase/ModuleBase_WidgetDoubleValue.h delete mode 100644 src/ModuleBase/ModuleBase_Widgets.h diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 8679b5724..22c359484 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -2,30 +2,30 @@ INCLUDE(Common) SET(CMAKE_AUTOMOC ON) SET(PROJECT_HEADERS - ModuleBase.h + ModuleBase.h ModuleBase_IOperation.h ModuleBase_Operation.h ModuleBase_OperationDescription.h ModuleBase_ModelWidget.h + ModuleBase_WidgetBoolValue.h + ModuleBase_WidgetDoubleValue.h ModuleBase_WidgetFactory.h ModuleBase_WidgetPoint2D.h ModuleBase_WidgetSwitch.h - ModuleBase_MetaWidget.h - ModuleBase_SelectorWidget.h - ModuleBase_IWorkshop.h - ModuleBase_Widgets.h + ModuleBase_SelectorWidget.h + ModuleBase_IWorkshop.h ) SET(PROJECT_SOURCES ModuleBase_IOperation.cpp ModuleBase_Operation.cpp ModuleBase_OperationDescription.cpp + ModuleBase_WidgetBoolValue.cpp + ModuleBase_WidgetDoubleValue.cpp ModuleBase_WidgetFactory.cpp ModuleBase_WidgetPoint2D.cpp ModuleBase_WidgetSwitch.cpp - ModuleBase_MetaWidget.cpp - ModuleBase_SelectorWidget.cpp - ModuleBase_Widgets.cpp + ModuleBase_SelectorWidget.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModuleBase/ModuleBase_MetaWidget.cpp b/src/ModuleBase/ModuleBase_MetaWidget.cpp deleted file mode 100644 index ba8eb260d..000000000 --- a/src/ModuleBase/ModuleBase_MetaWidget.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - */ - -#include -#include - -#ifdef _DEBUG -#include -#endif - -ModuleBase_MetaWidget::ModuleBase_MetaWidget(QWidget* theWrapped) - : ModuleBase_ModelWidget(theWrapped->parent()), - myWrappedWidget(theWrapped) -{ - -} - -ModuleBase_MetaWidget::~ModuleBase_MetaWidget() -{ - -} - -bool ModuleBase_MetaWidget::storeValue(FeaturePtr theFeature) -{ - #ifdef _DEBUG - std::cout << "ModuleBase_MetaWidget::storeValue" - << myWrappedWidget->metaObject()->className() << std::endl; - #endif - return true; -} - -bool ModuleBase_MetaWidget::restoreValue(FeaturePtr theFeature) -{ - #ifdef _DEBUG - std::cout << "ModuleBase_MetaWidget::restoreValue" - << myWrappedWidget->metaObject()->className() << std::endl; - #endif - return true; -} - -bool ModuleBase_MetaWidget::focusTo(const std::string& theAttributeName) -{ - #ifdef _DEBUG - std::cout << "ModuleBase_MetaWidget::focusTo" - << myWrappedWidget->metaObject()->className() << std::endl; - #endif - return true; -} - -QList ModuleBase_MetaWidget::getControls() const -{ - return QList(); -} diff --git a/src/ModuleBase/ModuleBase_MetaWidget.h b/src/ModuleBase/ModuleBase_MetaWidget.h deleted file mode 100644 index 42504e0f0..000000000 --- a/src/ModuleBase/ModuleBase_MetaWidget.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - */ - -#ifndef MODULEBASE_METAWIDGET_H_ -#define MODULEBASE_METAWIDGET_H_ - -#include -#include - -#include - -#include - -#include - -/* - * - */ -class ModuleBase_MetaWidget : public ModuleBase_ModelWidget -{ -public: - MODULEBASE_EXPORT ModuleBase_MetaWidget(QWidget* theWrapped); - virtual ~ModuleBase_MetaWidget(); - //! Interface for saving widget's data into the data model - MODULEBASE_EXPORT virtual bool storeValue(FeaturePtr theFeature); - //! Interface for loading widget's data from the data model - MODULEBASE_EXPORT virtual bool restoreValue(FeaturePtr theFeature); - - /// Set focus to the current widget if it corresponds to the given attribute - /// \param theAttribute name - MODULEBASE_EXPORT virtual bool focusTo(const std::string& theAttributeName); - - /// Returns list of widget controls - /// \return a control list - virtual QList getControls() const; - -private: - QWidget* myWrappedWidget; -}; - -#endif /* MODULEBASE_METAWIDGET_H_ */ diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp new file mode 100644 index 000000000..d55bd18e0 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp @@ -0,0 +1,76 @@ +// File: ModuleBase_Widgets.h +// Created: 04 June 2014 +// Author: Vitaly Smetannikov + +#include + +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData) + : ModuleBase_ModelWidget(theParent) +{ + myAttributeID = theData->widgetId(); + QString aText = QString::fromStdString(theData->widgetLabel()); + QString aToolTip = QString::fromStdString(theData->widgetTooltip()); + QString aDefault = QString::fromStdString(theData->getProperty("default")); + + myCheckBox = new QCheckBox(aText, theParent); + myCheckBox->setToolTip(aToolTip); + myCheckBox->setChecked(aDefault == "true"); + + connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged())); +} + +ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue() +{ +} + +QWidget* ModuleBase_WidgetBoolValue::getControl() const +{ + return myCheckBox; +} + +bool ModuleBase_WidgetBoolValue::storeValue(FeaturePtr theFeature) const +{ + DataPtr aData = theFeature->data(); + boost::shared_ptr aBool = aData->boolean(myAttributeID); + + if (aBool->value() != myCheckBox->isChecked()) { + aBool->setValue(myCheckBox->isChecked()); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); + } + return true; +} + +bool ModuleBase_WidgetBoolValue::restoreValue(FeaturePtr theFeature) +{ + DataPtr aData = theFeature->data(); + boost::shared_ptr aRef = aData->boolean(myAttributeID); + + bool isBlocked = myCheckBox->blockSignals(true); + myCheckBox->setChecked(aRef->value()); + myCheckBox->blockSignals(isBlocked); + + return true; +} + +QList ModuleBase_WidgetBoolValue::getControls() const +{ + QList aList; + aList.append(myCheckBox); + return aList; +} diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.h b/src/ModuleBase/ModuleBase_WidgetBoolValue.h new file mode 100644 index 000000000..8753c4cfd --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.h @@ -0,0 +1,45 @@ +// File: ModuleBase_WidgetBoolValue.h +// Created: 04 June 2014 +// Author: Vitaly Smetannikov + +#ifndef ModuleBase_WidgetBoolValue_H +#define ModuleBase_WidgetBoolValue_H + +#include "ModuleBase.h" +#include "ModuleBase_ModelWidget.h" + +class Config_WidgetAPI; +class QWidget; +class QLabel; +class QDoubleSpinBox; +class QCheckBox; + +class MODULEBASE_EXPORT ModuleBase_WidgetBoolValue: public ModuleBase_ModelWidget +{ + Q_OBJECT +public: + ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData); + + virtual ~ModuleBase_WidgetBoolValue(); + + /// Saves the internal parameters to the given feature + /// \param theFeature a model feature to be changed + virtual bool storeValue(FeaturePtr theFeature) const; + + virtual bool restoreValue(FeaturePtr theFeature); + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + + /// Returns the internal parent wiget control, that can be shown anywhere + /// \returns the widget + QWidget* getControl() const; + +private: + std::string myAttributeID; + + QCheckBox* myCheckBox; +}; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_Widgets.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp similarity index 58% rename from src/ModuleBase/ModuleBase_Widgets.cpp rename to src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 0d810ece1..d65091fd1 100644 --- a/src/ModuleBase/ModuleBase_Widgets.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -2,7 +2,7 @@ // Created: 04 June 2014 // Author: Vitaly Smetannikov -#include "ModuleBase_Widgets.h" +#include #include #include @@ -21,7 +21,7 @@ #include -ModuleBase_DoubleValueWidget::ModuleBase_DoubleValueWidget(QWidget* theParent, const Config_WidgetAPI* theData) +ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, const Config_WidgetAPI* theData) : ModuleBase_ModelWidget(theParent) { myContainer = new QWidget(theParent); @@ -77,11 +77,11 @@ ModuleBase_DoubleValueWidget::ModuleBase_DoubleValueWidget(QWidget* theParent, c connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); } -ModuleBase_DoubleValueWidget::~ModuleBase_DoubleValueWidget() +ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue() { } -bool ModuleBase_DoubleValueWidget::storeValue(FeaturePtr theFeature) const +bool ModuleBase_WidgetDoubleValue::storeValue(FeaturePtr theFeature) const { DataPtr aData = theFeature->data(); boost::shared_ptr aReal = aData->real(myAttributeID); @@ -92,7 +92,7 @@ bool ModuleBase_DoubleValueWidget::storeValue(FeaturePtr theFeature) const return true; } -bool ModuleBase_DoubleValueWidget::restoreValue(FeaturePtr theFeature) +bool ModuleBase_WidgetDoubleValue::restoreValue(FeaturePtr theFeature) { DataPtr aData = theFeature->data(); boost::shared_ptr aRef = aData->real(myAttributeID); @@ -104,67 +104,10 @@ bool ModuleBase_DoubleValueWidget::restoreValue(FeaturePtr theFeature) return true; } -QList ModuleBase_DoubleValueWidget::getControls() const +QList ModuleBase_WidgetDoubleValue::getControls() const { QList aList; aList.append(myLabel); aList.append(mySpinBox); return aList; } - - -////////////////////////////////////////////////////////////////////////////////// -ModuleBase_BoolValueWidget::ModuleBase_BoolValueWidget(QWidget* theParent, const Config_WidgetAPI* theData) - : ModuleBase_ModelWidget(theParent) -{ - myAttributeID = theData->widgetId(); - QString aText = QString::fromStdString(theData->widgetLabel()); - QString aToolTip = QString::fromStdString(theData->widgetTooltip()); - QString aDefault = QString::fromStdString(theData->getProperty("default")); - - myCheckBox = new QCheckBox(aText, theParent); - myCheckBox->setToolTip(aToolTip); - myCheckBox->setChecked(aDefault == "true"); - - connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged())); -} - -ModuleBase_BoolValueWidget::~ModuleBase_BoolValueWidget() -{ -} - -QWidget* ModuleBase_BoolValueWidget::getControl() const -{ - return myCheckBox; -} - -bool ModuleBase_BoolValueWidget::storeValue(FeaturePtr theFeature) const -{ - DataPtr aData = theFeature->data(); - boost::shared_ptr aBool = aData->boolean(myAttributeID); - - if (aBool->value() != myCheckBox->isChecked()) { - aBool->setValue(myCheckBox->isChecked()); - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); - } - return true; -} - -bool ModuleBase_BoolValueWidget::restoreValue(FeaturePtr theFeature) -{ - DataPtr aData = theFeature->data(); - boost::shared_ptr aRef = aData->boolean(myAttributeID); - - bool isBlocked = myCheckBox->blockSignals(true); - myCheckBox->setChecked(aRef->value()); - myCheckBox->blockSignals(isBlocked); - - return true; -} - -QList ModuleBase_BoolValueWidget::getControls() const -{ - QList aList; - aList.append(myCheckBox); - return aList; -} diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h new file mode 100644 index 000000000..caab19556 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h @@ -0,0 +1,47 @@ +// File: ModuleBase_WidgetDoubleValue.h +// Created: 04 June 2014 +// Author: Vitaly Smetannikov + +#ifndef ModuleBase_WidgetDoubleValue_H +#define ModuleBase_WidgetDoubleValue_H + +#include "ModuleBase.h" +#include "ModuleBase_ModelWidget.h" + +class Config_WidgetAPI; +class QWidget; +class QLabel; +class QDoubleSpinBox; +class QCheckBox; + +class MODULEBASE_EXPORT ModuleBase_WidgetDoubleValue: public ModuleBase_ModelWidget +{ + Q_OBJECT +public: + ModuleBase_WidgetDoubleValue(QWidget* theParent, const Config_WidgetAPI* theData); + + virtual ~ModuleBase_WidgetDoubleValue(); + + /// Saves the internal parameters to the given feature + /// \param theFeature a model feature to be changed + virtual bool storeValue(FeaturePtr theFeature) const; + + virtual bool restoreValue(FeaturePtr theFeature); + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + + /// Returns the internal parent wiget control, that can be shown anywhere + /// \returns the widget + QWidget* getControl() const { return myContainer; } + +private: + std::string myAttributeID; + + QWidget* myContainer; + QLabel* myLabel; + QDoubleSpinBox* mySpinBox; +}; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 63646b956..1f2f6a673 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -12,7 +12,8 @@ #include #include #include -#include +#include +#include #include #include @@ -149,7 +150,7 @@ QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, Q QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl(QWidget* theParent) { - ModuleBase_DoubleValueWidget* aDblWgt = new ModuleBase_DoubleValueWidget(theParent, myWidgetApi); + ModuleBase_WidgetDoubleValue* aDblWgt = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi); QObject::connect(aDblWgt, SIGNAL(valuesChanged()), myOperation, SLOT(storeCustomValue())); myModelWidgets.append(aDblWgt); @@ -203,7 +204,7 @@ QWidget* ModuleBase_WidgetFactory::selectorControl(QWidget* theParent) QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent) { - ModuleBase_BoolValueWidget* aBoolWgt = new ModuleBase_BoolValueWidget(theParent, myWidgetApi); + ModuleBase_WidgetBoolValue* aBoolWgt = new ModuleBase_WidgetBoolValue(theParent, myWidgetApi); QObject::connect(aBoolWgt, SIGNAL(valuesChanged()), myOperation, SLOT(storeCustomValue())); myModelWidgets.append(aBoolWgt); diff --git a/src/ModuleBase/ModuleBase_Widgets.h b/src/ModuleBase/ModuleBase_Widgets.h deleted file mode 100644 index d8030f9ab..000000000 --- a/src/ModuleBase/ModuleBase_Widgets.h +++ /dev/null @@ -1,78 +0,0 @@ -// File: ModuleBase_Widgets.h -// Created: 04 June 2014 -// Author: Vitaly Smetannikov - -#ifndef ModuleBase_Widgets_H -#define ModuleBase_Widgets_H - -#include "ModuleBase.h" -#include "ModuleBase_ModelWidget.h" - -class Config_WidgetAPI; -class QWidget; -class QLabel; -class QDoubleSpinBox; -class QCheckBox; - -class MODULEBASE_EXPORT ModuleBase_DoubleValueWidget: public ModuleBase_ModelWidget -{ - Q_OBJECT -public: - ModuleBase_DoubleValueWidget(QWidget* theParent, const Config_WidgetAPI* theData); - - virtual ~ModuleBase_DoubleValueWidget(); - - /// Saves the internal parameters to the given feature - /// \param theFeature a model feature to be changed - virtual bool storeValue(FeaturePtr theFeature) const; - - virtual bool restoreValue(FeaturePtr theFeature); - - /// Returns list of widget controls - /// \return a control list - virtual QList getControls() const; - - /// Returns the internal parent wiget control, that can be shown anywhere - /// \returns the widget - QWidget* getControl() const { return myContainer; } - -private: - std::string myAttributeID; - - QWidget* myContainer; - QLabel* myLabel; - QDoubleSpinBox* mySpinBox; -}; - - -////////////////////////////////////////////////////////////////////////////////// - -class MODULEBASE_EXPORT ModuleBase_BoolValueWidget: public ModuleBase_ModelWidget -{ - Q_OBJECT -public: - ModuleBase_BoolValueWidget(QWidget* theParent, const Config_WidgetAPI* theData); - - virtual ~ModuleBase_BoolValueWidget(); - - /// Saves the internal parameters to the given feature - /// \param theFeature a model feature to be changed - virtual bool storeValue(FeaturePtr theFeature) const; - - virtual bool restoreValue(FeaturePtr theFeature); - - /// Returns list of widget controls - /// \return a control list - virtual QList getControls() const; - - /// Returns the internal parent wiget control, that can be shown anywhere - /// \returns the widget - QWidget* getControl() const; - -private: - std::string myAttributeID; - - QCheckBox* myCheckBox; -}; - -#endif \ No newline at end of file -- 2.39.2