summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2017-12-31 12:38:33 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-01-03 07:53:33 +0000
commite95495142321fdf5c3a50a7ff6322a711be68555 (patch)
tree1db0357a70c43cfd93367c64e3693e2e959ff817
parentfb58845d8f2aa0cffe031d3b16f041dcb61a51f8 (diff)
Fix QAbstractItemModel::beginRemoveRows in examples
QAbstractItemModel::beginRemoveRows() must not take a negative value for first or last. It will assert so we should make sure the examples are correct. The assertion was added in 00c09e752ff7e482e1308e0e34721dc979204595 Change-Id: I539175c0597ed6f0ae76b7493fd3dca40638714e Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Martin Smith <martin.smith@qt.io>
-rw-r--r--examples/widgets/itemviews/fetchmore/filelistmodel.cpp3
-rw-r--r--examples/widgets/itemviews/puzzle/piecesmodel.cpp10
2 files changed, 9 insertions, 4 deletions
diff --git a/examples/widgets/itemviews/fetchmore/filelistmodel.cpp b/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
index cd21712e04..086d45eca3 100644
--- a/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
+++ b/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
@@ -103,6 +103,9 @@ void FileListModel::fetchMore(const QModelIndex & /* index */)
int remainder = fileList.size() - fileCount;
int itemsToFetch = qMin(100, remainder);
+ if (itemsToFetch <= 0)
+ return;
+
beginInsertRows(QModelIndex(), fileCount, fileCount+itemsToFetch-1);
fileCount += itemsToFetch;
diff --git a/examples/widgets/itemviews/puzzle/piecesmodel.cpp b/examples/widgets/itemviews/puzzle/piecesmodel.cpp
index f0649d3776..28b46836f4 100644
--- a/examples/widgets/itemviews/puzzle/piecesmodel.cpp
+++ b/examples/widgets/itemviews/puzzle/piecesmodel.cpp
@@ -203,10 +203,12 @@ Qt::DropActions PiecesModel::supportedDropActions() const
void PiecesModel::addPieces(const QPixmap& pixmap)
{
- beginRemoveRows(QModelIndex(), 0, 24);
- pixmaps.clear();
- locations.clear();
- endRemoveRows();
+ if (!pixmaps.isEmpty()) {
+ beginRemoveRows(QModelIndex(), 0, pixmaps.size() - 1);
+ pixmaps.clear();
+ locations.clear();
+ endRemoveRows();
+ }
for (int y = 0; y < 5; ++y) {
for (int x = 0; x < 5; ++x) {
QPixmap pieceImage = pixmap.copy(x*m_PieceSize, y*m_PieceSize, m_PieceSize, m_PieceSize);