From 9e25e6de24bbf4a35fcf57f43e8b54e40181c5fa Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 19 Nov 2019 15:46:11 +0200 Subject: [PATCH] Introducing vRound function. Shortcut to round double to X points decimal. --HG-- branch : develop --- src/app/valentina/dialogs/vabstractlayoutdialog.cpp | 9 +++++---- src/libs/vmisc/vmath.h | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/app/valentina/dialogs/vabstractlayoutdialog.cpp b/src/app/valentina/dialogs/vabstractlayoutdialog.cpp index 30bed4dbc..a93afa42d 100644 --- a/src/app/valentina/dialogs/vabstractlayoutdialog.cpp +++ b/src/app/valentina/dialogs/vabstractlayoutdialog.cpp @@ -28,6 +28,7 @@ #include "vabstractlayoutdialog.h" #include "../core/vapplication.h" +#include "../vmisc/vmath.h" //must be the same order as PaperSizeTemplate constants const VAbstractLayoutDialog::FormatsVector VAbstractLayoutDialog::pageFormatNames @@ -172,12 +173,12 @@ QSizeF VAbstractLayoutDialog::RoundTemplateSize(qreal width, qreal height, Unit case Unit::Cm: case Unit::Mm: case Unit::Px: - w = qRound(width * 100.0) / 100.0; - h = qRound(height * 100.0) / 100.0; + w = vRound(width, 2); + h = vRound(height, 2); return QSizeF(w, h); case Unit::Inch: - w = qRound(width * 100000.0) / 100000.0; - h = qRound(height * 100000.0) / 100000.0; + w = vRound(width, 5); + h = vRound(height, 5); return QSizeF(w, h); default: break; diff --git a/src/libs/vmisc/vmath.h b/src/libs/vmisc/vmath.h index 9fc1424cd..e7f73c1ef 100644 --- a/src/libs/vmisc/vmath.h +++ b/src/libs/vmisc/vmath.h @@ -51,5 +51,9 @@ #define M_EULER (0.57721566490153286060) #endif +template +Q_DECL_CONSTEXPR inline T vRound(T d, int p) +{ return p > 0 ? qRound(d * (p * 10.0)) / (p * 10.0) : qRound(d); } + #endif // VMATH_H