diff options
Diffstat (limited to 'examples/widgets/itemviews/fetchmore')
4 files changed, 16 insertions, 18 deletions
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 <QApplication> -#include <QBrush> +#include <QGuiApplication> #include <QDir> #include <QPalette> 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; diff --git a/examples/widgets/itemviews/fetchmore/filelistmodel.h b/examples/widgets/itemviews/fetchmore/filelistmodel.h index 9251eaf959..35cf6f7b46 100644 --- a/examples/widgets/itemviews/fetchmore/filelistmodel.h +++ b/examples/widgets/itemviews/fetchmore/filelistmodel.h @@ -52,7 +52,6 @@ #define FILELISTMODEL_H #include <QAbstractListModel> -#include <QList> #include <QStringList> //![0] @@ -61,7 +60,7 @@ class FileListModel : public QAbstractListModel Q_OBJECT public: - FileListModel(QObject *parent = 0); + FileListModel(QObject *parent = nullptr); int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; diff --git a/examples/widgets/itemviews/fetchmore/window.cpp b/examples/widgets/itemviews/fetchmore/window.cpp index 886f76d6ab..d71ac7059d 100644 --- a/examples/widgets/itemviews/fetchmore/window.cpp +++ b/examples/widgets/itemviews/fetchmore/window.cpp @@ -48,8 +48,8 @@ ** ****************************************************************************/ -#include "filelistmodel.h" #include "window.h" +#include "filelistmodel.h" #include <QtWidgets> @@ -66,7 +66,7 @@ Window::Window(QWidget *parent) QListView *view = new QListView; view->setModel(model); - logViewer = new QTextBrowser; + logViewer = new QTextBrowser(this); logViewer->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); connect(lineEdit, &QLineEdit::textChanged, diff --git a/examples/widgets/itemviews/fetchmore/window.h b/examples/widgets/itemviews/fetchmore/window.h index f234683785..61bcb94bde 100644 --- a/examples/widgets/itemviews/fetchmore/window.h +++ b/examples/widgets/itemviews/fetchmore/window.h @@ -62,7 +62,7 @@ class Window : public QWidget Q_OBJECT public: - Window(QWidget *parent = 0); + Window(QWidget *parent = nullptr); public slots: void updateLog(int number); |