diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2022-12-14 18:33:00 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-12-16 14:09:07 (GMT) |
commit | cb00fe08926b404b523c80021f17195baf1fdabd (patch) | |
tree | 8bf36357823d0fc43999e98544f1e3c3d421f262 /Source/QtDialog | |
parent | dcb1c9c080d9dc7231893baf8bd71713ed2fe021 (diff) | |
download | CMake-cb00fe08926b404b523c80021f17195baf1fdabd.zip CMake-cb00fe08926b404b523c80021f17195baf1fdabd.tar.gz CMake-cb00fe08926b404b523c80021f17195baf1fdabd.tar.bz2 |
cmake-gui: do not set search filter if regex is invalid
Fixes: #24248
Diffstat (limited to 'Source/QtDialog')
-rw-r--r-- | Source/QtDialog/CMakeSetupDialog.cxx | 3 | ||||
-rw-r--r-- | Source/QtDialog/EnvironmentDialog.cxx | 14 | ||||
-rw-r--r-- | Source/QtDialog/QCMakeCacheView.cxx | 8 | ||||
-rw-r--r-- | Source/QtDialog/QCMakeCacheView.h | 7 | ||||
-rw-r--r-- | Source/QtDialog/QCMakeWidgets.cxx | 34 | ||||
-rw-r--r-- | Source/QtDialog/QCMakeWidgets.h | 8 |
6 files changed, 56 insertions, 18 deletions
diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 01fa7bb..3d4d726 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -1344,7 +1344,8 @@ void CMakeSetupDialog::showUserChanges() void CMakeSetupDialog::setSearchFilter(const QString& str) { this->CacheValues->selectionModel()->clear(); - this->CacheValues->setSearchFilter(str); + const bool valid = this->CacheValues->setSearchFilter(str); + QtCMake::setSearchFilterColor(this->Search, valid); } void CMakeSetupDialog::doOutputContextMenu(QPoint pt) diff --git a/Source/QtDialog/EnvironmentDialog.cxx b/Source/QtDialog/EnvironmentDialog.cxx index bf89816..2752c0f 100644 --- a/Source/QtDialog/EnvironmentDialog.cxx +++ b/Source/QtDialog/EnvironmentDialog.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "EnvironmentDialog.h" +#include "QCMakeWidgets.h" #include <QDialogButtonBox> #include <QGridLayout> #include <QItemSelectionModel> @@ -110,14 +111,11 @@ EnvironmentDialog::EnvironmentDialog(const QProcessEnvironment& environment, &EnvironmentDialog::addEntry); QObject::connect(this->RemoveEntry, &QAbstractButton::clicked, this, &EnvironmentDialog::removeSelectedEntries); -#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) - QObject::connect(this->Search, &QLineEdit::textChanged, this->m_filter, - QOverload<const QString&>::of( - &EnvironmentSearchFilter::setFilterRegularExpression)); -#else - QObject::connect(this->Search, &QLineEdit::textChanged, this->m_filter, - &EnvironmentSearchFilter::setFilterFixedString); -#endif + QObject::connect( + this->Search, &QLineEdit::textChanged, [this](const QString& text) { + const bool valid = QtCMake::setSearchFilter(this->m_filter, text); + QtCMake::setSearchFilterColor(this->Search, valid); + }); QObject::connect(this->Environment->selectionModel(), &QItemSelectionModel::selectionChanged, this, &EnvironmentDialog::selectionChanged); diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx index f79d6fc..6f19b67 100644 --- a/Source/QtDialog/QCMakeCacheView.cxx +++ b/Source/QtDialog/QCMakeCacheView.cxx @@ -167,13 +167,9 @@ bool QCMakeCacheView::showAdvanced() const return this->AdvancedFilter->showAdvanced(); } -void QCMakeCacheView::setSearchFilter(const QString& s) +bool QCMakeCacheView::setSearchFilter(const QString& s) { -#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) - this->SearchFilter->setFilterRegularExpression(s); -#else - this->SearchFilter->setFilterFixedString(s); -#endif + return QtCMake::setSearchFilter(this->SearchFilter, s); } QCMakeCacheModel::QCMakeCacheModel(QObject* p) diff --git a/Source/QtDialog/QCMakeCacheView.h b/Source/QtDialog/QCMakeCacheView.h index c5e6dd4..89068ab 100644 --- a/Source/QtDialog/QCMakeCacheView.h +++ b/Source/QtDialog/QCMakeCacheView.h @@ -28,12 +28,13 @@ public: QSize sizeHint() const { return QSize(200, 200); } + // set the search filter string. any property key or value not matching will + // be filtered out + bool setSearchFilter(const QString&); + public slots: // set whether to show advanced entries void setShowAdvanced(bool); - // set the search filter string. any property key or value not matching will - // be filtered out - void setSearchFilter(const QString&); protected: QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers); diff --git a/Source/QtDialog/QCMakeWidgets.cxx b/Source/QtDialog/QCMakeWidgets.cxx index 03d6ed1..f1bb2f1 100644 --- a/Source/QtDialog/QCMakeWidgets.cxx +++ b/Source/QtDialog/QCMakeWidgets.cxx @@ -10,8 +10,13 @@ #include <QFileDialog> #include <QFileInfo> #include <QResizeEvent> +#include <QSortFilterProxyModel> #include <QToolButton> +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) +# include <QRegularExpression> +#endif + #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) # include <QFileSystemModel> #else @@ -155,3 +160,32 @@ QString QCMakeFileCompleter::pathFromIndex(const QModelIndex& idx) const { return QDir::fromNativeSeparators(QCompleter::pathFromIndex(idx)); } + +namespace QtCMake { +bool setSearchFilter(QSortFilterProxyModel* model, const QString& searchString) +{ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + QRegularExpression const regex(searchString, + QRegularExpression::CaseInsensitiveOption | + QRegularExpression::DontCaptureOption); + if (regex.isValid()) { + model->setFilterRegularExpression(regex); + return true; + } + model->setFilterFixedString(QString{}); + return false; +#else + model->setFilterFixedString(searchString); + return true; +#endif +} + +void setSearchFilterColor(QLineEdit* edit, bool valid) +{ + QPalette palette; + if (!valid) { + palette.setColor(QPalette::Base, Qt::red); + } + edit->setPalette(palette); +} +} diff --git a/Source/QtDialog/QCMakeWidgets.h b/Source/QtDialog/QCMakeWidgets.h index 9a2a27e..858a913 100644 --- a/Source/QtDialog/QCMakeWidgets.h +++ b/Source/QtDialog/QCMakeWidgets.h @@ -9,6 +9,7 @@ #include <QLineEdit> class QToolButton; +class QSortFilterProxyModel; // common widgets for Qt based CMake @@ -76,3 +77,10 @@ public: } } }; + +namespace QtCMake { +bool setSearchFilter(QSortFilterProxyModel* model, + const QString& searchString); + +void setSearchFilterColor(QLineEdit* edit, bool valid); +} |