##// END OF EJS Templates
Fix attempt to wrong graphics items hadnling
Michal Klocek -
r790:68c6a254cbfa
parent child
Show More
@@ -1,11 +1,13
1 #include "legendscrollbutton_p.h"
1 #include "legendscrollbutton_p.h"
2 #include "qlegend.h"
2 #include <QGraphicsSceneEvent>
3 #include <QGraphicsSceneEvent>
3
4
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
6
6 LegendScrollButton::LegendScrollButton(ScrollButtonId id, QGraphicsItem *parent)
7 LegendScrollButton::LegendScrollButton(ScrollButtonId id, QLegend *legend)
7 : QGraphicsPolygonItem(parent)
8 : QGraphicsPolygonItem(legend),
8 ,m_id(id)
9 m_id(id),
10 m_ledgend(legend)
9 {
11 {
10 setAcceptedMouseButtons(Qt::LeftButton);
12 setAcceptedMouseButtons(Qt::LeftButton);
11 }
13 }
@@ -17,7 +19,8 LegendScrollButton::ScrollButtonId LegendScrollButton::id()
17
19
18 void LegendScrollButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
20 void LegendScrollButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
19 {
21 {
20 emit clicked(event);
22 Q_UNUSED(event);
23 m_ledgend->scrollButtonClicked(this);
21 }
24 }
22
25
23 #include "moc_legendscrollbutton_p.cpp"
26 #include "moc_legendscrollbutton_p.cpp"
@@ -7,9 +7,10
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class LegendScrollButton : public QObject, public QGraphicsPolygonItem
10 class QLegend;
11
12 class LegendScrollButton : public QGraphicsPolygonItem
11 {
13 {
12 Q_OBJECT
13 public:
14 public:
14 enum ScrollButtonId {
15 enum ScrollButtonId {
15 ScrollButtonIdLeft,
16 ScrollButtonIdLeft,
@@ -18,19 +19,14 public:
18 ScrollButtonIdDown
19 ScrollButtonIdDown
19 };
20 };
20
21
21 explicit LegendScrollButton(ScrollButtonId id, QGraphicsItem *parent = 0);
22 explicit LegendScrollButton(ScrollButtonId id, QLegend *legend);
22 ScrollButtonId id();
23 ScrollButtonId id();
23
24
24 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
25 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
25
26
26 Q_SIGNALS:
27 void clicked(QGraphicsSceneMouseEvent* event);
28
29 public Q_SLOTS:
30
31 private:
27 private:
32
33 ScrollButtonId m_id;
28 ScrollButtonId m_id;
29 QLegend *m_ledgend;
34 };
30 };
35
31
36 QTCOMMERCIALCHART_END_NAMESPACE
32 QTCOMMERCIALCHART_END_NAMESPACE
@@ -105,6 +105,7 protected:
105 protected:
105 protected:
106 QScopedPointer<QChartPrivate> d_ptr;
106 QScopedPointer<QChartPrivate> d_ptr;
107 friend class QChartView;
107 friend class QChartView;
108 friend class QLegend;
108 Q_DISABLE_COPY(QChart)
109 Q_DISABLE_COPY(QChart)
109 };
110 };
110
111
@@ -1,5 +1,5
1 #include "qchartglobal.h"
2 #include "qlegend.h"
1 #include "qlegend.h"
2 #include "qchart_p.h"
3 #include "qseries.h"
3 #include "qseries.h"
4 #include "legendmarker_p.h"
4 #include "legendmarker_p.h"
5 #include "legendscrollbutton_p.h"
5 #include "legendscrollbutton_p.h"
@@ -66,7 +66,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
66 /*!
66 /*!
67 Constructs the legend object and sets the parent to \a parent
67 Constructs the legend object and sets the parent to \a parent
68 */
68 */
69 QLegend::QLegend(QGraphicsItem *parent) : QGraphicsObject(parent),
69 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart->d_ptr->m_presenter->rootItem()),
70 m_margin(5),
70 m_margin(5),
71 m_pos(0,0),
71 m_pos(0,0),
72 m_minimumSize(50,20), // TODO: magic numbers
72 m_minimumSize(50,20), // TODO: magic numbers
@@ -80,16 +80,6 QLegend::QLegend(QGraphicsItem *parent) : QGraphicsObject(parent),
80 m_scrollButtonRight = new LegendScrollButton(LegendScrollButton::ScrollButtonIdRight, this);
80 m_scrollButtonRight = new LegendScrollButton(LegendScrollButton::ScrollButtonIdRight, this);
81 m_scrollButtonUp = new LegendScrollButton(LegendScrollButton::ScrollButtonIdUp, this);
81 m_scrollButtonUp = new LegendScrollButton(LegendScrollButton::ScrollButtonIdUp, this);
82 m_scrollButtonDown = new LegendScrollButton(LegendScrollButton::ScrollButtonIdDown, this);
82 m_scrollButtonDown = new LegendScrollButton(LegendScrollButton::ScrollButtonIdDown, this);
83
84 connect(m_scrollButtonLeft, SIGNAL(clicked(QGraphicsSceneMouseEvent*)),
85 this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*)));
86 connect(m_scrollButtonRight, SIGNAL(clicked(QGraphicsSceneMouseEvent*)),
87 this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*)));
88 connect(m_scrollButtonUp, SIGNAL(clicked(QGraphicsSceneMouseEvent*)),
89 this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*)));
90 connect(m_scrollButtonDown, SIGNAL(clicked(QGraphicsSceneMouseEvent*)),
91 this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*)));
92
93 setZValue(ChartPresenter::LegendZValue);
83 setZValue(ChartPresenter::LegendZValue);
94 }
84 }
95
85
@@ -297,12 +287,9 void QLegend::handleMarkerDestroyed()
297 /*!
287 /*!
298 \internal \a event Handles clicked signals from scroll buttons
288 \internal \a event Handles clicked signals from scroll buttons
299 */
289 */
300 void QLegend::handleScrollButtonClicked(QGraphicsSceneMouseEvent *event)
290 void QLegend::scrollButtonClicked(LegendScrollButton *scrollButton)
301 {
291 {
302 Q_UNUSED(event); // Maybe later something happens with right click...
292 Q_ASSERT(scrollButton);
303
304 LegendScrollButton* scrollButton = static_cast<LegendScrollButton *> (sender());
305 Q_ASSERT(scrollButton);
306
293
307 switch (scrollButton->id()) {
294 switch (scrollButton->id()) {
308 case LegendScrollButton::ScrollButtonIdLeft:
295 case LegendScrollButton::ScrollButtonIdLeft:
@@ -1,8 +1,8
1 #ifndef QLEGEND_H
1 #ifndef QLEGEND_H
2 #define QLEGEND_H
2 #define QLEGEND_H
3
3
4 #include <qchartglobal.h>
4 #include <QChartGlobal>
5 #include <QGraphicsObject>
5 #include <QGraphicsWidget>
6 #include <QPen>
6 #include <QPen>
7 #include <QBrush>
7 #include <QBrush>
8
8
@@ -17,9 +17,10 class QBarSeries;
17 class QPieSeries;
17 class QPieSeries;
18 class LegendScrollButton;
18 class LegendScrollButton;
19 class QSeries;
19 class QSeries;
20 class QChart;
20
21
21 // TODO: This as widget
22 // TODO: This as widget
22 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsObject
23 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
23 {
24 {
24 Q_OBJECT
25 Q_OBJECT
25 public:
26 public:
@@ -31,9 +32,10 public:
31 LayoutLeft = Qt::AlignLeft,
32 LayoutLeft = Qt::AlignLeft,
32 LayoutRight = Qt::AlignRight
33 LayoutRight = Qt::AlignRight
33 };
34 };
35 private:
36 explicit QLegend(QChart *chart);
34
37
35 explicit QLegend(QGraphicsItem *parent = 0);
38 public:
36
37 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
39 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
38 QRectF boundingRect() const;
40 QRectF boundingRect() const;
39
41
@@ -53,6 +55,8 public:
53 void setSize(const QSizeF size);
55 void setSize(const QSizeF size);
54 void setPos(const QPointF &pos);
56 void setPos(const QPointF &pos);
55
57
58 void scrollButtonClicked(LegendScrollButton *scrollButton);
59
56 Q_SIGNALS:
60 Q_SIGNALS:
57 // for interactions.
61 // for interactions.
58 void clicked(QSeries *series, Qt::MouseButton button);
62 void clicked(QSeries *series, Qt::MouseButton button);
@@ -66,7 +70,7 public Q_SLOTS:
66 void handleAdded(QList<QPieSlice *> slices);
70 void handleAdded(QList<QPieSlice *> slices);
67 void handleRemoved(QList<QPieSlice *> slices);
71 void handleRemoved(QList<QPieSlice *> slices);
68 void handleMarkerDestroyed();
72 void handleMarkerDestroyed();
69 void handleScrollButtonClicked(QGraphicsSceneMouseEvent *event);
73
70 // PIMPL <---
74 // PIMPL <---
71
75
72 private:
76 private:
@@ -103,6 +107,7 private:
103 LegendScrollButton *m_scrollButtonUp;
107 LegendScrollButton *m_scrollButtonUp;
104 LegendScrollButton *m_scrollButtonDown;
108 LegendScrollButton *m_scrollButtonDown;
105
109
110 friend class QChart;
106 // <--- PIMPL
111 // <--- PIMPL
107 };
112 };
108
113
General Comments 0
You need to be logged in to leave comments. Login now