##// END OF EJS Templates
Q_SIGNALS and Q_SLOTS
sauimone -
r775:02f25710c73d
parent child
Show More
@@ -1,95 +1,95
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE:BSD$
10 10 ** You may use this file under the terms of the BSD license as follows:
11 11 **
12 12 ** "Redistribution and use in source and binary forms, with or without
13 13 ** modification, are permitted provided that the following conditions are
14 14 ** met:
15 15 ** * Redistributions of source code must retain the above copyright
16 16 ** notice, this list of conditions and the following disclaimer.
17 17 ** * Redistributions in binary form must reproduce the above copyright
18 18 ** notice, this list of conditions and the following disclaimer in
19 19 ** the documentation and/or other materials provided with the
20 20 ** distribution.
21 21 ** * Neither the name of Digia nor the names of its contributors
22 22 ** may be used to endorse or promote products derived from this
23 23 ** software without specific prior written permission.
24 24 **
25 25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 36 ** $QT_END_LICENSE$
37 37 **
38 38 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
39 39 **
40 40 ****************************************************************************/
41 41
42 42 #ifndef THEMEWINDOW_H_
43 43 #define THEMEWINDOW_H_
44 44 #include <QWidget>
45 45 #include <QChartGlobal>
46 46
47 47 class QComboBox;
48 48 class QCheckBox;
49 49
50 50 QTCOMMERCIALCHART_BEGIN_NAMESPACE
51 51 class QChartView;
52 52 class QChart;
53 53 QTCOMMERCIALCHART_END_NAMESPACE
54 54
55 55 typedef QPair<QPointF, QString> Data;
56 56 typedef QList<Data> DataList;
57 57 typedef QList<DataList> DataTable;
58 58
59 59 QTCOMMERCIALCHART_USE_NAMESPACE
60 60
61 61 class ThemeWidget: public QWidget
62 62 {
63 63 Q_OBJECT
64 64 public:
65 65 explicit ThemeWidget(QWidget *parent = 0);
66 66 ~ThemeWidget();
67 67
68 private slots:
68 private Q_SLOTS:
69 69 void updateUI();
70 70
71 71 private:
72 72 DataTable generateRandomData(int listCount,int valueMax,int valueCount) const;
73 73 QComboBox* createThemeBox() const;
74 74 QComboBox* createAnimationBox() const;
75 75 void connectSignals();
76 76 QChart* createAreaChart() const;
77 77 QChart* createBarChart(int valueCount) const;
78 78 QChart* createPieChart() const;
79 79 QChart* createLineChart() const;
80 80 QChart* createSplineChart() const;
81 81 QChart* createScatterChart() const;
82 82
83 83 private:
84 84 int m_listCount;
85 85 int m_valueMax;
86 86 int m_valueCount;
87 87 QList<QChartView*> m_charts;
88 88 DataTable m_dataTable;
89 89
90 90 QComboBox *m_themeComboBox;
91 91 QCheckBox *m_antialiasCheckBox;
92 92 QComboBox *m_animatedComboBox;
93 93 };
94 94
95 95 #endif /* THEMEWINDOW_H_ */
@@ -1,39 +1,39
1 1 #ifndef DECLARATIVEBARSERIES_H
2 2 #define DECLARATIVEBARSERIES_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include <QDeclarativeItem>
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 class QChart;
10 10 class QBarSeries;
11 11
12 12 class DeclarativeBarSeries : public QDeclarativeItem
13 13 {
14 14 Q_OBJECT
15 15 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
16 16
17 17 public:
18 18 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
19 19
20 20 public: // from QDeclarativeParserStatus
21 21 void componentComplete();
22 22
23 23 public:
24 24 void setBarCategories(QStringList categories);
25 25 QStringList barCategories();
26 26
27 signals:
27 Q_SIGNALS:
28 28
29 public slots:
29 public Q_SLOTS:
30 30
31 31 public:
32 32 QChart *m_chart;
33 33 QBarSeries *m_series;
34 34 QStringList m_categories;
35 35 };
36 36
37 37 QTCOMMERCIALCHART_END_NAMESPACE
38 38
39 39 #endif // DECLARATIVEBARSERIES_H
@@ -1,39 +1,39
1 1 #ifndef DECLARATIVEPIESERIES_H
2 2 #define DECLARATIVEPIESERIES_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include "qpieslice.h"
6 6 #include <QDeclarativeItem>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class QPieSeries;
11 11 class QChart;
12 12
13 13 class DeclarativePieSeries : public QDeclarativeItem
14 14 {
15 15 Q_OBJECT
16 16 Q_PROPERTY(QDeclarativeListProperty<QPieSlice> data READ data)
17 17
18 18 public:
19 19 explicit DeclarativePieSeries(QDeclarativeItem *parent = 0);
20 20 QDeclarativeListProperty<QPieSlice> data();
21 21
22 signals:
22 Q_SIGNALS:
23 23
24 public slots:
24 public Q_SLOTS:
25 25 static void appendData(QDeclarativeListProperty<QPieSlice> *list,
26 26 QPieSlice *element);
27 27
28 private slots:
28 private Q_SLOTS:
29 29 void setParentForSeries();
30 30
31 31 private:
32 32 QChart *m_chart;
33 33 QPieSeries *m_series;
34 34 QList<QPieSlice *> m_data;
35 35 };
36 36
37 37 QTCOMMERCIALCHART_END_NAMESPACE
38 38
39 39 #endif // DECLARATIVEPIESERIES_H
@@ -1,45 +1,45
1 1 #ifndef DECLARATIVE_XY_SERIES_H
2 2 #define DECLARATIVE_XY_SERIES_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include "declarativexypoint.h"
6 6 #include "qxyseries.h"
7 7 #include <QDeclarativeItem>
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 class QChart;
12 12
13 13 class DeclarativeXySeries : public QDeclarativeItem
14 14 {
15 15 Q_OBJECT
16 16 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
17 17
18 18 public:
19 19 explicit DeclarativeXySeries(QSeries::QSeriesType type, QDeclarativeItem *parent = 0);
20 20 ~DeclarativeXySeries();
21 21
22 22 public: // from QDeclarativeParserStatus
23 23 void componentComplete();
24 24
25 25 public:
26 26 QDeclarativeListProperty<DeclarativeXyPoint> points();
27 27
28 signals:
28 Q_SIGNALS:
29 29
30 public slots:
30 public Q_SLOTS:
31 31 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
32 32 DeclarativeXyPoint *element);
33 33
34 private slots:
34 private Q_SLOTS:
35 35
36 36 public:
37 37 QSeries::QSeriesType m_seriesType;
38 38 QChart *m_chart;
39 39 QXYSeries *m_series;
40 40 QList<DeclarativeXyPoint *> m_points;
41 41 };
42 42
43 43 QTCOMMERCIALCHART_END_NAMESPACE
44 44
45 45 #endif // DECLARATIVE_XY_SERIES_H
@@ -1,72 +1,72
1 1 #ifndef AREACHARTITEM_H
2 2 #define AREACHARTITEM_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include "linechartitem_p.h"
6 6 #include <QPen>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class QAreaSeries;
11 11 class AreaChartItem;
12 12
13 13 class AreaChartItem : public ChartItem
14 14 {
15 15 Q_OBJECT
16 16 public:
17 17 AreaChartItem(QAreaSeries *areaSeries, ChartPresenter *presenter);
18 18 ~AreaChartItem();
19 19
20 20 //from QGraphicsItem
21 21 QRectF boundingRect() const;
22 22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23 23 QPainterPath shape() const;
24 24
25 25 LineChartItem* upperLineItem() const { return m_upper; }
26 26 LineChartItem* lowerLineItem() const { return m_lower; }
27 27
28 28 void updatePath();
29 29
30 30 protected:
31 31 void mousePressEvent(QGraphicsSceneMouseEvent *event);
32 32
33 signals:
33 Q_SIGNALS:
34 34 void clicked(const QPointF &point);
35 35
36 public slots:
36 public Q_SLOTS:
37 37 void handleUpdated();
38 38 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
39 39 void handleGeometryChanged(const QRectF &size);
40 40
41 41 private:
42 42 QAreaSeries* m_series;
43 43 LineChartItem* m_upper;
44 44 LineChartItem* m_lower;
45 45 QPainterPath m_path;
46 46 QRectF m_rect;
47 47 QRectF m_clipRect;
48 48 QPen m_linePen;
49 49 QPen m_pointPen;
50 50 QBrush m_brush;
51 51 bool m_pointsVisible;
52 52
53 53 };
54 54
55 55 class AreaBoundItem : public LineChartItem
56 56 {
57 57 public:
58 58 AreaBoundItem(AreaChartItem *item,QLineSeries *lineSeries) : LineChartItem(lineSeries, 0), m_item(item) {}
59 59 ~AreaBoundItem() {}
60 60
61 61 void setLayout(QVector<QPointF> &points) {
62 62 LineChartItem::setLayout(points);
63 63 m_item->updatePath();
64 64 }
65 65
66 66 private:
67 67 AreaChartItem* m_item;
68 68 };
69 69
70 70 QTCOMMERCIALCHART_END_NAMESPACE
71 71
72 72 #endif
@@ -1,52 +1,52
1 1 #ifndef QAREASERIES_H_
2 2 #define QAREASERIES_H_
3 3
4 4 #include <qchartglobal.h>
5 5 #include <qseries.h>
6 6 #include <QPen>
7 7 #include <QBrush>
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10 class QLineSeries;
11 11
12 12 class QTCOMMERCIALCHART_EXPORT QAreaSeries : public QSeries
13 13 {
14 14 Q_OBJECT
15 15 public:
16 16 QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries = 0);
17 17 virtual ~QAreaSeries();
18 18
19 19 public: // from QChartSeries
20 20 virtual QSeriesType type() const { return QSeries::SeriesTypeArea; }
21 21
22 22 QLineSeries* upperSeries() const { return m_upperSeries; }
23 23 QLineSeries* lowerSeries() const { return m_lowerSeries; }
24 24
25 25 void setPen(const QPen &pen);
26 26 QPen pen() const { return m_pen;}
27 27
28 28 void setBrush(const QBrush &brush);
29 29 QBrush brush() const { return m_brush;}
30 30
31 31 void setPointsVisible(bool visible);
32 32 bool pointsVisible() const { return m_pointsVisible; }
33 33
34 34 // bool setModel(QAbstractItemModel* model);
35 35 // void setModelMappingUpper(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
36 36 // void setModelMappingLower(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
37 37
38 signals:
38 Q_SIGNALS:
39 39 void updated();
40 40 void clicked(const QPointF &point);
41 41
42 42 private:
43 43 QBrush m_brush;
44 44 QPen m_pen;
45 45 QLineSeries* m_upperSeries;
46 46 QLineSeries* m_lowerSeries;
47 47 bool m_pointsVisible;
48 48 };
49 49
50 50 QTCOMMERCIALCHART_END_NAMESPACE
51 51
52 52 #endif
@@ -1,123 +1,123
1 1 #ifndef AXISITEM_H_
2 2 #define AXISITEM_H_
3 3
4 4 #include "chart_p.h"
5 5 #include <QGraphicsItem>
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 class QChartAxis;
10 10 class ChartPresenter;
11 11
12 12 class Axis : public Chart
13 13 {
14 14 Q_OBJECT
15 15 public:
16 16 enum AxisType{X_AXIS,Y_AXIS};
17 17
18 18 Axis(QChartAxis *axis, ChartPresenter *presenter, AxisType type = X_AXIS);
19 19 ~Axis();
20 20
21 21 AxisType axisType() const { return m_type; }
22 22
23 23 void setAxisOpacity(qreal opacity);
24 24 qreal axisOpacity() const;
25 25
26 26 void setGridOpacity(qreal opacity);
27 27 qreal gridOpacity() const;
28 28
29 29 void setLabelsOpacity(qreal opacity);
30 30 qreal labelsOpacity() const;
31 31
32 32 void setShadesOpacity(qreal opacity);
33 33 qreal shadesOpacity() const;
34 34
35 35 void setLabelsAngle(int angle);
36 36 int labelsAngle()const { return m_labelsAngle; }
37 37
38 38 void setShadesBrush(const QBrush &brush);
39 39 void setShadesPen(const QPen &pen);
40 40
41 41 void setAxisPen(const QPen &pen);
42 42 void setGridPen(const QPen &pen);
43 43
44 44 void setLabelsPen(const QPen &pen);
45 45 void setLabelsBrush(const QBrush &brush);
46 46 void setLabelsFont(const QFont &font);
47 47
48 48 inline QRectF geometry() const { return m_rect; }
49 49 inline QVector<qreal> layout() { return m_layoutVector; }
50 50
51 public slots:
51 public Q_SLOTS:
52 52 void handleAxisUpdated();
53 53 void handleAxisCategoriesUpdated();
54 54 void handleRangeChanged(qreal min , qreal max,int tickCount);
55 55 void handleGeometryChanged(const QRectF &size);
56 56
57 57
58 58 private:
59 59 inline bool isEmpty();
60 60 void createItems(int count);
61 61 void deleteItems(int count);
62 62
63 63 QVector<qreal> calculateLayout() const;
64 64 void updateLayout(QVector<qreal> &layout);
65 65 void setLayout(QVector<qreal> &layout);
66 66
67 67 bool createLabels(QStringList &labels,qreal min, qreal max,int ticks) const;
68 68 void axisSelected();
69 69
70 70 private:
71 71 QChartAxis* m_chartAxis;
72 72 AxisType m_type;
73 73 QRectF m_rect;
74 74 int m_labelsAngle;
75 75 QGraphicsItemGroup m_grid;
76 76 QGraphicsItemGroup m_shades;
77 77 QGraphicsItemGroup m_labels;
78 78 QGraphicsItemGroup m_axis;
79 79 QVector<qreal> m_layoutVector;
80 80 qreal m_min;
81 81 qreal m_max;
82 82 int m_ticksCount;
83 83 qreal m_zoomFactor;
84 84
85 85 friend class AxisAnimation;
86 86 friend class AxisItem;
87 87
88 88 };
89 89
90 90 class AxisItem: public QGraphicsLineItem
91 91 {
92 92 public:
93 93
94 94 AxisItem(Axis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {}
95 95
96 96 protected:
97 97 void mousePressEvent(QGraphicsSceneMouseEvent *event)
98 98 {
99 99 Q_UNUSED(event)
100 100 m_axis->axisSelected();
101 101 }
102 102
103 103 QRectF boundingRect() const
104 104 {
105 105 return shape().boundingRect();
106 106 }
107 107
108 108 QPainterPath shape() const
109 109 {
110 110 QPainterPath path = QGraphicsLineItem::shape();
111 111 QRectF rect = path.boundingRect();
112 112 path.addRect(rect.adjusted(0,0,m_axis->axisType()!=Axis::X_AXIS?8:0,m_axis->axisType()!=Axis::Y_AXIS?8:0));
113 113 return path;
114 114 }
115 115
116 116 private:
117 117 Axis* m_axis;
118 118
119 119 };
120 120
121 121 QTCOMMERCIALCHART_END_NAMESPACE
122 122
123 123 #endif /* AXISITEM_H_ */
@@ -1,114 +1,114
1 1 #ifndef QCHARTAXIS_H_
2 2 #define QCHARTAXIS_H_
3 3
4 4 #include <qchartglobal.h>
5 5 #include <qchartaxiscategories.h>
6 6 #include <QPen>
7 7 #include <QFont>
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject
12 12 {
13 13 Q_OBJECT
14 14 public:
15 15
16 16 QChartAxis(QObject *parent =0);
17 17 ~QChartAxis();
18 18
19 19 //axis handling
20 20 bool isAxisVisible() const { return m_axisVisible; }
21 21 void setAxisVisible(bool visible);
22 22 void setAxisPen(const QPen &pen);
23 23 QPen axisPen() const { return m_axisPen; }
24 24
25 25 //grid handling
26 26 bool isGridLineVisible() const { return m_gridLineVisible; }
27 27 void setGridLineVisible(bool visible);
28 28 void setGridLinePen(const QPen &pen);
29 29 QPen gridLinePen() const { return m_gridLinePen; }
30 30
31 31 //labels handling
32 32 bool labelsVisible() const { return m_labelsVisible; }
33 33 void setLabelsVisible(bool visible);
34 34 void setLabelsPen(const QPen &pen);
35 35 QPen labelsPen() const { return m_labelsPen;}
36 36 void setLabelsBrush(const QBrush &brush);
37 37 QBrush labelsBrush() const { return m_labelsBrush; }
38 38 void setLabelsFont(const QFont &font);
39 39 QFont labelsFont() const { return m_labelsFont; }
40 40 void setLabelsAngle(int angle);
41 41 int labelsAngle() const { return m_labelsAngle; }
42 42
43 43 //shades handling
44 44 bool shadesVisible() const { return m_shadesVisible; }
45 45 void setShadesVisible(bool visible);
46 46 void setShadesPen(const QPen &pen);
47 47 QPen shadesPen() const { return m_shadesPen; }
48 48 void setShadesBrush(const QBrush &brush);
49 49 QBrush shadesBrush() const { return m_shadesBrush; }
50 50 void setShadesOpacity(qreal opacity);
51 51 qreal shadesOpacity() const { return m_shadesOpacity; }
52 52
53 53 //range handling
54 54 void setMin(qreal min);
55 55 qreal min() const { return m_min; }
56 56 void setMax(qreal max);
57 57 qreal max() const { return m_max; }
58 58 void setRange(qreal min, qreal max);
59 59
60 60 //ticks handling
61 61 void setTicksCount(int count);
62 62 int ticksCount() const { return m_ticksCount;}
63 63
64 64 void setNiceNumbers(bool enabled);
65 65 bool niceNumbers() const { return m_niceNumbers;}
66 66
67 67 QChartAxisCategories* categories() { return &m_category; }
68 68
69 69 void show();
70 70 void hide();
71 71
72 signals:
72 Q_SIGNALS:
73 73 void minChanged(qreal min);
74 74 void maxChanged(qreal max);
75 75 void rangeChanged(qreal min, qreal max);
76 76 void ticksCountChanged(int count);
77 77
78 78 //interal signal
79 79 void updated();
80 80 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
81 81 //internal slot
82 public slots:
82 public Q_SLOTS:
83 83 void handleAxisRangeChanged(qreal min, qreal max,int count);
84 84
85 85 private:
86 86 bool m_axisVisible;
87 87 QPen m_axisPen;
88 88 QBrush m_axisBrush;
89 89
90 90 bool m_gridLineVisible;
91 91 QPen m_gridLinePen;
92 92
93 93 bool m_labelsVisible;
94 94 QPen m_labelsPen;
95 95 QBrush m_labelsBrush;
96 96 QFont m_labelsFont;
97 97 int m_labelsAngle;
98 98
99 99 bool m_shadesVisible;
100 100 QPen m_shadesPen;
101 101 QBrush m_shadesBrush;
102 102 qreal m_shadesOpacity;
103 103
104 104 qreal m_min;
105 105 qreal m_max;
106 106
107 107 int m_ticksCount;
108 108 QChartAxisCategories m_category;
109 109
110 110 bool m_niceNumbers;
111 111 };
112 112
113 113 QTCOMMERCIALCHART_END_NAMESPACE
114 114 #endif /* QCHARTAXIS_H_ */
@@ -1,38 +1,38
1 1 #ifndef QCHARTAXISCATEGORIES_H_
2 2 #define QCHARTAXISCATEGORIES_H_
3 3
4 4 #include <qchartglobal.h>
5 5 #include <qbarseries.h>
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 class QTCOMMERCIALCHART_EXPORT QChartAxisCategories : public QObject
10 10 {
11 11 Q_OBJECT
12 12 private:
13 13 QChartAxisCategories();
14 14 public:
15 15 ~QChartAxisCategories();
16 16
17 17 void insert(const QBarCategories &category);
18 18 void insert(qreal value,QString label);
19 19 void remove(qreal value);
20 20 QList<qreal> values() const;
21 21 QString label(qreal value) const;
22 22 void clear();
23 23 int count();
24 24
25 25 //internal signal
26 signals:
26 Q_SIGNALS:
27 27 void updated();
28 28
29 29 private:
30 30 QMap<qreal,QString> m_map;
31 31
32 32 friend class QChartAxis;
33 33 };
34 34
35 35
36 36 QTCOMMERCIALCHART_END_NAMESPACE
37 37
38 38 #endif /* QCHARTAXISCATEGORIES_H_ */
@@ -1,75 +1,73
1 1 #ifndef BARCHARTITEM_H
2 2 #define BARCHARTITEM_H
3 3
4 4 #include "chartitem_p.h"
5 5 #include "qbarseries.h"
6 6 #include <QPen>
7 7 #include <QBrush>
8 8 #include <QGraphicsItem>
9 9
10 10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 11
12 12 class Bar;
13 13 class BarValue;
14 14 class QChartAxisCategories;
15 15 class QChart;
16 16
17 17 //typedef QVector<QRectF> BarLayout;
18 18
19 19 class BarChartItem : public ChartItem
20 20 {
21 21 Q_OBJECT
22 22 public:
23 23 BarChartItem(QBarSeries *series, ChartPresenter *presenter);
24 24 virtual ~BarChartItem();
25 25
26 26 // Common implemantation of different presenters. Not to be instantiated.
27 27 // TODO: combine this with BarPresenter and derive other presenters from it?
28 28
29 29 public:
30 30 // From QGraphicsItem
31 31 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
32 32 QRectF boundingRect() const;
33 33
34 34 // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it
35 35 virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes
36 private slots:
37 36
38 public:
39 37 virtual QVector<QRectF> calculateLayout();
40 38 void applyLayout(const QVector<QRectF> &layout);
41 39 void setLayout(const QVector<QRectF> &layout);
42 40 void updateLayout(const QVector<QRectF> &layout);
43 41
44 42 QRectF geometry() const { return m_rect;}
45 43
46 public slots:
44 public Q_SLOTS:
47 45 void handleModelChanged(int index);
48 46 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
49 47 void handleGeometryChanged(const QRectF &size);
50 48 void handleLayoutChanged();
51 49
52 50 // Internal slots
53 51 void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled)
54 52
55 53 protected:
56 54
57 55 // TODO: consider these.
58 56 qreal m_domainMinX;
59 57 qreal m_domainMaxX;
60 58 qreal m_domainMinY;
61 59 qreal m_domainMaxY;
62 60
63 61 QRectF m_rect;
64 62 bool m_layoutSet; // True, if component has been laid out.
65 63 QVector<QRectF> m_layout;
66 64
67 65 // Not owned.
68 66 QBarSeries *m_series;
69 67 QList<Bar *> m_bars;
70 68 QList<BarValue *> m_floatingValues;
71 69 };
72 70
73 71 QTCOMMERCIALCHART_END_NAMESPACE
74 72
75 73 #endif // BARCHARTITEM_H
@@ -1,57 +1,57
1 1 #ifndef BARCHARTMODEL_H
2 2 #define BARCHARTMODEL_H
3 3
4 4 #include <QObject>
5 5 #include <QStringList>
6 6 #include "qchartglobal.h"
7 7 #include <qseries.h>
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 // Model for bar chart. Internal class.
12 12 // TODO: Implement as QAbstractItemModel?
13 13
14 14 class QBarSet;
15 15
16 16 class BarChartModel : public QObject //, public QAbstractItemModel
17 17 {
18 18 Q_OBJECT
19 19 public:
20 20 explicit BarChartModel(QStringList categories, QObject *parent = 0);
21 21
22 22 QStringList category();
23 23 void addBarSet(QBarSet *set);
24 24 void removeBarSet(QBarSet *set);
25 25 void insertBarSet(int i, QBarSet *set);
26 26 void insertCategory(int i, QString category);
27 27 void removeCategory(int i);
28 28 QBarSet *setAt(int index);
29 29 QList<QBarSet *> barSets();
30 30
31 31 int barsetCount(); // Number of sets in model
32 32 int categoryCount(); // Number of categories
33 33
34 34 qreal max(); // Maximum value of all sets
35 35 qreal min(); // Minimum value of all sets
36 36 qreal valueAt(int set, int category);
37 37 qreal percentageAt(int set, int category);
38 38
39 39 qreal categorySum(int category);
40 40 qreal maxCategorySum(); // returns maximum sum of sets in all categories.
41 41
42 42 QString categoryName(int category);
43 43
44 signals:
44 Q_SIGNALS:
45 45 void modelUpdated();
46 46
47 public slots:
47 public Q_SLOTS:
48 48
49 49 private:
50 50
51 51 QList<QBarSet *> m_dataModel;
52 52 QStringList m_category;
53 53 };
54 54
55 55 QTCOMMERCIALCHART_END_NAMESPACE
56 56
57 57 #endif // BARCHARTMODEL_H
@@ -1,97 +1,97
1 1 #ifndef BARSERIES_H
2 2 #define BARSERIES_H
3 3
4 4 #include <qseries.h>
5 5 #include <QStringList>
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 typedef QStringList QBarCategories;
10 10
11 11 class QBarSet;
12 12 class BarChartModel;
13 13 class BarCategory;
14 14
15 15 // Container for series
16 16 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries
17 17 {
18 18 Q_OBJECT
19 19 public:
20 20 QBarSeries(QStringList categories, QObject *parent = 0);
21 21
22 22 virtual QSeriesType type() const { return QSeries::SeriesTypeBar; }
23 23
24 24 void addBarSet(QBarSet *set); // Takes ownership of set
25 25 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
26 26 void insertBarSet(int i, QBarSet *set);
27 27 void insertCategory(int i, QString category);
28 28 void removeCategory(int i);
29 29 int barsetCount();
30 30 int categoryCount();
31 31 QList<QBarSet*> barSets();
32 32 QBarCategories categories() const;
33 33
34 34 bool setModel(QAbstractItemModel *model);
35 35 QAbstractItemModel *modelExt() { return m_model; }
36 36 void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical);
37 37 void setModelMappingShift(int first, int count);
38 38
39 39 public:
40 40 // TODO: Functions below this are not part of api and will be moved
41 41 // to private implementation, when we start using it
42 42 // TODO: TO PIMPL --->
43 43 QBarSet* barsetAt(int index);
44 44 QString categoryName(int category);
45 45 qreal min();
46 46 qreal max();
47 47 qreal valueAt(int set, int category);
48 48 qreal percentageAt(int set, int category);
49 49 qreal categorySum(int category);
50 50 qreal maxCategorySum();
51 51 BarChartModel& model();
52 52 // <--- TO PIMPL
53 53
54 signals:
54 Q_SIGNALS:
55 55 //void changed(int index);
56 56 void clicked(QBarSet *barset, QString category); // Up to user of api, what to do with these signals
57 57 void rightClicked(QBarSet *barset, QString category);
58 58
59 59 //
60 60 void updatedBars();
61 61 void restructuredBar(int);
62 62
63 63 // TODO: internal signals, these to private implementation.
64 64 // TODO: TO PIMPL --->
65 65 void showToolTip(QPoint pos, QString tip);
66 66 // <--- TO PIMPL
67 67
68 68 public Q_SLOTS:
69 69 void setToolTipEnabled(bool enabled = true); // enables tooltips
70 70
71 71 // TODO: TO PIMPL --->
72 72 void barsetClicked(QString category);
73 73 void barsetRightClicked(QString category);
74 74 // <--- TO PIMPL
75 75
76 76 private Q_SLOTS:
77 77 // slots for updating bars when data in model changes
78 78 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
79 79 void modelDataAdded(QModelIndex parent, int start, int end);
80 80 void modelDataRemoved(QModelIndex parent, int start, int end);
81 81 void barsetChanged();
82 82
83 83 protected:
84 84 BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good.
85 85
86 86 QAbstractItemModel* m_model;
87 87 int m_mapCategories;
88 88 int m_mapBarBottom;
89 89 int m_mapBarTop;
90 90 int m_mapFirst;
91 91 int m_mapCount;
92 92 Qt::Orientation m_mapOrientation;
93 93 };
94 94
95 95 QTCOMMERCIALCHART_END_NAMESPACE
96 96
97 97 #endif // BARSERIES_H
@@ -1,35 +1,35
1 1 #ifndef CHART_H_
2 2 #define CHART_H_
3 3
4 4 #include "qchartglobal.h"
5 5 #include <QRect>
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 class ChartAnimator;
10 10 class ChartPresenter;
11 11
12 12 class Chart: public QObject
13 13 {
14 14 Q_OBJECT
15 15 public:
16 16 explicit Chart(ChartPresenter *presenter);
17 17
18 public slots:
18 public Q_SLOTS:
19 19 virtual void handleGeometryChanged(const QRectF& rect);
20 20 virtual void handleDomainChanged(qreal minX,qreal maxX,qreal minY,qreal maxY);
21 21 virtual void rangeXChanged(qreal min, qreal max, int tickXCount);
22 22 virtual void rangeYChanged(qreal min, qreal max, int tickYCount);
23 23
24 24 void setAnimator(ChartAnimator* animator);
25 25 ChartAnimator* animator() const;
26 26 ChartPresenter* presenter() const;
27 27
28 28 private:
29 29 ChartAnimator* m_animator;
30 30 ChartPresenter* m_presenter;
31 31 };
32 32
33 33 QTCOMMERCIALCHART_END_NAMESPACE
34 34
35 35 #endif
@@ -1,88 +1,88
1 1 #ifndef CHARTPRESENTER_H_
2 2 #define CHARTPRESENTER_H_
3 3
4 4 #include "qchartglobal.h"
5 5 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
6 6 #include "qchartaxis.h"
7 7 #include <QRectF>
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 class Chart;
12 12 class QSeries;
13 13 class ChartDataSet;
14 14 class Domain;
15 15 class Axis;
16 16 class ChartTheme;
17 17 class ChartAnimator;
18 18
19 19 class ChartPresenter: public QObject
20 20 {
21 21 Q_OBJECT
22 22 public:
23 23 enum ZValues {
24 24 BackgroundZValue = -1,
25 25 ShadesZValue,
26 26 GridZValue,
27 27 LineChartZValue,
28 28 BarSeriesZValue,
29 29 ScatterSeriesZValue,
30 30 PieSeriesZValue,
31 31 AxisZValue,
32 32 LegendZValue
33 33 };
34 34
35 35 ChartPresenter(QChart* chart,ChartDataSet *dataset);
36 36 virtual ~ChartPresenter();
37 37
38 38 int padding() const { return m_padding; }
39 39 int backgroundPadding() const { return m_backgroundPadding; }
40 40 QRectF geometry() const { return m_rect; }
41 41 ChartAnimator* animator() const { return m_animator; }
42 42 ChartTheme *chartTheme() const { return m_chartTheme; }
43 43 ChartDataSet *dataSet() const { return m_dataset; }
44 44 QGraphicsItem* rootItem() const { return m_chart; }
45 45
46 46 void setTheme(QChart::ChartTheme theme,bool force = true);
47 47 QChart::ChartTheme theme();
48 48
49 49 void setAnimationOptions(QChart::AnimationOptions options);
50 50 QChart::AnimationOptions animationOptions() const;
51 51
52 52 void zoomIn();
53 53 void zoomIn(const QRectF& rect);
54 54 void zoomOut();
55 55 void scroll(int dx,int dy);
56 56
57 57 private:
58 58 void createConnections();
59 59 void resetAllElements();
60 60
61 public slots:
61 public Q_SLOTS:
62 62 void handleSeriesAdded(QSeries* series,Domain* domain);
63 63 void handleSeriesRemoved(QSeries* series);
64 64 void handleAxisAdded(QChartAxis* axis,Domain* domain);
65 65 void handleAxisRemoved(QChartAxis* axis);
66 66 void handleGeometryChanged();
67 67
68 signals:
68 Q_SIGNALS:
69 69 void geometryChanged(const QRectF& rect);
70 70
71 71 private:
72 72 QChart* m_chart;
73 73 ChartAnimator* m_animator;
74 74 ChartDataSet* m_dataset;
75 75 ChartTheme *m_chartTheme;
76 76 QMap<QSeries*,Chart*> m_chartItems;
77 77 QMap<QChartAxis*,Axis*> m_axisItems;
78 78 QRectF m_rect;
79 79 QChart::AnimationOptions m_options;
80 80 bool m_themeForce;
81 81 int m_padding;
82 82 int m_backgroundPadding;
83 83
84 84 };
85 85
86 86 QTCOMMERCIALCHART_END_NAMESPACE
87 87
88 88 #endif /* CHARTPRESENTER_H_ */
@@ -1,71 +1,71
1 1 #ifndef DOMAIN_H_
2 2 #define DOMAIN_H_
3 3 #include "qchartglobal.h"
4 4 #include <QRectF>
5 5 #include <QSizeF>
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 class Domain: public QObject {
10 10 Q_OBJECT
11 11 public:
12 12 explicit Domain(QObject* object=0);
13 13 virtual ~Domain();
14 14
15 15 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
16 16 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY, int tickXCount, int tickYCount);
17 17 void setRangeX(qreal min, qreal max);
18 18 void setRangeX(qreal min, qreal max, int tickCount);
19 19 void setRangeY(qreal min, qreal max);
20 20 void setRangeY(qreal min, qreal max, int tickCount);
21 21 void setMinX(qreal min);
22 22 void setMaxX(qreal max);
23 23 void setMinY(qreal min);
24 24 void setMaxY(qreal max);
25 25
26 26 qreal minX() const { return m_minX; }
27 27 qreal maxX() const { return m_maxX; }
28 28 qreal minY() const { return m_minY; }
29 29 qreal maxY() const { return m_maxY; }
30 30
31 31 qreal spanX() const;
32 32 qreal spanY() const;
33 33 bool isEmpty() const;
34 34
35 35 int tickXCount() const {return m_tickXCount;}
36 36 int tickYCount() const {return m_tickYCount;}
37 37
38 38 friend bool operator== (const Domain &domain1, const Domain &domain2);
39 39 friend bool operator!= (const Domain &domain1, const Domain &domain2);
40 40 friend QDebug operator<<(QDebug dbg, const Domain &domain);
41 41
42 42 void zoomIn(const QRectF& rect, const QSizeF& size);
43 43 void zoomOut(const QRectF& rect, const QSizeF& size);
44 44 void move(int dx,int dy,const QSizeF& size);
45 45
46 signals:
46 Q_SIGNALS:
47 47 void domainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
48 48 void rangeXChanged(qreal min, qreal max, int tickXCount);
49 49 void rangeYChanged(qreal min, qreal max, int tickYCount);
50 50
51 public slots:
51 public Q_SLOTS:
52 52 void handleAxisXChanged(qreal min,qreal max,int tickXCount = 5,bool niceNumbers = false);
53 53 void handleAxisYChanged(qreal min,qreal max,int tickYCount = 5,bool niceNumbers = false);
54 54
55 55 private:
56 56 void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount);
57 57 qreal niceNumber(qreal x,bool celing);
58 58
59 59 private:
60 60 qreal m_minX;
61 61 qreal m_maxX;
62 62 qreal m_minY;
63 63 qreal m_maxY;
64 64 int m_tickXCount;
65 65 int m_tickYCount;
66 66 bool m_niceNumbers;
67 67 };
68 68
69 69 QTCOMMERCIALCHART_END_NAMESPACE
70 70
71 71 #endif
@@ -1,38 +1,38
1 1 #ifndef LEGENDSCROLLBUTTON_P_H
2 2 #define LEGENDSCROLLBUTTON_P_H
3 3
4 4 #include <QObject>
5 5 #include <qchartglobal.h>
6 6 #include <QGraphicsPolygonItem>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class LegendScrollButton : public QObject, public QGraphicsPolygonItem
11 11 {
12 12 Q_OBJECT
13 13 public:
14 14 enum ScrollButtonId {
15 15 ScrollButtonIdLeft,
16 16 ScrollButtonIdRight,
17 17 ScrollButtonIdUp,
18 18 ScrollButtonIdDown
19 19 };
20 20
21 21 explicit LegendScrollButton(ScrollButtonId id, QGraphicsItem *parent = 0);
22 22 ScrollButtonId id();
23 23
24 24 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
25 25
26 signals:
26 Q_SIGNALS:
27 27 void clicked(QGraphicsSceneMouseEvent* event);
28 28
29 public slots:
29 public Q_SLOTS:
30 30
31 31 private:
32 32
33 33 ScrollButtonId mId;
34 34 };
35 35
36 36 QTCOMMERCIALCHART_END_NAMESPACE
37 37
38 38 #endif // LEGENDSCROLLBUTTON_P_H
@@ -1,44 +1,44
1 1 #ifndef LINECHARTITEM_H
2 2 #define LINECHARTITEM_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include "xychartitem_p.h"
6 6 #include <QPen>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class QLineSeries;
11 11 class ChartPresenter;
12 12
13 13 class LineChartItem : public XYChartItem
14 14 {
15 15 Q_OBJECT
16 16 public:
17 17 explicit LineChartItem(QLineSeries *series,ChartPresenter *presenter);
18 18 ~LineChartItem() {};
19 19
20 20 //from QGraphicsItem
21 21 QRectF boundingRect() const;
22 22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23 23 QPainterPath shape() const;
24 24
25 public slots:
25 public Q_SLOTS:
26 26 void handleUpdated();
27 27
28 28 protected:
29 29 void setLayout(QVector<QPointF>& points);
30 30
31 31 private:
32 32 QLineSeries* m_series;
33 33 QGraphicsItemGroup m_items;
34 34 QPainterPath m_path;
35 35 QRectF m_rect;
36 36 QPen m_linePen;
37 37 QPen m_pointPen;
38 38 bool m_pointsVisible;
39 39
40 40 };
41 41
42 42 QTCOMMERCIALCHART_END_NAMESPACE
43 43
44 44 #endif
@@ -1,111 +1,111
1 1 #ifndef QLEGEND_H
2 2 #define QLEGEND_H
3 3
4 4 #include <qchartglobal.h>
5 5 #include <QGraphicsObject>
6 6 #include <QPen>
7 7 #include <QBrush>
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 class Domain;
12 12 class LegendMarker;
13 13 class QPieSlice;
14 14 class QXYSeries;
15 15 class QBarSet;
16 16 class QBarSeries;
17 17 class QPieSeries;
18 18 class LegendScrollButton;
19 19 class QSeries;
20 20
21 21 // TODO: This as widget
22 22 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsObject
23 23 {
24 24 Q_OBJECT
25 25 public:
26 26
27 27 // We only support these alignments (for now)
28 28 enum Layout {
29 29 LayoutTop = Qt::AlignTop,
30 30 LayoutBottom = Qt::AlignBottom,
31 31 LayoutLeft = Qt::AlignLeft,
32 32 LayoutRight = Qt::AlignRight
33 33 };
34 34
35 35 explicit QLegend(QGraphicsItem *parent = 0);
36 36
37 37 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
38 38 QRectF boundingRect() const;
39 39
40 40 void setBrush(const QBrush &brush);
41 41 QBrush brush() const;
42 42
43 43 void setPen(const QPen &pen);
44 44 QPen pen() const;
45 45
46 46 void setAlignmnent(QLegend::Layout alignment);
47 47 QLegend::Layout alignment() const;
48 48
49 49 QSizeF maximumSize() const;
50 50 void setMaximumSize(const QSizeF size);
51 51
52 52 QSizeF size() const;
53 53 void setSize(const QSizeF size);
54 54 void setPos(const QPointF &pos);
55 55
56 signals:
56 Q_SIGNALS:
57 57 // for interactions.
58 58 void clicked(QSeries *series, Qt::MouseButton button);
59 59 void clicked(QBarSet *barset, Qt::MouseButton button);
60 60 void clicked(QPieSlice *slice, Qt::MouseButton button);
61 61
62 public slots:
62 public Q_SLOTS:
63 63 // PIMPL --->
64 64 void handleSeriesAdded(QSeries *series, Domain *domain);
65 65 void handleSeriesRemoved(QSeries *series);
66 66 void handleAdded(QList<QPieSlice *> slices);
67 67 void handleRemoved(QList<QPieSlice *> slices);
68 68 void handleMarkerDestroyed();
69 69 void handleScrollButtonClicked(QGraphicsSceneMouseEvent *event);
70 70 // PIMPL <---
71 71
72 72 private:
73 73 // PIMPL --->
74 74 void connectSeries(QSeries *series);
75 75 void disconnectSeries(QSeries *series);
76 76 void createMarkers(QSeries *series);
77 77 void appendMarkers(QXYSeries *series); // All line series are derived from QXYSeries, so this works for now
78 78 void appendMarkers(QBarSeries *series);
79 79 void appendMarkers(QPieSeries *series);
80 80 void deleteMarkers(QSeries *series);
81 81 void updateLayout();
82 82 void rescaleScrollButtons(const QSize &size);
83 83 QSizeF maximumMarkerSize();
84 84 void checkFirstMarkerBounds();
85 85 bool scrollButtonsVisible();
86 86
87 87 QPointF m_pos;
88 88 QSizeF m_size;
89 89 QSizeF m_minimumSize;
90 90 QSizeF m_maximumSize;
91 91
92 92 QList<LegendMarker *> m_markers;
93 93
94 94 QBrush m_brush;
95 95 QPen m_pen;
96 96 QLegend::Layout m_alignment;
97 97
98 98 int mFirstMarker;
99 99
100 100 LegendScrollButton *m_scrollButtonLeft;
101 101 LegendScrollButton *m_scrollButtonRight;
102 102 LegendScrollButton *m_scrollButtonUp;
103 103 LegendScrollButton *m_scrollButtonDown;
104 104
105 105 qreal m_margin;
106 106 // <--- PIMPL
107 107 };
108 108
109 109 QTCOMMERCIALCHART_END_NAMESPACE
110 110
111 111 #endif // QLEGEND_H
@@ -1,120 +1,120
1 1 #ifndef SCATTERPRESENTER_H
2 2 #define SCATTERPRESENTER_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include "xychartitem_p.h"
6 6 #include <QGraphicsEllipseItem>
7 7 #include <QPen>
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 class QScatterSeries;
12 12 class Marker;
13 13
14 14 class ScatterChartItem : public XYChartItem
15 15 {
16 16 Q_OBJECT
17 17 public:
18 18 explicit ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter);
19 19
20 20 public:
21 21 //from QGraphicsItem
22 22 QRectF boundingRect() const;
23 23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
24 24
25 25 void setPen(const QPen &pen);
26 26 void setBrush(const QBrush &brush);
27 27
28 28 void markerSelected(Marker *item);
29 29
30 public slots:
30 public Q_SLOTS:
31 31 void handleUpdated();
32 32
33 33 private:
34 34 void createPoints(int count);
35 35 void deletePoints(int count);
36 36
37 37 protected:
38 38 void setLayout(QVector<QPointF> &points);
39 39
40 40 private:
41 41 QScatterSeries *m_series;
42 42 QGraphicsItemGroup m_items;
43 43 int m_shape;
44 44 int m_size;
45 45 QRectF m_rect;
46 46
47 47 };
48 48
49 49
50 50 class Marker: public QAbstractGraphicsShapeItem
51 51 {
52 52
53 53 public:
54 54
55 55 Marker(QAbstractGraphicsShapeItem *item , ScatterChartItem *parent) : QAbstractGraphicsShapeItem(0) ,m_item(item), m_parent(parent)
56 56 {
57 57 };
58 58
59 59 ~Marker()
60 60 {
61 61 delete m_item;
62 62 }
63 63
64 64 void setIndex(int index)
65 65 {
66 66 m_index=index;
67 67 }
68 68
69 69 int index() const
70 70 {
71 71 return m_index;
72 72 }
73 73
74 74 QPainterPath shape() const
75 75 {
76 76 return m_item->shape();
77 77 }
78 78
79 79 QRectF boundingRect() const
80 80 {
81 81 return m_item->boundingRect();
82 82 }
83 83
84 84 bool contains(const QPointF &point) const
85 85 {
86 86 return m_item->contains(point);
87 87 }
88 88
89 89 void setPen(const QPen &pen)
90 90 {
91 91 m_item->setPen(pen);
92 92 }
93 93
94 94 void setBrush(const QBrush &brush)
95 95 {
96 96 m_item->setBrush(brush);
97 97 }
98 98
99 99 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
100 100 {
101 101 m_item->paint(painter,option,widget);
102 102 }
103 103
104 104 protected:
105 105
106 106 void mousePressEvent(QGraphicsSceneMouseEvent *event)
107 107 {
108 108 Q_UNUSED(event)
109 109 m_parent->markerSelected(this);
110 110 }
111 111
112 112 private:
113 113 QAbstractGraphicsShapeItem* m_item;
114 114 ScatterChartItem* m_parent;
115 115 int m_index;
116 116 };
117 117
118 118 QTCOMMERCIALCHART_END_NAMESPACE
119 119
120 120 #endif // SCATTERPRESENTER_H
@@ -1,47 +1,47
1 1 #ifndef QSPLINESERIES_H
2 2 #define QSPLINESERIES_H
3 3
4 4 #include <qchartglobal.h>
5 5 #include <qlineseries.h>
6 6 #include <QList>
7 7 #include <QPointF>
8 8 #include <QtGlobal>
9 9
10 10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 11
12 12 class QTCOMMERCIALCHART_EXPORT QSplineSeries : public QLineSeries
13 13 {
14 14 Q_OBJECT
15 15 public:
16 16
17 17 QSplineSeries(QObject *parent = 0);
18 18 QSeriesType type() const {return QSeries::SeriesTypeSpline;}
19 19
20 20 // int count() const { return m_x.size(); }
21 21 QPointF controlPoint(int index) const {return m_controlPoints[index];}
22 22 bool setModel(QAbstractItemModel *model);
23 23
24 24 void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
25 25 void setModelMappingShift(int first, int count);
26 26
27 27 // TODO: allow the user to set custom control points
28 28 // void setCustomControlPoints(QList<QPointsF> controlPoints);
29 29 // bool calculateControlPointsAutomatically();
30 30 // void setCalculateControlPointsAutomatically();
31 31
32 32
33 33 private:
34 34 void calculateControlPoints();
35 35 QList<qreal> getFirstControlPoints(QList<qreal> rhs);
36 36
37 private slots:
37 private Q_SLOTS:
38 38 void updateControlPoints();
39 39
40 40 private:
41 41 QList<QPointF> m_controlPoints;
42 42
43 43 };
44 44
45 45 QTCOMMERCIALCHART_END_NAMESPACE
46 46
47 47 #endif // QSPLINESERIES_H
@@ -1,44 +1,44
1 1 #ifndef SPLINECHARTITEM_P_H
2 2 #define SPLINECHARTITEM_P_H
3 3
4 4 #include "qsplineseries.h"
5 5 #include "xychartitem_p.h"
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 class SplineChartItem : public XYChartItem
10 10 {
11 11 Q_OBJECT
12 12 public:
13 13 SplineChartItem(QSplineSeries *series, ChartPresenter *presenter);
14 14
15 15 //from QGraphicsItem
16 16 QRectF boundingRect() const;
17 17 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
18 18 QPainterPath shape() const;
19 19
20 public slots:
20 public Q_SLOTS:
21 21 void handleUpdated();
22 22
23 23 protected:
24 24 void setLayout(QVector<QPointF> &points,QVector<QPointF> &controlPoints);
25 25 void updateLayout(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index);
26 26
27 27 private:
28 28 QPointF calculateGeometryControlPoint(int index) const;
29 29
30 30 private:
31 31 QSplineSeries* m_series;
32 32 QPainterPath m_path;
33 33 QRectF m_rect;
34 34 QPen m_linePen;
35 35 QPen m_pointPen;
36 36 bool m_pointsVisible;
37 37 QVector<QPointF> m_controlPoints;
38 38
39 39 friend class SplineAnimation;
40 40 };
41 41
42 42 QTCOMMERCIALCHART_END_NAMESPACE
43 43
44 44 #endif // SPLINECHARTITEM_P_H
@@ -1,80 +1,80
1 1 #ifndef QXYSERIES_H_
2 2 #define QXYSERIES_H_
3 3
4 4 #include <qchartglobal.h>
5 5 #include <qseries.h>
6 6 #include <QPen>
7 7 #include <QBrush>
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries
12 12 {
13 13 Q_OBJECT
14 14 protected:
15 15 QXYSeries(QObject *parent = 0);
16 16 virtual ~QXYSeries();
17 17
18 18 public:
19 19 void add(qreal x, qreal y);
20 20 void add(const QPointF &point);
21 21 void add(const QList<QPointF> points);
22 22 void replace(qreal x,qreal y);
23 23 void replace(const QPointF &point);
24 24 void remove(qreal x);
25 25 void remove(qreal x, qreal y);
26 26 void remove(const QPointF &point);
27 27 void removeAll();
28 28
29 29 int count() const;
30 30 qreal x(int pos) const;
31 31 qreal y(int pos) const;
32 32 QList<QPointF> data();
33 33
34 34 QXYSeries& operator << (const QPointF &point);
35 35 QXYSeries& operator << (const QList<QPointF> points);
36 36
37 37 void setPen(const QPen &pen);
38 38 QPen pen() const {return m_pen;}
39 39 void setBrush(const QBrush &brush);
40 40 QBrush brush() const {return m_brush;}
41 41
42 42 bool setModel(QAbstractItemModel *model);
43 43 QAbstractItemModel* model() { return m_model; }
44 44
45 45 virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
46 46 virtual void setModelMappingShift(int first, int count = 0);
47 47
48 private slots:
48 private Q_SLOTS:
49 49 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
50 50 void modelDataAboutToBeAdded(QModelIndex parent, int start, int end);
51 51 void modelDataAdded(QModelIndex parent, int start, int end);
52 52 void modelDataAboutToBeRemoved(QModelIndex parent, int start, int end);
53 53 void modelDataRemoved(QModelIndex parent, int start, int end);
54 54
55 signals:
55 Q_SIGNALS:
56 56 void clicked(const QPointF &point);
57 57 void updated();
58 58 void pointReplaced(int index);
59 59 void pointRemoved(int index);
60 60 void pointAdded(int index);
61 61
62 62 protected:
63 63 QVector<qreal> m_x;
64 64 QVector<qreal> m_y;
65 65
66 66 QPen m_pen;
67 67 QBrush m_brush;
68 68
69 69 int m_mapX;
70 70 int m_mapY;
71 71 int m_mapFirst;
72 72 int m_mapCount;
73 73 bool m_mapLimited;
74 74 Qt::Orientation m_mapOrientation;
75 75 int tempItemsRemoved;
76 76 };
77 77
78 78 QTCOMMERCIALCHART_END_NAMESPACE
79 79
80 80 #endif
@@ -1,65 +1,65
1 1 #ifndef XYCHARTITEM_H
2 2 #define XYCHARTITEM_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include "chartitem_p.h"
6 6 #include <QPen>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class ChartPresenter;
11 11 class QXYSeries;
12 12
13 13 class XYChartItem : public ChartItem
14 14 {
15 15 Q_OBJECT
16 16 public:
17 17 explicit XYChartItem(QXYSeries *series, ChartPresenter *presenter);
18 18 ~XYChartItem(){};
19 19
20 20 QVector<QPointF> points() const {return m_points;}
21 21 QRectF clipRect() const { return m_clipRect;}
22 22
23 23
24 public slots:
24 public Q_SLOTS:
25 25 void handlePointAdded(int index);
26 26 void handlePointRemoved(int index);
27 27 void handlePointReplaced(int index);
28 28 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
29 29 void handleGeometryChanged(const QRectF &size);
30 30
31 signals:
31 Q_SIGNALS:
32 32 void clicked(const QPointF& point);
33 33
34 34 protected:
35 35
36 36 virtual void setLayout(QVector<QPointF> &points);
37 37 virtual void updateLayout(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = 0);
38 38
39 39 QPointF calculateGeometryPoint(const QPointF &point) const;
40 40 QPointF calculateGeometryPoint(int index) const;
41 41 QPointF calculateDomainPoint(const QPointF &point) const;
42 42 QVector<QPointF> calculateGeometryPoints() const;
43 43 void mousePressEvent(QGraphicsSceneMouseEvent *event);
44 44
45 45 private:
46 46 inline bool isEmpty();
47 47
48 48 private:
49 49 qreal m_minX;
50 50 qreal m_maxX;
51 51 qreal m_minY;
52 52 qreal m_maxY;
53 53 QXYSeries* m_series;
54 54 QSizeF m_size;
55 55 QRectF m_clipRect;
56 56 QVector<QPointF> m_points;
57 57
58 58 friend class XYAnimation;
59 59 friend class AreaChartItem;
60 60
61 61 };
62 62
63 63 QTCOMMERCIALCHART_END_NAMESPACE
64 64
65 65 #endif
General Comments 0
You need to be logged in to leave comments. Login now