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 "Logger.h"
10#include <qdebug.h>
11#include <QGraphicsItem>
12#include <QGraphicsScene>
13#include <QPen>
14
18
19GridLine::GridLine (const GridLine & /* other */)
20{
21 LOG4CPP_ERROR_S ((*mainCat)) << "GridLine::GridLine";
22 ENGAUGE_ASSERT (false);
23}
24
26{
27 // Crash here means QGraphicsScene::clear was called, which is entirely unnecessary
28
29 for (int i = 0; i < m_segments.count(); i++) {
30 QGraphicsItem *item = m_segments [i];
31 delete item;
32 }
33
34 m_segments.clear ();
35}
36
38{
39 LOG4CPP_ERROR_S ((*mainCat)) << "GridLine::operator=";
40 ENGAUGE_ASSERT (false);
41
42 return *this;
43}
44
45void GridLine::add (QGraphicsItem *item)
46{
47 m_segments.push_back (item);
48}
49
50void GridLine::setPen (const QPen &pen)
51{
52 for (int i = 0; i < m_segments.count(); i++) {
53 QGraphicsItem *item = m_segments [i];
54 if (item != nullptr) {
55
56 // Downcast since QGraphicsItem does not have a pen
57 QGraphicsLineItem *itemLine = dynamic_cast<QGraphicsLineItem*> (item);
58 QGraphicsEllipseItem *itemArc = dynamic_cast<QGraphicsEllipseItem*> (item);
59 if (itemLine != nullptr) {
60 itemLine->setPen (pen);
61 } else if (itemArc != nullptr) {
62 itemArc->setPen (pen);
63 }
64 }
65 }
66}
67
68void GridLine::setVisible (bool visible)
69{
70 for (int i = 0; i < m_segments.count(); i++) {
71 QGraphicsItem *item = m_segments [i];
72 item->setVisible (visible);
73 }
74}
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
log4cpp::Category * mainCat
Definition Logger.cpp:14
void setPen(const QPen &pen)
Set the pen style.
Definition GridLine.cpp:50
GridLine & operator=(GridLine &other)
Assignment constructor. This will assert if called since copying of pointer containers is problematic...
Definition GridLine.cpp:37
void add(QGraphicsItem *item)
Add graphics item which represents one segment of the line.
Definition GridLine.cpp:45
void setVisible(bool visible)
Set each grid line as visible or hidden.
Definition GridLine.cpp:68
virtual ~GridLine()
Definition GridLine.cpp:25
GridLine()
Default constructor for storage in containers.
Definition GridLine.cpp:15
#define LOG4CPP_ERROR_S(logger)
Definition convenience.h:12