qbarseries.cpp
242 lines
| 5.1 KiB
| text/x-c
|
CppLexer
|
r71 | #include <QDebug> | ||
|
r338 | #include "qbarseries.h" | ||
|
r172 | #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 | ||||
|
r377 | by QStringList. | ||
|
r313 | |||
|
r319 | \mainclass | ||
|
r377 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | ||
|
r313 | */ | ||
/*! | ||||
|
r360 | \fn virtual QSeriesType QBarSeries::type() const | ||
|
r313 | \brief Returns type of series. | ||
|
r360 | \sa QSeries, QSeriesType | ||
|
r313 | */ | ||
|
r425 | |||
|
r313 | /*! | ||
|
r338 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | ||
|
r319 | \brief \internal \a pos \a tip | ||
|
r313 | */ | ||
/*! | ||||
|
r387 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | ||
|
r338 | QBarSeries is QObject which is a child of a \a parent. | ||
|
r313 | */ | ||
|
r377 | QBarSeries::QBarSeries(QStringList categories, QObject *parent) | ||
|
r360 | : QSeries(parent) | ||
|
r377 | ,mModel(new BarChartModel(categories, this)) | ||
|
r71 | { | ||
|
r528 | m_model = NULL; | ||
m_mapCategories = -1; | ||||
m_mapBarBottom - 1; | ||||
m_mapBarTop - 1; | ||||
|
r71 | } | ||
|
r313 | /*! | ||
|
r425 | Adds a set of bars to series. Takes ownership of \a set. | ||
Connects the clicked(QString) and rightClicked(QString) signals | ||||
of \a set to this series | ||||
|
r313 | */ | ||
|
r338 | void QBarSeries::addBarSet(QBarSet *set) | ||
|
r171 | { | ||
|
r172 | mModel->addBarSet(set); | ||
|
r425 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | ||
connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | ||||
|
r171 | } | ||
|
r313 | /*! | ||
Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | ||||
|
r425 | Disconnects the clicked(QString) and rightClicked(QString) signals | ||
of \a set from this series | ||||
|
r313 | */ | ||
|
r338 | void QBarSeries::removeBarSet(QBarSet *set) | ||
|
r171 | { | ||
|
r425 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | ||
disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | ||||
|
r172 | mModel->removeBarSet(set); | ||
} | ||||
|
r313 | /*! | ||
Returns number of sets in series. | ||||
*/ | ||||
|
r366 | int QBarSeries::barsetCount() | ||
|
r214 | { | ||
|
r527 | if(m_model) | ||
return m_mapBarTop - m_mapBarBottom; | ||||
else | ||||
return mModel->barsetCount(); | ||||
|
r214 | } | ||
|
r323 | /*! | ||
Returns number of categories in series | ||||
*/ | ||||
|
r366 | int QBarSeries::categoryCount() | ||
|
r323 | { | ||
|
r387 | return mModel->categoryCount(); | ||
|
r323 | } | ||
|
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 | /*! | ||
|
r319 | \internal \a category | ||
|
r313 | */ | ||
|
r412 | QString QBarSeries::categoryName(int category) | ||
|
r288 | { | ||
|
r412 | return mModel->categoryName(category); | ||
|
r288 | } | ||
|
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 | { | ||
|
r487 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | ||
|
r296 | if (enabled) { | ||
|
r387 | for (int i=0; i<mModel->barsetCount(); i++) { | ||
|
r296 | QBarSet *set = mModel->setAt(i); | ||
connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | ||||
} | ||||
} else { | ||||
|
r387 | for (int i=0; i<mModel->barsetCount(); i++) { | ||
|
r296 | 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 | ||||
*/ | ||||
|
r505 | void QBarSeries::setSeparatorsVisible(bool visible) | ||
|
r288 | { | ||
|
r505 | mSeparatorsVisible = visible; | ||
emit enableSeparators(visible); | ||||
|
r280 | } | ||
|
r425 | |||
/*! | ||||
\internal \a category | ||||
*/ | ||||
void QBarSeries::barsetClicked(QString category) | ||||
{ | ||||
emit clicked(qobject_cast<QBarSet*>(sender()), category); | ||||
} | ||||
/*! | ||||
\internal \a category | ||||
*/ | ||||
void QBarSeries::barsetRightClicked(QString category) | ||||
{ | ||||
emit rightClicked(qobject_cast<QBarSet*>(sender()), category); | ||||
} | ||||
|
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; | ||||
} | ||||
|
r505 | bool QBarSeries::separatorsVisible() | ||
{ | ||||
return mSeparatorsVisible; | ||||
} | ||||
|
r527 | bool QBarSeries::setModel(QAbstractItemModel* model) | ||
{ | ||||
m_model = model; | ||||
|
r605 | return true; | ||
|
r527 | } | ||
void QBarSeries::setModelMappingCategories(int modelColumn) | ||||
{ | ||||
// | ||||
} | ||||
void QBarSeries::setModelMappingBarRange(int bottomBoundry, int topBoundry) | ||||
{ | ||||
// | ||||
} | ||||
|
r338 | #include "moc_qbarseries.cpp" | ||
|
r71 | |||
|
r56 | QTCOMMERCIALCHART_END_NAMESPACE | ||