From 962f6942eabfcadb90add4652baef695ccbeb148 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 7 Aug 2014 14:17:24 +0300 Subject: [PATCH 1/9] Get gradation options. --HG-- branch : feature --- src/app/xml/vdomdocument.cpp | 39 +++++++ src/app/xml/vdomdocument.h | 1 + src/app/xml/vpattern.cpp | 198 +++++++++++++++++++++++++++++++++++ src/app/xml/vpattern.h | 52 +++++++++ 4 files changed, 290 insertions(+) diff --git a/src/app/xml/vdomdocument.cpp b/src/app/xml/vdomdocument.cpp index f0c92c3a4..1e062ed98 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..2cfe16785 100644 --- a/src/app/xml/vdomdocument.h +++ b/src/app/xml/vdomdocument.h @@ -100,6 +100,7 @@ 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; diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 27c3c8114..658231781 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -61,11 +61,53 @@ 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::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"); @@ -1815,6 +1857,162 @@ quint32 VPattern::GetParametrId(const QDomElement &domElement) const return id; } +//--------------------------------------------------------------------------------------------------------------------- +QMap VPattern::GetGradationHeights() const +{ + QMap map; + 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); + + 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; + } + + 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)); + return map; + break; + case 1: // TagSizes + break; + default: + break; + } + } + } + domNode = domNode.nextSibling(); + } + return map; +} + +//--------------------------------------------------------------------------------------------------------------------- +QMap VPattern::GetGradationSizes() const +{ + QMap map; + 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; + } + + 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; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @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..95ecb2873 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -37,6 +37,10 @@ class VMainGraphicsScene; enum class Document : char { LiteParse, LitePPParse, FullParse}; +enum class GHeights : char { H92, H98, H104, H110, H116, H122, H128, H134, H140, H146, H152, H158, H164, H170, H176, + H182, H188}; +enum class GSizes : char { S22, S24, S26, S28, S30, S32, S34, S36, S38, S40, S42, S44, S46, S48, S50, S52, S54, S56}; + /* VAL_VERSION is (major << 16) + (minor << 8) + patch. */ @@ -103,18 +107,66 @@ 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 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; + QMap GetGradationSizes() const; signals: /** * @brief ChangedActivDraw change active pattern peace. From 68a3a15c4564efa565b5191dc4759223e203cdd3 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 7 Aug 2014 15:03:24 +0300 Subject: [PATCH 2/9] Prepare gradation list. --HG-- branch : feature --- src/app/container/vmeasurement.cpp | 42 ++++++++++++++++++++++++------ src/app/container/vmeasurement.h | 5 ++-- src/app/mainwindow.cpp | 4 +-- src/app/options.h | 7 +++++ src/app/xml/vpattern.cpp | 1 + src/app/xml/vpattern.h | 6 +---- 6 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/app/container/vmeasurement.cpp b/src/app/container/vmeasurement.cpp index d8b0ab33c..1701e604e 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()) + { + ListValue(list, static_cast(i.key())); + } + ++i; + } + + if (list.isEmpty()) + { + // from 92 cm to 188 cm + for (int i = 92; i<= 188; 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()) + { + 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/mainwindow.cpp b/src/app/mainwindow.cpp index a8e64756f..3d20241f8 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -762,8 +762,8 @@ 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); diff --git a/src/app/options.h b/src/app/options.h index 7dee201cb..8ea646eaf 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -75,6 +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, + H140=140, H146=146, H152=152, H158=158, H164=164, H170=170, H176=176, H182=182, + H188=188 }; + +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, + 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/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 658231781..bff2bfe79 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 diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index 95ecb2873..e63d1f4ed 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -35,11 +35,7 @@ class VDataTool; class VMainGraphicsScene; -enum class Document : char { LiteParse, LitePPParse, FullParse}; - -enum class GHeights : char { H92, H98, H104, H110, H116, H122, H128, H134, H140, H146, H152, H158, H164, H170, H176, - H182, H188}; -enum class GSizes : char { S22, S24, S26, S28, S30, S32, S34, S36, S38, S40, S42, S44, S46, S48, S50, S52, S54, S56}; +enum class Document : char { LiteParse, LitePPParse, FullParse }; /* VAL_VERSION is (major << 16) + (minor << 8) + patch. From ee5211a8114474f3025a048ba04bf6f822886db7 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 7 Aug 2014 17:05:37 +0300 Subject: [PATCH 3/9] Show gradation options. --HG-- branch : feature --- src/app/container/vmeasurement.cpp | 4 +- .../dialogs/app/dialogpatternproperties.cpp | 6 + .../dialogs/app/dialogpatternproperties.ui | 756 ++++++++++++++++-- src/app/options.h | 2 +- src/app/xml/vpattern.cpp | 3 + src/app/xml/vpattern.h | 1 + 6 files changed, 722 insertions(+), 50 deletions(-) diff --git a/src/app/container/vmeasurement.cpp b/src/app/container/vmeasurement.cpp index 1701e604e..0ecf094e7 100644 --- a/src/app/container/vmeasurement.cpp +++ b/src/app/container/vmeasurement.cpp @@ -118,8 +118,8 @@ QStringList VMeasurement::ListHeights(QMap heights) if (list.isEmpty()) { - // from 92 cm to 188 cm - for (int i = 92; i<= 188; i = i+6) + // from 92 cm to 194 cm + for (int i = 92; i<= 194; i = i+6) { ListValue(list, i); } diff --git a/src/app/dialogs/app/dialogpatternproperties.cpp b/src/app/dialogs/app/dialogpatternproperties.cpp index b0e24d325..07783621f 100644 --- a/src/app/dialogs/app/dialogpatternproperties.cpp +++ b/src/app/dialogs/app/dialogpatternproperties.cpp @@ -62,6 +62,12 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent) connect(bCansel, &QPushButton::clicked, this, &DialogPatternProperties::close); connect(this, &DialogPatternProperties::haveChange, this->doc, &VPattern::haveLiteChange); + + ui->tabWidget->setCurrentIndex(0); + if (qApp->patternUnit() == Unit::Inch) + { + ui->tabWidget->setTabEnabled(1, false); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/app/dialogpatternproperties.ui b/src/app/dialogs/app/dialogpatternproperties.ui index f18932430..82cf6a777 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,714 @@ :/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 + + + + + + 0 + 0 + + + + 92 + + + true + + + + + + + + 0 + 0 + + + + 146 + + + true + + + + + + + + 0 + 0 + + + + 98 + + + true + + + + + + + + 0 + 0 + + + + 152 + + + true + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + 104 + + + true + + + + + + + + 0 + 0 + + + + 158 + + + true + + + + + + + + 0 + 0 + + + + 110 + + + true + + + + + + + + 0 + 0 + + + + 164 + + + true + + + + + + + + 0 + 0 + + + + 116 + + + true + + + + + + + + 0 + 0 + + + + 170 + + + true + + + + + + + + 0 + 0 + + + + 122 + + + true + + + + + + + + 0 + 0 + + + + 176 + + + true + + + + + + + + 0 + 0 + + + + 128 + + + true + + + + + + + + 0 + 0 + + + + 182 + + + true + + + + + + + + 0 + 0 + + + + 134 + + + true + + + + + + + + 0 + 0 + + + + 188 + + + true + + + + + + + + 0 + 0 + + + + 140 + + + true + + + + + + + + 0 + 0 + + + + 194 + + + true + + + + + + + + + + + + + + All sizes (cm) + + + true + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 0 + 0 + + + + 22 + + + true + + + + + + + + 0 + 0 + + + + 40 + + + true + + + + + + + + 0 + 0 + + + + 24 + + + true + + + + + + + + 0 + 0 + + + + 42 + + + true + + + + + + + + 0 + 0 + + + + 26 + + + true + + + + + + + + 0 + 0 + + + + 44 + + + true + + + + + + + + 0 + 0 + + + + 28 + + + true + + + + + + + + 0 + 0 + + + + 46 + + + true + + + + + + + + 0 + 0 + + + + 30 + + + true + + + + + + + + 0 + 0 + + + + 48 + + + true + + + + + + + + 0 + 0 + + + + 32 + + + true + + + + + + + + 0 + 0 + + + + 50 + + + true + + + + + + + + 0 + 0 + + + + 34 + + + true + + + + + + + + 0 + 0 + + + + 52 + + + true + + + + + + + + 0 + 0 + + + + 36 + + + true + + + + + + + + 0 + 0 + + + + 54 + + + true + + + + + + + + 0 + 0 + + + + 38 + + + true + + + + + + + + 0 + 0 + + + + 56 + + + true + + + + + + + + + + + + + diff --git a/src/app/options.h b/src/app/options.h index 8ea646eaf..6c6c22db4 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -77,7 +77,7 @@ 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, H140=140, H146=146, H152=152, H158=158, H164=164, H170=170, H176=176, H182=182, - H188=188 }; + 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, S42=42, S44=44, S46=46, S48=48, S50=50, S52=52, S54=54, S56=56 }; diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index bff2bfe79..70c75dc19 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -89,6 +89,7 @@ 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"); @@ -1879,6 +1880,7 @@ QMap VPattern::GetGradationHeights() const 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) @@ -1921,6 +1923,7 @@ QMap VPattern::GetGradationHeights() const 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 diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index e63d1f4ed..2008a23c2 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -130,6 +130,7 @@ public: static const QString AttrH176; static const QString AttrH182; static const QString AttrH188; + static const QString AttrH194; static const QString AttrS22; static const QString AttrS24; From a7b9637f5f331430fcb83b3132afb8bdc6851c51 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 7 Aug 2014 22:06:36 +0300 Subject: [PATCH 4/9] CheckBoxs. --HG-- branch : feature --- .../dialogs/app/dialogpatternproperties.cpp | 229 +++++++++++++++++- src/app/dialogs/app/dialogpatternproperties.h | 7 + .../dialogs/app/dialogpatternproperties.ui | 184 +++++++++++--- src/app/mainwindow.cpp | 2 +- 4 files changed, 380 insertions(+), 42 deletions(-) diff --git a/src/app/dialogs/app/dialogpatternproperties.cpp b/src/app/dialogs/app/dialogpatternproperties.cpp index 07783621f..6f05c604f 100644 --- a/src/app/dialogs/app/dialogpatternproperties.cpp +++ b/src/app/dialogs/app/dialogpatternproperties.cpp @@ -33,9 +33,12 @@ #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) { ui->setupUi(this); @@ -64,10 +67,50 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent) connect(this, &DialogPatternProperties::haveChange, this->doc, &VPattern::haveLiteChange); ui->tabWidget->setCurrentIndex(0); - if (qApp->patternUnit() == Unit::Inch) + 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); + + 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); } //--------------------------------------------------------------------------------------------------------------------- @@ -86,6 +129,140 @@ void DialogPatternProperties::Apply() close(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::SelectAll(int state) +{ + QCheckBox* box = qobject_cast(sender()); + if (box) + { + if (box == ui->checkBoxAllHeights) + { + 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); + } + else if (state == Qt::Unchecked) + { + SetHeightsEnabled(true); + } + } + + if (box == ui->checkBoxAllSizes) + { + 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); + } + else if (state == Qt::Unchecked) + { + SetSizesEnabled(true); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::UncheckHeight(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) + { + ++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; + } + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::UncheckSize(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) + { + ++sizesChecked; + } + else if (state == Qt::Unchecked) + { + if (sizesChecked == 1) + { + box->setCheckState(Qt::Checked);//Will call this method again with Qt::Checked state + --sizesChecked; // That's why we will increase. + } + else + { + --sizesChecked; + } + } + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::Write(const QString &tagName, const QString &text) const { @@ -97,7 +274,7 @@ void DialogPatternProperties::Write(const QString &tagName, const QString &text) 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). + //The Old pattern file doesn't have comment. But here we try insert the tag after first child (comment). // // // -->place for new tag<-- @@ -125,3 +302,49 @@ void DialogPatternProperties::Write(const QString &tagName, const QString &text) } } } + +//--------------------------------------------------------------------------------------------------------------------- +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 c099058a5..2d89a7b5e 100644 --- a/src/app/dialogs/app/dialogpatternproperties.h +++ b/src/app/dialogs/app/dialogpatternproperties.h @@ -48,11 +48,18 @@ signals: void haveChange(); public slots: void Apply(); + void SelectAll(int state); + void UncheckHeight(int state); + void UncheckSize(int state); 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); }; #endif // DIALOGPATTERNPROPERTIES_H diff --git a/src/app/dialogs/app/dialogpatternproperties.ui b/src/app/dialogs/app/dialogpatternproperties.ui index 82cf6a777..16dd0bdd3 100644 --- a/src/app/dialogs/app/dialogpatternproperties.ui +++ b/src/app/dialogs/app/dialogpatternproperties.ui @@ -86,7 +86,7 @@ - + All heights (cm) @@ -108,7 +108,10 @@ QLayout::SetMaximumSize - + + + false + 0 @@ -124,7 +127,10 @@ - + + + false + 0 @@ -140,7 +146,10 @@ - + + + false + 0 @@ -156,7 +165,10 @@ - + + + false + 0 @@ -172,7 +184,10 @@ - + + + false + 0 @@ -194,7 +209,10 @@ - + + + false + 0 @@ -210,7 +228,10 @@ - + + + false + 0 @@ -226,7 +247,10 @@ - + + + false + 0 @@ -242,7 +266,10 @@ - + + + false + 0 @@ -258,7 +285,10 @@ - + + + false + 0 @@ -274,7 +304,10 @@ - + + + false + 0 @@ -290,7 +323,10 @@ - + + + false + 0 @@ -306,7 +342,10 @@ - + + + false + 0 @@ -322,7 +361,10 @@ - + + + false + 0 @@ -338,7 +380,10 @@ - + + + false + 0 @@ -354,7 +399,10 @@ - + + + false + 0 @@ -370,7 +418,10 @@ - + + + false + 0 @@ -386,7 +437,10 @@ - + + + false + 0 @@ -409,7 +463,7 @@ - + All sizes (cm) @@ -428,7 +482,10 @@ - + + + false + 0 @@ -444,7 +501,10 @@ - + + + false + 0 @@ -460,7 +520,10 @@ - + + + false + 0 @@ -476,7 +539,10 @@ - + + + false + 0 @@ -492,7 +558,10 @@ - + + + false + 0 @@ -508,7 +577,10 @@ - + + + false + 0 @@ -524,7 +596,10 @@ - + + + false + 0 @@ -540,7 +615,10 @@ - + + + false + 0 @@ -556,7 +634,10 @@ - + + + false + 0 @@ -572,7 +653,10 @@ - + + + false + 0 @@ -588,7 +672,10 @@ - + + + false + 0 @@ -604,7 +691,10 @@ - + + + false + 0 @@ -620,7 +710,10 @@ - + + + false + 0 @@ -636,7 +729,10 @@ - + + + false + 0 @@ -652,7 +748,10 @@ - + + + false + 0 @@ -668,7 +767,10 @@ - + + + false + 0 @@ -684,7 +786,10 @@ - + + + false + 0 @@ -700,7 +805,10 @@ - + + + false + 0 diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 64ec90702..c12ff3294 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -1813,7 +1813,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); From 83e3af90f88beb1be178e05816643dcbbb2c4793 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 8 Aug 2014 19:07:44 +0300 Subject: [PATCH 5/9] Save gradation options. --HG-- branch : feature --- src/app/container/vmeasurement.cpp | 4 +- .../dialogs/app/dialogpatternproperties.cpp | 496 ++++++++++-------- src/app/dialogs/app/dialogpatternproperties.h | 36 +- .../dialogs/app/dialogpatternproperties.ui | 74 +-- src/app/mainwindow.cpp | 2 +- src/app/options.h | 6 +- src/app/xml/vdomdocument.h | 26 +- src/app/xml/vpattern.cpp | 256 +++++++++ src/app/xml/vpattern.h | 16 + 9 files changed, 635 insertions(+), 281 deletions(-) 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); }; //--------------------------------------------------------------------------------------------------------------------- From 750825eb6a6e6868aeefa2db6438ce9106b44026 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 8 Aug 2014 19:22:32 +0300 Subject: [PATCH 6/9] Change in schema - support gradation tags. --HG-- branch : feature --- src/app/share/resources/schema/pattern.xsd | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From b31069859ed4e5f720298337ed4b3578356ac718 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 8 Aug 2014 19:24:36 +0300 Subject: [PATCH 7/9] Don't parse gradation in main parse loop. --HG-- branch : feature --- src/app/xml/vpattern.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 3b7f2666e..214f601c8 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -300,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) @@ -344,6 +345,8 @@ void VPattern::Parse(const Document &parse) break; case 6: // TagVersion break; + case 7: // TagGradation + break; default: qDebug()<<"Wrong tag name"< Date: Fri, 8 Aug 2014 22:46:05 +0300 Subject: [PATCH 8/9] Update after change, set default gradation options in list. --HG-- branch : feature --- src/app/mainwindow.cpp | 120 ++++++++++++++++++++++++++++++++++++----- src/app/mainwindow.h | 10 +++- 2 files changed, 116 insertions(+), 14 deletions(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index dc9c7b02f..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(); } @@ -764,8 +766,15 @@ void MainWindow::ToolBarOption() 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); } 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 From c0b6c3e9477e8f912894b336e9f50add578ccb1c Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 9 Aug 2014 10:42:14 +0300 Subject: [PATCH 9/9] Minor change in pattern format. Fixed issue #20. --HG-- branch : feature --- src/app/xml/vpattern.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index 72d65c8a9..1a264244c 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -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.