Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
Ghosts Class Reference

Class for showing points and lines for all coordinate systems simultaneously, even though the code normally only allows graphical items for once coordinate system to be visible at a time. More...

#include <Ghosts.h>

Collaboration diagram for Ghosts:
Collaboration graph

Public Member Functions

 Ghosts (unsigned int coordSystemIndexToBeRestored)
 Single constructor. More...
 
 ~Ghosts ()
 
unsigned int coordSystemIndexToBeRestored () const
 Coordinate system index that was active before the ghosts. More...
 
void captureGraphicsItems (QGraphicsScene &scene)
 Take a snapshot of the graphics items. More...
 
void createGhosts (QGraphicsScene &scene)
 Create ghosts from the path/rect/polygon lists. More...
 
void destroyGhosts (QGraphicsScene &scene)
 Destory ghosts. Called at end of algorithm. More...
 

Detailed Description

Class for showing points and lines for all coordinate systems simultaneously, even though the code normally only allows graphical items for once coordinate system to be visible at a time.

QGraphicsLineItems are ignored since those are just used for the AxesChecker, and QGraphicsPixmapItems are ignored since those are just used for the background. The other QGraphicsItem subclasses are captured and converted into ghosts.

Definition at line 26 of file Ghosts.h.

Constructor & Destructor Documentation

Ghosts::Ghosts ( unsigned int  coordSystemIndexToBeRestored)

Single constructor.

Definition at line 17 of file Ghosts.cpp.

17  :
18  m_coordSystemIndexToBeRestored (coordSystemIndexToBeRestored)
19 {
20 }
unsigned int coordSystemIndexToBeRestored() const
Coordinate system index that was active before the ghosts.
Definition: Ghosts.cpp:73
Ghosts::~Ghosts ( )

Definition at line 22 of file Ghosts.cpp.

23 {
24 }

Member Function Documentation

void Ghosts::captureGraphicsItems ( QGraphicsScene &  scene)

Take a snapshot of the graphics items.

Definition at line 26 of file Ghosts.cpp.

27 {
28  QList<QGraphicsItem*> items = scene.items();
29 
30  QList<QGraphicsItem*>::iterator itr;
31  for (itr = items.begin(); itr != items.end(); itr++) {
32 
33  QGraphicsItem *item = *itr;
34 
35  QGraphicsEllipseItem *itemEllipse = dynamic_cast<QGraphicsEllipseItem*> (item);
36  if (itemEllipse != nullptr) {
37 
38  GhostEllipse ghost (itemEllipse->boundingRect(),
39  itemEllipse->pen(),
40  itemEllipse->brush());
41  m_ellipses.push_back (ghost);
42 
43  } else {
44 
45  QGraphicsPathItem *itemPath = dynamic_cast<QGraphicsPathItem*> (item);
46  if (itemPath != nullptr) {
47 
48  GhostPath ghost (itemPath->path (),
49  itemPath->pen(),
50  itemPath->brush());
51  m_paths.push_back (ghost);
52 
53  } else {
54 
55  QGraphicsPolygonItem *itemPolygon = dynamic_cast<QGraphicsPolygonItem*> (item);
56  if (itemPolygon != nullptr) {
57 
58  // Polygon is centered at origin so we have to add offset
59  QPolygonF polygon = itemPolygon->polygon();
60  polygon.translate (itemPolygon->pos ());
61 
62  GhostPolygon ghost (polygon,
63  itemPolygon->pen(),
64  itemPolygon->brush());
65  m_polygons.push_back (ghost);
66 
67  }
68  }
69  }
70  }
71 }
Ghost for a QGraphicsPathItem.
Definition: GhostPath.h:15
Ghost for a QGraphicsPolygonItem.
Definition: GhostPolygon.h:15
Ghost for a QGraphicsEllipseItem.
Definition: GhostEllipse.h:15
unsigned int Ghosts::coordSystemIndexToBeRestored ( ) const

Coordinate system index that was active before the ghosts.

Definition at line 73 of file Ghosts.cpp.

74 {
75  return m_coordSystemIndexToBeRestored;
76 }
void Ghosts::createGhosts ( QGraphicsScene &  scene)

Create ghosts from the path/rect/polygon lists.

Definition at line 78 of file Ghosts.cpp.

79 {
80  int i;
81 
82  for (i = 0; i < m_ellipses.count(); i++) {
83  GhostEllipse ghost = m_ellipses.at(i);
84 
85  QGraphicsEllipseItem *item = scene.addEllipse (ghost.rect());
86 
87  item->setData (DATA_KEY_GHOST, QVariant (true));
88  item->setPen (ghost.pen());
89  item->setBrush (ghost.brush());
90  item->setZValue (Z_VALUE);
91  item->setVisible (true);
92  }
93 
94  for (i = 0; i < m_paths.count(); i++) {
95  GhostPath ghost = m_paths.at(i);
96 
97  QGraphicsPathItem *item = scene.addPath (ghost.path(),
98  ghost.pen(),
99  ghost.brush());
100 
101  item->setData (DATA_KEY_GHOST, QVariant (true));
102  item->setZValue (Z_VALUE);
103  item->setVisible (true);
104  }
105 
106  for (i = 0; i < m_polygons.count(); i++) {
107  GhostPolygon ghost = m_polygons.at(i);
108 
109  QGraphicsPolygonItem *item = scene.addPolygon (ghost.polygon(),
110  ghost.pen(),
111  ghost.brush());
112 
113  item->setData (DATA_KEY_GHOST, QVariant (true));
114  item->setZValue (Z_VALUE);
115  item->setVisible (true);
116  }
117 }
QBrush brush() const
Get method for brush.
Definition: GhostPath.cpp:38
QPen pen() const
Get method for pen.
Definition: GhostPath.cpp:48
Ghost for a QGraphicsPathItem.
Definition: GhostPath.h:15
QPainterPath path() const
Get method for path.
Definition: GhostPath.cpp:43
True if item has changed since last mousePressEvent
Definition: DataKey.h:17
QPen pen() const
Get method for pen.
QPolygonF polygon() const
Get method for polygon.
const double Z_VALUE
QBrush brush() const
Get method for brush.
QBrush brush() const
Get method for brush.
Ghost for a QGraphicsPolygonItem.
Definition: GhostPolygon.h:15
Ghost for a QGraphicsEllipseItem.
Definition: GhostEllipse.h:15
QPen pen() const
Get method for pen.
QRectF rect() const
Get method for bounding rectangle.
void Ghosts::destroyGhosts ( QGraphicsScene &  scene)

Destory ghosts. Called at end of algorithm.

Definition at line 119 of file Ghosts.cpp.

120 {
121  QList<QGraphicsItem*> items = scene.items();
122  QList<QGraphicsItem*>::iterator itr;
123  for (itr = items.begin(); itr != items.end(); itr++) {
124 
125  QGraphicsItem *item = *itr;
126  QVariant data = item->data (DATA_KEY_GHOST);
127  if (!data.isNull()) {
128  if (data.toBool()) {
129  scene.removeItem (item);
130  }
131  }
132  }
133 }
True if item has changed since last mousePressEvent
Definition: DataKey.h:17

The documentation for this class was generated from the following files: