##// END OF EJS Templates
removed legend background drawing
removed legend background drawing

File last commit:

r785:fe2ea9e69ee8
r785:fe2ea9e69ee8
Show More
qlegend.cpp
706 lines | 21.9 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
legend documentation fix. detaching and attaching the legend
r728 /*!
\class QLegend
\brief part of QtCommercial chart API.
QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
handle the drawing manually.
User isn't supposed to create or delete legend objects, but can reference it via QChart class.
\mainclass
\sa QChart, QSeries
*/
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
sauimone
legend fixes
r766 \enum QLegend::Layout
sauimone
layout fix to legend. Documented legend functions.
r724
This enum describes the possible position for legend inside chart.
sauimone
legend fixes
r766 \value LayoutTop
\value LayoutBottom
\value LayoutLeft
\value LayoutRight
sauimone
layout fix to legend. Documented legend functions.
r724 */
/*!
sauimone
legend documentation fix. detaching and attaching the legend
r728 \fn void QLegend::clicked(QSeries* series, Qt::MouseButton button)
sauimone
layout fix to legend. Documented legend functions.
r724 \brief Notifies when series has been clicked on legend \a series \a button
*/
/*!
sauimone
legend documentation fix. detaching and attaching the legend
r728 \fn void QLegend::clicked(QBarSet* barset, Qt::MouseButton button)
sauimone
layout fix to legend. Documented legend functions.
r724 \brief Notifies when barset has been clicked on legend \a barset \a button
*/
/*!
sauimone
legend documentation fix. detaching and attaching the legend
r728 \fn void QLegend::clicked(QPieSlice* slice, Qt::MouseButton button)
sauimone
layout fix to legend. Documented legend functions.
r724 \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
minor code review fixes
r762 QLegend::QLegend(QGraphicsItem *parent) : QGraphicsObject(parent),
sauimone
improved legend layout
r783 m_margin(5),
sauimone
legend fixes
r766 m_pos(0,0),
m_minimumSize(50,20), // TODO: magic numbers
m_maximumSize(150,100),
sauimone
improved legend layout
r783 m_size(m_minimumSize),
sauimone
removed legend background drawing
r785 m_brush(Qt::darkGray), // TODO: default should come from theme
sauimone
legend fixes
r766 m_alignment(QLegend::LayoutTop),
sauimone
improved legend layout
r783 mFirstMarker(0)
sauimone
minor code review fixes
r762 {
sauimone
legend fixes
r766 m_scrollButtonLeft = new LegendScrollButton(LegendScrollButton::ScrollButtonIdLeft, this);
m_scrollButtonRight = new LegendScrollButton(LegendScrollButton::ScrollButtonIdRight, this);
m_scrollButtonUp = new LegendScrollButton(LegendScrollButton::ScrollButtonIdUp, this);
m_scrollButtonDown = new LegendScrollButton(LegendScrollButton::ScrollButtonIdDown, this);
sauimone
minor code review fixes
r762
sauimone
legend fixes
r766 connect(m_scrollButtonLeft, SIGNAL(clicked(QGraphicsSceneMouseEvent*)),
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*)));
sauimone
legend fixes
r766 connect(m_scrollButtonRight, SIGNAL(clicked(QGraphicsSceneMouseEvent*)),
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*)));
sauimone
legend fixes
r766 connect(m_scrollButtonUp, SIGNAL(clicked(QGraphicsSceneMouseEvent*)),
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*)));
sauimone
legend fixes
r766 connect(m_scrollButtonDown, SIGNAL(clicked(QGraphicsSceneMouseEvent*)),
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*)));
sauimone
Scrolling logic to legend
r716
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
removed legend background drawing
r785 // 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
legend fixes
r766 return QRectF(m_pos,m_size);
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.
*/
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 void QLegend::setBrush(const QBrush &brush)
sauimone
background to legend, theme applies
r540 {
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 if (m_brush != brush) {
Michal Klocek
Adds force option to chartTheme...
r645 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.
*/
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 void QLegend::setPen(const QPen &pen)
Michal Klocek
Adds force option to chartTheme...
r645 {
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 if (m_pen != pen) {
Michal Klocek
Adds force option to chartTheme...
r645 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.
sauimone
legend fixes
r766 \sa QLegend::Layout
sauimone
layout fix to legend. Documented legend functions.
r724 */
sauimone
legend fixes
r766 void QLegend::setAlignmnent(QLegend::Layout alignment)
sauimone
legend layouting change
r616 {
sauimone
legend fixes
r766 m_alignment = alignment;
sauimone
Scrolling logic to legend
r716 updateLayout();
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Returns the preferred layout for legend
*/
sauimone
legend fixes
r766 QLegend::Layout QLegend::alignment() const
sauimone
Scrolling logic to legend
r716 {
sauimone
legend fixes
r766 return m_alignment;
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
legend fixes
r766 return m_maximumSize;
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
legend fixes
r766 m_maximumSize = 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
{
sauimone
legend fixes
r766 return m_size;
sauimone
layout fix to legend. Documented legend functions.
r724 }
/*!
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)
{
sauimone
legend fixes
r766 m_size = size;
if (m_size.width() > m_maximumSize.width()) {
m_size.setWidth(m_maximumSize.width());
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 }
sauimone
legend fixes
r766 if (m_size.height() > m_maximumSize.height()) {
m_size.setHeight(m_maximumSize.height());
sauimone
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 }
}
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)
{
sauimone
legend fixes
r766 m_pos = 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
Code review: Fixed simple issues in Bar and Legend
r737 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.
*/
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 void QLegend::handleSeriesRemoved(QSeries *series)
sauimone
handleThemeChanged slot to legend.
r586 {
sauimone
Added handling for pieslice add/remove to legend
r637 disconnectSeries(series);
sauimone
legend fixes
r766 if (series->type() == QSeries::SeriesTypeArea) {
sauimone
handleThemeChanged slot to legend.
r586 // This is special case. Area series has upper and lower series, which each have markers
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 QAreaSeries* s = static_cast<QAreaSeries *> (series);
sauimone
handleThemeChanged slot to legend.
r586 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.
*/
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 void QLegend::handleAdded(QList<QPieSlice *> slices)
sauimone
Added handling for pieslice add/remove to legend
r637 {
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 QPieSeries* series = static_cast<QPieSeries *> (sender());
sauimone
Added handling for pieslice add/remove to legend
r637 foreach(QPieSlice* s, slices) {
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 LegendMarker* marker = new LegendMarker(series, s, this);
sauimone
Added handling for pieslice add/remove to legend
r637 marker->setName(s->label());
Jani Honkonen
remove "slice" word from pen/brush setters/getters
r756 marker->setBrush(s->brush());
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 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()));
connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed()));
sauimone
legend fixes
r766 m_markers.append(marker);
sauimone
Added handling for pieslice add/remove to legend
r637 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 }
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()
{
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 LegendMarker* m = static_cast<LegendMarker *> (sender());
sauimone
legend fixes
r766 m_markers.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
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 LegendScrollButton* scrollButton = static_cast<LegendScrollButton *> (sender());
sauimone
Scrolling logic to legend
r716 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)
{
sauimone
legend fixes
r766 // Connect relevant signals from series. Currently only pie series has interesting signals
// TODO: bar chart may have
if (series->type() == QSeries::SeriesTypePie) {
sauimone
Added handling for pieslice add/remove to legend
r637 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>)));
}
}
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)
{
sauimone
legend fixes
r766 if (series->type() == QSeries::SeriesTypePie) {
sauimone
Added handling for pieslice add/remove to legend
r637 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 disconnect(pieSeries, SIGNAL(added(QList<QPieSlice *>)), this, SLOT(handleAdded(QList<QPieSlice *>)));
sauimone
Added handling for pieslice add/remove to legend
r637 }
}
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: {
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 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: {
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 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())
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 appendMarkers(areaSeries->lowerSeries());
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 break;
}
case QSeries::SeriesTypeBar: {
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 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: {
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 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: {
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 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: {
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 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
legend fixes
r766 qWarning()<< "QLegend::createMarkers" << series->type() << "unknown series type.";
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());
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 connect(marker, SIGNAL(clicked(QSeries *, Qt::MouseButton)), this, SIGNAL(clicked(QSeries *, Qt::MouseButton)));
connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed()));
sauimone
legend fixes
r766 m_markers.append(marker);
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 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()) {
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 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());
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 connect(marker, SIGNAL(clicked(QBarSet *, Qt::MouseButton)),
this, SIGNAL(clicked(QBarSet *, Qt::MouseButton)));
connect(s, SIGNAL(valueChanged()), marker, SLOT(changed()));
connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed()));
sauimone
legend fixes
r766 m_markers.append(marker);
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 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()) {
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 LegendMarker* marker = new LegendMarker(series, s, this);
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 marker->setName(s->label());
Jani Honkonen
remove "slice" word from pen/brush setters/getters
r756 marker->setPen(s->pen());
marker->setBrush(s->brush());
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 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()));
connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed()));
sauimone
legend fixes
r766 m_markers.append(marker);
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 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.
sauimone
legend fixes
r766 foreach (LegendMarker *m, m_markers) {
sauimone
handleThemeChanged slot to legend.
r586 if (m->series() == series) {
sauimone
legend fixes
r766 m_markers.removeOne(m);
sauimone
handleThemeChanged slot to legend.
r586 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
sauimone
legend fixes
r766 if (m_markers.count() <= 0) {
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529 // 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
Adaptive layout to legend. Tries to fit all items inside given maximum size
r626 qreal totalWidth = 0;
qreal totalHeight = 0;
sauimone
legend fixes
r766 switch (m_alignment)
sauimone
legend layouting change
r616 {
sauimone
Scrolling logic to legend
r716 // Both cases organise items horizontally
sauimone
legend fixes
r766 case QLegend::LayoutBottom:
case QLegend::LayoutTop: {
sauimone
Scrolling logic to legend
r716
qreal xStep = markerMaxSize.width();
sauimone
legend fixes
r766 qreal x = m_pos.x() + m_margin;
qreal y = m_pos.y() + m_margin;
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()) {
sauimone
legend fixes
r766 m_scrollButtonLeft->setVisible(true);
m_scrollButtonRight->setVisible(true);
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 // scrollbuttons visible, so add their width to total width
sauimone
legend fixes
r766 totalWidth += (m_scrollButtonLeft->boundingRect().width() + m_margin) * 2;
scrollButtonWidth = m_scrollButtonLeft->boundingRect().width() + m_margin;
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 // start position changes by scrollbutton width
x += scrollButtonWidth;
sauimone
Scrolling logic to legend
r716 } else {
sauimone
legend fixes
r766 m_scrollButtonLeft->setVisible(false);
m_scrollButtonRight->setVisible(false);
sauimone
Scrolling logic to legend
r716 }
sauimone
legend fixes
r766 m_scrollButtonUp->setVisible(false);
m_scrollButtonDown->setVisible(false);
sauimone
Scrolling logic to legend
r716
sauimone
legend fixes
r766 for (int i=0; i < m_markers.count(); i++) {
LegendMarker *m = m_markers.at(i);
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 if (i < mFirstMarker) {
sauimone
Scrolling logic to legend
r716 // Markers before first are not visible.
m->setVisible(false);
} else {
sauimone
legend fixes
r766 if ((x + xStep + scrollButtonWidth + m_margin) > (m_pos.x() + m_maximumSize.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);
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 m->setPos(x, y);
sauimone
Scrolling logic to legend
r716 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
sauimone
legend fixes
r766 m_scrollButtonLeft->setPos(m_pos.x() + m_margin, y);
m_scrollButtonRight->setPos(x + m_margin, y);
sauimone
Scrolling logic to legend
r716
sauimone
legend fixes
r766 totalWidth += maxColumns * markerMaxSize.width() + m_margin * 2;
totalHeight = markerMaxSize.height() + m_margin * 2;
sauimone
Scrolling logic to legend
r716
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
sauimone
legend fixes
r766 case QLegend::LayoutLeft:
case QLegend::LayoutRight: {
sauimone
Scrolling logic to legend
r716 qreal yStep = markerMaxSize.height();
sauimone
legend fixes
r766 qreal x = m_pos.x() + m_margin;
qreal y = m_pos.y() + m_margin;
sauimone
Scrolling logic to legend
r716 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()) {
sauimone
legend fixes
r766 m_scrollButtonUp->setVisible(true);
m_scrollButtonDown->setVisible(true);
totalHeight += (m_scrollButtonUp->boundingRect().height() + m_margin) * 2; // scrollbuttons visible, so add their height to total height
scrollButtonHeight = m_scrollButtonUp->boundingRect().height();
y += scrollButtonHeight + m_margin; // start position changes by scrollbutton height
sauimone
Scrolling logic to legend
r716 } else {
sauimone
legend fixes
r766 m_scrollButtonUp->setVisible(false);
m_scrollButtonDown->setVisible(false);
sauimone
legend layouting change
r616 }
sauimone
legend fixes
r766 m_scrollButtonLeft->setVisible(false);
m_scrollButtonRight->setVisible(false);
sauimone
Scrolling logic to legend
r716
sauimone
legend fixes
r766 for (int i=0; i < m_markers.count(); i++) {
LegendMarker* m = m_markers.at(i);
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 if (i < mFirstMarker) {
sauimone
Scrolling logic to legend
r716 // Markers before first are not visible.
m->setVisible(false);
} else {
sauimone
legend fixes
r766 if ((y + yStep + scrollButtonHeight) > (m_pos.y() + m_maximumSize.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);
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 m->setPos(x, y);
sauimone
Scrolling logic to legend
r716 y += yStep;
row++;
}
}
maxRows = row;
}
sauimone
legend fixes
r766 m_scrollButtonUp->setPos(m_pos.x() + m_margin, m_pos.y() + m_margin);
m_scrollButtonDown->setPos(m_pos.x() + m_margin, y + m_margin);
sauimone
Scrolling logic to legend
r716
sauimone
legend fixes
r766 totalWidth += markerMaxSize.width() + m_margin * 2;
totalHeight = maxRows * markerMaxSize.height() + m_margin * 4 + scrollButtonHeight; // TODO: check this
sauimone
legend layouting change
r616 break;
}
default: {
break;
}
}
sauimone
legend fixes
r766 m_size.setWidth(totalWidth);
m_size.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;
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 left << QPointF(size.width(), 0) << QPointF(0, size.height() / 2) << QPointF(size.width(), size.height());
sauimone
Scrolling logic to legend
r716 QPolygonF right;
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 right << QPointF(0, 0) << QPointF(size.width(), size.height() / 2) << QPointF(0, size.height());
sauimone
Scrolling logic to legend
r716 QPolygonF up;
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 up << QPointF(0, size.height()) << QPointF(size.width() / 2,0) << QPointF(size.width(), size.height());
sauimone
Scrolling logic to legend
r716 QPolygonF down;
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 down << QPointF(0, 0) << QPointF(size.width() / 2, size.height()) << QPointF(size.width(), 0);
sauimone
Scrolling logic to legend
r716
sauimone
legend fixes
r766 m_scrollButtonLeft->setPolygon(left);
m_scrollButtonRight->setPolygon(right);
m_scrollButtonUp->setPolygon(up);
m_scrollButtonDown->setPolygon(down);
sauimone
Scrolling logic to legend
r716 }
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);
sauimone
legend fixes
r766 foreach (LegendMarker* m, m_markers) {
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 if (m->boundingRect().width() > max.width())
sauimone
Scrolling logic to legend
r716 max.setWidth(m->boundingRect().width());
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 if (m->boundingRect().height() > max.height())
sauimone
Scrolling logic to legend
r716 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 {
sauimone
legend fixes
r766 if ((m_alignment == QLegend::LayoutLeft) || (m_alignment == QLegend::LayoutRight)) {
sauimone
layout fix to legend. Documented legend functions.
r724 // Bounds limited by height.
sauimone
Scrolling logic to legend
r716 int max;
if (scrollButtonsVisible()) {
sauimone
legend fixes
r766 max = (m_maximumSize.height() - m_scrollButtonLeft->boundingRect().height() * 2 - m_margin * 4) / maximumMarkerSize().height();
sauimone
Scrolling logic to legend
r716 } else {
sauimone
legend fixes
r766 max = m_maximumSize.height() / maximumMarkerSize().height();
sauimone
Scrolling logic to legend
r716 }
sauimone
legend fixes
r766 if (mFirstMarker > m_markers.count() - max)
mFirstMarker = m_markers.count() - max;
sauimone
Scrolling logic to legend
r716 } else {
// Bounds limited by width
int max;
if (scrollButtonsVisible()) {
sauimone
legend fixes
r766 max = (m_maximumSize.width() - m_scrollButtonLeft->boundingRect().width() * 2 - m_margin*4) / maximumMarkerSize().width();
sauimone
Scrolling logic to legend
r716 } else {
sauimone
legend fixes
r766 max = m_maximumSize.width() / maximumMarkerSize().width();
sauimone
Scrolling logic to legend
r716 }
sauimone
legend fixes
r766 if (mFirstMarker > m_markers.count() - max)
mFirstMarker = m_markers.count() - max;
sauimone
Scrolling logic to legend
r716 }
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 if (mFirstMarker < 0)
sauimone
Scrolling logic to legend
r716 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 :)
sauimone
legend fixes
r766 if ((m_alignment == QLegend::LayoutTop) || (m_alignment == QLegend::LayoutBottom)) {
return (maximumMarkerSize().width() * m_markers.count() + m_margin * 2 > m_maximumSize.width());
} else if ((m_alignment == QLegend::LayoutLeft) || (m_alignment == QLegend::LayoutRight)) {
return (maximumMarkerSize().height() * m_markers.count() + m_margin * 2 > m_maximumSize.height());
sauimone
Scrolling logic to legend
r716 }
sauimone
layout fix to legend. Documented legend functions.
r724
sauimone
legend fixes
r766 return (maximumMarkerSize().height() * m_markers.count() + m_margin * 2 > m_maximumSize.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"
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737
sauimone
framework for legend
r524 QTCOMMERCIALCHART_END_NAMESPACE