Merge branch 'develop' into feature/manual-layout

This commit is contained in:
Roman Telezhynskyi 2020-11-21 19:05:46 +02:00
commit e8fd8095b4
13 changed files with 191 additions and 121 deletions

View File

@ -1,5 +1,6 @@
# Version 0.7.40 (unreleased) # Version 0.7.40 (unreleased)
- New function Warning. - New function Warning.
- [smart-pattern/valentina#80] Allow insertion of multiple nodes.
# Version 0.7.39 Nov 17, 2020 # Version 0.7.39 Nov 17, 2020
- Fix crash for Line tool notes. - Fix crash for Line tool notes.

View File

@ -1336,7 +1336,7 @@ void MainWindow::ClosedDialogInsertNode(int result)
{ {
const QPointer<DialogInsertNode> dTool = qobject_cast<DialogInsertNode *>(dialogTool); const QPointer<DialogInsertNode> dTool = qobject_cast<DialogInsertNode *>(dialogTool);
SCASSERT(not dTool.isNull()) SCASSERT(not dTool.isNull())
VToolSeamAllowance::InsertNode(dTool->GetNode(), dTool->GetPieceId(), sceneDetails, pattern, doc); VToolSeamAllowance::InsertNode(dTool->GetNodes(), dTool->GetPieceId(), sceneDetails, pattern, doc);
} }
ArrowTool(true); ArrowTool(true);
doc->LiteParseTree(Document::LiteParse); doc->LiteParseTree(Document::LiteParse);
@ -1493,9 +1493,12 @@ void MainWindow::ToolTrueDarts(bool checked)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindow::ToolInsertNode(bool checked) void MainWindow::ToolInsertNode(bool checked)
{ {
ToolSelectAllDrawObjects(); ToolSelectOperationObjects();
const QString tooltip = tr("Select one or more objects, hold <b>%1</b> - for multiple selection, "
"<b>%2</b> - finish creation")
.arg(VModifierKey::Control(), VModifierKey::EnterKey());
SetToolButton<DialogInsertNode>(checked, Tool::InsertNode, "://cursor/insert_node_cursor.png", SetToolButton<DialogInsertNode>(checked, Tool::InsertNode, "://cursor/insert_node_cursor.png",
tr("Select an item to insert"), &MainWindow::ClosedDialogInsertNode); tooltip, &MainWindow::ClosedDialogInsertNode);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -449,7 +449,7 @@ QString DialogTool::GetNodeName(const VPieceNode &node, bool showPassmarkDetails
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogTool::NewNodeItem(QListWidget *listWidget, const VPieceNode &node, bool showPassmark) void DialogTool::NewNodeItem(QListWidget *listWidget, const VPieceNode &node, bool showPassmark, bool showExclusion)
{ {
SCASSERT(listWidget != nullptr); SCASSERT(listWidget != nullptr);
SCASSERT(node.GetId() > NULL_ID); SCASSERT(node.GetId() > NULL_ID);
@ -485,7 +485,7 @@ void DialogTool::NewNodeItem(QListWidget *listWidget, const VPieceNode &node, bo
if(canAddNewPoint) if(canAddNewPoint)
{ {
QListWidgetItem *item = new QListWidgetItem(name); QListWidgetItem *item = new QListWidgetItem(name);
item->setFont(NodeFont(item->font(), node.IsExcluded())); item->setFont(NodeFont(item->font(), showExclusion ? node.IsExcluded() : false));
item->setData(Qt::UserRole, QVariant::fromValue(node)); item->setData(Qt::UserRole, QVariant::fromValue(node));
listWidget->addItem(item); listWidget->addItem(item);
listWidget->setCurrentRow(listWidget->count()-1); listWidget->setCurrentRow(listWidget->count()-1);

View File

@ -214,7 +214,8 @@ protected:
virtual void SaveData() {} virtual void SaveData() {}
quint32 DNumber(const QString &baseName) const; quint32 DNumber(const QString &baseName) const;
QString GetNodeName(const VPieceNode &node, bool showPassmarkDetails = false) const; QString GetNodeName(const VPieceNode &node, bool showPassmarkDetails = false) const;
void NewNodeItem(QListWidget *listWidget, const VPieceNode &node, bool showPassmark = true); void NewNodeItem(QListWidget *listWidget, const VPieceNode &node, bool showPassmark = true,
bool showExclusion = true);
void InitNodeAngles(QComboBox *box); void InitNodeAngles(QComboBox *box);
private: private:

View File

@ -30,24 +30,24 @@
#include "ui_dialoginsertnode.h" #include "ui_dialoginsertnode.h"
#include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vcontainer.h"
#include <QMenu>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogInsertNode::DialogInsertNode(const VContainer *data, quint32 toolId, QWidget *parent) DialogInsertNode::DialogInsertNode(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent), : DialogTool(data, toolId, parent),
ui(new Ui::DialogInsertNode), ui(new Ui::DialogInsertNode)
m_node(),
m_flagItem(false),
m_flagError(false)
{ {
ui->setupUi(this); ui->setupUi(this);
InitOkCancel(ui); InitOkCancel(ui);
CheckPieces(); CheckPieces();
CheckItem();
connect(ui->comboBoxPiece, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]() connect(ui->comboBoxPiece, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
{ {
CheckPieces(); CheckPieces();
}); });
connect(ui->listWidget, &QListWidget::customContextMenuRequested, this, &DialogInsertNode::ShowContextMenu);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -96,73 +96,134 @@ void DialogInsertNode::SetPieceId(quint32 id)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPieceNode DialogInsertNode::GetNode() const QVector<VPieceNode> DialogInsertNode::GetNodes() const
{ {
return m_node; QVector<VPieceNode> nodes;
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
{
nodes.append(qvariant_cast<VPieceNode>(ui->listWidget->item(i)->data(Qt::UserRole)));
}
return nodes;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogInsertNode::SetNode(const VPieceNode &node) void DialogInsertNode::ShowDialog(bool click)
{ {
m_node = node; if (not click)
m_flagItem = true;
QString name = tr("Uknown");
try
{ {
name = data->GetGObject(m_node.GetId())->ObjectName(); if (m_nodes.isEmpty())
}
catch (const VExceptionBadId &)
{
m_flagItem = false;
// Broken id
}
ui->labelItemName->setText(name);
ui->labelItemName->setToolTip(name);
CheckItem();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogInsertNode::ChosenObject(quint32 id, const SceneObject &type)
{
if (not prepare)
{
VPieceNode node;
switch (type)
{ {
case SceneObject::Arc: return;
node = VPieceNode(id, Tool::NodeArc);
break;
case SceneObject::ElArc:
node = VPieceNode(id, Tool::NodeElArc);
break;
case SceneObject::Point:
node = VPieceNode(id, Tool::NodePoint);
break;
case SceneObject::Spline:
node = VPieceNode(id, Tool::NodeSpline);
break;
case SceneObject::SplinePath:
node = VPieceNode(id, Tool::NodeSplinePath);
break;
case (SceneObject::Line):
case (SceneObject::Detail):
case (SceneObject::Unknown):
default:
qDebug() << "Got wrong scene object. Ignore.";
return;
} }
node.SetExcluded(true); for (auto &node : m_nodes)
SetNode(node); {
NewNodeItem(ui->listWidget, node, false, false);
}
m_nodes.clear();
CheckNodes();
prepare = true; prepare = true;
this->setModal(true); setModal(true);
this->show(); emit ToolTip(QString());
show();
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogInsertNode::SelectedObject(bool selected, quint32 object, quint32 tool)
{
Q_UNUSED(tool)
if (prepare)
{
return;
}
auto nodeIterator = std::find_if(m_nodes.begin(), m_nodes.end(),
[object](const VPieceNode &node) { return node.GetId() == object; });
if (selected)
{
if (nodeIterator == m_nodes.cend())
{
GOType type = GOType::Unknown;
try
{
type = data->GetGObject(object)->getType();
}
catch (const VExceptionBadId &)
{
qDebug() << "Cannot find an object with id" << object;
return;
}
VPieceNode node;
switch (type)
{
case GOType::Arc:
node = VPieceNode(object, Tool::NodeArc);
break;
case GOType::EllipticalArc:
node = VPieceNode(object, Tool::NodeElArc);
break;
case GOType::Point:
node = VPieceNode(object, Tool::NodePoint);
break;
case GOType::Spline:
case GOType::CubicBezier:
node = VPieceNode(object, Tool::NodeSpline);
break;
case GOType::SplinePath:
case GOType::CubicBezierPath:
node = VPieceNode(object, Tool::NodeSplinePath);
break;
case GOType::Unknown:
case GOType::PlaceLabel:
default:
qDebug() << "Got unexpected object type. Ignore.";
return;
}
node.SetExcluded(true);
m_nodes.append(node);
}
}
else
{
if (nodeIterator != m_nodes.end())
{
m_nodes.erase(nodeIterator);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogInsertNode::ShowContextMenu(const QPoint &pos)
{
const int row = ui->listWidget->currentRow();
if (ui->listWidget->count() == 0 || row == -1 || row >= ui->listWidget->count())
{
return;
}
QScopedPointer<QMenu> menu(new QMenu());
QListWidgetItem *rowItem = ui->listWidget->item(row);
SCASSERT(rowItem != nullptr);
QAction *actionDelete = menu->addAction(QIcon::fromTheme(editDeleteIcon), tr("Delete"));
QAction *selectedAction = menu->exec(ui->listWidget->viewport()->mapToGlobal(pos));
if (selectedAction == actionDelete)
{
delete rowItem;
}
CheckNodes();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogInsertNode::CheckPieces() void DialogInsertNode::CheckPieces()
{ {
@ -182,10 +243,8 @@ void DialogInsertNode::CheckPieces()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogInsertNode::CheckItem() void DialogInsertNode::CheckNodes()
{ {
QColor color; m_flagNodes = ui->listWidget->count() > 0;
m_flagItem ? color = OkColor(this) : color = errorColor;
ChangeColor(ui->labelItem, color);
CheckState(); CheckState();
} }

View File

@ -50,31 +50,35 @@ public:
quint32 GetPieceId() const; quint32 GetPieceId() const;
void SetPieceId(quint32 id); void SetPieceId(quint32 id);
VPieceNode GetNode() const; QVector<VPieceNode> GetNodes() const;
void SetNode(const VPieceNode &node);
virtual void ShowDialog(bool click) override;
public slots: public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override; virtual void SelectedObject(bool selected, quint32 object, quint32 tool) override;
protected: protected:
virtual bool IsValid() const final; virtual bool IsValid() const final;
private slots:
void ShowContextMenu(const QPoint &pos);
private: private:
Q_DISABLE_COPY(DialogInsertNode) Q_DISABLE_COPY(DialogInsertNode)
Ui::DialogInsertNode *ui; Ui::DialogInsertNode *ui;
VPieceNode m_node; QVector<VPieceNode> m_nodes{};
bool m_flagItem; bool m_flagNodes{false};
bool m_flagError; bool m_flagError{false};
void CheckPieces(); void CheckPieces();
void CheckItem(); void CheckNodes();
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline bool DialogInsertNode::IsValid() const inline bool DialogInsertNode::IsValid() const
{ {
return m_flagItem && m_flagError; return m_flagNodes && m_flagError;
} }
#endif // DIALOGINSERTNODE_H #endif // DIALOGINSERTNODE_H

View File

@ -6,45 +6,34 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>244</width> <width>411</width>
<height>103</height> <height>399</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Insert node</string> <string>Insert nodes</string>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset resource="../../../vmisc/share/resources/icon.qrc"> <iconset resource="../../../../vmisc/share/resources/icon.qrc">
<normaloff>:/icon/64x64/icon64x64.png</normaloff>:/icon/64x64/icon64x64.png</iconset> <normaloff>:/icon/64x64/icon64x64.png</normaloff>:/icon/64x64/icon64x64.png</iconset>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
<item> <item>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy"> <property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum> <enum>QFormLayout::ExpandingFieldsGrow</enum>
</property> </property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="labelItem">
<property name="text">
<string>Item:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="labelItemName">
<property name="text">
<string notr="true">item name</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelPiece"> <widget class="QLabel" name="labelPiece">
<property name="text"> <property name="text">
<string>Piece:</string> <string>Piece:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="comboBoxPiece"/> <widget class="QComboBox" name="comboBoxPiece"/>
</item> </item>
</layout> </layout>
@ -62,7 +51,7 @@
</layout> </layout>
</widget> </widget>
<resources> <resources>
<include location="../../../vmisc/share/resources/icon.qrc"/> <include location="../../../../vmisc/share/resources/icon.qrc"/>
</resources> </resources>
<connections> <connections>
<connection> <connection>

View File

@ -502,14 +502,17 @@ QString VAbstractSpline::GetAliasSuffix() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VAbstractSpline::SetAliasSuffix(const QString &alias) void VAbstractSpline::SetAliasSuffix(QString alias)
{ {
QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(m_id); QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(m_id);
const QString oldAliasSuffix = curve->GetAliasSuffix(); const QString oldAliasSuffix = curve->GetAliasSuffix();
alias = alias.simplified().replace(QChar(QChar::Space), QChar('_'));
curve->SetAliasSuffix(alias); curve->SetAliasSuffix(alias);
if (alias.isEmpty() || VAbstractTool::data.IsUnique(curve->GetAlias())) QRegularExpression rx(NameRegExp());
if (alias.isEmpty() || (rx.match(curve->GetAlias()).hasMatch() && VAbstractTool::data.IsUnique(curve->GetAlias())))
{ {
QSharedPointer<VGObject> obj = qSharedPointerCast<VGObject>(curve); QSharedPointer<VGObject> obj = qSharedPointerCast<VGObject>(curve);
SaveOption(obj); SaveOption(obj);

View File

@ -97,7 +97,7 @@ public:
quint32 GetDuplicate() const; quint32 GetDuplicate() const;
QString GetAliasSuffix() const; QString GetAliasSuffix() const;
void SetAliasSuffix(const QString &alias); void SetAliasSuffix(QString alias);
virtual void GroupVisibility(quint32 object, bool visible) override; virtual void GroupVisibility(quint32 object, bool visible) override;
public slots: public slots:

View File

@ -42,6 +42,7 @@
#include "../../../../vabstracttool.h" #include "../../../../vabstracttool.h"
#include "../../../vdrawtool.h" #include "../../../vdrawtool.h"
#include "../vtoolsinglepoint.h" #include "../vtoolsinglepoint.h"
#include "../qmuparser/qmudef.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VToolCut::VToolCut(const VToolCutInitData &initData, QGraphicsItem *parent) VToolCut::VToolCut(const VToolCutInitData &initData, QGraphicsItem *parent)
@ -108,14 +109,17 @@ QString VToolCut::GetAliasSuffix1() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolCut::SetAliasSuffix1(const QString &alias) void VToolCut::SetAliasSuffix1(QString alias)
{ {
QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(baseCurveId); QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(baseCurveId);
const QString oldAliasSuffix = curve->GetAliasSuffix(); const QString oldAliasSuffix = curve->GetAliasSuffix();
alias = alias.simplified().replace(QChar(QChar::Space), QChar('_'));
curve->SetAliasSuffix(alias); curve->SetAliasSuffix(alias);
if (alias.isEmpty() || VAbstractTool::data.IsUnique(curve->GetAlias())) QRegularExpression rx(NameRegExp());
if (alias.isEmpty() || (rx.match(curve->GetAlias()).hasMatch() && VAbstractTool::data.IsUnique(curve->GetAlias())))
{ {
m_aliasSuffix1 = alias; m_aliasSuffix1 = alias;
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id); QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);
@ -134,14 +138,17 @@ QString VToolCut::GetAliasSuffix2() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolCut::SetAliasSuffix2(const QString &alias) void VToolCut::SetAliasSuffix2(QString alias)
{ {
QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(baseCurveId); QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(baseCurveId);
const QString oldAliasSuffix = curve->GetAliasSuffix(); const QString oldAliasSuffix = curve->GetAliasSuffix();
alias = alias.simplified().replace(QChar(QChar::Space), QChar('_'));
curve->SetAliasSuffix(alias); curve->SetAliasSuffix(alias);
if (alias.isEmpty() || VAbstractTool::data.IsUnique(curve->GetAlias())) QRegularExpression rx(NameRegExp());
if (alias.isEmpty() || (rx.match(curve->GetAlias()).hasMatch() && VAbstractTool::data.IsUnique(curve->GetAlias())))
{ {
m_aliasSuffix2 = alias; m_aliasSuffix2 = alias;
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id); QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);

View File

@ -69,10 +69,10 @@ public:
void SetFormulaLength(const VFormula &value); void SetFormulaLength(const VFormula &value);
QString GetAliasSuffix1() const; QString GetAliasSuffix1() const;
void SetAliasSuffix1(const QString &alias); void SetAliasSuffix1(QString alias);
QString GetAliasSuffix2() const; QString GetAliasSuffix2() const;
void SetAliasSuffix2(const QString &alias); void SetAliasSuffix2(QString alias);
QString CurveName() const; QString CurveName() const;

View File

@ -225,14 +225,14 @@ void VToolSeamAllowance::RemoveWithConfirm(bool ask)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::InsertNode(VPieceNode node, quint32 pieceId, VMainGraphicsScene *scene, void VToolSeamAllowance::InsertNode(const QVector<VPieceNode> &nodes, quint32 pieceId, VMainGraphicsScene *scene,
VContainer *data, VAbstractPattern *doc) VContainer *data, VAbstractPattern *doc)
{ {
SCASSERT(scene != nullptr) SCASSERT(scene != nullptr)
SCASSERT(data != nullptr) SCASSERT(data != nullptr)
SCASSERT(doc != nullptr) SCASSERT(doc != nullptr)
if (pieceId > NULL_ID) if (pieceId > NULL_ID && not nodes.isEmpty())
{ {
VPiece oldDet; VPiece oldDet;
try try
@ -246,21 +246,24 @@ void VToolSeamAllowance::InsertNode(VPieceNode node, quint32 pieceId, VMainGraph
VPiece newDet = oldDet; VPiece newDet = oldDet;
const quint32 id = PrepareNode(node, scene, doc, data); for (auto node : nodes)
if (id == NULL_ID)
{ {
return; const quint32 id = PrepareNode(node, scene, doc, data);
if (id == NULL_ID)
{
return;
}
node.SetId(id);
newDet.GetPath().Append(node);
// Seam allowance tool already initializated and can't init the node
VToolSeamAllowance *saTool = qobject_cast<VToolSeamAllowance*>(VAbstractPattern::getTool(pieceId));
SCASSERT(saTool != nullptr);
InitNode(node, scene, data, doc, saTool);
} }
node.SetId(id);
newDet.GetPath().Append(node);
// Seam allowance tool already initializated and can't init the node
VToolSeamAllowance *saTool = qobject_cast<VToolSeamAllowance*>(VAbstractPattern::getTool(pieceId));
SCASSERT(saTool != nullptr);
InitNode(node, scene, data, doc, saTool);
qApp->getUndoStack()->push(new SavePieceOptions(oldDet, newDet, doc, pieceId)); qApp->getUndoStack()->push(new SavePieceOptions(oldDet, newDet, doc, pieceId));
} }
} }

View File

@ -91,8 +91,8 @@ public:
void RemoveWithConfirm(bool ask); void RemoveWithConfirm(bool ask);
static void InsertNode(VPieceNode node, quint32 pieceId, VMainGraphicsScene *scene, VContainer *data, static void InsertNode(const QVector<VPieceNode> &nodes, quint32 pieceId, VMainGraphicsScene *scene,
VAbstractPattern *doc); VContainer *data, VAbstractPattern *doc);
static void AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece); static void AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece);
static void AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, CustomSARecord record); static void AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, CustomSARecord record);