##// END OF EJS Templates
Checkbox for anti-alias to chartwidgettest
Checkbox for anti-alias to chartwidgettest

File last commit:

r377:a61a7697be62
r379:ef3b0565576e
Show More
barchartmodel.cpp
183 lines | 4.0 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 "qbarset.h"
sauimone
model prototyping for bar chart
r159
QTCOMMERCIALCHART_BEGIN_NAMESPACE
sauimone
replaced qbarcategory with qstringlist
r377 BarChartModel::BarChartModel(QStringList categories, QObject *parent) :
sauimone
model prototyping for bar chart
r159 QObject(parent)
sauimone
replaced qbarcategory with qstringlist
r377 ,mCategory(categories)
sauimone
model prototyping for bar chart
r159 {
}
sauimone
replaced qbarcategory with qstringlist
r377 QStringList BarChartModel::category()
sauimone
model prototyping for bar chart
r159 {
sauimone
replaced qbarcategory with qstringlist
r377 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);
}
}
sauimone
proof of concept implementation for barset and barcategory
r169
sauimone
review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators
r357 QBarSet* BarChartModel::setAt(int index)
sauimone
Added pen & brush to QBarSet
r214 {
sauimone
review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators
r357 return mDataModel.at(index);
sauimone
Added pen & brush to QBarSet
r214 }
sauimone
review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators
r357 QList<QBarSet*> BarChartModel::barSets()
sauimone
Added pen & brush to QBarSet
r214 {
sauimone
review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators
r357 return mDataModel;
sauimone
Added pen & brush to QBarSet
r214 }
sauimone
barcharts: added legend to model. added signals for hover events (for tooltip). updated examples
r280 QList<QString> BarChartModel::legend()
{
QList<QString> legend;
for (int i=0; i<mDataModel.count(); i++) {
legend.append(mDataModel.at(i)->name());
}
return legend;
}
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
Floating values to bar charts
r263 qreal BarChartModel::percentageAt(int set, int category)
{
if ((set < 0) || (set >= mDataModel.count())) {
// No set, no value.
return 0;
} else if ((category < 0) || (category >= mDataModel.at(set)->count())) {
// No category, no value.
return 0;
}
qreal value = mDataModel.at(set)->valueAt(category);
qreal total = categorySum(category);
if (0 == total) {
return 100.0;
}
return value / total;
}
qreal BarChartModel::categorySum(int category)
sauimone
model delegate for bar series. updated examples
r161 {
sauimone
Barset and barcategory implememtation. Updated test application
r171 qreal sum(0);
sauimone
Floating values to bar charts
r263 int count = mDataModel.count(); // Count sets
sauimone
model delegate for bar series. updated examples
r161
sauimone
Floating values to bar charts
r263 for (int set = 0; set < count; set++) {
if (category < mDataModel.at(set)->count()) {
sum += mDataModel.at(set)->valueAt(category);
sauimone
model delegate for bar series. updated examples
r161 }
}
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
replaced qbarcategory with qstringlist
r377 return mCategory.at(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