valentina/src/libs/vmisc/vcommonsettings.cpp

1570 lines
67 KiB
C++
Raw Normal View History

/************************************************************************
**
** @file vcommonsettings.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 15 7, 2015
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2015 Valentina project
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
**
** Valentina 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.
**
** Valentina 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 Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vcommonsettings.h"
#include <QApplication>
#include <QDate>
#include <QDir>
#include <QLocale>
#include <QMessageLogger>
#include <QStaticStringData>
#include <QStringData>
#include <QStringDataPtr>
#include <QVariant>
#include <QtDebug>
#include <QTextCodec>
#include <QFont>
#include <QGlobalStatic>
2021-08-21 15:13:56 +02:00
#include <QMarginsF>
2021-09-11 18:39:38 +02:00
#include <QColor>
#include "../vmisc/def.h"
#include "../vmisc/compatibility.h"
2022-02-18 09:36:38 +01:00
#include "../vmisc/literals.h"
const int VCommonSettings::defaultScrollingDuration = 300;
const int VCommonSettings::scrollingDurationMin = 100;
const int VCommonSettings::scrollingDurationMax = 1000;
const int VCommonSettings::defaultScrollingUpdateInterval = 30;
const int VCommonSettings::scrollingUpdateIntervalMin = 10;
const int VCommonSettings::scrollingUpdateIntervalMax = 100;
const qreal VCommonSettings::defaultSensorMouseScale = 2.0;
const qreal VCommonSettings::sensorMouseScaleMin = 1.0;
const qreal VCommonSettings::sensorMouseScaleMax = 10.0;
const qreal VCommonSettings::defaultWheelMouseScale = 45.0;
const qreal VCommonSettings::wheelMouseScaleMin = 1.0;
const qreal VCommonSettings::wheelMouseScaleMax = 100.0;
const qreal VCommonSettings::defaultScrollingAcceleration = 1.3;
const qreal VCommonSettings::scrollingAccelerationMin = 1.0;
const qreal VCommonSettings::scrollingAccelerationMax = 10.0;
2022-08-12 17:50:13 +02:00
Q_DECLARE_METATYPE(QMarginsF) // NOLINT
namespace
{
2022-08-12 17:50:13 +02:00
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsIndividualMeasurements, (QLatin1String("paths/individual_measurements"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsMultisizeMeasurements, (QLatin1String("paths/standard_measurements"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsPattern, (QLatin1String("paths/pattern"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsTemplates, (QLatin1String("paths/templates"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsLabelTemplate, (QLatin1String("paths/labels"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsManualLayouts, (QLatin1String("paths/manualLayouts"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationOsSeparator, (QLatin1String("configuration/osSeparator"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAutosaveState, (QLatin1String("configuration/autosave/state"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAutosaveTime , (QLatin1String("configuration/autosave/time"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationLocale, (QLatin1String("configuration/locale"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPMSystemCode, (QLatin1String("configuration/pmscode"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationUnit, (QLatin1String("configuration/unit"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationConfirmItemDeletion, (QLatin1String("configuration/confirm_item_deletion"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationConfirmFormatRewriting, (QLatin1String("configuration/confirm_format_rewriting"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAskContinueIfLayoutStale, (QLatin1String("configuration/askContinueIfLayoutStale"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationToolBarStyle, (QLatin1String("configuration/tool_bar_style"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationFreeCurveMode, (QLatin1String("configuration/freeCurveMode"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationDoubleClickZoomFitBestCurrentPP, (QLatin1String("configuration/doubleClickZoomFitBestCurrentPP"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationDontUseNativeDialog, (QLatin1String("configuration/dontUseNativeDialog"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternUndo, (QLatin1String("pattern/undo"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternForbidFlipping, (QLatin1String("pattern/forbidFlipping"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternForceFlipping, (QLatin1String("pattern/forceFlipping"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternSewLineOnDrawing, (QLatin1String("pattern/sewLineOnDrawing"))) // NOLINT
2022-08-12 17:50:13 +02:00
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternHideMainPath, (QLatin1String("pattern/hideMainPath"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDoublePassmark, (QLatin1String("pattern/doublePassmark"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternDefaultSeamAllowance, (QLatin1String("pattern/defaultSeamAllowance"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLabelFont, (QLatin1String("pattern/labelFont"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLineWidth, (QLatin1String("pattern/lineWidth"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternCurveApproximationScale, (QLatin1String("pattern/curveApproximationScale"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternShowCurveDetails, (QLatin1String("pattern/showCurveDetails"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternPieceShowMainPath, (QLatin1String("pattern/pieceShowMainPath"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLabelFontSize, (QLatin1String("pattern/labelFontSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternHideLabels, (QLatin1String("pattern/hideLabels"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternUseOpenGLRender, (QLatin1String("pattern/useOpenGLRender"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternGraphicalOutput, (QLatin1String("pattern/graphicalOutput"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralRecentFileList, (QLatin1String("recentFileList"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralRestoreFileList, (QLatin1String("restoreFileList"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralGeometry, (QLatin1String("geometry"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralWindowState, (QLatin1String("windowState"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralToolbarsState, (QLatin1String("toolbarsState"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationDarkMode, (QLatin1String("configuration/dark_mode"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPreferenceDialogSize, (QLatin1String("preferenceDialogSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingToolSeamAllowanceDialogSize, (QLatin1String("toolSeamAllowanceDialogSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingIncrementsDialogSize, (QLatin1String("toolIncrementsDialogSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingFormulaWizardDialogSize, (QLatin1String("formulaWizardDialogSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingFinalMeasurementsDialogSize, (QLatin1String("finalMeasurementsDialogSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSettingsDialogSize, (QLatin1String("layoutSettingsDialogSize"))) // NOLINT
2022-09-05 13:38:26 +02:00
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDialogSplinePathSize, (QLatin1String("splinePathDialogSize"))) // NOLINT
2022-08-12 17:50:13 +02:00
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingAutomaticallyCheckUpdates, (QLatin1String("automaticallyCheckUpdates"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLatestSkippedVersion, (QLatin1String("lastestSkippedVersion"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDateOfLastRemind, (QLatin1String("dateOfLastRemind"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingCSVWithHeader, (QLatin1String("csv/withHeader"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingCSVCodec, (QLatin1String("csv/withCodec"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingCSVSeparator, (QLatin1String("csv/withSeparator"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelDateFormat, (QLatin1String("label/dateFormat"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelUserDateFormats, (QLatin1String("label/userDateFormats"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelTimeFormat, (QLatin1String("label/timeFormat"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelUserTimeFormats, (QLatin1String("label/userTimeFormats"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingDuration, (QLatin1String("scrolling/duration"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingUpdateInterval, (QLatin1String("scrolling/updateInterval"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingSensorMouseScale, (QLatin1String("scrolling/sensorMouseScale"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingWheelMouseScale, (QLatin1String("scrolling/wheelMouseScale"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingAcceleration, (QLatin1String("scrolling/acceleration"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFMargins, (QLatin1String("tiledPDF/margins"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFOrientation, (QLatin1String("tiledPDF/orientation"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingWatermarkEditorSize, (QLatin1String("watermarkEditorSize"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingWatermarkCustomColors, (QLatin1String("watermarkCustomColors"))) // NOLINT
2021-09-11 18:39:38 +02:00
// Reading settings file is very expensive, cache curve approximation to speed up getting value
2022-08-12 17:50:13 +02:00
qreal curveApproximationCached = -1; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
Q_GLOBAL_STATIC(QString, localeCached) // NOLINT
qreal lineWidthCached = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
int labelFontSizeCached = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
int pieceShowMainPath = -1; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
int scrollingDurationCached = -1; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
int scrollingUpdateIntervalCached = -1; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
qreal scrollingSensorMouseScaleCached = -1; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
qreal scrollingWheelMouseScaleCached = -1; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
qreal scrollingAccelerationCached = -1; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto ClearFormats(const QStringList &predefinedFormats, QStringList formats) -> QStringList
{
2022-08-12 17:50:13 +02:00
for (const auto &f : predefinedFormats)
{
formats.removeAll(f);
}
return formats;
}
2022-08-12 17:50:13 +02:00
} // namespace
2022-08-12 17:50:13 +02:00
Q_GLOBAL_STATIC_WITH_ARGS(const QString, commonIniFilename, (QLatin1String("common"))) // NOLINT
#if !defined(Q_OS_WIN)
2022-08-12 17:50:13 +02:00
const QString VCommonSettings::unixStandardSharePath = QStringLiteral(PKGDATADIR); // NOLINT(cert-err58-cpp)
#endif
namespace
{
//---------------------------------------------------------------------------------------------------------------------
void SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool replaceOnConflit)
{
QDir dir;
dir.setPath(fromDir);
const QStringList list = dir.entryList(QDir::Files);
for (const QString &copyFile : list)
{
const QString from = fromDir + QDir::separator() + copyFile;
QString to = toDir + QDir::separator() + copyFile;
#ifdef Q_OS_WIN
{
// To fix issue #702 check each not symlink if it is actually broken symlink.
// Also trying to mimic Unix symlink. If a file eaxists do not create a symlink and remove it if exists.
QFile fileTo(to);
if (fileTo.exists())
{
if (not fileTo.rename(to + QLatin1String(".lnk")))
{
QFile::remove(to + QLatin1String(".lnk"));
fileTo.rename(to + QLatin1String(".lnk"));
}
QFileInfo info(to + QLatin1String(".lnk"));
if (info.symLinkTarget().isEmpty())
{
fileTo.copy(to);
fileTo.remove();
continue; // The file already exists, skip creating shortcut
}
}
}
to = to + QLatin1String(".lnk");
#endif
QFileInfo fileTo(to);
if (not fileTo.isSymLink() && fileTo.exists())
{
if (replaceOnConflit)
{
QFile::remove(to);
}
else
{
continue;
}
}
else if (fileTo.isSymLink())
{
2022-08-12 17:50:13 +02:00
if (not fileTo.exists() || replaceOnConflit)
{ // automatically fix broken symlink
QFile::remove(to);
}
else
{
continue;
}
}
QFile::link(from, to);
}
const QStringList dirList = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
for (const QString &copyDir : dirList)
{
const QString from = fromDir + QDir::separator() + copyDir;
const QString to = toDir + QDir::separator() + copyDir;
2022-08-12 17:50:13 +02:00
if (not dir.mkpath(to))
{
return;
}
SymlinkCopyDirRecursive(from, to, replaceOnConflit);
}
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto PrepareStandardFiles(const QString &currentPath, const QString &standardPath, const QString &defPath) -> QString
{
QDir standardPathDir(standardPath);
QDir currentPathDir(currentPath);
if ((currentPath == defPath || not currentPathDir.exists()) && standardPathDir.exists())
{
const QDir localdata (defPath);
if (localdata.mkpath(QChar('.')))
{
SymlinkCopyDirRecursive(standardPath, defPath, false);
}
return defPath;
}
return currentPath;
}
2022-08-12 17:50:13 +02:00
} // namespace
//---------------------------------------------------------------------------------------------------------------------
VCommonSettings::VCommonSettings(Format format, Scope scope, const QString &organization,
const QString &application, QObject *parent)
:QSettings(format, scope, organization, application, parent)
{}
//---------------------------------------------------------------------------------------------------------------------
VCommonSettings::VCommonSettings(const QString &fileName, QSettings::Format format, QObject *parent)
:QSettings(fileName, format, parent)
{}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::SharePath(const QString &shareItem) -> QString
{
#ifdef Q_OS_WIN
return QCoreApplication::applicationDirPath() + shareItem;
#elif defined(Q_OS_MAC)
QDir dirBundle(QCoreApplication::applicationDirPath() + QStringLiteral("/../Resources") + shareItem);
if (dirBundle.exists())
{
return dirBundle.absolutePath();
}
else
{
QDir appDir = QDir(qApp->applicationDirPath());
appDir.cdUp();
appDir.cdUp();
appDir.cdUp();
QDir dir(appDir.absolutePath() + shareItem);
if (dir.exists())
{
return dir.absolutePath();
}
else
{
return VCommonSettings::unixStandardSharePath + shareItem;
}
}
#else // Unix
#ifdef QT_DEBUG
return QCoreApplication::applicationDirPath() + shareItem;
#else
QDir dir(QCoreApplication::applicationDirPath() + shareItem);
if (dir.exists())
{
return dir.absolutePath();
}
else
{
return VCommonSettings::unixStandardSharePath + shareItem;
}
#endif
#endif
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::MultisizeTablesPath() -> QString
{
return SharePath(QStringLiteral("/tables/multisize"));
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::StandardTemplatesPath() -> QString
{
return SharePath(QStringLiteral("/tables/templates"));
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::LabelTemplatesPath() -> QString
{
return SharePath(QStringLiteral("/labels"));
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::PrepareStandardTemplates(const QString & currentPath) -> QString
{
return PrepareStandardFiles(currentPath, StandardTemplatesPath(), GetDefPathTemplate());
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::PrepareMultisizeTables(const QString &currentPath) -> QString
{
return PrepareStandardFiles(currentPath, MultisizeTablesPath(), GetDefPathMultisizeMeasurements());
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::PrepareLabelTemplates(const QString &currentPath) -> QString
{
return PrepareStandardFiles(currentPath, LabelTemplatesPath(), GetDefPathLabelTemplate());
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetDefPathIndividualMeasurements() -> QString
{
2022-08-12 17:50:13 +02:00
return QDir::homePath() + QStringLiteral("/valentina/") + tr("measurements") + QStringLiteral("/") +
tr("individual");
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetPathIndividualMeasurements() const -> QString
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return settings.value(*settingPathsIndividualMeasurements, GetDefPathIndividualMeasurements()).toString();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetPathIndividualMeasurements(const QString &value)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingPathsIndividualMeasurements, value);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetDefPathMultisizeMeasurements() -> QString
{
2022-08-12 17:50:13 +02:00
return QDir::homePath() + QStringLiteral("/valentina/") + tr("measurements") + QChar('/') + tr("multisize");
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetPathMultisizeMeasurements() const -> QString
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return settings.value(*settingPathsMultisizeMeasurements, GetDefPathMultisizeMeasurements()).toString();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetPathMultisizeMeasurements(const QString &value)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingPathsMultisizeMeasurements, value);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetDefPathPattern() -> QString
{
2022-08-12 17:50:13 +02:00
return QDir::homePath() + QStringLiteral("/valentina/") + tr("patterns");
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetPathPattern() const -> QString
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return settings.value(*settingPathsPattern, GetDefPathPattern()).toString();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetPathPattern(const QString &value)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingPathsPattern, value);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetDefPathTemplate() -> QString
{
2022-08-12 17:50:13 +02:00
return QDir::homePath() + QStringLiteral("/valentina/") + tr("templates");
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetPathTemplate() const -> QString
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return settings.value(*settingPathsTemplates, GetDefPathTemplate()).toString();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetPathTemplate(const QString &value)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingPathsTemplates, value);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetDefPathLabelTemplate() -> QString
{
2022-08-12 17:50:13 +02:00
return QDir::homePath() + QStringLiteral("/valentina/") + tr("label templates");
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetPathLabelTemplate() const -> QString
{
return value(*settingPathsLabelTemplate, GetDefPathLabelTemplate()).toString();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetPathLabelTemplate(const QString &value)
{
setValue(*settingPathsLabelTemplate, value);
}
2020-04-21 17:57:11 +02:00
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetDefPathManualLayouts() -> QString
2020-04-21 17:57:11 +02:00
{
2022-08-12 17:50:13 +02:00
return QDir::homePath() + QStringLiteral("/valentina/") + tr("manual layouts");
2020-04-21 17:57:11 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetPathManualLayouts() const -> QString
2020-04-21 17:57:11 +02:00
{
return value(*settingPathsManualLayouts, GetDefPathManualLayouts()).toString();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetPathManualLayouts(const QString &value)
{
setValue(*settingPathsManualLayouts, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetOsSeparator() const -> bool
{
return value(*settingConfigurationOsSeparator, 1).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetOsSeparator(const bool &value)
{
setValue(*settingConfigurationOsSeparator, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetAutosaveState() const -> bool
{
return value(*settingConfigurationAutosaveState, 1).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetAutosaveState(const bool &value)
{
setValue(*settingConfigurationAutosaveState, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetAutosaveTime() const -> int
{
bool ok = false;
int val = value(*settingConfigurationAutosaveTime, 1).toInt(&ok);
2022-08-12 17:50:13 +02:00
if (not ok)
{
qDebug()<<"Could not convert value"<<value(*settingConfigurationAutosaveTime, 1)
<<"to int. Return default value for autosave time"<<1<<"minutes.";
val = 1;
}
return val;
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetAutosaveTime(const int &value)
{
setValue(*settingConfigurationAutosaveTime, value);
}
//---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::IsLocaleSelected() const -> bool
{
const QString fakeLocale = QStringLiteral("Fake");
QString locale = value(*settingConfigurationLocale, fakeLocale).toString();
return locale != fakeLocale;
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetLocale() const -> QString
{
if (localeCached->isEmpty())
{
*localeCached = value(*settingConfigurationLocale, QLocale().name()).toString();
}
return *localeCached;
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetLocale(const QString &value)
{
setValue(*settingConfigurationLocale, value);
*localeCached = value;
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetPMSystemCode() const -> QString
{
return value(*settingPMSystemCode, "p998").toString();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetPMSystemCode(const QString &value)
{
setValue(*settingPMSystemCode, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetUnit() const -> QString
{
return value(*settingConfigurationUnit,
QLocale().measurementSystem() == QLocale::MetricSystem ? unitCM : unitINCH).toString();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetUnit(const QString &value)
{
setValue(*settingConfigurationUnit, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetConfirmItemDelete() const -> bool
{
return value(*settingConfigurationConfirmItemDeletion, 1).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetConfirmItemDelete(const bool &value)
{
setValue(*settingConfigurationConfirmItemDeletion, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetConfirmFormatRewriting() const -> bool
{
return value(*settingConfigurationConfirmFormatRewriting, 1).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetConfirmFormatRewriting(const bool &value)
{
setValue(*settingConfigurationConfirmFormatRewriting, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetAskContinueIfLayoutStale() const -> bool
{
return value(*settingConfigurationAskContinueIfLayoutStale, 1).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetAskContinueIfLayoutStale(const bool &value)
{
setValue(*settingConfigurationAskContinueIfLayoutStale, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetToolBarStyle() const -> bool
{
return value(*settingConfigurationToolBarStyle, 1).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetToolBarStyle(const bool &value)
{
setValue(*settingConfigurationToolBarStyle, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetDarkMode() const -> bool
{
return value(*settingConfigurationDarkMode, 0).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetDarkMode(const bool &value)
{
setValue(*settingConfigurationDarkMode, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::IsFreeCurveMode() const -> bool
{
return value(*settingConfigurationFreeCurveMode, 1).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetFreeCurveMode(bool value)
{
setValue(*settingConfigurationFreeCurveMode, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::IsDoubleClickZoomFitBestCurrentPP() const -> bool
{
return value(*settingConfigurationDoubleClickZoomFitBestCurrentPP, 1).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetDoubleClickZoomFitBestCurrentPP(bool value)
{
setValue(*settingConfigurationDoubleClickZoomFitBestCurrentPP, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetUndoCount() const -> int
{
bool ok = false;
int val = value(*settingPatternUndo, 0).toInt(&ok);
2022-08-12 17:50:13 +02:00
if (not ok)
{
qDebug()<<"Could not convert value"<<value(*settingPatternUndo, 0)
<<"to int. Return default value for undo counts 0 (no limit).";
val = 0;
}
return val;
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetUndoCount(const int &value)
{
setValue(*settingPatternUndo, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetRecentFileList() const -> QStringList
{
const QStringList files = value(*settingGeneralRecentFileList).toStringList();
QStringList cleared;
2022-08-12 17:50:13 +02:00
for (const auto &f : files)
{
if (QFileInfo::exists(f))
{
cleared.append(f);
}
}
return cleared;
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetRecentFileList(const QStringList &value)
{
setValue(*settingGeneralRecentFileList, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetRestoreFileList() const -> QStringList
{
return value(*settingGeneralRestoreFileList).toStringList();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetRestoreFileList(const QStringList &value)
{
setValue(*settingGeneralRestoreFileList, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetGeometry() const -> QByteArray
{
return value(*settingGeneralGeometry).toByteArray();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetGeometry(const QByteArray &value)
{
setValue(*settingGeneralGeometry, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetWindowState() const -> QByteArray
{
return value(*settingGeneralWindowState).toByteArray();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetWindowState(const QByteArray &value)
{
setValue(*settingGeneralWindowState, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetToolbarsState() const -> QByteArray
{
return value(*settingGeneralToolbarsState).toByteArray();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetToolbarsState(const QByteArray &value)
{
setValue(*settingGeneralToolbarsState, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetPreferenceDialogSize() const -> QSize
{
return value(*settingPreferenceDialogSize, QSize(0, 0)).toSize();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetPreferenceDialogSize(const QSize& sz)
{
setValue(*settingPreferenceDialogSize, sz);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetToolSeamAllowanceDialogSize() const -> QSize
{
return value(*settingToolSeamAllowanceDialogSize, QSize(0, 0)).toSize();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetToolSeamAllowanceDialogSize(const QSize &sz)
{
setValue(*settingToolSeamAllowanceDialogSize, sz);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetFormulaWizardDialogSize() const -> QSize
{
return value(*settingFormulaWizardDialogSize, QSize(0, 0)).toSize();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetFormulaWizardDialogSize(const QSize &sz)
{
setValue(*settingFormulaWizardDialogSize, sz);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetIncrementsDialogSize() const -> QSize
{
return value(*settingIncrementsDialogSize, QSize(0, 0)).toSize();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetIncrementsDialogSize(const QSize &sz)
{
setValue(*settingIncrementsDialogSize, sz);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetFinalMeasurementsDialogSize() const -> QSize
{
return value(*settingFinalMeasurementsDialogSize, QSize(0, 0)).toSize();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetFinalMeasurementsDialogSize(const QSize &sz)
{
setValue(*settingFinalMeasurementsDialogSize, sz);
}
//---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::GetLayoutSettingsDialogSize() const -> QSize
{
return value(*settingLayoutSettingsDialogSize, QSize(0, 0)).toSize();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetLayoutSettingsDialogSize(const QSize &sz)
{
setValue(*settingLayoutSettingsDialogSize, sz);
}
2022-09-05 13:38:26 +02:00
//---------------------------------------------------------------------------------------------------------------------
QSize VCommonSettings::GetDialogSplinePathSize() const
{
return value(*settingDialogSplinePathSize, QSize(0, 0)).toSize();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetDialogSplinePathSize(const QSize &sz)
{
setValue(*settingDialogSplinePathSize, sz);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::IsAutomaticallyCheckUpdates() const -> bool
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return settings.value(*settingAutomaticallyCheckUpdates, true).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetAutomaticallyCheckUpdates(bool value)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingAutomaticallyCheckUpdates, value);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetLatestSkippedVersion() const -> unsigned
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
2021-09-24 13:57:30 +02:00
return settings.value(*settingLatestSkippedVersion, 0x0).toUInt();
}
//---------------------------------------------------------------------------------------------------------------------
2021-09-24 13:57:30 +02:00
void VCommonSettings::SetLatestSkippedVersion(unsigned value)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingLatestSkippedVersion, value);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetDateOfLastRemind() const -> QDate
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return settings.value(*settingDateOfLastRemind, QDate(1900, 1, 1)).toDate();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetDateOfLastRemind(const QDate &date)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingDateOfLastRemind, date);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetForbidWorkpieceFlipping() const -> bool
{
return value(*settingPatternForbidFlipping, false).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetForbidWorkpieceFlipping(bool value)
{
setValue(*settingPatternForbidFlipping, value);
if (value)
{
SetForceWorkpieceFlipping(not value);
}
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetForceWorkpieceFlipping() const -> bool
{
return value(*settingPatternForceFlipping, false).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetForceWorkpieceFlipping(bool value)
{
setValue(*settingPatternForceFlipping, value);
if (value)
{
SetForbidWorkpieceFlipping(not value);
}
}
//---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::GetSewLineOnDrawing() const -> bool
{
return value(*settingPatternSewLineOnDrawing, false).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetSewLineOnDrawing(bool value)
{
setValue(*settingPatternSewLineOnDrawing, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::IsHideMainPath() const -> bool
{
return value(*settingPatternHideMainPath, false).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetHideMainPath(bool value)
{
setValue(*settingPatternHideMainPath, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::IsDoublePassmark() const -> bool
{
return value(*settingDoublePassmark, false).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetDoublePassmark(bool value)
{
setValue(*settingDoublePassmark, value);
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetCSVWithHeader(bool withHeader)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingCSVWithHeader, withHeader);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetCSVWithHeader() const -> bool
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return settings.value(*settingCSVWithHeader, GetDefCSVWithHeader()).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetDefCSVWithHeader() -> bool
{
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetCSVCodec(int mib)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingCSVCodec, mib);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetCSVCodec() const -> int
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return settings.value(*settingCSVCodec, GetDefCSVCodec()).toInt();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetDefCSVCodec() -> int
{
return QTextCodec::codecForLocale()->mibEnum();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetCSVSeparator(const QChar &separator)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
switch(separator.toLatin1())
{
case '\t':
settings.setValue(*settingCSVSeparator, 0);
break;
case ';':
settings.setValue(*settingCSVSeparator, 1);
break;
case ' ':
settings.setValue(*settingCSVSeparator, 2);
break;
default:
settings.setValue(*settingCSVSeparator, 3);
break;
}
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetCSVSeparator() const -> QChar
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
const quint8 separator = static_cast<quint8>(settings.value(*settingCSVSeparator, 3).toUInt());
switch(separator)
{
case 0:
return QChar('\t');
case 1:
return QChar(';');
case 2:
return QChar(' ');
default:
return QChar(',');
}
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetDefCSVSeparator() -> QChar
{
return QChar(',');
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetDefaultSeamAllowance(double value)
{
setValue(*settingPatternDefaultSeamAllowance, UnitConvertor(value, StrToUnits(GetUnit()), Unit::Cm));
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief returns the default seam allowance. The corresponding unit is the default unit.
* @return the default seam allowance
*/
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetDefaultSeamAllowance() -> double
{
double defaultValue;
const Unit globalUnit = StrToUnits(GetUnit());
switch (globalUnit)
{
case Unit::Mm:
defaultValue = 10;
break;
case Unit::Inch:
defaultValue = 0.25;
break;
case Unit::Cm:
default:
defaultValue = 1;
break;
}
bool ok = false;
double val = value(*settingPatternDefaultSeamAllowance, -1).toDouble(&ok);
2022-08-12 17:50:13 +02:00
if (not ok)
{
qDebug()<< "Could not convert value"<<value(*settingPatternDefaultSeamAllowance, 0)
<< "to real. Return default value for default seam allowance is "
<< defaultValue << QChar('.');
val = defaultValue;
}
if (val < 0)
{
val = defaultValue;
}
else
{
val = UnitConvertor(val, Unit::Cm, globalUnit);
}
return val;
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetLabelFont() const -> QFont
{
return qvariant_cast<QFont>(value(*settingPatternLabelFont, QApplication::font()));
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetLabelFont(const QFont &f)
{
setValue(*settingPatternLabelFont, f);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetLabelFontSize() const -> int
{
if (labelFontSizeCached <= 0)
{
bool ok = false;
labelFontSizeCached = value(*settingPatternLabelFontSize, GetDefLabelFontSize()).toInt(&ok);
if (not ok)
{
labelFontSizeCached = GetDefLabelFontSize();
}
labelFontSizeCached = qBound(minLabelFontSize, labelFontSizeCached, maxLabelFontSize);
}
return labelFontSizeCached;
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetLabelFontSize(int size)
{
size = qBound(minLabelFontSize, size, maxLabelFontSize);
setValue(*settingPatternLabelFontSize, size);
labelFontSizeCached = size;
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetDefLabelFontSize() -> int
{
return 32;
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetHideLabels() const -> bool
{
return value(*settingPatternHideLabels, false).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetHideLabels(bool value)
{
setValue(*settingPatternHideLabels, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetLabelDateFormat() const -> QString
{
const QString format = value(*settingLabelDateFormat,
ConstFirst<QString> (VCommonSettings::PredefinedDateFormats())).toString();
const QStringList allFormats = VCommonSettings::PredefinedDateFormats() + GetUserDefinedDateFormats();
return allFormats.contains(format) ? format : ConstFirst<QString> (VCommonSettings::PredefinedDateFormats());
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetLabelDateFormat(const QString &format)
{
setValue(*settingLabelDateFormat, format);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::PredefinedDateFormats() -> QStringList
{
2019-05-28 15:20:53 +02:00
return QStringList
{
"MM-dd-yyyy",
"d/M/yy",
"ddddMMMM dd, yyyy",
"dd/MM/yy",
"dd/MM/yyyy",
"MMM d, yy",
"MMM d, yyyy",
"d. MMM. yyyy",
"MMMM d, yyyy",
"d. MMMM yyyy",
"ddd, MMM d, yy",
"ddd dd/MMM yy",
"ddd, MMMM d, yyyy",
"ddddMMMM d, yyyy",
"MM-dd",
"yy-MM-dd",
"yyyy-MM-dd",
"MM/yy",
"MMM dd",
"MMMM"
};
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetUserDefinedDateFormats() const -> QStringList
{
return value(*settingLabelUserDateFormats, QStringList()).toStringList();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetUserDefinedDateFormats(const QStringList &formats)
{
setValue(*settingLabelUserDateFormats, ClearFormats(VCommonSettings::PredefinedDateFormats(), formats));
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetLabelTimeFormat() const -> QString
{
const QString format = value(*settingLabelTimeFormat,
ConstFirst<QString> (VCommonSettings::PredefinedTimeFormats())).toString();
const QStringList allFormats = VCommonSettings::PredefinedTimeFormats() + GetUserDefinedTimeFormats();
return allFormats.contains(format) ? format : ConstFirst<QString> (VCommonSettings::PredefinedTimeFormats());
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetLabelTimeFormat(const QString &format)
{
setValue(*settingLabelTimeFormat, format);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::PredefinedTimeFormats() -> QStringList
{
2019-05-28 15:20:53 +02:00
return QStringList
{
"hh:mm:ss",
"hh:mm:ss AP",
"hh:mm",
"hh:mm AP"
};
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetUserDefinedTimeFormats() const -> QStringList
{
return value(*settingLabelUserTimeFormats, QStringList()).toStringList();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetUserDefinedTimeFormats(const QStringList &formats)
{
setValue(*settingLabelUserTimeFormats, ClearFormats(VCommonSettings::PredefinedTimeFormats(), formats));
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetCurveApproximationScale() const -> qreal
{
if (curveApproximationCached < 0)
{
bool ok = false;
const qreal scale = value(*settingPatternCurveApproximationScale, defCurveApproximationScale).toDouble(&ok);
if (ok && scale >= minCurveApproximationScale && scale <= maxCurveApproximationScale)
{
curveApproximationCached = scale;
}
else
{
curveApproximationCached = defCurveApproximationScale;
}
}
return curveApproximationCached;
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetCurveApproximationScale(qreal value)
{
if (value >= minCurveApproximationScale && value <= maxCurveApproximationScale)
{
setValue(*settingPatternCurveApproximationScale, value);
curveApproximationCached = value;
}
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::IsShowCurveDetails() const -> bool
{
return value(*settingPatternShowCurveDetails, false).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetShowCurveDetails(bool value)
{
setValue(*settingPatternShowCurveDetails, value);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::IsPieceShowMainPath() const -> bool
{
if (pieceShowMainPath < 0)
{
pieceShowMainPath = value(*settingPatternPieceShowMainPath, 0).toInt();
}
return pieceShowMainPath;
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetPieceShowMainPath(bool value)
{
pieceShowMainPath = value;
setValue(*settingPatternPieceShowMainPath, pieceShowMainPath);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::IsDontUseNativeDialog() const -> bool
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return settings.value(*settingConfigurationDontUseNativeDialog, false).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetDontUseNativeDialog(bool value)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingConfigurationDontUseNativeDialog, value);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetLineWidth() const -> qreal
{
if (lineWidthCached <= 0)
{
lineWidthCached = qBound(VCommonSettings::MinimalLineWidth(), value(*settingPatternLineWidth, 1.2).toDouble(),
VCommonSettings::MaximalLineWidth());
}
return lineWidthCached;
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetLineWidth(qreal width)
{
lineWidthCached = qBound(VCommonSettings::MinimalLineWidth(), width, VCommonSettings::MaximalLineWidth());
setValue(*settingPatternLineWidth, lineWidthCached);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::WidthMainLine() const -> qreal
{
return GetLineWidth() / 25.4 * PrintDPI;
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::WidthHairLine() const -> qreal
{
return WidthMainLine()/3.0;
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetScrollingDuration() const -> int
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return GetCachedValue(settings, scrollingDurationCached, *settingScrollingDuration, defaultScrollingDuration,
scrollingDurationMin, scrollingDurationMax);
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetScrollingDuration(int duration)
{
scrollingDurationCached = qBound(scrollingDurationMin, duration, scrollingDurationMax);
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingScrollingDuration, scrollingDurationCached);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetScrollingUpdateInterval() const -> int
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return GetCachedValue(settings, scrollingUpdateIntervalCached, *settingScrollingUpdateInterval,
defaultScrollingUpdateInterval, scrollingUpdateIntervalMin, scrollingUpdateIntervalMax);
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetScrollingUpdateInterval(int updateInterval)
{
scrollingUpdateIntervalCached = qBound(scrollingUpdateIntervalMin, updateInterval, scrollingUpdateIntervalMax);
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingScrollingUpdateInterval, scrollingUpdateIntervalCached);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetSensorMouseScale() const -> qreal
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return GetCachedValue(settings, scrollingSensorMouseScaleCached, *settingScrollingSensorMouseScale,
defaultSensorMouseScale, sensorMouseScaleMin, sensorMouseScaleMax);
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetSensorMouseScale(qreal scale)
{
scrollingSensorMouseScaleCached = qBound(sensorMouseScaleMin, scale, sensorMouseScaleMax);
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingScrollingSensorMouseScale, scrollingSensorMouseScaleCached);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetWheelMouseScale() const -> qreal
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return GetCachedValue(settings, scrollingWheelMouseScaleCached, *settingScrollingWheelMouseScale,
defaultWheelMouseScale, wheelMouseScaleMin, wheelMouseScaleMax);
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetWheelMouseScale(qreal scale)
{
scrollingWheelMouseScaleCached = qBound(wheelMouseScaleMin, scale, wheelMouseScaleMax);
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingScrollingWheelMouseScale, scrollingWheelMouseScaleCached);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetScrollingAcceleration() const -> qreal
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return GetCachedValue(settings, scrollingAccelerationCached, *settingScrollingAcceleration,
defaultScrollingAcceleration, scrollingAccelerationMin, scrollingAccelerationMax);
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetScrollingAcceleration(qreal acceleration)
{
scrollingAccelerationCached = qBound(scrollingAccelerationMin, acceleration, scrollingAccelerationMax);
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingScrollingAcceleration, scrollingAccelerationCached);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::IsOpenGLRender() const -> bool
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return settings.value(*settingPatternUseOpenGLRender, 0).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetOpenGLRender(bool value)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingPatternUseOpenGLRender, value);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetGraphicalOutput() const -> bool
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return settings.value(*settingPatternGraphicalOutput, 1).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetGraphicalOutput(const bool &value)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingPatternGraphicalOutput, value);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetTiledPDFMargins returns the tiled pdf margins in the given unit. When the setting is
* called for the first time, the 4 default margins are 10mm.
* @param unit the unit in which are the value. Necessary because we save the values
* internaly as mm so there is conversion beeing made.
* @return tiled pdf margins
*/
auto VCommonSettings::GetTiledPDFMargins(const Unit &unit) const -> QMarginsF
{
// default value is 10mm. We save the margins in mm in the setting.
return UnitConvertor(
ValueOrDef<QMarginsF>(*this, *settingTiledPDFMargins, QMarginsF(10, 10, 10, 10)), Unit::Mm, unit);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetTiledPDFMargins sets the setting tiled pdf margins to the given value.
* @param value the margins to save
* @param unit the unit in which are the value. Necessary because we save the values
* internaly as mm so there is conversion beeing made.
*/
void VCommonSettings::SetTiledPDFMargins(const QMarginsF &value, const Unit &unit)
{
setValue(*settingTiledPDFMargins, QVariant::fromValue(UnitConvertor(value, unit, Unit::Mm)));
}
//---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::GetTiledPDFOrientation() const -> PageOrientation
{
bool defaultValue = static_cast<bool>(PageOrientation::Portrait);
bool result = value(*settingTiledPDFOrientation, defaultValue).toBool();
return static_cast<PageOrientation>(result);
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetTiledPDFOrientation(PageOrientation value)
{
setValue(*settingTiledPDFOrientation, static_cast<bool> (value));
}
2021-09-11 18:39:38 +02:00
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetWatermarkEditorSize() const -> QSize
2021-09-11 18:39:38 +02:00
{
return value(*settingWatermarkEditorSize, QSize(0, 0)).toSize();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetWatermarkEditorSize(const QSize &sz)
{
setValue(*settingWatermarkEditorSize, sz);
}
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
auto VCommonSettings::GetWatermarkCustomColors() const -> QVector<QColor>
2021-09-11 18:39:38 +02:00
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
QStringList colors = settings.value(*settingPatternGraphicalOutput, 1).toStringList();
QVector<QColor> customColors;
customColors.reserve(colors.size());
2022-08-12 17:50:13 +02:00
for (const auto &color : colors)
2021-09-11 18:39:38 +02:00
{
QColor c(color);
if (c.isValid())
{
customColors.append(c);
}
}
if (customColors.count() > 7)
{
customColors.remove(0, customColors.count() - 7);
}
return customColors;
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetWatermarkCustomColors(QVector<QColor> colors)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
if (colors.count() > 7)
{
colors.remove(0, colors.count() - 7);
}
QStringList customColors;
customColors.reserve(colors.size());
2022-08-12 17:50:13 +02:00
for (const auto &color : colors)
2021-09-11 18:39:38 +02:00
{
customColors.append(color.name());
}
settings.setValue(*settingWatermarkCustomColors, customColors);
settings.sync();
}