mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-04 16:25:27 +08:00
qt 6.6.0 clean
This commit is contained in:
@ -174,6 +174,7 @@ private slots:
|
||||
void appFocusWidgetWhenLosingFocusProxy();
|
||||
void explicitTabOrderWithComplexWidget();
|
||||
void explicitTabOrderWithSpinBox_QTBUG81097();
|
||||
void tabOrderList();
|
||||
void tabOrderComboBox_data();
|
||||
void tabOrderComboBox();
|
||||
#if defined(Q_OS_WIN)
|
||||
@ -1932,6 +1933,26 @@ public:
|
||||
QLineEdit *lineEdit3;
|
||||
};
|
||||
|
||||
static QList<QWidget *> getFocusChain(QWidget *start, bool bForward)
|
||||
{
|
||||
QList<QWidget *> ret;
|
||||
QWidget *cur = start;
|
||||
// detect infinite loop
|
||||
int count = 100;
|
||||
auto loopGuard = qScopeGuard([]{
|
||||
QFAIL("Inifinite loop detected in focus chain");
|
||||
});
|
||||
do {
|
||||
ret += cur;
|
||||
auto widgetPrivate = static_cast<QWidgetPrivate *>(qt_widget_private(cur));
|
||||
cur = bForward ? widgetPrivate->focus_next : widgetPrivate->focus_prev;
|
||||
if (!--count)
|
||||
return ret;
|
||||
} while (cur != start);
|
||||
loopGuard.dismiss();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void tst_QWidget::defaultTabOrder()
|
||||
{
|
||||
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
|
||||
@ -2051,6 +2072,17 @@ void tst_QWidget::reverseTabOrder()
|
||||
QVERIFY(firstEdit->hasFocus());
|
||||
}
|
||||
|
||||
void tst_QWidget::tabOrderList()
|
||||
{
|
||||
Composite c;
|
||||
QCOMPARE(getFocusChain(&c, true),
|
||||
QList<QWidget *>({&c, c.lineEdit1, c.lineEdit2, c.lineEdit3}));
|
||||
QWidget::setTabOrder({c.lineEdit3, c.lineEdit2, c.lineEdit1});
|
||||
// not starting with 3 like one would maybe expect, but still 3, 2, 1
|
||||
QCOMPARE(getFocusChain(&c, true),
|
||||
QList<QWidget *>({&c, c.lineEdit1, c.lineEdit3, c.lineEdit2}));
|
||||
}
|
||||
|
||||
void tst_QWidget::tabOrderComboBox_data()
|
||||
{
|
||||
QTest::addColumn<const bool>("editableAtBeginning");
|
||||
@ -2061,26 +2093,6 @@ void tst_QWidget::tabOrderComboBox_data()
|
||||
QTest::addRow("4 editable") << true << QList<int>{2, 1, 0, 3} << QList<int>{3, 0, 2, 1};
|
||||
}
|
||||
|
||||
static QList<QWidget *> getFocusChain(QWidget *start, bool bForward)
|
||||
{
|
||||
QList<QWidget *> ret;
|
||||
QWidget *cur = start;
|
||||
// detect infinite loop
|
||||
int count = 100;
|
||||
auto loopGuard = qScopeGuard([]{
|
||||
QFAIL("Inifinite loop detected in focus chain");
|
||||
});
|
||||
do {
|
||||
ret += cur;
|
||||
auto widgetPrivate = static_cast<QWidgetPrivate *>(qt_widget_private(cur));
|
||||
cur = bForward ? widgetPrivate->focus_next : widgetPrivate->focus_prev;
|
||||
if (!--count)
|
||||
return ret;
|
||||
} while (cur != start);
|
||||
loopGuard.dismiss();
|
||||
return ret;
|
||||
}
|
||||
|
||||
QWidgetList expectedFocusChain(const QList<QComboBox *> &boxes, const QList<int> &sequence)
|
||||
{
|
||||
Q_ASSERT(boxes.count() == sequence.count());
|
||||
@ -2132,6 +2144,7 @@ void tst_QWidget::tabOrderComboBox()
|
||||
QFETCH(const QList<int>, secondTabOrder);
|
||||
const int count = firstTabOrder.count();
|
||||
Q_ASSERT(count == secondTabOrder.count());
|
||||
Q_ASSERT(count > 1);
|
||||
|
||||
QWidget w;
|
||||
w.setObjectName("MainWidget");
|
||||
@ -2164,6 +2177,31 @@ void tst_QWidget::tabOrderComboBox()
|
||||
|
||||
COMPARE(secondTabOrder);
|
||||
|
||||
// Remove the focus proxy of the first combobox's line edit.
|
||||
QComboBox *box = boxes.at(0);
|
||||
QLineEdit *lineEdit = box->lineEdit();
|
||||
QWidgetPrivate *lePriv = QWidgetPrivate::get(lineEdit);
|
||||
const QWidget *prev = lePriv->focus_prev;
|
||||
const QWidget *next = lePriv->focus_next;
|
||||
const QWidget *proxy = lePriv->extra->focus_proxy;
|
||||
QCOMPARE(proxy, box);
|
||||
lineEdit->setFocusProxy(nullptr);
|
||||
QCOMPARE(lePriv->extra->focus_proxy, nullptr);
|
||||
QCOMPARE(lePriv->focus_prev, prev);
|
||||
QCOMPARE(lePriv->focus_next, next);
|
||||
|
||||
// Remove first item and check chain consistency
|
||||
boxes.removeFirst();
|
||||
delete box;
|
||||
|
||||
// Create new list with 0 removed and other indexes updated
|
||||
QList<int> thirdTabOrder(secondTabOrder);
|
||||
thirdTabOrder.removeIf([](int i){ return i == 0; });
|
||||
for (int &i : thirdTabOrder)
|
||||
--i;
|
||||
|
||||
COMPARE(thirdTabOrder);
|
||||
|
||||
#undef COMPARE
|
||||
}
|
||||
|
||||
@ -2557,9 +2595,9 @@ void tst_QWidget::tabOrderWithCompoundWidgetsInflection()
|
||||
qCritical() << " Actual :" << forwardChain;
|
||||
qCritical() << " Expected:" << expectedFocusChain;
|
||||
});
|
||||
for (qsizetype i = 0; i < expectedFocusChain.size() - 2; ++i) {
|
||||
QVERIFY(forwardChain.indexOf(expectedFocusChain.at(i)) <
|
||||
forwardChain.indexOf(expectedFocusChain.at(i + 1)));
|
||||
for (qsizetype i = 0; i < expectedFocusChain.size() - 2; ++i) {
|
||||
QCOMPARE_LT(forwardChain.indexOf(expectedFocusChain.at(i)),
|
||||
forwardChain.indexOf(expectedFocusChain.at(i + 1)));
|
||||
}
|
||||
logger.dismiss();
|
||||
}
|
||||
|
Reference in New Issue
Block a user