Engauge Digitizer  2
GridLine.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "EngaugeAssert.h"
8 #include "GridLine.h"
9 #include <qdebug.h>
10 #include <QGraphicsItem>
11 #include <QGraphicsScene>
12 #include <QPen>
13 
15 {
16 }
17 
18 GridLine::~GridLine ()
19 {
20  // Crash here means QGraphicsScene::clear was called, which is entirely unnecessary
21 
22  for (int i = 0; i < m_segments.count(); i++) {
23  QGraphicsItem *item = m_segments [i];
24  delete item;
25  }
26 
27  m_segments.clear ();
28 }
29 
30 GridLine::GridLine (const GridLine & /* other */)
31 {
32  ENGAUGE_ASSERT (false);
33 }
34 
36 {
37  ENGAUGE_ASSERT (false);
38 
39  return *this;
40 }
41 
42 void GridLine::add (QGraphicsItem *item)
43 {
44  m_segments.push_back (item);
45 }
46 
47 void GridLine::setPen (const QPen &pen)
48 {
49  for (int i = 0; i < m_segments.count(); i++) {
50  QGraphicsItem *item = m_segments [i];
51  if (item != 0) {
52 
53  // Downcast since QGraphicsItem does not have a pen
54  QGraphicsLineItem *itemLine = dynamic_cast<QGraphicsLineItem*> (item);
55  QGraphicsEllipseItem *itemArc = dynamic_cast<QGraphicsEllipseItem*> (item);
56  if (itemLine != 0) {
57  itemLine->setPen (pen);
58  } else if (itemArc != 0) {
59  itemArc->setPen (pen);
60  }
61  }
62  }
63 }
64 
65 void GridLine::setVisible (bool visible)
66 {
67  for (int i = 0; i < m_segments.count(); i++) {
68  QGraphicsItem *item = m_segments [i];
69  item->setVisible (visible);
70  }
71 }
GridLine()
Default constructor for storage in containers.
Definition: GridLine.cpp:14
GridLine & operator=(GridLine &other)
Assignment constructor. This will assert if called since copying of pointer containers is problematic...
Definition: GridLine.cpp:35
void setPen(const QPen &pen)
Set the pen style.
Definition: GridLine.cpp:47
Single grid line drawn a straight or curved line.
Definition: GridLine.h:20
void setVisible(bool visible)
Set each grid line as visible or hidden.
Definition: GridLine.cpp:65
void add(QGraphicsItem *item)
Add graphics item which represents one segment of the line.
Definition: GridLine.cpp:42