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 default property alias _children: legend.children
58 implicitWidth: Math.max(implicitContentWidth, implicitBackgroundWidth) + leftPadding + rightPadding
59 implicitHeight: Math.max(implicitContentHeight, implicitBackgroundHeight) + topPadding + bottomPadding
61 contentItem: Flickable {
64 contentHeight: legend.implicitHeight
66 boundsBehavior: Flickable.StopAtBounds
68 implicitHeight: legend.implicitHeight
69 implicitWidth: legend.implicitWidth
73 maximumFlickVelocity: Theme.gridUnit * 50
85 property var itemData: typeof modelData !==
"undefined" ? modelData : model
87 name: itemData[control.nameRole] ??
""
88 shortName: itemData[control.shortNameRole] ??
""
89 color: itemData[control.colorRole] ??
"white"
90 value: control.formatValue(itemData[control.valueRole] ??
"", index)
93 var result = control.maximumValueWidth(model.value, index)
101 LegendLayout.minimumWidth: minimumWidth
102 LegendLayout.preferredWidth: preferredWidth
103 LegendLayout.maximumWidth: Math.max(control.maximumDelegateWidth, preferredWidth)
107 horizontalSpacing: Theme.largeSpacing
108 verticalSpacing: Theme.smallSpacing
115 visible: parent.contentY > 0
119 horizontalCenter: parent.horizontalCenter
123 width: Theme.smallIconSize
124 height: Theme.smallIconSize
126 icon.name:
"arrow-up-symbolic"
127 icon.width: Theme.smallIconSize
128 icon.height: Theme.smallIconSize
136 visible: parent.contentY + parent.height < legend.height
140 horizontalCenter: parent.horizontalCenter
141 bottom: parent.bottom
144 width: Theme.smallIconSize
145 height: Theme.smallIconSize
147 icon.name:
"arrow-down-symbolic"
148 icon.width: Theme.smallIconSize
149 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.