##// END OF EJS Templates
Removes obsolete functions...
Michal Klocek -
r141:c4fe96eff980
parent child
Show More
@@ -1,73 +1,68
1 1 #ifndef AXISITEM_H_
2 2 #define AXISITEM_H_
3 3
4 4 #include "domain_p.h"
5 5 #include "chartitem_p.h"
6 6 #include <QGraphicsItem>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class QChartAxis;
11 11
12 12 class AxisItem : public QObject, public ChartItem
13 13 {
14 14 Q_OBJECT
15 15 public:
16 16 enum AxisType{X_AXIS,Y_AXIS};
17 17
18 18 AxisItem(QChartAxis* axis,AxisType type = X_AXIS,QGraphicsItem* parent = 0);
19 19 ~AxisItem();
20 20
21 21 //from QGraphicsItem
22 22 QRectF boundingRect() const;
23 23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
24 24
25 25 protected slots:
26 26 void handleAxisChanged();
27 27 void handleDomainChanged(const Domain& domain);
28 28 void handleGeometryChanged(const QRectF& size);
29 29
30 30 protected:
31 31 void updateDomain();
32 32
33 33 private:
34 34 void clear();
35 35
36
37 public: // from ChartItem
38 void setSize(const QSizeF &size){};
39 void setPlotDomain(const PlotDomain& data){};
40
41 36 public:
42 37 void setLength(int length);
43 38 void setWidth(int width);
44 39 AxisType axisType() const {return m_type;};
45 40
46 41 protected:
47 42
48 43
49 44 private:
50 45 void createItems();
51 46 private:
52 47
53 48 QChartAxis* m_axis;
54 49 AxisType m_type;
55 50 int m_ticks;
56 51 Domain m_domain;
57 52
58 53
59 54
60 55 QRectF m_rect;
61 56
62 57 QPainterPath m_path;
63 58
64 59
65 60 QList<QGraphicsLineItem*> m_grid;
66 61 QList<QGraphicsRectItem*> m_shades;
67 62 QList<QGraphicsSimpleTextItem*> m_labels;
68 63
69 64 };
70 65
71 66 QTCOMMERCIALCHART_END_NAMESPACE
72 67
73 68 #endif /* AXISITEM_H_ */
@@ -1,30 +1,22
1 1 #ifndef CHARTITEM_H_
2 2 #define CHARTITEM_H_
3 3
4 4 #include "plotdomain_p.h"
5 5 #include "domain_p.h"
6 6 #include <QGraphicsItem>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class ChartAnimationManager;
11 11
12 12 class ChartItem : public QGraphicsItem
13 13 {
14 14 enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM};
15 15 public:
16 16 ChartItem(QGraphicsItem* parent = 0):QGraphicsItem(parent){};
17 17 virtual ~ChartItem(){};
18
19 virtual void setSize(const QSizeF& size) = 0;
20 virtual void setPlotDomain(const PlotDomain& data) = 0;
21
22 //future interface
23 virtual void setDomain(const Domain& data){};
24 virtual void updateItem(){};
25 virtual ChartAnimationManager* animationManager(){ return 0;};
26 18 };
27 19
28 20 QTCOMMERCIALCHART_END_NAMESPACE
29 21
30 22 #endif /* CHARTITEM_H_ */
@@ -1,231 +1,226
1 1 #include "qchart.h"
2 2 #include "qchartseries.h"
3 3 #include "qscatterseries.h"
4 4 #include "qscatterseries_p.h"
5 5 #include "qpieseries.h"
6 6 #include "qpieseries_p.h"
7 7 #include "qchartaxis.h"
8 8 #include "charttheme_p.h"
9 9 #include "chartitem_p.h"
10 10 #include "plotdomain_p.h"
11 11 #include "axisitem_p.h"
12 12 #include "chartpresenter_p.h"
13 13 #include "chartdataset_p.h"
14 14
15 15 //series
16 16 #include "barchartseries.h"
17 17 #include "stackedbarchartseries.h"
18 18 #include "percentbarchartseries.h"
19 19 #include "qxychartseries.h"
20 20
21 21
22 22 #include <QGraphicsScene>
23 23 #include <QGraphicsSceneResizeEvent>
24 24 #include <QDebug>
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
29 29 m_backgroundItem(0),
30 30 m_titleItem(0),
31 31 m_axisXItem(0),
32 m_plotDataIndex(0),
33 32 m_chartTheme(new ChartTheme(this)),
34 33 //m_dataset(0),
35 34 m_dataset(new ChartDataSet(this)),
36 35 //m_presenter(0)
37 36 m_presenter(new ChartPresenter(this,m_dataset))
38 37 {
39 38 // TODO: the default theme?
40 39 setTheme(QChart::ChartThemeDefault);
41
42 PlotDomain domain;
43 m_plotDomainList << domain;
44
45 40 //m_chartItems << m_axisXItem;
46 41 //m_chartItems << m_axisYItem.at(0);
47 42 }
48 43
49 44 QChart::~QChart(){}
50 45
51 46 void QChart::addSeries(QChartSeries* series)
52 47 {
53 48 m_dataset->addSeries(series);
54 49 }
55 50
56 51 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
57 52 {
58 53 // TODO: support also other types; not only scatter and pie
59 54
60 55 QChartSeries *series(0);
61 56
62 57 switch (type) {
63 58 case QChartSeries::SeriesTypeLine: {
64 59 series = QXYChartSeries::create();
65 60 break;
66 61 }
67 62 case QChartSeries::SeriesTypeBar: {
68 63 series = new BarChartSeries(this);
69 64 break;
70 65 }
71 66 case QChartSeries::SeriesTypeStackedBar: {
72 67 series = new StackedBarChartSeries(this);
73 68 break;
74 69 }
75 70 case QChartSeries::SeriesTypePercentBar: {
76 71 series = new PercentBarChartSeries(this);
77 72 break;
78 73 }
79 74 case QChartSeries::SeriesTypeScatter: {
80 75 series = new QScatterSeries(this);
81 76 break;
82 77 }
83 78 case QChartSeries::SeriesTypePie: {
84 79 series = new QPieSeries(this);
85 80 break;
86 81 }
87 82 default:
88 83 Q_ASSERT(false);
89 84 break;
90 85 }
91 86
92 87 addSeries(series);
93 88 return series;
94 89 }
95 90
96 91 void QChart::setChartBackgroundBrush(const QBrush& brush)
97 92 {
98 93
99 94 if(!m_backgroundItem){
100 95 m_backgroundItem = new QGraphicsRectItem(this);
101 96 m_backgroundItem->setZValue(-1);
102 97 }
103 98
104 99 m_backgroundItem->setBrush(brush);
105 100 m_backgroundItem->update();
106 101 }
107 102
108 103 void QChart::setChartBackgroundPen(const QPen& pen)
109 104 {
110 105
111 106 if(!m_backgroundItem){
112 107 m_backgroundItem = new QGraphicsRectItem(this);
113 108 m_backgroundItem->setZValue(-1);
114 109 }
115 110
116 111 m_backgroundItem->setPen(pen);
117 112 m_backgroundItem->update();
118 113 }
119 114
120 115 void QChart::setTitle(const QString& title,const QFont& font)
121 116 {
122 117 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
123 118 m_titleItem->setPlainText(title);
124 119 m_titleItem->setFont(font);
125 120 }
126 121
127 122 int QChart::margin() const
128 123 {
129 124 m_presenter->margin();
130 125 }
131 126
132 127 void QChart::setMargin(int margin)
133 128 {
134 129 m_presenter->setMargin(margin);
135 130 }
136 131
137 132 void QChart::setTheme(QChart::ChartThemeId theme)
138 133 {
139 134 m_chartTheme->setTheme(theme);
140 135
141 136 QLinearGradient backgroundGradient;
142 137 backgroundGradient.setColorAt(0.0, m_chartTheme->d->m_gradientStartColor);
143 138 backgroundGradient.setColorAt(1.0, m_chartTheme->d->m_gradientEndColor);
144 139 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
145 140 setChartBackgroundBrush(backgroundGradient);
146 141
147 142 // TODO: Move the controlling of the series presentations into private implementation of the
148 143 // series instead of QChart controlling themes for each
149 144 // In other words, the following should be used when creating xy series:
150 145 // m_chartTheme->addObserver(xyseries)
151 146 foreach (QChartSeries *series, m_chartSeries) {
152 147 if (series->type() == QChartSeries::SeriesTypeLine) {
153 148 QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series);
154 149 SeriesTheme seriesTheme = m_chartTheme->themeForSeries();
155 150 xyseries->setPen(seriesTheme.linePen);
156 151 }
157 152 }
158 153
159 154 update();
160 155 }
161 156
162 157 QChart::ChartThemeId QChart::theme()
163 158 {
164 159 return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme;
165 160 }
166 161
167 162 void QChart::zoomInToRect(const QRectF& rectangle)
168 163 {
169 164 m_presenter->zoomInToRect(rectangle);
170 165 }
171 166
172 167 void QChart::zoomIn()
173 168 {
174 169 m_presenter->zoomIn();
175 170 }
176 171
177 172 void QChart::zoomOut()
178 173 {
179 174 m_presenter->zoomOut();
180 175 }
181 176
182 177 void QChart::zoomReset()
183 178 {
184 179 m_presenter->zoomReset();
185 180 }
186 181
187 182 void QChart::setAxisX(const QChartAxis& axis)
188 183 {
189 184 setAxis(m_axisXItem,axis);
190 185 }
191 186 void QChart::setAxisY(const QChartAxis& axis)
192 187 {
193 188 setAxis(m_axisYItem.at(0),axis);
194 189 }
195 190
196 191 void QChart::setAxisY(const QList<QChartAxis>& axis)
197 192 {
198 193 //TODO not implemented
199 194 }
200 195
201 196 void QChart::setAxis(AxisItem *item, const QChartAxis& axis)
202 197 {
203 198 item->setVisible(axis.isAxisVisible());
204 199 }
205 200
206 201 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
207 202 {
208 203
209 204 m_rect = QRectF(QPoint(0,0),event->newSize());
210 205 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
211 206
212 207 // recalculate title position
213 208 if (m_titleItem) {
214 209 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
215 210 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
216 211 }
217 212
218 213 //recalculate background gradient
219 214 if (m_backgroundItem) {
220 215 m_backgroundItem->setRect(rect);
221 216 }
222 217
223 218 QGraphicsWidget::resizeEvent(event);
224 219 update();
225 220 }
226 221
227 222
228 223
229 224 #include "moc_qchart.cpp"
230 225
231 226 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,101 +1,99
1 1 #ifndef CHART_H
2 2 #define CHART_H
3 3
4 4 #include <qchartglobal.h>
5 5 #include <qchartseries.h>
6 6 #include <QGraphicsWidget>
7 7 #include <QLinearGradient>
8 8 #include <QFont>
9 9
10 10 class QGraphicsSceneResizeEvent;
11 11
12 12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13 13
14 14 class AxisItem;
15 15 class QChartSeries;
16 16 class PlotDomain;
17 17 class BarGroup;
18 18 class QChartAxis;
19 19 class ChartTheme;
20 20 class ChartItem;
21 21 class ChartDataSet;
22 22 class ChartPresenter;
23 23
24 24 // TODO: We don't need to have QChart tied to QGraphicsItem:
25 25 //class QTCOMMERCIALCHART_EXPORT QChart
26 26 //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem {
27 27 // public: QChartGraphicsItem(QChart &chart);
28 28
29 29 /*!
30 30 * TODO: define the responsibilities
31 31 */
32 32 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
33 33 {
34 34 Q_OBJECT
35 35 public:
36 36 enum ChartThemeId {
37 37 ChartThemeInvalid = -1,
38 38 /*! The default theme follows the GUI style of the Operating System */
39 39 ChartThemeDefault,
40 40 ChartThemeVanilla,
41 41 ChartThemeIcy,
42 42 ChartThemeGrayscale,
43 43 ChartThemeScientific,
44 44 ChartThemeUnnamed1
45 45 };
46 46
47 47 public:
48 48 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
49 49 ~QChart();
50 50
51 51 void addSeries(QChartSeries* series);
52 52
53 53 //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type);
54 54 // TODO: who owns the series now? maybe owned by chart and returned a reference instead...
55 55 QChartSeries* createSeries(QChartSeries::QChartSeriesType type);
56 56
57 57 void setMargin(int margin);
58 58 int margin() const;
59 59 void setTheme(QChart::ChartThemeId theme);
60 60 QChart::ChartThemeId theme();
61 61
62 62 void setTitle(const QString& title,const QFont& font = QFont());
63 63 void setChartBackgroundBrush(const QBrush& brush);
64 64 void setChartBackgroundPen(const QPen& pen);
65 65
66 66 void zoomInToRect(const QRectF& rectangle);
67 67 void zoomIn();
68 68 void zoomOut();
69 69 void zoomReset();
70 70
71 71 void setAxisX(const QChartAxis& axis);
72 72 void setAxisY(const QChartAxis& axis);
73 73 void setAxisY(const QList<QChartAxis>& axis);
74 74
75 75 protected:
76 76 void resizeEvent(QGraphicsSceneResizeEvent *event);
77 77
78 78 private:
79 79 void setAxis(AxisItem *item, const QChartAxis& axis);
80 80
81 81 private:
82 82 Q_DISABLE_COPY(QChart)
83 83 QGraphicsRectItem* m_backgroundItem;
84 84 QGraphicsTextItem* m_titleItem;
85 85 AxisItem* m_axisXItem;
86 86 QList<AxisItem*> m_axisYItem;
87 87 QRectF m_rect;
88 88 QList<QChartSeries *> m_chartSeries;
89 89 QList<ChartItem *> m_chartItems;
90 QVector<PlotDomain> m_plotDomainList;
91 int m_plotDataIndex;
92 90 ChartTheme *m_chartTheme;
93 91
94 92
95 93 ChartDataSet *m_dataset;
96 94 ChartPresenter *m_presenter;
97 95 };
98 96
99 97 QTCOMMERCIALCHART_END_NAMESPACE
100 98
101 99 #endif
General Comments 0
You need to be logged in to leave comments. Login now