Issue #334 mostly with minor neccessary changes, all options implemented
for command line, disabled gui popups when command line detected. --HG-- branch : develop
This commit is contained in:
parent
3adeed1896
commit
799d5d1dc2
|
@ -21,7 +21,6 @@ HEADERS += \
|
||||||
$$PWD/stable.h \
|
$$PWD/stable.h \
|
||||||
$$PWD/version.h \
|
$$PWD/version.h \
|
||||||
$$PWD/mainwindowsnogui.h
|
$$PWD/mainwindowsnogui.h
|
||||||
|
|
||||||
# Main forms
|
# Main forms
|
||||||
FORMS += \
|
FORMS += \
|
||||||
$$PWD/mainwindow.ui
|
$$PWD/mainwindow.ui
|
||||||
|
|
|
@ -108,6 +108,8 @@ CONFIG(debug, debug|release){
|
||||||
# -isystem key works only for headers. In some cases it's not enough. But we can't delete this warnings and
|
# -isystem key works only for headers. In some cases it's not enough. But we can't delete this warnings and
|
||||||
# want them in global list. Compromise decision delete them from local list.
|
# want them in global list. Compromise decision delete them from local list.
|
||||||
QMAKE_CXXFLAGS -= \
|
QMAKE_CXXFLAGS -= \
|
||||||
|
-Wuninitialized \
|
||||||
|
-Winit-self \
|
||||||
-Wmissing-prototypes \
|
-Wmissing-prototypes \
|
||||||
-Wundefined-reinterpret-cast
|
-Wundefined-reinterpret-cast
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,12 @@ HEADERS += \
|
||||||
$$PWD/vapplication.h \
|
$$PWD/vapplication.h \
|
||||||
$$PWD/vformulaproperty.h \
|
$$PWD/vformulaproperty.h \
|
||||||
$$PWD/vformulapropertyeditor.h \
|
$$PWD/vformulapropertyeditor.h \
|
||||||
$$PWD/vtooloptionspropertybrowser.h
|
$$PWD/vtooloptionspropertybrowser.h \
|
||||||
|
$$PWD/vcmdexport.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/vapplication.cpp \
|
$$PWD/vapplication.cpp \
|
||||||
$$PWD/vformulaproperty.cpp \
|
$$PWD/vformulaproperty.cpp \
|
||||||
$$PWD/vformulapropertyeditor.cpp \
|
$$PWD/vformulapropertyeditor.cpp \
|
||||||
$$PWD/vtooloptionspropertybrowser.cpp
|
$$PWD/vtooloptionspropertybrowser.cpp \
|
||||||
|
$$PWD/vcmdexport.cpp
|
||||||
|
|
|
@ -48,6 +48,8 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
||||||
# include <QLockFile>
|
# include <QLockFile>
|
||||||
#endif
|
#endif
|
||||||
|
@ -87,8 +89,11 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
|
||||||
QCoreApplication *instance = QCoreApplication::instance();
|
QCoreApplication *instance = QCoreApplication::instance();
|
||||||
const bool isGuiThread = instance && (QThread::currentThread() == instance->thread());
|
const bool isGuiThread = instance && (QThread::currentThread() == instance->thread());
|
||||||
|
|
||||||
|
|
||||||
if (isGuiThread)
|
if (isGuiThread)
|
||||||
{
|
{
|
||||||
|
//fixme: trying to make sure there are no save/load dialogs are opened, because error message during them will lead to crash
|
||||||
|
const bool topWinAllowsPop = (qApp->activeModalWidget() == nullptr) || !qApp->activeModalWidget()->inherits("QFileDialog");
|
||||||
QString debugdate = "[" + QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss");
|
QString debugdate = "[" + QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss");
|
||||||
QMessageBox messageBox;
|
QMessageBox messageBox;
|
||||||
switch (type)
|
switch (type)
|
||||||
|
@ -119,6 +124,11 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
|
||||||
(*qApp->LogFile()) << debugdate << endl;
|
(*qApp->LogFile()) << debugdate << endl;
|
||||||
|
|
||||||
if (type == QtWarningMsg || type == QtCriticalMsg || type == QtFatalMsg)
|
if (type == QtWarningMsg || type == QtCriticalMsg || type == QtFatalMsg)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (VApplication::CheckGUI())
|
||||||
|
{
|
||||||
|
if (topWinAllowsPop)
|
||||||
{
|
{
|
||||||
messageBox.setInformativeText(msg);
|
messageBox.setInformativeText(msg);
|
||||||
messageBox.setStandardButtons(QMessageBox::Ok);
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
||||||
|
@ -126,6 +136,12 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
|
||||||
messageBox.setModal(true);
|
messageBox.setModal(true);
|
||||||
messageBox.exec();
|
messageBox.exec();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qStdErr() << msg << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (QtFatalMsg == type)
|
if (QtFatalMsg == type)
|
||||||
{
|
{
|
||||||
|
@ -165,6 +181,8 @@ VApplication::VApplication(int &argc, char **argv)
|
||||||
out(nullptr)
|
out(nullptr)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
VCommandLine::Reset(); // making sure will create new instance...just in case we will ever do 2 objects of VApplication
|
||||||
|
VCommandLine::Get(*this);
|
||||||
undoStack = new QUndoStack(this);
|
undoStack = new QUndoStack(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,8 +201,8 @@ VApplication::~VApplication()
|
||||||
delete logLock;
|
delete logLock;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
delete trVars;
|
delete trVars;
|
||||||
|
VCommandLine::Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -374,6 +392,7 @@ void VApplication::BeginLogging()
|
||||||
{
|
{
|
||||||
out = new QTextStream(log);
|
out = new QTextStream(log);
|
||||||
qInstallMessageHandler(noisyFailureMsgHandler);
|
qInstallMessageHandler(noisyFailureMsgHandler);
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
||||||
logLock = new QLockFile(LogPath()+".lock");
|
logLock = new QLockFile(LogPath()+".lock");
|
||||||
logLock->setStaleLockTime(0);
|
logLock->setStaleLockTime(0);
|
||||||
|
@ -578,6 +597,17 @@ void VApplication::InitTrVars()
|
||||||
{
|
{
|
||||||
trVars = new VTranslateVars(Settings());
|
trVars = new VTranslateVars(Settings());
|
||||||
}
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool VApplication::CheckGUI()
|
||||||
|
{
|
||||||
|
return (VCommandLine::instance != nullptr) && VCommandLine::instance->IsGuiEnabled();
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
const VCommandLinePtr VApplication::CommandLine() const
|
||||||
|
{
|
||||||
|
return VCommandLine::instance;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
#include "../libs/vwidgets/vmaingraphicsview.h"
|
#include "../libs/vwidgets/vmaingraphicsview.h"
|
||||||
#include "../libs/vpatterndb/vtranslatevars.h"
|
#include "../libs/vpatterndb/vtranslatevars.h"
|
||||||
#include "vsettings.h"
|
#include "vsettings.h"
|
||||||
|
#include "vcmdexport.h"
|
||||||
|
|
||||||
|
|
||||||
class VApplication;// use in define
|
class VApplication;// use in define
|
||||||
class VMainGraphicsView;
|
class VMainGraphicsView;
|
||||||
|
@ -55,6 +57,7 @@ class VApplication : public VAbstractApplication
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VApplication(int &argc, char ** argv);
|
VApplication(int &argc, char ** argv);
|
||||||
virtual ~VApplication() Q_DECL_OVERRIDE;
|
virtual ~VApplication() Q_DECL_OVERRIDE;
|
||||||
static void NewValentina(const QString &fileName = QString());
|
static void NewValentina(const QString &fileName = QString());
|
||||||
|
@ -83,7 +86,10 @@ public:
|
||||||
static void DrMingw();
|
static void DrMingw();
|
||||||
void CollectReports() const;
|
void CollectReports() const;
|
||||||
#endif // defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
#endif // defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
||||||
|
bool static CheckGUI();
|
||||||
|
|
||||||
|
|
||||||
|
const VCommandLinePtr CommandLine() const;
|
||||||
private slots:
|
private slots:
|
||||||
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
||||||
void CleanGist() const;
|
void CleanGist() const;
|
||||||
|
@ -129,5 +135,7 @@ inline void VApplication::setAutoSaveTimer(QTimer *value)
|
||||||
{
|
{
|
||||||
autoSaveTimer = value;
|
autoSaveTimer = value;
|
||||||
}
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
#endif // VAPPLICATION_H
|
#endif // VAPPLICATION_H
|
||||||
|
|
318
src/app/core/vcmdexport.cpp
Normal file
318
src/app/core/vcmdexport.cpp
Normal file
|
@ -0,0 +1,318 @@
|
||||||
|
#include "vcmdexport.h"
|
||||||
|
#include "dialogs/dialoglayoutsettings.h"
|
||||||
|
#include "dialogs/dialogsavelayout.h"
|
||||||
|
#include "xml/vdomdocument.h"
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
||||||
|
# include "../libs/vmisc/backport/qcommandlineparser.h"
|
||||||
|
#else
|
||||||
|
# include <QCommandLineParser>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
VCommandLinePtr VCommandLine::instance = nullptr;
|
||||||
|
|
||||||
|
const static auto OPTION_OUTFILE = QStringLiteral("outfile");
|
||||||
|
const static auto OPTION_MEASUREFILE = QStringLiteral("mfile");
|
||||||
|
const static auto OPTION_PAGETEMPLATE = QStringLiteral("pageformat");
|
||||||
|
const static auto OPTION_EXP2FORMAT = QStringLiteral("format");
|
||||||
|
const static auto OPTION_ROTATE = QStringLiteral("rotate");
|
||||||
|
const static auto OPTION_CROP = QStringLiteral("crop");
|
||||||
|
const static auto OPTION_UNITE = QStringLiteral("unite");
|
||||||
|
|
||||||
|
const static auto OPTION_PAGEW = QStringLiteral("pagew");
|
||||||
|
const static auto OPTION_PAGEH = QStringLiteral("pageh");
|
||||||
|
const static auto OPTION_PAGEUNITS = QStringLiteral("pageunits");
|
||||||
|
|
||||||
|
const static auto OPTION_SAVELENGTH = QStringLiteral("savelen");
|
||||||
|
const static auto OPTION_SHIFTLENGTH = QStringLiteral("shiftlen");
|
||||||
|
const static auto OPTION_SHIFTUNITS = QStringLiteral("layounits");
|
||||||
|
const static auto OPTION_GAPWIDTH = QStringLiteral("gapwidth");
|
||||||
|
const static auto OPTION_GROUPPING = QStringLiteral("groups");
|
||||||
|
|
||||||
|
#define tr(A) QCoreApplication::translate("VCommandLine",(A))
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//such a tricky initialization is used, because it uses static functions which relay on static variables and order of initialization is not defined between compiled units.
|
||||||
|
//i.e. - segv is possible (I hit it when VDomDocument::UnitsHelpString() was crashing because of not inited string vars).
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
VCommandLine::VCommandLine() : parser()
|
||||||
|
, optionsUsed ({
|
||||||
|
QCommandLineOption(OPTION_OUTFILE, tr("Path to output exported layout file. Use it to enable console export mode."), OPTION_OUTFILE),
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_MEASUREFILE, tr("Path to custom measure file (export mode)."), OPTION_MEASUREFILE),
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_EXP2FORMAT, tr("Number corresponding to output format (default = 0, export mode): ") +
|
||||||
|
DialogSaveLayout::MakeHelpFormatList(), OPTION_EXP2FORMAT, "0"),
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_PAGETEMPLATE, tr("Number corresponding to page template (default = 0, export mode): ")+
|
||||||
|
DialogLayoutSettings::MakeHelpTemplateList(), OPTION_PAGETEMPLATE, "0"),
|
||||||
|
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_PAGEW, tr("Page width in current units like 12.0 (cannot be used with \"")+OPTION_PAGETEMPLATE+tr("\", export mode)."), OPTION_PAGEW),
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_PAGEH, tr("Page height in current units like 12.0 (cannot be used with \"")+OPTION_PAGETEMPLATE+tr("\", export mode)."), OPTION_PAGEH),
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_PAGEUNITS, tr("Page height/width measure units (cannot be used with \"")+
|
||||||
|
OPTION_PAGETEMPLATE+tr("\", export mode): ") + VDomDocument::UnitsHelpString(), OPTION_PAGEUNITS),
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_ROTATE, tr("Rotation in degrees (one of predefined). Default (or 0) is no-rotate (export mode)."), OPTION_ROTATE),
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_CROP, tr("Auto crop unused length (export mode).")),
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_UNITE, tr("Unite pages if possible (export mode).")),
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_SAVELENGTH, tr("Save length of the sheet if set. (export mode).")),
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_SHIFTUNITS, tr("Layout units (as paper's one except px, export mode)."), OPTION_SHIFTUNITS),
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_SHIFTLENGTH, tr("Shift layout length measured in layout units (export mode)."), OPTION_SHIFTLENGTH),
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_GAPWIDTH, tr("Gap width x2, measured in layout units. (export mode)."), OPTION_GAPWIDTH),
|
||||||
|
|
||||||
|
QCommandLineOption(OPTION_GROUPPING, tr("Sets layout groupping (export mode): ") + DialogLayoutSettings::MakeGroupsHelp(), OPTION_GROUPPING, "2"),
|
||||||
|
}),
|
||||||
|
isGuiEnabled(false)
|
||||||
|
{
|
||||||
|
parser.setApplicationDescription(QCoreApplication::translate("main", "Pattern making program."));
|
||||||
|
parser.addHelpOption();
|
||||||
|
parser.addVersionOption();
|
||||||
|
parser.addPositionalArgument("filename", QCoreApplication::translate("main", "Pattern file."));
|
||||||
|
|
||||||
|
foreach(const auto& o, optionsUsed)
|
||||||
|
{
|
||||||
|
parser.addOption(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
int VCommandLine::Lo2Px(const QString &src, const DialogLayoutSettings &converter)
|
||||||
|
{
|
||||||
|
//that is dirty-dirty hack ...eventually number is converted float <--> int 3 or 4 times including inside dialog ... that will loose precision for sure
|
||||||
|
return converter.LayoutToPixels(src.toFloat());
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
int VCommandLine::Pg2Px(const QString& src, const DialogLayoutSettings& converter)
|
||||||
|
{
|
||||||
|
return converter.PageToPixels(src.toFloat());
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
|
||||||
|
{
|
||||||
|
//this functions covers all options found into layout setup dialog, nothing to add here, unless dialog extended
|
||||||
|
|
||||||
|
VLayoutGeneratorPtr res(new VLayoutGenerator());
|
||||||
|
DialogLayoutSettings diag(res.get(), nullptr, true);
|
||||||
|
|
||||||
|
{
|
||||||
|
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
|
||||||
|
bool x = parser.isSet(OPTION_PAGETEMPLATE);
|
||||||
|
|
||||||
|
bool a = parser.isSet(OPTION_PAGEH);
|
||||||
|
bool b = parser.isSet(OPTION_PAGEW);
|
||||||
|
bool c = parser.isSet(OPTION_PAGEUNITS);
|
||||||
|
|
||||||
|
if ((a || b || c) && x)
|
||||||
|
{
|
||||||
|
Error(tr("Cannot use pageformat and page explicit size/units together."));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((a || b || c) && !(a && b && c))
|
||||||
|
{
|
||||||
|
Error(tr("Page height, width, units must be used all 3 at once."));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//fixme: not really sure ...if shift length must be set with shift units ...or separated, will comment for now. Uncomment if need them both only.
|
||||||
|
|
||||||
|
// {
|
||||||
|
// //just anonymous namespace ...don' like to have a,b,c,d everywhere defined
|
||||||
|
// bool a = parser.isSet(OPTION_SHIFTLENGTH);
|
||||||
|
// bool b = parser.isSet(OPTION_SHIFTUNITS);
|
||||||
|
|
||||||
|
// if ((a || b) && !(a && b))
|
||||||
|
// {
|
||||||
|
// Error(tr("Shift length must be used together with shift units."));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
int rotateDegree = OptRotation();
|
||||||
|
diag.SetRotate(rotateDegree != 0 );
|
||||||
|
|
||||||
|
if (rotateDegree != 0)
|
||||||
|
{
|
||||||
|
if (!diag.SetIncrease(rotateDegree))
|
||||||
|
{
|
||||||
|
Error(tr("Invalid rotation value. That must be one of predefined values."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if present units MUST be set before any other to keep conversions correct
|
||||||
|
if (!diag.SelectTemplate(OptPaperSize()))
|
||||||
|
{
|
||||||
|
Error(tr("Unknown page templated selected."));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser.isSet(OPTION_PAGEH)) //at this point we already sure 3 are set or none
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!diag.SelectPaperUnit(parser.value(OPTION_PAGEUNITS)))
|
||||||
|
{
|
||||||
|
Error(tr("Unsupported paper units."));
|
||||||
|
}
|
||||||
|
|
||||||
|
diag.SetPaperHeight (Pg2Px(parser.value(OPTION_PAGEH), diag));
|
||||||
|
diag.SetPaperWidth (Pg2Px(parser.value(OPTION_PAGEW), diag));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser.isSet(OPTION_SHIFTUNITS))
|
||||||
|
{
|
||||||
|
if (!diag.SelectLayoutUnit(parser.value(OPTION_SHIFTUNITS)))
|
||||||
|
{
|
||||||
|
Error(tr("Unsupported layout units."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser.isSet(OPTION_SHIFTLENGTH))
|
||||||
|
{
|
||||||
|
|
||||||
|
diag.SetShift(Lo2Px(parser.value(OPTION_SHIFTLENGTH), diag));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser.isSet(OPTION_GAPWIDTH))
|
||||||
|
{
|
||||||
|
diag.SetLayoutWidth(Lo2Px(parser.value(OPTION_GAPWIDTH), diag));
|
||||||
|
}
|
||||||
|
|
||||||
|
diag.SetAutoCrop(parser.isSet(OPTION_CROP));
|
||||||
|
diag.SetUnitePages(parser.isSet(OPTION_UNITE));
|
||||||
|
diag.SetSaveLength(parser.isSet(OPTION_SAVELENGTH));
|
||||||
|
diag.SetGroup(OptGroup());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
diag.DialogAccepted(); // filling VLayoutGenerator
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
VCommandLinePtr VCommandLine::Get(const QCoreApplication& app)
|
||||||
|
{
|
||||||
|
if (instance == nullptr)
|
||||||
|
{
|
||||||
|
instance.reset(new VCommandLine());
|
||||||
|
}
|
||||||
|
instance->parser.process(app);
|
||||||
|
|
||||||
|
//fixme: in case of additional options/modes which will need to disable GUI - add it here too
|
||||||
|
instance->isGuiEnabled = !instance->IsExportEnabled();
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
NORET_ATTR void VCommandLine::Error(const QString &text) const
|
||||||
|
{
|
||||||
|
qStdErr() << text << "\n";
|
||||||
|
const_cast<VCommandLine*>(this)->parser.showHelp(FAILED_HELP_SHOWN_STATUS);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
void VCommandLine::Reset()
|
||||||
|
{
|
||||||
|
instance.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
bool VCommandLine::IsExportEnabled() const
|
||||||
|
{
|
||||||
|
bool r = parser.isSet(OPTION_OUTFILE);
|
||||||
|
if (r && parser.positionalArguments().size() != 1)
|
||||||
|
{
|
||||||
|
Error(tr("Export options can be used with single input file only."));
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
DialogLayoutSettings::PaperSizeTemplate VCommandLine::OptPaperSize() const
|
||||||
|
{
|
||||||
|
int ppsize = 0;
|
||||||
|
if (parser.isSet(OPTION_PAGETEMPLATE))
|
||||||
|
{
|
||||||
|
ppsize = parser.value(OPTION_PAGETEMPLATE).toInt();
|
||||||
|
}
|
||||||
|
return static_cast<DialogLayoutSettings::PaperSizeTemplate>(ppsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
int VCommandLine::OptRotation() const
|
||||||
|
{
|
||||||
|
int rotate = 0;
|
||||||
|
if (parser.isSet(OPTION_ROTATE))
|
||||||
|
{
|
||||||
|
rotate = parser.value(OPTION_ROTATE).toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rotate;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
Cases VCommandLine::OptGroup() const
|
||||||
|
{
|
||||||
|
int r = parser.value(OPTION_GROUPPING).toInt();
|
||||||
|
if ( r < 0 || r >= static_cast<int>(Cases::UnknownCase))
|
||||||
|
{
|
||||||
|
r = 0;
|
||||||
|
}
|
||||||
|
return static_cast<Cases>(r);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
QString VCommandLine::OptMeasurePath() const
|
||||||
|
{
|
||||||
|
QString measure;
|
||||||
|
if (parser.isSet(OPTION_MEASUREFILE)
|
||||||
|
&& IsExportEnabled() //todo: don't want yet to allow user set measure file for general loading, because need to fix multiply opened windows as well
|
||||||
|
)
|
||||||
|
{
|
||||||
|
measure = parser.value(OPTION_MEASUREFILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return measure;
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
QString VCommandLine::OptExportPath() const
|
||||||
|
{
|
||||||
|
QString path;
|
||||||
|
if (IsExportEnabled())
|
||||||
|
{
|
||||||
|
path = parser.value(OPTION_OUTFILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
int VCommandLine::OptExportType() const
|
||||||
|
{
|
||||||
|
int r = 0;
|
||||||
|
if (parser.isSet(OPTION_EXP2FORMAT))
|
||||||
|
{
|
||||||
|
r = parser.value(OPTION_EXP2FORMAT).toInt();
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
QStringList VCommandLine::OptInputFileNames() const
|
||||||
|
{
|
||||||
|
return parser.positionalArguments();
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
bool VCommandLine::IsGuiEnabled() const
|
||||||
|
{
|
||||||
|
return isGuiEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
#undef tr
|
104
src/app/core/vcmdexport.h
Normal file
104
src/app/core/vcmdexport.h
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
#ifndef VCMDEXPORT_H
|
||||||
|
#define VCMDEXPORT_H
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "dialogs/dialoglayoutsettings.h"
|
||||||
|
|
||||||
|
|
||||||
|
constexpr auto GENERAL_ERROR_STATUS = 255;
|
||||||
|
constexpr auto INVALID_PARAMS_STATUS = 254;
|
||||||
|
constexpr auto FAILED_TO_GEN_LAYOUT_STATUS = 253;
|
||||||
|
constexpr auto FAILED_HELP_SHOWN_STATUS = 250;
|
||||||
|
|
||||||
|
//making QtCReator happy....[[noreturn]] is part of C++11 standard
|
||||||
|
//http://en.cppreference.com/w/cpp/language/attributes
|
||||||
|
|
||||||
|
#define NORET_ATTR [[noreturn]]
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline QTextStream& qStdErr()
|
||||||
|
{
|
||||||
|
static QTextStream ts( stderr );
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
NORET_ATTR inline void AppAbort(const QString& text, int code = GENERAL_ERROR_STATUS)
|
||||||
|
{
|
||||||
|
//well ..std::runtime_error was leading to zombies in memory and a lot of dumping all the time ...better to do just exit
|
||||||
|
//possibly compiler do not have -fexceptions set
|
||||||
|
qStdErr() << text << "\n";
|
||||||
|
std::exit(code);
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class VCommandLine;
|
||||||
|
typedef std::shared_ptr<VCommandLine> VCommandLinePtr;
|
||||||
|
|
||||||
|
//@brief: class used to install export command line options and parse their values
|
||||||
|
//QCommandLineParser* object must exists until this object alive
|
||||||
|
class VCommandLine
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static VCommandLinePtr instance;
|
||||||
|
QCommandLineParser parser;
|
||||||
|
const std::vector<QCommandLineOption> optionsUsed;
|
||||||
|
bool isGuiEnabled;
|
||||||
|
friend class VApplication;
|
||||||
|
|
||||||
|
static int Lo2Px(const QString& src, const DialogLayoutSettings& converter);
|
||||||
|
static int Pg2Px(const QString& src, const DialogLayoutSettings& converter);
|
||||||
|
protected:
|
||||||
|
|
||||||
|
explicit VCommandLine();
|
||||||
|
|
||||||
|
|
||||||
|
//@brief returns DialogLayoutSettings::PaperSizeTemplate
|
||||||
|
DialogLayoutSettings::PaperSizeTemplate OptPaperSize() const;
|
||||||
|
//@brief returns rotation in degrees or 0 if not set
|
||||||
|
int OptRotation() const;
|
||||||
|
|
||||||
|
Cases OptGroup() const;
|
||||||
|
|
||||||
|
//@brief convinient shortcut to show error and help and exit
|
||||||
|
NORET_ATTR void Error(const QString& text) const;
|
||||||
|
|
||||||
|
//@brief: called in destructor of application, so instance destroyed and new maybe created (never happen scenario though)
|
||||||
|
static void Reset();
|
||||||
|
|
||||||
|
//@brief called to create single object, by VApplication only
|
||||||
|
static VCommandLinePtr Get(const QCoreApplication& app);
|
||||||
|
|
||||||
|
public:
|
||||||
|
VCommandLine(const VCommandLine&) = delete;
|
||||||
|
VCommandLine& operator =(const VCommandLine&) = delete;
|
||||||
|
virtual ~VCommandLine(){}
|
||||||
|
|
||||||
|
//@brief creates object and applies export related options to parser
|
||||||
|
|
||||||
|
//@brief tests if user enabled export from cmd, throws exception if not exactly 1 input VAL file supplied in case export enabled
|
||||||
|
bool IsExportEnabled() const;
|
||||||
|
|
||||||
|
//@brief returns path to custom measure file or empty string
|
||||||
|
QString OptMeasurePath() const;
|
||||||
|
|
||||||
|
//@brief returns export path or empty string if not set
|
||||||
|
QString OptExportPath() const;
|
||||||
|
|
||||||
|
//@brief returns export type set, defaults 0 - svg
|
||||||
|
int OptExportType() const;
|
||||||
|
|
||||||
|
//generator creation is moved here ... because most options are for it only, so no need to create extra getters...
|
||||||
|
//@brief creates VLayoutGenerator
|
||||||
|
VLayoutGeneratorPtr DefaultGenerator() const;
|
||||||
|
|
||||||
|
//@brief gets filenames which should be loaded
|
||||||
|
QStringList OptInputFileNames() const;
|
||||||
|
|
||||||
|
bool IsGuiEnabled()const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VCMDEXPORT_H
|
|
@ -31,7 +31,7 @@
|
||||||
#include "../core/vapplication.h"
|
#include "../core/vapplication.h"
|
||||||
#include "../../libs/ifc/xml/vdomdocument.h"
|
#include "../../libs/ifc/xml/vdomdocument.h"
|
||||||
#include "../../libs/vmisc/vsettings.h"
|
#include "../../libs/vmisc/vsettings.h"
|
||||||
#include "../../libs/vlayout/vlayoutgenerator.h"
|
#include <vector>
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
||||||
# include "../../libs/vmisc/vmath.h"
|
# include "../../libs/vmisc/vmath.h"
|
||||||
|
@ -41,20 +41,48 @@
|
||||||
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
|
//must be the same order as PaperSizeTemplate constants
|
||||||
enum class PaperSizeTemplate : char { A0, A1, A2, A3, A4, Letter, Legal, Roll24in, Roll30in, Roll36in, Roll42in,
|
const DialogLayoutSettings::FormatsVector DialogLayoutSettings::pageFormatNames={
|
||||||
Roll44in};
|
"A0",
|
||||||
|
"A1",
|
||||||
|
"A2",
|
||||||
|
"A3",
|
||||||
|
"A4",
|
||||||
|
tr("Letter"),
|
||||||
|
tr("Legal"),
|
||||||
|
tr("Roll 24in"),
|
||||||
|
tr("Roll 30in"),
|
||||||
|
tr("Roll 36in"),
|
||||||
|
tr("Roll 42in"),
|
||||||
|
tr("Roll 44in"),
|
||||||
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent)
|
DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent, bool disableSetting)
|
||||||
: QDialog(parent), ui(new Ui::DialogLayoutSettings), oldPaperUnit(Unit::Mm), oldLayoutUnit(Unit::Mm),
|
: QDialog(parent), disableSettings(disableSetting),ui(new Ui::DialogLayoutSettings), oldPaperUnit(Unit::Mm), oldLayoutUnit(Unit::Mm),
|
||||||
generator(generator)
|
generator(generator)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
qApp->Settings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale(QLocale::C));
|
qApp->Settings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale(QLocale::C));
|
||||||
|
|
||||||
|
//moved from ReadSettings - well...it seems it can be done once only (i.e. constructor) because Init funcs dont even cleanse lists before adding
|
||||||
|
InitPaperUnits();
|
||||||
|
InitLayoutUnits();
|
||||||
|
InitTemplates();
|
||||||
|
MinimumPaperSize();
|
||||||
|
MinimumLayoutSize();
|
||||||
|
|
||||||
|
//in export console mode going to use defaults
|
||||||
|
if (!disableSettings)
|
||||||
|
{
|
||||||
ReadSettings();
|
ReadSettings();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RestoreDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
connect(ui->comboBoxTemplates, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
connect(ui->comboBoxTemplates, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||||
this, &DialogLayoutSettings::TemplateSelected);
|
this, &DialogLayoutSettings::TemplateSelected);
|
||||||
|
@ -193,16 +221,17 @@ int DialogLayoutSettings::GetIncrease() const
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void DialogLayoutSettings::SetIncrease(int increase)
|
bool DialogLayoutSettings::SetIncrease(int increase)
|
||||||
{
|
{
|
||||||
int index = ui->comboBoxIncrease->findText(QString::number(increase));
|
int index = ui->comboBoxIncrease->findText(QString::number(increase));
|
||||||
|
bool failed = (index == -1);
|
||||||
if (index == -1)
|
if (failed)
|
||||||
{
|
{
|
||||||
index = 21;//180 degree
|
index = 21;//180 degree
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->comboBoxIncrease->setCurrentIndex(index);
|
ui->comboBoxIncrease->setCurrentIndex(index);
|
||||||
|
return failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -240,7 +269,6 @@ void DialogLayoutSettings::SetUnitePages(bool save)
|
||||||
{
|
{
|
||||||
ui->checkBoxUnitePages->setChecked(save);
|
ui->checkBoxUnitePages->setChecked(save);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void DialogLayoutSettings::TemplateSelected()
|
void DialogLayoutSettings::TemplateSelected()
|
||||||
{
|
{
|
||||||
|
@ -266,6 +294,43 @@ void DialogLayoutSettings::ConvertPaperSize()
|
||||||
MinimumPaperSize();
|
MinimumPaperSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool DialogLayoutSettings::SelectPaperUnit(const QString& units)
|
||||||
|
{
|
||||||
|
qint32 indexUnit = ui->comboBoxPaperSizeUnit->findData(units);
|
||||||
|
if (indexUnit != -1)
|
||||||
|
{
|
||||||
|
ui->comboBoxPaperSizeUnit->setCurrentIndex(indexUnit);
|
||||||
|
}
|
||||||
|
return indexUnit != -1;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool DialogLayoutSettings::SelectLayoutUnit(const QString &units)
|
||||||
|
{
|
||||||
|
qint32 indexUnit = ui->comboBoxLayoutUnit->findData(units);
|
||||||
|
if (indexUnit != -1)
|
||||||
|
{
|
||||||
|
ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit);
|
||||||
|
}
|
||||||
|
return indexUnit != -1;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
int DialogLayoutSettings::LayoutToPixels(qreal value) const
|
||||||
|
{
|
||||||
|
return static_cast<quint32>(qFloor(UnitConvertor(value, LayoutUnit(), Unit::Px)));
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
int DialogLayoutSettings::PageToPixels(qreal value) const
|
||||||
|
{
|
||||||
|
return static_cast<quint32>(qFloor(UnitConvertor(value, PaperUnit(), Unit::Px)));
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QString DialogLayoutSettings::MakeGroupsHelp()
|
||||||
|
{
|
||||||
|
//that is REALLY dummy ... can't figure fast how to automate generation... :/
|
||||||
|
return tr("\n\tThree groups: big, middle, small = 0\n\tTwo groups: big, small = 1\n\tDescending area = 2\n");
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void DialogLayoutSettings::ConvertLayoutSize()
|
void DialogLayoutSettings::ConvertLayoutSize()
|
||||||
{
|
{
|
||||||
|
@ -301,8 +366,20 @@ void DialogLayoutSettings::PaperSizeChanged()
|
||||||
|
|
||||||
Label();
|
Label();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool DialogLayoutSettings::SelectTemplate(const PaperSizeTemplate& id)
|
||||||
|
{
|
||||||
|
int index = ui->comboBoxTemplates->findData(static_cast<VIndexType>(id));
|
||||||
|
if (index > -1)
|
||||||
|
{
|
||||||
|
ui->comboBoxTemplates->setCurrentIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (index > -1);
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
void DialogLayoutSettings::Swap(bool checked)
|
void DialogLayoutSettings::Swap(bool checked)
|
||||||
{
|
{
|
||||||
if (checked)
|
if (checked)
|
||||||
|
@ -337,7 +414,11 @@ void DialogLayoutSettings::DialogAccepted()
|
||||||
generator->SetSaveLength(IsSaveLength());
|
generator->SetSaveLength(IsSaveLength());
|
||||||
generator->SetUnitePages(IsUnitePages());
|
generator->SetUnitePages(IsUnitePages());
|
||||||
|
|
||||||
|
//don't want to break visual settings when cmd used
|
||||||
|
if (!disableSettings)
|
||||||
|
{
|
||||||
WriteSettings();
|
WriteSettings();
|
||||||
|
}
|
||||||
accepted();
|
accepted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,26 +474,26 @@ void DialogLayoutSettings::InitTemplates()
|
||||||
const QIcon icoRoll("://icon/16x16/roll.png");
|
const QIcon icoRoll("://icon/16x16/roll.png");
|
||||||
const QString pdi = QString("(%1ppi)").arg(PrintDPI);
|
const QString pdi = QString("(%1ppi)").arg(PrintDPI);
|
||||||
|
|
||||||
ui->comboBoxTemplates->addItem(icoPaper, "A0 "+pdi, QVariant(static_cast<char>(PaperSizeTemplate::A0)));
|
auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0);
|
||||||
ui->comboBoxTemplates->addItem(icoPaper, "A1 "+pdi, QVariant(static_cast<char>(PaperSizeTemplate::A1)));
|
foreach(const auto& v, pageFormatNames)
|
||||||
ui->comboBoxTemplates->addItem(icoPaper, "A2 "+pdi, QVariant(static_cast<char>(PaperSizeTemplate::A2)));
|
{
|
||||||
ui->comboBoxTemplates->addItem(icoPaper, "A3 "+pdi, QVariant(static_cast<char>(PaperSizeTemplate::A3)));
|
ui->comboBoxTemplates->addItem(icoPaper, v+" "+pdi, QVariant(cntr++));
|
||||||
ui->comboBoxTemplates->addItem(icoPaper, "A4 "+pdi, QVariant(static_cast<char>(PaperSizeTemplate::A4)));
|
}
|
||||||
ui->comboBoxTemplates->addItem(icoPaper, tr("Letter ")+pdi, QVariant(static_cast<char>(PaperSizeTemplate::Letter)));
|
|
||||||
ui->comboBoxTemplates->addItem(icoPaper, tr("Legal ")+pdi, QVariant(static_cast<char>(PaperSizeTemplate::Legal)));
|
|
||||||
ui->comboBoxTemplates->addItem(icoRoll,
|
|
||||||
tr("Roll 24in ")+pdi, QVariant(static_cast<char>(PaperSizeTemplate::Roll24in)));
|
|
||||||
ui->comboBoxTemplates->addItem(icoRoll,
|
|
||||||
tr("Roll 30in ")+pdi, QVariant(static_cast<char>(PaperSizeTemplate::Roll30in)));
|
|
||||||
ui->comboBoxTemplates->addItem(icoRoll,
|
|
||||||
tr("Roll 36in ")+pdi, QVariant(static_cast<char>(PaperSizeTemplate::Roll36in)));
|
|
||||||
ui->comboBoxTemplates->addItem(icoRoll,
|
|
||||||
tr("Roll 42in ")+pdi, QVariant(static_cast<char>(PaperSizeTemplate::Roll42in)));
|
|
||||||
ui->comboBoxTemplates->addItem(icoRoll,
|
|
||||||
tr("Roll 44in ")+pdi, QVariant(static_cast<char>(PaperSizeTemplate::Roll44in)));
|
|
||||||
|
|
||||||
ui->comboBoxTemplates->setCurrentIndex(-1);
|
ui->comboBoxTemplates->setCurrentIndex(-1);
|
||||||
}
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
QString DialogLayoutSettings::MakeHelpTemplateList()
|
||||||
|
{
|
||||||
|
QString out = "\n";
|
||||||
|
|
||||||
|
auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0);
|
||||||
|
foreach(const auto& v, pageFormatNames)
|
||||||
|
{
|
||||||
|
out += "\t"+v+" = "+ QString::number(cntr++)+"\n";
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QSizeF DialogLayoutSettings::Template()
|
QSizeF DialogLayoutSettings::Template()
|
||||||
|
@ -604,12 +685,6 @@ void DialogLayoutSettings::MinimumLayoutSize()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void DialogLayoutSettings::ReadSettings()
|
void DialogLayoutSettings::ReadSettings()
|
||||||
{
|
{
|
||||||
InitPaperUnits();
|
|
||||||
InitLayoutUnits();
|
|
||||||
InitTemplates();
|
|
||||||
MinimumPaperSize();
|
|
||||||
MinimumLayoutSize();
|
|
||||||
|
|
||||||
SetLayoutWidth(qApp->Settings()->GetLayoutWidth());
|
SetLayoutWidth(qApp->Settings()->GetLayoutWidth());
|
||||||
SetShift(qApp->Settings()->GetLayoutShift());
|
SetShift(qApp->Settings()->GetLayoutShift());
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
#include "../../libs/vlayout/vbank.h"
|
#include "../../libs/vlayout/vbank.h"
|
||||||
#include "../../libs/ifc/ifcdef.h"
|
#include "../../libs/ifc/ifcdef.h"
|
||||||
|
#include "../../libs/vlayout/vlayoutgenerator.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
|
@ -46,7 +47,8 @@ class DialogLayoutSettings : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent = 0);
|
enum class PaperSizeTemplate : char { A0 = 0, A1, A2, A3, A4, Letter, Legal, Roll24in, Roll30in, Roll36in, Roll42in, Roll44in};
|
||||||
|
DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent = 0, bool disableSetting = false);
|
||||||
~DialogLayoutSettings();
|
~DialogLayoutSettings();
|
||||||
|
|
||||||
int GetPaperHeight() const;
|
int GetPaperHeight() const;
|
||||||
|
@ -68,7 +70,7 @@ public:
|
||||||
void SetRotate(bool state);
|
void SetRotate(bool state);
|
||||||
|
|
||||||
int GetIncrease() const;
|
int GetIncrease() const;
|
||||||
void SetIncrease(int increase);
|
bool SetIncrease(int increase);
|
||||||
|
|
||||||
bool GetAutoCrop() const;
|
bool GetAutoCrop() const;
|
||||||
void SetAutoCrop(bool crop);
|
void SetAutoCrop(bool crop);
|
||||||
|
@ -79,6 +81,14 @@ public:
|
||||||
bool IsUnitePages() const;
|
bool IsUnitePages() const;
|
||||||
void SetUnitePages(bool save);
|
void SetUnitePages(bool save);
|
||||||
|
|
||||||
|
//support functions for the command line parser which uses invisible dialog to properly build layout generator
|
||||||
|
bool SelectTemplate(const PaperSizeTemplate& id);
|
||||||
|
static QString MakeHelpTemplateList();
|
||||||
|
bool SelectPaperUnit(const QString& units);
|
||||||
|
bool SelectLayoutUnit(const QString& units);
|
||||||
|
int LayoutToPixels(qreal value) const;
|
||||||
|
int PageToPixels(qreal value) const;
|
||||||
|
static QString MakeGroupsHelp();
|
||||||
public slots:
|
public slots:
|
||||||
void ConvertPaperSize();
|
void ConvertPaperSize();
|
||||||
void ConvertLayoutSize();
|
void ConvertLayoutSize();
|
||||||
|
@ -92,6 +102,12 @@ public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(DialogLayoutSettings)
|
Q_DISABLE_COPY(DialogLayoutSettings)
|
||||||
|
typedef std::vector<QString> FormatsVector;
|
||||||
|
typedef int VIndexType;
|
||||||
|
const static FormatsVector pageFormatNames;
|
||||||
|
|
||||||
|
bool disableSettings;
|
||||||
|
|
||||||
Ui::DialogLayoutSettings *ui;
|
Ui::DialogLayoutSettings *ui;
|
||||||
Unit oldPaperUnit;
|
Unit oldPaperUnit;
|
||||||
Unit oldLayoutUnit;
|
Unit oldLayoutUnit;
|
||||||
|
|
|
@ -36,8 +36,23 @@
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
using namespace nm_DialogSaveLayout;
|
||||||
|
|
||||||
|
bool VFrmWithTest::havePdf = false;
|
||||||
|
bool VFrmWithTest::tested = false;
|
||||||
|
|
||||||
|
const std::vector<VFrmWithTest> DialogSaveLayout::availFormats = {
|
||||||
|
VFrmWithTest(tr("Svg files (*.svg)"), ".svg"),
|
||||||
|
VFrmWithTest(tr("PDF files (*.pdf)"), ".pdf"),
|
||||||
|
VFrmWithTest(tr("Images (*.png)"), ".png"),
|
||||||
|
VFrmWithTest(tr("Wavefront OBJ (*.obj)"), ".obj"),
|
||||||
|
VFrmWithTest(tr("PS files (*.ps)"), ".ps", 1), //fixme: use 1 to have exe once tested on 1st run, or any other value to test always as original do
|
||||||
|
VFrmWithTest(tr("EPS files (*.eps)"), ".eps", 1),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
DialogSaveLayout::DialogSaveLayout(const QMap<QString, QString> &formates, int count, const QString &fileName,
|
DialogSaveLayout::DialogSaveLayout(int count, const QString &fileName,
|
||||||
QWidget *parent)
|
QWidget *parent)
|
||||||
:QDialog(parent), ui(new Ui::DialogSaveLAyout), count(count)
|
:QDialog(parent), ui(new Ui::DialogSaveLAyout), count(count)
|
||||||
{
|
{
|
||||||
|
@ -53,13 +68,13 @@ DialogSaveLayout::DialogSaveLayout(const QMap<QString, QString> &formates, int c
|
||||||
ui->lineEditFileName->setValidator(validator);
|
ui->lineEditFileName->setValidator(validator);
|
||||||
ui->lineEditFileName->setText(fileName+"_");
|
ui->lineEditFileName->setText(fileName+"_");
|
||||||
|
|
||||||
QMap<QString, QString>::const_iterator i = formates.constBegin();
|
foreach (auto& v , availFormats)
|
||||||
while (i != formates.constEnd())
|
|
||||||
{
|
{
|
||||||
ui->comboBoxFormat->addItem(i.key(), QVariant(i.value()));
|
if (v.test())
|
||||||
++i;
|
{
|
||||||
|
ui->comboBoxFormat->addItem(v.pair.first, QVariant(v.pair.second));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(bOk, &QPushButton::clicked, this, &DialogSaveLayout::Save);
|
connect(bOk, &QPushButton::clicked, this, &DialogSaveLayout::Save);
|
||||||
connect(ui->lineEditFileName, &QLineEdit::textChanged, this, &DialogSaveLayout::ShowExample);
|
connect(ui->lineEditFileName, &QLineEdit::textChanged, this, &DialogSaveLayout::ShowExample);
|
||||||
connect(ui->comboBoxFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
connect(ui->comboBoxFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||||
|
@ -73,6 +88,37 @@ DialogSaveLayout::DialogSaveLayout(const QMap<QString, QString> &formates, int c
|
||||||
setMaximumSize(size());
|
setMaximumSize(size());
|
||||||
setMinimumSize(size());
|
setMinimumSize(size());
|
||||||
}
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void DialogSaveLayout::SelectFormate(const size_t formate)
|
||||||
|
{
|
||||||
|
if (formate >= availFormats.size())
|
||||||
|
{
|
||||||
|
AppAbort(tr("Tried to use out of range format number."), INVALID_PARAMS_STATUS);
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = ui->comboBoxFormat->findData(availFormats[formate].pair.second);
|
||||||
|
if (i < 0)
|
||||||
|
{
|
||||||
|
AppAbort(tr("Selected not present format."), INVALID_PARAMS_STATUS);
|
||||||
|
}
|
||||||
|
ui->comboBoxFormat->setCurrentIndex(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QString DialogSaveLayout::MakeHelpFormatList()
|
||||||
|
{
|
||||||
|
QString out = "\n";
|
||||||
|
int cntr = 0;
|
||||||
|
foreach(auto& v, availFormats)
|
||||||
|
{
|
||||||
|
if (v.test())
|
||||||
|
{
|
||||||
|
out += "\t"+v.pair.first+" = "+ QString::number(cntr++)+"\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
DialogSaveLayout::~DialogSaveLayout()
|
DialogSaveLayout::~DialogSaveLayout()
|
||||||
|
@ -163,3 +209,25 @@ void DialogSaveLayout::PathChanged(const QString &text)
|
||||||
|
|
||||||
ui->lineEditPath->setPalette(palette);
|
ui->lineEditPath->setPalette(palette);
|
||||||
}
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool VFrmWithTest::TestPdf()
|
||||||
|
{
|
||||||
|
bool res = false;
|
||||||
|
|
||||||
|
QProcess proc;
|
||||||
|
#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
|
||||||
|
proc.start(qApp->applicationDirPath()+"/"+PDFTOPS); // Seek pdftops in app bundle or near valentin.exe
|
||||||
|
#else
|
||||||
|
proc.start(PDFTOPS); // Seek pdftops in standard path
|
||||||
|
#endif
|
||||||
|
if (proc.waitForFinished(15000))
|
||||||
|
{
|
||||||
|
res = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug()<<PDFTOPS<<"error"<<proc.error()<<proc.errorString();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,49 @@
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
# define PDFTOPS "pdftops.exe"
|
||||||
|
#else
|
||||||
|
# define PDFTOPS "pdftops"
|
||||||
|
#endif
|
||||||
|
#include <vector>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace nm_DialogSaveLayout
|
||||||
|
{
|
||||||
|
struct VFrmWithTest //could declare inside dialog class, but using namespace shorter to write and understand
|
||||||
|
{
|
||||||
|
typedef std::function<bool()> test_func;
|
||||||
|
const std::pair<QString, QString> pair;
|
||||||
|
const test_func test;
|
||||||
|
|
||||||
|
VFrmWithTest(const QString& v1, const QString& v2)
|
||||||
|
:pair(std::make_pair(v1,v2)),
|
||||||
|
test([](){return true;})
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VFrmWithTest(const QString& v1, const QString& v2, int dummy)
|
||||||
|
:pair(std::make_pair(v1,v2)), test((dummy != 1 )?TestPdf:VFrmWithTest::SingleTest)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
static bool havePdf;
|
||||||
|
static bool tested;
|
||||||
|
|
||||||
|
static bool TestPdf();
|
||||||
|
static bool SingleTest()
|
||||||
|
{
|
||||||
|
if (!tested)
|
||||||
|
{
|
||||||
|
havePdf = TestPdf();
|
||||||
|
tested = true;
|
||||||
|
}
|
||||||
|
return havePdf;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class DialogSaveLAyout;
|
class DialogSaveLAyout;
|
||||||
|
@ -41,13 +84,15 @@ class DialogSaveLayout : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DialogSaveLayout(const QMap<QString, QString> &formates, int count, const QString &fileName = QString(),
|
DialogSaveLayout(int count, const QString &fileName = QString(),
|
||||||
QWidget *parent = 0);
|
QWidget *parent = 0);
|
||||||
~DialogSaveLayout();
|
~DialogSaveLayout();
|
||||||
|
|
||||||
QString Path() const;
|
QString Path() const;
|
||||||
QString FileName() const;
|
QString FileName() const;
|
||||||
QString Formate() const;
|
QString Formate() const;
|
||||||
|
void SelectFormate(const size_t formate);
|
||||||
|
static QString MakeHelpFormatList();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void Save();
|
void Save();
|
||||||
|
@ -56,6 +101,7 @@ public slots:
|
||||||
void PathChanged(const QString &text);
|
void PathChanged(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const static std::vector<nm_DialogSaveLayout::VFrmWithTest> availFormats;
|
||||||
Q_DISABLE_COPY(DialogSaveLayout)
|
Q_DISABLE_COPY(DialogSaveLayout)
|
||||||
Ui::DialogSaveLAyout *ui;
|
Ui::DialogSaveLAyout *ui;
|
||||||
int count;
|
int count;
|
||||||
|
|
|
@ -28,16 +28,11 @@
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "core/vapplication.h"
|
#include "core/vapplication.h"
|
||||||
|
#include <iostream>
|
||||||
#include <QMessageBox> // For QT_REQUIRE_VERSION
|
#include <QMessageBox> // For QT_REQUIRE_VERSION
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
|
||||||
# include "../libs/vmisc/backport/qcommandlineparser.h"
|
|
||||||
#else
|
|
||||||
# include <QCommandLineParser>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
Q_INIT_RESOURCE(cursor);
|
Q_INIT_RESOURCE(cursor);
|
||||||
|
@ -51,29 +46,31 @@ int main(int argc, char *argv[])
|
||||||
QT_REQUIRE_VERSION(argc, argv, "5.0.0");
|
QT_REQUIRE_VERSION(argc, argv, "5.0.0");
|
||||||
|
|
||||||
VApplication app(argc, argv);
|
VApplication app(argc, argv);
|
||||||
|
|
||||||
app.InitOptions();
|
app.InitOptions();
|
||||||
|
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png"));
|
app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png"));
|
||||||
app.setMainWindow(&w);
|
app.setMainWindow(&w);
|
||||||
|
|
||||||
QCommandLineParser parser;
|
auto args = app.CommandLine()->OptInputFileNames();
|
||||||
parser.setApplicationDescription(QCoreApplication::translate("main", "Pattern making program."));
|
|
||||||
parser.addHelpOption();
|
|
||||||
parser.addVersionOption();
|
|
||||||
parser.addPositionalArgument("filename", QCoreApplication::translate("main", "Pattern file."));
|
|
||||||
parser.process(app);
|
|
||||||
QStringList args = parser.positionalArguments();
|
|
||||||
|
|
||||||
//Before we load pattern show window.
|
//Before we load pattern show window.
|
||||||
w.show();
|
if (VApplication::CheckGUI())
|
||||||
|
|
||||||
w.ReopenFilesAfterCrash(args);
|
|
||||||
|
|
||||||
for (int i=0;i<args.size();++i)
|
|
||||||
{
|
{
|
||||||
w.LoadPattern(args.at(i));
|
w.show();
|
||||||
|
w.ReopenFilesAfterCrash(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
return app.exec();
|
for (size_t i=0, sz = args.size(); i < sz;++i)
|
||||||
|
{
|
||||||
|
w.LoadPattern(args.at(static_cast<int>(i)), app.CommandLine()->OptMeasurePath());
|
||||||
|
if (app.CommandLine()->IsExportEnabled())
|
||||||
|
{
|
||||||
|
w.DoExport(app.CommandLine());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (VApplication::CheckGUI()) ? app.exec() : 0; // single return point is always better than more
|
||||||
}
|
}
|
||||||
|
|
|
@ -756,6 +756,12 @@ void MainWindow::ToolTrueDarts(bool checked)
|
||||||
&MainWindow::ClosedDialogWithApply<VToolTrueDarts>,
|
&MainWindow::ClosedDialogWithApply<VToolTrueDarts>,
|
||||||
&MainWindow::ApplyDialog<VToolTrueDarts>);
|
&MainWindow::ApplyDialog<VToolTrueDarts>);
|
||||||
}
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void MainWindow::ToolRotate(bool checked)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
|
@ -1073,6 +1079,8 @@ void MainWindow::InitToolButtons()
|
||||||
connect(ui->toolButtonPointFromArcAndTangent, &QToolButton::clicked, this, &MainWindow::ToolPointFromArcAndTangent);
|
connect(ui->toolButtonPointFromArcAndTangent, &QToolButton::clicked, this, &MainWindow::ToolPointFromArcAndTangent);
|
||||||
connect(ui->toolButtonArcWithLength, &QToolButton::clicked, this, &MainWindow::ToolArcWithLength);
|
connect(ui->toolButtonArcWithLength, &QToolButton::clicked, this, &MainWindow::ToolArcWithLength);
|
||||||
connect(ui->toolButtonTrueDarts, &QToolButton::clicked, this, &MainWindow::ToolTrueDarts);
|
connect(ui->toolButtonTrueDarts, &QToolButton::clicked, this, &MainWindow::ToolTrueDarts);
|
||||||
|
|
||||||
|
//connect(ui->toolButtonRotate, &QToolButton::clicked, this, &MainWindow::ToolRotate);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -2797,7 +2805,7 @@ MainWindow::~MainWindow()
|
||||||
* @brief LoadPattern open pattern file.
|
* @brief LoadPattern open pattern file.
|
||||||
* @param fileName name of file.
|
* @param fileName name of file.
|
||||||
*/
|
*/
|
||||||
void MainWindow::LoadPattern(const QString &fileName)
|
void MainWindow::LoadPattern(const QString &fileName, const QString& customMeasureFile)
|
||||||
{
|
{
|
||||||
qCDebug(vMainWindow, "Loading new file %s.", fileName.toUtf8().constData());
|
qCDebug(vMainWindow, "Loading new file %s.", fileName.toUtf8().constData());
|
||||||
|
|
||||||
|
@ -2851,7 +2859,10 @@ void MainWindow::LoadPattern(const QString &fileName)
|
||||||
|
|
||||||
VDomDocument::ValidateXML(VPatternConverter::CurrentSchema, fileName);
|
VDomDocument::ValidateXML(VPatternConverter::CurrentSchema, fileName);
|
||||||
doc->setXMLContent(fileName);
|
doc->setXMLContent(fileName);
|
||||||
|
if (!customMeasureFile.isEmpty())
|
||||||
|
{
|
||||||
|
doc->SetPath(customMeasureFile);
|
||||||
|
}
|
||||||
qApp->setPatternUnit(doc->MUnit());
|
qApp->setPatternUnit(doc->MUnit());
|
||||||
qApp->setPatternType(doc->MType());
|
qApp->setPatternType(doc->MType());
|
||||||
QString path = doc->MPath();
|
QString path = doc->MPath();
|
||||||
|
@ -3054,6 +3065,27 @@ void MainWindow::ReopenFilesAfterCrash(QStringList &args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MainWindow::DoExport(const VCommandLinePtr &expParams)
|
||||||
|
{
|
||||||
|
auto settings = expParams->DefaultGenerator();
|
||||||
|
|
||||||
|
const QHash<quint32, VDetail> *details = pattern->DataDetails();
|
||||||
|
if(not qApp->getOpeningPattern())
|
||||||
|
{
|
||||||
|
if (details->count() == 0)
|
||||||
|
{
|
||||||
|
AppAbort(tr("You can't export empty scene."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PrepareDetailsForLayout(details);
|
||||||
|
LayoutSettings(*settings.get());
|
||||||
|
DialogSaveLayout dialog(scenes.size(), expParams->OptExportPath(), this);
|
||||||
|
dialog.SelectFormate(expParams->OptExportType());
|
||||||
|
ExportLayout(dialog);
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString MainWindow::CheckPathToMeasurements(const QString &path, const MeasurementsType &patternType)
|
QString MainWindow::CheckPathToMeasurements(const QString &path, const MeasurementsType &patternType)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "tools/vtooldetail.h"
|
#include "tools/vtooldetail.h"
|
||||||
#include "tools/vtooluniondetails.h"
|
#include "tools/vtooluniondetails.h"
|
||||||
#include "tools/drawTools/drawtools.h"
|
#include "tools/drawTools/drawtools.h"
|
||||||
|
#include "core/vcmdexport.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
|
@ -53,8 +54,10 @@ class MainWindow : public MainWindowsNoGUI
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(QWidget *parent = nullptr);
|
||||||
virtual ~MainWindow() Q_DECL_OVERRIDE;
|
virtual ~MainWindow() Q_DECL_OVERRIDE;
|
||||||
void LoadPattern(const QString &curFile);
|
void LoadPattern(const QString &curFile, const QString &customMeasureFile = QString());
|
||||||
void ReopenFilesAfterCrash(QStringList &args);
|
void ReopenFilesAfterCrash(QStringList &args);
|
||||||
|
|
||||||
|
void DoExport(const VCommandLinePtr& expParams);
|
||||||
public slots:
|
public slots:
|
||||||
void mouseMove(const QPointF &scenePos);
|
void mouseMove(const QPointF &scenePos);
|
||||||
void ArrowTool();
|
void ArrowTool();
|
||||||
|
@ -122,6 +125,7 @@ public slots:
|
||||||
void ToolPointFromArcAndTangent(bool checked);
|
void ToolPointFromArcAndTangent(bool checked);
|
||||||
void ToolArcWithLength(bool checked);
|
void ToolArcWithLength(bool checked);
|
||||||
void ToolTrueDarts(bool checked);
|
void ToolTrueDarts(bool checked);
|
||||||
|
void ToolRotate(bool checked);
|
||||||
|
|
||||||
void ClosedDialogDetail(int result);
|
void ClosedDialogDetail(int result);
|
||||||
void ClosedDialogUnionDetails(int result);
|
void ClosedDialogUnionDetails(int result);
|
||||||
|
|
|
@ -30,11 +30,11 @@
|
||||||
#include "core/vapplication.h"
|
#include "core/vapplication.h"
|
||||||
#include "../libs/vpatterndb/vcontainer.h"
|
#include "../libs/vpatterndb/vcontainer.h"
|
||||||
#include "../libs/vobj/vobjpaintdevice.h"
|
#include "../libs/vobj/vobjpaintdevice.h"
|
||||||
#include "dialogs/dialoglayoutsettings.h"
|
|
||||||
#include "../libs/vlayout/vlayoutgenerator.h"
|
|
||||||
#include "dialogs/dialoglayoutprogress.h"
|
#include "dialogs/dialoglayoutprogress.h"
|
||||||
#include "dialogs/dialogsavelayout.h"
|
|
||||||
#include "../libs/vlayout/vposter.h"
|
#include "../libs/vlayout/vposter.h"
|
||||||
|
#include "dialogs/dialoglayoutsettings.h"
|
||||||
|
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
@ -80,8 +80,8 @@ void MainWindowsNoGUI::ToolLayoutSettings(bool checked)
|
||||||
|
|
||||||
if (checked)
|
if (checked)
|
||||||
{
|
{
|
||||||
VLayoutGenerator lGenerator(this);
|
VLayoutGenerator lGenerator;
|
||||||
lGenerator.SetDetails(listDetails);
|
|
||||||
|
|
||||||
DialogLayoutSettings layout(&lGenerator, this);
|
DialogLayoutSettings layout(&lGenerator, this);
|
||||||
if (layout.exec() == QDialog::Rejected)
|
if (layout.exec() == QDialog::Rejected)
|
||||||
|
@ -89,15 +89,32 @@ void MainWindowsNoGUI::ToolLayoutSettings(bool checked)
|
||||||
tButton->setChecked(false);
|
tButton->setChecked(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
LayoutSettings(lGenerator);
|
||||||
|
tButton->setChecked(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tButton->setChecked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator)
|
||||||
|
{
|
||||||
|
lGenerator.SetDetails(listDetails);
|
||||||
DialogLayoutProgress progress(listDetails.count(), this);
|
DialogLayoutProgress progress(listDetails.count(), this);
|
||||||
|
if (VApplication::CheckGUI())
|
||||||
|
{
|
||||||
connect(&lGenerator, &VLayoutGenerator::Start, &progress, &DialogLayoutProgress::Start);
|
connect(&lGenerator, &VLayoutGenerator::Start, &progress, &DialogLayoutProgress::Start);
|
||||||
connect(&lGenerator, &VLayoutGenerator::Arranged, &progress, &DialogLayoutProgress::Arranged);
|
connect(&lGenerator, &VLayoutGenerator::Arranged, &progress, &DialogLayoutProgress::Arranged);
|
||||||
connect(&lGenerator, &VLayoutGenerator::Error, &progress, &DialogLayoutProgress::Error);
|
connect(&lGenerator, &VLayoutGenerator::Error, &progress, &DialogLayoutProgress::Error);
|
||||||
connect(&lGenerator, &VLayoutGenerator::Finished, &progress, &DialogLayoutProgress::Finished);
|
connect(&lGenerator, &VLayoutGenerator::Finished, &progress, &DialogLayoutProgress::Finished);
|
||||||
connect(&progress, &DialogLayoutProgress::Abort, &lGenerator, &VLayoutGenerator::Abort);
|
connect(&progress, &DialogLayoutProgress::Abort, &lGenerator, &VLayoutGenerator::Abort);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
connect(&lGenerator, &VLayoutGenerator::Error, this, &MainWindowsNoGUI::ErrorConsoleMode);
|
||||||
|
}
|
||||||
lGenerator.Generate();
|
lGenerator.Generate();
|
||||||
|
|
||||||
switch (lGenerator.State())
|
switch (lGenerator.State())
|
||||||
|
@ -122,16 +139,33 @@ void MainWindowsNoGUI::ToolLayoutSettings(bool checked)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
tButton->setChecked(false);
|
|
||||||
}
|
}
|
||||||
else
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state)
|
||||||
{
|
{
|
||||||
tButton->setChecked(true);
|
QString text;
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case LayoutErrors::NoError:
|
||||||
|
return;
|
||||||
|
case LayoutErrors::PrepareLayoutError:
|
||||||
|
text = tr("Couldn't prepare data for creation layout");
|
||||||
|
break;
|
||||||
|
case LayoutErrors::ProcessStoped:
|
||||||
|
break;
|
||||||
|
case LayoutErrors::EmptyPaperError:
|
||||||
|
text = tr("Several workpieces left not arranged, but none of them match for paper");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
AppAbort(text, FAILED_TO_GEN_LAYOUT_STATUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
void MainWindowsNoGUI::ExportLayoutAs()
|
void MainWindowsNoGUI::ExportLayoutAs()
|
||||||
{
|
{
|
||||||
if (isLayoutStale)
|
if (isLayoutStale)
|
||||||
|
@ -141,14 +175,20 @@ void MainWindowsNoGUI::ExportLayoutAs()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QMap<QString, QString> extByMessage = InitFormates();
|
DialogSaveLayout dialog(scenes.size(), FileName(), this);
|
||||||
DialogSaveLayout dialog(extByMessage, scenes.size(), FileName(), this);
|
|
||||||
|
|
||||||
if (dialog.exec() == QDialog::Rejected)
|
if (dialog.exec() == QDialog::Rejected)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExportLayout(dialog);
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog)
|
||||||
|
{
|
||||||
|
|
||||||
QString suf = dialog.Formate();
|
QString suf = dialog.Formate();
|
||||||
suf.replace(".", "");
|
suf.replace(".", "");
|
||||||
|
|
||||||
|
@ -459,33 +499,6 @@ void MainWindowsNoGUI::CreateScenes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QMap<QString, QString> MainWindowsNoGUI::InitFormates() const
|
|
||||||
{
|
|
||||||
QMap<QString, QString> extByMessage;
|
|
||||||
extByMessage[ tr("Svg files (*.svg)") ] = ".svg";
|
|
||||||
extByMessage[ tr("PDF files (*.pdf)") ] = ".pdf";
|
|
||||||
extByMessage[ tr("Images (*.png)") ] = ".png";
|
|
||||||
extByMessage[ tr("Wavefront OBJ (*.obj)") ] = ".obj";
|
|
||||||
|
|
||||||
QProcess proc;
|
|
||||||
#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
|
|
||||||
proc.start(qApp->applicationDirPath()+"/"+PDFTOPS); // Seek pdftops in app bundle or near valentin.exe
|
|
||||||
#else
|
|
||||||
proc.start(PDFTOPS); // Seek pdftops in standard path
|
|
||||||
#endif
|
|
||||||
if (proc.waitForFinished(15000))
|
|
||||||
{
|
|
||||||
extByMessage[ tr("PS files (*.ps)") ] = ".ps";
|
|
||||||
extByMessage[ tr("EPS files (*.eps)") ] = ".eps";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug()<<PDFTOPS<<"error"<<proc.error()<<proc.errorString();
|
|
||||||
}
|
|
||||||
return extByMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief SvgFile save layout to svg file.
|
* @brief SvgFile save layout to svg file.
|
||||||
|
|
|
@ -34,10 +34,14 @@
|
||||||
#include "../libs/vpatterndb/vdetail.h"
|
#include "../libs/vpatterndb/vdetail.h"
|
||||||
#include "../libs/vlayout/vlayoutdetail.h"
|
#include "../libs/vlayout/vlayoutdetail.h"
|
||||||
#include "xml/vpattern.h"
|
#include "xml/vpattern.h"
|
||||||
|
#include "dialogs/dialogsavelayout.h"
|
||||||
|
#include "../libs/vlayout/vlayoutgenerator.h"
|
||||||
|
|
||||||
|
|
||||||
class QGraphicsScene;
|
class QGraphicsScene;
|
||||||
class QPrinter;
|
class QPrinter;
|
||||||
|
|
||||||
|
|
||||||
class MainWindowsNoGUI : public QMainWindow
|
class MainWindowsNoGUI : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -55,7 +59,7 @@ public slots:
|
||||||
void PrintPreviewTiled();
|
void PrintPreviewTiled();
|
||||||
void PrintOrigin();
|
void PrintOrigin();
|
||||||
void PrintTiled();
|
void PrintTiled();
|
||||||
|
void ErrorConsoleMode(const LayoutErrors &state);
|
||||||
protected:
|
protected:
|
||||||
QVector<VLayoutDetail> listDetails;
|
QVector<VLayoutDetail> listDetails;
|
||||||
|
|
||||||
|
@ -85,12 +89,13 @@ protected:
|
||||||
bool isLayoutStale;
|
bool isLayoutStale;
|
||||||
|
|
||||||
void PrepareDetailsForLayout(const QHash<quint32, VDetail> *details);
|
void PrepareDetailsForLayout(const QHash<quint32, VDetail> *details);
|
||||||
|
void ExportLayout(const DialogSaveLayout &dialog);
|
||||||
|
|
||||||
void InitTempLayoutScene();
|
void InitTempLayoutScene();
|
||||||
virtual void CleanLayout()=0;
|
virtual void CleanLayout()=0;
|
||||||
virtual void PrepareSceneList()=0;
|
virtual void PrepareSceneList()=0;
|
||||||
QIcon ScenePreview(int i) const;
|
QIcon ScenePreview(int i) const;
|
||||||
|
void LayoutSettings(VLayoutGenerator& lGenerator);
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(MainWindowsNoGUI)
|
Q_DISABLE_COPY(MainWindowsNoGUI)
|
||||||
|
|
||||||
|
@ -99,7 +104,6 @@ private:
|
||||||
void CreateShadows();
|
void CreateShadows();
|
||||||
void CreateScenes();
|
void CreateScenes();
|
||||||
|
|
||||||
QMap<QString, QString> InitFormates() const;
|
|
||||||
|
|
||||||
void SvgFile(const QString &name, int i)const;
|
void SvgFile(const QString &name, int i)const;
|
||||||
void PngFile(const QString &name, int i)const;
|
void PngFile(const QString &name, int i)const;
|
||||||
|
|
|
@ -597,6 +597,21 @@ QString VDomDocument::UnitsToStr(const Unit &unit, const bool translate)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QString VDomDocument::UnitsHelpString()
|
||||||
|
{
|
||||||
|
QString r;
|
||||||
|
for (auto i = static_cast<int>(Unit::Mm), last = static_cast<int>(Unit::LAST_UNIT_DO_NOT_USE); i < last;++i)
|
||||||
|
{
|
||||||
|
r += UnitsToStr(static_cast<Unit>(i));
|
||||||
|
if (i < last - 1)
|
||||||
|
{
|
||||||
|
r += ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VDomDocument::SaveDocument(const QString &fileName, QString &error) const
|
bool VDomDocument::SaveDocument(const QString &fileName, QString &error) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -97,6 +97,8 @@ public:
|
||||||
void setXMLContent(const QString &fileName);
|
void setXMLContent(const QString &fileName);
|
||||||
static Unit StrToUnits(const QString &unit);
|
static Unit StrToUnits(const QString &unit);
|
||||||
static QString UnitsToStr(const Unit &unit, const bool translate = false);
|
static QString UnitsToStr(const Unit &unit, const bool translate = false);
|
||||||
|
static QString UnitsHelpString();
|
||||||
|
|
||||||
virtual bool SaveDocument(const QString &fileName, QString &error) const;
|
virtual bool SaveDocument(const QString &fileName, QString &error) const;
|
||||||
QString Major() const;
|
QString Major() const;
|
||||||
QString Minor() const;
|
QString Minor() const;
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
class QPointF;
|
class QPointF;
|
||||||
class VLayoutDetail;
|
class VLayoutDetail;
|
||||||
|
|
||||||
enum class Cases : char { CaseThreeGroup, CaseTwoGroup, CaseDesc, UnknownCase};
|
enum class Cases : char { CaseThreeGroup = 0, CaseTwoGroup, CaseDesc, UnknownCase};
|
||||||
|
|
||||||
class VBank
|
class VBank
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
#include "vlayoutdef.h"
|
#include "vlayoutdef.h"
|
||||||
#include "vbank.h"
|
#include "vbank.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class VLayoutPaper;
|
class VLayoutPaper;
|
||||||
class VLayoutDetail;
|
class VLayoutDetail;
|
||||||
|
@ -107,4 +108,6 @@ private:
|
||||||
bool unitePages;
|
bool unitePages;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef std::shared_ptr<VLayoutGenerator> VLayoutGeneratorPtr;
|
||||||
|
|
||||||
#endif // VLAYOUTGENERATOR_H
|
#endif // VLAYOUTGENERATOR_H
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
enum class NodeDetail : char { Contour, Modeling };
|
enum class NodeDetail : char { Contour, Modeling };
|
||||||
enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail, Unknown };
|
enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail, Unknown };
|
||||||
enum class MeasurementsType : char { Standard, Individual };
|
enum class MeasurementsType : char { Standard, Individual };
|
||||||
enum class Unit : char { Mm, Cm, Inch, Px };
|
enum class Unit : char { Mm = 0, Cm, Inch, Px, LAST_UNIT_DO_NOT_USE};
|
||||||
enum class Source : char { FromGui, FromFile, FromTool };
|
enum class Source : char { FromGui, FromFile, FromTool };
|
||||||
|
|
||||||
enum class Tool : unsigned char
|
enum class Tool : unsigned char
|
||||||
|
@ -81,12 +81,13 @@ enum class Tool : unsigned char
|
||||||
PointFromCircleAndTangent,
|
PointFromCircleAndTangent,
|
||||||
PointFromArcAndTangent,
|
PointFromArcAndTangent,
|
||||||
TrueDarts,
|
TrueDarts,
|
||||||
UnionDetails // 37
|
UnionDetails, // 37
|
||||||
|
LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Vis : unsigned char
|
enum class Vis : unsigned char
|
||||||
{
|
{
|
||||||
ControlPointSpline = 38, // increase this value if need more positions in Tool enum
|
ControlPointSpline = static_cast<Vis>(Tool::LAST_ONE_DO_NOT_USE), //38,// increase this value if need more positions in Tool enum
|
||||||
GraphicsSimpleTextItem,
|
GraphicsSimpleTextItem,
|
||||||
SimpleSplinePath,
|
SimpleSplinePath,
|
||||||
SimplePoint,
|
SimplePoint,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user