QStandardItem: correctly set model during insertRows()
When calling insertRows(), the model of the child items was not correctly updated. insertRow() is behaving correctly. Pick-to: 6.8 Fixes: QTBUG-131372 Change-Id: I8b6aef7ab97887c6eb46eb21b992d76e4d59b3a0 Reviewed-by: David Faure <david.faure@kdab.com> (cherry picked from commit 5bab8448feb2661f871e71d71a95afaffcb1656a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
3660ff9ff8
commit
3536eb32bf
@ -451,8 +451,7 @@ bool QStandardItemPrivate::insertRows(int row, const QList<QStandardItem*> &item
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < items.size(); ++i) {
|
for (int i = 0; i < items.size(); ++i) {
|
||||||
QStandardItem *item = items.at(i);
|
QStandardItem *item = items.at(i);
|
||||||
item->d_func()->model = model;
|
item->d_func()->setParentAndModel(q, model);
|
||||||
item->d_func()->parent = q;
|
|
||||||
int index = childIndex(i + row, 0);
|
int index = childIndex(i + row, 0);
|
||||||
children.replace(index, item);
|
children.replace(index, item);
|
||||||
if (item)
|
if (item)
|
||||||
|
@ -68,6 +68,7 @@ private slots:
|
|||||||
void insertRow();
|
void insertRow();
|
||||||
void insertRows();
|
void insertRows();
|
||||||
void insertRowsItems();
|
void insertRowsItems();
|
||||||
|
void insertRowsWithChildItems();
|
||||||
void insertRowInHierarcy();
|
void insertRowInHierarcy();
|
||||||
void insertColumn_data();
|
void insertColumn_data();
|
||||||
void insertColumn();
|
void insertColumn();
|
||||||
@ -296,6 +297,39 @@ void tst_QStandardItemModel::insertRowsItems()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QStandardItemModel::insertRowsWithChildItems()
|
||||||
|
{
|
||||||
|
QStandardItemModel model;
|
||||||
|
auto *top = new QStandardItem("top");
|
||||||
|
auto *mid = new QStandardItem("mid");
|
||||||
|
auto *btm = new QStandardItem("bottom");
|
||||||
|
|
||||||
|
model.appendRow(top);
|
||||||
|
mid->appendRow(btm);
|
||||||
|
|
||||||
|
QCOMPARE(top->model(), &model);
|
||||||
|
QCOMPARE(mid->model(), nullptr);
|
||||||
|
QCOMPARE(btm->model(), nullptr);
|
||||||
|
|
||||||
|
top->appendRow(mid);
|
||||||
|
QCOMPARE(top->model(), &model);
|
||||||
|
QCOMPARE(mid->model(), &model);
|
||||||
|
QCOMPARE(btm->model(), &model);
|
||||||
|
|
||||||
|
auto mid2 = top->takeChild(0);
|
||||||
|
top->removeRow(0);
|
||||||
|
QCOMPARE(mid, mid2);
|
||||||
|
QCOMPARE(top->model(), &model);
|
||||||
|
QCOMPARE(mid->model(), nullptr);
|
||||||
|
QCOMPARE(btm->model(), nullptr);
|
||||||
|
|
||||||
|
top->appendRows({mid}); // other codepath than appendRow() above
|
||||||
|
QCOMPARE(top->model(), &model);
|
||||||
|
QCOMPARE(mid->model(), &model);
|
||||||
|
QCOMPARE(btm->model(), &model);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void tst_QStandardItemModel::insertRowInHierarcy()
|
void tst_QStandardItemModel::insertRowInHierarcy()
|
||||||
{
|
{
|
||||||
QVERIFY(m_model->insertRows(0, 1, QModelIndex()));
|
QVERIFY(m_model->insertRows(0, 1, QModelIndex()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user