Show all pins when tab Pins is active.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-02-14 17:33:30 +02:00
parent 79a1caa4d7
commit 6597f68dad
10 changed files with 235 additions and 56 deletions

View File

@ -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,

View File

@ -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<quint32>(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<VPieceNode>(item->data(Qt::UserRole)));
}
QVector<CustomSARecord> records;
for (qint32 i = 0; i < ui->listWidgetCustomSA->count(); ++i)
{
QListWidgetItem *item = ui->listWidgetCustomSA->item(i);
records.append(qvariant_cast<CustomSARecord>(item->data(Qt::UserRole)));
}
piece.SetCustomSARecords(records);
QVector<quint32> iPaths;
for (qint32 i = 0; i < ui->listWidgetInternalPaths->count(); ++i)
{
QListWidgetItem *item = ui->listWidgetInternalPaths->item(i);
iPaths.append(qvariant_cast<quint32>(item->data(Qt::UserRole)));
}
piece.SetInternalPaths(iPaths);
QVector<quint32> pins;
for (qint32 i = 0; i < ui->listWidgetPins->count(); ++i)
{
QListWidgetItem *item = ui->listWidgetPins->item(i);
pins.append(qvariant_cast<quint32>(item->data(Qt::UserRole)));
}
piece.SetPins(pins);
piece.GetPath().SetNodes(GetPieceInternals<VPieceNode>(ui->listWidgetMainPath));
piece.SetCustomSARecords(GetPieceInternals<CustomSARecord>(ui->listWidgetCustomSA));
piece.SetInternalPaths(GetPieceInternals<quint32>(ui->listWidgetInternalPaths));
piece.SetPins(GetPieceInternals<quint32>(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 <typename T>
QVector<T> DialogSeamAllowance::GetPieceInternals(const QListWidget *list) const
{
SCASSERT(list != nullptr)
QVector<T> internals;
for (qint32 i = 0; i < list->count(); ++i)
{
QListWidgetItem *item = list->item(i);
internals.append(qvariant_cast<T>(item->data(Qt::UserRole)));
}
return internals;
}

View File

@ -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();
@ -126,6 +129,7 @@ private:
qreal m_my;
QPointer<DialogTool> m_dialog;
QPointer<VisPiecePins> m_visPins;
QStringList m_qslMaterials;
QStringList m_qslPlacements;
@ -181,6 +185,9 @@ private:
void InitPinsTab();
void SetFormulaSAWidth(const QString &formula);
template <typename T>
QVector<T> GetPieceInternals(const QListWidget *list) const;
};
#endif // DIALOGSEAMALLOWANCE_H

View File

@ -21,7 +21,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<widget class="QWidget" name="tabMainPath">
<attribute name="title">

View File

@ -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<VSimplePoint *> &points, quint32 i, const QColor &color)
{
if (not points.isEmpty() && static_cast<quint32>(points.size() - 1) >= i)
{
return points.at(static_cast<int>(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;
}

View File

@ -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<VSimplePoint *> &points, quint32 i, const QColor &color);
private:
Q_DISABLE_COPY(VisPath)
};

View File

@ -0,0 +1,84 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#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<quint32>(i), supportColor);
point->SetOnlyPoint(false);
const QSharedPointer<VPointF> p = Visualization::data->GeometricObject<VPointF>(m_pins.at(i));
point->RefreshGeometry(*p);
point->setVisible(true);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VisPiecePins::SetPins(const QVector<quint32> &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);
}
}
}

View File

@ -0,0 +1,57 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#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<quint32> &pins);
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Vis::PiecePins)};
private:
Q_DISABLE_COPY(VisPiecePins)
QVector<VSimplePoint *> m_points;
QVector<quint32> m_pins;
VSimplePoint *GetPoint(quint32 i, const QColor &color);
void HideAllItems();
};
#endif // VISPIECEPINS_H

View File

@ -91,21 +91,7 @@ void VisToolPiecePath::mousePressEvent(QGraphicsSceneMouseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
VSimplePoint *VisToolPiecePath::GetPoint(quint32 i, const QColor &color)
{
if (not m_points.isEmpty() && static_cast<quint32>(m_points.size() - 1) >= i)
{
return m_points.at(static_cast<int>(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);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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