qpielegendmarker.cpp
144 lines
| 3.6 KiB
| text/x-c
|
CppLexer
|
r2162 | /**************************************************************************** | ||
** | ||||
|
r2688 | ** Copyright (C) 2014 Digia Plc | ||
|
r2162 | ** All rights reserved. | ||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
|
r2574 | ** This file is part of the Qt Enterprise Charts Add-on. | ||
|
r2162 | ** | ||
** $QT_BEGIN_LICENSE$ | ||||
|
r2574 | ** Licensees holding valid Qt Enterprise licenses may use this file in | ||
** accordance with the Qt Enterprise License Agreement provided with the | ||||
|
r2162 | ** Software or, alternatively, in accordance with the terms contained in | ||
** a written agreement between you and Digia. | ||||
** | ||||
** If you have questions regarding the use of this file, please use | ||||
** contact form at http://qt.digia.com | ||||
** $QT_END_LICENSE$ | ||||
** | ||||
****************************************************************************/ | ||||
#include "qpielegendmarker.h" | ||||
|
r2166 | #include "qpielegendmarker_p.h" | ||
|
r2162 | #include <QPieSeries> | ||
|
r2174 | #include <QPieSlice> | ||
|
r2162 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
|
r2168 | |||
|
r2216 | /*! | ||
\class QPieLegendMarker | ||||
|
r2639 | \inmodule Qt Charts | ||
|
r2520 | \brief LegendMarker object. | ||
|
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 | |||
QTCOMMERCIALCHART_END_NAMESPACE | ||||