# HG changeset patch # User Teemu Piippo # Date 1525956519 -10800 # Node ID 6393b6020c622a17de1b2b146f9d215da61b46b7 # Parent c59dac18b06bb6ce7a1254423b1d2ef0f427b60a added a doublespinbox variant that uses "." as the decimal point and omits trailing zeros diff -r c59dac18b06b -r 6393b6020c62 CMakeLists.txt --- a/CMakeLists.txt Thu May 10 14:57:23 2018 +0300 +++ b/CMakeLists.txt Thu May 10 15:48:39 2018 +0300 @@ -93,6 +93,7 @@ src/types/boundingbox.cpp src/types/matrix.cpp src/types/vertex.cpp + src/widgets/doublespinbox.cpp src/widgets/headeredit.cpp src/widgets/vertexobjecteditor.cpp ) @@ -170,6 +171,7 @@ src/types/library.h src/types/matrix.h src/types/vertex.h + src/widgets/doublespinbox.h src/widgets/headeredit.h src/widgets/vertexobjecteditor.h ) diff -r c59dac18b06b -r 6393b6020c62 src/dialogs/subfilereferenceeditor.cpp --- a/src/dialogs/subfilereferenceeditor.cpp Thu May 10 14:57:23 2018 +0300 +++ b/src/dialogs/subfilereferenceeditor.cpp Thu May 10 15:48:39 2018 +0300 @@ -185,7 +185,7 @@ { for (int row : {0, 1, 2}) { - double cellValue = abs(this->matrixCell(row, column)->value()); + double cellValue = this->matrixCell(row, column)->value(); cellValue *= newScaling / oldScaling; QDoubleSpinBox* cellWidget = this->matrixCell(row, column); cellWidget->blockSignals(true); diff -r c59dac18b06b -r 6393b6020c62 src/dialogs/subfilereferenceeditor.ui --- a/src/dialogs/subfilereferenceeditor.ui Thu May 10 14:57:23 2018 +0300 +++ b/src/dialogs/subfilereferenceeditor.ui Thu May 10 15:48:39 2018 +0300 @@ -6,7 +6,7 @@ 0 0 - 625 + 699 644 @@ -70,7 +70,10 @@ - + + + 𝑥 = + 5 @@ -83,7 +86,10 @@ - + + + 𝑦 = + 5 @@ -96,7 +102,10 @@ - + + + 𝑧 = + 5 @@ -127,7 +136,7 @@ - + 5 @@ -140,7 +149,7 @@ - + 5 @@ -153,7 +162,7 @@ - + 5 @@ -166,7 +175,7 @@ - + 5 @@ -179,7 +188,7 @@ - + 5 @@ -192,7 +201,7 @@ - + 5 @@ -205,7 +214,7 @@ - + 5 @@ -218,7 +227,7 @@ - + 5 @@ -231,7 +240,7 @@ - + 5 @@ -255,7 +264,7 @@ - + 𝑥 × @@ -271,7 +280,7 @@ - + 𝑦 × @@ -287,7 +296,7 @@ - + 𝑧 × @@ -325,6 +334,13 @@ + + + DoubleSpinBox + QDoubleSpinBox +
widgets/doublespinbox.h
+
+
primitivesTreeView referenceName diff -r c59dac18b06b -r 6393b6020c62 src/widgets/doublespinbox.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/widgets/doublespinbox.cpp Thu May 10 15:48:39 2018 +0300 @@ -0,0 +1,59 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 - 2018 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "doublespinbox.h" + +/* + * Constructs a new double spin box. The locale is fixed to system default "C". + */ +DoubleSpinBox::DoubleSpinBox(QWidget* parent) : + QDoubleSpinBox {parent} +{ + this->setLocale({"C"}); +} + +/* + * Reimplementation of QDoubleSpinBox::textFromValue to remove trailing zeros. + */ +QString DoubleSpinBox::textFromValue(double value) const +{ + QString result = QDoubleSpinBox::textFromValue(value); + + if (result.contains(".")) + { + // Remove trailing zeros + while (result.endsWith("0")) + result.chop(1); + + // Remove trailing decimal point if we just removed all the zeros. + if (result.endsWith(".")) + result.chop(1); + } + + return result; +} + +/* + * Reimplementation of QDoubleSpinBox::validate to fix the decimal point if the locale-specific + * decimal point was used. + */ +QValidator::State DoubleSpinBox::validate(QString& input, int& pos) const +{ + input.replace(QLocale().decimalPoint(), this->locale().decimalPoint()); + return QDoubleSpinBox::validate(input, pos); +} diff -r c59dac18b06b -r 6393b6020c62 src/widgets/doublespinbox.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/widgets/doublespinbox.h Thu May 10 15:48:39 2018 +0300 @@ -0,0 +1,35 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 - 2018 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include + +/* + * A version of QDoubleSpinBox that consistently uses "." as the decimal separator + * and does not display trailing zeros. + */ +class DoubleSpinBox : public QDoubleSpinBox +{ +public: + DoubleSpinBox(QWidget* parent = nullptr); + +protected: + QString textFromValue(double value) const override; + QValidator::State validate(QString& input, int& pos) const override; +}; +