Skip to content

Commit

Permalink
Gui: allow change ExpressionCompleter filter mode
Browse files Browse the repository at this point in the history
Fixes #4428

Filter mode set to Qt::MatchContains for tree view search and link
property editor object search.

Other usage of the completer (e.g. property editor, speadsheet) defaults
to Qt::MatchContains, but can be changed using parameter,

    BaseApp/Preferences/Expression/CompleterMatchExact
  • Loading branch information
realthunder authored and wwmayer committed Sep 13, 2020
1 parent 82038bb commit 4f5a2e9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Gui/DlgPropertyLink.cpp
Expand Up @@ -76,6 +76,7 @@ DlgPropertyLink::DlgPropertyLink(QWidget* parent)
ui->typeTree->hide();
ui->searchBox->installEventFilter(this);
ui->searchBox->setNoProperty(true);
ui->searchBox->setMatchExact(false);

timer = new QTimer(this);
timer->setSingleShot(true);
Expand Down
34 changes: 33 additions & 1 deletion src/Gui/ExpressionCompleter.cpp
Expand Up @@ -537,7 +537,11 @@ ExpressionLineEdit::ExpressionLineEdit(QWidget *parent, bool noProperty)
, block(true)
, noProperty(noProperty)
{
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(slotTextChanged(const QString&)));
auto handle = GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Expression");
matchExact = handle->GetBool("CompleterMatchExact", false);

connect(this, SIGNAL(textEdited(const QString&)), this, SLOT(slotTextChanged(const QString&)));
}

void ExpressionLineEdit::setDocumentObject(const App::DocumentObject * currentDocObj)
Expand All @@ -550,6 +554,10 @@ void ExpressionLineEdit::setDocumentObject(const App::DocumentObject * currentDo
completer = new ExpressionCompleter(currentDocObj, this, noProperty);
completer->setWidget(this);
completer->setCaseSensitivity(Qt::CaseInsensitive);
#if QT_VERSION>=QT_VERSION_CHECK(5,2,0)
if (!matchExact)
completer->setFilterMode(Qt::MatchContains);
#endif
connect(completer, SIGNAL(activated(QString)), this, SLOT(slotCompleteText(QString)));
connect(completer, SIGNAL(highlighted(QString)), this, SLOT(slotCompleteText(QString)));
connect(this, SIGNAL(textChanged2(QString,int)), completer, SLOT(slotUpdate(QString,int)));
Expand All @@ -562,6 +570,14 @@ void ExpressionLineEdit::setNoProperty(bool enabled) {
completer->setNoProperty(enabled);
}

void ExpressionLineEdit::setMatchExact(bool enabled) {
matchExact = enabled;
#if QT_VERSION>=QT_VERSION_CHECK(5,2,0)
if (completer)
completer->setFilterMode(matchExact ? Qt::MatchExactly : Qt::MatchContains);
#endif
}

bool ExpressionLineEdit::completerActive() const
{
return completer && completer->popup() && completer->popup()->isVisible();
Expand Down Expand Up @@ -607,9 +623,21 @@ ExpressionTextEdit::ExpressionTextEdit(QWidget *parent)
, completer(0)
, block(true)
{
auto handle = GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Expression");
matchExact = handle->GetBool("CompleterMatchExact", false);

connect(this, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
}

void ExpressionTextEdit::setMatchExact(bool enabled) {
matchExact = enabled;
#if QT_VERSION>=QT_VERSION_CHECK(5,2,0)
if (completer)
completer->setFilterMode(matchExact ? Qt::MatchExactly : Qt::MatchContains);
#endif
}

void ExpressionTextEdit::setDocumentObject(const App::DocumentObject * currentDocObj)
{
if (completer) {
Expand All @@ -619,6 +647,10 @@ void ExpressionTextEdit::setDocumentObject(const App::DocumentObject * currentDo

if (currentDocObj != 0) {
completer = new ExpressionCompleter(currentDocObj, this);
#if QT_VERSION>=QT_VERSION_CHECK(5,2,0)
if (!matchExact)
completer->setFilterMode(Qt::MatchContains);
#endif
completer->setWidget(this);
completer->setCaseSensitivity(Qt::CaseInsensitive);
connect(completer, SIGNAL(activated(QString)), this, SLOT(slotCompleteText(QString)));
Expand Down
4 changes: 4 additions & 0 deletions src/Gui/ExpressionCompleter.h
Expand Up @@ -68,6 +68,7 @@ class GuiExport ExpressionLineEdit : public QLineEdit {
bool completerActive() const;
void hideCompleter();
void setNoProperty(bool enabled=true);
void setMatchExact(bool enabled=true);
Q_SIGNALS:
void textChanged2(QString text, int pos);
public Q_SLOTS:
Expand All @@ -79,6 +80,7 @@ public Q_SLOTS:
ExpressionCompleter * completer;
bool block;
bool noProperty;
bool matchExact;
};

class GuiExport ExpressionTextEdit : public QPlainTextEdit {
Expand All @@ -88,6 +90,7 @@ class GuiExport ExpressionTextEdit : public QPlainTextEdit {
void setDocumentObject(const App::DocumentObject *currentDocObj);
bool completerActive() const;
void hideCompleter();
void setMatchExact(bool enabled=true);
protected:
void keyPressEvent(QKeyEvent * event);
Q_SIGNALS:
Expand All @@ -98,6 +101,7 @@ public Q_SLOTS:
private:
ExpressionCompleter * completer;
bool block;
bool matchExact;
};

}
Expand Down
1 change: 1 addition & 0 deletions src/Gui/Tree.cpp
Expand Up @@ -2838,6 +2838,7 @@ TreePanel::TreePanel(const char *name, QWidget* parent)
this, SLOT(showEditor()));

this->searchBox = new Gui::ExpressionLineEdit(this,true);
static_cast<ExpressionLineEdit*>(this->searchBox)->setMatchExact(false);
pLayout->addWidget(this->searchBox);
this->searchBox->hide();
this->searchBox->installEventFilter(this);
Expand Down

0 comments on commit 4f5a2e9

Please sign in to comment.