qpieseries.h
163 lines
| 4.3 KiB
| text/x-c
|
CLexer
Jani Honkonen
|
r142 | #ifndef PIESERIES_H | ||
#define PIESERIES_H | ||||
#include "qchartseries.h" | ||||
#include <QObject> | ||||
#include <QRectF> | ||||
#include <QColor> | ||||
Jani Honkonen
|
r174 | #include <QPen> | ||
#include <QBrush> | ||||
Jani Honkonen
|
r142 | |||
class QGraphicsObject; | ||||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Jani Honkonen
|
r146 | class PiePresenter; | ||
Jani Honkonen
|
r142 | class PieSlice; | ||
Jani Honkonen
|
r174 | typedef quint64 QPieSliceId; | ||
Jani Honkonen
|
r142 | class QPieSlice | ||
{ | ||||
public: | ||||
QPieSlice() | ||||
Jani Honkonen
|
r174 | :m_id(-1), m_value(0), m_isLabelVisible(true), m_isExploded(false), m_percentage(0) {} | ||
Jani Honkonen
|
r142 | |||
Jani Honkonen
|
r174 | QPieSlice(qreal value, QString label = QString(), bool labelVisible = true, bool exploded = false, QPen pen = QPen(), QBrush brush = QBrush()) | ||
:m_id(-1), m_value(value), m_label(label), m_isLabelVisible(labelVisible), m_isExploded(exploded), m_pen(pen), m_brush(brush), m_percentage(0) {} | ||||
QPieSliceId id() const { return m_id; } | ||||
void setValue(qreal value) { m_value = value; } | ||||
qreal value() const { return m_value; } | ||||
void setLabel(QString label) { m_label = label; } | ||||
QString label() const { return m_label; } | ||||
void setLabelVisible(bool visible) { m_isLabelVisible = visible; } | ||||
bool isLabelVisible() const { return m_isLabelVisible; } | ||||
Jani Honkonen
|
r181 | // TODO: | ||
//void setLabelPen(QPen pen) {}; | ||||
//QPen labelPen() const {}; | ||||
//void setLabelFont(QFont font); | ||||
//QFont labelFont() const; | ||||
//void setLabelArmLenght(qreal len) {}; | ||||
//qreal labelArmLenght() const {}; | ||||
Jani Honkonen
|
r174 | void setExploded(bool exploded) { m_isExploded = exploded; } | ||
bool isExploded() const { return m_isExploded; } | ||||
void setPen(QPen pen) { m_pen = pen; } | ||||
QPen pen() const { return m_pen; } | ||||
void setBrush(QBrush brush) { m_brush = brush; } | ||||
QBrush brush() const { return m_brush; } | ||||
qreal percentage() const { return m_percentage; } | ||||
private: | ||||
// TODO: use private class | ||||
friend class QPieSeries; | ||||
QPieSliceId m_id; | ||||
Jani Honkonen
|
r142 | qreal m_value; | ||
QString m_label; | ||||
Jani Honkonen
|
r174 | bool m_isLabelVisible; | ||
Jani Honkonen
|
r142 | bool m_isExploded; | ||
Jani Honkonen
|
r174 | QPen m_pen; | ||
QBrush m_brush; | ||||
qreal m_percentage; // generated content | ||||
Jani Honkonen
|
r157 | }; | ||
Jani Honkonen
|
r142 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries | ||
{ | ||||
Q_OBJECT | ||||
public: | ||||
enum PiePosition { | ||||
PiePositionMaximized = 0, | ||||
PiePositionTopLeft, | ||||
PiePositionTopRight, | ||||
PiePositionBottomLeft, | ||||
PiePositionBottomRight | ||||
}; | ||||
Jani Honkonen
|
r174 | class ChangeSet | ||
{ | ||||
public: | ||||
QList<QPieSliceId> m_added; | ||||
QList<QPieSliceId> m_removed; | ||||
QList<QPieSliceId> m_changed; | ||||
}; | ||||
Jani Honkonen
|
r142 | public: | ||
QPieSeries(QObject *parent = 0); | ||||
~QPieSeries(); | ||||
public: // from QChartSeries | ||||
QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } | ||||
Jani Honkonen
|
r174 | virtual bool setData(QList<qreal> data); // TODO: remove this | ||
Jani Honkonen
|
r142 | |||
public: | ||||
Jani Honkonen
|
r174 | // TODO: should we return id/bool or what? | ||
// TODO: should we prefer passing a modifiable reference? | ||||
bool set(const QList<QPieSlice>& slices); | ||||
bool add(const QList<QPieSlice>& slices); | ||||
bool add(const QPieSlice& slice); | ||||
bool update(const QPieSlice& slice); | ||||
bool remove(QPieSliceId id); | ||||
Jani Honkonen
|
r142 | |||
int count() const { return m_slices.count(); } | ||||
Jani Honkonen
|
r174 | QList<QPieSlice> slices() const { return m_slices.values(); } | ||
QList<QPieSliceId> ids() const { return m_slices.keys(); } | ||||
QPieSlice slice(QPieSliceId id) const; | ||||
// TODO: sorting? | ||||
Jani Honkonen
|
r142 | |||
Jani Honkonen
|
r181 | // TODO: convenience functions? | ||
//void setValue(QPieSliceId id, qreal value); | ||||
//void setLabel(QPieSliceId id, QString label); | ||||
//void setPen(QPieSliceId id, QPen pen); | ||||
//void setBrush(QPieSliceId id, QBrush brush); | ||||
//void setExploded(QPieSliceId id, bool exploded); | ||||
Jani Honkonen
|
r174 | |||
Jani Honkonen
|
r142 | void setSizeFactor(qreal sizeFactor); | ||
qreal sizeFactor() const { return m_sizeFactor; } | ||||
void setPosition(PiePosition position); | ||||
PiePosition position() const { return m_position; } | ||||
Jani Honkonen
|
r157 | Q_SIGNALS: | ||
Jani Honkonen
|
r174 | void changed(const QPieSeries::ChangeSet& changeSet); | ||
Jani Honkonen
|
r157 | void sizeFactorChanged(); | ||
void positionChanged(); | ||||
Jani Honkonen
|
r181 | |||
// TODO: | ||||
Jani Honkonen
|
r174 | //void sliceClicked(QPieSliceId id); | ||
Jani Honkonen
|
r181 | // ?? void sliceHoverEnter(QPieSliceId id); | ||
// ?? void sliceHoverLeave(QPieSliceId id); | ||||
Jani Honkonen
|
r174 | |||
private: | ||||
QPieSliceId generateSliceId(); | ||||
void updateDerivativeData(); | ||||
Jani Honkonen
|
r157 | |||
Jani Honkonen
|
r142 | private: | ||
Q_DISABLE_COPY(QPieSeries) | ||||
Jani Honkonen
|
r174 | |||
Jani Honkonen
|
r142 | // TODO: use PIML | ||
Jani Honkonen
|
r174 | friend class PiePresenter; | ||
friend class PieSlice; | ||||
QHash<QPieSliceId, QPieSlice> m_slices; | ||||
Jani Honkonen
|
r142 | qreal m_sizeFactor; | ||
PiePosition m_position; | ||||
Jani Honkonen
|
r174 | qreal m_total; | ||
QPieSliceId m_sliceIdSeed; | ||||
Jani Honkonen
|
r142 | }; | ||
QTCOMMERCIALCHART_END_NAMESPACE | ||||
#endif // PIESERIES_H | ||||