##// END OF EJS Templates
barchart mouse event fix
sauimone -
r852:28f6927f312e
parent child
Show More
@@ -39,6 +39,7 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
39 m_layoutSet(false),
39 m_layoutSet(false),
40 m_series(series)
40 m_series(series)
41 {
41 {
42 setFlag(ItemClipsChildrenToShape);
42 connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString)));
43 connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString)));
43 connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
44 connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
44 connect(series, SIGNAL(restructuredBars()), this, SLOT(handleModelChanged()));
45 connect(series, SIGNAL(restructuredBars()), this, SLOT(handleModelChanged()));
@@ -49,35 +50,26 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
49 BarChartItem::~BarChartItem()
50 BarChartItem::~BarChartItem()
50 {
51 {
51 disconnect(this,SLOT(showToolTip(QPoint,QString)));
52 disconnect(this,SLOT(showToolTip(QPoint,QString)));
52 deleteItems();
53 }
53 }
54
54
55 void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
55 void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
56 {
56 {
57 if (!m_layoutSet) {
57 Q_UNUSED(painter);
58 qWarning() << "BarChartItem::paint called without layout set. Aborting.";
58 Q_UNUSED(option);
59 return;
59 Q_UNUSED(widget);
60 }
61
62 painter->save();
63 painter->setClipRect(m_clipRect);
64 foreach (Bar *bar, m_bars)
65 bar->paint(painter,option,widget);
66 foreach (BarLabel* label, m_labels)
67 label->paint(painter,option,widget);
68 painter->restore();
69 }
60 }
70
61
71 QRectF BarChartItem::boundingRect() const
62 QRectF BarChartItem::boundingRect() const
72 {
63 {
73 return m_rect.translated(-m_rect.topLeft());
64 return m_rect.translated(-m_rect.topLeft());
74 // return m_rect;
75 }
65 }
76
66
77 void BarChartItem::dataChanged()
67 void BarChartItem::dataChanged()
78 {
68 {
79 // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them?
69 // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them?
80 deleteItems();
70 foreach(QGraphicsItem *item, childItems()) {
71 delete item;
72 }
81
73
82 m_bars.clear();
74 m_bars.clear();
83 m_labels.clear();
75 m_labels.clear();
@@ -88,7 +80,7 void BarChartItem::dataChanged()
88 QString category = m_series->categoryName(c);
80 QString category = m_series->categoryName(c);
89 for (int s = 0; s < m_series->barsetCount(); s++) {
81 for (int s = 0; s < m_series->barsetCount(); s++) {
90 QBarSet *set = m_series->barsetAt(s);
82 QBarSet *set = m_series->barsetAt(s);
91 Bar *bar = new Bar(category,0); // Null parent is best :)
83 Bar *bar = new Bar(category,this);
92 m_bars.append(bar);
84 m_bars.append(bar);
93 connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons)));
85 connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons)));
94 connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint)));
86 connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint)));
@@ -101,7 +93,7 void BarChartItem::dataChanged()
101 for (int category = 0; category < m_series->categoryCount(); category++) {
93 for (int category = 0; category < m_series->categoryCount(); category++) {
102 for (int s = 0; s < m_series->barsetCount(); s++) {
94 for (int s = 0; s < m_series->barsetCount(); s++) {
103 QBarSet *set = m_series->barsetAt(s);
95 QBarSet *set = m_series->barsetAt(s);
104 BarLabel *value = new BarLabel(*set, 0);
96 BarLabel *value = new BarLabel(*set, this);
105 m_labels.append(value);
97 m_labels.append(value);
106 connect(set,SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool)));
98 connect(set,SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool)));
107 }
99 }
@@ -175,15 +167,6 void BarChartItem::setLayout(const QVector<QRectF> &layout)
175
167
176 update();
168 update();
177 }
169 }
178
179 void BarChartItem::deleteItems()
180 {
181 foreach (Bar *bar, m_bars)
182 delete bar;
183 foreach (BarLabel* label, m_labels)
184 delete label;
185 }
186
187 //handlers
170 //handlers
188
171
189 void BarChartItem::handleModelChanged(int index)
172 void BarChartItem::handleModelChanged(int index)
@@ -57,9 +57,6 public:
57
57
58 QRectF geometry() const { return m_rect;}
58 QRectF geometry() const { return m_rect;}
59
59
60 private:
61 void deleteItems();
62
63 public Q_SLOTS:
60 public Q_SLOTS:
64 void handleModelChanged(int index);
61 void handleModelChanged(int index);
65 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
62 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
General Comments 0
You need to be logged in to leave comments. Login now