diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-11-24 17:29:15 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-12-17 19:50:38 +0000 |
commit | af84f12298e7ba51d4121f9dd7a1b6e3ba050266 (patch) | |
tree | e50ee76c43ae66b638cfc367cf74cbeda7de0a28 /examples/widgets/itemviews/fetchmore | |
parent | b8720e3e7a93121cd2e6dc081d872e8000ce81c9 (diff) |
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 <v.ronin@yahoo.it>
Reviewed-by: Sze Howe Koh <szehowe.koh@gmail.com>
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); |