##// END OF EJS Templates
Warnings are errors, fixed one in barvalue.cpp
Warnings are errors, fixed one in barvalue.cpp

File last commit:

r810:c712716bc681
r816:75470b1f1776
Show More
qlegend.cpp
751 lines | 22.0 KiB | text/x-c | CppLexer
Jani Honkonen
Add license headers
r794 /****************************************************************************
**
** 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
framework for legend
r524 #include "qlegend.h"
Michal Klocek
Fix attempt to wrong graphics items hadnling
r790 #include "qchart_p.h"
sauimone
framework for legend
r524 #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
*/
Michal Klocek
Fixes previous commit
r791 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
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
solid brush for all legend markers
r800 m_alignment(QLegend::AlignmentTop),
sauimone
legend layout with padding
r799 mFirstMarker(0),
sauimone
legend pos to theme example, legend padding
r803 m_attachedToChart(true),
m_chart(chart)
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
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 pos to theme example, legend padding
r803 void QLegend::setAlignmnent(QLegend::Alignments alignment)
sauimone
legend layouting change
r616 {
sauimone
legend pos to theme example, legend padding
r803 // if (!m_attachedToChart) {
m_alignment = alignment;
updateLayout();
m_chart->resize(m_chart->size());
// }
sauimone
Scrolling logic to legend
r716 }
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
Returns the preferred layout for legend
*/
sauimone
legend pos to theme example, legend padding
r803 QLegend::Alignments 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
legend refactoring.
r792 switch (series->type())
{
case QSeries::SeriesTypeLine: {
QLineSeries *lineSeries = static_cast<QLineSeries *>(series);
appendMarkers(lineSeries);
break;
}
case QSeries::SeriesTypeArea: {
QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series);
appendMarkers(areaSeries);
break;
}
case QSeries::SeriesTypeBar: {
QBarSeries *barSeries = static_cast<QBarSeries *>(series);
appendMarkers(barSeries);
break;
}
case QSeries::SeriesTypeStackedBar: {
QStackedBarSeries *stackedBarSeries = static_cast<QStackedBarSeries *>(series);
appendMarkers(stackedBarSeries);
break;
}
case QSeries::SeriesTypePercentBar: {
QPercentBarSeries *percentBarSeries = static_cast<QPercentBarSeries *>(series);
appendMarkers(percentBarSeries);
break;
}
case QSeries::SeriesTypeScatter: {
QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
appendMarkers(scatterSeries);
break;
}
case QSeries::SeriesTypePie: {
QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
appendMarkers(pieSeries);
connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>)));
break;
}
case QSeries::SeriesTypeSpline: {
QSplineSeries *splineSeries = static_cast<QSplineSeries *>(series);
appendMarkers(splineSeries);
break;
}
default: {
qWarning()<< "QLegend::handleSeriesAdded" << series->type() << "unknown series type.";
break;
}
}
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
legend refactoring.
r792 switch (series->type())
{
case QSeries::SeriesTypeArea: {
QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series);
deleteMarkers(areaSeries);
break;
}
case QSeries::SeriesTypePie: {
QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
disconnect(pieSeries, SIGNAL(added(QList<QPieSlice *>)), this, SLOT(handleAdded(QList<QPieSlice *>)));
deleteMarkers(series);
break;
}
default: {
// All other types
sauimone
handleThemeChanged slot to legend.
r586 deleteMarkers(series);
sauimone
legend refactoring.
r792 break;
}
sauimone
handleThemeChanged slot to legend.
r586 }
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
*/
Michal Klocek
Fix attempt to wrong graphics items hadnling
r790 void QLegend::scrollButtonClicked(LegendScrollButton *scrollButton)
sauimone
Scrolling logic to legend
r716 {
Michal Klocek
Fix attempt to wrong graphics items hadnling
r790 Q_ASSERT(scrollButton);
sauimone
Scrolling logic to legend
r716
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
legend layout with padding
r799 /*!
Detaches the legend from chart. Chart won't change layout of the legend.
*/
void QLegend::detachFromChart()
{
m_attachedToChart = false;
}
/*!
Attaches the legend to chart. Chart may change layout of the legend.
*/
void QLegend::attachToChart()
{
m_attachedToChart = true;
}
/*!
Returns true, if legend is attached to chart.
*/
bool QLegend::attachedToChart()
{
return m_attachedToChart;
}
sauimone
layout fix to legend. Documented legend functions.
r724 /*!
sauimone
legend refactoring.
r792 \internal Helper function. Appends markers from \a series to legend.
sauimone
layout fix to legend. Documented legend functions.
r724 */
sauimone
legend refactoring.
r792 void QLegend::appendMarkers(QAreaSeries* series)
sauimone
handleThemeChanged slot to legend.
r586 {
sauimone
legend refactoring.
r792 LegendMarker* marker = new LegendMarker(series,this);
connect(marker, SIGNAL(clicked(QSeries *, Qt::MouseButton)), this, SIGNAL(clicked(QSeries *, Qt::MouseButton)));
connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed()));
connect(series,SIGNAL(updated()),marker,SLOT(changed()));
sauimone
solid brush for all legend markers
r800 marker->changed();
sauimone
legend refactoring.
r792 m_markers.append(marker);
childItems().append(marker);
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);
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 refactoring.
r792 connect(series,SIGNAL(updated()),marker,SLOT(changed()));
sauimone
solid brush for all legend markers
r800 marker->changed();
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 /*!
sauimone
legend refactoring.
r792 \internal Helper function. Appends markers from \a series to legend.
sauimone
layout fix to legend. Documented legend functions.
r724 */
sauimone
handleThemeChanged slot to legend.
r586 void QLegend::appendMarkers(QBarSeries *series)
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 {
sauimone
updated theme example. minor fix to legend
r786 foreach(QBarSet* set, series->barSets()) {
LegendMarker* marker = new LegendMarker(series, set, this);
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)));
sauimone
updated theme example. minor fix to legend
r786 connect(set, SIGNAL(valueChanged()), marker, SLOT(changed()));
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed()));
sauimone
solid brush for all legend markers
r800 marker->changed();
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 /*!
sauimone
legend refactoring.
r792 \internal Helper function. Appends markers from \a series to legend.
sauimone
layout fix to legend. Documented legend functions.
r724 */
sauimone
handleThemeChanged slot to legend.
r586 void QLegend::appendMarkers(QPieSeries *series)
sauimone
more intelligent legend. fixed compiler warning in bar.cpp
r565 {
sauimone
updated theme example. minor fix to legend
r786 foreach(QPieSlice* slice, series->slices()) {
LegendMarker* marker = new LegendMarker(series, slice, this);
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)));
sauimone
updated theme example. minor fix to legend
r786 connect(slice, SIGNAL(changed()), marker, SLOT(changed()));
connect(slice, SIGNAL(destroyed()), marker, SLOT(deleteLater()));
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed()));
sauimone
solid brush for all legend markers
r800 marker->changed();
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
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
legend fixes
r766 switch (m_alignment)
sauimone
legend layouting change
r616 {
sauimone
Scrolling logic to legend
r716 // Both cases organise items horizontally
sauimone
legend layout with padding
r799 case QLegend::AlignmentBottom:
case QLegend::AlignmentTop: {
sauimone
split legend layout to vertical and horizontal functions
r810 layoutHorizontal();
break;
}
// Both cases organize items vertically
case QLegend::AlignmentLeft:
case QLegend::AlignmentRight: {
layoutVertical();
break;
}
default: {
break;
}
}
sauimone
Scrolling logic to legend
r716
sauimone
split legend layout to vertical and horizontal functions
r810 }
/*!
\internal Organizes markers horizontally.
Causes legend to be resized.
*/
void QLegend::layoutHorizontal()
{
// Find out widest item.
QSizeF markerMaxSize = maximumMarkerSize();
// Use max height as scroll button size
rescaleScrollButtons(QSize(markerMaxSize.height() ,markerMaxSize.height()));
sauimone
Scrolling logic to legend
r716
sauimone
split legend layout to vertical and horizontal functions
r810 qreal totalWidth = 0;
qreal totalHeight = 0;
qreal xStep = markerMaxSize.width();
qreal x = m_pos.x() + m_margin;
qreal y = m_pos.y() + m_margin;
int column = 0;
int maxColumns = 1;
qreal scrollButtonWidth = 0;
// Set correct visibility for scroll scrollbuttons
if (scrollButtonsVisible()) {
m_scrollButtonLeft->setVisible(true);
m_scrollButtonRight->setVisible(true);
// scrollbuttons visible, so add their width to total width
totalWidth += (m_scrollButtonLeft->boundingRect().width() + m_margin) * 2;
scrollButtonWidth = m_scrollButtonLeft->boundingRect().width() + m_margin;
// start position changes by scrollbutton width
x += scrollButtonWidth;
} else {
m_scrollButtonLeft->setVisible(false);
m_scrollButtonRight->setVisible(false);
}
m_scrollButtonUp->setVisible(false);
m_scrollButtonDown->setVisible(false);
for (int i=0; i < m_markers.count(); i++) {
LegendMarker *m = m_markers.at(i);
if (i < mFirstMarker) {
// Markers before first are not visible.
m->setVisible(false);
} else {
if ((x + xStep + scrollButtonWidth + m_margin) > (m_pos.x() + m_maximumSize.width())) {
// This marker would go outside legend rect.
sauimone
Scrolling logic to legend
r716 m->setVisible(false);
} else {
sauimone
split legend layout to vertical and horizontal functions
r810 // 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
legend layouting change
r616 }
sauimone
split legend layout to vertical and horizontal functions
r810 maxColumns = column;
}
sauimone
Scrolling logic to legend
r716
sauimone
split legend layout to vertical and horizontal functions
r810 m_scrollButtonLeft->setPos(m_pos.x() + m_margin, y);
m_scrollButtonRight->setPos(x + m_margin, y);
sauimone
Scrolling logic to legend
r716
sauimone
split legend layout to vertical and horizontal functions
r810 totalWidth += maxColumns * markerMaxSize.width() + m_margin * 2;
totalHeight = markerMaxSize.height() + m_margin * 2;
sauimone
Scrolling logic to legend
r716
sauimone
split legend layout to vertical and horizontal functions
r810 m_size.setWidth(totalWidth);
m_size.setHeight(totalHeight);
}
/*!
\internal Organizes markers vertically.
Causes legend to be resized.
*/
void QLegend::layoutVertical()
{
// Find out widest item.
QSizeF markerMaxSize = maximumMarkerSize();
// Use max height as scroll button size
rescaleScrollButtons(QSize(markerMaxSize.height() ,markerMaxSize.height()));
qreal totalWidth = 0;
qreal totalHeight = 0;
qreal yStep = markerMaxSize.height();
qreal x = m_pos.x() + m_margin;
qreal y = m_pos.y() + m_margin;
int row = 1;
int maxRows = 1;
qreal scrollButtonHeight = 0;
// Set correct visibility for scroll scrollbuttons
if (scrollButtonsVisible()) {
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
} else {
m_scrollButtonUp->setVisible(false);
m_scrollButtonDown->setVisible(false);
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529 }
sauimone
split legend layout to vertical and horizontal functions
r810 m_scrollButtonLeft->setVisible(false);
m_scrollButtonRight->setVisible(false);
for (int i=0; i < m_markers.count(); i++) {
LegendMarker* m = m_markers.at(i);
if (i < mFirstMarker) {
// Markers before first are not visible.
m->setVisible(false);
sauimone
Scrolling logic to legend
r716 } else {
sauimone
split legend layout to vertical and horizontal functions
r810 if ((y + yStep + scrollButtonHeight) > (m_pos.y() + m_maximumSize.height())) {
// This marker would go outside legend rect.
sauimone
Scrolling logic to legend
r716 m->setVisible(false);
} else {
sauimone
split legend layout to vertical and horizontal functions
r810 // This marker is ok
m->setVisible(true);
m->setPos(x, y);
y += yStep;
row++;
sauimone
Scrolling logic to legend
r716 }
}
sauimone
split legend layout to vertical and horizontal functions
r810 maxRows = row;
}
sauimone
Scrolling logic to legend
r716
sauimone
split legend layout to vertical and horizontal functions
r810 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
split legend layout to vertical and horizontal functions
r810 totalWidth += markerMaxSize.width() + m_margin * 2;
totalHeight = maxRows * markerMaxSize.height() + m_margin * 4 + scrollButtonHeight; // TODO: check this
sauimone
legend layouting change
r616
sauimone
legend fixes
r766 m_size.setWidth(totalWidth);
m_size.setHeight(totalHeight);
sauimone
Scrolling logic to legend
r716 }
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 layout with padding
r799 if ((m_alignment == QLegend::AlignmentLeft) || (m_alignment == QLegend::AlignmentRight)) {
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 layout with padding
r799 if ((m_alignment == QLegend::AlignmentTop) || (m_alignment == QLegend::AlignmentBottom)) {
sauimone
legend fixes
r766 return (maximumMarkerSize().width() * m_markers.count() + m_margin * 2 > m_maximumSize.width());
sauimone
legend layout with padding
r799 } else if ((m_alignment == QLegend::AlignmentLeft) || (m_alignment == QLegend::AlignmentRight)) {
sauimone
legend fixes
r766 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