##// END OF EJS Templates
toggling of floating values. still bit buggy
sauimone -
r267:8eda47151036
parent child
Show More
@@ -69,7 +69,7 void BarPresenterBase::dataChanged()
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(barClicked()));
72 connect(bar,SIGNAL(clicked()),set,SLOT(toggleFloatingValuesVisible()));
73 }
73 }
74 }
74 }
75
75
@@ -93,17 +93,30 void BarPresenterBase::dataChanged()
93
93
94 // Create floating values
94 // Create floating values
95 for (int s=0; s<mModel.countSets(); s++) {
95 for (int s=0; s<mModel.countSets(); s++) {
96 QBarSet *set = mModel.nextSet(0==s);
96 for (int category=0; category<mModel.countCategories(); category++) {
97 for (int category=0; category<mModel.countCategories(); category++) {
97 BarValue *value = new BarValue(this);
98 BarValue *value = new BarValue(*set, this);
98 childItems().append(value);
99 childItems().append(value);
99 mFloatingValues.append(value);
100 mFloatingValues.append(value);
100 }
101 }
102 connect(set,SIGNAL(setFloatingValuesVisible(QBarSet*)),this,SLOT(setFloatingValues(QBarSet*)));
101 }
103 }
102
104
103 // TODO: if (autolayout) { layoutChanged() } or something
105 // TODO: if (autolayout) { layoutChanged() } or something
104 mLayoutDirty = true;
106 mLayoutDirty = true;
105 }
107 }
106
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
107 //handlers
120 //handlers
108
121
109 void BarPresenterBase::handleModelChanged(int index)
122 void BarPresenterBase::handleModelChanged(int index)
@@ -41,6 +41,9 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
44 protected slots:
47 protected slots:
45 void handleModelChanged(int index);
48 void handleModelChanged(int index);
46 void handleDomainChanged(const Domain& domain);
49 void handleDomainChanged(const Domain& domain);
@@ -4,8 +4,9
4
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 BarValue::BarValue(QGraphicsItem *parent)
7 BarValue::BarValue(QBarSet &set, QGraphicsItem *parent)
8 : QGraphicsItem(parent)
8 : QGraphicsItem(parent)
9 ,mBarSet(set)
9 {
10 {
10 // setVisible(false);
11 // setVisible(false);
11 }
12 }
@@ -42,6 +43,11 void BarValue::setPos(qreal x, qreal y)
42 mYpos = y;
43 mYpos = y;
43 }
44 }
44
45
46 bool BarValue::belongsToSet(QBarSet *set)
47 {
48 return (&mBarSet == set);
49 }
50
45 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
51 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
46 {
52 {
47 painter->setPen(mPen);
53 painter->setPen(mPen);
@@ -7,14 +7,15
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class QBarSet;
10
11
11 // Visual class for floating bar values
12 // Visual class for floating bar values
12 // TODO: fonts, colors etc.
13 // TODO: fonts, colors etc.
13 // By default these are not visible.
14 // By default these are not visible.
14 class BarValue : public QGraphicsItem
15 class BarValue : public QGraphicsItem // TODO: public QGraphicsObject for signals?
15 {
16 {
16 public:
17 public:
17 BarValue(QGraphicsItem *parent = 0);
18 BarValue(QBarSet &set, QGraphicsItem *parent = 0);
18
19
19 void setValueString(QString str);
20 void setValueString(QString str);
20 QString valueString();
21 QString valueString();
@@ -25,12 +26,15 public:
25 void resize(qreal w, qreal h);
26 void resize(qreal w, qreal h);
26 void setPos(qreal x, qreal y);
27 void setPos(qreal x, qreal y);
27
28
29 bool belongsToSet(QBarSet *set);
30
28 // From QGraphicsItem
31 // From QGraphicsItem
29 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
32 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
30 QRectF boundingRect() const;
33 QRectF boundingRect() const;
31
34
32 private:
35 private:
33
36
37 QBarSet& mBarSet;
34 QPen mPen;
38 QPen mPen;
35 QString mValueString;
39 QString mValueString;
36
40
@@ -5,6 +5,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
5
6 QBarSet::QBarSet()
6 QBarSet::QBarSet()
7 {
7 {
8 mFloatingValuesVisible = false;
8 }
9 }
9
10
10 void QBarSet::setName(QString name)
11 void QBarSet::setName(QString name)
@@ -57,6 +58,11 const QBrush& QBarSet::brush() const
57 return mBrush;
58 return mBrush;
58 }
59 }
59
60
61 bool QBarSet::isFloatingValuesVisible()
62 {
63 return mFloatingValuesVisible;
64 }
65
60 void QBarSet::barClicked()
66 void QBarSet::barClicked()
61 {
67 {
62 qDebug() << "QBarset::barClicked";
68 qDebug() << "QBarset::barClicked";
@@ -65,6 +71,18 void QBarSet::barClicked()
65 emit clicked(); // Notify that set has been clicked
71 emit clicked(); // Notify that set has been clicked
66 }
72 }
67
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
68
86
69 #include "moc_qbarset.cpp"
87 #include "moc_qbarset.cpp"
70 QTCOMMERCIALCHART_END_NAMESPACE
88 QTCOMMERCIALCHART_END_NAMESPACE
@@ -27,8 +27,11 public:
27 void setBrush(const QBrush& brush);
27 void setBrush(const QBrush& brush);
28 const QBrush& brush() const;
28 const QBrush& brush() const;
29
29
30 bool isFloatingValuesVisible();
31
30 Q_SIGNALS:
32 Q_SIGNALS:
31 void clicked();
33 void clicked();
34 void setFloatingValuesVisible(QBarSet* set);
32 /*
35 /*
33 void hoverEnter();
36 void hoverEnter();
34 void hoverLeave();
37 void hoverLeave();
@@ -36,6 +39,7 Q_SIGNALS:
36
39
37 public Q_SLOTS:
40 public Q_SLOTS:
38 void barClicked();
41 void barClicked();
42 void toggleFloatingValuesVisible();
39
43
40 private:
44 private:
41
45
@@ -44,6 +48,7 private:
44 QPen mPen;
48 QPen mPen;
45 QBrush mBrush;
49 QBrush mBrush;
46
50
51 bool mFloatingValuesVisible;
47 };
52 };
48
53
49 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now