From 6597f68dad67e65847f934172c5a74cdfb272987 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 14 Feb 2017 17:33:30 +0200 Subject: [PATCH] Show all pins when tab Pins is active. --HG-- branch : feature --- src/libs/vmisc/def.h | 3 +- .../dialogs/tools/dialogseamallowance.cpp | 90 +++++++++++-------- .../dialogs/tools/dialogseamallowance.h | 9 +- .../dialogs/tools/dialogseamallowance.ui | 2 +- .../vtools/visualization/path/vispath.cpp | 21 +++++ src/libs/vtools/visualization/path/vispath.h | 3 + .../visualization/path/vispiecepins.cpp | 84 +++++++++++++++++ .../vtools/visualization/path/vispiecepins.h | 57 ++++++++++++ .../visualization/path/vistoolpiecepath.cpp | 16 +--- .../vtools/visualization/visualization.pri | 6 +- 10 files changed, 235 insertions(+), 56 deletions(-) create mode 100644 src/libs/vtools/visualization/path/vispiecepins.cpp create mode 100644 src/libs/vtools/visualization/path/vispiecepins.h diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 7234eaa95..c0903a1d9 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -195,7 +195,8 @@ enum class Vis : ToolVisHolderType ToolEllipticalArc, ToolPiece, ToolPiecePath, - ToolPin + ToolPin, + PiecePins }; enum class VarType : char { Measurement, Increment, LineLength, CurveLength, CurveCLength, LineAngle, CurveAngle, diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 54074d27c..d77868741 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -32,6 +32,7 @@ #include "../vpatterndb/vpiecepath.h" #include "../vpatterndb/calculator.h" #include "visualization/path/vistoolpiece.h" +#include "visualization/path/vispiecepins.h" #include "dialogpiecepath.h" #include "../../undocommands/savepiecepathoptions.h" #include "../support/dialogeditwrongformula.h" @@ -73,6 +74,7 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & m_mx(0), m_my(0), m_dialog(), + m_visPins(), m_qslMaterials(), m_qslPlacements(), m_conMCP(), @@ -101,6 +103,8 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & InitGrainlineTab(); InitPinsTab(); + connect(ui->tabWidget, &QTabWidget::currentChanged, this, &DialogSeamAllowance::TabChanged); + flagName = true;//We have default name of piece. ChangeColor(ui->labelEditName, okColor); flagError = MainPathIsValid(); @@ -622,6 +626,7 @@ void DialogSeamAllowance::ShowPinsContextMenu(const QPoint &pos) if (selectedAction == actionDelete) { delete ui->listWidgetPins->item(row); + TabChanged(ui->tabWidget->currentIndex()); } } @@ -932,6 +937,36 @@ void DialogSeamAllowance::PathDialogClosed(int result) delete m_dialog; } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::TabChanged(int index) +{ + if (ui->tabWidget->indexOf(ui->tabPins) == index) + { + if (m_visPins.isNull()) + { + m_visPins = new VisPiecePins(data); + } + + m_visPins->SetPins(GetPieceInternals(ui->listWidgetPins)); + + if (not qApp->getCurrentScene()->items().contains(m_visPins)) + { + m_visPins->VisualMode(NULL_ID); + } + else + { + m_visPins->RefreshGeometry(); + } + } + else + { + if (not m_visPins.isNull()) + { + delete m_visPins; + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::UpdateValues() { @@ -1276,47 +1311,16 @@ void DialogSeamAllowance::DeployWidthAfterFormulaTextEdit() VPiece DialogSeamAllowance::CreatePiece() const { VPiece piece; - for (qint32 i = 0; i < ui->listWidgetMainPath->count(); ++i) - { - QListWidgetItem *item = ui->listWidgetMainPath->item(i); - piece.GetPath().Append(qvariant_cast(item->data(Qt::UserRole))); - } - - QVector records; - for (qint32 i = 0; i < ui->listWidgetCustomSA->count(); ++i) - { - QListWidgetItem *item = ui->listWidgetCustomSA->item(i); - records.append(qvariant_cast(item->data(Qt::UserRole))); - } - piece.SetCustomSARecords(records); - - QVector iPaths; - for (qint32 i = 0; i < ui->listWidgetInternalPaths->count(); ++i) - { - QListWidgetItem *item = ui->listWidgetInternalPaths->item(i); - iPaths.append(qvariant_cast(item->data(Qt::UserRole))); - } - piece.SetInternalPaths(iPaths); - - QVector pins; - for (qint32 i = 0; i < ui->listWidgetPins->count(); ++i) - { - QListWidgetItem *item = ui->listWidgetPins->item(i); - pins.append(qvariant_cast(item->data(Qt::UserRole))); - } - piece.SetPins(pins); - + piece.GetPath().SetNodes(GetPieceInternals(ui->listWidgetMainPath)); + piece.SetCustomSARecords(GetPieceInternals(ui->listWidgetCustomSA)); + piece.SetInternalPaths(GetPieceInternals(ui->listWidgetInternalPaths)); + piece.SetPins(GetPieceInternals(ui->listWidgetPins)); piece.SetForbidFlipping(ui->checkBoxForbidFlipping->isChecked()); piece.SetSeamAllowance(ui->checkBoxSeams->isChecked()); piece.SetName(ui->lineEditName->text()); piece.SetMx(m_mx); piece.SetMy(m_my); - - QString width = ui->plainTextEditFormulaWidth->toPlainText(); - width.replace("\n", " "); - width = qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator()); - piece.SetFormulaSAWidth(width, m_saWidth); - + piece.SetFormulaSAWidth(GetFormulaFromUser(ui->plainTextEditFormulaWidth), m_saWidth); piece.GetPatternPieceData().SetLetter(ui->lineEditLetter->text()); for (int i = 0; i < m_conMCP.count(); ++i) @@ -1849,3 +1853,17 @@ void DialogSeamAllowance::ClearFields() ui->spinBoxCutNumber->setValue(0); ui->comboBoxPlacement->setCurrentIndex(0); } + +//--------------------------------------------------------------------------------------------------------------------- +template +QVector DialogSeamAllowance::GetPieceInternals(const QListWidget *list) const +{ + SCASSERT(list != nullptr) + QVector internals; + for (qint32 i = 0; i < list->count(); ++i) + { + QListWidgetItem *item = list->item(i); + internals.append(qvariant_cast(item->data(Qt::UserRole))); + } + return internals; +} diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/dialogseamallowance.h index 04bda4583..94c2e04d7 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.h +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.h @@ -40,6 +40,8 @@ namespace Ui class DialogSeamAllowance; } +class VisPiecePins; + class DialogSeamAllowance : public DialogTool { Q_OBJECT @@ -90,6 +92,7 @@ private slots: void ReturnDefAfter(); void CustomSAChanged(int row); void PathDialogClosed(int result); + void TabChanged(int index); void UpdateValues(); void SetAddMode(); @@ -125,7 +128,8 @@ private: qreal m_mx; qreal m_my; - QPointer m_dialog; + QPointer m_dialog; + QPointer m_visPins; QStringList m_qslMaterials; QStringList m_qslPlacements; @@ -181,6 +185,9 @@ private: void InitPinsTab(); void SetFormulaSAWidth(const QString &formula); + + template + QVector GetPieceInternals(const QListWidget *list) const; }; #endif // DIALOGSEAMALLOWANCE_H diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index 73d9c4118..c9139733a 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -21,7 +21,7 @@ - 0 + 3 diff --git a/src/libs/vtools/visualization/path/vispath.cpp b/src/libs/vtools/visualization/path/vispath.cpp index ff1bbdabf..9fc28c8c4 100644 --- a/src/libs/vtools/visualization/path/vispath.cpp +++ b/src/libs/vtools/visualization/path/vispath.cpp @@ -34,6 +34,7 @@ #include "../vmisc/vabstractapplication.h" #include "../vpatterndb/vcontainer.h" #include "../visualization.h" +#include "../vwidgets/vsimplepoint.h" //--------------------------------------------------------------------------------------------------------------------- VisPath::VisPath(const VContainer *data, QGraphicsItem *parent) @@ -59,3 +60,23 @@ void VisPath::AddOnScene() { AddItem(this); } + +//--------------------------------------------------------------------------------------------------------------------- +VSimplePoint *VisPath::GetPoint(QVector &points, quint32 i, const QColor &color) +{ + if (not points.isEmpty() && static_cast(points.size() - 1) >= i) + { + return points.at(static_cast(i)); + } + else + { + VSimplePoint *point = new VSimplePoint(NULL_ID, color, *Visualization::data->GetPatternUnit(), &factor); + point->SetPointHighlight(true); + point->setParentItem(this); + point->SetVisualizationMode(true); + points.append(point); + + return point; + } + return nullptr; +} diff --git a/src/libs/vtools/visualization/path/vispath.h b/src/libs/vtools/visualization/path/vispath.h index 3e42e952f..38c50462e 100644 --- a/src/libs/vtools/visualization/path/vispath.h +++ b/src/libs/vtools/visualization/path/vispath.h @@ -41,6 +41,7 @@ #include "../vmisc/def.h" class VContainer; +class VSimplePoint; class VisPath : public Visualization, public QGraphicsPathItem { @@ -54,6 +55,8 @@ public: protected: virtual void InitPen() Q_DECL_OVERRIDE; virtual void AddOnScene() Q_DECL_OVERRIDE; + + VSimplePoint *GetPoint(QVector &points, quint32 i, const QColor &color); private: Q_DISABLE_COPY(VisPath) }; diff --git a/src/libs/vtools/visualization/path/vispiecepins.cpp b/src/libs/vtools/visualization/path/vispiecepins.cpp new file mode 100644 index 000000000..7c17fff7d --- /dev/null +++ b/src/libs/vtools/visualization/path/vispiecepins.cpp @@ -0,0 +1,84 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 14 2, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vispiecepins.h" +#include "../vwidgets/vsimplepoint.h" +#include "../vgeometry/vpointf.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisPiecePins::VisPiecePins(const VContainer *data, QGraphicsItem *parent) + : VisPath(data, parent), + m_points(), + m_pins() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VisPiecePins::~VisPiecePins() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisPiecePins::RefreshGeometry() +{ + HideAllItems(); + + for (int i = 0; i < m_pins.size(); ++i) + { + VSimplePoint *point = GetPoint(static_cast(i), supportColor); + point->SetOnlyPoint(false); + const QSharedPointer p = Visualization::data->GeometricObject(m_pins.at(i)); + point->RefreshGeometry(*p); + point->setVisible(true); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisPiecePins::SetPins(const QVector &pins) +{ + m_pins = pins; +} + +//--------------------------------------------------------------------------------------------------------------------- +VSimplePoint *VisPiecePins::GetPoint(quint32 i, const QColor &color) +{ + return VisPath::GetPoint(m_points, i, color); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisPiecePins::HideAllItems() +{ + for (int i=0; i < m_points.size(); ++i) + { + if (QGraphicsEllipseItem *item = m_points.at(i)) + { + item->setVisible(false); + } + } +} + diff --git a/src/libs/vtools/visualization/path/vispiecepins.h b/src/libs/vtools/visualization/path/vispiecepins.h new file mode 100644 index 000000000..6e874099d --- /dev/null +++ b/src/libs/vtools/visualization/path/vispiecepins.h @@ -0,0 +1,57 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 14 2, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VISPIECEPINS_H +#define VISPIECEPINS_H + +#include "vispath.h" + +class VSimplePoint; + +class VisPiecePins : public VisPath +{ + Q_OBJECT +public: + VisPiecePins(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisPiecePins(); + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + void SetPins(const QVector &pins); + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::PiecePins)}; +private: + Q_DISABLE_COPY(VisPiecePins) + QVector m_points; + QVector m_pins; + + VSimplePoint *GetPoint(quint32 i, const QColor &color); + + void HideAllItems(); +}; + +#endif // VISPIECEPINS_H diff --git a/src/libs/vtools/visualization/path/vistoolpiecepath.cpp b/src/libs/vtools/visualization/path/vistoolpiecepath.cpp index a5e294f2a..46bc4ea55 100644 --- a/src/libs/vtools/visualization/path/vistoolpiecepath.cpp +++ b/src/libs/vtools/visualization/path/vistoolpiecepath.cpp @@ -91,21 +91,7 @@ void VisToolPiecePath::mousePressEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- VSimplePoint *VisToolPiecePath::GetPoint(quint32 i, const QColor &color) { - if (not m_points.isEmpty() && static_cast(m_points.size() - 1) >= i) - { - return m_points.at(static_cast(i)); - } - else - { - VSimplePoint *point = new VSimplePoint(NULL_ID, color, *Visualization::data->GetPatternUnit(), &factor); - point->SetPointHighlight(true); - point->setParentItem(this); - point->SetVisualizationMode(true); - m_points.append(point); - - return point; - } - return nullptr; + return VisPath::GetPoint(m_points, i, color); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index 042360691..1f822647e 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -41,7 +41,8 @@ HEADERS += \ $$PWD/path/vistoolellipticalarc.h \ $$PWD/path/vistoolpiece.h \ $$PWD/path/vistoolpiecepath.h \ - $$PWD/line/vistoolpin.h + $$PWD/line/vistoolpin.h \ + $$PWD/path/vispiecepins.h SOURCES += \ $$PWD/visualization.cpp \ @@ -83,4 +84,5 @@ SOURCES += \ $$PWD/path/vistoolellipticalarc.cpp \ $$PWD/path/vistoolpiece.cpp \ $$PWD/path/vistoolpiecepath.cpp \ - $$PWD/line/vistoolpin.cpp + $$PWD/line/vistoolpin.cpp \ + $$PWD/path/vispiecepins.cpp