##// END OF EJS Templates
refactoring internal barchart items
refactoring internal barchart items

File last commit:

r1586:9c6a61adadc9
r1674:2849be5cffb7
Show More
legendmarker.cpp
237 lines | 6.4 KiB | text/x-c | CppLexer
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"
sauimone
renamed barseries files to abstractbarseries
r1586 #include "qabstractbarseries.h"
Michal Klocek
Refactor qledgend handling...
r855 #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>
Michal Klocek
Removes selected() signal form legend and API for now
r1068 #include <QDebug>
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Tero Ahola
Fixed a bug with legend not updating series labels
r1328 LegendMarker::LegendMarker(QAbstractSeries *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)),
Michal Klocek
Refactors layout managment...
r1534 m_rectItem(new QGraphicsRectItem(this)),
m_margin(2),
m_space(4)
sauimone
legend fixes
r766 {
Michal Klocek
Refactor qledgend handling...
r855 //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
m_rectItem->setRect(m_markerRect);
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 {
Tero Ahola
Removed QLegend::setLabelPen, clean up theme label brushes
r1528 m_rectItem->setPen(pen);
Michal Klocek
Refactors layout managment...
r1534 m_textItem->setPen(pen);
sauimone
layout fix to legend. Documented legend functions.
r724 }
QPen LegendMarker::pen() const
{
Tero Ahola
Removed QLegend::setLabelPen, clean up theme label brushes
r1528 return m_rectItem->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 }
sauimone
legend font fix
r1522 void LegendMarker::setFont(const QFont &font)
{
m_textItem->setFont(font);
Michal Klocek
Adds marker rectangle scaling according to font
r1539 QFontMetrics fn(font);
m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
Michal Klocek
Fixes detach legend layout logic
r1536 updateGeometry();
sauimone
legend font fix
r1522 }
QFont LegendMarker::font() const
{
return m_textItem->font();
}
sauimone
changed barset name to label to be consistent with pie series. Series have names, barsets and pieslices have labels
r1429 void LegendMarker::setLabel(const QString label)
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 {
sauimone
changed barset name to label to be consistent with pie series. Series have names, barsets and pieslices have labels
r1429 m_textItem->setText(label);
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 }
Michal Klocek
Refactors layout managment...
r1534 QString LegendMarker::label() const
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 {
Michal Klocek
Refactors layout managment...
r1534 return m_textItem->text();
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 }
Michal Klocek
Refactors layout managment...
r1534 QRectF LegendMarker::boundingRect() const
sauimone
Legend can handle removing of series
r576 {
Michal Klocek
Refactors layout managment...
r1534 return m_boundingRect;
sauimone
Legend can handle removing of series
r576 }
sauimone
legend theme fix
r1527 void LegendMarker::setLabelBrush(const QBrush &brush)
{
m_textItem->setBrush(brush);
}
QBrush LegendMarker::labelBrush() const
{
return m_textItem->brush();
}
Michal Klocek
Refactors layout managment...
r1534
void LegendMarker::setGeometry(const QRectF& rect)
{
const QRectF& textRect = m_textItem->boundingRect();
m_textItem->setPos(m_markerRect.width() + m_space + m_margin,rect.height()/2 - textRect.height()/2);
Michal Klocek
Adds marker rectangle scaling according to font
r1539 m_rectItem->setRect(m_markerRect);
Michal Klocek
Refactors layout managment...
r1534 m_rectItem->setPos(m_margin,rect.height()/2 - m_markerRect.height()/2);
prepareGeometryChange();
m_boundingRect = rect;
}
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 }
Michal Klocek
Refactors layout managment...
r1534 QSizeF LegendMarker::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 {
Michal Klocek
Refactors layout managment...
r1534 Q_UNUSED(constraint)
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626
Michal Klocek
Refactors layout managment...
r1534 QFontMetrics fn(m_textItem->font());
QSizeF sh;
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626
Michal Klocek
Refactors layout managment...
r1534 switch (which) {
case Qt::MinimumSize:
sh = QSizeF(fn.boundingRect("...").width(),fn.height());
break;
case Qt::PreferredSize:
sh = QSizeF(fn.boundingRect(m_textItem->text()).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
break;
default:
break;
}
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626
Michal Klocek
Refactors layout managment...
r1534 return sh;
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);
Michal Klocek
Removes selected() signal form legend and API for now
r1068 qDebug()<<"Not implemented"; //TODO: selected signal removed for now
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
Removes selected() signal form legend and API for now
r1068 //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()));
Tero Ahola
Fixed a bug with legend not updating series labels
r1328 QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
Michal Klocek
Refactor qledgend handling...
r855 updated();
}
void AreaLegendMarker::updated()
{
setBrush(m_series->brush());
setLabel(m_series->name());
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sauimone
QBarSeries to QAbstractBarSeries
r1584 BarLegendMarker::BarLegendMarker(QAbstractBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend),
Michal Klocek
Refactor qledgend handling...
r855 m_barset(barset)
{
Michal Klocek
Removes selected() signal form legend and API for now
r1068 //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected()));
sauimone
barchart: removed mousebuttons from clicked signal. removed selected signal. unified internal signal naming in barset and barseries private
r1008 QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated()));
Michal Klocek
Refactor qledgend handling...
r855 updated();
}
void BarLegendMarker::updated()
{
setBrush(m_barset->brush());
sauimone
changed barset name to label to be consistent with pie series. Series have names, barsets and pieslices have labels
r1429 setLabel(m_barset->label());
Michal Klocek
Refactor qledgend handling...
r855 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend),
m_pieslice(pieslice)
{
Jani Honkonen
pie: remove changed() signal and replace it with more refined signals...
r1224 QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated()));
Jani Honkonen
pie: added everything as a property in QPieSlice...
r1274 QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated()));
Michal Klocek
Refactor qledgend handling...
r855 updated();
}
void PieLegendMarker::updated()
{
setBrush(m_pieslice->brush());
setLabel(m_pieslice->label());
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend),
m_series(series)
{
Michal Klocek
Removes selected() signal form legend and API for now
r1068 //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()));
Tero Ahola
Fixed a bug with legend not updating series labels
r1328 QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
Michal Klocek
Refactor qledgend handling...
r855 updated();
}
void XYLegendMarker::updated()
{
setLabel(m_series->name());
Tero Ahola
Renamed QSeries to QAbstractSeries
r988 if(m_series->type()== QAbstractSeries::SeriesTypeScatter)
Michal Klocek
Refactor qledgend handling...
r855 {
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