qbarchartseries.cpp
252 lines
| 5.9 KiB
| text/x-c
|
CppLexer
sauimone
|
r71 | #include <QDebug> | ||
sauimone
|
r216 | #include "qbarchartseries.h" | ||
sauimone
|
r172 | #include "qbarcategory.h" | ||
#include "qbarset.h" | ||||
#include "barchartmodel_p.h" | ||||
sauimone
|
r126 | |||
sauimone
|
r56 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
sauimone
|
r313 | /*! | ||
\class QBarChartSeries | ||||
\brief part of QtCommercial chart API. | ||||
QBarChartSeries represents a series of data shown as bars. One QBarChartSeries can contain multible | ||||
QBarSet data sets. QBarChartSeries groups the data from sets to categories, which are defined | ||||
by QBarCategory class. | ||||
sauimone
|
r319 | \mainclass | ||
sauimone
|
r325 | Example on how to create category: | ||
\snippet ../example/barchart/main.cpp 1 | ||||
Example on how to create sets of data: | ||||
sauimone
|
r319 | \snippet ../example/barchart/main.cpp 2 | ||
sauimone
|
r325 | Example on how to add sets to bar chart: | ||
\snippet ../example/barchart/main.cpp 3 | ||||
sauimone
|
r319 | |||
Example on how to enable tooltip and floating values: | ||||
sauimone
|
r325 | \snippet ../example/barchart/main.cpp 4 | ||
Example on how to create view and apply theme: | ||||
\snippet ../example/barchart/main.cpp 5 | ||||
sauimone
|
r319 | |||
sauimone
|
r313 | \sa QBarCategory, QBarSet, QStackedBarChartSeries, QPercentBarChartSeries | ||
*/ | ||||
/*! | ||||
\fn virtual QChartSeriesType QBarChartSeries::type() const | ||||
\brief Returns type of series. | ||||
\sa QChartSeries, QChartSeriesType | ||||
*/ | ||||
/*! | ||||
\fn void QBarChartSeries::changed(int index) | ||||
sauimone
|
r319 | \brief \internal \a index | ||
sauimone
|
r313 | */ | ||
/*! | ||||
\fn void QBarChartSeries::floatingValuesEnabled(bool enabled) | ||||
sauimone
|
r319 | \brief \internal \a enabled | ||
sauimone
|
r313 | */ | ||
/*! | ||||
\fn void QBarChartSeries::toolTipEnabled(bool enabled) | ||||
sauimone
|
r319 | \brief \internal \a enabled | ||
sauimone
|
r313 | */ | ||
/*! | ||||
\fn void QBarChartSeries::separatorsEnabled(bool enabled) | ||||
sauimone
|
r319 | \brief \internal \a enabled | ||
sauimone
|
r313 | */ | ||
/*! | ||||
\fn void QBarChartSeries::showToolTip(QPoint pos, QString tip) | ||||
sauimone
|
r319 | \brief \internal \a pos \a tip | ||
sauimone
|
r313 | */ | ||
/*! | ||||
Constructs empty QBarChartSeries. Parameter \a category defines the categories for chart. | ||||
sauimone
|
r323 | Takes ownership of \a category. | ||
sauimone
|
r319 | QBarChartSeries is QObject which is a child of a \a parent. | ||
sauimone
|
r313 | */ | ||
sauimone
|
r216 | QBarChartSeries::QBarChartSeries(QBarCategory *category, QObject *parent) | ||
sauimone
|
r172 | : QChartSeries(parent) | ||
,mModel(new BarChartModel(category, this)) | ||||
sauimone
|
r71 | { | ||
} | ||||
sauimone
|
r313 | /*! | ||
Adds a set of bars to series. Takes ownership of \a set | ||||
*/ | ||||
sauimone
|
r216 | void QBarChartSeries::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
|
r216 | void QBarChartSeries::removeBarSet(QBarSet *set) | ||
sauimone
|
r171 | { | ||
sauimone
|
r172 | mModel->removeBarSet(set); | ||
} | ||||
sauimone
|
r313 | /*! | ||
Returns number of sets in series. | ||||
*/ | ||||
sauimone
|
r216 | int QBarChartSeries::countSets() | ||
sauimone
|
r214 | { | ||
return mModel->countSets(); | ||||
} | ||||
sauimone
|
r323 | /*! | ||
Returns number of categories in series | ||||
*/ | ||||
int QBarChartSeries::countCategories() | ||||
{ | ||||
return mModel->countCategories(); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
Simple iterator for set. Returns pointer to next set in series. | ||||
sauimone
|
r319 | Returns first set, if parameter \a getFirst is true. | ||
If series is empty, returns 0. | ||||
Returns 0 after last set. | ||||
sauimone
|
r313 | */ | ||
sauimone
|
r216 | QBarSet* QBarChartSeries::nextSet(bool getFirst) | ||
sauimone
|
r214 | { | ||
return mModel->nextSet(getFirst); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
Returns set indexed by \a index. Doesn't check for index bounds. | ||||
Assumes that \a index is between 0 and number of sets. Use countSets() to get valid index bound. | ||||
\sa countSets() | ||||
*/ | ||||
sauimone
|
r288 | QBarSet* QBarChartSeries::setAt(int index) | ||
{ | ||||
return mModel->setAt(index); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
Returns legend of series. Legend is a list of set names in series. | ||||
*/ | ||||
sauimone
|
r280 | QList<QString> QBarChartSeries::legend() | ||
{ | ||||
return mModel->legend(); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal \a category | ||
sauimone
|
r313 | */ | ||
sauimone
|
r288 | QString QBarChartSeries::label(int category) | ||
{ | ||||
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
|
r280 | void QBarChartSeries::enableFloatingValues(bool enabled) | ||
{ | ||||
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
|
r288 | void QBarChartSeries::enableToolTip(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
|
r288 | void QBarChartSeries::enableSeparators(bool enabled) | ||
{ | ||||
emit separatorsEnabled(enabled); | ||||
sauimone
|
r280 | } | ||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal | ||
sauimone
|
r313 | */ | ||
sauimone
|
r216 | qreal QBarChartSeries::min() | ||
sauimone
|
r172 | { | ||
return mModel->min(); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal | ||
sauimone
|
r313 | */ | ||
sauimone
|
r216 | qreal QBarChartSeries::max() | ||
sauimone
|
r172 | { | ||
return mModel->max(); | ||||
sauimone
|
r171 | } | ||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal \a set \a category | ||
sauimone
|
r313 | */ | ||
sauimone
|
r216 | qreal QBarChartSeries::valueAt(int set, int category) | ||
sauimone
|
r172 | { | ||
return mModel->valueAt(set,category); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal \a set \a category | ||
sauimone
|
r313 | */ | ||
sauimone
|
r288 | qreal QBarChartSeries::percentageAt(int set, int category) | ||
{ | ||||
return mModel->percentageAt(set,category); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal \a category | ||
sauimone
|
r313 | */ | ||
sauimone
|
r288 | qreal QBarChartSeries::categorySum(int category) | ||
{ | ||||
return mModel->categorySum(category); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal | ||
sauimone
|
r313 | */ | ||
sauimone
|
r216 | qreal QBarChartSeries::maxCategorySum() | ||
sauimone
|
r172 | { | ||
return mModel->maxCategorySum(); | ||||
} | ||||
sauimone
|
r313 | /*! | ||
sauimone
|
r319 | \internal | ||
sauimone
|
r313 | */ | ||
sauimone
|
r216 | BarChartModel& QBarChartSeries::model() | ||
sauimone
|
r172 | { | ||
return *mModel; | ||||
} | ||||
sauimone
|
r216 | #include "moc_qbarchartseries.cpp" | ||
sauimone
|
r71 | |||
sauimone
|
r56 | QTCOMMERCIALCHART_END_NAMESPACE | ||