Skip to content

Commit 9ce17b4

Browse files
hjmjohnsonjamesobutler
authored andcommitted
COMP: Need full definitions not forward declarations
1 parent 3176586 commit 9ce17b4

4 files changed

Lines changed: 169 additions & 176 deletions

File tree

Libs/Widgets/ctkPathLineEdit.cpp

Lines changed: 25 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,13 @@
2121
// Qt includes
2222
#include <QAbstractItemView>
2323
#include <QApplication>
24-
#include <QComboBox>
25-
#include <QCompleter>
26-
#include <QDebug>
2724
#include <QFileDialog>
28-
#include <QFileSystemModel>
2925
#include <QHBoxLayout>
3026
#include <QLineEdit>
3127
#include <QRegularExpression>
3228
#include <QRegularExpressionValidator>
3329
#include <QSettings>
3430
#include <QStyleOptionComboBox>
35-
#include <QToolButton>
3631

3732
// CTK includes
3833
#include "ctkPathLineEdit.h"
@@ -51,74 +46,39 @@
5146

5247
namespace // hide private implementation details
5348
{
54-
55-
//-----------------------------------------------------------------------------
56-
static QFileSystemModel* globalFileSystemModelForFiles()
57-
{
58-
static QFileSystemModel* m = NULL;
59-
if (!m)
49+
//-----------------------------------------------------------------------------
50+
static QFileSystemModel* globalFileSystemModelForFiles()
6051
{
61-
m = new QFileSystemModel();
52+
static QFileSystemModel* m = NULL;
53+
if (!m)
54+
{
55+
m = new QFileSystemModel();
6256
#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);
6559
#endif
66-
m->setRootPath("");
60+
m->setRootPath("");
61+
}
62+
return m;
6763
}
68-
return m;
69-
}
7064

71-
//-----------------------------------------------------------------------------
72-
static QFileSystemModel* globalFileSystemModelForDirectories()
73-
{
74-
static QFileSystemModel* m = NULL;
75-
if (!m)
65+
//-----------------------------------------------------------------------------
66+
static QFileSystemModel* globalFileSystemModelForDirectories()
7667
{
77-
m = new QFileSystemModel();
68+
static QFileSystemModel* m = NULL;
69+
if (!m)
70+
{
71+
m = new QFileSystemModel();
7872
#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);
8175
#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;
8480
}
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
12282

12383
//-----------------------------------------------------------------------------
12484
ctkFileCompleter::ctkFileCompleter(QObject* o, bool showFiles)
@@ -167,8 +127,7 @@ bool ctkFileCompleter::showFiles()
167127
}
168128

169129
//-----------------------------------------------------------------------------
170-
void ctkFileCompleter::setNameFilters(const QStringList& filters)
171-
{
130+
void ctkFileCompleter::setNameFilters(const QStringList& filters) {
172131
if (filters.empty())
173132
{
174133
// no name filter set use the global file system models
@@ -244,59 +203,6 @@ void ctkFileCompleter::addPathToIndex(const QString& path)
244203
}
245204
}
246205

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-
300206
QString ctkPathLineEditPrivate::sCurrentDirectory = "";
301207
int ctkPathLineEditPrivate::sMaxHistory = 5;
302208

@@ -951,7 +857,3 @@ QSize ctkPathLineEdit::sizeHint()const
951857
Q_D(const ctkPathLineEdit);
952858
return d->recomputeSizeHint(d->SizeHint);
953859
}
954-
955-
#include "moc_ctkPathLineEdit.cpp"
956-
957-
#include "ctkPathLineEdit.moc"

Libs/Widgets/ctkPathLineEdit.h

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,22 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
4848
// Qt includes
4949
#include <QDir>
5050
#include <QWidget>
51-
class QComboBox;
51+
#include <QComboBox>
52+
#include <QCompleter>
53+
#include <QDebug>
54+
#include <QFileSystemModel>
55+
#include <QToolButton>
56+
57+
class QRegularExpressionValidator;
58+
5259

5360
// CTK includes
5461
#include "ctkWidgetsExport.h"
55-
class ctkPathLineEditPrivate;
5662

5763
/// \ingroup Widgets
5864
/// \brief Advanced line edit to select a file or directory.
5965
/// \sa ctkDirectoryButton, ctkPathListWidget
60-
///
66+
class ctkPathLineEditPrivate; //Forward declaration needed within file
6167
class CTK_WIDGETS_EXPORT ctkPathLineEdit: public QWidget
6268
{
6369
Q_OBJECT
@@ -285,6 +291,92 @@ protected Q_SLOTS:
285291
Q_PRIVATE_SLOT(d_ptr, void _q_recomputeCompleterPopupSize())
286292
};
287293

294+
//-----------------------------------------------------------------------------
295+
/// Completer class with built-in file system model
296+
class ctkFileCompleter : public QCompleter {
297+
Q_OBJECT
298+
public:
299+
ctkFileCompleter(QObject* o, bool showFiles);
300+
301+
// Ensure auto-completed file always uses forward-slash as separator
302+
QString pathFromIndex(const QModelIndex& idx) const override;
303+
304+
// Helper function for getting the current model casted to QFileSystemModel
305+
QFileSystemModel* fileSystemModel() const;
306+
307+
// Adds path to the file system model.
308+
// This also automatically adds all children to the model.
309+
void addPathToIndex(const QString& path);
310+
311+
// Switch between showing files or folders only
312+
void setShowFiles(bool show);
313+
bool showFiles();
314+
315+
// Set name filter. If filters is empty then all folder/file names are displayed
316+
// and the global shared file system models are used. If name filters are set then
317+
// a custom custom file system is created for the widget.
318+
void setNameFilters(const QStringList& filters);
319+
320+
// Since nameFilters() function may be relevant when more work will be done,
321+
// it is commented to quiet the "-Wunused-function" warning.
322+
//
323+
// QStringList nameFilters() const;
324+
325+
protected:
326+
QFileSystemModel* CustomFileSystemModel;
327+
};
328+
329+
//-----------------------------------------------------------------------------
330+
class ctkPathLineEditPrivate
331+
{
332+
Q_DECLARE_PUBLIC(ctkPathLineEdit);
333+
334+
protected:
335+
ctkPathLineEdit* const q_ptr;
336+
337+
public:
338+
ctkPathLineEditPrivate(ctkPathLineEdit& object);
339+
void init();
340+
QSize recomputeSizeHint(QSize& sh)const;
341+
void updateFilter();
342+
343+
void adjustPathLineEditSize();
344+
345+
void _q_recomputeCompleterPopupSize();
346+
347+
void createPathLineEditWidget(bool useComboBox);
348+
QString settingKey()const;
349+
350+
QLineEdit* LineEdit;
351+
QComboBox* ComboBox;
352+
QToolButton* BrowseButton; //!< "..." button
353+
354+
int MinimumContentsLength;
355+
ctkPathLineEdit::SizeAdjustPolicy SizeAdjustPolicy;
356+
357+
QString Label; //!< used in file dialogs
358+
QStringList NameFilters; //!< Regular expression (in wildcard mode) used to help the user to complete the line
359+
QDir::Filters Filters; //!< Type of path (file, dir...)
360+
#ifdef USE_QFILEDIALOG_OPTIONS
361+
QFileDialog::Options DialogOptions;
362+
#else
363+
ctkPathLineEdit::Options DialogOptions;
364+
#endif
365+
366+
bool HasValidInput; //!< boolean that stores the old state of valid input
367+
QString SettingKey;
368+
369+
static QString sCurrentDirectory; //!< Content the last value of the current directory
370+
static int sMaxHistory; //!< Size of the history, if the history is full and a new value is added, the oldest value is dropped
371+
372+
mutable QSize SizeHint;
373+
mutable QSize MinimumSizeHint;
374+
375+
ctkFileCompleter* Completer;
376+
QRegularExpressionValidator* Validator;
377+
};
378+
379+
288380
Q_DECLARE_OPERATORS_FOR_FLAGS(ctkPathLineEdit::Filters)
289381
#ifndef USE_QFILEDIALOG_OPTIONS
290382
Q_DECLARE_OPERATORS_FOR_FLAGS(ctkPathLineEdit::Options);

Libs/Widgets/ctkPathListWidget.cpp

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -31,52 +31,6 @@
3131
// QtGUI includes
3232
#include "ctkPathListWidget.h"
3333

34-
// --------------------------------------------------------------------------
35-
// ctkPathListWidgetPrivate
36-
37-
//-----------------------------------------------------------------------------
38-
class ctkPathListWidgetPrivate
39-
{
40-
Q_DECLARE_PUBLIC(ctkPathListWidget)
41-
Q_GADGET
42-
43-
protected:
44-
ctkPathListWidget* const q_ptr;
45-
46-
public:
47-
48-
enum PathType {
49-
Unknown,
50-
File,
51-
Directory
52-
};
53-
54-
ctkPathListWidgetPrivate(ctkPathListWidget& object);
55-
56-
void _q_emitPathClicked(const QModelIndex &index);
57-
void _q_emitPathDoubleClicked(const QModelIndex &index);
58-
void _q_emitPathActivated(const QModelIndex &index);
59-
void _q_emitCurrentPathChanged(const QModelIndex &current, const QModelIndex &previous);
60-
61-
bool addPath(const QString& path);
62-
bool removePath(const QString& path);
63-
64-
void fileOptionsChanged();
65-
void directoryOptionsChanged();
66-
67-
PathType pathType(const QString& absolutePath) const;
68-
69-
bool isValidPath(const QString& absoluteFilePath, PathType pathType) const;
70-
bool isValidFile(const QString& absoluteFilePath) const;
71-
bool isValidDir(const QString& absoluteDirPath) const;
72-
73-
QStandardItemModel PathListModel;
74-
ctkPathListWidget::Mode Mode;
75-
ctkPathListWidget::PathOptions FileOptions;
76-
ctkPathListWidget::PathOptions DirectoryOptions;
77-
QIcon FileIcon;
78-
QIcon DirectoryIcon;
79-
};
8034

8135
// --------------------------------------------------------------------------
8236
// ctkPathListWidgetPrivate methods

0 commit comments

Comments
 (0)