qbarset.cpp
229 lines
| 4.6 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" | ||
sauimone
|
r239 | #include <QDebug> | ||
sauimone
|
r283 | #include <QToolTip> | ||
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
|
r812 | \fn void QBarSet::clicked(QString category, Qt::MouseButtons button) | ||
sauimone
|
r313 | \brief signals that set has been clicked | ||
sauimone
|
r425 | Parameter \a category describes on which category was clicked | ||
sauimone
|
r812 | Parameter \a button mouse button | ||
sauimone
|
r425 | */ | ||
sauimone
|
r313 | /*! | ||
\fn void QBarSet::hoverEnter(QPoint pos) | ||||
\brief signals that mouse has entered over the set at position \a pos. | ||||
*/ | ||||
sauimone
|
r425 | |||
sauimone
|
r313 | /*! | ||
\fn void QBarSet::hoverLeave() | ||||
\brief signals that mouse has left from the set. | ||||
*/ | ||||
sauimone
|
r425 | |||
sauimone
|
r313 | /*! | ||
sauimone
|
r817 | \fn void QBarSet::setValuesVisible(bool visible = true) | ||
\brief Sets visibility of bar values. Values are visible, if parameter \a visible is true | ||||
sauimone
|
r313 | */ | ||
sauimone
|
r425 | |||
sauimone
|
r313 | /*! | ||
\fn void QBarSet::showToolTip(QPoint pos, QString tip) | ||||
sauimone
|
r319 | \brief \internal \a pos \a tip | ||
sauimone
|
r313 | */ | ||
/*! | ||||
Constructs QBarSet with a name of \a name and with parent of \a parent | ||||
*/ | ||||
sauimone
|
r280 | QBarSet::QBarSet(QString name, QObject *parent) | ||
sauimone
|
r276 | : QObject(parent) | ||
sauimone
|
r763 | ,m_name(name) | ||
sauimone
|
r169 | { | ||
} | ||||
sauimone
|
r313 | /*! | ||
Sets new \a name for set. | ||||
*/ | ||||
sauimone
|
r169 | void QBarSet::setName(QString name) | ||
{ | ||||
sauimone
|
r763 | m_name = name; | ||
sauimone
|
r169 | } | ||
sauimone
|
r313 | |||
/*! | ||||
Returns name of the set. | ||||
*/ | ||||
sauimone
|
r776 | QString QBarSet::name() const | ||
sauimone
|
r171 | { | ||
sauimone
|
r763 | return m_name; | ||
sauimone
|
r171 | } | ||
sauimone
|
r169 | |||
sauimone
|
r313 | /*! | ||
Appends new value \a value to the end of set. | ||||
*/ | ||||
sauimone
|
r169 | QBarSet& QBarSet::operator << (const qreal &value) | ||
{ | ||||
sauimone
|
r763 | m_values.append(value); | ||
Marek Rosa
|
r655 | emit structureChanged(); | ||
sauimone
|
r169 | return *this; | ||
} | ||||
Marek Rosa
|
r662 | void QBarSet::insertValue(int i, qreal value) | ||
{ | ||||
sauimone
|
r763 | m_values.insert(i, value); | ||
Marek Rosa
|
r662 | } | ||
Marek Rosa
|
r663 | void QBarSet::removeValue(int i) | ||
{ | ||||
sauimone
|
r763 | m_values.removeAt(i); | ||
Marek Rosa
|
r663 | } | ||
sauimone
|
r313 | /*! | ||
Returns count of values in set. | ||||
*/ | ||||
sauimone
|
r776 | int QBarSet::count() const | ||
sauimone
|
r171 | { | ||
sauimone
|
r763 | return m_values.count(); | ||
sauimone
|
r171 | } | ||
sauimone
|
r313 | /*! | ||
Returns value of set indexed by \a index | ||||
*/ | ||||
sauimone
|
r776 | qreal QBarSet::valueAt(int index) const | ||
sauimone
|
r171 | { | ||
sauimone
|
r763 | return m_values.at(index); | ||
sauimone
|
r171 | } | ||
sauimone
|
r313 | /*! | ||
Sets a new value \a value to set, indexed by \a index | ||||
*/ | ||||
sauimone
|
r183 | void QBarSet::setValue(int index, qreal value) | ||
{ | ||||
sauimone
|
r763 | m_values.replace(index,value); | ||
Marek Rosa
|
r655 | emit valueChanged(); | ||
sauimone
|
r183 | } | ||
sauimone
|
r492 | /*! | ||
Returns total sum of all values in barset. | ||||
*/ | ||||
sauimone
|
r776 | qreal QBarSet::total() const | ||
sauimone
|
r438 | { | ||
qreal total(0); | ||||
sauimone
|
r763 | for (int i=0; i < m_values.count(); i++) { | ||
total += 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 | { | ||
sauimone
|
r763 | m_pen = pen; | ||
Marek Rosa
|
r655 | emit valueChanged(); | ||
sauimone
|
r214 | } | ||
sauimone
|
r313 | /*! | ||
Returns pen of the set. | ||||
*/ | ||||
sauimone
|
r473 | QPen QBarSet::pen() const | ||
sauimone
|
r214 | { | ||
sauimone
|
r763 | return 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 | { | ||
sauimone
|
r763 | m_brush = brush; | ||
Marek Rosa
|
r655 | emit valueChanged(); | ||
sauimone
|
r214 | } | ||
sauimone
|
r313 | /*! | ||
Returns brush of the set. | ||||
*/ | ||||
sauimone
|
r473 | QBrush QBarSet::brush() const | ||
sauimone
|
r214 | { | ||
sauimone
|
r763 | return m_brush; | ||
sauimone
|
r214 | } | ||
sauimone
|
r512 | /*! | ||
sauimone
|
r817 | Sets the pen for values that are drawn on top of this set | ||
sauimone
|
r512 | */ | ||
sauimone
|
r817 | void QBarSet::setValuePen(const QPen &pen) | ||
sauimone
|
r512 | { | ||
sauimone
|
r817 | m_valuePen = pen; | ||
sauimone
|
r512 | } | ||
/*! | ||||
sauimone
|
r817 | Returns the pen for values that are drawn on top of this set | ||
sauimone
|
r512 | */ | ||
sauimone
|
r817 | QPen QBarSet::valuePen() const | ||
sauimone
|
r512 | { | ||
sauimone
|
r817 | return m_valuePen; | ||
sauimone
|
r512 | } | ||
sauimone
|
r813 | /*! | ||
Sets the visibility of barset values to \a visible | ||||
*/ | ||||
void QBarSet::setValuesVisible(bool visible) | ||||
{ | ||||
emit valuesVisibleChanged(visible); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal \a pos | ||
sauimone
|
r313 | */ | ||
sauimone
|
r412 | void QBarSet::barHoverEnterEvent(QPoint pos) | ||
sauimone
|
r276 | { | ||
sauimone
|
r763 | emit showToolTip(pos, m_name); | ||
sauimone
|
r288 | emit hoverEnter(pos); | ||
sauimone
|
r276 | } | ||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal | ||
sauimone
|
r313 | */ | ||
sauimone
|
r412 | void QBarSet::barHoverLeaveEvent() | ||
sauimone
|
r276 | { | ||
sauimone
|
r288 | // Emit signal to user of charts | ||
emit hoverLeave(); | ||||
sauimone
|
r276 | } | ||
sauimone
|
r239 | #include "moc_qbarset.cpp" | ||
Tero Ahola
|
r737 | |||
sauimone
|
r169 | QTCOMMERCIALCHART_END_NAMESPACE | ||