##// END OF EJS Templates
Integrating bar chart. Cleaned up old implementation. TODO: show this in test application. how?
sauimone -
r56:c2f871dd8e7e
parent child
Show More
@@ -0,0 +1,46
1 #include "barchartseries.h"
2 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3
4 BarChartSeries::BarChartSeries(QList<int> data, QObject *parent)
5 : QChartSeries(parent)
6 , mData(data)
7 {
8 }
9
10 int BarChartSeries::min()
11 {
12 // TODO: make min and max members and update them when data changes.
13 // This is slower since they are checked every time, even if data is same since previous call.
14 int min = mData.at(0);
15
16 for (int i=0; i <mData.count(); i++) {
17 if (mData.at(i) < min) {
18 min = mData.at(i);
19 }
20 }
21 return min;
22 }
23
24 int BarChartSeries::max()
25 {
26 int max = mData.at(0);
27
28 for (int i=0; i <mData.count(); i++) {
29 if (mData.at(i) > max) {
30 max = mData.at(i);
31 }
32 }
33 return max;
34 }
35
36 int BarChartSeries::count()
37 {
38 return mData.count();
39 }
40
41 int BarChartSeries::valueAt(int i)
42 {
43 return mData.at(i);
44 }
45
46 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,34
1 #ifndef BARCHARTSERIES_H
2 #define BARCHARTSERIES_H
3
4 #include <QList>
5 #include "qchartseries.h"
6 #include "qchartglobal.h"
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10 // Container for series
11 class QTCOMMERCIALCHART_EXPORT BarChartSeries : public QChartSeries
12 {
13
14 public:
15 BarChartSeries(QList<int> data, QObject* parent=0);
16
17 // from QChartSeries
18 static QChartSeries* create(QObject* parent = 0 );
19 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
20
21 // Methods to find out minimum and maximum values of data
22 int min();
23 int max();
24 int count();
25 int valueAt(int i);
26
27 private:
28
29 QList<int> mData;
30 };
31
32 QTCOMMERCIALCHART_END_NAMESPACE
33
34 #endif // BARCHARTSERIES_H
@@ -0,0 +1,106
1 #include "bargroup.h"
2 #include "bar.h"
3 #include <QDebug>
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
7 BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) :
8 QGraphicsItem(parent)
9 ,mSeries(series)
10 ,mLayoutSet(false)
11 ,mLayoutDirty(true)
12 {
13 dataChanged();
14 }
15
16 void BarGroup::resize( int w, int h )
17 {
18 qDebug() << "QBarChart::resize";
19 mWidth = w;
20 mHeight = h;
21 layoutChanged();
22 mLayoutSet = true;
23 }
24
25 void BarGroup::setBarWidth( int w )
26 {
27 mBarDefaultWidth = w;
28 }
29
30 void BarGroup::setColor( QColor color )
31 {
32 mColor = color;
33 }
34
35 void BarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
36 {
37 if (!mLayoutSet) {
38 qDebug() << "QBarChart::paint called without layout set. Aborting.";
39 return;
40 }
41 if (mLayoutDirty) {
42 // Layout or data has changed. Need to redraw.
43 foreach(QGraphicsItem* i, childItems()) {
44 i->paint(painter,option,widget);
45 }
46 }
47 }
48
49 QRectF BarGroup::boundingRect() const
50 {
51 // TODO: correct this (currently ignores position)
52 return QRectF(0,0,mWidth,mHeight);
53 }
54
55
56 void BarGroup::dataChanged()
57 {
58 qDebug() << "QBarChart::dataChanged mSeries";
59
60 // Find out maximum and minimum of all series
61 mMax = mSeries.max();
62 mMin = mSeries.min();
63
64 // Delete old bars
65 // Is this correct way to delete childItems?
66 foreach (QGraphicsItem* item, childItems()) {
67 delete item;
68 }
69
70 // Create new graphic items for bars
71 for (int i=0; i<mSeries.count(); i++) {
72 Bar *bar = new Bar(this);
73 childItems().append(bar);
74 }
75
76 mLayoutDirty = true;
77 }
78
79 void BarGroup::layoutChanged()
80 {
81 // Scale bars to new layout
82 // Layout for bars:
83 int count = mSeries.count();
84 if (count <= 0) {
85 // Nothing to do.
86 return;
87 }
88
89 // Align center
90 int posStep = (mWidth / (count));
91 int startPos = (mWidth / count+1);
92 qDebug() << "startpos" << startPos;
93
94 // Scaling. TODO: better one.
95 for (int i=0; i<count; i++) {
96 int barHeight = mSeries.valueAt(i) * mHeight / mMax;
97 Bar* bar = reinterpret_cast<Bar*> (childItems().at(i));
98
99 bar->resize(mBarDefaultWidth, barHeight); // TODO: width settable per bar
100 bar->setColor(mColor);
101 bar->setPos(i*posStep+startPos, 0);
102 }
103 mLayoutDirty = true;
104 }
105
106 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,55
1 #ifndef QBARCHART_H
2 #define QBARCHART_H
3
4 #include <QGraphicsItem>
5
6 #include "bar.h"
7 //#include "qbarchartview.h"
8 #include "barchartseries.h"
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
12 // TODO: Better name for this? The function of this class is to know where each bar in series is laid out.
13 // Class has knowledge of single series of data (owns vs reference?)
14 class BarGroup : public QGraphicsItem
15 {
16
17 public:
18 explicit BarGroup(BarChartSeries& series, QGraphicsItem *parent = 0);
19
20 // Layout "api"
21 void resize( int w, int h ); // Size for whole series. Single bars are drawn inside this area
22 void setPos(qreal x, qreal y);
23 void setBarWidth( int w ); // Default width for each bar
24 void setColor( QColor color ); // Default color for each bar
25
26 // From QGraphicsItem
27 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
28 QRectF boundingRect() const;
29
30 private:
31
32 void dataChanged(); // data of series has changed -> need to recalculate bar sizes
33 void layoutChanged(); // layout has changed -> need to recalculate bar sizes
34
35 private:
36
37 // Data
38 BarChartSeries& mSeries;
39 int mMin; // Min and max values of data. (updated when data is changed, used when drawing)
40 int mMax;
41
42 int mHeight; // Layout spesific
43 int mWidth;
44 int mBarDefaultWidth;
45
46 QColor mColor;
47
48 bool mLayoutSet; // True, if component has been laid out.
49 bool mLayoutDirty;
50
51 };
52
53 QTCOMMERCIALCHART_END_NAMESPACE
54
55 #endif // QBARCHART_H
@@ -1,39 +1,50
1 #include "qbarchartbar.h"
1 #include "bar.h"
2 #include <QDebug>
2 #include <QDebug>
3 #include <Qpainter>
3 #include <Qpainter>
4
4
5 QBarChartBar::QBarChartBar(QGraphicsItem *parent)
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
7 Bar::Bar(QGraphicsItem *parent)
6 : QGraphicsItem(parent)
8 : QGraphicsItem(parent)
7 {
9 {
8 }
10 }
9
11
10 void QBarChartBar::setSize( int h, int w )
12 void Bar::resize( int w, int h )
11 {
13 {
12 mHeight = h;
13 mWidth = w;
14 mWidth = w;
15 mHeight = h;
14 }
16 }
15
17
16 void QBarChartBar::setColor( QColor col )
18 void Bar::setColor( QColor col )
17 {
19 {
18 mColor = col;
20 mColor = col;
19 }
21 }
22 void Bar::setPos(qreal x, qreal y)
23 {
24 mXpos = x;
25 mYpos = y;
26 }
20
27
21 void QBarChartBar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
28 void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
22 {
29 {
23 qDebug() << "QBarChartBar::paint" << scenePos();
24 // Set color for bar. TODO: gradients, textures etc
30 // Set color for bar. TODO: gradients, textures etc
25 QPen pen = painter->pen();
31 QPen pen = painter->pen();
26 pen.setColor( mColor );
32 pen.setColor( mColor );
27 pen.setWidth( mWidth );
33 pen.setWidth( mWidth );
28 painter->setPen(pen);
34 painter->setPen(pen);
29
35
30 // Draw bar
36 // Draw bar
31 painter->drawLine(scenePos().x(), scenePos().y() + parentItem()->boundingRect().height(),
37 // TODO: Pen width affects bar height for now. This should be rect
32 scenePos().x(), scenePos().y() + parentItem()->boundingRect().height() - mHeight );
38 painter->drawLine(scenePos().x() + mXpos, scenePos().y() + mYpos + parentItem()->boundingRect().height() - mHeight - mWidth,
39 scenePos().x() + mXpos, scenePos().y() + mYpos + parentItem()->boundingRect().height() - mWidth);
33 }
40 }
34
41
35 QRectF QBarChartBar::boundingRect() const
42 QRectF Bar::boundingRect() const
36 {
43 {
37 QRectF r(scenePos().x(), scenePos().y(), scenePos().x() + mWidth, scenePos().y() + mHeight );
44 // TODO: check validity of this (I suppose there is easier way, and currently this bit incorrect :)
45 // QRectF r(scenePos().x()+mXpos, scenePos().y()+mYpos, scenePos().x() + mWidth, scenePos().y() + mHeight );
46 QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight);
38 return r;
47 return r;
39 }
48 }
49
50 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,31 +1,37
1 #ifndef QBARCHARTBAR_H
1 #ifndef BAR_H
2 #define QBARCHARTBAR_H
2 #define BAR_H
3
3
4 #include <QGraphicsItem>
4 #include <QGraphicsItem>
5 #include "qchartglobal.h"
5
6
6 // Single bar item of chart
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
8
8 class QBarChartBar : public QGraphicsItem
9 // Single bar item of chart
10 class Bar : public QGraphicsItem
9 {
11 {
10 public:
12 public:
11 QBarChartBar(QGraphicsItem *parent=0);
13 Bar(QGraphicsItem *parent=0);
12
14
13 // Layout Stuff
15 // Layout Stuff
14 void setSize( int h, int w ); // Size of bar. in screen coordinates.
16 void resize( int w, int h ); // Size of bar. in screen coordinates.
15 void setColor( QColor col ); // Color of bar
17 void setColor( QColor col ); // Color of bar
18 void setPos(qreal x, qreal y);
16
19
17 public:
20 public:
18 // From QGraphicsItem
21 // From QGraphicsItem
19
22
20 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
21 QRectF boundingRect() const;
24 QRectF boundingRect() const;
22
25
23 private:
26 private:
24
27
25 int mHeight;
28 int mHeight;
26 int mWidth;
29 int mWidth;
27 QPointF mPos;
30 qreal mXpos;
31 qreal mYpos;
28 QColor mColor;
32 QColor mColor;
29 };
33 };
30
34
31 #endif // QBARCHARTBAR_H
35 QTCOMMERCIALCHART_END_NAMESPACE
36
37 #endif // BAR_H
@@ -1,150 +1,166
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartseries.h"
2 #include "qchartseries.h"
3 #include "qscatterseries.h"
3 #include "qscatterseries.h"
4 #include "qscatterseries_p.h"
4 #include "qscatterseries_p.h"
5 #include "qpieseries.h"
5 #include "qpieseries.h"
6 #include "qxychartseries.h"
6 #include "qxychartseries.h"
7
8 #include "barchartseries.h"
9 #include "bargroup.h"
10
7 #include "xylinechartitem_p.h"
11 #include "xylinechartitem_p.h"
8 #include "xyplotdomain_p.h"
12 #include "xyplotdomain_p.h"
9 #include "axis_p.h"
13 #include "axis_p.h"
10 #include "xygrid_p.h"
14 #include "xygrid_p.h"
11 #include <QGraphicsScene>
15 #include <QGraphicsScene>
12 #include <QDebug>
16 #include <QDebug>
13
17
14 QTCOMMERCIALCHART_BEGIN_NAMESPACE
18 QTCOMMERCIALCHART_BEGIN_NAMESPACE
15
19
16 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
20 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
17 m_axisX(new Axis(this)),
21 m_axisX(new Axis(this)),
18 m_axisY(new Axis(this)),
22 m_axisY(new Axis(this)),
19 m_grid(new XYGrid(this)),
23 m_grid(new XYGrid(this)),
20 m_plotDataIndex(0),
24 m_plotDataIndex(0),
21 m_marginSize(0)
25 m_marginSize(0)
22 {
26 {
23 // setFlags(QGraphicsItem::ItemClipsChildrenToShape);
27 // setFlags(QGraphicsItem::ItemClipsChildrenToShape);
24 // set axis
28 // set axis
25 m_axisY->rotate(90);
29 m_axisY->rotate(90);
26 }
30 }
27
31
28 QChart::~QChart(){}
32 QChart::~QChart(){}
29
33
30 QRectF QChart::boundingRect() const
34 QRectF QChart::boundingRect() const
31 {
35 {
32 return m_rect;
36 return m_rect;
33 }
37 }
34
38
35 void QChart::addSeries(QChartSeries* series)
39 void QChart::addSeries(QChartSeries* series)
36 {
40 {
37 // TODO: we should check the series not already added
41 // TODO: we should check the series not already added
38
42
39 m_series<<series;
43 m_series<<series;
40
44
41 switch(series->type())
45 switch(series->type())
42 {
46 {
43 case QChartSeries::SeriesTypeLine: {
47 case QChartSeries::SeriesTypeLine: {
44
48
45 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
49 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
46
50
47 XYPlotDomain domain;
51 XYPlotDomain domain;
48 //TODO "nice numbers algorithm"
52 //TODO "nice numbers algorithm"
49 domain.m_ticksX=4;
53 domain.m_ticksX=4;
50 domain.m_ticksY=4;
54 domain.m_ticksY=4;
51
55
52 for (int i = 0 ; i < xyseries->count() ; i++)
56 for (int i = 0 ; i < xyseries->count() ; i++)
53 {
57 {
54 qreal x = xyseries->x(i);
58 qreal x = xyseries->x(i);
55 qreal y = xyseries->y(i);
59 qreal y = xyseries->y(i);
56 domain.m_minX = qMin(domain.m_minX,x);
60 domain.m_minX = qMin(domain.m_minX,x);
57 domain.m_minY = qMin(domain.m_minY,y);
61 domain.m_minY = qMin(domain.m_minY,y);
58 domain.m_maxX = qMax(domain.m_maxX,x);
62 domain.m_maxX = qMax(domain.m_maxX,x);
59 domain.m_maxY = qMax(domain.m_maxY,y);
63 domain.m_maxY = qMax(domain.m_maxY,y);
60 }
64 }
61
65
62 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
66 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
63 item->updateXYPlotDomain(domain);
67 item->updateXYPlotDomain(domain);
64 m_plotDomainList<<domain;
68 m_plotDomainList<<domain;
65 m_xyLineChartItems<<item;
69 m_xyLineChartItems<<item;
66 break;
70 break;
67 }
71 }
68 // TODO: Not tested:
72 // TODO: Not tested:
69 // case QChartSeries::SeriesTypeScatter: {
73 // case QChartSeries::SeriesTypeScatter: {
70 // QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
74 // QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
71 // if (scatter) {
75 // if (scatter) {
72 // scatter->d->setParentItem(this);
76 // scatter->d->setParentItem(this);
73 // scene()->addItem(scatter->d);
77 // scene()->addItem(scatter->d);
74 // }
78 // }
75 // break;
79 // break;
76 // }
80 // }
81
82 case QChartSeries::SeriesTypeBar: {
83
84 qDebug() << "barSeries added";
85 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
86
87 // Who owns the series?
88 BarGroup* group = new BarGroup(*barSeries, this);
89 scene()->addItem(group);
90 m_BarGroupItems.append(group); // If we need to access group later
91 break;
92 }
77 }
93 }
78 }
94 }
79
95
80 QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type)
96 QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type)
81 {
97 {
82 // TODO: support also other types; not only scatter and pie
98 // TODO: support also other types; not only scatter and pie
83 Q_ASSERT(type == QChartSeries::SeriesTypeScatter
99 Q_ASSERT(type == QChartSeries::SeriesTypeScatter
84 || type == QChartSeries::SeriesTypePie);
100 || type == QChartSeries::SeriesTypePie);
85
101
86 switch (type) {
102 switch (type) {
87 case QChartSeries::SeriesTypeScatter: {
103 case QChartSeries::SeriesTypeScatter: {
88 QScatterSeries *scatterSeries = new QScatterSeries(x, y, this);
104 QScatterSeries *scatterSeries = new QScatterSeries(x, y, this);
89 connect(this, SIGNAL(sizeChanged(QRectF)),
105 connect(this, SIGNAL(sizeChanged(QRectF)),
90 scatterSeries, SLOT(chartSizeChanged(QRectF)));
106 scatterSeries, SLOT(chartSizeChanged(QRectF)));
91 scatterSeries->d->setParentItem(this);
107 scatterSeries->d->setParentItem(this);
92 return scatterSeries;
108 return scatterSeries;
93 }
109 }
94 case QChartSeries::SeriesTypePie: {
110 case QChartSeries::SeriesTypePie: {
95 // TODO: we now have also a list of y values as a parameter, it is ignored
111 // TODO: we now have also a list of y values as a parameter, it is ignored
96 // we should use a generic data class instead of list of x and y values
112 // we should use a generic data class instead of list of x and y values
97 QPieSeries *pieSeries = new QPieSeries(x, this);
113 QPieSeries *pieSeries = new QPieSeries(x, this);
98 connect(this, SIGNAL(sizeChanged(QRectF)),
114 connect(this, SIGNAL(sizeChanged(QRectF)),
99 pieSeries, SLOT(chartSizeChanged(QRectF)));
115 pieSeries, SLOT(chartSizeChanged(QRectF)));
100 return pieSeries;
116 return pieSeries;
101 }
117 }
102 default:
118 default:
103 break;
119 break;
104 }
120 }
105
121
106 return 0;
122 return 0;
107 }
123 }
108
124
109 void QChart::setSize(const QSizeF& size)
125 void QChart::setSize(const QSizeF& size)
110 {
126 {
111 m_rect = QRect(QPoint(0,0),size.toSize());
127 m_rect = QRect(QPoint(0,0),size.toSize());
112 m_rect.adjust(margin(),margin(), -margin(), -margin());
128 m_rect.adjust(margin(),margin(), -margin(), -margin());
113 m_grid->setPos(m_rect.topLeft());
129 m_grid->setPos(m_rect.topLeft());
114 m_grid->setSize(m_rect.size());
130 m_grid->setSize(m_rect.size());
115
131
116 // TODO: TTD for setting scale
132 // TODO: TTD for setting scale
117 //emit scaleChanged(100, 100);
133 //emit scaleChanged(100, 100);
118 // TODO: calculate the origo
134 // TODO: calculate the origo
119 // TODO: not sure if emitting a signal here is the best from performance point of view
135 // TODO: not sure if emitting a signal here is the best from performance point of view
120 emit sizeChanged(QRectF(0, 0, size.width(), size.height()));
136 emit sizeChanged(QRectF(0, 0, size.width(), size.height()));
121
137
122 for (int i(0); i < m_plotDomainList.size(); i++)
138 for (int i(0); i < m_plotDomainList.size(); i++)
123 m_plotDomainList[i].m_viewportRect = m_rect;
139 m_plotDomainList[i].m_viewportRect = m_rect;
124
140
125 // TODO: line chart items are updated separately as they don't support update
141 // TODO: line chart items are updated separately as they don't support update
126 // via sizeChanged signal
142 // via sizeChanged signal
127 foreach(XYLineChartItem* item ,m_xyLineChartItems)
143 foreach(XYLineChartItem* item ,m_xyLineChartItems)
128 item->updateXYPlotDomain(m_plotDomainList.at(m_plotDataIndex));
144 item->updateXYPlotDomain(m_plotDomainList.at(m_plotDataIndex));
129
145
130
146
131 if (m_plotDomainList.count())
147 if (m_plotDomainList.count())
132 m_grid->setXYPlotData(m_plotDomainList.at(m_plotDataIndex));
148 m_grid->setXYPlotData(m_plotDomainList.at(m_plotDataIndex));
133
149
134 update();
150 update();
135 }
151 }
136
152
137 int QChart::margin() const
153 int QChart::margin() const
138 {
154 {
139 return m_marginSize;
155 return m_marginSize;
140 }
156 }
141
157
142 void QChart::setMargin(int margin)
158 void QChart::setMargin(int margin)
143 {
159 {
144 m_marginSize = margin;
160 m_marginSize = margin;
145 }
161 }
146
162
147 #include "moc_qchart.cpp"
163 #include "moc_qchart.cpp"
148
164
149
165
150 QTCOMMERCIALCHART_END_NAMESPACE
166 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,64 +1,67
1 #ifndef CHART_H
1 #ifndef CHART_H
2 #define CHART_H
2 #define CHART_H
3
3
4 #include <qchartglobal.h>
4 #include <qchartglobal.h>
5 #include <qchartseries.h>
5 #include <qchartseries.h>
6 #include <QGraphicsObject>
6 #include <QGraphicsObject>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class Axis;
10 class Axis;
11 class XYGrid;
11 class XYGrid;
12 class QChartSeries;
12 class QChartSeries;
13 class XYPlotDomain;
13 class XYPlotDomain;
14 class XYLineChartItem;
14 class XYLineChartItem;
15 class BarGroup;
15
16
16 // TODO: We don't need to have QChart tied to QGraphicsItem:
17 // TODO: We don't need to have QChart tied to QGraphicsItem:
17 //class QTCOMMERCIALCHART_EXPORT QChart
18 //class QTCOMMERCIALCHART_EXPORT QChart
18 //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem {
19 //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem {
19 // public: QChartGraphicsItem(QChart &chart);
20 // public: QChartGraphicsItem(QChart &chart);
20
21
21 /*!
22 /*!
22 * TODO: define the responsibilities
23 * TODO: define the responsibilities
23 */
24 */
24 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsObject
25 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsObject
25 {
26 {
26 Q_OBJECT
27 Q_OBJECT
27 public:
28 public:
28 QChart(QGraphicsObject* parent = 0);
29 QChart(QGraphicsObject* parent = 0);
29 ~QChart();
30 ~QChart();
30
31
31 //from QGraphicsItem
32 //from QGraphicsItem
32 QRectF boundingRect() const;
33 QRectF boundingRect() const;
33 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
34 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
34
35
35 void addSeries(QChartSeries* series);
36 void addSeries(QChartSeries* series);
36 //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type);
37 //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type);
37 // TODO: who owns the series now? maybe owned by chart and returned a reference instead...
38 // TODO: who owns the series now? maybe owned by chart and returned a reference instead...
38 QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type);
39 QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type);
39
40
40 virtual void setSize(const QSizeF& rect);
41 virtual void setSize(const QSizeF& rect);
41 void setMargin(int margin);
42 void setMargin(int margin);
42 int margin() const;
43 int margin() const;
43
44
44 signals:
45 signals:
45 void sizeChanged(QRectF rect);
46 void sizeChanged(QRectF rect);
46 void scaleChanged(qreal xscale, qreal yscale);
47 void scaleChanged(qreal xscale, qreal yscale);
47
48
48 private:
49 private:
49 Q_DISABLE_COPY(QChart)
50 Q_DISABLE_COPY(QChart)
50 Axis* m_axisX;
51 Axis* m_axisX;
51 Axis* m_axisY;
52 Axis* m_axisY;
52 XYGrid* m_grid;
53 XYGrid* m_grid;
53 QRect m_rect;
54 QRect m_rect;
54 QList<const QChartSeries*> m_series;
55 QList<const QChartSeries*> m_series;
55 QList<XYPlotDomain> m_plotDomainList;
56 QList<XYPlotDomain> m_plotDomainList;
56 QList<XYLineChartItem*> m_xyLineChartItems;
57 QList<XYLineChartItem*> m_xyLineChartItems;
57 QList<QGraphicsItem*> m_items;
58 QList<QGraphicsItem*> m_items;
58 int m_plotDataIndex;
59 int m_plotDataIndex;
59 int m_marginSize;
60 int m_marginSize;
61
62 QList<BarGroup*> m_BarGroupItems;
60 };
63 };
61
64
62 QTCOMMERCIALCHART_END_NAMESPACE
65 QTCOMMERCIALCHART_END_NAMESPACE
63
66
64 #endif
67 #endif
@@ -1,38 +1,38
1 #ifndef QCHARTSERIES_H
1 #ifndef QCHARTSERIES_H
2 #define QCHARTSERIES_H
2 #define QCHARTSERIES_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QObject>
5 #include <QObject>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject
9 class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject
10 {
10 {
11
11
12 public:
12 public:
13 enum QChartSeriesType {
13 enum QChartSeriesType {
14 SeriesTypeLine = 0,
14 SeriesTypeLine = 0,
15 // SeriesTypeArea,
15 // SeriesTypeArea,
16 // SeriesTypeBar,
16 SeriesTypeBar,
17 SeriesTypePie,
17 SeriesTypePie,
18 SeriesTypeScatter
18 SeriesTypeScatter
19 // SeriesTypeSpline
19 // SeriesTypeSpline
20 };
20 };
21
21
22 protected:
22 protected:
23 QChartSeries(QObject *parent = 0):QObject(parent){};
23 QChartSeries(QObject *parent = 0):QObject(parent){};
24
24
25 public:
25 public:
26 virtual ~QChartSeries(){};
26 virtual ~QChartSeries(){};
27
27
28 //factory method
28 //factory method
29 static QChartSeries* create(QObject* parent = 0 ){ return 0;}
29 static QChartSeries* create(QObject* parent = 0 ){ return 0;}
30 //pure virtual
30 //pure virtual
31 virtual QChartSeriesType type() const = 0;
31 virtual QChartSeriesType type() const = 0;
32
32
33 };
33 };
34
34
35 QTCOMMERCIALCHART_END_NAMESPACE
35 QTCOMMERCIALCHART_END_NAMESPACE
36
36
37 #endif
37 #endif
38
38
@@ -1,39 +1,40
1 #ifndef QCHARTWIDGET_H
1 #ifndef QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qchart.h"
5 #include "qchart.h"
6 #include <QGraphicsView>
6 #include <QGraphicsView>
7
7
8 class QGraphicsScene;
8 class QGraphicsScene;
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 class QChartSeries;
12 class QChartSeries;
13 class QChartWidgetPrivate;
13 class QChartWidgetPrivate;
14
14
15 class QTCOMMERCIALCHART_EXPORT QChartWidget : public QGraphicsView
15 class QTCOMMERCIALCHART_EXPORT QChartWidget : public QGraphicsView
16 {
16 {
17 Q_OBJECT
17 Q_OBJECT
18 public:
18 public:
19 explicit QChartWidget(QWidget *parent = 0);
19 explicit QChartWidget(QWidget *parent = 0);
20 ~QChartWidget();
20 ~QChartWidget();
21
21
22 //implement from QWidget
22 //implement from QWidget
23 void resizeEvent(QResizeEvent *event);
23 void resizeEvent(QResizeEvent *event);
24 QSize sizeHint() const;
24 QSize sizeHint() const;
25
25
26 // TODO: addSeries and createSeries are optional solutions
26 // TODO: addSeries and createSeries are optional solutions
27 // TODO: currently createSeries assumes x, y value pairs. This isn't case with all charts. So is there another createSeries for other types (for example one list of ints)?
27 void addSeries(QChartSeries* series);
28 void addSeries(QChartSeries* series);
28 QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type);
29 QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type);
29
30
30 private:
31 private:
31 Q_DISABLE_COPY(QChartWidget)
32 Q_DISABLE_COPY(QChartWidget)
32 QGraphicsScene *m_scene;
33 QGraphicsScene *m_scene;
33 QChart* m_chart;
34 QChart* m_chart;
34
35
35 };
36 };
36
37
37 QTCOMMERCIALCHART_END_NAMESPACE
38 QTCOMMERCIALCHART_END_NAMESPACE
38
39
39 #endif // QCHARTWIDGET_H
40 #endif // QCHARTWIDGET_H
@@ -1,81 +1,87
1 !include( ../common.pri ) {
1 !include( ../common.pri ) {
2 error( Couldn't find the common.pri file! )
2 error( Couldn't find the common.pri file! )
3 }
3 }
4
4
5 TARGET = QtCommercialChart
5 TARGET = QtCommercialChart
6 DESTDIR = $$CHART_BUILD_LIB_DIR
6 DESTDIR = $$CHART_BUILD_LIB_DIR
7 TEMPLATE = lib
7 TEMPLATE = lib
8 QT += core \
8 QT += core \
9 gui
9 gui
10
10
11 CONFIG += debug_and_release
11 CONFIG += debug_and_release
12 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
12 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
13
13
14 SOURCES += \
14 SOURCES += \
15 barchart/barchartseries.cpp \
16 barchart/bargroup.cpp \
17 barchart/bar.cpp \
15 xylinechart/qxychartseries.cpp \
18 xylinechart/qxychartseries.cpp \
16 xylinechart/xylinechartitem.cpp \
19 xylinechart/xylinechartitem.cpp \
17 xylinechart/xygrid.cpp \
20 xylinechart/xygrid.cpp \
18 xylinechart/xyplotdomain.cpp \
21 xylinechart/xyplotdomain.cpp \
19 qscatterseries.cpp \
22 qscatterseries.cpp \
20 qpieseries.cpp \
23 qpieseries.cpp \
21 qchart.cpp \
24 qchart.cpp \
22 axis.cpp \
25 axis.cpp \
23 qchartwidget.cpp \
26 qchartwidget.cpp \
24 pieslice.cpp
27 pieslice.cpp
25
28
26 PRIVATE_HEADERS += \
29 PRIVATE_HEADERS += \
27 xylinechart/xylinechartitem_p.h \
30 xylinechart/xylinechartitem_p.h \
28 xylinechart/xyplotdomain_p.h \
31 xylinechart/xyplotdomain_p.h \
29 xylinechart/xygrid_p.h \
32 xylinechart/xygrid_p.h \
30 qscatterseries_p.h \
33 qscatterseries_p.h \
31 pieslice.h \
34 pieslice.h \
32 axis_p.h
35 axis_p.h
33
36
34 PUBLIC_HEADERS += \
37 PUBLIC_HEADERS += \
35 qchartseries.h \
38 qchartseries.h \
36 qscatterseries.h \
39 qscatterseries.h \
37 qpieseries.h \
40 qpieseries.h \
38 qchart.h \
41 qchart.h \
39 qchartwidget.h \
42 qchartwidget.h \
40 qchartglobal.h \
43 qchartglobal.h \
41 xylinechart/qxychartseries.h
44 xylinechart/qxychartseries.h \
42
45 barchart/barchartseries.h \
46 barchart/bargroup.h
47
43 HEADERS += $$PUBLIC_HEADERS
48 HEADERS += $$PUBLIC_HEADERS
44 HEADERS += $$PRIVATE_HEADERS
49 HEADERS += $$PRIVATE_HEADERS
45
50
46 INCLUDEPATH += xylinechart \
51 INCLUDEPATH += xylinechart \
52 barchart \
47 .
53 .
48
54
49 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
55 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
50 MOC_DIR = $$CHART_BUILD_DIR/lib
56 MOC_DIR = $$CHART_BUILD_DIR/lib
51 UI_DIR = $$CHART_BUILD_DIR/lib
57 UI_DIR = $$CHART_BUILD_DIR/lib
52 RCC_DIR = $$CHART_BUILD_DIR/lib
58 RCC_DIR = $$CHART_BUILD_DIR/lib
53
59
54
60
55 DEFINES += QTCOMMERCIALCHART_LIBRARY
61 DEFINES += QTCOMMERCIALCHART_LIBRARY
56
62
57 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
63 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
58 public_headers.files = $$PUBLIC_HEADERS
64 public_headers.files = $$PUBLIC_HEADERS
59 target.path = $$[QT_INSTALL_LIBS]
65 target.path = $$[QT_INSTALL_LIBS]
60 INSTALLS += target \
66 INSTALLS += target \
61 public_headers
67 public_headers
62
68
63
69
64 install_build_headers.name = bild_headers
70 install_build_headers.name = bild_headers
65 install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h
71 install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h
66 install_build_headers.input = PUBLIC_HEADERS
72 install_build_headers.input = PUBLIC_HEADERS
67 install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR
73 install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR
68 install_build_headers.CONFIG += target_predeps no_link
74 install_build_headers.CONFIG += target_predeps no_link
69 QMAKE_EXTRA_COMPILERS += install_build_headers
75 QMAKE_EXTRA_COMPILERS += install_build_headers
70
76
71 chartversion.target = qchartversion_p.h
77 chartversion.target = qchartversion_p.h
72 chartversion.commands = @echo "build_time" > $$chartversion.target;
78 chartversion.commands = @echo "build_time" > $$chartversion.target;
73 chartversion.depends = $$HEADERS $$SOURCES
79 chartversion.depends = $$HEADERS $$SOURCES
74 PRE_TARGETDEPS += qchartversion_p.h
80 PRE_TARGETDEPS += qchartversion_p.h
75 QMAKE_CLEAN+= qchartversion_p.h
81 QMAKE_CLEAN+= qchartversion_p.h
76 QMAKE_EXTRA_TARGETS += chartversion
82 QMAKE_EXTRA_TARGETS += chartversion
77
83
78 unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
84 unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
79 win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
85 win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
80
86
81
87
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now