##// END OF EJS Templates
Revert "Fixes line uder grid issue"...
Revert "Fixes line uder grid issue" This reverts commit 3ea3ba4a33950ea7420e16913d228ed53fe566c3.

File last commit:

r173:5bd6f6e4373b
r191:0b54368f72bb
Show More
barchartmodel.cpp
151 lines | 3.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
fixed bug in category implementation. model now owns the category and sets
r173 BarChartModel::BarChartModel(QBarCategory *category, QObject *parent) :
sauimone
model prototyping for bar chart
r159 QObject(parent)
sauimone
proof of concept implementation for barset and barcategory
r169 ,mCategory(category)
sauimone
model prototyping for bar chart
r159 {
}
sauimone
fixed bug in category implementation. model now owns the category and sets
r173 BarChartModel::~BarChartModel()
sauimone
model prototyping for bar chart
r159 {
sauimone
fixed bug in category implementation. model now owns the category and sets
r173 delete mCategory;
sauimone
model prototyping for bar chart
r159 }
sauimone
fixed bug in category implementation. model now owns the category and sets
r173
QBarCategory& BarChartModel::category()
sauimone
proof of concept implementation for barset and barcategory
r169 {
sauimone
fixed bug in category implementation. model now owns the category and sets
r173 return *mCategory;
sauimone
proof of concept implementation for barset and barcategory
r169 }
sauimone
fixed bug in category implementation. model now owns the category and sets
r173 void BarChartModel::addBarSet(QBarSet *set)
sauimone
proof of concept implementation for barset and barcategory
r169 {
sauimone
fixed bug in category implementation. model now owns the category and sets
r173 mDataModel.append(set);
sauimone
proof of concept implementation for barset and barcategory
r169 }
sauimone
fixed bug in category implementation. model now owns the category and sets
r173 void BarChartModel::removeBarSet(QBarSet *set)
{
if (mDataModel.contains(set)) {
mDataModel.removeOne(set);
delete set;
}
}
sauimone
proof of concept implementation for barset and barcategory
r169
sauimone
Barset and barcategory implememtation. Updated test application
r171 int BarChartModel::countSets()
sauimone
model prototyping for bar chart
r159 {
sauimone
model delegate for bar series. updated examples
r161 return mDataModel.count();
sauimone
model prototyping for bar chart
r159 }
sauimone
Barset and barcategory implememtation. Updated test application
r171 int BarChartModel::countCategories()
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
Barset and barcategory implememtation. Updated test application
r171 int temp = mDataModel.at(i)->count();
sauimone
model prototyping for bar chart
r159 if (temp > count) {
count = temp;
}
}
return count;
}
int BarChartModel::countTotalItems()
{
sauimone
Barset and barcategory implememtation. Updated test application
r171 int total = mDataModel.count() * countCategories();
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
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++) {
sauimone
Barset and barcategory implememtation. Updated test application
r171 int itemCount = mDataModel.at(i)->count();
sauimone
model delegate for bar series. updated examples
r161 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
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++) {
sauimone
Barset and barcategory implememtation. Updated test application
r171 int itemCount = mDataModel.at(i)->count();
sauimone
model delegate for bar series. updated examples
r161 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;
}
sauimone
Barset and barcategory implememtation. Updated test application
r171 qreal BarChartModel::valueAt(int set, int category)
sauimone
model prototyping for bar chart
r159 {
sauimone
Barset and barcategory implememtation. Updated test application
r171 if ((set < 0) || (set >= mDataModel.count())) {
// No set, no value.
sauimone
model prototyping for bar chart
r159 return 0;
sauimone
Barset and barcategory implememtation. Updated test application
r171 } else if ((category < 0) || (category >= mDataModel.at(set)->count())) {
// No category, no value.
sauimone
model prototyping for bar chart
r159 return 0;
}
sauimone
Barset and barcategory implememtation. Updated test application
r171 return mDataModel.at(set)->valueAt(category);
sauimone
model delegate for bar series. updated examples
r161 }
sauimone
Barset and barcategory implememtation. Updated test application
r171 qreal BarChartModel::categorySum(int column)
sauimone
model delegate for bar series. updated examples
r161 {
sauimone
Barset and barcategory implememtation. Updated test application
r171 qreal sum(0);
sauimone
model delegate for bar series. updated examples
r161 int count = mDataModel.count(); // Count rows
for (int row = 0; row < count; row++) {
sauimone
Barset and barcategory implememtation. Updated test application
r171 if (column < mDataModel.at(row)->count()) {
sauimone
model delegate for bar series. updated examples
r161 sum += mDataModel.at(row)->valueAt(column);
}
}
return sum;
}
sauimone
Barset and barcategory implememtation. Updated test application
r171 qreal BarChartModel::maxCategorySum()
sauimone
model delegate for bar series. updated examples
r161 {
sauimone
Barset and barcategory implememtation. Updated test application
r171 qreal max = INT_MIN;
int count = countCategories();
sauimone
model delegate for bar series. updated examples
r161
for (int col=0; col<count; col++) {
sauimone
Barset and barcategory implememtation. Updated test application
r171 qreal sum = categorySum(col);
sauimone
model delegate for bar series. updated examples
r161 if (sum > max) {
max = sum;
}
}
return max;
sauimone
model prototyping for bar chart
r159 }
sauimone
removed barchartseriesbase. functionality is now in model
r172 QString BarChartModel::label(int category)
{
sauimone
fixed bug in category implementation. model now owns the category and sets
r173 return mCategory->label(category);
sauimone
removed barchartseriesbase. functionality is now in model
r172 }
sauimone
model prototyping for bar chart
r159 #include "moc_barchartmodel_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE