From af84f12298e7ba51d4121f9dd7a1b6e3ba050266 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 24 Nov 2018 17:29:15 +0100 Subject: Cleanup Itemviews examples Cleanup the Itemviews examples - use nullptr instead 0 - use for loop instead foreach - include own header first - remove uselss includes Change-Id: I32e9f64356e42038707d063dcad977239ce1fe9e Reviewed-by: Luca Beldi Reviewed-by: Sze Howe Koh --- .../widgets/itemviews/fetchmore/filelistmodel.cpp | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'examples/widgets/itemviews/fetchmore/filelistmodel.cpp') diff --git a/examples/widgets/itemviews/fetchmore/filelistmodel.cpp b/examples/widgets/itemviews/fetchmore/filelistmodel.cpp index 086d45eca3..3ee80617c0 100644 --- a/examples/widgets/itemviews/fetchmore/filelistmodel.cpp +++ b/examples/widgets/itemviews/fetchmore/filelistmodel.cpp @@ -50,20 +50,18 @@ #include "filelistmodel.h" -#include -#include +#include #include #include FileListModel::FileListModel(QObject *parent) - : QAbstractListModel(parent) -{ -} + : QAbstractListModel(parent), fileCount(0) +{} //![4] -int FileListModel::rowCount(const QModelIndex & /* parent */) const +int FileListModel::rowCount(const QModelIndex &parent) const { - return fileCount; + return parent.isValid() ? 0 : fileCount; } QVariant FileListModel::data(const QModelIndex &index, int role) const @@ -88,25 +86,26 @@ QVariant FileListModel::data(const QModelIndex &index, int role) const //![4] //![1] -bool FileListModel::canFetchMore(const QModelIndex & /* index */) const +bool FileListModel::canFetchMore(const QModelIndex &parent) const { - if (fileCount < fileList.size()) - return true; - else + if (parent.isValid()) return false; + return (fileCount < fileList.size()); } //![1] //![2] -void FileListModel::fetchMore(const QModelIndex & /* index */) +void FileListModel::fetchMore(const QModelIndex &parent) { + if (parent.isValid()) + return; int remainder = fileList.size() - fileCount; int itemsToFetch = qMin(100, remainder); if (itemsToFetch <= 0) return; - beginInsertRows(QModelIndex(), fileCount, fileCount+itemsToFetch-1); + beginInsertRows(QModelIndex(), fileCount, fileCount + itemsToFetch - 1); fileCount += itemsToFetch; -- cgit v1.2.3