2020-04-15 23:12:07 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
2020-05-23 14:43:57 +02:00
|
|
|
** @file vpcommandline.cpp
|
2020-04-15 23:12:07 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 12 4, 2020
|
|
|
|
**
|
|
|
|
** @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) 2020 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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
2020-05-23 14:43:57 +02:00
|
|
|
#include "vpcommandline.h"
|
2020-05-23 14:12:07 +02:00
|
|
|
#include "vpcommands.h"
|
2020-04-06 23:57:01 +02:00
|
|
|
#include "../vmisc/vsysexits.h"
|
2020-04-12 22:28:36 +02:00
|
|
|
#include "../vmisc/literals.h"
|
2020-04-06 23:57:01 +02:00
|
|
|
#include <QDebug>
|
2020-04-03 22:05:03 +02:00
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
std::shared_ptr<VPCommandLine> VPCommandLine::instance = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
2020-04-06 23:57:01 +02:00
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
#define translate(context, source) QCoreApplication::translate((context), source)// NOLINT(cppcoreguidelines-macro-usage)
|
2020-04-06 23:57:01 +02:00
|
|
|
|
2020-04-13 11:48:09 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
auto VPCommandLine::OptionRawLayouts() const -> QStringList
|
2020-04-13 11:48:09 +02:00
|
|
|
{
|
|
|
|
return OptionValues(LONG_OPTION_RAW_LAYOUT);
|
|
|
|
}
|
|
|
|
|
2020-04-06 23:57:01 +02:00
|
|
|
//--------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
auto VPCommandLine::IsGuiEnabled() const -> bool
|
2020-04-06 23:57:01 +02:00
|
|
|
{
|
|
|
|
return isGuiEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
auto VPCommandLine::OptionFileNames() const -> QStringList
|
2020-04-06 23:57:01 +02:00
|
|
|
{
|
|
|
|
return parser.positionalArguments();
|
|
|
|
}
|
|
|
|
|
2020-04-12 22:28:36 +02:00
|
|
|
//-------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
auto VPCommandLine::IsNoScalingEnabled() const -> bool
|
2020-04-12 22:28:36 +02:00
|
|
|
{
|
|
|
|
return IsOptionSet(LONG_OPTION_NO_HDPI_SCALING);
|
|
|
|
}
|
|
|
|
|
2020-04-21 17:58:01 +02:00
|
|
|
//----------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:43:57 +02:00
|
|
|
void VPCommandLine::ShowHelp(int exitCode)
|
2020-04-21 17:58:01 +02:00
|
|
|
{
|
|
|
|
parser.showHelp(exitCode);
|
|
|
|
}
|
|
|
|
|
2020-04-06 23:57:01 +02:00
|
|
|
//----------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
VPCommandLine::VPCommandLine()
|
2020-04-03 22:05:03 +02:00
|
|
|
{
|
2020-04-06 23:57:01 +02:00
|
|
|
parser.setApplicationDescription(translate("Puzzle", "Valentina's manual layout editor."));
|
2020-04-03 22:05:03 +02:00
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
2020-04-13 11:48:09 +02:00
|
|
|
parser.addPositionalArgument(QStringLiteral("filename"), translate("Puzzle", "The manual layout file."));
|
2020-04-06 23:57:01 +02:00
|
|
|
|
|
|
|
InitCommandLineOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
auto VPCommandLine::Instance() -> VPCommandLinePtr
|
2020-04-14 10:36:21 +02:00
|
|
|
{
|
2021-09-16 13:18:36 +02:00
|
|
|
VPCommandLine::ProcessInstance(instance, QCoreApplication::arguments());
|
2020-04-14 10:36:21 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:43:57 +02:00
|
|
|
void VPCommandLine::ProcessInstance(VPCommandLinePtr &instance, const QStringList &arguments)
|
2020-04-06 23:57:01 +02:00
|
|
|
{
|
|
|
|
if (instance == nullptr)
|
|
|
|
{
|
2020-05-23 14:43:57 +02:00
|
|
|
instance.reset(new VPCommandLine);
|
2020-04-06 23:57:01 +02:00
|
|
|
}
|
2020-04-14 10:36:21 +02:00
|
|
|
instance->parser.process(arguments);
|
2020-04-06 23:57:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------
|
2020-05-23 14:43:57 +02:00
|
|
|
void VPCommandLine::InitCommandLineOptions()
|
2020-04-06 23:57:01 +02:00
|
|
|
{
|
2020-04-13 11:48:09 +02:00
|
|
|
//keep in mind order here - that is how user will see it, so group-up for usability
|
|
|
|
//=================================================================================================================
|
|
|
|
parser.addOptions({
|
|
|
|
{{SINGLE_OPTION_RAW_LAYOUT, LONG_OPTION_RAW_LAYOUT},
|
2022-03-28 16:40:44 +02:00
|
|
|
translate("VCommandLine", "Load pattern pieces from the raw layout data file."),
|
2020-04-13 11:48:09 +02:00
|
|
|
translate("VCommandLine", "The raw layout data file")},
|
|
|
|
{LONG_OPTION_NO_HDPI_SCALING,
|
|
|
|
translate("VCommandLine", "Disable high dpi scaling. Call this option if has problem with scaling (by default "
|
|
|
|
"scaling enabled). Alternatively you can use the %1 environment variable.")
|
|
|
|
.arg(QStringLiteral("QT_AUTO_SCREEN_SCALE_FACTOR=0"))},
|
|
|
|
});
|
2020-04-06 23:57:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
auto VPCommandLine::IsOptionSet(const QString &option) const -> bool
|
2020-04-06 23:57:01 +02:00
|
|
|
{
|
|
|
|
return parser.isSet(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
auto VPCommandLine::OptionValue(const QString &option) const -> QString
|
2020-04-06 23:57:01 +02:00
|
|
|
{
|
|
|
|
return parser.value(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------
|
2022-08-12 17:50:13 +02:00
|
|
|
auto VPCommandLine::OptionValues(const QString &option) const -> QStringList
|
2020-04-06 23:57:01 +02:00
|
|
|
{
|
|
|
|
return parser.values(option);
|
2020-04-03 22:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|