Salome HOME
Issue #1477 Build Vertex - wrong selection in viewer
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetExprEditor.cpp
index a7e7878e65d52e34722b4cf43f88c2a758e09006..ed22ac55f76d1a41cc0e30a1c8bb15c4acb7ddcf 100644 (file)
@@ -36,7 +36,7 @@
 #include <string>
 
 ExpressionEditor::ExpressionEditor(QWidget* theParent)
-: QPlainTextEdit(theParent), myCompletedAndSelected(false), myIsModified(false)
+: QPlainTextEdit(theParent), myCompletedAndSelected(false)
 {
   myCompleter = new QCompleter(this);
   myCompleter->setWidget(this);
@@ -114,8 +114,6 @@ void ExpressionEditor::performCompletion(const QString& theCompletionPrefix)
 
 void ExpressionEditor::keyPressEvent(QKeyEvent* theEvent)
 {
-  bool anIsModified = myIsModified;
-
   if (myCompletedAndSelected && handledCompletedAndSelected(theEvent))
     return;
   myCompletedAndSelected = false;
@@ -137,7 +135,7 @@ void ExpressionEditor::keyPressEvent(QKeyEvent* theEvent)
     switch (theEvent->key()) {
       case Qt::Key_Enter:
       case Qt::Key_Return:
-        emit keyReleased(theEvent);
+        emit keyReleased(this, theEvent);
         // do not react to the Enter key, the property panel processes it
         return;
       break;
@@ -173,16 +171,6 @@ QString ExpressionEditor::placeHolderText() const
   return myPlaceHolderText;
 }
 
-bool ExpressionEditor::isModified() const
-{
-  return myIsModified;
-}
-
-void ExpressionEditor::clearModified()
-{
-  myIsModified = false;
-}
-
 void ExpressionEditor::paintEvent( QPaintEvent* theEvent )
 {
   QPlainTextEdit::paintEvent( theEvent );
@@ -212,27 +200,16 @@ void ExpressionEditor::paintEvent( QPaintEvent* theEvent )
   }
 }
 
-bool ExpressionEditor::focusNextPrevChild(bool theIsNext)
-{
-  if (myIsModified)
-    emit editingFinished();
-  emit valueStored();
-  emit focusNextPrev();
-  return QPlainTextEdit::focusNextPrevChild(theIsNext);
-}
-
 void ExpressionEditor::onTextChanged()
 {
-  myIsModified = true;
   emit valueModified();
 }
 
 
 ModuleBase_WidgetExprEditor::ModuleBase_WidgetExprEditor( QWidget* theParent,
                                                           const Config_WidgetAPI* theData,
-                                                          const std::string& theParentId,
                                                           const std::string& thePlaceHolder )
-    : ModuleBase_ModelWidget(theParent, theData, theParentId)
+: ModuleBase_ModelWidget(theParent, theData)
 {
   QVBoxLayout* aMainLay = new QVBoxLayout(this);
   ModuleBase_Tools::adjustMargins(aMainLay);
@@ -250,26 +227,35 @@ ModuleBase_WidgetExprEditor::ModuleBase_WidgetExprEditor( QWidget* theParent,
   this->setLayout(aMainLay);
 
   connect(myEditor, SIGNAL(valueModified()), this, SIGNAL(valuesModified()));
-  //connect(myEditor, SIGNAL(editingFinished()), this, SLOT(onTextChanged()));
-  connect(myEditor, SIGNAL(valueStored()), this, SLOT(onTextChanged()));
-  connect(myEditor, SIGNAL(focusNextPrev()), this, SIGNAL(focusNextPrev()));
-
-  connect(myEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*)));
-    /// The signal about key release on the control, that corresponds to the attribute
-  /// \param theEvent key release event
+  connect(myEditor, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
+          this, SIGNAL(keyReleased(QObject*, QKeyEvent*)));
 }
 
 ModuleBase_WidgetExprEditor::~ModuleBase_WidgetExprEditor()
 {
 }
 
-bool ModuleBase_WidgetExprEditor::storeValueCustom() const
+void ModuleBase_WidgetExprEditor::activateCustom()
+{
+  ModuleBase_ModelWidget::activateCustom();
+
+  QStringList aParameters;
+  ModuleBase_Tools::getParameters(aParameters);
+  myEditor->setCompletionList(aParameters);
+}
+
+void ModuleBase_WidgetExprEditor::initializeValueByActivate()
+{
+}
+
+bool ModuleBase_WidgetExprEditor::storeValueCustom()
 {
   // A rare case when plugin was not loaded. 
   if(!myFeature)
     return false;
   DataPtr aData = myFeature->data();
   AttributeStringPtr aStringAttr = aData->string(attributeID());
+
   QString aWidgetValue = myEditor->toPlainText();
   aStringAttr->setValue(aWidgetValue.toStdString());
   updateObject(myFeature);
@@ -324,10 +310,9 @@ QList<QWidget*> ModuleBase_WidgetExprEditor::getControls() const
 
 bool ModuleBase_WidgetExprEditor::processEnter()
 {
-  bool isModified = myEditor->isModified();
+  bool isModified = getValueState() == ModifiedInPP;
   if (isModified) {
     emit valuesChanged();
-    myEditor->clearModified();
     myEditor->selectAll();
   }
   return isModified;