@@ -1,93 +1,93 | |||||
1 | #include "bar_p.h" |
|
1 | #include "bar_p.h" | |
2 | #include <QDebug> |
|
2 | #include <QDebug> | |
3 | #include <QPainter> |
|
3 | #include <QPainter> | |
4 | #include <QGraphicsSceneEvent> |
|
4 | #include <QGraphicsSceneEvent> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | Bar::Bar(QString category, QGraphicsItem *parent) |
|
8 | Bar::Bar(QString category, QGraphicsItem *parent) | |
9 | : QGraphicsObject(parent), |
|
9 | : QGraphicsObject(parent), | |
10 | mCategory(category), |
|
|||
11 | mXpos(0), |
|
10 | mXpos(0), | |
12 | mYpos(0), |
|
11 | mYpos(0), | |
13 | mWidth(0), |
|
12 | mWidth(0), | |
14 | mHeight(0) |
|
13 | mHeight(0), | |
|
14 | mCategory(category) | |||
15 | { |
|
15 | { | |
16 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
16 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | |
17 | setAcceptHoverEvents(true); |
|
17 | setAcceptHoverEvents(true); | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 | void Bar::setSize(const QSizeF& size) |
|
20 | void Bar::setSize(const QSizeF& size) | |
21 | { |
|
21 | { | |
22 | mWidth = size.width(); |
|
22 | mWidth = size.width(); | |
23 | mHeight = size.height(); |
|
23 | mHeight = size.height(); | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | void Bar::resize( qreal w, qreal h ) |
|
27 | void Bar::resize( qreal w, qreal h ) | |
28 | { |
|
28 | { | |
29 | mWidth = w; |
|
29 | mWidth = w; | |
30 | mHeight = h; |
|
30 | mHeight = h; | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | void Bar::setPos(qreal x, qreal y) |
|
33 | void Bar::setPos(qreal x, qreal y) | |
34 | { |
|
34 | { | |
35 | mXpos = x; |
|
35 | mXpos = x; | |
36 | mYpos = y; |
|
36 | mYpos = y; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | void Bar::setPen(QPen pen) |
|
39 | void Bar::setPen(QPen pen) | |
40 | { |
|
40 | { | |
41 | mPen = pen; |
|
41 | mPen = pen; | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | void Bar::setBrush(QBrush brush) |
|
44 | void Bar::setBrush(QBrush brush) | |
45 | { |
|
45 | { | |
46 | mBrush = brush; |
|
46 | mBrush = brush; | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
49 | void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
50 | { |
|
50 | { | |
51 | if (0 == mHeight) { |
|
51 | if (0 == mHeight) { | |
52 | return; |
|
52 | return; | |
53 | } |
|
53 | } | |
54 | painter->setBrush(mBrush); |
|
54 | painter->setBrush(mBrush); | |
55 |
|
55 | |||
56 | // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1. |
|
56 | // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1. | |
57 | int x0 = mXpos; |
|
57 | int x0 = mXpos; | |
58 | int x1 = (mXpos + mWidth); |
|
58 | int x1 = (mXpos + mWidth); | |
59 | int w = x1-x0; |
|
59 | int w = x1-x0; | |
60 | int y0 = mYpos; |
|
60 | int y0 = mYpos; | |
61 | int y1 = (mYpos + mHeight); |
|
61 | int y1 = (mYpos + mHeight); | |
62 | int h = y1-y0; |
|
62 | int h = y1-y0; | |
63 | painter->drawRect(x0, y0 ,w ,h); |
|
63 | painter->drawRect(x0, y0 ,w ,h); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QRectF Bar::boundingRect() const |
|
66 | QRectF Bar::boundingRect() const | |
67 | { |
|
67 | { | |
68 | QRectF r(mXpos, mYpos, mWidth, mHeight); |
|
68 | QRectF r(mXpos, mYpos, mWidth, mHeight); | |
69 | return r; |
|
69 | return r; | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent* event) |
|
72 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent* event) | |
73 | { |
|
73 | { | |
74 | if (event->button() == Qt::LeftButton) { |
|
74 | if (event->button() == Qt::LeftButton) { | |
75 | emit clicked(mCategory); |
|
75 | emit clicked(mCategory); | |
76 | } else if (event->button() == Qt::RightButton) { |
|
76 | } else if (event->button() == Qt::RightButton) { | |
77 | emit rightClicked(mCategory); |
|
77 | emit rightClicked(mCategory); | |
78 | } |
|
78 | } | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* event) |
|
81 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* event) | |
82 | { |
|
82 | { | |
83 | emit hoverEntered(event->lastScreenPos()); |
|
83 | emit hoverEntered(event->lastScreenPos()); | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) |
|
86 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) | |
87 | { |
|
87 | { | |
88 | emit hoverLeaved(); |
|
88 | emit hoverLeaved(); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | #include "moc_bar_p.cpp" |
|
91 | #include "moc_bar_p.cpp" | |
92 |
|
92 | |||
93 | QTCOMMERCIALCHART_END_NAMESPACE |
|
93 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,184 +1,184 | |||||
1 | #include "barpresenterbase_p.h" |
|
1 | #include "barpresenterbase_p.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barvalue_p.h" |
|
3 | #include "barvalue_p.h" | |
4 | #include "separator_p.h" |
|
4 | #include "separator_p.h" | |
5 | #include "qbarset.h" |
|
5 | #include "qbarset.h" | |
6 | #include "qbarseries.h" |
|
6 | #include "qbarseries.h" | |
7 | #include "qchart.h" |
|
7 | #include "qchart.h" | |
8 | #include "qchartaxis.h" |
|
8 | #include "qchartaxis.h" | |
9 | #include "qchartaxiscategories.h" |
|
9 | #include "qchartaxiscategories.h" | |
10 | #include "chartpresenter_p.h" |
|
10 | #include "chartpresenter_p.h" | |
11 | #include <QDebug> |
|
11 | #include <QDebug> | |
12 | #include <QToolTip> |
|
12 | #include <QToolTip> | |
13 |
|
13 | |||
14 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
14 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
15 |
|
15 | |||
16 | BarPresenterBase::BarPresenterBase(QBarSeries *series, QChart *parent) : |
|
16 | BarPresenterBase::BarPresenterBase(QBarSeries *series, QChart *parent) : | |
17 | ChartItem(parent), |
|
17 | ChartItem(parent), | |
|
18 | mHeight(0), | |||
|
19 | mWidth(0), | |||
18 | mLayoutSet(false), |
|
20 | mLayoutSet(false), | |
19 | mSeries(series), |
|
21 | mSeries(series), | |
20 |
mChart(parent) |
|
22 | mChart(parent) | |
21 | mWidth(0), |
|
|||
22 | mHeight(0) |
|
|||
23 | { |
|
23 | { | |
24 | connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); |
|
24 | connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); | |
25 | // connect(series,SIGNAL(enableSeparators(bool)),this,SLOT(enableSeparators(bool))); |
|
25 | // connect(series,SIGNAL(enableSeparators(bool)),this,SLOT(enableSeparators(bool))); | |
26 | // enableSeparators(series->separatorsVisible()); |
|
26 | // enableSeparators(series->separatorsVisible()); | |
27 | setZValue(ChartPresenter::BarSeriesZValue); |
|
27 | setZValue(ChartPresenter::BarSeriesZValue); | |
28 | initAxisLabels(); |
|
28 | initAxisLabels(); | |
29 | dataChanged(); |
|
29 | dataChanged(); | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | BarPresenterBase::~BarPresenterBase() |
|
32 | BarPresenterBase::~BarPresenterBase() | |
33 | { |
|
33 | { | |
34 | disconnect(this,SLOT(showToolTip(QPoint,QString))); |
|
34 | disconnect(this,SLOT(showToolTip(QPoint,QString))); | |
35 | disconnect(this,SLOT(enableSeparators(bool))); |
|
35 | disconnect(this,SLOT(enableSeparators(bool))); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
38 | void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
39 | { |
|
39 | { | |
40 | if (!mLayoutSet) { |
|
40 | if (!mLayoutSet) { | |
41 | qDebug() << "BarPresenterBase::paint called without layout set. Aborting."; |
|
41 | qDebug() << "BarPresenterBase::paint called without layout set. Aborting."; | |
42 | return; |
|
42 | return; | |
43 | } |
|
43 | } | |
44 | foreach(QGraphicsItem* i, childItems()) { |
|
44 | foreach(QGraphicsItem* i, childItems()) { | |
45 | i->paint(painter,option,widget); |
|
45 | i->paint(painter,option,widget); | |
46 | } |
|
46 | } | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | QRectF BarPresenterBase::boundingRect() const |
|
49 | QRectF BarPresenterBase::boundingRect() const | |
50 | { |
|
50 | { | |
51 | return QRectF(0, 0, mWidth, mHeight); |
|
51 | return QRectF(0, 0, mWidth, mHeight); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void BarPresenterBase::dataChanged() |
|
54 | void BarPresenterBase::dataChanged() | |
55 | { |
|
55 | { | |
56 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? |
|
56 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? | |
57 | // Delete old bars |
|
57 | // Delete old bars | |
58 | foreach (QGraphicsItem* item, childItems()) { |
|
58 | foreach (QGraphicsItem* item, childItems()) { | |
59 | delete item; |
|
59 | delete item; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | mBars.clear(); |
|
62 | mBars.clear(); | |
63 | // mSeparators.clear(); |
|
63 | // mSeparators.clear(); | |
64 | mFloatingValues.clear(); |
|
64 | mFloatingValues.clear(); | |
65 |
|
65 | |||
66 | // Create new graphic items for bars |
|
66 | // Create new graphic items for bars | |
67 | for (int c=0; c<mSeries->categoryCount(); c++) { |
|
67 | for (int c=0; c<mSeries->categoryCount(); c++) { | |
68 | QString category = mSeries->categoryName(c); |
|
68 | QString category = mSeries->categoryName(c); | |
69 | for (int s=0; s<mSeries->barsetCount(); s++) { |
|
69 | for (int s=0; s<mSeries->barsetCount(); s++) { | |
70 | QBarSet *set = mSeries->barsetAt(s); |
|
70 | QBarSet *set = mSeries->barsetAt(s); | |
71 | Bar *bar = new Bar(category,this); |
|
71 | Bar *bar = new Bar(category,this); | |
72 | childItems().append(bar); |
|
72 | childItems().append(bar); | |
73 | mBars.append(bar); |
|
73 | mBars.append(bar); | |
74 | connect(bar,SIGNAL(clicked(QString)),set,SIGNAL(clicked(QString))); |
|
74 | connect(bar,SIGNAL(clicked(QString)),set,SIGNAL(clicked(QString))); | |
75 | connect(bar,SIGNAL(rightClicked(QString)),set,SIGNAL(rightClicked(QString))); |
|
75 | connect(bar,SIGNAL(rightClicked(QString)),set,SIGNAL(rightClicked(QString))); | |
76 | connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint))); |
|
76 | connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint))); | |
77 | connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent())); |
|
77 | connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent())); | |
78 | } |
|
78 | } | |
79 | } |
|
79 | } | |
80 | /* |
|
80 | /* | |
81 | // Create separators |
|
81 | // Create separators | |
82 | int count = mSeries->categoryCount() - 1; // There is one less separator than columns |
|
82 | int count = mSeries->categoryCount() - 1; // There is one less separator than columns | |
83 | for (int i=0; i<count; i++) { |
|
83 | for (int i=0; i<count; i++) { | |
84 | Separator* sep = new Separator(this); |
|
84 | Separator* sep = new Separator(this); | |
85 | sep->setVisible(mSeries->separatorsVisible()); |
|
85 | sep->setVisible(mSeries->separatorsVisible()); | |
86 | childItems().append(sep); |
|
86 | childItems().append(sep); | |
87 | mSeparators.append(sep); |
|
87 | mSeparators.append(sep); | |
88 | } |
|
88 | } | |
89 | */ |
|
89 | */ | |
90 | // Create floating values |
|
90 | // Create floating values | |
91 | for (int category=0; category<mSeries->categoryCount(); category++) { |
|
91 | for (int category=0; category<mSeries->categoryCount(); category++) { | |
92 | for (int s=0; s<mSeries->barsetCount(); s++) { |
|
92 | for (int s=0; s<mSeries->barsetCount(); s++) { | |
93 | QBarSet *set = mSeries->barsetAt(s); |
|
93 | QBarSet *set = mSeries->barsetAt(s); | |
94 | BarValue *value = new BarValue(*set, this); |
|
94 | BarValue *value = new BarValue(*set, this); | |
95 | childItems().append(value); |
|
95 | childItems().append(value); | |
96 | mFloatingValues.append(value); |
|
96 | mFloatingValues.append(value); | |
97 | connect(set,SIGNAL(toggleFloatingValues()),value,SLOT(toggleVisible())); |
|
97 | connect(set,SIGNAL(toggleFloatingValues()),value,SLOT(toggleVisible())); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void BarPresenterBase::initAxisLabels() |
|
102 | void BarPresenterBase::initAxisLabels() | |
103 | { |
|
103 | { | |
104 | int count = mSeries->categoryCount(); |
|
104 | int count = mSeries->categoryCount(); | |
105 | if (0 == count) { |
|
105 | if (0 == count) { | |
106 | return; |
|
106 | return; | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | mChart->axisX()->setTicksCount(count+2); |
|
109 | mChart->axisX()->setTicksCount(count+2); | |
110 |
|
110 | |||
111 | qreal min = 0; |
|
111 | qreal min = 0; | |
112 | qreal max = count+1; |
|
112 | qreal max = count+1; | |
113 |
|
113 | |||
114 | mChart->axisX()->setMin(min); |
|
114 | mChart->axisX()->setMin(min); | |
115 | mChart->axisX()->setMax(max); |
|
115 | mChart->axisX()->setMax(max); | |
116 |
|
116 | |||
117 | QChartAxisCategories* categories = mChart->axisX()->categories(); |
|
117 | QChartAxisCategories* categories = mChart->axisX()->categories(); | |
118 | categories->clear(); |
|
118 | categories->clear(); | |
119 | for (int i=0; i<count; i++) { |
|
119 | for (int i=0; i<count; i++) { | |
120 | categories->insert(i+1,mSeries->categoryName(i)); |
|
120 | categories->insert(i+1,mSeries->categoryName(i)); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 |
|
123 | |||
124 |
|
124 | |||
125 | mChart->axisX()->setLabelsVisible(true); |
|
125 | mChart->axisX()->setLabelsVisible(true); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | //handlers |
|
128 | //handlers | |
129 |
|
129 | |||
130 | void BarPresenterBase::handleModelChanged(int index) |
|
130 | void BarPresenterBase::handleModelChanged(int index) | |
131 | { |
|
131 | { | |
132 | // qDebug() << "BarPresenterBase::handleModelChanged" << index; |
|
132 | // qDebug() << "BarPresenterBase::handleModelChanged" << index; | |
133 | dataChanged(); |
|
133 | dataChanged(); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | void BarPresenterBase::handleDomainChanged(const Domain& domain) |
|
136 | void BarPresenterBase::handleDomainChanged(const Domain& domain) | |
137 | { |
|
137 | { | |
138 | qDebug() << "BarPresenterBase::handleDomainChanged"; |
|
138 | qDebug() << "BarPresenterBase::handleDomainChanged"; | |
139 | /* |
|
139 | /* | |
140 | int count = mSeries->categoryCount(); |
|
140 | int count = mSeries->categoryCount(); | |
141 | if (0 == count) { |
|
141 | if (0 == count) { | |
142 | return; |
|
142 | return; | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | // Position labels to domain |
|
145 | // Position labels to domain | |
146 | qreal min = domain.minX(); |
|
146 | qreal min = domain.minX(); | |
147 | qreal max = domain.maxX(); |
|
147 | qreal max = domain.maxX(); | |
148 | qreal step = (max-min)/count; |
|
148 | qreal step = (max-min)/count; | |
149 | QChartAxisCategories& categories = mChart->axisX()->categories(); |
|
149 | QChartAxisCategories& categories = mChart->axisX()->categories(); | |
150 | categories.clear(); |
|
150 | categories.clear(); | |
151 | for (int i=0; i<count; i++) { |
|
151 | for (int i=0; i<count; i++) { | |
152 | categories.insert(min,mSeries->categoryName(i)); |
|
152 | categories.insert(min,mSeries->categoryName(i)); | |
153 | min += step; |
|
153 | min += step; | |
154 | } |
|
154 | } | |
155 | */ |
|
155 | */ | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | void BarPresenterBase::handleGeometryChanged(const QRectF& rect) |
|
158 | void BarPresenterBase::handleGeometryChanged(const QRectF& rect) | |
159 | { |
|
159 | { | |
160 | mWidth = rect.width(); |
|
160 | mWidth = rect.width(); | |
161 | mHeight = rect.height(); |
|
161 | mHeight = rect.height(); | |
162 | layoutChanged(); |
|
162 | layoutChanged(); | |
163 | mLayoutSet = true; |
|
163 | mLayoutSet = true; | |
164 | setPos(rect.topLeft()); |
|
164 | setPos(rect.topLeft()); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | void BarPresenterBase::showToolTip(QPoint pos, QString tip) |
|
167 | void BarPresenterBase::showToolTip(QPoint pos, QString tip) | |
168 | { |
|
168 | { | |
169 | // TODO: cool tooltip instead of default |
|
169 | // TODO: cool tooltip instead of default | |
170 | QToolTip::showText(pos,tip); |
|
170 | QToolTip::showText(pos,tip); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | /* |
|
173 | /* | |
174 | void BarPresenterBase::enableSeparators(bool enabled) |
|
174 | void BarPresenterBase::enableSeparators(bool enabled) | |
175 | { |
|
175 | { | |
176 | for (int i=0; i<mSeparators.count(); i++) { |
|
176 | for (int i=0; i<mSeparators.count(); i++) { | |
177 | mSeparators.at(i)->setVisible(enabled); |
|
177 | mSeparators.at(i)->setVisible(enabled); | |
178 | } |
|
178 | } | |
179 | } |
|
179 | } | |
180 | */ |
|
180 | */ | |
181 |
|
181 | |||
182 | #include "moc_barpresenterbase_p.cpp" |
|
182 | #include "moc_barpresenterbase_p.cpp" | |
183 |
|
183 | |||
184 | QTCOMMERCIALCHART_END_NAMESPACE |
|
184 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,242 +1,242 | |||||
1 | #include <QDebug> |
|
1 | #include <QDebug> | |
2 | #include "qbarseries.h" |
|
2 | #include "qbarseries.h" | |
3 | #include "qbarset.h" |
|
3 | #include "qbarset.h" | |
4 | #include "barchartmodel_p.h" |
|
4 | #include "barchartmodel_p.h" | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | /*! |
|
8 | /*! | |
9 | \class QBarSeries |
|
9 | \class QBarSeries | |
10 | \brief part of QtCommercial chart API. |
|
10 | \brief part of QtCommercial chart API. | |
11 |
|
11 | |||
12 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible |
|
12 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | |
13 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
13 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
14 | by QStringList. |
|
14 | by QStringList. | |
15 |
|
15 | |||
16 | \mainclass |
|
16 | \mainclass | |
17 |
|
17 | |||
18 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
18 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
19 | */ |
|
19 | */ | |
20 |
|
20 | |||
21 | /*! |
|
21 | /*! | |
22 | \fn virtual QSeriesType QBarSeries::type() const |
|
22 | \fn virtual QSeriesType QBarSeries::type() const | |
23 | \brief Returns type of series. |
|
23 | \brief Returns type of series. | |
24 | \sa QSeries, QSeriesType |
|
24 | \sa QSeries, QSeriesType | |
25 | */ |
|
25 | */ | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) |
|
28 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | |
29 | \brief \internal \a pos \a tip |
|
29 | \brief \internal \a pos \a tip | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
34 | QBarSeries is QObject which is a child of a \a parent. |
|
34 | QBarSeries is QObject which is a child of a \a parent. | |
35 | */ |
|
35 | */ | |
36 | QBarSeries::QBarSeries(QStringList categories, QObject *parent) |
|
36 | QBarSeries::QBarSeries(QStringList categories, QObject *parent) | |
37 | : QSeries(parent) |
|
37 | : QSeries(parent) | |
38 | ,mModel(new BarChartModel(categories, this)) |
|
38 | ,mModel(new BarChartModel(categories, this)) | |
39 | { |
|
39 | { | |
40 | m_model = NULL; |
|
40 | m_model = NULL; | |
41 | m_mapCategories = -1; |
|
41 | m_mapCategories = -1; | |
42 |
m_mapBarBottom - |
|
42 | m_mapBarBottom = -1; | |
43 |
m_mapBarTop - |
|
43 | m_mapBarTop = -1; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | /*! |
|
46 | /*! | |
47 | Adds a set of bars to series. Takes ownership of \a set. |
|
47 | Adds a set of bars to series. Takes ownership of \a set. | |
48 | Connects the clicked(QString) and rightClicked(QString) signals |
|
48 | Connects the clicked(QString) and rightClicked(QString) signals | |
49 | of \a set to this series |
|
49 | of \a set to this series | |
50 | */ |
|
50 | */ | |
51 | void QBarSeries::addBarSet(QBarSet *set) |
|
51 | void QBarSeries::addBarSet(QBarSet *set) | |
52 | { |
|
52 | { | |
53 | mModel->addBarSet(set); |
|
53 | mModel->addBarSet(set); | |
54 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
54 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | |
55 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
55 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
59 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
60 | Disconnects the clicked(QString) and rightClicked(QString) signals |
|
60 | Disconnects the clicked(QString) and rightClicked(QString) signals | |
61 | of \a set from this series |
|
61 | of \a set from this series | |
62 | */ |
|
62 | */ | |
63 | void QBarSeries::removeBarSet(QBarSet *set) |
|
63 | void QBarSeries::removeBarSet(QBarSet *set) | |
64 | { |
|
64 | { | |
65 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
65 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | |
66 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
66 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | |
67 | mModel->removeBarSet(set); |
|
67 | mModel->removeBarSet(set); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | Returns number of sets in series. |
|
71 | Returns number of sets in series. | |
72 | */ |
|
72 | */ | |
73 | int QBarSeries::barsetCount() |
|
73 | int QBarSeries::barsetCount() | |
74 | { |
|
74 | { | |
75 | if(m_model) |
|
75 | if(m_model) | |
76 | return m_mapBarTop - m_mapBarBottom; |
|
76 | return m_mapBarTop - m_mapBarBottom; | |
77 | else |
|
77 | else | |
78 | return mModel->barsetCount(); |
|
78 | return mModel->barsetCount(); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | Returns number of categories in series |
|
82 | Returns number of categories in series | |
83 | */ |
|
83 | */ | |
84 | int QBarSeries::categoryCount() |
|
84 | int QBarSeries::categoryCount() | |
85 | { |
|
85 | { | |
86 | return mModel->categoryCount(); |
|
86 | return mModel->categoryCount(); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | Returns a list of sets in series. Keeps ownership of sets. |
|
90 | Returns a list of sets in series. Keeps ownership of sets. | |
91 | */ |
|
91 | */ | |
92 | QList<QBarSet*> QBarSeries::barSets() |
|
92 | QList<QBarSet*> QBarSeries::barSets() | |
93 | { |
|
93 | { | |
94 | return mModel->barSets(); |
|
94 | return mModel->barSets(); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | /*! |
|
97 | /*! | |
98 | \internal \a index |
|
98 | \internal \a index | |
99 | */ |
|
99 | */ | |
100 | QBarSet* QBarSeries::barsetAt(int index) |
|
100 | QBarSet* QBarSeries::barsetAt(int index) | |
101 | { |
|
101 | { | |
102 | return mModel->setAt(index); |
|
102 | return mModel->setAt(index); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \internal \a category |
|
106 | \internal \a category | |
107 | */ |
|
107 | */ | |
108 | QString QBarSeries::categoryName(int category) |
|
108 | QString QBarSeries::categoryName(int category) | |
109 | { |
|
109 | { | |
110 | return mModel->categoryName(category); |
|
110 | return mModel->categoryName(category); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | /*! |
|
113 | /*! | |
114 | Enables or disables tooltip depending on parameter \a enabled. |
|
114 | Enables or disables tooltip depending on parameter \a enabled. | |
115 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
115 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
116 | Calling without parameter \a enabled, enables the tooltip |
|
116 | Calling without parameter \a enabled, enables the tooltip | |
117 | */ |
|
117 | */ | |
118 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
118 | void QBarSeries::setToolTipEnabled(bool enabled) | |
119 | { |
|
119 | { | |
120 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
120 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
121 | if (enabled) { |
|
121 | if (enabled) { | |
122 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
122 | for (int i=0; i<mModel->barsetCount(); i++) { | |
123 | QBarSet *set = mModel->setAt(i); |
|
123 | QBarSet *set = mModel->setAt(i); | |
124 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
124 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
125 | } |
|
125 | } | |
126 | } else { |
|
126 | } else { | |
127 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
127 | for (int i=0; i<mModel->barsetCount(); i++) { | |
128 | QBarSet *set = mModel->setAt(i); |
|
128 | QBarSet *set = mModel->setAt(i); | |
129 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
129 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
130 | } |
|
130 | } | |
131 | } |
|
131 | } | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | Enables or disables separators depending on parameter \a enabled. |
|
135 | Enables or disables separators depending on parameter \a enabled. | |
136 | Separators are visual elements that are drawn between categories. |
|
136 | Separators are visual elements that are drawn between categories. | |
137 | Calling without parameter \a enabled, enables the separators |
|
137 | Calling without parameter \a enabled, enables the separators | |
138 | */ |
|
138 | */ | |
139 | void QBarSeries::setSeparatorsVisible(bool visible) |
|
139 | void QBarSeries::setSeparatorsVisible(bool visible) | |
140 | { |
|
140 | { | |
141 | mSeparatorsVisible = visible; |
|
141 | mSeparatorsVisible = visible; | |
142 | emit enableSeparators(visible); |
|
142 | emit enableSeparators(visible); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 |
|
145 | |||
146 | /*! |
|
146 | /*! | |
147 | \internal \a category |
|
147 | \internal \a category | |
148 | */ |
|
148 | */ | |
149 | void QBarSeries::barsetClicked(QString category) |
|
149 | void QBarSeries::barsetClicked(QString category) | |
150 | { |
|
150 | { | |
151 | emit clicked(qobject_cast<QBarSet*>(sender()), category); |
|
151 | emit clicked(qobject_cast<QBarSet*>(sender()), category); | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \internal \a category |
|
155 | \internal \a category | |
156 | */ |
|
156 | */ | |
157 | void QBarSeries::barsetRightClicked(QString category) |
|
157 | void QBarSeries::barsetRightClicked(QString category) | |
158 | { |
|
158 | { | |
159 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); |
|
159 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | \internal |
|
164 | \internal | |
165 | */ |
|
165 | */ | |
166 | qreal QBarSeries::min() |
|
166 | qreal QBarSeries::min() | |
167 | { |
|
167 | { | |
168 | return mModel->min(); |
|
168 | return mModel->min(); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | \internal |
|
172 | \internal | |
173 | */ |
|
173 | */ | |
174 | qreal QBarSeries::max() |
|
174 | qreal QBarSeries::max() | |
175 | { |
|
175 | { | |
176 | return mModel->max(); |
|
176 | return mModel->max(); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | \internal \a set \a category |
|
180 | \internal \a set \a category | |
181 | */ |
|
181 | */ | |
182 | qreal QBarSeries::valueAt(int set, int category) |
|
182 | qreal QBarSeries::valueAt(int set, int category) | |
183 | { |
|
183 | { | |
184 | return mModel->valueAt(set,category); |
|
184 | return mModel->valueAt(set,category); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
188 | \internal \a set \a category |
|
188 | \internal \a set \a category | |
189 | */ |
|
189 | */ | |
190 | qreal QBarSeries::percentageAt(int set, int category) |
|
190 | qreal QBarSeries::percentageAt(int set, int category) | |
191 | { |
|
191 | { | |
192 | return mModel->percentageAt(set,category); |
|
192 | return mModel->percentageAt(set,category); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | /*! |
|
195 | /*! | |
196 | \internal \a category |
|
196 | \internal \a category | |
197 | */ |
|
197 | */ | |
198 | qreal QBarSeries::categorySum(int category) |
|
198 | qreal QBarSeries::categorySum(int category) | |
199 | { |
|
199 | { | |
200 | return mModel->categorySum(category); |
|
200 | return mModel->categorySum(category); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | \internal |
|
204 | \internal | |
205 | */ |
|
205 | */ | |
206 | qreal QBarSeries::maxCategorySum() |
|
206 | qreal QBarSeries::maxCategorySum() | |
207 | { |
|
207 | { | |
208 | return mModel->maxCategorySum(); |
|
208 | return mModel->maxCategorySum(); | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | /*! |
|
211 | /*! | |
212 | \internal |
|
212 | \internal | |
213 | */ |
|
213 | */ | |
214 | BarChartModel& QBarSeries::model() |
|
214 | BarChartModel& QBarSeries::model() | |
215 | { |
|
215 | { | |
216 | return *mModel; |
|
216 | return *mModel; | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | bool QBarSeries::separatorsVisible() |
|
219 | bool QBarSeries::separatorsVisible() | |
220 | { |
|
220 | { | |
221 | return mSeparatorsVisible; |
|
221 | return mSeparatorsVisible; | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | bool QBarSeries::setModel(QAbstractItemModel* model) |
|
224 | bool QBarSeries::setModel(QAbstractItemModel* model) | |
225 | { |
|
225 | { | |
226 | m_model = model; |
|
226 | m_model = model; | |
227 | return true; |
|
227 | return true; | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | void QBarSeries::setModelMappingCategories(int modelColumn) |
|
230 | void QBarSeries::setModelMappingCategories(int modelColumn) | |
231 | { |
|
231 | { | |
232 | // |
|
232 | // | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | void QBarSeries::setModelMappingBarRange(int bottomBoundry, int topBoundry) |
|
235 | void QBarSeries::setModelMappingBarRange(int bottomBoundry, int topBoundry) | |
236 | { |
|
236 | { | |
237 | // |
|
237 | // | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | #include "moc_qbarseries.cpp" |
|
240 | #include "moc_qbarseries.cpp" | |
241 |
|
241 | |||
242 | QTCOMMERCIALCHART_END_NAMESPACE |
|
242 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,319 +1,319 | |||||
1 | #include "chartdataset_p.h" |
|
1 | #include "chartdataset_p.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | //series |
|
3 | //series | |
4 | #include "qlineseries.h" |
|
4 | #include "qlineseries.h" | |
5 | #include "qareaseries.h" |
|
5 | #include "qareaseries.h" | |
6 | #include "qbarseries.h" |
|
6 | #include "qbarseries.h" | |
7 | #include "qstackedbarseries.h" |
|
7 | #include "qstackedbarseries.h" | |
8 | #include "qpercentbarseries.h" |
|
8 | #include "qpercentbarseries.h" | |
9 | #include "qpieseries.h" |
|
9 | #include "qpieseries.h" | |
10 | #include "qscatterseries.h" |
|
10 | #include "qscatterseries.h" | |
11 | #include "qsplineseries.h" |
|
11 | #include "qsplineseries.h" | |
12 |
|
12 | |||
13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
14 |
|
14 | |||
15 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), |
|
15 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), | |
16 | m_axisX(new QChartAxis(this)), |
|
16 | m_axisX(new QChartAxis(this)), | |
17 | m_axisY(new QChartAxis(this)), |
|
17 | m_axisY(new QChartAxis(this)), | |
18 | m_domainIndex(0), |
|
18 | m_domainIndex(0), | |
19 | m_axisXInitialized(false) |
|
19 | m_axisXInitialized(false) | |
20 | { |
|
20 | { | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | ChartDataSet::~ChartDataSet() |
|
23 | ChartDataSet::~ChartDataSet() | |
24 | { |
|
24 | { | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) |
|
27 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |
28 | { |
|
28 | { | |
29 | if(axisY==0) axisY = m_axisY; |
|
29 | if(axisY==0) axisY = m_axisY; | |
30 |
|
30 | |||
31 | QChartAxis* axis = m_seriesAxisMap.value(series); |
|
31 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
32 |
|
32 | |||
33 | if(axis) { |
|
33 | if(axis) { | |
34 | qWarning() << "Can not add series. Series already on the chart"; |
|
34 | qWarning() << "Can not add series. Series already on the chart"; | |
35 | return; |
|
35 | return; | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | if(!series->parent()){ |
|
38 | if(!series->parent()){ | |
39 | series->setParent(this); // take ownership |
|
39 | series->setParent(this); // take ownership | |
40 | }; |
|
40 | }; | |
41 |
|
41 | |||
42 | if(!axisY->parent()){ |
|
42 | if(!axisY->parent()){ | |
43 | axisY->setParent(this); // take ownership |
|
43 | axisY->setParent(this); // take ownership | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | Domain* domain = m_axisDomainMap.value(axisY); |
|
46 | Domain* domain = m_axisDomainMap.value(axisY); | |
47 |
|
47 | |||
48 | if(!domain) { |
|
48 | if(!domain) { | |
49 | domain = new Domain(); |
|
49 | domain = new Domain(); | |
50 | QObject::connect(axisY,SIGNAL(rangeChanged(qreal,qreal)),domain,SLOT(handleAxisRangeYChanged(qreal,qreal))); |
|
50 | QObject::connect(axisY,SIGNAL(rangeChanged(qreal,qreal)),domain,SLOT(handleAxisRangeYChanged(qreal,qreal))); | |
51 | QObject::connect(axisX(),SIGNAL(rangeChanged(qreal,qreal)),domain,SLOT(handleAxisRangeXChanged(qreal,qreal))); |
|
51 | QObject::connect(axisX(),SIGNAL(rangeChanged(qreal,qreal)),domain,SLOT(handleAxisRangeXChanged(qreal,qreal))); | |
52 | QObject::connect(axisY,SIGNAL(ticksCountChanged(int)),domain,SLOT(handleAxisYTicksCountChanged(int))); |
|
52 | QObject::connect(axisY,SIGNAL(ticksCountChanged(int)),domain,SLOT(handleAxisYTicksCountChanged(int))); | |
53 | QObject::connect(axisX(),SIGNAL(ticksCountChanged(int)),domain,SLOT(handleAxisXTicksCountChanged(int))); |
|
53 | QObject::connect(axisX(),SIGNAL(ticksCountChanged(int)),domain,SLOT(handleAxisXTicksCountChanged(int))); | |
54 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY,SLOT(handleAxisRangeChanged(qreal,qreal))); |
|
54 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY,SLOT(handleAxisRangeChanged(qreal,qreal))); | |
55 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX(),SLOT(handleAxisRangeChanged(qreal,qreal))); |
|
55 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX(),SLOT(handleAxisRangeChanged(qreal,qreal))); | |
56 | //initialize |
|
56 | //initialize | |
57 | m_axisDomainMap.insert(axisY,domain); |
|
57 | m_axisDomainMap.insert(axisY,domain); | |
58 | emit axisAdded(axisY,domain); |
|
58 | emit axisAdded(axisY,domain); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | if(!m_axisXInitialized){ |
|
61 | if(!m_axisXInitialized){ | |
62 | emit axisAdded(axisX(),domain); |
|
62 | emit axisAdded(axisX(),domain); | |
63 | m_axisXInitialized=true; |
|
63 | m_axisXInitialized=true; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | calculateDomain(series,domain); |
|
66 | calculateDomain(series,domain); | |
67 |
|
67 | |||
68 | m_seriesAxisMap.insert(series,axisY); |
|
68 | m_seriesAxisMap.insert(series,axisY); | |
69 | emit seriesAdded(series,domain); |
|
69 | emit seriesAdded(series,domain); | |
70 |
|
70 | |||
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void ChartDataSet::removeSeries(QSeries* series) |
|
73 | void ChartDataSet::removeSeries(QSeries* series) | |
74 | { |
|
74 | { | |
75 |
|
75 | |||
76 | QChartAxis* axis = m_seriesAxisMap.value(series); |
|
76 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
77 |
|
77 | |||
78 | if(!axis){ |
|
78 | if(!axis){ | |
79 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
79 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
80 | return; |
|
80 | return; | |
81 | } |
|
81 | } | |
82 | emit seriesRemoved(series); |
|
82 | emit seriesRemoved(series); | |
83 | m_seriesAxisMap.remove(series); |
|
83 | m_seriesAxisMap.remove(series); | |
84 |
|
84 | |||
85 | if(series->parent()==this){ |
|
85 | if(series->parent()==this){ | |
86 | delete series; |
|
86 | delete series; | |
87 | series=0; |
|
87 | series=0; | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | QList<QChartAxis*> axes = m_seriesAxisMap.values(); |
|
90 | QList<QChartAxis*> axes = m_seriesAxisMap.values(); | |
91 |
|
91 | |||
92 | int i = axes.indexOf(axis); |
|
92 | int i = axes.indexOf(axis); | |
93 |
|
93 | |||
94 | if(i==-1){ |
|
94 | if(i==-1){ | |
95 | Domain* domain = m_axisDomainMap.take(axis); |
|
95 | Domain* domain = m_axisDomainMap.take(axis); | |
96 | emit axisRemoved(axis); |
|
96 | emit axisRemoved(axis); | |
97 | if(axis!=axisY()){ |
|
97 | if(axis!=axisY()){ | |
98 | if(axis->parent()==this){ |
|
98 | if(axis->parent()==this){ | |
99 | delete axis; |
|
99 | delete axis; | |
100 | axis=0; |
|
100 | axis=0; | |
101 | } |
|
101 | } | |
102 | } |
|
102 | } | |
103 | delete domain; |
|
103 | delete domain; | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | if(m_seriesAxisMap.values().size()==0) |
|
106 | if(m_seriesAxisMap.values().size()==0) | |
107 | { |
|
107 | { | |
108 | m_axisXInitialized=false; |
|
108 | m_axisXInitialized=false; | |
109 | emit axisRemoved(axisX()); |
|
109 | emit axisRemoved(axisX()); | |
110 | } |
|
110 | } | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void ChartDataSet::removeAllSeries() |
|
113 | void ChartDataSet::removeAllSeries() | |
114 | { |
|
114 | { | |
115 |
|
115 | |||
116 | QList<QSeries*> series = m_seriesAxisMap.keys(); |
|
116 | QList<QSeries*> series = m_seriesAxisMap.keys(); | |
117 |
|
117 | |||
118 | foreach(QSeries* s , series) { |
|
118 | foreach(QSeries* s , series) { | |
119 | removeSeries(s); |
|
119 | removeSeries(s); | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | Q_ASSERT(m_seriesAxisMap.count()==0); |
|
122 | Q_ASSERT(m_seriesAxisMap.count()==0); | |
123 | Q_ASSERT(m_axisDomainMap.count()==0); |
|
123 | Q_ASSERT(m_axisDomainMap.count()==0); | |
124 |
|
124 | |||
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | //to be removed with PIMPL |
|
127 | //to be removed with PIMPL | |
128 | void ChartDataSet::calculateDomain(QSeries* series,Domain* domain) const |
|
128 | void ChartDataSet::calculateDomain(QSeries* series,Domain* domain) const | |
129 | { |
|
129 | { | |
130 | switch(series->type()) |
|
130 | switch(series->type()) | |
131 | { |
|
131 | { | |
132 | case QSeries::SeriesTypeLine: |
|
132 | case QSeries::SeriesTypeLine: | |
133 | case QSeries::SeriesTypeSpline: |
|
133 | case QSeries::SeriesTypeSpline: | |
134 | case QSeries::SeriesTypeScatter: |
|
134 | case QSeries::SeriesTypeScatter: | |
135 | { |
|
135 | { | |
136 |
|
136 | |||
137 | QXYSeries* xySeries = static_cast<QXYSeries*>(series); |
|
137 | QXYSeries* xySeries = static_cast<QXYSeries*>(series); | |
138 |
|
138 | |||
139 | qreal minX(domain->minX()); |
|
139 | qreal minX(domain->minX()); | |
140 | qreal minY(domain->minY()); |
|
140 | qreal minY(domain->minY()); | |
141 | qreal maxX(domain->maxX()); |
|
141 | qreal maxX(domain->maxX()); | |
142 | qreal maxY(domain->maxY()); |
|
142 | qreal maxY(domain->maxY()); | |
143 |
|
143 | |||
144 | for (int i = 0; i < xySeries->count(); i++) |
|
144 | for (int i = 0; i < xySeries->count(); i++) | |
145 | { |
|
145 | { | |
146 | qreal x = xySeries->x(i); |
|
146 | qreal x = xySeries->x(i); | |
147 | qreal y = xySeries->y(i); |
|
147 | qreal y = xySeries->y(i); | |
148 | minX = qMin(minX, x); |
|
148 | minX = qMin(minX, x); | |
149 | minY = qMin(minY, y); |
|
149 | minY = qMin(minY, y); | |
150 | maxX = qMax(maxX, x); |
|
150 | maxX = qMax(maxX, x); | |
151 | maxY = qMax(maxY, y); |
|
151 | maxY = qMax(maxY, y); | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | domain->setRange(minX, maxX, minY, maxY); |
|
154 | domain->setRange(minX, maxX, minY, maxY); | |
155 | break; |
|
155 | break; | |
156 | } |
|
156 | } | |
157 | case QSeries::SeriesTypeArea: { |
|
157 | case QSeries::SeriesTypeArea: { | |
158 |
|
158 | |||
159 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
159 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
160 |
|
160 | |||
161 | QLineSeries* upperSeries = areaSeries->upperSeries(); |
|
161 | QLineSeries* upperSeries = areaSeries->upperSeries(); | |
162 | QLineSeries* lowerSeries = areaSeries->lowerSeries(); |
|
162 | QLineSeries* lowerSeries = areaSeries->lowerSeries(); | |
163 |
|
163 | |||
164 | for (int i = 0; i < upperSeries->count(); i++) |
|
164 | for (int i = 0; i < upperSeries->count(); i++) | |
165 | { |
|
165 | { | |
166 | qreal x = upperSeries->x(i); |
|
166 | qreal x = upperSeries->x(i); | |
167 | qreal y = upperSeries->y(i); |
|
167 | qreal y = upperSeries->y(i); | |
168 | domain->setMinX(qMin(domain->minX(),x)); |
|
168 | domain->setMinX(qMin(domain->minX(),x)); | |
169 | domain->setMinY(qMin(domain->minY(),y)); |
|
169 | domain->setMinY(qMin(domain->minY(),y)); | |
170 | domain->setMaxX(qMax(domain->maxX(),x)); |
|
170 | domain->setMaxX(qMax(domain->maxX(),x)); | |
171 | domain->setMaxY(qMax(domain->maxY(),y)); |
|
171 | domain->setMaxY(qMax(domain->maxY(),y)); | |
172 | } |
|
172 | } | |
173 | if(lowerSeries) { |
|
173 | if(lowerSeries) { | |
174 | for (int i = 0; i < lowerSeries->count(); i++) |
|
174 | for (int i = 0; i < lowerSeries->count(); i++) | |
175 | { |
|
175 | { | |
176 | qreal x = lowerSeries->x(i); |
|
176 | qreal x = lowerSeries->x(i); | |
177 | qreal y = lowerSeries->y(i); |
|
177 | qreal y = lowerSeries->y(i); | |
178 | domain->setMinX(qMin(domain->minX(),x)); |
|
178 | domain->setMinX(qMin(domain->minX(),x)); | |
179 | domain->setMinY(qMin(domain->minY(),y)); |
|
179 | domain->setMinY(qMin(domain->minY(),y)); | |
180 | domain->setMaxX(qMax(domain->maxX(),x)); |
|
180 | domain->setMaxX(qMax(domain->maxX(),x)); | |
181 | domain->setMaxY(qMax(domain->maxY(),y)); |
|
181 | domain->setMaxY(qMax(domain->maxY(),y)); | |
182 | }} |
|
182 | }} | |
183 | break; |
|
183 | break; | |
184 | } |
|
184 | } | |
185 | case QSeries::SeriesTypeBar: { |
|
185 | case QSeries::SeriesTypeBar: { | |
186 | qDebug() << "QChartSeries::SeriesTypeBar"; |
|
186 | qDebug() << "QChartSeries::SeriesTypeBar"; | |
187 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
187 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
188 | qreal x = barSeries->categoryCount(); |
|
188 | qreal x = barSeries->categoryCount(); | |
189 | qreal y = barSeries->max(); |
|
189 | qreal y = barSeries->max(); | |
190 | domain->setMinX(qMin(domain->minX(),x)); |
|
190 | domain->setMinX(qMin(domain->minX(),x)); | |
191 | domain->setMinY(qMin(domain->minY(),y)); |
|
191 | domain->setMinY(qMin(domain->minY(),y)); | |
192 | domain->setMaxX(qMax(domain->maxX(),x)); |
|
192 | domain->setMaxX(qMax(domain->maxX(),x)); | |
193 | domain->setMaxY(qMax(domain->maxY(),y)); |
|
193 | domain->setMaxY(qMax(domain->maxY(),y)); | |
194 | break; |
|
194 | break; | |
195 | } |
|
195 | } | |
196 | case QSeries::SeriesTypeStackedBar: { |
|
196 | case QSeries::SeriesTypeStackedBar: { | |
197 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; |
|
197 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; | |
198 |
|
198 | |||
199 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
199 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
200 | qreal x = stackedBarSeries->categoryCount(); |
|
200 | qreal x = stackedBarSeries->categoryCount(); | |
201 | qreal y = stackedBarSeries->maxCategorySum(); |
|
201 | qreal y = stackedBarSeries->maxCategorySum(); | |
202 | domain->setMinX(qMin(domain->minX(),x)); |
|
202 | domain->setMinX(qMin(domain->minX(),x)); | |
203 | domain->setMinY(qMin(domain->minY(),y)); |
|
203 | domain->setMinY(qMin(domain->minY(),y)); | |
204 | domain->setMaxX(qMax(domain->maxX(),x)); |
|
204 | domain->setMaxX(qMax(domain->maxX(),x)); | |
205 | domain->setMaxY(qMax(domain->maxY(),y)); |
|
205 | domain->setMaxY(qMax(domain->maxY(),y)); | |
206 | break; |
|
206 | break; | |
207 | } |
|
207 | } | |
208 | case QSeries::SeriesTypePercentBar: { |
|
208 | case QSeries::SeriesTypePercentBar: { | |
209 | qDebug() << "QChartSeries::SeriesTypePercentBar"; |
|
209 | qDebug() << "QChartSeries::SeriesTypePercentBar"; | |
210 |
|
210 | |||
211 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
211 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
212 | qreal x = percentBarSeries->categoryCount(); |
|
212 | qreal x = percentBarSeries->categoryCount(); | |
213 | domain->setMinX(qMin(domain->minX(),x)); |
|
213 | domain->setMinX(qMin(domain->minX(),x)); | |
214 | domain->setMinY(0); |
|
214 | domain->setMinY(0); | |
215 | domain->setMaxX(qMax(domain->maxX(),x)); |
|
215 | domain->setMaxX(qMax(domain->maxX(),x)); | |
216 | domain->setMaxY(100); |
|
216 | domain->setMaxY(100); | |
217 | break; |
|
217 | break; | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | case QSeries::SeriesTypePie: { |
|
220 | case QSeries::SeriesTypePie: { | |
221 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
221 | //QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
222 | // TODO: domain stuff |
|
222 | // TODO: domain stuff | |
223 | break; |
|
223 | break; | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 |
|
226 | |||
227 | default: { |
|
227 | default: { | |
228 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
228 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; | |
229 | return; |
|
229 | return; | |
230 | break; |
|
230 | break; | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
236 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
237 | { |
|
237 | { | |
238 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); |
|
238 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); | |
239 | while (i.hasNext()) { |
|
239 | while (i.hasNext()) { | |
240 | i.next(); |
|
240 | i.next(); | |
241 | i.value()->zoomIn(rect,size); |
|
241 | i.value()->zoomIn(rect,size); | |
242 | } |
|
242 | } | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
245 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
246 | { |
|
246 | { | |
247 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); |
|
247 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); | |
248 | while (i.hasNext()) { |
|
248 | while (i.hasNext()) { | |
249 | i.next(); |
|
249 | i.next(); | |
250 | i.value()->zoomOut(rect,size); |
|
250 | i.value()->zoomOut(rect,size); | |
251 | } |
|
251 | } | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | int ChartDataSet::seriesCount(QSeries::QSeriesType type) |
|
254 | int ChartDataSet::seriesCount(QSeries::QSeriesType type) | |
255 | { |
|
255 | { | |
256 | int count=0; |
|
256 | int count=0; | |
257 | QMapIterator<QSeries*, QChartAxis*> i( m_seriesAxisMap); |
|
257 | QMapIterator<QSeries*, QChartAxis*> i( m_seriesAxisMap); | |
258 | while (i.hasNext()) { |
|
258 | while (i.hasNext()) { | |
259 | i.next(); |
|
259 | i.next(); | |
260 | if(i.key()->type()==type) count++; |
|
260 | if(i.key()->type()==type) count++; | |
261 | } |
|
261 | } | |
262 | return count; |
|
262 | return count; | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | int ChartDataSet::seriesIndex(QSeries *series) |
|
265 | int ChartDataSet::seriesIndex(QSeries *series) | |
266 | { |
|
266 | { | |
267 | int count(-1); |
|
267 | int count(-1); | |
268 | QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap); |
|
268 | QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap); | |
269 | while (i.hasNext()) { |
|
269 | while (i.hasNext()) { | |
270 | i.next(); |
|
270 | i.next(); | |
271 | count++; |
|
271 | count++; | |
272 | if (i.key() == series) |
|
272 | if (i.key() == series) | |
273 | return count; |
|
273 | return count; | |
274 | } |
|
274 | } | |
275 | return count; |
|
275 | return count; | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | QChartAxis* ChartDataSet::axisY(QSeries* series) const |
|
278 | QChartAxis* ChartDataSet::axisY(QSeries* series) const | |
279 | { |
|
279 | { | |
280 | if(series == 0) return m_axisY; |
|
280 | if(series == 0) return m_axisY; | |
281 | return m_seriesAxisMap.value(series); |
|
281 | return m_seriesAxisMap.value(series); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | Domain* ChartDataSet::domain(QSeries* series) const |
|
284 | Domain* ChartDataSet::domain(QSeries* series) const | |
285 | { |
|
285 | { | |
286 | QChartAxis* axis = m_seriesAxisMap.value(series); |
|
286 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
287 | if(axis){ |
|
287 | if(axis){ | |
288 | return m_axisDomainMap.value(axis); |
|
288 | return m_axisDomainMap.value(axis); | |
289 | }else |
|
289 | }else | |
290 | return 0; |
|
290 | return 0; | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | Domain* ChartDataSet::domain(QChartAxis* axis) const |
|
293 | Domain* ChartDataSet::domain(QChartAxis* axis) const | |
294 | { |
|
294 | { | |
295 | if(axis==axisX()) { |
|
295 | if(axis==axisX()) { | |
296 | return m_axisDomainMap.value(axisY()); |
|
296 | return m_axisDomainMap.value(axisY()); | |
297 | } |
|
297 | } | |
298 | else { |
|
298 | else { | |
299 | return m_axisDomainMap.value(axis); |
|
299 | return m_axisDomainMap.value(axis); | |
300 | } |
|
300 | } | |
301 | } |
|
301 | } | |
302 |
|
302 | |||
303 | QChartAxis* ChartDataSet::axis(QSeries* series) const |
|
303 | QChartAxis* ChartDataSet::axis(QSeries* series) const | |
304 | { |
|
304 | { | |
305 | return m_seriesAxisMap.value(series); |
|
305 | return m_seriesAxisMap.value(series); | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) |
|
308 | void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) | |
309 | { |
|
309 | { | |
310 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); |
|
310 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); | |
311 | while (i.hasNext()) { |
|
311 | while (i.hasNext()) { | |
312 | i.next(); |
|
312 | i.next(); | |
313 | i.value()->move(dx,dy,size); |
|
313 | i.value()->move(dx,dy,size); | |
314 | } |
|
314 | } | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | #include "moc_chartdataset_p.cpp" |
|
317 | #include "moc_chartdataset_p.cpp" | |
318 |
|
318 | |||
319 | QTCOMMERCIALCHART_END_NAMESPACE |
|
319 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,41 +1,43 | |||||
1 | #ifndef CHARTGLOBAL_H |
|
1 | #ifndef CHARTGLOBAL_H | |
2 | #define CHARTGLOBAL_H |
|
2 | #define CHARTGLOBAL_H | |
3 |
|
3 | |||
4 | #define QTCOMMERCIALCHART_VERSION_STR "1.0" |
|
4 | #define QTCOMMERCIALCHART_VERSION_STR "1.0" | |
5 | #define QTCOMMERCIALCHART_VERSION 0x01 |
|
5 | #define QTCOMMERCIALCHART_VERSION 0x01 | |
6 |
|
6 | |||
7 | #if defined(QTCOMMERCIALCHART_LIBRARY) |
|
7 | #if defined(QTCOMMERCIALCHART_LIBRARY) | |
8 | # define QTCOMMERCIALCHART_EXPORT Q_DECL_EXPORT |
|
8 | # define QTCOMMERCIALCHART_EXPORT Q_DECL_EXPORT | |
9 | #else |
|
9 | #else | |
10 | # define QTCOMMERCIALCHART_EXPORT Q_DECL_IMPORT |
|
10 | # define QTCOMMERCIALCHART_EXPORT Q_DECL_IMPORT | |
11 | #endif |
|
11 | #endif | |
12 |
|
12 | |||
13 | #define QTCOMMERCIALCHART_NAMESPACE QtCommercialChart |
|
13 | #define QTCOMMERCIALCHART_NAMESPACE QtCommercialChart | |
14 |
|
14 | |||
15 | #ifdef QTCOMMERCIALCHART_NAMESPACE |
|
15 | #ifdef QTCOMMERCIALCHART_NAMESPACE | |
16 | # define QTCOMMERCIALCHART_BEGIN_NAMESPACE namespace QTCOMMERCIALCHART_NAMESPACE { |
|
16 | # define QTCOMMERCIALCHART_BEGIN_NAMESPACE namespace QTCOMMERCIALCHART_NAMESPACE { | |
17 | # define QTCOMMERCIALCHART_END_NAMESPACE } |
|
17 | # define QTCOMMERCIALCHART_END_NAMESPACE } | |
18 | # define QTCOMMERCIALCHART_USE_NAMESPACE using namespace QTCOMMERCIALCHART_NAMESPACE; |
|
18 | # define QTCOMMERCIALCHART_USE_NAMESPACE using namespace QTCOMMERCIALCHART_NAMESPACE; | |
19 | #else |
|
19 | #else | |
20 | # define QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
20 | # define QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
21 | # define QTCOMMERCIALCHART_END_NAMESPACE |
|
21 | # define QTCOMMERCIALCHART_END_NAMESPACE | |
22 | # define QTCOMMERCIALCHART_USE_NAMESPACE |
|
22 | # define QTCOMMERCIALCHART_USE_NAMESPACE | |
23 | #endif |
|
23 | #endif | |
24 |
|
24 | |||
25 | #define CHART_DEBUG chartDebug(3,__LINE__,__FILE__,__FUNCTION__); |
|
25 | #define CHART_DEBUG chartDebug(3,__LINE__,__FILE__,__FUNCTION__); | |
26 |
|
26 | |||
27 | #include <stdarg.h> |
|
27 | #include <stdarg.h> | |
28 | #include <QDebug> |
|
28 | #include <QDebug> | |
29 |
|
29 | |||
|
30 | /* | |||
30 | static QDebug chartDebug(int numargs,...) |
|
31 | static QDebug chartDebug(int numargs,...) | |
31 |
|
|
32 | { | |
32 | va_list valist; |
|
33 | va_list valist; | |
33 | va_start(valist,numargs); |
|
34 | va_start(valist,numargs); | |
34 | //for( int i = 0 ; i < numargs; i++ ) |
|
35 | //for( int i = 0 ; i < numargs; i++ ) | |
35 | int line=va_arg(valist,int); |
|
36 | int line=va_arg(valist,int); | |
36 | char* file=va_arg(valist,char*); |
|
37 | char* file=va_arg(valist,char*); | |
37 | char* function=va_arg(valist,char*); |
|
38 | char* function=va_arg(valist,char*); | |
38 | va_end(valist); |
|
39 | va_end(valist); | |
39 | return qDebug()<<QString().append(function).append("(").append(file).append(":%1)").arg(line); |
|
40 | return qDebug()<<QString().append(function).append("(").append(file).append(":%1)").arg(line); | |
40 |
|
|
41 | } | |
|
42 | */ | |||
41 | #endif |
|
43 | #endif |
@@ -1,132 +1,134 | |||||
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) |
|
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) | |
2 | TARGET = QtCommercialChart |
|
2 | TARGET = QtCommercialChart | |
3 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
3 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
4 | TEMPLATE = lib |
|
4 | TEMPLATE = lib | |
5 | QT += core \ |
|
5 | QT += core \ | |
6 | gui |
|
6 | gui | |
7 | win32-msvc*: LIBS += User32.lib |
|
7 | win32-msvc*: LIBS += User32.lib | |
8 | CONFIG += debug_and_release |
|
8 | CONFIG += debug_and_release | |
9 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
9 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
10 | SOURCES += \ |
|
10 | SOURCES += \ | |
11 | chartdataset.cpp \ |
|
11 | chartdataset.cpp \ | |
12 | chartpresenter.cpp \ |
|
12 | chartpresenter.cpp \ | |
13 | charttheme.cpp \ |
|
13 | charttheme.cpp \ | |
14 | domain.cpp \ |
|
14 | domain.cpp \ | |
15 | qchart.cpp \ |
|
15 | qchart.cpp \ | |
16 | qchartview.cpp \ |
|
16 | qchartview.cpp \ | |
17 | qseries.cpp \ |
|
17 | qseries.cpp \ | |
18 | qlegend.cpp \ |
|
18 | qlegend.cpp \ | |
19 | legendmarker.cpp |
|
19 | legendmarker.cpp | |
20 | PRIVATE_HEADERS += \ |
|
20 | PRIVATE_HEADERS += \ | |
21 | chartdataset_p.h \ |
|
21 | chartdataset_p.h \ | |
22 | chartitem_p.h \ |
|
22 | chartitem_p.h \ | |
23 | chartpresenter_p.h \ |
|
23 | chartpresenter_p.h \ | |
24 | charttheme_p.h \ |
|
24 | charttheme_p.h \ | |
25 | domain_p.h \ |
|
25 | domain_p.h \ | |
26 | legendmarker_p.h |
|
26 | legendmarker_p.h | |
27 | PUBLIC_HEADERS += \ |
|
27 | PUBLIC_HEADERS += \ | |
28 | qchart.h \ |
|
28 | qchart.h \ | |
29 | qchartglobal.h \ |
|
29 | qchartglobal.h \ | |
30 | qseries.h \ |
|
30 | qseries.h \ | |
31 | qchartview.h \ |
|
31 | qchartview.h \ | |
32 | qlegend.h |
|
32 | qlegend.h | |
33 |
|
33 | |||
34 | include(animations/animations.pri) |
|
34 | include(animations/animations.pri) | |
35 | include(axis/axis.pri) |
|
35 | include(axis/axis.pri) | |
36 | include(xychart/xychart.pri) |
|
36 | include(xychart/xychart.pri) | |
37 | include(linechart/linechart.pri) |
|
37 | include(linechart/linechart.pri) | |
38 | include(areachart/areachart.pri) |
|
38 | include(areachart/areachart.pri) | |
39 | include(barchart/barchart.pri) |
|
39 | include(barchart/barchart.pri) | |
40 | include(piechart/piechart.pri) |
|
40 | include(piechart/piechart.pri) | |
41 | include(scatterseries/scatter.pri) |
|
41 | include(scatterseries/scatter.pri) | |
42 | include(splinechart/splinechart.pri) |
|
42 | include(splinechart/splinechart.pri) | |
43 |
|
43 | |||
44 | THEMES += themes/chartthemedefault_p.h \ |
|
44 | THEMES += themes/chartthemedefault_p.h \ | |
45 | themes/chartthemeicy_p.h \ |
|
45 | themes/chartthemeicy_p.h \ | |
46 | themes/chartthemegrayscale_p.h \ |
|
46 | themes/chartthemegrayscale_p.h \ | |
47 | themes/chartthemescientific_p.h \ |
|
47 | themes/chartthemescientific_p.h \ | |
48 | themes/chartthemevanilla_p.h \ |
|
48 | themes/chartthemevanilla_p.h \ | |
49 | themes/chartthemebluecerulean_p.h \ |
|
49 | themes/chartthemebluecerulean_p.h \ | |
50 | themes/chartthemelight_p.h |
|
50 | themes/chartthemelight_p.h | |
51 |
|
51 | |||
52 | HEADERS += $$PUBLIC_HEADERS |
|
52 | HEADERS += $$PUBLIC_HEADERS | |
53 | HEADERS += $$PRIVATE_HEADERS |
|
53 | HEADERS += $$PRIVATE_HEADERS | |
54 | HEADERS += $$THEMES |
|
54 | HEADERS += $$THEMES | |
55 | INCLUDEPATH += linechart \ |
|
55 | INCLUDEPATH += linechart \ | |
56 | barchart \ |
|
56 | barchart \ | |
57 | themes \ |
|
57 | themes \ | |
58 | . |
|
58 | . | |
59 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
59 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
60 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
60 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
61 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
61 | UI_DIR = $$CHART_BUILD_DIR/lib | |
62 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
62 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
63 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
63 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
64 |
|
64 | |||
65 | #qt public headers |
|
65 | #qt public headers | |
66 | #this is very primitive and lame parser , TODO: make perl script insted |
|
66 | #this is very primitive and lame parser , TODO: make perl script insted | |
67 | !exists($$CHART_BUILD_PUBLIC_HEADER_DIR) |
|
67 | !exists($$CHART_BUILD_PUBLIC_HEADER_DIR) | |
68 | { |
|
68 | { | |
69 | system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR) |
|
69 | system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR) | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | for(file, PUBLIC_HEADERS) { |
|
72 | for(file, PUBLIC_HEADERS) { | |
73 | name = $$split(file,'/') |
|
73 | name = $$split(file,'/') | |
74 | name = $$last(name) |
|
74 | name = $$last(name) | |
75 | class = "$$cat($$file)" |
|
75 | class = "$$cat($$file)" | |
76 | class = $$find(class,class) |
|
76 | class = $$find(class,class) | |
77 | !isEmpty(class){ |
|
77 | !isEmpty(class){ | |
78 | class = $$split(class,QTCOMMERCIALCHART_EXPORT) |
|
78 | class = $$split(class,QTCOMMERCIALCHART_EXPORT) | |
79 | class = $$member(class,1) |
|
79 | class = $$member(class,1) | |
80 | class = $$split(class,' ') |
|
80 | class = $$split(class,' ') | |
81 | class = $$replace(class,' ','') |
|
81 | class = $$replace(class,' ','') | |
82 | class = $$member(class,0) |
|
82 | class = $$member(class,0) | |
83 | command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" |
|
83 | command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" | |
84 | PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class |
|
84 | PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class | |
85 | system($$command) |
|
85 | system($$command) | |
86 | } |
|
86 | } | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
89 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
90 | public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS |
|
90 | public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS | |
91 |
|
91 | |||
92 | target.path = $$[QT_INSTALL_LIBS] |
|
92 | target.path = $$[QT_INSTALL_LIBS] | |
93 | INSTALLS += target public_headers |
|
93 | INSTALLS += target public_headers | |
94 |
|
94 | |||
95 | install_build_public_headers.name = build_public_headers |
|
95 | install_build_public_headers.name = build_public_headers | |
96 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
96 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
97 | install_build_public_headers.input = PUBLIC_HEADERS |
|
97 | install_build_public_headers.input = PUBLIC_HEADERS | |
98 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
98 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
99 | ${QMAKE_FILE_NAME} \ |
|
99 | ${QMAKE_FILE_NAME} \ | |
100 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
100 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
101 | install_build_public_headers.CONFIG += target_predeps \ |
|
101 | install_build_public_headers.CONFIG += target_predeps \ | |
102 | no_link |
|
102 | no_link | |
103 |
|
103 | |||
104 | install_build_private_headers.name = buld_private_headers |
|
104 | install_build_private_headers.name = buld_private_headers | |
105 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
105 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
106 | install_build_private_headers.input = PRIVATE_HEADERS |
|
106 | install_build_private_headers.input = PRIVATE_HEADERS | |
107 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
107 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
108 | ${QMAKE_FILE_NAME} \ |
|
108 | ${QMAKE_FILE_NAME} \ | |
109 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
109 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
110 | install_build_private_headers.CONFIG += target_predeps \ |
|
110 | install_build_private_headers.CONFIG += target_predeps \ | |
111 | no_link |
|
111 | no_link | |
112 |
|
112 | |||
113 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ |
|
113 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ | |
114 | install_build_private_headers \ |
|
114 | install_build_private_headers \ | |
115 |
|
115 | |||
116 | chartversion.target = qchartversion_p.h |
|
116 | chartversion.target = qchartversion_p.h | |
117 | chartversion.commands = @echo \ |
|
117 | chartversion.commands = @echo \ | |
118 | "build_time" \ |
|
118 | "build_time" \ | |
119 | > \ |
|
119 | > \ | |
120 | $$chartversion.target; |
|
120 | $$chartversion.target; | |
121 | chartversion.depends = $$HEADERS \ |
|
121 | chartversion.depends = $$HEADERS \ | |
122 | $$SOURCES |
|
122 | $$SOURCES | |
123 | PRE_TARGETDEPS += qchartversion_p.h |
|
123 | PRE_TARGETDEPS += qchartversion_p.h | |
124 | QMAKE_CLEAN += qchartversion_p.h |
|
124 | QMAKE_CLEAN += qchartversion_p.h | |
125 | QMAKE_EXTRA_TARGETS += chartversion |
|
125 | QMAKE_EXTRA_TARGETS += chartversion | |
126 | unix:QMAKE_DISTCLEAN += -r \ |
|
126 | unix:QMAKE_DISTCLEAN += -r \ | |
127 | $$CHART_BUILD_HEADER_DIR \ |
|
127 | $$CHART_BUILD_HEADER_DIR \ | |
128 | $$CHART_BUILD_LIB_DIR |
|
128 | $$CHART_BUILD_LIB_DIR | |
129 | win32:QMAKE_DISTCLEAN += /Q \ |
|
129 | win32:QMAKE_DISTCLEAN += /Q \ | |
130 | $$CHART_BUILD_HEADER_DIR \ |
|
130 | $$CHART_BUILD_HEADER_DIR \ | |
131 | $$CHART_BUILD_LIB_DIR |
|
131 | $$CHART_BUILD_LIB_DIR | |
132 |
|
132 | |||
|
133 | # treat warnings as errors | |||
|
134 | QMAKE_CXXFLAGS += -Werror |
@@ -1,311 +1,312 | |||||
1 | #include "qxyseries.h" |
|
1 | #include "qxyseries.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QXYSeries |
|
6 | \class QXYSeries | |
7 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
7 | \brief The QXYSeries class is a base class for line, spline and scatter series. | |
8 | */ |
|
8 | */ | |
9 |
|
9 | |||
10 | /*! |
|
10 | /*! | |
11 | \fn QPen QXYSeries::pen() const |
|
11 | \fn QPen QXYSeries::pen() const | |
12 | \brief Returns pen used to draw points for series. |
|
12 | \brief Returns pen used to draw points for series. | |
13 | \sa setPen() |
|
13 | \sa setPen() | |
14 | */ |
|
14 | */ | |
15 |
|
15 | |||
16 | /*! |
|
16 | /*! | |
17 | \fn QBrush QXYSeries::brush() const |
|
17 | \fn QBrush QXYSeries::brush() const | |
18 | \brief Returns brush used to draw points for series. |
|
18 | \brief Returns brush used to draw points for series. | |
19 | \sa setBrush() |
|
19 | \sa setBrush() | |
20 | */ |
|
20 | */ | |
21 |
|
21 | |||
22 | /*! |
|
22 | /*! | |
23 | \fn void QXYSeries::clicked(const QPointF& point) |
|
23 | \fn void QXYSeries::clicked(const QPointF& point) | |
24 | \brief Signal is emitted when user clicks the \a point on chart. |
|
24 | \brief Signal is emitted when user clicks the \a point on chart. | |
25 | */ |
|
25 | */ | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \fn void QXYSeries::pointReplaced(int index) |
|
28 | \fn void QXYSeries::pointReplaced(int index) | |
29 | \brief \internal \a index |
|
29 | \brief \internal \a index | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \fn void QXYSeries::pointAdded(int index) |
|
33 | \fn void QXYSeries::pointAdded(int index) | |
34 | \brief \internal \a index |
|
34 | \brief \internal \a index | |
35 | */ |
|
35 | */ | |
36 |
|
36 | |||
37 | /*! |
|
37 | /*! | |
38 | \fn void QXYSeries::pointRemoved(int index) |
|
38 | \fn void QXYSeries::pointRemoved(int index) | |
39 | \brief \internal \a index |
|
39 | \brief \internal \a index | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \fn void QXYSeries::updated() |
|
43 | \fn void QXYSeries::updated() | |
44 | \brief \internal |
|
44 | \brief \internal | |
45 | */ |
|
45 | */ | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | Constructs empty series object which is a child of \a parent. |
|
48 | Constructs empty series object which is a child of \a parent. | |
49 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
49 | When series object is added to QChartView or QChart instance ownerships is transfered. | |
50 | */ |
|
50 | */ | |
51 | QXYSeries::QXYSeries(QObject* parent):QSeries(parent) |
|
51 | QXYSeries::QXYSeries(QObject* parent):QSeries(parent) | |
52 | { |
|
52 | { | |
53 | m_mapX = -1; |
|
53 | m_mapX = -1; | |
54 | m_mapY = -1; |
|
54 | m_mapY = -1; | |
55 | m_mapOrientation = Qt::Vertical; |
|
55 | m_mapOrientation = Qt::Vertical; | |
56 | // m_mapYOrientation = Qt::Vertical; |
|
56 | // m_mapYOrientation = Qt::Vertical; | |
57 | } |
|
57 | } | |
58 | /*! |
|
58 | /*! | |
59 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
59 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
60 | and are deleted when mentioned object are destroyed. |
|
60 | and are deleted when mentioned object are destroyed. | |
61 | */ |
|
61 | */ | |
62 | QXYSeries::~QXYSeries() |
|
62 | QXYSeries::~QXYSeries() | |
63 | { |
|
63 | { | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
67 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
68 | */ |
|
68 | */ | |
69 | void QXYSeries::add(qreal x,qreal y) |
|
69 | void QXYSeries::add(qreal x,qreal y) | |
70 | { |
|
70 | { | |
71 | Q_ASSERT(m_x.size() == m_y.size()); |
|
71 | Q_ASSERT(m_x.size() == m_y.size()); | |
72 | m_x<<x; |
|
72 | m_x<<x; | |
73 | m_y<<y; |
|
73 | m_y<<y; | |
74 | emit pointAdded(m_x.size()-1); |
|
74 | emit pointAdded(m_x.size()-1); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | This is an overloaded function. |
|
78 | This is an overloaded function. | |
79 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
79 | Adds data \a point to the series. Points are connected with lines on the chart. | |
80 | */ |
|
80 | */ | |
81 | void QXYSeries::add(const QPointF& point) |
|
81 | void QXYSeries::add(const QPointF& point) | |
82 | { |
|
82 | { | |
83 | add(point.x(),point.y()); |
|
83 | add(point.x(),point.y()); | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | /*! |
|
86 | /*! | |
87 | This is an overloaded function. |
|
87 | This is an overloaded function. | |
88 | Adds list of data \a points to the series. Points are connected with lines on the chart. |
|
88 | Adds list of data \a points to the series. Points are connected with lines on the chart. | |
89 | */ |
|
89 | */ | |
90 | void QXYSeries::add(const QList<QPointF> points) |
|
90 | void QXYSeries::add(const QList<QPointF> points) | |
91 | { |
|
91 | { | |
92 | foreach(const QPointF& point , points) { |
|
92 | foreach(const QPointF& point , points) { | |
93 | add(point.x(),point.y()); |
|
93 | add(point.x(),point.y()); | |
94 | } |
|
94 | } | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | /*! |
|
97 | /*! | |
98 | Modifies \a y value for given \a x a value. |
|
98 | Modifies \a y value for given \a x a value. | |
99 | */ |
|
99 | */ | |
100 | void QXYSeries::replace(qreal x,qreal y) |
|
100 | void QXYSeries::replace(qreal x,qreal y) | |
101 | { |
|
101 | { | |
102 | int index = m_x.indexOf(x); |
|
102 | int index = m_x.indexOf(x); | |
103 | m_x[index]=x; |
|
103 | m_x[index]=x; | |
104 | m_y[index]=y; |
|
104 | m_y[index]=y; | |
105 | emit pointReplaced(index); |
|
105 | emit pointReplaced(index); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | This is an overloaded function. |
|
109 | This is an overloaded function. | |
110 | Replaces current y value of for given \a point x value with \a point y value. |
|
110 | Replaces current y value of for given \a point x value with \a point y value. | |
111 | */ |
|
111 | */ | |
112 | void QXYSeries::replace(const QPointF& point) |
|
112 | void QXYSeries::replace(const QPointF& point) | |
113 | { |
|
113 | { | |
114 | replace(point.x(),point.y()); |
|
114 | replace(point.x(),point.y()); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | Removes current \a x and \a y value. |
|
118 | Removes current \a x and \a y value. | |
119 | */ |
|
119 | */ | |
120 | void QXYSeries::remove(qreal x,qreal y) |
|
120 | void QXYSeries::remove(qreal x,qreal y) | |
121 | { |
|
121 | { | |
122 | int index =-1; |
|
122 | int index =-1; | |
123 | do{ |
|
123 | do{ | |
124 | index = m_x.indexOf(x,index+1); |
|
124 | index = m_x.indexOf(x,index+1); | |
125 | }while(index !=-1 && m_y.at(index)!=y); |
|
125 | }while(index !=-1 && m_y.at(index)!=y); | |
126 |
|
126 | |||
127 | if(index==-1) return; |
|
127 | if(index==-1) return; | |
128 |
|
128 | |||
129 | m_x.remove(index); |
|
129 | m_x.remove(index); | |
130 | m_y.remove(index); |
|
130 | m_y.remove(index); | |
131 | emit pointRemoved(index); |
|
131 | emit pointRemoved(index); | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | Removes current \a point x value. Note \a point y value is ignored. |
|
135 | Removes current \a point x value. Note \a point y value is ignored. | |
136 | */ |
|
136 | */ | |
137 | void QXYSeries::remove(const QPointF& point) |
|
137 | void QXYSeries::remove(const QPointF& point) | |
138 | { |
|
138 | { | |
139 | remove(point.x(),point.y()); |
|
139 | remove(point.x(),point.y()); | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | Removes all data points from the series. |
|
143 | Removes all data points from the series. | |
144 | */ |
|
144 | */ | |
145 | void QXYSeries::removeAll() |
|
145 | void QXYSeries::removeAll() | |
146 | { |
|
146 | { | |
147 | m_x.clear(); |
|
147 | m_x.clear(); | |
148 | m_y.clear(); |
|
148 | m_y.clear(); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | /*! |
|
151 | /*! | |
152 | \internal \a pos |
|
152 | \internal \a pos | |
153 | */ |
|
153 | */ | |
154 | qreal QXYSeries::x(int pos) const |
|
154 | qreal QXYSeries::x(int pos) const | |
155 | { |
|
155 | { | |
156 | if (m_model) |
|
156 | if (m_model) | |
157 | if (m_mapOrientation == Qt::Vertical) |
|
157 | if (m_mapOrientation == Qt::Vertical) | |
158 | // consecutive data is read from model's column |
|
158 | // consecutive data is read from model's column | |
159 | return m_model->data(m_model->index(pos, m_mapX), Qt::DisplayRole).toDouble(); |
|
159 | return m_model->data(m_model->index(pos, m_mapX), Qt::DisplayRole).toDouble(); | |
160 | else |
|
160 | else | |
161 | // consecutive data is read from model's row |
|
161 | // consecutive data is read from model's row | |
162 | return m_model->data(m_model->index(m_mapX, pos), Qt::DisplayRole).toDouble(); |
|
162 | return m_model->data(m_model->index(m_mapX, pos), Qt::DisplayRole).toDouble(); | |
163 | else |
|
163 | else | |
164 | // model is not specified, return the data from series' internal data store |
|
164 | // model is not specified, return the data from series' internal data store | |
165 | return m_x.at(pos); |
|
165 | return m_x.at(pos); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | /*! |
|
168 | /*! | |
169 | \internal \a pos |
|
169 | \internal \a pos | |
170 | */ |
|
170 | */ | |
171 | qreal QXYSeries::y(int pos) const |
|
171 | qreal QXYSeries::y(int pos) const | |
172 | { |
|
172 | { | |
173 | if (m_model) |
|
173 | if (m_model) | |
174 | if (m_mapOrientation == Qt::Vertical) |
|
174 | if (m_mapOrientation == Qt::Vertical) | |
175 | // consecutive data is read from model's column |
|
175 | // consecutive data is read from model's column | |
176 | return m_model->data(m_model->index(pos, m_mapY), Qt::DisplayRole).toDouble(); |
|
176 | return m_model->data(m_model->index(pos, m_mapY), Qt::DisplayRole).toDouble(); | |
177 | else |
|
177 | else | |
178 | // consecutive data is read from model's row |
|
178 | // consecutive data is read from model's row | |
179 | return m_model->data(m_model->index(m_mapY, pos), Qt::DisplayRole).toDouble(); |
|
179 | return m_model->data(m_model->index(m_mapY, pos), Qt::DisplayRole).toDouble(); | |
180 | else |
|
180 | else | |
181 | // model is not specified, return the data from series' internal data store |
|
181 | // model is not specified, return the data from series' internal data store | |
182 | return m_y.at(pos); |
|
182 | return m_y.at(pos); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | Returns number of data points within series. |
|
186 | Returns number of data points within series. | |
187 | */ |
|
187 | */ | |
188 | int QXYSeries::count() const |
|
188 | int QXYSeries::count() const | |
189 | { |
|
189 | { | |
190 | Q_ASSERT(m_x.size() == m_y.size()); |
|
190 | Q_ASSERT(m_x.size() == m_y.size()); | |
191 |
|
191 | |||
192 | if (m_model) |
|
192 | if (m_model) { | |
193 | if (m_mapOrientation == Qt::Vertical) |
|
193 | if (m_mapOrientation == Qt::Vertical) | |
194 | // data is in a column, so return the number of items in single column |
|
194 | // data is in a column, so return the number of items in single column | |
195 | return m_model->rowCount(); |
|
195 | return m_model->rowCount(); | |
196 | else |
|
196 | else | |
197 | // data is in a row, so return the number of items in single row |
|
197 | // data is in a row, so return the number of items in single row | |
198 | m_model->columnCount(); |
|
198 | return m_model->columnCount(); | |
199 |
|
|
199 | } | |
|
200 | ||||
200 |
|
|
201 | // model is not specified, return the number of points in the series internal data store | |
201 |
|
|
202 | return m_x.size(); | |
202 | } |
|
203 | } | |
203 |
|
204 | |||
204 | /*! |
|
205 | /*! | |
205 | Returns the data points of the series. |
|
206 | Returns the data points of the series. | |
206 | */ |
|
207 | */ | |
207 | QList<QPointF> QXYSeries::data() |
|
208 | QList<QPointF> QXYSeries::data() | |
208 | { |
|
209 | { | |
209 | QList<QPointF> data; |
|
210 | QList<QPointF> data; | |
210 | for (int i(0); i < m_x.count() && i < m_y.count(); i++) |
|
211 | for (int i(0); i < m_x.count() && i < m_y.count(); i++) | |
211 | data.append(QPointF(m_x.at(i), m_y.at(i))); |
|
212 | data.append(QPointF(m_x.at(i), m_y.at(i))); | |
212 | return data; |
|
213 | return data; | |
213 | } |
|
214 | } | |
214 |
|
215 | |||
215 |
|
216 | |||
216 | /*! |
|
217 | /*! | |
217 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
218 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the | |
218 | pen from chart theme is used. |
|
219 | pen from chart theme is used. | |
219 | \sa QChart::setChartTheme() |
|
220 | \sa QChart::setChartTheme() | |
220 | */ |
|
221 | */ | |
221 | void QXYSeries::setPen(const QPen& pen) |
|
222 | void QXYSeries::setPen(const QPen& pen) | |
222 | { |
|
223 | { | |
223 | if(pen!=m_pen){ |
|
224 | if(pen!=m_pen){ | |
224 | m_pen=pen; |
|
225 | m_pen=pen; | |
225 | emit updated(); |
|
226 | emit updated(); | |
226 | } |
|
227 | } | |
227 | } |
|
228 | } | |
228 |
|
229 | |||
229 | /*! |
|
230 | /*! | |
230 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
231 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush | |
231 | from chart theme setting is used. |
|
232 | from chart theme setting is used. | |
232 | \sa QChart::setChartTheme() |
|
233 | \sa QChart::setChartTheme() | |
233 | */ |
|
234 | */ | |
234 |
|
235 | |||
235 | void QXYSeries::setBrush(const QBrush& brush) |
|
236 | void QXYSeries::setBrush(const QBrush& brush) | |
236 | { |
|
237 | { | |
237 | if(brush!=m_brush){ |
|
238 | if(brush!=m_brush){ | |
238 | m_brush=brush; |
|
239 | m_brush=brush; | |
239 | emit updated(); |
|
240 | emit updated(); | |
240 | } |
|
241 | } | |
241 | } |
|
242 | } | |
242 |
|
243 | |||
243 |
|
244 | |||
244 | /*! |
|
245 | /*! | |
245 | Stream operator for adding a data \a point to the series. |
|
246 | Stream operator for adding a data \a point to the series. | |
246 | \sa add() |
|
247 | \sa add() | |
247 | */ |
|
248 | */ | |
248 |
|
249 | |||
249 | QXYSeries& QXYSeries::operator<< (const QPointF &point) |
|
250 | QXYSeries& QXYSeries::operator<< (const QPointF &point) | |
250 | { |
|
251 | { | |
251 | add(point); |
|
252 | add(point); | |
252 | return *this; |
|
253 | return *this; | |
253 | } |
|
254 | } | |
254 |
|
255 | |||
255 |
|
256 | |||
256 | /*! |
|
257 | /*! | |
257 | Stream operator for adding a list of \a points to the series. |
|
258 | Stream operator for adding a list of \a points to the series. | |
258 | \sa add() |
|
259 | \sa add() | |
259 | */ |
|
260 | */ | |
260 |
|
261 | |||
261 | QXYSeries& QXYSeries::operator<< (const QList<QPointF> points) |
|
262 | QXYSeries& QXYSeries::operator<< (const QList<QPointF> points) | |
262 | { |
|
263 | { | |
263 | add(points); |
|
264 | add(points); | |
264 | return *this; |
|
265 | return *this; | |
265 | } |
|
266 | } | |
266 |
|
267 | |||
267 |
|
268 | |||
268 | void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
269 | void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
269 | { |
|
270 | { | |
270 | if (m_mapOrientation == Qt::Vertical) |
|
271 | if (m_mapOrientation == Qt::Vertical) | |
271 | emit pointReplaced(topLeft.row()); |
|
272 | emit pointReplaced(topLeft.row()); | |
272 | else |
|
273 | else | |
273 | emit pointReplaced(topLeft.column()); |
|
274 | emit pointReplaced(topLeft.column()); | |
274 | } |
|
275 | } | |
275 |
|
276 | |||
276 | void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) |
|
277 | void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) | |
277 | { |
|
278 | { | |
278 | emit pointAdded(start); |
|
279 | emit pointAdded(start); | |
279 | } |
|
280 | } | |
280 |
|
281 | |||
281 | void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
282 | void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
282 | { |
|
283 | { | |
283 | emit pointRemoved(start); |
|
284 | emit pointRemoved(start); | |
284 | } |
|
285 | } | |
285 |
|
286 | |||
286 | bool QXYSeries::setModel(QAbstractItemModel* model) { |
|
287 | bool QXYSeries::setModel(QAbstractItemModel* model) { | |
287 | m_model = model; |
|
288 | m_model = model; | |
288 | // for (int i = 0; i < m_model->rowCount(); i++) |
|
289 | // for (int i = 0; i < m_model->rowCount(); i++) | |
289 | // emit pointAdded(i); |
|
290 | // emit pointAdded(i); | |
290 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
291 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
291 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
292 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
292 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
293 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
293 | return true; |
|
294 | return true; | |
294 | } |
|
295 | } | |
295 |
|
296 | |||
296 | void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) |
|
297 | void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) | |
297 | { |
|
298 | { | |
298 | m_mapX = modelX; |
|
299 | m_mapX = modelX; | |
299 | m_mapY = modelY; |
|
300 | m_mapY = modelY; | |
300 | m_mapOrientation = orientation; |
|
301 | m_mapOrientation = orientation; | |
301 | } |
|
302 | } | |
302 |
|
303 | |||
303 | //void QXYSeries::setModelMappingY(int modelLineIndex, Qt::Orientation orientation) |
|
304 | //void QXYSeries::setModelMappingY(int modelLineIndex, Qt::Orientation orientation) | |
304 | //{ |
|
305 | //{ | |
305 | // m_mapY = modelLineIndex; |
|
306 | // m_mapY = modelLineIndex; | |
306 | // m_mapYOrientation = orientation; |
|
307 | // m_mapYOrientation = orientation; | |
307 | //} |
|
308 | //} | |
308 |
|
309 | |||
309 | #include "moc_qxyseries.cpp" |
|
310 | #include "moc_qxyseries.cpp" | |
310 |
|
311 | |||
311 | QTCOMMERCIALCHART_END_NAMESPACE |
|
312 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now