1 /************************************************************************
2 **
3 ** @file toolsdef.cpp
4 ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5 ** @date 6 11, 2020
6 **
7 ** @brief
8 ** @copyright
9 ** This source code is part of the Valentina project, a pattern making
10 ** program, whose allow create and modeling patterns of clothing.
11 ** Copyright (C) 2020 Valentina project
12 ** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13 **
14 ** Valentina is free software: you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License as published by
16 ** the Free Software Foundation, either version 3 of the License, or
17 ** (at your option) any later version.
18 **
19 ** Valentina is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ** GNU General Public License for more details.
23 **
24 ** You should have received a copy of the GNU General Public License
25 ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
26 **
27 *************************************************************************/
28
29 #include "toolsdef.h"
30
31 #include <QBrush>
32 #include <QIcon>
33 #include <QPainter>
34 #include <QPen>
35 #include <QPixmap>
36 #include <QRegularExpression>
37 #include <QVector>
38
39 #include "../vgeometry/vgobject.h"
40 #include "../qmuparser/qmudef.h"
41 #include "../vpatterndb/vcontainer.h"
42
43 //---------------------------------------------------------------------------------------------------------------------
SourceToObjects(const QVector<SourceItem> & source)44 QVector<quint32> SourceToObjects(const QVector<SourceItem> &source)
45 {
46 QVector<quint32> ids;
47 ids.reserve(source.size());
48
49 for (auto s: source)
50 {
51 ids.append(s.id);
52 }
53
54 return ids;
55 }
56
57 //---------------------------------------------------------------------------------------------------------------------
SourceAliasValid(const SourceItem & item,const QSharedPointer<VGObject> & obj,const VContainer * data,const QString & originAlias)58 bool SourceAliasValid(const SourceItem &item, const QSharedPointer<VGObject> &obj, const VContainer *data,
59 const QString &originAlias)
60 {
61 SCASSERT(data != nullptr)
62
63 QRegularExpression rx(NameRegExp());
64
65 QString alias;
66
67 if (obj->getType() == GOType::Point)
68 {
69 alias = item.alias;
70 }
71 else
72 {
73 const QString oldAlias = obj->GetAliasSuffix();
74 obj->SetAliasSuffix(item.alias);
75 alias = obj->GetAlias();
76 obj->SetAliasSuffix(oldAlias);
77 }
78
79 if (not alias.isEmpty() && originAlias != alias &&
80 (not rx.match(alias).hasMatch() || not data->IsUnique(alias)))
81 {
82 return false;
83 }
84
85 return true;
86 }
87
88 //---------------------------------------------------------------------------------------------------------------------
OriginAlias(quint32 id,const QVector<SourceItem> & source,const QSharedPointer<VGObject> & obj)89 QString OriginAlias(quint32 id, const QVector<SourceItem> &source, const QSharedPointer<VGObject> &obj)
90 {
91 auto item = std::find_if(source.begin(), source.end(),
92 [id](const SourceItem &sItem) { return sItem.id == id; });
93 if (item != source.end())
94 {
95 if (obj->getType() == GOType::Point)
96 {
97 return item->alias;
98 }
99 else
100 {
101 const QString oldAlias = obj->GetAliasSuffix();
102 obj->SetAliasSuffix(item->alias);
103 QString alias = obj->GetAlias();
104 obj->SetAliasSuffix(oldAlias);
105 return alias;
106 }
107 }
108
109 return QString();
110 }
111
112 //---------------------------------------------------------------------------------------------------------------------
OperationLineStylesPics()113 QMap<QString, QIcon> OperationLineStylesPics()
114 {
115 QMap<QString, QIcon> map = LineStylesPics();
116 map.insert(TypeLineDefault, QIcon());
117 return map;
118 }
119