@@ -1,67 +1,71 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartview.h> |
|
3 | #include <qchartview.h> | |
4 | #include <qlineseries.h> |
|
4 | #include <qlineseries.h> | |
5 | #include <qchart.h> |
|
5 | #include <qchart.h> | |
6 | #include <qchartaxis.h> |
|
6 | #include <qchartaxis.h> | |
7 | #include <cmath> |
|
7 | #include <cmath> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
9 | QTCOMMERCIALCHART_USE_NAMESPACE | |
10 |
|
10 | |||
11 | #define PI 3.14159265358979 |
|
11 | #define PI 3.14159265358979 | |
12 |
|
12 | |||
13 | int main(int argc, char *argv[]) |
|
13 | int main(int argc, char *argv[]) | |
14 | { |
|
14 | { | |
15 | QApplication a(argc, argv); |
|
15 | QApplication a(argc, argv); | |
16 |
|
16 | |||
17 | QMainWindow window; |
|
17 | QMainWindow window; | |
18 |
|
18 | |||
19 | QLineSeries* series0 = new QLineSeries(); |
|
19 | QLineSeries* series0 = new QLineSeries(); | |
20 | QPen blue(Qt::blue); |
|
20 | QPen blue(Qt::blue); | |
21 | blue.setWidth(3); |
|
21 | blue.setWidth(3); | |
22 | series0->setPen(blue); |
|
22 | series0->setPen(blue); | |
23 | QLineSeries* series1 = new QLineSeries(); |
|
23 | QLineSeries* series1 = new QLineSeries(); | |
24 | QPen red(Qt::red); |
|
24 | QPen red(Qt::red); | |
25 | red.setWidth(3); |
|
25 | red.setWidth(3); | |
26 | series1->setPen(red); |
|
26 | series1->setPen(red); | |
27 |
|
27 | |||
28 | int numPoints = 100; |
|
28 | int numPoints = 100; | |
29 |
|
29 | |||
30 | for (int x = 0; x <= numPoints; ++x) { |
|
30 | for (int x = 0; x <= numPoints; ++x) { | |
31 | series0->add(x, fabs(sin(PI/50*x)*100)); |
|
31 | series0->add(x, fabs(sin(PI/50*x)*100)); | |
32 | series1->add(x, fabs(cos(PI/50*x)*100)); |
|
32 | series1->add(x, fabs(cos(PI/50*x)*100)); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | QChartView* chartView = new QChartView(&window); |
|
35 | QChartView* chartView = new QChartView(&window); | |
36 |
|
36 | |||
37 | chartView->setRenderHint(QPainter::Antialiasing); |
|
37 | chartView->setRenderHint(QPainter::Antialiasing); | |
38 | chartView->setChartTitle("This is custom axis chart example"); |
|
38 | chartView->setChartTitle("This is custom axis chart example"); | |
39 | chartView->addSeries(series0); |
|
39 | chartView->addSeries(series0); | |
40 | chartView->addSeries(series1); |
|
40 | chartView->addSeries(series1); | |
41 |
|
41 | |||
42 | QLinearGradient backgroundGradient; |
|
42 | QLinearGradient backgroundGradient; | |
43 | backgroundGradient.setColorAt(0.0, Qt::white); |
|
43 | backgroundGradient.setColorAt(0.0, Qt::white); | |
44 | backgroundGradient.setColorAt(1.0, QRgb(0xffff80)); |
|
44 | backgroundGradient.setColorAt(1.0, QRgb(0xffff80)); | |
45 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
45 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
46 | chartView->setChartBackgroundBrush(backgroundGradient); |
|
46 | chartView->setChartBackgroundBrush(backgroundGradient); | |
47 |
|
47 | |||
48 | QChartAxis* axisX = chartView->axisX(); |
|
48 | QChartAxis* axisX = chartView->axisX(); | |
49 | axisX->setLabelsAngle(45); |
|
49 | axisX->setLabelsAngle(45); | |
50 | axisX->setGridPen(Qt::DashLine); |
|
50 | axisX->setGridPen(Qt::DashLine); | |
51 | axisX->addAxisTickLabel(0,"low"); |
|
51 | axisX->addAxisTickLabel(0,"low"); | |
52 | axisX->addAxisTickLabel(50,"medium"); |
|
52 | axisX->addAxisTickLabel(50,"medium"); | |
53 | axisX->addAxisTickLabel(100,"High"); |
|
53 | axisX->addAxisTickLabel(100,"High"); | |
|
54 | axisX->setMin(-10); | |||
|
55 | axisX->setMax(200); | |||
54 |
|
56 | |||
55 | QChartAxis* axisY = chartView->axisY(); |
|
57 | QChartAxis* axisY = chartView->axisY(); | |
56 | axisY->setLabelsAngle(45); |
|
58 | axisY->setLabelsAngle(45); | |
57 | axisY->setShadesBrush(Qt::yellow); |
|
59 | axisY->setShadesBrush(Qt::yellow); | |
58 | axisY->addAxisTickLabel(0,"low"); |
|
60 | axisY->addAxisTickLabel(0,"low"); | |
59 | axisY->addAxisTickLabel(50,"medium"); |
|
61 | axisY->addAxisTickLabel(50,"medium"); | |
60 | axisY->addAxisTickLabel(100,"High"); |
|
62 | axisY->addAxisTickLabel(100,"High"); | |
|
63 | axisY->setMin(-10); | |||
|
64 | axisY->setMax(200); | |||
61 |
|
65 | |||
62 | window.setCentralWidget(chartView); |
|
66 | window.setCentralWidget(chartView); | |
63 | window.resize(400, 300); |
|
67 | window.resize(400, 300); | |
64 | window.show(); |
|
68 | window.show(); | |
65 |
|
69 | |||
66 | return a.exec(); |
|
70 | return a.exec(); | |
67 | } |
|
71 | } |
@@ -1,358 +1,379 | |||||
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 "qbarseries.h" |
|
5 | #include "qbarseries.h" | |
6 | #include "qstackedbarseries.h" |
|
6 | #include "qstackedbarseries.h" | |
7 | #include "qpercentbarseries.h" |
|
7 | #include "qpercentbarseries.h" | |
8 | #include "qpieseries.h" |
|
8 | #include "qpieseries.h" | |
9 | #include "qscatterseries.h" |
|
9 | #include "qscatterseries.h" | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), |
|
13 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), | |
14 | m_axisX(new QChartAxis(this)), |
|
14 | m_axisX(new QChartAxis(this)), | |
15 | m_axisY(new QChartAxis(this)), |
|
15 | m_axisY(new QChartAxis(this)), | |
16 | m_domainIndex(0), |
|
16 | m_domainIndex(0), | |
17 | m_axisXInitialized(false) |
|
17 | m_axisXInitialized(false) | |
18 | { |
|
18 | { | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | ChartDataSet::~ChartDataSet() |
|
21 | ChartDataSet::~ChartDataSet() | |
22 | { |
|
22 | { | |
23 | // TODO Auto-generated destructor stub |
|
23 | // TODO Auto-generated destructor stub | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | const Domain ChartDataSet::domain(QChartAxis *axisY) const |
|
26 | const Domain ChartDataSet::domain(QChartAxis *axisY) const | |
27 | { |
|
27 | { | |
28 | int i = m_domainMap.count(axisY); |
|
28 | int i = m_domainMap.count(axisY); | |
29 | if(i == 0){ |
|
29 | if(i == 0){ | |
30 | return Domain(); |
|
30 | return Domain(); | |
31 | } |
|
31 | } | |
32 | i = i - m_domainIndex -1; |
|
32 | i = i - m_domainIndex -1; | |
33 | return m_domainMap.values(axisY).at(i); |
|
33 | return m_domainMap.values(axisY).at(i); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) |
|
36 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |
37 | { |
|
37 | { | |
38 | // TODO: we should check the series not already added |
|
38 | // TODO: we should check the series not already added | |
39 |
|
39 | |||
40 | series->setParent(this); // take ownership |
|
40 | series->setParent(this); // take ownership | |
41 | clearDomains(); |
|
41 | clearDomains(); | |
42 |
|
42 | |||
43 | if(axisY==0) axisY = m_axisY; |
|
43 | if(axisY==0) axisY = m_axisY; | |
44 | axisY->setParent(this); // take ownership |
|
44 | axisY->setParent(this); // take ownership | |
45 |
|
45 | |||
46 | QList<QSeries*> seriesList = m_seriesMap.values(axisY); |
|
46 | QList<QSeries*> seriesList = m_seriesMap.values(axisY); | |
47 |
|
47 | |||
48 | QList<Domain> domainList = m_domainMap.values(axisY); |
|
48 | QList<Domain> domainList = m_domainMap.values(axisY); | |
49 |
|
49 | |||
50 | Q_ASSERT(domainList.size()<=1); |
|
50 | Q_ASSERT(domainList.size()<=1); | |
51 |
|
51 | |||
52 | Domain domain; |
|
52 | Domain domain; | |
53 |
|
53 | |||
54 | if(domainList.size()>0) domain = domainList.at(0); |
|
54 | if(domainList.size()>0) domain = domainList.at(0); | |
55 |
|
55 | |||
56 | switch(series->type()) |
|
56 | switch(series->type()) | |
57 | { |
|
57 | { | |
58 | case QSeries::SeriesTypeLine: { |
|
58 | case QSeries::SeriesTypeLine: { | |
59 |
|
59 | |||
60 | QLineSeries* xyseries = static_cast<QLineSeries*>(series); |
|
60 | QLineSeries* xyseries = static_cast<QLineSeries*>(series); | |
61 |
|
61 | |||
62 | for (int i = 0; i < xyseries->count(); i++) |
|
62 | for (int i = 0; i < xyseries->count(); i++) | |
63 | { |
|
63 | { | |
64 | qreal x = xyseries->x(i); |
|
64 | qreal x = xyseries->x(i); | |
65 | qreal y = xyseries->y(i); |
|
65 | qreal y = xyseries->y(i); | |
66 | domain.m_minX = qMin(domain.m_minX,x); |
|
66 | domain.m_minX = qMin(domain.m_minX,x); | |
67 | domain.m_minY = qMin(domain.m_minY,y); |
|
67 | domain.m_minY = qMin(domain.m_minY,y); | |
68 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
68 | domain.m_maxX = qMax(domain.m_maxX,x); | |
69 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
69 | domain.m_maxY = qMax(domain.m_maxY,y); | |
70 | } |
|
70 | } | |
71 | break; |
|
71 | break; | |
72 | } |
|
72 | } | |
73 | case QSeries::SeriesTypeBar: { |
|
73 | case QSeries::SeriesTypeBar: { | |
74 | qDebug() << "QChartSeries::SeriesTypeBar"; |
|
74 | qDebug() << "QChartSeries::SeriesTypeBar"; | |
75 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
75 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
76 | qreal x = barSeries->categoryCount(); |
|
76 | qreal x = barSeries->categoryCount(); | |
77 | qreal y = barSeries->max(); |
|
77 | qreal y = barSeries->max(); | |
78 | domain.m_minX = qMin(domain.m_minX,x); |
|
78 | domain.m_minX = qMin(domain.m_minX,x); | |
79 | domain.m_minY = qMin(domain.m_minY,y); |
|
79 | domain.m_minY = qMin(domain.m_minY,y); | |
80 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
80 | domain.m_maxX = qMax(domain.m_maxX,x); | |
81 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
81 | domain.m_maxY = qMax(domain.m_maxY,y); | |
82 | break; |
|
82 | break; | |
83 | } |
|
83 | } | |
84 | case QSeries::SeriesTypeStackedBar: { |
|
84 | case QSeries::SeriesTypeStackedBar: { | |
85 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; |
|
85 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; | |
86 |
|
86 | |||
87 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
87 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
88 | qreal x = stackedBarSeries->categoryCount(); |
|
88 | qreal x = stackedBarSeries->categoryCount(); | |
89 | qreal y = stackedBarSeries->maxCategorySum(); |
|
89 | qreal y = stackedBarSeries->maxCategorySum(); | |
90 | domain.m_minX = qMin(domain.m_minX,x); |
|
90 | domain.m_minX = qMin(domain.m_minX,x); | |
91 | domain.m_minY = qMin(domain.m_minY,y); |
|
91 | domain.m_minY = qMin(domain.m_minY,y); | |
92 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
92 | domain.m_maxX = qMax(domain.m_maxX,x); | |
93 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
93 | domain.m_maxY = qMax(domain.m_maxY,y); | |
94 | break; |
|
94 | break; | |
95 | } |
|
95 | } | |
96 | case QSeries::SeriesTypePercentBar: { |
|
96 | case QSeries::SeriesTypePercentBar: { | |
97 | qDebug() << "QChartSeries::SeriesTypePercentBar"; |
|
97 | qDebug() << "QChartSeries::SeriesTypePercentBar"; | |
98 |
|
98 | |||
99 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
99 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
100 | qreal x = percentBarSeries->categoryCount(); |
|
100 | qreal x = percentBarSeries->categoryCount(); | |
101 | domain.m_minX = qMin(domain.m_minX,x); |
|
101 | domain.m_minX = qMin(domain.m_minX,x); | |
102 | domain.m_minY = 0; |
|
102 | domain.m_minY = 0; | |
103 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
103 | domain.m_maxX = qMax(domain.m_maxX,x); | |
104 | domain.m_maxY = 100; |
|
104 | domain.m_maxY = 100; | |
105 | break; |
|
105 | break; | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | case QSeries::SeriesTypePie: { |
|
108 | case QSeries::SeriesTypePie: { | |
109 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
109 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
110 | // TODO: domain stuff |
|
110 | // TODO: domain stuff | |
111 | break; |
|
111 | break; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | case QSeries::SeriesTypeScatter: { |
|
114 | case QSeries::SeriesTypeScatter: { | |
115 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
115 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
116 | Q_ASSERT(scatterSeries); |
|
116 | Q_ASSERT(scatterSeries); | |
117 | foreach (QPointF point, scatterSeries->data()) { |
|
117 | foreach (QPointF point, scatterSeries->data()) { | |
118 | domain.m_minX = qMin(domain.m_minX, point.x()); |
|
118 | domain.m_minX = qMin(domain.m_minX, point.x()); | |
119 | domain.m_maxX = qMax(domain.m_maxX, point.x()); |
|
119 | domain.m_maxX = qMax(domain.m_maxX, point.x()); | |
120 | domain.m_minY = qMin(domain.m_minY, point.y()); |
|
120 | domain.m_minY = qMin(domain.m_minY, point.y()); | |
121 | domain.m_maxY = qMax(domain.m_maxY, point.y()); |
|
121 | domain.m_maxY = qMax(domain.m_maxY, point.y()); | |
122 | } |
|
122 | } | |
123 | break; |
|
123 | break; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | default: { |
|
126 | default: { | |
127 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
127 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; | |
128 | return; |
|
128 | return; | |
129 | break; |
|
129 | break; | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | if(!m_domainMap.contains(axisY)) |
|
134 | if(!m_domainMap.contains(axisY)) | |
135 | { |
|
135 | { | |
136 | emit axisAdded(axisY); |
|
136 | emit axisAdded(axisY); | |
137 |
QObject::connect(axisY,SIGNAL( |
|
137 | QObject::connect(axisY,SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); | |
138 | QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); |
|
|||
139 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
138 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
140 | } |
|
139 | } | |
141 | m_domainMap.replace(axisY,domain); |
|
|||
142 | m_seriesMap.insert(axisY,series); |
|
|||
143 |
|
140 | |||
144 | if(!m_axisXInitialized) |
|
141 | if(!m_axisXInitialized) | |
145 | { |
|
142 | { | |
146 | emit axisAdded(axisX()); |
|
143 | emit axisAdded(axisX()); | |
147 |
QObject::connect(axisX(),SIGNAL( |
|
144 | QObject::connect(axisX(),SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); | |
148 | QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); |
|
|||
149 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
145 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
150 | m_axisXInitialized=true; |
|
146 | m_axisXInitialized=true; | |
151 | } |
|
147 | } | |
152 |
|
148 | |||
153 | QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); |
|
149 | m_domainMap.replace(axisY,domain); | |
154 | QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
150 | m_seriesMap.insert(axisY,series); | |
155 | emit axisRangeChanged(axisY,ylabels); |
|
|||
156 | emit axisRangeChanged(axisX(),xlabels); |
|
|||
157 | emit seriesAdded(series); |
|
151 | emit seriesAdded(series); | |
158 | emit seriesDomainChanged(series,domain); |
|
152 | setDomain(m_domainIndex); | |
159 |
|
153 | |||
160 | } |
|
154 | } | |
161 |
|
155 | |||
162 | void ChartDataSet::removeSeries(QSeries* series) |
|
156 | void ChartDataSet::removeSeries(QSeries* series) | |
163 | { |
|
157 | { | |
164 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
158 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
165 | foreach(QChartAxis* axis , keys) { |
|
159 | foreach(QChartAxis* axis , keys) { | |
166 | if(m_seriesMap.contains(axis,series)){ |
|
160 | if(m_seriesMap.contains(axis,series)){ | |
167 | emit seriesRemoved(series); |
|
161 | emit seriesRemoved(series); | |
168 | m_seriesMap.remove(axis,series); |
|
162 | m_seriesMap.remove(axis,series); | |
169 | //remove axis if no longer there |
|
163 | //remove axis if no longer there | |
170 | if(!m_seriesMap.contains(axis)){ |
|
164 | if(!m_seriesMap.contains(axis)){ | |
171 | emit axisRemoved(axis); |
|
165 | emit axisRemoved(axis); | |
172 | m_domainMap.remove(axis); |
|
166 | m_domainMap.remove(axis); | |
173 | if(axis != m_axisY) |
|
167 | if(axis != m_axisY) | |
174 | delete axis; |
|
168 | delete axis; | |
175 | } |
|
169 | } | |
176 | series->setParent(0); |
|
170 | series->setParent(0); | |
177 | break; |
|
171 | break; | |
178 | } |
|
172 | } | |
179 | } |
|
173 | } | |
180 | } |
|
174 | } | |
181 |
|
175 | |||
182 | void ChartDataSet::removeAllSeries() |
|
176 | void ChartDataSet::removeAllSeries() | |
183 | { |
|
177 | { | |
184 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
178 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
185 | foreach(QChartAxis* axis , keys) { |
|
179 | foreach(QChartAxis* axis , keys) { | |
186 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
180 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
187 | for(int i =0 ; i < seriesList.size();i++ ) |
|
181 | for(int i =0 ; i < seriesList.size();i++ ) | |
188 | { |
|
182 | { | |
189 | emit seriesRemoved(seriesList.at(i)); |
|
183 | emit seriesRemoved(seriesList.at(i)); | |
190 | delete(seriesList.at(i)); |
|
184 | delete(seriesList.at(i)); | |
191 | } |
|
185 | } | |
192 | m_seriesMap.remove(axis); |
|
186 | m_seriesMap.remove(axis); | |
193 | m_domainMap.remove(axis); |
|
187 | m_domainMap.remove(axis); | |
194 | emit axisRemoved(axis); |
|
188 | emit axisRemoved(axis); | |
195 | if(axis != m_axisY) delete axis; |
|
189 | if(axis != m_axisY) delete axis; | |
196 | } |
|
190 | } | |
197 | m_domainIndex=0; |
|
191 | m_domainIndex=0; | |
198 | } |
|
192 | } | |
199 |
|
193 | |||
200 | bool ChartDataSet::nextDomain() |
|
194 | bool ChartDataSet::nextDomain() | |
201 | { |
|
195 | { | |
202 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; |
|
196 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; | |
203 |
|
197 | |||
204 | if (m_domainIndex < limit) { |
|
198 | if (m_domainIndex < limit) { | |
205 | m_domainIndex++; |
|
199 | m_domainIndex++; | |
206 | setDomain(m_domainIndex); |
|
200 | setDomain(m_domainIndex); | |
207 | return true; |
|
201 | return true; | |
208 | } |
|
202 | } | |
209 | else { |
|
203 | else { | |
210 | return false; |
|
204 | return false; | |
211 | } |
|
205 | } | |
212 | } |
|
206 | } | |
213 |
|
207 | |||
214 | bool ChartDataSet::previousDomain() |
|
208 | bool ChartDataSet::previousDomain() | |
215 | { |
|
209 | { | |
216 | if (m_domainIndex > 0) { |
|
210 | if (m_domainIndex > 0) { | |
217 | m_domainIndex--; |
|
211 | m_domainIndex--; | |
218 | setDomain(m_domainIndex); |
|
212 | setDomain(m_domainIndex); | |
219 | return true; |
|
213 | return true; | |
220 | } |
|
214 | } | |
221 | else { |
|
215 | else { | |
222 | return false; |
|
216 | return false; | |
223 | } |
|
217 | } | |
224 | } |
|
218 | } | |
225 |
|
219 | |||
226 | void ChartDataSet::setDomain(int index) |
|
220 | void ChartDataSet::setDomain(int index) | |
227 | { |
|
221 | { | |
228 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
222 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
229 |
|
223 | |||
230 | if(domainList.count()==0) return; |
|
224 | if(domainList.count()==0) return; | |
231 |
|
225 | |||
232 | Domain domain; |
|
226 | Domain domain; | |
233 |
|
227 | |||
234 | foreach (QChartAxis* axis , domainList) { |
|
228 | foreach (QChartAxis* axis , domainList) { | |
235 | int i = m_domainMap.count(axis) - index -1; |
|
229 | int i = m_domainMap.count(axis) - index -1; | |
236 | Q_ASSERT(i>=0); |
|
230 | Q_ASSERT(i>=0); | |
237 | domain = m_domainMap.values(axis).at(i); |
|
231 | domain = m_domainMap.values(axis).at(i); | |
238 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
232 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
239 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
233 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
240 | foreach(QSeries* series, seriesList) { |
|
234 | foreach(QSeries* series, seriesList) { | |
241 | emit seriesDomainChanged(series,domain); |
|
235 | emit seriesDomainChanged(series,domain); | |
242 | } |
|
236 | } | |
|
237 | axis->setRange(domain.m_minY,domain.m_maxY); | |||
243 | emit axisRangeChanged(axis,labels); |
|
238 | emit axisRangeChanged(axis,labels); | |
|
239 | ||||
244 | } |
|
240 | } | |
245 |
|
241 | |||
246 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
242 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
|
243 | axisX()->setRange(domain.m_minX,domain.m_maxY); | |||
247 | emit axisRangeChanged(axisX(),labels); |
|
244 | emit axisRangeChanged(axisX(),labels); | |
248 | } |
|
245 | } | |
249 |
|
246 | |||
250 | void ChartDataSet::clearDomains(int toIndex) |
|
247 | void ChartDataSet::clearDomains(int toIndex) | |
251 | { |
|
248 | { | |
252 | Q_ASSERT(toIndex>=0); |
|
249 | Q_ASSERT(toIndex>=0); | |
253 |
|
250 | |||
254 | m_domainIndex = toIndex; |
|
251 | m_domainIndex = toIndex; | |
255 |
|
252 | |||
256 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); |
|
253 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); | |
257 |
|
254 | |||
258 | foreach (QChartAxis* key , keys) |
|
255 | foreach (QChartAxis* key , keys) | |
259 | { |
|
256 | { | |
260 | QList<Domain> domains = m_domainMap.values(key); |
|
257 | QList<Domain> domains = m_domainMap.values(key); | |
261 | m_domainMap.remove(key); |
|
258 | m_domainMap.remove(key); | |
262 | int i = domains.size() - toIndex - 1; |
|
259 | int i = domains.size() - toIndex - 1; | |
263 | while(i--){ |
|
260 | while(i--){ | |
264 | domains.removeFirst(); |
|
261 | domains.removeFirst(); | |
265 | } |
|
262 | } | |
266 | for(int j=domains.size()-1; j>=0 ;j--) |
|
263 | for(int j=domains.size()-1; j>=0 ;j--) | |
267 | m_domainMap.insert(key,domains.at(j)); |
|
264 | m_domainMap.insert(key,domains.at(j)); | |
268 | } |
|
265 | } | |
269 | } |
|
266 | } | |
270 |
|
267 | |||
271 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) |
|
268 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) | |
272 | { |
|
269 | { | |
273 | Q_ASSERT(rect.isValid()); |
|
270 | Q_ASSERT(rect.isValid()); | |
274 | Q_ASSERT(viewport.isValid()); |
|
271 | Q_ASSERT(viewport.isValid()); | |
275 |
|
272 | |||
276 | clearDomains(m_domainIndex); |
|
273 | clearDomains(m_domainIndex); | |
277 |
|
274 | |||
278 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
275 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
279 |
|
276 | |||
280 | Domain domain; |
|
277 | Domain domain; | |
281 |
|
278 | |||
282 | foreach (QChartAxis* axis , domainList){ |
|
279 | foreach (QChartAxis* axis , domainList){ | |
283 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); |
|
280 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); | |
284 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
|||
285 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
|||
286 | foreach(QSeries* series, seriesList){ |
|
|||
287 | emit seriesDomainChanged(series,domain); |
|
|||
288 | } |
|
|||
289 | emit axisRangeChanged(axis,labels); |
|
|||
290 | m_domainMap.insert(axis,domain); |
|
281 | m_domainMap.insert(axis,domain); | |
291 | } |
|
282 | } | |
292 |
|
283 | |||
293 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
284 | setDomain(++m_domainIndex); | |
294 | emit axisRangeChanged(axisX(),labels); |
|
|||
295 |
|
||||
296 | m_domainIndex++; |
|
|||
297 | } |
|
285 | } | |
298 |
|
286 | |||
299 | QChartAxis* ChartDataSet::axisY(QSeries* series) const |
|
287 | QChartAxis* ChartDataSet::axisY(QSeries* series) const | |
300 | { |
|
288 | { | |
301 | if(series == 0) return m_axisY; |
|
289 | if(series == 0) return m_axisY; | |
302 |
|
290 | |||
303 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
291 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
304 |
|
292 | |||
305 | foreach(QChartAxis* axis , keys) { |
|
293 | foreach(QChartAxis* axis , keys) { | |
306 | if(m_seriesMap.contains(axis,series)){ |
|
294 | if(m_seriesMap.contains(axis,series)){ | |
307 | return axis; |
|
295 | return axis; | |
308 | } |
|
296 | } | |
309 | } |
|
297 | } | |
310 | return 0; |
|
298 | return 0; | |
311 | } |
|
299 | } | |
312 |
|
300 | |||
313 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) |
|
301 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) | |
314 | { |
|
302 | { | |
315 | Q_ASSERT(max>=min); |
|
303 | Q_ASSERT(max>=min); | |
316 |
|
304 | |||
317 | QStringList labels; |
|
305 | QStringList labels; | |
318 |
|
306 | |||
319 | int ticks = axis->ticksCount()-1; |
|
307 | int ticks = axis->ticksCount()-1; | |
320 |
|
308 | |||
321 | for(int i=0; i<= ticks; i++){ |
|
309 | for(int i=0; i<= ticks; i++){ | |
322 | qreal value = min + (i * (max - min)/ ticks); |
|
310 | qreal value = min + (i * (max - min)/ ticks); | |
323 | QString label = axis->axisTickLabel(value); |
|
311 | QString label = axis->axisTickLabel(value); | |
324 | if(label.isEmpty()){ |
|
312 | if(label.isEmpty()){ | |
325 | labels << QString::number(value); |
|
313 | labels << QString::number(value); | |
326 | }else{ |
|
314 | }else{ | |
327 | labels << label; |
|
315 | labels << label; | |
328 | } |
|
316 | } | |
329 | } |
|
317 | } | |
330 | return labels; |
|
318 | return labels; | |
331 | } |
|
319 | } | |
332 |
|
320 | |||
333 |
|
321 | |||
334 |
void ChartDataSet::handle |
|
322 | void ChartDataSet::handleRangeChanged(QChartAxis* axis) | |
335 | { |
|
323 | { | |
|
324 | qreal min = axis->min(); | |||
|
325 | qreal max = axis->max(); | |||
336 |
|
326 | |||
337 | } |
|
327 | if(axis==axisX()) { | |
338 |
|
328 | |||
339 | void ChartDataSet::handleMaxChanged(qreal max) |
|
329 | m_domainIndex=0; | |
340 | { |
|
330 | ||
|
331 | clearDomains(m_domainIndex); | |||
|
332 | ||||
|
333 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |||
|
334 | ||||
|
335 | foreach (QChartAxis* axis , domainList) { | |||
|
336 | ||||
|
337 | Q_ASSERT(m_domainMap.values(axis).size()==1); | |||
|
338 | ||||
|
339 | Domain domain = m_domainMap.value(axis); | |||
|
340 | domain.m_minX=min; | |||
|
341 | domain.m_maxX=max; | |||
|
342 | m_domainMap.replace(axis,domain); | |||
|
343 | } | |||
|
344 | ||||
|
345 | } | |||
|
346 | else { | |||
|
347 | ||||
|
348 | QList<Domain> domains = m_domainMap.values(axis); | |||
|
349 | m_domainMap.remove(axis); | |||
|
350 | ||||
|
351 | for(int i=0;i<domains.size();i++) | |||
|
352 | { | |||
|
353 | domains[i].m_minY=min; | |||
|
354 | domains[i].m_maxY=max; | |||
|
355 | } | |||
|
356 | ||||
|
357 | for(int j=domains.size()-1; j>=0;j--) | |||
|
358 | m_domainMap.insert(axis,domains.at(j)); | |||
|
359 | } | |||
341 |
|
360 | |||
|
361 | setDomain(m_domainIndex); | |||
342 | } |
|
362 | } | |
343 |
|
363 | |||
344 | void ChartDataSet::handleTickChanged(QChartAxis* axis) |
|
364 | void ChartDataSet::handleTickChanged(QChartAxis* axis) | |
345 | { |
|
365 | { | |
346 | Domain domain = m_domainMap.value(axisY()); |
|
|||
347 | if(axis==axisX()){ |
|
366 | if(axis==axisX()){ | |
|
367 | Domain domain = m_domainMap.value(axisY()); | |||
348 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); |
|
368 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); | |
349 | emit axisRangeChanged(axis,labels); |
|
369 | emit axisRangeChanged(axis,labels); | |
350 | }else{ |
|
370 | }else{ | |
|
371 | Domain domain = m_domainMap.value(axis); | |||
351 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
372 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
352 | emit axisRangeChanged(axis,labels); |
|
373 | emit axisRangeChanged(axis,labels); | |
353 | } |
|
374 | } | |
354 | } |
|
375 | } | |
355 |
|
376 | |||
356 | #include "moc_chartdataset_p.cpp" |
|
377 | #include "moc_chartdataset_p.cpp" | |
357 |
|
378 | |||
358 | QTCOMMERCIALCHART_END_NAMESPACE |
|
379 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,60 +1,59 | |||||
1 | #ifndef CHARTDATASET_P_H_ |
|
1 | #ifndef CHARTDATASET_P_H_ | |
2 | #define CHARTDATASET_P_H_ |
|
2 | #define CHARTDATASET_P_H_ | |
3 |
|
3 | |||
4 | #include "qseries.h" |
|
4 | #include "qseries.h" | |
5 | #include "domain_p.h" |
|
5 | #include "domain_p.h" | |
6 | #include <QVector> |
|
6 | #include <QVector> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QChartAxis; |
|
10 | class QChartAxis; | |
11 |
|
11 | |||
12 | class ChartDataSet : public QObject |
|
12 | class ChartDataSet : public QObject | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | ChartDataSet(QObject* parent=0); |
|
16 | ChartDataSet(QObject* parent=0); | |
17 | virtual ~ChartDataSet(); |
|
17 | virtual ~ChartDataSet(); | |
18 |
|
18 | |||
19 | void addSeries(QSeries* series,QChartAxis *axisY = 0); |
|
19 | void addSeries(QSeries* series,QChartAxis *axisY = 0); | |
20 | void removeSeries(QSeries* series); |
|
20 | void removeSeries(QSeries* series); | |
21 | void removeAllSeries(); |
|
21 | void removeAllSeries(); | |
22 | void addDomain(const QRectF& rect, const QRectF& viewport); |
|
22 | void addDomain(const QRectF& rect, const QRectF& viewport); | |
23 | bool nextDomain(); |
|
23 | bool nextDomain(); | |
24 | bool previousDomain(); |
|
24 | bool previousDomain(); | |
25 | void clearDomains(int toIndex =0); |
|
25 | void clearDomains(int toIndex =0); | |
26 | const Domain domain(QChartAxis *axisY) const; |
|
26 | const Domain domain(QChartAxis *axisY) const; | |
27 | int domainIndex() const {return m_domainIndex;} |
|
27 | int domainIndex() const {return m_domainIndex;} | |
28 | void setDomain(int index); |
|
28 | void setDomain(int index); | |
29 |
|
29 | |||
30 | QChartAxis* axisX() const { return m_axisX;}; |
|
30 | QChartAxis* axisX() const { return m_axisX;}; | |
31 | QChartAxis* axisY(QSeries* series = 0) const; |
|
31 | QChartAxis* axisY(QSeries* series = 0) const; | |
32 |
|
32 | |||
33 | signals: |
|
33 | signals: | |
34 | void seriesAdded(QSeries* series); |
|
34 | void seriesAdded(QSeries* series); | |
35 | void seriesRemoved(QSeries* series); |
|
35 | void seriesRemoved(QSeries* series); | |
36 | void axisAdded(QChartAxis* axis); |
|
36 | void axisAdded(QChartAxis* axis); | |
37 | void axisRemoved(QChartAxis* axis); |
|
37 | void axisRemoved(QChartAxis* axis); | |
38 | void axisRangeChanged(QChartAxis* axis, const QStringList& labels); |
|
38 | void axisRangeChanged(QChartAxis* axis, const QStringList& labels); | |
39 | void seriesDomainChanged(QSeries* series,const Domain& domain); |
|
39 | void seriesDomainChanged(QSeries* series,const Domain& domain); | |
40 |
|
40 | |||
41 | private slots: |
|
41 | private slots: | |
42 |
void handle |
|
42 | void handleRangeChanged(QChartAxis*); | |
43 | void handleMaxChanged(qreal max); |
|
|||
44 | void handleTickChanged(QChartAxis*); |
|
43 | void handleTickChanged(QChartAxis*); | |
45 |
|
44 | |||
46 | private: |
|
45 | private: | |
47 | QStringList createLabels(QChartAxis* axis,qreal min, qreal max); |
|
46 | QStringList createLabels(QChartAxis* axis,qreal min, qreal max); | |
48 |
|
47 | |||
49 | private: |
|
48 | private: | |
50 | QMultiMap<QChartAxis*, Domain> m_domainMap; |
|
49 | QMultiMap<QChartAxis*, Domain> m_domainMap; | |
51 | QMultiMap<QChartAxis*, QSeries*> m_seriesMap; |
|
50 | QMultiMap<QChartAxis*, QSeries*> m_seriesMap; | |
52 | QChartAxis* m_axisX; |
|
51 | QChartAxis* m_axisX; | |
53 | QChartAxis* m_axisY; |
|
52 | QChartAxis* m_axisY; | |
54 | int m_domainIndex; |
|
53 | int m_domainIndex; | |
55 | bool m_axisXInitialized; |
|
54 | bool m_axisXInitialized; | |
56 | }; |
|
55 | }; | |
57 |
|
56 | |||
58 | QTCOMMERCIALCHART_END_NAMESPACE |
|
57 | QTCOMMERCIALCHART_END_NAMESPACE | |
59 |
|
58 | |||
60 | #endif /* CHARTENGINE_P_H_ */ |
|
59 | #endif /* CHARTENGINE_P_H_ */ |
@@ -1,224 +1,224 | |||||
1 | #include "qlineseries.h" |
|
1 | #include "qlineseries.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QLineSeries |
|
6 | \class QLineSeries | |
7 | \brief The QLineSeries class is used for making line charts. |
|
7 | \brief The QLineSeries class is used for making line charts. | |
8 |
|
8 | |||
9 | \mainclass |
|
9 | \mainclass | |
10 |
|
10 | |||
11 | A line chart is used to show information as a series of data points |
|
11 | A line chart is used to show information as a series of data points | |
12 | connected by straight lines. |
|
12 | connected by straight lines. | |
13 |
|
13 | |||
14 | \image linechart.png |
|
14 | \image linechart.png | |
15 |
|
15 | |||
16 | Creating basic line chart is simple: |
|
16 | Creating basic line chart is simple: | |
17 | \code |
|
17 | \code | |
18 | QLineSeries* series = new QLineSeries(); |
|
18 | QLineSeries* series = new QLineSeries(); | |
19 | series->add(0, 6); |
|
19 | series->add(0, 6); | |
20 | series->add(2, 4); |
|
20 | series->add(2, 4); | |
21 | ... |
|
21 | ... | |
22 | chartView->addSeries(series); |
|
22 | chartView->addSeries(series); | |
23 | \endcode |
|
23 | \endcode | |
24 | */ |
|
24 | */ | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \fn virtual QSeriesType QLineSeries::type() const |
|
27 | \fn virtual QSeriesType QLineSeries::type() const | |
28 | \brief Returns type of series. |
|
28 | \brief Returns type of series. | |
29 | \sa QSeries, QSeriesType |
|
29 | \sa QSeries, QSeriesType | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \fn QPen QLineSeries::pen() const |
|
33 | \fn QPen QLineSeries::pen() const | |
34 | \brief Returns the pen used to draw line for this series. |
|
34 | \brief Returns the pen used to draw line for this series. | |
35 | \sa setPen() |
|
35 | \sa setPen() | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \fn bool QLineSeries::pointsVisible() const |
|
39 | \fn bool QLineSeries::pointsVisible() const | |
40 | \brief Returns if the points are drawn for this series. |
|
40 | \brief Returns if the points are drawn for this series. | |
41 | \sa setPointsVisible() |
|
41 | \sa setPointsVisible() | |
42 | */ |
|
42 | */ | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | \fn void QLineSeries::pointReplaced(int index) |
|
46 | \fn void QLineSeries::pointReplaced(int index) | |
47 | \brief \internal \a index |
|
47 | \brief \internal \a index | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \fn void QLineSeries::pointAdded(int index) |
|
51 | \fn void QLineSeries::pointAdded(int index) | |
52 | \brief \internal \a index |
|
52 | \brief \internal \a index | |
53 | */ |
|
53 | */ | |
54 |
|
54 | |||
55 | /*! |
|
55 | /*! | |
56 | \fn void QLineSeries::pointRemoved(int index) |
|
56 | \fn void QLineSeries::pointRemoved(int index) | |
57 | \brief \internal \a index |
|
57 | \brief \internal \a index | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 |
\fn void QLineSeries::updated( |
|
61 | \fn void QLineSeries::updated() | |
62 | \brief \internal |
|
62 | \brief \internal | |
63 | */ |
|
63 | */ | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | Constructs empty series object which is a child of \a parent. |
|
66 | Constructs empty series object which is a child of \a parent. | |
67 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
67 | When series object is added to QChartView or QChart instance ownerships is transfered. | |
68 | */ |
|
68 | */ | |
69 | QLineSeries::QLineSeries(QObject* parent):QSeries(parent), |
|
69 | QLineSeries::QLineSeries(QObject* parent):QSeries(parent), | |
70 | m_pointsVisible(false) |
|
70 | m_pointsVisible(false) | |
71 | { |
|
71 | { | |
72 | } |
|
72 | } | |
73 | /*! |
|
73 | /*! | |
74 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
74 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
75 | and are deleted when mentioned object are destroyed. |
|
75 | and are deleted when mentioned object are destroyed. | |
76 | */ |
|
76 | */ | |
77 | QLineSeries::~QLineSeries() |
|
77 | QLineSeries::~QLineSeries() | |
78 | { |
|
78 | { | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
82 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
83 | */ |
|
83 | */ | |
84 | void QLineSeries::add(qreal x,qreal y) |
|
84 | void QLineSeries::add(qreal x,qreal y) | |
85 | { |
|
85 | { | |
86 | Q_ASSERT(m_x.size() == m_y.size()); |
|
86 | Q_ASSERT(m_x.size() == m_y.size()); | |
87 | m_x<<x; |
|
87 | m_x<<x; | |
88 | m_y<<y; |
|
88 | m_y<<y; | |
89 | emit pointAdded(m_x.size()-1); |
|
89 | emit pointAdded(m_x.size()-1); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | This is an overloaded function. |
|
93 | This is an overloaded function. | |
94 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
94 | Adds data \a point to the series. Points are connected with lines on the chart. | |
95 | */ |
|
95 | */ | |
96 | void QLineSeries::add(const QPointF& point) |
|
96 | void QLineSeries::add(const QPointF& point) | |
97 | { |
|
97 | { | |
98 | add(point.x(),point.y()); |
|
98 | add(point.x(),point.y()); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | Modifies \a y value for given \a x a value. |
|
102 | Modifies \a y value for given \a x a value. | |
103 | */ |
|
103 | */ | |
104 | void QLineSeries::replace(qreal x,qreal y) |
|
104 | void QLineSeries::replace(qreal x,qreal y) | |
105 | { |
|
105 | { | |
106 | int index = m_x.indexOf(x); |
|
106 | int index = m_x.indexOf(x); | |
107 | m_x[index]=x; |
|
107 | m_x[index]=x; | |
108 | m_y[index]=y; |
|
108 | m_y[index]=y; | |
109 | emit pointReplaced(index); |
|
109 | emit pointReplaced(index); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | This is an overloaded function. |
|
113 | This is an overloaded function. | |
114 | Replaces current y value of for given \a point x value with \a point y value. |
|
114 | Replaces current y value of for given \a point x value with \a point y value. | |
115 | */ |
|
115 | */ | |
116 | void QLineSeries::replace(const QPointF& point) |
|
116 | void QLineSeries::replace(const QPointF& point) | |
117 | { |
|
117 | { | |
118 | replace(point.x(),point.y()); |
|
118 | replace(point.x(),point.y()); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | /*! |
|
121 | /*! | |
122 | Removes current \a x and y value. |
|
122 | Removes current \a x and y value. | |
123 | */ |
|
123 | */ | |
124 | void QLineSeries::remove(qreal x) |
|
124 | void QLineSeries::remove(qreal x) | |
125 | { |
|
125 | { | |
126 | int index = m_x.indexOf(x); |
|
126 | int index = m_x.indexOf(x); | |
127 | m_x.remove(index); |
|
127 | m_x.remove(index); | |
128 | m_y.remove(index); |
|
128 | m_y.remove(index); | |
129 | emit pointRemoved(index); |
|
129 | emit pointRemoved(index); | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | Removes current \a point x value. Note \a point y value is ignored. |
|
133 | Removes current \a point x value. Note \a point y value is ignored. | |
134 | */ |
|
134 | */ | |
135 | void QLineSeries::remove(const QPointF& point) |
|
135 | void QLineSeries::remove(const QPointF& point) | |
136 | { |
|
136 | { | |
137 | remove(point.x()); |
|
137 | remove(point.x()); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | Clears all the data. |
|
141 | Clears all the data. | |
142 | */ |
|
142 | */ | |
143 | void QLineSeries::clear() |
|
143 | void QLineSeries::clear() | |
144 | { |
|
144 | { | |
145 | m_x.clear(); |
|
145 | m_x.clear(); | |
146 | m_y.clear(); |
|
146 | m_y.clear(); | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \internal \a pos |
|
150 | \internal \a pos | |
151 | */ |
|
151 | */ | |
152 | qreal QLineSeries::x(int pos) const |
|
152 | qreal QLineSeries::x(int pos) const | |
153 | { |
|
153 | { | |
154 | return m_x.at(pos); |
|
154 | return m_x.at(pos); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | \internal \a pos |
|
158 | \internal \a pos | |
159 | */ |
|
159 | */ | |
160 | qreal QLineSeries::y(int pos) const |
|
160 | qreal QLineSeries::y(int pos) const | |
161 | { |
|
161 | { | |
162 | return m_y.at(pos); |
|
162 | return m_y.at(pos); | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | /*! |
|
165 | /*! | |
166 | Returns number of data points within series. |
|
166 | Returns number of data points within series. | |
167 | */ |
|
167 | */ | |
168 | int QLineSeries::count() const |
|
168 | int QLineSeries::count() const | |
169 | { |
|
169 | { | |
170 | Q_ASSERT(m_x.size() == m_y.size()); |
|
170 | Q_ASSERT(m_x.size() == m_y.size()); | |
171 |
|
171 | |||
172 | return m_x.size(); |
|
172 | return m_x.size(); | |
173 |
|
173 | |||
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | Sets \a pen used for drawing given series.. |
|
177 | Sets \a pen used for drawing given series.. | |
178 | */ |
|
178 | */ | |
179 | void QLineSeries::setPen(const QPen& pen) |
|
179 | void QLineSeries::setPen(const QPen& pen) | |
180 | { |
|
180 | { | |
181 | if(pen!=m_pen){ |
|
181 | if(pen!=m_pen){ | |
182 | m_pen=pen; |
|
182 | m_pen=pen; | |
183 | emit updated(); |
|
183 | emit updated(); | |
184 | } |
|
184 | } | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
188 | Sets if data points are \a visible and should be drawn on line. |
|
188 | Sets if data points are \a visible and should be drawn on line. | |
189 | */ |
|
189 | */ | |
190 | void QLineSeries::setPointsVisible(bool visible) |
|
190 | void QLineSeries::setPointsVisible(bool visible) | |
191 | { |
|
191 | { | |
192 | if(m_pointsVisible!=visible){ |
|
192 | if(m_pointsVisible!=visible){ | |
193 | m_pointsVisible=visible; |
|
193 | m_pointsVisible=visible; | |
194 | emit updated(); |
|
194 | emit updated(); | |
195 | } |
|
195 | } | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | QDebug operator<< (QDebug debug, const QLineSeries series) |
|
198 | QDebug operator<< (QDebug debug, const QLineSeries series) | |
199 | { |
|
199 | { | |
200 | Q_ASSERT(series.m_x.size() == series.m_y.size()); |
|
200 | Q_ASSERT(series.m_x.size() == series.m_y.size()); | |
201 |
|
201 | |||
202 | int size = series.m_x.size(); |
|
202 | int size = series.m_x.size(); | |
203 |
|
203 | |||
204 | for (int i=0;i<size;i++) { |
|
204 | for (int i=0;i<size;i++) { | |
205 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; |
|
205 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; | |
206 | } |
|
206 | } | |
207 | return debug.space(); |
|
207 | return debug.space(); | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | Stream operator for adding a data \a point to the series. |
|
211 | Stream operator for adding a data \a point to the series. | |
212 | \sa add() |
|
212 | \sa add() | |
213 | */ |
|
213 | */ | |
214 |
|
214 | |||
215 | QLineSeries& QLineSeries::operator<< (const QPointF &point) |
|
215 | QLineSeries& QLineSeries::operator<< (const QPointF &point) | |
216 | { |
|
216 | { | |
217 | add(point); |
|
217 | add(point); | |
218 | return *this; |
|
218 | return *this; | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 |
|
221 | |||
222 | #include "moc_qlineseries.cpp" |
|
222 | #include "moc_qlineseries.cpp" | |
223 |
|
223 | |||
224 | QTCOMMERCIALCHART_END_NAMESPACE |
|
224 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,353 +1,377 | |||||
1 | #include "qchartaxis.h" |
|
1 | #include "qchartaxis.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QChartAxis |
|
6 | \class QChartAxis | |
7 | \brief The QChartAxis class is used for manipulating chart's axis |
|
7 | \brief The QChartAxis class is used for manipulating chart's axis | |
8 | and for adding optional axes to the chart. |
|
8 | and for adding optional axes to the chart. | |
9 | \mainclass |
|
9 | \mainclass | |
10 |
|
10 | |||
11 | There is only one x Axis, however there can be multiple y axes. |
|
11 | There is only one x Axis, however there can be multiple y axes. | |
12 | Each chart series can be bound to exactly one Y axis and the share common X axis. |
|
12 | Each chart series can be bound to exactly one Y axis and the share common X axis. | |
13 | Axis can be setup to show axis line with ticks, gird lines and shades. |
|
13 | Axis can be setup to show axis line with ticks, gird lines and shades. | |
14 |
|
14 | |||
15 | */ |
|
15 | */ | |
16 |
|
16 | |||
17 | /*! |
|
17 | /*! | |
18 | \fn bool QChartAxis::isAxisVisible() const |
|
18 | \fn bool QChartAxis::isAxisVisible() const | |
19 | \brief Returns if axis is visible |
|
19 | \brief Returns if axis is visible | |
20 | \sa setAxisVisible() |
|
20 | \sa setAxisVisible() | |
21 | */ |
|
21 | */ | |
22 |
|
22 | |||
23 | /*! |
|
23 | /*! | |
24 | \fn QPen QChartAxis::axisPen() const |
|
24 | \fn QPen QChartAxis::axisPen() const | |
25 | \brief Returns pen used to draw axis and ticks. |
|
25 | \brief Returns pen used to draw axis and ticks. | |
26 | \sa setAxisPen() |
|
26 | \sa setAxisPen() | |
27 | */ |
|
27 | */ | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \fn bool QChartAxis::isGridVisible() const |
|
31 | \fn bool QChartAxis::isGridVisible() const | |
32 | \brief Returns if grid is visible |
|
32 | \brief Returns if grid is visible | |
33 | \sa setGridVisible() |
|
33 | \sa setGridVisible() | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \fn QPen QChartAxis::gridPen() const |
|
37 | \fn QPen QChartAxis::gridPen() const | |
38 | \brief Returns pen used to draw grid. |
|
38 | \brief Returns pen used to draw grid. | |
39 | \sa setGridPen() |
|
39 | \sa setGridPen() | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \fn bool QChartAxis::labelsVisible() const |
|
43 | \fn bool QChartAxis::labelsVisible() const | |
44 | \brief Returns if grid is visible |
|
44 | \brief Returns if grid is visible | |
45 | \sa setLabelsVisible() |
|
45 | \sa setLabelsVisible() | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | /*! |
|
48 | /*! | |
49 | \fn QPen QChartAxis::labelsPen() const |
|
49 | \fn QPen QChartAxis::labelsPen() const | |
50 | \brief Returns the pen used to labels. |
|
50 | \brief Returns the pen used to labels. | |
51 | \sa setLabelsPen() |
|
51 | \sa setLabelsPen() | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | \fn QBrush QChartAxis::labelsBrush() const |
|
55 | \fn QBrush QChartAxis::labelsBrush() const | |
56 | \brief Returns brush used to draw labels. |
|
56 | \brief Returns brush used to draw labels. | |
57 | \sa setLabelsBrush() |
|
57 | \sa setLabelsBrush() | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \fn QFont QChartAxis::labelsFont() const |
|
61 | \fn QFont QChartAxis::labelsFont() const | |
62 | \brief Returns font used to draw labels. |
|
62 | \brief Returns font used to draw labels. | |
63 | \sa setLabelsFont() |
|
63 | \sa setLabelsFont() | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | \fn QFont QChartAxis::labelsAngle() const |
|
67 | \fn QFont QChartAxis::labelsAngle() const | |
68 | \brief Returns angle used to draw labels. |
|
68 | \brief Returns angle used to draw labels. | |
69 | \sa setLabelsAngle() |
|
69 | \sa setLabelsAngle() | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \fn bool QChartAxis::shadesVisible() const |
|
73 | \fn bool QChartAxis::shadesVisible() const | |
74 | \brief Returns if shades are visible. |
|
74 | \brief Returns if shades are visible. | |
75 | \sa setShadesVisible() |
|
75 | \sa setShadesVisible() | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \fn qreal QChartAxis::shadesOpacity() const |
|
79 | \fn qreal QChartAxis::shadesOpacity() const | |
80 | \brief Returns opacity of shades. |
|
80 | \brief Returns opacity of shades. | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \fn QPen QChartAxis::shadesPen() const |
|
84 | \fn QPen QChartAxis::shadesPen() const | |
85 | \brief Returns pen used to draw shades. |
|
85 | \brief Returns pen used to draw shades. | |
86 | \sa setShadesPen() |
|
86 | \sa setShadesPen() | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \fn QBrush QChartAxis::shadesBrush() const |
|
90 | \fn QBrush QChartAxis::shadesBrush() const | |
91 | \brief Returns brush used to draw shades. |
|
91 | \brief Returns brush used to draw shades. | |
92 | \sa setShadesBrush() |
|
92 | \sa setShadesBrush() | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \fn qreal QChartAxis::min() const |
|
96 | \fn qreal QChartAxis::min() const | |
97 | \brief Returns minimum value on the axis. |
|
97 | \brief Returns minimum value on the axis. | |
98 | \sa setMin() |
|
98 | \sa setMin() | |
99 | */ |
|
99 | */ | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | \fn qreal QChartAxis::max() const |
|
102 | \fn qreal QChartAxis::max() const | |
103 | \brief Returns maximim value on the axis. |
|
103 | \brief Returns maximim value on the axis. | |
104 | \sa setMax() |
|
104 | \sa setMax() | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \fn void QChartAxis::minChanged(qreal min) |
|
108 | \fn void QChartAxis::minChanged(qreal min) | |
109 | \brief Axis emits signal when \a min of axis has changed. |
|
109 | \brief Axis emits signal when \a min of axis has changed. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \fn void QChartAxis::maxChanged(qreal max) |
|
113 | \fn void QChartAxis::maxChanged(qreal max) | |
114 | \brief Axis emits signal when \a max of axis has changed. |
|
114 | \brief Axis emits signal when \a max of axis has changed. | |
115 | */ |
|
115 | */ | |
116 | /*! |
|
116 | /*! | |
117 | \fn int QChartAxis::ticksCount() const |
|
117 | \fn int QChartAxis::ticksCount() const | |
118 | \brief Return number of ticks on the axis |
|
118 | \brief Return number of ticks on the axis | |
119 | \sa setTicksCount() |
|
119 | \sa setTicksCount() | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \fn void QChartAxis::update(QChartAxis*) |
|
123 | \fn void QChartAxis::update(QChartAxis*) | |
124 | \brief \internal |
|
124 | \brief \internal | |
125 | */ |
|
125 | */ | |
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \fn void QChartAxis::ticksChanged(QChartAxis*) |
|
128 | \fn void QChartAxis::ticksChanged(QChartAxis*) | |
129 | \brief \internal |
|
129 | \brief \internal | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
|
133 | \fn void QChartAxis::rangeChanged(QChartAxis*) | |||
|
134 | \brief \internal | |||
|
135 | */ | |||
|
136 | ||||
|
137 | /*! | |||
|
138 | \fn void QChartAxis::updateRange(qreal min, qreal max) | |||
|
139 | \brief \internal \a min \a max | |||
|
140 | */ | |||
|
141 | ||||
|
142 | /*! | |||
133 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
143 | Constructs new axis object which is a child of \a parent. Ownership is taken by | |
134 | QChatView or QChart when axis added. |
|
144 | QChatView or QChart when axis added. | |
135 | */ |
|
145 | */ | |
136 |
|
146 | |||
137 | QChartAxis::QChartAxis(QObject* parent):QObject(parent), |
|
147 | QChartAxis::QChartAxis(QObject* parent):QObject(parent), | |
138 | m_axisVisible(true), |
|
148 | m_axisVisible(true), | |
139 | m_gridVisible(true), |
|
149 | m_gridVisible(true), | |
140 | m_labelsVisible(true), |
|
150 | m_labelsVisible(true), | |
141 | m_labelsAngle(0), |
|
151 | m_labelsAngle(0), | |
142 | m_shadesVisible(true), |
|
152 | m_shadesVisible(true), | |
143 | m_shadesOpacity(1.0), |
|
153 | m_shadesOpacity(1.0), | |
144 | m_min(0), |
|
154 | m_min(0), | |
145 | m_max(0), |
|
155 | m_max(0), | |
146 | m_ticksCount(5) |
|
156 | m_ticksCount(5) | |
147 | { |
|
157 | { | |
148 |
|
158 | |||
149 | } |
|
159 | } | |
150 |
|
160 | |||
151 | /*! |
|
161 | /*! | |
152 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
162 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. | |
153 | */ |
|
163 | */ | |
154 |
|
164 | |||
155 | QChartAxis::~QChartAxis() |
|
165 | QChartAxis::~QChartAxis() | |
156 | { |
|
166 | { | |
157 | } |
|
167 | } | |
158 |
|
168 | |||
159 | /*! |
|
169 | /*! | |
160 | Sets \a pen used to draw axis line and ticks. |
|
170 | Sets \a pen used to draw axis line and ticks. | |
161 | */ |
|
171 | */ | |
162 | void QChartAxis::setAxisPen(const QPen& pen) |
|
172 | void QChartAxis::setAxisPen(const QPen& pen) | |
163 | { |
|
173 | { | |
164 | m_axisPen=pen; |
|
174 | m_axisPen=pen; | |
165 | emit update(this); |
|
175 | emit update(this); | |
166 | } |
|
176 | } | |
167 |
|
177 | |||
168 | /*! |
|
178 | /*! | |
169 | Sets if axis and ticks are \a visible. |
|
179 | Sets if axis and ticks are \a visible. | |
170 | */ |
|
180 | */ | |
171 | void QChartAxis::setAxisVisible(bool visible) |
|
181 | void QChartAxis::setAxisVisible(bool visible) | |
172 | { |
|
182 | { | |
173 | m_axisVisible=visible; |
|
183 | m_axisVisible=visible; | |
174 | emit update(this); |
|
184 | emit update(this); | |
175 | } |
|
185 | } | |
176 |
|
186 | |||
177 | /*! |
|
187 | /*! | |
178 | Sets if grid is \a visible. |
|
188 | Sets if grid is \a visible. | |
179 | */ |
|
189 | */ | |
180 | void QChartAxis::setGridVisible(bool visible) |
|
190 | void QChartAxis::setGridVisible(bool visible) | |
181 | { |
|
191 | { | |
182 | m_gridVisible=visible; |
|
192 | m_gridVisible=visible; | |
183 | emit update(this); |
|
193 | emit update(this); | |
184 | } |
|
194 | } | |
185 |
|
195 | |||
186 | /*! |
|
196 | /*! | |
187 | Sets \a pen used to draw grid. |
|
197 | Sets \a pen used to draw grid. | |
188 | */ |
|
198 | */ | |
189 | void QChartAxis::setGridPen(const QPen& pen) |
|
199 | void QChartAxis::setGridPen(const QPen& pen) | |
190 | { |
|
200 | { | |
191 | m_gridPen=pen; |
|
201 | m_gridPen=pen; | |
192 | emit update(this); |
|
202 | emit update(this); | |
193 | } |
|
203 | } | |
194 |
|
204 | |||
195 | /*! |
|
205 | /*! | |
196 | Sets if axis' labels are \a visible. |
|
206 | Sets if axis' labels are \a visible. | |
197 | */ |
|
207 | */ | |
198 | void QChartAxis::setLabelsVisible(bool visible) |
|
208 | void QChartAxis::setLabelsVisible(bool visible) | |
199 | { |
|
209 | { | |
200 | m_labelsVisible=visible; |
|
210 | m_labelsVisible=visible; | |
201 | emit update(this); |
|
211 | emit update(this); | |
202 | } |
|
212 | } | |
203 |
|
213 | |||
204 | /*! |
|
214 | /*! | |
205 | Sets \a pen used to draw labels. |
|
215 | Sets \a pen used to draw labels. | |
206 | */ |
|
216 | */ | |
207 | void QChartAxis::setLabelsPen(const QPen& pen) |
|
217 | void QChartAxis::setLabelsPen(const QPen& pen) | |
208 | { |
|
218 | { | |
209 | m_labelsPen=pen; |
|
219 | m_labelsPen=pen; | |
210 | emit update(this); |
|
220 | emit update(this); | |
211 | } |
|
221 | } | |
212 |
|
222 | |||
213 | /*! |
|
223 | /*! | |
214 | Sets \a brush used to draw labels. |
|
224 | Sets \a brush used to draw labels. | |
215 | */ |
|
225 | */ | |
216 | void QChartAxis::setLabelsBrush(const QBrush& brush) |
|
226 | void QChartAxis::setLabelsBrush(const QBrush& brush) | |
217 | { |
|
227 | { | |
218 | m_labelsBrush=brush; |
|
228 | m_labelsBrush=brush; | |
219 | emit update(this); |
|
229 | emit update(this); | |
220 | } |
|
230 | } | |
221 |
|
231 | |||
222 | /*! |
|
232 | /*! | |
223 | Sets \a font used to draw labels. |
|
233 | Sets \a font used to draw labels. | |
224 | */ |
|
234 | */ | |
225 | void QChartAxis::setLabelsFont(const QFont& font) |
|
235 | void QChartAxis::setLabelsFont(const QFont& font) | |
226 | { |
|
236 | { | |
227 | m_labelsFont=font; |
|
237 | m_labelsFont=font; | |
228 | emit update(this); |
|
238 | emit update(this); | |
229 | } |
|
239 | } | |
230 |
|
240 | |||
231 | /*! |
|
241 | /*! | |
232 | Sets \a angle for all the labels on given axis. |
|
242 | Sets \a angle for all the labels on given axis. | |
233 | */ |
|
243 | */ | |
234 | void QChartAxis::setLabelsAngle(int angle) |
|
244 | void QChartAxis::setLabelsAngle(int angle) | |
235 | { |
|
245 | { | |
236 | m_labelsAngle=angle; |
|
246 | m_labelsAngle=angle; | |
237 | emit update(this); |
|
247 | emit update(this); | |
238 | } |
|
248 | } | |
239 |
|
249 | |||
240 | /*! |
|
250 | /*! | |
241 | Sets if shades are \a visible. |
|
251 | Sets if shades are \a visible. | |
242 | */ |
|
252 | */ | |
243 | void QChartAxis::setShadesVisible(bool visible) |
|
253 | void QChartAxis::setShadesVisible(bool visible) | |
244 | { |
|
254 | { | |
245 | m_shadesVisible=visible; |
|
255 | m_shadesVisible=visible; | |
246 | emit update(this); |
|
256 | emit update(this); | |
247 | } |
|
257 | } | |
248 |
|
258 | |||
249 | /*! |
|
259 | /*! | |
250 | Sets \a pen used to draw shades. |
|
260 | Sets \a pen used to draw shades. | |
251 | */ |
|
261 | */ | |
252 | void QChartAxis::setShadesPen(const QPen& pen) |
|
262 | void QChartAxis::setShadesPen(const QPen& pen) | |
253 | { |
|
263 | { | |
254 | m_shadesPen=pen; |
|
264 | m_shadesPen=pen; | |
255 | emit update(this); |
|
265 | emit update(this); | |
256 | } |
|
266 | } | |
257 |
|
267 | |||
258 | /*! |
|
268 | /*! | |
259 | Sets \a brush used to draw shades. |
|
269 | Sets \a brush used to draw shades. | |
260 | */ |
|
270 | */ | |
261 | void QChartAxis::setShadesBrush(const QBrush& brush) |
|
271 | void QChartAxis::setShadesBrush(const QBrush& brush) | |
262 | { |
|
272 | { | |
263 | m_shadesBrush=brush; |
|
273 | m_shadesBrush=brush; | |
264 | emit update(this); |
|
274 | emit update(this); | |
265 | } |
|
275 | } | |
266 |
|
276 | |||
267 | /*! |
|
277 | /*! | |
268 | Sets \a opacity of the shades. |
|
278 | Sets \a opacity of the shades. | |
269 | */ |
|
279 | */ | |
270 | void QChartAxis::setShadesOpacity(qreal opacity) |
|
280 | void QChartAxis::setShadesOpacity(qreal opacity) | |
271 | { |
|
281 | { | |
272 | m_shadesOpacity=opacity; |
|
282 | m_shadesOpacity=opacity; | |
273 | emit update(this); |
|
283 | emit update(this); | |
274 | } |
|
284 | } | |
275 |
|
285 | |||
276 | /*! |
|
286 | /*! | |
277 |
|
|
287 | Sets \a min value on the axis. | |
278 | */ |
|
288 | */ | |
279 | void QChartAxis::setMin(qreal min) |
|
289 | void QChartAxis::setMin(qreal min) | |
280 | { |
|
290 | { | |
281 |
|
|
291 | if(m_min!=min) { | |
282 |
|
|
292 | m_min=min; | |
283 | emit minChanged(m_min); |
|
293 | emit rangeChanged(this); | |
284 | } |
|
294 | } | |
285 | } |
|
295 | } | |
286 |
|
296 | |||
287 | /*! |
|
297 | /*! | |
288 |
|
|
298 | Sets \a max value on the axis. | |
289 | */ |
|
299 | */ | |
290 | void QChartAxis::setMax(qreal max) |
|
300 | void QChartAxis::setMax(qreal max) | |
291 | { |
|
301 | { | |
292 |
|
|
302 | if(m_max!=max) { | |
293 |
|
|
303 | m_max=max; | |
294 | emit maxChanged(m_max); |
|
304 | emit rangeChanged(this); | |
295 | } |
|
305 | } | |
296 | } |
|
306 | } | |
297 |
|
307 | |||
298 | /*! |
|
308 | /*! | |
299 | Sets range from \a min to \a max on the axis. |
|
309 | Sets range from \a min to \a max on the axis. | |
300 | */ |
|
310 | */ | |
301 | void QChartAxis::setRange(qreal min, qreal max) |
|
311 | void QChartAxis::setRange(qreal min, qreal max) | |
302 | { |
|
312 | { | |
303 |
|
|
313 | setMin(min); | |
304 |
|
|
314 | setMax(max); | |
|
315 | } | |||
|
316 | ||||
|
317 | void QChartAxis::updateRange(qreal min, qreal max) | |||
|
318 | { | |||
|
319 | if(m_max!=max){ | |||
|
320 | emit maxChanged(max); | |||
|
321 | } | |||
|
322 | ||||
|
323 | if(m_min!=min){ | |||
|
324 | emit minChanged(min); | |||
|
325 | } | |||
|
326 | ||||
|
327 | m_max=max; | |||
|
328 | m_min=min; | |||
305 | } |
|
329 | } | |
306 |
|
330 | |||
307 | /*! |
|
331 | /*! | |
308 | Sets \a count for ticks on the axis. |
|
332 | Sets \a count for ticks on the axis. | |
309 | */ |
|
333 | */ | |
310 | void QChartAxis::setTicksCount(int count) |
|
334 | void QChartAxis::setTicksCount(int count) | |
311 | { |
|
335 | { | |
312 | m_ticksCount=count; |
|
336 | m_ticksCount=count; | |
313 | emit ticksChanged(this); |
|
337 | emit ticksChanged(this); | |
314 | } |
|
338 | } | |
315 |
|
339 | |||
316 | /*! |
|
340 | /*! | |
317 | TODO: refactor me. Sets string \a label for \a value on the axis. |
|
341 | TODO: refactor me. Sets string \a label for \a value on the axis. | |
318 | */ |
|
342 | */ | |
319 | void QChartAxis::addAxisTickLabel(qreal value,const QString& label) |
|
343 | void QChartAxis::addAxisTickLabel(qreal value,const QString& label) | |
320 | { |
|
344 | { | |
321 | m_ticks.insert(value,label); |
|
345 | m_ticks.insert(value,label); | |
322 | emit ticksChanged(this); |
|
346 | emit ticksChanged(this); | |
323 | } |
|
347 | } | |
324 |
|
348 | |||
325 | /*! |
|
349 | /*! | |
326 | TODO: refactor me. Removes label for \a value on the axis. |
|
350 | TODO: refactor me. Removes label for \a value on the axis. | |
327 | */ |
|
351 | */ | |
328 | void QChartAxis::removeAxisTickLabel(qreal value) |
|
352 | void QChartAxis::removeAxisTickLabel(qreal value) | |
329 | { |
|
353 | { | |
330 | m_ticks.remove(value); |
|
354 | m_ticks.remove(value); | |
331 | emit ticksChanged(this); |
|
355 | emit ticksChanged(this); | |
332 | } |
|
356 | } | |
333 |
|
357 | |||
334 | /*! |
|
358 | /*! | |
335 | TODO: refactor me. Returns label for \a value on the axis. |
|
359 | TODO: refactor me. Returns label for \a value on the axis. | |
336 | */ |
|
360 | */ | |
337 | QString QChartAxis::axisTickLabel(qreal value) const |
|
361 | QString QChartAxis::axisTickLabel(qreal value) const | |
338 | { |
|
362 | { | |
339 | return m_ticks.value(value); |
|
363 | return m_ticks.value(value); | |
340 | } |
|
364 | } | |
341 |
|
365 | |||
342 | /*! |
|
366 | /*! | |
343 | TODO: refactor me. Removes all the string labels for on the axis. |
|
367 | TODO: refactor me. Removes all the string labels for on the axis. | |
344 | */ |
|
368 | */ | |
345 | void QChartAxis::clearAxisTickLabels() |
|
369 | void QChartAxis::clearAxisTickLabels() | |
346 | { |
|
370 | { | |
347 | m_ticks.clear(); |
|
371 | m_ticks.clear(); | |
348 | emit ticksChanged(this); |
|
372 | emit ticksChanged(this); | |
349 | } |
|
373 | } | |
350 |
|
374 | |||
351 | #include "moc_qchartaxis.cpp" |
|
375 | #include "moc_qchartaxis.cpp" | |
352 |
|
376 | |||
353 | QTCOMMERCIALCHART_END_NAMESPACE |
|
377 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,101 +1,105 | |||||
1 | #ifndef QCHARTAXIS_H_ |
|
1 | #ifndef QCHARTAXIS_H_ | |
2 | #define QCHARTAXIS_H_ |
|
2 | #define QCHARTAXIS_H_ | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <QPen> |
|
5 | #include <QPen> | |
6 | #include <QFont> |
|
6 | #include <QFont> | |
7 |
|
7 | |||
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject |
|
11 | class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject | |
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 | public: |
|
14 | public: | |
15 | QChartAxis(QObject* parent =0); |
|
15 | QChartAxis(QObject* parent =0); | |
16 | ~QChartAxis(); |
|
16 | ~QChartAxis(); | |
17 |
|
17 | |||
18 | //axis handling |
|
18 | //axis handling | |
19 | bool isAxisVisible() const { return m_axisVisible;}; |
|
19 | bool isAxisVisible() const { return m_axisVisible;}; | |
20 | void setAxisVisible(bool visible); |
|
20 | void setAxisVisible(bool visible); | |
21 | void setAxisPen(const QPen& pen); |
|
21 | void setAxisPen(const QPen& pen); | |
22 | QPen axisPen() const { return m_axisPen;}; |
|
22 | QPen axisPen() const { return m_axisPen;}; | |
23 |
|
23 | |||
24 | //grid handling |
|
24 | //grid handling | |
25 | bool isGridVisible() const { return m_gridVisible;}; |
|
25 | bool isGridVisible() const { return m_gridVisible;}; | |
26 | void setGridVisible(bool visible); |
|
26 | void setGridVisible(bool visible); | |
27 | void setGridPen(const QPen& pen); |
|
27 | void setGridPen(const QPen& pen); | |
28 | QPen gridPen() const {return m_gridPen;} |
|
28 | QPen gridPen() const {return m_gridPen;} | |
29 |
|
29 | |||
30 | //labels handling |
|
30 | //labels handling | |
31 | bool labelsVisible() const { return m_labelsVisible;}; |
|
31 | bool labelsVisible() const { return m_labelsVisible;}; | |
32 | void setLabelsVisible(bool visible); |
|
32 | void setLabelsVisible(bool visible); | |
33 | void setLabelsPen(const QPen& pen); |
|
33 | void setLabelsPen(const QPen& pen); | |
34 | QPen labelsPen() const { return m_labelsPen;} |
|
34 | QPen labelsPen() const { return m_labelsPen;} | |
35 | void setLabelsBrush(const QBrush& brush); |
|
35 | void setLabelsBrush(const QBrush& brush); | |
36 | QBrush labelsBrush() const { return m_labelsBrush;} |
|
36 | QBrush labelsBrush() const { return m_labelsBrush;} | |
37 | void setLabelsFont(const QFont& font); |
|
37 | void setLabelsFont(const QFont& font); | |
38 | QFont labelsFont() const { return m_labelsFont;} |
|
38 | QFont labelsFont() const { return m_labelsFont;} | |
39 | void setLabelsAngle(int angle); |
|
39 | void setLabelsAngle(int angle); | |
40 | int labelsAngle() const { return m_labelsAngle;}; |
|
40 | int labelsAngle() const { return m_labelsAngle;}; | |
41 |
|
41 | |||
42 | //shades handling |
|
42 | //shades handling | |
43 | bool shadesVisible() const { return m_shadesVisible;}; |
|
43 | bool shadesVisible() const { return m_shadesVisible;}; | |
44 | void setShadesVisible(bool visible); |
|
44 | void setShadesVisible(bool visible); | |
45 | void setShadesPen(const QPen& pen); |
|
45 | void setShadesPen(const QPen& pen); | |
46 | QPen shadesPen() const { return m_shadesPen;} |
|
46 | QPen shadesPen() const { return m_shadesPen;} | |
47 | void setShadesBrush(const QBrush& brush); |
|
47 | void setShadesBrush(const QBrush& brush); | |
48 | QBrush shadesBrush() const { return m_shadesBrush;} |
|
48 | QBrush shadesBrush() const { return m_shadesBrush;} | |
49 | void setShadesOpacity(qreal opacity); |
|
49 | void setShadesOpacity(qreal opacity); | |
50 | qreal shadesOpacity() const { return m_shadesOpacity;} |
|
50 | qreal shadesOpacity() const { return m_shadesOpacity;} | |
51 |
|
51 | |||
52 | //range handling |
|
52 | //range handling | |
53 | void setMin(qreal min); |
|
53 | void setMin(qreal min); | |
54 | qreal min() const { return m_min;}; |
|
54 | qreal min() const { return m_min;}; | |
55 | void setMax(qreal max); |
|
55 | void setMax(qreal max); | |
56 | qreal max() const { return m_max;}; |
|
56 | qreal max() const { return m_max;}; | |
57 | void setRange(qreal min, qreal max); |
|
57 | void setRange(qreal min, qreal max); | |
58 |
|
58 | |||
59 | //ticks handling |
|
59 | //ticks handling | |
60 | void setTicksCount(int count); |
|
60 | void setTicksCount(int count); | |
61 | int ticksCount() const { return m_ticksCount;} |
|
61 | int ticksCount() const { return m_ticksCount;} | |
62 | void addAxisTickLabel(qreal value,const QString& label); |
|
62 | void addAxisTickLabel(qreal value,const QString& label); | |
63 | void removeAxisTickLabel(qreal value); |
|
63 | void removeAxisTickLabel(qreal value); | |
64 | QString axisTickLabel(qreal value) const ; |
|
64 | QString axisTickLabel(qreal value) const ; | |
65 | void clearAxisTickLabels(); |
|
65 | void clearAxisTickLabels(); | |
66 |
|
66 | |||
|
67 | //internal | |||
|
68 | void updateRange(qreal min, qreal max); | |||
|
69 | ||||
67 | signals: |
|
70 | signals: | |
68 | void minChanged(qreal min); |
|
71 | void minChanged(qreal min); | |
69 | void maxChanged(qreal max); |
|
72 | void maxChanged(qreal max); | |
70 | //private signal |
|
73 | //private signal | |
71 | void update(QChartAxis*); |
|
74 | void update(QChartAxis*); | |
|
75 | void rangeChanged(QChartAxis*); | |||
72 | void ticksChanged(QChartAxis*); |
|
76 | void ticksChanged(QChartAxis*); | |
73 |
|
77 | |||
74 | private: |
|
78 | private: | |
75 | bool m_axisVisible; |
|
79 | bool m_axisVisible; | |
76 | QPen m_axisPen; |
|
80 | QPen m_axisPen; | |
77 | QBrush m_axisBrush; |
|
81 | QBrush m_axisBrush; | |
78 |
|
82 | |||
79 | bool m_gridVisible; |
|
83 | bool m_gridVisible; | |
80 | QPen m_gridPen; |
|
84 | QPen m_gridPen; | |
81 |
|
85 | |||
82 | bool m_labelsVisible; |
|
86 | bool m_labelsVisible; | |
83 | QPen m_labelsPen; |
|
87 | QPen m_labelsPen; | |
84 | QBrush m_labelsBrush; |
|
88 | QBrush m_labelsBrush; | |
85 | QFont m_labelsFont; |
|
89 | QFont m_labelsFont; | |
86 | int m_labelsAngle; |
|
90 | int m_labelsAngle; | |
87 |
|
91 | |||
88 | bool m_shadesVisible; |
|
92 | bool m_shadesVisible; | |
89 | QPen m_shadesPen; |
|
93 | QPen m_shadesPen; | |
90 | QBrush m_shadesBrush; |
|
94 | QBrush m_shadesBrush; | |
91 | qreal m_shadesOpacity; |
|
95 | qreal m_shadesOpacity; | |
92 |
|
96 | |||
93 | qreal m_min; |
|
97 | qreal m_min; | |
94 | qreal m_max; |
|
98 | qreal m_max; | |
95 |
|
99 | |||
96 | int m_ticksCount; |
|
100 | int m_ticksCount; | |
97 | QMap<qreal, QString> m_ticks; |
|
101 | QMap<qreal, QString> m_ticks; | |
98 | }; |
|
102 | }; | |
99 |
|
103 | |||
100 | QTCOMMERCIALCHART_END_NAMESPACE |
|
104 | QTCOMMERCIALCHART_END_NAMESPACE | |
101 | #endif /* QCHARTAXIS_H_ */ |
|
105 | #endif /* QCHARTAXIS_H_ */ |
General Comments 0
You need to be logged in to leave comments.
Login now