Browse Source

ctkPythonConsole - Fix autocomplete preference lookup

The condition to skip the current preference was incorrect. A pref
should be skipped:
  - if there are dots in pref and
  - if the completion has already more dots than the pref


The pref should be skip, breaking the loop couldn't give other pref
a chance to be compared.
Jean-Christophe Fillion-Robin 14 years ago
parent
commit
780ceb423f
1 changed files with 10 additions and 5 deletions
  1. 10 5
      Libs/Scripting/Python/Widgets/ctkPythonConsole.cpp

+ 10 - 5
Libs/Scripting/Python/Widgets/ctkPythonConsole.cpp

@@ -141,7 +141,8 @@ public:
       this->setModel(new QStringListModel(attrs, this));
       this->setCaseSensitivity(Qt::CaseInsensitive);
       this->setCompletionPrefix(compareText.toLower());
-
+      
+      //qDebug() << "completion" << completion;
       // If a dot as been entered and if an item of possible
       // choices matches one of the preference list, it will be selected.
       QModelIndex preferredIndex = this->completionModel()->index(0, 0);
@@ -150,7 +151,11 @@ public:
         {
         foreach(const QString& pref, this->AutocompletePreferenceList)
           {
-          if (dotCount < pref.count('.'))
+          //qDebug() << "pref" << pref;
+          int dotPref = pref.count('.');
+          // Skip if there are dots in pref and if the completion has already more dots 
+          // than the pref
+          if ((dotPref != 0) && (dotCount > dotPref))
             {
             continue;
             }
@@ -161,17 +166,17 @@ public:
             {
             prefBeforeLastDot = pref.left(lastDot);
             }
-          // qDebug() << "prefLookup" << prefBeforeLastDot;
+          //qDebug() << "prefBeforeLastDot" << prefBeforeLastDot;
           if (!prefBeforeLastDot.isEmpty() && QString::compare(prefBeforeLastDot, lookup) != 0)
             {
-            break;
+            continue;
             }
           QString prefAfterLastDot = pref;
           if (lastDot != -1 )
             {
             prefAfterLastDot = pref.right(pref.size() - lastDot - 1);
             }
-          // qDebug() << "prefAfterLastDot" << prefAfterLastDot;
+          //qDebug() << "prefAfterLastDot" << prefAfterLastDot;
           QModelIndexList list = this->completionModel()->match(
                 this->completionModel()->index(0, 0), Qt::DisplayRole, QVariant(prefAfterLastDot));
           if (list.count() > 0)