@@ -10,87 +10,87 | |||
|
10 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | 11 | |
|
12 | 12 | LegendMarker::LegendMarker(QSeries *series, QGraphicsItem *parent) : QGraphicsObject(parent), |
|
13 |
m |
|
|
14 |
m |
|
|
15 |
m |
|
|
16 |
m |
|
|
17 |
m |
|
|
18 |
m |
|
|
19 |
m |
|
|
20 |
m |
|
|
21 |
m |
|
|
13 | m_pos(0,0), | |
|
14 | m_size(0,0), | |
|
15 | m_boundingRect(0,0,0,0), | |
|
16 | m_markerBoundingRect(0,0,0,0), | |
|
17 | m_series(series), | |
|
18 | m_barset(0), | |
|
19 | m_pieslice(0), | |
|
20 | m_type(LegendMarkerTypeSeries), | |
|
21 | m_textItem(new QGraphicsSimpleTextItem(this)) | |
|
22 | 22 | { |
|
23 | 23 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
24 | 24 | } |
|
25 | 25 | |
|
26 | 26 | LegendMarker::LegendMarker(QSeries *series, QBarSet *barset, QGraphicsItem *parent) : QGraphicsObject(parent), |
|
27 |
m |
|
|
28 |
m |
|
|
29 |
m |
|
|
30 |
m |
|
|
31 |
m |
|
|
32 |
m |
|
|
33 |
m |
|
|
34 |
m |
|
|
35 |
m |
|
|
27 | m_pos(0,0), | |
|
28 | m_size(0,0), | |
|
29 | m_boundingRect(0,0,0,0), | |
|
30 | m_markerBoundingRect(0,0,0,0), | |
|
31 | m_series(series), | |
|
32 | m_barset(barset), | |
|
33 | m_pieslice(0), | |
|
34 | m_type(LegendMarkerTypeBarset), | |
|
35 | m_textItem(new QGraphicsSimpleTextItem(this)) | |
|
36 | 36 | { |
|
37 | 37 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | LegendMarker::LegendMarker(QSeries *series, QPieSlice *pieslice, QGraphicsItem *parent) : QGraphicsObject(parent), |
|
41 |
m |
|
|
42 |
m |
|
|
43 |
m |
|
|
44 |
m |
|
|
45 |
m |
|
|
46 |
m |
|
|
47 |
m |
|
|
48 |
m |
|
|
49 |
m |
|
|
41 | m_pos(0,0), | |
|
42 | m_size(0,0), | |
|
43 | m_boundingRect(0,0,0,0), | |
|
44 | m_markerBoundingRect(0,0,0,0), | |
|
45 | m_series(series), | |
|
46 | m_barset(0), | |
|
47 | m_pieslice(pieslice), | |
|
48 | m_type(LegendMarkerTypePieslice), | |
|
49 | m_textItem(new QGraphicsSimpleTextItem(this)) | |
|
50 | 50 | { |
|
51 | 51 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
52 | 52 | } |
|
53 | 53 | |
|
54 | 54 | void LegendMarker::setPos(qreal x, qreal y) |
|
55 | 55 | { |
|
56 |
m |
|
|
56 | m_pos = QPointF(x,y); | |
|
57 | 57 | layoutChanged(); |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | void LegendMarker::setPen(const QPen &pen) |
|
61 | 61 | { |
|
62 |
m |
|
|
62 | m_pen = pen; | |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | QPen LegendMarker::pen() const |
|
66 | 66 | { |
|
67 |
return m |
|
|
67 | return m_pen; | |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | void LegendMarker::setBrush(const QBrush &brush) |
|
71 | 71 | { |
|
72 |
m |
|
|
72 | m_brush = brush; | |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | QBrush LegendMarker::brush() const |
|
76 | 76 | { |
|
77 |
return m |
|
|
77 | return m_brush; | |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | void LegendMarker::setName(const QString name) |
|
81 | 81 | { |
|
82 |
m |
|
|
82 | m_textItem->setText(name); | |
|
83 | 83 | layoutChanged(); |
|
84 | 84 | } |
|
85 | 85 | |
|
86 | 86 | QString LegendMarker::name() const |
|
87 | 87 | { |
|
88 |
return m |
|
|
88 | return m_textItem->text(); | |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | QSeries* LegendMarker::series() const |
|
92 | 92 | { |
|
93 |
return m |
|
|
93 | return m_series; | |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
@@ -98,14 +98,14 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti | |||
|
98 | 98 | Q_UNUSED(option) |
|
99 | 99 | Q_UNUSED(widget) |
|
100 | 100 | |
|
101 |
painter->setPen(m |
|
|
102 |
painter->setBrush(m |
|
|
103 |
painter->drawRect(m |
|
|
101 | painter->setPen(m_pen); | |
|
102 | painter->setBrush(m_brush); | |
|
103 | painter->drawRect(m_markerBoundingRect); | |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | QRectF LegendMarker::boundingRect() const |
|
107 | 107 | { |
|
108 |
return m |
|
|
108 | return m_boundingRect; | |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | void LegendMarker::layoutChanged() |
@@ -113,30 +113,30 void LegendMarker::layoutChanged() | |||
|
113 | 113 | QSizeF markerSize(10,10); |
|
114 | 114 | qreal margin = 2; |
|
115 | 115 | |
|
116 |
m |
|
|
117 |
m |
|
|
116 | m_size.setHeight(markerSize.height() + 2 * margin); | |
|
117 | m_size.setWidth(m_textItem->boundingRect().width() + markerSize.width() + 3 * margin); | |
|
118 | 118 | |
|
119 |
m |
|
|
119 | m_boundingRect = QRectF(m_pos.x(),m_pos.y(),m_size.width(),m_size.height()); | |
|
120 | 120 | |
|
121 |
m |
|
|
121 | m_markerBoundingRect = QRectF(m_pos.x() + margin, m_pos.y() + margin, markerSize.width(),markerSize.height()); | |
|
122 | 122 | |
|
123 |
m |
|
|
123 | m_textItem->setPos(m_pos.x() + markerSize.width() + 2 * margin, m_pos.y() + margin); | |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
127 | 127 | { |
|
128 |
switch (m |
|
|
128 | switch (m_type) | |
|
129 | 129 | { |
|
130 | 130 | case LegendMarkerTypeSeries: { |
|
131 |
emit clicked(m |
|
|
131 | emit clicked(m_series,event->button()); | |
|
132 | 132 | break; |
|
133 | 133 | } |
|
134 | 134 | case LegendMarkerTypeBarset: { |
|
135 |
emit clicked(m |
|
|
135 | emit clicked(m_barset,event->button()); | |
|
136 | 136 | break; |
|
137 | 137 | } |
|
138 | 138 | case LegendMarkerTypePieslice: { |
|
139 |
emit clicked(m |
|
|
139 | emit clicked(m_pieslice,event->button()); | |
|
140 | 140 | break; |
|
141 | 141 | } |
|
142 | 142 | default: { |
@@ -147,22 +147,22 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) | |||
|
147 | 147 | |
|
148 | 148 | void LegendMarker::changed() |
|
149 | 149 | { |
|
150 |
switch (m |
|
|
150 | switch (m_type) | |
|
151 | 151 | { |
|
152 | 152 | case LegendMarkerTypeSeries: { |
|
153 |
QXYSeries* s = static_cast<QXYSeries*> (m |
|
|
153 | QXYSeries* s = static_cast<QXYSeries*> (m_series); | |
|
154 | 154 | setBrush(s->brush()); |
|
155 | 155 | setName(s->name()); |
|
156 | 156 | break; |
|
157 | 157 | } |
|
158 | 158 | case LegendMarkerTypeBarset: { |
|
159 |
setBrush(m |
|
|
160 |
setName(m |
|
|
159 | setBrush(m_barset->brush()); | |
|
160 | setName(m_barset->name()); | |
|
161 | 161 | break; |
|
162 | 162 | } |
|
163 | 163 | case LegendMarkerTypePieslice: { |
|
164 |
setBrush(m |
|
|
165 |
setName(m |
|
|
164 | setBrush(m_pieslice->brush()); | |
|
165 | setName(m_pieslice->label()); | |
|
166 | 166 | break; |
|
167 | 167 | } |
|
168 | 168 | } |
@@ -61,19 +61,19 public Q_SLOTS: | |||
|
61 | 61 | void changed(); |
|
62 | 62 | |
|
63 | 63 | private: |
|
64 |
QPointF m |
|
|
65 |
QSize m |
|
|
66 |
QRectF m |
|
|
67 |
QRectF m |
|
|
68 |
QBrush m |
|
|
69 |
QPen m |
|
|
70 | ||
|
71 |
QSeries *m |
|
|
72 |
QBarSet *m |
|
|
73 |
QPieSlice *m |
|
|
74 | ||
|
75 |
LegendMarkerType m |
|
|
76 |
QGraphicsSimpleTextItem |
|
|
64 | QPointF m_pos; | |
|
65 | QSize m_size; | |
|
66 | QRectF m_boundingRect; | |
|
67 | QRectF m_markerBoundingRect; | |
|
68 | QBrush m_brush; | |
|
69 | QPen m_pen; | |
|
70 | ||
|
71 | QSeries *m_series; | |
|
72 | QBarSet *m_barset; | |
|
73 | QPieSlice *m_pieslice; | |
|
74 | ||
|
75 | LegendMarkerType m_type; | |
|
76 | QGraphicsSimpleTextItem *m_textItem; | |
|
77 | 77 | |
|
78 | 78 | }; |
|
79 | 79 |
@@ -5,14 +5,14 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
5 | 5 | |
|
6 | 6 | LegendScrollButton::LegendScrollButton(ScrollButtonId id, QGraphicsItem *parent) |
|
7 | 7 | : QGraphicsPolygonItem(parent) |
|
8 |
,m |
|
|
8 | ,m_id(id) | |
|
9 | 9 | { |
|
10 | 10 | setAcceptedMouseButtons(Qt::LeftButton); |
|
11 | 11 | } |
|
12 | 12 | |
|
13 | 13 | LegendScrollButton::ScrollButtonId LegendScrollButton::id() |
|
14 | 14 | { |
|
15 |
return m |
|
|
15 | return m_id; | |
|
16 | 16 | } |
|
17 | 17 | |
|
18 | 18 | void LegendScrollButton::mousePressEvent(QGraphicsSceneMouseEvent *event) |
General Comments 0
You need to be logged in to leave comments.
Login now