1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
@@ -0,0 +1,41 | |||||
|
1 | /*! | |||
|
2 | \example examples/legendmarkers | |||
|
3 | \title LegendMarkers Example | |||
|
4 | \subtitle | |||
|
5 | ||||
|
6 | The example shows how to make use of legend markers. In this example we create an application which uses QLegendMarker clicked signal to show/hide corresponding series | |||
|
7 | in chart. | |||
|
8 | ||||
|
9 | \image examples_legendmarkers.png | |||
|
10 | ||||
|
11 | Our application has buttons for adding or removing series in chart and button to connect or disconnect legend markers clicked signal to our handler. In the image above, | |||
|
12 | we have connected the markers and clicked on one of them. | |||
|
13 | ||||
|
14 | \snippet ../examples/legendmarkers/mainwidget.cpp 1 | |||
|
15 | ||||
|
16 | Here we connect the markers in legend to our handler. To avoid conncecting same marker more than once, we first disconnect it. | |||
|
17 | ||||
|
18 | \snippet ../examples/legendmarkers/mainwidget.cpp 2 | |||
|
19 | ||||
|
20 | Here we disconnect all markers from our handler. | |||
|
21 | ||||
|
22 | \snippet ../examples/legendmarkers/mainwidget.cpp 3 | |||
|
23 | ||||
|
24 | In our handler we first cast the sender of event to QLegendMarker. | |||
|
25 | ||||
|
26 | \snippet ../examples/legendmarkers/mainwidget.cpp 4 | |||
|
27 | ||||
|
28 | Then we check the type of marker. This is needed if we want to access the detailed methods of the marker and cast it to correct type. | |||
|
29 | If all we need is the pointer to QAbstractSeries, the casting isn't necessary. In case of pie or bar series, we may need the pointer to related QPieSlice or QBarSet. | |||
|
30 | ||||
|
31 | \snippet ../examples/legendmarkers/mainwidget.cpp 5 | |||
|
32 | ||||
|
33 | We want to toggle the visibility of the series, when marker is clicked. To do so, we get the pointer to related series from marker and toggle its visibility. | |||
|
34 | Because the legend marker follows the visibility of the series by default, we also set the marked back to visible. If we don't do that, the marker will be | |||
|
35 | invisible in legend and we can't click on it anymore. | |||
|
36 | ||||
|
37 | \snippet ../examples/legendmarkers/mainwidget.cpp 6 | |||
|
38 | ||||
|
39 | Instead of making marker invisible when series is hidden, we dim the color of the marker. Here we do it by modifying the color of the laberBrush. | |||
|
40 | ||||
|
41 | */ |
@@ -116,9 +116,11 | |||||
116 |
|
116 | |||
117 | <tr> |
|
117 | <tr> | |
118 | <td><a href="examples-zoomlinechart.html">Zoom Line</a></td> |
|
118 | <td><a href="examples-zoomlinechart.html">Zoom Line</a></td> | |
|
119 | <td><a href="examples-legendmarkers.html">Legend Markers</a></td> | |||
119 | </tr> |
|
120 | </tr> | |
120 | <tr> |
|
121 | <tr> | |
121 | <td><a href="examples-zoomlinechart.html"><img src="images/examples_zoomlinechart1.png" width="300" alt="Zoom Line" /></a></td> |
|
122 | <td><a href="examples-zoomlinechart.html"><img src="images/examples_zoomlinechart1.png" width="300" alt="Zoom Line" /></a></td> | |
|
123 | <td><a href="examples-legendmarkers.html"><img src="images/examples_legendmarkers.png" width="300" alt="Legend Markers" /></a></td> | |||
122 | </tr> |
|
124 | </tr> | |
123 |
|
125 | |||
124 | </table> |
|
126 | </table> |
@@ -141,7 +141,6 void MainWidget::handleMarkerClicked() | |||||
141 | Q_ASSERT(marker); |
|
141 | Q_ASSERT(marker); | |
142 | //![3] |
|
142 | //![3] | |
143 |
|
143 | |||
144 |
|
||||
145 | //![4] |
|
144 | //![4] | |
146 | switch (marker->type()) |
|
145 | switch (marker->type()) | |
147 | //![4] |
|
146 | //![4] | |
@@ -159,8 +158,8 void MainWidget::handleMarkerClicked() | |||||
159 |
|
158 | |||
160 | //![6] |
|
159 | //![6] | |
161 | // Dim the marker, if series is not visible |
|
160 | // Dim the marker, if series is not visible | |
162 | QXYLegendMarker *xymarker = qobject_cast<QXYLegendMarker *> (marker); |
|
161 | QBrush labelBrush = marker->labelBrush(); | |
163 |
QColor color = |
|
162 | QColor color = labelBrush.color(); | |
164 |
|
163 | |||
165 | if (marker->series()->isVisible()) { |
|
164 | if (marker->series()->isVisible()) { | |
166 | color.setAlphaF(1.0); |
|
165 | color.setAlphaF(1.0); | |
@@ -168,7 +167,8 void MainWidget::handleMarkerClicked() | |||||
168 | color.setAlphaF(0.5); |
|
167 | color.setAlphaF(0.5); | |
169 | } |
|
168 | } | |
170 |
|
169 | |||
171 |
|
|
170 | labelBrush.setColor(color); | |
|
171 | marker->setLabelBrush(labelBrush); | |||
172 | //![6] |
|
172 | //![6] | |
173 | break; |
|
173 | break; | |
174 | } |
|
174 | } |
General Comments 0
You need to be logged in to leave comments.
Login now