QFileSystemModel: Improve class structure

Use member initialization in private classes and repack members to
minimize padding.

Use delegating constructors and default constructors/destructors.

Task-number: QTBUG-76493
Change-Id: Iaea8880811782ee5846c128590b83c23e6fae445
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Friedemann Kleint 2019-07-09 10:01:01 +02:00
parent d72ea9cbd3
commit e81ece3f8f
4 changed files with 32 additions and 54 deletions

View File

@ -79,14 +79,8 @@ static QString translateDriveName(const QFileInfo &drive)
Creates thread
*/
QFileInfoGatherer::QFileInfoGatherer(QObject *parent)
: QThread(parent), abort(false),
#if QT_CONFIG(filesystemwatcher)
watcher(0),
#endif
#ifdef Q_OS_WIN
m_resolveSymlinks(true),
#endif
m_iconProvider(&defaultProvider)
: QThread(parent)
, m_iconProvider(&defaultProvider)
{
#if QT_CONFIG(filesystemwatcher)
watcher = new QFileSystemWatcher(this);

View File

@ -210,13 +210,13 @@ private:
QAtomicInt abort;
#if QT_CONFIG(filesystemwatcher)
QFileSystemWatcher *watcher;
#endif
#ifdef Q_OS_WIN
bool m_resolveSymlinks; // not accessed by run()
QFileSystemWatcher *watcher = nullptr;
#endif
QFileIconProvider *m_iconProvider; // not accessed by run()
QFileIconProvider defaultProvider;
#ifdef Q_OS_WIN
bool m_resolveSymlinks = true; // not accessed by run()
#endif
};
QT_END_NAMESPACE

View File

@ -227,11 +227,9 @@ bool QFileSystemModel::remove(const QModelIndex &aindex)
/*!
Constructs a file system model with the given \a parent.
*/
QFileSystemModel::QFileSystemModel(QObject *parent)
: QAbstractItemModel(*new QFileSystemModelPrivate, parent)
QFileSystemModel::QFileSystemModel(QObject *parent) :
QFileSystemModel(*new QFileSystemModelPrivate, parent)
{
Q_D(QFileSystemModel);
d->init();
}
/*!
@ -247,9 +245,7 @@ QFileSystemModel::QFileSystemModel(QFileSystemModelPrivate &dd, QObject *parent)
/*!
Destroys this file system model.
*/
QFileSystemModel::~QFileSystemModel()
{
}
QFileSystemModel::~QFileSystemModel() = default;
/*!
\reimp
@ -1945,6 +1941,9 @@ QStringList QFileSystemModelPrivate::unwatchPathsAt(const QModelIndex &index)
void QFileSystemModelPrivate::init()
{
Q_Q(QFileSystemModel);
delayedSortTimer.setSingleShot(true);
qRegisterMetaType<QVector<QPair<QString,QFileInfo> > >();
#if QT_CONFIG(filesystemwatcher)
q->connect(&fileInfoGatherer, SIGNAL(newListOfFiles(QString,QStringList)),

View File

@ -99,13 +99,13 @@ public:
class QFileSystemNode
{
public:
Q_DISABLE_COPY_MOVE(QFileSystemNode)
explicit QFileSystemNode(const QString &filename = QString(), QFileSystemNode *p = nullptr)
: fileName(filename), populatedChildren(false), isVisible(false), dirtyChildrenIndex(-1), parent(p), info(nullptr) {}
: fileName(filename), parent(p) {}
~QFileSystemNode() {
qDeleteAll(children);
delete info;
info = nullptr;
parent = nullptr;
}
QString fileName;
@ -204,31 +204,16 @@ public:
}
}
bool populatedChildren;
bool isVisible;
QHash<QFileSystemModelNodePathKey, QFileSystemNode *> children;
QList<QString> visibleChildren;
int dirtyChildrenIndex;
QExtendedInformation *info = nullptr;
QFileSystemNode *parent;
QExtendedInformation *info;
int dirtyChildrenIndex = -1;
bool populatedChildren = false;
bool isVisible = false;
};
QFileSystemModelPrivate() :
forceSort(true),
sortColumn(0),
sortOrder(Qt::AscendingOrder),
readOnly(true),
setRootPath(false),
filters(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs),
nameFilterDisables(true), // false on windows, true on mac and unix
disableRecursiveSort(false)
{
delayedSortTimer.setSingleShot(true);
}
QFileSystemModelPrivate() = default;
void init();
/*
\internal
@ -303,18 +288,7 @@ public:
QFileInfoGatherer fileInfoGatherer;
#endif // filesystemwatcher
QTimer delayedSortTimer;
bool forceSort;
int sortColumn;
Qt::SortOrder sortOrder;
bool readOnly;
bool setRootPath;
QDir::Filters filters;
QHash<const QFileSystemNode*, bool> bypassFilters;
bool nameFilterDisables;
//This flag is an optimization for the QFileDialog
//It enable a sort which is not recursive, it means
//we sort only what we see.
bool disableRecursiveSort;
#if QT_CONFIG(regularexpression)
QStringList nameFilters;
#endif
@ -322,7 +296,6 @@ public:
QFileSystemNode root;
QBasicTimer fetchingTimer;
struct Fetching {
QString dir;
QString file;
@ -330,6 +303,18 @@ public:
};
QVector<Fetching> toFetch;
QBasicTimer fetchingTimer;
QDir::Filters filters = QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs;
int sortColumn = 0;
Qt::SortOrder sortOrder = Qt::AscendingOrder;
bool forceSort = true;
bool readOnly = true;
bool setRootPath = false;
bool nameFilterDisables = true; // false on windows, true on mac and unix
// This flag is an optimization for QFileDialog. It enables a sort which is
// not recursive, meaning we sort only what we see.
bool disableRecursiveSort = false;
};
Q_DECLARE_TYPEINFO(QFileSystemModelPrivate::Fetching, Q_MOVABLE_TYPE);