qlegend.cpp
630 lines
| 16.5 KiB
| text/x-c
|
CppLexer
|
r794 | /**************************************************************************** | ||
|
r950 | ** | ||
|
r2688 | ** Copyright (C) 2014 Digia Plc | ||
|
r950 | ** All rights reserved. | ||
|
r2740 | ** For any questions to Digia, please use contact form at http://qt.io | ||
|
r950 | ** | ||
|
r2740 | ** This file is part of the Qt Charts module. | ||
|
r950 | ** | ||
|
r2740 | ** 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 Digia. | ||||
|
r950 | ** | ||
** If you have questions regarding the use of this file, please use | ||||
|
r2740 | ** contact form at http://qt.io | ||
|
r950 | ** | ||
****************************************************************************/ | ||||
|
r794 | |||
|
r2714 | #include <QtCharts/QLegend> | ||
#include <private/qlegend_p.h> | ||||
#include <QtCharts/QAbstractSeries> | ||||
#include <private/qabstractseries_p.h> | ||||
#include <private/qchart_p.h> | ||||
#include <private/legendlayout_p.h> | ||||
#include <private/chartpresenter_p.h> | ||||
#include <private/abstractchartlayout_p.h> | ||||
#include <QtCharts/QLegendMarker> | ||||
#include <private/qlegendmarker_p.h> | ||||
#include <private/legendmarkeritem_p.h> | ||||
#include <private/chartdataset_p.h> | ||||
#include <QtGui/QPainter> | ||||
#include <QtGui/QPen> | ||||
#include <QtWidgets/QGraphicsItemGroup> | ||||
|
r2163 | |||
|
r2712 | QT_CHARTS_BEGIN_NAMESPACE | ||
|
r529 | |||
|
r728 | /*! | ||
|
r995 | \class QLegend | ||
|
r2639 | \inmodule Qt Charts | ||
|
r2520 | \brief Legend object. | ||
|
r995 | \mainclass | ||
|
r728 | |||
|
r2494 | QLegend is a graphical object for displaying the legend of the chart. Legend state is updated by QChart, when | ||
|
r995 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | ||
handle the drawing manually. | ||||
User isn't supposed to create or delete legend objects, but can reference it via QChart class. | ||||
|
r728 | |||
|
r995 | \image examples_percentbarchart_legend.png | ||
|
r728 | |||
|
r995 | \sa QChart | ||
*/ | ||||
|
r1452 | /*! | ||
|
r2639 | \qmltype Legend | ||
\instantiates QLegend | ||||
|
r2712 | \inqmlmodule QtCharts | ||
|
r1452 | |||
|
r2712 | \brief Legend is part of Qt Chart QML API. | ||
Legend is a graphical object, whics displays legend of the chart. Legend state is updated by | ||||
ChartView, when series have been changed. Legend is used via ChartView class. For example: | ||||
\code | ||||
ChartView { | ||||
legend.visible: true | ||||
legend.alignment: Qt.AlignBottom | ||||
// Add a few series... | ||||
} | ||||
\endcode | ||||
\image examples_percentbarchart_legend.png | ||||
|
r2240 | |||
|
r2712 | Please note that there is no QML API available for modifying legend markers, unlike in the Qt | ||
API of Charts. The use case of modifying markers can be implemented for example by creating your | ||||
own custom legend. For an example on how to do this, | ||||
see \l {qmlcustomlegend}{Qml Custom Example} application. | ||||
|
r1452 | */ | ||
/*! | ||||
\property QLegend::alignment | ||||
\brief The alignment of the legend. | ||||
Legend paints on the defined position in the chart. The following alignments are supported: | ||||
Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. | ||||
*/ | ||||
/*! | ||||
\qmlproperty Qt.Alignment Legend::alignment | ||||
\brief The alignment of the legend. | ||||
Legend paints on the defined position in the chart. The following alignments are supported: | ||||
Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. | ||||
*/ | ||||
/*! | ||||
\property QLegend::backgroundVisible | ||||
Whether the legend background is visible or not. | ||||
*/ | ||||
/*! | ||||
\qmlproperty bool Legend::backgroundVisible | ||||
Whether the legend background is visible or not. | ||||
*/ | ||||
/*! | ||||
\property QLegend::color | ||||
|
r1472 | The color of the legend, i.e. the background (brush) color. Note that if you change the color | ||
of the legend, the style of the legend brush is set to Qt::SolidPattern. | ||||
|
r1452 | */ | ||
/*! | ||||
\qmlproperty color Legend::color | ||||
|
r1472 | The color of the legend, i.e. the background (brush) color. | ||
|
r1452 | */ | ||
/*! | ||||
\property QLegend::borderColor | ||||
The border color of the legend, i.e. the line color. | ||||
*/ | ||||
/*! | ||||
\qmlproperty color Legend::borderColor | ||||
The border color of the legend, i.e. the line color. | ||||
*/ | ||||
|
r728 | |||
|
r1522 | /*! | ||
\property QLegend::font | ||||
|
r2686 | The font of markers used by legend. | ||
|
r1522 | */ | ||
/*! | ||||
|
r2113 | \qmlproperty Font Legend::font | ||
|
r2686 | The font of markers used by legend. | ||
|
r1522 | */ | ||
|
r1529 | /*! | ||
\property QLegend::labelColor | ||||
The color of brush used to draw labels. | ||||
*/ | ||||
/*! | ||||
|
r2686 | \qmlproperty color Legend::labelColor | ||
|
r1529 | The color of brush used to draw labels. | ||
*/ | ||||
|
r2676 | /*! | ||
\property QLegend::reverseMarkers | ||||
Whether reverse order is used for the markers in legend or not. False by default. | ||||
*/ | ||||
/*! | ||||
\qmlproperty bool Legend::reverseMarkers | ||||
Whether reverse order is used for the markers in legend or not. False by default. | ||||
*/ | ||||
|
r1452 | /*! | ||
\fn void QLegend::backgroundVisibleChanged(bool) | ||||
The visibility of the legend background changed to \a visible. | ||||
*/ | ||||
/*! | ||||
\fn void QLegend::colorChanged(QColor) | ||||
The color of the legend background changed to \a color. | ||||
*/ | ||||
/*! | ||||
\fn void QLegend::borderColorChanged(QColor) | ||||
The border color of the legend background changed to \a color. | ||||
|
r1357 | */ | ||
|
r724 | |||
|
r1522 | /*! | ||
\fn void QLegend::fontChanged(QFont) | ||||
The font of markers of the legend changed to \a font. | ||||
*/ | ||||
|
r1529 | /*! | ||
\fn void QLegend::labelColorChanged(QColor color) | ||||
This signal is emitted when the color of brush used to draw labels has changed to \a color. | ||||
*/ | ||||
|
r2686 | /*! | ||
\fn void QLegend::reverseMarkersChanged(bool) | ||||
The use of reverse order for the markers in legend is changed to \a reverseMarkers. | ||||
*/ | ||||
|
r2097 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), | ||
d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) | ||||
|
r762 | { | ||
|
r626 | setZValue(ChartPresenter::LegendZValue); | ||
|
r855 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | ||
|
r2273 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); | ||
|
r2131 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); | ||
|
r1534 | setLayout(d_ptr->m_layout); | ||
|
r950 | } | ||
|
r1002 | /*! | ||
Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. | ||||
*/ | ||||
|
r950 | QLegend::~QLegend() | ||
{ | ||||
|
r524 | } | ||
|
r724 | /*! | ||
|
r1501 | \internal | ||
|
r950 | */ | ||
|
r524 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||
{ | ||||
|
r950 | Q_UNUSED(option) | ||
Q_UNUSED(widget) | ||||
|
r1963 | |||
|
r2097 | if (!d_ptr->m_backgroundVisible) | ||
return; | ||||
|
r611 | |||
|
r724 | painter->setOpacity(opacity()); | ||
|
r950 | painter->setPen(d_ptr->m_pen); | ||
painter->setBrush(d_ptr->m_brush); | ||||
|
r2097 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); | ||
|
r524 | } | ||
|
r1534 | |||
|
r724 | /*! | ||
|
r950 | Sets the \a brush of legend. Brush affects the background of legend. | ||
*/ | ||||
|
r737 | void QLegend::setBrush(const QBrush &brush) | ||
|
r540 | { | ||
|
r950 | if (d_ptr->m_brush != brush) { | ||
d_ptr->m_brush = brush; | ||||
|
r645 | update(); | ||
|
r1543 | emit colorChanged(brush.color()); | ||
|
r645 | } | ||
} | ||||
|
r724 | /*! | ||
|
r950 | Returns the brush used by legend. | ||
*/ | ||||
|
r645 | QBrush QLegend::brush() const | ||
{ | ||||
|
r950 | return d_ptr->m_brush; | ||
|
r645 | } | ||
|
r1452 | void QLegend::setColor(QColor color) | ||
{ | ||||
QBrush b = d_ptr->m_brush; | ||||
|
r1472 | if (b.style() != Qt::SolidPattern || b.color() != color) { | ||
b.setStyle(Qt::SolidPattern); | ||||
|
r1452 | b.setColor(color); | ||
setBrush(b); | ||||
} | ||||
} | ||||
QColor QLegend::color() | ||||
{ | ||||
return d_ptr->m_brush.color(); | ||||
} | ||||
|
r724 | /*! | ||
|
r950 | Sets the \a pen of legend. Pen affects the legend borders. | ||
*/ | ||||
|
r737 | void QLegend::setPen(const QPen &pen) | ||
|
r645 | { | ||
|
r950 | if (d_ptr->m_pen != pen) { | ||
d_ptr->m_pen = pen; | ||||
|
r645 | update(); | ||
|
r1543 | emit borderColorChanged(pen.color()); | ||
|
r645 | } | ||
|
r540 | } | ||
|
r724 | /*! | ||
|
r2686 | Returns the pen used by legend. | ||
|
r950 | */ | ||
|
r724 | |||
|
r645 | QPen QLegend::pen() const | ||
|
r540 | { | ||
|
r950 | return d_ptr->m_pen; | ||
|
r540 | } | ||
|
r1534 | void QLegend::setFont(const QFont &font) | ||
{ | ||||
|
r2273 | if (d_ptr->m_font != font) { | ||
|
r2652 | // Hide items to avoid flickering | ||
d_ptr->items()->setVisible(false); | ||||
|
r1534 | d_ptr->m_font = font; | ||
|
r2273 | foreach (QLegendMarker *marker, d_ptr->markers()) { | ||
marker->setFont(d_ptr->m_font); | ||||
} | ||||
layout()->invalidate(); | ||||
emit fontChanged(font); | ||||
|
r1534 | } | ||
} | ||||
QFont QLegend::font() const | ||||
{ | ||||
|
r2097 | return d_ptr->m_font; | ||
|
r1534 | } | ||
|
r1452 | void QLegend::setBorderColor(QColor color) | ||
{ | ||||
QPen p = d_ptr->m_pen; | ||||
if (p.color() != color) { | ||||
p.setColor(color); | ||||
setPen(p); | ||||
} | ||||
} | ||||
|
r1357 | |||
|
r1452 | QColor QLegend::borderColor() | ||
{ | ||||
return d_ptr->m_pen.color(); | ||||
} | ||||
|
r1357 | |||
|
r1529 | /*! | ||
Set brush used to draw labels to \a brush. | ||||
*/ | ||||
|
r1527 | void QLegend::setLabelBrush(const QBrush &brush) | ||
{ | ||||
if (d_ptr->m_labelBrush != brush) { | ||||
|
r1534 | d_ptr->m_labelBrush = brush; | ||
|
r2185 | foreach (QLegendMarker *marker, d_ptr->markers()) { | ||
|
r1534 | marker->setLabelBrush(d_ptr->m_labelBrush); | ||
|
r1795 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API | ||
// instead of mapping it from label brush color | ||||
marker->setPen(brush.color()); | ||||
|
r1534 | } | ||
|
r1543 | emit labelColorChanged(brush.color()); | ||
|
r1527 | } | ||
} | ||||
|
r1529 | /*! | ||
Brush used to draw labels. | ||||
*/ | ||||
|
r1527 | QBrush QLegend::labelBrush() const | ||
{ | ||||
return d_ptr->m_labelBrush; | ||||
} | ||||
void QLegend::setLabelColor(QColor color) | ||||
{ | ||||
QBrush b = d_ptr->m_labelBrush; | ||||
if (b.style() != Qt::SolidPattern || b.color() != color) { | ||||
b.setStyle(Qt::SolidPattern); | ||||
b.setColor(color); | ||||
setLabelBrush(b); | ||||
} | ||||
} | ||||
QColor QLegend::labelColor() const | ||||
{ | ||||
return d_ptr->m_labelBrush.color(); | ||||
} | ||||
|
r1534 | |||
|
r1357 | void QLegend::setAlignment(Qt::Alignment alignment) | ||
|
r616 | { | ||
|
r2097 | if (d_ptr->m_alignment != alignment) { | ||
|
r950 | d_ptr->m_alignment = alignment; | ||
|
r2088 | layout()->invalidate(); | ||
|
r855 | } | ||
|
r716 | } | ||
|
r1357 | Qt::Alignment QLegend::alignment() const | ||
|
r716 | { | ||
|
r950 | return d_ptr->m_alignment; | ||
|
r616 | } | ||
|
r724 | /*! | ||
|
r950 | Detaches the legend from chart. Chart won't change layout of the legend. | ||
*/ | ||||
void QLegend::detachFromChart() | ||||
|
r524 | { | ||
|
r950 | d_ptr->m_attachedToChart = false; | ||
|
r2392 | // layout()->invalidate(); | ||
d_ptr->m_chart->layout()->invalidate(); | ||||
|
r1534 | setParent(0); | ||
|
r586 | } | ||
|
r724 | /*! | ||
|
r950 | Attaches the legend to chart. Chart may change layout of the legend. | ||
*/ | ||||
void QLegend::attachToChart() | ||||
|
r586 | { | ||
|
r1534 | d_ptr->m_attachedToChart = true; | ||
|
r2392 | // layout()->invalidate(); | ||
d_ptr->m_chart->layout()->invalidate(); | ||||
|
r1534 | setParent(d_ptr->m_chart); | ||
|
r586 | } | ||
|
r724 | /*! | ||
|
r950 | Returns true, if legend is attached to chart. | ||
*/ | ||||
bool QLegend::isAttachedToChart() | ||||
|
r637 | { | ||
|
r950 | return d_ptr->m_attachedToChart; | ||
|
r637 | } | ||
|
r799 | /*! | ||
|
r950 | Sets the visibility of legend background to \a visible | ||
*/ | ||||
void QLegend::setBackgroundVisible(bool visible) | ||||
|
r799 | { | ||
|
r2097 | if (d_ptr->m_backgroundVisible != visible) { | ||
|
r1452 | d_ptr->m_backgroundVisible = visible; | ||
|
r950 | update(); | ||
|
r1452 | emit backgroundVisibleChanged(visible); | ||
|
r950 | } | ||
|
r799 | } | ||
/*! | ||||
|
r950 | Returns the visibility of legend background | ||
*/ | ||||
bool QLegend::isBackgroundVisible() const | ||||
|
r799 | { | ||
|
r950 | return d_ptr->m_backgroundVisible; | ||
|
r799 | } | ||
|
r2216 | /*! | ||
Returns the list of markers in legend. The list can be filtered with \a series parameter. | ||||
If \a series is given, only markers related to that series are returned. | ||||
*/ | ||||
|
r2193 | QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const | ||
|
r2160 | { | ||
|
r2193 | return d_ptr->markers(series); | ||
|
r2160 | } | ||
|
r2676 | bool QLegend::reverseMarkers() | ||
{ | ||||
return d_ptr->m_reverseMarkers; | ||||
} | ||||
void QLegend::setReverseMarkers(bool reverseMarkers) | ||||
{ | ||||
if (d_ptr->m_reverseMarkers != reverseMarkers) { | ||||
d_ptr->m_reverseMarkers = reverseMarkers; | ||||
layout()->invalidate(); | ||||
emit reverseMarkersChanged(reverseMarkers); | ||||
} | ||||
} | ||||
|
r724 | /*! | ||
|
r950 | \internal \a event see QGraphicsWidget for details | ||
*/ | ||||
void QLegend::hideEvent(QHideEvent *event) | ||||
|
r529 | { | ||
|
r2097 | if (isAttachedToChart()) | ||
d_ptr->m_presenter->layout()->invalidate(); | ||||
QGraphicsWidget::hideEvent(event); | ||||
|
r565 | } | ||
|
r724 | /*! | ||
|
r950 | \internal \a event see QGraphicsWidget for details | ||
*/ | ||||
void QLegend::showEvent(QShowEvent *event) | ||||
|
r565 | { | ||
|
r2602 | if (isAttachedToChart()) | ||
|
r2097 | layout()->invalidate(); | ||
QGraphicsWidget::showEvent(event); | ||||
//layout activation will show the items | ||||
|
r950 | } | ||
|
r855 | |||
|
r950 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
r2104 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) | ||
|
r2097 | : q_ptr(q), | ||
m_presenter(presenter), | ||||
m_layout(new LegendLayout(q)), | ||||
m_chart(chart), | ||||
m_items(new QGraphicsItemGroup(q)), | ||||
m_alignment(Qt::AlignTop), | ||||
m_brush(QBrush()), | ||||
m_pen(QPen()), | ||||
m_labelBrush(QBrush()), | ||||
m_diameter(5), | ||||
m_attachedToChart(true), | ||||
|
r2676 | m_backgroundVisible(false), | ||
m_reverseMarkers(false) | ||||
|
r950 | { | ||
|
r2169 | m_items->setHandlesChildEvents(false); | ||
|
r586 | } | ||
|
r950 | QLegendPrivate::~QLegendPrivate() | ||
{ | ||||
|
r529 | |||
|
r950 | } | ||
|
r2189 | void QLegendPrivate::setOffset(const QPointF &offset) | ||
|
r855 | { | ||
|
r2189 | m_layout->setOffset(offset.x(), offset.y()); | ||
|
r855 | } | ||
|
r716 | |||
|
r1458 | QPointF QLegendPrivate::offset() const | ||
{ | ||||
|
r1534 | return m_layout->offset(); | ||
|
r1300 | } | ||
|
r1453 | int QLegendPrivate::roundness(qreal size) | ||
{ | ||||
|
r2097 | return 100 * m_diameter / int(size); | ||
|
r1453 | } | ||
|
r2193 | QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series) | ||
{ | ||||
// Return all markers | ||||
if (!series) { | ||||
return m_markers; | ||||
} | ||||
// Create filtered list | ||||
QList<QLegendMarker *> markers; | ||||
foreach (QLegendMarker *marker, m_markers) { | ||||
if (marker->series() == series) { | ||||
markers.append(marker); | ||||
} | ||||
} | ||||
return markers; | ||||
} | ||||
|
r2209 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) | ||
|
r2167 | { | ||
if (m_series.contains(series)) { | ||||
|
r2173 | return; | ||
|
r2167 | } | ||
|
r2164 | |||
|
r2163 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); | ||
|
r2182 | decorateMarkers(newMarkers); | ||
addMarkers(newMarkers); | ||||
|
r2163 | |||
|
r2192 | QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); | ||
|
r2163 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | ||
|
r956 | |||
|
r2173 | m_series.append(series); | ||
|
r2085 | m_items->setVisible(false); | ||
|
r2088 | m_layout->invalidate(); | ||
|
r716 | } | ||
|
r2209 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | ||
|
r716 | { | ||
|
r2173 | if (m_series.contains(series)) { | ||
m_series.removeOne(series); | ||||
} | ||||
|
r2171 | |||
|
r2182 | // Find out, which markers to remove | ||
QList<QLegendMarker *> removed; | ||||
|
r2185 | foreach (QLegendMarker *m, m_markers) { | ||
|
r2182 | if (m->series() == series) { | ||
removed << m; | ||||
|
r2163 | } | ||
} | ||||
|
r2182 | removeMarkers(removed); | ||
|
r2163 | |||
|
r2192 | QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); | ||
|
r2163 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | ||
|
r2088 | m_layout->invalidate(); | ||
|
r2173 | } | ||
|
r1459 | void QLegendPrivate::handleSeriesVisibleChanged() | ||
{ | ||||
|
r2104 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); | ||
|
r2085 | Q_ASSERT(series); | ||
|
r1459 | |||
|
r2193 | foreach (QLegendMarker *marker, m_markers) { | ||
|
r2163 | if (marker->series() == series) { | ||
marker->setVisible(series->isVisible()); | ||||
} | ||||
} | ||||
|
r2605 | |||
if (m_chart->isVisible()) | ||||
m_layout->invalidate(); | ||||
|
r1459 | } | ||
|
r2085 | void QLegendPrivate::handleCountChanged() | ||
|
r2081 | { | ||
|
r2182 | // Here we handle the changes in marker count. | ||
// Can happen for example when pieslice(s) have been added to or removed from pieseries. | ||||
|
r2173 | |||
|
r2192 | QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender()); | ||
QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr); | ||||
|
r2182 | |||
// Find out removed markers and created markers | ||||
QList<QLegendMarker *> removedMarkers; | ||||
|
r2185 | foreach (QLegendMarker *oldMarker, m_markers) { | ||
|
r2182 | // we have marker, which is related to sender. | ||
|
r2192 | if (oldMarker->series() == series->q_ptr) { | ||
|
r2182 | bool found = false; | ||
foreach(QLegendMarker *newMarker, createdMarkers) { | ||||
// New marker considered existing if: | ||||
// - d_ptr->relatedObject() is same for both markers. | ||||
if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) { | ||||
// Delete the new marker, since we already have existing marker, that might be connected on user side. | ||||
found = true; | ||||
createdMarkers.removeOne(newMarker); | ||||
delete newMarker; | ||||
} | ||||
} | ||||
if (!found) { | ||||
// No related object found for marker, add to removedMarkers list | ||||
removedMarkers << oldMarker; | ||||
} | ||||
} | ||||
} | ||||
removeMarkers(removedMarkers); | ||||
|
r2183 | decorateMarkers(createdMarkers); | ||
|
r2182 | addMarkers(createdMarkers); | ||
q_ptr->layout()->invalidate(); | ||||
} | ||||
void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers) | ||||
{ | ||||
|
r2193 | foreach (QLegendMarker *marker, markers) { | ||
|
r2182 | m_items->addToGroup(marker->d_ptr.data()->item()); | ||
|
r2185 | m_markers << marker; | ||
|
r2197 | m_markerHash.insert(marker->d_ptr->item(), marker); | ||
|
r2182 | } | ||
} | ||||
void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers) | ||||
{ | ||||
foreach (QLegendMarker *marker, markers) { | ||||
marker->d_ptr->item()->setVisible(false); | ||||
m_items->removeFromGroup(marker->d_ptr->item()); | ||||
|
r2185 | m_markers.removeOne(marker); | ||
|
r2197 | m_markerHash.remove(marker->d_ptr->item()); | ||
delete marker; | ||||
|
r2182 | } | ||
} | ||||
void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers) | ||||
{ | ||||
|
r2193 | foreach (QLegendMarker *marker, markers) { | ||
|
r2182 | marker->setFont(m_font); | ||
marker->setLabelBrush(m_labelBrush); | ||||
} | ||||
|
r2081 | } | ||
|
r2182 | |||
|
r524 | #include "moc_qlegend.cpp" | ||
|
r950 | #include "moc_qlegend_p.cpp" | ||
|
r737 | |||
|
r2712 | QT_CHARTS_END_NAMESPACE | ||