Changes to CLI.

This commit is contained in:
Roman Telezhynskyi 2020-10-03 07:33:56 +03:00
parent a16e6bc082
commit 20675a081a
4 changed files with 231 additions and 171 deletions

20
dist/debian/tape.1 vendored
View File

@ -1,6 +1,6 @@
.\" Manpage for tape.
.\" Contact dismine@gmail.com to correct errors.
.TH tape 1 "10 March, 2017" "tape man page"
.TH tape 1 "3 October, 2020" "tape man page"
.SH NAME
Tape \- Valentina's measurements editor.
.SH SYNOPSIS
@ -20,12 +20,14 @@ is a part of Valentina. And used for creating and editing measurement files.
Displays this help.
.IP "-v, --version"
Displays version information.
.IP "-e, --height <The base height>"
Open with the base height. Valid values: 92, 98, 104, 110, 116, 122, 128, 134, 140, 146, 152, 158, 164, 170, 176, 182, 188, 194, 200cm.
.IP "-s, --size <The base size>"
Open with the base size. Valid values: 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56cm.
.IP "-u, --unit <The pattern unit>"
Set pattern file unit: cm, mm, inch.
.IP "-a, --dimensionA <The dimension A base>"
Set base for dimension A in the table units.
.IP "-b, --dimensionB <The dimension B base>"
Set base for dimension B in the table units.
.IP "-c, --dimensionA <The dimension C base>"
Set base for dimension C in the table units.
.IP "-u, --units <The pattern units>"
Set pattern file units: cm, mm, inch.
.IP "--test"
Use for unit testing. Run the program and open a file without showing the main window.
.IP "--no-scaling"
@ -35,9 +37,5 @@ Disable high dpi scaling. Call this option if has problem with scaling (by defau
\- the measurement file.
.SH AUTHOR
.RI "This manual page was written by Roman Telezhynskyi <" dismine@gmail.com ">"
.SH "SEE ALSO"
.RB "Full " "User Manual" " is availiable in"
.UR https://bitbucket.org/dismine/valentina/wiki/manual/Content
.UE
.BR valentina (1)

View File

@ -599,96 +599,46 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("filename", tr("The measurement file."));
//-----
QCommandLineOption heightOption(QStringList() << "e" << "height",
tr("Open with the base height. Valid values: %1cm.")
.arg(VMeasurement::WholeListHeights(Unit::Cm).join(", ")),
tr("The base height"));
parser.addOption(heightOption);
//-----
QCommandLineOption sizeOption(QStringList() << "s" << "size",
tr("Open with the base size. Valid values: %1cm.").arg(VMeasurement::WholeListSizes(Unit::Cm).join(", ")),
tr("The base size"));
parser.addOption(sizeOption);
//-----
QCommandLineOption unitOption(QStringList() << "u" << "unit",
tr("Set pattern file unit: cm, mm, inch."),
tr("The pattern unit"));
parser.addOption(unitOption);
//-----
QCommandLineOption testOption(QStringList() << "test",
tr("Use for unit testing. Run the program and open a file without showing the main window."));
parser.addOption(testOption);
//-----
QCommandLineOption scalingOption(QStringList() << LONG_OPTION_NO_HDPI_SCALING,
const QString LONG_OPTION_DIMENSION_A = QStringLiteral("dimensionA");
const QString SINGLE_OPTION_DIMENSION_A = QChar('a');
const QString LONG_OPTION_DIMENSION_B = QStringLiteral("dimensionB");
const QString SINGLE_OPTION_DIMENSION_B = QChar('b');
const QString LONG_OPTION_DIMENSION_C = QStringLiteral("dimensionC");
const QString SINGLE_OPTION_DIMENSION_C = QChar('c');
const QString LONG_OPTION_UNITS = QStringLiteral("units");
const QString SINGLE_OPTION_UNITS = QChar('u');
const QString LONG_OPTION_TEST = QStringLiteral("test");
parser.addOptions(
{
{{SINGLE_OPTION_DIMENSION_A, LONG_OPTION_DIMENSION_A}, tr("Set base for dimension A in the table units."),
tr("The dimension A base")},
{{SINGLE_OPTION_DIMENSION_B, LONG_OPTION_DIMENSION_B}, tr("Set base for dimension B in the table units."),
tr("The dimension B base")},
{{SINGLE_OPTION_DIMENSION_C, LONG_OPTION_DIMENSION_C}, tr("Set base for dimension C in the table units."),
tr("The dimension C base")},
{{SINGLE_OPTION_UNITS, LONG_OPTION_UNITS}, tr("Set pattern file units: cm, mm, inch."),
tr("The pattern units")},
{LONG_OPTION_TEST,
tr("Use for unit testing. Run the program and open a file without showing the main window.")},
{LONG_OPTION_NO_HDPI_SCALING,
tr("Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). "
"Alternatively you can use the %1 environment variable.").arg("QT_AUTO_SCREEN_SCALE_FACTOR=0"));
parser.addOption(scalingOption);
//-----
"Alternatively you can use the %1 environment variable.").arg("QT_AUTO_SCREEN_SCALE_FACTOR=0")},
});
parser.process(arguments);
bool flagHeight = false;
bool flagSize = false;
bool flagUnit = false;
int size = 0;
int height = 0;
Unit unit = Unit::Cm;
if (parser.isSet(heightOption))
{
const QString heightValue = parser.value(heightOption);
if (VMeasurement::IsGradationHeightValid(heightValue))
{
flagHeight = true;
height = heightValue.toInt();
}
else
{
qCCritical(mApp, "%s\n",
qPrintable(tr("Invalid base height argument. Must be %1cm.")
.arg(VMeasurement::WholeListHeights(Unit::Cm).join(", "))));
parser.showHelp(V_EX_USAGE);
}
}
if (parser.isSet(sizeOption))
{
const QString sizeValue = parser.value(sizeOption);
if (VMeasurement::IsGradationSizeValid(sizeValue))
{
flagSize = true;
size = sizeValue.toInt();
}
else
{
qCCritical(mApp, "%s\n",
qPrintable(tr("Invalid base size argument. Must be %1cm.")
.arg(VMeasurement::WholeListSizes(Unit::Cm).join(", "))));
parser.showHelp(V_EX_USAGE);
}
}
{
const QString unitValue = parser.value(unitOption);
if (not unitValue.isEmpty())
{
const QStringList units = QStringList() << unitMM << unitCM << unitINCH;
if (units.contains(unitValue))
{
flagUnit = true;
unit = StrToUnits(unitValue);
}
else
{
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid base size argument. Must be cm, mm or inch.")));
parser.showHelp(V_EX_USAGE);
}
}
}
testMode = parser.isSet(testOption);
testMode = parser.isSet(LONG_OPTION_TEST);
if (not testMode && connection == SocketConnection::Client)
{
@ -737,6 +687,84 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
parser.showHelp(V_EX_USAGE);
}
bool flagDimensionA = false;
bool flagDimensionB = false;
bool flagDimensionC = false;
bool flagUnits = false;
int dimensionAValue = 0;
int dimensionBValue = 0;
int dimensionCValue = 0;
Unit unit = Unit::Cm;
if (parser.isSet(LONG_OPTION_DIMENSION_A))
{
const QString value = parser.value(LONG_OPTION_DIMENSION_A);
bool ok = false;
dimensionAValue = value.toInt(&ok);
if(ok && dimensionAValue > 0)
{
flagDimensionA = true;
}
else
{
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension A base value.")));
parser.showHelp(V_EX_USAGE);
}
}
if (parser.isSet(LONG_OPTION_DIMENSION_B))
{
const QString value = parser.value(LONG_OPTION_DIMENSION_B);
bool ok = false;
dimensionBValue = value.toInt(&ok);
if(ok && dimensionBValue > 0)
{
flagDimensionB = true;
}
else
{
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension B base value.")));
parser.showHelp(V_EX_USAGE);
}
}
if (parser.isSet(LONG_OPTION_DIMENSION_C))
{
const QString value = parser.value(LONG_OPTION_DIMENSION_C);
bool ok = false;
dimensionCValue = value.toInt(&ok);
if(ok && dimensionCValue > 0)
{
flagDimensionC = true;
}
else
{
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension C base value.")));
parser.showHelp(V_EX_USAGE);
}
}
{
const QString unitValue = parser.value(LONG_OPTION_UNITS);
if (not unitValue.isEmpty())
{
if (QStringList{unitMM, unitCM, unitINCH}.contains(unitValue))
{
flagUnits = true;
unit = StrToUnits(unitValue);
}
else
{
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid base size argument. Must be cm, mm or inch.")));
parser.showHelp(V_EX_USAGE);
}
}
}
for (auto &arg : args)
{
NewMainWindow();
@ -750,17 +778,31 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
continue;
}
if (flagSize)
if (flagDimensionA)
{
MainWindow()->SetBaseMSize(size);
if (not MainWindow()->SetDimensionABase(dimensionAValue))
{
parser.showHelp(V_EX_USAGE);
}
}
if (flagHeight)
if (flagDimensionB)
{
MainWindow()->SetBaseMHeight(height);
if (MainWindow()->SetDimensionBBase(dimensionBValue))
{
parser.showHelp(V_EX_USAGE);
}
}
if (flagUnit)
if (flagDimensionC)
{
if (MainWindow()->SetDimensionCBase(dimensionCValue))
{
parser.showHelp(V_EX_USAGE);
}
}
if (flagUnits)
{
MainWindow()->SetPUnit(unit);
}

View File

@ -87,24 +87,7 @@ enum {ColumnName = 0, ColumnFullName, ColumnCalcValue, ColumnFormula, ColumnBase
TMainWindow::TMainWindow(QWidget *parent)
: VAbstractMainWindow(parent),
ui(new Ui::TMainWindow),
m(nullptr),
data(nullptr),
mUnit(Unit::Cm),
pUnit(Unit::Cm),
mType(MeasurementsType::Individual),
curFile(),
gradationHeights(nullptr),
gradationSizes(nullptr),
comboBoxUnits(nullptr),
formulaBaseHeight(0),
lock(nullptr),
search(),
labelGradationHeights(nullptr),
labelGradationSizes(nullptr),
labelPatternUnit(nullptr),
isInitialized(false),
mIsReadOnly(false),
hackedWidgets()
formulaBaseHeight(0)
{
ui->setupUi(this);
@ -173,45 +156,79 @@ void TMainWindow::RetranslateTable()
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SetBaseMHeight(int height)
bool TMainWindow::SetDimensionABase(int base)
{
if (m != nullptr)
{
if (mType == MeasurementsType::Multisize)
{
const int row = ui->tableWidget->currentRow();
currentDimensionA = UnitConvertor(height, Unit::Cm, mUnit);
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
gradationHeights->blockSignals(true);
SetDefaultHeight(static_cast<int>(currentDimensionA));
gradationHeights->blockSignals(false);
if (dimensions.isEmpty())
{
qCCritical(tMainWindow, "%s\n", qPrintable(tr("The table doesn't provide dimensions")));
return false;
}
RefreshData();
search->RefreshList(ui->lineEditFind->text());
ui->tableWidget->selectRow(row);
const qint32 i = gradationDimensionA->findData(base);
if (i != -1)
{
gradationDimensionA->setCurrentIndex(i);
}
if (base != currentDimensionA)
{
qCCritical(tMainWindow, "%s\n", qPrintable(tr("Invalid base value for dimension A")));
return false;
}
return true;
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SetBaseMSize(int size)
bool TMainWindow::SetDimensionBBase(int base)
{
if (m != nullptr)
{
if (mType == MeasurementsType::Multisize)
{
const int row = ui->tableWidget->currentRow();
currentDimensionB = UnitConvertor(size, Unit::Cm, mUnit);
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
gradationSizes->blockSignals(true);
SetDefaultSize(static_cast<int>(currentDimensionB));
gradationSizes->blockSignals(false);
if (dimensions.size() <= 1)
{
qCCritical(tMainWindow, "%s\n", qPrintable(tr("The table doesn't support dimension B")));
return false;
}
RefreshData();
search->RefreshList(ui->lineEditFind->text());
ui->tableWidget->selectRow(row);
const qint32 i = gradationDimensionB->findData(base);
if (i != -1)
{
gradationDimensionB->setCurrentIndex(i);
}
if (base != currentDimensionB)
{
qCCritical(tMainWindow, "%s\n", qPrintable(tr("Invalid base value for dimension B")));
return false;
}
return true;
}
//---------------------------------------------------------------------------------------------------------------------
bool TMainWindow::SetDimensionCBase(int base)
{
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
if (dimensions.size() <= 2)
{
qCCritical(tMainWindow, "%s\n", qPrintable(tr("The table doesn't support dimension C")));
return false;
}
const qint32 i = gradationDimensionC->findData(base);
if (i != -1)
{
gradationDimensionC->setCurrentIndex(i);
}
if (base != currentDimensionC)
{
qCCritical(tMainWindow, "%s\n", qPrintable(tr("Invalid base value for dimension C")));
return false;
}
return true;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -57,8 +57,9 @@ public:
void RetranslateTable();
void SetBaseMHeight(int height);
void SetBaseMSize(int size);
bool SetDimensionABase(int base);
bool SetDimensionBBase(int base);
bool SetDimensionCBase(int base);
void SetPUnit(Unit unit);
bool LoadFile(const QString &path);
@ -132,29 +133,31 @@ private slots:
private:
Q_DISABLE_COPY(TMainWindow)
Ui::TMainWindow *ui;
VMeasurements *m;
VContainer *data;
Unit mUnit;
Unit pUnit;
MeasurementsType mType;
VMeasurements *m{nullptr};
VContainer *data{nullptr};
Unit mUnit{Unit::Cm};
Unit pUnit{Unit::Cm};
MeasurementsType mType{MeasurementsType::Individual};
int currentDimensionA{0};
int currentDimensionB{0};
int currentDimensionC{0};
QString curFile;
QComboBox *gradationHeights;
QComboBox *gradationSizes;
QComboBox *comboBoxUnits;
QString curFile{};
QComboBox *gradationDimensionA{nullptr};
QComboBox *gradationDimensionB{nullptr};
QComboBox *gradationDimensionC{nullptr};
QComboBox *comboBoxUnits{nullptr};
int formulaBaseHeight;
QSharedPointer<VLockGuard<char>> lock;
QSharedPointer<VTableSearch> search;
QLabel *labelGradationHeights;
QLabel *labelGradationSizes;
QLabel *labelPatternUnit;
bool isInitialized;
bool mIsReadOnly;
QSharedPointer<VLockGuard<char>> lock{nullptr};
QSharedPointer<VTableSearch> search{};
QLabel *labelGradationDimensionA{nullptr};
QLabel *labelGradationDimensionB{nullptr};
QLabel *labelGradationDimensionC{nullptr};
QLabel *labelPatternUnit{nullptr};
bool isInitialized{false};
bool mIsReadOnly{false};
QAction *actionFullCircumference{nullptr};
QVector<QObject *> hackedWidgets;
QVector<QObject *> hackedWidgets{};
void SetupMenu();
void InitWindow();