qbarseries.cpp
230 lines
| 4.9 KiB
| text/x-c
|
CppLexer
sauimone
|
r71 | #include <QDebug> | ||
sauimone
|
r338 | #include "qbarseries.h" | ||
sauimone
|
r172 | #include "qbarset.h" | ||
#include "barchartmodel_p.h" | ||||
sauimone
|
r126 | |||
sauimone
|
r56 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
sauimone
|
r313 | /*! | ||
sauimone
|
r338 | \class QBarSeries | ||
sauimone
|
r313 | \brief part of QtCommercial chart API. | ||
sauimone
|
r338 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | ||
QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | ||||
sauimone
|
r377 | by QStringList. | ||
sauimone
|
r313 | |||
sauimone
|
r319 | \mainclass | ||
sauimone
|
r377 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | ||
sauimone
|
r313 | */ | ||
/*! | ||||
Michal Klocek
|
r360 | \fn virtual QSeriesType QBarSeries::type() const | ||
sauimone
|
r313 | \brief Returns type of series. | ||
Michal Klocek
|
r360 | \sa QSeries, QSeriesType | ||
sauimone
|
r313 | */ | ||
/*! | ||||
sauimone
|
r338 | \fn void QBarSeries::changed(int index) | ||
sauimone
|
r319 | \brief \internal \a index | ||
sauimone
|
r313 | */ | ||
/*! | ||||
sauimone
|
r338 | \fn void QBarSeries::floatingValuesEnabled(bool enabled) | ||
sauimone
|
r319 | \brief \internal \a enabled | ||
sauimone
|
r313 | */ | ||
/*! | ||||
sauimone
|
r338 | \fn void QBarSeries::toolTipEnabled(bool enabled) | ||
sauimone
|
r319 | \brief \internal \a enabled | ||
sauimone
|
r313 | */ | ||
/*! | ||||
sauimone
|
r338 | \fn void QBarSeries::separatorsEnabled(bool enabled) | ||
sauimone
|
r319 | \brief \internal \a enabled | ||
sauimone
|
r313 | */ | ||
/*! | ||||
sauimone
|
r338 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | ||
sauimone
|
r319 | \brief \internal \a pos \a tip | ||
sauimone
|
r313 | */ | ||
/*! | ||||
sauimone
|
r338 | Constructs empty QBarSeries. Parameter \a category defines the categories for chart. | ||
QBarSeries is QObject which is a child of a \a parent. | ||||
sauimone
|
r313 | */ | ||
sauimone
|
r377 | QBarSeries::QBarSeries(QStringList categories, QObject *parent) | ||
Michal Klocek
|
r360 | : QSeries(parent) | ||
sauimone
|
r377 | ,mModel(new BarChartModel(categories, this)) | ||
sauimone
|
r71 | { | ||
} | ||||
sauimone
|
r313 | /*! | ||
Adds a set of bars to series. Takes ownership of \a set | ||||
*/ | ||||
sauimone
|
r338 | void QBarSeries::addBarSet(QBarSet *set) | ||
sauimone
|
r171 | { | ||
sauimone
|
r172 | mModel->addBarSet(set); | ||
sauimone
|
r171 | } | ||
sauimone
|
r313 | /*! | ||
Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | ||||
*/ | ||||
sauimone
|
r338 | void QBarSeries::removeBarSet(QBarSet *set) | ||
sauimone
|
r171 | { | ||
sauimone
|
r172 | mModel->removeBarSet(set); | ||
} | ||||
sauimone
|
r313 | /*! | ||
Returns number of sets in series. | ||||
*/ | ||||
sauimone
|
r366 | int QBarSeries::barsetCount() | ||
sauimone
|
r214 | { | ||
return mModel->countSets(); | ||||
} | ||||
sauimone
|
r323 | /*! | ||
Returns number of categories in series | ||||
*/ | ||||
sauimone
|
r366 | int QBarSeries::categoryCount() | ||
sauimone
|
r323 | { | ||
return mModel->countCategories(); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r357 | Returns a list of sets in series. Keeps ownership of sets. | ||
*/ | ||||
QList<QBarSet*> QBarSeries::barSets() | ||||
sauimone
|
r214 | { | ||
sauimone
|
r357 | return mModel->barSets(); | ||
sauimone
|
r214 | } | ||
sauimone
|
r313 | /*! | ||
sauimone
|
r357 | \internal \a index | ||
sauimone
|
r313 | */ | ||
sauimone
|
r357 | QBarSet* QBarSeries::barsetAt(int index) | ||
sauimone
|
r288 | { | ||
return mModel->setAt(index); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
Returns legend of series. Legend is a list of set names in series. | ||||
*/ | ||||
sauimone
|
r338 | QList<QString> QBarSeries::legend() | ||
sauimone
|
r280 | { | ||
return mModel->legend(); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal \a category | ||
sauimone
|
r313 | */ | ||
sauimone
|
r338 | QString QBarSeries::label(int category) | ||
sauimone
|
r288 | { | ||
return mModel->label(category); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
Enables or disables floating values depending on parameter \a enabled. | ||||
Floating values are bar values, that are displayed on top of each bar. | ||||
Calling without parameter \a enabled, enables the floating values | ||||
*/ | ||||
sauimone
|
r357 | void QBarSeries::setFloatingValuesEnabled(bool enabled) | ||
sauimone
|
r280 | { | ||
sauimone
|
r296 | if (enabled) { | ||
for (int i=0; i<mModel->countSets(); i++) { | ||||
QBarSet *set = mModel->setAt(i); | ||||
connect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues())); | ||||
} | ||||
} else { | ||||
for (int i=0; i<mModel->countSets(); i++) { | ||||
QBarSet *set = mModel->setAt(i); | ||||
disconnect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues())); | ||||
} | ||||
} | ||||
sauimone
|
r280 | } | ||
sauimone
|
r313 | /*! | ||
Enables or disables tooltip depending on parameter \a enabled. | ||||
Tooltip shows the name of set, when mouse is hovering on top of bar. | ||||
Calling without parameter \a enabled, enables the tooltip | ||||
*/ | ||||
sauimone
|
r357 | void QBarSeries::setToolTipEnabled(bool enabled) | ||
sauimone
|
r280 | { | ||
sauimone
|
r296 | if (enabled) { | ||
for (int i=0; i<mModel->countSets(); i++) { | ||||
QBarSet *set = mModel->setAt(i); | ||||
connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | ||||
} | ||||
} else { | ||||
for (int i=0; i<mModel->countSets(); i++) { | ||||
QBarSet *set = mModel->setAt(i); | ||||
disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | ||||
} | ||||
} | ||||
sauimone
|
r288 | } | ||
sauimone
|
r313 | /*! | ||
Enables or disables separators depending on parameter \a enabled. | ||||
Separators are visual elements that are drawn between categories. | ||||
Calling without parameter \a enabled, enables the separators | ||||
*/ | ||||
sauimone
|
r357 | void QBarSeries::setSeparatorsEnabled(bool enabled) | ||
sauimone
|
r288 | { | ||
emit separatorsEnabled(enabled); | ||||
sauimone
|
r280 | } | ||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal | ||
sauimone
|
r313 | */ | ||
sauimone
|
r338 | qreal QBarSeries::min() | ||
sauimone
|
r172 | { | ||
return mModel->min(); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal | ||
sauimone
|
r313 | */ | ||
sauimone
|
r338 | qreal QBarSeries::max() | ||
sauimone
|
r172 | { | ||
return mModel->max(); | ||||
sauimone
|
r171 | } | ||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal \a set \a category | ||
sauimone
|
r313 | */ | ||
sauimone
|
r338 | qreal QBarSeries::valueAt(int set, int category) | ||
sauimone
|
r172 | { | ||
return mModel->valueAt(set,category); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal \a set \a category | ||
sauimone
|
r313 | */ | ||
sauimone
|
r338 | qreal QBarSeries::percentageAt(int set, int category) | ||
sauimone
|
r288 | { | ||
return mModel->percentageAt(set,category); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal \a category | ||
sauimone
|
r313 | */ | ||
sauimone
|
r338 | qreal QBarSeries::categorySum(int category) | ||
sauimone
|
r288 | { | ||
return mModel->categorySum(category); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal | ||
sauimone
|
r313 | */ | ||
sauimone
|
r338 | qreal QBarSeries::maxCategorySum() | ||
sauimone
|
r172 | { | ||
return mModel->maxCategorySum(); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal | ||
sauimone
|
r313 | */ | ||
sauimone
|
r338 | BarChartModel& QBarSeries::model() | ||
sauimone
|
r172 | { | ||
return *mModel; | ||||
} | ||||
sauimone
|
r338 | #include "moc_qbarseries.cpp" | ||
sauimone
|
r71 | |||
sauimone
|
r56 | QTCOMMERCIALCHART_END_NAMESPACE | ||