Seamly2D
Code documentation
vabstractpoint.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 vabstractpoint.h
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 19 6, 2015
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) 2015 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 VABSTRACTPOINT_H
53 #define VABSTRACTPOINT_H
54 
55 #include <qcompilerdetection.h>
56 #include <QColor>
57 #include <QMetaObject>
58 #include <QObject>
59 #include <QPen>
60 #include <QPointF>
61 #include <QString>
62 #include <Qt>
63 #include <QtGlobal>
64 
65 #include "../vdrawtool.h"
66 #include "../ifc/ifcdef.h"
67 #include "../vgeometry/vpointf.h"
68 #include "../vmisc/vabstractapplication.h"
69 #include "../vpatterndb/vcontainer.h"
70 #include "../vmisc/def.h"
71 #include "../vwidgets/vmaingraphicsscene.h"
72 #include "../../../visualization/visualization.h"
73 #include "../../vabstracttool.h"
74 
76 {
77  Q_OBJECT
78 public:
80  virtual ~VAbstractPoint() Q_DECL_EQ_DEFAULT;
81 
82  virtual QString getTagName() const Q_DECL_OVERRIDE;
83 
84  template <typename T>
85  void ShowToolVisualization(bool show);
86 
87 public slots:
88  virtual void ShowTool(quint32 id, bool enable) Q_DECL_OVERRIDE;
89  void deletePoint();
90 
91 protected:
92  void SetPointName(quint32 id, const QString &name);
93  virtual void updatePointNamePosition(quint32 id, const QPointF &pos)=0;
94 
95 
96  template <typename T>
97  static void InitToolConnections(VMainGraphicsScene *scene, T *tool);
98 
99 private:
100  Q_DISABLE_COPY(VAbstractPoint)
101 };
102 
103 //---------------------------------------------------------------------------------------------------------------------
104 template <typename T>
106 {
107  if (show)
108  {
109  if (vis.isNull())
110  {
111  AddVisualization<T>();
113  }
114  else
115  {
116  if (T *visual = qobject_cast<T *>(vis))
117  {
118  visual->show();
119  }
120  }
121  }
122  else
123  {
124  delete vis;
125  }
126 }
127 
128 //---------------------------------------------------------------------------------------------------------------------
129 template <typename T>
131 {
132  SCASSERT(scene != nullptr)
133  SCASSERT(tool != nullptr)
134 
135  InitDrawToolConnections(scene, tool);
136  QObject::connect(scene, &VMainGraphicsScene::EnablePointItemHover, tool, &T::AllowHover);
137  QObject::connect(scene, &VMainGraphicsScene::EnablePointItemSelection, tool, &T::AllowSelecting);
138  QObject::connect(scene, &VMainGraphicsScene::enableTextItemHover, tool, &T::allowTextHover);
139  QObject::connect(scene, &VMainGraphicsScene::enableTextItemSelection, tool, &T::allowTextSelectable);
140 }
141 
142 #endif // VABSTRACTPOINT_H
virtual void updatePointNamePosition(quint32 id, const QPointF &pos)=0
virtual QString getTagName() const Q_DECL_OVERRIDE
virtual ~VAbstractPoint() Q_DECL_EQ_DEFAULT
static void InitToolConnections(VMainGraphicsScene *scene, T *tool)
void SetPointName(quint32 id, const QString &name)
VAbstractPoint(VAbstractPattern *doc, VContainer *data, quint32 id)
virtual void ShowTool(quint32 id, bool enable) Q_DECL_OVERRIDE
ShowTool highlight tool.
void ShowToolVisualization(bool show)
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 VMainGraphicsScene class main scene.
void EnablePointItemSelection(bool enable)
void enableTextItemSelection(bool enable)
void EnablePointItemHover(bool enable)
void enableTextItemHover(bool enable)
#define SCASSERT(cond)
Definition: def.h:317