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