##// END OF EJS Templates
proof of concept implementation for barset and barcategory
proof of concept implementation for barset and barcategory

File last commit:

r169:1723c50daa1e
r169:1723c50daa1e
Show More
barchartmodel.cpp
175 lines | 4.3 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"
sauimone
proof of concept implementation for barset and barcategory
r169 #include "qbarcategory.h"
#include "qbarset.h"
sauimone
model prototyping for bar chart
r159
QTCOMMERCIALCHART_BEGIN_NAMESPACE
sauimone
proof of concept implementation for barset and barcategory
r169 BarChartModel::BarChartModel(QBarCategory &category, QObject *parent) :
sauimone
model prototyping for bar chart
r159 QObject(parent)
sauimone
model delegate for bar series. updated examples
r161 ,mRunningId(1)
sauimone
proof of concept implementation for barset and barcategory
r169 ,mCategory(category)
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++;
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167 emit modelUpdated();
sauimone
model delegate for bar series. updated examples
r161 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
added labels to series, intergrated with test app. minor hack to test app
r167 emit modelUpdated();
sauimone
model prototyping for bar chart
r159 }
sauimone
proof of concept implementation for barset and barcategory
r169 void BarChartModel::addBarSet(QBarSet &set)
{
DataContainer* c = new DataContainer(set.mValues,mRunningId);
mDataModel.append(c);
mRunningId++;
}
void BarChartModel::removeBarSet(QBarSet &set)
{
// TODO:
}
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;
}
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167 qreal BarChartModel::min()
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::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.
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167 qreal min = INT_MAX;
sauimone
model prototyping for bar chart
r159
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++) {
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167 qreal temp = mDataModel.at(i)->valueAt(j);
sauimone
model delegate for bar series. updated examples
r161 if (temp < min) {
min = temp;
}
sauimone
model prototyping for bar chart
r159 }
}
return min;
}
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167 qreal BarChartModel::max()
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::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.
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167 qreal max = INT_MIN;
sauimone
model prototyping for bar chart
r159
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++) {
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167 qreal temp = mDataModel.at(i)->valueAt(j);
sauimone
model delegate for bar series. updated examples
r161 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