Преглед изворни кода

Expose ctkDoubleSpinBox::DecimalsOption to other widgets

Julien Finet пре 12 година
родитељ
комит
b3a1605ebb

+ 210 - 116
Libs/Widgets/Testing/Cpp/ctkDoubleSpinBoxTest.cpp

@@ -43,8 +43,14 @@ private slots:
   void testDecimalsByKey();
   void testDecimalsByKey_data();
 
+  void testPrefix();
+  void testPrefix_data();
+
   void testDecimalsByValue();
   void testDecimalsByValue_data();
+
+  void testDecimalPointAlwaysVisible();
+  void testDecimalPointAlwaysVisible_data();
 };
 
 // ----------------------------------------------------------------------------
@@ -53,18 +59,21 @@ void ctkDoubleSpinBoxTester::testUI()
   ctkDoubleSpinBox spinBox;
   spinBox.setMinimum(-100.);
   spinBox.setMaximum(100.);
-  spinBox.setValue(1.);
-  spinBox.setDecimalsOption( ctkDoubleSpinBox::DecimalsByKey );
+  spinBox.setDecimalsOption( ctkDoubleSpinBox::DecimalsByValue |ctkDoubleSpinBox::DecimalsByShortcuts );
+  spinBox.setValue(26.2110001);
+  spinBox.setPrefix("A: ");
+  spinBox.setSetMode(ctkDoubleSpinBox::SetAlways);
   spinBox.show();
+  QTest::qWaitForWindowShown(&spinBox);
+  QObject::connect(&spinBox, SIGNAL(valueChanged(double)),
+                   &spinBox, SLOT(setValue(double)), Qt::QueuedConnection);
 
   QDoubleSpinBox doubleSpinBox;
   doubleSpinBox.setMinimum(-100.);
   doubleSpinBox.setMaximum(100.);
   doubleSpinBox.setValue(2.);
-  doubleSpinBox.show();
-
-  QTest::qWaitForWindowShown(&spinBox);
-  QTest::qWaitForWindowShown(&doubleSpinBox);
+  //doubleSpinBox.show();
+  //QTest::qWaitForWindowShown(&doubleSpinBox);
 
   //qApp->exec();
 }
@@ -83,12 +92,13 @@ void ctkDoubleSpinBoxTester::testToLocals()
 void ctkDoubleSpinBoxTester::testDecimalsByKey()
 {
   ctkDoubleSpinBox spinBox;
-  spinBox.setMinimum(-100.);
-  spinBox.setMaximum(100.);
-  spinBox.setValue(1.);
+  spinBox.setMinimum(-200.);
+  spinBox.setMaximum(200.);
+  spinBox.setValue(1.23);
 
   QFETCH(int, decimalsOptions);
   spinBox.setDecimalsOption( static_cast<ctkDoubleSpinBox::DecimalsOptions>(decimalsOptions) );
+  const int oldDecimals = spinBox.decimals();
 
   QFETCH(int, cursorPosition);
   QFETCH(int, key);
@@ -106,7 +116,7 @@ void ctkDoubleSpinBoxTester::testDecimalsByKey()
   QCOMPARE(spinBox.text(), expectedText);
   QCOMPARE(spinBox.value(), expectedText.toDouble());
   QCOMPARE(spinBox.decimals(), expectedDecimals);
-  QCOMPARE(spy.count(), spinBox.decimals() != 2 ? 1 : 0);
+  QCOMPARE(spy.count(), spinBox.decimals() != oldDecimals ? 1 : 0);
 }
 
 // ----------------------------------------------------------------------------
@@ -121,128 +131,186 @@ void ctkDoubleSpinBoxTester::testDecimalsByKey_data()
   QList<int> options;
   // ctkDoubleSpinBox::DecimalsByKey
   options << ctkDoubleSpinBox::DecimalsByKey;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 0:'1' -> 11.00") << options.last() << 0 << int(Qt::Key_1) << "11.00"<< 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 0:'-' -> -1.00") << options.last() << 0 << int(Qt::Key_Minus) << "-1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 0:'del' -> .00") << options.last() << 0 << int(Qt::Key_Delete) << ".00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 0:'backspace' -> 1.00") << options.last() << 0 << int(Qt::Key_Backspace) << "1.00" << 2;
-
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 1:'1' -> 11.00") << options.last() << 1 << int(Qt::Key_1) << "11.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 1:'-' -> 1.00") << options.last() << 1 << int(Qt::Key_Minus) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 1:'del' -> 100.") << options.last() << 1 << int(Qt::Key_Delete) << "100." << 0;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 1:'backspace' -> .00") << options.last() << 1 << int(Qt::Key_Backspace) << ".00" << 2;
-
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 2:'1' -> 1.100") << options.last() << 2 << int(Qt::Key_1) << "1.100" << 3;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 2:'-' -> 1.00") << options.last() << 2 << int(Qt::Key_Minus) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 2:'del' -> 1.0") << options.last() << 2 << int(Qt::Key_Delete) << "1.0" << 1;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 2:'backspace' -> 100.") << options.last() << 2 << int(Qt::Key_Backspace) << "100." << 0;
-
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 3:'1' -> 1.010") << options.last() << 3 << int(Qt::Key_1) << "1.010" << 3;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 3:'-' -> 1.00") << options.last() << 3 << int(Qt::Key_Minus) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 3:'del' -> 1.0") << options.last() << 3 << int(Qt::Key_Delete) << "1.0" << 1;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 3:'backspace' -> 1.0") << options.last() << 3 << int(Qt::Key_Backspace) << "1.0" << 1;
-
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 4:'1' -> 1.001") << options.last() << 4 << int(Qt::Key_1) << "1.001" << 3;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 4:'-' -> 1.00") << options.last() << 4 << int(Qt::Key_Minus) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 4:'del' -> 1.00") << options.last() << 4 << int(Qt::Key_Delete) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 4:'backspace' -> 1.0") << options.last() << 4 << int(Qt::Key_Backspace) << "1.0" << 1;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 0:'1' -> 11.23") << options.last() << 0 << int(Qt::Key_1) << "11.23"<< 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 0:'del' -> .23") << options.last() << 0 << int(Qt::Key_Delete) << ".23" << 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 0:'backspace' -> 1.23") << options.last() << 0 << int(Qt::Key_Backspace) << "1.23" << 2;
+
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 1:'1' -> 11.23") << options.last() << 1 << int(Qt::Key_1) << "11.23" << 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 1:'del' -> 123") << options.last() << 1 << int(Qt::Key_Delete) << "123" << 0;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 1:'backspace' -> .23") << options.last() << 1 << int(Qt::Key_Backspace) << ".23" << 2;
+
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 2:'1' -> 1.12") << options.last() << 2 << int(Qt::Key_1) << "1.12" << 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 2:'del' -> 1.3") << options.last() << 2 << int(Qt::Key_Delete) << "1.3" << 1;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 2:'backspace' -> 123") << options.last() << 2 << int(Qt::Key_Backspace) << "123" << 0;
+
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 3:'1' -> 1.21") << options.last() << 3 << int(Qt::Key_1) << "1.21" << 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 3:'del' -> 1.2") << options.last() << 3 << int(Qt::Key_Delete) << "1.2" << 1;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 3:'backspace' -> 1.3") << options.last() << 3 << int(Qt::Key_Backspace) << "1.3" << 1;
+
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 4:'1' -> 1.231") << options.last() << 4 << int(Qt::Key_1) << "1.231" << 3;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 4:'del' -> 1.23") << options.last() << 4 << int(Qt::Key_Delete) << "1.23" << 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 4:'backspace' -> 1.2") << options.last() << 4 << int(Qt::Key_Backspace) << "1.2" << 1;
 
   // ctkDoubleSpinBox::ReplaceDecimals
   options << ctkDoubleSpinBox::ReplaceDecimals;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 0:'1' -> 11.00") << options.last() << 0 << int(Qt::Key_1) << "11.00"<< 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 0:'-' -> -1.00") << options.last() << 0 << int(Qt::Key_Minus) << "-1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 0:'del' -> .00") << options.last() << 0 << int(Qt::Key_Delete) << ".00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 0:'backspace' -> 1.00") << options.last() << 0 << int(Qt::Key_Backspace) << "1.00" << 2;
-
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 1:'1' -> 11.00") << options.last() << 1 << int(Qt::Key_1) << "11.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 1:'-' -> 1.00") << options.last() << 1 << int(Qt::Key_Minus) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 1:'del' -> 100") << options.last() << 1 << int(Qt::Key_Delete) << "100" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 1:'backspace' -> .00") << options.last() << 1 << int(Qt::Key_Backspace) << ".00" << 2;
-
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 2:'1' -> 1.10") << options.last() << 2 << int(Qt::Key_1) << "1.10" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 2:'-' -> 1.00") << options.last() << 2 << int(Qt::Key_Minus) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 2:'del' -> 1.00") << options.last() << 2 << int(Qt::Key_Delete) << "1.0" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 2:'backspace' -> 100") << options.last() << 2 << int(Qt::Key_Backspace) << "100" << 2;
-
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 3:'1' -> 1.01") << options.last() << 3 << int(Qt::Key_1) << "1.01" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 3:'-' -> 1.00") << options.last() << 3 << int(Qt::Key_Minus) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 3:'del' -> 1.0") << options.last() << 3 << int(Qt::Key_Delete) << "1.0" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 3:'backspace' -> 1.00") << options.last() << 3 << int(Qt::Key_Backspace) << "1.0" << 2;
-
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 4:'1' -> 1.00") << options.last() << 4 << int(Qt::Key_1) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 4:'-' -> 1.00") << options.last() << 4 << int(Qt::Key_Minus) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 4:'del' -> 1.00") << options.last() << 4 << int(Qt::Key_Delete) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 4:'backspace' -> 1.00") << options.last() << 4 << int(Qt::Key_Backspace) << "1.0" << 2;
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 0:'1' -> 11.23") << options.last() << 0 << int(Qt::Key_1) << "11.23"<< 2;
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 0:'del' -> .23") << options.last() << 0 << int(Qt::Key_Delete) << ".23" << 2;
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 0:'backspace' -> 1.23") << options.last() << 0 << int(Qt::Key_Backspace) << "1.23" << 2;
+
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 1:'1' -> 11.23") << options.last() << 1 << int(Qt::Key_1) << "11.23" << 2;
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 1:'del' -> 123") << options.last() << 1 << int(Qt::Key_Delete) << "123" << 2;
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 1:'backspace' -> .23") << options.last() << 1 << int(Qt::Key_Backspace) << ".23" << 2;
+
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 2:'1' -> 1.13") << options.last() << 2 << int(Qt::Key_1) << "1.13" << 2;
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 2:'del' -> 1.3") << options.last() << 2 << int(Qt::Key_Delete) << "1.3" << 2;
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 2:'backspace' -> 123") << options.last() << 2 << int(Qt::Key_Backspace) << "123" << 2;
+
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 3:'1' -> 1.21") << options.last() << 3 << int(Qt::Key_1) << "1.21" << 2;
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 3:'del' -> 1.2") << options.last() << 3 << int(Qt::Key_Delete) << "1.2" << 2;
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 3:'backspace' -> 1.3") << options.last() << 3 << int(Qt::Key_Backspace) << "1.3" << 2;
+
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 4:'1' -> 1.23") << options.last() << 4 << int(Qt::Key_1) << "1.23" << 2;
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 4:'del' -> 1.23") << options.last() << 4 << int(Qt::Key_Delete) << "1.23" << 2;
+  QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 4:'backspace' -> 1.2") << options.last() << 4 << int(Qt::Key_Backspace) << "1.2" << 2;
 
   // ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals
   options << (ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals);
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 0:'1' -> 11.00")
-    << options.last() << 0 << int(Qt::Key_1) << "11.00"<< 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 0:'-' -> -1.00")
-    << options.last() << 0 << int(Qt::Key_Minus) << "-1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 0:'del' -> .00")
-    << options.last() << 0 << int(Qt::Key_Delete) << ".00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 0:'backspace' -> 1.00")
-    << options.last() << 0 << int(Qt::Key_Backspace) << "1.00" << 2;
-
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 1:'1' -> 11.00")
-    << options.last() << 1 << int(Qt::Key_1) << "11.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 1:'-' -> 1.00")
-    << options.last() << 1 << int(Qt::Key_Minus) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 1:'del' -> 100.")
-    << options.last() << 1 << int(Qt::Key_Delete) << "100." << 0;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 1:'backspace' -> .00")
-    << options.last() << 1 << int(Qt::Key_Backspace) << ".00" << 2;
-
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 2:'1' -> 1.10")
-    << options.last() << 2 << int(Qt::Key_1) << "1.10" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 2:'-' -> 1.00")
-    << options.last() << 2 << int(Qt::Key_Minus) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 2:'del' -> 1.0")
-    << options.last() << 2 << int(Qt::Key_Delete) << "1.0" << 1;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 2:'backspace' -> 100.")
-    << options.last() << 2 << int(Qt::Key_Backspace) << "100." << 0;
-
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 3:'1' -> 1.01")
-    << options.last() << 3 << int(Qt::Key_1) << "1.01" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 3:'-' -> 1.00")
-    << options.last() << 3 << int(Qt::Key_Minus) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 3:'del' -> 1.0")
-    << options.last() << 3 << int(Qt::Key_Delete) << "1.0" << 1;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 3:'backspace' -> 1.0")
-    << options.last() << 3 << int(Qt::Key_Backspace) << "1.0" << 1;
-
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 4:'1' -> 1.001")
-    << options.last() << 4 << int(Qt::Key_1) << "1.001" << 3;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 4:'-' -> 1.00")
-    << options.last() << 4 << int(Qt::Key_Minus) << "1.00" << 2;
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 4:'del' -> 1.00")
-    << options.last() << 4 << int(Qt::Key_Delete) << "1.00" << 2;
-
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 4:'backspace' -> 1.00")
-    << options.last() << 4 << int(Qt::Key_Backspace) << "1.0" << 1;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 0:'1' -> 11.23")
+    << options.last() << 0 << int(Qt::Key_1) << "11.23"<< 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 0:'del' -> .23")
+    << options.last() << 0 << int(Qt::Key_Delete) << ".23" << 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 0:'backspace' -> 1.23")
+    << options.last() << 0 << int(Qt::Key_Backspace) << "1.23" << 2;
+
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 1:'1' -> 11.23")
+    << options.last() << 1 << int(Qt::Key_1) << "11.23" << 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 1:'del' -> 123")
+    << options.last() << 1 << int(Qt::Key_Delete) << "123" << 0;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 1:'backspace' -> .23")
+    << options.last() << 1 << int(Qt::Key_Backspace) << ".23" << 2;
+
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 2:'1' -> 1.13")
+    << options.last() << 2 << int(Qt::Key_1) << "1.13" << 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 2:'del' -> 1.3")
+    << options.last() << 2 << int(Qt::Key_Delete) << "1.3" << 1;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 2:'backspace' -> 123")
+    << options.last() << 2 << int(Qt::Key_Backspace) << "123" << 0;
+
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 3:'1' -> 1.21")
+    << options.last() << 3 << int(Qt::Key_1) << "1.21" << 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 3:'del' -> 1.2")
+    << options.last() << 3 << int(Qt::Key_Delete) << "1.2" << 1;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 3:'backspace' -> 1.3")
+    << options.last() << 3 << int(Qt::Key_Backspace) << "1.3" << 1;
+
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 4:'1' -> 1.231")
+    << options.last() << 4 << int(Qt::Key_1) << "1.231" << 3;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 4:'del' -> 1.23")
+    << options.last() << 4 << int(Qt::Key_Delete) << "1.23" << 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 4:'backspace' -> 1.23")
+    << options.last() << 4 << int(Qt::Key_Backspace) << "1.2" << 1;
+
+  // ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals
+  options << (ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals);
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 0:'1' -> 11.23")
+    << options.last() << 0 << int(Qt::Key_1) << "11.23"<< 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 0:'del' -> .23")
+    << options.last() << 0 << int(Qt::Key_Delete) << ".23" << 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 0:'backspace' -> 1.23")
+    << options.last() << 0 << int(Qt::Key_Backspace) << "1.23" << 2;
+
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 1:'1' -> 11.23")
+    << options.last() << 1 << int(Qt::Key_1) << "11.23" << 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 1:'del' -> 123")
+    << options.last() << 1 << int(Qt::Key_Delete) << "123" << 0;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 1:'backspace' -> .23")
+    << options.last() << 1 << int(Qt::Key_Backspace) << ".23" << 2;
+
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 2:'1' -> 1.123")
+    << options.last() << 2 << int(Qt::Key_1) << "1.123" << 3;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 2:'del' -> 1.3")
+    << options.last() << 2 << int(Qt::Key_Delete) << "1.3" << 1;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 2:'backspace' -> 123")
+    << options.last() << 2 << int(Qt::Key_Backspace) << "123" << 0;
+
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 3:'1' -> 1.213")
+    << options.last() << 3 << int(Qt::Key_1) << "1.213" << 3;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 3:'del' -> 1.2")
+    << options.last() << 3 << int(Qt::Key_Delete) << "1.2" << 1;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 3:'backspace' -> 1.3")
+    << options.last() << 3 << int(Qt::Key_Backspace) << "1.3" << 1;
+
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 4:'1' -> 1.231")
+    << options.last() << 4 << int(Qt::Key_1) << "1.231" << 3;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 4:'del' -> 1.23")
+    << options.last() << 4 << int(Qt::Key_Delete) << "1.23" << 2;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 4:'backspace' -> 1.23")
+    << options.last() << 4 << int(Qt::Key_Backspace) << "1.2" << 1;
 
   foreach(int option, options)
     {
     // bad keys are always rejected
     for (int i = 0; i < 5; ++i)
       {
-      QTest::newRow(QString("%1 %2:'a' -> 1.00").arg(option).arg(i).toLatin1())
-        << option << i << int(Qt::Key_A) << "1.00" << 2;
+      QTest::newRow(QString("%1 %2:'a' -> 1.23").arg(option).arg(i).toLatin1())
+        << option << i << int(Qt::Key_A) << "1.23" << 2;
       }
     // sign keys are only for the first digit
-    QTest::newRow(QString("%1 0:'+' -> 1.00").arg(option).toLatin1())
-      << option << 0 << int(Qt::Key_Plus) << "+1.00" << 2;
-    QTest::newRow(QString("%1 0:'-' -> -1.00").arg(option).toLatin1())
-      << option << 0 << int(Qt::Key_Minus) << "-1.00" << 2;
+    QTest::newRow(QString("%1 0:'+' -> 1.23").arg(option).toLatin1())
+      << option << 0 << int(Qt::Key_Plus) << "+1.23" << 2;
+    QTest::newRow(QString("%1 0:'-' -> -1.23").arg(option).toLatin1())
+      << option << 0 << int(Qt::Key_Minus) << "-1.23" << 2;
     for (int i = 1; i < 5; ++i)
       {
-      QTest::newRow(QString("%1 %2:'+' -> 1.00").arg(option).arg(i).toLatin1())
-        << option << i << int(Qt::Key_Plus) << "1.00" << 2;
-      QTest::newRow(QString("%1 %2:'-' -> 1.00").arg(option).arg(i).toLatin1())
-        << option << i << int(Qt::Key_Minus) << "1.00" << 2;
+      QTest::newRow(QString("%1 %2:'+' -> 1.23").arg(option).arg(i).toLatin1())
+        << option << i << int(Qt::Key_Plus) << "1.23" << 2;
+      QTest::newRow(QString("%1 %2:'-' -> 1.23").arg(option).arg(i).toLatin1())
+        << option << i << int(Qt::Key_Minus) << "1.23" << 2;
       }
     }
 }
+// ----------------------------------------------------------------------------
+void ctkDoubleSpinBoxTester::testPrefix()
+{
+  ctkDoubleSpinBox spinBox;
+  spinBox.setPrefix("A: ");
+  spinBox.setDecimalsOption( ctkDoubleSpinBox::FixedDecimals );
+
+  QFETCH(int, cursorPosition);
+  QFETCH(int, key);
+
+  spinBox.lineEdit()->setCursorPosition(cursorPosition);
+  QTest::keyClick(spinBox.lineEdit(), static_cast<Qt::Key>(key));
+
+  //spinBox.show();
+  //QTest::qWaitForWindowShown(&spinBox);
+  //qApp->exec();
+
+  QFETCH(double, expectedValue);
+  QFETCH(QString, expectedText);
+  QFETCH(int, expectedCursorPosition);
+
+  QCOMPARE(spinBox.text(), expectedText);
+  QCOMPARE(spinBox.value(), expectedValue);
+  QCOMPARE(spinBox.decimals(), 2);
+  QCOMPARE(spinBox.lineEdit()->cursorPosition(), expectedCursorPosition);
+}
+
+// ----------------------------------------------------------------------------
+void ctkDoubleSpinBoxTester::testPrefix_data()
+{
+  QTest::addColumn<int>("cursorPosition");
+  QTest::addColumn<int>("key");
+  QTest::addColumn<QString>("expectedText");
+  QTest::addColumn<double>("expectedValue");
+  QTest::addColumn<int>("expectedCursorPosition");
+
+  QTest::newRow("0:'1' -> 0.00") << 0 << int(Qt::Key_1) << "A: 0.00"<< 0.00 << 0;
+  QTest::newRow("1:'1' -> 10.00") << 1 << int(Qt::Key_1) << "A: 10.00"<< 10.00 << 4;
+  QTest::newRow("2:'1' -> 10.00") << 2 << int(Qt::Key_1) << "A: 10.00"<< 10.00 << 4;
+  QTest::newRow("3:'1' -> 10.00") << 3 << int(Qt::Key_1) << "A: 10.00"<< 10.00 << 4;
+  QTest::newRow("4:'1' -> 01.00") << 4 << int(Qt::Key_1) << "A: 01.00"<< 1.00 << 5;
+}
 
 // ----------------------------------------------------------------------------
 void ctkDoubleSpinBoxTester::testDecimalsByValue()
@@ -250,9 +318,10 @@ void ctkDoubleSpinBoxTester::testDecimalsByValue()
   ctkDoubleSpinBox spinBox;
   spinBox.setMinimum(-100.);
   spinBox.setMaximum(100.);
-  spinBox.setValue(1.);
+  spinBox.setValue(1.23);
   spinBox.setDecimalsOption( ctkDoubleSpinBox::DecimalsByValue );
   QSignalSpy spy(&spinBox, SIGNAL(decimalsChanged(int)));
+  const int oldDecimals = spinBox.decimals();
 
   QFETCH(double, value);
   spinBox.setValue(value);
@@ -263,7 +332,7 @@ void ctkDoubleSpinBoxTester::testDecimalsByValue()
   QCOMPARE(spinBox.text(), expectedText);
   QCOMPARE(spinBox.value(), value);
   QCOMPARE(spinBox.decimals(), expectedDecimals);
-  QCOMPARE(spy.count(), spinBox.decimals() != 2 ? 1 : 0);
+  QCOMPARE(spy.count(), spinBox.decimals() != oldDecimals ? 1 : 0);
 }
 
 // ----------------------------------------------------------------------------
@@ -273,7 +342,7 @@ void ctkDoubleSpinBoxTester::testDecimalsByValue_data()
   QTest::addColumn<QString>("expectedText");
   QTest::addColumn<int>("expectedDecimals");
 
-  QTest::newRow("ctkDoubleSpinBox::DecimalsByValue 0.00") << 0.00 << "0."<< 0;
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByValue 0") << 0. << "0"<< 0;
   QTest::newRow("ctkDoubleSpinBox::DecimalsByValue 0.1") << 0.1 << "0.1" << 1;
   QTest::newRow("ctkDoubleSpinBox::DecimalsByValue 0.02") << 0.02 << "0.02" << 2;
   QTest::newRow("ctkDoubleSpinBox::DecimalsByValue 10.003") << 10.003 << "10.003" << 3;
@@ -285,6 +354,31 @@ void ctkDoubleSpinBoxTester::testDecimalsByValue_data()
 }
 
 // ----------------------------------------------------------------------------
+void ctkDoubleSpinBoxTester::testDecimalPointAlwaysVisible()
+{
+  ctkDoubleSpinBox spinBox;
+  spinBox.setDecimals(0);
+  spinBox.setDecimalsOption( ctkDoubleSpinBox::DecimalPointAlwaysVisible );
+
+  QFETCH(double, value);
+  spinBox.setValue(value);
+
+  QFETCH(QString, expectedText);
+  QCOMPARE(spinBox.text(), expectedText);
+}
+
+// ----------------------------------------------------------------------------
+void ctkDoubleSpinBoxTester::testDecimalPointAlwaysVisible_data()
+{
+  QTest::addColumn<double>("value");
+  QTest::addColumn<QString>("expectedText");
+
+  QTest::newRow("ctkDoubleSpinBox::DecimalPointAlwaysVisible 0") << 0. << "0.";
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByValue 2") << 2. << "2.";
+  QTest::newRow("ctkDoubleSpinBox::DecimalsByValue 1.01") << 1.01 << "1.";
+}
+
+// ----------------------------------------------------------------------------
 CTK_TEST_MAIN(ctkDoubleSpinBoxTest)
 #include "moc_ctkDoubleSpinBoxTest.cpp"
 

+ 26 - 0
Libs/Widgets/ctkCoordinatesWidget.cpp

@@ -33,6 +33,8 @@
 ctkCoordinatesWidget::ctkCoordinatesWidget(QWidget* _parent) :QWidget(_parent)
 {
   this->Decimals = 3;
+  ctkDoubleSpinBox temp;
+  this->DecimalsOption = temp.decimalsOption();
   this->SingleStep = 1.;
   this->Minimum = -100000.;
   this->Maximum = 100000.;
@@ -58,6 +60,7 @@ void ctkCoordinatesWidget::addSpinBox()
 {
   ctkDoubleSpinBox* spinBox = new ctkDoubleSpinBox(this);
   spinBox->setDecimals(this->Decimals);
+  spinBox->setDecimalsOption(this->DecimalsOption);
   spinBox->setSingleStep(this->SingleStep);
   spinBox->setMinimum(this->Minimum);
   spinBox->setMaximum(this->Maximum);
@@ -204,6 +207,29 @@ int ctkCoordinatesWidget::decimals() const
   return this->Decimals;
 }
 
+// --------------------------------------------------------------------------
+ctkDoubleSpinBox::DecimalsOptions ctkCoordinatesWidget::decimalsOption()const
+{
+  return this->DecimalsOption;
+}
+
+// --------------------------------------------------------------------------
+void ctkCoordinatesWidget
+::setDecimalsOption(ctkDoubleSpinBox::DecimalsOptions newDecimalsOption)
+{
+  for (int i = 0; this->layout()->itemAt(i); ++i)
+    {
+    QLayoutItem* item = this->layout()->itemAt(i);
+    ctkDoubleSpinBox* spinBox = item ? qobject_cast<ctkDoubleSpinBox*>(
+      item->widget()) : 0;
+    if (spinBox)
+      {
+      spinBox->setDecimalsOption(newDecimalsOption);
+      }
+    }
+  this->DecimalsOption = newDecimalsOption;
+}
+
 //------------------------------------------------------------------------------
 void ctkCoordinatesWidget::setSingleStep(double step)
 {

+ 13 - 0
Libs/Widgets/ctkCoordinatesWidget.h

@@ -25,6 +25,7 @@
 #include <QWidget>
 
 // CTK includes
+#include "ctkDoubleSpinBox.h"
 #include "ctkWidgetsExport.h"
 
 /// \ingroup Widgets
@@ -44,6 +45,10 @@ class CTK_WIDGETS_EXPORT ctkCoordinatesWidget : public QWidget
   Q_PROPERTY(bool normalized READ isNormalized WRITE setNormalized)
 
   Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
+  /// This property provides more controls over the decimals.
+  /// \sa ctkDoubleSpinBox::DecimalsOptions, decimals
+  Q_PROPERTY(ctkDoubleSpinBox::DecimalsOptions decimalsOption READ decimalsOption WRITE setDecimalsOption)
+
   Q_PROPERTY(double singleStep  READ singleStep WRITE setSingleStep STORED false)
   Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
   Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
@@ -63,6 +68,13 @@ public:
   /// The default number of decimals is 3.
   int decimals() const;
 
+  /// Return the decimalsOption property value
+  /// \sa decimalsOption
+  ctkDoubleSpinBox::DecimalsOptions decimalsOption()const;
+  /// Set the decimalsOption property value.
+  /// \sa decimalsOption
+  void setDecimalsOption(ctkDoubleSpinBox::DecimalsOptions option);
+
   /// Set/Get the single step of each coordinate spin box
   /// The default single step is 1.
   void setSingleStep(double step);
@@ -130,6 +142,7 @@ protected:
   static double squaredNorm(double* coordinates, int dimension);
 
   int     Decimals;
+  ctkDoubleSpinBox::DecimalsOptions DecimalsOption;
   double  SingleStep;
   double  Minimum;
   double  Maximum;

+ 26 - 12
Libs/Widgets/ctkDoubleSpinBox.cpp

@@ -127,13 +127,11 @@ QString ctkQDoubleSpinBox::textFromValue(double value) const
     text = "0";
     }
   // If there is no decimal, it does not mean there won't be any.
-  if (text.indexOf(this->locale().decimalPoint()) == -1 &&
-      ((d->DOption & ctkDoubleSpinBox::DecimalsByKey) ||
-       (d->DOption & ctkDoubleSpinBox::DecimalsByValue)))
+  if (d->DOption & ctkDoubleSpinBox::DecimalPointAlwaysVisible &&
+      text.indexOf(this->locale().decimalPoint()) == -1)
     {
     text += this->locale().decimalPoint();
     }
-  //qDebug() << "textFromValue" << text;
   return text;
 }
 
@@ -172,7 +170,9 @@ ctkDoubleSpinBoxPrivate::ctkDoubleSpinBoxPrivate(ctkDoubleSpinBox& object)
   this->SpinBox = 0;
   this->Mode = ctkDoubleSpinBox::SetIfDifferent;
   this->DefaultDecimals = 2;
-  this->DOption = ctkDoubleSpinBox::DecimalsByShortcuts;
+  // InsertDecimals is not a great default, but it is QDoubleSpinBox's default.
+  this->DOption = ctkDoubleSpinBox::DecimalsByShortcuts
+    | ctkDoubleSpinBox::InsertDecimals;
   this->InvertedControls = false;
 }
 
@@ -321,7 +321,10 @@ double ctkDoubleSpinBoxPrivate
   const double max = q->maximum();
   const double min = q->minimum();
 
-  QString text = this->stripped(input, &pos);
+  int posInValue = pos;
+  QString text = this->stripped(input, &posInValue);
+  // posInValue can change, track the offset.
+  const int oldPosInValue = posInValue;
   //qDebug() << "text: " << text << pos;
   state = QValidator::Acceptable;
   decimals = 0;
@@ -376,7 +379,7 @@ double ctkDoubleSpinBoxPrivate
     // move the cursor pos to the right then
     if (dec + 1 < text.size() &&
         text.at(dec + 1) == q->locale().decimalPoint() &&
-        pos == dec + 1)
+        posInValue == dec + 1)
       {
       text.remove(dec + 1, 1);
       value = q->locale().toDouble(text, &ok);
@@ -390,12 +393,21 @@ double ctkDoubleSpinBoxPrivate
       if (decimals > q->decimals())
         {
         // With ReplaceDecimals on, key strokes replace decimal digits
-        if (this->DOption & ctkDoubleSpinBox::ReplaceDecimals &&
-            pos > dec && pos < text.size())
+        if (posInValue > dec && posInValue < text.size())
           {
-          text.remove(pos, decimals - q->decimals());
-          decimals = q->decimals();
-          value = q->locale().toDouble(text, &ok);
+          const int extraDecimals = decimals - q->decimals();
+          if (this->DOption & ctkDoubleSpinBox::ReplaceDecimals)
+            {
+            text.remove(posInValue, extraDecimals);
+            decimals = q->decimals();
+            value = q->locale().toDouble(text, &ok);
+            }
+          else if (!(this->DOption & ctkDoubleSpinBox::InsertDecimals))
+            {
+            text.remove(text.size() - extraDecimals, extraDecimals);
+            decimals = q->decimals();
+            value = q->locale().toDouble(text, &ok);
+            }
           }
         }
       // When DecimalsByKey is set, it is possible to extend the number of decimals
@@ -436,6 +448,7 @@ double ctkDoubleSpinBoxPrivate
     value = max > 0 ? min : max;
     }
 
+  pos += posInValue - oldPosInValue;
   input = q->prefix() + text + q->suffix();
   this->CachedText = input;
   this->CachedState = state;
@@ -969,6 +982,7 @@ void ctkDoubleSpinBox::setDecimalsOption(ctkDoubleSpinBox::DecimalsOptions optio
     }
 
   d->DOption = option;
+  this->setValueAlways(this->value());
 }
 
 //----------------------------------------------------------------------------

+ 20 - 6
Libs/Widgets/ctkDoubleSpinBox.h

@@ -64,6 +64,8 @@ class CTK_WIDGETS_EXPORT ctkDoubleSpinBox : public QWidget
   /// \sa decimalsOption, decimals(), setDecimals(), decimalsChanged
   Q_PROPERTY(int decimals READ decimals WRITE setDecimals NOTIFY decimalsChanged)
   /// This property provides more controls over the decimals.
+  /// The default (DecimalsByShortcuts|InsertDecimals) behaves as a QDoubleSpinbox
+  /// with an explicit control of decimals via shortcuts.
   /// \sa DecimalsOptions, decimals
   Q_PROPERTY(DecimalsOptions decimalsOption READ decimalsOption WRITE setDecimalsOption)
   Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
@@ -114,20 +116,32 @@ public:
     DecimalsByShortcuts = 0x001,
     /// Allow the number of decimals to be controlled by adding/removing digits
     /// with key strokes.
+    /// \sa InsertDecimals, ReplaceDecimals
     DecimalsByKey = 0x002,
     /// Allow the number of decimals to be controlled by the value set by
     /// setValue().
     DecimalsByValue = 0x004,
-    /// This flag controls whether intermediate decimals are replaced or added
-    /// with key strokes. This is similar to NumLock but just for decimal
-    /// digits.
-    ReplaceDecimals = 0x008,
+    /// This flag controls whether inserted intermediate decimals increase the
+    /// number of decimals (on) or not (off).
+    /// It is incompatible with the ReplaceDecimals flag.
+    /// \sa DecimalsByKey.
+    InsertDecimals = 0x008,
+    /// This flag controls whether inserted intermediate decimals replace the
+    /// existing decimals (on) or not (off). This is similar to Insert but just
+    /// for decimal digits.
+    /// It is incompatible with the InsertDecimals flag.
+    /// \sa DecimalsByKey, InsertDecimals
+    ReplaceDecimals = 0x010,
     /// Use the "decimals" property as a maximum limit for the number of
     /// decimals.
-    DecimalsAsMax = 0x010,
+    DecimalsAsMax = 0x020,
     /// Use the "decimals" property as a minimum limit for the number of
     /// decimals.
-    DecimalsAsMin = 0x020
+    DecimalsAsMin = 0x040,
+    /// Even if the number of decimals is 0, it enforces the decimal to be visible
+    /// (e.g. "0." )
+    /// \sa decimals
+    DecimalPointAlwaysVisible = 0x080
     };
   Q_DECLARE_FLAGS(DecimalsOptions, DecimalsOption)
 

+ 17 - 0
Libs/Widgets/ctkMatrixWidget.cpp

@@ -55,6 +55,7 @@ namespace
       this->setMinimum(matrixWidget->minimum());
       this->setMaximum(matrixWidget->maximum());
       this->setDecimals(matrixWidget->decimals());
+      this->setDecimalsOption(matrixWidget->decimalsOption());
       this->setSingleStep(matrixWidget->singleStep());
 
       this->connect(this, SIGNAL(decimalsChanged(int)),
@@ -83,6 +84,7 @@ public:
   double Minimum;
   double Maximum;
   int    Decimals;
+  ctkDoubleSpinBox::DecimalsOptions DecimalsOption;
   double SingleStep;
 };
 
@@ -349,6 +351,21 @@ void ctkMatrixWidget::setDecimals(int decimals)
 }
 
 // --------------------------------------------------------------------------
+ctkDoubleSpinBox::DecimalsOptions ctkMatrixWidget::decimalsOption()const
+{
+  Q_D(const ctkMatrixWidget);
+  return d->DecimalsOption;
+}
+
+// --------------------------------------------------------------------------
+void ctkMatrixWidget
+::setDecimalsOption(ctkDoubleSpinBox::DecimalsOptions newDecimalsOption)
+{
+  Q_D(ctkMatrixWidget);
+  d->DecimalsOption = newDecimalsOption;
+}
+
+// --------------------------------------------------------------------------
 QSize ctkMatrixWidget::minimumSizeHint() const
 {
   Q_D(const ctkMatrixWidget);

+ 11 - 0
Libs/Widgets/ctkMatrixWidget.h

@@ -26,6 +26,7 @@
 #include <QWidget>
 
 /// CTK includes
+#include "ctkDoubleSpinBox.h"
 #include "ctkPimpl.h"
 #include "ctkWidgetsExport.h"
 
@@ -43,6 +44,9 @@ class CTK_WIDGETS_EXPORT ctkMatrixWidget: public QWidget
   Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
   Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
   Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
+  /// This property provides more controls over the decimals.
+  /// \sa ctkDoubleSpinBox::DecimalsOptions, decimals
+  Q_PROPERTY(ctkDoubleSpinBox::DecimalsOptions decimalsOption READ decimalsOption WRITE setDecimalsOption)
   Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
   Q_PROPERTY(QVector<double> values READ values WRITE setValues)
 
@@ -123,6 +127,13 @@ public:
   /// used to adjust the value of a matrix element.
   int decimals()const;
 
+  /// Return the decimalsOption property value
+  /// \sa decimalsOption
+  ctkDoubleSpinBox::DecimalsOptions decimalsOption()const;
+  /// Set the decimalsOption property value.
+  /// \sa decimalsOption
+  void setDecimalsOption(ctkDoubleSpinBox::DecimalsOptions option);
+
   ///
   /// Reimplemented from QAbstractScrollArea
   virtual QSize minimumSizeHint () const;