Avoid using global static variables.

This commit is contained in:
Roman Telezhynskyi 2023-07-25 14:01:41 +03:00
parent ba9d9ff501
commit ccdabec868
27 changed files with 116 additions and 115 deletions

View File

@ -130,7 +130,7 @@ void VPDialogAbout::FontPointSize(QWidget *w, int pointSize)
//---------------------------------------------------------------------------------------------------------------------
void VPDialogAbout::RetranslateUi()
{
ui->label_Puzzle_Version->setText(QStringLiteral("Puzzle %1").arg(APP_VERSION_STR));
ui->label_Puzzle_Version->setText(QStringLiteral("Puzzle %1").arg(AppVersionStr()));
ui->labelBuildRevision->setText(tr("Build revision: %1").arg(QStringLiteral(BUILD_REVISION)));
ui->label_QT_Version->setText(buildCompatibilityString());

View File

@ -270,7 +270,7 @@ VPApplication::VPApplication(int &argc, char **argv)
setOrganizationName(QStringLiteral(VER_COMPANYNAME_STR));
setOrganizationDomain(QStringLiteral(VER_COMPANYDOMAIN_STR));
// Setting the Application version
setApplicationVersion(APP_VERSION_STR);
setApplicationVersion(AppVersionStr());
// We have been running Puzzle in two different cases.
// The first inside own bundle where info.plist is works fine, but the second,
// when we run inside Valentina's bundle, require direct setting the icon.
@ -420,7 +420,7 @@ void VPApplication::InitOptions()
OpenSettings();
qCDebug(pApp, "Version: %s", qUtf8Printable(APP_VERSION_STR));
qCDebug(pApp, "Version: %s", qUtf8Printable(AppVersionStr()));
qCDebug(pApp, "Build revision: %s", BUILD_REVISION);
qCDebug(pApp, "%s", qUtf8Printable(buildCompatibilityString()));
qCDebug(pApp, "Built on %s at %s", __DATE__, __TIME__);

View File

@ -142,7 +142,7 @@ void VPLayoutFileWriter::WriteFile(const VPLayoutPtr &layout, QIODevice *file)
writeStartDocument();
writeComment(
QStringLiteral("Layout created with Valentina v%1 (https://smart-pattern.com.ua/).").arg(APP_VERSION_STR));
QStringLiteral("Layout created with Valentina v%1 (https://smart-pattern.com.ua/).").arg(AppVersionStr()));
WriteLayout(layout);
writeEndDocument();
}

View File

@ -131,7 +131,7 @@ void DialogAboutTape::FontPointSize(QWidget *w, int pointSize)
//---------------------------------------------------------------------------------------------------------------------
void DialogAboutTape::RetranslateUi()
{
ui->label_Tape_Version->setText(QStringLiteral("Tape %1").arg(APP_VERSION_STR));
ui->label_Tape_Version->setText(QStringLiteral("Tape %1").arg(AppVersionStr()));
ui->labelBuildRevision->setText(tr("Build revision: %1").arg(QStringLiteral(BUILD_REVISION)));
ui->label_QT_Version->setText(buildCompatibilityString());

View File

@ -316,7 +316,7 @@ MApplication::MApplication(int &argc, char **argv)
setOrganizationName(QStringLiteral(VER_COMPANYNAME_STR));
setOrganizationDomain(QStringLiteral(VER_COMPANYDOMAIN_STR));
// Setting the Application version
setApplicationVersion(APP_VERSION_STR);
setApplicationVersion(AppVersionStr());
// We have been running Tape in two different cases.
// The first inside own bundle where info.plist is works fine, but the second,
// when we run inside Valentina's bundle, require direct setting the icon.
@ -471,7 +471,7 @@ void MApplication::InitOptions()
OpenSettings();
qCDebug(mApp, "Version: %s", qUtf8Printable(APP_VERSION_STR));
qCDebug(mApp, "Version: %s", qUtf8Printable(AppVersionStr()));
qCDebug(mApp, "Build revision: %s", BUILD_REVISION);
qCDebug(mApp, "%s", qUtf8Printable(buildCompatibilityString()));
qCDebug(mApp, "Built on %s at %s", __DATE__, __TIME__);

View File

@ -380,7 +380,7 @@ VApplication::VApplication(int &argc, char **argv)
setOrganizationName(QStringLiteral(VER_COMPANYNAME_STR));
setOrganizationDomain(QStringLiteral(VER_COMPANYDOMAIN_STR));
// Setting the Application version
setApplicationVersion(APP_VERSION_STR);
setApplicationVersion(AppVersionStr());
// making sure will create new instance...just in case we will ever do 2 objects of VApplication
VCommandLine::Reset();
VTheme::Instance()->StoreDefaultThemeName(QIcon::themeName());
@ -672,7 +672,7 @@ void VApplication::InitOptions()
// Run creation log after sending crash report
StartLogging();
qDebug() << "Version:" << APP_VERSION_STR;
qDebug() << "Version:" << AppVersionStr();
qDebug() << "Build revision:" << BUILD_REVISION;
qDebug() << buildCompatibilityString();
qDebug() << "Built on" << __DATE__ << "at" << __TIME__;

View File

@ -52,7 +52,7 @@ DialogAboutApp::DialogAboutApp(QWidget *parent) :
VAbstractValApplication::VApp()->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale())
: setLocale(QLocale::c());
ui->label_Valentina_Version->setText(QStringLiteral("Valentina %1").arg(APP_VERSION_STR));
ui->label_Valentina_Version->setText(QStringLiteral("Valentina %1").arg(AppVersionStr()));
ui->labelBuildRevision->setText(QStringLiteral("Build revision: %1").arg(QStringLiteral(BUILD_REVISION)));
ui->label_QT_Version->setText(buildCompatibilityString());

View File

@ -814,13 +814,13 @@ auto DialogLayoutSettings::MakeHelpTemplateList() -> QString
QString out = QChar('\n');
auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0);
for (int i = 0; i < VAbstractLayoutDialog::pageFormatNames.size(); ++i)
for (int i = 0; i < VAbstractLayoutDialog::PageFormatNames().size(); ++i)
{
if (cntr < static_cast<int>(PaperSizeTemplate::Custom))// Don't include custom template
{
out += "\t* "+VAbstractLayoutDialog::pageFormatNames.at(i)+" = "+ QString::number(cntr++);
out += "\t* "+VAbstractLayoutDialog::PageFormatNames().at(i)+" = "+ QString::number(cntr++);
if (i < VAbstractLayoutDialog::pageFormatNames.size() - 2)
if (i < VAbstractLayoutDialog::PageFormatNames().size() - 2)
{
out += QLatin1String(",\n");
}
@ -840,7 +840,7 @@ auto DialogLayoutSettings::MakeHelpTiledPdfTemplateList() -> QString
for (int i = 0; i <= static_cast<int>(PaperSizeTemplate::Tabloid); ++i)
{
out += "\t* "+VAbstractLayoutDialog::pageFormatNames.at(i)+" = "+ QString::number(i);
out += "\t* "+VAbstractLayoutDialog::PageFormatNames().at(i)+" = "+ QString::number(i);
if (i < static_cast<int>(PaperSizeTemplate::Tabloid))
{

View File

@ -71,8 +71,6 @@ auto main(int argc, char *argv[]) -> int
Q_INIT_RESOURCE(win_theme); // NOLINT
#endif
QT_REQUIRE_VERSION(argc, argv, "5.4.0") // clazy:exclude=qstring-arg,qstring-allocations NOLINT
#if defined(Q_OS_WIN)
VAbstractApplication::WinAttachConsole();
#endif
@ -103,6 +101,8 @@ auto main(int argc, char *argv[]) -> int
VApplication app(argc, argv);
app.InitOptions();
QT_REQUIRE_VERSION(argc, argv, "5.4.0") // clazy:exclude=qstring-arg,qstring-allocations NOLINT
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
VApplication::setDesktopFileName(QStringLiteral("ua.com.smart-pattern.valentina.desktop"));
#endif

View File

@ -140,7 +140,7 @@ namespace
//---------------------------------------------------------------------------------------------------------------------
auto FileComment() -> QString
{
return QStringLiteral("Pattern created with Valentina v%1 (https://smart-pattern.com.ua/).").arg(APP_VERSION_STR);
return QStringLiteral("Pattern created with Valentina v%1 (https://smart-pattern.com.ua/).").arg(AppVersionStr());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -317,35 +317,35 @@ const QString rotationElArc_ = rotation_V + elarc_;
const QString pieceArea_ = QStringLiteral("PieceArea_");
const QString pieceSeamLineArea_ = QStringLiteral("PieceSeamLineArea_");
const QStringList builInVariables
auto BuilInVariables() -> QStringList
{
measurement_,
increment_,
line_,
angleLine_,
arc_,
elarc_,
spl_,
splPath,
radiusArc_,
radius1ElArc_,
radius2ElArc_,
angle1Arc_,
angle2Arc_,
angle1ElArc_,
angle2ElArc_,
angle1Spl_,
angle2Spl_,
angle1SplPath,
angle2SplPath,
seg_,
currentLength,
currentSeamAllowance,
c1LengthSpl_,
c2LengthSpl_,
c1LengthSplPath,
c2LengthSplPath,
rotationElArc_,
pieceArea_,
pieceSeamLineArea_
};
return {measurement_,
increment_,
line_,
angleLine_,
arc_,
elarc_,
spl_,
splPath,
radiusArc_,
radius1ElArc_,
radius2ElArc_,
angle1Arc_,
angle2Arc_,
angle1ElArc_,
angle2ElArc_,
angle1Spl_,
angle2Spl_,
angle1SplPath,
angle2SplPath,
seg_,
currentLength,
currentSeamAllowance,
c1LengthSpl_,
c2LengthSpl_,
c1LengthSplPath,
c2LengthSplPath,
rotationElArc_,
pieceArea_,
pieceSeamLineArea_};
}

View File

@ -245,7 +245,7 @@ extern const QString rotationElArc_;
extern const QString pieceArea_;
extern const QString pieceSeamLineArea_;
extern const QStringList builInVariables;
auto BuilInVariables() -> QStringList;
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Weffc++")

View File

@ -2041,7 +2041,7 @@ auto VAbstractPattern::ListFinalMeasurementsExpressions() const -> QVector<VForm
//---------------------------------------------------------------------------------------------------------------------
auto VAbstractPattern::IsVariable(const QString &token) const -> bool
{
for (const auto &var : builInVariables)
for (const auto &var : BuilInVariables())
{
if (token.indexOf(var) == 0)
{
@ -2065,7 +2065,7 @@ auto VAbstractPattern::IsVariable(const QString &token) const -> bool
//---------------------------------------------------------------------------------------------------------------------
auto VAbstractPattern::IsFunction(const QString &token) const -> bool
{
for (const auto &fn : builInFunctions)
for (const auto &fn : BuilInFunctions())
{
if (token.indexOf(fn) == 0)
{

View File

@ -551,7 +551,7 @@ void QmuParserBase::DefineOprt( const QString &a_sName, fun_type2 a_pFun, unsign
// Check for conflicts with built in operator names
for (int i=0; m_bBuiltInOp && i<cmENDIF; ++i)
{
if (a_sName == c_DefaultOprt.at(i))
if (a_sName == GetOprtDef().at(i))
{
Error(ecBUILTIN_OVERLOAD, -1, a_sName);
}

View File

@ -143,7 +143,6 @@ protected:
*/
typedef QmuParserTokenReader token_reader_type;
static const QStringList c_DefaultOprt;
QLocale m_locale; ///< The locale used by the parser
QChar m_decimalPoint;
QChar m_thousandsSeparator;
@ -328,6 +327,15 @@ inline void QmuParserBase::AddValIdent(identfun_type a_pCallback)
*/
inline auto QmuParserBase::GetOprtDef() -> const QStringList &
{
/**
* @brief Identifiers for built in binary operators.
*
* When defining custom binary operators with #AddOprt(...) make sure not to choose
* names conflicting with these definitions.
*/
const static QStringList c_DefaultOprt = {"<=", ">=", "!=", "==", QChar('<'), QChar('>'),
QChar('+'), QChar('-'), QChar('*'), QChar('/'), QChar('^'), "&&",
"||", QChar('='), QChar('('), QChar(')'), QChar('?'), QChar(':')};
return c_DefaultOprt;
}

View File

@ -116,14 +116,14 @@ private:
// cppcheck-suppress unknownMacro
Q_DISABLE_COPY_MOVE(QmuParserErrorMsg) // NOLINT
QMap<int, QmuTranslation> m_vErrMsg; ///< A map with the predefined error messages
static const self_type m_Instance; ///< The instance pointer
};
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
inline auto QmuParserErrorMsg::Instance() -> const QmuParserErrorMsg &
{
return m_Instance;
const static QmuParserErrorMsg instance;
return instance;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -122,7 +122,7 @@ QT_WARNING_POP
//---------------------------------------------------------------------------------------------------------------------
auto FileComment() -> QString
{
return QString("Measurements created with Valentina v%1 (https://smart-pattern.com.ua/).").arg(APP_VERSION_STR);
return QString("Measurements created with Valentina v%1 (https://smart-pattern.com.ua/).").arg(AppVersionStr());
}
} // namespace

View File

@ -97,8 +97,7 @@ namespace
//---------------------------------------------------------------------------------------------------------------------
inline auto FileComment() -> QString
{
return QStringLiteral("Recipe created with Valentina v%1 (https://smart-pattern.com.ua/).")
.arg(APP_VERSION_STR);
return QStringLiteral("Recipe created with Valentina v%1 (https://smart-pattern.com.ua/).").arg(AppVersionStr());
}
//---------------------------------------------------------------------------------------------------------------------
@ -150,7 +149,7 @@ auto VPatternRecipe::Prerequisite() -> QDomElement
*/
QDomElement prerequisiteElement = createElement(QStringLiteral("prerequisite"));
prerequisiteElement.appendChild(CreateElementWithText(QStringLiteral("valentina"), APP_VERSION_STR));
prerequisiteElement.appendChild(CreateElementWithText(QStringLiteral("valentina"), AppVersionStr()));
prerequisiteElement.appendChild(CreateElementWithText(QStringLiteral("unit"),
UnitsToStr(VAbstractValApplication::VApp()->patternUnits())));
prerequisiteElement.appendChild(CreateElementWithText(QStringLiteral("author"), m_pattern->GetCompanyName()));

View File

@ -47,7 +47,7 @@ namespace
//---------------------------------------------------------------------------------------------------------------------
auto FileComment() -> QString
{
return QString("Watermark created with Valentina v%1 (https://smart-pattern.com.ua/).").arg(APP_VERSION_STR);
return QString("Watermark created with Valentina v%1 (https://smart-pattern.com.ua/).").arg(AppVersionStr());
}
} // namespace

View File

@ -32,26 +32,6 @@
#include <QApplication>
// must be the same order as PaperSizeTemplate constants
const VAbstractLayoutDialog::FormatsVector VAbstractLayoutDialog::pageFormatNames{
QStringLiteral("A0"),
QStringLiteral("A1"),
QStringLiteral("A2"),
QStringLiteral("A3"),
QStringLiteral("A4"),
QApplication::translate("VAbstractLayoutDialog", "Letter", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Legal", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Tabloid", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 24in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 30in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 36in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 42in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 44in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 48in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 62in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 72in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Custom", "Paper format")};
//---------------------------------------------------------------------------------------------------------------------
VAbstractLayoutDialog::VAbstractLayoutDialog(QWidget *parent)
: QDialog(parent)
@ -67,7 +47,7 @@ void VAbstractLayoutDialog::InitTemplates(QComboBox *comboBoxTemplates)
const QString pdi = QStringLiteral("(%1ppi)").arg(PrintDPI);
auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0);
for (const auto &v : pageFormatNames)
for (const auto &v : PageFormatNames())
{
if (cntr <= static_cast<int>(PaperSizeTemplate::Tabloid))
{
@ -103,6 +83,31 @@ void VAbstractLayoutDialog::InitTileTemplates(QComboBox *comboBoxTemplates, bool
}
}
//---------------------------------------------------------------------------------------------------------------------
auto VAbstractLayoutDialog::PageFormatNames() -> const VAbstractLayoutDialog::FormatsVector &
{
// must be the same order as PaperSizeTemplate constants
static const FormatsVector pageFormatNames{
QStringLiteral("A0"),
QStringLiteral("A1"),
QStringLiteral("A2"),
QStringLiteral("A3"),
QStringLiteral("A4"),
QApplication::translate("VAbstractLayoutDialog", "Letter", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Legal", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Tabloid", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 24in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 30in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 36in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 42in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 44in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 48in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 62in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Roll 72in", "Paper format"),
QApplication::translate("VAbstractLayoutDialog", "Custom", "Paper format")};
return pageFormatNames;
}
//---------------------------------------------------------------------------------------------------------------------
auto VAbstractLayoutDialog::GetTemplateSize(PaperSizeTemplate tmpl, Unit unit) -> QSizeF
{

View File

@ -71,9 +71,9 @@ public:
protected:
typedef QStringList FormatsVector;
const static FormatsVector pageFormatNames;
typedef int VIndexType;
static auto PageFormatNames() -> const FormatsVector &;
static auto RoundTemplateSize(qreal width, qreal height, Unit unit) -> QSizeF;
private:

View File

@ -78,31 +78,15 @@ const QString avg_F = QStringLiteral("avg");
const QString fmod_F = QStringLiteral("fmod");
const QString warning_F = QStringLiteral("warning");
const QStringList builInFunctions
auto BuilInFunctions() -> QStringList
{
degTorad_F, radTodeg_F,
sin_F, cos_F, tan_F,
asin_F, acos_F, atan_F,
sinh_F, cosh_F, tanh_F,
asinh_F, acosh_F, atanh_F,
sinD_F, cosD_F, tanD_F,
asinD_F, acosD_F, atanD_F,
log2_F, log10_F, log_F,
ln_F,
exp_F,
sqrt_F,
sign_F,
rint_F, r2cm_F,
csrCm_F, csrInch_F,
abs_F,
min_F, max_F,
sum_F,
avg_F,
fmod_F,
warning_F
};
return {degTorad_F, radTodeg_F, sin_F, cos_F, tan_F, asin_F, acos_F, atan_F, sinh_F, cosh_F,
tanh_F, asinh_F, acosh_F, atanh_F, sinD_F, cosD_F, tanD_F, asinD_F, acosD_F, atanD_F,
log2_F, log10_F, log_F, ln_F, exp_F, sqrt_F, sign_F, rint_F, r2cm_F, csrCm_F,
csrInch_F, abs_F, min_F, max_F, sum_F, avg_F, fmod_F, warning_F};
}
const QString pl_size = QStringLiteral("size");
const QString pl_size = QStringLiteral("size");
const QString pl_height = QStringLiteral("height");
const QString pl_hip = QStringLiteral("hip");
const QString pl_waist = QStringLiteral("waist");

View File

@ -87,7 +87,7 @@ extern const QString avg_F;
extern const QString fmod_F;
extern const QString warning_F;
extern const QStringList builInFunctions;
auto BuilInFunctions() -> QStringList;
// Placeholders
extern const QString pl_height;

View File

@ -41,8 +41,13 @@
#define LATEST_TAG_DISTANCE VCS_REPO_STATE_DISTANCE
#endif
extern const QString APP_VERSION_STR(
QStringLiteral("%1.%2.%3.%4").arg(MAJOR_VERSION).arg(MINOR_VERSION).arg(DEBUG_VERSION).arg(LATEST_TAG_DISTANCE));
//---------------------------------------------------------------------------------------------------------------------
auto AppVersionStr() -> const QString &
{
static const QString appVersionStr =
QStringLiteral("%1.%2.%3.%4").arg(MAJOR_VERSION).arg(MINOR_VERSION).arg(DEBUG_VERSION).arg(LATEST_TAG_DISTANCE);
return appVersionStr;
}
//---------------------------------------------------------------------------------------------------------------------
auto compilerString() -> QString

View File

@ -35,7 +35,7 @@ constexpr unsigned MAJOR_VERSION = 0;
constexpr unsigned MINOR_VERSION = 7;
constexpr unsigned DEBUG_VERSION = 52;
extern const QString APP_VERSION_STR;
auto AppVersionStr() -> const QString &;
constexpr inline auto FormatVersion(unsigned major, unsigned minor, unsigned patch) -> unsigned
{

View File

@ -668,7 +668,7 @@ auto VContainer::IsUnique(const QString &name, const QString &nspace) -> bool
{
if (uniqueNames.contains(nspace))
{
return (!uniqueNames.value(nspace).contains(name) && !builInFunctions.contains(name));
return (!uniqueNames.value(nspace).contains(name) && !BuilInFunctions().contains(name));
}
else
{
@ -687,7 +687,7 @@ auto VContainer::AllUniqueNames(const QString &nspace) -> QStringList
{
if (uniqueNames.contains(nspace))
{
QStringList names = builInFunctions;
QStringList names = BuilInFunctions();
names.append(uniqueNames.value(nspace).values());
return names;
}

View File

@ -173,8 +173,8 @@ void TST_BuitInRegExp::TestCheckUnderlineExists_data()
data.insert(pieceArea_, true);
data.insert(pieceSeamLineArea_, true);
//Catch case when new internal variable appears.
QCOMPARE(data.size(), builInVariables.size());
// Catch case when new internal variable appears.
QCOMPARE(data.size(), BuilInVariables().size());
QTest::addColumn<QString>("name");
QTest::addColumn<bool>("exists");
@ -209,7 +209,7 @@ void TST_BuitInRegExp::TestCheckInternalVaribleRegExp_data()
QTest::addColumn<QString>("var");
QTest::addColumn<QString>("originalName");
for (const auto &var : qAsConst(builInVariables))
for (const auto &var : BuilInVariables())
{
const QString tag = QString("Locale: '%1'. Var '%2'").arg(m_locale, var);
const QStringList originalNames = AllNames();
@ -286,5 +286,5 @@ void TST_BuitInRegExp::PrepareData()
//---------------------------------------------------------------------------------------------------------------------
auto TST_BuitInRegExp::AllNames() -> QStringList
{
return builInFunctions + builInVariables;
return BuilInFunctions() + BuilInVariables();
}