##// END OF EJS Templates
tst_qchart and tst_qchartview updates
tst_qchart and tst_qchartview updates

File last commit:

r850:ce48b0dbab03
r914:5d82b4aac9d4
Show More
barchartmodel.cpp
199 lines | 4.8 KiB | text/x-c | CppLexer
Jani Honkonen
Add license headers
r794 /****************************************************************************
**
** Copyright (C) 2012 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
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
percent barchart layout fix. signal fix
r850 qreal BarChartModel::absoluteCategorySum(int category) const
{
qreal sum(0);
int count = m_dataModel.count(); // Count sets
for (int set = 0; set < count; set++) {
if (category < m_dataModel.at(set)->count())
sum += qAbs(m_dataModel.at(set)->valueAt(category));
}
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