##// END OF EJS Templates
Added createLegendMarkers to private series. This will replace old createLegendMarker method. Notice the s in new method name. PIMPL for QLegendMarker. Newlegend example updated a bit
Added createLegendMarkers to private series. This will replace old createLegendMarker method. Notice the s in new method name. PIMPL for QLegendMarker. Newlegend example updated a bit

File last commit:

r2104:f8a933676fbd
r2163:5397c9eef2aa
Show More
legendmarker.cpp
252 lines | 7.1 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
Fixes legend markers updates
r2085 #include <QGraphicsLayout>
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),
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_markerRect(0, 0, 10.0, 10.0),
m_boundingRect(0, 0, 0, 0),
Tero Ahola
Fixed a bug with legend not updating series labels
r1328 m_legend(legend),
m_textItem(new QGraphicsSimpleTextItem(this)),
Michal Klocek
Refactors layout managment...
r1534 m_rectItem(new QGraphicsRectItem(this)),
Michal Klocek
Refactors layout...
r1965 m_margin(4),
Michal Klocek
Refactors layout managment...
r1534 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);
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);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_markerRect = QRectF(0, 0, fn.height() / 2, fn.height() / 2);
Michal Klocek
Fixes detach legend layout logic
r1536 updateGeometry();
Michal Klocek
Fix title font resize does not invalidate layout
r2088 m_legend->layout()->invalidate();
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 {
Michal Klocek
Refactors layout...
r1965 m_text = label;
updateGeometry();
Michal Klocek
Fixes legend markers updates
r2085 m_legend->layout()->invalidate();
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...
r1965 return m_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
Jani Honkonen
more coding style fixes for src-folder...
r2104 void LegendMarker::setGeometry(const QRectF &rect)
Michal Klocek
Refactors layout managment...
r1534 {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 QFontMetrics fn(font());
Michal Klocek
Refactors layout...
r1965
int width = rect.width();
qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 qreal y = qMax(m_markerRect.height() + 2 * m_margin, fn.height() + 2 * m_margin);
Michal Klocek
Refactors layout...
r1965
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (fn.boundingRect(m_text).width() + x > width) {
Michal Klocek
Refactors layout...
r1965 QString string = m_text + "...";
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 while (fn.boundingRect(string).width() + x > width && string.length() > 3)
Michal Klocek
Refactors layout...
r1965 string.remove(string.length() - 4, 1);
m_textItem->setText(string);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 } else {
Michal Klocek
Refactors layout...
r1965 m_textItem->setText(m_text);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 }
Michal Klocek
Refactors layout...
r1965
Jani Honkonen
more coding style fixes for src-folder...
r2104 const QRectF &textRect = m_textItem->boundingRect();
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_textItem->setPos(x - m_margin, y / 2 - textRect.height() / 2);
Michal Klocek
Adds marker rectangle scaling according to font
r1539 m_rectItem->setRect(m_markerRect);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_rectItem->setPos(m_margin, y / 2 - m_markerRect.height() / 2);
Michal Klocek
Refactors layout managment...
r1534
prepareGeometryChange();
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_boundingRect = QRectF(0, 0, x + textRect.width() + m_margin, y);
Michal Klocek
Refactors layout managment...
r1534 }
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 }
Jani Honkonen
more coding style fixes for src-folder...
r2104 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
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 switch (which) {
case Qt::MinimumSize:
sh = QSizeF(fn.boundingRect("...").width() + 2 * m_margin + m_space + m_markerRect.width(), qMax(m_markerRect.height() + 2 * m_margin, fn.height() + 2 * m_margin));
break;
case Qt::PreferredSize:
sh = QSizeF(fn.boundingRect(m_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;
}
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
Refactors layout...
r1965 //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 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 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()));
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 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());
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 BarLegendMarker::BarLegendMarker(QAbstractBarSeries *barseries, QBarSet *barset, QLegend *legend)
: LegendMarker(barseries, legend),
m_barset(barset)
Michal Klocek
Refactor qledgend handling...
r855 {
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
Fix barset missing slot connection to singal labelchanged
r2092 QObject::connect(barset, SIGNAL(labelChanged()), 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 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Jani Honkonen
more coding style fixes for src-folder...
r2104 PieLegendMarker::PieLegendMarker(QPieSeries *series, QPieSlice *pieslice, QLegend *legend)
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 : LegendMarker(series, legend),
m_pieslice(pieslice)
Michal Klocek
Refactor qledgend handling...
r855 {
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());
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend)
: LegendMarker(series, legend),
m_series(series)
Michal Klocek
Refactor qledgend handling...
r855 {
Michal Klocek
Removes selected() signal form legend and API for now
r1068 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 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());
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (m_series->type() == QAbstractSeries::SeriesTypeScatter)
Michal Klocek
Refactor qledgend handling...
r855 setBrush(m_series->brush());
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 else
Michal Klocek
Refactor qledgend handling...
r855 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