Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetExprEditor.cpp
index 4c37116b2a9fb15487402461c43ca7bdb0d283cf..5da885e1333d502f66d661a4eda3275dc316a790 100644 (file)
@@ -1,11 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-/*
- * ModuleBase_WidgetExprEditor.cpp
- *
- *  Created on: Aug 28, 2014
- *      Author: sbh
- */
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #include <ModuleBase_WidgetExprEditor.h>
 #include <ModuleBase_Tools.h>
 #include <QScrollBar>
 #include <QFontMetrics>
 #include <QPainter>
+#include <QStyle>
+#include <QAbstractItemView>
 
 #include <memory>
 #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 +127,6 @@ void ExpressionEditor::performCompletion(const QString& theCompletionPrefix)
 
 void ExpressionEditor::keyPressEvent(QKeyEvent* theEvent)
 {
-  bool anIsModified = myIsModified;
-
   if (myCompletedAndSelected && handledCompletedAndSelected(theEvent))
     return;
   myCompletedAndSelected = false;
@@ -137,7 +148,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 +184,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 );
@@ -206,7 +207,8 @@ void ExpressionEditor::paintEvent( QPaintEvent* theEvent )
     QPen anOldpen = aPainter.pen();
     aPainter.setPen( aColor );
     lineRect.adjust(minLB, 0, 0, 0);
-    QString elidedText = aFontMetrics.elidedText( myPlaceHolderText, Qt::ElideRight, lineRect.width() );
+    QString elidedText =
+      aFontMetrics.elidedText( myPlaceHolderText, Qt::ElideRight, lineRect.width() );
     aPainter.drawText( lineRect, va, elidedText );
     aPainter.setPen( anOldpen );
   }
@@ -214,16 +216,14 @@ void ExpressionEditor::paintEvent( QPaintEvent* theEvent )
 
 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);
@@ -241,20 +241,30 @@ ModuleBase_WidgetExprEditor::ModuleBase_WidgetExprEditor( QWidget* theParent,
   this->setLayout(aMainLay);
 
   connect(myEditor, SIGNAL(valueModified()), this, SIGNAL(valuesModified()));
-  connect(myEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*)));
+  connect(myEditor, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
+          this, SIGNAL(keyReleased(QObject*, QKeyEvent*)));
 }
 
 ModuleBase_WidgetExprEditor::~ModuleBase_WidgetExprEditor()
 {
 }
 
+void ModuleBase_WidgetExprEditor::activateCustom()
+{
+  ModuleBase_ModelWidget::activateCustom();
+
+  QStringList aParameters;
+  ModuleBase_Tools::getParameters(aParameters);
+  myEditor->setCompletionList(aParameters);
+}
+
 void ModuleBase_WidgetExprEditor::initializeValueByActivate()
 {
 }
 
-bool ModuleBase_WidgetExprEditor::storeValueCustom() const
+bool ModuleBase_WidgetExprEditor::storeValueCustom()
 {
-  // A rare case when plugin was not loaded. 
+  // A rare case when plugin was not loaded.
   if(!myFeature)
     return false;
   DataPtr aData = myFeature->data();
@@ -287,7 +297,7 @@ bool ModuleBase_WidgetExprEditor::storeValueCustom() const
 
 bool ModuleBase_WidgetExprEditor::restoreValueCustom()
 {
-  // A rare case when plugin was not loaded. 
+  // A rare case when plugin was not loaded.
   if(!myFeature)
     return false;
   DataPtr aData = myFeature->data();
@@ -314,10 +324,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;