diff --git a/ChangeLog.txt b/ChangeLog.txt index 17d1bcbd4..0d0ab8011 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -52,6 +52,7 @@ - Mouse double click zoom fit best current pattern piece. - [#862] Force Valentina to immediately terminate if a pattern contains a parsing warning. - [#865] New feature. Dynamic Way to define Material in piece label. +- [#867] Visibility control for place labels. # Version 0.5.1 (unreleased) - [#683] Tool Seam allowance's dialog is off screen on small resolutions. diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index b8c8a19c1..6fd22fa4b 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -1827,16 +1827,21 @@ void VPattern::ParsePlaceLabel(QDomElement &domElement, const Document &parse) initData.angle = GetParametrString(domElement, AttrAngle, "0.0"); const QString angle = initData.angle;//need for saving fixed formula; + initData.visibilityTrigger = GetParametrString(domElement, VAbstractPattern::AttrVisible, "1.0"); + const QString visibility = initData.visibilityTrigger;//need for saving fixed formula; + initData.type = static_cast(GetParametrUInt(domElement, AttrPlaceLabelType, QChar('0'))); VToolPlaceLabel::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (w != initData.width || h != initData.height || angle != initData.angle) + if (w != initData.width || h != initData.height || angle != initData.angle + || visibility != initData.visibilityTrigger) { SetAttribute(domElement, AttrWidth, initData.width); SetAttribute(domElement, AttrHeight, initData.height); SetAttribute(domElement, AttrAngle, initData.angle); + SetAttribute(domElement, VAbstractPattern::AttrVisible, initData.visibilityTrigger); modified = true; haveLiteChange(); } diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index a386caf32..851514a50 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -50,6 +50,7 @@ schema/pattern/v0.7.6.xsd schema/pattern/v0.7.7.xsd schema/pattern/v0.7.8.xsd + schema/pattern/v0.7.9.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd @@ -63,5 +64,5 @@ schema/individual_measurements/v0.3.3.xsd schema/individual_measurements/v0.4.0.xsd schema/label_template/v1.0.0.xsd - + diff --git a/src/libs/ifc/schema/pattern/v0.7.9.xsd b/src/libs/ifc/schema/pattern/v0.7.9.xsd new file mode 100644 index 000000000..ec6b4ae78 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.7.9.xsd @@ -0,0 +1,1062 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index f58daa0be..b8112eecf 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -59,8 +59,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.7.8"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.7.8.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.7.9"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.7.9.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -228,7 +228,8 @@ QString VPatternConverter::XSDSchema(int ver) const std::make_pair(0x000705, QStringLiteral("://schema/pattern/v0.7.5.xsd")), std::make_pair(0x000706, QStringLiteral("://schema/pattern/v0.7.6.xsd")), std::make_pair(0x000707, QStringLiteral("://schema/pattern/v0.7.7.xsd")), - std::make_pair(0x000708, CurrentSchema) + std::make_pair(0x000708, QStringLiteral("://schema/pattern/v0.7.8.xsd")), + std::make_pair(0x000709, CurrentSchema) }; if (schemas.contains(ver)) @@ -443,6 +444,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000708), m_convertedFileName); V_FALLTHROUGH case (0x000708): + ToV0_7_9(); + ValidateXML(XSDSchema(0x000709), m_convertedFileName); + V_FALLTHROUGH + case (0x000709): break; default: InvalidVersion(m_ver); @@ -460,7 +465,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion() bool VPatternConverter::IsReadOnly() const { // Check if attribute readOnly was not changed in file format - Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 7, 8), + Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 7, 9), "Check attribute readOnly."); // Possibly in future attribute readOnly will change position etc. @@ -1014,6 +1019,15 @@ void VPatternConverter::ToV0_7_8() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_7_9() +{ + // TODO. Delete if minimal supported version is 0.7.9 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 9), + "Time to refactor the code."); + SetVersion(QStringLiteral("0.7.9")); + Save(); +} //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 9a6bb750b..0592d20ec 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -53,7 +53,7 @@ public: static const QString PatternMaxVerStr; static const QString CurrentSchema; static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 8); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 9); protected: virtual int MinVer() const override; @@ -121,6 +121,7 @@ private: void ToV0_7_6(); void ToV0_7_7(); void ToV0_7_8(); + void ToV0_7_9(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vgeometry/vplacelabelitem.cpp b/src/libs/vgeometry/vplacelabelitem.cpp index 1e43006ea..8d3f71e87 100644 --- a/src/libs/vgeometry/vplacelabelitem.cpp +++ b/src/libs/vgeometry/vplacelabelitem.cpp @@ -125,6 +125,41 @@ void VPlaceLabelItem::SetAngle(qreal value, const QString &formula) d->angle = formula; } +//--------------------------------------------------------------------------------------------------------------------- +QString VPlaceLabelItem::GetVisibilityTrigger() const +{ + return d->visibilityTrigger; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString &VPlaceLabelItem::GetVisibilityTrigger() +{ + return d->visibilityTrigger; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPlaceLabelItem::IsVisible() const +{ + bool visible = true; + + if (qIsInf(d->isVisible) || qIsNaN(d->isVisible)) + { + qWarning() << QObject::tr("Visibility trigger contains error and will be ignored"); + } + else if (qFuzzyIsNull(d->isVisible)) + { + visible = false; + } + return visible; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPlaceLabelItem::SetVisibilityTrigger(qreal visible, const QString &formula) +{ + d->visibilityTrigger = formula; + d->isVisible = visible; +} + //--------------------------------------------------------------------------------------------------------------------- qreal VPlaceLabelItem::GetCorrectionAngle() const { diff --git a/src/libs/vgeometry/vplacelabelitem.h b/src/libs/vgeometry/vplacelabelitem.h index 0a4df1c17..55f46004b 100644 --- a/src/libs/vgeometry/vplacelabelitem.h +++ b/src/libs/vgeometry/vplacelabelitem.h @@ -68,6 +68,11 @@ public: qreal GetAngle() const; void SetAngle(qreal value, const QString &formula); + QString GetVisibilityTrigger() const; + QString& GetVisibilityTrigger(); + bool IsVisible() const; + void SetVisibilityTrigger(qreal visible, const QString &formula); + qreal GetCorrectionAngle() const; void SetCorrectionAngle(qreal value); diff --git a/src/libs/vgeometry/vplacelabelitem_p.h b/src/libs/vgeometry/vplacelabelitem_p.h index 2fdf0197a..3eccc3965 100644 --- a/src/libs/vgeometry/vplacelabelitem_p.h +++ b/src/libs/vgeometry/vplacelabelitem_p.h @@ -44,12 +44,14 @@ public: : width(), height(), angle('0'), + visibilityTrigger('1'), type(PlaceLabelType::Button), centerPoint(0), wValue(0), hValue(0), aValue(0), - correctionAngle(0) + correctionAngle(0), + isVisible(1) {} VPlaceLabelItemData(const VPlaceLabelItemData &item) @@ -57,12 +59,14 @@ public: width(item.width), height(item.height), angle(item.angle), + visibilityTrigger(item.visibilityTrigger), type(item.type), centerPoint(item.centerPoint), wValue(item.wValue), hValue(item.hValue), aValue(item.aValue), - correctionAngle(item.correctionAngle) + correctionAngle(item.correctionAngle), + isVisible(item.isVisible) {} virtual ~VPlaceLabelItemData(); @@ -70,6 +74,7 @@ public: QString width; QString height; QString angle; + QString visibilityTrigger; PlaceLabelType type; quint32 centerPoint; @@ -77,6 +82,7 @@ public: qreal hValue; qreal aValue; qreal correctionAngle; + qreal isVisible; private: VPlaceLabelItemData &operator=(const VPlaceLabelItemData &) Q_DECL_EQ_DELETE; diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index b942a069b..9945cfd94 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -352,11 +352,14 @@ QVector ConvertPlaceLabels(const VPiece &piece, const VContai for(auto placeLabel : placeLabels) { const auto label = pattern->GeometricObject(placeLabel); - VLayoutPlaceLabel layoutLabel; - layoutLabel.shape = label->LabelShape(); - layoutLabel.center = label->toQPointF(); - layoutLabel.type = label->GetLabelType(); - labels.append(layoutLabel); + if (label->IsVisible()) + { + VLayoutPlaceLabel layoutLabel; + layoutLabel.shape = label->LabelShape(); + layoutLabel.center = label->toQPointF(); + layoutLabel.type = label->GetLabelType(); + labels.append(layoutLabel); + } } return labels; } diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index fd0153bca..dfad10a6b 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -452,7 +452,10 @@ QVector VPiece::PlaceLabelPoints(const VContainer *data) const try { const auto label = data->GeometricObject(placeLabel); - points.append(label->LabelShape()); + if (label->IsVisible()) + { + points.append(label->LabelShape()); + } } catch (const VExceptionBadId &e) { diff --git a/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.cpp b/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.cpp index 63ddeb9ce..f0bd3308c 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.cpp @@ -45,50 +45,27 @@ DialogPlaceLabel::DialogPlaceLabel(const VContainer *data, quint32 toolId, QWidg m_flagWidth(false), m_flagHeight(false), m_flagAngle(false), + m_flagFormulaVisible(false), m_formulaBaseHeightWidth(0), m_formulaBaseHeightHeight(0), m_formulaBaseHeightAngle(0), + m_formulaBaseVisible(0), timerAngle(new QTimer(this)), timerWidth(new QTimer(this)), - timerHeight(new QTimer(this)) + timerHeight(new QTimer(this)), + m_timerVisible(new QTimer(this)) { ui->setupUi(this); InitOkCancel(ui); - FillComboBoxPoints(ui->comboBoxPoint); - FillPlaceLabelTypes(); + InitPlaceLabelTab(); + InitControlTab(); - m_formulaBaseHeightWidth = ui->plainTextEditFormulaWidth->height(); - m_formulaBaseHeightHeight = ui->plainTextEditFormulaHeight->height(); - m_formulaBaseHeightAngle = ui->plainTextEditFormulaAngle->height(); - - ui->plainTextEditFormulaWidth->installEventFilter(this); - ui->plainTextEditFormulaHeight->installEventFilter(this); - ui->plainTextEditFormulaAngle->installEventFilter(this); - - ui->plainTextEditFormulaWidth->setPlainText(QString::number(UnitConvertor(1, Unit::Cm, qApp->patternUnit()))); - ui->plainTextEditFormulaHeight->setPlainText(QString::number(UnitConvertor(1, Unit::Cm, qApp->patternUnit()))); + EvalVisible(); flagError = false; CheckState(); - connect(ui->toolButtonExprWidth, &QPushButton::clicked, this, &DialogPlaceLabel::FXWidth); - connect(ui->toolButtonExprHeight, &QPushButton::clicked, this, &DialogPlaceLabel::FXHeight); - connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogPlaceLabel::FXAngle); - - connect(ui->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this, &DialogPlaceLabel::FormulaWidthChanged); - connect(ui->plainTextEditFormulaHeight, &QPlainTextEdit::textChanged, this, - &DialogPlaceLabel::FormulaHeightChanged); - connect(ui->plainTextEditFormulaAngle, &QPlainTextEdit::textChanged, this, &DialogPlaceLabel::FormulaAngleChanged); - - connect(ui->pushButtonGrowWidth, &QPushButton::clicked, this, &DialogPlaceLabel::DeployFormulaWidthEdit); - connect(ui->pushButtonGrowHeight, &QPushButton::clicked, this, &DialogPlaceLabel::DeployFormulaHeightEdit); - connect(ui->pushButtonGrowAngle, &QPushButton::clicked, this, &DialogPlaceLabel::DeployFormulaAngleEdit); - - connect(timerWidth, &QTimer::timeout, this, &DialogPlaceLabel::EvalWidth); - connect(timerHeight, &QTimer::timeout, this, &DialogPlaceLabel::EvalHeight); - connect(timerAngle, &QTimer::timeout, this, &DialogPlaceLabel::EvalAngle); - connect(ui->comboBoxPiece, QOverload::of(&QComboBox::currentIndexChanged), this, [this]() { CheckPieces(); @@ -287,7 +264,7 @@ void DialogPlaceLabel::ChosenObject(quint32 id, const SceneObject &type) void DialogPlaceLabel::CheckState() { SCASSERT(bOk != nullptr); - bOk->setEnabled(m_flagPoint && flagError && m_flagWidth && m_flagHeight && m_flagAngle); + bOk->setEnabled(m_flagPoint && flagError && m_flagWidth && m_flagHeight && m_flagAngle && m_flagFormulaVisible); } //--------------------------------------------------------------------------------------------------------------------- @@ -305,6 +282,7 @@ void DialogPlaceLabel::closeEvent(QCloseEvent *event) ui->plainTextEditFormulaWidth->blockSignals(true); ui->plainTextEditFormulaHeight->blockSignals(true); ui->plainTextEditFormulaAngle->blockSignals(true); + ui->plainTextEditFormulaVisible->blockSignals(true); DialogTool::closeEvent(event); } @@ -326,6 +304,12 @@ void DialogPlaceLabel::DeployFormulaAngleEdit() DeployFormula(ui->plainTextEditFormulaAngle, ui->pushButtonGrowAngle, m_formulaBaseHeightAngle); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::DeployVisibleFormulaTextEdit() +{ + DeployFormula(ui->plainTextEditFormulaVisible, ui->pushButtonGrowVisible, m_formulaBaseVisible); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPlaceLabel::FormulaWidthChanged() { @@ -352,6 +336,14 @@ void DialogPlaceLabel::FormulaAngleChanged() ValFormulaChanged(m_flagAngle, ui->plainTextEditFormulaAngle, timerAngle, degreeSymbol); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::VisibleChanged() +{ + labelEditFormula = ui->labelEditVisible; + labelResultCalculation = ui->labelResultVisible; + ValFormulaChanged(m_flagFormulaVisible, ui->plainTextEditFormulaVisible, m_timerVisible, QString()); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPlaceLabel::EvalWidth() { @@ -378,6 +370,14 @@ void DialogPlaceLabel::EvalAngle() false); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::EvalVisible() +{ + labelEditFormula = ui->labelEditVisible; + QString formula = ui->plainTextEditFormulaVisible->toPlainText(); + Eval(formula, m_flagFormulaVisible, ui->labelResultVisible, QString(), false, true); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPlaceLabel::FXWidth() { @@ -417,6 +417,67 @@ void DialogPlaceLabel::FXAngle() } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::FXVisible() +{ + QScopedPointer dialog(new DialogEditWrongFormula(data, toolId, this)); + dialog->setWindowTitle(tr("Control visibility")); + dialog->SetFormula(GetFormulaVisible()); + if (dialog->exec() == QDialog::Accepted) + { + SetFormulaVisible(dialog->GetFormula()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::InitPlaceLabelTab() +{ + FillComboBoxPoints(ui->comboBoxPoint); + FillPlaceLabelTypes(); + + m_formulaBaseHeightWidth = ui->plainTextEditFormulaWidth->height(); + m_formulaBaseHeightHeight = ui->plainTextEditFormulaHeight->height(); + m_formulaBaseHeightAngle = ui->plainTextEditFormulaAngle->height(); + + ui->plainTextEditFormulaWidth->installEventFilter(this); + ui->plainTextEditFormulaHeight->installEventFilter(this); + ui->plainTextEditFormulaAngle->installEventFilter(this); + + ui->plainTextEditFormulaWidth->setPlainText(QString::number(UnitConvertor(1, Unit::Cm, qApp->patternUnit()))); + ui->plainTextEditFormulaHeight->setPlainText(QString::number(UnitConvertor(1, Unit::Cm, qApp->patternUnit()))); + + connect(ui->toolButtonExprWidth, &QPushButton::clicked, this, &DialogPlaceLabel::FXWidth); + connect(ui->toolButtonExprHeight, &QPushButton::clicked, this, &DialogPlaceLabel::FXHeight); + connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogPlaceLabel::FXAngle); + + connect(ui->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this, &DialogPlaceLabel::FormulaWidthChanged); + connect(ui->plainTextEditFormulaHeight, &QPlainTextEdit::textChanged, this, + &DialogPlaceLabel::FormulaHeightChanged); + connect(ui->plainTextEditFormulaAngle, &QPlainTextEdit::textChanged, this, &DialogPlaceLabel::FormulaAngleChanged); + + connect(ui->pushButtonGrowWidth, &QPushButton::clicked, this, &DialogPlaceLabel::DeployFormulaWidthEdit); + connect(ui->pushButtonGrowHeight, &QPushButton::clicked, this, &DialogPlaceLabel::DeployFormulaHeightEdit); + connect(ui->pushButtonGrowAngle, &QPushButton::clicked, this, &DialogPlaceLabel::DeployFormulaAngleEdit); + + connect(timerWidth, &QTimer::timeout, this, &DialogPlaceLabel::EvalWidth); + connect(timerHeight, &QTimer::timeout, this, &DialogPlaceLabel::EvalHeight); + connect(timerAngle, &QTimer::timeout, this, &DialogPlaceLabel::EvalAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::InitControlTab() +{ + this->m_formulaBaseVisible = ui->plainTextEditFormulaVisible->height(); + + ui->plainTextEditFormulaVisible->installEventFilter(this); + + connect(m_timerVisible, &QTimer::timeout, this, &DialogPlaceLabel::EvalVisible); + connect(ui->toolButtonExprVisible, &QPushButton::clicked, this, &DialogPlaceLabel::FXVisible); + connect(ui->plainTextEditFormulaVisible, &QPlainTextEdit::textChanged, this, &DialogPlaceLabel::VisibleChanged); + connect(ui->pushButtonGrowVisible, &QPushButton::clicked, this, + &DialogPlaceLabel::DeployVisibleFormulaTextEdit); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPlaceLabel::FillPlaceLabelTypes() { @@ -469,3 +530,23 @@ void DialogPlaceLabel::CheckPoint() ChangeColor(ui->labelPoint, color); CheckState(); } + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogPlaceLabel::GetFormulaVisible() const +{ + QString formula = ui->plainTextEditFormulaVisible->toPlainText(); + return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPlaceLabel::SetFormulaVisible(const QString &formula) +{ + const QString f = qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (f.length() > 80) + { + this->DeployVisibleFormulaTextEdit(); + } + ui->plainTextEditFormulaVisible->setPlainText(f); + MoveCursorToEnd(ui->plainTextEditFormulaVisible); +} diff --git a/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.h b/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.h index 145ed5830..8cdfbffe7 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.h +++ b/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.h @@ -65,6 +65,9 @@ public: quint32 GetPieceId() const; void SetPieceId(quint32 id); + QString GetFormulaVisible() const; + void SetFormulaVisible(const QString &formula); + virtual void SetPiecesList(const QVector &list) override; public slots: @@ -79,18 +82,22 @@ private slots: void DeployFormulaWidthEdit(); void DeployFormulaHeightEdit(); void DeployFormulaAngleEdit(); + void DeployVisibleFormulaTextEdit(); void FormulaWidthChanged(); void FormulaHeightChanged(); void FormulaAngleChanged(); + void VisibleChanged(); void EvalWidth(); void EvalHeight(); void EvalAngle(); + void EvalVisible(); void FXWidth(); void FXHeight(); void FXAngle(); + void FXVisible(); private: Q_DISABLE_COPY(DialogPlaceLabel) @@ -100,15 +107,21 @@ private: bool m_flagWidth; bool m_flagHeight; bool m_flagAngle; + bool m_flagFormulaVisible; /** @brief formulaBaseHeight base height defined by dialogui */ int m_formulaBaseHeightWidth; int m_formulaBaseHeightHeight; int m_formulaBaseHeightAngle; + int m_formulaBaseVisible; QTimer *timerAngle; QTimer *timerWidth; QTimer *timerHeight; + QTimer *m_timerVisible; + + void InitPlaceLabelTab(); + void InitControlTab(); void FillPlaceLabelTypes(); diff --git a/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.ui b/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.ui index 4376d64f7..6b0113e46 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.ui +++ b/src/libs/vtools/dialogs/tools/piece/dialogplacelabel.ui @@ -6,602 +6,829 @@ 0 0 - 338 - 363 + 396 + 414 - Dialog + Place label + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png - - - - - - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - - - Width: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Formula wizard - - - ... - - - - :/icon/24x24/fx.png:/icon/24x24/fx.png - - - - 24 - 24 - - - - - - - - - - - :/icon/24x24/equal.png - - - - - - - - 0 - 0 - - - - - 87 - 0 - - - - Value - - - - - - _ - - - - - - - - - - - - 0 - 0 - - - - - 16777215 - 28 - - - - Calculation - - - true - - - - - - - - 18 - 18 - - - - - 0 - 0 - - - - <html><head/><body><p>Show full calculation in message box</p></body></html> - - - - - - - .. - - - - 16 - 16 - - - - true - - - - - - - - - - - - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - - - Height: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Formula wizard - - - ... - - - - :/icon/24x24/fx.png:/icon/24x24/fx.png - - - - 24 - 24 - - - - - - - - - - - :/icon/24x24/equal.png - - - - - - - - 0 - 0 - - - - - 87 - 0 - - - - Value - - - - - - _ - - - - - - - - - - - - 0 - 0 - - - - - 16777215 - 28 - - - - Calculation - - - true - - - - - - - - 18 - 18 - - - - - 0 - 0 - - - - <html><head/><body><p>Show full calculation in message box</p></body></html> - - - - - - - .. - - - - 16 - 16 - - - - true - - - - - - - - - - - - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - - - Angle: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Formula wizard - - - ... - - - - :/icon/24x24/fx.png:/icon/24x24/fx.png - - - - 24 - 24 - - - - - - - - - - - :/icon/24x24/equal.png - - - - - - - - 0 - 0 - - - - - 87 - 0 - - - - Value - - - - - - _ - - - - - - - - - - - - 0 - 0 - - - - - 16777215 - 28 - - - - Calculation - - - true - - - 0 - - - - - - - - 18 - 18 - - - - - 0 - 0 - - - - <html><head/><body><p>Show full calculation in message box</p></body></html> - - - - - - - .. - - - - 16 - 16 - - - - true - - - - - - - - - QFormLayout::ExpandingFieldsGrow + + + 0 - - - - Point: - - - - - - - - - - Piece: - - - - - - - - - - Type: - - - - - - - + + + Place label + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Width: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Height: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Angle: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 0 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Point: + + + + + + + + + + Piece: + + + + + + + + + + Type: + + + + + + + + + + + + + Control + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Visible + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + true + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Create a formula that regulates visibility. Values different from "0" make a path visible. + + + true + + + 1 + + + + + + + true + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index e122374cb..174eac69b 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -843,6 +843,7 @@ void DialogSeamAllowance::ShowPlaceLabelsContextMenu(const QPoint &pos) dialog->SetWidth(currentLabel.GetWidthFormula()); dialog->SetHeight(currentLabel.GetHeightFormula()); dialog->SetAngle(currentLabel.GetAngleFormula()); + dialog->SetFormulaVisible(currentLabel.GetVisibilityTrigger()); dialog->SetPieceId(toolId); dialog->EnbleShowMode(true); m_dialog = dialog; @@ -1295,7 +1296,8 @@ void DialogSeamAllowance::PlaceLabelDialogClosed(int result) const qreal w = qAbs(Visualization::FindLengthFromUser(dialogTool->GetWidth(), vars, false)); const qreal h = qAbs(Visualization::FindLengthFromUser(dialogTool->GetHeight(), vars, false)); const qreal a = Visualization::FindValFromUser(dialogTool->GetAngle(), vars, false); - qDebug() << w << h << a; + const qreal v = Visualization::FindValFromUser(dialogTool->GetFormulaVisible(), vars, false); + qDebug() << w << h << a << v; VPlaceLabelItem newLabel = VPlaceLabelItem(); newLabel.setName(currentLabel.name()); @@ -1306,6 +1308,7 @@ void DialogSeamAllowance::PlaceLabelDialogClosed(int result) newLabel.SetWidth(w, dialogTool->GetWidth()); newLabel.SetHeight(h, dialogTool->GetHeight()); newLabel.SetAngle(a, dialogTool->GetAngle()); + newLabel.SetVisibilityTrigger(v, dialogTool->GetFormulaVisible()); newLabel.SetLabelType(dialogTool->GetLabelType()); newLabel.SetCenterPoint(currentLabel.GetCenterPoint()); newLabel.SetCorrectionAngle(currentLabel.GetCorrectionAngle()); diff --git a/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.cpp b/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.cpp index 67ef4e39d..653aa7ebb 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.cpp @@ -46,6 +46,7 @@ VToolPlaceLabel *VToolPlaceLabel::Create(QSharedPointer dialog, VAbs initData.width = dialogTool->GetWidth(); initData.height = dialogTool->GetHeight(); initData.angle = dialogTool->GetAngle(); + initData.visibilityTrigger = dialogTool->GetFormulaVisible(); initData.type = dialogTool->GetLabelType(); initData.centerPoint = dialogTool->GetCenterPoint(); initData.idObject = dialogTool->GetPieceId(); @@ -63,11 +64,13 @@ VToolPlaceLabel *VToolPlaceLabel::Create(VToolPlaceLabelInitData &initData) const qreal w = qAbs(qApp->toPixel(CheckFormula(initData.id, initData.width, initData.data))); const qreal h = qAbs(qApp->toPixel(CheckFormula(initData.id, initData.height, initData.data))); const qreal a = CheckFormula(initData.id, initData.angle, initData.data); + const qreal v = CheckFormula(initData.id, initData.visibilityTrigger, initData.data); QSharedPointer node(new VPlaceLabelItem()); node->SetWidth(w, initData.width); node->SetHeight(h, initData.height); node->SetAngle(a, initData.angle); + node->SetVisibilityTrigger(v, initData.visibilityTrigger); node->SetLabelType(initData.type); node->SetCenterPoint(initData.centerPoint); @@ -159,6 +162,7 @@ void VToolPlaceLabel::AddAttributes(VAbstractPattern *doc, QDomElement &domEleme doc->SetAttribute(domElement, AttrWidth, label.GetWidthFormula()); doc->SetAttribute(domElement, AttrHeight, label.GetHeightFormula()); doc->SetAttribute(domElement, AttrAngle, label.GetAngleFormula()); + doc->SetAttribute(domElement, VAbstractPattern::AttrVisible, label.GetVisibilityTrigger()); doc->SetAttribute(domElement, AttrPlaceLabelType, static_cast(label.GetLabelType())); } diff --git a/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.h b/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.h index 16c2acc1e..a06e8d6e9 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.h +++ b/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.h @@ -43,7 +43,8 @@ struct VToolPlaceLabelInitData : VAbstractNodeInitData height('0'), angle('0'), type(PlaceLabelType::Button), - centerPoint(NULL_ID) + centerPoint(NULL_ID), + visibilityTrigger('1') {} QString width; @@ -51,6 +52,7 @@ struct VToolPlaceLabelInitData : VAbstractNodeInitData QString angle; PlaceLabelType type; quint32 centerPoint; + QString visibilityTrigger; }; class VToolPlaceLabel : public VAbstractNode diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 2b718d1e5..5f2ee7076 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -2093,6 +2093,7 @@ QVector VToolSeamAllowance::DuplicatePlaceLabels(const QVector initNodeData.width = label->GetWidthFormula(); initNodeData.height = label->GetHeightFormula(); initNodeData.angle = label->GetAngleFormula(); + initNodeData.visibilityTrigger = label->GetVisibilityTrigger(); initNodeData.type = label->GetLabelType(); initNodeData.centerPoint = label->GetCenterPoint(); initNodeData.id = initNodeData.data->AddGObject(new VPlaceLabelItem(*label)); diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 60da8045b..9d41f196a 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -490,6 +490,7 @@ quint32 AddPlaceLabel(quint32 id, const VToolUnionDetailsInitData &initData, QVe initNodeData.width = label->GetWidthFormula(); initNodeData.height = label->GetHeightFormula(); initNodeData.angle = label->GetAngleFormula(); + initNodeData.visibilityTrigger = label->GetVisibilityTrigger(); initNodeData.type = label->GetLabelType(); QScopedPointer label1(new VPlaceLabelItem(*label));