MCPcopy Create free account
hub / github.com/KDE/labplot / numberSpinBoxEnterNumber

Method numberSpinBoxEnterNumber

tests/commonfrontend/widgets/SpinBoxTest.cpp:804–903  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

802}
803
804void SpinBoxTest::numberSpinBoxEnterNumber() {
805 NumberSpinBox sb;
806 sb.setDecimals(0);
807 sb.setValue(5);
808 sb.setMaximum(100);
809 sb.setMinimum(0);
810
811 int valueChangedCounter = 0;
812 double lastValue = NAN;
813 connect(&sb, QOverload<double>::of(&NumberSpinBox::valueChanged), [&valueChangedCounter, &lastValue](double value) {
814 lastValue = value;
815 valueChangedCounter++;
816 });
817
818 QCOMPARE(sb.toolTip(), QString());
819 sb.lineEdit()->setCursorPosition(1);
820 QKeyEvent event(QKeyEvent::Type::KeyPress, Qt::Key_1, Qt::KeyboardModifier::NoModifier, QStringLiteral("1"));
821 sb.keyPressEvent(&event);
822 QCOMPARE(sb.toolTip(), QString());
823 QCOMPARE(sb.value(), 51);
824 QCOMPARE(valueChangedCounter, 1);
825
826 // 511
827 sb.keyPressEvent(&event);
828 QCOMPARE(sb.toolTip(), sb.errorToString(NumberSpinBox::Errors::Max));
829 QCOMPARE(sb.value(), 51);
830 QCOMPARE(sb.lineEdit()->text(), QStringLiteral("511"));
831 QCOMPARE(valueChangedCounter, 1);
832
833 // 51
834 QKeyEvent event2(QKeyEvent::Type::KeyPress, Qt::Key_Backspace, Qt::KeyboardModifier::NoModifier, QString());
835 sb.keyPressEvent(&event2);
836 QCOMPARE(sb.lineEdit()->cursorPosition(), 2);
837 QCOMPARE(sb.toolTip(), sb.errorToString(NumberSpinBox::Errors::NoError));
838 QCOMPARE(sb.value(), 51);
839 QCOMPARE(valueChangedCounter, 1);
840
841 // 5
842 QKeyEvent event3(QKeyEvent::Type::KeyPress, Qt::Key_Backspace, Qt::KeyboardModifier::NoModifier, QString());
843 sb.keyPressEvent(&event3);
844 QCOMPARE(sb.lineEdit()->cursorPosition(), 1);
845 QCOMPARE(sb.toolTip(), sb.errorToString(NumberSpinBox::Errors::NoError));
846 QCOMPARE(sb.value(), 5);
847 QCOMPARE(valueChangedCounter, 2);
848
849 // nothing
850 QKeyEvent event4(QKeyEvent::Type::KeyPress, Qt::Key_Backspace, Qt::KeyboardModifier::NoModifier, QString());
851 sb.keyPressEvent(&event4);
852 QCOMPARE(sb.lineEdit()->cursorPosition(), 0);
853 QCOMPARE(sb.lineEdit()->text(), QString());
854 QCOMPARE(sb.toolTip(), sb.errorToString(NumberSpinBox::Errors::NoNumber));
855 QCOMPARE(sb.value(), 5);
856 QCOMPARE(valueChangedCounter, 2);
857
858 // -
859 QKeyEvent event5(QKeyEvent::Type::KeyPress, Qt::Key_Minus, Qt::KeyboardModifier::NoModifier, QStringLiteral("-"));
860 sb.keyPressEvent(&event5);
861 QCOMPARE(sb.lineEdit()->cursorPosition(), 1);

Callers

nothing calls this directly

Calls 11

setMaximumMethod · 0.80
setMinimumMethod · 0.80
setCursorPositionMethod · 0.80
lineEditMethod · 0.80
errorToStringMethod · 0.80
QStringClass · 0.50
setValueMethod · 0.45
toolTipMethod · 0.45
keyPressEventMethod · 0.45
valueMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected