Fixed issue #914. Filtering custom seam allowance paths prevent including more

than one.

--HG--
branch : release
This commit is contained in:
Roman Telezhynskyi 2018-12-21 13:01:32 +02:00
parent b36e4e2cf8
commit 940d0be073
9 changed files with 124 additions and 54 deletions

View File

@ -4,6 +4,7 @@
- [#909] Valentina produces wrong united path. - [#909] Valentina produces wrong united path.
- [#912] Labels in inactive state return to initial color. - [#912] Labels in inactive state return to initial color.
- [#913] Unable to save changes for piece path if it doesn't contain a point. - [#913] Unable to save changes for piece path if it doesn't contain a point.
- [#914] Filtering custom seam allowance paths prevent including more than one.
# Version 0.6.1 October 23, 2018 # Version 0.6.1 October 23, 2018
- [#885] Regression. Broken support for multi size measurements. - [#885] Regression. Broken support for multi size measurements.

View File

@ -54,6 +54,8 @@ int main(int argc, char *argv[])
// Need to internally move a node inside a piece main path // Need to internally move a node inside a piece main path
qRegisterMetaTypeStreamOperators<VPieceNode>("VPieceNode"); qRegisterMetaTypeStreamOperators<VPieceNode>("VPieceNode");
// Need to internally move a node inside a custom seam allowance path
qRegisterMetaTypeStreamOperators<CustomSARecord>("CustomSARecord");
#ifndef Q_OS_MAC // supports natively #ifndef Q_OS_MAC // supports natively
InitHighDpiScaling(argc, argv); InitHighDpiScaling(argc, argv);

View File

@ -56,6 +56,7 @@
#include <QGlobalStatic> #include <QGlobalStatic>
#include "vabstractapplication.h" #include "vabstractapplication.h"
#include "vdatastreamenum.h"
const qreal defCurveApproximationScale = 0.5; const qreal defCurveApproximationScale = 0.5;
const qreal minCurveApproximationScale = 0.1; const qreal minCurveApproximationScale = 0.1;
@ -844,3 +845,26 @@ void InitLanguages(QComboBox *combobox)
combobox->setCurrentIndex(index); combobox->setCurrentIndex(index);
} }
} }
// Friend functions
//---------------------------------------------------------------------------------------------------------------------
QDataStream &operator<<(QDataStream &out, const CustomSARecord &record)
{
out << record.startPoint;
out << record.path;
out << record.endPoint;
out << record.reverse;
out << record.includeType;
return out;
}
//---------------------------------------------------------------------------------------------------------------------
QDataStream &operator>>(QDataStream &in, CustomSARecord &record)
{
in >> record.startPoint;
in >> record.path;
in >> record.endPoint;
in >> record.reverse;
in >> record.includeType;
return in;
}

View File

@ -485,6 +485,9 @@ struct CustomSARecord
includeType(PiecePathIncludeType::AsCustomSA) includeType(PiecePathIncludeType::AsCustomSA)
{} {}
friend QDataStream& operator<<(QDataStream& out, const CustomSARecord& record);
friend QDataStream& operator>>(QDataStream& in, CustomSARecord& record);
quint32 startPoint; quint32 startPoint;
quint32 path; quint32 path;
quint32 endPoint; quint32 endPoint;

View File

@ -0,0 +1,59 @@
/************************************************************************
**
** @file vdatastreamenum.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 21 12, 2018
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2015 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 DATASTREAM_ENUM_H
#define DATASTREAM_ENUM_H
#include <QDataStream>
#include <type_traits>
// (de)serialize enums into QDataStream
//a function that can serialize any enum into QDataStream
//it stores the enum in a qint64
template<typename Enum,
typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
QDataStream& operator<<(QDataStream& stream, const Enum& e)
{
stream << static_cast<qint64>(e);
return stream;
}
//a function that can deserialize any enum from QDataStream
//it reads the enum as if it was stored in qint64
template<typename Enum,
typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
QDataStream& operator>>(QDataStream& stream, Enum& e)
{
qint64 v;
stream >> v;
e = static_cast<Enum>(v);
return stream;
}
#endif // DATASTREAM_ENUM_H

View File

@ -39,7 +39,8 @@ HEADERS += \
$$PWD/backport/qoverload.h \ $$PWD/backport/qoverload.h \
$$PWD/testvapplication.h \ $$PWD/testvapplication.h \
$$PWD/literals.h \ $$PWD/literals.h \
$$PWD/qt_dispatch/qt_dispatch.h $$PWD/qt_dispatch/qt_dispatch.h \
$$PWD/vdatastreamenum.h
# Qt's versions # Qt's versions
# 5.2.0, 5.2.1 # 5.2.0, 5.2.1

View File

@ -1004,48 +1004,35 @@ QVector<CustomSARecord> VPiece::FilterRecords(QVector<CustomSARecord> records) c
return records; return records;
} }
// cppcheck-suppress variableScope QVector<VPieceNode> path = d->m_path.GetNodes();
bool foundFilter = false;// Need in case "filter" will stay empty. QVector<CustomSARecord> filteredRecords;
CustomSARecord filter; for (auto record : qAsConst(records))
int startIndex = d->m_path.CountNodes()-1;
for (int i = 0; i < records.size(); ++i)
{ {
const int indexStartPoint = d->m_path.indexOfNode(records.at(i).startPoint); const int indexStartPoint = VPiecePath::indexOfNode(path, record.startPoint);
if (indexStartPoint < startIndex) const int indexEndPoint = VPiecePath::indexOfNode(path, record.endPoint);
if (indexStartPoint == -1 || indexEndPoint == -1)
{ {
startIndex = i; continue;
filter = records.at(i);
// cppcheck-suppress unreadVariable
foundFilter = true;
} }
}
if (not foundFilter) QVector<VPieceNode> midBefore;
{ QVector<VPieceNode> midAfter;
return records; // return as is if (indexStartPoint <= indexEndPoint)
}
records.remove(startIndex);
QVector<CustomSARecord> secondRound;
secondRound.reserve(records.size());
for (auto &record : records)
{
const int indexStartPoint = d->m_path.indexOfNode(record.startPoint);
const int indexEndPoint = d->m_path.indexOfNode(filter.endPoint);
if (indexStartPoint > indexEndPoint)
{ {
secondRound.append(record); midBefore = path.mid(0, indexStartPoint+1);
midAfter = path.mid(indexEndPoint, path.size() - midBefore.size());
} }
else
{
midBefore = path.mid(indexEndPoint, indexStartPoint+1);
}
path = midBefore + midAfter;
filteredRecords.append(record);
} }
QVector<CustomSARecord> filtered; return filteredRecords;
filtered.append(filter);
filtered += FilterRecords(secondRound);
return filtered;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -33,6 +33,7 @@
#include <QDataStream> #include <QDataStream>
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#include "../vmisc/diagnostic.h" #include "../vmisc/diagnostic.h"
#include "../vmisc/vdatastreamenum.h"
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Weffc++") QT_WARNING_DISABLE_GCC("-Weffc++")
@ -143,15 +144,15 @@ private:
QDataStream &operator<<(QDataStream &out, const VPieceNodeData &p) QDataStream &operator<<(QDataStream &out, const VPieceNodeData &p)
{ {
out << p.m_id out << p.m_id
<< static_cast<int>(p.m_typeTool) << p.m_typeTool
<< p.m_reverse << p.m_reverse
<< p.m_excluded << p.m_excluded
<< p.m_isPassmark << p.m_isPassmark
<< p.m_formulaWidthBefore << p.m_formulaWidthBefore
<< p.m_formulaWidthAfter << p.m_formulaWidthAfter
<< static_cast<int>(p.m_angleType) << p.m_angleType
<< static_cast<int>(p.m_passmarkLineType) << p.m_passmarkLineType
<< static_cast<int>(p.m_passmarkAngleType) << p.m_passmarkAngleType
<< p.m_isShowSecondPassmark; << p.m_isShowSecondPassmark;
return out; return out;
} }
@ -159,28 +160,17 @@ QDataStream &operator<<(QDataStream &out, const VPieceNodeData &p)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QDataStream &operator>>(QDataStream &in, VPieceNodeData &p) QDataStream &operator>>(QDataStream &in, VPieceNodeData &p)
{ {
int typeTool = 0;
int angleType = 0;
int passmarkLineType = 0;
int passmarkAngleType = 0;
in >> p.m_id in >> p.m_id
>> typeTool >> p.m_typeTool
>> p.m_reverse >> p.m_reverse
>> p.m_excluded >> p.m_excluded
>> p.m_isPassmark >> p.m_isPassmark
>> p.m_formulaWidthBefore >> p.m_formulaWidthBefore
>> p.m_formulaWidthAfter >> p.m_formulaWidthAfter
>> angleType >> p.m_angleType
>> passmarkLineType >> p.m_passmarkLineType
>> passmarkAngleType >> p.m_passmarkAngleType
>> p.m_isShowSecondPassmark; >> p.m_isShowSecondPassmark;
p.m_typeTool = static_cast<Tool>(typeTool);
p.m_angleType = static_cast<PieceNodeAngle>(angleType);
p.m_passmarkLineType = static_cast<PassmarkLineType>(passmarkLineType);
p.m_passmarkAngleType = static_cast<PassmarkAngleType>(passmarkAngleType);
return in; return in;
} }

View File

@ -1015,6 +1015,9 @@
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
</widget> </widget>
</widget> </widget>
</item> </item>