summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-01-30 12:39:22 +0100
committerLiang Qi <liang.qi@qt.io>2017-01-30 12:46:20 +0100
commit246799d8a7bf42c1f22fca7ef6d77e8d58054bad (patch)
treea0b92a804d7d2a30cd68fa327df5777d8bcc36ba /tests/auto/widgets/itemviews
parent5ad191850becd7dc1d61d0975f141a5db64e6373 (diff)
parent02cc57f4edbae450ecfa8368052afa44f8aeee19 (diff)
Merge remote-tracking branch 'origin/5.8' into dev
Conflicts: examples/network/network-chat/peermanager.cpp src/widgets/util/qsystemtrayicon.cpp src/widgets/util/qsystemtrayicon_qpa.cpp src/widgets/util/qsystemtrayicon_win.cpp src/widgets/util/qsystemtrayicon_x11.cpp Change-Id: I1c026df83818c0ccaf956980370e7522960627db
Diffstat (limited to 'tests/auto/widgets/itemviews')
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp8
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp6
-rw-r--r--tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp2
-rw-r--r--tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp2
-rw-r--r--tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp2
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp9
-rw-r--r--tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp41
7 files changed, 39 insertions, 31 deletions
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
index bd6733e2d0..426db265ae 100644
--- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
+++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
@@ -1567,7 +1567,7 @@ void tst_QAbstractItemView::testChangeEditorState()
QTableView view;
view.setEditTriggers(QAbstractItemView::CurrentChanged);
- view.setItemDelegate(new StateChangeDelegate);
+ view.setItemDelegate(new StateChangeDelegate(&view));
view.setModel(&model);
centerOnScreen(&view);
moveCursorAway(&view);
@@ -1941,7 +1941,8 @@ void tst_QAbstractItemView::QTBUG50102_SH_ItemView_ScrollMode()
QCOMPARE(view.horizontalScrollMode(), styleScrollMode);
// Change style, get new value
- view.setStyle(new ScrollModeProxyStyle(styleScrollMode));
+ ScrollModeProxyStyle proxyStyle1(styleScrollMode);
+ view.setStyle(&proxyStyle1);
auto proxyScrollMode = static_cast<QAbstractItemView::ScrollMode>(view.style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, &view, 0));
QVERIFY(styleScrollMode != proxyScrollMode);
QCOMPARE(view.verticalScrollMode(), proxyScrollMode);
@@ -1953,7 +1954,8 @@ void tst_QAbstractItemView::QTBUG50102_SH_ItemView_ScrollMode()
QCOMPARE(view.horizontalScrollMode(), proxyScrollMode);
// Change style, won't change value for vertical, will change for horizontal
- view.setStyle(new ScrollModeProxyStyle(proxyScrollMode));
+ ScrollModeProxyStyle proxyStyle2(proxyScrollMode);
+ view.setStyle(&proxyStyle2);
QCOMPARE(view.verticalScrollMode(), proxyScrollMode);
QCOMPARE(view.horizontalScrollMode(), styleScrollMode);
}
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index 1078dcc2e9..7bfec2831d 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -2523,7 +2523,8 @@ void tst_QHeaderView::calculateAndCheck(int cppline, const int precalced_compare
const bool sanity_checks = true;
if (sanity_checks) {
QString msg = QString("sanity problem at ") + sline;
- char *verifytext = QTest::toString(msg);
+ const QScopedArrayPointer<char> holder(QTest::toString(msg));
+ const auto verifytext = holder.data();
QVERIFY2(m_tableview->model()->rowCount() == view->count() , verifytext);
QVERIFY2(view->visualIndex(lastindex + 1) <= 0, verifytext); // there is no such index in model
@@ -2555,7 +2556,8 @@ void tst_QHeaderView::calculateAndCheck(int cppline, const int precalced_compare
msg += istr(chk_visual) + istr(chk_logical) + istr(chk_sizes) + istr(chk_hidden_size)
+ istr(chk_lookup_visual) + istr(chk_lookup_logical) + istr(header_lenght, false) + "};";
- char *verifytext = QTest::toString(msg);
+ const QScopedArrayPointer<char> holder(QTest::toString(msg));
+ const auto verifytext = holder.data();
QVERIFY2(chk_visual == x[0], verifytext);
QVERIFY2(chk_logical == x[1], verifytext);
diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp
index 0720a4f766..5b353bb2ae 100644
--- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp
+++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp
@@ -1350,7 +1350,7 @@ void tst_QItemDelegate::QTBUG4435_keepSelectionOnCheck()
}
QTableView view;
view.setModel(&model);
- view.setItemDelegate(new TestItemDelegate);
+ view.setItemDelegate(new TestItemDelegate(&view));
view.show();
view.selectAll();
QVERIFY(QTest::qWaitForWindowExposed(&view));
diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
index 8c7c5f1050..29e4bbfe29 100644
--- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
+++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
@@ -1489,7 +1489,7 @@ void tst_QListView::task203585_selectAll()
//we make sure that "select all" doesn't select the hidden items
QListView view;
view.setSelectionMode(QAbstractItemView::ExtendedSelection);
- view.setModel(new QStringListModel( QStringList() << "foo"));
+ view.setModel(new QStringListModel(QStringList() << "foo", &view));
view.setRowHidden(0, true);
view.selectAll();
QVERIFY(view.selectionModel()->selectedIndexes().isEmpty());
diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
index eb93e4c167..6547bb8985 100644
--- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
+++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
@@ -1629,7 +1629,7 @@ void tst_QListWidget::QTBUG14363_completerWithAnyKeyPressedEditTriggers()
{
QListWidget listWidget;
listWidget.setEditTriggers(QAbstractItemView::AnyKeyPressed);
- listWidget.setItemDelegate(new ItemDelegate);
+ listWidget.setItemDelegate(new ItemDelegate(&listWidget));
QListWidgetItem *item = new QListWidgetItem(QLatin1String("select an item (don't start editing)"), &listWidget);
item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsEditable);
new QListWidgetItem(QLatin1String("try to type the letter 'c'"), &listWidget);
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
index 80ef0879cc..e2886cfcfe 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -3796,25 +3796,24 @@ void tst_QTreeView::task248022_changeSelection()
void tst_QTreeView::task245654_changeModelAndExpandAll()
{
QTreeView view;
- QStandardItemModel *model = new QStandardItemModel;
+ QScopedPointer<QStandardItemModel> model(new QStandardItemModel);
QStandardItem *top = new QStandardItem("top");
QStandardItem *sub = new QStandardItem("sub");
top->appendRow(sub);
model->appendRow(top);
- view.setModel(model);
+ view.setModel(model.data());
view.expandAll();
QApplication::processEvents();
QVERIFY(view.isExpanded(top->index()));
//now let's try to delete the model
//then repopulate and expand again
- delete model;
- model = new QStandardItemModel;
+ model.reset(new QStandardItemModel);
top = new QStandardItem("top");
sub = new QStandardItem("sub");
top->appendRow(sub);
model->appendRow(top);
- view.setModel(model);
+ view.setModel(model.data());
view.expandAll();
QApplication::processEvents();
QVERIFY(view.isExpanded(top->index()));
diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
index fcffaa0eb9..f20805f97e 100644
--- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
@@ -554,16 +554,16 @@ void tst_QTreeWidget::removeChild()
QFETCH(int, childCount);
QFETCH(int, removeAt);
- QTreeWidgetItem *root = new QTreeWidgetItem;
+ const QScopedPointer<QTreeWidgetItem> root(new QTreeWidgetItem);
for (int i = 0; i < childCount; ++i)
- new QTreeWidgetItem(root, QStringList(QString::number(i)));
+ new QTreeWidgetItem(root.data(), QStringList(QString::number(i)));
QCOMPARE(root->childCount(), childCount);
for (int j = 0; j < childCount; ++j)
QCOMPARE(root->child(j)->text(0), QString::number(j));
- QTreeWidgetItem *remove = root->child(removeAt);
- root->removeChild(remove);
+ const QScopedPointer<QTreeWidgetItem> remove(root->child(removeAt));
+ root->removeChild(remove.data());
QCOMPARE(root->childCount(), childCount - 1);
for (int k = 0; k < childCount; ++k) {
@@ -574,7 +574,6 @@ void tst_QTreeWidget::removeChild()
else if (k > removeAt)
QCOMPARE(root->child(k - 1)->text(0), QString::number(k));
}
- delete root;
}
void tst_QTreeWidget::setItemHidden()
@@ -1954,9 +1953,9 @@ void tst_QTreeWidget::itemData()
void tst_QTreeWidget::enableDisable()
{
- QTreeWidgetItem *itm = new QTreeWidgetItem();
+ const QScopedPointer<QTreeWidgetItem> itm(new QTreeWidgetItem);
for (int i = 0; i < 10; ++i)
- new QTreeWidgetItem(itm);
+ new QTreeWidgetItem(itm.data());
// make sure all items are enabled
QVERIFY(itm->flags() & Qt::ItemIsEnabled);
@@ -2720,7 +2719,10 @@ void tst_QTreeWidget::setDisabled()
children.append(new QTreeWidgetItem());
children.append(new QTreeWidgetItem());
children.append(new QTreeWidgetItem());
- i1 = top->takeChild(0);
+ {
+ const QScopedPointer<QTreeWidgetItem> taken(top->takeChild(0));
+ QCOMPARE(taken.data(), i1);
+ }
top->addChildren(children);
QCOMPARE(top->child(0)->isDisabled(), false);
@@ -2732,16 +2734,21 @@ void tst_QTreeWidget::setDisabled()
QCOMPARE(top->child(1)->isDisabled(), true);
QCOMPARE(top->child(1)->isDisabled(), true);
- children = top->takeChildren();
- QCOMPARE(children.at(0)->isDisabled(), false);
- QCOMPARE(children.at(1)->isDisabled(), false);
- QCOMPARE(children.at(1)->isDisabled(), false);
+ struct Deleter {
+ QList<QTreeWidgetItem *> items;
+ explicit Deleter(QList<QTreeWidgetItem *> items) : items(std::move(items)) {}
+ ~Deleter() { qDeleteAll(items); }
+ };
+ const Deleter takenChildren(top->takeChildren());
+ QCOMPARE(takenChildren.items[0]->isDisabled(), false);
+ QCOMPARE(takenChildren.items[1]->isDisabled(), false);
+ QCOMPARE(takenChildren.items[1]->isDisabled(), false);
}
void tst_QTreeWidget::removeSelectedItem()
{
- QTreeWidget *w = new QTreeWidget();
+ const QScopedPointer <QTreeWidget> w(new QTreeWidget);
w->setSortingEnabled(true);
QTreeWidgetItem *first = new QTreeWidgetItem();
@@ -2767,15 +2774,13 @@ void tst_QTreeWidget::removeSelectedItem()
QCOMPARE(selModel->hasSelection(), true);
QCOMPARE(selModel->selectedRows().count(), 1);
- QTreeWidgetItem *taken = w->takeTopLevelItem(2);
+ const QScopedPointer<QTreeWidgetItem> taken(w->takeTopLevelItem(2));
QCOMPARE(taken->text(0), QLatin1String("C"));
QCOMPARE(selModel->hasSelection(), false);
QCOMPARE(selModel->selectedRows().count(), 0);
QItemSelection sel = selModel->selection();
QCOMPARE(selModel->isSelected(w->model()->index(0,0)), false);
-
- delete w;
}
class AnotherTreeWidget : public QTreeWidget
@@ -2934,11 +2939,11 @@ void tst_QTreeWidget::sortAndSelect()
void tst_QTreeWidget::defaultRowSizes()
{
- QTreeWidget *tw = new QTreeWidget();
+ const QScopedPointer<QTreeWidget> tw(new QTreeWidget);
tw->setIconSize(QSize(50, 50));
tw->setColumnCount(6);
for (int i=0; i<10; ++i) {
- QTreeWidgetItem *it = new QTreeWidgetItem(tw);
+ auto it = new QTreeWidgetItem(tw.data());
for (int j=0; j<tw->columnCount() - 1; ++j) {
it->setText(j, "This is a test");
}