qbarseries.cpp
232 lines
| 5.0 KiB
| text/x-c
|
CppLexer
|
r71 | #include <QDebug> | ||
|
r338 | #include "qbarseries.h" | ||
|
r172 | #include "qbarcategory.h" | ||
#include "qbarset.h" | ||||
#include "barchartmodel_p.h" | ||||
|
r126 | |||
|
r56 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
|
r313 | /*! | ||
|
r338 | \class QBarSeries | ||
|
r313 | \brief part of QtCommercial chart API. | ||
|
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 | ||||
|
r313 | by QBarCategory class. | ||
|
r319 | \mainclass | ||
|
r338 | \sa QBarCategory, QBarSet, QStackedBarSeries, QPercentBarSeries | ||
|
r313 | */ | ||
/*! | ||||
|
r338 | \fn virtual QChartSeriesType QBarSeries::type() const | ||
|
r313 | \brief Returns type of series. | ||
\sa QChartSeries, QChartSeriesType | ||||
*/ | ||||
/*! | ||||
|
r338 | \fn void QBarSeries::changed(int index) | ||
|
r319 | \brief \internal \a index | ||
|
r313 | */ | ||
/*! | ||||
|
r338 | \fn void QBarSeries::floatingValuesEnabled(bool enabled) | ||
|
r319 | \brief \internal \a enabled | ||
|
r313 | */ | ||
/*! | ||||
|
r338 | \fn void QBarSeries::toolTipEnabled(bool enabled) | ||
|
r319 | \brief \internal \a enabled | ||
|
r313 | */ | ||
/*! | ||||
|
r338 | \fn void QBarSeries::separatorsEnabled(bool enabled) | ||
|
r319 | \brief \internal \a enabled | ||
|
r313 | */ | ||
/*! | ||||
|
r338 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | ||
|
r319 | \brief \internal \a pos \a tip | ||
|
r313 | */ | ||
/*! | ||||
|
r338 | Constructs empty QBarSeries. Parameter \a category defines the categories for chart. | ||
|
r323 | Takes ownership of \a category. | ||
|
r338 | QBarSeries is QObject which is a child of a \a parent. | ||
|
r313 | */ | ||
|
r338 | QBarSeries::QBarSeries(QBarCategory *category, QObject *parent) | ||
|
r172 | : QChartSeries(parent) | ||
,mModel(new BarChartModel(category, this)) | ||||
|
r71 | { | ||
} | ||||
|
r313 | /*! | ||
Adds a set of bars to series. Takes ownership of \a set | ||||
*/ | ||||
|
r338 | void QBarSeries::addBarSet(QBarSet *set) | ||
|
r171 | { | ||
|
r172 | mModel->addBarSet(set); | ||
|
r171 | } | ||
|
r313 | /*! | ||
Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | ||||
*/ | ||||
|
r338 | void QBarSeries::removeBarSet(QBarSet *set) | ||
|
r171 | { | ||
|
r172 | mModel->removeBarSet(set); | ||
} | ||||
|
r313 | /*! | ||
Returns number of sets in series. | ||||
*/ | ||||
|
r338 | int QBarSeries::countSets() | ||
|
r214 | { | ||
return mModel->countSets(); | ||||
} | ||||
|
r323 | /*! | ||
Returns number of categories in series | ||||
*/ | ||||
|
r338 | int QBarSeries::countCategories() | ||
|
r323 | { | ||
return mModel->countCategories(); | ||||
} | ||||
|
r313 | /*! | ||
|
r357 | Returns a list of sets in series. Keeps ownership of sets. | ||
*/ | ||||
QList<QBarSet*> QBarSeries::barSets() | ||||
|
r214 | { | ||
|
r357 | return mModel->barSets(); | ||
|
r214 | } | ||
|
r313 | /*! | ||
|
r357 | \internal \a index | ||
|
r313 | */ | ||
|
r357 | QBarSet* QBarSeries::barsetAt(int index) | ||
|
r288 | { | ||
return mModel->setAt(index); | ||||
} | ||||
|
r313 | /*! | ||
Returns legend of series. Legend is a list of set names in series. | ||||
*/ | ||||
|
r338 | QList<QString> QBarSeries::legend() | ||
|
r280 | { | ||
return mModel->legend(); | ||||
} | ||||
|
r313 | /*! | ||
|
r319 | \internal \a category | ||
|
r313 | */ | ||
|
r338 | QString QBarSeries::label(int category) | ||
|
r288 | { | ||
return mModel->label(category); | ||||
} | ||||
|
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 | ||||
*/ | ||||
|
r357 | void QBarSeries::setFloatingValuesEnabled(bool enabled) | ||
|
r280 | { | ||
|
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())); | ||||
} | ||||
} | ||||
|
r280 | } | ||
|
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 | ||||
*/ | ||||
|
r357 | void QBarSeries::setToolTipEnabled(bool enabled) | ||
|
r280 | { | ||
|
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))); | ||||
} | ||||
} | ||||
|
r288 | } | ||
|
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 | ||||
*/ | ||||
|
r357 | void QBarSeries::setSeparatorsEnabled(bool enabled) | ||
|
r288 | { | ||
emit separatorsEnabled(enabled); | ||||
|
r280 | } | ||
|
r313 | /*! | ||
|
r319 | \internal | ||
|
r313 | */ | ||
|
r338 | qreal QBarSeries::min() | ||
|
r172 | { | ||
return mModel->min(); | ||||
} | ||||
|
r313 | /*! | ||
|
r319 | \internal | ||
|
r313 | */ | ||
|
r338 | qreal QBarSeries::max() | ||
|
r172 | { | ||
return mModel->max(); | ||||
|
r171 | } | ||
|
r313 | /*! | ||
|
r319 | \internal \a set \a category | ||
|
r313 | */ | ||
|
r338 | qreal QBarSeries::valueAt(int set, int category) | ||
|
r172 | { | ||
return mModel->valueAt(set,category); | ||||
} | ||||
|
r313 | /*! | ||
|
r319 | \internal \a set \a category | ||
|
r313 | */ | ||
|
r338 | qreal QBarSeries::percentageAt(int set, int category) | ||
|
r288 | { | ||
return mModel->percentageAt(set,category); | ||||
} | ||||
|
r313 | /*! | ||
|
r319 | \internal \a category | ||
|
r313 | */ | ||
|
r338 | qreal QBarSeries::categorySum(int category) | ||
|
r288 | { | ||
return mModel->categorySum(category); | ||||
} | ||||
|
r313 | /*! | ||
|
r319 | \internal | ||
|
r313 | */ | ||
|
r338 | qreal QBarSeries::maxCategorySum() | ||
|
r172 | { | ||
return mModel->maxCategorySum(); | ||||
} | ||||
|
r313 | /*! | ||
|
r319 | \internal | ||
|
r313 | */ | ||
|
r338 | BarChartModel& QBarSeries::model() | ||
|
r172 | { | ||
return *mModel; | ||||
} | ||||
|
r338 | #include "moc_qbarseries.cpp" | ||
|
r71 | |||
|
r56 | QTCOMMERCIALCHART_END_NAMESPACE | ||