For avoiding losing precision use double everywhere.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-11-05 13:07:51 +02:00
parent 6b54c5bb7d
commit 2e49d1437a
7 changed files with 73 additions and 67 deletions

View File

@ -82,17 +82,15 @@ VCommandLine::VCommandLine() : parser(), optionsUsed(InitOptionsUsed()), isGuiEn
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VCommandLine::Lo2Px(const QString &src, const DialogLayoutSettings &converter) qreal VCommandLine::Lo2Px(const QString &src, const DialogLayoutSettings &converter)
{ {
//that is dirty-dirty hack ...eventually number is converted float <--> int 3 or 4 times including inside dialog ... return converter.LayoutToPixels(src.toDouble());
// that will loose precision for sure
return converter.LayoutToPixels(src.toFloat());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VCommandLine::Pg2Px(const QString& src, const DialogLayoutSettings& converter) qreal VCommandLine::Pg2Px(const QString& src, const DialogLayoutSettings& converter)
{ {
return converter.PageToPixels(src.toFloat()); return converter.PageToPixels(src.toDouble());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -320,12 +318,12 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
if (parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH))) if (parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH)))
{ {
diag.SetShift(static_cast<quint32>(Lo2Px(parser.value(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH)), diag))); diag.SetShift(Lo2Px(parser.value(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH)), diag));
} }
if (parser.isSet(*optionsUsed.value(LONG_OPTION_GAPWIDTH))) if (parser.isSet(*optionsUsed.value(LONG_OPTION_GAPWIDTH)))
{ {
diag.SetLayoutWidth(static_cast<quint32>(Lo2Px(parser.value(*optionsUsed.value(LONG_OPTION_GAPWIDTH)), diag))); diag.SetLayoutWidth(Lo2Px(parser.value(*optionsUsed.value(LONG_OPTION_GAPWIDTH)), diag));
} }
diag.SetAutoCrop(parser.isSet(*optionsUsed.value(LONG_OPTION_CROP))); diag.SetAutoCrop(parser.isSet(*optionsUsed.value(LONG_OPTION_CROP)));

View File

@ -85,9 +85,9 @@ private:
bool isGuiEnabled; bool isGuiEnabled;
friend class VApplication; friend class VApplication;
static int Lo2Px(const QString& src, const DialogLayoutSettings& converter); static qreal Lo2Px(const QString& src, const DialogLayoutSettings& converter);
static int Pg2Px(const QString& src, const DialogLayoutSettings& converter); static qreal Pg2Px(const QString& src, const DialogLayoutSettings& converter);
static QMap<QString, QCommandLineOption *> InitOptionsUsed(); static QMap<QString, QCommandLineOption *> InitOptionsUsed();
}; };

View File

@ -112,49 +112,49 @@ DialogLayoutSettings::~DialogLayoutSettings()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int DialogLayoutSettings::GetPaperHeight() const qreal DialogLayoutSettings::GetPaperHeight() const
{ {
return qFloor(UnitConvertor(ui->doubleSpinBoxPaperHeight->value(), oldPaperUnit, Unit::Px)); return UnitConvertor(ui->doubleSpinBoxPaperHeight->value(), oldPaperUnit, Unit::Px);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetPaperHeight(int value) void DialogLayoutSettings::SetPaperHeight(qreal value)
{ {
ui->doubleSpinBoxPaperHeight->setValue(UnitConvertor(value, Unit::Px, PaperUnit())); ui->doubleSpinBoxPaperHeight->setValue(UnitConvertor(value, Unit::Px, PaperUnit()));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int DialogLayoutSettings::GetPaperWidth() const qreal DialogLayoutSettings::GetPaperWidth() const
{ {
return qFloor(UnitConvertor(ui->doubleSpinBoxPaperWidth->value(), oldPaperUnit, Unit::Px)); return UnitConvertor(ui->doubleSpinBoxPaperWidth->value(), oldPaperUnit, Unit::Px);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetPaperWidth(int value) void DialogLayoutSettings::SetPaperWidth(qreal value)
{ {
ui->doubleSpinBoxPaperWidth->setValue(UnitConvertor(value, Unit::Px, PaperUnit())); ui->doubleSpinBoxPaperWidth->setValue(UnitConvertor(value, Unit::Px, PaperUnit()));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
quint32 DialogLayoutSettings::GetShift() const qreal DialogLayoutSettings::GetShift() const
{ {
return static_cast<quint32>(qFloor(UnitConvertor(ui->doubleSpinBoxShift->value(), oldLayoutUnit, Unit::Px))); return UnitConvertor(ui->doubleSpinBoxShift->value(), oldLayoutUnit, Unit::Px);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetShift(quint32 value) void DialogLayoutSettings::SetShift(qreal value)
{ {
ui->doubleSpinBoxShift->setValue(UnitConvertor(value, Unit::Px, LayoutUnit())); ui->doubleSpinBoxShift->setValue(UnitConvertor(value, Unit::Px, LayoutUnit()));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
quint32 DialogLayoutSettings::GetLayoutWidth() const qreal DialogLayoutSettings::GetLayoutWidth() const
{ {
return static_cast<quint32>(qFloor(UnitConvertor(ui->doubleSpinBoxLayoutWidth->value(), oldLayoutUnit, Unit::Px))); return UnitConvertor(ui->doubleSpinBoxLayoutWidth->value(), oldLayoutUnit, Unit::Px);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetLayoutWidth(quint32 value) void DialogLayoutSettings::SetLayoutWidth(qreal value)
{ {
ui->doubleSpinBoxLayoutWidth->setValue(UnitConvertor(value, Unit::Px, LayoutUnit())); ui->doubleSpinBoxLayoutWidth->setValue(UnitConvertor(value, Unit::Px, LayoutUnit()));
} }
@ -282,11 +282,15 @@ void DialogLayoutSettings::ConvertPaperSize()
ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, paperUnit)); ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, paperUnit));
ui->doubleSpinBoxPaperHeight->setMaximum(FromPixel(QIMAGE_MAX, paperUnit)); ui->doubleSpinBoxPaperHeight->setMaximum(FromPixel(QIMAGE_MAX, paperUnit));
ui->doubleSpinBoxPaperWidth->setValue(UnitConvertor(width, oldPaperUnit, paperUnit)); const qreal newWidth = UnitConvertor(width, oldPaperUnit, paperUnit);
ui->doubleSpinBoxPaperHeight->setValue(UnitConvertor(height, oldPaperUnit, paperUnit)); const qreal newHeight = UnitConvertor(height, oldPaperUnit, paperUnit);
oldPaperUnit = paperUnit; oldPaperUnit = paperUnit;
CorrectPaperDecimals(); CorrectPaperDecimals();
MinimumPaperSize(); MinimumPaperSize();
ui->doubleSpinBoxPaperWidth->setValue(newWidth);
ui->doubleSpinBoxPaperHeight->setValue(newHeight);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -312,15 +316,15 @@ bool DialogLayoutSettings::SelectLayoutUnit(const QString &units)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int DialogLayoutSettings::LayoutToPixels(qreal value) const qreal DialogLayoutSettings::LayoutToPixels(qreal value) const
{ {
return qFloor(UnitConvertor(value, LayoutUnit(), Unit::Px)); return UnitConvertor(value, LayoutUnit(), Unit::Px);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int DialogLayoutSettings::PageToPixels(qreal value) const qreal DialogLayoutSettings::PageToPixels(qreal value) const
{ {
return qFloor(UnitConvertor(value, PaperUnit(), Unit::Px)); return UnitConvertor(value, PaperUnit(), Unit::Px);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -340,11 +344,15 @@ void DialogLayoutSettings::ConvertLayoutSize()
ui->doubleSpinBoxLayoutWidth->setMaximum(FromPixel(QIMAGE_MAX, unit)); ui->doubleSpinBoxLayoutWidth->setMaximum(FromPixel(QIMAGE_MAX, unit));
ui->doubleSpinBoxShift->setMaximum(FromPixel(QIMAGE_MAX, unit)); ui->doubleSpinBoxShift->setMaximum(FromPixel(QIMAGE_MAX, unit));
ui->doubleSpinBoxLayoutWidth->setValue(UnitConvertor(layoutWidth, oldLayoutUnit, unit)); const qreal newLayoutWidth = UnitConvertor(layoutWidth, oldLayoutUnit, unit);
ui->doubleSpinBoxShift->setValue(UnitConvertor(shift, oldLayoutUnit, unit)); const qreal newShift = UnitConvertor(shift, oldLayoutUnit, unit);
oldLayoutUnit = unit; oldLayoutUnit = unit;
CorrectLayoutDecimals(); CorrectLayoutDecimals();
MinimumLayoutSize(); MinimumLayoutSize();
ui->doubleSpinBoxLayoutWidth->setValue(newLayoutWidth);
ui->doubleSpinBoxShift->setValue(newShift);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -404,9 +412,9 @@ void DialogLayoutSettings::DialogAccepted()
SCASSERT(generator != nullptr) SCASSERT(generator != nullptr)
generator->SetLayoutWidth(GetLayoutWidth()); generator->SetLayoutWidth(GetLayoutWidth());
generator->SetCaseType(GetGroup()); generator->SetCaseType(GetGroup());
generator->SetPaperHeight(GetPaperHeight()); generator->SetPaperHeight(qFloor(GetPaperHeight()));
generator->SetPaperWidth(GetPaperWidth()); generator->SetPaperWidth(qFloor(GetPaperWidth()));
generator->SetShift(GetShift()); generator->SetShift(qFloor(GetShift()));
generator->SetRotate(GetRotate()); generator->SetRotate(GetRotate());
generator->SetRotationIncrease(GetIncrease()); generator->SetRotationIncrease(GetIncrease());
generator->SetAutoCrop(GetAutoCrop()); generator->SetAutoCrop(GetAutoCrop());
@ -636,8 +644,8 @@ void DialogLayoutSettings::CorrectPaperDecimals()
ui->doubleSpinBoxPaperHeight->setDecimals(5); ui->doubleSpinBoxPaperHeight->setDecimals(5);
break; break;
case Unit::Px: case Unit::Px:
ui->doubleSpinBoxPaperWidth->setDecimals(0); ui->doubleSpinBoxPaperWidth->setDecimals(2);
ui->doubleSpinBoxPaperHeight->setDecimals(0); ui->doubleSpinBoxPaperHeight->setDecimals(2);
break; break;
default: default:
break; break;
@ -659,8 +667,8 @@ void DialogLayoutSettings::CorrectLayoutDecimals()
ui->doubleSpinBoxShift->setDecimals(5); ui->doubleSpinBoxShift->setDecimals(5);
break; break;
case Unit::Px: case Unit::Px:
ui->doubleSpinBoxLayoutWidth->setDecimals(0); ui->doubleSpinBoxLayoutWidth->setDecimals(2);
ui->doubleSpinBoxShift->setDecimals(0); ui->doubleSpinBoxShift->setDecimals(2);
break; break;
default: default:
break; break;

View File

@ -62,17 +62,17 @@ public:
explicit DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent = nullptr, bool disableSettings = false); explicit DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent = nullptr, bool disableSettings = false);
~DialogLayoutSettings(); ~DialogLayoutSettings();
int GetPaperHeight() const; qreal GetPaperHeight() const;
void SetPaperHeight(int value); void SetPaperHeight(qreal value);
int GetPaperWidth() const; qreal GetPaperWidth() const;
void SetPaperWidth(int value); void SetPaperWidth(qreal value);
quint32 GetShift() const; qreal GetShift() const;
void SetShift(quint32 value); void SetShift(qreal value);
quint32 GetLayoutWidth() const; qreal GetLayoutWidth() const;
void SetLayoutWidth(quint32 value); void SetLayoutWidth(qreal value);
Cases GetGroup() const; Cases GetGroup() const;
void SetGroup(const Cases &value); void SetGroup(const Cases &value);
@ -97,8 +97,8 @@ public:
static QString MakeHelpTemplateList(); static QString MakeHelpTemplateList();
bool SelectPaperUnit(const QString& units); bool SelectPaperUnit(const QString& units);
bool SelectLayoutUnit(const QString& units); bool SelectLayoutUnit(const QString& units);
int LayoutToPixels(qreal value) const; qreal LayoutToPixels(qreal value) const;
int PageToPixels(qreal value) const; qreal PageToPixels(qreal value) const;
static QString MakeGroupsHelp(); static QString MakeGroupsHelp();
public slots: public slots:
void ConvertPaperSize(); void ConvertPaperSize();

View File

@ -59,7 +59,7 @@ public:
void SetPaperWidth(int value); void SetPaperWidth(int value);
quint32 GetShift() const; quint32 GetShift() const;
void SetShift(quint32 shift); void SetShift(quint32 shift);
void Generate(); void Generate();

View File

@ -251,11 +251,11 @@ void VSettings::SetUserPassword(const QString &value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VSettings::GetLayoutPaperHeight() const qreal VSettings::GetLayoutPaperHeight() const
{ {
const int def = qFloor(UnitConvertor(1189/*A0*/, Unit::Mm, Unit::Px)); const qreal def = UnitConvertor(1189/*A0*/, Unit::Mm, Unit::Px);
bool ok = false; bool ok = false;
const int height = value(SettingLayoutPaperHeight, def).toInt(&ok); const qreal height = value(SettingLayoutPaperHeight, def).toDouble(&ok);
if (ok) if (ok)
{ {
return height; return height;
@ -267,17 +267,17 @@ int VSettings::GetLayoutPaperHeight() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VSettings::SetLayoutPaperHeight(int value) void VSettings::SetLayoutPaperHeight(qreal value)
{ {
setValue(SettingLayoutPaperHeight, value); setValue(SettingLayoutPaperHeight, value);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VSettings::GetLayoutPaperWidth() const qreal VSettings::GetLayoutPaperWidth() const
{ {
const int def = qFloor(UnitConvertor(841/*A0*/, Unit::Mm, Unit::Px)); const qreal def = UnitConvertor(841/*A0*/, Unit::Mm, Unit::Px);
bool ok = false; bool ok = false;
const int width = value(SettingLayoutPaperWidth, def).toInt(&ok); const qreal width = value(SettingLayoutPaperWidth, def).toDouble(&ok);
if (ok) if (ok)
{ {
return width; return width;
@ -289,7 +289,7 @@ int VSettings::GetLayoutPaperWidth() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VSettings::SetLayoutPaperWidth(int value) void VSettings::SetLayoutPaperWidth(qreal value)
{ {
setValue(SettingLayoutPaperWidth, value); setValue(SettingLayoutPaperWidth, value);
} }
@ -311,9 +311,9 @@ quint32 VSettings::GetLayoutShift() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
quint32 VSettings::GetDefLayoutShift() qreal VSettings::GetDefLayoutShift()
{ {
return static_cast<quint32>(UnitConvertor(50, Unit::Mm, Unit::Px)); return UnitConvertor(50, Unit::Mm, Unit::Px);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -339,9 +339,9 @@ quint32 VSettings::GetLayoutWidth() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
quint32 VSettings::GetDefLayoutWidth() qreal VSettings::GetDefLayoutWidth()
{ {
return static_cast<quint32>(UnitConvertor(2.5, Unit::Mm, Unit::Px)); return UnitConvertor(2.5, Unit::Mm, Unit::Px);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -83,18 +83,18 @@ public:
QString GetUserPassword() const; QString GetUserPassword() const;
void SetUserPassword(const QString &value); void SetUserPassword(const QString &value);
int GetLayoutPaperHeight() const; qreal GetLayoutPaperHeight() const;
void SetLayoutPaperHeight(int value); void SetLayoutPaperHeight(qreal value);
int GetLayoutPaperWidth() const; qreal GetLayoutPaperWidth() const;
void SetLayoutPaperWidth(int value); void SetLayoutPaperWidth(qreal value);
quint32 GetLayoutShift() const; quint32 GetLayoutShift() const;
static quint32 GetDefLayoutShift(); static qreal GetDefLayoutShift();
void SetLayoutShift(quint32 value); void SetLayoutShift(quint32 value);
quint32 GetLayoutWidth() const; quint32 GetLayoutWidth() const;
static quint32 GetDefLayoutWidth(); static qreal GetDefLayoutWidth();
void SetLayoutWidth(quint32 value); void SetLayoutWidth(quint32 value);
Cases GetLayoutGroup() const; Cases GetLayoutGroup() const;