QTreeWidgetItem::insertChildren: ignore out of bounds indexes
QTreeWidgetItem::insertChildren should behave like a more-optimized QTreeWidgetItem::insertChild. Unlike the latter, the former lacks out-of-bounds checks, resulting in successful insertions even when using an invalid index (say, bigger than the row/column count). Reintroduce some sanity checks instead. This allows to fix a "fixme" left in the autotest. [ChangeLog][QtWidgets][QTreeWidgetItem] QTreeWidgetItem::insertChildren now ignores insertions happening at invalid indices, for consistency with QTreeWidgetItem::insertChild. Change-Id: I1532597768cc6aff96a6e8f356bc6075b582801d Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
This commit is contained in:
parent
c35342ffeb
commit
bdcbbd7d5b
@ -2009,6 +2009,9 @@ void QTreeWidgetItem::addChildren(const QList<QTreeWidgetItem*> &children)
|
||||
*/
|
||||
void QTreeWidgetItem::insertChildren(int index, const QList<QTreeWidgetItem*> &children)
|
||||
{
|
||||
if (index < 0 || index > this->children.count() || children.isEmpty())
|
||||
return;
|
||||
|
||||
if (view && view->isSortingEnabled()) {
|
||||
for (int n = 0; n < children.count(); ++n)
|
||||
insertChild(index, children.at(n));
|
||||
|
@ -332,10 +332,19 @@ void tst_QTreeWidget::addTopLevelItem()
|
||||
for (int i = 0; i < 10; ++i)
|
||||
tops << new TreeItem();
|
||||
int count = tree.topLevelItemCount();
|
||||
tree.insertTopLevelItems(100000, tops);
|
||||
// ### fixme
|
||||
tree.insertTopLevelItems(count, tops);
|
||||
QCOMPARE(tree.topLevelItemCount(), count + 10);
|
||||
}
|
||||
|
||||
// invalid insert
|
||||
{
|
||||
tops.clear();
|
||||
for (int i = 0; i < 10; ++i)
|
||||
tops << new TreeItem();
|
||||
int count = tree.topLevelItemCount();
|
||||
tree.insertTopLevelItems(100000, tops); // should be a no-op
|
||||
QCOMPARE(tree.topLevelItemCount(), count);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QTreeWidget::currentItem_data()
|
||||
|
Loading…
x
Reference in New Issue
Block a user