@@ -1,29 +1,32 | |||||
1 | /*! |
|
1 | /*! | |
2 | \page index.html |
|
2 | \page index.html | |
3 | \keyword About |
|
3 | \keyword About | |
4 |
|
4 | |||
5 | \raw HTML |
|
5 | \raw HTML | |
6 | <div class="qchart"> |
|
6 | <div class="qchart"> | |
7 | <img src="images/qt_commercial_logo.png" alt="qtcommercial"/> |
|
7 | <img src="images/qt_commercial_logo.png" alt="qtcommercial"/> | |
8 |
|
8 | |||
9 | <p> |
|
9 | <p> | |
10 |
QCharts is a part of Qt Commercial addons package. It provides a set of |
|
10 | QCharts is a part of Qt Commercial addons package. It provides a set of easy to use chart | |
11 | It uses Qt Graphics View Framework, therefore charts can be easily integrated 2D modern user interfaces. QCharts can be used as QWidgets, QGraphicsWidget or QML elements. |
|
11 | components which are available for Qt Commercial customers. It uses Qt Graphics View | |
12 | Users can easily create impressive graphs by selecting one of the charts themes. |
|
12 | Framework, therefore charts can be easily integrated to modern 2D user interfaces. QCharts can | |
|
13 | be used as QWidgets, QGraphicsWidget or QML elements. Users can easily create impressive | |||
|
14 | graphs by selecting one of the charts themes. | |||
13 | </p> |
|
15 | </p> | |
|
16 | ||||
14 | <table><tr> |
|
17 | <table><tr> | |
15 | <td><img src="images/linechart.png" alt="linechart" /></td> |
|
18 | <td><img src="images/linechart.png" alt="linechart" /></td> | |
16 | <td><img src="images/chartview_example_bar.jpg " alt="barchart" /></td> |
|
19 | <td><img src="images/chartview_example_bar.jpg " alt="barchart" /></td> | |
17 | <td><img src="images/chartview_example_pie.jpg " alt="piechart" /></td> |
|
20 | <td><img src="images/chartview_example_pie.jpg " alt="piechart" /></td> | |
18 | </tr> |
|
21 | </tr> | |
19 | <tr> |
|
22 | <tr> | |
20 | <td><img src="images/chartview_example.jpg " alt="linechart" /></td> |
|
23 | <td><img src="images/chartview_example.jpg " alt="linechart" /></td> | |
21 | <td><img src="images/chartview_example_scatter.jpg " alt="scatterchart" /></td> |
|
24 | <td><img src="images/chartview_example_scatter.jpg " alt="scatterchart" /></td> | |
22 | <td><img src="images/chartview_example_theme.jpg " alt="themechart" /></td> |
|
25 | <td><img src="images/chartview_example_theme.jpg " alt="themechart" /></td> | |
23 | </tr> |
|
26 | </tr> | |
24 | </table> |
|
27 | </table> | |
25 | </div> |
|
28 | </div> | |
26 | \endraw |
|
29 | \endraw | |
27 |
|
30 | |||
28 |
|
31 | |||
29 | */ |
|
32 | */ |
@@ -1,67 +1,62 | |||||
1 | #include <QtGui/QApplication> |
|
1 | #include <QtGui/QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartglobal.h> |
|
3 | #include <qchartglobal.h> | |
4 | #include <qchartview.h> |
|
4 | #include <qchartview.h> | |
5 | #include <qscatterseries.h> |
|
5 | #include <qscatterseries.h> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
7 | QTCOMMERCIALCHART_USE_NAMESPACE | |
8 |
|
8 | |||
9 | int main(int argc, char *argv[]) |
|
9 | int main(int argc, char *argv[]) | |
10 | { |
|
10 | { | |
11 | QApplication a(argc, argv); |
|
11 | QApplication a(argc, argv); | |
12 |
|
12 | |||
13 | //! [1] |
|
13 | //! [1] | |
14 | // Create chart view |
|
14 | // Create chart view | |
15 | QChartView *chartView = new QChartView(); |
|
15 | QChartView *chartView = new QChartView(); | |
16 | chartView->setChartTheme(QChart::ChartThemeIcy); |
|
16 | chartView->setChartTheme(QChart::ChartThemeIcy); | |
17 |
|
17 | |||
18 | // Add scatter series with simple test data |
|
18 | // Add scatter series with simple test data | |
19 | QScatterSeries *scatter = new QScatterSeries(); |
|
19 | QScatterSeries *scatter = new QScatterSeries(); | |
20 | *scatter << QPointF(0.5, 5.0) |
|
20 | *scatter << QPointF(0.5, 5.0) | |
21 | << QPointF(1.0, 4.5) |
|
21 | << QPointF(1.0, 4.5) | |
22 | << QPointF(1.0, 5.5) |
|
22 | << QPointF(1.0, 5.5) | |
23 | << QPointF(1.5, 5.0) |
|
23 | << QPointF(1.5, 5.0) | |
24 | << QPointF(2.0, 4.5) |
|
24 | << QPointF(2.0, 4.5) | |
25 | << QPointF(2.5, 5.0); |
|
25 | << QPointF(2.5, 5.0); | |
26 | // Chart takes ownership |
|
26 | // Chart takes ownership | |
27 | chartView->addSeries(scatter); |
|
27 | chartView->addSeries(scatter); | |
28 | //! [1] |
|
28 | //! [1] | |
29 |
|
29 | |||
30 | // Add some more data |
|
|||
31 | //! [2] |
|
|||
32 | scatter->addData(QPointF(2.0, 5.5)); |
|
|||
33 | //! [2] |
|
|||
34 |
|
||||
35 | // And more |
|
30 | // And more | |
36 | //! [3] |
|
31 | //! [3] | |
37 | *scatter << QPointF(2.0, 5.5); |
|
32 | *scatter << QPointF(2.0, 5.5) << QPointF(2.2, 5.4); | |
38 | //! [3] |
|
33 | //! [3] | |
39 |
|
34 | |||
40 | // Add another scatter series (re-use the previous pointer) |
|
35 | // Add another scatter series (re-use the previous pointer) | |
41 | // - more data with random component |
|
36 | // - more data with random component | |
42 | scatter = new QScatterSeries(); |
|
37 | scatter = new QScatterSeries(); | |
43 | for (qreal i(0.0); i < 20; i += 0.15) { |
|
38 | for (qreal i(0.0); i < 20; i += 0.15) { | |
44 | (*scatter) << QPointF(i + (qreal)(rand() % 100) / 100.0, |
|
39 | (*scatter) << QPointF(i + (qreal)(rand() % 100) / 100.0, | |
45 | i + (qreal)(rand() % 100) / 100.0); |
|
40 | i + (qreal)(rand() % 100) / 100.0); | |
46 | } |
|
41 | } | |
47 | //! [4] |
|
42 | //! [4] | |
48 | QBrush brush(QColor(255, 0, 0, 100), Qt::SolidPattern); |
|
43 | QBrush brush(QColor(255, 0, 0, 100), Qt::SolidPattern); | |
49 |
scatter->set |
|
44 | scatter->setBrush(brush); | |
50 | //! [4] |
|
45 | //! [4] | |
51 | //! [5] |
|
46 | //! [5] | |
52 | QPen pen(QColor(0, 255, 0, 80), 3); |
|
47 | QPen pen(QColor(0, 255, 0, 80), 3); | |
53 |
scatter->set |
|
48 | scatter->setPen(pen); | |
54 | //! [5] |
|
49 | //! [5] | |
55 | //! [6] |
|
50 | //! [6] | |
56 |
scatter->set |
|
51 | scatter->setShape(QScatterSeries::MarkerShapeRectangle); | |
57 | //! [6] |
|
52 | //! [6] | |
58 | chartView->addSeries(scatter); |
|
53 | chartView->addSeries(scatter); | |
59 |
|
54 | |||
60 | // Use the chart widget as the central widget |
|
55 | // Use the chart widget as the central widget | |
61 | QMainWindow w; |
|
56 | QMainWindow w; | |
62 | w.resize(640, 480); |
|
57 | w.resize(640, 480); | |
63 | w.setCentralWidget(chartView); |
|
58 | w.setCentralWidget(chartView); | |
64 | w.show(); |
|
59 | w.show(); | |
65 |
|
60 | |||
66 | return a.exec(); |
|
61 | return a.exec(); | |
67 | } |
|
62 | } |
@@ -1,68 +1,68 | |||||
1 | #include "declarativescatterseries.h" |
|
1 | #include "declarativescatterseries.h" | |
2 | #include "declarativechart.h" |
|
2 | #include "declarativechart.h" | |
3 | #include "qchart.h" |
|
3 | #include "qchart.h" | |
4 | #include "qscatterseries.h" |
|
4 | #include "qscatterseries.h" | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | DeclarativeScatterSeries::DeclarativeScatterSeries(QDeclarativeItem *parent) : |
|
8 | DeclarativeScatterSeries::DeclarativeScatterSeries(QDeclarativeItem *parent) : | |
9 | QDeclarativeItem(parent), |
|
9 | QDeclarativeItem(parent), | |
10 | m_chart(0), |
|
10 | m_chart(0), | |
11 | m_series(0) |
|
11 | m_series(0) | |
12 | { |
|
12 | { | |
13 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
13 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
14 | connect(this, SIGNAL(parentChanged()), |
|
14 | connect(this, SIGNAL(parentChanged()), | |
15 | this, SLOT(setParentForSeries())); |
|
15 | this, SLOT(setParentForSeries())); | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | void DeclarativeScatterSeries::setParentForSeries() |
|
18 | void DeclarativeScatterSeries::setParentForSeries() | |
19 | { |
|
19 | { | |
20 | if (!m_series) |
|
20 | if (!m_series) | |
21 | initSeries(); |
|
21 | initSeries(); | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | void DeclarativeScatterSeries::initSeries() |
|
24 | void DeclarativeScatterSeries::initSeries() | |
25 | { |
|
25 | { | |
26 | Q_ASSERT(!m_series); |
|
26 | Q_ASSERT(!m_series); | |
27 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); |
|
27 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); | |
28 |
|
28 | |||
29 | if (declarativeChart) { |
|
29 | if (declarativeChart) { | |
30 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); |
|
30 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); | |
31 | qDebug() << "creating scatter series for chart: " << chart; |
|
31 | qDebug() << "creating scatter series for chart: " << chart; | |
32 | Q_ASSERT(chart); |
|
32 | Q_ASSERT(chart); | |
33 |
|
33 | |||
34 | m_series = new QScatterSeries(); |
|
34 | m_series = new QScatterSeries(); | |
35 | Q_ASSERT(m_series); |
|
35 | Q_ASSERT(m_series); | |
36 | for (int i(0); i < m_data.count(); i++) { |
|
36 | for (int i(0); i < m_data.count(); i++) { | |
37 | ScatterElement *element = m_data.at(i); |
|
37 | ScatterElement *element = m_data.at(i); | |
38 | *m_series << QPointF(element->x(), element->y()); |
|
38 | *m_series << QPointF(element->x(), element->y()); | |
39 | } |
|
39 | } | |
40 | chart->addSeries(m_series); |
|
40 | chart->addSeries(m_series); | |
41 | } |
|
41 | } | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | QDeclarativeListProperty<ScatterElement> DeclarativeScatterSeries::data() |
|
44 | QDeclarativeListProperty<ScatterElement> DeclarativeScatterSeries::data() | |
45 | { |
|
45 | { | |
46 | return QDeclarativeListProperty<ScatterElement>(this, 0, |
|
46 | return QDeclarativeListProperty<ScatterElement>(this, 0, | |
47 | &DeclarativeScatterSeries::appendData); |
|
47 | &DeclarativeScatterSeries::appendData); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | void DeclarativeScatterSeries::appendData(QDeclarativeListProperty<ScatterElement> *list, |
|
50 | void DeclarativeScatterSeries::appendData(QDeclarativeListProperty<ScatterElement> *list, | |
51 | ScatterElement *element) |
|
51 | ScatterElement *element) | |
52 | { |
|
52 | { | |
53 | DeclarativeScatterSeries *series = qobject_cast<DeclarativeScatterSeries *>(list->object); |
|
53 | DeclarativeScatterSeries *series = qobject_cast<DeclarativeScatterSeries *>(list->object); | |
54 | qDebug() << "appendData: " << series; |
|
54 | qDebug() << "appendData: " << series; | |
55 | qDebug() << "appendData: " << element; |
|
55 | qDebug() << "appendData: " << element; | |
56 | qDebug() << "appendData: " << element->x(); |
|
56 | qDebug() << "appendData: " << element->x(); | |
57 | qDebug() << "appendData: " << element->y(); |
|
57 | qDebug() << "appendData: " << element->y(); | |
58 | qDebug() << "appendData: " << series->m_series; |
|
58 | qDebug() << "appendData: " << series->m_series; | |
59 | if (series) { |
|
59 | if (series) { | |
60 | series->m_data.append(element); |
|
60 | series->m_data.append(element); | |
61 | if (series->m_series) |
|
61 | if (series->m_series) | |
62 |
series->m_series->add |
|
62 | series->m_series->add(element->x(), element->y()); | |
63 | } |
|
63 | } | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | #include "moc_declarativescatterseries.cpp" |
|
66 | #include "moc_declarativescatterseries.cpp" | |
67 |
|
67 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
68 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,228 +1,225 | |||||
1 | #include "qscatterseries.h" |
|
1 | #include "qscatterseries.h" | |
2 | #include "scatterseries_p.h" |
|
2 | #include "scatterseries_p.h" | |
3 | #include "qchart.h" |
|
3 | #include "qchart.h" | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QScatterSeries |
|
6 | \class QScatterSeries | |
7 | \brief QtCommercial Chart series API for showing scatter series. |
|
7 | \brief QtCommercial Chart series API for showing scatter series. | |
8 |
|
8 | |||
9 | \mainclass |
|
9 | \mainclass | |
10 |
|
10 | |||
11 | Example on how to create a chart with scatter series: |
|
11 | Example on how to create a chart with scatter series: | |
12 | \snippet ../example/scatter/main.cpp 1 |
|
12 | \snippet ../example/scatter/main.cpp 1 | |
13 |
|
13 | |||
14 | The example code would result the following: |
|
14 | The example code would result the following: | |
15 |
|
15 | |||
16 | \image scatter_example1.jpg |
|
16 | \image scatter_example1.jpg | |
17 | */ |
|
17 | */ | |
18 |
|
18 | |||
19 | /*! |
|
19 | /*! | |
20 | \enum QScatterSeries::MarkerShape |
|
20 | \enum QScatterSeries::MarkerShape | |
21 |
|
21 | |||
22 | This enum describes the shape used when rendering marker items. |
|
22 | This enum describes the shape used when rendering marker items. | |
23 |
|
23 | |||
24 | \value MarkerShapeDefault |
|
24 | \value MarkerShapeDefault | |
25 | \value MarkerShapePoint |
|
25 | \value MarkerShapePoint | |
26 | \value MarkerShapeX |
|
26 | \value MarkerShapeX | |
27 | \value MarkerShapeRectangle |
|
27 | \value MarkerShapeRectangle | |
28 | \value MarkerShapeTiltedRectangle |
|
28 | \value MarkerShapeTiltedRectangle | |
29 | \value MarkerShapeTriangle |
|
29 | \value MarkerShapeTriangle | |
30 | \value MarkerShapeCircle |
|
30 | \value MarkerShapeCircle | |
31 | */ |
|
31 | */ | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \fn QChartSeriesType QScatterSeries::type() const |
|
34 | \fn QChartSeriesType QScatterSeries::type() const | |
35 | \brief Returns QChartSeries::SeriesTypeScatter. |
|
35 | \brief Returns QChartSeries::SeriesTypeScatter. | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \fn void QScatterSeries::clicked() |
|
39 | \fn void QScatterSeries::clicked() | |
40 | \brief TODO |
|
40 | \brief TODO | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \fn void QScatterSeries::hoverEnter() |
|
|||
45 | \brief TODO |
|
|||
46 | */ |
|
|||
47 |
|
||||
48 | /*! |
|
|||
49 | \fn void QScatterSeries::hoverLeave() |
|
|||
50 | \brief TODO |
|
|||
51 | */ |
|
|||
52 |
|
||||
53 | /*! |
|
|||
54 | \fn void QScatterSeries::changed() |
|
44 | \fn void QScatterSeries::changed() | |
55 | \brief TODO |
|
45 | \brief TODO | |
56 | */ |
|
46 | */ | |
57 |
|
47 | |||
58 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
48 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
59 |
|
49 | |||
60 | QScatterSeriesPrivate::QScatterSeriesPrivate() : |
|
50 | QScatterSeriesPrivate::QScatterSeriesPrivate() : | |
61 | m_data(QList<QPointF>()), |
|
51 | m_data(QList<QPointF>()), | |
62 | m_markerPen(QPen()), |
|
52 | m_markerPen(QPen()), | |
63 | m_markerBrush(QBrush()), |
|
53 | m_markerBrush(QBrush()), | |
64 | m_markerShape(QScatterSeries::MarkerShapeDefault) |
|
54 | m_markerShape(QScatterSeries::MarkerShapeDefault) | |
65 | { |
|
55 | { | |
66 | // Initialize pen color to invalid to use a theme color by default |
|
56 | // Initialize pen color to invalid to use a theme color by default | |
67 | m_markerPen.setColor(QColor::Invalid); |
|
57 | m_markerPen.setColor(QColor::Invalid); | |
68 | m_markerBrush.setColor(QColor::Invalid); |
|
58 | m_markerBrush.setColor(QColor::Invalid); | |
69 | } |
|
59 | } | |
70 |
|
60 | |||
71 | /*! |
|
61 | /*! | |
72 | Constructs a series object which is a child of \a parent. |
|
62 | Constructs a series object which is a child of \a parent. | |
73 | */ |
|
63 | */ | |
74 | QScatterSeries::QScatterSeries(QObject *parent) : |
|
64 | QScatterSeries::QScatterSeries(QObject *parent) : | |
75 | QChartSeries(parent), |
|
65 | QChartSeries(parent), | |
76 | d(new QScatterSeriesPrivate()) |
|
66 | d(new QScatterSeriesPrivate()) | |
77 | { |
|
67 | { | |
78 | } |
|
68 | } | |
79 |
|
69 | |||
80 | /*! |
|
70 | /*! | |
81 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. |
|
71 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. | |
82 | */ |
|
72 | */ | |
83 | QScatterSeries::~QScatterSeries() |
|
73 | QScatterSeries::~QScatterSeries() | |
84 | { |
|
74 | { | |
85 | delete d; |
|
75 | delete d; | |
86 | } |
|
76 | } | |
87 |
|
77 | |||
88 | /*! |
|
78 | /*! | |
|
79 | Add single data point with \a x and \a y coordinates to the series. | |||
|
80 | */ | |||
|
81 | void QScatterSeries::add(qreal x, qreal y) | |||
|
82 | { | |||
|
83 | d->m_data.append(QPointF(x, y)); | |||
|
84 | emit changed(); | |||
|
85 | } | |||
|
86 | ||||
|
87 | /*! | |||
89 | Add single data point with \a value to the series. |
|
88 | Add single data point with \a value to the series. | |
90 | For example: |
|
|||
91 | \snippet ../example/scatter/main.cpp 2 |
|
|||
92 | */ |
|
89 | */ | |
93 |
void QScatterSeries::add |
|
90 | void QScatterSeries::add(QPointF value) | |
94 | { |
|
91 | { | |
95 | d->m_data.append(value); |
|
92 | d->m_data.append(value); | |
96 | emit changed(); |
|
93 | emit changed(); | |
97 | } |
|
94 | } | |
98 |
|
95 | |||
99 | /*! |
|
96 | /*! | |
100 | Add list of \a points to the series. |
|
97 | Add list of \a points to the series. | |
101 | */ |
|
98 | */ | |
102 |
void QScatterSeries::add |
|
99 | void QScatterSeries::add(QList<QPointF> points) | |
103 | { |
|
100 | { | |
104 | d->m_data.append(points); |
|
101 | d->m_data.append(points); | |
105 | emit changed(); |
|
102 | emit changed(); | |
106 | } |
|
103 | } | |
107 |
|
104 | |||
108 | /*! |
|
105 | /*! | |
109 | Stream operator for adding a data point with \a value to the series. |
|
106 | Stream operator for adding a data point with \a value to the series. | |
110 |
\sa add |
|
107 | \sa add() | |
111 |
|
108 | |||
112 | For example: |
|
109 | For example: | |
113 | \snippet ../example/scatter/main.cpp 3 |
|
110 | \snippet ../example/scatter/main.cpp 3 | |
114 | */ |
|
111 | */ | |
115 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) |
|
112 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) | |
116 | { |
|
113 | { | |
117 | d->m_data.append(value); |
|
114 | d->m_data.append(value); | |
118 | emit changed(); |
|
115 | emit changed(); | |
119 | return *this; |
|
116 | return *this; | |
120 | } |
|
117 | } | |
121 |
|
118 | |||
122 | /*! |
|
119 | /*! | |
123 | Stream operator for adding a list of points to the series. |
|
120 | Stream operator for adding a list of points to the series. | |
124 |
\sa add |
|
121 | \sa add() | |
125 | */ |
|
122 | */ | |
126 | QScatterSeries& QScatterSeries::operator << (QList<QPointF> value) |
|
123 | QScatterSeries& QScatterSeries::operator << (QList<QPointF> value) | |
127 | { |
|
124 | { | |
128 | d->m_data.append(value); |
|
125 | d->m_data.append(value); | |
129 | emit changed(); |
|
126 | emit changed(); | |
130 | return *this; |
|
127 | return *this; | |
131 | } |
|
128 | } | |
132 |
|
129 | |||
133 | /*! |
|
130 | /*! | |
134 | Replaces the data of the series with the given list of data \a points. |
|
131 | Replaces the data of the series with the given list of data \a points. | |
135 | */ |
|
132 | */ | |
136 | void QScatterSeries::setData(QList<QPointF> points) |
|
133 | void QScatterSeries::setData(QList<QPointF> points) | |
137 | { |
|
134 | { | |
138 | d->m_data = points; |
|
135 | d->m_data = points; | |
139 | emit changed(); |
|
136 | emit changed(); | |
140 | } |
|
137 | } | |
141 |
|
138 | |||
142 | /*! |
|
139 | /*! | |
143 | Returns the current list of data points of the series. |
|
140 | Returns the current list of data points of the series. | |
144 | */ |
|
141 | */ | |
145 | QList<QPointF> QScatterSeries::data() |
|
142 | QList<QPointF> QScatterSeries::data() | |
146 | { |
|
143 | { | |
147 | return d->m_data; |
|
144 | return d->m_data; | |
148 | } |
|
145 | } | |
149 |
|
146 | |||
150 | /*! |
|
147 | /*! | |
151 | Overrides the default pen used for drawing a marker item with a user defined \a pen. The |
|
148 | Overrides the default pen used for drawing a marker item with a user defined \a pen. The | |
152 | default pen is defined by chart theme setting. |
|
149 | default pen is defined by chart theme setting. | |
153 |
|
150 | |||
154 | For example: |
|
151 | For example: | |
155 | \snippet ../example/scatter/main.cpp 5 |
|
152 | \snippet ../example/scatter/main.cpp 5 | |
156 |
|
153 | |||
157 | Would present your scatter markers with an opaque, uglyish green outlines instead of the |
|
154 | Would present your scatter markers with an opaque, uglyish green outlines instead of the | |
158 | beatiful markers defined by the chart's theme: |
|
155 | beatiful markers defined by the chart's theme: | |
159 | \image scatter_example_pen.jpg |
|
156 | \image scatter_example_pen.jpg | |
160 |
|
157 | |||
161 |
\sa set |
|
158 | \sa setBrush() | |
162 | \sa QChart::setChartTheme() |
|
159 | \sa QChart::setChartTheme() | |
163 | */ |
|
160 | */ | |
164 |
void QScatterSeries::set |
|
161 | void QScatterSeries::setPen(QPen pen) | |
165 | { |
|
162 | { | |
166 | d->m_markerPen = pen; |
|
163 | d->m_markerPen = pen; | |
167 | } |
|
164 | } | |
168 |
|
165 | |||
169 | /*! |
|
166 | /*! | |
170 | Returns the pen used for drawing markers. |
|
167 | Returns the pen used for drawing markers. | |
171 | */ |
|
168 | */ | |
172 |
QPen QScatterSeries:: |
|
169 | QPen QScatterSeries::pen() | |
173 | { |
|
170 | { | |
174 | return d->m_markerPen; |
|
171 | return d->m_markerPen; | |
175 | } |
|
172 | } | |
176 |
|
173 | |||
177 | /*! |
|
174 | /*! | |
178 | Overrides the default brush of the marker items with a user defined \a brush. The default brush |
|
175 | Overrides the default brush of the marker items with a user defined \a brush. The default brush | |
179 | is defined by chart theme setting. |
|
176 | is defined by chart theme setting. | |
180 |
|
177 | |||
181 | For example: |
|
178 | For example: | |
182 | \snippet ../example/scatter/main.cpp 4 |
|
179 | \snippet ../example/scatter/main.cpp 4 | |
183 |
|
180 | |||
184 | Would fill your scatter markers with an opaque red color: |
|
181 | Would fill your scatter markers with an opaque red color: | |
185 | \image scatter_example_brush.jpg |
|
182 | \image scatter_example_brush.jpg | |
186 |
|
183 | |||
187 |
\sa set |
|
184 | \sa setPen() | |
188 | \sa QChart::setChartTheme() |
|
185 | \sa QChart::setChartTheme() | |
189 | */ |
|
186 | */ | |
190 |
void QScatterSeries::set |
|
187 | void QScatterSeries::setBrush(QBrush brush) | |
191 | { |
|
188 | { | |
192 | d->m_markerBrush = brush; |
|
189 | d->m_markerBrush = brush; | |
193 | } |
|
190 | } | |
194 |
|
191 | |||
195 | /*! |
|
192 | /*! | |
196 | Returns the brush used for drawing markers. |
|
193 | Returns the brush used for drawing markers. | |
197 | */ |
|
194 | */ | |
198 |
QBrush QScatterSeries:: |
|
195 | QBrush QScatterSeries::brush() | |
199 | { |
|
196 | { | |
200 | return d->m_markerBrush; |
|
197 | return d->m_markerBrush; | |
201 | } |
|
198 | } | |
202 |
|
199 | |||
203 | /*! |
|
200 | /*! | |
204 | Overrides the default shape of the marker items with a user defined \a shape. The default shape |
|
201 | Overrides the default shape of the marker items with a user defined \a shape. The default shape | |
205 | is defined by chart theme setting. |
|
202 | is defined by chart theme setting. | |
206 |
|
203 | |||
207 | For example: |
|
204 | For example: | |
208 | \snippet ../example/scatter/main.cpp 6 |
|
205 | \snippet ../example/scatter/main.cpp 6 | |
209 |
|
206 | |||
210 | Would make your scatter marker items rectangle: |
|
207 | Would make your scatter marker items rectangle: | |
211 | \image scatter_example_shape.jpg |
|
208 | \image scatter_example_shape.jpg | |
212 | */ |
|
209 | */ | |
213 |
void QScatterSeries::set |
|
210 | void QScatterSeries::setShape(MarkerShape shape) | |
214 | { |
|
211 | { | |
215 | d->m_markerShape = shape; |
|
212 | d->m_markerShape = shape; | |
216 | } |
|
213 | } | |
217 |
|
214 | |||
218 | /*! |
|
215 | /*! | |
219 | Returns the shape used for drawing markers. |
|
216 | Returns the shape used for drawing markers. | |
220 | */ |
|
217 | */ | |
221 |
QScatterSeries::MarkerShape QScatterSeries:: |
|
218 | QScatterSeries::MarkerShape QScatterSeries::shape() | |
222 | { |
|
219 | { | |
223 | return (QScatterSeries::MarkerShape) d->m_markerShape; |
|
220 | return (QScatterSeries::MarkerShape) d->m_markerShape; | |
224 | } |
|
221 | } | |
225 |
|
222 | |||
226 | #include "moc_qscatterseries.cpp" |
|
223 | #include "moc_qscatterseries.cpp" | |
227 |
|
224 | |||
228 | QTCOMMERCIALCHART_END_NAMESPACE |
|
225 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,71 +1,68 | |||||
1 | #ifndef QSCATTERSERIES_H |
|
1 | #ifndef QSCATTERSERIES_H | |
2 | #define QSCATTERSERIES_H |
|
2 | #define QSCATTERSERIES_H | |
3 |
|
3 | |||
4 | #include "qchartseries.h" |
|
4 | #include "qchartseries.h" | |
5 | #include <QRectF> |
|
5 | #include <QRectF> | |
6 | #include <QColor> |
|
6 | #include <QColor> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 | class QScatterSeriesPrivate; |
|
9 | class QScatterSeriesPrivate; | |
10 |
|
10 | |||
11 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries |
|
11 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries | |
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 |
|
14 | |||
15 | public: |
|
15 | public: | |
16 | enum MarkerShape { |
|
16 | enum MarkerShape { | |
17 | // TODO: to be defined by the graphics design |
|
17 | // TODO: to be defined by the graphics design | |
18 | // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot |
|
18 | // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot | |
19 | MarkerShapeDefault = 0, |
|
19 | MarkerShapeDefault = 0, | |
20 | MarkerShapePoint, |
|
20 | MarkerShapePoint, | |
21 | MarkerShapeX, |
|
21 | MarkerShapeX, | |
22 | MarkerShapeRectangle, |
|
22 | MarkerShapeRectangle, | |
23 | MarkerShapeTiltedRectangle, |
|
23 | MarkerShapeTiltedRectangle, | |
24 | MarkerShapeTriangle, |
|
24 | MarkerShapeTriangle, | |
25 | MarkerShapeCircle |
|
25 | MarkerShapeCircle | |
26 | }; |
|
26 | }; | |
27 |
|
27 | |||
28 | public: |
|
28 | public: | |
29 | QScatterSeries(QObject *parent = 0); |
|
29 | QScatterSeries(QObject *parent = 0); | |
30 | ~QScatterSeries(); |
|
30 | ~QScatterSeries(); | |
31 |
|
31 | |||
32 | public: // from QChartSeries |
|
32 | public: // from QChartSeries | |
33 | QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } |
|
33 | QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } | |
34 |
|
34 | |||
35 | public: |
|
35 | public: | |
36 | void addData(QPointF value); |
|
36 | void add(qreal x, qreal y); | |
37 |
void add |
|
37 | void add(QPointF value); | |
|
38 | void add(QList<QPointF> points); | |||
38 | void setData(QList<QPointF> points); |
|
39 | void setData(QList<QPointF> points); | |
39 | QScatterSeries& operator << (const QPointF &value); |
|
40 | QScatterSeries& operator << (const QPointF &value); | |
40 | QScatterSeries& operator << (QList<QPointF> points); |
|
41 | QScatterSeries& operator << (QList<QPointF> points); | |
41 | QList<QPointF> data(); |
|
42 | QList<QPointF> data(); | |
42 |
//TODO: insert |
|
43 | //TODO: insert, replace, remove, clear...? | |
43 |
|
44 | |||
44 |
QPen |
|
45 | QPen pen(); | |
45 | QBrush markerBrush(); |
|
46 | void setPen(QPen pen); | |
46 | MarkerShape markerShape(); |
|
47 | QBrush brush(); | |
|
48 | void setBrush(QBrush brush); | |||
|
49 | MarkerShape shape(); | |||
|
50 | void setShape(MarkerShape shape); | |||
47 | // TODO: marker size? |
|
51 | // TODO: marker size? | |
48 |
|
52 | |||
49 | public Q_SLOTS: |
|
|||
50 | void setMarkerPen(QPen pen); |
|
|||
51 | void setMarkerBrush(QBrush brush); |
|
|||
52 | void setMarkerShape(MarkerShape shape); |
|
|||
53 |
|
||||
54 | Q_SIGNALS: |
|
53 | Q_SIGNALS: | |
55 | void clicked(/* TODO: parameters? */); |
|
54 | void clicked(/* TODO: parameters? */); | |
56 | void hoverEnter(/* TODO: parameters? */); |
|
|||
57 | void hoverLeave(/* TODO: parameters? */); |
|
|||
58 | // TODO: move to PIMPL for simplicity or does the user ever need changed signals? |
|
55 | // TODO: move to PIMPL for simplicity or does the user ever need changed signals? | |
59 | // TODO: more finegrained signaling for performance reasons |
|
56 | // TODO: more finegrained signaling for performance reasons | |
60 | // (check QPieSeries implementation with change sets) |
|
57 | // (check QPieSeries implementation with change sets) | |
61 | void changed(); |
|
58 | void changed(); | |
62 |
|
59 | |||
63 | private: |
|
60 | private: | |
64 | Q_DECLARE_PRIVATE(QScatterSeries) |
|
61 | Q_DECLARE_PRIVATE(QScatterSeries) | |
65 | Q_DISABLE_COPY(QScatterSeries) |
|
62 | Q_DISABLE_COPY(QScatterSeries) | |
66 | QScatterSeriesPrivate *const d; |
|
63 | QScatterSeriesPrivate *const d; | |
67 | }; |
|
64 | }; | |
68 |
|
65 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
66 | QTCOMMERCIALCHART_END_NAMESPACE | |
70 |
|
67 | |||
71 | #endif // QSCATTERSERIES_H |
|
68 | #endif // QSCATTERSERIES_H |
@@ -1,129 +1,124 | |||||
1 | #include "scatterpresenter_p.h" |
|
1 | #include "scatterpresenter_p.h" | |
2 | #include "qscatterseries.h" |
|
2 | #include "qscatterseries.h" | |
3 | #include <QPen> |
|
3 | #include <QPen> | |
4 | #include <QPainter> |
|
4 | #include <QPainter> | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QGraphicsSceneMouseEvent> |
|
6 | #include <QGraphicsSceneMouseEvent> | |
7 | #include <QGraphicsDropShadowEffect> |
|
7 | #include <QGraphicsDropShadowEffect> | |
8 | #include <QDebug> |
|
8 | #include <QDebug> | |
9 | #include <QTime> |
|
9 | #include <QTime> | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent) : |
|
13 | ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent) : | |
14 | ChartItem(parent), |
|
14 | ChartItem(parent), | |
15 | m_series(series), |
|
15 | m_series(series), | |
16 | m_boundingRect(), |
|
16 | m_boundingRect(), | |
17 | m_visibleChartArea() |
|
17 | m_visibleChartArea() | |
18 | { |
|
18 | { | |
19 | if (parent) |
|
19 | if (parent) | |
20 | m_boundingRect = parent->boundingRect(); |
|
20 | m_boundingRect = parent->boundingRect(); | |
21 |
|
21 | |||
22 | if (series) { |
|
22 | if (series) { | |
23 | connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged())); |
|
23 | connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged())); | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect(); |
|
26 | QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect(); | |
27 | dropShadow->setOffset(2.0); |
|
27 | dropShadow->setOffset(2.0); | |
|
28 | dropShadow->setBlurRadius(2.0); | |||
28 | setGraphicsEffect(dropShadow); |
|
29 | setGraphicsEffect(dropShadow); | |
29 | } |
|
30 | } | |
30 |
|
31 | |||
31 | void ScatterPresenter::handleDomainChanged(const Domain& domain) |
|
32 | void ScatterPresenter::handleDomainChanged(const Domain& domain) | |
32 | { |
|
33 | { | |
33 | m_visibleChartArea = domain; |
|
34 | m_visibleChartArea = domain; | |
34 | changeGeometry(); |
|
35 | changeGeometry(); | |
35 | } |
|
36 | } | |
36 |
|
37 | |||
37 | void ScatterPresenter::handleGeometryChanged(const QRectF& rect) |
|
38 | void ScatterPresenter::handleGeometryChanged(const QRectF& rect) | |
38 | { |
|
39 | { | |
39 | m_boundingRect = rect; |
|
40 | m_boundingRect = rect; | |
40 | changeGeometry(); |
|
41 | changeGeometry(); | |
41 | } |
|
42 | } | |
42 |
|
43 | |||
43 | void ScatterPresenter::handleModelChanged() |
|
44 | void ScatterPresenter::handleModelChanged() | |
44 | { |
|
45 | { | |
45 | // TODO: more fine grained modelChanged signaling |
|
46 | // TODO: more fine grained modelChanged signaling | |
46 | changeGeometry(); |
|
47 | changeGeometry(); | |
47 | } |
|
48 | } | |
48 |
|
49 | |||
49 | void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) |
|
50 | void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) | |
50 | { |
|
51 | { | |
51 | painter->save(); |
|
52 | painter->save(); | |
52 | painter->setClipRect(m_boundingRect); |
|
53 | painter->setClipRect(m_boundingRect); | |
53 |
|
54 | |||
54 | // Paint the shape |
|
55 | // Paint the shape | |
55 | // The custom settings in series override those defined by the theme |
|
56 | // The custom settings in series override those defined by the theme | |
56 | QPen pen = m_markerPen; |
|
57 | QPen pen = m_markerPen; | |
57 |
if (m_series-> |
|
58 | if (m_series->pen().color().isValid()) | |
58 |
pen = m_series-> |
|
59 | pen = m_series->pen(); | |
59 |
if (m_series-> |
|
60 | if (m_series->brush().color().isValid()) | |
60 |
painter->setBrush(m_series-> |
|
61 | painter->setBrush(m_series->brush()); | |
61 | else |
|
62 | else | |
62 | painter->setBrush(m_markerBrush); |
|
63 | painter->setBrush(m_markerBrush); | |
63 | painter->setPen(pen); |
|
64 | painter->setPen(pen); | |
64 | painter->drawPath(m_path); |
|
65 | painter->drawPath(m_path); | |
65 |
|
66 | |||
66 | painter->restore(); |
|
67 | painter->restore(); | |
67 | } |
|
68 | } | |
68 |
|
69 | |||
69 | void ScatterPresenter::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
70 | void ScatterPresenter::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
70 | { |
|
71 | { | |
71 | qDebug() << "ScatterPresenter::mousePressEvent" << event << " cont: " |
|
72 | qDebug() << "ScatterPresenter::mousePressEvent" << event << " cont: " | |
72 | << m_path.contains(event->lastPos()); |
|
73 | << m_path.contains(event->lastPos()); | |
73 |
|
74 | |||
74 | if (m_path.contains(event->lastPos())) |
|
75 | if (m_path.contains(event->lastPos())) | |
75 | emit clicked(); |
|
76 | emit clicked(); | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 | void ScatterPresenter::changeGeometry() |
|
79 | void ScatterPresenter::changeGeometry() | |
79 | { |
|
80 | { | |
80 | if (m_boundingRect.isValid()) { |
|
81 | if (m_boundingRect.isValid()) { | |
81 | prepareGeometryChange(); |
|
82 | prepareGeometryChange(); | |
82 | qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); |
|
83 | qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); | |
83 | qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); |
|
84 | qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); | |
84 |
|
85 | |||
85 |
int shape = m_series-> |
|
86 | int shape = m_series->shape(); | |
86 | m_path = QPainterPath(); |
|
87 | m_path = QPainterPath(); | |
87 |
|
88 | |||
88 | foreach (QPointF point, m_series->data()) { |
|
89 | foreach (QPointF point, m_series->data()) { | |
89 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing |
|
90 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing | |
90 | qreal x = m_boundingRect.left() + point.x() * scalex - m_visibleChartArea.m_minX * scalex; |
|
91 | qreal x = m_boundingRect.left() + point.x() * scalex - m_visibleChartArea.m_minX * scalex; | |
91 | qreal y = m_boundingRect.bottom() - point.y() * scaley + m_visibleChartArea.m_minY * scaley; |
|
92 | qreal y = m_boundingRect.bottom() - point.y() * scaley + m_visibleChartArea.m_minY * scaley; | |
92 |
|
93 | |||
93 | if (scene()->width() > x && scene()->height() > y) { |
|
94 | if (scene()->width() > x && scene()->height() > y) { | |
94 | switch (shape) { |
|
95 | switch (shape) { | |
95 | case QScatterSeries::MarkerShapeDefault: |
|
96 | case QScatterSeries::MarkerShapeDefault: | |
96 | // Fallthrough, defaults to circle |
|
97 | // Fallthrough, defaults to circle | |
97 | case QScatterSeries::MarkerShapeCircle: |
|
98 | case QScatterSeries::MarkerShapeCircle: | |
98 | m_path.addEllipse(x, y, 9, 9); |
|
99 | m_path.addEllipse(x, y, 9, 9); | |
99 | break; |
|
100 | break; | |
100 | case QScatterSeries::MarkerShapePoint: |
|
101 | case QScatterSeries::MarkerShapePoint: | |
101 | m_path.addEllipse(x, y, 2, 2); |
|
102 | m_path.addEllipse(x, y, 2, 2); | |
102 | break; |
|
103 | break; | |
103 | case QScatterSeries::MarkerShapeRectangle: |
|
104 | case QScatterSeries::MarkerShapeRectangle: | |
104 | m_path.addRect(x, y, 9, 9); |
|
105 | m_path.addRect(x, y, 9, 9); | |
105 | break; |
|
106 | break; | |
106 | case QScatterSeries::MarkerShapeTiltedRectangle: { |
|
107 | case QScatterSeries::MarkerShapeTiltedRectangle: { | |
107 | // TODO: |
|
108 | // TODO: tilt the rectangle | |
108 | // static const QPointF points[4] = { |
|
109 | m_path.addRect(x, y, 9, 9); | |
109 | // QPointF(-1.0 + x, 0.0 + y), |
|
|||
110 | // QPointF(0.0 + x, 1.0 + y), |
|
|||
111 | // QPointF(1.0 + x, 0.0 + y), |
|
|||
112 | // QPointF(0.0 + x, -1.0 + y) |
|
|||
113 | // }; |
|
|||
114 | //m_path.addPolygon(QPolygon(4, &points)); |
|
|||
115 | break; |
|
110 | break; | |
116 | } |
|
111 | } | |
117 | default: |
|
112 | default: | |
118 | // TODO: implement the rest of the shapes |
|
113 | // TODO: implement the rest of the shapes | |
119 | Q_ASSERT(false); |
|
114 | Q_ASSERT(false); | |
120 | break; |
|
115 | break; | |
121 | } |
|
116 | } | |
122 | } |
|
117 | } | |
123 | } |
|
118 | } | |
124 | } |
|
119 | } | |
125 | } |
|
120 | } | |
126 |
|
121 | |||
127 | #include "moc_scatterpresenter_p.cpp" |
|
122 | #include "moc_scatterpresenter_p.cpp" | |
128 |
|
123 | |||
129 | QTCOMMERCIALCHART_END_NAMESPACE |
|
124 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now