Salome HOME
Double value control improved, the improvement is currently commented.
authornds <nds@opencascade.com>
Fri, 18 Mar 2016 04:41:26 +0000 (07:41 +0300)
committernds <nds@opencascade.com>
Fri, 18 Mar 2016 04:41:26 +0000 (07:41 +0300)
src/ModuleBase/ModuleBase_ParamSpinBox.cpp
src/ModuleBase/ModuleBase_ParamSpinBox.h
src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp
src/ModuleBase/ModuleBase_WidgetDoubleValue.h

index 40b50fb1757ff1dca0a7f0dbbe0a3b3f88689685..f559eb68ae905e635206739f874b6c9a1fc10958 100644 (file)
 #include <QToolTip>
 #include <QApplication>
 
+#include <QStringListModel>
+#include <QCompleter>
+#include <QShortcut>
+
 #include <string>
 #include <iostream>
 
+//#define DEBUG_COMPLETE_WITH_PARAMETERS
 
 ModuleBase_ParamSpinBox::ModuleBase_ParamSpinBox(QWidget* theParent, int thePrecision)
     : ModuleBase_DoubleSpinBox(theParent, thePrecision),
       myAcceptVariables(true)
 {
+#ifdef DEBUG_COMPLETE_WITH_PARAMETERS
+  myCompleter = new QCompleter(this);
+  myCompleter->setWidget(this);
+  myCompleter->setCompletionMode(QCompleter::PopupCompletion);
+
+  myCompleterModel = new QStringListModel(this);
+  myCompleter->setModel(myCompleterModel);
+  // Use sorted model to accelerate completion (QCompleter will use binary search)
+  myCompleter->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
+  myCompleter->setCaseSensitivity(Qt::CaseInsensitive);
+
+  lineEdit()->setCompleter(myCompleter);
+#endif
+
   connectSignalsAndSlots();
 }
 
+void ModuleBase_ParamSpinBox::setCompletionList(QStringList& theList)
+{
+#ifdef DEBUG_COMPLETE_WITH_PARAMETERS
+  theList.sort();
+  theList.removeDuplicates();
+  myCompleterModel->setStringList(theList);
+#endif
+}
+
 /*!
  \brief Destructor.
  */
index 591d0cfd970658fa981a8ffc0f6a47ad69d3c117..6f2252ec81bdeb3cdbb6c4ed6b46450e9368a331 100644 (file)
@@ -8,6 +8,9 @@
 
 #include <QValidator>
 
+class QStringListModel;
+class QCompleter;
+
 /**
 * \ingroup GUI
 * An extension of a double spin box which let to use parameters and expressions for value definition
@@ -30,6 +33,10 @@ public:
    \param thePrecision a precision of values display
    */
   explicit ModuleBase_ParamSpinBox( QWidget* theParent = 0, int thePrecision = -12 );
+
+  /// Set list of completion strings
+  void setCompletionList(QStringList&);
+
   virtual ~ModuleBase_ParamSpinBox();
 
   virtual void stepBy(int);
@@ -52,7 +59,7 @@ public:
   /// Returns True if the input value contains variable
   bool hasVariable() const;
 
- protected:
+protected:
    /// Returns True if the given text contains variable
    /// \param theText a text string
   bool hasVariable(const QString& theText) const;
@@ -82,6 +89,9 @@ public:
   QString myTextValue;
 
   bool myAcceptVariables;
+
+  QStringListModel* myCompleterModel;
+  QCompleter* myCompleter;
 };
 
 #endif
index 672539acba696db961dc67cb45040ac419855270..fa4e22c18af5f9f90f58b7054304c164dce5fa78 100644 (file)
@@ -31,6 +31,8 @@
 #include <iostream>
 #endif
 
+//#define DEBUG_COMPLETE_WITH_PARAMETERS
+
 ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
                                                            const Config_WidgetAPI* theData)
     : ModuleBase_ModelWidget(theParent, theData)
@@ -95,6 +97,16 @@ ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
 {
 }
 
+void ModuleBase_WidgetDoubleValue::activateCustom()
+{
+  ModuleBase_ModelWidget::activateCustom();
+#ifdef DEBUG_COMPLETE_WITH_PARAMETERS
+  QStringList aParameters;
+  ModuleBase_Tools::getParameters(aParameters);
+  mySpinBox->setCompletionList(aParameters);
+#endif
+}
+
 bool ModuleBase_WidgetDoubleValue::resetCustom()
 {
   bool aDone = false;
index 0abf5b526c99f2fcd77ee2feb9d34ec4f65e09a5..e77b17cc35636d48fedc49f137d8e53307bbfdc6 100644 (file)
@@ -35,6 +35,9 @@ Q_OBJECT
 
   virtual ~ModuleBase_WidgetDoubleValue();
 
+  /// The methiod called when widget is activated
+  virtual void activateCustom();
+
   /// Select the internal content if it can be selected. It is empty in the default realization
   virtual void selectContent();