mirror of https://github.com/qt/qtgraphs.git
Add series index dynamic properties for custom delegates
Support for series index in BarSeries (barIndex) and XYSeries (pointIndex). These will allow new customization possibilities. Task-number: QTBUG-129382 Change-Id: I4b332efda9c630bcb0394ffa49e999a3aca4fbf1 Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io> Reviewed-by: Jere Tuliniemi <jere.tuliniemi@qt.io>
This commit is contained in:
parent
f5f3d9b16b
commit
ddab1d76dc
|
|
@ -262,6 +262,10 @@ QT_BEGIN_NAMESPACE
|
|||
\li barSelected
|
||||
\li This value is true when the bar is selected, meaning that the bar index
|
||||
is in \l{QBarSet::selectedBars}.
|
||||
\row
|
||||
\li int
|
||||
\li barIndex
|
||||
\li Index of the bar, from 0 to the amount of bars - 1. [since 6.9]
|
||||
\endtable
|
||||
|
||||
To use any of these, add property with the defined name into your custom component.
|
||||
|
|
@ -308,6 +312,10 @@ QT_BEGIN_NAMESPACE
|
|||
\li barSelected
|
||||
\li This value is true when the bar is selected, meaning that the bar index
|
||||
is in \l{BarSet::selectedBars}.
|
||||
\row
|
||||
\li int
|
||||
\li barIndex
|
||||
\li Index of the bar, from 0 to the amount of bars - 1. [since 6.9]
|
||||
\endtable
|
||||
|
||||
To use any of these, add property with the defined name into your custom component.
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ static const char* TAG_BAR_BORDER_WIDTH = "barBorderWidth";
|
|||
static const char* TAG_BAR_SELECTED = "barSelected";
|
||||
static const char* TAG_BAR_VALUE = "barValue";
|
||||
static const char* TAG_BAR_LABEL = "barLabel";
|
||||
static const char* TAG_BAR_INDEX = "barIndex";
|
||||
|
||||
BarsRenderer::BarsRenderer(QGraphsView *graph)
|
||||
: QQuickItem(graph)
|
||||
|
|
@ -179,6 +180,8 @@ void BarsRenderer::updateComponents(QBarSeries *series)
|
|||
barItem->setProperty(TAG_BAR_VALUE, d.value);
|
||||
if (barItem->property(TAG_BAR_LABEL).isValid())
|
||||
barItem->setProperty(TAG_BAR_LABEL, d.label);
|
||||
if (barItem->property(TAG_BAR_INDEX).isValid())
|
||||
barItem->setProperty(TAG_BAR_INDEX, barIndex);
|
||||
} else {
|
||||
// Set default rectangle bars
|
||||
auto barItem = qobject_cast<QQuickRectangle *>(barItems[barIndex]);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ static const char *TAG_POINT_SELECTED_COLOR = "pointSelectedColor";
|
|||
static const char *TAG_POINT_SELECTED = "pointSelected";
|
||||
static const char *TAG_POINT_VALUE_X = "pointValueX";
|
||||
static const char *TAG_POINT_VALUE_Y = "pointValueY";
|
||||
static const char *TAG_POINT_INDEX = "pointIndex";
|
||||
|
||||
PointRenderer::PointRenderer(QGraphsView *graph)
|
||||
: QQuickItem(graph)
|
||||
|
|
@ -139,6 +140,8 @@ void PointRenderer::updatePointDelegate(
|
|||
marker->setProperty(TAG_POINT_VALUE_X, point.x());
|
||||
if (marker->property(TAG_POINT_VALUE_Y).isValid())
|
||||
marker->setProperty(TAG_POINT_VALUE_Y, point.y());
|
||||
if (marker->property(TAG_POINT_INDEX).isValid())
|
||||
marker->setProperty(TAG_POINT_INDEX, pointIndex);
|
||||
|
||||
marker->setX(x - marker->width() / 2.0);
|
||||
marker->setY(y - marker->height() / 2.0);
|
||||
|
|
|
|||
|
|
@ -790,6 +790,10 @@ QColor QXYSeries::selectedColor() const
|
|||
\li qreal
|
||||
\li pointValueY
|
||||
\li The value of the \l{QXYPoint::y} at this position.
|
||||
\row
|
||||
\li int
|
||||
\li pointIndex
|
||||
\li The index of the point, from 0 to the amount of points - 1. [since 6.9]
|
||||
\endtable
|
||||
|
||||
To use any of these, add property with the defined name into your custom component.
|
||||
|
|
@ -836,6 +840,10 @@ QColor QXYSeries::selectedColor() const
|
|||
\li real
|
||||
\li pointValueY
|
||||
\li The value of the \l{XYPoint::y} at this position.
|
||||
\row
|
||||
\li int
|
||||
\li pointIndex
|
||||
\li The index of the point, from 0 to the amount of points - 1. [since 6.9]
|
||||
\endtable
|
||||
|
||||
To use any of these, add property with the defined name into your custom component.
|
||||
|
|
|
|||
|
|
@ -71,8 +71,9 @@ Rectangle {
|
|||
Rectangle {
|
||||
id: comp
|
||||
property color barColor
|
||||
property int barIndex
|
||||
gradient: Gradient {
|
||||
GradientStop { position: 0.0; color: "red" }
|
||||
GradientStop { position: 0.0; color: (comp.barIndex % 2 === 0) ? "#f02020" : "#d0d020"}
|
||||
GradientStop { position: 0.4; color: Qt.darker(comp.barColor, 2.0) }
|
||||
GradientStop { position: 1.0; color: comp.barColor }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,6 +183,7 @@ Rectangle {
|
|||
property color pointColor
|
||||
property real pointValueX
|
||||
property real pointValueY
|
||||
property int pointIndex
|
||||
width: 16
|
||||
height: 16
|
||||
Rectangle {
|
||||
|
|
@ -190,14 +191,14 @@ Rectangle {
|
|||
color: "#202020"
|
||||
border.width: 2
|
||||
border.color: pointColor
|
||||
radius: width / 2
|
||||
radius: (pointIndex % 2 === 0) ? width / 2 : 2
|
||||
}
|
||||
Text {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.bottom: parent.top
|
||||
color: "#ffffff"
|
||||
font.pixelSize: 16
|
||||
text: "(" + pointValueX.toFixed(1) + ", " + pointValueY.toFixed(1) + ")"
|
||||
text: pointIndex + ": (" + pointValueX.toFixed(1) + ", " + pointValueY.toFixed(1) + ")"
|
||||
}
|
||||
}
|
||||
XYPoint { x: 0; y: 6.6 }
|
||||
|
|
|
|||
Loading…
Reference in New Issue