| 617 | } |
| 618 | |
| 619 | void 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 | |
| 666 | void SpinBoxTest::numberSpinBoxPrefixSuffix() { |
| 667 | NumberSpinBox sb(5.01); |
nothing calls this directly
no test coverage detected