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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/*
* This file is part of KQuickCharts
* SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
*
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.2
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kquickcontrols 2.0
import org.kde.quickcharts 1.0 as Charts
import org.kde.quickcharts.controls 1.0 as ChartsControls
Kirigami.Page {
title: "Line Chart"
ListModel {
id: lineModel;
dynamicRoles: true;
Component.onCompleted: {
append({label: "Item 1", value1: 10, value2: 15, value3: 20})
append({label: "Item 2", value1: 15, value2: 25, value3: 25})
append({label: "Item 3", value1: 15, value2: 20, value3: 30})
append({label: "Item 4", value1: 10, value2: 10, value3: 35})
append({label: "Item 5", value1: 20, value2: 5, value3: 40})
}
}
ColumnLayout {
anchors.fill: parent
anchors.margins: Kirigami.Units.largeSpacing
spacing: Kirigami.Units.largeSpacing
Kirigami.AbstractCard {
Layout.fillHeight: false
Layout.preferredHeight: 400
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
ChartsControls.LineChartControl {
id: lineChart
anchors.fill: parent
valueSources: [
Charts.ModelSource { roleName: "value1"; model: lineModel },
Charts.ModelSource { roleName: "value2"; model: lineModel },
Charts.ModelSource { roleName: "value3"; model: lineModel }
]
names: ["Example 1", "Example 2", "Example 3"]
pointDelegate: Item {
Rectangle {
anchors.centerIn: parent
width: lineChart.lineWidth + Kirigami.Units.smallSpacing;
height: width
radius: width / 2;
color: parent.Charts.LineChart.color
MouseArea {
id: mouse
anchors.fill: parent
hoverEnabled: true
}
ToolTip.visible: mouse.containsMouse
ToolTip.text: "%1: %2".arg(parent.Charts.LineChart.name).arg(parent.Charts.LineChart.value)
}
}
}
}
RangeEditor { label: "X Axis"; range: lineChart.xRange }
RangeEditor { label: "Y Axis"; range: lineChart.yRange }
RowLayout {
Button { text: "Add Item"; onClicked: lineModel.append({label: "New", value1: 0, value2: 0, value3: 0}) }
Button { text: "Remove Item"; onClicked: lineModel.remove(lineModel.count - 1)}
Label { text: "Line Width" }
SpinBox { from: 0; to: 1000; value: lineChart.lineWidth; onValueModified: lineChart.lineWidth = value; }
Label { text: "Fill Opacity" }
SpinBox { from: 0; to: 100; value: lineChart.fillOpacity * 100; onValueModified: lineChart.fillOpacity = value / 100; }
CheckBox { text: "Stacked"; checked: lineChart.stacked; onToggled: lineChart.stacked = checked }
CheckBox { text: "Smooth"; checked: lineChart.chart.smooth; onToggled: lineChart.chart.smooth = checked }
}
Frame {
Layout.fillWidth: true
Layout.fillHeight: true
ScrollView {
anchors.fill: parent
ListView {
model: lineModel;
delegate: Kirigami.BasicListItem {
width: ListView.view.width
height: Kirigami.Units.gridUnit * 2 + Kirigami.Units.smallSpacing
contentItem: RowLayout {
Label { text: "Label" }
TextField {
Layout.preferredWidth: 75
text: model.label;
onEditingFinished: lineModel.setProperty(index, "label", text)
}
Label { text: "Value 1" }
SpinBox {
Layout.preferredWidth: 75
from: -10000; to: 10000;
stepSize: 1;
value: model.value1;
onValueModified: lineModel.setProperty(index, "value1", value)
}
Label { text: "Value 2" }
SpinBox {
Layout.preferredWidth: 75
from: -10000; to: 10000;
stepSize: 1;
value: model.value2;
onValueModified: lineModel.setProperty(index, "value2", value)
}
Label { text: "Value 3" }
SpinBox {
Layout.preferredWidth: 75
from: -10000; to: 10000;
stepSize: 1;
value: model.value3;
onValueModified: lineModel.setProperty(index, "value3", value)
}
}
}
}
}
}
}
}
|