LibEngsas
echartbase.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  MA 02110-1301 USA.
18 */
19 
20 #ifndef ECHARTBASE_H
21 #define ECHARTBASE_H
22 
23 #include <ewidget.h>
24 #include "echarts.h"
25 
26 #include "echartvalues.h"
27 
28 class EAction;
29 
57 {
58  Q_OBJECT
59  Q_PROPERTY(QString chartTitle READ chartTitle WRITE setChartTitle)
60  Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision)
61  Q_PROPERTY(char numberFormat READ numberFormat WRITE setNumberFormat)
62  Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
63  Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont)
64  public:
65  EChartBase(QWidget *parent = NULL);
66 
67  void setChartTitle(QString chartTitle);
68  inline QString chartTitle() const { return myChartTitle; }
69  void setNumberPrecision(int precision);
70  inline int numberPrecision() const { return myNumberPrecision; }
71  void setNumberFormat(char format);
72  inline char numberFormat() const { return myNumberFormat; }
73 
82  void addDataSet(EChartValues dataSet, const QString label, QColor color = QColor());
83  bool removeDataSet(const QString label);
84 
85  void setTitleFont(QFont font);
86  QFont titleFont() const;
87  void setLabelFont(QFont font);
88  QFont labelFont() const;
89 
90  EAction *exportAction() const;
91 
92  public slots:
93  void exportChart();
94  void exportChart(QPainter *painter, QRect boundingRect);
95  void clear();
96 
97  protected:
98  void paintEvent(QPaintEvent *event);
107  virtual void drawChart(QPainter *painter, QRect viewPort) = 0;
108 
109  int marginHorizontal, marginVertical;
110  QRect viewPort;
111  QStringList colorNames;
112  QList<void (*)(QPainter*, QPoint)> markers;
113  QMap<QString, EChartValues> dataSets;
114  QMap<QString, QColor> dataSetsColors;
115  QMap<QString, void (*)(QPainter *, QPoint)> dataSetsMarkers;
116 
117  protected slots:
124  virtual void contextMenu(QPoint pos) const;
125 
126  private:
132  void legend(QPointF origin, QPainter *painter);
138  QRect createViewPort(QPainter *painter, QRect boundingRect);
139 
142  QString myChartTitle;
143  QFont myTitleFont, myLabelFont;
145 };
146 
147 #endif // ECHARTBASE_H