add VPuzzleCommandLine to Puzzleapplication
This commit is contained in:
parent
b88e23697e
commit
e1c945d02c
|
@ -7,7 +7,7 @@
|
||||||
# File with common stuff for whole project
|
# File with common stuff for whole project
|
||||||
include(../../../common.pri)
|
include(../../../common.pri)
|
||||||
|
|
||||||
QT += core gui widgets network xml xmlpatterns printsupport testlib
|
QT += core gui widgets network xml xmlpatterns printsupport
|
||||||
|
|
||||||
# Name of binary file
|
# Name of binary file
|
||||||
TARGET = puzzle
|
TARGET = puzzle
|
||||||
|
|
|
@ -387,6 +387,8 @@ void PuzzleApplication::InitOptions()
|
||||||
|
|
||||||
LoadTranslation(QLocale().name());// By default the console version uses system locale
|
LoadTranslation(QLocale().name());// By default the console version uses system locale
|
||||||
|
|
||||||
|
VPuzzleCommandLine::Instance(*this);
|
||||||
|
|
||||||
static const char * GENERIC_ICON_TO_CHECK = "document-open";
|
static const char * GENERIC_ICON_TO_CHECK = "document-open";
|
||||||
if (QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK) == false)
|
if (QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK) == false)
|
||||||
{
|
{
|
||||||
|
@ -442,24 +444,26 @@ void PuzzleApplication::ActivateDarkMode()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void PuzzleApplication::ParseCommandLine(const SocketConnection &connection, const QStringList &arguments)
|
void PuzzleApplication::ParseCommandLine(const SocketConnection &connection, const QStringList &arguments)
|
||||||
{
|
{
|
||||||
QCommandLineParser parser;
|
std::shared_ptr<VPuzzleCommandLine>cmd = CommandLine();
|
||||||
parser.setApplicationDescription(tr("Valentina's manual layout editor."));
|
// QCommandLineParser parser;
|
||||||
parser.addHelpOption();
|
// parser.setApplicationDescription(tr("Valentina's manual layout editor."));
|
||||||
parser.addVersionOption();
|
// parser.addHelpOption();
|
||||||
parser.addPositionalArgument("filename", tr("The raw layout file."));
|
// parser.addVersionOption();
|
||||||
//-----
|
// parser.addPositionalArgument("filename", tr("The raw layout file."));
|
||||||
QCommandLineOption testOption(QStringList() << "test",
|
// //-----
|
||||||
tr("Use for unit testing. Run the program and open a file without showing the main window."));
|
// QCommandLineOption testOption(QStringList() << "test",
|
||||||
parser.addOption(testOption);
|
// tr("Use for unit testing. Run the program and open a file without showing the main window."));
|
||||||
//-----
|
// parser.addOption(testOption);
|
||||||
QCommandLineOption scalingOption(QStringList() << LONG_OPTION_NO_HDPI_SCALING,
|
// //-----
|
||||||
tr("Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). "
|
// QCommandLineOption scalingOption(QStringList() << LONG_OPTION_NO_HDPI_SCALING,
|
||||||
"Alternatively you can use the %1 environment variable.").arg("QT_AUTO_SCREEN_SCALE_FACTOR=0"));
|
// tr("Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). "
|
||||||
parser.addOption(scalingOption);
|
// "Alternatively you can use the %1 environment variable.").arg("QT_AUTO_SCREEN_SCALE_FACTOR=0"));
|
||||||
//-----
|
// parser.addOption(scalingOption);
|
||||||
parser.process(arguments);
|
// //-----
|
||||||
|
// parser.process(arguments);
|
||||||
|
|
||||||
testMode = parser.isSet(testOption);
|
// testMode = parser.isSet(testOption);
|
||||||
|
testMode = cmd->IsTestModeEnabled();
|
||||||
|
|
||||||
if (not testMode && connection == SocketConnection::Client)
|
if (not testMode && connection == SocketConnection::Client)
|
||||||
{
|
{
|
||||||
|
@ -499,13 +503,14 @@ void PuzzleApplication::ParseCommandLine(const SocketConnection &connection, con
|
||||||
LoadTranslation(PuzzleSettings()->GetLocale());
|
LoadTranslation(PuzzleSettings()->GetLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
const QStringList args = parser.positionalArguments();
|
// const QStringList args = parser.positionalArguments();
|
||||||
|
const QStringList args = cmd->OptionFileNames();
|
||||||
if (args.count() > 0)
|
if (args.count() > 0)
|
||||||
{
|
{
|
||||||
if (testMode && args.count() > 1)
|
if (testMode && args.count() > 1)
|
||||||
{
|
{
|
||||||
qCCritical(mApp, "%s\n", qPrintable(tr("Test mode doesn't support openning several files.")));
|
qCCritical(mApp, "%s\n", qPrintable(tr("Test mode doesn't support openning several files.")));
|
||||||
parser.showHelp(V_EX_USAGE);
|
cmd.get()->parser.showHelp(V_EX_USAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &arg : args)
|
for (auto &arg : args)
|
||||||
|
@ -531,7 +536,7 @@ void PuzzleApplication::ParseCommandLine(const SocketConnection &connection, con
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qCCritical(mApp, "%s\n", qPrintable(tr("Please, provide one input file.")));
|
qCCritical(mApp, "%s\n", qPrintable(tr("Please, provide one input file.")));
|
||||||
parser.showHelp(V_EX_USAGE);
|
cmd.get()->parser.showHelp(V_EX_USAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,3 +639,9 @@ void PuzzleApplication::Clean()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------
|
||||||
|
const std::shared_ptr<VPuzzleCommandLine> PuzzleApplication::CommandLine()
|
||||||
|
{
|
||||||
|
return VPuzzleCommandLine::instance;
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
#include "../vmisc/def.h"
|
#include "../vmisc/def.h"
|
||||||
#include "../vmisc/vpuzzlesettings.h"
|
#include "../vmisc/vpuzzlesettings.h"
|
||||||
#include "../vmisc/vabstractapplication.h"
|
#include "../vmisc/vabstractapplication.h"
|
||||||
|
#include "vpuzzlecommandline.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class PuzzleApplication;// use in define
|
class PuzzleApplication;// use in define
|
||||||
class PuzzleMainWindow;
|
class PuzzleMainWindow;
|
||||||
|
@ -68,7 +71,7 @@ public:
|
||||||
void ActivateDarkMode();
|
void ActivateDarkMode();
|
||||||
|
|
||||||
void ParseCommandLine(const SocketConnection &connection, const QStringList &arguments);
|
void ParseCommandLine(const SocketConnection &connection, const QStringList &arguments);
|
||||||
|
const std::shared_ptr<VPuzzleCommandLine> CommandLine();
|
||||||
public slots:
|
public slots:
|
||||||
void ProcessCMD();
|
void ProcessCMD();
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "vpuzzlecommandline.h"
|
#include "vpuzzlecommandline.h"
|
||||||
#include "../vmisc/commandoptions.h"
|
#include "../vmisc/commandoptions.h"
|
||||||
#include "../vmisc/vsysexits.h"
|
#include "../vmisc/vsysexits.h"
|
||||||
|
#include "../vmisc/literals.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTest>
|
|
||||||
|
|
||||||
std::shared_ptr<VPuzzleCommandLine> VPuzzleCommandLine::instance = nullptr;
|
std::shared_ptr<VPuzzleCommandLine> VPuzzleCommandLine::instance = nullptr;
|
||||||
|
|
||||||
|
@ -57,6 +57,12 @@ QStringList VPuzzleCommandLine::OptionFileNames() const
|
||||||
return parser.positionalArguments();
|
return parser.positionalArguments();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------
|
||||||
|
bool VPuzzleCommandLine::IsNoScalingEnabled() const
|
||||||
|
{
|
||||||
|
return IsOptionSet(LONG_OPTION_NO_HDPI_SCALING);
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------
|
||||||
VPuzzleCommandLine::VPuzzleCommandLine():
|
VPuzzleCommandLine::VPuzzleCommandLine():
|
||||||
parser(),
|
parser(),
|
||||||
|
@ -85,8 +91,6 @@ std::shared_ptr<VPuzzleCommandLine> VPuzzleCommandLine::Instance(const QCoreAppl
|
||||||
//-------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------
|
||||||
void VPuzzleCommandLine::InitCommandLineOptions()
|
void VPuzzleCommandLine::InitCommandLineOptions()
|
||||||
{
|
{
|
||||||
if (IsExportEnabled())
|
|
||||||
{
|
|
||||||
QStringList args = parser.positionalArguments();
|
QStringList args = parser.positionalArguments();
|
||||||
parser.setSingleDashWordOptionMode(
|
parser.setSingleDashWordOptionMode(
|
||||||
QCommandLineParser::SingleDashWordOptionMode(args.takeFirst().toInt()));
|
QCommandLineParser::SingleDashWordOptionMode(args.takeFirst().toInt()));
|
||||||
|
@ -97,11 +101,20 @@ void VPuzzleCommandLine::InitCommandLineOptions()
|
||||||
translate("Puzzle", "The raw layout input file."));
|
translate("Puzzle", "The raw layout input file."));
|
||||||
parser.addPositionalArgument(destination,
|
parser.addPositionalArgument(destination,
|
||||||
translate("Puzzle", "The destination folder"));
|
translate("Puzzle", "The destination folder"));
|
||||||
}
|
|
||||||
|
|
||||||
QCommandLineOption forceOption(QStringList() << "f" << "force",
|
QCommandLineOption forceOption(QStringList() << "f" << "force",
|
||||||
translate("Puzzle", "Overwrite existing files."));
|
translate("Puzzle", "Overwrite existing files."));
|
||||||
parser.addOption(forceOption);
|
parser.addOption(forceOption);
|
||||||
|
|
||||||
|
QCommandLineOption testOption(QStringList() << "test",
|
||||||
|
tr("Use for unit testing. Run the program and open a file without showing the main window."));
|
||||||
|
parser.addOption(testOption);
|
||||||
|
|
||||||
|
QCommandLineOption scalingOption(QStringList() << LONG_OPTION_NO_HDPI_SCALING,
|
||||||
|
tr("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("QT_AUTO_SCREEN_SCALE_FACTOR=0"));
|
||||||
|
parser.addOption(scalingOption);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
class VPuzzleCommandLine: public QObject
|
class VPuzzleCommandLine: public QObject
|
||||||
{
|
{
|
||||||
|
friend class PuzzleApplication;
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
virtual ~VPuzzleCommandLine() = default;
|
virtual ~VPuzzleCommandLine() = default;
|
||||||
|
@ -15,24 +16,34 @@ public:
|
||||||
* @brief if user enabled export from cmd
|
* @brief if user enabled export from cmd
|
||||||
*/
|
*/
|
||||||
bool IsExportEnabled() const;
|
bool IsExportEnabled() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief the base name of layout file or empty string if not
|
* @brief the base name of layout file or empty string if not
|
||||||
*/
|
*/
|
||||||
QString OptionBaseName() const;
|
QString OptionBaseName() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief if user enabled test mode from cmd
|
* @brief if user enabled test mode from cmd
|
||||||
*/
|
*/
|
||||||
bool IsTestModeEnabled() const;
|
bool IsTestModeEnabled() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief if gui enabled or not
|
* @brief if gui enabled or not
|
||||||
*/
|
*/
|
||||||
bool IsGuiEnabled() const;
|
bool IsGuiEnabled() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief the file name which should be loaded
|
* @brief the file name which should be loaded
|
||||||
*/
|
*/
|
||||||
QStringList OptionFileNames() const;
|
QStringList OptionFileNames() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief if high dpi scaling is enabled
|
||||||
|
*/
|
||||||
|
bool IsNoScalingEnabled() const;
|
||||||
protected:
|
protected:
|
||||||
VPuzzleCommandLine();
|
VPuzzleCommandLine();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief create the single instance of the class inside puzzleapplication
|
* @brief create the single instance of the class inside puzzleapplication
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user