Gui: allow change ExpressionCompleter filter mode

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
This commit is contained in:
Zheng, Lei
2020-09-06 01:44:39 +00:00
committed by wwmayer
parent a0ac281684
commit 49150836bd
4 changed files with 39 additions and 1 deletions

View File

@@ -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);

View File

@@ -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)
@@ -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)));
@@ -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();
@@ -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) {
@@ -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)));

View File

@@ -68,6 +68,7 @@ public:
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:
@@ -79,6 +80,7 @@ private:
ExpressionCompleter * completer;
bool block;
bool noProperty;
bool matchExact;
};
class GuiExport ExpressionTextEdit : public QPlainTextEdit {
@@ -88,6 +90,7 @@ public:
void setDocumentObject(const App::DocumentObject *currentDocObj);
bool completerActive() const;
void hideCompleter();
void setMatchExact(bool enabled=true);
protected:
void keyPressEvent(QKeyEvent * event);
Q_SIGNALS:
@@ -98,6 +101,7 @@ public Q_SLOTS:
private:
ExpressionCompleter * completer;
bool block;
bool matchExact;
};
}

View File

@@ -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);