Refactoring VPuzzleCommandLine

This commit is contained in:
Ronan Le Tiec 2020-05-23 14:43:57 +02:00
parent fb78189d29
commit 9e532edc1a
6 changed files with 54 additions and 54 deletions

View File

@ -9,9 +9,9 @@ SOURCES += \
$$PWD/vpcarrouselpiece.cpp \
$$PWD/vpcarrouselpiecelist.cpp \
$$PWD/vpcarrouselpiecepreview.cpp \
$$PWD/vpcommandline.cpp \
$$PWD/vpcommands.cpp \
$$PWD/vpmainwindow.cpp \
$$PWD/vpuzzlecommandline.cpp \
$$PWD/vpuzzlegraphicslayout.cpp \
$$PWD/vpuzzlegraphicspiece.cpp \
$$PWD/vpuzzlelayout.cpp \
@ -33,10 +33,10 @@ HEADERS += \
$$PWD/vpcarrouselpiece.h \
$$PWD/vpcarrouselpiecelist.h \
$$PWD/vpcarrouselpiecepreview.h \
$$PWD/vpcommandline.h \
$$PWD/vpcommands.h \
$$PWD/vpmainwindow.h \
$$PWD/vpstable.h \
$$PWD/vpuzzlecommandline.h \
$$PWD/vpuzzlegraphicslayout.h \
$$PWD/vpuzzlegraphicspiece.h \
$$PWD/vpuzzlelayout.h \

View File

@ -335,9 +335,9 @@ VPMainWindow *VPApplication::MainWindow()
Clean();
if (mainWindows.isEmpty())
{
VPuzzleCommandLinePtr cmd;
VPuzzleCommandLine::ProcessInstance(cmd, QStringList());
NewMainWindow(VPuzzleCommandLinePtr());
VPCommandLinePtr cmd;
VPCommandLine::ProcessInstance(cmd, QStringList());
NewMainWindow(VPCommandLinePtr());
}
return mainWindows[0];
}
@ -355,7 +355,7 @@ QList<VPMainWindow *> VPApplication::MainWindows()
}
//---------------------------------------------------------------------------------------------------------------------
VPMainWindow *VPApplication::NewMainWindow(const VPuzzleCommandLinePtr &cmd)
VPMainWindow *VPApplication::NewMainWindow(const VPCommandLinePtr &cmd)
{
VPMainWindow *puzzle = new VPMainWindow(cmd);
mainWindows.prepend(puzzle);
@ -382,7 +382,7 @@ void VPApplication::InitOptions()
LoadTranslation(QLocale().name());// By default the console version uses system locale
VPuzzleCommandLine::Instance(*this);
VPCommandLine::Instance(*this);
static const char * GENERIC_ICON_TO_CHECK = "document-open";
if (QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK) == false)
@ -439,8 +439,8 @@ void VPApplication::ActivateDarkMode()
//---------------------------------------------------------------------------------------------------------------------
void VPApplication::ParseCommandLine(const SocketConnection &connection, const QStringList &arguments)
{
VPuzzleCommandLinePtr cmd;
VPuzzleCommandLine::ProcessInstance(cmd, arguments);
VPCommandLinePtr cmd;
VPCommandLine::ProcessInstance(cmd, arguments);
if (cmd->IsGuiEnabled() && connection == SocketConnection::Client)
{
@ -484,7 +484,7 @@ void VPApplication::ParseCommandLine(const SocketConnection &connection, const Q
}
//---------------------------------------------------------------------------------------------------------------------
void VPApplication::ProcessArguments(const VPuzzleCommandLinePtr &cmd)
void VPApplication::ProcessArguments(const VPCommandLinePtr &cmd)
{
const QStringList rawLayouts = cmd->OptionRawLayouts();
const QStringList args = cmd->OptionFileNames();
@ -638,7 +638,7 @@ void VPApplication::Clean()
}
//--------------------------------------------------------------------------------------------
VPuzzleCommandLinePtr VPApplication::CommandLine() const
VPCommandLinePtr VPApplication::CommandLine() const
{
return VPuzzleCommandLine::instance;
return VPCommandLine::instance;
}

View File

@ -31,7 +31,7 @@
#include "../vmisc/def.h"
#include "vpuzzlesettings.h"
#include "../vmisc/vabstractapplication.h"
#include "vpuzzlecommandline.h"
#include "vpcommandline.h"
#include <memory>
@ -58,7 +58,7 @@ public:
virtual bool IsAppInGUIMode() const override;
VPMainWindow *MainWindow();
QList<VPMainWindow*> MainWindows();
VPMainWindow *NewMainWindow(const VPuzzleCommandLinePtr &cmd);
VPMainWindow *NewMainWindow(const VPCommandLinePtr &cmd);
void InitOptions();
@ -69,8 +69,8 @@ public:
void ActivateDarkMode();
void ParseCommandLine(const SocketConnection &connection, const QStringList &arguments);
void ProcessArguments(const VPuzzleCommandLinePtr &cmd);
VPuzzleCommandLinePtr CommandLine() const;
void ProcessArguments(const VPCommandLinePtr &cmd);
VPCommandLinePtr CommandLine() const;
public slots:
void ProcessCMD();

View File

@ -72,10 +72,10 @@ protected:
private slots:
/**
* @brief on_ActionPieceMovedToLayer Slot called when the piece is moved via the
* context menu to anoter layer
* @brief on_ActionPieceMovedToPieceList Slot called when the piece is moved via the
* context menu to anoter piece list
*/
void on_ActionPieceMovedToLayer();
void on_ActionPieceMovedToPieceList();
private:
Q_DISABLE_COPY(VPCarrouselPiece)

View File

@ -1,6 +1,6 @@
/************************************************************************
**
** @file vpuzzlecommandline.cpp
** @file vpcommandline.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 12 4, 2020
**
@ -25,31 +25,31 @@
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vpuzzlecommandline.h"
#include "vpcommandline.h"
#include "vpcommands.h"
#include "../vmisc/vsysexits.h"
#include "../vmisc/literals.h"
#include <QDebug>
std::shared_ptr<VPuzzleCommandLine> VPuzzleCommandLine::instance = nullptr;
std::shared_ptr<VPCommandLine> VPCommandLine::instance = nullptr;
#define translate(context, source) QCoreApplication::translate((context), source)
//------------------------------------------------------------------------------------------------
bool VPuzzleCommandLine::IsExportEnabled() const
bool VPCommandLine::IsExportEnabled() const
{
const bool result = IsOptionSet(LONG_OPTION_EXPORT_FILE);
int argSize = parser.positionalArguments().size();
if (result && argSize != 1)
{
qCritical() << translate("Puzzle", "Export options can be used with single input file only.") << "/n";
const_cast<VPuzzleCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
const_cast<VPCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
return result;
}
//----------------------------------------------------------------------------------------------
QString VPuzzleCommandLine::OptionExportFile() const
QString VPCommandLine::OptionExportFile() const
{
QString path;
if (IsExportEnabled())
@ -61,49 +61,49 @@ QString VPuzzleCommandLine::OptionExportFile() const
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VPuzzleCommandLine::OptionRawLayouts() const
QStringList VPCommandLine::OptionRawLayouts() const
{
return OptionValues(LONG_OPTION_RAW_LAYOUT);
}
//--------------------------------------------------------------------------------------------
bool VPuzzleCommandLine::IsTestModeEnabled() const
bool VPCommandLine::IsTestModeEnabled() const
{
const bool r = IsOptionSet(LONG_OPTION_TEST);
if (r && parser.positionalArguments().size() != 1)
{
qCritical() << translate("VCommandLine", "Test option can be used with single input file only.") << "/n";
const_cast<VPuzzleCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
const_cast<VPCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
return r;
}
//--------------------------------------------------------------------------------------------
bool VPuzzleCommandLine::IsGuiEnabled() const
bool VPCommandLine::IsGuiEnabled() const
{
return isGuiEnabled;
}
//--------------------------------------------------------------------------------------------
QStringList VPuzzleCommandLine::OptionFileNames() const
QStringList VPCommandLine::OptionFileNames() const
{
return parser.positionalArguments();
}
//-------------------------------------------------------------------------------------------
bool VPuzzleCommandLine::IsNoScalingEnabled() const
bool VPCommandLine::IsNoScalingEnabled() const
{
return IsOptionSet(LONG_OPTION_NO_HDPI_SCALING);
}
//----------------------------------------------------------------------------------------------------------------------
void VPuzzleCommandLine::ShowHelp(int exitCode)
void VPCommandLine::ShowHelp(int exitCode)
{
parser.showHelp(exitCode);
}
//----------------------------------------------------------------------------------------------
VPuzzleCommandLine::VPuzzleCommandLine():
VPCommandLine::VPCommandLine():
parser(),
isGuiEnabled(false)
{
@ -116,18 +116,18 @@ VPuzzleCommandLine::VPuzzleCommandLine():
}
//-------------------------------------------------------------------------------------------
VPuzzleCommandLinePtr VPuzzleCommandLine::Instance(const QCoreApplication &app)
VPCommandLinePtr VPCommandLine::Instance(const QCoreApplication &app)
{
VPuzzleCommandLine::ProcessInstance(instance, app.arguments());
VPCommandLine::ProcessInstance(instance, app.arguments());
return instance;
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleCommandLine::ProcessInstance(VPuzzleCommandLinePtr &instance, const QStringList &arguments)
void VPCommandLine::ProcessInstance(VPCommandLinePtr &instance, const QStringList &arguments)
{
if (instance == nullptr)
{
instance.reset(new VPuzzleCommandLine);
instance.reset(new VPCommandLine);
}
instance->parser.process(arguments);
@ -135,7 +135,7 @@ void VPuzzleCommandLine::ProcessInstance(VPuzzleCommandLinePtr &instance, const
}
//-------------------------------------------------------------------------------------------
void VPuzzleCommandLine::InitCommandLineOptions()
void VPCommandLine::InitCommandLineOptions()
{
//keep in mind order here - that is how user will see it, so group-up for usability
//=================================================================================================================
@ -193,19 +193,19 @@ void VPuzzleCommandLine::InitCommandLineOptions()
}
//--------------------------------------------------------------------------------------------
bool VPuzzleCommandLine::IsOptionSet(const QString &option) const
bool VPCommandLine::IsOptionSet(const QString &option) const
{
return parser.isSet(option);
}
//-------------------------------------------------------------------------------------------
QString VPuzzleCommandLine::OptionValue(const QString &option) const
QString VPCommandLine::OptionValue(const QString &option) const
{
return parser.value(option);
}
//--------------------------------------------------------------------------------------------
QStringList VPuzzleCommandLine::OptionValues(const QString &option) const
QStringList VPCommandLine::OptionValues(const QString &option) const
{
return parser.values(option);
}

View File

@ -1,6 +1,6 @@
/************************************************************************
**
** @file vpuzzlecommandline.h
** @file vpcommandline.h
** @author Dmytro Hladkykh <vorzelmir@gmail.com>
** @date 12 4, 2020
**
@ -25,21 +25,21 @@
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VPUZZLECOMMANDLINE_H
#define VPUZZLECOMMANDLINE_H
#ifndef VPCOMMANDLINE_H
#define VPCOMMANDLINE_H
#include <memory>
#include <QCoreApplication>
#include <QCommandLineParser>
class VPuzzleCommandLine;
using VPuzzleCommandLinePtr = std::shared_ptr<VPuzzleCommandLine>;
class VPCommandLine;
using VPCommandLinePtr = std::shared_ptr<VPCommandLine>;
class VPuzzleCommandLine: public QObject
class VPCommandLine: public QObject
{
Q_OBJECT
public:
virtual ~VPuzzleCommandLine() = default;
virtual ~VPCommandLine() = default;
/** @brief if user enabled export from cmd */
bool IsExportEnabled() const;
@ -64,14 +64,14 @@ public:
Q_NORETURN void ShowHelp(int exitCode = 0);
protected:
VPuzzleCommandLine();
VPCommandLine();
/** @brief create the single instance of the class inside vpapplication */
static VPuzzleCommandLinePtr Instance(const QCoreApplication &app);
static void ProcessInstance(VPuzzleCommandLinePtr &instance, const QStringList &arguments);
static VPCommandLinePtr Instance(const QCoreApplication &app);
static void ProcessInstance(VPCommandLinePtr &instance, const QStringList &arguments);
private:
Q_DISABLE_COPY(VPuzzleCommandLine)
static VPuzzleCommandLinePtr instance;
Q_DISABLE_COPY(VPCommandLine)
static VPCommandLinePtr instance;
QCommandLineParser parser;
bool isGuiEnabled;
friend class VPApplication;
@ -84,4 +84,4 @@ private:
QStringList OptionValues(const QString &option) const;
};
#endif // VPUZZLECOMMANDLINE_H
#endif // VPCOMMANDLINE_H