qpielegendmarker.cpp
142 lines
| 3.6 KiB
| text/x-c
|
CppLexer
|
r2162 | /**************************************************************************** | ||
** | ||||
|
r2776 | ** Copyright (C) 2015 The Qt Company Ltd | ||
|
r2162 | ** All rights reserved. | ||
|
r2776 | ** For any questions to The Qt Company, please use contact form at http://qt.io | ||
|
r2162 | ** | ||
|
r2740 | ** This file is part of the Qt Charts module. | ||
|
r2162 | ** | ||
|
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 | ||||
|
r2776 | ** agreement between you and The Qt Company. | ||
|
r2162 | ** | ||
** If you have questions regarding the use of this file, please use | ||||
|
r2740 | ** contact form at http://qt.io | ||
|
r2162 | ** | ||
****************************************************************************/ | ||||
|
r2714 | #include <QtCharts/QPieLegendMarker> | ||
#include <private/qpielegendmarker_p.h> | ||||
#include <QtCharts/QPieSeries> | ||||
#include <QtCharts/QPieSlice> | ||||
|
r2162 | |||
|
r2712 | QT_CHARTS_BEGIN_NAMESPACE | ||
|
r2168 | |||
|
r2216 | /*! | ||
\class QPieLegendMarker | ||||
|
r2639 | \inmodule Qt Charts | ||
|
r2712 | \brief QLegendMarker subclass for pie series. | ||
|
r2216 | \mainclass | ||
QPieLegendMarker is related to QPieSeries. With QPieSeries, each slice of pie is related to one marker in QLegend. | ||||
|
r2639 | \sa QLegend, QPieSeries, QPieSlice | ||
|
r2216 | */ | ||
/*! | ||||
\fn virtual LegendMarkerType QPieLegendMarker::type() | ||||
Returns QLegendMarker::LegendMarkerTypePie | ||||
*/ | ||||
/*! | ||||
|
r2265 | \internal | ||
|
r2216 | */ | ||
|
r2193 | QPieLegendMarker::QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent) : | ||
|
r2171 | QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent) | ||
|
r2162 | { | ||
|
r2227 | d_ptr->updated(); | ||
|
r2162 | } | ||
|
r2216 | /*! | ||
Destructor | ||||
*/ | ||||
|
r2168 | QPieLegendMarker::~QPieLegendMarker() | ||
|
r2167 | { | ||
} | ||||
/*! | ||||
\internal | ||||
*/ | ||||
QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) : | ||||
QLegendMarker(d, parent) | ||||
|
r2164 | { | ||
} | ||||
|
r2216 | /*! | ||
Returns the related series of marker. | ||||
*/ | ||||
|
r2174 | QPieSeries* QPieLegendMarker::series() | ||
|
r2163 | { | ||
|
r2167 | Q_D(QPieLegendMarker); | ||
return d->m_series; | ||||
} | ||||
|
r2216 | /*! | ||
Returns the related slice of marker. | ||||
*/ | ||||
|
r2179 | QPieSlice* QPieLegendMarker::slice() | ||
|
r2167 | { | ||
Q_D(QPieLegendMarker); | ||||
return d->m_slice; | ||||
|
r2163 | } | ||
|
r2162 | |||
|
r2166 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
r2171 | QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) : | ||
QLegendMarkerPrivate(q,legend), | ||||
|
r2227 | q_ptr(q), | ||
|
r2167 | m_series(series), | ||
m_slice(slice) | ||||
|
r2166 | { | ||
|
r2168 | QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); | ||
QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); | ||||
|
r2174 | QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); | ||
|
r2166 | } | ||
QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate() | ||||
{ | ||||
} | ||||
|
r2182 | QPieSeries* QPieLegendMarkerPrivate::series() | ||
{ | ||||
return m_series; | ||||
} | ||||
QObject* QPieLegendMarkerPrivate::relatedObject() | ||||
{ | ||||
return m_slice; | ||||
} | ||||
|
r2167 | void QPieLegendMarkerPrivate::updated() | ||
{ | ||||
|
r2225 | bool labelChanged = false; | ||
bool brushChanged = false; | ||||
bool penChanged = false; | ||||
|
r2429 | if (!m_customPen && (m_item->pen() != m_slice->pen())) { | ||
|
r2225 | m_item->setPen(m_slice->pen()); | ||
penChanged = true; | ||||
} | ||||
|
r2429 | if (!m_customBrush && (m_item->brush() != m_slice->brush())) { | ||
|
r2225 | m_item->setBrush(m_slice->brush()); | ||
brushChanged = true; | ||||
} | ||||
|
r2429 | if (!m_customLabel && (m_item->label() != m_slice->label())) { | ||
|
r2225 | m_item->setLabel(m_slice->label()); | ||
labelChanged = true; | ||||
} | ||||
|
r2194 | invalidateLegend(); | ||
|
r2225 | |||
if (labelChanged) | ||||
emit q_ptr->labelChanged(); | ||||
if (brushChanged) | ||||
emit q_ptr->brushChanged(); | ||||
if (penChanged) | ||||
emit q_ptr->penChanged(); | ||||
|
r2167 | } | ||
|
r2162 | #include "moc_qpielegendmarker.cpp" | ||
|
r2166 | #include "moc_qpielegendmarker_p.cpp" | ||
|
r2162 | |||
|
r2712 | QT_CHARTS_END_NAMESPACE | ||