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. .\" Manpage for tape.
.\" Contact dismine@gmail.com to correct errors. .\" 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 .SH NAME
Tape \- Valentina's measurements editor. Tape \- Valentina's measurements editor.
.SH SYNOPSIS .SH SYNOPSIS
@ -20,12 +20,14 @@ is a part of Valentina. And used for creating and editing measurement files.
Displays this help. Displays this help.
.IP "-v, --version" .IP "-v, --version"
Displays version information. Displays version information.
.IP "-e, --height <The base height>" .IP "-a, --dimensionA <The dimension A base>"
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. Set base for dimension A in the table units.
.IP "-s, --size <The base size>" .IP "-b, --dimensionB <The dimension B base>"
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. Set base for dimension B in the table units.
.IP "-u, --unit <The pattern unit>" .IP "-c, --dimensionA <The dimension C base>"
Set pattern file unit: cm, mm, inch. Set base for dimension C in the table units.
.IP "-u, --units <The pattern units>"
Set pattern file units: cm, mm, inch.
.IP "--test" .IP "--test"
Use for unit testing. Run the program and open a file without showing the main window. Use for unit testing. Run the program and open a file without showing the main window.
.IP "--no-scaling" .IP "--no-scaling"
@ -35,9 +37,5 @@ Disable high dpi scaling. Call this option if has problem with scaling (by defau
\- the measurement file. \- the measurement file.
.SH AUTHOR .SH AUTHOR
.RI "This manual page was written by Roman Telezhynskyi <" dismine@gmail.com ">" .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) .BR valentina (1)

View File

@ -599,96 +599,46 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
parser.addHelpOption(); parser.addHelpOption();
parser.addVersionOption(); parser.addVersionOption();
parser.addPositionalArgument("filename", tr("The measurement file.")); parser.addPositionalArgument("filename", tr("The measurement file."));
//-----
QCommandLineOption heightOption(QStringList() << "e" << "height", const QString LONG_OPTION_DIMENSION_A = QStringLiteral("dimensionA");
tr("Open with the base height. Valid values: %1cm.") const QString SINGLE_OPTION_DIMENSION_A = QChar('a');
.arg(VMeasurement::WholeListHeights(Unit::Cm).join(", ")),
tr("The base height")); const QString LONG_OPTION_DIMENSION_B = QStringLiteral("dimensionB");
parser.addOption(heightOption); const QString SINGLE_OPTION_DIMENSION_B = QChar('b');
//-----
QCommandLineOption sizeOption(QStringList() << "s" << "size", const QString LONG_OPTION_DIMENSION_C = QStringLiteral("dimensionC");
tr("Open with the base size. Valid values: %1cm.").arg(VMeasurement::WholeListSizes(Unit::Cm).join(", ")), const QString SINGLE_OPTION_DIMENSION_C = QChar('c');
tr("The base size"));
parser.addOption(sizeOption); const QString LONG_OPTION_UNITS = QStringLiteral("units");
//----- const QString SINGLE_OPTION_UNITS = QChar('u');
QCommandLineOption unitOption(QStringList() << "u" << "unit",
tr("Set pattern file unit: cm, mm, inch."), const QString LONG_OPTION_TEST = QStringLiteral("test");
tr("The pattern unit"));
parser.addOption(unitOption); parser.addOptions(
//----- {
QCommandLineOption testOption(QStringList() << "test", {{SINGLE_OPTION_DIMENSION_A, LONG_OPTION_DIMENSION_A}, tr("Set base for dimension A in the table units."),
tr("Use for unit testing. Run the program and open a file without showing the main window.")); tr("The dimension A base")},
parser.addOption(testOption);
//----- {{SINGLE_OPTION_DIMENSION_B, LONG_OPTION_DIMENSION_B}, tr("Set base for dimension B in the table units."),
QCommandLineOption scalingOption(QStringList() << LONG_OPTION_NO_HDPI_SCALING, tr("The dimension B base")},
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")); {{SINGLE_OPTION_DIMENSION_C, LONG_OPTION_DIMENSION_C}, tr("Set base for dimension C in the table units."),
parser.addOption(scalingOption); 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.process(arguments); parser.process(arguments);
bool flagHeight = false; testMode = parser.isSet(LONG_OPTION_TEST);
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);
if (not testMode && connection == SocketConnection::Client) if (not testMode && connection == SocketConnection::Client)
{ {
@ -737,6 +687,84 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
parser.showHelp(V_EX_USAGE); 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) for (auto &arg : args)
{ {
NewMainWindow(); NewMainWindow();
@ -750,17 +778,31 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
continue; 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); MainWindow()->SetPUnit(unit);
} }

View File

@ -87,24 +87,7 @@ enum {ColumnName = 0, ColumnFullName, ColumnCalcValue, ColumnFormula, ColumnBase
TMainWindow::TMainWindow(QWidget *parent) TMainWindow::TMainWindow(QWidget *parent)
: VAbstractMainWindow(parent), : VAbstractMainWindow(parent),
ui(new Ui::TMainWindow), ui(new Ui::TMainWindow),
m(nullptr), formulaBaseHeight(0)
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()
{ {
ui->setupUi(this); ui->setupUi(this);
@ -173,45 +156,79 @@ void TMainWindow::RetranslateTable()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SetBaseMHeight(int height) bool TMainWindow::SetDimensionABase(int base)
{ {
if (m != nullptr) const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
if (dimensions.isEmpty())
{ {
if (mType == MeasurementsType::Multisize) qCCritical(tMainWindow, "%s\n", qPrintable(tr("The table doesn't provide dimensions")));
{ return false;
const int row = ui->tableWidget->currentRow();
currentDimensionA = UnitConvertor(height, Unit::Cm, mUnit);
gradationHeights->blockSignals(true);
SetDefaultHeight(static_cast<int>(currentDimensionA));
gradationHeights->blockSignals(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) const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
if (dimensions.size() <= 1)
{ {
if (mType == MeasurementsType::Multisize) qCCritical(tMainWindow, "%s\n", qPrintable(tr("The table doesn't support dimension B")));
{ return false;
const int row = ui->tableWidget->currentRow();
currentDimensionB = UnitConvertor(size, Unit::Cm, mUnit);
gradationSizes->blockSignals(true);
SetDefaultSize(static_cast<int>(currentDimensionB));
gradationSizes->blockSignals(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 RetranslateTable();
void SetBaseMHeight(int height); bool SetDimensionABase(int base);
void SetBaseMSize(int size); bool SetDimensionBBase(int base);
bool SetDimensionCBase(int base);
void SetPUnit(Unit unit); void SetPUnit(Unit unit);
bool LoadFile(const QString &path); bool LoadFile(const QString &path);
@ -132,29 +133,31 @@ private slots:
private: private:
Q_DISABLE_COPY(TMainWindow) Q_DISABLE_COPY(TMainWindow)
Ui::TMainWindow *ui; Ui::TMainWindow *ui;
VMeasurements *m; VMeasurements *m{nullptr};
VContainer *data; VContainer *data{nullptr};
Unit mUnit; Unit mUnit{Unit::Cm};
Unit pUnit; Unit pUnit{Unit::Cm};
MeasurementsType mType; MeasurementsType mType{MeasurementsType::Individual};
int currentDimensionA{0}; int currentDimensionA{0};
int currentDimensionB{0}; int currentDimensionB{0};
int currentDimensionC{0}; int currentDimensionC{0};
QString curFile; QString curFile{};
QComboBox *gradationHeights; QComboBox *gradationDimensionA{nullptr};
QComboBox *gradationSizes; QComboBox *gradationDimensionB{nullptr};
QComboBox *comboBoxUnits; QComboBox *gradationDimensionC{nullptr};
QComboBox *comboBoxUnits{nullptr};
int formulaBaseHeight; int formulaBaseHeight;
QSharedPointer<VLockGuard<char>> lock; QSharedPointer<VLockGuard<char>> lock{nullptr};
QSharedPointer<VTableSearch> search; QSharedPointer<VTableSearch> search{};
QLabel *labelGradationHeights; QLabel *labelGradationDimensionA{nullptr};
QLabel *labelGradationSizes; QLabel *labelGradationDimensionB{nullptr};
QLabel *labelPatternUnit; QLabel *labelGradationDimensionC{nullptr};
bool isInitialized; QLabel *labelPatternUnit{nullptr};
bool mIsReadOnly; bool isInitialized{false};
bool mIsReadOnly{false};
QAction *actionFullCircumference{nullptr}; QAction *actionFullCircumference{nullptr};
QVector<QObject *> hackedWidgets; QVector<QObject *> hackedWidgets{};
void SetupMenu(); void SetupMenu();
void InitWindow(); void InitWindow();