summaryrefslogtreecommitdiffstats
path: root/src/charts/doc/src/examples-legendmarkers.qdoc
blob: 7b49988ff2f7de80a29a8786b57e7d41f590b4b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd
** All rights reserved.
** For any questions to The Qt Company, please use contact form at http://qt.io
**
** This file is part of the Qt Charts module.
**
** Licensees holding valid commercial license for Qt may use this file in
** accordance with the Qt License Agreement provided with the Software
** or, alternatively, in accordance with the terms contained in a written
** agreement between you and The Qt Company.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.io
**
****************************************************************************/

/*!
    \example legendmarkers
    \title LegendMarkers Example
    \ingroup qtcharts_examples

    \brief The example shows how to make use of legend markers.

    In this example we create an application which uses the QLegendMarker clicked signal to show/hide the corresponding series
    in a chart. The connect marker button connects a clicked signal from all markers in a legend to the handleMarkerClicked slot.

    \image examples_legendmarkers.png

    Our application has buttons for adding or removing a series in a chart and a button to connect or disconnect the legend markers clicked signal to our handler.
    In the image above we have connected the markers and clicked on one of them.

    \snippet legendmarkers/mainwidget.cpp 1

    Here we connect the markers in the legend to our handler. To avoid connecting the same marker more than once, we first disconnect it.

    \snippet legendmarkers/mainwidget.cpp 2

    Here we disconnect all markers from our handler.

    \snippet legendmarkers/mainwidget.cpp 3

    In our handler we first cast the sender of the event to the QLegendMarker.

    \snippet legendmarkers/mainwidget.cpp 4

    Then we check the type of the marker. This is required if we want to access the detailed methods of the marker and cast it to the correct type.
    If all we need is the pointer to QAbstractSeries, the casting isn't necessary. In case of a pie or bar series, we may need the pointer to a related QPieSlice or QBarSet.

    \snippet legendmarkers/mainwidget.cpp 5

    We want to toggle the visibility of the series, when the marker is clicked. To do so, we get the pointer to a related series from the marker and toggle its visibility.
    Since the legend marker follows the visibility of the series by default, we also set the marked back to visible. If we don't do so, the marker will be
    invisible in the legend and we can't click on it anymore.

    \snippet legendmarkers/mainwidget.cpp 6

    Instead of making the marker invisible when the series is hidden, we dim the color of the marker. Here we do it by modifying the color of the laberBrush.

*/