##// END OF EJS Templates
Added piechart customization demo screenshot
Added piechart customization demo screenshot

File last commit:

r953:4f43e4b42147
r954:bf8288db1aea
Show More
legendmarker.cpp
195 lines | 5.4 KiB | text/x-c | CppLexer
/ src / legendmarker.cpp
Jani Honkonen
Add license headers
r794 /****************************************************************************
Michal Klocek
Refactor qledgend handling...
r855 **
** Copyright (C) 2012 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** 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$
**
****************************************************************************/
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 #include "legendmarker_p.h"
Michal Klocek
Adds big fat pimpl to series classes...
r938 #include "qxyseries.h"
#include "qxyseries_p.h"
Michal Klocek
Refactor qledgend handling...
r855 #include "qlegend.h"
#include "qbarseries.h"
#include "qpieseries.h"
Michal Klocek
Adds big fat pimpl to series classes...
r938 #include "qpieslice.h"
#include "qbarset.h"
sauimone
legend signal fix for barchart
r953 #include "qbarset_p.h"
Michal Klocek
Adds big fat pimpl to series classes...
r938 #include "qareaseries.h"
#include "qareaseries_p.h"
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 #include <QPainter>
#include <QGraphicsSceneEvent>
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 #include <QGraphicsSimpleTextItem>
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Refactor qledgend handling...
r855 LegendMarker::LegendMarker(QSeries* series,QLegend *legend) : QGraphicsObject(legend),
m_series(series),
m_markerRect(0,0,10.0,10.0),
m_boundingRect(0,0,0,0),
m_legend(legend),
m_textItem(new QGraphicsSimpleTextItem(this)),
m_rectItem(new QGraphicsRectItem(this))
sauimone
legend fixes
r766 {
Michal Klocek
Refactor qledgend handling...
r855 //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
m_rectItem->setRect(m_markerRect);
updateLayout();
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 }
sauimone
legend fixes
r766 void LegendMarker::setPen(const QPen &pen)
sauimone
layout fix to legend. Documented legend functions.
r724 {
Michal Klocek
Refactor qledgend handling...
r855 m_textItem->setPen(pen);
updateLayout();
sauimone
layout fix to legend. Documented legend functions.
r724 }
QPen LegendMarker::pen() const
{
Michal Klocek
Refactor qledgend handling...
r855 return m_textItem->pen();
sauimone
layout fix to legend. Documented legend functions.
r724 }
sauimone
legend fixes
r766 void LegendMarker::setBrush(const QBrush &brush)
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 {
Michal Klocek
Refactor qledgend handling...
r855 m_rectItem->setBrush(brush);
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 }
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 QBrush LegendMarker::brush() const
{
Michal Klocek
Refactor qledgend handling...
r855 return m_rectItem->brush();
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 }
Michal Klocek
Refactor qledgend handling...
r855 void LegendMarker::setLabel(const QString name)
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 {
sauimone
legend marker pointer fix
r778 m_textItem->setText(name);
Michal Klocek
Refactor qledgend handling...
r855 updateLayout();
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 }
Michal Klocek
Refactor qledgend handling...
r855 void LegendMarker::setSize(const QSize& size)
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 {
Michal Klocek
Refactor qledgend handling...
r855 m_markerRect = QRectF(0,0,size.width(),size.height());
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 }
Michal Klocek
Refactor qledgend handling...
r855 QString LegendMarker::label() const
sauimone
Legend can handle removing of series
r576 {
Michal Klocek
Refactor qledgend handling...
r855 return m_textItem->text();
sauimone
Legend can handle removing of series
r576 }
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Tero Ahola
Squashed bunch of warnings
r611 Q_UNUSED(option)
Q_UNUSED(widget)
Michal Klocek
Refactor qledgend handling...
r855 Q_UNUSED(painter)
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 }
QRectF LegendMarker::boundingRect() const
{
sauimone
legend marker pointer fix
r778 return m_boundingRect;
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 }
Michal Klocek
Refactor qledgend handling...
r855 void LegendMarker::updateLayout()
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 {
Michal Klocek
Refactor qledgend handling...
r855 static const qreal margin = 2;
static const qreal space = 4;
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626
Michal Klocek
Refactor qledgend handling...
r855 const QRectF& textRect = m_textItem->boundingRect();
prepareGeometryChange();
m_boundingRect = QRectF(0,0,m_markerRect.width() + 2*margin + space + textRect.width(),qMax(m_markerRect.height()+2*margin,textRect.height()+2*margin));
m_textItem->setPos(m_markerRect.width() + space + margin,m_boundingRect.height()/2 - textRect.height()/2);
m_rectItem->setPos(margin,m_boundingRect.height()/2 - m_markerRect.height()/2);
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626
}
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Michal Klocek
Refactor qledgend handling...
r855 QGraphicsObject::mousePressEvent(event);
emit selected();
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 }
Michal Klocek
Refactor qledgend handling...
r855 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend),
m_series(series)
sauimone
removed handlethemechange for legend. Too complex solution. Legend now listens the changed signals from series
r587 {
Michal Klocek
Refactor qledgend handling...
r855 QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
Michal Klocek
Adds big fat pimpl to series classes...
r938 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
Michal Klocek
Refactor qledgend handling...
r855 updated();
}
void AreaLegendMarker::updated()
{
setBrush(m_series->brush());
setLabel(m_series->name());
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sauimone
legend signal fix for barchart
r953 BarLegendMarker::BarLegendMarker(QBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend),
Michal Klocek
Refactor qledgend handling...
r855 m_barset(barset)
{
sauimone
legend signal fix for barchart
r953 QObject::connect(this, SIGNAL(selected()),barseries, SIGNAL(selected()));
QObject::connect(barset->d_ptr.data(), SIGNAL(valueChanged()), this, SLOT(updated()));
Michal Klocek
Refactor qledgend handling...
r855 updated();
}
void BarLegendMarker::updated()
{
setBrush(m_barset->brush());
setLabel(m_barset->name());
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend),
m_pieslice(pieslice)
{
QObject::connect(this, SIGNAL(selected()),pieslice, SIGNAL(selected()));
QObject::connect(pieslice, SIGNAL(changed()), this, SLOT(updated()));
QObject::connect(pieslice, SIGNAL(destroyed()), this, SLOT(deleteLater())); //TODO:checkthis
updated();
}
void PieLegendMarker::updated()
{
setBrush(m_pieslice->brush());
setLabel(m_pieslice->label());
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend),
m_series(series)
{
QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
Michal Klocek
Adds big fat pimpl to series classes...
r938 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
Michal Klocek
Refactor qledgend handling...
r855 updated();
}
void XYLegendMarker::updated()
{
setLabel(m_series->name());
if(m_series->type()== QSeries::SeriesTypeScatter)
{
setBrush(m_series->brush());
sauimone
solid brush for all legend markers
r800 }
Michal Klocek
Refactor qledgend handling...
r855 else {
setBrush(QBrush(m_series->pen().color()));
sauimone
removed handlethemechange for legend. Too complex solution. Legend now listens the changed signals from series
r587 }
}
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 #include "moc_legendmarker_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE