#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);
}
#define ModuleBase_WidgetEditor_H
#include <ModuleBase.h>
-#include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_WidgetDoubleValue.h"
#include <QObject>
#include <QStringList>
* \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:
/// 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