##// END OF EJS Templates
minor. add missing license files
minor. add missing license files

File last commit:

r855:e561e621da22
r875:329bfbd049c1
Show More
legendmarker.cpp
192 lines | 5.3 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
Refactor qledgend handling...
r855 #include "qlegend.h"
#include "qbarseries.h"
#include "qpieseries.h"
sauimone
removed handlethemechange for legend. Too complex solution. Legend now listens the changed signals from series
r587 #include <qpieslice.h>
#include <qbarset.h>
sauimone
legend layouting change
r616 #include <qxyseries.h>
sauimone
legend refactoring.
r792 #include <qareaseries.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()));
QObject::connect(series,SIGNAL(updated()), this, SLOT(updated()));
updated();
}
void AreaLegendMarker::updated()
{
setBrush(m_series->brush());
setLabel(m_series->name());
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BarLegendMarker::BarLegendMarker(QBarSeries *series,QBarSet *barset, QLegend *legend) : LegendMarker(series,legend),
m_barset(barset)
{
QObject::connect(this, SIGNAL(selected()),series, SIGNAL(selected()));
QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(updated()));
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()));
QObject::connect(series,SIGNAL(updated()), this, SLOT(updated()));
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