QFileSystem{Model,Watcher}: port to PMF signal/slot syntax
Also remove the `_q_` prefix from private slot names, it was needed to mark them as being used with Q_PRIVATE_SLOT, which is also gone in this commit. Drive-by change: de-duplicate some code. Change-Id: Ib41d0ac24ae584746751c0c2b5c477f600627db1 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
This commit is contained in:
parent
e366a47d65
commit
27dd178900
@ -58,29 +58,29 @@ QFileSystemWatcherPrivate::QFileSystemWatcherPrivate()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QFileSystemWatcherPrivate::connectEngine(QFileSystemWatcherEngine *engine)
|
||||||
|
{
|
||||||
|
QObjectPrivate::connect(engine, &QFileSystemWatcherEngine::fileChanged,
|
||||||
|
this, &QFileSystemWatcherPrivate::fileChanged);
|
||||||
|
QObjectPrivate::connect(engine, &QFileSystemWatcherEngine::directoryChanged,
|
||||||
|
this, &QFileSystemWatcherPrivate::directoryChanged);
|
||||||
|
}
|
||||||
|
|
||||||
void QFileSystemWatcherPrivate::init()
|
void QFileSystemWatcherPrivate::init()
|
||||||
{
|
{
|
||||||
Q_Q(QFileSystemWatcher);
|
Q_Q(QFileSystemWatcher);
|
||||||
native = createNativeEngine(q);
|
native = createNativeEngine(q);
|
||||||
if (native) {
|
if (native) {
|
||||||
QObject::connect(native,
|
connectEngine(native);
|
||||||
SIGNAL(fileChanged(QString,bool)),
|
|
||||||
q,
|
|
||||||
SLOT(_q_fileChanged(QString,bool)));
|
|
||||||
QObject::connect(native,
|
|
||||||
SIGNAL(directoryChanged(QString,bool)),
|
|
||||||
q,
|
|
||||||
SLOT(_q_directoryChanged(QString,bool)));
|
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
QObject::connect(static_cast<QWindowsFileSystemWatcherEngine *>(native),
|
auto *windowsWatcher = static_cast<QWindowsFileSystemWatcherEngine *>(native);
|
||||||
&QWindowsFileSystemWatcherEngine::driveLockForRemoval,
|
using WinE = QWindowsFileSystemWatcherEngine;
|
||||||
q, [this] (const QString &p) { _q_winDriveLockForRemoval(p); });
|
QObjectPrivate::connect(windowsWatcher, &WinE::driveLockForRemoval,
|
||||||
QObject::connect(static_cast<QWindowsFileSystemWatcherEngine *>(native),
|
this, &QFileSystemWatcherPrivate::winDriveLockForRemoval);
|
||||||
&QWindowsFileSystemWatcherEngine::driveLockForRemovalFailed,
|
QObjectPrivate::connect(windowsWatcher, &WinE::driveLockForRemovalFailed,
|
||||||
q, [this] (const QString &p) { _q_winDriveLockForRemovalFailed(p); });
|
this, &QFileSystemWatcherPrivate::winDriveLockForRemovalFailed);
|
||||||
QObject::connect(static_cast<QWindowsFileSystemWatcherEngine *>(native),
|
QObjectPrivate::connect(windowsWatcher, &WinE::driveRemoved,
|
||||||
&QWindowsFileSystemWatcherEngine::driveRemoved,
|
this, &QFileSystemWatcherPrivate::winDriveRemoved);
|
||||||
q, [this] (const QString &p) { _q_winDriveRemoved(p); });
|
|
||||||
#endif // Q_OS_WIN
|
#endif // Q_OS_WIN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,17 +92,10 @@ void QFileSystemWatcherPrivate::initPollerEngine()
|
|||||||
|
|
||||||
Q_Q(QFileSystemWatcher);
|
Q_Q(QFileSystemWatcher);
|
||||||
poller = new QPollingFileSystemWatcherEngine(q); // that was a mouthful
|
poller = new QPollingFileSystemWatcherEngine(q); // that was a mouthful
|
||||||
QObject::connect(poller,
|
connectEngine(poller);
|
||||||
SIGNAL(fileChanged(QString,bool)),
|
|
||||||
q,
|
|
||||||
SLOT(_q_fileChanged(QString,bool)));
|
|
||||||
QObject::connect(poller,
|
|
||||||
SIGNAL(directoryChanged(QString,bool)),
|
|
||||||
q,
|
|
||||||
SLOT(_q_directoryChanged(QString,bool)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QFileSystemWatcherPrivate::_q_fileChanged(const QString &path, bool removed)
|
void QFileSystemWatcherPrivate::fileChanged(const QString &path, bool removed)
|
||||||
{
|
{
|
||||||
Q_Q(QFileSystemWatcher);
|
Q_Q(QFileSystemWatcher);
|
||||||
qCDebug(lcWatcher) << "file changed" << path << "removed?" << removed << "watching?" << files.contains(path);
|
qCDebug(lcWatcher) << "file changed" << path << "removed?" << removed << "watching?" << files.contains(path);
|
||||||
@ -115,7 +108,7 @@ void QFileSystemWatcherPrivate::_q_fileChanged(const QString &path, bool removed
|
|||||||
emit q->fileChanged(path, QFileSystemWatcher::QPrivateSignal());
|
emit q->fileChanged(path, QFileSystemWatcher::QPrivateSignal());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QFileSystemWatcherPrivate::_q_directoryChanged(const QString &path, bool removed)
|
void QFileSystemWatcherPrivate::directoryChanged(const QString &path, bool removed)
|
||||||
{
|
{
|
||||||
Q_Q(QFileSystemWatcher);
|
Q_Q(QFileSystemWatcher);
|
||||||
qCDebug(lcWatcher) << "directory changed" << path << "removed?" << removed << "watching?" << directories.contains(path);
|
qCDebug(lcWatcher) << "directory changed" << path << "removed?" << removed << "watching?" << directories.contains(path);
|
||||||
@ -130,7 +123,7 @@ void QFileSystemWatcherPrivate::_q_directoryChanged(const QString &path, bool re
|
|||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
|
|
||||||
void QFileSystemWatcherPrivate::_q_winDriveLockForRemoval(const QString &path)
|
void QFileSystemWatcherPrivate::winDriveLockForRemoval(const QString &path)
|
||||||
{
|
{
|
||||||
// Windows: Request to lock a (removable/USB) drive for removal, release
|
// Windows: Request to lock a (removable/USB) drive for removal, release
|
||||||
// its paths under watch, temporarily storing them should the lock fail.
|
// its paths under watch, temporarily storing them should the lock fail.
|
||||||
@ -147,7 +140,7 @@ void QFileSystemWatcherPrivate::_q_winDriveLockForRemoval(const QString &path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QFileSystemWatcherPrivate::_q_winDriveLockForRemovalFailed(const QString &path)
|
void QFileSystemWatcherPrivate::winDriveLockForRemovalFailed(const QString &path)
|
||||||
{
|
{
|
||||||
// Windows: Request to lock a (removable/USB) drive failed (blocked by other
|
// Windows: Request to lock a (removable/USB) drive failed (blocked by other
|
||||||
// application), restore the watched paths.
|
// application), restore the watched paths.
|
||||||
@ -161,7 +154,7 @@ void QFileSystemWatcherPrivate::_q_winDriveLockForRemovalFailed(const QString &p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QFileSystemWatcherPrivate::_q_winDriveRemoved(const QString &path)
|
void QFileSystemWatcherPrivate::winDriveRemoved(const QString &path)
|
||||||
{
|
{
|
||||||
// Windows: Drive finally removed, clear out paths stored in lock request.
|
// Windows: Drive finally removed, clear out paths stored in lock request.
|
||||||
if (!path.isEmpty())
|
if (!path.isEmpty())
|
||||||
|
@ -34,10 +34,6 @@ public:
|
|||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void fileChanged(const QString &path, QPrivateSignal);
|
void fileChanged(const QString &path, QPrivateSignal);
|
||||||
void directoryChanged(const QString &path, QPrivateSignal);
|
void directoryChanged(const QString &path, QPrivateSignal);
|
||||||
|
|
||||||
private:
|
|
||||||
Q_PRIVATE_SLOT(d_func(), void _q_fileChanged(const QString &path, bool removed))
|
|
||||||
Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &path, bool removed))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -69,13 +69,15 @@ public:
|
|||||||
QStringList files, directories;
|
QStringList files, directories;
|
||||||
|
|
||||||
// private slots
|
// private slots
|
||||||
void _q_fileChanged(const QString &path, bool removed);
|
void fileChanged(const QString &path, bool removed);
|
||||||
void _q_directoryChanged(const QString &path, bool removed);
|
void directoryChanged(const QString &path, bool removed);
|
||||||
|
|
||||||
|
void connectEngine(QFileSystemWatcherEngine *e);
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
void _q_winDriveLockForRemoval(const QString &);
|
void winDriveLockForRemoval(const QString &);
|
||||||
void _q_winDriveLockForRemovalFailed(const QString &);
|
void winDriveLockForRemovalFailed(const QString &);
|
||||||
void _q_winDriveRemoved(const QString &);
|
void winDriveRemoved(const QString &);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<QChar, QStringList> temporarilyRemovedPaths;
|
QHash<QChar, QStringList> temporarilyRemovedPaths;
|
||||||
|
@ -997,7 +997,7 @@ Qt::ItemFlags QFileSystemModel::flags(const QModelIndex &index) const
|
|||||||
/*!
|
/*!
|
||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
void QFileSystemModelPrivate::_q_performDelayedSort()
|
void QFileSystemModelPrivate::performDelayedSort()
|
||||||
{
|
{
|
||||||
Q_Q(QFileSystemModel);
|
Q_Q(QFileSystemModel);
|
||||||
q->sort(sortColumn, sortOrder);
|
q->sort(sortColumn, sortOrder);
|
||||||
@ -1764,7 +1764,7 @@ bool QFileSystemModel::rmdir(const QModelIndex &aindex)
|
|||||||
Performed quick listing and see if any files have been added or removed,
|
Performed quick listing and see if any files have been added or removed,
|
||||||
then fetch more information on visible files.
|
then fetch more information on visible files.
|
||||||
*/
|
*/
|
||||||
void QFileSystemModelPrivate::_q_directoryChanged(const QString &directory, const QStringList &files)
|
void QFileSystemModelPrivate::directoryChanged(const QString &directory, const QStringList &files)
|
||||||
{
|
{
|
||||||
QFileSystemModelPrivate::QFileSystemNode *parentNode = node(directory, false);
|
QFileSystemModelPrivate::QFileSystemNode *parentNode = node(directory, false);
|
||||||
if (parentNode->children.size() == 0)
|
if (parentNode->children.size() == 0)
|
||||||
@ -1912,7 +1912,7 @@ void QFileSystemModelPrivate::removeVisibleFile(QFileSystemNode *parentNode, int
|
|||||||
The thread has received new information about files,
|
The thread has received new information about files,
|
||||||
update and emit dataChanged if it has actually changed.
|
update and emit dataChanged if it has actually changed.
|
||||||
*/
|
*/
|
||||||
void QFileSystemModelPrivate::_q_fileSystemChanged(const QString &path,
|
void QFileSystemModelPrivate::fileSystemChanged(const QString &path,
|
||||||
const QList<std::pair<QString, QFileInfo>> &updates)
|
const QList<std::pair<QString, QFileInfo>> &updates)
|
||||||
{
|
{
|
||||||
#if QT_CONFIG(filesystemwatcher)
|
#if QT_CONFIG(filesystemwatcher)
|
||||||
@ -2023,7 +2023,7 @@ void QFileSystemModelPrivate::_q_fileSystemChanged(const QString &path,
|
|||||||
/*!
|
/*!
|
||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
void QFileSystemModelPrivate::_q_resolvedName(const QString &fileName, const QString &resolvedName)
|
void QFileSystemModelPrivate::resolvedName(const QString &fileName, const QString &resolvedName)
|
||||||
{
|
{
|
||||||
resolvedSymLinks[fileName] = resolvedName;
|
resolvedSymLinks[fileName] = resolvedName;
|
||||||
}
|
}
|
||||||
@ -2102,16 +2102,18 @@ void QFileSystemModelPrivate::init()
|
|||||||
|
|
||||||
qRegisterMetaType<QList<std::pair<QString, QFileInfo>>>();
|
qRegisterMetaType<QList<std::pair<QString, QFileInfo>>>();
|
||||||
#if QT_CONFIG(filesystemwatcher)
|
#if QT_CONFIG(filesystemwatcher)
|
||||||
q->connect(fileInfoGatherer.get(), SIGNAL(newListOfFiles(QString,QStringList)),
|
QObjectPrivate::connect(fileInfoGatherer.get(), &QFileInfoGatherer::newListOfFiles,
|
||||||
q, SLOT(_q_directoryChanged(QString,QStringList)));
|
this, &QFileSystemModelPrivate::directoryChanged);
|
||||||
q->connect(fileInfoGatherer.get(), SIGNAL(updates(QString,QList<std::pair<QString,QFileInfo>>)), q,
|
QObjectPrivate::connect(fileInfoGatherer.get(), &QFileInfoGatherer::updates,
|
||||||
SLOT(_q_fileSystemChanged(QString,QList<std::pair<QString,QFileInfo>>)));
|
this, &QFileSystemModelPrivate::fileSystemChanged);
|
||||||
q->connect(fileInfoGatherer.get(), SIGNAL(nameResolved(QString,QString)),
|
QObjectPrivate::connect(fileInfoGatherer.get(), &QFileInfoGatherer::nameResolved,
|
||||||
q, SLOT(_q_resolvedName(QString,QString)));
|
this, &QFileSystemModelPrivate::resolvedName);
|
||||||
q->connect(fileInfoGatherer.get(), SIGNAL(directoryLoaded(QString)),
|
q->connect(fileInfoGatherer.get(), &QFileInfoGatherer::directoryLoaded,
|
||||||
q, SIGNAL(directoryLoaded(QString)));
|
q, &QFileSystemModel::directoryLoaded);
|
||||||
#endif // filesystemwatcher
|
#endif // filesystemwatcher
|
||||||
q->connect(&delayedSortTimer, SIGNAL(timeout()), q, SLOT(_q_performDelayedSort()), Qt::QueuedConnection);
|
QObjectPrivate::connect(&delayedSortTimer, &QTimer::timeout,
|
||||||
|
this, &QFileSystemModelPrivate::performDelayedSort,
|
||||||
|
Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -134,13 +134,6 @@ private:
|
|||||||
Q_DECLARE_PRIVATE(QFileSystemModel)
|
Q_DECLARE_PRIVATE(QFileSystemModel)
|
||||||
Q_DISABLE_COPY(QFileSystemModel)
|
Q_DISABLE_COPY(QFileSystemModel)
|
||||||
|
|
||||||
Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &directory, const QStringList &list))
|
|
||||||
Q_PRIVATE_SLOT(d_func(), void _q_performDelayedSort())
|
|
||||||
Q_PRIVATE_SLOT(d_func(),
|
|
||||||
void _q_fileSystemChanged(const QString &path,
|
|
||||||
const QList<std::pair<QString, QFileInfo>> &))
|
|
||||||
Q_PRIVATE_SLOT(d_func(), void _q_resolvedName(const QString &fileName, const QString &resolvedName))
|
|
||||||
|
|
||||||
friend class QFileDialogPrivate;
|
friend class QFileDialogPrivate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -250,10 +250,10 @@ public:
|
|||||||
QString type(const QModelIndex &index) const;
|
QString type(const QModelIndex &index) const;
|
||||||
QString time(const QModelIndex &index) const;
|
QString time(const QModelIndex &index) const;
|
||||||
|
|
||||||
void _q_directoryChanged(const QString &directory, const QStringList &list);
|
void directoryChanged(const QString &directory, const QStringList &list);
|
||||||
void _q_performDelayedSort();
|
void performDelayedSort();
|
||||||
void _q_fileSystemChanged(const QString &path, const QList<std::pair<QString, QFileInfo>> &);
|
void fileSystemChanged(const QString &path, const QList<std::pair<QString, QFileInfo>> &);
|
||||||
void _q_resolvedName(const QString &fileName, const QString &resolvedName);
|
void resolvedName(const QString &fileName, const QString &resolvedName);
|
||||||
|
|
||||||
QDir rootDir;
|
QDir rootDir;
|
||||||
#if QT_CONFIG(filesystemwatcher)
|
#if QT_CONFIG(filesystemwatcher)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user