diff --git a/src/app/container/vmeasurement.cpp b/src/app/container/vmeasurement.cpp index d8b0ab33c..a93ef1a41 100644 --- a/src/app/container/vmeasurement.cpp +++ b/src/app/container/vmeasurement.cpp @@ -97,7 +97,7 @@ VMeasurement::~VMeasurement() {} //--------------------------------------------------------------------------------------------------------------------- -QStringList VMeasurement::ListHeights() +QStringList VMeasurement::ListHeights(QMap heights) { QStringList list; if (qApp->patternUnit() == Unit::Inch) @@ -106,16 +106,29 @@ QStringList VMeasurement::ListHeights() return list; } - // from 92 cm to 188 cm - for (int i = 92; i<= 188; i = i+6) + QMap::const_iterator i = heights.constBegin(); + while (i != heights.constEnd()) { - ListValue(list, i); + if (i.value() && i.key() != GHeights::ALL) + { + ListValue(list, static_cast(i.key())); + } + ++i; + } + + if (list.isEmpty()) + { + // from 92 cm to 194 cm + for (int i = 92; i<= 194; i = i+6) + { + ListValue(list, i); + } } return list; } //--------------------------------------------------------------------------------------------------------------------- -QStringList VMeasurement::ListSizes() +QStringList VMeasurement::ListSizes(QMap sizes) { QStringList list; if (qApp->patternUnit() == Unit::Inch) @@ -124,10 +137,23 @@ QStringList VMeasurement::ListSizes() return list; } - // from 22 cm to 56 cm - for (int i = 22; i<= 56; i = i+2) + QMap::const_iterator i = sizes.constBegin(); + while (i != sizes.constEnd()) { - ListValue(list, i); + if (i.value() && i.key() != GSizes::ALL) + { + ListValue(list, static_cast(i.key())); + } + ++i; + } + + if (list.isEmpty()) + { + // from 22 cm to 56 cm + for (int i = 22; i<= 56; i = i+2) + { + ListValue(list, i); + } } return list; } diff --git a/src/app/container/vmeasurement.h b/src/app/container/vmeasurement.h index a5955b09a..5bcdaede7 100644 --- a/src/app/container/vmeasurement.h +++ b/src/app/container/vmeasurement.h @@ -30,6 +30,7 @@ #define VSTANDARDTABLEROW_H #include "vvariable.h" +#include "../options.h" #include @@ -52,8 +53,8 @@ public: QString GetGuiText() const; QString TagName() const; void setTagName(const QString &TagName); - static QStringList ListHeights(); - static QStringList ListSizes(); + static QStringList ListHeights(QMap heights); + static QStringList ListSizes(QMap sizes); private: /** @brief description description measurement */ QString gui_text; diff --git a/src/app/dialogs/app/dialogpatternproperties.cpp b/src/app/dialogs/app/dialogpatternproperties.cpp index b0e24d325..d040d08f6 100644 --- a/src/app/dialogs/app/dialogpatternproperties.cpp +++ b/src/app/dialogs/app/dialogpatternproperties.cpp @@ -28,40 +28,56 @@ #include "dialogpatternproperties.h" #include "ui_dialogpatternproperties.h" -#include #include #include "../../xml/vpattern.h" #include "../../widgets/vapplication.h" +#define MAX_HEIGHTS 18 +#define MAX_SIZES 18 + //--------------------------------------------------------------------------------------------------------------------- DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent) : - QDialog(parent), ui(new Ui::DialogPatternProperties), doc(doc) + QDialog(parent), ui(new Ui::DialogPatternProperties), doc(doc), heightsChecked(MAX_HEIGHTS), + sizesChecked(MAX_SIZES), heights (QMap()), sizes(QMap()), + data(QMap()), descriptionChanged(false), gradationChanged(false) { ui->setupUi(this); SCASSERT(doc != nullptr); - QSettings *settings = qApp->getSettings(); - SCASSERT(settings != nullptr); -#ifdef Q_OS_WIN - QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString(); -#else - QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USER").constData())).toString(); -#endif + ui->lineEditAuthor->setText(doc->GetAuthor()); + connect(ui->lineEditAuthor, &QLineEdit::editingFinished, this, &DialogPatternProperties::DescEdited); - ui->lineEditAuthor->setText(this->doc->UniqueTagText("author", user)); - ui->plainTextEditDescription->setPlainText(this->doc->UniqueTagText("description")); - ui->plainTextEditTechNotes->setPlainText(this->doc->UniqueTagText("notes")); + ui->plainTextEditDescription->setPlainText(doc->GetDescription()); + connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &DialogPatternProperties::DescEdited); - QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - SCASSERT(bOk != nullptr); - connect(bOk, &QPushButton::clicked, this, &DialogPatternProperties::Apply); + ui->plainTextEditTechNotes->setPlainText(doc->GetNotes()); + connect(ui->plainTextEditTechNotes, &QPlainTextEdit::textChanged, this, &DialogPatternProperties::DescEdited); + + connect(ui->buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &DialogPatternProperties::Ok); + connect(ui->buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, + &DialogPatternProperties::Apply); QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); SCASSERT(bCansel != nullptr); connect(bCansel, &QPushButton::clicked, this, &DialogPatternProperties::close); - connect(this, &DialogPatternProperties::haveChange, this->doc, &VPattern::haveLiteChange); + ui->tabWidget->setCurrentIndex(0); + if (qApp->patternType() == MeasurementsType::Individual) + { + ui->tabWidget->setTabEnabled(1, false); + } + + InitHeights(); + InitSizes(); + + heights = doc->GetGradationHeights(); + sizes = doc->GetGradationSizes(); + + SetOptions(heights); + SetOptions(sizes); + + gradationChanged = false;//Set to default value after initialization } //--------------------------------------------------------------------------------------------------------------------- @@ -73,49 +89,312 @@ DialogPatternProperties::~DialogPatternProperties() //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::Apply() { - Write("notes", ui->plainTextEditTechNotes->document()->toPlainText()); - Write("description", ui->plainTextEditDescription->document()->toPlainText()); - Write("author", ui->lineEditAuthor->text()); - emit haveChange(); + switch (ui->tabWidget->currentIndex()) + { + case 0: + SaveDescription(); + descriptionChanged = false; + break; + case 1: + SaveGradation(); + gradationChanged = false; + break; + default: + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::Ok() +{ + if (descriptionChanged) + { + SaveDescription(); + descriptionChanged = false; + } + + if (gradationChanged) + { + SaveGradation(); + gradationChanged = false; + } + close(); } //--------------------------------------------------------------------------------------------------------------------- -void DialogPatternProperties::Write(const QString &tagName, const QString &text) const +void DialogPatternProperties::SelectAll(int state) { - QDomNodeList nodeList = doc->elementsByTagName(tagName); - if (nodeList.isEmpty()) + QCheckBox* box = qobject_cast(sender()); + if (box) { - QDomElement pattern = doc->documentElement(); + if (box == ui->checkBoxAllHeights) + { + if (state == Qt::Checked) + { + SetHeightsChecked(true); + } + else if (state == Qt::Unchecked) + { + SetHeightsChecked(false); + } - QDomElement tag = doc->createElement(tagName); - QDomText domText = doc->createTextNode(text); - tag.appendChild(domText); - //Old pattern file doesn't have comment. But here we try insert tag after first child (comment). - // - // - // -->place for new tag<-- - // - if (pattern.firstChild().isComment()) - { - pattern.insertAfter(tag, pattern.firstChild()); + if (data.contains(box)) + { + heights.insert(static_cast(data.value(box)), box->isChecked()); + } } - else - { - pattern.insertBefore(tag, pattern.firstChild()); - } - } - else - { - QDomElement oldTag = nodeList.at(0).toElement(); - if (oldTag.isElement()) - { - QDomElement newTag = doc->createElement(tagName); - QDomText domText = doc->createTextNode(text); - newTag.appendChild(domText); - QDomElement pattern = doc->documentElement(); - pattern.replaceChild(newTag, oldTag); + if (box == ui->checkBoxAllSizes) + { + if (state == Qt::Checked) + { + SetSizesChecked(true); + } + else if (state == Qt::Unchecked) + { + SetSizesChecked(false); + } + + if (data.contains(box)) + { + sizes.insert(static_cast(data.value(box)), box->isChecked()); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::CheckStateHeight(int state) +{ + QCheckBox* box = qobject_cast(sender()); + if (box) + { + if (state == Qt::Checked) + { + ++heightsChecked; + if (heightsChecked == MAX_HEIGHTS) + { + ui->checkBoxAllHeights->blockSignals(true);//don't touch anothers checkboxes + ui->checkBoxAllHeights->setCheckState(Qt::Checked); + heights.insert(GHeights::ALL, true); + ui->checkBoxAllHeights->blockSignals(false); + } + } + else if (state == Qt::Unchecked) + { + if (heightsChecked == MAX_HEIGHTS) + { + ui->checkBoxAllHeights->blockSignals(true);//don't touch anothers checkboxes + ui->checkBoxAllHeights->setCheckState(Qt::Unchecked); + heights.insert(GHeights::ALL, false); + ui->checkBoxAllHeights->blockSignals(false); + } + --heightsChecked; + } + + if (data.contains(box)) + { + heights.insert(static_cast(data.value(box)), box->isChecked()); + } + + CheckApplyOk(); + gradationChanged = true; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::CheckStateSize(int state) +{ + QCheckBox* box = qobject_cast(sender()); + if (box) + { + + if (state == Qt::Checked) + { + ++sizesChecked; + if (sizesChecked == MAX_SIZES) + { + ui->checkBoxAllSizes->blockSignals(true);//don't touch anothers checkboxes + ui->checkBoxAllSizes->setCheckState(Qt::Checked); + sizes.insert(GSizes::ALL, true); + ui->checkBoxAllSizes->blockSignals(false); + } + } + else if (state == Qt::Unchecked) + { + if (sizesChecked == MAX_SIZES) + { + ui->checkBoxAllSizes->blockSignals(true);//don't touch anothers checkboxes + ui->checkBoxAllSizes->setCheckState(Qt::Unchecked); + sizes.insert(GSizes::ALL, false); + ui->checkBoxAllSizes->blockSignals(false); + } + --sizesChecked; + } + + if (data.contains(box)) + { + sizes.insert(static_cast(data.value(box)), box->isChecked()); + } + + CheckApplyOk(); + gradationChanged = true; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::DescEdited() +{ + descriptionChanged = true; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::SetHeightsChecked(bool enabled) +{ + ui->checkBoxH92->setChecked(enabled); + ui->checkBoxH98->setChecked(enabled); + ui->checkBoxH104->setChecked(enabled); + ui->checkBoxH110->setChecked(enabled); + ui->checkBoxH116->setChecked(enabled); + ui->checkBoxH122->setChecked(enabled); + ui->checkBoxH128->setChecked(enabled); + ui->checkBoxH134->setChecked(enabled); + ui->checkBoxH140->setChecked(enabled); + ui->checkBoxH146->setChecked(enabled); + ui->checkBoxH152->setChecked(enabled); + ui->checkBoxH158->setChecked(enabled); + ui->checkBoxH164->setChecked(enabled); + ui->checkBoxH170->setChecked(enabled); + ui->checkBoxH176->setChecked(enabled); + ui->checkBoxH182->setChecked(enabled); + ui->checkBoxH188->setChecked(enabled); + ui->checkBoxH194->setChecked(enabled); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::SetSizesChecked(bool enabled) +{ + ui->checkBoxS22->setChecked(enabled); + ui->checkBoxS24->setChecked(enabled); + ui->checkBoxS26->setChecked(enabled); + ui->checkBoxS28->setChecked(enabled); + ui->checkBoxS30->setChecked(enabled); + ui->checkBoxS32->setChecked(enabled); + ui->checkBoxS34->setChecked(enabled); + ui->checkBoxS36->setChecked(enabled); + ui->checkBoxS38->setChecked(enabled); + ui->checkBoxS40->setChecked(enabled); + ui->checkBoxS42->setChecked(enabled); + ui->checkBoxS44->setChecked(enabled); + ui->checkBoxS46->setChecked(enabled); + ui->checkBoxS48->setChecked(enabled); + ui->checkBoxS50->setChecked(enabled); + ui->checkBoxS52->setChecked(enabled); + ui->checkBoxS54->setChecked(enabled); + ui->checkBoxS56->setChecked(enabled); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::InitHeights() +{ + Init(ui->checkBoxAllHeights, static_cast(GHeights::ALL), &DialogPatternProperties::SelectAll); + + Init(ui->checkBoxH92, static_cast(GHeights::H92), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH98, static_cast(GHeights::H98), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH104, static_cast(GHeights::H104), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH110, static_cast(GHeights::H110), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH116, static_cast(GHeights::H116), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH122, static_cast(GHeights::H122), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH128, static_cast(GHeights::H128), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH134, static_cast(GHeights::H134), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH140, static_cast(GHeights::H140), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH146, static_cast(GHeights::H146), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH152, static_cast(GHeights::H152), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH158, static_cast(GHeights::H158), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH164, static_cast(GHeights::H164), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH170, static_cast(GHeights::H170), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH176, static_cast(GHeights::H176), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH182, static_cast(GHeights::H182), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH188, static_cast(GHeights::H188), &DialogPatternProperties::CheckStateHeight); + Init(ui->checkBoxH194, static_cast(GHeights::H194), &DialogPatternProperties::CheckStateHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::InitSizes() +{ + Init(ui->checkBoxAllSizes, static_cast(GSizes::ALL), &DialogPatternProperties::SelectAll); + + Init(ui->checkBoxS22, static_cast(GSizes::S22), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS24, static_cast(GSizes::S24), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS26, static_cast(GSizes::S26), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS28, static_cast(GSizes::S28), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS30, static_cast(GSizes::S30), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS32, static_cast(GSizes::S32), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS34, static_cast(GSizes::S34), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS36, static_cast(GSizes::S36), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS38, static_cast(GSizes::S38), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS40, static_cast(GSizes::S40), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS42, static_cast(GSizes::S42), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS44, static_cast(GSizes::S44), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS46, static_cast(GSizes::S46), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS48, static_cast(GSizes::S48), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS50, static_cast(GSizes::S50), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS52, static_cast(GSizes::S52), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS54, static_cast(GSizes::S54), &DialogPatternProperties::CheckStateSize); + Init(ui->checkBoxS56, static_cast(GSizes::S56), &DialogPatternProperties::CheckStateSize); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::CheckApplyOk() +{ + bool enable = !(heightsChecked == 0 || sizesChecked == 0); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enable); + ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(enable); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::SaveDescription() +{ + doc->SetNotes(ui->plainTextEditTechNotes->document()->toPlainText()); + doc->SetDescription(ui->plainTextEditTechNotes->document()->toPlainText()); + doc->SetAuthor(ui->lineEditAuthor->text()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::SaveGradation() +{ + doc->SetGradationHeights(heights); + doc->SetGradationSizes(sizes); + emit UpdateGradation(); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void DialogPatternProperties::Init(QCheckBox *check, int val, Func slot) +{ + connect(check, &QCheckBox::stateChanged, this, slot); + data.insert(check, val); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void DialogPatternProperties::SetOptions(const QMap &option) +{ + if (option.value(GVal::ALL) == false) + { + QMapIterator i(option); + while (i.hasNext()) + { + i.next(); + if (i.value() == false && i.key() != GVal::ALL) + { + QCheckBox *box = data.key(static_cast(i.key())); + if (box != nullptr) + { + box->setCheckState(Qt::Unchecked); + } + } } } } diff --git a/src/app/dialogs/app/dialogpatternproperties.h b/src/app/dialogs/app/dialogpatternproperties.h index c099058a5..1adcfbce3 100644 --- a/src/app/dialogs/app/dialogpatternproperties.h +++ b/src/app/dialogs/app/dialogpatternproperties.h @@ -30,8 +30,10 @@ #define DIALOGPATTERNPROPERTIES_H #include +#include "../../options.h" class VPattern; +class QCheckBox; namespace Ui { @@ -45,14 +47,37 @@ public: DialogPatternProperties(VPattern *doc, QWidget *parent = nullptr); virtual ~DialogPatternProperties(); signals: - void haveChange(); + void UpdateGradation(); public slots: void Apply(); + void Ok(); + void SelectAll(int state); + void CheckStateHeight(int state); + void CheckStateSize(int state); + void DescEdited(); private: Q_DISABLE_COPY(DialogPatternProperties) Ui::DialogPatternProperties *ui; - VPattern *doc; - void Write(const QString &tagName, const QString &text) const; + VPattern *doc; + char heightsChecked; + char sizesChecked; + QMap heights; + QMap sizes; + QMap data; + bool descriptionChanged; + bool gradationChanged; + + void SetHeightsChecked(bool enabled); + void SetSizesChecked(bool enabled); + void InitHeights(); + void InitSizes(); + template + void Init(QCheckBox *check, int val, Func slot); + template + void SetOptions(const QMap &option); + void CheckApplyOk(); + void SaveDescription(); + void SaveGradation(); }; #endif // DIALOGPATTERNPROPERTIES_H diff --git a/src/app/dialogs/app/dialogpatternproperties.ui b/src/app/dialogs/app/dialogpatternproperties.ui index f18932430..b7522a3c3 100644 --- a/src/app/dialogs/app/dialogpatternproperties.ui +++ b/src/app/dialogs/app/dialogpatternproperties.ui @@ -6,8 +6,8 @@ 0 0 - 646 - 605 + 657 + 562 @@ -17,52 +17,822 @@ :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png - + - - - - - Author name - - - - - - - - - - - - - - Pattern description - - - - - - - - - - - - - - - - - - For technical notes. - - - - - - - + + + 1 + + + + Description + + + + + + + + Author name + + + + + + + + + + + + + + Pattern description + + + + + + + + + + + + + + + + + + For technical notes. + + + + + + + + + + + + + Heights and Sizes + + + + + + + + + + All heights (cm) + + + true + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + QLayout::SetMaximumSize + + + + + true + + + + 0 + 0 + + + + 92 + + + true + + + + + + + true + + + + 0 + 0 + + + + 146 + + + true + + + + + + + true + + + + 0 + 0 + + + + 98 + + + true + + + + + + + true + + + + 0 + 0 + + + + 152 + + + true + + + + + + + true + + + + 0 + 0 + + + + + 0 + 0 + + + + 104 + + + true + + + + + + + true + + + + 0 + 0 + + + + 158 + + + true + + + + + + + true + + + + 0 + 0 + + + + 110 + + + true + + + + + + + true + + + + 0 + 0 + + + + 164 + + + true + + + + + + + true + + + + 0 + 0 + + + + 116 + + + true + + + + + + + true + + + + 0 + 0 + + + + 170 + + + true + + + + + + + true + + + + 0 + 0 + + + + 122 + + + true + + + + + + + true + + + + 0 + 0 + + + + 176 + + + true + + + + + + + true + + + + 0 + 0 + + + + 128 + + + true + + + + + + + true + + + + 0 + 0 + + + + 182 + + + true + + + + + + + true + + + + 0 + 0 + + + + 134 + + + true + + + + + + + true + + + + 0 + 0 + + + + 188 + + + true + + + + + + + true + + + + 0 + 0 + + + + 140 + + + true + + + + + + + true + + + + 0 + 0 + + + + 194 + + + true + + + + + + + + + + + + + + All sizes (cm) + + + true + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + true + + + + 0 + 0 + + + + 22 + + + true + + + + + + + true + + + + 0 + 0 + + + + 40 + + + true + + + + + + + true + + + + 0 + 0 + + + + 24 + + + true + + + + + + + true + + + + 0 + 0 + + + + 42 + + + true + + + + + + + true + + + + 0 + 0 + + + + 26 + + + true + + + + + + + true + + + + 0 + 0 + + + + 44 + + + true + + + + + + + true + + + + 0 + 0 + + + + 28 + + + true + + + + + + + true + + + + 0 + 0 + + + + 46 + + + true + + + + + + + true + + + + 0 + 0 + + + + 30 + + + true + + + + + + + true + + + + 0 + 0 + + + + 48 + + + true + + + + + + + true + + + + 0 + 0 + + + + 32 + + + true + + + + + + + true + + + + 0 + 0 + + + + 50 + + + true + + + + + + + true + + + + 0 + 0 + + + + 34 + + + true + + + + + + + true + + + + 0 + 0 + + + + 52 + + + true + + + + + + + true + + + + 0 + 0 + + + + 36 + + + true + + + + + + + true + + + + 0 + 0 + + + + 54 + + + true + + + + + + + true + + + + 0 + 0 + + + + 38 + + + true + + + + + + + true + + + + 0 + 0 + + + + 56 + + + true + + + + + + + + + + + + + @@ -70,7 +840,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index e347ab04f..38ca9d758 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -65,7 +65,8 @@ MainWindow::MainWindow(QWidget *parent) view(nullptr), isInitialized(false), dialogTable(0), dialogTool(nullptr), dialogHistory(nullptr), comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true), recentFileActs{nullptr, nullptr, nullptr, nullptr, nullptr}, - separatorAct(nullptr), autoSaveTimer(nullptr), guiEnabled(true) + separatorAct(nullptr), autoSaveTimer(nullptr), guiEnabled(true), gradationHeights(nullptr), + gradationSizes(nullptr) { CreateActions(); CreateMenus(); @@ -690,6 +691,7 @@ void MainWindow::OpenRecentFile() void MainWindow::PatternProperties() { DialogPatternProperties proper(doc, this); + connect(&proper, &DialogPatternProperties::UpdateGradation, this, &MainWindow::UpdateGradation); proper.exec(); } @@ -761,11 +763,18 @@ void MainWindow::ToolBarOption() { if (qApp->patternType() == MeasurementsType::Standard) { - const QStringList listHeights = VMeasurement::ListHeights(); - const QStringList listSizes = VMeasurement::ListSizes(); + const QStringList listHeights = VMeasurement::ListHeights(doc->GetGradationHeights()); + const QStringList listSizes = VMeasurement::ListSizes(doc->GetGradationSizes()); - SetGradationList(tr("Height: "), listHeights, &MainWindow::ChangedHeight); - SetGradationList(tr("Size: "), listSizes, &MainWindow::ChangedSize); + gradationHeights = SetGradationList(tr("Height: "), listHeights); + SetDefaultHeight(static_cast(GHeights::H176)); + connect(gradationHeights, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::ChangedHeight); + + gradationSizes = SetGradationList(tr("Size: "), listSizes); + SetDefaultSize(static_cast(GSizes::S50)); + connect(gradationSizes, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::ChangedSize); ui->toolBarOption->addSeparator(); } @@ -775,17 +784,49 @@ void MainWindow::ToolBarOption() } //--------------------------------------------------------------------------------------------------------------------- -template -void MainWindow::SetGradationList(const QString &label, const QStringList &list, Func changeSlot) +QComboBox *MainWindow::SetGradationList(const QString &label, const QStringList &list) { ui->toolBarOption->addWidget(new QLabel(label)); QComboBox *comboBox = new QComboBox; comboBox->addItems(list); - comboBox->setCurrentIndex(14);//176 cm ui->toolBarOption->addWidget(comboBox); - connect(comboBox, static_cast(&QComboBox::currentIndexChanged), - this, changeSlot); + + return comboBox; +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::SetDefaultHeight(int value) +{ + qreal val = VAbstractMeasurements::UnitConvertor(value, Unit::Cm, qApp->patternUnit()); + QString strVal = QString("%1").arg(val); + + qint32 index = gradationHeights->findText(strVal); + if (index != -1) + { + gradationHeights->setCurrentIndex(index); + } + else + { + pattern->SetHeight(gradationHeights->currentText().toInt()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::SetDefaultSize(int value) +{ + qreal val = VAbstractMeasurements::UnitConvertor(value, Unit::Cm, qApp->patternUnit()); + QString strVal = QString("%1").arg(val); + + qint32 index = gradationSizes->findText(strVal); + if (index != -1) + { + gradationSizes->setCurrentIndex(index); + } + else + { + pattern->SetSize(gradationSizes->currentText().toInt()); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -1446,6 +1487,63 @@ void MainWindow::Layout() } } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::UpdateGradation() +{ + UpdateHeightsList(VMeasurement::ListHeights(doc->GetGradationHeights())); + UpdateSizesList(VMeasurement::ListSizes(doc->GetGradationSizes())); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::UpdateHeightsList(const QStringList &list) +{ + QString val; + if (gradationHeights->currentIndex() != -1) + { + val = gradationHeights->currentText(); + } + + gradationHeights->blockSignals(true); + gradationHeights->clear(); + gradationHeights->addItems(list); + gradationHeights->blockSignals(false); + + int index = gradationHeights->findText(val); + if (index != -1) + { + gradationHeights->setCurrentIndex(index); + } + else + { + ChangedHeight(list.at(0)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::UpdateSizesList(const QStringList &list) +{ + QString val; + if (gradationSizes->currentIndex() != -1) + { + val = gradationSizes->currentText(); + } + + gradationSizes->blockSignals(true); + gradationSizes->clear(); + gradationSizes->addItems(list); + gradationSizes->blockSignals(false); + + int index = gradationSizes->findText(val); + if (index != -1) + { + gradationSizes->setCurrentIndex(index); + } + else + { + ChangedSize(list.at(0)); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NewPattern create new empty pattern. @@ -1480,8 +1578,7 @@ void MainWindow::PatternWasModified(bool saved) */ void MainWindow::ChangedSize(const QString & text) { - qint32 size = text.toInt(); - pattern->SetSize(size); + pattern->SetSize(text.toInt()); doc->LiteParseTree(Document::LiteParse); } @@ -1492,8 +1589,7 @@ void MainWindow::ChangedSize(const QString & text) */ void MainWindow::ChangedHeight(const QString &text) { - qint32 growth = text.toInt(); - pattern->SetHeight(growth); + pattern->SetHeight(text.toInt()); doc->LiteParseTree(Document::LiteParse); } @@ -1594,7 +1690,7 @@ void MainWindow::ActionLayout(bool checked) QPainterPath path = VEquidistant().ContourPath(idetail.key(), pattern); listDetails.append(new VItem(path, listDetails.size())); } - QString description = doc->UniqueTagText("description"); + QString description = doc->GetDescription(); emit ModelChosen(listDetails, curFile, description); } @@ -1813,7 +1909,7 @@ void MainWindow::UpdateRecentFileActions() for (int i = 0; i < numRecentFiles; ++i) { - QString text = QString("&%1 %2").arg(i + 1).arg(strippedName(files.at(i))); + QString text = QString("&%1. %2").arg(i + 1).arg(strippedName(files.at(i))); recentFileActs[i]->setText(text); recentFileActs[i]->setData(files.at(i)); recentFileActs[i]->setVisible(true); diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 4e72d9149..5406d7d24 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -120,6 +120,7 @@ public slots: void SetEnabledGUI(bool enabled); void ClickEndVisualization(); void Layout(); + void UpdateGradation(); signals: /** * @brief ModelChosen emit after calculation all details. @@ -194,6 +195,8 @@ private: QAction *separatorAct; QTimer *autoSaveTimer; bool guiEnabled; + QComboBox *gradationHeights; + QComboBox *gradationSizes; void ToolBarOption(); void ToolBarDraws(); void ToolBarTools(); @@ -232,14 +235,17 @@ private: QString PatternPieceName(const QString &text); QString CheckPathToMeasurements(const QString &path, const MeasurementsType &patternType); void OpenPattern(const QString &filePath); - template - void SetGradationList(const QString &label, const QStringList &list, Func changeSlot); + QComboBox *SetGradationList(const QString &label, const QStringList &list); void ChangePP(int index , bool zoomBestFit = true); /** * @brief EndVisualization try show dialog after and working with tool visualization. */ void EndVisualization(bool click = false); void ZoomFirstShow(); + void UpdateHeightsList(const QStringList &list); + void UpdateSizesList(const QStringList &list); + void SetDefaultHeight(int value); + void SetDefaultSize(int value); }; #endif // MAINWINDOW_H diff --git a/src/app/options.h b/src/app/options.h index 7dee201cb..a7239aebf 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -75,6 +75,15 @@ enum class Draw : char { Calculation, Modeling }; enum class Unit : char { Mm, Cm, Inch }; enum class MeasurementsType : char { Standard, Individual }; +enum class GHeights : unsigned char { ALL, + H92=92, H98=98, H104=104, H110=110, H116=116, H122=122, H128=128, H134=134, + H140=140, H146=146, H152=152, H158=158, H164=164, H170=170, H176=176, H182=182, + H188=188, H194=194}; + +enum class GSizes : unsigned char { ALL, + S22=22, S24=24, S26=26, S28=28, S30=30, S32=32, S34=34, S36=36, S38=38, S40=40, + S42=42, S44=44, S46=46, S48=48, S50=50, S52=52, S54=54, S56=56 }; + // measurements extern const QString headGirth_M; extern const QString midNeckGirth_M; diff --git a/src/app/share/resources/schema/pattern.xsd b/src/app/share/resources/schema/pattern.xsd index dc58f0e41..7f0a5f96a 100644 --- a/src/app/share/resources/schema/pattern.xsd +++ b/src/app/share/resources/schema/pattern.xsd @@ -8,6 +8,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/app/xml/vdomdocument.cpp b/src/app/xml/vdomdocument.cpp index 8019623e0..7c86d7687 100644 --- a/src/app/xml/vdomdocument.cpp +++ b/src/app/xml/vdomdocument.cpp @@ -221,6 +221,45 @@ quint32 VDomDocument::GetParametrUInt(const QDomElement &domElement, const QStri return id; } +//--------------------------------------------------------------------------------------------------------------------- +bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString &name, const QString &defValue) const +{ + Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty"); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + + bool ok = false; + QString parametr; + bool val = true; + + QString message = tr("Can't convert toBool parameter"); + try + { + parametr = GetParametrString(domElement, name, defValue); + + QStringList bools {QLatin1String("true"), QLatin1String("false")}; + switch (bools.indexOf(parametr)) + { + case 0: // true + val = true; + break; + case 1: // false + val = false; + break; + default:// others + throw VExceptionConversionError(message, name); + break; + } + } + catch (const VExceptionEmptyParameter &e) + { + VExceptionConversionError excep(message, name); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + + return val; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Returns the string value of the given attribute. RENAME: see above diff --git a/src/app/xml/vdomdocument.h b/src/app/xml/vdomdocument.h index a51a2d562..d1c17a186 100644 --- a/src/app/xml/vdomdocument.h +++ b/src/app/xml/vdomdocument.h @@ -87,11 +87,6 @@ public: * @param domElement element in xml tree. * @param name name of attribute. * @param value value of attribute. - * @param parse parsing mode - * @return list of tool pointers - * @return list of history record lists - * @return cursor - * @throw VExceptionUniqueId */ void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const { @@ -100,10 +95,11 @@ public: domElement.setAttribute(name, val); } quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue) const; + bool GetParametrBool(const QDomElement& domElement, const QString &name, const QString &defValue) const; QString GetParametrString(const QDomElement& domElement, const QString &name, const QString &defValue = QString()) const; qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const; - QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const; + static void ValidateXML(const QString &schema, const QString &fileName); void setContent(const QString &fileName); static Unit StrToUnits(const QString &unit); @@ -117,7 +113,8 @@ protected: /** @brief data container with data. */ VContainer *data; - void setTagText(const QString &tag, const QString &text); + void setTagText(const QString &tag, const QString &text); + QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const; private: Q_DISABLE_COPY(VDomDocument) /** @brief Map used for finding element by id. */ @@ -134,6 +131,22 @@ inline void VDomDocument::SetAttribute(QDomElement &domElement, const Q domElement.setAttribute(name, value); } +//--------------------------------------------------------------------------------------------------------------------- +template <> +inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &name, const bool &value) const +{ + QString string; + if (value) + { + string = "true"; + } + else + { + string = "false"; + } + domElement.setAttribute(name, string); +} + //--------------------------------------------------------------------------------------------------------------------- template <> inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &name, diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 27c3c8114..214f601c8 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -42,6 +42,7 @@ #include "vindividualmeasurements.h" #include "../../libs/qmuparser/qmuparsererror.h" #include "../geometry/varc.h" + #include #include @@ -61,11 +62,54 @@ const QString VPattern::TagLine = QStringLiteral("line"); const QString VPattern::TagSpline = QStringLiteral("spline"); const QString VPattern::TagArc = QStringLiteral("arc"); const QString VPattern::TagTools = QStringLiteral("tools"); +const QString VPattern::TagGradation = QStringLiteral("gradation"); +const QString VPattern::TagHeights = QStringLiteral("heights"); +const QString VPattern::TagSizes = QStringLiteral("sizes"); const QString VPattern::AttrName = QStringLiteral("name"); const QString VPattern::AttrType = QStringLiteral("type"); const QString VPattern::AttrPath = QStringLiteral("path"); +const QString VPattern::AttrAll = QStringLiteral("all"); + +const QString VPattern::AttrH92 = QStringLiteral("h92"); +const QString VPattern::AttrH98 = QStringLiteral("h98"); +const QString VPattern::AttrH104 = QStringLiteral("h104"); +const QString VPattern::AttrH110 = QStringLiteral("h110"); +const QString VPattern::AttrH116 = QStringLiteral("h116"); +const QString VPattern::AttrH122 = QStringLiteral("h122"); +const QString VPattern::AttrH128 = QStringLiteral("h128"); +const QString VPattern::AttrH134 = QStringLiteral("h134"); +const QString VPattern::AttrH140 = QStringLiteral("h140"); +const QString VPattern::AttrH146 = QStringLiteral("h146"); +const QString VPattern::AttrH152 = QStringLiteral("h152"); +const QString VPattern::AttrH158 = QStringLiteral("h158"); +const QString VPattern::AttrH164 = QStringLiteral("h164"); +const QString VPattern::AttrH170 = QStringLiteral("h170"); +const QString VPattern::AttrH176 = QStringLiteral("h176"); +const QString VPattern::AttrH182 = QStringLiteral("h182"); +const QString VPattern::AttrH188 = QStringLiteral("h188"); +const QString VPattern::AttrH194 = QStringLiteral("h194"); + +const QString VPattern::AttrS22 = QStringLiteral("s22"); +const QString VPattern::AttrS24 = QStringLiteral("s24"); +const QString VPattern::AttrS26 = QStringLiteral("s26"); +const QString VPattern::AttrS28 = QStringLiteral("s28"); +const QString VPattern::AttrS30 = QStringLiteral("s30"); +const QString VPattern::AttrS32 = QStringLiteral("s32"); +const QString VPattern::AttrS34 = QStringLiteral("s34"); +const QString VPattern::AttrS36 = QStringLiteral("s36"); +const QString VPattern::AttrS38 = QStringLiteral("s38"); +const QString VPattern::AttrS40 = QStringLiteral("s40"); +const QString VPattern::AttrS42 = QStringLiteral("s42"); +const QString VPattern::AttrS44 = QStringLiteral("s44"); +const QString VPattern::AttrS46 = QStringLiteral("s46"); +const QString VPattern::AttrS48 = QStringLiteral("s48"); +const QString VPattern::AttrS50 = QStringLiteral("s50"); +const QString VPattern::AttrS52 = QStringLiteral("s52"); +const QString VPattern::AttrS54 = QStringLiteral("s54"); +const QString VPattern::AttrS56 = QStringLiteral("s56"); + const QString VPattern::IncrementName = QStringLiteral("name"); const QString VPattern::IncrementBase = QStringLiteral("base"); const QString VPattern::IncrementKsize = QStringLiteral("ksize"); @@ -256,7 +300,8 @@ void VPattern::Parse(const Document &parse) { SCASSERT(sceneDraw != nullptr); SCASSERT(sceneDetail != nullptr); - QStringList tags{TagDraw, TagIncrements, TagAuthor, TagDescription, TagNotes, TagMeasurements, TagVersion}; + QStringList tags{TagDraw, TagIncrements, TagAuthor, TagDescription, TagNotes, TagMeasurements, TagVersion, + TagGradation}; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -300,6 +345,8 @@ void VPattern::Parse(const Document &parse) break; case 6: // TagVersion break; + case 7: // TagGradation + break; default: qDebug()<<"Wrong tag name"<= 0; --i) + { + QDomNodeList list = elementsByTagName(tags.at(i)); + if (list.isEmpty()) + { + continue; + } + pattern.insertAfter(createElement(TagDescription), list.at(0)); + } + SetVersion(); + break; + } + case 3: //TagNotes + { + for (int i = tags.indexOf(tag)-1; i >= 0; --i) + { + QDomNodeList list = elementsByTagName(tags.at(i)); + if (list.isEmpty()) + { + continue; + } + pattern.insertAfter(createElement(TagNotes), list.at(0)); + } + SetVersion(); + break; + } + case 4: //TagGradation + { + QDomElement gradation = createElement(TagGradation); + gradation.appendChild(createElement(TagHeights)); + gradation.appendChild(createElement(TagSizes)); + + for (int i = tags.indexOf(tag)-1; i >= 0; --i) + { + QDomNodeList list = elementsByTagName(tags.at(i)); + if (list.isEmpty()) + { + continue; + } + pattern.insertAfter(gradation, list.at(0)); + break; + } + SetVersion(); + break; + } + default: + break; + } + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ParseSplineElement parse spline tag. @@ -1815,6 +1931,351 @@ quint32 VPattern::GetParametrId(const QDomElement &domElement) const return id; } +//--------------------------------------------------------------------------------------------------------------------- +QMap VPattern::GetGradationHeights() const +{ + QMap map; + map.insert(GHeights::ALL, true); + map.insert(GHeights::H92, true); + map.insert(GHeights::H98, true); + map.insert(GHeights::H104, true); + map.insert(GHeights::H110, true); + map.insert(GHeights::H116, true); + map.insert(GHeights::H122, true); + map.insert(GHeights::H128, true); + map.insert(GHeights::H134, true); + map.insert(GHeights::H140, true); + map.insert(GHeights::H146, true); + map.insert(GHeights::H152, true); + map.insert(GHeights::H158, true); + map.insert(GHeights::H164, true); + map.insert(GHeights::H170, true); + map.insert(GHeights::H176, true); + map.insert(GHeights::H182, true); + map.insert(GHeights::H188, true); + map.insert(GHeights::H194, true); + + QDomNodeList tags = elementsByTagName(TagGradation); + if (tags.size() == 0) + { + return map; + } + + QStringList gTags{TagHeights, TagSizes}; + QDomNode domNode = tags.at(0).firstChild(); + while (domNode.isNull() == false) + { + if (domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + const QString defValue = QStringLiteral("true"); + switch (gTags.indexOf(domElement.tagName())) + { + case 0: // TagHeights + if (GetParametrBool(domElement, AttrAll, defValue)) + { + return map; + } + else + { + map.insert(GHeights::ALL, false); + } + + map.insert(GHeights::H92, GetParametrBool(domElement, AttrH92, defValue)); + map.insert(GHeights::H98, GetParametrBool(domElement, AttrH98, defValue)); + map.insert(GHeights::H104, GetParametrBool(domElement, AttrH104, defValue)); + map.insert(GHeights::H110, GetParametrBool(domElement, AttrH110, defValue)); + map.insert(GHeights::H116, GetParametrBool(domElement, AttrH116, defValue)); + map.insert(GHeights::H122, GetParametrBool(domElement, AttrH122, defValue)); + map.insert(GHeights::H128, GetParametrBool(domElement, AttrH128, defValue)); + map.insert(GHeights::H134, GetParametrBool(domElement, AttrH134, defValue)); + map.insert(GHeights::H140, GetParametrBool(domElement, AttrH140, defValue)); + map.insert(GHeights::H146, GetParametrBool(domElement, AttrH146, defValue)); + map.insert(GHeights::H152, GetParametrBool(domElement, AttrH152, defValue)); + map.insert(GHeights::H158, GetParametrBool(domElement, AttrH158, defValue)); + map.insert(GHeights::H164, GetParametrBool(domElement, AttrH164, defValue)); + map.insert(GHeights::H170, GetParametrBool(domElement, AttrH170, defValue)); + map.insert(GHeights::H176, GetParametrBool(domElement, AttrH176, defValue)); + map.insert(GHeights::H182, GetParametrBool(domElement, AttrH182, defValue)); + map.insert(GHeights::H188, GetParametrBool(domElement, AttrH188, defValue)); + map.insert(GHeights::H194, GetParametrBool(domElement, AttrH194, defValue)); + return map; + break; + case 1: // TagSizes + break; + default: + break; + } + } + } + domNode = domNode.nextSibling(); + } + return map; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::SetGradationHeights(const QMap &options) +{ + CheckTagExists(TagGradation); + QDomNodeList tags = elementsByTagName(TagGradation); + if (tags.size() == 0) + { + qDebug()<<"Can't save tag "< VPattern::GetGradationSizes() const +{ + QMap map; + map.insert(GSizes::ALL, true); + map.insert(GSizes::S22, true); + map.insert(GSizes::S24, true); + map.insert(GSizes::S26, true); + map.insert(GSizes::S28, true); + map.insert(GSizes::S30, true); + map.insert(GSizes::S32, true); + map.insert(GSizes::S34, true); + map.insert(GSizes::S36, true); + map.insert(GSizes::S38, true); + map.insert(GSizes::S40, true); + map.insert(GSizes::S42, true); + map.insert(GSizes::S44, true); + map.insert(GSizes::S46, true); + map.insert(GSizes::S48, true); + map.insert(GSizes::S50, true); + map.insert(GSizes::S52, true); + map.insert(GSizes::S54, true); + map.insert(GSizes::S56, true); + + QDomNodeList tags = elementsByTagName(TagGradation); + if (tags.size() == 0) + { + return map; + } + + QStringList gTags{TagHeights, TagSizes}; + QDomNode domNode = tags.at(0).firstChild(); + while (domNode.isNull() == false) + { + if (domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + const QString defValue = QStringLiteral("true"); + switch (gTags.indexOf(domElement.tagName())) + { + case 0: // TagHeights + break; + case 1: // TagSizes + if (GetParametrBool(domElement, AttrAll, defValue)) + { + return map; + } + else + { + map.insert(GSizes::ALL, false); + } + + map.insert(GSizes::S22, GetParametrBool(domElement, AttrS22, defValue)); + map.insert(GSizes::S24, GetParametrBool(domElement, AttrS24, defValue)); + map.insert(GSizes::S26, GetParametrBool(domElement, AttrS26, defValue)); + map.insert(GSizes::S28, GetParametrBool(domElement, AttrS28, defValue)); + map.insert(GSizes::S30, GetParametrBool(domElement, AttrS30, defValue)); + map.insert(GSizes::S32, GetParametrBool(domElement, AttrS32, defValue)); + map.insert(GSizes::S34, GetParametrBool(domElement, AttrS34, defValue)); + map.insert(GSizes::S36, GetParametrBool(domElement, AttrS36, defValue)); + map.insert(GSizes::S38, GetParametrBool(domElement, AttrS38, defValue)); + map.insert(GSizes::S40, GetParametrBool(domElement, AttrS40, defValue)); + map.insert(GSizes::S42, GetParametrBool(domElement, AttrS42, defValue)); + map.insert(GSizes::S44, GetParametrBool(domElement, AttrS44, defValue)); + map.insert(GSizes::S46, GetParametrBool(domElement, AttrS46, defValue)); + map.insert(GSizes::S48, GetParametrBool(domElement, AttrS48, defValue)); + map.insert(GSizes::S50, GetParametrBool(domElement, AttrS50, defValue)); + map.insert(GSizes::S52, GetParametrBool(domElement, AttrS52, defValue)); + map.insert(GSizes::S54, GetParametrBool(domElement, AttrS54, defValue)); + map.insert(GSizes::S56, GetParametrBool(domElement, AttrS56, defValue)); + return map; + break; + default: + break; + } + } + } + domNode = domNode.nextSibling(); + } + return map; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::SetGradationSizes(const QMap &options) +{ + CheckTagExists(TagGradation); + QDomNodeList tags = elementsByTagName(TagGradation); + if (tags.size() == 0) + { + qDebug()<<"Can't save tag "<getSettings(); + SCASSERT(settings != nullptr); +#ifdef Q_OS_WIN + QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString(); +#else + QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USER").constData())).toString(); +#endif + + return UniqueTagText(TagAuthor, user); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::SetAuthor(const QString &text) +{ + CheckTagExists(TagAuthor); + setTagText(TagAuthor, text); + emit patternChanged(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPattern::GetDescription() const +{ + return UniqueTagText(TagDescription); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::SetDescription(const QString &text) +{ + CheckTagExists(TagDescription); + setTagText(TagDescription, text); + emit patternChanged(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPattern::GetNotes() const +{ + return UniqueTagText(TagNotes); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::SetNotes(const QString &text) +{ + CheckTagExists(TagNotes); + setTagText(TagNotes, text); + emit patternChanged(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPattern::GetVersion() const +{ + return UniqueTagText(TagVersion, VAL_STR_VERSION); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::SetVersion() +{ + setTagText(TagVersion, VAL_STR_VERSION); + emit patternChanged(false); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief CollectId recursive function, try find id attribute in file. Throw exclusion if find not unique. diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index de01fbe33..1a264244c 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -35,7 +35,7 @@ class VDataTool; class VMainGraphicsScene; -enum class Document : char { LiteParse, LitePPParse, FullParse}; +enum class Document : char { LiteParse, LitePPParse, FullParse }; /* VAL_VERSION is (major << 16) + (minor << 8) + patch. @@ -43,9 +43,9 @@ enum class Document : char { LiteParse, LitePPParse, FullParse}; // version without patch part #define VAL_MIN_VERSION 0x000100 // max support version of format -#define VAL_VERSION 0x000100 +#define VAL_VERSION 0x000101 -#define VAL_STR_VERSION "0.1.0" +#define VAL_STR_VERSION "0.1.1" /** * @brief The VPattern class working with pattern file. @@ -103,18 +103,82 @@ public: static const QString TagSpline; static const QString TagArc; static const QString TagTools; + static const QString TagGradation; + static const QString TagHeights; + static const QString TagSizes; + static const QString AttrName; static const QString AttrType; static const QString AttrPath; + + static const QString AttrAll; + + static const QString AttrH92; + static const QString AttrH98; + static const QString AttrH104; + static const QString AttrH110; + static const QString AttrH116; + static const QString AttrH122; + static const QString AttrH128; + static const QString AttrH134; + static const QString AttrH140; + static const QString AttrH146; + static const QString AttrH152; + static const QString AttrH158; + static const QString AttrH164; + static const QString AttrH170; + static const QString AttrH176; + static const QString AttrH182; + static const QString AttrH188; + static const QString AttrH194; + + static const QString AttrS22; + static const QString AttrS24; + static const QString AttrS26; + static const QString AttrS28; + static const QString AttrS30; + static const QString AttrS32; + static const QString AttrS34; + static const QString AttrS36; + static const QString AttrS38; + static const QString AttrS40; + static const QString AttrS42; + static const QString AttrS44; + static const QString AttrS46; + static const QString AttrS48; + static const QString AttrS50; + static const QString AttrS52; + static const QString AttrS54; + static const QString AttrS56; + static const QString IncrementName; static const QString IncrementBase; static const QString IncrementKsize; static const QString IncrementKgrowth; static const QString IncrementDescription; + virtual bool SaveDocument(const QString &fileName); QStringList getPatternPieces() const; QRectF ActiveDrawBoundingRect() const; quint32 GetParametrId(const QDomElement& domElement) const; + + QMap GetGradationHeights() const; + void SetGradationHeights(const QMap &options); + + QMap GetGradationSizes() const; + void SetGradationSizes(const QMap &options); + + QString GetAuthor() const; + void SetAuthor(const QString &text); + + QString GetDescription() const; + void SetDescription(const QString &text); + + QString GetNotes() const; + void SetNotes(const QString &text); + + QString GetVersion() const; + void SetVersion(); signals: /** * @brief ChangedActivDraw change active pattern peace. @@ -215,6 +279,7 @@ private: template QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const; void ParseCurrentPP(); + void CheckTagExists(const QString &tag); }; //---------------------------------------------------------------------------------------------------------------------