##// END OF EJS Templates
values visibility handling changed in barchart
sauimone -
r813:95eb00cb8ef8
parent child
Show More
@@ -41,7 +41,6 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
41 41 {
42 42 connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString)));
43 43 connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
44 //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged()));
45 44 connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int)));
46 45 setZValue(ChartPresenter::BarSeriesZValue);
47 46 dataChanged();
@@ -76,7 +75,7 void BarChartItem::dataChanged()
76 75 delete item;
77 76
78 77 m_bars.clear();
79 m_floatingValues.clear();
78 m_values.clear();
80 79 m_layout.clear();
81 80
82 81 // Create new graphic items for bars
@@ -100,8 +99,8 void BarChartItem::dataChanged()
100 99 QBarSet *set = m_series->barsetAt(s);
101 100 BarValue *value = new BarValue(*set, this);
102 101 childItems().append(value);
103 m_floatingValues.append(value);
104 connect(set, SIGNAL(toggleFloatingValues()), value, SLOT(toggleVisible()));
102 m_values.append(value);
103 connect(set,SIGNAL(valuesVisibleChanged(bool)),value,SLOT(valuesVisibleChanged(bool)));
105 104 }
106 105 }
107 106 }
@@ -152,7 +151,7 QVector<QRectF> BarChartItem::calculateLayout()
152 151 qreal yPos = height;
153 152 for (int set=0; set < m_series->barsetCount(); set++) {
154 153 qreal barHeight = m_series->valueAt(set, category) * scale;
155 BarValue* value = m_floatingValues.at(itemIndex);
154 BarValue* value = m_values.at(itemIndex);
156 155
157 156 QBarSet* barSet = m_series->barsetAt(set);
158 157
@@ -84,7 +84,7 protected:
84 84 // Not owned.
85 85 QBarSeries *m_series;
86 86 QList<Bar *> m_bars;
87 QList<BarValue *> m_floatingValues;
87 QList<BarValue *> m_values;
88 88 };
89 89
90 90 QTCOMMERCIALCHART_END_NAMESPACE
@@ -29,6 +29,7 BarValue::BarValue(QBarSet &set, QGraphicsItem *parent) : QGraphicsObject(parent
29 29 m_barSet(set),
30 30 m_textItem(new QGraphicsSimpleTextItem(this))
31 31 {
32 // connect(&set,SIGNAL(valuesVisibleChanged(bool)),value,SLOT(valuesVisibleChanged(bool)));
32 33 setVisible(false);
33 34 }
34 35
@@ -78,10 +79,9 QRectF BarValue::boundingRect() const
78 79 return m_textItem->boundingRect();
79 80 }
80 81
81 void BarValue::toggleVisible()
82 void BarValue::valuesVisibleChanged(bool visible)
82 83 {
83 qDebug() << "toggle visible";
84 setVisible(!isVisible());
84 setVisible(visible);
85 85 }
86 86
87 87 #include "moc_barvalue_p.cpp"
@@ -54,7 +54,7 public:
54 54 QRectF boundingRect() const;
55 55
56 56 public Q_SLOTS:
57 void toggleVisible();
57 void valuesVisibleChanged(bool visible);
58 58
59 59 private:
60 60
@@ -71,7 +71,7 QVector<QRectF> PercentBarChartItem::calculateLayout()
71 71 qreal scale = (height / colSum);
72 72 for (int set=0; set < m_series->barsetCount(); set++) {
73 73 qreal barHeight = m_series->valueAt(set,category) * scale;
74 BarValue* value = m_floatingValues.at(itemIndex);
74 BarValue* value = m_values.at(itemIndex);
75 75
76 76 QBarSet* barSet = m_series->barsetAt(set);
77 77
@@ -391,6 +391,14 QBarCategories QBarSeries::categories() const
391 391 return categories;
392 392 }
393 393
394 void QBarSeries::setValuesVisible(bool visible)
395 {
396 foreach (QBarSet* s, barSets()) {
397 s->setValuesVisible(visible);
398 }
399 }
400
401
394 402 #include "moc_qbarseries.cpp"
395 403
396 404 QTCOMMERCIALCHART_END_NAMESPACE
@@ -51,6 +51,8 public:
51 51 QList<QBarSet*> barSets() const;
52 52 QBarCategories categories() const;
53 53
54 void setValuesVisible(bool visible = true);
55
54 56 bool setModel(QAbstractItemModel *model);
55 57 QAbstractItemModel *modelExt() { return m_model; }
56 58 void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical);
@@ -199,6 +199,14 QPen QBarSet::floatingValuePen() const
199 199 }
200 200
201 201 /*!
202 Sets the visibility of barset values to \a visible
203 */
204 void QBarSet::setValuesVisible(bool visible)
205 {
206 emit valuesVisibleChanged(visible);
207 }
208
209 /*!
202 210 \internal \a pos
203 211 */
204 212 void QBarSet::barHoverEnterEvent(QPoint pos)
@@ -58,17 +58,18 public:
58 58 void setFloatingValuePen(const QPen &pen);
59 59 QPen floatingValuePen() const;
60 60
61 void setValuesVisible(bool visible = true);
62
61 63 Q_SIGNALS:
62 64 void clicked(QString category, Qt::MouseButtons button); // Clicked and hover signals exposed to user
63 void toggleFloatingValues();
64 65
65 // TODO: Expose this to user or not?
66 66 // TODO: TO PIMPL --->
67 67 void structureChanged();
68 68 void valueChanged();
69 69 void hoverEnter(QPoint pos);
70 70 void hoverLeave();
71 71 void showToolTip(QPoint pos, QString tip); // Private signal
72 void valuesVisibleChanged(bool visible);
72 73 // <--- TO PIMPL
73 74
74 75 public Q_SLOTS:
@@ -77,7 +77,7 QVector<QRectF> StackedBarChartItem::calculateLayout()
77 77 qreal yPos = height;
78 78 for (int set=0; set < m_series->barsetCount(); set++) {
79 79 qreal barHeight = m_series->valueAt(set, category) * scale;
80 BarValue* value = m_floatingValues.at(itemIndex);
80 BarValue* value = m_values.at(itemIndex);
81 81
82 82 QBarSet* barSet = m_series->barsetAt(set);
83 83
General Comments 0
You need to be logged in to leave comments. Login now