Widget autotests: replace deprecated QWidget::repaint() calls
Replace QWidget::repaint() with update() + wait until the paint event is received. Task-number: QTBUG-80237 Change-Id: I57da7cd8fa119344484b849a88729bca7b48616c Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
64760504e7
commit
e70fe301d9
@ -8297,20 +8297,14 @@ void tst_QGraphicsItem::sorting()
|
||||
|
||||
_paintedItems.clear();
|
||||
|
||||
view.viewport()->repaint();
|
||||
#if defined(Q_OS_MAC)
|
||||
// There's no difference between repaint and update on the Mac,
|
||||
// so we have to process events here to make sure we get the event.
|
||||
QTest::qWait(100);
|
||||
#endif
|
||||
|
||||
view.viewport()->update();
|
||||
const GraphicsItems expected{grid[0][0], grid[0][1], grid[0][2], grid[0][3],
|
||||
grid[1][0], grid[1][1], grid[1][2], grid[1][3],
|
||||
grid[2][0], grid[2][1], grid[2][2], grid[2][3],
|
||||
grid[3][0], grid[3][1], grid[3][2], grid[3][3],
|
||||
grid[4][0], grid[4][1], grid[4][2], grid[4][3],
|
||||
item1, item2};
|
||||
QCOMPARE(_paintedItems, expected);
|
||||
QTRY_COMPARE(_paintedItems, expected);
|
||||
}
|
||||
|
||||
void tst_QGraphicsItem::itemHasNoContents()
|
||||
@ -8337,13 +8331,7 @@ void tst_QGraphicsItem::itemHasNoContents()
|
||||
|
||||
_paintedItems.clear();
|
||||
|
||||
view.viewport()->repaint();
|
||||
#ifdef Q_OS_MAC
|
||||
// There's no difference between update() and repaint() on the Mac,
|
||||
// so we have to process events here to make sure we get the event.
|
||||
QTest::qWait(10);
|
||||
#endif
|
||||
|
||||
view.viewport()->update();
|
||||
QTRY_COMPARE(_paintedItems, GraphicsItems{item2});
|
||||
}
|
||||
|
||||
|
@ -358,13 +358,13 @@ void tst_QGraphicsView::renderHints()
|
||||
QCOMPARE(item->hints, 0);
|
||||
view.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
||||
view.repaint();
|
||||
view.update();
|
||||
QTRY_COMPARE(item->hints, view.renderHints());
|
||||
|
||||
view.setRenderHints(QPainter::Antialiasing);
|
||||
QCOMPARE(view.renderHints(), QPainter::Antialiasing);
|
||||
|
||||
view.repaint();
|
||||
view.update();
|
||||
QTRY_COMPARE(item->hints, view.renderHints());
|
||||
}
|
||||
|
||||
@ -2631,13 +2631,12 @@ void tst_QGraphicsView::optimizationFlags()
|
||||
class MessUpPainterItem : public QGraphicsRectItem
|
||||
{
|
||||
public:
|
||||
MessUpPainterItem(const QRectF &rect) : QGraphicsRectItem(rect), dirtyPainter(false)
|
||||
{ }
|
||||
|
||||
bool dirtyPainter;
|
||||
|
||||
using QGraphicsRectItem::QGraphicsRectItem;
|
||||
bool dirtyPainter = false;
|
||||
bool receivedPaintEvent = false;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *w)
|
||||
{
|
||||
receivedPaintEvent = true;
|
||||
dirtyPainter = (painter->pen().color() != w->palette().color(w->foregroundRole()));
|
||||
painter->setPen(Qt::red);
|
||||
}
|
||||
@ -2675,18 +2674,22 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState()
|
||||
QGraphicsView view(&scene);
|
||||
view.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
||||
view.viewport()->repaint();
|
||||
parent->receivedPaintEvent = false;
|
||||
child->receivedPaintEvent = false;
|
||||
view.viewport()->update();
|
||||
|
||||
QTRY_VERIFY(parent->receivedPaintEvent);
|
||||
QTRY_VERIFY(child->receivedPaintEvent);
|
||||
QVERIFY(!parent->dirtyPainter);
|
||||
QVERIFY(!child->dirtyPainter);
|
||||
|
||||
view.setOptimizationFlags(QGraphicsView::DontSavePainterState);
|
||||
view.viewport()->repaint();
|
||||
parent->receivedPaintEvent = false;
|
||||
child->receivedPaintEvent = false;
|
||||
view.viewport()->update();
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
// Repaint on OS X actually does require spinning the event loop.
|
||||
QTest::qWait(100);
|
||||
#endif
|
||||
QTRY_VERIFY(parent->receivedPaintEvent);
|
||||
QTRY_VERIFY(child->receivedPaintEvent);
|
||||
QVERIFY(!parent->dirtyPainter);
|
||||
QVERIFY(child->dirtyPainter);
|
||||
|
||||
@ -2753,7 +2756,7 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState2()
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
||||
|
||||
// Make sure the view is repainted; otherwise the tests below will fail.
|
||||
view.viewport()->repaint();
|
||||
view.viewport()->update();
|
||||
QTRY_VERIFY(view.painted);
|
||||
|
||||
// Make sure the painter's world transform is preserved after drawItems.
|
||||
@ -4732,14 +4735,12 @@ void tst_QGraphicsView::QTBUG_5859_exposedRect()
|
||||
QGraphicsView view(&scene);
|
||||
view.scale(4.15, 4.15);
|
||||
view.showNormal();
|
||||
qApp->setActiveWindow(&view);
|
||||
QApplication::setActiveWindow(&view);
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
||||
QVERIFY(QTest::qWaitForWindowActive(&view));
|
||||
|
||||
view.viewport()->repaint(10,10,20,20);
|
||||
QApplication::processEvents();
|
||||
|
||||
QCOMPARE(item.lastExposedRect, scene.lastBackgroundExposedRect);
|
||||
view.viewport()->update(10,10,20,20);
|
||||
QTRY_COMPARE(item.lastExposedRect, scene.lastBackgroundExposedRect);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_CURSOR
|
||||
|
@ -1186,7 +1186,7 @@ void tst_QGraphicsWidget::layoutDirection()
|
||||
for (int i = 0; i < children.count(); ++i) {
|
||||
QTRY_COMPARE(children[i]->layoutDirection(), layoutDirection);
|
||||
QTRY_COMPARE(children[i]->testAttribute(Qt::WA_SetLayoutDirection), false);
|
||||
view->repaint();
|
||||
view->update();
|
||||
QTRY_COMPARE(children[i]->m_painterLayoutDirection, layoutDirection);
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,30 @@ static void initStandardTreeModel(QStandardItemModel *model)
|
||||
model->insertRow(2, item);
|
||||
}
|
||||
|
||||
class TreeView : public QTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QTreeView::QTreeView;
|
||||
using QTreeView::selectedIndexes;
|
||||
|
||||
void paintEvent(QPaintEvent *event) override
|
||||
{
|
||||
QTreeView::paintEvent(event);
|
||||
wasPainted = true;
|
||||
}
|
||||
bool wasPainted = false;
|
||||
public slots:
|
||||
void handleSelectionChanged()
|
||||
{
|
||||
//let's select the last item
|
||||
QModelIndex idx = model()->index(0, 0);
|
||||
selectionModel()->select(QItemSelection(idx, idx), QItemSelectionModel::Select);
|
||||
disconnect(selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
this, &TreeView::handleSelectionChanged);
|
||||
}
|
||||
};
|
||||
|
||||
class tst_QTreeView : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -2980,7 +3004,7 @@ void tst_QTreeView::evilModel()
|
||||
{
|
||||
QFETCH(bool, visible);
|
||||
// init
|
||||
QTreeView view;
|
||||
TreeView view;
|
||||
EvilModel model;
|
||||
view.setModel(&model);
|
||||
view.setVisible(visible);
|
||||
@ -3018,7 +3042,7 @@ void tst_QTreeView::evilModel()
|
||||
view.scrollTo(thirdLevel);
|
||||
model.change();
|
||||
|
||||
view.repaint();
|
||||
view.update(); // will not do anything since view is not visible
|
||||
model.change();
|
||||
|
||||
QTest::mouseDClick(view.viewport(), Qt::LeftButton);
|
||||
@ -3175,7 +3199,7 @@ void tst_QTreeView::filterProxyModelCrash()
|
||||
QSortFilterProxyModel proxy;
|
||||
proxy.setSourceModel(&model);
|
||||
|
||||
QTreeView view;
|
||||
TreeView view;
|
||||
view.setModel(&proxy);
|
||||
view.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
||||
@ -3184,7 +3208,8 @@ void tst_QTreeView::filterProxyModelCrash()
|
||||
QTest::qWait(20);
|
||||
|
||||
proxy.invalidate();
|
||||
view.repaint(); //used to crash
|
||||
view.update(); //used to crash
|
||||
QTRY_VERIFY(view.wasPainted);
|
||||
}
|
||||
|
||||
void tst_QTreeView::renderToPixmap_data()
|
||||
@ -3652,10 +3677,7 @@ void tst_QTreeView::task220298_selectColumns()
|
||||
}
|
||||
};
|
||||
|
||||
class TreeView : public QTreeView {
|
||||
public:
|
||||
using QTreeView::selectedIndexes;
|
||||
} view;
|
||||
TreeView view;
|
||||
Model model;
|
||||
view.setModel(&model);
|
||||
view.show();
|
||||
@ -4004,20 +4026,6 @@ void tst_QTreeView::task254234_proxySort()
|
||||
QCOMPARE(view.model()->data(view.model()->index(1, 1)).toString(), QString::fromLatin1("g"));
|
||||
}
|
||||
|
||||
class TreeView : public QTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
public slots:
|
||||
void handleSelectionChanged()
|
||||
{
|
||||
//let's select the last item
|
||||
QModelIndex idx = model()->index(0, 0);
|
||||
selectionModel()->select(QItemSelection(idx, idx), QItemSelectionModel::Select);
|
||||
disconnect(selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
this, &TreeView::handleSelectionChanged);
|
||||
}
|
||||
};
|
||||
|
||||
void tst_QTreeView::task248022_changeSelection()
|
||||
{
|
||||
//we check that changing the selection between the mouse press and the mouse release
|
||||
|
@ -8385,12 +8385,9 @@ void tst_QWidget::resizeInPaintEvent()
|
||||
widget.resizeInPaintEvent = true;
|
||||
// This will call resize in the paintEvent, which in turn will call
|
||||
// invalidateBackingStore() and a new update request should be posted.
|
||||
widget.repaint();
|
||||
QCOMPARE(widget.numPaintEvents, 1);
|
||||
widget.numPaintEvents = 0;
|
||||
|
||||
// Make sure the resize triggers another update.
|
||||
QTRY_COMPARE(widget.numPaintEvents, 1);
|
||||
// the resize triggers another update.
|
||||
widget.update();
|
||||
QTRY_COMPARE(widget.numPaintEvents, 2);
|
||||
}
|
||||
|
||||
void tst_QWidget::opaqueChildren()
|
||||
@ -8559,8 +8556,8 @@ void tst_QWidget::immediateRepaintAfterInvalidateBackingStore()
|
||||
// The entire widget is already dirty, but this time we want to update immediately
|
||||
// by calling repaint(), and thus we have to repaint the widget and not wait for
|
||||
// the UpdateRequest to be sent when we get back to the event loop.
|
||||
widget->repaint();
|
||||
QCOMPARE(widget->numPaintEvents, 1);
|
||||
widget->update();
|
||||
QTRY_COMPARE(widget->numPaintEvents, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -9832,7 +9829,7 @@ public:
|
||||
if (!static_cast<QWidgetPrivate*>(d_ptr.data())->maybeRepaintManager()) {
|
||||
static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->repaintManager.reset(new QWidgetRepaintManager(this));
|
||||
static_cast<QWidgetPrivate*>(d_ptr.data())->invalidateBackingStore(this->rect());
|
||||
repaint();
|
||||
update();
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -9855,7 +9852,7 @@ void tst_QWidget::scrollWithoutBackingStore()
|
||||
scrollable.scroll(-25,-25);
|
||||
QCOMPARE(child.pos(),QPoint(25,25));
|
||||
scrollable.enableBackingStore();
|
||||
QCOMPARE(child.pos(),QPoint(25,25));
|
||||
QTRY_COMPARE(child.pos(),QPoint(25,25));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -77,24 +77,22 @@ using namespace QTestPrivate;
|
||||
|
||||
class StyleOptionTestStyle : public QCommonStyle
|
||||
{
|
||||
private:
|
||||
bool readOnly;
|
||||
|
||||
public:
|
||||
inline StyleOptionTestStyle() : QCommonStyle(), readOnly(false)
|
||||
{
|
||||
}
|
||||
bool readOnly = false;
|
||||
mutable bool wasDrawn = false;
|
||||
|
||||
inline void setReadOnly(bool readOnly)
|
||||
using QCommonStyle::QCommonStyle;
|
||||
void setReadOnly(bool readOnly)
|
||||
{
|
||||
this->readOnly = readOnly;
|
||||
}
|
||||
|
||||
inline void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *,
|
||||
const QWidget *) const
|
||||
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *,
|
||||
const QWidget *) const override
|
||||
{
|
||||
switch (pe) {
|
||||
case PE_PanelLineEdit:
|
||||
wasDrawn = true;
|
||||
if (readOnly)
|
||||
QVERIFY(opt->state & QStyle::State_ReadOnly);
|
||||
else
|
||||
@ -3271,19 +3269,22 @@ void tst_QLineEdit::readOnlyStyleOption()
|
||||
QLineEdit *testWidget = ensureTestWidget();
|
||||
bool wasReadOnly = testWidget->isReadOnly();
|
||||
QStyle *oldStyle = testWidget->style();
|
||||
testWidget->show();
|
||||
QTRY_VERIFY(QTest::qWaitForWindowExposed(testWidget));
|
||||
|
||||
StyleOptionTestStyle myStyle;
|
||||
testWidget->setStyle(&myStyle);
|
||||
|
||||
myStyle.setReadOnly(true);
|
||||
testWidget->setReadOnly(true);
|
||||
testWidget->repaint();
|
||||
qApp->processEvents();
|
||||
testWidget->update();
|
||||
QTRY_VERIFY(myStyle.wasDrawn);
|
||||
myStyle.wasDrawn = false;
|
||||
|
||||
testWidget->setReadOnly(false);
|
||||
myStyle.setReadOnly(false);
|
||||
testWidget->repaint();
|
||||
qApp->processEvents();
|
||||
testWidget->update();
|
||||
QTRY_VERIFY(myStyle.wasDrawn);
|
||||
|
||||
testWidget->setReadOnly(wasReadOnly);
|
||||
testWidget->setStyle(oldStyle);
|
||||
|
Loading…
x
Reference in New Issue
Block a user