From 2ae203897a5d7021661b85671d8b1e86695f8972 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 23 Feb 2024 14:42:57 +0200 Subject: [PATCH] Reverse change. Cache object must not be available public, must be static. --- src/app/puzzle/vpsettings.cpp | 33 ++++++++++++++------------------- src/app/puzzle/vpsettings.h | 14 +++++--------- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/app/puzzle/vpsettings.cpp b/src/app/puzzle/vpsettings.cpp index 1a3672ed2..5ea6b78da 100644 --- a/src/app/puzzle/vpsettings.cpp +++ b/src/app/puzzle/vpsettings.cpp @@ -76,6 +76,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsRawLayoutData, ("paths/rawL QT_WARNING_POP +int cachedLineWidth = -1; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + } // namespace #ifndef QPRINTENGINE_H @@ -83,15 +85,18 @@ Q_DECLARE_METATYPE(QMarginsF) // NOLINT #endif //--------------------------------------------------------------------------------------------------------------------- -VPSettings::VPSettings(Format format, Scope scope, const QString &organization, const QString &application, QObject *parent) - : VCommonSettings(format, scope, organization, application, parent), cachedLineWidth(-1) { - REGISTER_META_TYPE_STREAM_OPERATORS(QMarginsF) +VPSettings::VPSettings(Format format, Scope scope, const QString &organization, const QString &application, + QObject *parent) + : VCommonSettings(format, scope, organization, application, parent) +{ + REGISTER_META_TYPE_STREAM_OPERATORS(QMarginsF); } //--------------------------------------------------------------------------------------------------------------------- VPSettings::VPSettings(const QString &fileName, QSettings::Format format, QObject *parent) - : VCommonSettings(fileName, format, parent), cachedLineWidth(-1) { - REGISTER_META_TYPE_STREAM_OPERATORS(QMarginsF) + : VCommonSettings(fileName, format, parent) +{ + REGISTER_META_TYPE_STREAM_OPERATORS(QMarginsF); } //--------------------------------------------------------------------------------------------------------------------- @@ -353,12 +358,8 @@ void VPSettings::SetLayoutExportFormat(qint8 format) } //--------------------------------------------------------------------------------------------------------------------- -void VPSettings::SetCachedLineWidth(int lineWidth) { - cachedLineWidth = lineWidth; -} - -//--------------------------------------------------------------------------------------------------------------------- -auto VPSettings::GetCachedLineWidth() -> int { +auto VPSettings::GetLayoutLineWidth() const -> int +{ if (cachedLineWidth == -1) { cachedLineWidth = qvariant_cast(value(*settingLayoutLineWidth, 3)); @@ -367,17 +368,11 @@ auto VPSettings::GetCachedLineWidth() -> int { return cachedLineWidth; } -//--------------------------------------------------------------------------------------------------------------------- -auto VPSettings::GetLayoutLineWidth() -> int -{ - return GetCachedLineWidth(); -} - //--------------------------------------------------------------------------------------------------------------------- void VPSettings::SetLayoutLineWidth(int width) { - SetCachedLineWidth(qBound(1, width, 10)); - setValue(*settingLayoutLineWidth, GetCachedLineWidth()); + cachedLineWidth = qBound(1, width, 10); + setValue(*settingLayoutLineWidth, cachedLineWidth); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpsettings.h b/src/app/puzzle/vpsettings.h index 8bc08f165..39edda649 100644 --- a/src/app/puzzle/vpsettings.h +++ b/src/app/puzzle/vpsettings.h @@ -36,12 +36,9 @@ class VPSettings : public VCommonSettings { Q_OBJECT // NOLINT -private: - Q_DISABLE_COPY_MOVE(VPSettings) // NOLINT - int cachedLineWidth; - public: - VPSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), QObject *parent = nullptr); + VPSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), + QObject *parent = nullptr); VPSettings(const QString &fileName, Format format, QObject *parent = nullptr); ~VPSettings() override = default; @@ -108,15 +105,14 @@ public: auto GetLayoutExportFormat() const -> qint8; void SetLayoutExportFormat(qint8 format); - void SetCachedLineWidth(int lineWidth); - auto GetCachedLineWidth() -> int; - - auto GetLayoutLineWidth() -> int; + auto GetLayoutLineWidth() const -> int; void SetLayoutLineWidth(int width); auto GetShowGrainline() const -> bool; void SetShowGrainline(bool value); +private: + Q_DISABLE_COPY_MOVE(VPSettings) // NOLINT }; #endif // VPSETTINGS_H