Introspect qrc files in FolderListModel.
And don't use "file watchers" for resource file paths, otherwise it generates the following warning: QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed: No such file or directory Change-Id: I6b75c9195fb2b2ba7b3e0bb7d146fc5cd343927e Task-number: QTBUG-40307 Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
parent
3cc2b8d7d9
commit
253e9257e1
|
@ -92,7 +92,8 @@ void FileInfoThread::removePath(const QString &path)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
#ifndef QT_NO_FILESYSTEMWATCHER
|
#ifndef QT_NO_FILESYSTEMWATCHER
|
||||||
watcher->removePath(path);
|
if (!path.startsWith(QLatin1Char(':')))
|
||||||
|
watcher->removePath(path);
|
||||||
#endif
|
#endif
|
||||||
currentPath.clear();
|
currentPath.clear();
|
||||||
}
|
}
|
||||||
|
@ -103,7 +104,8 @@ void FileInfoThread::setPath(const QString &path)
|
||||||
|
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
#ifndef QT_NO_FILESYSTEMWATCHER
|
#ifndef QT_NO_FILESYSTEMWATCHER
|
||||||
watcher->addPath(path);
|
if (!path.startsWith(QLatin1Char(':')))
|
||||||
|
watcher->addPath(path);
|
||||||
#endif
|
#endif
|
||||||
currentPath = path;
|
currentPath = path;
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
|
|
|
@ -536,8 +536,8 @@ void QQuickFolderListModel::classBegin()
|
||||||
void QQuickFolderListModel::componentComplete()
|
void QQuickFolderListModel::componentComplete()
|
||||||
{
|
{
|
||||||
Q_D(QQuickFolderListModel);
|
Q_D(QQuickFolderListModel);
|
||||||
|
QString localPath = QQmlFile::urlToLocalFileOrQrc(d->currentDir);
|
||||||
if (!d->currentDir.isValid() || !d->currentDir.isLocalFile() || !QDir().exists(d->currentDir.toLocalFile()))
|
if (localPath.isEmpty() || !QDir(localPath).exists())
|
||||||
setFolder(QUrl::fromLocalFile(QDir::currentPath()));
|
setFolder(QUrl::fromLocalFile(QDir::currentPath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
<RCC>
|
||||||
|
<qresource prefix="/myprefix/subdir">
|
||||||
|
<file>txtdir/hello.txt</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
|
@ -0,0 +1,7 @@
|
||||||
|
import Qt.labs.folderlistmodel 2.1
|
||||||
|
|
||||||
|
FolderListModel {
|
||||||
|
nameFilters: [ "*.txt" ]
|
||||||
|
folder: "qrc:/myprefix/subdir/txtdir"
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Hello from hello.txt
|
|
@ -11,3 +11,5 @@ TESTDATA = data/*
|
||||||
CONFIG += parallel_test
|
CONFIG += parallel_test
|
||||||
QT += core-private gui-private qml-private testlib
|
QT += core-private gui-private qml-private testlib
|
||||||
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
|
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
|
||||||
|
|
||||||
|
RESOURCES += data/introspect.qrc
|
||||||
|
|
|
@ -83,6 +83,7 @@ private slots:
|
||||||
void showDotAndDotDot();
|
void showDotAndDotDot();
|
||||||
void showDotAndDotDot_data();
|
void showDotAndDotDot_data();
|
||||||
void sortReversed();
|
void sortReversed();
|
||||||
|
void introspectQrc();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void checkNoErrors(const QQmlComponent& component);
|
void checkNoErrors(const QQmlComponent& component);
|
||||||
|
@ -127,7 +128,7 @@ void tst_qquickfolderlistmodel::basicProperties()
|
||||||
QSignalSpy folderChangedSpy(flm, SIGNAL(folderChanged()));
|
QSignalSpy folderChangedSpy(flm, SIGNAL(folderChanged()));
|
||||||
flm->setProperty("folder", dataDirectoryUrl());
|
flm->setProperty("folder", dataDirectoryUrl());
|
||||||
QVERIFY(folderChangedSpy.wait());
|
QVERIFY(folderChangedSpy.wait());
|
||||||
QCOMPARE(flm->property("count").toInt(), 6);
|
QCOMPARE(flm->property("count").toInt(), 8);
|
||||||
QCOMPARE(flm->property("folder").toUrl(), dataDirectoryUrl());
|
QCOMPARE(flm->property("folder").toUrl(), dataDirectoryUrl());
|
||||||
QCOMPARE(flm->property("parentFolder").toUrl(), QUrl::fromLocalFile(QDir(directory()).canonicalPath()));
|
QCOMPARE(flm->property("parentFolder").toUrl(), QUrl::fromLocalFile(QDir(directory()).canonicalPath()));
|
||||||
QCOMPARE(flm->property("sortField").toInt(), int(Name));
|
QCOMPARE(flm->property("sortField").toInt(), int(Name));
|
||||||
|
@ -153,12 +154,12 @@ void tst_qquickfolderlistmodel::showFiles()
|
||||||
QVERIFY(flm != 0);
|
QVERIFY(flm != 0);
|
||||||
|
|
||||||
flm->setProperty("folder", dataDirectoryUrl());
|
flm->setProperty("folder", dataDirectoryUrl());
|
||||||
QTRY_COMPARE(flm->property("count").toInt(), 6); // wait for refresh
|
QTRY_COMPARE(flm->property("count").toInt(), 8); // wait for refresh
|
||||||
QCOMPARE(flm->property("showFiles").toBool(), true);
|
QCOMPARE(flm->property("showFiles").toBool(), true);
|
||||||
|
|
||||||
flm->setProperty("showFiles", false);
|
flm->setProperty("showFiles", false);
|
||||||
QCOMPARE(flm->property("showFiles").toBool(), false);
|
QCOMPARE(flm->property("showFiles").toBool(), false);
|
||||||
QTRY_COMPARE(flm->property("count").toInt(), 1); // wait for refresh
|
QTRY_COMPARE(flm->property("count").toInt(), 2); // wait for refresh
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qquickfolderlistmodel::resetFiltering()
|
void tst_qquickfolderlistmodel::resetFiltering()
|
||||||
|
@ -225,7 +226,7 @@ void tst_qquickfolderlistmodel::refresh()
|
||||||
QVERIFY(flm != 0);
|
QVERIFY(flm != 0);
|
||||||
|
|
||||||
flm->setProperty("folder", dataDirectoryUrl());
|
flm->setProperty("folder", dataDirectoryUrl());
|
||||||
QTRY_COMPARE(flm->property("count").toInt(),6); // wait for refresh
|
QTRY_COMPARE(flm->property("count").toInt(),8); // wait for refresh
|
||||||
|
|
||||||
int count = flm->rowCount();
|
int count = flm->rowCount();
|
||||||
|
|
||||||
|
@ -329,7 +330,7 @@ void tst_qquickfolderlistmodel::showDotAndDotDot()
|
||||||
flm->setProperty("rootFolder", rootFolder);
|
flm->setProperty("rootFolder", rootFolder);
|
||||||
flm->setProperty("showDotAndDotDot", showDotAndDotDot);
|
flm->setProperty("showDotAndDotDot", showDotAndDotDot);
|
||||||
|
|
||||||
int count = 6;
|
int count = 9;
|
||||||
if (showDot) count++;
|
if (showDot) count++;
|
||||||
if (showDotDot) count++;
|
if (showDotDot) count++;
|
||||||
QTRY_COMPARE(flm->property("count").toInt(), count); // wait for refresh
|
QTRY_COMPARE(flm->property("count").toInt(), count); // wait for refresh
|
||||||
|
@ -360,10 +361,18 @@ void tst_qquickfolderlistmodel::sortReversed()
|
||||||
QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create());
|
QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create());
|
||||||
QVERIFY(flm != 0);
|
QVERIFY(flm != 0);
|
||||||
flm->setProperty("folder", dataDirectoryUrl());
|
flm->setProperty("folder", dataDirectoryUrl());
|
||||||
|
QTRY_COMPARE(flm->property("count").toInt(), 9); // wait for refresh
|
||||||
|
QCOMPARE(flm->data(flm->index(0),FileNameRole).toString(), QLatin1String("txtdir"));
|
||||||
|
}
|
||||||
|
|
||||||
int count = 6;
|
void tst_qquickfolderlistmodel::introspectQrc()
|
||||||
QTRY_COMPARE(flm->property("count").toInt(), count); // wait for refresh
|
{
|
||||||
QCOMPARE(flm->data(flm->index(0),FileNameRole).toString(), QLatin1String("sortReversed.qml"));
|
QQmlComponent component(&engine, testFileUrl("qrc.qml"));
|
||||||
|
checkNoErrors(component);
|
||||||
|
QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create());
|
||||||
|
QVERIFY(flm != 0);
|
||||||
|
QTRY_COMPARE(flm->property("count").toInt(), 1); // wait for refresh
|
||||||
|
QCOMPARE(flm->data(flm->index(0),FileNameRole).toString(), QLatin1String("hello.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_qquickfolderlistmodel)
|
QTEST_MAIN(tst_qquickfolderlistmodel)
|
||||||
|
|
Loading…
Reference in New Issue