Command line options for showing a measurement file.
--HG-- branch : feature
This commit is contained in:
parent
99a018c900
commit
81d072d030
|
@ -31,6 +31,12 @@
|
||||||
|
|
||||||
#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
|
||||||
|
|
||||||
// Lock producing random attribute order in XML
|
// Lock producing random attribute order in XML
|
||||||
// https://stackoverflow.com/questions/27378143/qt-5-produce-random-attribute-order-in-xml
|
// https://stackoverflow.com/questions/27378143/qt-5-produce-random-attribute-order-in-xml
|
||||||
extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed;
|
extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed;
|
||||||
|
@ -54,14 +60,123 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
app.InitOptions();
|
app.InitOptions();
|
||||||
|
|
||||||
QStringList args = QCoreApplication::arguments();
|
QCommandLineParser parser;
|
||||||
|
parser.setApplicationDescription(QCoreApplication::translate("main", "Valentina's measurements editor."));
|
||||||
|
parser.addHelpOption();
|
||||||
|
parser.addVersionOption();
|
||||||
|
parser.addPositionalArgument("filename", QCoreApplication::translate("main", "The measurement file."));
|
||||||
|
//-----
|
||||||
|
QCommandLineOption heightOption(QStringList() << "h" << "height",
|
||||||
|
QCoreApplication::translate("main", "Open with the base height: 92, 98, 104, 110, 116, 122, 128, 134, 140, 146, "
|
||||||
|
"152, 158, 164, 170, 176, 182, 188 (default is measurement file value)."),
|
||||||
|
QCoreApplication::translate("main", "The base height"));
|
||||||
|
parser.addOption(heightOption);
|
||||||
|
//-----
|
||||||
|
QCommandLineOption sizeOption(QStringList() << "s" << "size",
|
||||||
|
QCoreApplication::translate("main", "Open with the base size: 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, "
|
||||||
|
"48, 50, 52, 54, 56 (default is measurement file value)."),
|
||||||
|
QCoreApplication::translate("main", "The Base size"));
|
||||||
|
parser.addOption(sizeOption);
|
||||||
|
//-----
|
||||||
|
QCommandLineOption unitOption(QStringList() << "u" << "unit",
|
||||||
|
QCoreApplication::translate("main", "Set pattern file unit: cm, mm, inch (default is measurement file value)."),
|
||||||
|
QCoreApplication::translate("main", "The pattern unit"));
|
||||||
|
parser.addOption(unitOption);
|
||||||
|
//-----
|
||||||
|
parser.process(app);
|
||||||
|
|
||||||
|
bool flagHeight = false;
|
||||||
|
bool flagSize = false;
|
||||||
|
bool flagUnit = false;
|
||||||
|
|
||||||
|
int size = 0;
|
||||||
|
int height = 0;
|
||||||
|
Unit unit = Unit::Cm;
|
||||||
|
|
||||||
|
{
|
||||||
|
const QString heightValue = parser.value(heightOption);
|
||||||
|
if (not heightValue.isEmpty())
|
||||||
|
{
|
||||||
|
const QStringList heights = VMeasurement::WholeListHeights(Unit::Cm);
|
||||||
|
if (heights.contains(heightValue))
|
||||||
|
{
|
||||||
|
flagHeight = true;
|
||||||
|
height = heightValue.toInt();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s\n", qPrintable(QCoreApplication::translate("main",
|
||||||
|
"Error: Invalid base height argument. Must be 92, 98, 104, 110, 116, 122, 128, 134, 140, 146, 152, 158, "
|
||||||
|
"164, 170, 176, 182 or 188.")));
|
||||||
|
parser.showHelp(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const QString sizeValue = parser.value(sizeOption);
|
||||||
|
if (not sizeValue.isEmpty())
|
||||||
|
{
|
||||||
|
const QStringList sizes = VMeasurement::WholeListSizes(Unit::Cm);
|
||||||
|
if (sizes.contains(sizeValue))
|
||||||
|
{
|
||||||
|
flagSize = true;
|
||||||
|
size = sizeValue.toInt();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s\n", qPrintable(QCoreApplication::translate("main",
|
||||||
|
"Error: Invalid base size argument. Must be 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, "
|
||||||
|
"52, 54 or 56.")));
|
||||||
|
parser.showHelp(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const QString unitValue = parser.value(unitOption);
|
||||||
|
if (not unitValue.isEmpty())
|
||||||
|
{
|
||||||
|
|
||||||
|
const QStringList units = QStringList() << VDomDocument::UnitMM
|
||||||
|
<< VDomDocument::UnitCM
|
||||||
|
<< VDomDocument::UnitINCH;
|
||||||
|
if (units.contains(unitValue))
|
||||||
|
{
|
||||||
|
flagUnit = true;
|
||||||
|
unit = VDomDocument::StrToUnits(unitValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s\n", qPrintable(QCoreApplication::translate("main",
|
||||||
|
"Error: Invalid base size argument. Must be cm, mm or inch.")));
|
||||||
|
parser.showHelp(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const QStringList args = parser.positionalArguments();
|
||||||
if (args.count() > 1)
|
if (args.count() > 1)
|
||||||
{
|
{
|
||||||
args.removeFirst();
|
|
||||||
for (int i = 0; i < args.size(); ++i)
|
for (int i = 0; i < args.size(); ++i)
|
||||||
{
|
{
|
||||||
app.NewMainWindow();
|
app.NewMainWindow();
|
||||||
app.MainWindow()->LoadFile(args.at(i));
|
app.MainWindow()->LoadFile(args.at(i));
|
||||||
|
|
||||||
|
if (flagSize)
|
||||||
|
{
|
||||||
|
app.MainWindow()->SetBaseMSize(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flagHeight)
|
||||||
|
{
|
||||||
|
app.MainWindow()->SetBaseMHeight(height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flagUnit)
|
||||||
|
{
|
||||||
|
app.MainWindow()->SetPUnit(unit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -119,6 +119,43 @@ void TMainWindow::RetranslateTable()
|
||||||
ui->tableWidget->selectRow(row);
|
ui->tableWidget->selectRow(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TMainWindow::SetBaseMHeight(int height)
|
||||||
|
{
|
||||||
|
if (m != nullptr)
|
||||||
|
{
|
||||||
|
if (mType == MeasurementsType::Standard)
|
||||||
|
{
|
||||||
|
const int row = ui->tableWidget->currentRow();
|
||||||
|
data->SetHeight(UnitConvertor(height, Unit::Cm, mUnit));
|
||||||
|
RefreshData();
|
||||||
|
ui->tableWidget->selectRow(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TMainWindow::SetBaseMSize(int size)
|
||||||
|
{
|
||||||
|
if (m != nullptr)
|
||||||
|
{
|
||||||
|
if (mType == MeasurementsType::Standard)
|
||||||
|
{
|
||||||
|
const int row = ui->tableWidget->currentRow();
|
||||||
|
data->SetSize(UnitConvertor(size, Unit::Cm, mUnit));
|
||||||
|
RefreshData();
|
||||||
|
ui->tableWidget->selectRow(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TMainWindow::SetPUnit(Unit unit)
|
||||||
|
{
|
||||||
|
pUnit = unit;
|
||||||
|
UpdatePatternUnit();
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TMainWindow::LoadFile(const QString &path)
|
void TMainWindow::LoadFile(const QString &path)
|
||||||
{
|
{
|
||||||
|
@ -880,36 +917,18 @@ void TMainWindow::ImportFromPattern()
|
||||||
void TMainWindow::ChangedSize(const QString &text)
|
void TMainWindow::ChangedSize(const QString &text)
|
||||||
{
|
{
|
||||||
const int row = ui->tableWidget->currentRow();
|
const int row = ui->tableWidget->currentRow();
|
||||||
|
|
||||||
if (row == -1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
data->SetSize(text.toInt());
|
data->SetSize(text.toInt());
|
||||||
RefreshData();
|
RefreshData();
|
||||||
|
|
||||||
ui->tableWidget->blockSignals(true);
|
|
||||||
ui->tableWidget->selectRow(row);
|
ui->tableWidget->selectRow(row);
|
||||||
ui->tableWidget->blockSignals(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TMainWindow::ChangedHeight(const QString &text)
|
void TMainWindow::ChangedHeight(const QString &text)
|
||||||
{
|
{
|
||||||
const int row = ui->tableWidget->currentRow();
|
const int row = ui->tableWidget->currentRow();
|
||||||
|
|
||||||
if (row == -1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
data->SetHeight(text.toInt());
|
data->SetHeight(text.toInt());
|
||||||
RefreshData();
|
RefreshData();
|
||||||
|
|
||||||
ui->tableWidget->blockSignals(true);
|
|
||||||
ui->tableWidget->selectRow(row);
|
ui->tableWidget->selectRow(row);
|
||||||
ui->tableWidget->blockSignals(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -1282,17 +1301,7 @@ void TMainWindow::PatternUnitChanged(int index)
|
||||||
{
|
{
|
||||||
pUnit = static_cast<Unit>(comboBoxUnits->itemData(index).toInt());
|
pUnit = static_cast<Unit>(comboBoxUnits->itemData(index).toInt());
|
||||||
|
|
||||||
const int row = ui->tableWidget->currentRow();
|
UpdatePatternUnit();
|
||||||
|
|
||||||
if (row == -1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ShowUnits();
|
|
||||||
RefreshTable();
|
|
||||||
|
|
||||||
ui->tableWidget->selectRow(row);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -1936,6 +1945,22 @@ QStringList TMainWindow::FilterMeasurements(const QStringList &mNew, const QStri
|
||||||
return QStringList(import.toList());
|
return QStringList(import.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TMainWindow::UpdatePatternUnit()
|
||||||
|
{
|
||||||
|
const int row = ui->tableWidget->currentRow();
|
||||||
|
|
||||||
|
if (row == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowUnits();
|
||||||
|
RefreshTable();
|
||||||
|
|
||||||
|
ui->tableWidget->selectRow(row);
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TMainWindow::SetDecimals()
|
void TMainWindow::SetDecimals()
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,6 +58,10 @@ public:
|
||||||
|
|
||||||
void RetranslateTable();
|
void RetranslateTable();
|
||||||
|
|
||||||
|
void SetBaseMHeight(int height);
|
||||||
|
void SetBaseMSize(int size);
|
||||||
|
void SetPUnit(Unit unit);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void LoadFile(const QString &path);
|
void LoadFile(const QString &path);
|
||||||
void FileNew();
|
void FileNew();
|
||||||
|
@ -171,6 +175,8 @@ private:
|
||||||
void WriteSettings();
|
void WriteSettings();
|
||||||
|
|
||||||
QStringList FilterMeasurements(const QStringList &mNew, const QStringList &mFilter);
|
QStringList FilterMeasurements(const QStringList &mNew, const QStringList &mFilter);
|
||||||
|
|
||||||
|
void UpdatePatternUnit();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TMAINWINDOW_H
|
#endif // TMAINWINDOW_H
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include <QMessageBox> // For QT_REQUIRE_VERSION
|
#include <QMessageBox> // For QT_REQUIRE_VERSION
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
||||||
# include "../libs/vmisc/backport/qcommandlineparser.h"
|
# include "../../libs/vmisc/backport/qcommandlineparser.h"
|
||||||
#else
|
#else
|
||||||
# include <QCommandLineParser>
|
# include <QCommandLineParser>
|
||||||
#endif
|
#endif
|
||||||
|
@ -68,6 +68,7 @@ int main(int argc, char *argv[])
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
parser.addVersionOption();
|
parser.addVersionOption();
|
||||||
parser.addPositionalArgument("filename", QCoreApplication::translate("main", "Pattern file."));
|
parser.addPositionalArgument("filename", QCoreApplication::translate("main", "Pattern file."));
|
||||||
|
// Process the actual command line arguments given by the user
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
QStringList args = parser.positionalArguments();
|
QStringList args = parser.positionalArguments();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user