From: nds Date: Tue, 24 Jun 2014 08:58:23 +0000 (+0400) Subject: refs #80 - Sketch base GUI: create/draw point, circle and arc X-Git-Tag: V_0.4.4~264 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=49542ab918c826db5c10abda5be3787937113d94;p=modules%2Fshaper.git refs #80 - Sketch base GUI: create/draw point, circle and arc Double editor for the constraint value. --- diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 0d16ad432..08614013b 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -31,8 +31,8 @@ const static char* WDG_SELECTOR = "selector"; //Specific widget containers const static char* WDG_POINT_SELECTOR = "point_selector"; - const static char* WDG_FEATURE_SELECTOR = "feature_selector"; +const static char* WDG_DOUBLEVALUE_EDITOR = "doublevalue_editor"; const static char* _ID = "id"; //const static char* WORKBENCH_ID = "id"; diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index b617a5062..77a30bbad 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -9,6 +9,7 @@ SET(PROJECT_HEADERS ModuleBase_ModelWidget.h ModuleBase_WidgetBoolValue.h ModuleBase_WidgetDoubleValue.h + ModuleBase_WidgetEditor.h ModuleBase_WidgetFactory.h ModuleBase_WidgetFeature.h ModuleBase_WidgetPoint2D.h @@ -24,6 +25,7 @@ SET(PROJECT_SOURCES ModuleBase_ModelWidget.cpp ModuleBase_WidgetBoolValue.cpp ModuleBase_WidgetDoubleValue.cpp + ModuleBase_WidgetEditor.cpp ModuleBase_WidgetFactory.cpp ModuleBase_WidgetFeature.cpp ModuleBase_WidgetPoint2D.cpp diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index b7b3de3b8..5a13b4cc0 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -69,6 +69,9 @@ signals: /// \param theAttributeName a name of the attribute /// \param theEvent key release event void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent); + /// The signal about the widget is lost focus + /// \param theWidget the model base widget + void focusOutWidget(ModuleBase_ModelWidget* theWidget); protected: bool myHasDefaultValue; /// the boolean state whether the control has a default value diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp new file mode 100644 index 000000000..84b63cf28 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -0,0 +1,93 @@ +// File: ModuleBase_WidgetEditor.cpp +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include + +ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, + const Config_WidgetAPI* theData) +: ModuleBase_ModelWidget(theParent, theData) +{ + myEditor = new QLineEdit(0); + myEditor->setWindowFlags(Qt::ToolTip); + myEditor->setFocusPolicy(Qt::StrongFocus); + + connect(myEditor, SIGNAL(returnPressed()), this, SLOT(onStopEditing())); + connect(myEditor, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesChanged())); +} + +ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() +{ + delete myEditor; +} + +bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const +{ + DataPtr aData = theFeature->data(); + AttributeDoublePtr aReal = aData->real(attributeID()); + bool isOk; + double aValue = myEditor->text().toDouble(&isOk); + if (isOk && aReal->value() != aValue) { + //ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this; + //bool isBlocked = that->blockSignals(true); + aReal->setValue(aValue); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); + //that->blockSignals(isBlocked); + } + return true; +} + +bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature) +{ + boost::shared_ptr aData = theFeature->data(); + AttributeDoublePtr aRef = aData->real(attributeID()); + + //bool isBlocked = this->blockSignals(true); + myEditor->setText(QString::number(aRef->value())); + //this->blockSignals(isBlocked); + return true; +} + +void ModuleBase_WidgetEditor::focusTo() +{ + QPoint aPoint = QCursor::pos(); + + myEditor->move(aPoint); + myEditor->show(); + + myEditor->selectAll(); + myEditor->setFocus(); +} + +QWidget* ModuleBase_WidgetEditor::getControl() const +{ + return 0; +} + +QList ModuleBase_WidgetEditor::getControls() const +{ + QList aControls; + return aControls; +} + +void ModuleBase_WidgetEditor::onStopEditing() +{ + myEditor->hide(); + emit focusOutWidget(this); +} diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.h b/src/ModuleBase/ModuleBase_WidgetEditor.h new file mode 100644 index 000000000..e2f67a0cb --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetEditor.h @@ -0,0 +1,61 @@ +// File: ModuleBase_WidgetEditor.h +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_WidgetEditor_H +#define ModuleBase_WidgetEditor_H + +#include +#include "ModuleBase_ModelWidget.h" + +#include +#include + +class ModelAPI_Feature; +class QLineEdit; + +/**\class ModuleBase_WidgetEditor + * \ingroup GUI + * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls + */ +class MODULEBASE_EXPORT ModuleBase_WidgetEditor : public ModuleBase_ModelWidget +{ + Q_OBJECT +public: + /// Constructor + /// \theParent the parent object + /// \theParent the parent object + /// \theData the widget configuation. The attribute of the model widget is obtained from + ModuleBase_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData); + /// Destructor + virtual ~ModuleBase_WidgetEditor(); + + /// 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); + + /// Set focus to the first control of the current widget. The focus policy of the control is checked. + /// If the widget has the NonFocus focus policy, it is skipped. + virtual void focusTo(); + + /// Returns the internal parent wiget control, that can be shown anywhere + /// \returns the widget + QWidget* getControl() const; + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + +protected slots: + /// Slot to check the editing stop + void onStopEditing(); + +private: + QLineEdit* myEditor; + FeaturePtr myFeature; ///< the current widget feature + QStringList myFeatureKinds; ///< the kinds of possible features +}; + +#endif diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 1c372fd67..e651ba7d3 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -123,6 +124,9 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType } else if (theType == WDG_FEATURE_SELECTOR) { result = featureSelectorControl(theParent); + } else if (theType == WDG_DOUBLEVALUE_EDITOR) { + result = doubleValueEditor(theParent); + } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) { result = createContainer(theType, theParent); @@ -175,6 +179,13 @@ QWidget* ModuleBase_WidgetFactory::featureSelectorControl(QWidget* theParent) return aWidget->getControl(); } +QWidget* ModuleBase_WidgetFactory::doubleValueEditor(QWidget* theParent) +{ + ModuleBase_WidgetEditor* aWidget = new ModuleBase_WidgetEditor(theParent, myWidgetApi); + myModelWidgets.append(aWidget); + return 0; +} + QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const { return QString::fromStdString(theStdString); diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index e2162872c..b51c4bc32 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -39,6 +39,7 @@ protected: QWidget* doubleSpinBoxControl(QWidget* theParent); QWidget* pointSelectorControl(QWidget* theParent); QWidget* featureSelectorControl(QWidget* theParent); + QWidget* doubleValueEditor(QWidget* theParent); QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL); QWidget* selectorControl(QWidget* theParent); QWidget* booleanControl(QWidget* theParent); diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index a318a1280..bd5529244 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -53,7 +53,7 @@ PartSet_OperationFeatureCreate::~PartSet_OperationFeatureCreate() bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId) { - return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND /*|| + return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND || theId == SKETCH_CONSTRAINT_DISTANCE_KIND/*|| theId == SKETCH_CIRCLE_KIND || theId == SKETCH_ARC_KIND*/; } diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index f1d354e46..de1152c92 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -27,7 +27,7 @@ - +