10import QtQuick.Controls
12import org.kde.quickcharts as Charts
13import org.kde.quickcharts.controls
24 property Charts.Chart chart
30 property alias delegate: legendRepeater.delegate
34 property alias model: legendRepeater.model
36 property alias horizontalSpacing: legend.horizontalSpacing
37 property alias verticalSpacing: legend.verticalSpacing
39 property real maximumDelegateWidth: Theme.gridUnit * 10
41 property var formatValue: function(input, index) { return input }
42 property var maximumValueWidth: function(input, index) { return -1 }
44 property alias preferredWidth: legend.preferredWidth
46 property string nameRole: "name"
47 property string shortNameRole:
"shortName"
48 property string colorRole:
"color"
49 property string valueRole:
"value"
51 property bool highlightEnabled:
false
52 property int highlightedIndex: -1
54 default property alias _children: legend.children
61 implicitWidth: Math.max(implicitContentWidth, implicitBackgroundWidth) + leftPadding + rightPadding
62 implicitHeight: Math.max(implicitContentHeight, implicitBackgroundHeight) + topPadding + bottomPadding
64 contentItem: Flickable {
67 contentHeight: legend.implicitHeight
69 boundsBehavior: Flickable.StopAtBounds
71 implicitHeight: legend.implicitHeight
72 implicitWidth: legend.implicitWidth
76 maximumFlickVelocity: Theme.gridUnit * 50
88 property var itemData: typeof modelData !==
"undefined" ? modelData : model
90 name: itemData[control.nameRole] ??
""
91 shortName: itemData[control.shortNameRole] ??
""
92 color: itemData[control.colorRole] ??
"white"
93 value: control.formatValue(itemData[control.valueRole] ??
"", index)
95 highlighted: control.highlightEnabled && hovered
98 var result = control.maximumValueWidth(model.value, index)
106 LegendLayout.minimumWidth: minimumWidth
107 LegendLayout.preferredWidth: preferredWidth
108 LegendLayout.maximumWidth: Math.max(control.maximumDelegateWidth, preferredWidth)
111 if (control.highlightEnabled) {
113 control.highlightedIndex = index
114 }
else if (control.highlightedIndex == index) {
115 control.highlightedIndex = -1
122 horizontalSpacing: Theme.smallSpacing
123 verticalSpacing: Theme.smallSpacing
130 visible: parent.contentY > 0
134 horizontalCenter: parent.horizontalCenter
138 width: Theme.smallIconSize
139 height: Theme.smallIconSize
141 icon.name:
"arrow-up-symbolic"
142 icon.width: Theme.smallIconSize
143 icon.height: Theme.smallIconSize
148 y: parent.height - height
151 visible: parent.contentY + parent.height < legend.height
155 horizontalCenter: parent.horizontalCenter
156 bottom: parent.bottom
159 width: Theme.smallIconSize
160 height: Theme.smallIconSize
162 icon.name:
"arrow-down-symbolic"
163 icon.width: Theme.smallIconSize
164 icon.height: Theme.smallIconSize
A delegate that can be used as part of a Legend.
A model that extracts information from a chart that can be displayed as a legend.