##// END OF EJS Templates
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.

File last commit:

r165:2ff4f264aa68
r165:2ff4f264aa68
Show More
barchartmodel.cpp
157 lines | 3.9 KiB | text/x-c | CppLexer
sauimone
model prototyping for bar chart
r159 #include <limits.h>
sauimone
model delegate for bar series. updated examples
r161 #include <QVector>
#include <QDebug>
sauimone
model prototyping for bar chart
r159 #include "barchartmodel_p.h"
QTCOMMERCIALCHART_BEGIN_NAMESPACE
BarChartModel::BarChartModel(QObject *parent) :
QObject(parent)
sauimone
model delegate for bar series. updated examples
r161 ,mRunningId(1)
sauimone
model prototyping for bar chart
r159 {
}
sauimone
model delegate for bar series. updated examples
r161 BarChartModel::~BarChartModel()
sauimone
model prototyping for bar chart
r159 {
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarChartModel::~BarChartModel";
sauimone
model delegate for bar series. updated examples
r161 foreach (DataContainer* c, mDataModel) {
delete c;
}
sauimone
model prototyping for bar chart
r159 }
sauimone
model delegate for bar series. updated examples
r161 int BarChartModel::addData(QList<qreal> data)
sauimone
model prototyping for bar chart
r159 {
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarChartModel::addData" << data.count();
sauimone
model delegate for bar series. updated examples
r161 DataContainer* c = new DataContainer(data,mRunningId);
mDataModel.append(c);
mRunningId++;
return mRunningId-1;
}
void BarChartModel::removeData(int id)
{
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarChartModel::removeData";
sauimone
model delegate for bar series. updated examples
r161 foreach(DataContainer* c, mDataModel) {
if (c->mId == id) {
mDataModel.removeOne(c);
delete c;
}
sauimone
model prototyping for bar chart
r159 }
}
sauimone
model delegate for bar series. updated examples
r161 int BarChartModel::countRows()
sauimone
model prototyping for bar chart
r159 {
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarChartModel::countRows";
sauimone
model delegate for bar series. updated examples
r161 return mDataModel.count();
sauimone
model prototyping for bar chart
r159 }
sauimone
model delegate for bar series. updated examples
r161 int BarChartModel::countColumns()
sauimone
model prototyping for bar chart
r159 {
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarChartModel::countColumns";
sauimone
model prototyping for bar chart
r159 int count(0);
sauimone
model delegate for bar series. updated examples
r161 for (int i=0; i<mDataModel.count(); i++){
sauimone
barchart mvp model integrating
r160 // TODO: can we assume that all series have same number of values? If not. then which values are empty?
sauimone
model delegate for bar series. updated examples
r161 int temp = mDataModel.at(i)->countColumns();
sauimone
model prototyping for bar chart
r159 if (temp > count) {
count = temp;
}
}
return count;
}
int BarChartModel::countTotalItems()
{
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarChartModel::countTotalItems";
sauimone
model delegate for bar series. updated examples
r161 int total = mDataModel.count() * countColumns();
sauimone
model prototyping for bar chart
r159 return total;
}
int BarChartModel::min()
{
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarChartModel::min";
sauimone
model delegate for bar series. updated examples
r161 Q_ASSERT(mDataModel.count() > 0);
sauimone
model prototyping for bar chart
r159 // 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.
int min = INT_MAX;
sauimone
model delegate for bar series. updated examples
r161 for (int i=0; i <mDataModel.count(); i++) {
int itemCount = mDataModel.at(i)->countColumns();
for (int j=0; j<itemCount; j++) {
int temp = mDataModel.at(i)->valueAt(j);
if (temp < min) {
min = temp;
}
sauimone
model prototyping for bar chart
r159 }
}
return min;
}
int BarChartModel::max()
{
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarChartModel::max";
sauimone
model delegate for bar series. updated examples
r161 Q_ASSERT(mDataModel.count() > 0);
sauimone
model prototyping for bar chart
r159
// 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.
int max = INT_MIN;
sauimone
model delegate for bar series. updated examples
r161 for (int i=0; i <mDataModel.count(); i++) {
int itemCount = mDataModel.at(i)->countColumns();
for (int j=0; j<itemCount; j++) {
int temp = mDataModel.at(i)->valueAt(j);
if (temp > max) {
max = temp;
}
sauimone
model prototyping for bar chart
r159 }
}
sauimone
model delegate for bar series. updated examples
r161
sauimone
model prototyping for bar chart
r159 return max;
}
qreal BarChartModel::valueAt(int series, int item)
{
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarChartModel::valueAt" << series << item;
sauimone
model delegate for bar series. updated examples
r161 if ((series < 0) || (series >= mDataModel.count())) {
sauimone
model prototyping for bar chart
r159 // No series, no value.
return 0;
sauimone
model delegate for bar series. updated examples
r161 } else if ((item < 0) || (item >= mDataModel.at(series)->countColumns())) {
sauimone
model prototyping for bar chart
r159 // No item, no value.
return 0;
}
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "ValueAt" << series << item << "=" << mDataModel.at(series)->valueAt(item);
sauimone
model delegate for bar series. updated examples
r161 return mDataModel.at(series)->valueAt(item);
}
qreal BarChartModel::columnSum(int column)
{
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarChartModel::columnSum";
sauimone
model delegate for bar series. updated examples
r161 int sum(0);
int count = mDataModel.count(); // Count rows
for (int row = 0; row < count; row++) {
if (column < mDataModel.at(row)->countColumns()) {
sum += mDataModel.at(row)->valueAt(column);
}
}
return sum;
}
qreal BarChartModel::maxColumnSum()
{
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarChartModel::maxColumnSum";
sauimone
model delegate for bar series. updated examples
r161 int max = INT_MIN;
int count = countColumns();
for (int col=0; col<count; col++) {
int sum = columnSum(col);
if (sum > max) {
max = sum;
}
}
return max;
sauimone
model prototyping for bar chart
r159 }
#include "moc_barchartmodel_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE