X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetExprEditor.h;h=310021975840233f1702942a2edbd228b0aeeb44;hb=f2f34e30b41047d12277ad87e1adf6c0e410e4ff;hp=41a209f20df0438c3fbaf0060c60c53dcc66de8e;hpb=dcf404632ceef566c6785bf95f9eee1b6159d32b;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetExprEditor.h b/src/ModuleBase/ModuleBase_WidgetExprEditor.h index 41a209f20..310021975 100644 --- a/src/ModuleBase/ModuleBase_WidgetExprEditor.h +++ b/src/ModuleBase/ModuleBase_WidgetExprEditor.h @@ -1,11 +1,22 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -/* - * ModuleBase_WidgetExprEditor.h - * - * Created on: Oct 8, 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 +// #ifndef MODULEBASE_WIDGETEXPREDITOR_H_ #define MODULEBASE_WIDGETEXPREDITOR_H_ @@ -14,6 +25,7 @@ #include #include +#include #include #include #include @@ -22,34 +34,75 @@ class QWidget; class QStringListModel; class QCompleter; +/** +* \ingroup GUI +* A multi-line text editor which lets to input formula and provides a list of completion strings +*/ class ExpressionEditor: public QPlainTextEdit { Q_OBJECT - public: + /// Constructor + /// \param theParent a parent widget explicit ExpressionEditor(QWidget* theParent = 0); virtual ~ExpressionEditor(); + /// Set list of completion strings void setCompletionList(QStringList&); + /// Set a text which will be shown when the listr is empty + void setPlaceHolderText( const QString& ); + + /// Returns placeholder list + QString placeHolderText() const; + public slots: - void insertCompletion(const QString&, bool isSingleWord = false); + /// Insert additional string for completion + /// \param theCompletion a string to insert + /// \param isSingleWord a flag shows that inserted string is single word or not + void insertCompletion(const QString& theCompletion, bool isSingleWord = false); + + /// Perform completion void performCompletion(); + /// A slot for processing text changed event + void onTextChanged(); + +signals: + /// The signal about text change in the text editor + void valueModified(); + + /// The signal about key release on the control, that corresponds to the attribute + /// \param theObject a sender of the event + /// \param theEvent key release event + void keyReleased(QObject* theObject, QKeyEvent* theEvent); + protected: + /// Perform completion by prefix + /// \param theCompletionPrefix a prefix for looking for completion void performCompletion(const QString& theCompletionPrefix); + + /// Redefinition of virtual method + /// \param theEvent a key press event virtual void keyPressEvent(QKeyEvent* theEvent); + + /// Key events processing + /// theEvent a key event bool handledCompletedAndSelected(QKeyEvent* theEvent); - private: + /// Redefinition of virtual method + virtual void paintEvent( QPaintEvent* ); + +private: QStringListModel* myCompleterModel; QCompleter* myCompleter; bool myCompletedAndSelected; + QString myPlaceHolderText; }; /** * \ingroup GUI -* TODO(sbh) add doc +* A Widget which provides an input of an expression */ class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget { @@ -58,27 +111,39 @@ class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWid /// Constructor /// \param theParent the parent object /// \param theData the widget configuration. - /// \param theParentId is Id of a parent of the current attribute - ModuleBase_WidgetExprEditor(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId); + /// \param thePlaceHolder a placeholder string + ModuleBase_WidgetExprEditor( QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& thePlaceHolder ); virtual ~ModuleBase_WidgetExprEditor(); - virtual bool restoreValue(); + /// The methiod called when widget is activated + virtual void activateCustom(); + /// Redefinition of virtual method virtual QList getControls() const; - public slots: - /// A slot for processing text changed event +protected slots: + /// A slot for processing text changed event void onTextChanged(); protected: + /// Returns true if the event is processed. + virtual bool processEnter(); + + /// Do not initialize value on the widget activation + virtual void initializeValueByActivate(); + /// Saves the internal parameters to the given feature /// \return True in success - virtual bool storeValueCustom() const; + virtual bool storeValueCustom(); + + /// Redefinition of virtual method + virtual bool restoreValueCustom(); private: /// A line edit control + QLabel* myResultLabel; ExpressionEditor* myEditor; };