|
21 | 21 | // Qt includes |
22 | 22 | #include <QAbstractItemView> |
23 | 23 | #include <QApplication> |
24 | | -#include <QComboBox> |
25 | | -#include <QCompleter> |
26 | | -#include <QDebug> |
27 | 24 | #include <QFileDialog> |
28 | | -#include <QFileSystemModel> |
29 | 25 | #include <QHBoxLayout> |
30 | 26 | #include <QLineEdit> |
31 | 27 | #include <QRegularExpression> |
32 | 28 | #include <QRegularExpressionValidator> |
33 | 29 | #include <QSettings> |
34 | 30 | #include <QStyleOptionComboBox> |
35 | | -#include <QToolButton> |
36 | 31 |
|
37 | 32 | // CTK includes |
38 | 33 | #include "ctkPathLineEdit.h" |
|
51 | 46 |
|
52 | 47 | namespace // hide private implementation details |
53 | 48 | { |
54 | | - |
55 | | -//----------------------------------------------------------------------------- |
56 | | -static QFileSystemModel* globalFileSystemModelForFiles() |
57 | | -{ |
58 | | - static QFileSystemModel* m = NULL; |
59 | | - if (!m) |
| 49 | + //----------------------------------------------------------------------------- |
| 50 | + static QFileSystemModel* globalFileSystemModelForFiles() |
60 | 51 | { |
61 | | - m = new QFileSystemModel(); |
| 52 | + static QFileSystemModel* m = NULL; |
| 53 | + if (!m) |
| 54 | + { |
| 55 | + m = new QFileSystemModel(); |
62 | 56 | #if (QT_VERSION >= QT_VERSION_CHECK(5,14,0)) |
63 | | - // Prevent slow browsing of network drives |
64 | | - m->setOption(QFileSystemModel::DontUseCustomDirectoryIcons); |
| 57 | + // Prevent slow browsing of network drives |
| 58 | + m->setOption(QFileSystemModel::DontUseCustomDirectoryIcons); |
65 | 59 | #endif |
66 | | - m->setRootPath(""); |
| 60 | + m->setRootPath(""); |
| 61 | + } |
| 62 | + return m; |
67 | 63 | } |
68 | | - return m; |
69 | | -} |
70 | 64 |
|
71 | | -//----------------------------------------------------------------------------- |
72 | | -static QFileSystemModel* globalFileSystemModelForDirectories() |
73 | | -{ |
74 | | - static QFileSystemModel* m = NULL; |
75 | | - if (!m) |
| 65 | + //----------------------------------------------------------------------------- |
| 66 | + static QFileSystemModel* globalFileSystemModelForDirectories() |
76 | 67 | { |
77 | | - m = new QFileSystemModel(); |
| 68 | + static QFileSystemModel* m = NULL; |
| 69 | + if (!m) |
| 70 | + { |
| 71 | + m = new QFileSystemModel(); |
78 | 72 | #if (QT_VERSION >= QT_VERSION_CHECK(5,14,0)) |
79 | | - // Prevent slow browsing of network drives |
80 | | - m->setOption(QFileSystemModel::DontUseCustomDirectoryIcons); |
| 73 | + // Prevent slow browsing of network drives |
| 74 | + m->setOption(QFileSystemModel::DontUseCustomDirectoryIcons); |
81 | 75 | #endif |
82 | | - m->setFilter(QDir::AllDirs | QDir::Drives | QDir::NoDotAndDotDot); |
83 | | - m->setRootPath(""); |
| 76 | + m->setFilter(QDir::AllDirs | QDir::Drives | QDir::NoDotAndDotDot); |
| 77 | + m->setRootPath(""); |
| 78 | + } |
| 79 | + return m; |
84 | 80 | } |
85 | | - return m; |
86 | | -} |
87 | | - |
88 | | -//----------------------------------------------------------------------------- |
89 | | -/// Completer class with built-in file system model |
90 | | -class ctkFileCompleter : public QCompleter { |
91 | | - Q_OBJECT |
92 | | -public: |
93 | | - ctkFileCompleter(QObject* o, bool showFiles); |
94 | | - |
95 | | - // Ensure auto-completed file always uses forward-slash as separator |
96 | | - QString pathFromIndex(const QModelIndex& idx) const override; |
97 | | - |
98 | | - // Helper function for getting the current model casted to QFileSystemModel |
99 | | - QFileSystemModel* fileSystemModel() const; |
100 | | - |
101 | | - // Adds path to the file system model. |
102 | | - // This also automatically adds all children to the model. |
103 | | - void addPathToIndex(const QString& path); |
104 | | - |
105 | | - // Switch between showing files or folders only |
106 | | - void setShowFiles(bool show); |
107 | | - bool showFiles(); |
108 | | - |
109 | | - // Set name filter. If filters is empty then all folder/file names are displayed |
110 | | - // and the global shared file system models are used. If name filters are set then |
111 | | - // a custom custom file system is created for the widget. |
112 | | - void setNameFilters(const QStringList& filters); |
113 | | - |
114 | | - // Since nameFilters() function may be relevant when more work will be done, |
115 | | - // it is commented to quiet the "-Wunused-function" warning. |
116 | | - // |
117 | | - // QStringList nameFilters() const; |
118 | | - |
119 | | -protected: |
120 | | - QFileSystemModel* CustomFileSystemModel; |
121 | | -}; |
| 81 | +} // end of anonymous namespace |
122 | 82 |
|
123 | 83 | //----------------------------------------------------------------------------- |
124 | 84 | ctkFileCompleter::ctkFileCompleter(QObject* o, bool showFiles) |
@@ -167,8 +127,7 @@ bool ctkFileCompleter::showFiles() |
167 | 127 | } |
168 | 128 |
|
169 | 129 | //----------------------------------------------------------------------------- |
170 | | -void ctkFileCompleter::setNameFilters(const QStringList& filters) |
171 | | -{ |
| 130 | +void ctkFileCompleter::setNameFilters(const QStringList& filters) { |
172 | 131 | if (filters.empty()) |
173 | 132 | { |
174 | 133 | // no name filter set use the global file system models |
@@ -244,59 +203,6 @@ void ctkFileCompleter::addPathToIndex(const QString& path) |
244 | 203 | } |
245 | 204 | } |
246 | 205 |
|
247 | | -} // end of anonymous namespace |
248 | | - |
249 | | -//----------------------------------------------------------------------------- |
250 | | -class ctkPathLineEditPrivate |
251 | | -{ |
252 | | - Q_DECLARE_PUBLIC(ctkPathLineEdit); |
253 | | - Q_GADGET |
254 | | - |
255 | | -protected: |
256 | | - ctkPathLineEdit* const q_ptr; |
257 | | - |
258 | | -public: |
259 | | - ctkPathLineEditPrivate(ctkPathLineEdit& object); |
260 | | - void init(); |
261 | | - QSize recomputeSizeHint(QSize& sh)const; |
262 | | - void updateFilter(); |
263 | | - |
264 | | - void adjustPathLineEditSize(); |
265 | | - |
266 | | - void _q_recomputeCompleterPopupSize(); |
267 | | - |
268 | | - void createPathLineEditWidget(bool useComboBox); |
269 | | - QString settingKey()const; |
270 | | - |
271 | | - QLineEdit* LineEdit; |
272 | | - QComboBox* ComboBox; |
273 | | - QToolButton* BrowseButton; //!< "..." button |
274 | | - |
275 | | - int MinimumContentsLength; |
276 | | - ctkPathLineEdit::SizeAdjustPolicy SizeAdjustPolicy; |
277 | | - |
278 | | - QString Label; //!< used in file dialogs |
279 | | - QStringList NameFilters; //!< Regular expression (in wildcard mode) used to help the user to complete the line |
280 | | - QDir::Filters Filters; //!< Type of path (file, dir...) |
281 | | -#ifdef USE_QFILEDIALOG_OPTIONS |
282 | | - QFileDialog::Options DialogOptions; |
283 | | -#else |
284 | | - ctkPathLineEdit::Options DialogOptions; |
285 | | -#endif |
286 | | - |
287 | | - bool HasValidInput; //!< boolean that stores the old state of valid input |
288 | | - QString SettingKey; |
289 | | - |
290 | | - static QString sCurrentDirectory; //!< Content the last value of the current directory |
291 | | - static int sMaxHistory; //!< Size of the history, if the history is full and a new value is added, the oldest value is dropped |
292 | | - |
293 | | - mutable QSize SizeHint; |
294 | | - mutable QSize MinimumSizeHint; |
295 | | - |
296 | | - ctkFileCompleter* Completer; |
297 | | - QRegularExpressionValidator* Validator; |
298 | | -}; |
299 | | - |
300 | 206 | QString ctkPathLineEditPrivate::sCurrentDirectory = ""; |
301 | 207 | int ctkPathLineEditPrivate::sMaxHistory = 5; |
302 | 208 |
|
@@ -951,7 +857,3 @@ QSize ctkPathLineEdit::sizeHint()const |
951 | 857 | Q_D(const ctkPathLineEdit); |
952 | 858 | return d->recomputeSizeHint(d->SizeHint); |
953 | 859 | } |
954 | | - |
955 | | -#include "moc_ctkPathLineEdit.cpp" |
956 | | - |
957 | | -#include "ctkPathLineEdit.moc" |
0 commit comments