##// END OF EJS Templates
floating values working now. bounding rect bug fixed
sauimone -
r273:108ca5a00d74
parent child
Show More
@@ -26,15 +26,15 int main(int argc, char *argv[])
26
26
27 // Create some test data to chart
27 // Create some test data to chart
28 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
28 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
29 *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
29 // *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
30 *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
30 // *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
31 *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
31 // *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
32 *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
32 *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
33
33
34 series0->addBarSet(set0);
34 series0->addBarSet(set0);
35 series0->addBarSet(set1);
35 // series0->addBarSet(set1);
36 series0->addBarSet(set2);
36 // series0->addBarSet(set2);
37 series0->addBarSet(set3);
37 // series0->addBarSet(set3);
38 series0->addBarSet(set4);
38 series0->addBarSet(set4);
39
39
40 ChartWidget* chartWidget = new ChartWidget(&window);
40 ChartWidget* chartWidget = new ChartWidget(&window);
@@ -63,7 +63,7 void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidg
63
63
64 QRectF Bar::boundingRect() const
64 QRectF Bar::boundingRect() const
65 {
65 {
66 QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight);
66 QRectF r(mXpos, mYpos, mWidth, mHeight);
67 return r;
67 return r;
68 }
68 }
69
69
@@ -51,10 +51,9 QBarSet* BarChartModel::nextSet(bool getFirst)
51 return set;
51 return set;
52 }
52 }
53
53
54
54 QBarSet* BarChartModel::setAt(int index)
55 QBarSet& BarChartModel::setAt(int index)
56 {
55 {
57 return *mDataModel.at(index);
56 return mDataModel.at(index);
58 }
57 }
59
58
60 int BarChartModel::countSets()
59 int BarChartModel::countSets()
@@ -23,8 +23,7 public:
23 void addBarSet(QBarSet *set);
23 void addBarSet(QBarSet *set);
24 void removeBarSet(QBarSet *set);
24 void removeBarSet(QBarSet *set);
25 QBarSet* nextSet(bool getFirst);
25 QBarSet* nextSet(bool getFirst);
26
26 QBarSet *setAt(int index);
27 QBarSet& setAt(int index); // Internal
28
27
29 int countSets(); // Number of sets in model
28 int countSets(); // Number of sets in model
30 int countCategories(); // Number of categories
29 int countCategories(); // Number of categories
@@ -29,7 +29,7 void BarLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
29
29
30 QRectF BarLabel::boundingRect() const
30 QRectF BarLabel::boundingRect() const
31 {
31 {
32 QRectF r(mXpos, mYpos, mXpos + mSize.width(), mYpos + mSize.height());
32 QRectF r(mXpos, mYpos, mSize.width(), mSize.height());
33 return r;
33 return r;
34 }
34 }
35
35
@@ -52,7 +52,7 void BarPresenter::layoutChanged()
52
52
53 // TODO: width settable per bar?
53 // TODO: width settable per bar?
54 bar->resize(mBarDefaultWidth, barHeight);
54 bar->resize(mBarDefaultWidth, barHeight);
55 bar->setBrush(mModel.setAt(set).brush());
55 bar->setBrush(mModel.setAt(set)->brush());
56 bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + set * mBarDefaultWidth, mHeight);
56 bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + set * mBarDefaultWidth, mHeight);
57 itemIndex++;
57 itemIndex++;
58 xPos += mBarDefaultWidth;
58 xPos += mBarDefaultWidth;
@@ -63,13 +63,13 void BarPresenterBase::dataChanged()
63 mFloatingValues.clear();
63 mFloatingValues.clear();
64
64
65 // Create new graphic items for bars
65 // Create new graphic items for bars
66 for (int s=0; s<mModel.countSets(); s++) {
67 QBarSet *set = mModel.nextSet(0==s);
68 for (int c=0; c<mModel.countCategories(); c++) {
66 for (int c=0; c<mModel.countCategories(); c++) {
67 for (int s=0; s<mModel.countSets(); s++) {
68 QBarSet *set = mModel.setAt(s);
69 Bar *bar = new Bar(this);
69 Bar *bar = new Bar(this);
70 childItems().append(bar);
70 childItems().append(bar);
71 mBars.append(bar);
71 mBars.append(bar);
72 connect(bar,SIGNAL(clicked()),set,SLOT(toggleFloatingValuesVisible()));
72 connect(bar,SIGNAL(clicked()),set,SLOT(barClicked()));
73 }
73 }
74 }
74 }
75
75
@@ -92,31 +92,20 void BarPresenterBase::dataChanged()
92 }
92 }
93
93
94 // Create floating values
94 // Create floating values
95 for (int s=0; s<mModel.countSets(); s++) {
96 QBarSet *set = mModel.nextSet(0==s);
97 for (int category=0; category<mModel.countCategories(); category++) {
95 for (int category=0; category<mModel.countCategories(); category++) {
96 for (int s=0; s<mModel.countSets(); s++) {
97 QBarSet *set = mModel.setAt(s);
98 BarValue *value = new BarValue(*set, this);
98 BarValue *value = new BarValue(*set, this);
99 childItems().append(value);
99 childItems().append(value);
100 mFloatingValues.append(value);
100 mFloatingValues.append(value);
101 connect(set,SIGNAL(clicked()),value,SLOT(toggleVisible()));
101 }
102 }
102 connect(set,SIGNAL(setFloatingValuesVisible(QBarSet*)),this,SLOT(setFloatingValues(QBarSet*)));
103 }
103 }
104
104
105 // TODO: if (autolayout) { layoutChanged() } or something
105 // TODO: if (autolayout) { layoutChanged() } or something
106 mLayoutDirty = true;
106 mLayoutDirty = true;
107 }
107 }
108
108
109 void BarPresenterBase::setFloatingValues(QBarSet *set)
110 {
111 qDebug() << "BarPresenterBase::setFloatingValues";
112 // TODO: better way to map set to BarValues?
113 for (int i=0; i<mFloatingValues.count(); i++) {
114 if (mFloatingValues.at(i)->belongsToSet(set)) {
115 mFloatingValues.at(i)->setVisible(set->isFloatingValuesVisible());
116 }
117 }
118 }
119
120 //handlers
109 //handlers
121
110
122 void BarPresenterBase::handleModelChanged(int index)
111 void BarPresenterBase::handleModelChanged(int index)
@@ -41,9 +41,6 public:
41 virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes
41 virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes
42 virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes
42 virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes
43
43
44 public Q_SLOTS:
45 void setFloatingValues(QBarSet *set);
46
47 protected slots:
44 protected slots:
48 void handleModelChanged(int index);
45 void handleModelChanged(int index);
49 void handleDomainChanged(const Domain& domain);
46 void handleDomainChanged(const Domain& domain);
@@ -5,10 +5,10
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 BarValue::BarValue(QBarSet &set, QGraphicsItem *parent)
7 BarValue::BarValue(QBarSet &set, QGraphicsItem *parent)
8 : QGraphicsItem(parent)
8 : QGraphicsObject(parent)
9 ,mBarSet(set)
9 ,mBarSet(set)
10 {
10 {
11 // setVisible(false);
11 setVisible(false);
12 }
12 }
13
13
14 void BarValue::setValueString(QString str)
14 void BarValue::setValueString(QString str)
@@ -56,9 +56,14 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
56
56
57 QRectF BarValue::boundingRect() const
57 QRectF BarValue::boundingRect() const
58 {
58 {
59 QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight);
59 QRectF r(mXpos, mYpos, mWidth, mHeight);
60 return r;
60 return r;
61 }
61 }
62
62
63 void BarValue::toggleVisible()
64 {
65 setVisible(!isVisible());
66 }
63
67
68 #include "moc_barvalue_p.cpp"
64 QTCOMMERCIALCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
@@ -2,7 +2,7
2 #define BARVALUE_P_H
2 #define BARVALUE_P_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QGraphicsItem>
5 #include <QGraphicsObject>
6 #include <QPen>
6 #include <QPen>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -12,8 +12,9 class QBarSet;
12 // Visual class for floating bar values
12 // Visual class for floating bar values
13 // TODO: fonts, colors etc.
13 // TODO: fonts, colors etc.
14 // By default these are not visible.
14 // By default these are not visible.
15 class BarValue : public QGraphicsItem // TODO: public QGraphicsObject for signals?
15 class BarValue : public QGraphicsObject
16 {
16 {
17 Q_OBJECT
17 public:
18 public:
18 BarValue(QBarSet &set, QGraphicsItem *parent = 0);
19 BarValue(QBarSet &set, QGraphicsItem *parent = 0);
19
20
@@ -32,6 +33,9 public:
32 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
33 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
33 QRectF boundingRect() const;
34 QRectF boundingRect() const;
34
35
36 public Q_SLOTS:
37 void toggleVisible();
38
35 private:
39 private:
36
40
37 QBarSet& mBarSet;
41 QBarSet& mBarSet;
@@ -50,7 +50,7 void PercentBarPresenter::layoutChanged()
50
50
51 // TODO: width settable per bar?
51 // TODO: width settable per bar?
52 bar->resize(mBarDefaultWidth, barHeight);
52 bar->resize(mBarDefaultWidth, barHeight);
53 bar->setBrush(mModel.setAt(set).brush());
53 bar->setBrush(mModel.setAt(set)->brush());
54 bar->setPos(xPos, yPos-barHeight);
54 bar->setPos(xPos, yPos-barHeight);
55 itemIndex++;
55 itemIndex++;
56 yPos -= barHeight;
56 yPos -= barHeight;
@@ -65,24 +65,11 bool QBarSet::isFloatingValuesVisible()
65
65
66 void QBarSet::barClicked()
66 void QBarSet::barClicked()
67 {
67 {
68 qDebug() << "QBarset::barClicked";
68 qDebug() << "QBarset::barClicked" << this;
69 // Some bar of this set has been clicked
69 // Some bar of this set has been clicked
70 // TODO: What happens then?
70 // TODO: What happens then?
71 emit clicked(); // Notify that set has been clicked
71 emit clicked(); // Notify that set has been clicked
72 }
72 }
73
73
74 void QBarSet::toggleFloatingValuesVisible()
75 {
76 qDebug() << "QBarset::toggleFloatingValuesVisible";
77 // TODO: toggle vs explicit set?
78 if (mFloatingValuesVisible) {
79 mFloatingValuesVisible=false;
80 } else {
81 mFloatingValuesVisible=true;
82 }
83 emit setFloatingValuesVisible(this);
84 }
85
86
87 #include "moc_qbarset.cpp"
74 #include "moc_qbarset.cpp"
88 QTCOMMERCIALCHART_END_NAMESPACE
75 QTCOMMERCIALCHART_END_NAMESPACE
@@ -31,7 +31,6 public:
31
31
32 Q_SIGNALS:
32 Q_SIGNALS:
33 void clicked();
33 void clicked();
34 void setFloatingValuesVisible(QBarSet* set);
35 /*
34 /*
36 void hoverEnter();
35 void hoverEnter();
37 void hoverLeave();
36 void hoverLeave();
@@ -39,7 +38,6 Q_SIGNALS:
39
38
40 public Q_SLOTS:
39 public Q_SLOTS:
41 void barClicked();
40 void barClicked();
42 void toggleFloatingValuesVisible();
43
41
44 private:
42 private:
45
43
@@ -55,7 +55,7 void StackedBarPresenter::layoutChanged()
55 Bar* bar = mBars.at(itemIndex);
55 Bar* bar = mBars.at(itemIndex);
56
56
57 bar->resize(mBarDefaultWidth, barHeight);
57 bar->resize(mBarDefaultWidth, barHeight);
58 bar->setBrush(mModel.setAt(set).brush());
58 bar->setBrush(mModel.setAt(set)->brush());
59 bar->setPos(xPos, yPos-barHeight);
59 bar->setPos(xPos, yPos-barHeight);
60 itemIndex++;
60 itemIndex++;
61 yPos -= barHeight;
61 yPos -= barHeight;
General Comments 0
You need to be logged in to leave comments. Login now