##// END OF EJS Templates
BarGroup and Bar as ChartItems instead of GraphicItems
sauimone -
r74:5412c444e1e8
parent child
Show More
@@ -4,11 +4,23
4
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 Bar::Bar(QGraphicsItem *parent)
7 Bar::Bar(ChartItem *parent)
8 : QGraphicsItem(parent)
8 : ChartItem(parent)
9 {
9 {
10 }
10 }
11
11
12 void Bar::setSize(const QSize& size)
13 {
14 //mSize = size;
15 mWidth = size.width();
16 mHeight = size.height();
17 }
18
19 void Bar::setPlotDomain(const PlotDomain& data)
20 {
21 mPlotDomain = data;
22 }
23
12 void Bar::resize( int w, int h )
24 void Bar::resize( int w, int h )
13 {
25 {
14 mWidth = w;
26 mWidth = w;
@@ -1,16 +1,20
1 #ifndef BAR_H
1 #ifndef BAR_H
2 #define BAR_H
2 #define BAR_H
3
3
4 #include <QGraphicsItem>
4 #include "chartitem_p.h"
5 #include "qchartglobal.h"
5 #include "qchartglobal.h"
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 // Single bar item of chart
9 // Single bar item of chart
10 class Bar : public QGraphicsItem
10 class Bar : public ChartItem
11 {
11 {
12 public:
12 public:
13 Bar(QGraphicsItem *parent=0);
13 Bar(ChartItem *parent=0);
14
15 // From ChartItem
16 virtual void setSize(const QSize& size);
17 virtual void setPlotDomain(const PlotDomain& data);
14
18
15 // Layout Stuff
19 // Layout Stuff
16 void resize( int w, int h ); // Size of bar. in screen coordinates.
20 void resize( int w, int h ); // Size of bar. in screen coordinates.
@@ -30,6 +34,8 private:
30 qreal mXpos;
34 qreal mXpos;
31 qreal mYpos;
35 qreal mYpos;
32 QColor mColor;
36 QColor mColor;
37
38 PlotDomain mPlotDomain;
33 };
39 };
34
40
35 QTCOMMERCIALCHART_END_NAMESPACE
41 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,5 +1,6
1 #include <QDebug>
1 #include <QDebug>
2 #include "barchartseries.h"
2 #include "barchartseries.h"
3 #include "bargroup.h"
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
5
5 BarChartSeries::BarChartSeries(QObject *parent)
6 BarChartSeries::BarChartSeries(QObject *parent)
@@ -12,7 +13,6 bool BarChartSeries::setData(QAbstractItemModel* model)
12 mModel = model;
13 mModel = model;
13 }
14 }
14
15
15
16 int BarChartSeries::min()
16 int BarChartSeries::min()
17 {
17 {
18 Q_ASSERT(mModel->rowCount() > 0);
18 Q_ASSERT(mModel->rowCount() > 0);
@@ -79,10 +79,10 int BarChartSeries::valueAt(int series, int item)
79 return mModel->data(index).toInt();
79 return mModel->data(index).toInt();
80 }
80 }
81
81
82
83 void BarChartSeries::chartSizeChanged(QRectF rect)
82 void BarChartSeries::chartSizeChanged(QRectF rect)
84 {
83 {
85 qDebug() << "barchart size changed:" << rect;
84 qDebug() << "barchart size changed:" << rect;
85 // mBarGroup->resize(rect.toRect().width(), rect.toRect().height());
86 }
86 }
87
87
88 #include "moc_barchartseries.cpp"
88 #include "moc_barchartseries.cpp"
@@ -7,6 +7,9
7 #include "qchartseries.h"
7 #include "qchartseries.h"
8 #include "qchartglobal.h"
8 #include "qchartglobal.h"
9
9
10 // TODO: Can this class be combined with series?
11 class BarGroup;
12
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
14
12 // Container for series
15 // Container for series
@@ -36,8 +39,8 public Q_SLOTS:
36
39
37 private:
40 private:
38
41
39 //QList<int> mData;
40 QAbstractItemModel* mModel;
42 QAbstractItemModel* mModel;
43 BarGroup* mBarGroup;
41 };
44 };
42
45
43 QTCOMMERCIALCHART_END_NAMESPACE
46 QTCOMMERCIALCHART_END_NAMESPACE
@@ -10,8 +10,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 //BarGroup::BarGroup(QGraphicsItem *parent) :
10 //BarGroup::BarGroup(QGraphicsItem *parent) :
11 // QGraphicsItem(parent)
11 // QGraphicsItem(parent)
12 // ,mSeries(series)
12 // ,mSeries(series)
13 BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) :
13 BarGroup::BarGroup(BarChartSeries& series, ChartItem *parent) :
14 QGraphicsItem(parent)
14 ChartItem(parent)
15 ,mSeries(series)
15 ,mSeries(series)
16 ,mLayoutSet(false)
16 ,mLayoutSet(false)
17 ,mLayoutDirty(true)
17 ,mLayoutDirty(true)
@@ -1,10 +1,8
1 #ifndef QBARCHART_H
1 #ifndef QBARCHART_H
2 #define QBARCHART_H
2 #define QBARCHART_H
3
3
4 #include <QGraphicsObject>
4 #include "chartitem_p.h"
5
6 #include "bar.h"
5 #include "bar.h"
7 //#include "qbarchartview.h"
8 #include "barchartseries.h"
6 #include "barchartseries.h"
9
7
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -12,7 +10,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 // TODO: Better name for this? The function of this class is to know where each bar in series is laid out.
10 // TODO: Better name for this? The function of this class is to know where each bar in series is laid out.
13 //class BarGroup : public QGraphicsItemGroup
11 //class BarGroup : public QGraphicsItemGroup
14
12
15 class BarGroup : public QGraphicsItem
13 class BarGroup : public ChartItem
16 {
14 {
17 /* // TODO: implement as singleton?
15 /* // TODO: implement as singleton?
18 private:
16 private:
@@ -29,7 +27,7 public:
29 private:
27 private:
30 */
28 */
31 public:
29 public:
32 explicit BarGroup(BarChartSeries& series, QGraphicsItem *parent = 0);
30 explicit BarGroup(BarChartSeries& series, ChartItem *parent = 0);
33
31
34 // Layout "api"
32 // Layout "api"
35 void resize( int w, int h ); // Size for whole series. Single bars are drawn inside this area
33 void resize( int w, int h ); // Size for whole series. Single bars are drawn inside this area
General Comments 0
You need to be logged in to leave comments. Login now