summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2011-08-25 14:38:55 +1000
committerMichael Brasser <michael.brasser@nokia.com>2011-08-25 14:38:55 +1000
commit057666b294f8d0ac50fc97134a6591bd2f33b83c (patch)
treeaea08551e08deae3c607834427d3669ac85b4b47
parent163b4b8310af7aaa994246cbcdab8ac2618f316d (diff)
Off-by-one fixes.HEADmaster
-rw-r--r--qobjectlistmodel.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/qobjectlistmodel.cpp b/qobjectlistmodel.cpp
index 899a0a1..d7ab1e9 100644
--- a/qobjectlistmodel.cpp
+++ b/qobjectlistmodel.cpp
@@ -167,7 +167,7 @@ void QObjectListModel::append(QObject *object)
*/
void QObjectListModel::append(const QObjectList &objects)
{
- beginInsertRows(QModelIndex(), m_objects.count(), m_objects.count()+objects.count());
+ beginInsertRows(QModelIndex(), m_objects.count(), m_objects.count()+objects.count()-1);
m_objects.append(objects);
endInsertRows();
emit countChanged();
@@ -196,7 +196,10 @@ void QObjectListModel::insert(int i, QObject *object)
*/
void QObjectListModel::insert(int i, const QObjectList &objects)
{
- beginInsertRows(QModelIndex(), i, i+objects.count());
+ if (objects.isEmpty())
+ return;
+
+ beginInsertRows(QModelIndex(), i, i+objects.count()-1);
for (int j = objects.count() - 1; j > -1; --j)
m_objects.insert(i, objects.at(j));
endInsertRows();
@@ -237,13 +240,13 @@ void QObjectListModel::move(int from, int to)
/*!
Removes \a count number of items from index position \a i and notifies any views.
\a i must be a valid index position in the model (i.e., 0 <= \a i < size()), as
- must \c{i + count}.
+ must \c{i + count - 1}.
\sa takeAt()
*/
void QObjectListModel::removeAt(int i, int count)
{
- beginRemoveRows(QModelIndex(), i, i + count);
+ beginRemoveRows(QModelIndex(), i, i + count - 1);
for (int j = 0; j < count; ++j)
m_objects.removeAt(i);
endRemoveRows();