##// END OF EJS Templates
Fix test application to have valid window size
Michal Klocek -
r147:ede69107bdd8
parent child
Show More
@@ -1,248 +1,249
1 1 #include "qchart.h"
2 2 #include "qchartaxis.h"
3 3 #include "chartpresenter_p.h"
4 4 #include "chartdataset_p.h"
5 5 #include "charttheme_p.h"
6 6 //series
7 7 #include "barchartseries.h"
8 8 #include "stackedbarchartseries.h"
9 9 #include "percentbarchartseries.h"
10 10 #include "qlinechartseries.h"
11 11 #include "qpieseries.h"
12 12 //items
13 13 #include "axisitem_p.h"
14 14 #include "bargroup.h"
15 15 #include "stackedbargroup.h"
16 16 #include "linechartitem_p.h"
17 17 #include "percentbargroup.h"
18 18 #include "linechartanimationitem_p.h"
19 19 #include "piepresenter.h"
20 20
21 21 QTCOMMERCIALCHART_BEGIN_NAMESPACE
22 22
23 23 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
24 24 m_chart(chart),
25 25 m_dataset(dataset),
26 26 m_chartTheme(0),
27 27 m_domainIndex(0),
28 28 m_marginSize(0),
29 29 m_rect(QRectF(QPoint(0,0),m_chart->size()))
30 30 {
31 31 setTheme(QChart::ChartThemeDefault);
32 32 createConnections();
33 33 createDeafultAxis();
34 34 }
35 35
36 36 ChartPresenter::~ChartPresenter()
37 37 {
38 38 }
39 39
40 40 void ChartPresenter::createDeafultAxis()
41 41 {
42 42 //default axis
43 43 QChartAxis* axisX = new QChartAxis(this);
44 44 QChartAxis* axisY = new QChartAxis(this);
45 45
46 46 m_axis << new AxisItem(axisX,AxisItem::X_AXIS,m_chart);
47 47 m_axis << new AxisItem(axisY,AxisItem::Y_AXIS,m_chart);
48 48
49 49 foreach(AxisItem* item, m_axis) {
50 50 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
51 51 QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
52 52 }
53 53 }
54 54
55 55 void ChartPresenter::createConnections()
56 56 {
57 57 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
58 58 QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*)));
59 59 }
60 60
61 61 void ChartPresenter::handleGeometryChanged()
62 62 {
63 63 m_rect = QRectF(QPoint(0,0),m_chart->size());
64 64 m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize);
65 Q_ASSERT(m_rect.isValid());
65 66 emit geometryChanged(m_rect);
66 67 }
67 68
68 69 int ChartPresenter::margin() const
69 70 {
70 71 return m_marginSize;
71 72 }
72 73
73 74 void ChartPresenter::setMargin(int margin)
74 75 {
75 76 m_marginSize = margin;
76 77 }
77 78
78 79 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
79 80 {
80 81 switch(series->type())
81 82 {
82 83 case QChartSeries::SeriesTypeLine: {
83 84 QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series);
84 85 LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart);
85 86 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
86 87 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
87 88 QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
88 89 QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
89 90 m_chartItems.insert(series,item);
90 91 break;
91 92 }
92 93
93 94 case QChartSeries::SeriesTypeBar: {
94 95 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
95 96 BarGroup* item = new BarGroup(*barSeries,m_chart);
96 97 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
97 98 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
98 99 QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
99 100 QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
100 101 m_chartItems.insert(series,item);
101 102 // m_axisXItem->setVisible(false);
102 103 break;
103 104 }
104 105
105 106 case QChartSeries::SeriesTypeStackedBar: {
106 107
107 108 StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
108 109 StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart);
109 110 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
110 111 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
111 112 QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
112 113 QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
113 114 m_chartItems.insert(series,item);
114 115 break;
115 116 }
116 117
117 118 case QChartSeries::SeriesTypePercentBar: {
118 119
119 120 PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series);
120 121 PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart);
121 122 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
122 123 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
123 124 QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
124 125 QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
125 126 m_chartItems.insert(series,item);
126 127 break;
127 128 }
128 129 /*
129 130 case QChartSeries::SeriesTypeScatter: {
130 131 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
131 132 scatterSeries->d->m_theme = m_chartTheme->themeForSeries();
132 133 scatterSeries->d->setParentItem(this);
133 134 scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
134 135 m_chartItems << scatterSeries->d;
135 136 m_chartTheme->addObserver(scatterSeries->d);
136 137
137 138 foreach (qreal x, scatterSeries->d->m_x) {
138 139 domain.m_minX = qMin(domain.m_minX, x);
139 140 domain.m_maxX = qMax(domain.m_maxX, x);
140 141 }
141 142 foreach (qreal y, scatterSeries->d->m_y) {
142 143 domain.m_minY = qMin(domain.m_minY, y);
143 144 domain.m_maxY = qMax(domain.m_maxY, y);
144 145 }
145 146
146 147 break;
147 148 }
148 149 */
149 150
150 151 case QChartSeries::SeriesTypePie: {
151 152 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
152 153 PiePresenter* pie = new PiePresenter(m_chart, pieSeries);
153 154 pieSeries->m_piePresenter = pie; // TODO: remove this pointer passing use signals&slots
154 155 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&)));
155 156 QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&)));
156 157 m_chartItems.insert(series, pie);
157 158 break;
158 159 }
159 160
160 161 default: {
161 162 qDebug()<< "Series type" << series->type() << "not implemented.";
162 163 break;
163 164 }
164 165 }
165 166 }
166 167
167 168 void ChartPresenter::handleSeriesChanged(QChartSeries* series)
168 169 {
169 170 //TODO:
170 171 }
171 172
172 173 void ChartPresenter::zoomInToRect(const QRectF& rect)
173 174 {
174 175 if(!rect.isValid()) return;
175 176 QRectF r = rect.normalized();
176 177 r.translate(-m_marginSize, -m_marginSize);
177 178 Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height()));
178 179 m_dataset->addDomain(domain);
179 180 }
180 181
181 182 void ChartPresenter::zoomIn()
182 183 {
183 184 if (!m_dataset->nextDomain()) {
184 185 QRectF rect = m_rect;
185 186 rect.setWidth(rect.width()/2);
186 187 rect.setHeight(rect.height()/2);
187 188 rect.moveCenter(m_rect.center());
188 189 Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height()));
189 190 m_dataset->addDomain(domain);
190 191 }
191 192 }
192 193
193 194 void ChartPresenter::zoomOut()
194 195 {
195 196 m_dataset->previousDomain();
196 197 }
197 198
198 199 void ChartPresenter::zoomReset()
199 200 {
200 201 m_dataset->clearDomains();
201 202 }
202 203
203 204 void ChartPresenter::setTheme(QChart::ChartThemeId theme)
204 205 {
205 206 delete m_chartTheme;
206 207
207 208 m_chartTheme = ChartTheme::createTheme(theme);
208 209
209 210 m_chartTheme->decorate(m_chart);
210 211 QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems);
211 212
212 213 int index=0;
213 214 while (i.hasNext()) {
214 215 i.next();
215 216 index++;
216 217 m_chartTheme->decorate(i.value(),i.key(),index);
217 218 }
218 219 }
219 220
220 221
221 222 QChart::ChartThemeId ChartPresenter::theme()
222 223 {
223 224 return (QChart::ChartThemeId) 0;
224 225 }
225 226
226 227 /*
227 228 void ChartPresenter::setAxisX(const QChartAxis& axis)
228 229 {
229 230 setAxis(m_axisXItem,axis);
230 231 }
231 232 void ChartPresenter::setAxisY(const QChartAxis& axis)
232 233 {
233 234 setAxis(m_axisYItem.at(0),axis);
234 235 }
235 236
236 237 void ChartPresenter::setAxisY(const QList<QChartAxis>& axis)
237 238 {
238 239 //TODO not implemented
239 240 }
240 241
241 242 void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis)
242 243 {
243 244 item->setVisible(axis.isAxisVisible());
244 245 }
245 246 */
246 247 #include "moc_chartpresenter_p.cpp"
247 248
248 249 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,17 +1,18
1 1 #include <QtCore/QtGlobal>
2 2 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
3 3 #include <QApplication>
4 4 #else
5 5 #include <QtWidgets/QApplication>
6 6 #endif
7 7 #include "mainwidget.h"
8 8
9 9 int main(int argc, char *argv[])
10 10 {
11 11 QApplication a(argc, argv);
12 12
13 13 MainWidget w;
14 w.resize(1000,600);
14 15 w.show();
15 16
16 17 return a.exec();
17 18 }
General Comments 0
You need to be logged in to leave comments. Login now