@@ -10,6 +10,7 | |||||
10 | <li><a href="qml-chartview.html">ChartView</a></li> |
|
10 | <li><a href="qml-chartview.html">ChartView</a></li> | |
11 | <li><a href="qml-pieseries.html">PieSeries</a></li> |
|
11 | <li><a href="qml-pieseries.html">PieSeries</a></li> | |
12 | <li><a href="qml-axis.html">Axis</a></li> |
|
12 | <li><a href="qml-axis.html">Axis</a></li> | |
|
13 | <li><a href="qml-legend.html">Legend</a></li> | |||
13 | </ul> |
|
14 | </ul> | |
14 | \endraw |
|
15 | \endraw | |
15 | */ |
|
16 | */ |
@@ -60,10 +60,83 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
60 |
|
60 | |||
61 | \sa QChart |
|
61 | \sa QChart | |
62 | */ |
|
62 | */ | |
|
63 | /*! | |||
|
64 | \qmlclass Legend QLegend | |||
|
65 | \brief Legend is part of QtCommercial Chart QML API. | |||
|
66 | ||||
|
67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when | |||
|
68 | series have been changed. Legend is referenced via ChartView class. For example: | |||
|
69 | \code | |||
|
70 | ChartView { | |||
|
71 | legend.visible: true | |||
|
72 | legend.alignment: Qt.AlignBottom | |||
|
73 | // Add a few series... | |||
|
74 | } | |||
|
75 | \endcode | |||
|
76 | ||||
|
77 | \image examples_percentbarchart_legend.png | |||
|
78 | */ | |||
|
79 | ||||
|
80 | /*! | |||
|
81 | \property QLegend::alignment | |||
|
82 | \brief The alignment of the legend. | |||
|
83 | ||||
|
84 | Legend paints on the defined position in the chart. The following alignments are supported: | |||
|
85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. | |||
|
86 | */ | |||
|
87 | /*! | |||
|
88 | \qmlproperty Qt.Alignment Legend::alignment | |||
|
89 | \brief The alignment of the legend. | |||
|
90 | ||||
|
91 | Legend paints on the defined position in the chart. The following alignments are supported: | |||
|
92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. | |||
|
93 | */ | |||
|
94 | ||||
|
95 | /*! | |||
|
96 | \property QLegend::backgroundVisible | |||
|
97 | Whether the legend background is visible or not. | |||
|
98 | */ | |||
|
99 | /*! | |||
|
100 | \qmlproperty bool Legend::backgroundVisible | |||
|
101 | Whether the legend background is visible or not. | |||
|
102 | */ | |||
|
103 | ||||
|
104 | /*! | |||
|
105 | \property QLegend::color | |||
|
106 | The color of the legend, i.e. the background color. | |||
|
107 | */ | |||
|
108 | /*! | |||
|
109 | \qmlproperty color Legend::color | |||
|
110 | The color of the legend, i.e. the background color. | |||
|
111 | */ | |||
|
112 | ||||
|
113 | /*! | |||
|
114 | \property QLegend::borderColor | |||
|
115 | The border color of the legend, i.e. the line color. | |||
|
116 | */ | |||
|
117 | /*! | |||
|
118 | \qmlproperty color Legend::borderColor | |||
|
119 | The border color of the legend, i.e. the line color. | |||
|
120 | */ | |||
63 |
|
121 | |||
64 | /*! |
|
122 | /*! | |
65 | \fn void QLegend::alignmentChanged() |
|
123 | \fn void QLegend::alignmentChanged(Qt::Alignment) | |
66 | Emitted when the alignment of the legend changes. |
|
124 | Emitted when the \a alignment of the legend changes. | |
|
125 | */ | |||
|
126 | ||||
|
127 | /*! | |||
|
128 | \fn void QLegend::backgroundVisibleChanged(bool) | |||
|
129 | The visibility of the legend background changed to \a visible. | |||
|
130 | */ | |||
|
131 | ||||
|
132 | /*! | |||
|
133 | \fn void QLegend::colorChanged(QColor) | |||
|
134 | The color of the legend background changed to \a color. | |||
|
135 | */ | |||
|
136 | ||||
|
137 | /*! | |||
|
138 | \fn void QLegend::borderColorChanged(QColor) | |||
|
139 | The border color of the legend background changed to \a color. | |||
67 | */ |
|
140 | */ | |
68 |
|
141 | |||
69 | /*! |
|
142 | /*! | |
@@ -141,6 +214,21 QBrush QLegend::brush() const | |||||
141 | return d_ptr->m_brush; |
|
214 | return d_ptr->m_brush; | |
142 | } |
|
215 | } | |
143 |
|
216 | |||
|
217 | void QLegend::setColor(QColor color) | |||
|
218 | { | |||
|
219 | QBrush b = d_ptr->m_brush; | |||
|
220 | if (b.color() != color) { | |||
|
221 | b.setColor(color); | |||
|
222 | setBrush(b); | |||
|
223 | emit colorChanged(color); | |||
|
224 | } | |||
|
225 | } | |||
|
226 | ||||
|
227 | QColor QLegend::color() | |||
|
228 | { | |||
|
229 | return d_ptr->m_brush.color(); | |||
|
230 | } | |||
|
231 | ||||
144 | /*! |
|
232 | /*! | |
145 | Sets the \a pen of legend. Pen affects the legend borders. |
|
233 | Sets the \a pen of legend. Pen affects the legend borders. | |
146 | */ |
|
234 | */ | |
@@ -161,30 +249,30 QPen QLegend::pen() const | |||||
161 | return d_ptr->m_pen; |
|
249 | return d_ptr->m_pen; | |
162 | } |
|
250 | } | |
163 |
|
251 | |||
164 | /*! |
|
252 | void QLegend::setBorderColor(QColor color) | |
165 | \property QLegend::alignment |
|
253 | { | |
166 | \brief The alignment of the legend. |
|
254 | QPen p = d_ptr->m_pen; | |
167 | */ |
|
255 | if (p.color() != color) { | |
|
256 | p.setColor(color); | |||
|
257 | setPen(p); | |||
|
258 | emit borderColorChanged(color); | |||
|
259 | } | |||
|
260 | } | |||
168 |
|
261 | |||
169 | /*! |
|
262 | QColor QLegend::borderColor() | |
170 | Sets the \a alignment for legend. Legend paints on the defined position in chart. The following alignments are |
|
263 | { | |
171 | supported: Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result |
|
264 | return d_ptr->m_pen.color(); | |
172 | is undefined. |
|
265 | } | |
173 |
|
266 | |||
174 | \sa QLegend::Alignment |
|
|||
175 | */ |
|
|||
176 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
267 | void QLegend::setAlignment(Qt::Alignment alignment) | |
177 | { |
|
268 | { | |
178 | if(d_ptr->m_alignment!=alignment) { |
|
269 | if(d_ptr->m_alignment!=alignment) { | |
179 | d_ptr->m_alignment = alignment; |
|
270 | d_ptr->m_alignment = alignment; | |
180 | d_ptr->updateLayout(); |
|
271 | d_ptr->updateLayout(); | |
181 | alignmentChanged(); |
|
272 | alignmentChanged(alignment); | |
182 | } |
|
273 | } | |
183 | } |
|
274 | } | |
184 |
|
275 | |||
185 | /*! |
|
|||
186 | Returns the preferred layout for legend |
|
|||
187 | */ |
|
|||
188 | Qt::Alignment QLegend::alignment() const |
|
276 | Qt::Alignment QLegend::alignment() const | |
189 | { |
|
277 | { | |
190 | return d_ptr->m_alignment; |
|
278 | return d_ptr->m_alignment; | |
@@ -235,10 +323,10 QPointF QLegend::offset() const | |||||
235 | */ |
|
323 | */ | |
236 | void QLegend::setBackgroundVisible(bool visible) |
|
324 | void QLegend::setBackgroundVisible(bool visible) | |
237 | { |
|
325 | { | |
238 | if(d_ptr->m_backgroundVisible!=visible) |
|
326 | if(d_ptr->m_backgroundVisible != visible) { | |
239 | { |
|
327 | d_ptr->m_backgroundVisible = visible; | |
240 | d_ptr->m_backgroundVisible=visible; |
|
|||
241 | update(); |
|
328 | update(); | |
|
329 | emit backgroundVisibleChanged(visible); | |||
242 | } |
|
330 | } | |
243 | } |
|
331 | } | |
244 |
|
332 |
@@ -44,6 +44,9 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget | |||||
44 | { |
|
44 | { | |
45 | Q_OBJECT |
|
45 | Q_OBJECT | |
46 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) |
|
46 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) | |
|
47 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) | |||
|
48 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) | |||
|
49 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) | |||
47 |
|
50 | |||
48 | private: |
|
51 | private: | |
49 | explicit QLegend(QChart *chart); |
|
52 | explicit QLegend(QChart *chart); | |
@@ -56,9 +59,13 public: | |||||
56 |
|
59 | |||
57 | void setBrush(const QBrush &brush); |
|
60 | void setBrush(const QBrush &brush); | |
58 | QBrush brush() const; |
|
61 | QBrush brush() const; | |
|
62 | void setColor(QColor color); | |||
|
63 | QColor color(); | |||
59 |
|
64 | |||
60 | void setPen(const QPen &pen); |
|
65 | void setPen(const QPen &pen); | |
61 | QPen pen() const; |
|
66 | QPen pen() const; | |
|
67 | void setBorderColor(QColor color); | |||
|
68 | QColor borderColor(); | |||
62 |
|
69 | |||
63 | void setAlignment(Qt::Alignment alignment); |
|
70 | void setAlignment(Qt::Alignment alignment); | |
64 | Qt::Alignment alignment() const; |
|
71 | Qt::Alignment alignment() const; | |
@@ -82,11 +89,14 protected: | |||||
82 | void showEvent(QShowEvent *event); |
|
89 | void showEvent(QShowEvent *event); | |
83 |
|
90 | |||
84 | Q_SIGNALS: |
|
91 | Q_SIGNALS: | |
85 | void alignmentChanged(); |
|
92 | void alignmentChanged(Qt::Alignment alignment); | |
|
93 | void backgroundVisibleChanged(bool visible); | |||
|
94 | void colorChanged(QColor color); | |||
|
95 | void borderColorChanged(QColor color); | |||
86 |
|
96 | |||
87 | private: |
|
97 | private: | |
88 | QScopedPointer<QLegendPrivate> d_ptr; |
|
98 | QScopedPointer<QLegendPrivate> d_ptr; | |
89 |
Q_DISABLE_COPY(QLegend) |
|
99 | Q_DISABLE_COPY(QLegend) | |
90 | friend class LegendScroller; |
|
100 | friend class LegendScroller; | |
91 | }; |
|
101 | }; | |
92 |
|
102 |
@@ -48,8 +48,11 Flow { | |||||
48 | Connections { |
|
48 | Connections { | |
49 | id: legendConnections |
|
49 | id: legendConnections | |
50 | ignoreUnknownSignals: true |
|
50 | ignoreUnknownSignals: true | |
51 |
onAlignmentChanged: console.log("legend.onAlignmentChanged: " + |
|
51 | onAlignmentChanged: console.log("legend.onAlignmentChanged: " + alignment); | |
52 | onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible); |
|
52 | onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible); | |
|
53 | onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); | |||
|
54 | onColorChanged: console.log("legend.onColorChanged: " + color); | |||
|
55 | onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); | |||
53 | } |
|
56 | } | |
54 |
|
57 | |||
55 | Connections { |
|
58 | Connections { | |
@@ -113,6 +116,22 Flow { | |||||
113 | onClicked: series.backgroundColor = main.nextColor(); |
|
116 | onClicked: series.backgroundColor = main.nextColor(); | |
114 | } |
|
117 | } | |
115 | Button { |
|
118 | Button { | |
|
119 | text: "legend visible" | |||
|
120 | onClicked: series.legend.visible = !series.legend.visible; | |||
|
121 | } | |||
|
122 | Button { | |||
|
123 | text: "legend bckgrd visible" | |||
|
124 | onClicked: series.legend.backgroundVisible = !series.legend.backgroundVisible; | |||
|
125 | } | |||
|
126 | Button { | |||
|
127 | text: "legend color" | |||
|
128 | onClicked: series.legend.color = main.nextColor(); | |||
|
129 | } | |||
|
130 | Button { | |||
|
131 | text: "legend border color" | |||
|
132 | onClicked: series.legend.borderColor = main.nextColor(); | |||
|
133 | } | |||
|
134 | Button { | |||
116 | text: "legend top" |
|
135 | text: "legend top" | |
117 | onClicked: series.legend.alignment ^= Qt.AlignTop; |
|
136 | onClicked: series.legend.alignment ^= Qt.AlignTop; | |
118 | } |
|
137 | } | |
@@ -129,10 +148,6 Flow { | |||||
129 | onClicked: series.legend.alignment ^= Qt.AlignRight; |
|
148 | onClicked: series.legend.alignment ^= Qt.AlignRight; | |
130 | } |
|
149 | } | |
131 | Button { |
|
150 | Button { | |
132 | text: "legend visible" |
|
|||
133 | onClicked: series.legend.visible = !series.legend.visible; |
|
|||
134 | } |
|
|||
135 | Button { |
|
|||
136 | text: "axis X nice nmb" |
|
151 | text: "axis X nice nmb" | |
137 | onClicked: series.axisX.niceNumbersEnabled = !series.axisX.niceNumbersEnabled; |
|
152 | onClicked: series.axisX.niceNumbersEnabled = !series.axisX.niceNumbersEnabled; | |
138 | } |
|
153 | } |
General Comments 0
You need to be logged in to leave comments.
Login now