From fb3549fc47b19de2956cd2dda07ef67ec529cf3e Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Tue, 14 Sep 2021 11:45:24 +0200 Subject: Introduce QDoubleValidator::fixup() The provided implementation tries to fix positions for the group separator. In case of scientific notation it can also converts the value to normalized form. It uses QLocale::FloatingPointShortest internally to convert the double value back to string, so the number of decimals may change after calling this method. Change-Id: I963bc5f97b653e2bb912f4b95b09a4d1ee201e7f Reviewed-by: Edward Welbourne --- src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/gui/doc/snippets/code') diff --git a/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp b/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp index 51fc3a6e14..7503c12afb 100644 --- a/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp +++ b/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp @@ -57,6 +57,7 @@ struct Wrapper : public QWidget { void wrapper0(); void wrapper1(); void wrapper2(); + void wrapper3(); }; void Wrapper::wrapper0() { @@ -164,4 +165,22 @@ s = "readm"; v.validate(s, pos); // Returns Intermediate } // Wrapper::wrapper2 +void Wrapper::wrapper3() +{ +//! [7] +QString input = "0.98765e2"; +QDoubleValidator val; +val.setLocale(QLocale::C); +val.setNotation(QDoubleValidator::ScientificNotation); +val.fixup(input); // input == "9.8765e+01" +//! [7] +//! [8] +input = "-1234.6789"; +val.setDecimals(2); +val.setLocale(QLocale::C); +val.setNotation(QDoubleValidator::StandardNotation); +val.fixup(input); // input == "-1234.68" +//! [8] +} // Wrapper::wrapper3 + } // src_gui_util_qvalidator -- cgit v1.2.1