@@ -0,0 +1,63 | |||
|
1 | #include "qchartglobal.h" | |
|
2 | #include "legendmarker_p.h" | |
|
3 | #include <QPainter> | |
|
4 | #include <QGraphicsSceneEvent> | |
|
5 | ||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
7 | ||
|
8 | LegendMarker::LegendMarker(QSeries* series, QGraphicsItem *parent) | |
|
9 | : QGraphicsObject(parent) | |
|
10 | ,mSeries(series) | |
|
11 | ,mBoundingRect(0,0,1,1) | |
|
12 | { | |
|
13 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | |
|
14 | } | |
|
15 | ||
|
16 | void LegendMarker::setBoundingRect(const QRectF rect) | |
|
17 | { | |
|
18 | mBoundingRect = rect; | |
|
19 | } | |
|
20 | ||
|
21 | void LegendMarker::setBrush(const QBrush brush) | |
|
22 | { | |
|
23 | mBrush = brush; | |
|
24 | } | |
|
25 | ||
|
26 | void LegendMarker::setName(const QString name) | |
|
27 | { | |
|
28 | mName = name; | |
|
29 | } | |
|
30 | ||
|
31 | QString LegendMarker::name() const | |
|
32 | { | |
|
33 | return mName; | |
|
34 | } | |
|
35 | ||
|
36 | QColor LegendMarker::color() const | |
|
37 | { | |
|
38 | return mBrush.color(); | |
|
39 | } | |
|
40 | ||
|
41 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
42 | { | |
|
43 | painter->setBrush(mBrush); | |
|
44 | painter->drawRect(mBoundingRect); | |
|
45 | } | |
|
46 | ||
|
47 | QRectF LegendMarker::boundingRect() const | |
|
48 | { | |
|
49 | return mBoundingRect; | |
|
50 | } | |
|
51 | ||
|
52 | void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
|
53 | { | |
|
54 | if (event->button() == Qt::LeftButton) { | |
|
55 | emit clicked(mSeries, mName); | |
|
56 | } else if (event->button() == Qt::RightButton) { | |
|
57 | emit rightClicked(mSeries, mName); | |
|
58 | } | |
|
59 | } | |
|
60 | ||
|
61 | #include "moc_legendmarker_p.cpp" | |
|
62 | ||
|
63 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,44 | |||
|
1 | #ifndef LEGENDMARKER_P_H | |
|
2 | #define LEGENDMARKER_P_H | |
|
3 | ||
|
4 | #include "qchartglobal.h" | |
|
5 | #include <QGraphicsObject> | |
|
6 | #include <QBrush> | |
|
7 | ||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
9 | ||
|
10 | class QSeries; | |
|
11 | ||
|
12 | ||
|
13 | class LegendMarker : public QGraphicsObject | |
|
14 | { | |
|
15 | Q_OBJECT | |
|
16 | public: | |
|
17 | LegendMarker(QSeries* series, QGraphicsItem *parent = 0); | |
|
18 | void setBoundingRect(const QRectF rect); | |
|
19 | void setBrush(const QBrush brush); | |
|
20 | void setName(const QString name); | |
|
21 | QString name() const; | |
|
22 | QColor color() const; | |
|
23 | ||
|
24 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
|
25 | ||
|
26 | QRectF boundingRect() const; | |
|
27 | ||
|
28 | public: | |
|
29 | // From QGraphicsObject | |
|
30 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
|
31 | ||
|
32 | Q_SIGNALS: | |
|
33 | void clicked(QSeries* series, QString name); | |
|
34 | void rightClicked(QSeries* series, QString name); | |
|
35 | ||
|
36 | private: | |
|
37 | QRectF mBoundingRect; | |
|
38 | QBrush mBrush; | |
|
39 | QString mName; | |
|
40 | QSeries* mSeries; | |
|
41 | }; | |
|
42 | ||
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
44 | #endif // LEGENDMARKER_P_H |
|
1 | NO CONTENT: modified file |
@@ -1,140 +1,119 | |||
|
1 | 1 | #include "qchartglobal.h" |
|
2 | 2 | #include "qlegend.h" |
|
3 | 3 | #include "qseries.h" |
|
4 | #include "legendmarker_p.h" | |
|
4 | 5 | #include <QPainter> |
|
5 | 6 | #include <QPen> |
|
6 | 7 | |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
8 | ||
|
9 | // TODO: this to legendmarker_p.h header | |
|
10 | class LegendMarker : public QGraphicsItem | |
|
11 | { | |
|
12 | public: | |
|
13 | LegendMarker(QGraphicsItem *parent = 0) : QGraphicsItem(parent) | |
|
14 | ,mBoundingRect(0,0,1,1) | |
|
15 | {} | |
|
16 | ||
|
17 | void setBoundingRect(const QRectF rect) { mBoundingRect = rect; } | |
|
18 | void setBrush(const QBrush brush) { mBrush = brush; } | |
|
19 | void setName(const QString name) { mName = name; } | |
|
20 | QString name() const { return mName; } | |
|
21 | QColor color() const { return mBrush.color(); } | |
|
8 | #include <QGraphicsSceneEvent> | |
|
22 | 9 | |
|
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) | |
|
24 | { | |
|
25 | painter->setBrush(mBrush); | |
|
26 | painter->drawRect(mBoundingRect); | |
|
27 | } | |
|
28 | ||
|
29 | QRectF boundingRect() const { return mBoundingRect; } | |
|
30 | ||
|
31 | private: | |
|
32 | QRectF mBoundingRect; | |
|
33 | QBrush mBrush; | |
|
34 | QString mName; | |
|
35 | }; | |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
36 | 11 | |
|
37 | 12 | QLegend::QLegend(QGraphicsItem *parent) |
|
38 | 13 | : QGraphicsObject(parent) |
|
39 | 14 | ,mBoundingRect(0,0,1,1) |
|
40 | 15 | ,mBackgroundBrush(Qt::darkGray) // TODO: from theme? |
|
41 | 16 | { |
|
42 | 17 | } |
|
43 | 18 | |
|
44 | 19 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
45 | 20 | { |
|
46 | 21 | painter->setBrush(mBackgroundBrush); |
|
47 | 22 | painter->drawRect(mBoundingRect); |
|
48 | 23 | |
|
49 | 24 | foreach(LegendMarker* m, mMarkers) { |
|
50 | 25 | QRectF r = m->boundingRect(); |
|
51 | 26 | painter->setPen(m->color()); |
|
52 |
painter->drawText(r.x() + 2 |
|
|
27 | painter->drawText(r.x() + r.width()*2, r.y() + r.height(), m->name()); | |
|
53 | 28 | } |
|
54 | 29 | } |
|
55 | 30 | |
|
56 | 31 | QRectF QLegend::boundingRect() const |
|
57 | 32 | { |
|
58 | 33 | return mBoundingRect; |
|
59 | 34 | } |
|
60 | 35 | |
|
61 | 36 | void QLegend::setBackgroundBrush(const QBrush& brush) |
|
62 | 37 | { |
|
63 | 38 | mBackgroundBrush = brush; |
|
64 | 39 | } |
|
65 | 40 | |
|
66 | 41 | QBrush QLegend::backgroundBrush() const |
|
67 | 42 | { |
|
68 | 43 | return mBackgroundBrush; |
|
69 | 44 | } |
|
70 | 45 | |
|
71 | 46 | void QLegend::handleSeriesAdded(QSeries* series,Domain* domain) |
|
72 | 47 | { |
|
73 | 48 | mSeriesList.append(series); |
|
74 | 49 | dataChanged(); |
|
75 | 50 | layoutChanged(); |
|
76 | 51 | } |
|
77 | 52 | |
|
78 | 53 | void QLegend::handleSeriesRemoved(QSeries* series) |
|
79 | 54 | { |
|
80 | 55 | mSeriesList.removeOne(series); |
|
81 | 56 | dataChanged(); |
|
82 | 57 | layoutChanged(); |
|
83 | 58 | } |
|
84 | 59 | |
|
85 | 60 | void QLegend::handleGeometryChanged(const QRectF& size) |
|
86 | 61 | { |
|
87 | 62 | mBoundingRect = size; |
|
88 | 63 | layoutChanged(); |
|
89 | 64 | } |
|
90 | 65 | |
|
91 | 66 | void QLegend::dataChanged() |
|
92 | 67 | { |
|
93 | foreach (QGraphicsItem* i, childItems()) { | |
|
94 | delete i; | |
|
68 | foreach (LegendMarker* marker, mMarkers) { | |
|
69 | disconnect(marker,SIGNAL(clicked(QSeries*,QString)),this,SIGNAL(clicked(QSeries*,QString))); | |
|
70 | disconnect(marker,SIGNAL(rightClicked(QSeries*,QString)),this,SIGNAL(rightClicked(QSeries*,QString))); | |
|
71 | delete marker; | |
|
95 | 72 | } |
|
96 | 73 | |
|
97 | 74 | mMarkers.clear(); |
|
98 | 75 | |
|
99 | 76 | foreach (QSeries* s, mSeriesList) { |
|
100 | 77 | for (int i=0; i<s->legendEntries().count(); i++) { |
|
101 | LegendMarker *marker = new LegendMarker(this); | |
|
78 | LegendMarker *marker = new LegendMarker(s, this); | |
|
102 | 79 | marker->setBrush(s->legendEntries().at(i).mBrush); |
|
103 | 80 | marker->setName(s->legendEntries().at(i).mName); |
|
104 | 81 | mMarkers.append(marker); |
|
105 |
|
|
|
82 | childItems().append(marker); | |
|
83 | connect(marker,SIGNAL(clicked(QSeries*,QString)),this,SIGNAL(clicked(QSeries*,QString))); | |
|
84 | connect(marker,SIGNAL(rightClicked(QSeries*,QString)),this,SIGNAL(rightClicked(QSeries*,QString))); | |
|
106 | 85 | } |
|
107 | 86 | } |
|
108 | 87 | } |
|
109 | 88 | |
|
110 | 89 | void QLegend::layoutChanged() |
|
111 | 90 | { |
|
112 | 91 | // Calculate layout for markers and text |
|
113 | 92 | if (mMarkers.count() <= 0) { |
|
114 | 93 | // Nothing to do |
|
115 | 94 | return; |
|
116 | 95 | } |
|
117 | 96 | |
|
118 | 97 | // TODO: marker defined by series. |
|
119 | 98 | QSizeF markerSize(10,10); |
|
120 | 99 | |
|
121 | 100 | // TODO: better layout, this is just concept. |
|
122 | 101 | // Leave some space around markers like this: | x x x x | |
|
123 | 102 | qreal steps = mMarkers.count(); |
|
124 | 103 | |
|
125 | 104 | qreal xStep = mBoundingRect.width() / steps; |
|
126 | 105 | qreal yStep = mBoundingRect.height() / steps; |
|
127 | 106 | qreal x = mBoundingRect.x() + 5; |
|
128 | 107 | qreal y = mBoundingRect.y() + (mBoundingRect.height() - markerSize.height())/2; |
|
129 | 108 | foreach (LegendMarker* m, mMarkers) { |
|
130 | 109 | qDebug() << "marker x:" << x; |
|
131 | 110 | qDebug() << "marker y:" << y; |
|
132 | 111 | m->setBoundingRect(QRectF(x,y,markerSize.width(),markerSize.height())); |
|
133 | 112 | x += xStep; |
|
134 | 113 | } |
|
135 | 114 | } |
|
136 | 115 | |
|
137 | 116 | |
|
138 | 117 | |
|
139 | 118 | #include "moc_qlegend.cpp" |
|
140 | 119 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,49 | |||
|
1 | 1 | #ifndef QLEGEND_H |
|
2 | 2 | #define QLEGEND_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "qseries.h" |
|
6 | 6 | #include <QGraphicsObject> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | class Domain; |
|
11 | 11 | class LegendMarker; |
|
12 | 12 | |
|
13 | 13 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsObject |
|
14 | 14 | { |
|
15 | 15 | Q_OBJECT |
|
16 | 16 | public: |
|
17 | 17 | |
|
18 | 18 | explicit QLegend(QGraphicsItem *parent = 0); |
|
19 | 19 | |
|
20 | 20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
21 | 21 | QRectF boundingRect() const; |
|
22 | 22 | |
|
23 | 23 | void setBackgroundBrush(const QBrush& brush); |
|
24 | 24 | QBrush backgroundBrush() const; |
|
25 | 25 | |
|
26 | 26 | signals: |
|
27 | // for interactions. | |
|
28 | void clicked(QSeries* series, QString name); | |
|
29 | void rightClicked(QSeries* series, QString name); | |
|
27 | 30 | |
|
28 | 31 | public slots: |
|
29 | 32 | void handleSeriesAdded(QSeries* series,Domain* domain); |
|
30 | 33 | void handleSeriesRemoved(QSeries* series); |
|
31 | 34 | void handleGeometryChanged(const QRectF& size); |
|
32 | 35 | |
|
33 | 36 | private: |
|
34 | 37 | void dataChanged(); |
|
35 | 38 | void layoutChanged(); |
|
36 | 39 | |
|
37 | 40 | QRectF mBoundingRect; |
|
38 | 41 | QList<QSeries*> mSeriesList; |
|
39 | 42 | QList<LegendMarker*> mMarkers; |
|
40 | 43 | |
|
41 | 44 | QBrush mBackgroundBrush; |
|
42 | 45 | }; |
|
43 | 46 | |
|
44 | 47 | QTCOMMERCIALCHART_END_NAMESPACE |
|
45 | 48 | |
|
46 | 49 | #endif // QLEGEND_H |
@@ -1,96 +1,98 | |||
|
1 | 1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) |
|
2 | 2 | TARGET = QtCommercialChart |
|
3 | 3 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
4 | 4 | TEMPLATE = lib |
|
5 | 5 | QT += core \ |
|
6 | 6 | gui |
|
7 | 7 | CONFIG += debug_and_release |
|
8 | 8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
9 | 9 | SOURCES += \ |
|
10 | 10 | chartdataset.cpp \ |
|
11 | 11 | chartpresenter.cpp \ |
|
12 | 12 | charttheme.cpp \ |
|
13 | 13 | domain.cpp \ |
|
14 | 14 | qchart.cpp \ |
|
15 | 15 | qchartview.cpp \ |
|
16 | 16 | qseries.cpp \ |
|
17 | qlegend.cpp | |
|
17 | qlegend.cpp \ | |
|
18 | legendmarker.cpp | |
|
18 | 19 | PRIVATE_HEADERS += \ |
|
19 | 20 | chartdataset_p.h \ |
|
20 | 21 | chartitem_p.h \ |
|
21 | 22 | chartpresenter_p.h \ |
|
22 | 23 | charttheme_p.h \ |
|
23 | domain_p.h | |
|
24 | domain_p.h \ | |
|
25 | legendmarker_p.h | |
|
24 | 26 |
PUBLIC_HEADERS += \ |
|
25 | 27 | qchart.h \ |
|
26 | 28 | qchartglobal.h \ |
|
27 | 29 | qseries.h \ |
|
28 | 30 | qchartview.h \ |
|
29 | 31 | qlegend.h |
|
30 | 32 | |
|
31 | 33 | include(animations/animations.pri) |
|
32 | 34 | include(axis/axis.pri) |
|
33 | 35 | include(xychart/xychart.pri) |
|
34 | 36 | include(linechart/linechart.pri) |
|
35 | 37 | include(areachart/areachart.pri) |
|
36 | 38 | include(barchart/barchart.pri) |
|
37 | 39 | include(piechart/piechart.pri) |
|
38 | 40 | include(scatterseries/scatter.pri) |
|
39 | 41 | include(splinechart/splinechart.pri) |
|
40 | 42 | |
|
41 | 43 | THEMES += themes/chartthemedefault_p.h \ |
|
42 | 44 | themes/chartthemeicy_p.h \ |
|
43 | 45 | themes/chartthemegrayscale_p.h \ |
|
44 | 46 | themes/chartthemescientific_p.h \ |
|
45 | 47 | themes/chartthemevanilla_p.h |
|
46 | 48 | HEADERS += $$PUBLIC_HEADERS |
|
47 | 49 | HEADERS += $$PRIVATE_HEADERS |
|
48 | 50 | HEADERS += $$THEMES |
|
49 | 51 | INCLUDEPATH += linechart \ |
|
50 | 52 | barchart \ |
|
51 | 53 | themes \ |
|
52 | 54 | . |
|
53 | 55 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
54 | 56 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
55 | 57 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
56 | 58 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
57 | 59 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
58 | 60 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
59 | 61 | public_headers.files = $$PUBLIC_HEADERS |
|
60 | 62 | target.path = $$[QT_INSTALL_LIBS] |
|
61 | 63 | INSTALLS += target \ |
|
62 | 64 | public_headers |
|
63 | 65 | install_build_public_headers.name = bild_public_headers |
|
64 | 66 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
65 | 67 | install_build_public_headers.input = PUBLIC_HEADERS |
|
66 | 68 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
67 | 69 | ${QMAKE_FILE_NAME} \ |
|
68 | 70 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
69 | 71 | install_build_public_headers.CONFIG += target_predeps \ |
|
70 | 72 | no_link |
|
71 | 73 | install_build_private_headers.name = bild_private_headers |
|
72 | 74 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
73 | 75 | install_build_private_headers.input = PRIVATE_HEADERS |
|
74 | 76 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
75 | 77 | ${QMAKE_FILE_NAME} \ |
|
76 | 78 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
77 | 79 | install_build_private_headers.CONFIG += target_predeps \ |
|
78 | 80 | no_link |
|
79 | 81 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ |
|
80 | 82 | install_build_private_headers |
|
81 | 83 | chartversion.target = qchartversion_p.h |
|
82 | 84 | chartversion.commands = @echo \ |
|
83 | 85 | "build_time" \ |
|
84 | 86 | > \ |
|
85 | 87 | $$chartversion.target; |
|
86 | 88 | chartversion.depends = $$HEADERS \ |
|
87 | 89 | $$SOURCES |
|
88 | 90 | PRE_TARGETDEPS += qchartversion_p.h |
|
89 | 91 | QMAKE_CLEAN += qchartversion_p.h |
|
90 | 92 | QMAKE_EXTRA_TARGETS += chartversion |
|
91 | 93 | unix:QMAKE_DISTCLEAN += -r \ |
|
92 | 94 | $$CHART_BUILD_HEADER_DIR \ |
|
93 | 95 | $$CHART_BUILD_LIB_DIR |
|
94 | 96 | win32:QMAKE_DISTCLEAN += /Q \ |
|
95 | 97 | $$CHART_BUILD_HEADER_DIR \ |
|
96 | 98 | $$CHART_BUILD_LIB_DIR |
General Comments 0
You need to be logged in to leave comments.
Login now