]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Wed, 25 Jun 2014 12:27:14 +0000 (16:27 +0400)
committernds <natalia.donis@opencascade.com>
Wed, 25 Jun 2014 12:27:14 +0000 (16:27 +0400)
1. The widget editor shows the double value in the property panel.

src/ModuleBase/ModuleBase_WidgetEditor.cpp
src/ModuleBase/ModuleBase_WidgetEditor.h
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/PartSet/PartSet_OperationFeatureEdit.cpp

index fe901b9a1840cc1b579be609758b953b6656d00e..694e5a809deb39a7074c0f82b885a31578af6297 100644 (file)
 #include <QTimer>
 #include <QDialog>
 #include <QLayout>
+#include <QDoubleSpinBox>
 
 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<ModelAPI_Data> 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<QWidget*> ModuleBase_WidgetEditor::getControls() const
+void ModuleBase_WidgetEditor::focusTo()
 {
-  QList<QWidget*> 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);
 }
index 657e2303a3bedf2985d010d4fab3bcf51468841c..e75d4cebda4b7c171b743359b64f6ba3b27d83c4 100644 (file)
@@ -6,7 +6,7 @@
 #define ModuleBase_WidgetEditor_H
 
 #include <ModuleBase.h>
-#include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_WidgetDoubleValue.h"
 
 #include <QObject>
 #include <QStringList>
@@ -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<QWidget*> 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
index 8f97d85de8bd810437bd06894d4c62d03cdc97d1..eb132cb54c3985c991ad50ff400f86e316ba8f4b 100644 (file)
@@ -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
index d87a1b5b58b313ac9e3fbf647e7e93fd80ee803d..091595a6487c211c659cd2377118a918c94184fa 100644 (file)
@@ -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();
     }
   }
 }