barchartseries.cpp
91 lines
| 2.2 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. | ||||
|
r71 | QModelIndex modelIndex = mModel->index(0,0); | ||
int min = mModel->data(modelIndex).toInt(); | ||||
|
r56 | |||
|
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; | ||||
} | ||||
|
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. | ||||
QModelIndex modelIndex = mModel->index(0,0); | ||||
int max = mModel->data(modelIndex).toInt(); | ||||
|
r56 | |||
|
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; | ||||
} | ||||
|
r56 | } | ||
} | ||||
return max; | ||||
} | ||||
|
r71 | |||
int BarChartSeries::countSeries() | ||||
{ | ||||
return mModel->rowCount(); | ||||
} | ||||
int BarChartSeries::countItemsInSeries() | ||||
|
r56 | { | ||
|
r71 | return mModel->columnCount(); | ||
|
r56 | } | ||
|
r71 | int BarChartSeries::countTotalItems() | ||
|
r56 | { | ||
|
r71 | return mModel->rowCount() * mModel->columnCount(); | ||
|
r56 | } | ||
|
r71 | int BarChartSeries::valueAt(int series, int item) | ||
{ | ||||
QModelIndex index = mModel->index(series,item); | ||||
return mModel->data(index).toInt(); | ||||
} | ||||
|
r82 | /* | ||
|
r71 | void BarChartSeries::chartSizeChanged(QRectF rect) | ||
{ | ||||
qDebug() << "barchart size changed:" << rect; | ||||
|
r74 | // mBarGroup->resize(rect.toRect().width(), rect.toRect().height()); | ||
|
r71 | } | ||
|
r82 | */ | ||
|
r71 | #include "moc_barchartseries.cpp" | ||
|
r56 | QTCOMMERCIALCHART_END_NAMESPACE | ||