X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetEditor.cpp;h=9774a52bbb86c664001846b2e9cf190a42ad1fe3;hb=dc488f733ac5d7f70745b5764442aa2399bc3c63;hp=f62eae3d3fbe4085328d8c643146d0e566c83850;hpb=fe28efc3b8215891d15aea3ba9b35a5eb0686dde;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index f62eae3d3..9774a52bb 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include @@ -22,69 +22,72 @@ #include #include #include +#include ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, - const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent, theData), myValue(0) + const Config_WidgetAPI* theData, + const std::string& theParentId) +: ModuleBase_WidgetDoubleValue(theParent, theData, theParentId) { } -ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() +ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, const std::string& theAttribute) +: ModuleBase_WidgetDoubleValue(theParent, 0, "") { - //delete myEditor; -} - -bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const -{ - DataPtr aData = theFeature->data(); - AttributeDoublePtr aReal = aData->real(attributeID()); - bool isOk; - if (isOk && aReal->value() != myValue) { - aReal->setValue(myValue); - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); - } - return true; + setAttributeID(theAttribute); } -bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature) +ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() { - boost::shared_ptr aData = theFeature->data(); - AttributeDoublePtr aRef = aData->real(attributeID()); - - myValue = aRef->value(); - return true; } -void ModuleBase_WidgetEditor::focusTo() +double editedValue(double theValue, bool& isDone) { - 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); + aEditor->setValidator(new QDoubleValidator(aEditor)); + 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 focusOutWidget(this); + isDone = aDlg.exec() == QDialog::Accepted; + double aValue = theValue; + if (isDone) + aValue = aEditor->text().toDouble(); + return aValue; } -QWidget* ModuleBase_WidgetEditor::getControl() const +bool ModuleBase_WidgetEditor::focusTo() { - return 0; + 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); + + return false; } -QList ModuleBase_WidgetEditor::getControls() const +void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature, const std::string theAttribute) { - QList aControls; - return aControls; -} + DataPtr aData = theFeature->data(); + AttributeDoublePtr aRef = aData->real(theAttribute); + double aValue = aRef->value(); + bool isDone; + aValue = editedValue(aValue, isDone); + if (isDone) + aRef->setValue(aValue); +}