Seamly2D
Code documentation
vabstractoperation.h
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 12 9, 2016
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2016 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #ifndef VABSTRACTOPERATION_H
53 #define VABSTRACTOPERATION_H
54 
55 #include <QtGlobal>
56 #include <qcompilerdetection.h>
57 #include <QMap>
58 #include <QMetaObject>
59 #include <QObject>
60 #include <QString>
61 #include <QVector>
62 #include <QGraphicsLineItem>
63 
64 #include "../vdrawtool.h"
65 #include "../vwidgets/vsimplecurve.h"
66 #include "../vwidgets/vsimplepoint.h"
67 
68 struct SourceItem
69 {
70  quint32 id{NULL_ID};
71  QString alias{QString()};
72  QString lineType{"solidLine"};
73  QString lineWidth{"1.00"};
74  QString color{"black"};
75 };
76 
77 Q_DECLARE_METATYPE(SourceItem)
78 Q_DECLARE_TYPEINFO(SourceItem, Q_MOVABLE_TYPE);
79 
80 QVector<quint32> sourceToObjects(const QVector<SourceItem> &source);
81 
83 {
84  quint32 id{0};
85  qreal mx{1};
86  qreal my{1};
87  bool showPointName{true};
88 };
89 
90 // FIXME. I don't know how to use QGraphicsItem properly, so just took first available finished class.
91 // QGraphicsItem itself produce case where clicking on empty space produce call to QGraphicsItem.
92 // And i don't know how to fix it.
93 class VAbstractOperation : public VDrawTool, public QGraphicsLineItem
94 {
95  Q_OBJECT
96  // Fix warning "Class implements the interface QGraphicsItem but does not list it
97  // in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!"
98  Q_INTERFACES(QGraphicsItem)
99 
100 public:
101  virtual ~VAbstractOperation() Q_DECL_EQ_DEFAULT;
102 
103  static const QString TagItem;
104  static const QString TagSource;
105  static const QString TagDestination;
106 
107  virtual QString getTagName() const Q_DECL_OVERRIDE;
108 
109  QString Suffix() const;
110  void setSuffix(const QString &suffix);
111 
112  virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE;
113  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
114 
115  virtual bool isPointNameVisible(quint32 id) const Q_DECL_OVERRIDE;
116  virtual void setPointNameVisiblity(quint32 id, bool visible) Q_DECL_OVERRIDE;
117 
118  virtual void setPointNamePosition(quint32 id, const QPointF &pos) Q_DECL_OVERRIDE;
119 
120  static void ExtractData(const QDomElement &domElement, QVector<SourceItem> &source,
122 
123 public slots:
124  virtual void FullUpdateFromFile() Q_DECL_OVERRIDE;
125 
126  virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE;
127  virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE;
128  virtual void EnableToolMove(bool move) Q_DECL_OVERRIDE;
129 
130  void AllowPointHover(bool enabled);
131  void AllowPointSelecting(bool enabled);
132 
133  void AllowPointLabelHover(bool enabled);
134  void AllowPointLabelSelecting(bool enabled);
135 
136  void AllowSplineHover(bool enabled);
137  void AllowSplineSelecting(bool enabled);
138 
139  void AllowSplinePathHover(bool enabled);
140  void AllowSplinePathSelecting(bool enabled);
141 
142  void AllowArcHover(bool enabled);
143  void AllowArcSelecting(bool enabled);
144 
145  void AllowElArcHover(bool enabled);
146  void AllowElArcSelecting(bool enabled);
147 
148  virtual void ToolSelectionType(const SelectionType &type) Q_DECL_OVERRIDE;
149  virtual void Disable(bool disable, const QString &draftBlockName) Q_DECL_OVERRIDE;
150  void ObjectSelected(bool selected, quint32 objId);
151  void deletePoint();
152  void pointNamePositionChanged(const QPointF &pos, quint32 labelId);
153  virtual void updatePointNameVisibility(quint32 id, bool visible) Q_DECL_OVERRIDE;
154 
155 
156 protected:
157  QString suffix;
161 
163  const QString &suffix, const QVector<SourceItem> &source,
165  QGraphicsItem *parent = nullptr);
166 
167  virtual void AddToFile() Q_DECL_OVERRIDE;
168  virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE;
169  virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) Q_DECL_OVERRIDE;
170 
171 
172  //virtual void updatePointNameVisibility(quint32 id, bool visible) Q_DECL_OVERRIDE;
173  void updatePointNamePosition(quint32 id, const QPointF &pos);
174 
175  void SaveSourceDestination(QDomElement &tag);
176 
177  template <typename T>
178  void ShowToolVisualization(bool show);
179 
180  void InitCurve(quint32 id, VContainer *data, GOType curveType, SceneObject sceneType);
181 
182  template <typename T>
183  static void initOperationToolConnections(VMainGraphicsScene *scene, T *tool);
184 
185  void InitOperatedObjects();
186  QString complexPointToolTip(quint32 itemId) const;
187  QString complexCurveToolTip(quint32 itemId) const;
188 
189 private:
190  Q_DISABLE_COPY(VAbstractOperation)
191 
192  void AllowCurveHover(bool enabled, GOType type);
193  void AllowCurveSelecting(bool enabled, GOType type);
194 };
195 
196 //---------------------------------------------------------------------------------------------------------------------
197 template <typename T>
199 {
200  if (show)
201  {
202  if (vis.isNull())
203  {
204  AddVisualization<T>();
206  }
207  else
208  {
209  if (T *visual = qobject_cast<T *>(vis))
210  {
211  visual->show();
212  }
213  }
214  }
215  else
216  {
217  delete vis;
218  }
219 }
220 
221 //---------------------------------------------------------------------------------------------------------------------
222 template <typename T>
224 {
225  SCASSERT(scene != nullptr)
226  SCASSERT(tool != nullptr)
227 
228  InitDrawToolConnections(scene, tool);
229 
230  QObject::connect(scene, &VMainGraphicsScene::EnablePointItemHover, tool, &T::AllowPointHover);
231  QObject::connect(scene, &VMainGraphicsScene::EnablePointItemSelection, tool, &T::AllowPointSelecting);
232  QObject::connect(scene, &VMainGraphicsScene::enableTextItemHover, tool, &T::AllowPointLabelHover);
233  QObject::connect(scene, &VMainGraphicsScene::enableTextItemSelection, tool, &T::AllowPointLabelSelecting);
234 
235  QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemHover, tool, &T::AllowSplineHover);
236  QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemSelection, tool, &T::AllowSplineSelecting);
237 
238  QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemHover, tool, &T::AllowSplinePathHover);
239  QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemSelection, tool, &T::AllowSplinePathSelecting);
240 
241  QObject::connect(scene, &VMainGraphicsScene::EnableArcItemHover, tool, &T::AllowArcHover);
242  QObject::connect(scene, &VMainGraphicsScene::EnableArcItemSelection, tool, &T::AllowArcSelecting);
243 
244  QObject::connect(scene, &VMainGraphicsScene::EnableElArcItemHover, tool, &T::AllowElArcHover);
245  QObject::connect(scene, &VMainGraphicsScene::EnableElArcItemSelection, tool, &T::AllowElArcSelecting);
246 }
247 
248 #endif // VABSTRACTOPERATION_H
void AllowArcSelecting(bool enabled)
virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE
virtual void FullUpdateFromFile() Q_DECL_OVERRIDE
virtual void SaveOptions(QDomElement &tag, QSharedPointer< VGObject > &obj) Q_DECL_OVERRIDE
virtual void ToolSelectionType(const SelectionType &type) Q_DECL_OVERRIDE
virtual ~VAbstractOperation() Q_DECL_EQ_DEFAULT
QMap< quint32, VAbstractSimple * > operatedObjects
void updatePointNamePosition(quint32 id, const QPointF &pos)
virtual void setPointNamePosition(quint32 id, const QPointF &pos) Q_DECL_OVERRIDE
void AllowElArcSelecting(bool enabled)
QVector< SourceItem > source
virtual void AddToFile() Q_DECL_OVERRIDE
AddToFile add tag with Information about tool into file.
static const QString TagDestination
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE
void pointNamePositionChanged(const QPointF &pos, quint32 labelId)
void AllowArcHover(bool enabled)
static void initOperationToolConnections(VMainGraphicsScene *scene, T *tool)
static const QString TagItem
void SaveSourceDestination(QDomElement &tag)
QString Suffix() const
void AllowPointLabelSelecting(bool enabled)
void AllowPointSelecting(bool enabled)
static void ExtractData(const QDomElement &domElement, QVector< SourceItem > &source, QVector< DestinationItem > &destination)
void AllowCurveSelecting(bool enabled, GOType type)
virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE
virtual void Disable(bool disable, const QString &draftBlockName) Q_DECL_OVERRIDE
void ObjectSelected(bool selected, quint32 objId)
void ShowToolVisualization(bool show)
void AllowSplinePathHover(bool enabled)
virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE
void setSuffix(const QString &suffix)
void AllowPointLabelHover(bool enabled)
virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE
void AllowSplineHover(bool enabled)
QString complexPointToolTip(quint32 itemId) const
void AllowPointHover(bool enabled)
virtual void EnableToolMove(bool move) Q_DECL_OVERRIDE
QVector< DestinationItem > destination
static const QString TagSource
virtual void setPointNameVisiblity(quint32 id, bool visible) Q_DECL_OVERRIDE
void AllowSplinePathSelecting(bool enabled)
virtual void updatePointNameVisibility(quint32 id, bool visible) Q_DECL_OVERRIDE
virtual bool isPointNameVisible(quint32 id) const Q_DECL_OVERRIDE
QString complexCurveToolTip(quint32 itemId) const
void AllowCurveHover(bool enabled, GOType type)
virtual QString getTagName() const Q_DECL_OVERRIDE
void AllowSplineSelecting(bool enabled)
void InitCurve(quint32 id, VContainer *data, GOType curveType, SceneObject sceneType)
void AllowElArcHover(bool enabled)
VAbstractPattern * doc
doc dom document container
QPointer< Visualization > vis
virtual void SetVisualization()=0
The VContainer class container of all variables.
Definition: vcontainer.h:141
VContainer data
data container with data
Definition: vdatatool.h:84
The VDrawTool abstract class for all draw tool.
Definition: vdrawtool.h:68
static void InitDrawToolConnections(VMainGraphicsScene *scene, T *tool)
Definition: vdrawtool.h:364
The VGObject class keep information graphical objects.
Definition: vgobject.h:74
The VMainGraphicsScene class main scene.
void EnableSplinePathItemHover(bool enable)
void EnableArcItemHover(bool enable)
void EnablePointItemSelection(bool enable)
void EnableElArcItemHover(bool enable)
void enableTextItemSelection(bool enable)
void EnableSplineItemSelection(bool enable)
void EnablePointItemHover(bool enable)
void EnableArcItemSelection(bool enable)
void enableTextItemHover(bool enable)
void EnableElArcItemSelection(bool enable)
void EnableSplineItemHover(bool enable)
void EnableSplinePathItemSelection(bool enable)
#define SCASSERT(cond)
Definition: def.h:317
SceneObject
Definition: def.h:103
SelectionType
Definition: def.h:108
#define NULL_ID
Definition: ifcdef.h:76
QVector< quint32 > sourceToObjects(const QVector< SourceItem > &source)
Q_DECLARE_TYPEINFO(SourceItem, Q_MOVABLE_TYPE)
GOType
Definition: vgeometrydef.h:56