24 #include "gobchartsgrid.h"
25 #include "utils/globalincludes.h"
27 #include <QGraphicsLineItem>
28 #include <QGraphicsScene>
41 m_gridPen ( QPen( QBrush( Qt::black ), 1, Qt::DotLine ) ),
42 m_axesPen ( QPen( QBrush( Qt::black ), 2 ) ),
43 m_nrHorizontalLines ( 0 ),
44 m_nrVerticalLines ( 0 ),
45 m_showHorizontalGrid( false ),
46 m_showVerticalGrid ( false ),
55 for(
int i = 0; i < m_gridLines.size(); i++ )
57 QGraphicsLineItem *line = m_gridLines.at( i );
73 foreach( QGraphicsLineItem *line, m_gridLines )
75 if( line ) scene->addItem( line );
82 emit
lastDebugLogMsg( tr(
"GobChartsGrid::addGridToScene# Attempting to add grid to an invalid scene." ) );
93 foreach( QGraphicsLineItem *line, m_gridLines )
95 if( line ) scene->removeItem( line );
102 emit
lastDebugLogMsg( tr(
"GobChartsGrid::removeGridFromScene# Attempting to remove grid from an invalid scene." ) );
112 if( !m_gridLines.empty() )
114 for(
int i = 0; i < m_gridLines.size(); i++ )
116 QGraphicsLineItem *line = m_gridLines.at( i );
129 QGraphicsLineItem *xAxis =
new QGraphicsLineItem;
130 xAxis->setLine( m_rectF.left(), m_rectF.bottom(), m_rectF.right(), m_rectF.bottom() );
131 xAxis->setPen ( m_axesPen );
132 m_gridLines.append( xAxis );
134 QGraphicsLineItem *yAxis =
new QGraphicsLineItem;
135 yAxis->setLine( m_rectF.left(), m_rectF.top(), m_rectF.left(), m_rectF.bottom() );
136 yAxis->setPen ( m_axesPen );
137 m_gridLines.append( yAxis );
140 if( m_nrVerticalLines > 0 )
142 qreal spacing = ( m_rectF.width()/m_nrVerticalLines );
144 if( m_showVerticalGrid )
146 for(
int i = 1; i <= m_nrVerticalLines; i++ )
148 QGraphicsLineItem *xLine =
new QGraphicsLineItem( m_rectF.left() + i * spacing,
150 m_rectF.left() + i * spacing,
151 m_rectF.bottom() + EXTEND );
152 xLine->setPen( m_gridPen );
153 m_gridLines.append( xLine );
159 if( m_nrHorizontalLines > 0 )
161 qreal spacing = ( m_rectF.height()/m_nrHorizontalLines );
163 if( m_showHorizontalGrid )
165 for(
int i = 0; i <= m_nrHorizontalLines; i++ )
167 QGraphicsLineItem *yLine =
new QGraphicsLineItem( m_rectF.left() - EXTEND,
168 m_rectF.top() + i * spacing,
170 m_rectF.top() + i * spacing );
171 yLine->setPen( m_gridPen );
172 m_gridLines.append( yLine );
189 return m_rectF.width();
196 m_showHorizontalGrid =
set;
197 m_nrHorizontalLines = number;
204 m_showVerticalGrid =
set;
205 m_nrVerticalLines = number;
212 m_gridPen.setColor( colour );
219 m_gridPen.setStyle( style );
226 m_loggingOn = logging;