From e6aea428c7da7751e753eac36b99e16b7e3166e4 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 25 Jun 2014 16:27:14 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc 1. The widget editor shows the double value in the property panel. --- src/ModuleBase/ModuleBase_WidgetEditor.cpp | 78 ++++++++------------ src/ModuleBase/ModuleBase_WidgetEditor.h | 22 ++---- src/ModuleBase/ModuleBase_WidgetFactory.cpp | 2 +- src/PartSet/PartSet_OperationFeatureEdit.cpp | 4 +- 4 files changed, 39 insertions(+), 67 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index fe901b9a1..694e5a809 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -22,82 +22,68 @@ #include #include #include +#include ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent, theData), myValue(0) +: ModuleBase_WidgetDoubleValue(theParent, theData) { } ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, const std::string& theAttribute) -: ModuleBase_ModelWidget(theParent, 0), myValue(0) +: ModuleBase_WidgetDoubleValue(theParent, 0) { - this->setAttributeID(theAttribute); + setAttributeID(theAttribute); } ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() { } -bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const +double editedValue(double theValue, bool& isDone) { - DataPtr aData = theFeature->data(); - AttributeDoublePtr aReal = aData->real(attributeID()); - if (aReal->value() != myValue) { - aReal->setValue(myValue); - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); - } - return true; -} - -bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature) -{ - boost::shared_ptr aData = theFeature->data(); - AttributeDoublePtr aRef = aData->real(attributeID()); - - myValue = aRef->value(); - return true; -} - -void ModuleBase_WidgetEditor::focusTo() -{ - QPoint aPoint = QCursor::pos(); - QDialog aDlg; aDlg.setWindowFlags(Qt::FramelessWindowHint); QHBoxLayout* aLay = new QHBoxLayout(&aDlg); aLay->setContentsMargins(0,0,0,0); - QLineEdit* aEditor = new QLineEdit(QString::number(myValue), &aDlg); - connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept())); + QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg); + QObject::connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept())); aLay->addWidget(aEditor); + QPoint aPoint = QCursor::pos(); aDlg.move(aPoint); - int aRes = aDlg.exec(); - - if (aRes == QDialog::Accepted) - myValue = aEditor->text().toDouble(); - - emit valuesChanged(); - emit focusOutWidget(this); -} -QWidget* ModuleBase_WidgetEditor::getControl() const -{ - return 0; + isDone = aDlg.exec() == QDialog::Accepted; + double aValue = theValue; + if (isDone) + aValue = aEditor->text().toDouble(); + return aValue; } -QList ModuleBase_WidgetEditor::getControls() const +void ModuleBase_WidgetEditor::focusTo() { - QList aControls; - return aControls; + double aValue = mySpinBox->value(); + bool isDone; + aValue = editedValue(aValue, isDone); + + if (isDone) { + bool isBlocked = mySpinBox->blockSignals(true); + mySpinBox->setValue(aValue); + mySpinBox->blockSignals(isBlocked); + } + emit valuesChanged(); + emit focusOutWidget(this); } void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature, const std::string theAttribute) { - ModuleBase_WidgetEditor anEditor(0, theAttribute); + DataPtr aData = theFeature->data(); + AttributeDoublePtr aRef = aData->real(theAttribute); + double aValue = aRef->value(); - anEditor.restoreValue(theFeature); - anEditor.focusTo(); - anEditor.storeValue(theFeature); + bool isDone; + aValue = editedValue(aValue, isDone); + if (isDone) + aRef->setValue(aValue); } diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.h b/src/ModuleBase/ModuleBase_WidgetEditor.h index 657e2303a..e75d4cebd 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.h +++ b/src/ModuleBase/ModuleBase_WidgetEditor.h @@ -6,7 +6,7 @@ #define ModuleBase_WidgetEditor_H #include -#include "ModuleBase_ModelWidget.h" +#include "ModuleBase_WidgetDoubleValue.h" #include #include @@ -18,7 +18,7 @@ class QLineEdit; * \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 +class MODULEBASE_EXPORT ModuleBase_WidgetEditor : public ModuleBase_WidgetDoubleValue { Q_OBJECT public: @@ -36,30 +36,18 @@ public: /// 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; - + /// Creates an editor for the real value and set the new value to the feature + /// \param theFeature the model feature + /// \param theAttribute the feature attribute static void editFeatureValue(FeaturePtr theFeature, const std::string theAttribute); private: FeaturePtr myFeature; ///< the current widget feature QStringList myFeatureKinds; ///< the kinds of possible features - double myValue; }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 8f97d85de..eb132cb54 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -193,7 +193,7 @@ QWidget* ModuleBase_WidgetFactory::doubleValueEditor(QWidget* theParent) { ModuleBase_WidgetEditor* aWidget = new ModuleBase_WidgetEditor(theParent, myWidgetApi); myModelWidgets.append(aWidget); - return 0; + return aWidget->getControl(); } QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const diff --git a/src/PartSet/PartSet_OperationFeatureEdit.cpp b/src/PartSet/PartSet_OperationFeatureEdit.cpp index d87a1b5b5..091595a64 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.cpp +++ b/src/PartSet/PartSet_OperationFeatureEdit.cpp @@ -140,9 +140,7 @@ void PartSet_OperationFeatureEdit::mouseDoubleClick(QMouseEvent* theEvent, Handl double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid); if (isValid) { ModuleBase_WidgetEditor::editFeatureValue(feature(), CONSTRAINT_ATTR_VALUE); - - //QPoint aPos = theEvent->globalPos(); - //myEditor->start(aPos, aValue); + flushUpdated(); } } } -- 2.39.2