@@ -1,55 +1,48 | |||
|
1 | 1 | #include "baranimation_p.h" |
|
2 | 2 | #include "barchartitem_p.h" |
|
3 | 3 | #include <QParallelAnimationGroup> |
|
4 | 4 | #include <QTimer> |
|
5 | 5 | |
|
6 | 6 | Q_DECLARE_METATYPE(QVector<QRectF>) |
|
7 | 7 | //Q_DECLARE_METATYPE(BarLayout) // TODO? |
|
8 | 8 | |
|
9 | 9 | |
|
10 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | 11 | |
|
12 | 12 | BarAnimation::BarAnimation(BarChartItem *item) |
|
13 | 13 | :ChartAnimation(item), |
|
14 | 14 | m_item(item) |
|
15 | 15 | { |
|
16 | 16 | } |
|
17 | 17 | |
|
18 | 18 | BarAnimation::~BarAnimation() |
|
19 | 19 | { |
|
20 | 20 | } |
|
21 | 21 | |
|
22 | void BarAnimation::updateValues(const QVector<QRectF>& layout) | |
|
23 | { | |
|
24 | // TODO?: | |
|
25 | // qDebug() << "BarAnimation::updateValues" << layout.count(); | |
|
26 | } | |
|
27 | ||
|
28 | ||
|
29 | 22 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
|
30 | 23 | { |
|
31 | 24 | QVector<QRectF> startVector = qVariantValue<QVector<QRectF> > (from); |
|
32 | 25 | QVector<QRectF> endVector = qVariantValue<QVector<QRectF> > (to); |
|
33 | 26 | QVector<QRectF> result; |
|
34 | 27 | |
|
35 | 28 | Q_ASSERT(startVector.count() == endVector.count()) ; |
|
36 | 29 | |
|
37 | 30 | for(int i =0 ;i< startVector.count();i++){ |
|
38 | 31 | //QRectF value = startVector[i] + ((endVector[i] - startVector[i]) * progress); |
|
39 | 32 | QPointF topLeft = startVector[i].topLeft() + ((endVector[i].topLeft() - startVector[i].topLeft()) * progress); |
|
40 | 33 | QSizeF size = startVector[i].size() + ((endVector[i].size() - startVector[i].size()) * progress); |
|
41 | 34 | QRectF value(topLeft,size); |
|
42 | 35 | result << value; |
|
43 | 36 | } |
|
44 | 37 | return qVariantFromValue(result); |
|
45 | 38 | } |
|
46 | 39 | |
|
47 | 40 | void BarAnimation::updateCurrentValue(const QVariant &value) |
|
48 | 41 | { |
|
49 | 42 | QVector<QRectF> layout = qVariantValue<QVector<QRectF> >(value); |
|
50 | 43 | m_item->setLayout(layout); |
|
51 | 44 | } |
|
52 | 45 | |
|
53 | 46 | #include "moc_baranimation_p.cpp" |
|
54 | 47 | |
|
55 | 48 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,36 +1,34 | |||
|
1 | 1 | #ifndef BARANIMATION_P_H_ |
|
2 | 2 | #define BARANIMATION_P_H_ |
|
3 | 3 | |
|
4 | 4 | #include "chartanimation_p.h" |
|
5 | 5 | #include "barchartitem_p.h" |
|
6 | 6 | |
|
7 | 7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | 8 | |
|
9 | 9 | class BarChartItem; |
|
10 | 10 | class QBarSet; |
|
11 | 11 | class BarSetAnimation; |
|
12 | 12 | |
|
13 | 13 | class BarAnimation : public ChartAnimation |
|
14 | 14 | { |
|
15 | 15 | Q_OBJECT |
|
16 | 16 | |
|
17 | 17 | public: |
|
18 | 18 | BarAnimation(BarChartItem *item); |
|
19 | 19 | ~BarAnimation(); |
|
20 | 20 | |
|
21 | void updateValues(const QVector<QRectF>& layout); | |
|
22 | ||
|
23 | 21 | public: // from QVariantAnimation |
|
24 | 22 | virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress ) const; |
|
25 | 23 | virtual void updateCurrentValue (const QVariant & value ); |
|
26 | 24 | |
|
27 | 25 | public Q_SLOTS: |
|
28 | 26 | |
|
29 | 27 | private: |
|
30 | 28 | BarChartItem *m_item; |
|
31 | 29 | QHash<QBarSet*, BarSetAnimation*> m_animations; |
|
32 | 30 | }; |
|
33 | 31 | |
|
34 | 32 | QTCOMMERCIALCHART_END_NAMESPACE |
|
35 | 33 | |
|
36 | 34 | #endif |
@@ -1,357 +1,354 | |||
|
1 | 1 | #include "barchartitem_p.h" |
|
2 | 2 | #include "bar_p.h" |
|
3 | 3 | #include "barvalue_p.h" |
|
4 | 4 | #include "qbarset.h" |
|
5 | 5 | #include "qbarseries.h" |
|
6 | 6 | #include "qchart.h" |
|
7 | 7 | #include "qchartaxis.h" |
|
8 | 8 | #include "qchartaxiscategories.h" |
|
9 | 9 | #include "chartpresenter_p.h" |
|
10 | 10 | #include "chartanimator_p.h" |
|
11 | 11 | #include "chartdataset_p.h" |
|
12 | 12 | #include <QDebug> |
|
13 | 13 | #include <QToolTip> |
|
14 | 14 | |
|
15 | 15 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
16 | 16 | |
|
17 | 17 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
18 | 18 | ChartItem(presenter), |
|
19 | 19 | mLayoutSet(false), |
|
20 | 20 | mSeries(series) |
|
21 | 21 | { |
|
22 | 22 | connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); |
|
23 | 23 | connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); |
|
24 | 24 | //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged())); |
|
25 | 25 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); |
|
26 | 26 | setZValue(ChartPresenter::BarSeriesZValue); |
|
27 | 27 | initAxisLabels(); |
|
28 | 28 | dataChanged(); |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | BarChartItem::~BarChartItem() |
|
32 | 32 | { |
|
33 | 33 | disconnect(this,SLOT(showToolTip(QPoint,QString))); |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
37 | 37 | { |
|
38 | 38 | if (!mLayoutSet) { |
|
39 | 39 | qDebug() << "BarChartItem::paint called without layout set. Aborting."; |
|
40 | 40 | return; |
|
41 | 41 | } |
|
42 | 42 | foreach(QGraphicsItem* i, childItems()) { |
|
43 | 43 | i->paint(painter,option,widget); |
|
44 | 44 | } |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | 47 | QRectF BarChartItem::boundingRect() const |
|
48 | 48 | { |
|
49 | 49 | return m_rect; |
|
50 | 50 | } |
|
51 | 51 | |
|
52 | 52 | void BarChartItem::dataChanged() |
|
53 | 53 | { |
|
54 | 54 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? |
|
55 | 55 | // Delete old bars |
|
56 | 56 | foreach (QGraphicsItem* item, childItems()) { |
|
57 | 57 | delete item; |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | mBars.clear(); |
|
61 | 61 | mFloatingValues.clear(); |
|
62 | 62 | mLayout.clear(); |
|
63 | 63 | |
|
64 | 64 | // Create new graphic items for bars |
|
65 | 65 | for (int c=0; c<mSeries->categoryCount(); c++) { |
|
66 | 66 | QString category = mSeries->categoryName(c); |
|
67 | 67 | for (int s=0; s<mSeries->barsetCount(); s++) { |
|
68 | 68 | QBarSet *set = mSeries->barsetAt(s); |
|
69 | 69 | Bar *bar = new Bar(category,this); |
|
70 | 70 | childItems().append(bar); |
|
71 | 71 | mBars.append(bar); |
|
72 | 72 | connect(bar,SIGNAL(clicked(QString)),set,SIGNAL(clicked(QString))); |
|
73 | 73 | connect(bar,SIGNAL(rightClicked(QString)),set,SIGNAL(rightClicked(QString))); |
|
74 | 74 | connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint))); |
|
75 | 75 | connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent())); |
|
76 | 76 | mLayout.append(QRectF(0,0,0,0)); |
|
77 | 77 | } |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | // Create floating values |
|
81 | 81 | for (int category=0; category<mSeries->categoryCount(); category++) { |
|
82 | 82 | for (int s=0; s<mSeries->barsetCount(); s++) { |
|
83 | 83 | QBarSet *set = mSeries->barsetAt(s); |
|
84 | 84 | BarValue *value = new BarValue(*set, this); |
|
85 | 85 | childItems().append(value); |
|
86 | 86 | mFloatingValues.append(value); |
|
87 | 87 | connect(set,SIGNAL(toggleFloatingValues()),value,SLOT(toggleVisible())); |
|
88 | 88 | } |
|
89 | 89 | } |
|
90 | 90 | } |
|
91 | 91 | /* |
|
92 | 92 | void BarChartItem::layoutChanged() |
|
93 | 93 | { |
|
94 | 94 | qDebug() << "Deprecated BarChartItem::layoutChanged called. aborting"; |
|
95 | 95 | return; |
|
96 | 96 | // Scale bars to new layout |
|
97 | 97 | // Layout for bars: |
|
98 | 98 | if (mSeries->barsetCount() <= 0) { |
|
99 | 99 | qDebug() << "No sets in model!"; |
|
100 | 100 | return; |
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | if (childItems().count() == 0) { |
|
104 | 104 | qDebug() << "WARNING: BarChartitem::layoutChanged called before graphics items are created!"; |
|
105 | 105 | return; |
|
106 | 106 | } |
|
107 | 107 | |
|
108 | 108 | |
|
109 | 109 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
110 | 110 | qreal categoryCount = mSeries->categoryCount(); |
|
111 | 111 | qreal setCount = mSeries->barsetCount(); |
|
112 | 112 | qreal max = mSeries->max(); |
|
113 | 113 | |
|
114 | 114 | // Domain: |
|
115 | 115 | if (mDomainMaxY > max) { |
|
116 | 116 | max = mDomainMaxY; |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | qreal width = geometry().width(); |
|
120 | 120 | qreal height = geometry().height(); |
|
121 | 121 | qreal scale = (height/max); |
|
122 | 122 | qreal categoryWidth = width/categoryCount; |
|
123 | 123 | qreal barWidth = categoryWidth / (setCount+1); |
|
124 | 124 | |
|
125 | 125 | BarLayout layout; |
|
126 | 126 | |
|
127 | 127 | int itemIndex(0); |
|
128 | 128 | for (int category=0; category < categoryCount; category++) { |
|
129 | 129 | qreal xPos = categoryWidth * category + barWidth/2; |
|
130 | 130 | qreal yPos = height; |
|
131 | 131 | for (int set = 0; set < setCount; set++) { |
|
132 | 132 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
133 | 133 | Bar* bar = mBars.at(itemIndex); |
|
134 | 134 | |
|
135 | 135 | QRectF rect(xPos,yPos-barHeight,mBarWidth,barHeight); |
|
136 | 136 | layout.insert(bar,rect); |
|
137 | 137 | // TODO: width settable per bar? |
|
138 | 138 | bar->setRect(xPos, yPos-barHeight,barWidth, barHeight); |
|
139 | 139 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
140 | 140 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
141 | 141 | |
|
142 | 142 | // bar->resize(mBarWidth, barHeight); |
|
143 | 143 | // layout.insert(bar,QSizeF(mBarWidth,barHeight)); |
|
144 | 144 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
145 | 145 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
146 | 146 | // bar->setPos(xPos, yPos-barHeight); |
|
147 | 147 | itemIndex++; |
|
148 | 148 | xPos += barWidth; |
|
149 | 149 | } |
|
150 | 150 | } |
|
151 | 151 | |
|
152 | 152 | // Position floating values |
|
153 | 153 | itemIndex = 0; |
|
154 | 154 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
155 | 155 | qreal xPos = categoryWidth * category + categoryWidth/2 + barWidth; |
|
156 | 156 | qreal yPos = height; |
|
157 | 157 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
158 | 158 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
159 | 159 | BarValue* value = mFloatingValues.at(itemIndex); |
|
160 | 160 | |
|
161 | 161 | QBarSet* barSet = mSeries->barsetAt(set); |
|
162 | 162 | value->resize(100,50); // TODO: proper layout for this. |
|
163 | 163 | value->setPos(xPos, yPos-barHeight/2); |
|
164 | 164 | value->setPen(barSet->floatingValuePen()); |
|
165 | 165 | |
|
166 | 166 | if (mSeries->valueAt(set,category) != 0) { |
|
167 | 167 | value->setValueString(QString::number(mSeries->valueAt(set,category))); |
|
168 | 168 | } else { |
|
169 | 169 | value->setValueString(QString("")); |
|
170 | 170 | } |
|
171 | 171 | |
|
172 | 172 | itemIndex++; |
|
173 | 173 | xPos += barWidth; |
|
174 | 174 | } |
|
175 | 175 | } |
|
176 | 176 | // update(); |
|
177 | 177 | } |
|
178 | 178 | */ |
|
179 | 179 | QVector<QRectF> BarChartItem::calculateLayout() |
|
180 | 180 | { |
|
181 | 181 | // layoutChanged(); |
|
182 | 182 | /* |
|
183 | 183 | BarLayout layout; |
|
184 | 184 | foreach(Bar* bar, mBars) { |
|
185 | 185 | layout.insert(bar,bar->boundingRect()); |
|
186 | 186 | } |
|
187 | 187 | */ |
|
188 | 188 | QVector<QRectF> layout; |
|
189 | 189 | |
|
190 | 190 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
191 |
|
|
|
192 |
|
|
|
191 | qreal categoryCount = mSeries->categoryCount(); | |
|
192 | qreal setCount = mSeries->barsetCount(); | |
|
193 | 193 | |
|
194 | // qreal tW = mWidth; | |
|
195 | // qreal tH = mHeight; | |
|
196 | 194 | qreal width = geometry().width(); |
|
197 | 195 | qreal height = geometry().height(); |
|
198 | 196 | |
|
199 |
qreal |
|
|
197 | qreal max = mSeries->max(); | |
|
200 | 198 | |
|
201 | 199 | // Domain: |
|
202 |
if (mDomainMaxY > |
|
|
203 |
|
|
|
200 | if (mDomainMaxY > max) { | |
|
201 | max = mDomainMaxY; | |
|
204 | 202 | } |
|
205 | 203 | |
|
206 |
qreal scale = (height/ |
|
|
207 |
qreal |
|
|
208 | qreal categoryWidth = width/tC; | |
|
204 | qreal scale = (height/max); | |
|
205 | qreal categoryWidth = width/categoryCount; | |
|
209 | 206 | qreal barWidth = categoryWidth / (setCount+1); |
|
210 | 207 | |
|
211 | 208 | int itemIndex(0); |
|
212 | 209 | for (int category=0; category < categoryCount; category++) { |
|
213 |
qreal xPos = categoryWidth * category + |
|
|
210 | qreal xPos = categoryWidth * category + barWidth/2; | |
|
214 | 211 | qreal yPos = height; |
|
215 | 212 | for (int set = 0; set < setCount; set++) { |
|
216 | 213 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
217 | 214 | Bar* bar = mBars.at(itemIndex); |
|
218 | 215 | |
|
219 | 216 | QRectF rect(xPos,yPos-barHeight,barWidth,barHeight); |
|
220 | 217 | //layout.insert(bar,rect); |
|
221 | 218 | layout.append(rect); |
|
222 | 219 | // TODO: width settable per bar? |
|
223 | 220 | // bar->resize(mBarWidth, barHeight); |
|
224 | 221 | // layout.insert(bar,QSizeF(mBarWidth,barHeight)); |
|
225 | 222 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
226 | 223 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
227 | 224 | // bar->setPos(xPos, yPos-barHeight); |
|
228 | 225 | itemIndex++; |
|
229 | 226 | xPos += barWidth; |
|
230 | 227 | } |
|
231 | 228 | } |
|
232 | 229 | |
|
233 | 230 | // Position floating values |
|
234 | 231 | itemIndex = 0; |
|
235 | 232 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
236 |
qreal xPos = categoryWidth * category |
|
|
233 | qreal xPos = categoryWidth * category + barWidth; | |
|
237 | 234 | qreal yPos = height; |
|
238 | 235 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
239 | 236 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
240 | 237 | BarValue* value = mFloatingValues.at(itemIndex); |
|
241 | 238 | |
|
242 | 239 | QBarSet* barSet = mSeries->barsetAt(set); |
|
243 | 240 | value->resize(100,50); // TODO: proper layout for this. |
|
244 | 241 | value->setPos(xPos, yPos-barHeight/2); |
|
245 | 242 | value->setPen(barSet->floatingValuePen()); |
|
246 | 243 | |
|
247 | 244 | if (mSeries->valueAt(set,category) != 0) { |
|
248 | 245 | value->setValueString(QString::number(mSeries->valueAt(set,category))); |
|
249 | 246 | } else { |
|
250 | 247 | value->setValueString(QString("")); |
|
251 | 248 | } |
|
252 | 249 | |
|
253 | 250 | itemIndex++; |
|
254 | 251 | xPos += barWidth; |
|
255 | 252 | } |
|
256 | 253 | } |
|
257 | 254 | |
|
258 | 255 | return layout; |
|
259 | 256 | } |
|
260 | 257 | |
|
261 | 258 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
262 | 259 | { |
|
263 | 260 | if (animator()) |
|
264 | 261 | animator()->updateLayout(this, mLayout, layout); |
|
265 | 262 | else |
|
266 | 263 | setLayout(layout); |
|
267 | 264 | } |
|
268 | 265 | |
|
269 | 266 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
270 | 267 | { |
|
271 | 268 | mLayout = layout; |
|
272 | 269 | |
|
273 | 270 | for (int i=0; i<mBars.count(); i++) { |
|
274 | 271 | //mBars.at(i)->setSize(layout.at(i).size()); |
|
275 | 272 | //mBars.at(i)->setPos(layout.at(i).topLeft()); |
|
276 | 273 | mBars.at(i)->setRect(layout.at(i)); |
|
277 | 274 | } |
|
278 | 275 | |
|
279 | 276 | update(); |
|
280 | 277 | } |
|
281 | 278 | |
|
282 | 279 | void BarChartItem::initAxisLabels() |
|
283 | 280 | { |
|
284 | 281 | int count = mSeries->categoryCount(); |
|
285 | 282 | if (0 == count) { |
|
286 | 283 | return; |
|
287 | 284 | } |
|
288 | 285 | |
|
289 | 286 | Domain* domain = presenter()->dataSet()->domain(mSeries); |
|
290 | 287 | |
|
291 | 288 | qreal min = 0; |
|
292 | 289 | qreal max = count+1; |
|
293 | 290 | |
|
294 | 291 | domain->setRangeX(min,max,count+1); |
|
295 | 292 | } |
|
296 | 293 | |
|
297 | 294 | //handlers |
|
298 | 295 | |
|
299 | 296 | void BarChartItem::handleModelChanged(int index) |
|
300 | 297 | { |
|
301 | 298 | Q_UNUSED(index) |
|
302 | 299 | dataChanged(); |
|
303 | 300 | } |
|
304 | 301 | |
|
305 | 302 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
306 | 303 | { |
|
307 | 304 | mDomainMinX = minX; |
|
308 | 305 | mDomainMaxX = maxX; |
|
309 | 306 | mDomainMinY = minY; |
|
310 | 307 | mDomainMaxY = maxY; |
|
311 | 308 | handleLayoutChanged(); |
|
312 | 309 | |
|
313 | 310 | /* |
|
314 | 311 | int count = mSeries->categoryCount(); |
|
315 | 312 | if (0 == count) { |
|
316 | 313 | return; |
|
317 | 314 | } |
|
318 | 315 | |
|
319 | 316 | // Position labels to domain |
|
320 | 317 | qreal min = domain.minX(); |
|
321 | 318 | qreal max = domain.maxX(); |
|
322 | 319 | qreal step = (max-min)/count; |
|
323 | 320 | QChartAxisCategories& categories = mChart->axisX()->categories(); |
|
324 | 321 | categories.clear(); |
|
325 | 322 | for (int i=0; i<count; i++) { |
|
326 | 323 | categories.insert(min,mSeries->categoryName(i)); |
|
327 | 324 | min += step; |
|
328 | 325 | } |
|
329 | 326 | */ |
|
330 | 327 | } |
|
331 | 328 | |
|
332 | 329 | void BarChartItem::handleGeometryChanged(const QRectF& rect) |
|
333 | 330 | { |
|
334 | 331 | m_rect=rect; |
|
335 | 332 | handleLayoutChanged(); |
|
336 | 333 | mLayoutSet = true; |
|
337 | 334 | setPos(rect.topLeft()); |
|
338 | 335 | } |
|
339 | 336 | |
|
340 | 337 | void BarChartItem::handleLayoutChanged() |
|
341 | 338 | { |
|
342 | 339 | qDebug() << "BarChartItem::handleLayoutChanged"; |
|
343 | 340 | QVector<QRectF> layout = calculateLayout(); |
|
344 | 341 | applyLayout(layout); |
|
345 | 342 | update(); |
|
346 | 343 | } |
|
347 | 344 | |
|
348 | 345 | |
|
349 | 346 | void BarChartItem::showToolTip(QPoint pos, QString tip) |
|
350 | 347 | { |
|
351 | 348 | // TODO: cool tooltip instead of default |
|
352 | 349 | QToolTip::showText(pos,tip); |
|
353 | 350 | } |
|
354 | 351 | |
|
355 | 352 | #include "moc_barchartitem_p.cpp" |
|
356 | 353 | |
|
357 | 354 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,73 +1,73 | |||
|
1 | 1 | #ifndef DOMAIN_H_ |
|
2 | 2 | #define DOMAIN_H_ |
|
3 | 3 | #include "qchartglobal.h" |
|
4 | 4 | #include "qchartaxis.h" |
|
5 | 5 | #include <QRectF> |
|
6 | 6 | #include <QSizeF> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | class Domain: public QObject { |
|
11 | 11 | Q_OBJECT |
|
12 | 12 | public: |
|
13 | 13 | explicit Domain(QObject* object=0); |
|
14 | 14 | virtual ~Domain(); |
|
15 | 15 | |
|
16 | 16 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
17 | 17 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY, int tickXCount, int tickYCount); |
|
18 | 18 | void setRangeX(qreal min, qreal max); |
|
19 | 19 | void setRangeX(qreal min, qreal max, int tickCount); |
|
20 | 20 | void setRangeY(qreal min, qreal max); |
|
21 | 21 | void setRangeY(qreal min, qreal max, int tickCount); |
|
22 | 22 | void setMinX(qreal min); |
|
23 | 23 | void setMaxX(qreal max); |
|
24 | 24 | void setMinY(qreal min); |
|
25 | 25 | void setMaxY(qreal max); |
|
26 | 26 | |
|
27 | 27 | qreal minX() const {return m_minX;}; |
|
28 | 28 | qreal maxX() const {return m_maxX;}; |
|
29 | 29 | qreal minY() const {return m_minY;}; |
|
30 | 30 | qreal maxY() const {return m_maxY;}; |
|
31 | 31 | |
|
32 | 32 | qreal spanX() const; |
|
33 | 33 | qreal spanY() const; |
|
34 | 34 | bool isEmpty() const; |
|
35 | 35 | |
|
36 | 36 | int tickXCount() const {return m_tickXCount;} |
|
37 | 37 | int tickYCount() const {return m_tickYCount;} |
|
38 | 38 | |
|
39 | 39 | friend bool operator== (const Domain &domain1, const Domain &domain2); |
|
40 | 40 | friend bool operator!= (const Domain &domain1, const Domain &domain2); |
|
41 | 41 | friend QDebug operator<<(QDebug dbg, const Domain &domain); |
|
42 | 42 | |
|
43 | 43 | void zoomIn(const QRectF& rect, const QSizeF& size); |
|
44 | 44 | void zoomOut(const QRectF& rect, const QSizeF& size); |
|
45 | 45 | void move(int dx,int dy,const QSizeF& size); |
|
46 | 46 | |
|
47 | 47 | signals: |
|
48 | 48 | void domainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
49 | 49 | void rangeXChanged(qreal min, qreal max, int tickXCount); |
|
50 | 50 | void rangeYChanged(qreal min, qreal max, int tickYCount); |
|
51 | 51 | |
|
52 | 52 | public slots: |
|
53 | void handleAxisXChanged(qreal min,qreal max,int tickXCount,QChartAxis::LabelsSelection mode); | |
|
54 | void handleAxisYChanged(qreal min,qreal max,int tickYCount,QChartAxis::LabelsSelection mode); | |
|
53 | void handleAxisXChanged(qreal min,qreal max,int tickXCount = 5,QChartAxis::LabelsSelection mode = QChartAxis::NativeLabelsSelection); | |
|
54 | void handleAxisYChanged(qreal min,qreal max,int tickYCount = 5,QChartAxis::LabelsSelection mode = QChartAxis::NativeLabelsSelection); | |
|
55 | 55 | |
|
56 | 56 | private: |
|
57 | 57 | void niceNumbers(qreal &min, qreal &max, int &ticksCount); |
|
58 | 58 | void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount); |
|
59 | 59 | qreal niceNumber(qreal x,bool celing); |
|
60 | 60 | |
|
61 | 61 | private: |
|
62 | 62 | qreal m_minX; |
|
63 | 63 | qreal m_maxX; |
|
64 | 64 | qreal m_minY; |
|
65 | 65 | qreal m_maxY; |
|
66 | 66 | int m_tickXCount; |
|
67 | 67 | int m_tickYCount; |
|
68 | 68 | QChartAxis::LabelsSelection m_selection; |
|
69 | 69 | }; |
|
70 | 70 | |
|
71 | 71 | QTCOMMERCIALCHART_END_NAMESPACE |
|
72 | 72 | |
|
73 | 73 | #endif |
@@ -1,578 +1,579 | |||
|
1 | 1 | #include <QtTest/QtTest> |
|
2 | 2 | #include <private/domain_p.h> |
|
3 | #include <qchartaxis.h> | |
|
3 | 4 | |
|
4 | 5 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
5 | 6 | |
|
6 | 7 | Q_DECLARE_METATYPE(Domain*) |
|
7 | 8 | Q_DECLARE_METATYPE(QSizeF) |
|
8 | 9 | |
|
9 | 10 | class tst_Domain : public QObject |
|
10 | 11 | { |
|
11 | 12 | Q_OBJECT |
|
12 | 13 | |
|
13 | 14 | public slots: |
|
14 | 15 | void initTestCase(); |
|
15 | 16 | void cleanupTestCase(); |
|
16 | 17 | void init(); |
|
17 | 18 | void cleanup(); |
|
18 | 19 | |
|
19 | 20 | private slots: |
|
20 | 21 | void domain(); |
|
21 | 22 | void handleAxisRangeXChanged_data(); |
|
22 | 23 | void handleAxisRangeXChanged(); |
|
23 | 24 | void handleAxisRangeYChanged_data(); |
|
24 | 25 | void handleAxisRangeYChanged(); |
|
25 | 26 | void isEmpty_data(); |
|
26 | 27 | void isEmpty(); |
|
27 | 28 | void maxX_data(); |
|
28 | 29 | void maxX(); |
|
29 | 30 | void maxY_data(); |
|
30 | 31 | void maxY(); |
|
31 | 32 | void minX_data(); |
|
32 | 33 | void minX(); |
|
33 | 34 | void minY_data(); |
|
34 | 35 | void minY(); |
|
35 | 36 | void operatorEquals_data(); |
|
36 | 37 | void operatorEquals(); |
|
37 | 38 | void setRange_data(); |
|
38 | 39 | void setRange(); |
|
39 | 40 | void setRangeX_data(); |
|
40 | 41 | void setRangeX(); |
|
41 | 42 | void setRangeY_data(); |
|
42 | 43 | void setRangeY(); |
|
43 | 44 | void spanX_data(); |
|
44 | 45 | void spanX(); |
|
45 | 46 | void spanY_data(); |
|
46 | 47 | void spanY(); |
|
47 | 48 | void zoom_data(); |
|
48 | 49 | void zoom(); |
|
49 | 50 | }; |
|
50 | 51 | |
|
51 | 52 | void tst_Domain::initTestCase() |
|
52 | 53 | { |
|
53 | 54 | } |
|
54 | 55 | |
|
55 | 56 | void tst_Domain::cleanupTestCase() |
|
56 | 57 | { |
|
57 | 58 | } |
|
58 | 59 | |
|
59 | 60 | void tst_Domain::init() |
|
60 | 61 | { |
|
61 | 62 | } |
|
62 | 63 | |
|
63 | 64 | void tst_Domain::cleanup() |
|
64 | 65 | { |
|
65 | 66 | } |
|
66 | 67 | |
|
67 | 68 | void tst_Domain::domain() |
|
68 | 69 | { |
|
69 | 70 | Domain domain; |
|
70 | 71 | |
|
71 | 72 | QCOMPARE(domain.isEmpty(), true); |
|
72 | 73 | QCOMPARE(domain.maxX(), 0.0); |
|
73 | 74 | QCOMPARE(domain.maxY(), 0.0); |
|
74 | 75 | QCOMPARE(domain.minX(), 0.0); |
|
75 | 76 | QCOMPARE(domain.minY(), 0.0); |
|
76 | 77 | } |
|
77 | 78 | |
|
78 | 79 | void tst_Domain::handleAxisRangeXChanged_data() |
|
79 | 80 | { |
|
80 | 81 | QTest::addColumn<qreal>("min"); |
|
81 | 82 | QTest::addColumn<qreal>("max"); |
|
82 | 83 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
83 | 84 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
84 | 85 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
85 | 86 | } |
|
86 | 87 | |
|
87 | 88 | void tst_Domain::handleAxisRangeXChanged() |
|
88 | 89 | { |
|
89 | 90 | QFETCH(qreal, min); |
|
90 | 91 | QFETCH(qreal, max); |
|
91 | 92 | |
|
92 | 93 | Domain domain; |
|
93 | 94 | |
|
94 | 95 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); |
|
95 | 96 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); |
|
96 | 97 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); |
|
97 | 98 | |
|
98 |
domain.handleAxis |
|
|
99 | domain.handleAxisXChanged(min, max); | |
|
99 | 100 | |
|
100 | 101 | QList<QVariant> arg0 = spy0.first(); |
|
101 | 102 | QVERIFY(arg0.at(0).toReal() == min); |
|
102 | 103 | QVERIFY(arg0.at(1).toReal() == max); |
|
103 | 104 | |
|
104 | 105 | QList<QVariant> arg1 = spy1.first(); |
|
105 | 106 | QVERIFY(arg1.at(0).toReal() == min); |
|
106 | 107 | QVERIFY(arg1.at(1).toReal() == max); |
|
107 | 108 | |
|
108 | 109 | QCOMPARE(spy0.count(), 1); |
|
109 | 110 | QCOMPARE(spy1.count(), 1); |
|
110 | 111 | QCOMPARE(spy2.count(), 0); |
|
111 | 112 | |
|
112 | 113 | } |
|
113 | 114 | |
|
114 | 115 | void tst_Domain::handleAxisRangeYChanged_data() |
|
115 | 116 | { |
|
116 | 117 | QTest::addColumn<qreal>("min"); |
|
117 | 118 | QTest::addColumn<qreal>("max"); |
|
118 | 119 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
119 | 120 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
120 | 121 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
121 | 122 | } |
|
122 | 123 | |
|
123 | 124 | |
|
124 | 125 | void tst_Domain::handleAxisRangeYChanged() |
|
125 | 126 | { |
|
126 | 127 | QFETCH(qreal, min); |
|
127 | 128 | QFETCH(qreal, max); |
|
128 | 129 | |
|
129 | 130 | Domain domain; |
|
130 | 131 | |
|
131 | 132 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); |
|
132 | 133 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); |
|
133 | 134 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); |
|
134 | 135 | |
|
135 |
domain.handleAxis |
|
|
136 | domain.handleAxisYChanged(min, max,5); | |
|
136 | 137 | |
|
137 | 138 | QList<QVariant> arg0 = spy0.first(); |
|
138 | 139 | QVERIFY(arg0.at(2).toReal() == min); |
|
139 | 140 | QVERIFY(arg0.at(3).toReal() == max); |
|
140 | 141 | |
|
141 | 142 | QList<QVariant> arg1 = spy2.first(); |
|
142 | 143 | QVERIFY(arg1.at(0).toReal() == min); |
|
143 | 144 | QVERIFY(arg1.at(1).toReal() == max); |
|
144 | 145 | |
|
145 | 146 | QCOMPARE(spy0.count(), 1); |
|
146 | 147 | QCOMPARE(spy1.count(), 0); |
|
147 | 148 | QCOMPARE(spy2.count(), 1); |
|
148 | 149 | } |
|
149 | 150 | |
|
150 | 151 | void tst_Domain::isEmpty_data() |
|
151 | 152 | { |
|
152 | 153 | QTest::addColumn<qreal>("minX"); |
|
153 | 154 | QTest::addColumn<qreal>("maxX"); |
|
154 | 155 | QTest::addColumn<qreal>("minY"); |
|
155 | 156 | QTest::addColumn<qreal>("maxY"); |
|
156 | 157 | QTest::addColumn<bool>("isEmpty"); |
|
157 | 158 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true; |
|
158 | 159 | QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
159 | 160 | QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
160 | 161 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false; |
|
161 | 162 | } |
|
162 | 163 | |
|
163 | 164 | void tst_Domain::isEmpty() |
|
164 | 165 | { |
|
165 | 166 | QFETCH(qreal, minX); |
|
166 | 167 | QFETCH(qreal, maxX); |
|
167 | 168 | QFETCH(qreal, minY); |
|
168 | 169 | QFETCH(qreal, maxY); |
|
169 | 170 | QFETCH(bool, isEmpty); |
|
170 | 171 | |
|
171 | 172 | Domain domain; |
|
172 | 173 | domain.setRange(minX,maxX,minY,maxY); |
|
173 | 174 | QCOMPARE(domain.isEmpty(), isEmpty); |
|
174 | 175 | } |
|
175 | 176 | |
|
176 | 177 | void tst_Domain::maxX_data() |
|
177 | 178 | { |
|
178 | 179 | QTest::addColumn<qreal>("maxX1"); |
|
179 | 180 | QTest::addColumn<qreal>("maxX2"); |
|
180 | 181 | QTest::addColumn<int>("count"); |
|
181 | 182 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
182 | 183 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
183 | 184 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
184 | 185 | } |
|
185 | 186 | |
|
186 | 187 | void tst_Domain::maxX() |
|
187 | 188 | { |
|
188 | 189 | QFETCH(qreal, maxX1); |
|
189 | 190 | QFETCH(qreal, maxX2); |
|
190 | 191 | QFETCH(int, count); |
|
191 | 192 | |
|
192 | 193 | Domain domain; |
|
193 | 194 | |
|
194 | 195 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); |
|
195 | 196 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); |
|
196 | 197 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); |
|
197 | 198 | |
|
198 | 199 | domain.setMaxX(maxX1); |
|
199 | 200 | QCOMPARE(domain.maxX(), maxX1); |
|
200 | 201 | domain.setMaxX(maxX2); |
|
201 | 202 | QCOMPARE(domain.maxX(), maxX2); |
|
202 | 203 | |
|
203 | 204 | |
|
204 | 205 | QCOMPARE(spy0.count(), count); |
|
205 | 206 | QCOMPARE(spy1.count(), count); |
|
206 | 207 | QCOMPARE(spy2.count(), 0); |
|
207 | 208 | |
|
208 | 209 | } |
|
209 | 210 | |
|
210 | 211 | void tst_Domain::maxY_data() |
|
211 | 212 | { |
|
212 | 213 | QTest::addColumn<qreal>("maxY1"); |
|
213 | 214 | QTest::addColumn<qreal>("maxY2"); |
|
214 | 215 | QTest::addColumn<int>("count"); |
|
215 | 216 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
216 | 217 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
217 | 218 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
218 | 219 | } |
|
219 | 220 | |
|
220 | 221 | |
|
221 | 222 | void tst_Domain::maxY() |
|
222 | 223 | { |
|
223 | 224 | QFETCH(qreal, maxY1); |
|
224 | 225 | QFETCH(qreal, maxY2); |
|
225 | 226 | QFETCH(int, count); |
|
226 | 227 | |
|
227 | 228 | Domain domain; |
|
228 | 229 | |
|
229 | 230 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); |
|
230 | 231 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); |
|
231 | 232 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); |
|
232 | 233 | |
|
233 | 234 | domain.setMaxY(maxY1); |
|
234 | 235 | QCOMPARE(domain.maxY(), maxY1); |
|
235 | 236 | domain.setMaxY(maxY2); |
|
236 | 237 | QCOMPARE(domain.maxY(), maxY2); |
|
237 | 238 | |
|
238 | 239 | QCOMPARE(spy0.count(), count); |
|
239 | 240 | QCOMPARE(spy1.count(), 0); |
|
240 | 241 | QCOMPARE(spy2.count(), count); |
|
241 | 242 | } |
|
242 | 243 | |
|
243 | 244 | void tst_Domain::minX_data() |
|
244 | 245 | { |
|
245 | 246 | QTest::addColumn<qreal>("minX1"); |
|
246 | 247 | QTest::addColumn<qreal>("minX2"); |
|
247 | 248 | QTest::addColumn<int>("count"); |
|
248 | 249 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
249 | 250 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
250 | 251 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
251 | 252 | } |
|
252 | 253 | |
|
253 | 254 | |
|
254 | 255 | void tst_Domain::minX() |
|
255 | 256 | { |
|
256 | 257 | QFETCH(qreal, minX1); |
|
257 | 258 | QFETCH(qreal, minX2); |
|
258 | 259 | QFETCH(int, count); |
|
259 | 260 | |
|
260 | 261 | Domain domain; |
|
261 | 262 | |
|
262 | 263 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); |
|
263 | 264 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); |
|
264 | 265 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); |
|
265 | 266 | |
|
266 | 267 | domain.setMinX(minX1); |
|
267 | 268 | QCOMPARE(domain.minX(), minX1); |
|
268 | 269 | domain.setMinX(minX2); |
|
269 | 270 | QCOMPARE(domain.minX(), minX2); |
|
270 | 271 | |
|
271 | 272 | QCOMPARE(spy0.count(), count); |
|
272 | 273 | QCOMPARE(spy1.count(), count); |
|
273 | 274 | QCOMPARE(spy2.count(), 0); |
|
274 | 275 | } |
|
275 | 276 | |
|
276 | 277 | void tst_Domain::minY_data() |
|
277 | 278 | { |
|
278 | 279 | QTest::addColumn<qreal>("minY1"); |
|
279 | 280 | QTest::addColumn<qreal>("minY2"); |
|
280 | 281 | QTest::addColumn<int>("count"); |
|
281 | 282 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
282 | 283 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
283 | 284 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
284 | 285 | } |
|
285 | 286 | |
|
286 | 287 | void tst_Domain::minY() |
|
287 | 288 | { |
|
288 | 289 | QFETCH(qreal, minY1); |
|
289 | 290 | QFETCH(qreal, minY2); |
|
290 | 291 | QFETCH(int, count); |
|
291 | 292 | |
|
292 | 293 | Domain domain; |
|
293 | 294 | |
|
294 | 295 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); |
|
295 | 296 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); |
|
296 | 297 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); |
|
297 | 298 | |
|
298 | 299 | domain.setMinY(minY1); |
|
299 | 300 | QCOMPARE(domain.minY(), minY1); |
|
300 | 301 | domain.setMinY(minY2); |
|
301 | 302 | QCOMPARE(domain.minY(), minY2); |
|
302 | 303 | |
|
303 | 304 | QCOMPARE(spy0.count(), count); |
|
304 | 305 | QCOMPARE(spy1.count(), 0); |
|
305 | 306 | QCOMPARE(spy2.count(), count); |
|
306 | 307 | } |
|
307 | 308 | |
|
308 | 309 | void tst_Domain::operatorEquals_data() |
|
309 | 310 | { |
|
310 | 311 | |
|
311 | 312 | QTest::addColumn<Domain*>("domain1"); |
|
312 | 313 | QTest::addColumn<Domain*>("domain2"); |
|
313 | 314 | QTest::addColumn<bool>("equals"); |
|
314 | 315 | QTest::addColumn<bool>("notEquals"); |
|
315 | 316 | Domain* a; |
|
316 | 317 | Domain* b; |
|
317 | 318 | a = new Domain(); |
|
318 | 319 | a->setRange(0,100,0,100); |
|
319 | 320 | b = new Domain(); |
|
320 | 321 | b->setRange(0,100,0,100); |
|
321 | 322 | QTest::newRow("equals") << a << b << true <<false; |
|
322 | 323 | a = new Domain(); |
|
323 | 324 | a->setRange(0,100,0,100); |
|
324 | 325 | b = new Domain(); |
|
325 | 326 | b->setRange(0,100,0,1); |
|
326 | 327 | QTest::newRow("equals") << a << b << false << true; |
|
327 | 328 | a = new Domain(); |
|
328 | 329 | a->setRange(0,100,0,100); |
|
329 | 330 | b = new Domain(); |
|
330 | 331 | b->setRange(0,1,0,100); |
|
331 | 332 | QTest::newRow("equals") << a << b << false << true; |
|
332 | 333 | |
|
333 | 334 | } |
|
334 | 335 | |
|
335 | 336 | void tst_Domain::operatorEquals() |
|
336 | 337 | { |
|
337 | 338 | QFETCH(Domain*, domain1); |
|
338 | 339 | QFETCH(Domain*, domain2); |
|
339 | 340 | QFETCH(bool, equals); |
|
340 | 341 | QFETCH(bool, notEquals); |
|
341 | 342 | |
|
342 | 343 | Domain domain; |
|
343 | 344 | |
|
344 | 345 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); |
|
345 | 346 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); |
|
346 | 347 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); |
|
347 | 348 | |
|
348 | 349 | QCOMPARE(*domain1==*domain2, equals); |
|
349 | 350 | QCOMPARE(*domain1!=*domain2, notEquals); |
|
350 | 351 | |
|
351 | 352 | QCOMPARE(spy0.count(), 0); |
|
352 | 353 | QCOMPARE(spy1.count(), 0); |
|
353 | 354 | QCOMPARE(spy2.count(), 0); |
|
354 | 355 | } |
|
355 | 356 | |
|
356 | 357 | void tst_Domain::setRange_data() |
|
357 | 358 | { |
|
358 | 359 | QTest::addColumn<qreal>("minX"); |
|
359 | 360 | QTest::addColumn<qreal>("maxX"); |
|
360 | 361 | QTest::addColumn<qreal>("minY"); |
|
361 | 362 | QTest::addColumn<qreal>("maxY"); |
|
362 | 363 | QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0; |
|
363 | 364 | QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0; |
|
364 | 365 | QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0; |
|
365 | 366 | } |
|
366 | 367 | |
|
367 | 368 | void tst_Domain::setRange() |
|
368 | 369 | { |
|
369 | 370 | QFETCH(qreal, minX); |
|
370 | 371 | QFETCH(qreal, maxX); |
|
371 | 372 | QFETCH(qreal, minY); |
|
372 | 373 | QFETCH(qreal, maxY); |
|
373 | 374 | |
|
374 | 375 | Domain domain; |
|
375 | 376 | |
|
376 | 377 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); |
|
377 | 378 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); |
|
378 | 379 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); |
|
379 | 380 | |
|
380 | 381 | domain.setRange(minX, maxX, minY, maxY); |
|
381 | 382 | |
|
382 | 383 | QCOMPARE(domain.minX(), minX); |
|
383 | 384 | QCOMPARE(domain.maxX(), maxX); |
|
384 | 385 | QCOMPARE(domain.minY(), minY); |
|
385 | 386 | QCOMPARE(domain.maxY(), maxY); |
|
386 | 387 | |
|
387 | 388 | QCOMPARE(spy0.count(), 1); |
|
388 | 389 | QCOMPARE(spy1.count(), 1); |
|
389 | 390 | QCOMPARE(spy2.count(), 1); |
|
390 | 391 | |
|
391 | 392 | |
|
392 | 393 | } |
|
393 | 394 | |
|
394 | 395 | void tst_Domain::setRangeX_data() |
|
395 | 396 | { |
|
396 | 397 | QTest::addColumn<qreal>("min"); |
|
397 | 398 | QTest::addColumn<qreal>("max"); |
|
398 | 399 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
399 | 400 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
400 | 401 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
401 | 402 | } |
|
402 | 403 | |
|
403 | 404 | void tst_Domain::setRangeX() |
|
404 | 405 | { |
|
405 | 406 | QFETCH(qreal, min); |
|
406 | 407 | QFETCH(qreal, max); |
|
407 | 408 | |
|
408 | 409 | Domain domain; |
|
409 | 410 | |
|
410 | 411 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); |
|
411 | 412 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); |
|
412 | 413 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); |
|
413 | 414 | |
|
414 | 415 | domain.setRangeX(min, max); |
|
415 | 416 | |
|
416 | 417 | QList<QVariant> arg0 = spy0.first(); |
|
417 | 418 | QVERIFY(arg0.at(0).toReal() == min); |
|
418 | 419 | QVERIFY(arg0.at(1).toReal() == max); |
|
419 | 420 | |
|
420 | 421 | QList<QVariant> arg1 = spy1.first(); |
|
421 | 422 | QVERIFY(arg1.at(0).toReal() == min); |
|
422 | 423 | QVERIFY(arg1.at(1).toReal() == max); |
|
423 | 424 | |
|
424 | 425 | QCOMPARE(spy0.count(), 1); |
|
425 | 426 | QCOMPARE(spy1.count(), 1); |
|
426 | 427 | QCOMPARE(spy2.count(), 0); |
|
427 | 428 | } |
|
428 | 429 | |
|
429 | 430 | void tst_Domain::setRangeY_data() |
|
430 | 431 | { |
|
431 | 432 | QTest::addColumn<qreal>("min"); |
|
432 | 433 | QTest::addColumn<qreal>("max"); |
|
433 | 434 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
434 | 435 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
435 | 436 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
436 | 437 | } |
|
437 | 438 | |
|
438 | 439 | void tst_Domain::setRangeY() |
|
439 | 440 | { |
|
440 | 441 | QFETCH(qreal, min); |
|
441 | 442 | QFETCH(qreal, max); |
|
442 | 443 | |
|
443 | 444 | Domain domain; |
|
444 | 445 | |
|
445 | 446 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); |
|
446 | 447 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); |
|
447 | 448 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); |
|
448 | 449 | |
|
449 | 450 | domain.setRangeY(min, max); |
|
450 | 451 | |
|
451 | 452 | QList<QVariant> arg0 = spy0.first(); |
|
452 | 453 | QVERIFY(arg0.at(2).toReal() == min); |
|
453 | 454 | QVERIFY(arg0.at(3).toReal() == max); |
|
454 | 455 | |
|
455 | 456 | QList<QVariant> arg1 = spy2.first(); |
|
456 | 457 | QVERIFY(arg1.at(0).toReal() == min); |
|
457 | 458 | QVERIFY(arg1.at(1).toReal() == max); |
|
458 | 459 | |
|
459 | 460 | QCOMPARE(spy0.count(), 1); |
|
460 | 461 | QCOMPARE(spy1.count(), 0); |
|
461 | 462 | QCOMPARE(spy2.count(), 1); |
|
462 | 463 | } |
|
463 | 464 | |
|
464 | 465 | void tst_Domain::spanX_data() |
|
465 | 466 | { |
|
466 | 467 | QTest::addColumn<qreal>("minX"); |
|
467 | 468 | QTest::addColumn<qreal>("maxX"); |
|
468 | 469 | QTest::addColumn<qreal>("spanX"); |
|
469 | 470 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
470 | 471 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
471 | 472 | } |
|
472 | 473 | |
|
473 | 474 | void tst_Domain::spanX() |
|
474 | 475 | { |
|
475 | 476 | QFETCH(qreal, minX); |
|
476 | 477 | QFETCH(qreal, maxX); |
|
477 | 478 | QFETCH(qreal, spanX); |
|
478 | 479 | |
|
479 | 480 | Domain domain; |
|
480 | 481 | |
|
481 | 482 | domain.setRangeX(minX,maxX); |
|
482 | 483 | |
|
483 | 484 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); |
|
484 | 485 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); |
|
485 | 486 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); |
|
486 | 487 | |
|
487 | 488 | QCOMPARE(domain.spanX(), spanX); |
|
488 | 489 | |
|
489 | 490 | QCOMPARE(spy0.count(), 0); |
|
490 | 491 | QCOMPARE(spy1.count(), 0); |
|
491 | 492 | QCOMPARE(spy2.count(), 0); |
|
492 | 493 | } |
|
493 | 494 | |
|
494 | 495 | void tst_Domain::spanY_data() |
|
495 | 496 | { |
|
496 | 497 | QTest::addColumn<qreal>("minY"); |
|
497 | 498 | QTest::addColumn<qreal>("maxY"); |
|
498 | 499 | QTest::addColumn<qreal>("spanY"); |
|
499 | 500 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
500 | 501 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
501 | 502 | } |
|
502 | 503 | |
|
503 | 504 | void tst_Domain::spanY() |
|
504 | 505 | { |
|
505 | 506 | QFETCH(qreal, minY); |
|
506 | 507 | QFETCH(qreal, maxY); |
|
507 | 508 | QFETCH(qreal, spanY); |
|
508 | 509 | |
|
509 | 510 | Domain domain; |
|
510 | 511 | |
|
511 | 512 | domain.setRangeY(minY,maxY); |
|
512 | 513 | |
|
513 | 514 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); |
|
514 | 515 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); |
|
515 | 516 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); |
|
516 | 517 | |
|
517 | 518 | QCOMPARE(domain.spanY(), spanY); |
|
518 | 519 | |
|
519 | 520 | QCOMPARE(spy0.count(), 0); |
|
520 | 521 | QCOMPARE(spy1.count(), 0); |
|
521 | 522 | QCOMPARE(spy2.count(), 0); |
|
522 | 523 | } |
|
523 | 524 | |
|
524 | 525 | |
|
525 | 526 | void tst_Domain::zoom_data() |
|
526 | 527 | { |
|
527 | 528 | QTest::addColumn<QRectF>("rect0"); |
|
528 | 529 | QTest::addColumn<QSizeF>("size0"); |
|
529 | 530 | QTest::addColumn<QRectF>("rect1"); |
|
530 | 531 | QTest::addColumn<QSizeF>("size1"); |
|
531 | 532 | QTest::addColumn<QRectF>("rect2"); |
|
532 | 533 | QTest::addColumn<QSizeF>("size2"); |
|
533 | 534 | QTest::newRow("first") << QRectF(10,10,100,100) << QSizeF(1000,1000) << QRectF(20,20,100,100) << QSizeF(1000,1000) << QRectF(50,50,100,100) << QSizeF(1000,1000); |
|
534 | 535 | QTest::newRow("scound") << QRectF(10,10,50,50) << QSizeF(1000,1000) << QRectF(20,20,100,100) << QSizeF(1000,1000) << QRectF(50,50,100,100) << QSizeF(1000,1000); |
|
535 | 536 | QTest::newRow("third") << QRectF(10,10,10,10) << QSizeF(100,100) << QRectF(20,20,20,20) << QSizeF(100,100) << QRectF(50,50,50,50) << QSizeF(100,100); |
|
536 | 537 | } |
|
537 | 538 | |
|
538 | 539 | void tst_Domain::zoom() |
|
539 | 540 | { |
|
540 | 541 | QFETCH(QRectF, rect0); |
|
541 | 542 | QFETCH(QSizeF, size0); |
|
542 | 543 | QFETCH(QRectF, rect1); |
|
543 | 544 | QFETCH(QSizeF, size1); |
|
544 | 545 | QFETCH(QRectF, rect2); |
|
545 | 546 | QFETCH(QSizeF, size2); |
|
546 | 547 | |
|
547 | 548 | Domain domain; |
|
548 | 549 | |
|
549 | 550 | domain.setRange(0,1000,0,1000); |
|
550 | 551 | |
|
551 | 552 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); |
|
552 | 553 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); |
|
553 | 554 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); |
|
554 | 555 | |
|
555 | 556 | Domain domain0; |
|
556 | 557 | domain0.setRange(domain.minX(),domain.maxX(),domain.minY(),domain.maxY()); |
|
557 | 558 | domain.zoomIn(rect0, size0); |
|
558 | 559 | Domain domain1; |
|
559 | 560 | domain1.setRange(domain.minX(),domain.maxX(),domain.minY(),domain.maxY()); |
|
560 | 561 | domain.zoomIn(rect1, size1); |
|
561 | 562 | Domain domain2; |
|
562 | 563 | domain2.setRange(domain.minX(),domain.maxX(),domain.minY(),domain.maxY()); |
|
563 | 564 | domain.zoomIn(rect2, size2); |
|
564 | 565 | domain.zoomOut(rect2, size2); |
|
565 | 566 | QCOMPARE(domain == domain2,true); |
|
566 | 567 | domain.zoomOut(rect1, size1); |
|
567 | 568 | QCOMPARE(domain == domain1,true); |
|
568 | 569 | domain.zoomOut(rect0, size0); |
|
569 | 570 | QCOMPARE(domain == domain0,true); |
|
570 | 571 | QCOMPARE(spy0.count(), 6); |
|
571 | 572 | QCOMPARE(spy1.count(), 6); |
|
572 | 573 | QCOMPARE(spy2.count(), 6); |
|
573 | 574 | |
|
574 | 575 | } |
|
575 | 576 | |
|
576 | 577 | QTEST_MAIN(tst_Domain) |
|
577 | 578 | #include "tst_domain.moc" |
|
578 | 579 |
General Comments 0
You need to be logged in to leave comments.
Login now