From 25e2e372e43374c4f161c06e48f62e738b968370 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Fri, 21 May 2010 18:00:43 +1000 Subject: Fix FolderListModel parentFolder property's file drive handling Task-number: QT-3315 Reviewed-by: Martin Jones --- .../folderlistmodel/qdeclarativefolderlistmodel.cpp | 14 ++++++-------- tests/auto/declarative/declarative.pro | 1 + .../tst_qdeclarativefolderlistmodel.cpp | 6 ++++-- tools/qml/content/Browser.qml | 1 + 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp index 6a7383a..fccb9d4 100644 --- a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp @@ -179,7 +179,8 @@ void QDeclarativeFolderListModel::setFolder(const QUrl &folder) if (folder == d->folder) return; QModelIndex index = d->model.index(folder.toLocalFile()); - if (index.isValid() && d->model.isDir(index)) { + if ((index.isValid() && d->model.isDir(index)) || folder.toLocalFile().isEmpty()) { + d->folder = folder; QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); emit folderChanged(); @@ -188,26 +189,23 @@ void QDeclarativeFolderListModel::setFolder(const QUrl &folder) QUrl QDeclarativeFolderListModel::parentFolder() const { - QUrl r; QString localFile = d->folder.toLocalFile(); if (!localFile.isEmpty()) { QDir dir(localFile); -#if defined(Q_OS_SYMBIAN) +#if defined(Q_OS_SYMBIAN) || defined(Q_OS_WIN) if (dir.isRoot()) dir.setPath(""); else #endif dir.cdUp(); - r = d->folder; - r.setPath(dir.path()); + localFile = dir.path(); } else { int pos = d->folder.path().lastIndexOf(QLatin1Char('/')); if (pos == -1) return QUrl(); - r = d->folder; - r.setPath(d->folder.path().left(pos)); + localFile = d->folder.path().left(pos); } - return r; + return QUrl::fromLocalFile(localFile); } /*! diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 4bb3518..484fbef 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -24,6 +24,7 @@ SUBDIRS += \ qdeclarativeecmascript \ qdeclarativeengine \ qdeclarativeerror \ + qdeclarativefolderlistmodel \ qdeclarativefontloader \ qdeclarativeflickable \ qdeclarativeflipable \ diff --git a/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp b/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp index 8a8bfe7..3cf9613 100644 --- a/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp +++ b/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp @@ -93,7 +93,6 @@ void tst_qdeclarativefolderlistmodel::basicProperties() QAbstractListModel *flm = qobject_cast(component.create()); QVERIFY(flm != 0); - flm->setProperty("folder",QUrl::fromLocalFile(SRCDIR "/data")); QTRY_COMPARE(flm->property("count").toInt(),2); // wait for refresh QCOMPARE(flm->property("folder").toUrl(), QUrl::fromLocalFile(SRCDIR "/data")); @@ -105,7 +104,10 @@ void tst_qdeclarativefolderlistmodel::basicProperties() QCOMPARE(flm->property("showDotAndDotDot").toBool(), false); QCOMPARE(flm->property("showOnlyReadable").toBool(), false); QCOMPARE(flm->data(flm->index(0),FileNameRole).toString(), QLatin1String("basic.qml")); - QCOMPARE(flm->data(flm->index(1),FileNameRole).toString(), QLatin1String("dummy.qml")); + QCOMPARE(flm->data(flm->index(1),FileNameRole).toString(), QLatin1String("dummy.qml")); + + flm->setProperty("folder",QUrl::fromLocalFile("")); + QCOMPARE(flm->property("folder").toUrl(), QUrl::fromLocalFile("")); } QTEST_MAIN(tst_qdeclarativefolderlistmodel) diff --git a/tools/qml/content/Browser.qml b/tools/qml/content/Browser.qml index cc59375..838a848 100644 --- a/tools/qml/content/Browser.qml +++ b/tools/qml/content/Browser.qml @@ -129,6 +129,7 @@ Rectangle { anchors.leftMargin: 54 font.pixelSize: 32 color: (wrapper.ListView.isCurrentItem && root.keyPressed) ? palette.highlightedText : palette.windowText + elide: Text.ElideRight } MouseArea { id: mouseRegion -- cgit v0.12