##// END OF EJS Templates
We have so many stupid warnings that "treat warnings as errors" flag is needed...
We have so many stupid warnings that "treat warnings as errors" flag is needed...

File last commit:

r596:9551377d12c7
r609:a1ef8de9fe8d
Show More
qlegend.cpp
217 lines | 5.7 KiB | text/x-c | CppLexer
sauimone
framework for legend
r524 #include "qchartglobal.h"
#include "qlegend.h"
#include "qseries.h"
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 #include "legendmarker_p.h"
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 #include "qxyseries.h"
#include "qlineseries.h"
#include "qareaseries.h"
#include "qscatterseries.h"
#include "qsplineseries.h"
#include "qbarseries.h"
#include "qstackedbarseries.h"
#include "qpercentbarseries.h"
#include "qbarset.h"
#include "qpieseries.h"
#include "qpieslice.h"
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529 #include <QPainter>
#include <QPen>
sauimone
framework for legend
r524
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 #include <QGraphicsSceneEvent>
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529
sauimone
Separated legend marker to private header. Added signals for left and right mouse click
r547 QTCOMMERCIALCHART_BEGIN_NAMESPACE
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529
sauimone
framework for legend
r524 QLegend::QLegend(QGraphicsItem *parent)
: QGraphicsObject(parent)
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529 ,mBoundingRect(0,0,1,1)
sauimone
background to legend, theme applies
r540 ,mBackgroundBrush(Qt::darkGray) // TODO: from theme?
sauimone
legend scaling with chart
r582 ,mMinimumSize(50,20) // TODO: magic numbers
sauimone
framework for legend
r524 {
sauimone
disable legend by default
r596 setVisible(false);
sauimone
framework for legend
r524 }
void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
sauimone
background to legend, theme applies
r540 painter->setBrush(mBackgroundBrush);
painter->drawRect(mBoundingRect);
sauimone
framework for legend
r524 }
QRectF QLegend::boundingRect() const
{
return mBoundingRect;
}
sauimone
background to legend, theme applies
r540 void QLegend::setBackgroundBrush(const QBrush& brush)
{
mBackgroundBrush = brush;
}
QBrush QLegend::backgroundBrush() const
{
return mBackgroundBrush;
}
sauimone
legend scaling with chart
r582 QSizeF QLegend::minimumSize() const
{
return mMinimumSize;
}
void QLegend::setMinimumSize(const QSizeF size)
{
mMinimumSize = size;
}
sauimone
framework for legend
r524 void QLegend::handleSeriesAdded(QSeries* series,Domain* domain)
{
mSeriesList.append(series);
sauimone
handleThemeChanged slot to legend.
r586 createMarkers(series);
layoutChanged();
}
void QLegend::handleSeriesRemoved(QSeries* series)
{
if (series->type() == QSeries::SeriesTypeArea)
{
// This is special case. Area series has upper and lower series, which each have markers
QAreaSeries* s = static_cast<QAreaSeries*> (series);
deleteMarkers(s->upperSeries());
deleteMarkers(s->lowerSeries());
} else {
deleteMarkers(series);
}
mSeriesList.removeOne(series);
layoutChanged();
}
void QLegend::handleGeometryChanged(const QRectF& size)
{
mBoundingRect = size;
layoutChanged();
}
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565
sauimone
handleThemeChanged slot to legend.
r586 void QLegend::createMarkers(QSeries *series)
{
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 switch (series->type())
{
case QSeries::SeriesTypeLine: {
QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
sauimone
handleThemeChanged slot to legend.
r586 appendMarkers(lineSeries);
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 break;
}
case QSeries::SeriesTypeArea: {
QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
sauimone
handleThemeChanged slot to legend.
r586 appendMarkers(areaSeries->upperSeries());
Michal Klocek
Bugfix dangling pointer in qlegend, remove debug info
r572 if(areaSeries->lowerSeries())
sauimone
handleThemeChanged slot to legend.
r586 appendMarkers(areaSeries->lowerSeries());
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 break;
}
case QSeries::SeriesTypeBar: {
QBarSeries* barSeries = static_cast<QBarSeries*>(series);
sauimone
handleThemeChanged slot to legend.
r586 appendMarkers(barSeries);
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 break;
}
case QSeries::SeriesTypeStackedBar: {
QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
sauimone
handleThemeChanged slot to legend.
r586 appendMarkers(stackedBarSeries);
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 break;
}
case QSeries::SeriesTypePercentBar: {
QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
sauimone
handleThemeChanged slot to legend.
r586 appendMarkers(percentBarSeries);
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 break;
}
case QSeries::SeriesTypeScatter: {
QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
sauimone
handleThemeChanged slot to legend.
r586 appendMarkers(scatterSeries);
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 break;
}
case QSeries::SeriesTypePie: {
QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
sauimone
handleThemeChanged slot to legend.
r586 appendMarkers(pieSeries);
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 break;
}
case QSeries::SeriesTypeSpline: {
QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
sauimone
handleThemeChanged slot to legend.
r586 appendMarkers(splineSeries);
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 break;
}
default: {
sauimone
handleThemeChanged slot to legend.
r586 qDebug()<< "QLegend::createMarkers" << series->type() << "not implemented.";
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 break;
}
}
sauimone
Legend can handle removing of series
r576 }
sauimone
handleThemeChanged slot to legend.
r586 void QLegend::appendMarkers(QXYSeries* series)
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529 {
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 LegendMarker* marker = new LegendMarker(series,this);
marker->setName(series->name());
marker->setBrush(series->brush());
sauimone
combined clicked and rightclicked events of legend to one event with parameter
r567 connect(marker,SIGNAL(clicked(QSeries*,Qt::MouseButton)),this,SIGNAL(clicked(QSeries*,Qt::MouseButton)));
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 mMarkers.append(marker);
childItems().append(marker);
}
sauimone
handleThemeChanged slot to legend.
r586 void QLegend::appendMarkers(QBarSeries *series)
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 {
foreach(QBarSet* s, series->barSets()) {
sauimone
Legend can handle removing of series
r576 LegendMarker* marker = new LegendMarker(series,s,this);
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 marker->setName(s->name());
marker->setBrush(s->brush());
sauimone
combined clicked and rightclicked events of legend to one event with parameter
r567 connect(marker,SIGNAL(clicked(QBarSet*,Qt::MouseButton)),this,SIGNAL(clicked(QBarSet*,Qt::MouseButton)));
sauimone
removed handlethemechange for legend. Too complex solution. Legend now listens the changed signals from series
r587 connect(s,SIGNAL(changed()),marker,SLOT(changed()));
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 mMarkers.append(marker);
childItems().append(marker);
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529 }
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 }
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529
sauimone
handleThemeChanged slot to legend.
r586 void QLegend::appendMarkers(QPieSeries *series)
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 {
foreach(QPieSlice* s, series->slices()) {
sauimone
Legend can handle removing of series
r576 LegendMarker* marker = new LegendMarker(series,s,this);
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 marker->setName(s->label());
marker->setBrush(s->sliceBrush());
sauimone
combined clicked and rightclicked events of legend to one event with parameter
r567 connect(marker,SIGNAL(clicked(QPieSlice*,Qt::MouseButton)),this,SIGNAL(clicked(QPieSlice*,Qt::MouseButton)));
sauimone
removed handlethemechange for legend. Too complex solution. Legend now listens the changed signals from series
r587 connect(s,SIGNAL(changed()),marker,SLOT(changed()));
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 mMarkers.append(marker);
childItems().append(marker);
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529 }
}
sauimone
handleThemeChanged slot to legend.
r586 void QLegend::deleteMarkers(QSeries *series)
{
// Search all markers that belong to given series and delete them.
foreach (LegendMarker *m, mMarkers) {
if (m->series() == series) {
mMarkers.removeOne(m);
delete m;
}
}
}
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529 void QLegend::layoutChanged()
{
// Calculate layout for markers and text
if (mMarkers.count() <= 0) {
// Nothing to do
return;
}
sauimone
background to legend, theme applies
r540 qreal steps = mMarkers.count();
qreal xStep = mBoundingRect.width() / steps;
sauimone
fixed bug in legend name drawing
r585 qreal x=mBoundingRect.x();
qreal y = mBoundingRect.y() + (mBoundingRect.height()/4);
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529 foreach (LegendMarker* m, mMarkers) {
sauimone
fixed bug in legend name drawing
r585 m->setBoundingRect(QRectF(x,y,xStep,mBoundingRect.height()/2));
sauimone
background to legend, theme applies
r540 x += xStep;
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529 }
}
sauimone
framework for legend
r524 #include "moc_qlegend.cpp"
QTCOMMERCIALCHART_END_NAMESPACE