diff options
author | Sankhesh Jhaveri <sankhesh.jhaveri@kitware.com> | 2020-12-23 15:28:15 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-01-05 16:03:31 (GMT) |
commit | b3ee09290bcc6f660aeafbe3490a6016867ef2ae (patch) | |
tree | 4ee069a0067c1e4ac1233b99b7d1c4f791543a1f | |
parent | 020b2766f31c19f6a5953e3365641aeba06c3552 (diff) | |
download | CMake-b3ee09290bcc6f660aeafbe3490a6016867ef2ae.zip CMake-b3ee09290bcc6f660aeafbe3490a6016867ef2ae.tar.gz CMake-b3ee09290bcc6f660aeafbe3490a6016867ef2ae.tar.bz2 |
cmake-gui: Conditionally switch between QDirModel and QFileSystemModel
Uses QT_VERSION_CHECK to determine Qt version. The code switches to
QFileSystemModel for Qt versions >= 6
-rw-r--r-- | Source/QtDialog/QCMakeWidgets.cxx | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/Source/QtDialog/QCMakeWidgets.cxx b/Source/QtDialog/QCMakeWidgets.cxx index 45fd425..ca65d13 100644 --- a/Source/QtDialog/QCMakeWidgets.cxx +++ b/Source/QtDialog/QCMakeWidgets.cxx @@ -1,16 +1,23 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ +#define QT_DEPRECATED_WARNINGS_SINCE QT_VERSION_CHECK(5, 14, 0) + #include "QCMakeWidgets.h" #include <utility> #include <QFileDialog> #include <QFileInfo> -#include <QFileSystemModel> #include <QResizeEvent> #include <QToolButton> +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +# include <QFileSystemModel> +#else +# include <QDirModel> +#endif + QCMakeFileEditor::QCMakeFileEditor(QWidget* p, QString var) : QLineEdit(p) , Variable(std::move(var)) @@ -89,8 +96,10 @@ void QCMakePathEditor::chooseFile() } } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) // use same QFileSystemModel for all completers static QFileSystemModel* fileDirModel() + { static QFileSystemModel* m = nullptr; if (!m) { @@ -107,13 +116,39 @@ static QFileSystemModel* pathDirModel() } return m; } +#else +// use same QDirModel for all completers +static QDirModel* fileDirModel() + +{ + static QDirModel* m = nullptr; + if (!m) { + m = new QDirModel(); + } + return m; +} +static QDirModel* pathDirModel() +{ + static QDirModel* m = nullptr; + if (!m) { + m = new QDirModel(); + m->setFilter(QDir::AllDirs | QDir::Drives | QDir::NoDotAndDotDot); + } + return m; +} +#endif QCMakeFileCompleter::QCMakeFileCompleter(QObject* o, bool dirs) : QCompleter(o) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) QFileSystemModel* m = dirs ? pathDirModel() : fileDirModel(); this->setModel(m); m->setRootPath(QString()); +#else + QDirModel* m = dirs ? pathDirModel() : fileDirModel(); + this->setModel(m); +#endif } QString QCMakeFileCompleter::pathFromIndex(const QModelIndex& idx) const |