qbarset.cpp
303 lines
| 6.5 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
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
|
r169 | #include "qbarset.h" | ||
Michal Klocek
|
r938 | #include "qbarset_p.h" | ||
sauimone
|
r169 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
sauimone
|
r313 | /*! | ||
\class QBarSet | ||||
\brief part of QtCommercial chart API. | ||||
QBarSet represents one set of bars. Set of bars contains one data value for each category. | ||||
First value of set is assumed to belong to first category, second to second category and so on. | ||||
If set has fewer values than there are categories, then the missing values are assumed to be | ||||
at the end of set. For missing values in middle of a set, numerical value of zero is used. | ||||
sauimone
|
r325 | \mainclass | ||
sauimone
|
r377 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries | ||
sauimone
|
r313 | */ | ||
/*! | ||||
sauimone
|
r1008 | \fn void QBarSet::clicked(QString category) | ||
sauimone
|
r313 | \brief signals that set has been clicked | ||
sauimone
|
r425 | Parameter \a category describes on which category was clicked | ||
sauimone
|
r980 | */ | ||
sauimone
|
r975 | /*! | ||
\fn void QBarSet::hovered(bool status) | ||||
\brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left. | ||||
sauimone
|
r980 | |||
The signal is emitted if mouse is hovered on top of set | ||||
Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | ||||
sauimone
|
r975 | */ | ||
sauimone
|
r313 | /*! | ||
Constructs QBarSet with a name of \a name and with parent of \a parent | ||||
*/ | ||||
sauimone
|
r993 | QBarSet::QBarSet(const QString name, QObject *parent) | ||
sauimone
|
r276 | : QObject(parent) | ||
sauimone
|
r934 | ,d_ptr(new QBarSetPrivate(name,this)) | ||
sauimone
|
r169 | { | ||
} | ||||
sauimone
|
r980 | /*! | ||
Destroys the barset | ||||
*/ | ||||
Jani Honkonen
|
r944 | QBarSet::~QBarSet() | ||
{ | ||||
sauimone
|
r980 | // NOTE: d_ptr destroyed by QObject | ||
Jani Honkonen
|
r944 | } | ||
sauimone
|
r313 | /*! | ||
Sets new \a name for set. | ||||
*/ | ||||
sauimone
|
r993 | void QBarSet::setName(const QString name) | ||
sauimone
|
r169 | { | ||
Michal Klocek
|
r938 | d_ptr->m_name = name; | ||
sauimone
|
r169 | } | ||
sauimone
|
r313 | |||
/*! | ||||
Returns name of the set. | ||||
*/ | ||||
sauimone
|
r776 | QString QBarSet::name() const | ||
sauimone
|
r171 | { | ||
Michal Klocek
|
r938 | return d_ptr->m_name; | ||
sauimone
|
r171 | } | ||
sauimone
|
r169 | |||
sauimone
|
r313 | /*! | ||
Appends new value \a value to the end of set. | ||||
*/ | ||||
sauimone
|
r993 | void QBarSet::append(const qreal value) | ||
sauimone
|
r169 | { | ||
Michal Klocek
|
r938 | d_ptr->m_values.append(value); | ||
sauimone
|
r1008 | emit d_ptr->restructuredBars(); | ||
sauimone
|
r993 | } | ||
/*! | ||||
Appends new value \a value to the end of set. | ||||
*/ | ||||
QBarSet& QBarSet::operator << (const qreal &value) | ||||
{ | ||||
append(value); | ||||
sauimone
|
r169 | return *this; | ||
} | ||||
Marek Rosa
|
r901 | /*! | ||
sauimone
|
r993 | Inserts new \a value on the \a index position. | ||
The value that is currently at this postion is moved to postion index + 1 | ||||
\sa remove() | ||||
Marek Rosa
|
r901 | */ | ||
sauimone
|
r993 | void QBarSet::insert(const int index, const qreal value) | ||
Marek Rosa
|
r662 | { | ||
sauimone
|
r993 | d_ptr->m_values.insert(index, value); | ||
sauimone
|
r1008 | emit d_ptr->updatedBars(); | ||
Marek Rosa
|
r662 | } | ||
Marek Rosa
|
r901 | /*! | ||
sauimone
|
r993 | Removes the value specified by \a index | ||
\sa insert() | ||||
Marek Rosa
|
r901 | */ | ||
sauimone
|
r993 | void QBarSet::remove(const int index) | ||
Marek Rosa
|
r663 | { | ||
sauimone
|
r993 | d_ptr->m_values.removeAt(index); | ||
sauimone
|
r1008 | emit d_ptr->updatedBars(); | ||
Marek Rosa
|
r663 | } | ||
sauimone
|
r313 | /*! | ||
sauimone
|
r993 | Sets a new value \a value to set, indexed by \a index | ||
sauimone
|
r313 | */ | ||
sauimone
|
r993 | void QBarSet::replace(const int index, const qreal value) | ||
sauimone
|
r171 | { | ||
sauimone
|
r993 | d_ptr->m_values.replace(index,value); | ||
sauimone
|
r1008 | emit d_ptr->updatedBars(); | ||
sauimone
|
r171 | } | ||
sauimone
|
r313 | /*! | ||
Returns value of set indexed by \a index | ||||
*/ | ||||
sauimone
|
r993 | qreal QBarSet::at(const int index) const | ||
sauimone
|
r171 | { | ||
Michal Klocek
|
r938 | return d_ptr->m_values.at(index); | ||
sauimone
|
r171 | } | ||
sauimone
|
r313 | /*! | ||
sauimone
|
r993 | Returns value of set indexed by \a index | ||
sauimone
|
r313 | */ | ||
sauimone
|
r993 | qreal QBarSet::operator [] (int index) const | ||
sauimone
|
r183 | { | ||
sauimone
|
r993 | return d_ptr->m_values.at(index); | ||
} | ||||
/*! | ||||
Returns count of values in set. | ||||
*/ | ||||
int QBarSet::count() const | ||||
{ | ||||
return d_ptr->m_values.count(); | ||||
sauimone
|
r183 | } | ||
sauimone
|
r492 | /*! | ||
sauimone
|
r934 | Returns sum of all values in barset. | ||
sauimone
|
r492 | */ | ||
sauimone
|
r934 | qreal QBarSet::sum() const | ||
sauimone
|
r438 | { | ||
qreal total(0); | ||||
Michal Klocek
|
r938 | for (int i=0; i < d_ptr->m_values.count(); i++) { | ||
total += d_ptr->m_values.at(i); | ||||
sauimone
|
r438 | } | ||
return total; | ||||
} | ||||
sauimone
|
r313 | /*! | ||
Sets pen for set. Bars of this set are drawn using \a pen | ||||
*/ | ||||
sauimone
|
r763 | void QBarSet::setPen(const QPen &pen) | ||
sauimone
|
r214 | { | ||
Michal Klocek
|
r938 | if(d_ptr->m_pen!=pen){ | ||
d_ptr->m_pen = pen; | ||||
sauimone
|
r1008 | emit d_ptr->updatedBars(); | ||
Michal Klocek
|
r938 | } | ||
sauimone
|
r214 | } | ||
sauimone
|
r313 | /*! | ||
Returns pen of the set. | ||||
*/ | ||||
sauimone
|
r473 | QPen QBarSet::pen() const | ||
sauimone
|
r214 | { | ||
Michal Klocek
|
r938 | return d_ptr->m_pen; | ||
sauimone
|
r214 | } | ||
sauimone
|
r313 | /*! | ||
Sets brush for the set. Bars of this set are drawn using \a brush | ||||
*/ | ||||
sauimone
|
r763 | void QBarSet::setBrush(const QBrush &brush) | ||
sauimone
|
r214 | { | ||
Michal Klocek
|
r938 | if(d_ptr->m_brush!=brush){ | ||
d_ptr->m_brush = brush; | ||||
sauimone
|
r1008 | emit d_ptr->updatedBars(); | ||
Michal Klocek
|
r938 | } | ||
sauimone
|
r214 | } | ||
sauimone
|
r313 | /*! | ||
Returns brush of the set. | ||||
*/ | ||||
sauimone
|
r473 | QBrush QBarSet::brush() const | ||
sauimone
|
r214 | { | ||
Michal Klocek
|
r938 | return d_ptr->m_brush; | ||
sauimone
|
r214 | } | ||
sauimone
|
r512 | /*! | ||
sauimone
|
r839 | Sets \a pen of the values that are drawn on top of this barset | ||
sauimone
|
r512 | */ | ||
sauimone
|
r820 | void QBarSet::setLabelPen(const QPen &pen) | ||
sauimone
|
r512 | { | ||
Michal Klocek
|
r938 | if(d_ptr->m_labelPen!=pen){ | ||
d_ptr->m_labelPen = pen; | ||||
sauimone
|
r1008 | emit d_ptr->updatedBars(); | ||
Michal Klocek
|
r938 | } | ||
sauimone
|
r820 | } | ||
/*! | ||||
Returns pen of the values that are drawn on top of this barset | ||||
*/ | ||||
QPen QBarSet::labelPen() const | ||||
{ | ||||
Michal Klocek
|
r938 | return d_ptr->m_labelPen; | ||
sauimone
|
r820 | } | ||
/*! | ||||
sauimone
|
r839 | Sets \a brush of the values that are drawn on top of this barset | ||
sauimone
|
r820 | */ | ||
void QBarSet::setLabelBrush(const QBrush &brush) | ||||
{ | ||||
Michal Klocek
|
r938 | if(d_ptr->m_labelBrush!=brush){ | ||
d_ptr->m_labelBrush = brush; | ||||
sauimone
|
r1008 | emit d_ptr->updatedBars(); | ||
Michal Klocek
|
r938 | } | ||
sauimone
|
r820 | } | ||
/*! | ||||
Returns brush of the values that are drawn on top of this barset | ||||
*/ | ||||
QBrush QBarSet::labelBrush() const | ||||
{ | ||||
Michal Klocek
|
r938 | return d_ptr->m_labelBrush; | ||
sauimone
|
r820 | } | ||
/*! | ||||
sauimone
|
r839 | Sets the \a font for values that are drawn on top of this barset | ||
sauimone
|
r820 | */ | ||
void QBarSet::setLabelFont(const QFont &font) | ||||
{ | ||||
Michal Klocek
|
r938 | if(d_ptr->m_labelFont!=font) { | ||
d_ptr->m_labelFont = font; | ||||
sauimone
|
r1008 | emit d_ptr->updatedBars(); | ||
Michal Klocek
|
r938 | } | ||
sauimone
|
r512 | } | ||
/*! | ||||
sauimone
|
r817 | Returns the pen for values that are drawn on top of this set | ||
sauimone
|
r512 | */ | ||
sauimone
|
r820 | QFont QBarSet::labelFont() const | ||
sauimone
|
r512 | { | ||
Michal Klocek
|
r938 | return d_ptr->m_labelFont; | ||
sauimone
|
r512 | } | ||
sauimone
|
r813 | /*! | ||
Marek Rosa
|
r908 | Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. | ||
sauimone
|
r813 | */ | ||
Marek Rosa
|
r908 | |||
sauimone
|
r820 | void QBarSet::setLabelsVisible(bool visible) | ||
{ | ||||
Michal Klocek
|
r938 | if(d_ptr->m_labelsVisible!=visible) { | ||
d_ptr->m_labelsVisible = visible; | ||||
emit d_ptr->labelsVisibleChanged(visible); | ||||
} | ||||
sauimone
|
r820 | } | ||
/*! | ||||
Returns the visibility of values | ||||
*/ | ||||
bool QBarSet::labelsVisible() const | ||||
sauimone
|
r813 | { | ||
Michal Klocek
|
r938 | return d_ptr->m_labelsVisible; | ||
sauimone
|
r813 | } | ||
Michal Klocek
|
r938 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
sauimone
|
r993 | QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent), | ||
Michal Klocek
|
r938 | q_ptr(parent), | ||
m_name(name), | ||||
m_labelsVisible(false) | ||||
{ | ||||
} | ||||
QBarSetPrivate::~QBarSetPrivate() | ||||
{ | ||||
} | ||||
sauimone
|
r1017 | |||
sauimone
|
r239 | #include "moc_qbarset.cpp" | ||
Michal Klocek
|
r938 | #include "moc_qbarset_p.cpp" | ||
Tero Ahola
|
r737 | |||
sauimone
|
r169 | QTCOMMERCIALCHART_END_NAMESPACE | ||