barchartseries.cpp
79 lines
| 1.8 KiB
| text/x-c
|
CppLexer
|
r71 | #include <QDebug> | ||
|
r56 | #include "barchartseries.h" | ||
|
r74 | #include "bargroup.h" | ||
|
r56 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
|
r62 | BarChartSeries::BarChartSeries(QObject *parent) | ||
|
r56 | : QChartSeries(parent) | ||
{ | ||||
} | ||||
|
r71 | bool BarChartSeries::setData(QAbstractItemModel* model) | ||
|
r62 | { | ||
|
r71 | mModel = model; | ||
|
r62 | } | ||
|
r56 | int BarChartSeries::min() | ||
{ | ||||
|
r71 | Q_ASSERT(mModel->rowCount() > 0); | ||
Q_ASSERT(mModel->columnCount() > 0); | ||||
|
r62 | |||
|
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. | ||||
|
r94 | int min = INT_MAX; | ||
|
r56 | |||
|
r71 | for (int i=0; i <mModel->rowCount(); i++) { | ||
for(int j=0; j<mModel->columnCount(); j++) { | ||||
|
r94 | int temp = mModel->data(mModel->index(i,j)).toInt(); | ||
|
r71 | if (temp < min) { | ||
min = temp; | ||||
} | ||||
|
r56 | } | ||
} | ||||
return min; | ||||
} | ||||
int BarChartSeries::max() | ||||
{ | ||||
|
r71 | Q_ASSERT(mModel->rowCount() > 0); | ||
Q_ASSERT(mModel->columnCount() > 0); | ||||
|
r62 | |||
|
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. | ||||
|
r94 | int max = INT_MIN; | ||
|
r56 | |||
|
r71 | for (int i=0; i <mModel->rowCount(); i++) { | ||
for(int j=0; j<mModel->columnCount(); j++) { | ||||
|
r94 | int temp = mModel->data(mModel->index(i,j)).toInt(); | ||
|
r71 | if (temp > max) { | ||
max = temp; | ||||
} | ||||
|
r56 | } | ||
} | ||||
return max; | ||||
} | ||||
|
r71 | |||
int BarChartSeries::countSeries() | ||||
{ | ||||
return mModel->rowCount(); | ||||
} | ||||
|
r94 | int BarChartSeries::countColumns() | ||
|
r56 | { | ||
|
r71 | return mModel->columnCount(); | ||
|
r56 | } | ||
|
r71 | int BarChartSeries::countTotalItems() | ||
|
r56 | { | ||
|
r71 | return mModel->rowCount() * mModel->columnCount(); | ||
|
r56 | } | ||
|
r94 | int BarChartSeries::valueAt(int row, int column) | ||
|
r71 | { | ||
|
r94 | return mModel->data(mModel->index(row,column)).toInt(); | ||
|
r71 | } | ||
#include "moc_barchartseries.cpp" | ||||
|
r56 | QTCOMMERCIALCHART_END_NAMESPACE | ||