QPlainTextEdit: Don't block signals on page step
Signals of the vertical scroll bar were blocked when scrolling with
pageUp/pageDown keys or clicking on the scroll range outside the
scroll bar. This has lead to inconsistent signal emissions:
The vertical scroll bar's valueChanged signal was emitted only on
single steps and when the scroll bar was moved with the mouse.
When it was moved in page steps by clicking on the scroll range or
pressing pageUp/pageDown, it was not emitted.
This patch removes the signal blocker for page step movements, which
was added in 94fd108ea4 to replace
explicit calls to blockSignals(), which were added in
c14d442b08ac81327b173b0a220c7b1840667899.
The patch also adds test function to tst_QPlainTextEdit to check if
the valueChanged signal is emitted correctly.
Pick-to: 6.5 6.4 6.2
Fixes: QTBUG-8682
Fixes: QTBUG-25365
Change-Id: I4385a5387c91497f623978e35bbbe3e06f473afe
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
bb10
parent
99975ec07f
commit
09c3cd8503
|
|
@ -629,10 +629,7 @@ void QPlainTextEditPrivate::setTopBlock(int blockNumber, int lineNumber, int dx)
|
|||
lineNumber = maxTopLine - block.firstLineNumber();
|
||||
}
|
||||
|
||||
{
|
||||
const QSignalBlocker blocker(vbar);
|
||||
vbar->setValue(newTopLine);
|
||||
}
|
||||
vbar->setValue(newTopLine);
|
||||
|
||||
if (!dx && blockNumber == control->topBlock && lineNumber == topLine)
|
||||
return;
|
||||
|
|
@ -648,10 +645,7 @@ void QPlainTextEditPrivate::setTopBlock(int blockNumber, int lineNumber, int dx)
|
|||
control->topBlock = blockNumber;
|
||||
topLine = lineNumber;
|
||||
|
||||
{
|
||||
const QSignalBlocker blocker(vbar);
|
||||
vbar->setValue(block.firstLineNumber() + lineNumber);
|
||||
}
|
||||
vbar->setValue(block.firstLineNumber() + lineNumber);
|
||||
|
||||
if (dx || dy) {
|
||||
viewport->scroll(q->isRightToLeft() ? -dx : dx, dy);
|
||||
|
|
@ -1012,10 +1006,7 @@ void QPlainTextEditPrivate::_q_adjustScrollbars()
|
|||
if (firstVisibleBlock.isValid())
|
||||
visualTopLine = firstVisibleBlock.firstLineNumber() + topLine;
|
||||
|
||||
{
|
||||
const QSignalBlocker blocker(vbar);
|
||||
vbar->setValue(visualTopLine);
|
||||
}
|
||||
vbar->setValue(visualTopLine);
|
||||
|
||||
hbar->setRange(0, (int)documentSize.width() - viewport->width());
|
||||
hbar->setPageStep(viewport->width());
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ private slots:
|
|||
void appendTextWhenInvisible();
|
||||
void placeholderVisibility_data();
|
||||
void placeholderVisibility();
|
||||
void scrollBarSignals();
|
||||
|
||||
private:
|
||||
void createSelection();
|
||||
|
|
@ -1919,5 +1920,30 @@ void tst_QPlainTextEdit::placeholderVisibility()
|
|||
QTRY_VERIFY(plainTextEdit_d->placeholderVisible == placeholderVisible);
|
||||
}
|
||||
|
||||
|
||||
void tst_QPlainTextEdit::scrollBarSignals()
|
||||
{
|
||||
QPlainTextEdit plainTextEdit;
|
||||
QString longText;
|
||||
for (uint i = 0; i < 500; ++i)
|
||||
longText += "This is going to be a very long text for scroll signal testing.\n";
|
||||
plainTextEdit.setPlainText(longText);
|
||||
QScrollBar *vbar = plainTextEdit.verticalScrollBar();
|
||||
plainTextEdit.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&plainTextEdit));
|
||||
QSignalSpy spy(vbar, &QScrollBar::valueChanged);
|
||||
|
||||
QTest::keyClick(vbar, Qt::Key_Down);
|
||||
QTRY_COMPARE(spy.count(), 1);
|
||||
QTest::keyClick(vbar, Qt::Key_PageDown);
|
||||
QTRY_COMPARE(spy.count(), 2);
|
||||
QTest::keyClick(vbar, Qt::Key_PageDown);
|
||||
QTRY_COMPARE(spy.count(), 3);
|
||||
QTest::keyClick(vbar, Qt::Key_Up);
|
||||
QTRY_COMPARE(spy.count(), 4);
|
||||
QTest::keyClick(vbar, Qt::Key_PageUp);
|
||||
QTRY_COMPARE(spy.count(), 5);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QPlainTextEdit)
|
||||
#include "tst_qplaintextedit.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue