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 GridLine()15GridLine::GridLine () 16 { 17 } 18 GridLine(const GridLine &)19GridLine::GridLine (const GridLine & /* other */) 20 { 21 LOG4CPP_ERROR_S ((*mainCat)) << "GridLine::GridLine"; 22 ENGAUGE_ASSERT (false); 23 } 24 ~GridLine()25GridLine::~GridLine () 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 operator =(GridLine &)37GridLine &GridLine::operator= (GridLine & /* other */) 38 { 39 LOG4CPP_ERROR_S ((*mainCat)) << "GridLine::operator="; 40 ENGAUGE_ASSERT (false); 41 42 return *this; 43 } 44 add(QGraphicsItem * item)45void GridLine::add (QGraphicsItem *item) 46 { 47 m_segments.push_back (item); 48 } 49 setPen(const QPen & pen)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 setVisible(bool visible)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 } 75