##// END OF EJS Templates
Adds owvership to domain
Adds owvership to domain

File last commit:

r776:2e4d7bdf36a4
r787:e08865d3185f
Show More
barchartmodel.cpp
168 lines | 3.7 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
minor code review fixes
r762 BarChartModel::BarChartModel(QStringList categories, QObject *parent) : QObject(parent),
sauimone
minor code review fixes, part n
r763 m_category(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
minor code review fixes, part n
r763 return m_category;
sauimone
proof of concept implementation for barset and barcategory
r169 }
sauimone
const to getters, renamed addBarset to appendBarset
r776 void BarChartModel::appendBarSet(QBarSet *set)
sauimone
proof of concept implementation for barset and barcategory
r169 {
sauimone
minor code review fixes, part n
r763 m_dataModel.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)
{
sauimone
minor code review fixes, part n
r763 if (m_dataModel.contains(set)) {
m_dataModel.removeOne(set);
sauimone
fixed bug in category implementation. model now owns the category and sets
r173 }
}
sauimone
proof of concept implementation for barset and barcategory
r169
Marek Rosa
Adding data to BarSet through model added
r662 void BarChartModel::insertBarSet(int i, QBarSet *set)
{
sauimone
minor code review fixes, part n
r763 m_dataModel.insert(i, set);
Marek Rosa
Adding data to BarSet through model added
r662 }
void BarChartModel::insertCategory(int i, QString category)
{
sauimone
minor code review fixes, part n
r763 m_category.insert(i, category);
Marek Rosa
Adding data to BarSet through model added
r662 }
Marek Rosa
Removing data from BarSeries through model added
r663 void BarChartModel::removeCategory(int i)
{
sauimone
minor code review fixes, part n
r763 m_category.removeAt(i);
Marek Rosa
Removing data from BarSeries through model added
r663 }
sauimone
const to getters, renamed addBarset to appendBarset
r776 QBarSet* BarChartModel::barsetAt(int index) const
sauimone
Added pen & brush to QBarSet
r214 {
sauimone
minor code review fixes, part n
r763 return m_dataModel.at(index);
sauimone
Added pen & brush to QBarSet
r214 }
sauimone
const to getters, renamed addBarset to appendBarset
r776 QList<QBarSet*> BarChartModel::barSets() const
sauimone
Added pen & brush to QBarSet
r214 {
sauimone
minor code review fixes, part n
r763 return m_dataModel;
sauimone
Added pen & brush to QBarSet
r214 }
sauimone
const to getters, renamed addBarset to appendBarset
r776 int BarChartModel::barsetCount() const
sauimone
model prototyping for bar chart
r159 {
sauimone
minor code review fixes, part n
r763 return m_dataModel.count();
sauimone
model prototyping for bar chart
r159 }
sauimone
const to getters, renamed addBarset to appendBarset
r776 int BarChartModel::categoryCount() const
sauimone
model prototyping for bar chart
r159 {
sauimone
minor code review fixes, part n
r763 return m_category.count();
sauimone
model prototyping for bar chart
r159 }
sauimone
const to getters, renamed addBarset to appendBarset
r776 qreal BarChartModel::min() const
sauimone
model prototyping for bar chart
r159 {
sauimone
minor code review fixes, part n
r763 Q_ASSERT(m_dataModel.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
minor code review fixes, part n
r763 for (int i = 0; i < m_dataModel.count(); i++) {
int itemCount = m_dataModel.at(i)->count();
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 for (int j = 0; j < itemCount; j++) {
sauimone
minor code review fixes, part n
r763 qreal temp = m_dataModel.at(i)->valueAt(j);
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 if (temp < min)
sauimone
model delegate for bar series. updated examples
r161 min = temp;
sauimone
model prototyping for bar chart
r159 }
}
return min;
}
sauimone
const to getters, renamed addBarset to appendBarset
r776 qreal BarChartModel::max() const
sauimone
model prototyping for bar chart
r159 {
sauimone
minor code review fixes, part n
r763 Q_ASSERT(m_dataModel.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
minor code review fixes, part n
r763 for (int i = 0; i < m_dataModel.count(); i++) {
int itemCount = m_dataModel.at(i)->count();
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 for (int j = 0; j < itemCount; j++) {
sauimone
minor code review fixes, part n
r763 qreal temp = m_dataModel.at(i)->valueAt(j);
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 if (temp > max)
sauimone
model delegate for bar series. updated examples
r161 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
const to getters, renamed addBarset to appendBarset
r776 qreal BarChartModel::valueAt(int set, int category) const
sauimone
model prototyping for bar chart
r159 {
sauimone
minor code review fixes, part n
r763 if ((set < 0) || (set >= m_dataModel.count())) {
sauimone
Barset and barcategory implememtation. Updated test application
r171 // No set, no value.
sauimone
model prototyping for bar chart
r159 return 0;
sauimone
minor code review fixes, part n
r763 } else if ((category < 0) || (category >= m_dataModel.at(set)->count())) {
sauimone
Barset and barcategory implememtation. Updated test application
r171 // No category, no value.
sauimone
model prototyping for bar chart
r159 return 0;
}
sauimone
minor code review fixes, part n
r763 return m_dataModel.at(set)->valueAt(category);
sauimone
model delegate for bar series. updated examples
r161 }
sauimone
const to getters, renamed addBarset to appendBarset
r776 qreal BarChartModel::percentageAt(int set, int category) const
sauimone
Floating values to bar charts
r263 {
sauimone
minor code review fixes, part n
r763 if ((set < 0) || (set >= m_dataModel.count())) {
sauimone
Floating values to bar charts
r263 // No set, no value.
return 0;
sauimone
minor code review fixes, part n
r763 } else if ((category < 0) || (category >= m_dataModel.at(set)->count())) {
sauimone
Floating values to bar charts
r263 // No category, no value.
return 0;
}
sauimone
minor code review fixes, part n
r763 qreal value = m_dataModel.at(set)->valueAt(category);
sauimone
Floating values to bar charts
r263 qreal total = categorySum(category);
sauimone
code review fixes
r764 if ( qFuzzyCompare(total, 0) )
return 0;
sauimone
Floating values to bar charts
r263
return value / total;
}
sauimone
const to getters, renamed addBarset to appendBarset
r776 qreal BarChartModel::categorySum(int category) const
sauimone
model delegate for bar series. updated examples
r161 {
sauimone
Barset and barcategory implememtation. Updated test application
r171 qreal sum(0);
sauimone
minor code review fixes, part n
r763 int count = m_dataModel.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++) {
sauimone
minor code review fixes, part n
r763 if (category < m_dataModel.at(set)->count())
sum += m_dataModel.at(set)->valueAt(category);
sauimone
model delegate for bar series. updated examples
r161 }
return sum;
}
sauimone
const to getters, renamed addBarset to appendBarset
r776 qreal BarChartModel::maxCategorySum() const
sauimone
model delegate for bar series. updated examples
r161 {
sauimone
Barset and barcategory implememtation. Updated test application
r171 qreal max = INT_MIN;
sauimone
Updated barchart examples and documentation. Also bug fix to barchart model
r387 int count = categoryCount();
sauimone
model delegate for bar series. updated examples
r161
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 for (int col = 0; col < count; col++) {
sauimone
Barset and barcategory implememtation. Updated test application
r171 qreal sum = categorySum(col);
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737 if (sum > max)
sauimone
model delegate for bar series. updated examples
r161 max = sum;
}
return max;
sauimone
model prototyping for bar chart
r159 }
sauimone
right click feature for bar series. Enables drilldown
r412 QString BarChartModel::categoryName(int category)
sauimone
removed barchartseriesbase. functionality is now in model
r172 {
sauimone
minor code review fixes, part n
r763 return m_category.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