From 23440b0dd71b7b6a0ce33ad5196bd1b348db26bd Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 4 Jul 2018 20:54:27 +0300 Subject: [PATCH] Provide completion on editing --- src/ModuleBase/ModuleBase_ParamSpinBox.cpp | 22 ++++++++++++++++------ src/ModuleBase/ModuleBase_ParamSpinBox.h | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp index d0f527331..97b8e3f22 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp @@ -209,14 +209,21 @@ bool ModuleBase_ParamSpinBox::hasVariable(const QString& theText) const return !isDouble; } -void ModuleBase_ParamSpinBox::showCompletion() +void ModuleBase_ParamSpinBox::showCompletion(bool checkPrefix) { myCompletePos = lineEdit()->cursorPosition(); int aStart, aEnd; QString aPrefix; aPrefix = getPrefix(aStart, aEnd); - myCompleter->setCompletionPrefix(aPrefix); - myCompleter->complete(); + if (checkPrefix) { + if (aPrefix.length() > 0) { + myCompleter->setCompletionPrefix(aPrefix); + myCompleter->complete(); + } + } else { + myCompleter->setCompletionPrefix(aPrefix); + myCompleter->complete(); + } } void ModuleBase_ParamSpinBox::keyReleaseEvent(QKeyEvent* e) @@ -225,7 +232,10 @@ void ModuleBase_ParamSpinBox::keyReleaseEvent(QKeyEvent* e) switch (e->key()) { case Qt::Key_Backspace: - showCompletion(); + if (myCompleter->popup()->isVisible()) { + myCompleter->popup()->hide(); + } + showCompletion(true); break; case Qt::Key_Return: case Qt::Key_Enter: @@ -237,14 +247,14 @@ void ModuleBase_ParamSpinBox::keyReleaseEvent(QKeyEvent* e) break; case Qt::Key_Space: if (e->modifiers() & Qt::ControlModifier) { - showCompletion(); + showCompletion(false); } break; default: aText = e->text(); if (aText.length() == 1) { QChar aChar = aText.at(0); if (isVariableSymbol(aChar)) { - showCompletion(); + showCompletion(true); } } } diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.h b/src/ModuleBase/ModuleBase_ParamSpinBox.h index 489d082fd..7e33da9c6 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.h +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.h @@ -142,7 +142,7 @@ private slots: private: QString getPrefix(int& theStart, int& theEnd) const; - void showCompletion(); + void showCompletion(bool checkPrefix); bool myIsEquation; bool myAcceptVariables; -- 2.39.2