diff --git a/src/app/container/vmeasurement.cpp b/src/app/container/vmeasurement.cpp index 0ecf094e7..a93ef1a41 100644 --- a/src/app/container/vmeasurement.cpp +++ b/src/app/container/vmeasurement.cpp @@ -109,7 +109,7 @@ QStringList VMeasurement::ListHeights(QMap heights) QMap::const_iterator i = heights.constBegin(); while (i != heights.constEnd()) { - if (i.value()) + if (i.value() && i.key() != GHeights::ALL) { ListValue(list, static_cast(i.key())); } @@ -140,7 +140,7 @@ QStringList VMeasurement::ListSizes(QMap sizes) QMap::const_iterator i = sizes.constBegin(); while (i != sizes.constEnd()) { - if (i.value()) + if (i.value() && i.key() != GSizes::ALL) { ListValue(list, static_cast(i.key())); } diff --git a/src/app/dialogs/app/dialogpatternproperties.cpp b/src/app/dialogs/app/dialogpatternproperties.cpp index 6f05c604f..d040d08f6 100644 --- a/src/app/dialogs/app/dialogpatternproperties.cpp +++ b/src/app/dialogs/app/dialogpatternproperties.cpp @@ -28,7 +28,6 @@ #include "dialogpatternproperties.h" #include "ui_dialogpatternproperties.h" -#include #include #include "../../xml/vpattern.h" #include "../../widgets/vapplication.h" @@ -38,79 +37,47 @@ //--------------------------------------------------------------------------------------------------------------------- DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent) : - QDialog(parent), ui(new Ui::DialogPatternProperties), doc(doc), heightsChecked(MAX_HEIGHTS), sizesChecked(MAX_SIZES) + 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); } - connect(ui->checkBoxAllHeights, &QCheckBox::stateChanged, this, &DialogPatternProperties::SelectAll); - connect(ui->checkBoxAllSizes, &QCheckBox::stateChanged, this, &DialogPatternProperties::SelectAll); - connect(ui->checkBoxH92, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH98, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH104, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH110, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH116, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH122, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH128, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH134, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH140, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH146, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH152, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH158, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH164, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH170, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH176, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH182, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH188, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); - connect(ui->checkBoxH194, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckHeight); + InitHeights(); + InitSizes(); - connect(ui->checkBoxS22, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS24, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS26, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS28, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS30, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS32, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS34, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS36, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS38, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS40, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS42, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS44, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS46, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS48, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS50, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS52, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS54, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); - connect(ui->checkBoxS56, &QCheckBox::stateChanged, this, &DialogPatternProperties::UncheckSize); + heights = doc->GetGradationHeights(); + sizes = doc->GetGradationSizes(); + + SetOptions(heights); + SetOptions(sizes); + + gradationChanged = false;//Set to default value after initialization } //--------------------------------------------------------------------------------------------------------------------- @@ -122,10 +89,36 @@ 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(); } @@ -139,30 +132,16 @@ void DialogPatternProperties::SelectAll(int state) { if (state == Qt::Checked) { - ui->checkBoxH92->setChecked(true); - ui->checkBoxH98->setChecked(true); - ui->checkBoxH104->setChecked(true); - ui->checkBoxH110->setChecked(true); - ui->checkBoxH116->setChecked(true); - ui->checkBoxH122->setChecked(true); - ui->checkBoxH128->setChecked(true); - ui->checkBoxH134->setChecked(true); - ui->checkBoxH140->setChecked(true); - ui->checkBoxH146->setChecked(true); - ui->checkBoxH152->setChecked(true); - ui->checkBoxH158->setChecked(true); - ui->checkBoxH164->setChecked(true); - ui->checkBoxH170->setChecked(true); - ui->checkBoxH176->setChecked(true); - ui->checkBoxH182->setChecked(true); - ui->checkBoxH188->setChecked(true); - ui->checkBoxH194->setChecked(true); - - SetHeightsEnabled(false); + SetHeightsChecked(true); } else if (state == Qt::Unchecked) { - SetHeightsEnabled(true); + SetHeightsChecked(false); + } + + if (data.contains(box)) + { + heights.insert(static_cast(data.value(box)), box->isChecked()); } } @@ -170,181 +149,252 @@ void DialogPatternProperties::SelectAll(int state) { if (state == Qt::Checked) { - ui->checkBoxS22->setChecked(true); - ui->checkBoxS24->setChecked(true); - ui->checkBoxS26->setChecked(true); - ui->checkBoxS28->setChecked(true); - ui->checkBoxS30->setChecked(true); - ui->checkBoxS32->setChecked(true); - ui->checkBoxS34->setChecked(true); - ui->checkBoxS36->setChecked(true); - ui->checkBoxS38->setChecked(true); - ui->checkBoxS40->setChecked(true); - ui->checkBoxS42->setChecked(true); - ui->checkBoxS44->setChecked(true); - ui->checkBoxS46->setChecked(true); - ui->checkBoxS48->setChecked(true); - ui->checkBoxS50->setChecked(true); - ui->checkBoxS52->setChecked(true); - ui->checkBoxS54->setChecked(true); - ui->checkBoxS56->setChecked(true); - - SetSizesEnabled(false); + SetSizesChecked(true); } else if (state == Qt::Unchecked) { - SetSizesEnabled(true); + SetSizesChecked(false); + } + + if (data.contains(box)) + { + sizes.insert(static_cast(data.value(box)), box->isChecked()); } } } } //--------------------------------------------------------------------------------------------------------------------- -void DialogPatternProperties::UncheckHeight(int state) +void DialogPatternProperties::CheckStateHeight(int state) { QCheckBox* box = qobject_cast(sender()); if (box) { - if (box == ui->checkBoxH92 || box == ui->checkBoxH98 || box == ui->checkBoxH104 || box == ui->checkBoxH110 || - box == ui->checkBoxH116 || box == ui->checkBoxH122 || box == ui->checkBoxH128 || box == ui->checkBoxH134 || - box == ui->checkBoxH140 || box == ui->checkBoxH146 || box == ui->checkBoxH152 || box == ui->checkBoxH158 || - box == ui->checkBoxH164 || box == ui->checkBoxH170 || box == ui->checkBoxH176 || box == ui->checkBoxH182 || - box == ui->checkBoxH188 || box == ui->checkBoxH194) + if (state == Qt::Checked) { - if (state == Qt::Checked) + ++heightsChecked; + if (heightsChecked == MAX_HEIGHTS) { - ++heightsChecked; - } - else if (state == Qt::Unchecked) - { - if (heightsChecked == 1) - { - box->setCheckState(Qt::Checked);//Will call this method again with Qt::Checked state - --heightsChecked;// That's why we will increase. - } - else - { - --heightsChecked; - } + 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::UncheckSize(int state) +void DialogPatternProperties::CheckStateSize(int state) { QCheckBox* box = qobject_cast(sender()); if (box) { - if (box == ui->checkBoxS22 || box == ui->checkBoxS24 || box == ui->checkBoxS26 || box == ui->checkBoxS28 || - box == ui->checkBoxS30 || box == ui->checkBoxS32 || box == ui->checkBoxS34 || box == ui->checkBoxS36 || - box == ui->checkBoxS38 || box == ui->checkBoxS40 || box == ui->checkBoxS42 || box == ui->checkBoxS44 || - box == ui->checkBoxS46 || box == ui->checkBoxS48 || box == ui->checkBoxS50 || box == ui->checkBoxS52 || - box == ui->checkBoxS54 || box == ui->checkBoxS56) + + if (state == Qt::Checked) { - if (state == Qt::Checked) + ++sizesChecked; + if (sizesChecked == MAX_SIZES) { - ++sizesChecked; + 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) + } + else if (state == Qt::Unchecked) + { + if (sizesChecked == MAX_SIZES) { - if (sizesChecked == 1) + 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::Checked);//Will call this method again with Qt::Checked state - --sizesChecked; // That's why we will increase. - } - else - { - --sizesChecked; + box->setCheckState(Qt::Unchecked); } } } } } - -//--------------------------------------------------------------------------------------------------------------------- -void DialogPatternProperties::Write(const QString &tagName, const QString &text) const -{ - QDomNodeList nodeList = doc->elementsByTagName(tagName); - if (nodeList.isEmpty()) - { - QDomElement pattern = doc->documentElement(); - - QDomElement tag = doc->createElement(tagName); - QDomText domText = doc->createTextNode(text); - tag.appendChild(domText); - //The Old pattern file doesn't have comment. But here we try insert the tag after first child (comment). - // - // - // -->place for new tag<-- - // - if (pattern.firstChild().isComment()) - { - pattern.insertAfter(tag, pattern.firstChild()); - } - 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); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogPatternProperties::SetHeightsEnabled(bool enabled) -{ - ui->checkBoxH92->setEnabled(enabled); - ui->checkBoxH98->setEnabled(enabled); - ui->checkBoxH104->setEnabled(enabled); - ui->checkBoxH110->setEnabled(enabled); - ui->checkBoxH116->setEnabled(enabled); - ui->checkBoxH122->setEnabled(enabled); - ui->checkBoxH128->setEnabled(enabled); - ui->checkBoxH134->setEnabled(enabled); - ui->checkBoxH140->setEnabled(enabled); - ui->checkBoxH146->setEnabled(enabled); - ui->checkBoxH152->setEnabled(enabled); - ui->checkBoxH158->setEnabled(enabled); - ui->checkBoxH164->setEnabled(enabled); - ui->checkBoxH170->setEnabled(enabled); - ui->checkBoxH176->setEnabled(enabled); - ui->checkBoxH182->setEnabled(enabled); - ui->checkBoxH188->setEnabled(enabled); - ui->checkBoxH194->setEnabled(enabled); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogPatternProperties::SetSizesEnabled(bool enabled) -{ - ui->checkBoxS22->setEnabled(enabled); - ui->checkBoxS24->setEnabled(enabled); - ui->checkBoxS26->setEnabled(enabled); - ui->checkBoxS28->setEnabled(enabled); - ui->checkBoxS30->setEnabled(enabled); - ui->checkBoxS32->setEnabled(enabled); - ui->checkBoxS34->setEnabled(enabled); - ui->checkBoxS36->setEnabled(enabled); - ui->checkBoxS38->setEnabled(enabled); - ui->checkBoxS40->setEnabled(enabled); - ui->checkBoxS42->setEnabled(enabled); - ui->checkBoxS44->setEnabled(enabled); - ui->checkBoxS46->setEnabled(enabled); - ui->checkBoxS48->setEnabled(enabled); - ui->checkBoxS50->setEnabled(enabled); - ui->checkBoxS52->setEnabled(enabled); - ui->checkBoxS54->setEnabled(enabled); - ui->checkBoxS56->setEnabled(enabled); -} diff --git a/src/app/dialogs/app/dialogpatternproperties.h b/src/app/dialogs/app/dialogpatternproperties.h index 2d89a7b5e..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,21 +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 UncheckHeight(int state); - void UncheckSize(int state); + void CheckStateHeight(int state); + void CheckStateSize(int state); + void DescEdited(); private: Q_DISABLE_COPY(DialogPatternProperties) Ui::DialogPatternProperties *ui; - VPattern *doc; - char heightsChecked; - char sizesChecked; - void Write(const QString &tagName, const QString &text) const; - void SetHeightsEnabled(bool enabled); - void SetSizesEnabled(bool enabled); + 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 16dd0bdd3..b7522a3c3 100644 --- a/src/app/dialogs/app/dialogpatternproperties.ui +++ b/src/app/dialogs/app/dialogpatternproperties.ui @@ -110,7 +110,7 @@ - false + true @@ -129,7 +129,7 @@ - false + true @@ -148,7 +148,7 @@ - false + true @@ -167,7 +167,7 @@ - false + true @@ -186,7 +186,7 @@ - false + true @@ -211,7 +211,7 @@ - false + true @@ -230,7 +230,7 @@ - false + true @@ -249,7 +249,7 @@ - false + true @@ -268,7 +268,7 @@ - false + true @@ -287,7 +287,7 @@ - false + true @@ -306,7 +306,7 @@ - false + true @@ -325,7 +325,7 @@ - false + true @@ -344,7 +344,7 @@ - false + true @@ -363,7 +363,7 @@ - false + true @@ -382,7 +382,7 @@ - false + true @@ -401,7 +401,7 @@ - false + true @@ -420,7 +420,7 @@ - false + true @@ -439,7 +439,7 @@ - false + true @@ -484,7 +484,7 @@ - false + true @@ -503,7 +503,7 @@ - false + true @@ -522,7 +522,7 @@ - false + true @@ -541,7 +541,7 @@ - false + true @@ -560,7 +560,7 @@ - false + true @@ -579,7 +579,7 @@ - false + true @@ -598,7 +598,7 @@ - false + true @@ -617,7 +617,7 @@ - false + true @@ -636,7 +636,7 @@ - false + true @@ -655,7 +655,7 @@ - false + true @@ -674,7 +674,7 @@ - false + true @@ -693,7 +693,7 @@ - false + true @@ -712,7 +712,7 @@ - false + true @@ -731,7 +731,7 @@ - false + true @@ -750,7 +750,7 @@ - false + true @@ -769,7 +769,7 @@ - false + true @@ -788,7 +788,7 @@ - false + true @@ -807,7 +807,7 @@ - false + true @@ -840,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 c12ff3294..dc9c7b02f 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -1594,7 +1594,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); } diff --git a/src/app/options.h b/src/app/options.h index 6c6c22db4..a7239aebf 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -75,11 +75,13 @@ enum class Draw : char { Calculation, Modeling }; enum class Unit : char { Mm, Cm, Inch }; enum class MeasurementsType : char { Standard, Individual }; -enum class GHeights : unsigned char { H92=92, H98=98, H104=104, H110=110, H116=116, H122=122, H128=128, H134=134, +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 { S22=22, S24=24, S26=26, S28=28, S30=30, S32=32, S34=34, S36=36, S38=38, S40=40, +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 diff --git a/src/app/xml/vdomdocument.h b/src/app/xml/vdomdocument.h index 2cfe16785..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 { @@ -104,7 +99,7 @@ public: 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); @@ -118,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. */ @@ -135,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 70c75dc19..3b7f2666e 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -1543,6 +1543,75 @@ void VPattern::ParseCurrentPP() emit CheckLayout(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::CheckTagExists(const QString &tag) +{ + QDomNodeList list = elementsByTagName(tag); + if (list.size() == 0) + { + QStringList tags{TagVersion, TagAuthor, TagDescription, TagNotes, TagGradation}; + QDomElement pattern = documentElement(); + switch (tags.indexOf(tag)) + { + case 0: //TagVersion + break;// Mandatory tag + case 1: //TagAuthor + pattern.insertAfter(createElement(TagAuthor), elementsByTagName(TagVersion).at(0)); + SetVersion(); + break; + case 2: //TagDescription + { + for (int i = tags.indexOf(tag)-1; i >= 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. @@ -1863,6 +1932,7 @@ quint32 VPattern::GetParametrId(const QDomElement &domElement) const 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); @@ -1905,6 +1975,10 @@ QMap VPattern::GetGradationHeights() const { return map; } + else + { + map.insert(GHeights::ALL, false); + } map.insert(GHeights::H92, GetParametrBool(domElement, AttrH92, defValue)); map.insert(GHeights::H98, GetParametrBool(domElement, AttrH98, defValue)); @@ -1938,10 +2012,68 @@ QMap VPattern::GetGradationHeights() const 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); @@ -1986,6 +2118,10 @@ QMap VPattern::GetGradationSizes() const { return map; } + else + { + map.insert(GSizes::ALL, false); + } map.insert(GSizes::S22, GetParametrBool(domElement, AttrS22, defValue)); map.insert(GSizes::S24, GetParametrBool(domElement, AttrS24, defValue)); @@ -2017,6 +2153,126 @@ QMap VPattern::GetGradationSizes() const 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 2008a23c2..72d65c8a9 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -163,7 +163,22 @@ public: 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. @@ -264,6 +279,7 @@ private: template QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const; void ParseCurrentPP(); + void CheckTagExists(const QString &tag); }; //---------------------------------------------------------------------------------------------------------------------