diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-07-01 01:57:37 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-07-01 01:57:37 (GMT) |
commit | ee44073a48392972f704d36f8794171700dceba4 (patch) | |
tree | a82c7bc8f8791dcbaa3bfd307f816ef00cc4fbb6 /src | |
parent | 1971dbdde166f6e21da6bdceac582ca7bb5c5542 (diff) | |
download | Qt-ee44073a48392972f704d36f8794171700dceba4.zip Qt-ee44073a48392972f704d36f8794171700dceba4.tar.gz Qt-ee44073a48392972f704d36f8794171700dceba4.tar.bz2 |
FolderListModel fixes.
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/extra/qmlfolderlistmodel.cpp | 48 | ||||
-rw-r--r-- | src/declarative/extra/qmlfolderlistmodel.h | 2 |
2 files changed, 38 insertions, 12 deletions
diff --git a/src/declarative/extra/qmlfolderlistmodel.cpp b/src/declarative/extra/qmlfolderlistmodel.cpp index abec01e..649169b 100644 --- a/src/declarative/extra/qmlfolderlistmodel.cpp +++ b/src/declarative/extra/qmlfolderlistmodel.cpp @@ -51,7 +51,7 @@ QT_MODULE(Declarative) class QmlFolderListModelPrivate : public QObjectPrivate { public: - QmlFolderListModelPrivate() { + QmlFolderListModelPrivate() : count(0) { folder = QDir::currentPath(); nameFilters << "*"; } @@ -60,6 +60,7 @@ public: QString folder; QStringList nameFilters; QModelIndex folderIndex; + int count; }; QmlFolderListModel::QmlFolderListModel(QObject *parent) @@ -69,6 +70,11 @@ QmlFolderListModel::QmlFolderListModel(QObject *parent) d->model.setFilter(QDir::AllDirs | QDir::Files | QDir::Drives); connect(&d->model, SIGNAL(rowsInserted(const QModelIndex&,int,int)) , this, SLOT(inserted(const QModelIndex&,int,int))); + connect(&d->model, SIGNAL(rowsRemoved(const QModelIndex&,int,int)) + , this, SLOT(removed(const QModelIndex&,int,int))); + connect(&d->model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)) + , this, SLOT(dataChanged(const QModelIndex&,const QModelIndex&))); + connect(&d->model, SIGNAL(modelReset()), this, SLOT(refresh())); } QmlFolderListModel::~QmlFolderListModel() @@ -91,9 +97,7 @@ QHash<int,QVariant> QmlFolderListModel::data(int index, const QList<int> &roles) int QmlFolderListModel::count() const { Q_D(const QmlFolderListModel); - if (!d->folderIndex.isValid()) - return 0; - return d->model.rowCount(d->folderIndex); + return d->count; } QList<int> QmlFolderListModel::roles() const @@ -164,22 +168,42 @@ bool QmlFolderListModel::isFolder(int index) const void QmlFolderListModel::refresh() { Q_D(QmlFolderListModel); - int prevCount = count(); d->folderIndex = QModelIndex(); - if (prevCount) - emit itemsRemoved(0, prevCount); + if (d->count) { + int tmpCount = d->count; + d->count = 0; + emit itemsRemoved(0, tmpCount); + } d->folderIndex = d->model.index(d->folder); - qDebug() << "count" << count(); - if (count()) - emit itemsInserted(0, count()); + d->count = d->model.rowCount(d->folderIndex); + if (d->count) { + emit itemsInserted(0, d->count); + } } void QmlFolderListModel::inserted(const QModelIndex &index, int start, int end) { Q_D(QmlFolderListModel); - qDebug() << "inserted" << start << end; - if (index == d->folderIndex) + if (index == d->folderIndex) { + d->count = d->model.rowCount(d->folderIndex); emit itemsInserted(start, end - start + 1); + } +} + +void QmlFolderListModel::removed(const QModelIndex &index, int start, int end) +{ + Q_D(QmlFolderListModel); + if (index == d->folderIndex) { + d->count = d->model.rowCount(d->folderIndex); + emit itemsRemoved(start, end - start + 1); + } +} + +void QmlFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end) +{ + Q_D(QmlFolderListModel); + if (start.parent() == d->folderIndex) + emit itemsChanged(start.row(), end.row() - start.row() + 1, roles()); } QML_DEFINE_TYPE(QmlFolderListModel,FolderListModel) diff --git a/src/declarative/extra/qmlfolderlistmodel.h b/src/declarative/extra/qmlfolderlistmodel.h index a6e8526..d46ec79 100644 --- a/src/declarative/extra/qmlfolderlistmodel.h +++ b/src/declarative/extra/qmlfolderlistmodel.h @@ -88,6 +88,8 @@ Q_SIGNALS: private Q_SLOTS: void refresh(); void inserted(const QModelIndex &index, int start, int end); + void removed(const QModelIndex &index, int start, int end); + void dataChanged(const QModelIndex &start, const QModelIndex &end); private: Q_DECLARE_PRIVATE(QmlFolderListModel) |