Engauge Digitizer 2
Loading...
Searching...
No Matches
GridLine.cpp
Go to the documentation of this file.
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
17
18GridLine::GridLine (const GridLine & /* other */)
19{
20 ENGAUGE_ASSERT (false);
21}
22
24{
25 // Crash here means QGraphicsScene::clear was called, which is entirely unnecessary
26
27 for (int i = 0; i < m_segments.count(); i++) {
28 QGraphicsItem *item = m_segments [i];
29 delete item;
30 }
31
32 m_segments.clear ();
33}
34
36{
37 ENGAUGE_ASSERT (false);
38
39 return *this;
40}
41
43{
44 m_segments.push_back (item);
45}
46
47void 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 != nullptr) {
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 != nullptr) {
57 itemLine->setPen (pen);
58 } else if (itemArc != nullptr) {
59 itemArc->setPen (pen);
60 }
61 }
62 }
63}
64
66{
67 for (int i = 0; i < m_segments.count(); i++) {
68 QGraphicsItem *item = m_segments [i];
69 item->setVisible (visible);
70 }
71}
const int INNER_RADIUS_MIN
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Single grid line drawn a straight or curved line.
Definition GridLine.h:21
void setPen(const QPen &pen)
Set the pen style.
Definition GridLine.cpp:47
GridLine & operator=(GridLine &other)
Assignment constructor. This will assert if called since copying of pointer containers is problematic...
Definition GridLine.cpp:35
void add(QGraphicsItem *item)
Add graphics item which represents one segment of the line.
Definition GridLine.cpp:42
void setVisible(bool visible)
Set each grid line as visible or hidden.
Definition GridLine.cpp:65
virtual ~GridLine()
Definition GridLine.cpp:23
GridLine()
Default constructor for storage in containers.
Definition GridLine.cpp:14