summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-06-30 22:59:21 +0200
committerLiang Qi <liang.qi@qt.io>2018-07-02 11:23:45 +0200
commite3ed2281c0c891cf3b15c95f9f7cdae42e9f233a (patch)
treeaae8da6ce616eae02b69fb1fcdcb4383c8fe6811 /tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
parent3be141d5bc199080b524d8f6f5ce514e8f74d23a (diff)
parente75e4b39b78ba05ea2cd45dc96acf99fc89c5915 (diff)
Merge remote-tracking branch 'origin/5.11' into dev
Conflicts: src/plugins/platforms/cocoa/qnsview.mm src/plugins/platforms/cocoa/qnsview_dragging.mm src/plugins/platforms/ios/qiosinputcontext.mm src/plugins/platforms/xcb/qxcbconnection.cpp src/plugins/platforms/xcb/qxcbconnection_xi2.cpp src/plugins/platforms/xcb/qxcbwindow.cpp src/tools/androiddeployqt/main.cpp Was moved from qttools into qtbase in 5.11. So re-apply 32398e4d here. tests/auto/corelib/global/qlogging/test/test.pro tests/auto/corelib/global/qlogging/tst_qlogging.cpp tests/auto/corelib/io/qfile/tst_qfile.cpp tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp tests/auto/corelib/thread/qthreadstorage/test/test.pro tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp tests/auto/widgets/kernel/qapplication/test/test.pro Done-with: Gatis Paeglis <gatis.paeglis@qt.io> Done-with: MÃ¥rten Nordheim <marten.nordheim@qt.io> Done-with: Oliver Wolff <oliver.wolff@qt.io> Change-Id: Id970486c5315a1718c540f00deb2633533e8fc7b
Diffstat (limited to 'tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp')
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp69
1 files changed, 64 insertions, 5 deletions
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index 8ec8f0e3c8..e880640b6b 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -43,6 +43,7 @@
#include <qtreewidget.h>
#include <qdebug.h>
#include <qscreen.h>
+#include <qdesktopwidget.h>
typedef QList<int> IntList;
@@ -244,6 +245,7 @@ private slots:
void testMinMaxSectionSize();
void sizeHintCrash();
void testResetCachedSizeHint();
+ void statusTips();
protected:
void setupTestData(bool use_reset_model = false);
@@ -270,12 +272,20 @@ public:
int rowCount(const QModelIndex&) const override { return rows; }
int columnCount(const QModelIndex&) const override { return cols; }
bool isEditable(const QModelIndex &) const { return true; }
-
- QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
{
- if (role == Qt::DisplayRole)
- return m_bMultiLine ? QString("%1\n%1").arg(section) : QString::number(section);
- return QAbstractTableModel::headerData(section, orientation, role);
+ if (section < 0 || (role != Qt::DisplayRole && role != Qt::StatusTipRole))
+ return QVariant();
+ const int row = (orientation == Qt::Vertical ? section : 0);
+ const int col = (orientation == Qt::Horizontal ? section : 0);
+ if (orientation == Qt::Vertical && row >= rows)
+ return QVariant();
+ if (orientation == Qt::Horizontal && col >= cols)
+ return QVariant();
+ if (m_bMultiLine)
+ return QString("%1\n%1").arg(section);
+ return QLatin1Char('[') + QString::number(row) + QLatin1Char(',')
+ + QString::number(col) + QLatin1String(",0] -- Header");
}
QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override
{
@@ -3368,5 +3378,54 @@ void tst_QHeaderView::testResetCachedSizeHint()
}
+class StatusTipHeaderView : public QHeaderView
+{
+public:
+ StatusTipHeaderView(Qt::Orientation orientation = Qt::Horizontal, QWidget *parent = 0) :
+ QHeaderView(orientation, parent), gotStatusTipEvent(false) {}
+ bool gotStatusTipEvent;
+ QString statusTipText;
+protected:
+ bool event(QEvent *e)
+ {
+ if (e->type() == QEvent::StatusTip) {
+ gotStatusTipEvent = true;
+ statusTipText = static_cast<QStatusTipEvent *>(e)->tip();
+ }
+ return QHeaderView::event(e);
+ }
+};
+
+void tst_QHeaderView::statusTips()
+{
+ StatusTipHeaderView headerView;
+ QtTestModel model;
+ model.rows = model.cols = 5;
+ headerView.setModel(&model);
+ headerView.viewport()->setMouseTracking(true);
+ headerView.setGeometry(QRect(QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)),
+ QSize(500, 500)));
+ headerView.show();
+ qApp->setActiveWindow(&headerView);
+ QVERIFY(QTest::qWaitForWindowActive(&headerView));
+
+ // Ensure it is moved away first and then moved to the relevant section
+ QTest::mouseMove(QApplication::desktop(),
+ headerView.rect().bottomLeft() + QPoint(20, 20));
+ QPoint centerPoint = QRect(headerView.sectionPosition(0), headerView.y(),
+ headerView.sectionSize(0), headerView.height()).center();
+ QTest::mouseMove(headerView.windowHandle(), centerPoint);
+ QTRY_VERIFY(headerView.gotStatusTipEvent);
+ QCOMPARE(headerView.statusTipText, QLatin1String("[0,0,0] -- Header"));
+
+ headerView.gotStatusTipEvent = false;
+ headerView.statusTipText.clear();
+ centerPoint = QRect(headerView.sectionPosition(1), headerView.y(),
+ headerView.sectionSize(1), headerView.height()).center();
+ QTest::mouseMove(headerView.windowHandle(), centerPoint);
+ QTRY_VERIFY(headerView.gotStatusTipEvent);
+ QCOMPARE(headerView.statusTipText, QLatin1String("[0,1,0] -- Header"));
+}
+
QTEST_MAIN(tst_QHeaderView)
#include "tst_qheaderview.moc"