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

Method numberSpinBoxMinimumFeedback

tests/commonfrontend/widgets/SpinBoxTest.cpp:1119–1163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1117}
1118
1119void SpinBoxTest::numberSpinBoxMinimumFeedback() {
1120 // Limit to min/max when stepping in the spinbox
1121 // instead of raising an error
1122 NumberSpinBox sb;
1123 sb.setMinimum(0);
1124 sb.setValue(1.01);
1125 sb.setFeedback(true);
1126
1127 int valueChangedCounter = 0;
1128 double lastValue = NAN;
1129 connect(&sb, QOverload<double>::of(&NumberSpinBox::valueChanged), [&valueChangedCounter, &lastValue](double value) {
1130 valueChangedCounter++;
1131 lastValue = value;
1132 });
1133
1134 QCOMPARE(sb.lineEdit()->text(), QStringLiteral("1.01"));
1135
1136 sb.lineEdit()->setCursorPosition(1);
1137 QKeyEvent event(QKeyEvent::Type::KeyPress, Qt::Key_Down, Qt::KeyboardModifier::NoModifier);
1138 sb.keyPressEvent(&event);
1139
1140 QCOMPARE(sb.lineEdit()->text(), QStringLiteral("0.01"));
1141 QCOMPARE(sb.lineEdit()->cursorPosition(), 1);
1142 QCOMPARE(valueChangedCounter, 1);
1143 QCOMPARE(sb.toolTip(), QString());
1144
1145 sb.keyPressEvent(&event);
1146 QCOMPARE(sb.lineEdit()->text(), QStringLiteral("0.01"));
1147 QCOMPARE(sb.lineEdit()->cursorPosition(), 1);
1148 QCOMPARE(valueChangedCounter, 1);
1149 QCOMPARE(sb.toolTip(), QString());
1150
1151 sb.lineEdit()->setCursorPosition(4);
1152 sb.keyPressEvent(&event);
1153 QCOMPARE(sb.lineEdit()->text(), QStringLiteral("0.00"));
1154 QCOMPARE(sb.lineEdit()->cursorPosition(), 4);
1155 QCOMPARE(valueChangedCounter, 2);
1156 QCOMPARE(sb.toolTip(), QString());
1157
1158 sb.keyPressEvent(&event);
1159 QCOMPARE(sb.lineEdit()->text(), QStringLiteral("0.00"));
1160 QCOMPARE(sb.lineEdit()->cursorPosition(), 4);
1161 QCOMPARE(valueChangedCounter, 2);
1162 QCOMPARE(sb.toolTip(), QString());
1163}
1164
1165// \brief SpinBoxTest::numberSpinBoxDecimalsMinMax
1166// In the default implementation of QDoubleSpinbox the maximum and

Callers

nothing calls this directly

Calls 9

setMinimumMethod · 0.80
setFeedbackMethod · 0.80
lineEditMethod · 0.80
setCursorPositionMethod · 0.80
QStringClass · 0.50
setValueMethod · 0.45
textMethod · 0.45
keyPressEventMethod · 0.45
toolTipMethod · 0.45

Tested by

no test coverage detected