##// END OF EJS Templates
QML bar series categories
QML bar series categories

File last commit:

r724:2a4cd4554920
r726:5bffcd7b4ba5
Show More
qlegend.cpp
775 lines | 24.0 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
Scrolling logic to legend
r716 #include "legendscrollbutton_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
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 #include "chartpresenter_p.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
layout fix to legend. Documented legend functions.
r724 /*!
\enum QLegend::PreferredLayout
This enum describes the possible position for legend inside chart.
\value PreferredLayoutTop
\value PreferredLayoutBottom
\value PreferredLayoutLeft
\value PreferredLayoutRight
*/
/*!
\fn void clicked(QSeries* series, Qt::MouseButton button)
\brief Notifies when series has been clicked on legend \a series \a button
*/
/*!
\fn void clicked(QBarSet* barset, Qt::MouseButton button);
\brief Notifies when barset has been clicked on legend \a barset \a button
*/
/*!
\fn void clicked(QPieSlice* slice, Qt::MouseButton button);
\brief Notifies when pie slice has been clicked on legend \a slice \a button
*/
/*!
Constructs the legend object and sets the parent to \a parent
*/
sauimone
framework for legend
r524 QLegend::QLegend(QGraphicsItem *parent)
: QGraphicsObject(parent)
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 ,mPos(0,0)
,mSize(0,0)
sauimone
legend scaling with chart
r582 ,mMinimumSize(50,20) // TODO: magic numbers
sauimone
legend layouting change
r616 ,mMaximumSize(150,100)
sauimone
Scrolling logic to legend
r716 ,m_brush(Qt::darkGray) // TODO: from theme?
,mPreferredLayout(QLegend::PreferredLayoutTop)
,mFirstMarker(0)
,mMargin(5)
sauimone
framework for legend
r524 {
sauimone
Scrolling logic to legend
r716 // setVisible(false);
mScrollButtonLeft = new LegendScrollButton(LegendScrollButton::ScrollButtonIdLeft, this);
mScrollButtonRight = new LegendScrollButton(LegendScrollButton::ScrollButtonIdRight, this);
mScrollButtonUp = new LegendScrollButton(LegendScrollButton::ScrollButtonIdUp, this);
mScrollButtonDown = new LegendScrollButton(LegendScrollButton::ScrollButtonIdDown, this);
connect(mScrollButtonLeft,SIGNAL(clicked(QGraphicsSceneMouseEvent*)),this,SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*)));
connect(mScrollButtonRight,SIGNAL(clicked(QGraphicsSceneMouseEvent*)),this,SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*)));
connect(mScrollButtonUp,SIGNAL(clicked(QGraphicsSceneMouseEvent*)),this,SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*)));
connect(mScrollButtonDown,SIGNAL(clicked(QGraphicsSceneMouseEvent*)),this,SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*)));
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 setZValue(ChartPresenter::LegendZValue);
sauimone
framework for legend
r524 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Paints the legend to given \a painter. Paremeters \a option and \a widget arent used.
*/
sauimone
framework for legend
r524 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Tero Ahola
Squashed bunch of warnings
r611 Q_UNUSED(option)
Q_UNUSED(widget)
sauimone
layout fix to legend. Documented legend functions.
r724 painter->setOpacity(opacity());
Michal Klocek
Adds force option to chartTheme...
r645 painter->setPen(m_pen);
painter->setBrush(m_brush);
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 painter->drawRect(boundingRect());
sauimone
framework for legend
r524 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Bounding rect of legend.
*/
sauimone
framework for legend
r524 QRectF QLegend::boundingRect() const
{
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 return QRectF(mPos,mSize);
sauimone
framework for legend
r524 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Sets the \a brush of legend. Brush affects the background of legend.
*/
Michal Klocek
Adds force option to chartTheme...
r645 void QLegend::setBrush(const QBrush& brush)
sauimone
background to legend, theme applies
r540 {
Michal Klocek
Adds force option to chartTheme...
r645 if(m_brush!=brush){
m_brush = brush;
update();
}
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Returns the brush used by legend.
*/
Michal Klocek
Adds force option to chartTheme...
r645 QBrush QLegend::brush() const
{
return m_brush;
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Sets the \a pen of legend. Pen affects the legend borders.
*/
Michal Klocek
Adds force option to chartTheme...
r645 void QLegend::setPen(const QPen& pen)
{
if(m_pen!=pen){
m_pen = pen;
update();
}
sauimone
background to legend, theme applies
r540 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Returns the pen used by legend
*/
Michal Klocek
Adds force option to chartTheme...
r645 QPen QLegend::pen() const
sauimone
background to legend, theme applies
r540 {
Michal Klocek
Adds force option to chartTheme...
r645 return m_pen;
sauimone
background to legend, theme applies
r540 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Sets the \a preferred layout for legend. Legend tries to paint itself on the defined position in chart.
sa \QLegend::PreferredLayout
*/
sauimone
legend layouting change
r616 void QLegend::setPreferredLayout(QLegend::PreferredLayout preferred)
{
mPreferredLayout = preferred;
sauimone
Scrolling logic to legend
r716 updateLayout();
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Returns the preferred layout for legend
*/
sauimone
Scrolling logic to legend
r716 QLegend::PreferredLayout QLegend::preferredLayout() const
{
return mPreferredLayout;
sauimone
legend layouting change
r616 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Returns the maximum size of legend.
*/
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 QSizeF QLegend::maximumSize() const
sauimone
legend scaling with chart
r582 {
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 return mMaximumSize;
sauimone
legend scaling with chart
r582 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Sets the maximum \a size for legend. The legend can't grow bigger than this size. If there are
more series than legend can fit to this size, scroll buttons are displayed.
*/
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 void QLegend::setMaximumSize(const QSizeF size)
sauimone
legend scaling with chart
r582 {
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 mMaximumSize = size;
sauimone
Scrolling logic to legend
r716 updateLayout();
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Returns the current size of legend.
*/
QSizeF QLegend::size() const
{
return mSize;
}
/*!
Sets the \a size of legend. If size is bigger than maximum size of legend, the legend is resized to the maximum size.
\sa setMmaximumSize()
*/
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 void QLegend::setSize(const QSizeF size)
{
mSize = size;
if (mSize.width() > mMaximumSize.width()) {
mSize.setWidth(mMaximumSize.width());
}
if (mSize.height() > mMaximumSize.height()) {
mSize.setHeight(mMaximumSize.height());
}
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Sets position of legend to \a pos
*/
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 void QLegend::setPos(const QPointF &pos)
{
mPos = pos;
sauimone
Scrolling logic to legend
r716 updateLayout();
sauimone
legend scaling with chart
r582 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal \a series \a domain Should be called when series is added to chart.
*/
Tero Ahola
Squashed bunch of warnings
r611 void QLegend::handleSeriesAdded(QSeries* series, Domain* domain)
sauimone
framework for legend
r524 {
Tero Ahola
Squashed bunch of warnings
r611 Q_UNUSED(domain)
sauimone
handleThemeChanged slot to legend.
r586 createMarkers(series);
sauimone
Added handling for pieslice add/remove to legend
r637 connectSeries(series);
sauimone
Scrolling logic to legend
r716 updateLayout();
sauimone
handleThemeChanged slot to legend.
r586 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal \a series Should be called when series is removed from chart.
*/
sauimone
handleThemeChanged slot to legend.
r586 void QLegend::handleSeriesRemoved(QSeries* series)
{
sauimone
Added handling for pieslice add/remove to legend
r637 disconnectSeries(series);
sauimone
handleThemeChanged slot to legend.
r586 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);
}
sauimone
Scrolling logic to legend
r716 updateLayout();
sauimone
handleThemeChanged slot to legend.
r586 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal \a slices Should be called when slices are added to pie chart.
*/
sauimone
Added handling for pieslice add/remove to legend
r637 void QLegend::handleAdded(QList<QPieSlice*> slices)
{
QPieSeries* series = static_cast<QPieSeries*> (sender());
foreach(QPieSlice* s, slices) {
LegendMarker* marker = new LegendMarker(series,s,this);
marker->setName(s->label());
marker->setBrush(s->sliceBrush());
connect(marker,SIGNAL(clicked(QPieSlice*,Qt::MouseButton)),this,SIGNAL(clicked(QPieSlice*,Qt::MouseButton)));
connect(s,SIGNAL(changed()),marker,SLOT(changed()));
connect(s,SIGNAL(destroyed()),marker,SLOT(deleteLater()));
sauimone
fixed bug in legend marker removing
r643 connect(marker,SIGNAL(destroyed()),this,SLOT(handleMarkerDestroyed()));
sauimone
Added handling for pieslice add/remove to legend
r637 mMarkers.append(marker);
childItems().append(marker);
}
sauimone
Scrolling logic to legend
r716 updateLayout();
sauimone
Added handling for pieslice add/remove to legend
r637 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal \a slices Should be called when slices are removed from pie chart. Currently unused,
because removed slices are also deleted and we listen destroyed signal
*/
sauimone
fixed bug in legend marker removing
r643 void QLegend::handleRemoved(QList<QPieSlice *> slices)
{
Tero Ahola
Warnings treated as errors; fixed one
r647 Q_UNUSED(slices)
sauimone
fixed bug in legend marker removing
r643 // Propably no need to listen for this, since removed slices are deleted and we listen destroyed signal
// qDebug() << "QLegend::handleRemoved(QList<QPieSlice*> slices) count:" << slices.count();
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal Notifies legend that some marker has been removed. Sent by legend markers when destroyed
*/
sauimone
Added handling for pieslice add/remove to legend
r637 void QLegend::handleMarkerDestroyed()
{
// TODO: what if more than one markers are destroyed and we update layout after first one?
LegendMarker* m = static_cast<LegendMarker*> (sender());
mMarkers.removeOne(m);
sauimone
Scrolling logic to legend
r716 updateLayout();
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal \a event Handles clicked signals from scroll buttons
*/
sauimone
Scrolling logic to legend
r716 void QLegend::handleScrollButtonClicked(QGraphicsSceneMouseEvent *event)
{
sauimone
layout fix to legend. Documented legend functions.
r724 Q_UNUSED(event); // Maybe later something happens with right click...
sauimone
Scrolling logic to legend
r716
LegendScrollButton* scrollButton = static_cast<LegendScrollButton*> (sender());
Q_ASSERT(scrollButton);
switch (scrollButton->id()) {
case LegendScrollButton::ScrollButtonIdLeft:
case LegendScrollButton::ScrollButtonIdUp: {
// Lower limit is same in these cases
mFirstMarker--;
sauimone
layout fix to legend. Documented legend functions.
r724 checkFirstMarkerBounds();
sauimone
Scrolling logic to legend
r716 break;
}
case LegendScrollButton::ScrollButtonIdRight:
case LegendScrollButton::ScrollButtonIdDown: {
mFirstMarker++;
sauimone
layout fix to legend. Documented legend functions.
r724 checkFirstMarkerBounds();
sauimone
Scrolling logic to legend
r716 break;
}
default: {
break;
}
}
updateLayout();
sauimone
Added handling for pieslice add/remove to legend
r637 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal Connects the \a series to legend. Legend listens changes in series, for example pie slices added / removed.
Not all series notify about events
*/
sauimone
Added handling for pieslice add/remove to legend
r637 void QLegend::connectSeries(QSeries *series)
{
// Connect relevant signals from series
switch (series->type())
{
case QSeries::SeriesTypeLine: {
// QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
break;
}
case QSeries::SeriesTypeArea: {
// QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
break;
}
case QSeries::SeriesTypeBar: {
// QBarSeries* barSeries = static_cast<QBarSeries*>(series);
break;
}
case QSeries::SeriesTypeStackedBar: {
// QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
break;
}
case QSeries::SeriesTypePercentBar: {
// QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
break;
}
case QSeries::SeriesTypeScatter: {
// QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
break;
}
case QSeries::SeriesTypePie: {
QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>)));
// connect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleRemoved(QList<QPieSlice*>)));
break;
}
case QSeries::SeriesTypeSpline: {
// QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
break;
}
default: {
qDebug()<< "QLegend::connectSeries" << series->type() << "not implemented.";
break;
}
}
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal Disconnects \a series from legend. No more status updates from series to legend.
*/
sauimone
Added handling for pieslice add/remove to legend
r637 void QLegend::disconnectSeries(QSeries *series)
{
// Connect relevant signals from series
switch (series->type())
{
case QSeries::SeriesTypeLine: {
// QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
break;
}
case QSeries::SeriesTypeArea: {
// QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
break;
}
case QSeries::SeriesTypeBar: {
// QBarSeries* barSeries = static_cast<QBarSeries*>(series);
break;
}
case QSeries::SeriesTypeStackedBar: {
// QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
break;
}
case QSeries::SeriesTypePercentBar: {
// QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
break;
}
case QSeries::SeriesTypeScatter: {
// QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
break;
}
case QSeries::SeriesTypePie: {
QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
disconnect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>)));
// disconnect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleRemoved(QList<QPieSlice*>)));
break;
}
case QSeries::SeriesTypeSpline: {
// QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
break;
}
default: {
qDebug()<< "QLegend::disconnectSeries" << series->type() << "not implemented.";
break;
}
}
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal Creates new markers for \a series. Marker contains the colored rectangle and series name.
With pie chart, created markers depend on pie slices.
With bar chart, created markers depend on bar sets.
*/
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
layout fix to legend. Documented legend functions.
r724 /*!
\internal Helper function. Appends markers from \a series to legend.
*/
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());
sauimone
layout fix to legend. Documented legend functions.
r724 marker->setPen(series->pen());
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 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
Added handling for pieslice add/remove to legend
r637 connect(marker,SIGNAL(destroyed()),this,SLOT(handleMarkerDestroyed()));
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 mMarkers.append(marker);
childItems().append(marker);
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal Helper function. Appends markers from \a series to legend.
*/
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());
sauimone
layout fix to legend. Documented legend functions.
r724 marker->setPen(s->pen());
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 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
fixed changed singal name in legend
r670 connect(s,SIGNAL(valueChanged()),marker,SLOT(changed()));
sauimone
Added handling for pieslice add/remove to legend
r637 connect(marker,SIGNAL(destroyed()),this,SLOT(handleMarkerDestroyed()));
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
layout fix to legend. Documented legend functions.
r724 /*!
\internal Helper function. Appends markers from \a series to legend.
*/
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());
sauimone
layout fix to legend. Documented legend functions.
r724 marker->setPen(s->slicePen());
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 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
Added handling for pieslice add/remove to legend
r637 connect(s,SIGNAL(destroyed()),marker,SLOT(deleteLater()));
connect(marker,SIGNAL(destroyed()),this,SLOT(handleMarkerDestroyed()));
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
layout fix to legend. Documented legend functions.
r724 /*!
\internal Deletes all markers that are created from \a series
*/
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
layout fix to legend. Documented legend functions.
r724 /*!
\internal Updates layout of legend. Tries to fit as many markers as possible up to the maximum size of legend.
If items don't fit, sets the visibility of scroll buttons accordingly.
Causes legend to be resized.
*/
sauimone
Scrolling logic to legend
r716 void QLegend::updateLayout()
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529 {
// Calculate layout for markers and text
if (mMarkers.count() <= 0) {
// Nothing to do
return;
}
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 // Find out widest item.
sauimone
Scrolling logic to legend
r716 QSizeF markerMaxSize = maximumMarkerSize();
sauimone
layout fix to legend. Documented legend functions.
r724 checkFirstMarkerBounds();
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626
sauimone
Scrolling logic to legend
r716 // Use max height as scroll button size
rescaleScrollButtons(QSize(markerMaxSize.height() ,markerMaxSize.height()));
sauimone
legend layouting change
r616
sauimone
layout fix to legend. Documented legend functions.
r724
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 qreal totalWidth = 0;
qreal totalHeight = 0;
sauimone
legend layouting change
r616 switch (mPreferredLayout)
{
sauimone
Scrolling logic to legend
r716 // Both cases organise items horizontally
case QLegend::PreferredLayoutBottom:
case QLegend::PreferredLayoutTop: {
qreal xStep = markerMaxSize.width();
qreal x = mPos.x() + mMargin;
qreal y = mPos.y() + mMargin;
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 int column = 0;
int maxColumns = 1;
sauimone
layout fix to legend. Documented legend functions.
r724 qreal scrollButtonWidth = 0;
sauimone
Scrolling logic to legend
r716
// Set correct visibility for scroll scrollbuttons
if (scrollButtonsVisible()) {
mScrollButtonLeft->setVisible(true);
mScrollButtonRight->setVisible(true);
totalWidth += (mScrollButtonLeft->boundingRect().width() + mMargin) * 2; // scrollbuttons visible, so add their width to total width
sauimone
layout fix to legend. Documented legend functions.
r724 scrollButtonWidth = mScrollButtonLeft->boundingRect().width() + mMargin;
x += scrollButtonWidth; // start position changes by scrollbutton width
sauimone
Scrolling logic to legend
r716 } else {
mScrollButtonLeft->setVisible(false);
mScrollButtonRight->setVisible(false);
}
mScrollButtonUp->setVisible(false);
mScrollButtonDown->setVisible(false);
for (int i=0; i<mMarkers.count(); i++) {
LegendMarker* m = mMarkers.at(i);
if (i<mFirstMarker) {
// Markers before first are not visible.
m->setVisible(false);
} else {
sauimone
layout fix to legend. Documented legend functions.
r724 if ((x + xStep + scrollButtonWidth + mMargin) > (mPos.x() + mMaximumSize.width())) {
sauimone
Scrolling logic to legend
r716 // This marker would go outside legend rect.
m->setVisible(false);
} else {
// This marker is ok
m->setVisible(true);
m->setPos(x,y);
x += xStep;
column++;
}
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 }
sauimone
Scrolling logic to legend
r716 maxColumns = column;
sauimone
legend layouting change
r616 }
sauimone
Scrolling logic to legend
r716
mScrollButtonLeft->setPos(mPos.x() + mMargin, y);
mScrollButtonRight->setPos(x+mMargin,y);
totalWidth += maxColumns * markerMaxSize.width() + mMargin * 2;
totalHeight = markerMaxSize.height() + mMargin * 2;
sauimone
legend layouting change
r616 break;
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529 }
sauimone
Scrolling logic to legend
r716 // Both cases organize items vertically
case QLegend::PreferredLayoutLeft:
case QLegend::PreferredLayoutRight: {
qreal yStep = markerMaxSize.height();
qreal x = mPos.x() + mMargin;
qreal y = mPos.y() + mMargin;
int row = 1;
int maxRows = 1;
sauimone
layout fix to legend. Documented legend functions.
r724 qreal scrollButtonHeight = 0;
sauimone
Scrolling logic to legend
r716
// Set correct visibility for scroll scrollbuttons
if (scrollButtonsVisible()) {
mScrollButtonUp->setVisible(true);
mScrollButtonDown->setVisible(true);
totalHeight += (mScrollButtonUp->boundingRect().height() + mMargin) * 2; // scrollbuttons visible, so add their height to total height
sauimone
layout fix to legend. Documented legend functions.
r724 scrollButtonHeight = mScrollButtonUp->boundingRect().height();
y += scrollButtonHeight + mMargin; // start position changes by scrollbutton height
sauimone
Scrolling logic to legend
r716 } else {
mScrollButtonUp->setVisible(false);
mScrollButtonDown->setVisible(false);
sauimone
legend layouting change
r616 }
sauimone
Scrolling logic to legend
r716 mScrollButtonLeft->setVisible(false);
mScrollButtonRight->setVisible(false);
for (int i=0; i<mMarkers.count(); i++) {
LegendMarker* m = mMarkers.at(i);
if (i<mFirstMarker) {
// Markers before first are not visible.
m->setVisible(false);
} else {
sauimone
layout fix to legend. Documented legend functions.
r724 if ((y + yStep + scrollButtonHeight) > (mPos.y() + mMaximumSize.height())) {
sauimone
Scrolling logic to legend
r716 // This marker would go outside legend rect.
m->setVisible(false);
} else {
// This marker is ok
m->setVisible(true);
m->setPos(x,y);
y += yStep;
row++;
}
}
maxRows = row;
}
mScrollButtonUp->setPos(mPos.x() + mMargin, mPos.y() + mMargin);
mScrollButtonDown->setPos(mPos.x() + mMargin, y + mMargin);
totalWidth += markerMaxSize.width() + mMargin * 2;
sauimone
layout fix to legend. Documented legend functions.
r724 totalHeight = maxRows * markerMaxSize.height() + mMargin * 4 + scrollButtonHeight; // TODO: check this
sauimone
legend layouting change
r616 break;
}
default: {
break;
}
}
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 mSize.setWidth(totalWidth);
mSize.setHeight(totalHeight);
sauimone
Scrolling logic to legend
r716
update();
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal Sets the size of scroll buttons to \a size
*/
sauimone
Scrolling logic to legend
r716 void QLegend::rescaleScrollButtons(const QSize &size)
{
QPolygonF left;
left << QPointF(size.width(),0) << QPointF(0,size.height()/2) << QPointF(size.width(),size.height());
QPolygonF right;
right << QPointF(0,0) << QPointF(size.width(),size.height()/2) << QPointF(0,size.height());
QPolygonF up;
up << QPointF(0,size.height()) << QPointF(size.width()/2,0) << QPointF(size.width(),size.height());
QPolygonF down;
down << QPointF(0,0) << QPointF(size.width()/2,size.height()) << QPointF(size.width(),0);
mScrollButtonLeft->setPolygon(left);
mScrollButtonRight->setPolygon(right);
mScrollButtonUp->setPolygon(up);
mScrollButtonDown->setPolygon(down);
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal Finds out maximum size of single marker. Marker sizes depend on series names.
*/
sauimone
Scrolling logic to legend
r716 QSizeF QLegend::maximumMarkerSize()
{
QSizeF max(0,0);
foreach (LegendMarker* m, mMarkers) {
if (m->boundingRect().width() > max.width()) {
max.setWidth(m->boundingRect().width());
}
if (m->boundingRect().height() > max.height()) {
max.setHeight(m->boundingRect().height());
}
}
return max;
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal Checks that first marker is in acceptable bounds. Bounds range from 0 to (maximum number of markers - visible markers)
If scrollbuttons are visible, they affect the number of visible markers.
*/
void QLegend::checkFirstMarkerBounds()
sauimone
Scrolling logic to legend
r716 {
if ((mPreferredLayout == QLegend::PreferredLayoutLeft) || (mPreferredLayout == QLegend::PreferredLayoutRight)) {
sauimone
layout fix to legend. Documented legend functions.
r724 // Bounds limited by height.
sauimone
Scrolling logic to legend
r716 int max;
if (scrollButtonsVisible()) {
sauimone
layout fix to legend. Documented legend functions.
r724 max = (mMaximumSize.height() - mScrollButtonLeft->boundingRect().height() * 2 - mMargin*4) / maximumMarkerSize().height();
sauimone
Scrolling logic to legend
r716 } else {
max = mMaximumSize.height() / maximumMarkerSize().height();
}
if (mFirstMarker > mMarkers.count() - max) {
mFirstMarker = mMarkers.count() - max;
}
} else {
// Bounds limited by width
int max;
if (scrollButtonsVisible()) {
sauimone
layout fix to legend. Documented legend functions.
r724 max = (mMaximumSize.width() - mScrollButtonLeft->boundingRect().width() * 2 - mMargin*4) / maximumMarkerSize().width();
sauimone
Scrolling logic to legend
r716 } else {
max = mMaximumSize.width() / maximumMarkerSize().width();
}
if (mFirstMarker > mMarkers.count() - max) {
mFirstMarker = mMarkers.count() - max;
}
}
if (mFirstMarker < 0) {
mFirstMarker = 0;
}
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
\internal Helper function. Visibility of scroll buttons isn't quite obvious, so helper function clarifies the logic.
*/
sauimone
Scrolling logic to legend
r716 bool QLegend::scrollButtonsVisible()
{
// Just a helper to clarify, what the magic below means :)
if ((mPreferredLayout == QLegend::PreferredLayoutTop) || (mPreferredLayout == QLegend::PreferredLayoutBottom)) {
sauimone
layout fix to legend. Documented legend functions.
r724 return (maximumMarkerSize().width() * mMarkers.count() + mMargin * 2 > mMaximumSize.width());
} else if ((mPreferredLayout == QLegend::PreferredLayoutLeft) || (mPreferredLayout == QLegend::PreferredLayoutRight)) {
return (maximumMarkerSize().height() * mMarkers.count() + mMargin * 2 > mMaximumSize.height());
sauimone
Scrolling logic to legend
r716 }
sauimone
layout fix to legend. Documented legend functions.
r724
return (maximumMarkerSize().height() * mMarkers.count() + mMargin * 2 > mMaximumSize.height());
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