barchartseries.cpp
90 lines
| 2.2 KiB
| text/x-c
|
CppLexer
sauimone
|
r71 | #include <QDebug> | ||
sauimone
|
r56 | #include "barchartseries.h" | ||
sauimone
|
r74 | #include "bargroup.h" | ||
sauimone
|
r56 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
sauimone
|
r62 | BarChartSeries::BarChartSeries(QObject *parent) | ||
sauimone
|
r56 | : QChartSeries(parent) | ||
{ | ||||
} | ||||
sauimone
|
r71 | bool BarChartSeries::setData(QAbstractItemModel* model) | ||
sauimone
|
r62 | { | ||
sauimone
|
r71 | mModel = model; | ||
sauimone
|
r62 | } | ||
sauimone
|
r56 | int BarChartSeries::min() | ||
{ | ||||
sauimone
|
r71 | Q_ASSERT(mModel->rowCount() > 0); | ||
Q_ASSERT(mModel->columnCount() > 0); | ||||
sauimone
|
r62 | |||
sauimone
|
r56 | // TODO: make min and max members and update them when data changes. | ||
// This is slower since they are checked every time, even if data is same since previous call. | ||||
sauimone
|
r71 | QModelIndex modelIndex = mModel->index(0,0); | ||
int min = mModel->data(modelIndex).toInt(); | ||||
sauimone
|
r56 | |||
sauimone
|
r71 | for (int i=0; i <mModel->rowCount(); i++) { | ||
for(int j=0; j<mModel->columnCount(); j++) { | ||||
modelIndex = mModel->index(i,j); | ||||
int temp = mModel->data(modelIndex).toInt(); | ||||
if (temp < min) { | ||||
min = temp; | ||||
} | ||||
sauimone
|
r56 | } | ||
} | ||||
return min; | ||||
} | ||||
int BarChartSeries::max() | ||||
{ | ||||
sauimone
|
r71 | Q_ASSERT(mModel->rowCount() > 0); | ||
Q_ASSERT(mModel->columnCount() > 0); | ||||
sauimone
|
r62 | |||
sauimone
|
r71 | // TODO: make min and max members and update them when data changes. | ||
// This is slower since they are checked every time, even if data is same since previous call. | ||||
QModelIndex modelIndex = mModel->index(0,0); | ||||
int max = mModel->data(modelIndex).toInt(); | ||||
sauimone
|
r56 | |||
sauimone
|
r71 | for (int i=0; i <mModel->rowCount(); i++) { | ||
for(int j=0; j<mModel->columnCount(); j++) { | ||||
modelIndex = mModel->index(i,j); | ||||
int temp = mModel->data(modelIndex).toInt(); | ||||
if (temp > max) { | ||||
max = temp; | ||||
} | ||||
sauimone
|
r56 | } | ||
} | ||||
return max; | ||||
} | ||||
sauimone
|
r71 | |||
int BarChartSeries::countSeries() | ||||
{ | ||||
return mModel->rowCount(); | ||||
} | ||||
int BarChartSeries::countItemsInSeries() | ||||
sauimone
|
r56 | { | ||
sauimone
|
r71 | return mModel->columnCount(); | ||
sauimone
|
r56 | } | ||
sauimone
|
r71 | int BarChartSeries::countTotalItems() | ||
sauimone
|
r56 | { | ||
sauimone
|
r71 | return mModel->rowCount() * mModel->columnCount(); | ||
sauimone
|
r56 | } | ||
sauimone
|
r71 | int BarChartSeries::valueAt(int series, int item) | ||
{ | ||||
QModelIndex index = mModel->index(series,item); | ||||
return mModel->data(index).toInt(); | ||||
} | ||||
void BarChartSeries::chartSizeChanged(QRectF rect) | ||||
{ | ||||
qDebug() << "barchart size changed:" << rect; | ||||
sauimone
|
r74 | // mBarGroup->resize(rect.toRect().width(), rect.toRect().height()); | ||
sauimone
|
r71 | } | ||
#include "moc_barchartseries.cpp" | ||||
sauimone
|
r56 | QTCOMMERCIALCHART_END_NAMESPACE | ||