barchartmodel_p.h
69 lines
| 1.8 KiB
| text/x-c
|
CLexer
sauimone
|
r159 | #ifndef BARCHARTMODEL_H | ||
#define BARCHARTMODEL_H | ||||
#include <QObject> | ||||
sauimone
|
r161 | #include "qchartglobal.h" | ||
sauimone
|
r159 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
sauimone
|
r161 | // Model for bar chart. Internal class. | ||
sauimone
|
r159 | // TODO: Implement as QAbstractItemModel? | ||
sauimone
|
r169 | class QBarSet; | ||
class QBarCategory; | ||||
sauimone
|
r159 | class BarChartModel : public QObject //, public QAbstractItemModel | ||
{ | ||||
Q_OBJECT | ||||
public: | ||||
sauimone
|
r169 | explicit BarChartModel(QBarCategory &category, QObject *parent = 0); | ||
sauimone
|
r161 | ~BarChartModel(); | ||
sauimone
|
r169 | |||
// TODO: remove these after add and remove QBarSet works. | ||||
sauimone
|
r161 | int addData(QList<qreal> data); | ||
void removeData(int id); | ||||
sauimone
|
r159 | |||
sauimone
|
r169 | void addBarSet(QBarSet &set); | ||
void removeBarSet(QBarSet &set); | ||||
sauimone
|
r161 | int countRows(); // Number of series in model | ||
int countColumns(); // Maximum number of items in series | ||||
sauimone
|
r159 | int countTotalItems(); // Total items in all series. Includes empty items. | ||
sauimone
|
r167 | qreal max(); // Maximum value of all series | ||
qreal min(); // Minimum value of all series | ||||
sauimone
|
r159 | qreal valueAt(int series, int item); | ||
sauimone
|
r161 | qreal columnSum(int column); | ||
qreal maxColumnSum(); // returns maximum sum of items in all columns. | ||||
sauimone
|
r159 | signals: | ||
void modelUpdated(); | ||||
public slots: | ||||
private: | ||||
sauimone
|
r161 | // Little helper class. | ||
class DataContainer { | ||||
public: | ||||
DataContainer(QList<qreal> data, int id) : mId(id), mData(data) {} | ||||
int countColumns() { return mData.count(); } | ||||
qreal valueAt(int item) { return mData.at(item); } | ||||
int mId; // TODO: Is this needed? | ||||
private: | ||||
QList<qreal> mData; | ||||
}; | ||||
// Owned. N series. each has a list of values. | ||||
QList<DataContainer*> mDataModel; | ||||
int mRunningId; | ||||
int mMaxColumns; // longest series in datamodel | ||||
sauimone
|
r169 | QBarCategory& mCategory; | ||
sauimone
|
r159 | |||
}; | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||
#endif // BARCHARTMODEL_H | ||||