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

Method numberSpinBoxLimit

tests/commonfrontend/widgets/SpinBoxTest.cpp:619–664  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

617}
618
619void SpinBoxTest::numberSpinBoxLimit() {
620 NumberSpinBox sb(5);
621 sb.setMaximum(7);
622 sb.setMinimum(3);
623
624 int valueChangedCounter = 0;
625 double lastValue = NAN;
626 connect(&sb, QOverload<double>::of(&NumberSpinBox::valueChanged), [&valueChangedCounter, &lastValue](double value) {
627 lastValue = value;
628 valueChangedCounter++;
629 });
630
631 sb.lineEdit()->setCursorPosition(1);
632 sb.increaseValue();
633 VALUES_EQUAL(sb.value(), 6.);
634 QCOMPARE(valueChangedCounter, 1);
635 QCOMPARE(lastValue, 6);
636 sb.increaseValue();
637 VALUES_EQUAL(sb.value(), 7.);
638 QCOMPARE(valueChangedCounter, 2);
639 QCOMPARE(lastValue, 7);
640 sb.increaseValue();
641 VALUES_EQUAL(sb.value(), 7.); // unable to go beyond
642 QCOMPARE(valueChangedCounter, 2);
643
644 sb.setValue(4);
645 QCOMPARE(valueChangedCounter, 3);
646 sb.lineEdit()->setCursorPosition(1);
647 VALUES_EQUAL(sb.value(), 4.);
648 QCOMPARE(valueChangedCounter, 3);
649 sb.decreaseValue();
650 VALUES_EQUAL(sb.value(), 3.);
651 QCOMPARE(valueChangedCounter, 4);
652 QCOMPARE(lastValue, 3);
653 sb.decreaseValue();
654 VALUES_EQUAL(sb.value(), 3.);
655 QCOMPARE(valueChangedCounter, 4);
656
657 // Try to insert a number
658 sb.lineEdit()->setCursorPosition(1);
659 // Important: the event text is used by the lineedit. So it has to be filled!
660 QKeyEvent event(QKeyEvent::Type::KeyPress, Qt::Key_1, Qt::KeyboardModifier::NoModifier, QStringLiteral("1"));
661 sb.keyPressEvent(&event);
662 QCOMPARE(valueChangedCounter, 4);
663 VALUES_EQUAL(sb.value(), 3.);
664}
665
666void SpinBoxTest::numberSpinBoxPrefixSuffix() {
667 NumberSpinBox sb(5.01);

Callers

nothing calls this directly

Calls 9

setMaximumMethod · 0.80
setMinimumMethod · 0.80
setCursorPositionMethod · 0.80
lineEditMethod · 0.80
decreaseValueMethod · 0.80
increaseValueMethod · 0.45
valueMethod · 0.45
setValueMethod · 0.45
keyPressEventMethod · 0.45

Tested by

no test coverage detected