summaryrefslogtreecommitdiffstats
path: root/Source/QtDialog/QCMakeWidgets.cxx
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2022-12-14 18:33:00 (GMT)
committerBrad King <brad.king@kitware.com>2022-12-16 14:09:07 (GMT)
commitcb00fe08926b404b523c80021f17195baf1fdabd (patch)
tree8bf36357823d0fc43999e98544f1e3c3d421f262 /Source/QtDialog/QCMakeWidgets.cxx
parentdcb1c9c080d9dc7231893baf8bd71713ed2fe021 (diff)
downloadCMake-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/QCMakeWidgets.cxx')
-rw-r--r--Source/QtDialog/QCMakeWidgets.cxx34
1 files changed, 34 insertions, 0 deletions
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);
+}
+}