Command option for setting a locale.
--HG-- branch : develop
This commit is contained in:
parent
392548f444
commit
b5c6bf8260
7
dist/debian/valentina.1
vendored
7
dist/debian/valentina.1
vendored
|
@ -31,7 +31,7 @@ a unique pattern making tool.
|
|||
|
||||
-p, --pageformat <Template number> Number corresponding to page
|
||||
template (default = 0, export mode):
|
||||
A0 = 0
|
||||
A0 = 0
|
||||
A1 = 1
|
||||
A2 = 2
|
||||
A3 = 3
|
||||
|
@ -73,6 +73,11 @@ a unique pattern making tool.
|
|||
Three groups: big, middle, small = 0
|
||||
Two groups: big, small = 1
|
||||
Descending area = 2
|
||||
-L, --locale <Locale> Sets language locale (export mode).
|
||||
Default is system locale. Supported
|
||||
locales: ru_RU, uk_UA, de_DE, cs_CZ,
|
||||
he_IL, fr_FR, it_IT, nl_NL, id_ID,
|
||||
es_ES, fi_FI, en_US
|
||||
|
||||
|
||||
Arguments:
|
||||
|
|
|
@ -88,7 +88,7 @@ void TapeConfigurationPage::Apply()
|
|||
qApp->TapeSettings()->SetPMSystemCode(code);
|
||||
systemChanged = false;
|
||||
|
||||
qApp->LoadTranslation();
|
||||
qApp->LoadTranslation(locale);
|
||||
|
||||
// Part about measurments will not be updated automatically
|
||||
qApp->RetranslateTables();
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
#include <QDir>
|
||||
#include <QFileOpenEvent>
|
||||
#include <QLibraryInfo>
|
||||
#include <QLocalSocket>
|
||||
#include <QResource>
|
||||
#include <QTranslator>
|
||||
|
@ -138,11 +137,7 @@ MApplication::MApplication(int &argc, char **argv)
|
|||
mainWindows(),
|
||||
localServer(nullptr),
|
||||
trVars(nullptr),
|
||||
dataBase(QPointer<DialogMDataBase>()),
|
||||
qtTranslator(nullptr),
|
||||
qtxmlTranslator(nullptr),
|
||||
appTranslator(nullptr),
|
||||
pmsTranslator(nullptr)
|
||||
dataBase(QPointer<DialogMDataBase>())
|
||||
{
|
||||
setApplicationDisplayName(VER_PRODUCTNAME_STR);
|
||||
setApplicationName(VER_INTERNALNAME_STR);
|
||||
|
@ -236,7 +231,7 @@ void MApplication::InitOptions()
|
|||
qDebug()<<"Command-line arguments:"<<this->arguments();
|
||||
qDebug()<<"Process ID:"<<this->applicationPid();
|
||||
|
||||
LoadTranslation();
|
||||
LoadTranslation(TapeSettings()->GetLocale());
|
||||
|
||||
static const char * GENERIC_ICON_TO_CHECK = "document-open";
|
||||
if (QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK) == false)
|
||||
|
@ -251,43 +246,6 @@ void MApplication::InitOptions()
|
|||
QResource::registerResource(diagramsPath());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MApplication::LoadTranslation()
|
||||
{
|
||||
const QString checkedLocale = TapeSettings()->GetLocale();
|
||||
qDebug()<<"Checked locale:"<<checkedLocale;
|
||||
|
||||
ClearTranslation();
|
||||
|
||||
qtTranslator = new QTranslator(this);
|
||||
#if defined(Q_OS_WIN)
|
||||
qtTranslator->load("qt_" + checkedLocale, translationsPath());
|
||||
#else
|
||||
qtTranslator->load("qt_" + checkedLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
#endif
|
||||
installTranslator(qtTranslator);
|
||||
|
||||
qtxmlTranslator = new QTranslator(this);
|
||||
#if defined(Q_OS_WIN)
|
||||
qtxmlTranslator->load("qtxmlpatterns_" + checkedLocale, translationsPath());
|
||||
#else
|
||||
qtxmlTranslator->load("qtxmlpatterns_" + checkedLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
#endif
|
||||
installTranslator(qtxmlTranslator);
|
||||
|
||||
appTranslator = new QTranslator(this);
|
||||
bool result = appTranslator->load("valentina_" + checkedLocale, translationsPath());
|
||||
installTranslator(appTranslator);
|
||||
|
||||
const QString checkedSystem = TapeSettings()->GetPMSystemCode();
|
||||
|
||||
pmsTranslator = new QTranslator(this);
|
||||
result = pmsTranslator->load("measurements_" + checkedSystem + "_" + checkedLocale, translationsPath());
|
||||
installTranslator(pmsTranslator);
|
||||
|
||||
InitTrVars();//Very important do it after load QM files.
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
const VTranslateVars *MApplication::TrVars()
|
||||
{
|
||||
|
@ -645,35 +603,3 @@ void MApplication::Clean()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MApplication::ClearTranslation()
|
||||
{
|
||||
if (qtTranslator != nullptr)
|
||||
{
|
||||
removeTranslator(qtTranslator);
|
||||
delete qtTranslator;
|
||||
qtTranslator = nullptr;
|
||||
}
|
||||
|
||||
if (qtxmlTranslator != nullptr)
|
||||
{
|
||||
removeTranslator(qtxmlTranslator);
|
||||
delete qtxmlTranslator;
|
||||
qtxmlTranslator = nullptr;
|
||||
}
|
||||
|
||||
if (appTranslator != nullptr)
|
||||
{
|
||||
removeTranslator(appTranslator);
|
||||
delete appTranslator;
|
||||
appTranslator = nullptr;
|
||||
}
|
||||
|
||||
if (pmsTranslator != nullptr)
|
||||
{
|
||||
removeTranslator(pmsTranslator);
|
||||
delete pmsTranslator;
|
||||
pmsTranslator = nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,15 +61,13 @@ public:
|
|||
#endif
|
||||
|
||||
void InitOptions();
|
||||
void LoadTranslation();
|
||||
|
||||
virtual const VTranslateVars *TrVars();
|
||||
void InitTrVars();
|
||||
virtual const VTranslateVars *TrVars() Q_DECL_OVERRIDE;
|
||||
|
||||
virtual void OpenSettings() Q_DECL_OVERRIDE;
|
||||
VTapeSettings *TapeSettings();
|
||||
|
||||
QString translationsPath() const;
|
||||
virtual QString translationsPath() const Q_DECL_OVERRIDE;
|
||||
QString diagramsPath() const;
|
||||
|
||||
void ShowDataBase();
|
||||
|
@ -81,6 +79,9 @@ public:
|
|||
public slots:
|
||||
TMainWindow *NewMainWindow();
|
||||
|
||||
protected:
|
||||
virtual void InitTrVars() Q_DECL_OVERRIDE;
|
||||
|
||||
private slots:
|
||||
void OpenFile(const QString &path);
|
||||
void NewLocalSocketConnection();
|
||||
|
@ -91,13 +92,8 @@ private:
|
|||
QLocalServer *localServer;
|
||||
VTranslateVars *trVars;
|
||||
QPointer<DialogMDataBase> dataBase;
|
||||
QTranslator *qtTranslator;
|
||||
QTranslator *qtxmlTranslator;
|
||||
QTranslator *appTranslator;
|
||||
QTranslator *pmsTranslator;
|
||||
|
||||
void Clean();
|
||||
void ClearTranslation();
|
||||
};
|
||||
|
||||
#endif // MAPPLICATION_H
|
||||
|
|
|
@ -499,30 +499,7 @@ void VApplication::InitOptions()
|
|||
qDebug()<<"Command-line arguments:"<<this->arguments();
|
||||
qDebug()<<"Process ID:"<<this->applicationPid();
|
||||
|
||||
const QString checkedLocale = ValentinaSettings()->GetLocale();
|
||||
qDebug()<<"Checked locale:"<<checkedLocale;
|
||||
|
||||
QTranslator *qtTranslator = new QTranslator(this);
|
||||
#if defined(Q_OS_WIN)
|
||||
qtTranslator->load("qt_" + checkedLocale, translationsPath());
|
||||
#else
|
||||
qtTranslator->load("qt_" + checkedLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
#endif
|
||||
installTranslator(qtTranslator);
|
||||
|
||||
QTranslator *qtxmlTranslator = new QTranslator(this);
|
||||
#if defined(Q_OS_WIN)
|
||||
qtxmlTranslator->load("qtxmlpatterns_" + checkedLocale, translationsPath());
|
||||
#else
|
||||
qtxmlTranslator->load("qtxmlpatterns_" + checkedLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
#endif
|
||||
installTranslator(qtxmlTranslator);
|
||||
|
||||
QTranslator *appTranslator = new QTranslator(this);
|
||||
appTranslator->load("valentina_" + checkedLocale, translationsPath());
|
||||
installTranslator(appTranslator);
|
||||
|
||||
InitTrVars();//Very important do it after load QM files.
|
||||
InitTranslation();
|
||||
|
||||
static const char * GENERIC_ICON_TO_CHECK = "document-open";
|
||||
if (QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK) == false)
|
||||
|
@ -535,6 +512,19 @@ void VApplication::InitOptions()
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VApplication::InitTranslation()
|
||||
{
|
||||
if (VApplication::CheckGUI())
|
||||
{
|
||||
LoadTranslation(ValentinaSettings()->GetLocale());
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadTranslation(CommandLine()->OptLocale());
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QStringList VApplication::LabelLanguages()
|
||||
{
|
||||
|
|
|
@ -60,8 +60,9 @@ public:
|
|||
virtual bool notify(QObject * receiver, QEvent * event) Q_DECL_OVERRIDE;
|
||||
|
||||
void InitOptions();
|
||||
void InitTranslation();
|
||||
|
||||
QString translationsPath() const;
|
||||
virtual QString translationsPath() const Q_DECL_OVERRIDE;
|
||||
QString TapeFilePath() const;
|
||||
|
||||
QTimer *getAutoSaveTimer() const;
|
||||
|
@ -73,7 +74,6 @@ public:
|
|||
QTextStream *LogFile();
|
||||
|
||||
virtual const VTranslateVars *TrVars();
|
||||
void InitTrVars();
|
||||
|
||||
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
||||
static void DrMingw();
|
||||
|
@ -84,6 +84,9 @@ public:
|
|||
virtual void OpenSettings() Q_DECL_OVERRIDE;
|
||||
VSettings *ValentinaSettings();
|
||||
|
||||
protected:
|
||||
virtual void InitTrVars() Q_DECL_OVERRIDE;
|
||||
|
||||
private slots:
|
||||
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
||||
void CleanGist() const;
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
#include "dialogs/dialogsavelayout.h"
|
||||
#include "xml/vdomdocument.h"
|
||||
|
||||
|
||||
|
||||
VCommandLinePtr VCommandLine::instance = nullptr;
|
||||
|
||||
const static auto LONG_OPTION_OUTFILE = QStringLiteral("outfile");
|
||||
|
@ -52,6 +50,9 @@ const static auto SINGLE_OPTION_GAPWIDTH = QStringLiteral("G");
|
|||
const static auto LONG_OPTION_GROUPPING = QStringLiteral("groups");
|
||||
const static auto SINGLE_OPTION_GROUPPING = QStringLiteral("g");
|
||||
|
||||
const static auto SINGLE_OPTION_LOCALE = QStringLiteral("L");
|
||||
const static auto LONG_OPTION_LOCALE = QStringLiteral("locale");
|
||||
|
||||
#define tr(A) QCoreApplication::translate("VCommandLine", (A))
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -64,71 +65,89 @@ VCommandLine::VCommandLine() : parser()
|
|||
//keep in mind order here - that is how user will see it, so group-up for usability
|
||||
//===================================================================================
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_OUTFILE << LONG_OPTION_OUTFILE,
|
||||
{LONG_OPTION_OUTFILE,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_OUTFILE << LONG_OPTION_OUTFILE,
|
||||
tr("Path to output exported layout file. Use it to enable console export mode."),
|
||||
tr("The exported layout file")),
|
||||
tr("The exported layout file"))},
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_MEASUREFILE << LONG_OPTION_MEASUREFILE,
|
||||
{LONG_OPTION_MEASUREFILE,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_MEASUREFILE << LONG_OPTION_MEASUREFILE,
|
||||
tr("Path to custom measure file (export mode)."),
|
||||
tr("The measure file")),
|
||||
tr("The measure file"))},
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_EXP2FORMAT << LONG_OPTION_EXP2FORMAT,
|
||||
{LONG_OPTION_EXP2FORMAT,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_EXP2FORMAT << LONG_OPTION_EXP2FORMAT,
|
||||
tr("Number corresponding to output format (default = 0, export mode): ") +
|
||||
DialogSaveLayout::MakeHelpFormatList(), tr("Format number"), "0"),
|
||||
DialogSaveLayout::MakeHelpFormatList(), tr("Format number"), "0")},
|
||||
|
||||
//===================================================================================
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_PAGETEMPLATE << LONG_OPTION_PAGETEMPLATE,
|
||||
{LONG_OPTION_PAGETEMPLATE,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGETEMPLATE << LONG_OPTION_PAGETEMPLATE,
|
||||
tr("Number corresponding to page template (default = 0, export mode): ")+
|
||||
DialogLayoutSettings::MakeHelpTemplateList(), tr("Template number"), "0"),
|
||||
DialogLayoutSettings::MakeHelpTemplateList(), tr("Template number"), "0")},
|
||||
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEW << LONG_OPTION_PAGEW,
|
||||
{LONG_OPTION_PAGEW,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEW << LONG_OPTION_PAGEW,
|
||||
tr("Page width in current units like 12.0 (cannot be used with \"")
|
||||
+LONG_OPTION_PAGETEMPLATE+tr("\", export mode)."), tr("The page width")),
|
||||
+LONG_OPTION_PAGETEMPLATE+tr("\", export mode)."), tr("The page width"))},
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEH << LONG_OPTION_PAGEH,
|
||||
{LONG_OPTION_PAGEH,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEH << LONG_OPTION_PAGEH,
|
||||
tr("Page height in current units like 12.0 (cannot be used with \"")
|
||||
+LONG_OPTION_PAGETEMPLATE+tr("\", export mode)."), ("The page height")),
|
||||
+LONG_OPTION_PAGETEMPLATE+tr("\", export mode)."), ("The page height"))},
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEUNITS << LONG_OPTION_PAGEUNITS,
|
||||
{LONG_OPTION_PAGEUNITS,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEUNITS << LONG_OPTION_PAGEUNITS,
|
||||
tr("Page height/width measure units (cannot be used with \"")+
|
||||
LONG_OPTION_PAGETEMPLATE+tr("\", export mode): ") + VDomDocument::UnitsHelpString(),
|
||||
tr("The measure unit")),
|
||||
tr("The measure unit"))},
|
||||
|
||||
//===================================================================================
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_ROTATE << LONG_OPTION_ROTATE,
|
||||
{LONG_OPTION_ROTATE,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_ROTATE << LONG_OPTION_ROTATE,
|
||||
tr("Rotation in degrees (one of predefined). Default (or 0) is no-rotate "
|
||||
"(export mode)."),
|
||||
tr("Angle")),
|
||||
"(export mode)."), tr("Angle"))},
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_CROP << LONG_OPTION_CROP,
|
||||
tr("Auto crop unused length (export mode).")),
|
||||
{LONG_OPTION_CROP,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_CROP << LONG_OPTION_CROP,
|
||||
tr("Auto crop unused length (export mode)."))},
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_UNITE << LONG_OPTION_UNITE,
|
||||
tr("Unite pages if possible (export mode).")),
|
||||
{LONG_OPTION_UNITE,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_UNITE << LONG_OPTION_UNITE,
|
||||
tr("Unite pages if possible (export mode)."))},
|
||||
|
||||
//===================================================================================
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_SAVELENGTH << LONG_OPTION_SAVELENGTH,
|
||||
tr("Save length of the sheet if set. (export mode).")),
|
||||
{LONG_OPTION_SAVELENGTH,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_SAVELENGTH << LONG_OPTION_SAVELENGTH,
|
||||
tr("Save length of the sheet if set. (export mode)."))},
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTUNITS << LONG_OPTION_SHIFTUNITS,
|
||||
tr("Layout units (as paper's one except px, export mode)."),
|
||||
tr("The unit")),
|
||||
{LONG_OPTION_SHIFTUNITS,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTUNITS << LONG_OPTION_SHIFTUNITS,
|
||||
tr("Layout units (as paper's one except px, export mode)."), tr("The unit"))},
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTLENGTH << LONG_OPTION_SHIFTLENGTH,
|
||||
{LONG_OPTION_SHIFTLENGTH,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTLENGTH << LONG_OPTION_SHIFTLENGTH,
|
||||
tr("Shift layout length measured in layout units (export mode)."),
|
||||
tr("Shift length")),
|
||||
tr("Shift length"))},
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_GAPWIDTH << LONG_OPTION_GAPWIDTH,
|
||||
{LONG_OPTION_GAPWIDTH,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_GAPWIDTH << LONG_OPTION_GAPWIDTH,
|
||||
tr("Gap width x2, measured in layout units. (export mode)."),
|
||||
tr("The gap width")),
|
||||
tr("The gap width"))},
|
||||
|
||||
QCommandLineOption(QStringList() << SINGLE_OPTION_GROUPPING << LONG_OPTION_GROUPPING,
|
||||
{LONG_OPTION_GROUPPING,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_GROUPPING << LONG_OPTION_GROUPPING,
|
||||
tr("Sets layout groupping (export mode): ")
|
||||
+ DialogLayoutSettings::MakeGroupsHelp(), tr("Grouping type"), "2"),
|
||||
+ DialogLayoutSettings::MakeGroupsHelp(), tr("Grouping type"), "2")},
|
||||
|
||||
{LONG_OPTION_LOCALE,
|
||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_LOCALE << LONG_OPTION_LOCALE,
|
||||
tr("Sets language locale (export mode). Default is system locale. Supported "
|
||||
"locales: ") + SupportedLocales().join(", "), tr("Locale"))}
|
||||
}),
|
||||
isGuiEnabled(false)
|
||||
{
|
||||
|
@ -137,16 +156,19 @@ VCommandLine::VCommandLine() : parser()
|
|||
parser.addVersionOption();
|
||||
parser.addPositionalArgument("filename", QCoreApplication::translate("main", "Pattern file."));
|
||||
|
||||
foreach(const auto& o, optionsUsed)
|
||||
QMap<QString, QCommandLineOption *>::const_iterator i = optionsUsed.constBegin();
|
||||
while (i != optionsUsed.constEnd())
|
||||
{
|
||||
parser.addOption(o);
|
||||
parser.addOption(*i.value());
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
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
|
||||
//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());
|
||||
}
|
||||
|
||||
|
@ -166,11 +188,11 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
|
|||
|
||||
{
|
||||
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
|
||||
bool x = parser.isSet(LONG_OPTION_PAGETEMPLATE);
|
||||
bool x = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGETEMPLATE));
|
||||
|
||||
bool a = parser.isSet(LONG_OPTION_PAGEH);
|
||||
bool b = parser.isSet(LONG_OPTION_PAGEW);
|
||||
bool c = parser.isSet(LONG_OPTION_PAGEUNITS);
|
||||
bool a = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEH));
|
||||
bool b = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEW));
|
||||
bool c = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEUNITS));
|
||||
|
||||
if ((a || b || c) && x)
|
||||
{
|
||||
|
@ -188,8 +210,8 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
|
|||
|
||||
// {
|
||||
// //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);
|
||||
// bool a = parser.isSet(optionsUsed.value(LONG_OPTION_SHIFTLENGTH));
|
||||
// bool b = parser.isSet(optionsUsed.value(LONG_OPTION_SHIFTUNITS));
|
||||
|
||||
// if ((a || b) && !(a && b))
|
||||
// {
|
||||
|
@ -214,40 +236,40 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
|
|||
Error(tr("Unknown page templated selected."));
|
||||
}
|
||||
|
||||
if (parser.isSet(LONG_OPTION_PAGEH)) //at this point we already sure 3 are set or none
|
||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEH))) //at this point we already sure 3 are set or none
|
||||
{
|
||||
|
||||
if (!diag.SelectPaperUnit(parser.value(LONG_OPTION_PAGEUNITS)))
|
||||
if (!diag.SelectPaperUnit(parser.value(*optionsUsed.value(LONG_OPTION_PAGEUNITS))))
|
||||
{
|
||||
Error(tr("Unsupported paper units."));
|
||||
}
|
||||
|
||||
diag.SetPaperHeight (Pg2Px(parser.value(LONG_OPTION_PAGEH), diag));
|
||||
diag.SetPaperWidth (Pg2Px(parser.value(LONG_OPTION_PAGEW), diag));
|
||||
diag.SetPaperHeight (Pg2Px(parser.value(*optionsUsed.value(LONG_OPTION_PAGEH)), diag));
|
||||
diag.SetPaperWidth (Pg2Px(parser.value(*optionsUsed.value(LONG_OPTION_PAGEW)), diag));
|
||||
}
|
||||
|
||||
if (parser.isSet(LONG_OPTION_SHIFTUNITS))
|
||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTUNITS)))
|
||||
{
|
||||
if (!diag.SelectLayoutUnit(parser.value(LONG_OPTION_SHIFTUNITS)))
|
||||
if (!diag.SelectLayoutUnit(parser.value(*optionsUsed.value(LONG_OPTION_SHIFTUNITS))))
|
||||
{
|
||||
Error(tr("Unsupported layout units."));
|
||||
}
|
||||
}
|
||||
|
||||
if (parser.isSet(LONG_OPTION_SHIFTLENGTH))
|
||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH)))
|
||||
{
|
||||
|
||||
diag.SetShift(Lo2Px(parser.value(LONG_OPTION_SHIFTLENGTH), diag));
|
||||
diag.SetShift(Lo2Px(parser.value(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH)), diag));
|
||||
}
|
||||
|
||||
if (parser.isSet(LONG_OPTION_GAPWIDTH))
|
||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_GAPWIDTH)))
|
||||
{
|
||||
diag.SetLayoutWidth(Lo2Px(parser.value(LONG_OPTION_GAPWIDTH), diag));
|
||||
diag.SetLayoutWidth(Lo2Px(parser.value(*optionsUsed.value(LONG_OPTION_GAPWIDTH)), diag));
|
||||
}
|
||||
|
||||
diag.SetAutoCrop(parser.isSet(LONG_OPTION_CROP));
|
||||
diag.SetUnitePages(parser.isSet(LONG_OPTION_UNITE));
|
||||
diag.SetSaveLength(parser.isSet(LONG_OPTION_SAVELENGTH));
|
||||
diag.SetAutoCrop(parser.isSet(*optionsUsed.value(LONG_OPTION_CROP)));
|
||||
diag.SetUnitePages(parser.isSet(*optionsUsed.value(LONG_OPTION_UNITE)));
|
||||
diag.SetSaveLength(parser.isSet(*optionsUsed.value(LONG_OPTION_SAVELENGTH)));
|
||||
diag.SetGroup(OptGroup());
|
||||
|
||||
|
||||
|
@ -288,7 +310,7 @@ void VCommandLine::Reset()
|
|||
//------------------------------------------------------------------------------------------------------
|
||||
bool VCommandLine::IsExportEnabled() const
|
||||
{
|
||||
bool r = parser.isSet(LONG_OPTION_OUTFILE);
|
||||
bool r = parser.isSet(*optionsUsed.value(LONG_OPTION_OUTFILE));
|
||||
if (r && parser.positionalArguments().size() != 1)
|
||||
{
|
||||
Error(tr("Export options can be used with single input file only."));
|
||||
|
@ -300,9 +322,9 @@ bool VCommandLine::IsExportEnabled() const
|
|||
DialogLayoutSettings::PaperSizeTemplate VCommandLine::OptPaperSize() const
|
||||
{
|
||||
int ppsize = 0;
|
||||
if (parser.isSet(LONG_OPTION_PAGETEMPLATE))
|
||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_PAGETEMPLATE)))
|
||||
{
|
||||
ppsize = parser.value(LONG_OPTION_PAGETEMPLATE).toInt();
|
||||
ppsize = parser.value(*optionsUsed.value(LONG_OPTION_PAGETEMPLATE)).toInt();
|
||||
}
|
||||
return static_cast<DialogLayoutSettings::PaperSizeTemplate>(ppsize);
|
||||
}
|
||||
|
@ -311,9 +333,9 @@ DialogLayoutSettings::PaperSizeTemplate VCommandLine::OptPaperSize() const
|
|||
int VCommandLine::OptRotation() const
|
||||
{
|
||||
int rotate = 0;
|
||||
if (parser.isSet(LONG_OPTION_ROTATE))
|
||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_ROTATE)))
|
||||
{
|
||||
rotate = parser.value(LONG_OPTION_ROTATE).toInt();
|
||||
rotate = parser.value(*optionsUsed.value(LONG_OPTION_ROTATE)).toInt();
|
||||
}
|
||||
|
||||
return rotate;
|
||||
|
@ -322,7 +344,7 @@ int VCommandLine::OptRotation() const
|
|||
//------------------------------------------------------------------------------------------------------
|
||||
Cases VCommandLine::OptGroup() const
|
||||
{
|
||||
int r = parser.value(LONG_OPTION_GROUPPING).toInt();
|
||||
int r = parser.value(*optionsUsed.value(LONG_OPTION_GROUPPING)).toInt();
|
||||
if ( r < 0 || r >= static_cast<int>(Cases::UnknownCase))
|
||||
{
|
||||
r = 0;
|
||||
|
@ -334,11 +356,11 @@ Cases VCommandLine::OptGroup() const
|
|||
QString VCommandLine::OptMeasurePath() const
|
||||
{
|
||||
QString measure;
|
||||
if (parser.isSet(LONG_OPTION_MEASUREFILE)
|
||||
if (parser.isSet(*optionsUsed.value(LONG_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(LONG_OPTION_MEASUREFILE);
|
||||
measure = parser.value(*optionsUsed.value(LONG_OPTION_MEASUREFILE));
|
||||
}
|
||||
|
||||
return measure;
|
||||
|
@ -350,7 +372,7 @@ QString VCommandLine::OptExportPath() const
|
|||
QString path;
|
||||
if (IsExportEnabled())
|
||||
{
|
||||
path = parser.value(LONG_OPTION_OUTFILE);
|
||||
path = parser.value(*optionsUsed.value(LONG_OPTION_OUTFILE));
|
||||
}
|
||||
|
||||
return path;
|
||||
|
@ -360,9 +382,9 @@ QString VCommandLine::OptExportPath() const
|
|||
int VCommandLine::OptExportType() const
|
||||
{
|
||||
int r = 0;
|
||||
if (parser.isSet(LONG_OPTION_EXP2FORMAT))
|
||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_EXP2FORMAT)))
|
||||
{
|
||||
r = parser.value(LONG_OPTION_EXP2FORMAT).toInt();
|
||||
r = parser.value(*optionsUsed.value(LONG_OPTION_EXP2FORMAT)).toInt();
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
@ -373,11 +395,21 @@ QStringList VCommandLine::OptInputFileNames() const
|
|||
return parser.positionalArguments();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VCommandLine::OptLocale() const
|
||||
{
|
||||
QString locale = QLocale::system().name();
|
||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_LOCALE)))
|
||||
{
|
||||
locale = parser.value(*optionsUsed.value(LONG_OPTION_LOCALE));
|
||||
}
|
||||
return locale;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VCommandLine::IsGuiEnabled() const
|
||||
{
|
||||
return isGuiEnabled;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
#undef tr
|
||||
|
|
|
@ -52,7 +52,7 @@ class VCommandLine
|
|||
private:
|
||||
static VCommandLinePtr instance;
|
||||
QCommandLineParser parser;
|
||||
const std::vector<QCommandLineOption> optionsUsed;
|
||||
const QMap<QString, QCommandLineOption *> optionsUsed;
|
||||
bool isGuiEnabled;
|
||||
friend class VApplication;
|
||||
|
||||
|
@ -105,6 +105,9 @@ public:
|
|||
//@brief gets filenames which should be loaded
|
||||
QStringList OptInputFileNames() const;
|
||||
|
||||
//@brief gets locale name
|
||||
QString OptLocale() const;
|
||||
|
||||
bool IsGuiEnabled()const;
|
||||
};
|
||||
|
||||
|
|
|
@ -912,3 +912,22 @@ QStringList ListGroupQ()
|
|||
|
||||
return list;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QStringList SupportedLocales()
|
||||
{
|
||||
const QStringList locales = {QStringLiteral("ru_RU"),
|
||||
QStringLiteral("uk_UA"),
|
||||
QStringLiteral("de_DE"),
|
||||
QStringLiteral("cs_CZ"),
|
||||
QStringLiteral("he_IL"),
|
||||
QStringLiteral("fr_FR"),
|
||||
QStringLiteral("it_IT"),
|
||||
QStringLiteral("nl_NL"),
|
||||
QStringLiteral("id_ID"),
|
||||
QStringLiteral("es_ES"),
|
||||
QStringLiteral("fi_FI"),
|
||||
QStringLiteral("en_US")};
|
||||
|
||||
return locales;
|
||||
}
|
||||
|
|
|
@ -575,4 +575,6 @@ qreal UnitConvertor(qreal value, const Unit &from, const Unit &to);
|
|||
|
||||
void CheckFactor(qreal &oldFactor, const qreal &Newfactor);
|
||||
|
||||
QStringList SupportedLocales();
|
||||
|
||||
#endif // DEF_H
|
||||
|
|
|
@ -29,12 +29,18 @@
|
|||
#include "vabstractapplication.h"
|
||||
#include "../vmisc/def.h"
|
||||
|
||||
#include <QLibraryInfo>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VAbstractApplication::VAbstractApplication(int &argc, char **argv)
|
||||
:QApplication(argc, argv),
|
||||
undoStack(nullptr),
|
||||
mainWindow(nullptr),
|
||||
settings(nullptr),
|
||||
qtTranslator(nullptr),
|
||||
qtxmlTranslator(nullptr),
|
||||
appTranslator(nullptr),
|
||||
pmsTranslator(nullptr),
|
||||
_patternUnit(Unit::Cm),
|
||||
_patternType(MeasurementsType::Individual),
|
||||
currentScene(nullptr),
|
||||
|
@ -112,3 +118,72 @@ double VAbstractApplication::fromPixel(double pix) const
|
|||
{
|
||||
return FromPixel(pix, _patternUnit);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractApplication::LoadTranslation(const QString &locale)
|
||||
{
|
||||
if (locale.isEmpty())
|
||||
{
|
||||
qDebug()<<"Locale is empty.";
|
||||
return;
|
||||
}
|
||||
qDebug()<<"Checked locale:"<<locale;
|
||||
|
||||
ClearTranslation();
|
||||
|
||||
qtTranslator = new QTranslator(this);
|
||||
#if defined(Q_OS_WIN)
|
||||
qtTranslator->load("qt_" + locale, translationsPath());
|
||||
#else
|
||||
qtTranslator->load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
#endif
|
||||
installTranslator(qtTranslator);
|
||||
|
||||
qtxmlTranslator = new QTranslator(this);
|
||||
#if defined(Q_OS_WIN)
|
||||
qtxmlTranslator->load("qtxmlpatterns_" + locale, translationsPath());
|
||||
#else
|
||||
qtxmlTranslator->load("qtxmlpatterns_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
#endif
|
||||
installTranslator(qtxmlTranslator);
|
||||
|
||||
appTranslator = new QTranslator(this);
|
||||
appTranslator->load("valentina_" + locale, translationsPath());
|
||||
installTranslator(appTranslator);
|
||||
|
||||
const QString system = Settings()->GetPMSystemCode();
|
||||
|
||||
pmsTranslator = new QTranslator(this);
|
||||
pmsTranslator->load("measurements_" + system + "_" + locale, translationsPath());
|
||||
installTranslator(pmsTranslator);
|
||||
|
||||
InitTrVars();//Very important do it after load QM files.
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractApplication::ClearTranslation()
|
||||
{
|
||||
if (not qtTranslator.isNull())
|
||||
{
|
||||
removeTranslator(qtTranslator);
|
||||
delete qtTranslator;
|
||||
}
|
||||
|
||||
if (not qtxmlTranslator.isNull())
|
||||
{
|
||||
removeTranslator(qtxmlTranslator);
|
||||
delete qtxmlTranslator;
|
||||
}
|
||||
|
||||
if (not appTranslator.isNull())
|
||||
{
|
||||
removeTranslator(appTranslator);
|
||||
delete appTranslator;
|
||||
}
|
||||
|
||||
if (not pmsTranslator.isNull())
|
||||
{
|
||||
removeTranslator(pmsTranslator);
|
||||
delete pmsTranslator;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
#include <QApplication>
|
||||
#include <QGraphicsScene>
|
||||
#include <QPointer>
|
||||
|
||||
#include "def.h"
|
||||
#include "vsettings.h"
|
||||
#include "vlockguard.h"
|
||||
|
@ -53,6 +55,9 @@ public:
|
|||
virtual ~VAbstractApplication() Q_DECL_OVERRIDE;
|
||||
|
||||
virtual const VTranslateVars *TrVars()=0;
|
||||
virtual QString translationsPath() const=0;
|
||||
|
||||
void LoadTranslation(const QString &locale);
|
||||
|
||||
Unit patternUnit() const;
|
||||
const Unit *patternUnitP() const;
|
||||
|
@ -101,6 +106,13 @@ protected:
|
|||
*/
|
||||
VCommonSettings *settings;
|
||||
|
||||
QPointer<QTranslator> qtTranslator;
|
||||
QPointer<QTranslator> qtxmlTranslator;
|
||||
QPointer<QTranslator> appTranslator;
|
||||
QPointer<QTranslator> pmsTranslator;
|
||||
|
||||
virtual void InitTrVars()=0;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VAbstractApplication)
|
||||
Unit _patternUnit;
|
||||
|
@ -117,6 +129,8 @@ private:
|
|||
* we can allow user use Undo option.
|
||||
*/
|
||||
bool openingPattern;
|
||||
|
||||
void ClearTranslation();
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -69,8 +69,7 @@ void TST_MeasurementRegExp::TestOriginalMeasurementNamesRegExp()
|
|||
void TST_MeasurementRegExp::TestMeasurementRegExp()
|
||||
{
|
||||
const int systemCounts = 55;
|
||||
const QStringList locales {"ru_RU", "uk_UA", "de_DE", "cs_CZ", "he_IL", "fr_FR", "it_IT", "nl_NL", "id_ID",
|
||||
"es_ES", "fi_FI", "en_US"};
|
||||
const QStringList locales = SupportedLocales();
|
||||
|
||||
{
|
||||
const int combinations = systemCounts * locales.size(); // 55*12=660
|
||||
|
|
Loading…
Reference in New Issue
Block a user