qbarset.cpp
308 lines
| 6.3 KiB
| text/x-c
|
CppLexer
|
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$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r169 | #include "qbarset.h" | ||
|
r938 | #include "qbarset_p.h" | ||
|
r283 | #include <QToolTip> | ||
|
r169 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
|
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. | ||||
|
r325 | \mainclass | ||
|
r377 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries | ||
|
r313 | */ | ||
/*! | ||||
|
r812 | \fn void QBarSet::clicked(QString category, Qt::MouseButtons button) | ||
|
r313 | \brief signals that set has been clicked | ||
|
r425 | Parameter \a category describes on which category was clicked | ||
|
r812 | Parameter \a button mouse button | ||
|
r425 | */ | ||
|
r313 | /*! | ||
Constructs QBarSet with a name of \a name and with parent of \a parent | ||||
*/ | ||||
|
r280 | QBarSet::QBarSet(QString name, QObject *parent) | ||
|
r276 | : QObject(parent) | ||
|
r934 | ,d_ptr(new QBarSetPrivate(name,this)) | ||
|
r169 | { | ||
} | ||||
|
r944 | QBarSet::~QBarSet() | ||
{ | ||||
} | ||||
|
r313 | /*! | ||
Sets new \a name for set. | ||||
*/ | ||||
|
r169 | void QBarSet::setName(QString name) | ||
{ | ||||
|
r938 | d_ptr->m_name = name; | ||
|
r169 | } | ||
|
r313 | |||
/*! | ||||
Returns name of the set. | ||||
*/ | ||||
|
r776 | QString QBarSet::name() const | ||
|
r171 | { | ||
|
r938 | return d_ptr->m_name; | ||
|
r171 | } | ||
|
r169 | |||
|
r313 | /*! | ||
Appends new value \a value to the end of set. | ||||
*/ | ||||
|
r169 | QBarSet& QBarSet::operator << (const qreal &value) | ||
{ | ||||
|
r938 | d_ptr->m_values.append(value); | ||
emit d_ptr->structureChanged(); | ||||
|
r169 | return *this; | ||
} | ||||
|
r901 | /*! | ||
Inserts new \a value on the \a i position. | ||||
The value that is currently at this postion is moved to postion i + 1 | ||||
\sa removeValue() | ||||
*/ | ||||
|
r662 | void QBarSet::insertValue(int i, qreal value) | ||
{ | ||||
|
r938 | d_ptr->m_values.insert(i, value); | ||
|
r662 | } | ||
|
r901 | /*! | ||
Removes the value specified by \a i | ||||
\sa insertValue() | ||||
*/ | ||||
|
r663 | void QBarSet::removeValue(int i) | ||
{ | ||||
|
r938 | d_ptr->m_values.removeAt(i); | ||
|
r663 | } | ||
|
r313 | /*! | ||
Returns count of values in set. | ||||
*/ | ||||
|
r776 | int QBarSet::count() const | ||
|
r171 | { | ||
|
r938 | return d_ptr->m_values.count(); | ||
|
r171 | } | ||
|
r313 | /*! | ||
Returns value of set indexed by \a index | ||||
*/ | ||||
|
r776 | qreal QBarSet::valueAt(int index) const | ||
|
r171 | { | ||
|
r938 | return d_ptr->m_values.at(index); | ||
|
r171 | } | ||
|
r313 | /*! | ||
Sets a new value \a value to set, indexed by \a index | ||||
*/ | ||||
|
r183 | void QBarSet::setValue(int index, qreal value) | ||
{ | ||||
|
r938 | d_ptr->m_values.replace(index,value); | ||
emit d_ptr->valueChanged(); | ||||
|
r183 | } | ||
|
r492 | /*! | ||
|
r934 | Returns sum of all values in barset. | ||
|
r492 | */ | ||
|
r934 | qreal QBarSet::sum() const | ||
|
r438 | { | ||
qreal total(0); | ||||
|
r938 | for (int i=0; i < d_ptr->m_values.count(); i++) { | ||
total += d_ptr->m_values.at(i); | ||||
|
r438 | } | ||
return total; | ||||
} | ||||
|
r313 | /*! | ||
Sets pen for set. Bars of this set are drawn using \a pen | ||||
*/ | ||||
|
r763 | void QBarSet::setPen(const QPen &pen) | ||
|
r214 | { | ||
|
r938 | if(d_ptr->m_pen!=pen){ | ||
d_ptr->m_pen = pen; | ||||
emit d_ptr->valueChanged(); | ||||
} | ||||
|
r214 | } | ||
|
r313 | /*! | ||
Returns pen of the set. | ||||
*/ | ||||
|
r473 | QPen QBarSet::pen() const | ||
|
r214 | { | ||
|
r938 | return d_ptr->m_pen; | ||
|
r214 | } | ||
|
r313 | /*! | ||
Sets brush for the set. Bars of this set are drawn using \a brush | ||||
*/ | ||||
|
r763 | void QBarSet::setBrush(const QBrush &brush) | ||
|
r214 | { | ||
|
r938 | if(d_ptr->m_brush!=brush){ | ||
d_ptr->m_brush = brush; | ||||
emit d_ptr->valueChanged(); | ||||
} | ||||
|
r214 | } | ||
|
r313 | /*! | ||
Returns brush of the set. | ||||
*/ | ||||
|
r473 | QBrush QBarSet::brush() const | ||
|
r214 | { | ||
|
r938 | return d_ptr->m_brush; | ||
|
r214 | } | ||
|
r512 | /*! | ||
|
r839 | Sets \a pen of the values that are drawn on top of this barset | ||
|
r512 | */ | ||
|
r820 | void QBarSet::setLabelPen(const QPen &pen) | ||
|
r512 | { | ||
|
r938 | if(d_ptr->m_labelPen!=pen){ | ||
d_ptr->m_labelPen = pen; | ||||
emit d_ptr->valueChanged(); | ||||
} | ||||
|
r820 | } | ||
/*! | ||||
Returns pen of the values that are drawn on top of this barset | ||||
*/ | ||||
QPen QBarSet::labelPen() const | ||||
{ | ||||
|
r938 | return d_ptr->m_labelPen; | ||
|
r820 | } | ||
/*! | ||||
|
r839 | Sets \a brush of the values that are drawn on top of this barset | ||
|
r820 | */ | ||
void QBarSet::setLabelBrush(const QBrush &brush) | ||||
{ | ||||
|
r938 | if(d_ptr->m_labelBrush!=brush){ | ||
d_ptr->m_labelBrush = brush; | ||||
emit d_ptr->valueChanged(); | ||||
} | ||||
|
r820 | } | ||
/*! | ||||
Returns brush of the values that are drawn on top of this barset | ||||
*/ | ||||
QBrush QBarSet::labelBrush() const | ||||
{ | ||||
|
r938 | return d_ptr->m_labelBrush; | ||
|
r820 | } | ||
/*! | ||||
|
r839 | Sets the \a font for values that are drawn on top of this barset | ||
|
r820 | */ | ||
void QBarSet::setLabelFont(const QFont &font) | ||||
{ | ||||
|
r938 | if(d_ptr->m_labelFont!=font) { | ||
d_ptr->m_labelFont = font; | ||||
emit d_ptr->valueChanged(); | ||||
} | ||||
|
r512 | } | ||
/*! | ||||
|
r817 | Returns the pen for values that are drawn on top of this set | ||
|
r512 | */ | ||
|
r820 | QFont QBarSet::labelFont() const | ||
|
r512 | { | ||
|
r938 | return d_ptr->m_labelFont; | ||
|
r512 | } | ||
|
r813 | /*! | ||
|
r908 | Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. | ||
|
r813 | */ | ||
|
r908 | |||
|
r820 | void QBarSet::setLabelsVisible(bool visible) | ||
{ | ||||
|
r938 | if(d_ptr->m_labelsVisible!=visible) { | ||
d_ptr->m_labelsVisible = visible; | ||||
emit d_ptr->labelsVisibleChanged(visible); | ||||
} | ||||
|
r820 | } | ||
/*! | ||||
Returns the visibility of values | ||||
*/ | ||||
bool QBarSet::labelsVisible() const | ||||
|
r813 | { | ||
|
r938 | return d_ptr->m_labelsVisible; | ||
|
r813 | } | ||
|
r934 | /* | ||
|
r412 | void QBarSet::barHoverEnterEvent(QPoint pos) | ||
|
r276 | { | ||
|
r763 | emit showToolTip(pos, m_name); | ||
|
r288 | emit hoverEnter(pos); | ||
|
r276 | } | ||
|
r313 | */ | ||
|
r934 | /* | ||
|
r412 | void QBarSet::barHoverLeaveEvent() | ||
|
r276 | { | ||
|
r288 | // Emit signal to user of charts | ||
emit hoverLeave(); | ||||
|
r276 | } | ||
|
r934 | */ | ||
|
r938 | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
QBarSetPrivate::QBarSetPrivate(QString name, QBarSet *parent) : QObject(parent), | ||||
q_ptr(parent), | ||||
m_name(name), | ||||
m_labelsVisible(false) | ||||
{ | ||||
} | ||||
QBarSetPrivate::~QBarSetPrivate() | ||||
{ | ||||
} | ||||
//TODO: fixme , refactor it and get rid of it | ||||
void QBarSetPrivate::barHoverEnterEvent(QPoint pos) | ||||
{ | ||||
emit showToolTip(pos, m_name); | ||||
emit hoverEnter(pos); | ||||
} | ||||
//TODO: fixme , refactor it and get rid of it | ||||
void QBarSetPrivate::barHoverLeaveEvent() | ||||
{ | ||||
// Emit signal to user of charts | ||||
emit hoverLeave(); | ||||
} | ||||
|
r239 | #include "moc_qbarset.cpp" | ||
|
r938 | #include "moc_qbarset_p.cpp" | ||
|
r737 | |||
|
r169 | QTCOMMERCIALCHART_END_NAMESPACE | ||