diff --git a/ChangeLog.txt b/ChangeLog.txt index b13fd9bae..acfa3af26 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -4,6 +4,7 @@ - [#909] Valentina produces wrong united path. - [#912] Labels in inactive state return to initial color. - [#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 - [#885] Regression. Broken support for multi size measurements. diff --git a/src/app/valentina/main.cpp b/src/app/valentina/main.cpp index b5aaa90e0..5ecebf869 100644 --- a/src/app/valentina/main.cpp +++ b/src/app/valentina/main.cpp @@ -54,6 +54,8 @@ int main(int argc, char *argv[]) // Need to internally move a node inside a piece main path qRegisterMetaTypeStreamOperators("VPieceNode"); + // Need to internally move a node inside a custom seam allowance path + qRegisterMetaTypeStreamOperators("CustomSARecord"); #ifndef Q_OS_MAC // supports natively InitHighDpiScaling(argc, argv); diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 0cd21827e..759f44d5a 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -56,6 +56,7 @@ #include #include "vabstractapplication.h" +#include "vdatastreamenum.h" const qreal defCurveApproximationScale = 0.5; const qreal minCurveApproximationScale = 0.1; @@ -844,3 +845,26 @@ void InitLanguages(QComboBox *combobox) 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; +} diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 2247993c6..fd8cef62b 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -485,6 +485,9 @@ struct CustomSARecord includeType(PiecePathIncludeType::AsCustomSA) {} + friend QDataStream& operator<<(QDataStream& out, const CustomSARecord& record); + friend QDataStream& operator>>(QDataStream& in, CustomSARecord& record); + quint32 startPoint; quint32 path; quint32 endPoint; diff --git a/src/libs/vmisc/vdatastreamenum.h b/src/libs/vmisc/vdatastreamenum.h new file mode 100644 index 000000000..b158e80b2 --- /dev/null +++ b/src/libs/vmisc/vdatastreamenum.h @@ -0,0 +1,59 @@ +/************************************************************************ + ** + ** @file vdatastreamenum.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 DATASTREAM_ENUM_H +#define DATASTREAM_ENUM_H + +#include +#include + +// (de)serialize enums into QDataStream + +//a function that can serialize any enum into QDataStream +//it stores the enum in a qint64 +template::value>::type> +QDataStream& operator<<(QDataStream& stream, const Enum& e) +{ + stream << static_cast(e); + return stream; +} + +//a function that can deserialize any enum from QDataStream +//it reads the enum as if it was stored in qint64 +template::value>::type> +QDataStream& operator>>(QDataStream& stream, Enum& e) +{ + qint64 v; + stream >> v; + e = static_cast(v); + return stream; +} + +#endif // DATASTREAM_ENUM_H diff --git a/src/libs/vmisc/vmisc.pri b/src/libs/vmisc/vmisc.pri index 338fb0990..824f99929 100644 --- a/src/libs/vmisc/vmisc.pri +++ b/src/libs/vmisc/vmisc.pri @@ -39,7 +39,8 @@ HEADERS += \ $$PWD/backport/qoverload.h \ $$PWD/testvapplication.h \ $$PWD/literals.h \ - $$PWD/qt_dispatch/qt_dispatch.h + $$PWD/qt_dispatch/qt_dispatch.h \ + $$PWD/vdatastreamenum.h # Qt's versions # 5.2.0, 5.2.1 diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 9038fa05e..1523a9a63 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -1004,48 +1004,35 @@ QVector VPiece::FilterRecords(QVector records) c return records; } - // cppcheck-suppress variableScope - bool foundFilter = false;// Need in case "filter" will stay empty. - CustomSARecord filter; - int startIndex = d->m_path.CountNodes()-1; - - for (int i = 0; i < records.size(); ++i) + QVector path = d->m_path.GetNodes(); + QVector filteredRecords; + for (auto record : qAsConst(records)) { - const int indexStartPoint = d->m_path.indexOfNode(records.at(i).startPoint); - if (indexStartPoint < startIndex) + const int indexStartPoint = VPiecePath::indexOfNode(path, record.startPoint); + const int indexEndPoint = VPiecePath::indexOfNode(path, record.endPoint); + + if (indexStartPoint == -1 || indexEndPoint == -1) { - startIndex = i; - filter = records.at(i); - // cppcheck-suppress unreadVariable - foundFilter = true; + continue; } - } - if (not foundFilter) - { - return records; // return as is - } - - records.remove(startIndex); - - QVector 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) + QVector midBefore; + QVector midAfter; + 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 filtered; - filtered.append(filter); - - filtered += FilterRecords(secondRound); - - return filtered; + return filteredRecords; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vpiecenode_p.h b/src/libs/vpatterndb/vpiecenode_p.h index d6cd6e3c6..30c655413 100644 --- a/src/libs/vpatterndb/vpiecenode_p.h +++ b/src/libs/vpatterndb/vpiecenode_p.h @@ -33,6 +33,7 @@ #include #include "../ifc/ifcdef.h" #include "../vmisc/diagnostic.h" +#include "../vmisc/vdatastreamenum.h" QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Weffc++") @@ -143,15 +144,15 @@ private: QDataStream &operator<<(QDataStream &out, const VPieceNodeData &p) { out << p.m_id - << static_cast(p.m_typeTool) + << p.m_typeTool << p.m_reverse << p.m_excluded << p.m_isPassmark << p.m_formulaWidthBefore << p.m_formulaWidthAfter - << static_cast(p.m_angleType) - << static_cast(p.m_passmarkLineType) - << static_cast(p.m_passmarkAngleType) + << p.m_angleType + << p.m_passmarkLineType + << p.m_passmarkAngleType << p.m_isShowSecondPassmark; return out; } @@ -159,28 +160,17 @@ QDataStream &operator<<(QDataStream &out, const VPieceNodeData &p) //--------------------------------------------------------------------------------------------------------------------- QDataStream &operator>>(QDataStream &in, VPieceNodeData &p) { - int typeTool = 0; - int angleType = 0; - int passmarkLineType = 0; - int passmarkAngleType = 0; - in >> p.m_id - >> typeTool + >> p.m_typeTool >> p.m_reverse >> p.m_excluded >> p.m_isPassmark >> p.m_formulaWidthBefore >> p.m_formulaWidthAfter - >> angleType - >> passmarkLineType - >> passmarkAngleType + >> p.m_angleType + >> p.m_passmarkLineType + >> p.m_passmarkAngleType >> p.m_isShowSecondPassmark; - - p.m_typeTool = static_cast(typeTool); - p.m_angleType = static_cast(angleType); - p.m_passmarkLineType = static_cast(passmarkLineType); - p.m_passmarkAngleType = static_cast(passmarkAngleType); - return in; } diff --git a/src/libs/vtools/dialogs/tools/piece/tabs/tabpaths.ui b/src/libs/vtools/dialogs/tools/piece/tabs/tabpaths.ui index 016ddaa98..930d7a442 100644 --- a/src/libs/vtools/dialogs/tools/piece/tabs/tabpaths.ui +++ b/src/libs/vtools/dialogs/tools/piece/tabs/tabpaths.ui @@ -1015,6 +1015,9 @@ 0 + + QAbstractItemView::InternalMove +