X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetEditor.cpp;h=29e07a1f3efb95bb39f6d5c61e9c620b4abc08ac;hb=0cea3be102af7247b2fe2c8035a1bb38b7bf82ae;hp=fe901b9a1840cc1b579be609758b953b6656d00e;hpb=56e28f354780915ff5c316bce7841a034599cca3;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index fe901b9a1..29e07a1f3 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -1,14 +1,18 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: ModuleBase_WidgetEditor.cpp // Created: 25 Apr 2014 // Author: Natalia ERMOLAEVA #include +#include +#include #include #include #include -#include +#include #include #include @@ -17,87 +21,83 @@ #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), myValue(0) + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId) { } -ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, const std::string& theAttribute) -: ModuleBase_ModelWidget(theParent, 0), myValue(0) -{ - this->setAttributeID(theAttribute); -} - ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() { } -bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const +void editedValue(double& outValue, QString& outText) { - 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)); + QMenu* aPopup = new QMenu(); + + QLineEdit* aEditor = new QLineEdit(QString::number(outValue), aPopup); + QWidgetAction* aLineEditAction = new QWidgetAction(aPopup); + aLineEditAction->setDefaultWidget(aEditor); + aPopup->addAction(aLineEditAction); + + aEditor->setFocus(); + aEditor->selectAll(); + QString anExpression("([0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)|([_a-zA-Z][a-zA-Z0-9_]*)"); + aEditor->setValidator(new QRegExpValidator(QRegExp(anExpression), aEditor)); + QObject::connect(aEditor, SIGNAL(returnPressed()), aLineEditAction, SIGNAL(triggered())); + QObject::connect(aLineEditAction, SIGNAL(triggered()), aPopup, SLOT(hide())); + + QAction* aResult = aPopup->exec(QCursor::pos()); + outText = aEditor->text(); + bool isDouble; + double aValue = outText.toDouble(&isDouble); + if (isDouble) { + outValue = aValue; + outText = ""; // return empty string, if it's can be converted to a double } - return true; + aPopup->deleteLater(); } -bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature) +bool ModuleBase_WidgetEditor::focusTo() { - boost::shared_ptr aData = theFeature->data(); - AttributeDoublePtr aRef = aData->real(attributeID()); + // nds: it seems, that the timer is not necessary anymore + + // We can not launch here modal process for value editing because + // it can be called on other focusOutWidget event and will block it + //QTimer::singleShot(1, this, SLOT(showPopupEditor())); + + showPopupEditor(); - myValue = aRef->value(); return true; } -void ModuleBase_WidgetEditor::focusTo() +void ModuleBase_WidgetEditor::showPopupEditor() { - 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())); - aLay->addWidget(aEditor); - - aDlg.move(aPoint); - int aRes = aDlg.exec(); - - if (aRes == QDialog::Accepted) - myValue = aEditor->text().toDouble(); - + // we need to emit the focus in event manually in order to save the widget as an active + // in the property panel before the mouse leave event happens in the viewer. The module + // ask an active widget and change the feature visualization if the widget is not the current one. + emit focusInWidget(this); + + // nds: it seems, that the envents processing is not necessary anymore + // White while all events will be processed + //QApplication::processEvents(); + double aValue = mySpinBox->value(); + QString aText; + editedValue(aValue, aText); + if (aText.isEmpty()) { + ModuleBase_Tools::setSpinValue(mySpinBox, aValue); + } else { + ModuleBase_Tools::setSpinText(mySpinBox, aText); + } emit valuesChanged(); emit focusOutWidget(this); } - -QWidget* ModuleBase_WidgetEditor::getControl() const -{ - return 0; -} - -QList ModuleBase_WidgetEditor::getControls() const -{ - QList aControls; - return aControls; -} - -void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature, const std::string theAttribute) -{ - ModuleBase_WidgetEditor anEditor(0, theAttribute); - - anEditor.restoreValue(theFeature); - anEditor.focusTo(); - anEditor.storeValue(theFeature); -}