GobChartsWidget  1.0
gobchartsview.h
1 /* Copyright (C) 2012 by William Hallatt.
2  *
3  * This file forms part of the "GobChartsWidget" library.
4  *
5  * This library is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have downloaded a copy of the GNU General Public License
16  * (GNUGPL.txt) and GNU Lesser General Public License (GNULGPL.txt)
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * The official website for this project is www.goblincoding.com and,
20  * although not compulsory, it would be appreciated if all works of whatever
21  * nature referring to or using this library include a reference to this site.
22  */
23 
24 #ifndef GOBCHARTSVIEW_H
25 #define GOBCHARTSVIEW_H
26 
27 #include <QAbstractItemView>
28 #include "utils/globalincludes.h"
29 #include "utils/gobchartsnocopy.h"
30 
31 class QGraphicsView;
32 class QGraphicsItem;
33 class QDomNode;
34 class GobChartsTextItem;
35 
37 
60 class GobChartsView : public QAbstractItemView,
61  public GobChartsNoCopy
62 {
63  Q_OBJECT
64 
65 public:
69  virtual ~GobChartsView();
70 
73  void drawChart();
74 
76  void legendItemSelected( const QString &text );
77 
85  void setStateXML( const QDomNode &viewNode, const QDomNode &dataNode, bool includeData = true );
86 
93  QString getStateXML( bool includeData = true ) const;
94 
96  QRect visualRect( const QModelIndex &index ) const;
97 
99  QModelIndex indexAt( const QPoint &point ) const;
100 
102  void scrollTo( const QModelIndex &index, ScrollHint hint = EnsureVisible );
103 
105  void setModel( QAbstractItemModel *model );
106 
107 public slots:
112  void setLabelDetails( GobChartsLabel label, const QString &text, const QFont &font, const QColor &colour, Qt::Alignment align );
113 
119  void requestLabelDetails( GobChartsLabel label );
120 
124  void setGridLineStyle( Qt::PenStyle style );
125 
128  void setHorizontalGridLines( bool set, int number );
129 
132  void setVerticalGridLines( bool set, int number );
133 
136  void setGridColour( QColor colour );
137 
142  void setFixedColour( QColor colour );
143 
147  void setRandomColours();
148 
155  void setAllowedDataRange( qreal lowerBoundary, qreal upperBoundary );
156 
160  void setShowTotalRange();
161 
165  void setDebugLoggingOn( bool logging );
166 
167 signals:
171  void lastDebugLogMsg( QString );
172 
176  void emitLabelDetails( GobChartsLabel label, const QString &text, const QFont &font, const QColor &colour, Qt::Alignment align );
177 
181  void createLegendItem( const QColor &colour, const QString &text );
182 
184  void clearLegend();
185 
187  void highLightLegendItem( const QString &text );
188 
189 protected:
193  enum GobChartsColumn { CATEGORY, VALUE };
194 
196  explicit GobChartsView( QWidget *parent = 0 );
197 
201  virtual void generateGraphicsItems() = 0;
202 
206  virtual bool needsGrid() const = 0;
207 
212  virtual QString typeInteger() const = 0;
213 
216  bool useFixedColour() const;
217 
220  QColor fixedColour() const;
221 
226  void addToGraphItemsContainer( const QModelIndex &valueIndex, QGraphicsItem *item, const QString &legendText );
227 
231  int nrValidItems() const;
232 
235  QList< int > validRowList() const;
236 
239  QString category( int row ) const;
240 
243  qreal value( int row ) const;
244 
248  const QRectF &innerSceneRectF() const;
249 
252  bool isWithinAllowedRange( qreal value ) const;
253 
255  qreal gridWidth() const;
256 
260  qreal stripSpace( qreal perc ) const;
261 
263  qreal totalValue() const;
264 
266  QModelIndex moveCursor( QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers );
267 
269  QRegion visualRegionForSelection( const QItemSelection &selection ) const;
270 
272  int horizontalOffset() const;
273 
275  int verticalOffset() const;
276 
278  bool isIndexHidden( const QModelIndex &index ) const;
279 
281  void setSelection( const QRect& rect, QItemSelectionModel::SelectionFlags command );
282 
284  void keyPressEvent( QKeyEvent *event );
285 
286 protected slots:
288  void debugLog( QString msg );
289 
291  void dataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight );
292 
294  void rowsInserted( const QModelIndex &parent, int start, int end );
295 
297  void rowsAboutToBeRemoved( const QModelIndex &parent, int start, int end );
298 
300  void mousePressEvent( QMouseEvent *p_event );
301 
302 private:
308  friend class GobChartsViewPrivate;
309  class GobChartsViewPrivate;
310  GobChartsViewPrivate* const m_private;
311 
313  void resizeEvent( QResizeEvent *event );
314 
315 private slots:
317  void setSelectedTextItem( const QString &itemName );
318 };
319 
320 #endif // GOBCHARTSVIEW_H