qcolormaplegendmarker.cpp
105 lines
| 3.3 KiB
| text/x-c
|
CppLexer
|
r7 | /*------------------------------------------------------------------------------ | ||
-- This file is a part of the ColorMapChart API | ||||
-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS | ||||
-- | ||||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 2 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Hugo Winter | ||||
-- Mail : hugo.winter@lpp.polytechnique.fr | ||||
----------------------------------------------------------------------------*/ | ||||
|
r0 | #include <QtCharts/QColorMapLegendMarker> | ||
#include <private/qcolormapseries_p.h> | ||||
#include <private/qcolormaplegendmarker_p.h> | ||||
#include <QtCharts/QColorMapSeries> | ||||
QT_CHARTS_BEGIN_NAMESPACE | ||||
QColorMapLegendMarker::QColorMapLegendMarker(QColorMapSeries *series, QLegend *legend, QObject *parent) | ||||
: QLegendMarker(*new QColorMapLegendMarkerPrivate(this,series,legend), parent) | ||||
{ | ||||
d_ptr->updated(); | ||||
} | ||||
QColorMapLegendMarker::~QColorMapLegendMarker() | ||||
{ | ||||
} | ||||
QColorMapLegendMarker::QColorMapLegendMarker(QColorMapLegendMarkerPrivate &d, QObject *parent) : | ||||
QLegendMarker(d, parent) | ||||
{ | ||||
} | ||||
QColorMapSeries* QColorMapLegendMarker::series() | ||||
{ | ||||
Q_D(QColorMapLegendMarker); | ||||
return d->m_series; | ||||
} | ||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
QColorMapLegendMarkerPrivate::QColorMapLegendMarkerPrivate(QColorMapLegendMarker *q, QColorMapSeries *series, QLegend *legend) : | ||||
QLegendMarkerPrivate(q,legend), | ||||
q_ptr(q), | ||||
m_series(series) | ||||
{ | ||||
QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | ||||
QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); | ||||
} | ||||
QColorMapLegendMarkerPrivate::~QColorMapLegendMarkerPrivate() | ||||
{ | ||||
} | ||||
QAbstractSeries* QColorMapLegendMarkerPrivate::series() | ||||
{ | ||||
return m_series; | ||||
} | ||||
QObject* QColorMapLegendMarkerPrivate::relatedObject() | ||||
{ | ||||
return m_series; | ||||
} | ||||
void QColorMapLegendMarkerPrivate::updated() | ||||
{ | ||||
bool labelChanged = false; | ||||
bool brushChanged = false; | ||||
if (!m_customLabel && (m_item->label() != m_series->name())) { | ||||
m_item->setLabel(m_series->name()); | ||||
labelChanged = true; | ||||
} | ||||
QBrush emptyBrush; | ||||
if (!m_customBrush | ||||
&& (m_item->brush() == emptyBrush | ||||
|| m_item->brush().color() != m_series->pen().color())) { | ||||
m_item->setBrush(QBrush(m_series->pen().color())); | ||||
brushChanged = true; | ||||
} | ||||
invalidateLegend(); | ||||
if (labelChanged) | ||||
emit q_ptr->labelChanged(); | ||||
if (brushChanged) | ||||
emit q_ptr->brushChanged(); | ||||
} | ||||
//#include "moc_qcolormaplegendmarker.cpp" | ||||
//#include "moc_qcolormaplegendmarker_p.cpp" | ||||
QT_CHARTS_END_NAMESPACE | ||||