summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp55
-rw-r--r--tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp4
-rw-r--r--tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp2
-rw-r--r--tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp4
-rw-r--r--tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp159
-rw-r--r--tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp1
-rw-r--r--tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp126
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp152
-rw-r--r--tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp240
-rw-r--r--tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp16
-rw-r--r--tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp11
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp7
-rw-r--r--tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp47
-rw-r--r--tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp76
-rw-r--r--tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp48
-rw-r--r--tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp25
-rw-r--r--tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp11
-rw-r--r--tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp62
-rw-r--r--tests/auto/widgets/widgets/qsplitter/BLACKLIST2
-rw-r--r--tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp45
20 files changed, 915 insertions, 178 deletions
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index b6932d4892..9d3770064f 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -253,11 +253,12 @@ protected:
void calculateAndCheck(int cppline, const int precalced_comparedata[]);
void testMinMaxSectionSize(bool stretchLastSection);
- QWidget *topLevel;
- QHeaderView *view;
- QStandardItemModel *model;
- QTableView *m_tableview;
- bool m_using_reset_model;
+ QWidget *topLevel = nullptr;
+ QHeaderView *view = nullptr;
+ QStandardItemModel *model = nullptr;
+ QTableView *m_tableview = nullptr;
+ bool m_using_reset_model = false;
+ bool m_special_prepare = false;
QElapsedTimer timer;
};
@@ -614,6 +615,27 @@ void tst_QHeaderView::hidden()
view->setSectionHidden(1, false);
QCOMPARE(view->isSectionHidden(0), false);
QCOMPARE(view->sectionSize(0), view->defaultSectionSize());
+
+ // d->hiddenSectionSize could go out of sync when a new model
+ // was set which has fewer sections than before and some of them
+ // were hidden
+ QStandardItemModel model2(model->rowCount() - 1, model->columnCount());
+
+ for (int i = 0; i < model->rowCount(); ++i)
+ view->setSectionHidden(i, true);
+ view->setModel(&model2);
+ QVERIFY(view->sectionsHidden());
+ for (int i = 0; i < model2.rowCount(); ++i) {
+ QVERIFY(view->isSectionHidden(i));
+ }
+
+ view->setModel(model);
+ for (int i = 0; i < model2.rowCount(); ++i) {
+ QVERIFY(view->isSectionHidden(i));
+ }
+ QCOMPARE(view->isSectionHidden(model->rowCount() - 1), false);
+ for (int i = 0; i < model->rowCount(); ++i)
+ view->setSectionHidden(i, false);
}
void tst_QHeaderView::stretch()
@@ -2822,6 +2844,7 @@ void tst_QHeaderView::additionalInit()
QFETCH(bool, reset_model);
m_using_reset_model = reset_model;
+ m_special_prepare = special_prepare;
if (m_using_reset_model) {
XResetModel *m = new XResetModel();
@@ -3035,18 +3058,34 @@ void tst_QHeaderView::mixedTests()
view->moveSection(0, 5);
for (int u = model->rowCount(); u >= 0; --u) {
- if (u % 5 != 0)
+ if (u % 5 != 0) {
view->hideSection(u);
- if (u % 3 != 0)
+ QVERIFY(view->isSectionHidden(u));
+ }
+ if (u % 3 != 0) {
view->showSection(u);
+ QVERIFY(!view->isSectionHidden(u));
+ }
}
model->insertRows(3, 7);
model->removeRows(8, 3);
model->setRowCount(model->rowCount() - 10);
+ // the upper is not visible (when m_using_reset_model is true)
+ // the lower 11 are modified due to insert/removeRows
+ for (int u = model->rowCount() - 1; u >= 11; --u) {
+ // when using reset, the hidden rows will *not* move
+ const int calcMod = m_using_reset_model ? u : u - 4; // 7 added, 3 removed
+ if (calcMod % 5 != 0 && calcMod % 3 == 0) {
+ QVERIFY(view->isSectionHidden(u));
+ }
+ if (calcMod % 3 != 0) {
+ QVERIFY(!view->isSectionHidden(u));
+ }
+ }
if (m_using_reset_model) {
- const int precalced_results[] = { 898296472, 337096378, -543340640, 1, -1251526424, -568618976, 9250 };
+ const int precalced_results[] = { 898296472, 337096378, -543340640, -1964432121, -1251526424, -568618976, 9250 };
calculateAndCheck(__LINE__, precalced_results);
} else {
const int precalced_results[] = { 1911338224, 1693514365, -613398968, -1912534953, 1582159424, -1851079000, 9300 };
diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp
index aa11ed709f..7fd1822295 100644
--- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp
+++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp
@@ -1228,7 +1228,7 @@ void tst_QItemDelegate::editorEvent()
option.checkState = Qt::CheckState(checkState);
const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1;
- QPoint pos = inCheck ? qApp->style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &option, 0).center() + QPoint(checkMargin, 0) : QPoint(200,200);
+ QPoint pos = inCheck ? qApp->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &option, 0).center() + QPoint(checkMargin, 0) : QPoint(200,200);
QEvent *event = new QMouseEvent((QEvent::Type)type,
pos,
@@ -1384,7 +1384,7 @@ void tst_QItemDelegate::QTBUG4435_keepSelectionOnCheck()
option.features = QStyleOptionViewItem::HasDisplay | QStyleOptionViewItem::HasCheckIndicator;
option.checkState = Qt::CheckState(model.index(0, 0).data(Qt::CheckStateRole).toInt());
const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1;
- QPoint pos = qApp->style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &option, 0).center()
+ QPoint pos = qApp->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &option, 0).center()
+ QPoint(checkMargin, 0);
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, pos);
QTRY_VERIFY(view.selectionModel()->isColumnSelected(0, QModelIndex()));
diff --git a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
index bbdaac5c6f..071665a5e3 100644
--- a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
+++ b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
@@ -249,7 +249,7 @@ void tst_QItemView::populate()
for (int y = 0; y < treeModel->columnCount(); ++y) {
QModelIndex index = treeModel->index(x, y, parent);
treeModel->setData(index, xS + QLatin1Char('_') + QString::number(y) + QLatin1Char('_') + iS);
- treeModel->setData(index, QVariant(QColor(Qt::blue)), Qt::TextColorRole);
+ treeModel->setData(index, QVariant(QColor(Qt::blue)), Qt::ForegroundRole);
}
}
}
diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
index 5227db64ec..433b9e55e1 100644
--- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
+++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
@@ -873,6 +873,10 @@ void tst_QListView::setCurrentIndex()
}
}
}
+ while (model.rowCount()) {
+ view.setCurrentIndex(model.index(model.rowCount() - 1, 0));
+ model.removeRow(model.rowCount() - 1);
+ }
}
class PublicListView : public QListView
diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
index 98b44fe8aa..0c1b20d61a 100644
--- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
+++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
@@ -31,6 +31,7 @@
#include <QtGui/QtGui>
#include <QtWidgets/QtWidgets>
#include <qlist.h>
+#include <QSignalSpy>
#include <qlistwidget.h>
#include <private/qlistwidget_p.h>
@@ -116,6 +117,14 @@ private slots:
void QTBUG14363_completerWithAnyKeyPressedEditTriggers();
void mimeData();
void QTBUG50891_ensureSelectionModelSignalConnectionsAreSet();
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ void clearItemData();
+#endif
+
+ void moveRows_data();
+ void moveRows();
+ void moveRowsInvalid_data();
+ void moveRowsInvalid();
protected slots:
void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last)
@@ -148,6 +157,108 @@ private:
};
+void tst_QListWidget::moveRowsInvalid_data()
+{
+ QTest::addColumn<QListWidget*>("baseWidget");
+ QTest::addColumn<QModelIndex>("startParent");
+ QTest::addColumn<int>("startRow");
+ QTest::addColumn<int>("count");
+ QTest::addColumn<QModelIndex>("destinationParent");
+ QTest::addColumn<int>("destination");
+
+ const auto createWidget = []() -> QListWidget* {
+ QListWidget* result = new QListWidget;
+ result->addItems(QStringList{"A", "B", "C", "D", "E", "F"});
+ return result;
+ };
+
+ QTest::addRow("destination_equal_source") << createWidget() << QModelIndex() << 0 << 1 << QModelIndex() << 1;
+ QTest::addRow("count_equal_0") << createWidget() << QModelIndex() << 0 << 0 << QModelIndex() << 2;
+ QListWidget* tempWidget = createWidget();
+ QTest::addRow("move_child") << tempWidget << tempWidget->model()->index(0, 0) << 0 << 1 << QModelIndex() << 2;
+ tempWidget = createWidget();
+ QTest::addRow("move_to_child") << tempWidget << QModelIndex() << 0 << 1 << tempWidget->model()->index(0, 0) << 2;
+ QTest::addRow("negative_count") << createWidget() << QModelIndex() << 0 << -1 << QModelIndex() << 2;
+ QTest::addRow("negative_source_row") << createWidget() << QModelIndex() << -1 << 1 << QModelIndex() << 2;
+ QTest::addRow("negative_destination_row") << createWidget() << QModelIndex() << 0 << 1 << QModelIndex() << -1;
+ QTest::addRow("source_row_equal_rowCount") << createWidget() << QModelIndex() << 6 << 1 << QModelIndex() << 1;
+ QTest::addRow("destination_row_greater_rowCount") << createWidget() << QModelIndex() << 0 << 1 << QModelIndex() << 6 + 1;
+ QTest::addRow("move_row_within_source_range") << createWidget() << QModelIndex() << 0 << 3 << QModelIndex() << 2;
+ QTest::addRow("destination_row_before_0") << createWidget() << QModelIndex() << 1 << 1 << QModelIndex() << 0;
+}
+
+void tst_QListWidget::moveRowsInvalid()
+{
+ QFETCH(QListWidget* const, baseWidget);
+ QFETCH(const QModelIndex, startParent);
+ QFETCH(const int, startRow);
+ QFETCH(const int, count);
+ QFETCH(const QModelIndex, destinationParent);
+ QFETCH(const int, destination);
+ QAbstractItemModel *baseModel = baseWidget->model();
+ QSignalSpy rowMovedSpy(baseModel, &QAbstractItemModel::rowsMoved);
+ QSignalSpy rowAboutMovedSpy(baseModel, &QAbstractItemModel::rowsAboutToBeMoved);
+ QVERIFY(rowMovedSpy.isValid());
+ QVERIFY(rowAboutMovedSpy.isValid());
+ QVERIFY(!baseModel->moveRows(startParent, startRow, count, destinationParent, destination));
+ QCOMPARE(rowMovedSpy.size(), 0);
+ QCOMPARE(rowAboutMovedSpy.size(), 0);
+ delete baseWidget;
+}
+
+void tst_QListWidget::moveRows_data()
+{
+ QTest::addColumn<int>("startRow");
+ QTest::addColumn<int>("count");
+ QTest::addColumn<int>("destination");
+ QTest::addColumn<QStringList>("expected");
+
+ QTest::newRow("1_Item_from_top_to_middle") << 0 << 1 << 3 << QStringList{"B", "C", "A", "D", "E", "F"};
+ QTest::newRow("1_Item_from_top_to_bottom") << 0 << 1 << 6 << QStringList{"B", "C", "D", "E", "F", "A"};
+ QTest::newRow("1_Item_from_middle_to_top") << 2 << 1 << 1 << QStringList{"C", "A", "B", "D", "E", "F"};
+ QTest::newRow("1_Item_from_bottom_to_middle") << 5 << 1 << 3 << QStringList{"A", "B", "F", "C", "D", "E"};
+ QTest::newRow("1_Item_from_bottom to_top") << 5 << 1 << 1 << QStringList{"F", "A", "B", "C", "D", "E"};
+ QTest::newRow("1_Item_from_middle_to_bottom") << 2 << 1 << 6 << QStringList{"A", "B", "D", "E", "F", "C"};
+ QTest::newRow("1_Item_from_middle_to_middle_before") << 2 << 1 << 1 << QStringList{"C", "A", "B", "D", "E", "F"};
+ QTest::newRow("1_Item_from_middle_to_middle_after") << 2 << 1 << 4 << QStringList{"A", "B", "D", "C", "E", "F"};
+
+ QTest::newRow("2_Items_from_top_to_middle") << 0 << 2 << 3 << QStringList{"C", "A", "B", "D", "E", "F"};
+ QTest::newRow("2_Items_from_top_to_bottom") << 0 << 2 << 6 << QStringList{"C", "D", "E", "F", "A", "B"};
+ QTest::newRow("2_Items_from_middle_to_top") << 2 << 2 << 1 << QStringList{"C", "D", "A", "B", "E", "F"};
+ QTest::newRow("2_Items_from_bottom_to_middle") << 4 << 2 << 3 << QStringList{"A", "B", "E", "F", "C", "D"};
+ QTest::newRow("2_Items_from_bottom_to_top") << 4 << 2 << 1 << QStringList{"E", "F", "A", "B", "C", "D"};
+ QTest::newRow("2_Items_from_middle_to_bottom") << 2 << 2 << 6 << QStringList{"A", "B", "E", "F", "C", "D"};
+ QTest::newRow("2_Items_from_middle_to_middle_before") << 3 << 2 << 2 << QStringList{"A", "D", "E", "B", "C", "F"};
+ QTest::newRow("2_Items_from_middle_to_middle_after") << 1 << 2 << 5 << QStringList{"A", "D", "E", "B", "C", "F"};
+}
+
+void tst_QListWidget::moveRows()
+{
+ QFETCH(const int, startRow);
+ QFETCH(const int, count);
+ QFETCH(const int, destination);
+ QFETCH(const QStringList, expected);
+ QListWidget baseWidget;
+ baseWidget.addItems(QStringList{"A", "B", "C", "D", "E", "F"});
+ QAbstractItemModel *baseModel = baseWidget.model();
+ QSignalSpy rowMovedSpy(baseModel, &QAbstractItemModel::rowsMoved);
+ QSignalSpy rowAboutMovedSpy(baseModel, &QAbstractItemModel::rowsAboutToBeMoved);
+ QVERIFY(baseModel->moveRows(QModelIndex(), startRow, count, QModelIndex(), destination));
+ QCOMPARE(baseModel->rowCount(), expected.size());
+ for (int i = 0; i < expected.size(); ++i)
+ QCOMPARE(baseModel->index(i, 0).data().toString(), expected.at(i));
+ QCOMPARE(rowMovedSpy.size(), 1);
+ QCOMPARE(rowAboutMovedSpy.size(), 1);
+ for (const QList<QVariant> &signalArgs : {rowMovedSpy.first(), rowAboutMovedSpy.first()}){
+ QVERIFY(!signalArgs.at(0).value<QModelIndex>().isValid());
+ QCOMPARE(signalArgs.at(1).toInt(), startRow);
+ QCOMPARE(signalArgs.at(2).toInt(), startRow + count - 1);
+ QVERIFY(!signalArgs.at(3).value<QModelIndex>().isValid());
+ QCOMPARE(signalArgs.at(4).toInt(), destination);
+ }
+}
+
+
typedef QList<int> IntList;
tst_QListWidget::tst_QListWidget(): testWidget(0), rcParent(8), rcFirst(8,0), rcLast(8,0)
@@ -233,7 +344,7 @@ void tst_QListWidget::addItem2()
testWidget->addItem(item);
QCOMPARE(testWidget->count(), ++count);
QCOMPARE(testWidget->item(testWidget->count()-1), item);
- QCOMPARE(testWidget->isItemHidden(item), false);
+ QCOMPARE(item->isHidden(), false);
}
void tst_QListWidget::addItems()
@@ -291,9 +402,11 @@ void tst_QListWidget::closePersistentEditor()
void tst_QListWidget::setItemHidden()
{
+#if QT_DEPRECATED_SINCE(5, 13)
// Boundary checking
testWidget->setItemHidden(0, true);
testWidget->setItemHidden(0, false);
+#endif
int totalHidden = 0;
for (int i = 0; i < testWidget->model()->rowCount(); ++i)
@@ -310,27 +423,27 @@ void tst_QListWidget::setItemHidden()
newTotal++;
QCOMPARE(newTotal, totalHidden);
- testWidget->setItemHidden(item, true);
- QCOMPARE(testWidget->isItemHidden(item), true);
+ item->setHidden(true);
+ QCOMPARE(item->isHidden(), true);
// Check that nothing else changed
newTotal = 0;
for (int i = 0; i < testWidget->model()->rowCount(); ++i)
- if (testWidget->isItemHidden(testWidget->item(i)))
+ if (testWidget->item(i)->isHidden())
newTotal++;
QCOMPARE(newTotal, totalHidden + 1);
- testWidget->setItemHidden(item, false);
- QCOMPARE(testWidget->isItemHidden(item), false);
+ item->setHidden(false);
+ QCOMPARE(item->isHidden(), false);
// Check that nothing else changed
newTotal = 0;
for (int i = 0; i < testWidget->model()->rowCount(); ++i)
- if (testWidget->isItemHidden(testWidget->item(i)))
+ if (testWidget->item(i)->isHidden())
newTotal++;
QCOMPARE(newTotal, totalHidden);
- testWidget->setItemHidden(item, true);
+ item->setHidden(true);
}
void tst_QListWidget::setCurrentItem_data()
@@ -736,7 +849,7 @@ void tst_QListWidget::selectedItems()
testWidget->setSelectionMode(QListWidget::SingleSelection);
for (int i=0; i<itemCount; ++i) {
QListWidgetItem *item = testWidget->item(i);
- testWidget->setItemSelected(item, true);
+ item->setSelected(true);
QVERIFY(item->isSelected());
QCOMPARE(testWidget->selectedItems().count(), 1);
}
@@ -749,10 +862,10 @@ void tst_QListWidget::selectedItems()
QCOMPARE(testWidget->count(), itemCount);
// hide items
foreach (int row, hiddenRows)
- testWidget->setItemHidden(testWidget->item(row), true);
+ testWidget->item(row)->setHidden(true);
// select items
foreach (int row, selectedRows)
- testWidget->setItemSelected(testWidget->item(row), true);
+ testWidget->item(row)->setSelected(true);
// check that the correct number of items and the expected items are there
QList<QListWidgetItem *> selectedItems = testWidget->selectedItems();
@@ -763,7 +876,7 @@ void tst_QListWidget::selectedItems()
//check that isSelected agrees with selectedItems
for (int i=0; i<itemCount; ++i) {
QListWidgetItem *item = testWidget->item(i);
- if (testWidget->isItemSelected(item))
+ if (item->isSelected())
QVERIFY(selectedItems.contains(item));
}
}
@@ -1743,5 +1856,27 @@ void tst_QListWidget::QTBUG50891_ensureSelectionModelSignalConnectionsAreSet()
}
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+void tst_QListWidget::clearItemData()
+{
+ QListWidget list;
+ for (int i = 0 ; i < 4; ++i)
+ new QListWidgetItem(QString::number(i), &list);
+ QSignalSpy dataChangeSpy(list.model(), &QAbstractItemModel::dataChanged);
+ QVERIFY(dataChangeSpy.isValid());
+ QVERIFY(!list.model()->clearItemData(QModelIndex()));
+ QCOMPARE(dataChangeSpy.size(), 0);
+ QVERIFY(list.model()->clearItemData(list.model()->index(0, 0)));
+ QVERIFY(!list.model()->index(0, 0).data().isValid());
+ QCOMPARE(dataChangeSpy.size(), 1);
+ const QList<QVariant> dataChangeArgs = dataChangeSpy.takeFirst();
+ QCOMPARE(dataChangeArgs.at(0).value<QModelIndex>(), list.model()->index(0, 0));
+ QCOMPARE(dataChangeArgs.at(1).value<QModelIndex>(), list.model()->index(0, 0));
+ QVERIFY(dataChangeArgs.at(2).value<QVector<int>>().isEmpty());
+ QVERIFY(list.model()->clearItemData(list.model()->index(0, 0)));
+ QCOMPARE(dataChangeSpy.size(), 0);
+}
+#endif
+
QTEST_MAIN(tst_QListWidget)
#include "tst_qlistwidget.moc"
diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
index 1b95b5a3ca..e8ee735915 100644
--- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
+++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
@@ -2534,7 +2534,6 @@ void tst_QTableView::columnViewportPosition()
view.horizontalScrollBar()->setValue(horizontalScrollValue);
#ifdef Q_OS_WINRT
- QEXPECT_FAIL("column 1, scroll per item, 1", "Fails on WinRT - QTBUG-68297", Abort);
QEXPECT_FAIL("column 5, scroll per item, 5", "Fails on WinRT - QTBUG-68297", Abort);
QEXPECT_FAIL("column 9, scroll per item, 5", "Fails on WinRT - QTBUG-68297", Abort);
QEXPECT_FAIL("column 1, scroll per pixel 1", "Fails on WinRT - QTBUG-68297", Abort);
diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
index 4155ff1ec6..f97c43e347 100644
--- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
@@ -83,12 +83,18 @@ private slots:
void setItemData();
void cellWidget();
void cellWidgetGeometry();
+ void sizeHint_data();
+ void sizeHint();
void task231094();
void task219380_removeLastRow();
void task262056_sortDuplicate();
void itemWithHeaderItems();
void mimeData();
void selectedRowAfterSorting();
+ void search();
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ void clearItemData();
+#endif
private:
QTableWidget *testWidget;
@@ -159,6 +165,7 @@ void tst_QTableWidget::initTestCase()
{
testWidget = new QTableWidget();
testWidget->show();
+ QApplication::setKeyboardInputInterval(100);
}
void tst_QTableWidget::cleanupTestCase()
@@ -191,10 +198,10 @@ void tst_QTableWidget::clear()
{
QTableWidgetItem *item = new QTableWidgetItem("foo");
testWidget->setItem(0, 0, item);
- testWidget->setItemSelected(item, true);
+ item->setSelected(true);
QVERIFY(testWidget->item(0, 0) == item);
- QVERIFY(testWidget->isItemSelected(item));
+ QVERIFY(item->isSelected());
QPointer<QObjectTableItem> bla = new QObjectTableItem();
@@ -578,7 +585,7 @@ void tst_QTableWidget::selectedItems()
continue;
QTableWidgetItem *item = testWidget->item(row, column);
- if (item && testWidget->isItemSelected(item))
+ if (item && item->isSelected())
QVERIFY(selectedItems.contains(item));
}
}
@@ -1454,6 +1461,56 @@ void tst_QTableWidget::cellWidgetGeometry()
QCOMPARE(tw.visualItemRect(item).top(), le->geometry().top());
}
+void tst_QTableWidget::sizeHint_data()
+{
+ QTest::addColumn<int>("scrollBarPolicy");
+ QTest::addColumn<QSize>("viewSize");
+ QTest::newRow("ScrollBarAlwaysOn") << static_cast<int>(Qt::ScrollBarAlwaysOn) << QSize();
+ QTest::newRow("ScrollBarAlwaysOff") << static_cast<int>(Qt::ScrollBarAlwaysOff) << QSize();
+ // make sure the scrollbars are shown by resizing the view to 40x40
+ QTest::newRow("ScrollBarAsNeeded (40x40)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(40, 40);
+ QTest::newRow("ScrollBarAsNeeded (1000x1000)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(1000, 1000);
+}
+
+void tst_QTableWidget::sizeHint()
+{
+ QFETCH(int, scrollBarPolicy);
+ QFETCH(QSize, viewSize);
+
+ QTableWidget view(2, 2);
+ view.setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
+ view.setVerticalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy));
+ view.setHorizontalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy));
+ for (int r = 0 ; r < view.rowCount(); ++r)
+ for (int c = 0 ; c < view.columnCount(); ++c)
+ view.setItem(r, c, new QTableWidgetItem(QString("%1/%2").arg(r).arg(c)));
+
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+ if (viewSize.isValid()) {
+ view.resize(viewSize);
+ view.setColumnWidth(0, 100);
+ view.setRowHeight(0, 100);
+ QTRY_COMPARE(view.size(), viewSize);
+ }
+
+ auto sizeHint = view.sizeHint();
+ view.hide();
+ QCOMPARE(view.sizeHint(), sizeHint);
+
+ view.horizontalHeader()->hide();
+ view.show();
+ sizeHint = view.sizeHint();
+ view.hide();
+ QCOMPARE(view.sizeHint(), sizeHint);
+
+ view.verticalHeader()->hide();
+ view.show();
+ sizeHint = view.sizeHint();
+ view.hide();
+ QCOMPARE(view.sizeHint(), sizeHint);
+}
+
void tst_QTableWidget::task231094()
{
QTableWidget tw(5, 3);
@@ -1543,6 +1600,7 @@ public:
using QTableWidget::mimeData;
using QTableWidget::indexFromItem;
+ using QTableWidget::keyPressEvent;
};
void tst_QTableWidget::mimeData()
@@ -1617,5 +1675,67 @@ void tst_QTableWidget::selectedRowAfterSorting()
}
}
+void tst_QTableWidget::search()
+{
+ auto createItem = [](const QString &txt)
+ {
+ auto item = new QTableWidgetItem(txt);
+ item->setFlags(item->flags().setFlag(Qt::ItemIsEditable, false));
+ return item;
+ };
+
+ auto checkSeries = [](TestTableWidget &tw, const QVector<QPair<QKeyEvent, int>> &series)
+ {
+ for (const auto &p : series) {
+ QKeyEvent e = p.first;
+ tw.keyPressEvent(&e);
+ QVERIFY(tw.selectionModel()->isSelected(tw.model()->index(p.second, 0)));
+ }
+ };
+ TestTableWidget tw(5, 1);
+ tw.setItem(0, 0, createItem("12"));
+ tw.setItem(1, 0, createItem("123"));
+ tw.setItem(2, 0, createItem("123 4"));
+ tw.setItem(3, 0, createItem("123 5"));
+ tw.setItem(4, 0, createItem(" "));
+ tw.show();
+
+ QKeyEvent evSpace(QEvent::KeyPress, Qt::Key_Space, Qt::NoModifier, " ");
+ QKeyEvent ev1(QEvent::KeyPress, Qt::Key_1, Qt::NoModifier, "1");
+ QKeyEvent ev2(QEvent::KeyPress, Qt::Key_2, Qt::NoModifier, "2");
+ QKeyEvent ev3(QEvent::KeyPress, Qt::Key_3, Qt::NoModifier, "3");
+ QKeyEvent ev4(QEvent::KeyPress, Qt::Key_4, Qt::NoModifier, "4");
+ QKeyEvent ev5(QEvent::KeyPress, Qt::Key_5, Qt::NoModifier, "5");
+
+ checkSeries(tw, {{evSpace, 4}, {ev1, 4}});
+ QTest::qWait(QApplication::keyboardInputInterval() * 2);
+ checkSeries(tw, {{ev1, 0}, {ev2, 0}, {ev3, 1}, {evSpace, 2}, {ev5, 3}});
+ QTest::qWait(QApplication::keyboardInputInterval() * 2);
+ checkSeries(tw, {{ev1, 0}, {ev2, 0}, {ev3, 1}, {evSpace, 2}, {ev4, 2}});
+}
+
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+void tst_QTableWidget::clearItemData()
+{
+ QTableWidget table(3,3);
+ for (int r = 0; r < 3; r++)
+ for (int c = 0; c < 3; c++)
+ table.setItem(r,c,new QTableWidgetItem(QStringLiteral("0")));
+ QSignalSpy dataChangeSpy(table.model(), &QAbstractItemModel::dataChanged);
+ QVERIFY(dataChangeSpy.isValid());
+ QVERIFY(!table.model()->clearItemData(QModelIndex()));
+ QCOMPARE(dataChangeSpy.size(), 0);
+ QVERIFY(table.model()->clearItemData(table.model()->index(0, 0)));
+ QVERIFY(!table.model()->index(0, 0).data().isValid());
+ QCOMPARE(dataChangeSpy.size(), 1);
+ const QList<QVariant> dataChangeArgs = dataChangeSpy.takeFirst();
+ QCOMPARE(dataChangeArgs.at(0).value<QModelIndex>(), table.model()->index(0, 0));
+ QCOMPARE(dataChangeArgs.at(1).value<QModelIndex>(), table.model()->index(0, 0));
+ QVERIFY(dataChangeArgs.at(2).value<QVector<int>>().isEmpty());
+ QVERIFY(table.model()->clearItemData(table.model()->index(0, 0)));
+ QCOMPARE(dataChangeSpy.size(), 0);
+}
+#endif
+
QTEST_MAIN(tst_QTableWidget)
#include "tst_qtablewidget.moc"
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
index 8f9afeea4d..ece2e9a220 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -69,6 +69,7 @@ public slots:
void selectionOrderTest();
private slots:
+ void initTestCase() { QApplication::setKeyboardInputInterval(100); }
void getSetCheck();
// one test per QTreeView property
@@ -1647,50 +1648,96 @@ void tst_QTreeView::expandAndCollapse()
}
}
+static void checkExpandState(const QAbstractItemModel &model, const QTreeView &view,
+ const QModelIndex &startIdx, bool bIsExpanded, int *count)
+{
+ *count = 0;
+ QStack<QModelIndex> parents;
+ parents.push(startIdx);
+ if (startIdx.isValid()) {
+ QCOMPARE(view.isExpanded(startIdx), bIsExpanded);
+ *count += 1;
+ }
+ while (!parents.isEmpty()) {
+ const QModelIndex p = parents.pop();
+ const int rows = model.rowCount(p);
+ for (int r = 0; r < rows; ++r) {
+ const QModelIndex c = model.index(r, 0, p);
+ QCOMPARE(view.isExpanded(c), bIsExpanded);
+ parents.push(c);
+ }
+ *count += rows;
+ }
+}
+
void tst_QTreeView::expandAndCollapseAll()
{
- QtTestModel model(3, 2);
- model.levels = 2;
+ QStandardItemModel model;
+ // QtTestModel has a broken parent/child handling which will break the test
+ for (int i1 = 0; i1 < 3; ++i1) {
+ QStandardItem *s1 = new QStandardItem;
+ s1->setText(QString::number(i1));
+ model.appendRow(s1);
+ for (int i2 = 0; i2 < 3; ++i2) {
+ QStandardItem *s2 = new QStandardItem;
+ s2->setText(QStringLiteral("%1 - %2").arg(i1).arg(i2));
+ s1->appendRow(s2);
+ for (int i3 = 0; i3 < 3; ++i3) {
+ QStandardItem *s3 = new QStandardItem;
+ s3->setText(QStringLiteral("%1 - %2 - %3").arg(i1).arg(i2).arg(i3));
+ s2->appendRow(s3);
+ }
+ }
+ }
QTreeView view;
view.setUniformRowHeights(true);
view.setModel(&model);
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
- QSignalSpy expandedSpy(&view, SIGNAL(expanded(QModelIndex)));
- QSignalSpy collapsedSpy(&view, SIGNAL(collapsed(QModelIndex)));
+ QSignalSpy expandedSpy(&view, &QTreeView::expanded);
+ QSignalSpy collapsedSpy(&view, &QTreeView::collapsed);
+ int count;
view.expandAll();
- view.show();
-
+ checkExpandState(model, view, QModelIndex(), true, &count);
QCOMPARE(collapsedSpy.count(), 0);
+ QCOMPARE(expandedSpy.count(), 39); // == 3 (first) + 9 (second) + 27 (third level)
+ QCOMPARE(count, 39);
- QStack<QModelIndex> parents;
- parents.push(QModelIndex());
- int count = 0;
- while (!parents.isEmpty()) {
- QModelIndex p = parents.pop();
- int rows = model.rowCount(p);
- for (int r = 0; r < rows; ++r)
- QVERIFY(view.isExpanded(model.index(r, 0, p)));
- count += rows;
- for (int r = 0; r < rows; ++r)
- parents.push(model.index(r, 0, p));
- }
- QCOMPARE(expandedSpy.count(), 12); // == (3+1)*(2+1) from QtTestModel model(3, 2);
-
+ collapsedSpy.clear();
+ expandedSpy.clear();
view.collapseAll();
-
- parents.push(QModelIndex());
- count = 0;
- while (!parents.isEmpty()) {
- QModelIndex p = parents.pop();
- int rows = model.rowCount(p);
- for (int r = 0; r < rows; ++r)
- QVERIFY(!view.isExpanded(model.index(r, 0, p)));
- count += rows;
- for (int r = 0; r < rows; ++r)
- parents.push(model.index(r, 0, p));
- }
- QCOMPARE(collapsedSpy.count(), 12);
+ checkExpandState(model, view, QModelIndex(), false, &count);
+ QCOMPARE(collapsedSpy.count(), 39);
+ QCOMPARE(expandedSpy.count(), 0);
+ QCOMPARE(count, 39);
+
+ collapsedSpy.clear();
+ expandedSpy.clear();
+ view.expandRecursively(model.index(0, 0));
+ QCOMPARE(expandedSpy.count(), 13); // 1 + 3 + 9
+
+ checkExpandState(model, view, model.index(0, 0), true, &count);
+ QCOMPARE(count, 13);
+ checkExpandState(model, view, model.index(1, 0), false, &count);
+ QCOMPARE(count, 13);
+ checkExpandState(model, view, model.index(2, 0), false, &count);
+ QCOMPARE(count, 13);
+
+ expandedSpy.clear();
+ view.collapseAll();
+ view.expandRecursively(model.index(0, 0), 1);
+ QCOMPARE(expandedSpy.count(), 4); // 1 + 3
+ view.expandRecursively(model.index(0, 0), 2);
+ QCOMPARE(expandedSpy.count(), 13); // (1 + 3) + 9
+
+ checkExpandState(model, view, model.index(0, 0), true, &count);
+ QCOMPARE(count, 13);
+ checkExpandState(model, view, model.index(1, 0), false, &count);
+ QCOMPARE(count, 13);
+ checkExpandState(model, view, model.index(2, 0), false, &count);
+ QCOMPARE(count, 13);
}
void tst_QTreeView::expandWithNoChildren()
@@ -2435,6 +2482,8 @@ void tst_QTreeView::selection()
for (int i = 0;i < 10; ++i)
m.setData(m.index(i, 0), i);
treeView.setModel(&m);
+ treeView.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&treeView));
treeView.setSelectionBehavior(QAbstractItemView::SelectRows);
treeView.setSelectionMode(QAbstractItemView::ExtendedSelection);
@@ -2446,6 +2495,13 @@ void tst_QTreeView::selection()
QTest::mousePress(treeView.viewport(), Qt::LeftButton, 0, treeView.visualRect(m.index(1, 0)).center());
QTest::keyPress(treeView.viewport(), Qt::Key_Down);
+ auto selectedRows = treeView.selectionModel()->selectedRows();
+ QCOMPARE(selectedRows.size(), 1);
+ QCOMPARE(selectedRows.first(), m.index(2, 0, QModelIndex()));
+ QTest::keyPress(treeView.viewport(), Qt::Key_5);
+ selectedRows = treeView.selectionModel()->selectedRows();
+ QCOMPARE(selectedRows.size(), 1);
+ QCOMPARE(selectedRows.first(), m.index(5, 0, QModelIndex()));
}
//From task 151686 QTreeView ExtendedSelection selects hidden rows
@@ -2737,7 +2793,7 @@ void tst_QTreeView::sortByColumn()
view.setSortingEnabled(sortingEnabled);
view.setModel(&model);
- view.sortByColumn(1);
+ view.sortByColumn(1, Qt::DescendingOrder);
QCOMPARE(view.header()->sortIndicatorSection(), 1);
QCOMPARE(view.model()->data(view.model()->index(0,1)).toString(), QString::fromLatin1("h"));
QCOMPARE(view.model()->data(view.model()->index(1,1)).toString(), QString::fromLatin1("g"));
@@ -3047,7 +3103,7 @@ void tst_QTreeView::evilModel()
view.resizeColumnToContents(1);
model.change();
- view.sortByColumn(1);
+ view.sortByColumn(1, Qt::DescendingOrder);
model.change();
view.selectAll();
@@ -3891,7 +3947,7 @@ void tst_QTreeView::task254234_proxySort()
model.setItem(2,1,new QStandardItem("h"));
model.setItem(3,1,new QStandardItem("f"));
- view.sortByColumn(1);
+ view.sortByColumn(1, Qt::DescendingOrder);
view.setSortingEnabled(true);
QSortFilterProxyModel proxy;
@@ -4079,6 +4135,30 @@ void tst_QTreeView::keyboardNavigationWithDisabled()
QCOMPARE(view.currentIndex(), model.index(12, 0));
QTest::keyClick(view.viewport(), Qt::Key_Up);
QCOMPARE(view.currentIndex(), model.index(6, 0));
+ // QTBUG-44746 - when first/last item is disabled,
+ // Key_PageUp/Down/Home/End will not work as expected.
+ model.item(0)->setEnabled(false);
+ model.item(1)->setEnabled(true);
+ model.item(2)->setEnabled(true);
+ model.item(model.rowCount() - 1)->setEnabled(false);
+ model.item(model.rowCount() - 2)->setEnabled(true);
+ model.item(model.rowCount() - 3)->setEnabled(true);
+ // PageUp
+ view.setCurrentIndex(model.index(2, 0));
+ QCOMPARE(view.currentIndex(), model.index(2, 0));
+ QTest::keyClick(view.viewport(), Qt::Key_PageUp);
+ QCOMPARE(view.currentIndex(), model.index(1, 0));
+ // PageDown
+ view.setCurrentIndex(model.index(model.rowCount() - 3, 0));
+ QCOMPARE(view.currentIndex(), model.index(model.rowCount() - 3, 0));
+ QTest::keyClick(view.viewport(), Qt::Key_PageDown);
+ QCOMPARE(view.currentIndex(), model.index(model.rowCount() - 2, 0));
+ // Key_Home
+ QTest::keyClick(view.viewport(), Qt::Key_Home);
+ QCOMPARE(view.currentIndex(), model.index(1, 0));
+ // Key_End
+ QTest::keyClick(view.viewport(), Qt::Key_End);
+ QCOMPARE(view.currentIndex(), model.index(model.rowCount() - 2, 0));
}
class RemoveColumnOne : public QSortFilterProxyModel
diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
index adb2c54751..f2ed72be52 100644
--- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
@@ -99,6 +99,7 @@ private slots:
void insertTopLevelItems_data();
void insertTopLevelItems();
void keyboardNavigation();
+ void keyboardNavigationWithHidden();
void scrollToItem();
void setSortingEnabled();
void match();
@@ -115,6 +116,8 @@ private slots:
void changeDataWithSorting();
void changeDataWithStableSorting_data();
void changeDataWithStableSorting();
+ void sizeHint_data();
+ void sizeHint();
void sortedIndexOfChild_data();
void sortedIndexOfChild();
@@ -138,6 +141,7 @@ private slots:
void expandAndCallapse();
void itemData();
void setDisabled();
+ void setSpanned();
void removeSelectedItem();
void removeCurrentItem();
void removeCurrentItem_task186451();
@@ -161,6 +165,9 @@ private slots:
void getMimeDataWithInvalidItem();
void testVisualItemRect();
void reparentHiddenItem();
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ void clearItemData();
+#endif
public slots:
void itemSelectionChanged();
@@ -603,31 +610,31 @@ void tst_QTreeWidget::setItemHidden()
QVERIFY(testWidget->visualItemRect(child).isValid()
&& testWidget->viewport()->rect().intersects(testWidget->visualItemRect(child)));
- QVERIFY(!testWidget->isItemHidden(parent));
- QVERIFY(!testWidget->isItemHidden(child));
+ QVERIFY(!parent->isHidden());
+ QVERIFY(!child->isHidden());
- testWidget->setItemHidden(parent, true);
+ parent->setHidden(true);
QVERIFY(!(testWidget->visualItemRect(parent).isValid()
&& testWidget->viewport()->rect().intersects(testWidget->visualItemRect(parent))));
QVERIFY(!(testWidget->visualItemRect(child).isValid()
&& testWidget->viewport()->rect().intersects(testWidget->visualItemRect(child))));
- QVERIFY(testWidget->isItemHidden(parent));
- QVERIFY(!testWidget->isItemHidden(child));
+ QVERIFY(parent->isHidden());
+ QVERIFY(!child->isHidden());
// From task 78670 (This caused an core dump)
// Check if we can set an item visible if it already is visible.
- testWidget->setItemHidden(parent, false);
- testWidget->setItemHidden(parent, false);
- QVERIFY(!testWidget->isItemHidden(parent));
+ parent->setHidden(false);
+ parent->setHidden(false);
+ QVERIFY(!parent->isHidden());
// hide, hide and then unhide.
- testWidget->setItemHidden(parent, true);
- testWidget->setItemHidden(parent, true);
- testWidget->setItemHidden(parent, false);
- QVERIFY(!testWidget->isItemHidden(parent));
+ parent->setHidden(true);
+ parent->setHidden(true);
+ parent->setHidden(false);
+ QVERIFY(!parent->isHidden());
}
@@ -653,7 +660,7 @@ void tst_QTreeWidget::setItemHidden2()
if (testWidget->topLevelItemCount() > 0) {
top = testWidget->topLevelItem(0);
- testWidget->setItemExpanded(top, true);
+ top->setExpanded(true);
}
if (testWidget->topLevelItemCount() > 0) {
@@ -661,8 +668,8 @@ void tst_QTreeWidget::setItemHidden2()
for (int i = 0; i < top->childCount(); i++) {
leaf = top->child(i);
if (leaf->text(0).toInt() % 2 == 0) {
- if (!testWidget->isItemHidden(leaf)) {
- testWidget->setItemHidden(leaf, true);
+ if (!leaf->isHidden()) {
+ leaf->setHidden(true);
}
}
}
@@ -816,7 +823,7 @@ void tst_QTreeWidget::selectedItems()
else
item = item->child(index);
}
- testWidget->setItemSelected(item, true);
+ item->setSelected(true);
}
// hide rows
@@ -828,7 +835,7 @@ void tst_QTreeWidget::selectedItems()
else
item = item->child(index);
}
- testWidget->setItemHidden(item, true);
+ item->setHidden(true);
}
// open/close toplevel
@@ -857,18 +864,20 @@ void tst_QTreeWidget::selectedItems()
// compare isSelected
for (int t=0; t<testWidget->topLevelItemCount(); ++t) {
QTreeWidgetItem *top = testWidget->topLevelItem(t);
- if (testWidget->isItemSelected(top) && !testWidget->isItemHidden(top))
+ if (top->isSelected() && !top->isHidden())
QVERIFY(sel.contains(top));
for (int c=0; c<top->childCount(); ++c) {
QTreeWidgetItem *child = top->child(c);
- if (testWidget->isItemSelected(child) && !testWidget->isItemHidden(child))
+ if (child->isSelected() && !child->isHidden())
QVERIFY(sel.contains(child));
}
}
+#if QT_DEPRECATED_SINCE(5, 13)
// Possible to select null without crashing?
testWidget->setItemSelected(0, true);
QVERIFY(!testWidget->isItemSelected(0));
+#endif
// unselect
foreach (IntList itemPath, selectedItems) {
@@ -879,7 +888,7 @@ void tst_QTreeWidget::selectedItems()
else
item = item->child(index);
}
- testWidget->setItemSelected(item, false);
+ item->setSelected(false);
}
QCOMPARE(testWidget->selectedItems().count(), 0);
}
@@ -1005,21 +1014,21 @@ void tst_QTreeWidget::expand()
QTreeWidgetItem *topLevelItem = testWidget->topLevelItem(topLevelIndex);
QTreeWidgetItem *childItem = topLevelItem->child(childIndex);
- QVERIFY(!testWidget->isItemExpanded(topLevelItem));
- testWidget->setItemExpanded(topLevelItem, true);
- QVERIFY(testWidget->isItemExpanded(topLevelItem));
+ QVERIFY(!topLevelItem->isExpanded());
+ topLevelItem->setExpanded(true);
+ QVERIFY(topLevelItem->isExpanded());
- QVERIFY(!testWidget->isItemExpanded(childItem));
- testWidget->setItemExpanded(childItem, true);
- QVERIFY(testWidget->isItemExpanded(childItem));
+ QVERIFY(!childItem->isExpanded());
+ childItem->setExpanded(true);
+ QVERIFY(childItem->isExpanded());
- QVERIFY(testWidget->isItemExpanded(topLevelItem));
- testWidget->setItemExpanded(topLevelItem, false);
- QVERIFY(!testWidget->isItemExpanded(topLevelItem));
+ QVERIFY(topLevelItem->isExpanded());
+ topLevelItem->setExpanded(false);
+ QVERIFY(!topLevelItem->isExpanded());
- QVERIFY(testWidget->isItemExpanded(childItem));
- testWidget->setItemExpanded(childItem, false);
- QVERIFY(!testWidget->isItemExpanded(childItem));
+ QVERIFY(childItem->isExpanded());
+ childItem->setExpanded(false);
+ QVERIFY(!childItem->isExpanded());
}
void tst_QTreeWidget::checkState_data()
@@ -1520,7 +1529,7 @@ void tst_QTreeWidget::keyboardNavigation()
}
break;
case Qt::Key_Down:
- if (testWidget->isItemExpanded(item)) {
+ if (item->isExpanded()) {
row = 0;
item = item->child(row);
} else {
@@ -1533,7 +1542,7 @@ void tst_QTreeWidget::keyboardNavigation()
break;
case Qt::Key_Left:
if (checkScroll) {
- QVERIFY(testWidget->isItemExpanded(item));
+ QVERIFY(item->isExpanded());
QCOMPARE(scrollBar->value(), valueBeforeClick - scrollBar->singleStep());
}
// windows style right will walk to the parent
@@ -1567,6 +1576,33 @@ void tst_QTreeWidget::keyboardNavigation()
}
}
+void tst_QTreeWidget::keyboardNavigationWithHidden()
+{
+ QTreeWidget tw;
+ for (int i = 0; i < 1000; ++i)
+ tw.addTopLevelItem(new QTreeWidgetItem({QString::number(i), QStringLiteral("second col")}));
+ // QTBUG-34832 - when first/last item is hidden,
+ // Key_PageUp/Down/Home/End will not work as expected.
+ tw.topLevelItem(0)->setHidden(true);
+ tw.topLevelItem(tw.model()->rowCount() - 1)->setHidden(true);
+ // PageUp
+ tw.setCurrentIndex(tw.model()->index(2, 0));
+ QCOMPARE(tw.currentIndex(), tw.model()->index(2, 0));
+ QTest::keyClick(tw.viewport(), Qt::Key_PageUp);
+ QCOMPARE(tw.currentIndex(), tw.model()->index(1, 0));
+ // PageDown
+ tw.setCurrentIndex(tw.model()->index(tw.model()->rowCount() - 3, 0));
+ QCOMPARE(tw.currentIndex(), tw.model()->index(tw.model()->rowCount() - 3, 0));
+ QTest::keyClick(tw.viewport(), Qt::Key_PageDown);
+ QCOMPARE(tw.currentIndex(), tw.model()->index(tw.model()->rowCount() - 2, 0));
+ // Key_Home
+ QTest::keyClick(tw.viewport(), Qt::Key_Home);
+ QCOMPARE(tw.currentIndex(), tw.model()->index(1, 0));
+ // Key_End
+ QTest::keyClick(tw.viewport(), Qt::Key_End);
+ QCOMPARE(tw.currentIndex(), tw.model()->index(tw.model()->rowCount() - 2, 0));
+}
+
void tst_QTreeWidget::scrollToItem()
{
// Check if all parent nodes of the item found are expanded.
@@ -1592,9 +1628,9 @@ void tst_QTreeWidget::scrollToItem()
QCOMPARE(search->text(0), QLatin1String("111"));
QTreeWidgetItem *par = search->parent();
- QVERIFY(testWidget->isItemExpanded(par));
+ QVERIFY(par->isExpanded());
par = par->parent();
- QVERIFY(testWidget->isItemExpanded(par));
+ QVERIFY(par->isExpanded());
}
// From task #85413
@@ -1880,9 +1916,8 @@ void tst_QTreeWidget::setData()
QCOMPARE(qvariant_cast<QSize>(item->data(j, Qt::SizeHintRole)), sizeHint);
QCOMPARE(qvariant_cast<QFont>(item->data(j, Qt::FontRole)), font);
QCOMPARE(qvariant_cast<int>(item->data(j, Qt::TextAlignmentRole)), int(textAlignment));
- QCOMPARE(qvariant_cast<QBrush>(item->data(j, Qt::BackgroundColorRole)), QBrush(backgroundColor));
QCOMPARE(qvariant_cast<QBrush>(item->data(j, Qt::BackgroundRole)), QBrush(backgroundColor));
- QCOMPARE(qvariant_cast<QColor>(item->data(j, Qt::TextColorRole)), textColor);
+ QCOMPARE(qvariant_cast<QColor>(item->data(j, Qt::ForegroundRole)), textColor);
QCOMPARE(qvariant_cast<int>(item->data(j, Qt::CheckStateRole)), int(checkState));
item->setBackground(j, pixmap);
@@ -1902,8 +1937,8 @@ void tst_QTreeWidget::setData()
item->setData(j, Qt::SizeHintRole, QVariant());
item->setData(j, Qt::FontRole, QVariant());
item->setData(j, Qt::TextAlignmentRole, QVariant());
- item->setData(j, Qt::BackgroundColorRole, QVariant());
- item->setData(j, Qt::TextColorRole, QVariant());
+ item->setData(j, Qt::BackgroundRole, QVariant());
+ item->setData(j, Qt::ForegroundRole, QVariant());
item->setData(j, Qt::CheckStateRole, QVariant());
QCOMPARE(itemChangedSpy.count(), 11);
itemChangedSpy.clear();
@@ -1916,9 +1951,8 @@ void tst_QTreeWidget::setData()
QCOMPARE(item->data(j, Qt::SizeHintRole), QVariant());
QCOMPARE(item->data(j, Qt::FontRole), QVariant());
QCOMPARE(item->data(j, Qt::TextAlignmentRole), QVariant());
- QCOMPARE(item->data(j, Qt::BackgroundColorRole), QVariant());
QCOMPARE(item->data(j, Qt::BackgroundRole), QVariant());
- QCOMPARE(item->data(j, Qt::TextColorRole), QVariant());
+ QCOMPARE(item->data(j, Qt::ForegroundRole), QVariant());
QCOMPARE(item->data(j, Qt::CheckStateRole), QVariant());
}
}
@@ -2618,6 +2652,50 @@ void tst_QTreeWidget::changeDataWithStableSorting()
QCOMPARE(layoutChangedSpy.count(), reorderingExpected ? 1 : 0);
}
+void tst_QTreeWidget::sizeHint_data()
+{
+ QTest::addColumn<int>("scrollBarPolicy");
+ QTest::addColumn<QSize>("viewSize");
+ QTest::newRow("ScrollBarAlwaysOn") << static_cast<int>(Qt::ScrollBarAlwaysOn) << QSize();
+ QTest::newRow("ScrollBarAlwaysOff") << static_cast<int>(Qt::ScrollBarAlwaysOff) << QSize();
+ // make sure the scrollbars are shown by resizing the view to 40x40
+ QTest::newRow("ScrollBarAsNeeded (40x40)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(40, 40);
+ QTest::newRow("ScrollBarAsNeeded (1000x1000)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(1000, 1000);
+}
+
+void tst_QTreeWidget::sizeHint()
+{
+ QFETCH(int, scrollBarPolicy);
+ QFETCH(QSize, viewSize);
+
+ QTreeWidget view;
+ view.setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
+ view.setVerticalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy));
+ view.setHorizontalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy));
+ view.setColumnCount(2);
+ for (int i = 0 ; i < view.columnCount(); ++i)
+ view.addTopLevelItem(new QTreeWidgetItem(QStringList{"foo","bar"}));
+
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
+ if (viewSize.isValid()) {
+ view.resize(viewSize);
+ view.setColumnWidth(0, 100);
+ QTRY_COMPARE(view.size(), viewSize);
+ }
+
+ auto sizeHint = view.sizeHint();
+ view.hide();
+ QCOMPARE(view.sizeHint(), sizeHint);
+
+ view.header()->hide();
+ view.show();
+ sizeHint = view.sizeHint();
+ view.hide();
+ QCOMPARE(view.sizeHint(), sizeHint);
+}
+
void tst_QTreeWidget::itemOperatorLessThan()
{
QTreeWidget tw;
@@ -2769,6 +2847,28 @@ void tst_QTreeWidget::setDisabled()
QCOMPARE(takenChildren.items[1]->isDisabled(), false);
}
+void tst_QTreeWidget::setSpanned()
+{
+ QTreeWidget w;
+ QTreeWidgetItem *i1 = new QTreeWidgetItem();
+ QScopedPointer<QTreeWidgetItem> i2(new QTreeWidgetItem());
+
+ QTreeWidgetItem *top = new QTreeWidgetItem(&w);
+ top->addChild(i1);
+
+ top->setFirstColumnSpanned(true);
+ QCOMPARE(top->isFirstColumnSpanned(), true);
+ QCOMPARE(i1->isFirstColumnSpanned(), false);
+ QCOMPARE(i2->isFirstColumnSpanned(), false);
+
+ top->setFirstColumnSpanned(false);
+ i1->setFirstColumnSpanned(true);
+ i2->setFirstColumnSpanned(true);
+ QCOMPARE(top->isFirstColumnSpanned(), false);
+ QCOMPARE(i1->isFirstColumnSpanned(), true);
+ QCOMPARE(i2->isFirstColumnSpanned(), false);
+}
+
void tst_QTreeWidget::removeSelectedItem()
{
const QScopedPointer <QTreeWidget> w(new QTreeWidget);
@@ -2870,14 +2970,14 @@ void tst_QTreeWidget::randomExpand()
QTreeWidgetItem *newItem1 = 0;
for (int i = 0; i < 100; i++) {
newItem1 = new QTreeWidgetItem(&tree, item1);
- tree.setItemExpanded(newItem1, true);
- QCOMPARE(tree.isItemExpanded(newItem1), true);
+ newItem1->setExpanded(true);
+ QCOMPARE(newItem1->isExpanded(), true);
QTreeWidgetItem *x = new QTreeWidgetItem();
- QCOMPARE(tree.isItemExpanded(newItem1), true);
+ QCOMPARE(newItem1->isExpanded(), true);
newItem1->addChild(x);
- QCOMPARE(tree.isItemExpanded(newItem1), true);
+ QCOMPARE(newItem1->isExpanded(), true);
}
}
@@ -2890,19 +2990,19 @@ void tst_QTreeWidget::crashTest()
QTreeWidgetItem *item1 = new QTreeWidgetItem(tree);
item1->setText(0, "item1");
- tree->setItemExpanded(item1, true);
+ item1->setExpanded(true);
QTreeWidgetItem *item2 = new QTreeWidgetItem(item1);
item2->setText(0, "item2");
QTreeWidgetItem *item3 = new QTreeWidgetItem(tree, item1);
item3->setText(0, "item3");
- tree->setItemExpanded(item3, true);
+ item3->setExpanded(true);
QTreeWidgetItem *item4 = new QTreeWidgetItem(item3);
item4->setText(0, "item4");
QTreeWidgetItem *item5 = new QTreeWidgetItem(tree, item3);
item5->setText(0, "item5");
- tree->setItemExpanded(item5, true);
+ item5->setExpanded(true);
QTreeWidgetItem *item6 = new QTreeWidgetItem(item5);
item6->setText(0, "item6");
@@ -3004,7 +3104,7 @@ void tst_QTreeWidget::task191552_rtl()
opt.features = QStyleOptionViewItem::HasDisplay | QStyleOptionViewItem::HasCheckIndicator;
opt.checkState = Qt::Checked;
opt.widget = &tw;
- const QRect checkRect = tw.style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, &tw);
+ const QRect checkRect = tw.style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &opt, &tw);
QTest::mouseClick(tw.viewport(), Qt::LeftButton, Qt::NoModifier, checkRect.center());
QCOMPARE(item->checkState(0), Qt::Unchecked);
@@ -3218,7 +3318,7 @@ void tst_QTreeWidget::nonEditableTristate()
option.checkState = item->checkState(0);
const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1;
- QPoint pos = qApp->style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &option, 0).center() + QPoint(checkMargin, 0);
+ QPoint pos = qApp->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &option, 0).center() + QPoint(checkMargin, 0);
QTest::mouseClick(tree->viewport(), Qt::LeftButton, Qt::NoModifier, pos);
QCOMPARE(int(item->checkState(0)), int(Qt::Checked));
@@ -3530,5 +3630,43 @@ void tst_QTreeWidget::reparentHiddenItem()
QVERIFY(grandChild->isHidden());
}
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+void tst_QTreeWidget::clearItemData()
+{
+ QTreeWidget tree;
+ QAbstractItemModel* model = tree.model();
+ QVERIFY(model->insertColumn(0));
+ QVERIFY(model->insertRow(0));
+ const QModelIndex parentIdx = model->index(0, 0);
+ QVERIFY(model->insertColumn(0, parentIdx));
+ QVERIFY(model->insertRow(0, parentIdx));
+ const QModelIndex childIdx = model->index(0, 0, parentIdx);
+ model->setData(parentIdx, QStringLiteral("parent"));
+ model->setData(parentIdx, QStringLiteral("parent"), Qt::UserRole);
+ model->setData(childIdx, QStringLiteral("child"));
+ QSignalSpy dataChangeSpy(model, &QAbstractItemModel::dataChanged);
+ QVERIFY(dataChangeSpy.isValid());
+ QVERIFY(!model->clearItemData(QModelIndex()));
+ QCOMPARE(dataChangeSpy.size(), 0);
+ QVERIFY(model->clearItemData(parentIdx));
+ QVERIFY(!model->data(parentIdx).isValid());
+ QVERIFY(!model->data(parentIdx, Qt::UserRole).isValid());
+ QCOMPARE(dataChangeSpy.size(), 1);
+ QList<QVariant> dataChangeArgs = dataChangeSpy.takeFirst();
+ QCOMPARE(dataChangeArgs.at(0).value<QModelIndex>(), parentIdx);
+ QCOMPARE(dataChangeArgs.at(1).value<QModelIndex>(), parentIdx);
+ QVERIFY(dataChangeArgs.at(2).value<QVector<int>>().isEmpty());
+ QVERIFY(model->clearItemData(parentIdx));
+ QCOMPARE(dataChangeSpy.size(), 0);
+ QVERIFY(model->clearItemData(childIdx));
+ QVERIFY(!model->data(childIdx).isValid());
+ QCOMPARE(dataChangeSpy.size(), 1);
+ dataChangeArgs = dataChangeSpy.takeFirst();
+ QCOMPARE(dataChangeArgs.at(0).value<QModelIndex>(), childIdx);
+ QCOMPARE(dataChangeArgs.at(1).value<QModelIndex>(), childIdx);
+ QVERIFY(dataChangeArgs.at(2).value<QVector<int>>().isEmpty());
+}
+#endif
+
QTEST_MAIN(tst_QTreeWidget)
#include "tst_qtreewidget.moc"
diff --git a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp
index c2c02f3766..76ca148d3f 100644
--- a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp
+++ b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp
@@ -95,11 +95,11 @@ void tst_QTreeWidgetItemIterator::initTestCase()
const QString topS = QLatin1String("top") + QString::number(i);
top->setText(0, topS);
switch (i) {
- case 0: testWidget->setItemHidden(top, true);break;
- case 1: testWidget->setItemHidden(top, false);break;
+ case 0: top->setHidden(true);break;
+ case 1: top->setHidden(false);break;
- case 2: testWidget->setItemSelected(top, true);break;
- case 3: testWidget->setItemSelected(top, false);break;
+ case 2: top->setSelected(true);break;
+ case 3: top->setSelected(false);break;
case 4: top->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);break;
case 5: top->setFlags(Qt::ItemIsEnabled);break;
@@ -126,11 +126,11 @@ void tst_QTreeWidgetItemIterator::initTestCase()
QTreeWidgetItem *child = new QTreeWidgetItem(top);
child->setText(0, topS + QLatin1String(",child") + QString::number(j));
switch (j) {
- case 0: testWidget->setItemHidden(child, true);break;
- case 1: testWidget->setItemHidden(child, false);break;
+ case 0: child->setHidden(true);break;
+ case 1: child->setHidden(false);break;
- case 2: testWidget->setItemSelected(child, true);break;
- case 3: testWidget->setItemSelected(child, false);break;
+ case 2: child->setSelected(true);break;
+ case 3: child->setSelected(false);break;
case 4: child->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);break;
case 5: child->setFlags(Qt::ItemIsEnabled);break;
diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
index d2a244b762..e2ef5635c2 100644
--- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
+++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
@@ -240,6 +240,7 @@ void tst_QApplication::staticSetup()
QVERIFY(style);
QApplication::setStyle(style);
+ bool palette_changed = false;
QPalette pal;
QApplication::setPalette(pal);
@@ -247,7 +248,11 @@ void tst_QApplication::staticSetup()
QApplication::setFont(font);*/
int argc = 0;
- QApplication app(argc, 0);
+ QApplication app(argc, nullptr);
+ QObject::connect(&app, &QApplication::paletteChanged, [&palette_changed]{ palette_changed = true; });
+ QVERIFY(!palette_changed);
+ qApp->setPalette(QPalette(Qt::red));
+ QVERIFY(palette_changed);
}
@@ -355,8 +360,8 @@ void tst_QApplication::setFont_data()
int cnt = 0;
QFontDatabase fdb;
QStringList families = fdb.families();
- for (QStringList::const_iterator itr = families.begin();
- itr != families.end();
+ for (QStringList::const_iterator itr = families.cbegin();
+ itr != families.cend();
++itr) {
if (cnt < 3) {
QString family = *itr;
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 3b9c9060fa..93c8b095e0 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -7668,9 +7668,6 @@ void tst_QWidget::updateWhileMinimized()
// Restore window.
widget.showNormal();
- QTest::qWait(30);
- if (m_platform == QStringLiteral("xcb"))
- QSKIP("QTBUG-26424");
QTRY_COMPARE(widget.numPaintEvents, 1);
QCOMPARE(widget.paintedRegion, QRegion(0, 0, 50, 50));
}
@@ -9438,7 +9435,7 @@ QWidgetBackingStore* backingStore(QWidget &widget)
void tst_QWidget::rectOutsideCoordinatesLimit_task144779()
{
#ifndef QT_NO_CURSOR
- QApplication::setOverrideCursor(Qt::BlankCursor); //keep the cursor out of screen grabs
+ QGuiApplication::setOverrideCursor(Qt::BlankCursor); //keep the cursor out of screen grabs
#endif
QWidget main(0,Qt::FramelessWindowHint); //don't get confused by the size of the window frame
QPalette palette;
@@ -9475,7 +9472,7 @@ void tst_QWidget::rectOutsideCoordinatesLimit_task144779()
QTRY_COMPARE(mainPixmap.toImage().convertToFormat(QImage::Format_RGB32),
correct.toImage().convertToFormat(QImage::Format_RGB32));
#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
}
diff --git a/tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp b/tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp
index 077e8de328..06522b2bd3 100644
--- a/tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp
+++ b/tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp
@@ -41,6 +41,8 @@ public:
private slots:
void metaObject();
+ void saveAndLoadBuiltin_data();
+ void saveAndLoadBuiltin();
};
class CustomWidget : public QWidget
@@ -68,5 +70,50 @@ void tst_QWidgetMetaType::metaObject()
QCOMPARE(QMetaType::metaObjectForType(qMetaTypeId<QSizePolicy>()), &QSizePolicy::staticMetaObject);
}
+template <typename T>
+struct StreamingTraits
+{
+ // Streamable by default, as currently all widgets built-in types are streamable
+ enum { isStreamable = 1 };
+};
+
+void tst_QWidgetMetaType::saveAndLoadBuiltin_data()
+{
+ QTest::addColumn<int>("type");
+ QTest::addColumn<bool>("isStreamable");
+
+#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
+ QTest::newRow(#RealType) << MetaTypeId << bool(StreamingTraits<RealType>::isStreamable);
+ QT_FOR_EACH_STATIC_WIDGETS_CLASS(ADD_METATYPE_TEST_ROW)
+#undef ADD_METATYPE_TEST_ROW
+}
+
+void tst_QWidgetMetaType::saveAndLoadBuiltin()
+{
+ QFETCH(int, type);
+ QFETCH(bool, isStreamable);
+
+ void *value = QMetaType::create(type);
+
+ QByteArray ba;
+ QDataStream stream(&ba, QIODevice::ReadWrite);
+ QCOMPARE(QMetaType::save(stream, type, value), isStreamable);
+ QCOMPARE(stream.status(), QDataStream::Ok);
+
+ if (isStreamable)
+ QVERIFY(QMetaType::load(stream, type, value));
+
+ stream.device()->seek(0);
+ stream.resetStatus();
+ QCOMPARE(QMetaType::load(stream, type, value), isStreamable);
+ QCOMPARE(stream.status(), QDataStream::Ok);
+
+ if (isStreamable)
+ QVERIFY(QMetaType::load(stream, type, value));
+
+ QMetaType::destroy(type, value);
+}
+
+
QTEST_MAIN(tst_QWidgetMetaType)
#include "tst_qwidgetmetatype.moc"
diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
index 0e5c40f1b6..61b1fed1f8 100644
--- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
+++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
@@ -159,7 +159,7 @@ void tst_QStyleSheetStyle::numinstances()
QCOMPARE(QStyleSheetStyle::numinstances, 0);
qApp->setStyleSheet("* { color: red; }");
QCOMPARE(QStyleSheetStyle::numinstances, 1);
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
QCOMPARE(QStyleSheetStyle::numinstances, 0);
// set and unset application stylesheet+widget
@@ -168,9 +168,9 @@ void tst_QStyleSheetStyle::numinstances()
QCOMPARE(QStyleSheetStyle::numinstances, 2);
w.setStyle(style);
QCOMPARE(QStyleSheetStyle::numinstances, 2);
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
QCOMPARE(QStyleSheetStyle::numinstances, 1);
- w.setStyleSheet("");
+ w.setStyleSheet(QString());
QCOMPARE(QStyleSheetStyle::numinstances, 0);
// set and unset widget stylesheet
@@ -179,7 +179,7 @@ void tst_QStyleSheetStyle::numinstances()
QCOMPARE(QStyleSheetStyle::numinstances, 1);
c.setStyle(style);
QCOMPARE(QStyleSheetStyle::numinstances, 2);
- w.setStyleSheet("");
+ w.setStyleSheet(QString());
QCOMPARE(QStyleSheetStyle::numinstances, 0);
}
@@ -192,9 +192,9 @@ void tst_QStyleSheetStyle::widgetsBeforeAppStyleSheet()
QCOMPARE(COLOR(w1), red);
w1.setStyleSheet("color: white");
QCOMPARE(COLOR(w1), white);
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
QCOMPARE(COLOR(w1), white);
- w1.setStyleSheet("");
+ w1.setStyleSheet(QString());
QCOMPARE(COLOR(w1), APPCOLOR(w1));
}
@@ -217,17 +217,17 @@ void tst_QStyleSheetStyle::widgetsAfterAppStyleSheet()
QCOMPARE(COLOR(w1), white);
QCOMPARE(COLOR(spin), red);
QCOMPARE(COLOR(*spin.lineEdit()), red);
- w1.setStyleSheet("");
+ w1.setStyleSheet(QString());
QCOMPARE(COLOR(w1), red);
QCOMPARE(COLOR(spin), red);
QCOMPARE(COLOR(*spin.lineEdit()), red);
w1.setStyleSheet("color: white");
QCOMPARE(COLOR(w1), white);
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
QCOMPARE(COLOR(w1), white);
QCOMPARE(COLOR(spin), APPCOLOR(spin));
QCOMPARE(COLOR(*spin.lineEdit()), APPCOLOR(*spin.lineEdit()));
- w1.setStyleSheet("");
+ w1.setStyleSheet(QString());
QCOMPARE(COLOR(w1), APPCOLOR(w1));
// QCOMPARE(FONTSIZE(w1), APPFONTSIZE(w1)); //### task 244261
QCOMPARE(FONTSIZE(spin), APPFONTSIZE(spin));
@@ -243,7 +243,7 @@ void tst_QStyleSheetStyle::applicationStyleSheet()
QCOMPARE(COLOR(w1), red);
qApp->setStyleSheet("* { color: white; }");
QCOMPARE(COLOR(w1), white);
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
QCOMPARE(COLOR(w1), APPCOLOR(w1));
qApp->setStyleSheet("* { color: red }");
QCOMPARE(COLOR(w1), red);
@@ -254,21 +254,21 @@ void tst_QStyleSheetStyle::windowStyleSheet()
const QColor red(Qt::red);
const QColor white(Qt::white);
QPushButton w1;
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
w1.setStyleSheet("* { color: red; }");
QCOMPARE(COLOR(w1), red);
w1.setStyleSheet("* { color: white; }");
QCOMPARE(COLOR(w1), white);
- w1.setStyleSheet("");
+ w1.setStyleSheet(QString());
QCOMPARE(COLOR(w1), APPCOLOR(w1));
w1.setStyleSheet("* { color: red }");
QCOMPARE(COLOR(w1), red);
qApp->setStyleSheet("* { color: green }");
QCOMPARE(COLOR(w1), red);
- w1.setStyleSheet("");
+ w1.setStyleSheet(QString());
QCOMPARE(COLOR(w1), QColor("green"));
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
QCOMPARE(COLOR(w1), APPCOLOR(w1));
}
@@ -281,7 +281,7 @@ void tst_QStyleSheetStyle::widgetStyleSheet()
QPushButton *pb = new QPushButton(&w1);
QPushButton &w2 = *pb;
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
w1.setStyleSheet("* { color: red }");
QCOMPARE(COLOR(w1), red);
QCOMPARE(COLOR(w2), red);
@@ -293,11 +293,11 @@ void tst_QStyleSheetStyle::widgetStyleSheet()
QCOMPARE(COLOR(w1), blue);
QCOMPARE(COLOR(w2), white);
- w1.setStyleSheet("");
+ w1.setStyleSheet(QString());
QCOMPARE(COLOR(w1), APPCOLOR(w1));
QCOMPARE(COLOR(w2), white);
- w2.setStyleSheet("");
+ w2.setStyleSheet(QString());
QCOMPARE(COLOR(w1), APPCOLOR(w1));
QCOMPARE(COLOR(w2), APPCOLOR(w2));
}
@@ -311,7 +311,7 @@ void tst_QStyleSheetStyle::reparentWithNoChildStyleSheet()
QPushButton *pb = new QPushButton(&p1);
QPushButton &c1 = *pb; // child with no stylesheet
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
p1.setStyleSheet("* { color: red }");
QCOMPARE(COLOR(c1), red);
c1.setParent(&p2);
@@ -333,7 +333,7 @@ void tst_QStyleSheetStyle::reparentWithChildStyleSheet()
{
const QColor gray("gray");
const QColor white(Qt::white);
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
QPushButton p1, p2;
QPushButton *pb = new QPushButton(&p1);
QPushButton &c1 = *pb;
@@ -353,7 +353,7 @@ void tst_QStyleSheetStyle::repolish()
{
const QColor red(Qt::red);
const QColor white(Qt::white);
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
QPushButton p1;
p1.setStyleSheet("color: red; background: white");
QCOMPARE(BACKGROUND(p1), white);
@@ -362,14 +362,14 @@ void tst_QStyleSheetStyle::repolish()
p1.setStyleSheet("color: red");
QCOMPARE(COLOR(p1), red);
QCOMPARE(BACKGROUND(p1), APPBACKGROUND(p1));
- p1.setStyleSheet("");
+ p1.setStyleSheet(QString());
QCOMPARE(COLOR(p1), APPCOLOR(p1));
QCOMPARE(BACKGROUND(p1), APPBACKGROUND(p1));
}
void tst_QStyleSheetStyle::widgetStyle()
{
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
QWidget *window1 = new QWidget;
window1->setObjectName("window1");
@@ -429,7 +429,7 @@ void tst_QStyleSheetStyle::widgetStyle()
// Remove the stylesheet
proxy = (QStyleSheetStyle *)window1->style();
- window1->setStyleSheet("");
+ window1->setStyleSheet(QString());
QVERIFY(proxy.isNull()); // should have disappeared
QCOMPARE(window1->style(), style1.data()); // its restored
@@ -457,7 +457,7 @@ void tst_QStyleSheetStyle::widgetStyle()
QCOMPARE(proxy->baseStyle(), style1.data());
// Style Sheet propagation on a child widget with a custom style already set
- window2->setStyleSheet("");
+ window2->setStyleSheet(QString());
QCOMPARE(window2->style(), style2.data());
QCOMPARE(widget2->style(), style1.data());
widget2->setStyle(0);
@@ -470,9 +470,9 @@ void tst_QStyleSheetStyle::widgetStyle()
// clean everything out
window1->setStyle(0);
- window1->setStyleSheet("");
+ window1->setStyleSheet(QString());
window2->setStyle(0);
- window2->setStyleSheet("");
+ window2->setStyleSheet(QString());
qApp->setStyle(0);
qApp->setStyleSheet("may_insanity_prevail { }"); // app has stylesheet
@@ -489,14 +489,14 @@ void tst_QStyleSheetStyle::widgetStyle()
QCOMPARE(proxy->baseStyle(), newStyle); // magic ;) the widget still follows the application
QCOMPARE(static_cast<QStyle *>(proxy), widget1->style()); // child still follows...
- window1->setStyleSheet(""); // remove stylesheet
+ window1->setStyleSheet(QString()); // remove stylesheet
QCOMPARE(window1->style(), qApp->style()); // is this cool or what
QCOMPARE(widget1->style(), qApp->style()); // annoying child follows...
QScopedPointer<QStyle> wndStyle(QStyleFactory::create("Windows"));
window1->setStyle(wndStyle.data());
QCOMPARE(window1->style()->metaObject()->className(), "QStyleSheetStyle"); // auto wraps it
QCOMPARE(widget1->style(), window1->style()); // and auto propagates to child
- qApp->setStyleSheet(""); // remove the app stylesheet
+ qApp->setStyleSheet(QString()); // remove the app stylesheet
QCOMPARE(window1->style(), wndStyle.data()); // auto dewrap
QCOMPARE(widget1->style(), qApp->style()); // and child state is restored
window1->setStyle(0); // let sanity prevail
@@ -511,7 +511,7 @@ void tst_QStyleSheetStyle::widgetStyle()
void tst_QStyleSheetStyle::appStyle()
{
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
// qApp style can never be 0
QVERIFY(QApplication::style() != 0);
QPointer<QStyle> style1 = QStyleFactory::create("Windows");
@@ -544,11 +544,11 @@ void tst_QStyleSheetStyle::appStyle()
QCOMPARE(sss->baseStyle(), style1.data());
// Revert the stylesheet
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
QVERIFY(sss.isNull()); // should have disappeared
QCOMPARE(QApplication::style(), style1.data());
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
QCOMPARE(QApplication::style(), style1.data());
}
@@ -744,7 +744,7 @@ void tst_QStyleSheetStyle::fontPropagation()
window.setStyleSheet("* { font-size: 9pt }");
pb.setParent(&window);
QCOMPARE(FONTSIZE(pb), 9);
- window.setStyleSheet("");
+ window.setStyleSheet(QString());
QCOMPARE(FONTSIZE(pb), buttonFontSize);
QTabWidget tw;
@@ -757,7 +757,7 @@ void tst_QStyleSheetStyle::fontPropagation()
void tst_QStyleSheetStyle::onWidgetDestroyed()
{
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
QLabel *l = new QLabel;
l->setStyleSheet("QLabel { color: red }");
QPointer<QStyleSheetStyle> ss = (QStyleSheetStyle *) l->style();
@@ -778,14 +778,14 @@ void tst_QStyleSheetStyle::fontPrecedence()
font.setPointSize(16);
edit.setFont(font);
QCOMPARE(FONTSIZE(edit), 22);
- edit.setStyleSheet("");
+ edit.setStyleSheet(QString());
QCOMPARE(FONTSIZE(edit), 16);
font.setPointSize(18);
edit.setFont(font);
QCOMPARE(FONTSIZE(edit), 18);
edit.setStyleSheet("QLineEdit { font-size: 20pt; }");
QCOMPARE(FONTSIZE(edit), 20);
- edit.setStyleSheet("");
+ edit.setStyleSheet(QString());
QCOMPARE(FONTSIZE(edit), 18);
edit.hide();
@@ -1189,7 +1189,7 @@ void tst_QStyleSheetStyle::transparent()
QPushButton *p3=new QPushButton(&w);
p1->setStyleSheet("background:transparent");
p2->setStyleSheet("background-color:transparent");
- p3->setStyleSheet("background:rgb(0,0,0,0)");
+ p3->setStyleSheet("background:rgba(0,0,0,0)");
QCOMPARE(BACKGROUND(*p1) , QColor(0,0,0,0));
QCOMPARE(BACKGROUND(*p2) , QColor(0,0,0,0));
QCOMPARE(BACKGROUND(*p3) , QColor(0,0,0,0));
@@ -2051,7 +2051,7 @@ void tst_QStyleSheetStyle::styleSheetTargetAttribute()
QCOMPARE(lb.testAttribute(Qt::WA_StyleSheetTarget), true);
QCOMPARE(pb.testAttribute(Qt::WA_StyleSheetTarget), false);
- qApp->setStyleSheet("");
+ qApp->setStyleSheet(QString());
gb.ensurePolished(); lb.ensurePolished(); pb.ensurePolished();
QCOMPARE(gb.testAttribute(Qt::WA_StyleSheetTarget), false);
@@ -2066,7 +2066,7 @@ void tst_QStyleSheetStyle::unpolish()
w.setStyleSheet("QWidget { min-width: 100; }");
w.ensurePolished();
QCOMPARE(w.minimumWidth(), 100);
- w.setStyleSheet("");
+ w.setStyleSheet(QString());
QCOMPARE(w.minimumWidth(), 0);
}
diff --git a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp
index 078a3215fd..f8ce6a2c0a 100644
--- a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp
+++ b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp
@@ -71,6 +71,7 @@ private slots:
void restoreStateOfFloating();
void restoreDockWidget();
void restoreStateWhileStillFloating();
+ void setWindowTitle();
// task specific tests:
void task165177_deleteFocusWidget();
void task169808_setFloating();
@@ -993,7 +994,54 @@ void tst_QDockWidget::taskQTBUG_9758_undockedGeometry()
QVERIFY(dock1.y() >= 0);
}
+void tst_QDockWidget::setWindowTitle()
+{
+ QMainWindow window;
+ QDockWidget dock1(&window);
+ QDockWidget dock2(&window);
+ const QString dock1Title = QStringLiteral("&Window");
+ const QString dock2Title = QStringLiteral("&Modifiable Window [*]");
+
+ dock1.setWindowTitle(dock1Title);
+ dock2.setWindowTitle(dock2Title);
+ window.addDockWidget(Qt::RightDockWidgetArea, &dock1);
+ window.addDockWidget(Qt::RightDockWidgetArea, &dock2);
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ QCOMPARE(dock1.windowTitle(), dock1Title);
+ QCOMPARE(dock2.windowTitle(), dock2Title);
+
+ dock1.setFloating(true);
+ dock1.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&dock1));
+ QCOMPARE(dock1.windowTitle(), dock1Title);
+ dock1.setFloating(false);
+ QCOMPARE(dock1.windowTitle(), dock1Title);
+ dock1.setFloating(true);
+ dock1.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&dock1));
+ const QString changed = QStringLiteral("Changed ");
+ dock1.setWindowTitle(QString(changed + dock1Title));
+ QCOMPARE(dock1.windowTitle(), QString(changed + dock1Title));
+ dock1.setFloating(false);
+ QCOMPARE(dock1.windowTitle(), QString(changed + dock1Title));
+
+ dock2.setWindowModified(true);
+ QCOMPARE(dock2.windowTitle(), dock2Title);
+ dock2.setFloating(true);
+ dock2.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&dock2));
+ QCOMPARE(dock2.windowTitle(), dock2Title);
+ dock2.setWindowModified(false);
+ QCOMPARE(dock2.windowTitle(), dock2Title);
+ dock2.setFloating(false);
+ QCOMPARE(dock2.windowTitle(), dock2Title);
+ dock2.setFloating(true);
+ dock2.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&dock2));
+ QCOMPARE(dock2.windowTitle(), dock2Title);
+}
QTEST_MAIN(tst_QDockWidget)
#include "tst_qdockwidget.moc"
diff --git a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
index 6cc19051d2..67b79e3faf 100644
--- a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
+++ b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
@@ -1689,14 +1689,16 @@ void tst_QMdiArea::tileSubWindows()
workspace.setActiveSubWindow(0);
QVERIFY(workspace.viewport()->childrenRect() != workspace.viewport()->rect());
- // Make sure the active window is placed in top left corner regardless
+ // Make sure the active window does not move position after a tile regardless
// of whether we have any windows with staysOnTopHint or not.
+ workspace.tileSubWindows();
windows.at(3)->setWindowFlags(windows.at(3)->windowFlags() | Qt::WindowStaysOnTopHint);
QMdiSubWindow *activeSubWindow = windows.at(6);
workspace.setActiveSubWindow(activeSubWindow);
QCOMPARE(workspace.activeSubWindow(), activeSubWindow);
+ QPoint pos = activeSubWindow->geometry().topLeft();
workspace.tileSubWindows();
- QCOMPARE(activeSubWindow->geometry().topLeft(), QPoint(0, 0));
+ QCOMPARE(activeSubWindow->geometry().topLeft(), pos);
// Verify that we try to resize the area such that all sub-windows are visible.
// It's important that tiled windows are NOT overlapping.
@@ -1713,6 +1715,8 @@ void tst_QMdiArea::tileSubWindows()
// Prevent scrollbars from messing up the expected viewport calculation below
workspace.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
workspace.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ QCOMPARE(workspace.horizontalScrollBarPolicy(), Qt::ScrollBarAlwaysOff);
+ QCOMPARE(workspace.verticalScrollBarPolicy(), Qt::ScrollBarAlwaysOff);
workspace.tileSubWindows();
// The sub-windows are now tiled like this:
@@ -1731,9 +1735,11 @@ void tst_QMdiArea::tileSubWindows()
const QSize expectedViewportSize(3 * minSize.width() + spacing, 3 * minSize.height() + spacing);
QTRY_COMPARE(workspace.viewport()->rect().size(), expectedViewportSize);
- // Restore original scrollbar behavior for test below
+ // Enable scroll bar for test below (default property for QMdiArea is Qt::ScrollBarAlwaysOff)
workspace.setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
workspace.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ QCOMPARE(workspace.horizontalScrollBarPolicy(), Qt::ScrollBarAsNeeded);
+ QCOMPARE(workspace.verticalScrollBarPolicy(), Qt::ScrollBarAsNeeded);
// Not enough space for all sub-windows to be visible -> provide scroll bars.
workspace.resize(160, 150);
@@ -1754,13 +1760,16 @@ void tst_QMdiArea::tileSubWindows()
QCOMPARE(vBar->value(), 0);
QCOMPARE(vBar->minimum(), 0);
+ // Tile windows with scroll bars enabled.
workspace.tileSubWindows();
QVERIFY(QTest::qWaitForWindowExposed(&workspace));
qApp->processEvents();
- QTRY_VERIFY(workspace.size() != QSize(150, 150));
- QTRY_VERIFY(!vBar->isVisible());
- QTRY_VERIFY(!hBar->isVisible());
+ // Workspace should not have changed size after tile.
+ QTRY_VERIFY(workspace.size() == QSize(160, 150));
+ // Scroll bars should be visible.
+ QTRY_VERIFY(vBar->isVisible());
+ QTRY_VERIFY(hBar->isVisible());
}
void tst_QMdiArea::cascadeAndTileSubWindows()
@@ -2180,7 +2189,7 @@ void tst_QMdiArea::setActivationOrder_data()
list << 2 << 1 << 0 << 1 << 2 << 3 << 4;
list2 << 0 << 1 << 2 << 3 << 4;
- list3 << 1 << 4 << 3 << 1 << 2 << 0;
+ list3 << 4 << 3 << 2 << 4 << 1 << 0; // Most recently created window is in top-left position
QTest::newRow("CreationOrder") << QMdiArea::CreationOrder << 5 << 3 << 1 << list << list2 << list3;
list = QList<int>();
@@ -2188,7 +2197,7 @@ void tst_QMdiArea::setActivationOrder_data()
list2 = QList<int>();
list2 << 0 << 2 << 4 << 1 << 3;
list3 = QList<int>();
- list3 << 1 << 3 << 4 << 1 << 2 << 0;
+ list3 << 3 << 1 << 4 << 3 << 2 << 0; // Window with "stays-on-top" flag set will be in the top-left position
QTest::newRow("StackingOrder") << QMdiArea::StackingOrder << 5 << 3 << 1 << list << list2 << list3;
list = QList<int>();
diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
index a88fd8d19c..634e258250 100644
--- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
+++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
@@ -1143,8 +1143,16 @@ void tst_QMenu::QTBUG7411_submenus_activate()
QTRY_VERIFY(sub1.isVisible());
}
+static bool isPlatformWayland()
+{
+ return !QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive);
+}
+
void tst_QMenu::QTBUG30595_rtl_submenu()
{
+ if (isPlatformWayland())
+ QSKIP("Creating xdg_popups on Wayland requires real input events. Positions would be off.");
+
QMenu menu("Test Menu");
menu.setLayoutDirection(Qt::RightToLeft);
QMenu sub("&sub");
@@ -1179,6 +1187,9 @@ void tst_QMenu::QTBUG20403_nested_popup_on_shortcut_trigger()
#ifndef Q_OS_MACOS
void tst_QMenu::click_while_dismissing_submenu()
{
+ if (isPlatformWayland())
+ QSKIP("Wayland: Creating (grabbing) popups requires real mouse events.");
+
QMenu menu("Test Menu");
QAction *action = menu.addAction("action");
QMenu sub("&sub");
diff --git a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
index cfa2ddc4cc..be19cbc9d1 100644
--- a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
+++ b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
@@ -140,6 +140,11 @@ private slots:
void findBackwardWithRegExp();
void findWithRegExpReturnsFalseIfNoMoreResults();
#endif
+#if QT_CONFIG(regularexpression)
+ void findWithRegularExpression();
+ void findBackwardWithRegularExpression();
+ void findWithRegularExpressionReturnsFalseIfNoMoreResults();
+#endif
void layoutAfterMultiLineRemove();
void undoCommandRemovesAndReinsertsBlock();
void taskQTBUG_43562_lineCountCrash();
@@ -147,6 +152,9 @@ private slots:
void contextMenu();
#endif
void inputMethodCursorRect();
+#if QT_CONFIG(scrollbar)
+ void updateAfterChangeCenterOnScroll();
+#endif
private:
void createSelection();
@@ -1579,6 +1587,45 @@ void tst_QPlainTextEdit::findWithRegExpReturnsFalseIfNoMoreResults()
}
#endif
+#if QT_CONFIG(regularexpression)
+void tst_QPlainTextEdit::findWithRegularExpression()
+{
+ ed->setPlainText(QStringLiteral("arbitrary text"));
+ QRegularExpression rx("\\w{2}xt");
+
+ bool found = ed->find(rx);
+
+ QVERIFY(found);
+ QCOMPARE(ed->textCursor().selectedText(), QStringLiteral("text"));
+}
+
+void tst_QPlainTextEdit::findBackwardWithRegularExpression()
+{
+ ed->setPlainText(QStringLiteral("arbitrary text"));
+ QTextCursor cursor = ed->textCursor();
+ cursor.movePosition(QTextCursor::End);
+ ed->setTextCursor(cursor);
+ QRegularExpression rx("a\\w*t");
+
+ bool found = ed->find(rx, QTextDocument::FindBackward);
+
+ QVERIFY(found);
+ QCOMPARE(ed->textCursor().selectedText(), QStringLiteral("arbit"));
+}
+
+void tst_QPlainTextEdit::findWithRegularExpressionReturnsFalseIfNoMoreResults()
+{
+ ed->setPlainText(QStringLiteral("arbitrary text"));
+ QRegularExpression rx("t.xt");
+ ed->find(rx);
+
+ bool found = ed->find(rx);
+
+ QVERIFY(!found);
+ QCOMPARE(ed->textCursor().selectedText(), QStringLiteral("text"));
+}
+#endif
+
void tst_QPlainTextEdit::layoutAfterMultiLineRemove()
{
ed->setVisible(true); // The widget must be visible to reproduce this bug.
@@ -1727,5 +1774,20 @@ void tst_QPlainTextEdit::inputMethodCursorRect()
QCOMPARE(cursorRectV.toRect(), cursorRect.toRect());
}
+#if QT_CONFIG(scrollbar)
+// QTBUG-64730: Verify that the scrollbar is updated after center on scroll was set
+void tst_QPlainTextEdit::updateAfterChangeCenterOnScroll()
+{
+ ed->setPlainText("Line1\nLine2Line3\nLine3");
+ ed->show();
+ ed->setCenterOnScroll(true);
+ const int maxWithCenterOnScroll = ed->verticalScrollBar()->maximum();
+ ed->setCenterOnScroll(false);
+ const int maxWithoutCenterOnScroll = ed->verticalScrollBar()->maximum();
+ QVERIFY(maxWithCenterOnScroll > maxWithoutCenterOnScroll);
+}
+
+#endif
+
QTEST_MAIN(tst_QPlainTextEdit)
#include "tst_qplaintextedit.moc"
diff --git a/tests/auto/widgets/widgets/qsplitter/BLACKLIST b/tests/auto/widgets/widgets/qsplitter/BLACKLIST
deleted file mode 100644
index 1352805cd7..0000000000
--- a/tests/auto/widgets/widgets/qsplitter/BLACKLIST
+++ /dev/null
@@ -1,2 +0,0 @@
-[replaceWidget:visible, not collapsed]
-xcb
diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
index 6a2ae4951b..5f5cd78215 100644
--- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
+++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
@@ -199,6 +199,12 @@ private slots:
void findWithRegExpReturnsFalseIfNoMoreResults();
#endif
+#if QT_CONFIG(regularexpression)
+ void findWithRegularExpression();
+ void findBackwardWithRegularExpression();
+ void findWithRegularExpressionReturnsFalseIfNoMoreResults();
+#endif
+
#if QT_CONFIG(wheelevent)
void wheelEvent();
#endif
@@ -2572,6 +2578,45 @@ void tst_QTextEdit::findWithRegExpReturnsFalseIfNoMoreResults()
}
#endif
+#if QT_CONFIG(regularexpression)
+void tst_QTextEdit::findWithRegularExpression()
+{
+ ed->setHtml(QStringLiteral("arbitrary te<span style=\"color:#ff0000\">xt</span>"));
+ QRegularExpression rx("\\w{2}xt");
+
+ bool found = ed->find(rx);
+
+ QVERIFY(found);
+ QCOMPARE(ed->textCursor().selectedText(), QStringLiteral("text"));
+}
+
+void tst_QTextEdit::findBackwardWithRegularExpression()
+{
+ ed->setPlainText(QStringLiteral("arbitrary text"));
+ QTextCursor cursor = ed->textCursor();
+ cursor.movePosition(QTextCursor::End);
+ ed->setTextCursor(cursor);
+ QRegularExpression rx("a\\w*t");
+
+ bool found = ed->find(rx, QTextDocument::FindBackward);
+
+ QVERIFY(found);
+ QCOMPARE(ed->textCursor().selectedText(), QStringLiteral("arbit"));
+}
+
+void tst_QTextEdit::findWithRegularExpressionReturnsFalseIfNoMoreResults()
+{
+ ed->setPlainText(QStringLiteral("arbitrary text"));
+ QRegularExpression rx("t.xt");
+ ed->find(rx);
+
+ bool found = ed->find(rx);
+
+ QVERIFY(!found);
+ QCOMPARE(ed->textCursor().selectedText(), QStringLiteral("text"));
+}
+#endif
+
#if QT_CONFIG(wheelevent)
class TextEdit : public QTextEdit