@@ -82,7 +82,6 Window::Window(QWidget* parent) : | |||
|
82 | 82 | settingsLayout->addStretch(); |
|
83 | 83 | baseLayout->addItem(settingsLayout, 0, 3, 2, 1); |
|
84 | 84 | //create charts |
|
85 | ||
|
86 | 85 | Charts::ChartList list = Charts::chartList(); |
|
87 | 86 | |
|
88 | 87 | for(int i = 0 ; i < 9 && i<list.size() ; ++i) |
@@ -145,7 +144,6 void Window::createProxyWidgets() | |||
|
145 | 144 | |
|
146 | 145 | QComboBox* Window::createThemeBox() |
|
147 | 146 | { |
|
148 | // settings layoutQGLWidgetβ | |
|
149 | 147 | QComboBox* themeComboBox = new ComboBox(this); |
|
150 | 148 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
151 | 149 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
@@ -159,7 +157,6 QComboBox* Window::createThemeBox() | |||
|
159 | 157 | |
|
160 | 158 | QComboBox* Window::createAnimationBox() |
|
161 | 159 | { |
|
162 | // settings layout | |
|
163 | 160 | QComboBox* animationComboBox = new ComboBox(this); |
|
164 | 161 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
165 | 162 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
@@ -47,12 +47,6 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *prese | |||
|
47 | 47 | handleUpdated(); |
|
48 | 48 | |
|
49 | 49 | m_items.setHandlesChildEvents(false); |
|
50 | ||
|
51 | // TODO: how to draw a drop shadow? | |
|
52 | // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect(); | |
|
53 | // dropShadow->setOffset(2.0); | |
|
54 | // dropShadow->setBlurRadius(2.0); | |
|
55 | // setGraphicsEffect(dropShadow); | |
|
56 | 50 | } |
|
57 | 51 | |
|
58 | 52 | QRectF ScatterChartItem::boundingRect() const |
@@ -68,16 +62,14 void ScatterChartItem::createPoints(int count) | |||
|
68 | 62 | |
|
69 | 63 | switch (m_shape) { |
|
70 | 64 | case QScatterSeries::MarkerShapeCircle: { |
|
71 |
|
|
|
72 | const QRectF& rect = i->boundingRect(); | |
|
73 | i->setPos(-rect.width()/2,-rect.height()/2); | |
|
74 | item = new Marker(i,this); | |
|
65 | item = new CircleMarker(0,0,m_size,m_size,this); | |
|
66 | const QRectF& rect = item->boundingRect(); | |
|
67 | item->setPos(-rect.width()/2,-rect.height()/2); | |
|
75 | 68 | break; |
|
76 | 69 | } |
|
77 | 70 | case QScatterSeries::MarkerShapeRectangle: { |
|
78 |
|
|
|
79 | i->setPos(-m_size/2,-m_size/2); | |
|
80 | item = new Marker(i,this); | |
|
71 | item = new RectangleMarker(0,0,m_size,m_size,this); | |
|
72 | item->setPos(-m_size/2,-m_size/2); | |
|
81 | 73 | break; |
|
82 | 74 | } |
|
83 | 75 | default: |
@@ -94,13 +86,15 void ScatterChartItem::deletePoints(int count) | |||
|
94 | 86 | QList<QGraphicsItem *> items = m_items.childItems(); |
|
95 | 87 | |
|
96 | 88 | for (int i = 0; i < count; ++i) { |
|
97 |
|
|
|
89 | QGraphicsItem * item = items.takeLast(); | |
|
90 | m_markerMap.remove(item); | |
|
91 | delete(item); | |
|
98 | 92 | } |
|
99 | 93 | } |
|
100 | 94 | |
|
101 |
void ScatterChartItem::markerSelected( |
|
|
95 | void ScatterChartItem::markerSelected(QGraphicsItem *marker) | |
|
102 | 96 | { |
|
103 |
emit XYChart::clicked(calculateDomainPoint(marker |
|
|
97 | emit XYChart::clicked(calculateDomainPoint(m_markerMap[marker])); | |
|
104 | 98 | } |
|
105 | 99 | |
|
106 | 100 | void ScatterChartItem::updateGeometry() |
@@ -128,10 +122,10 void ScatterChartItem::updateGeometry() | |||
|
128 | 122 | QList<QGraphicsItem*> items = m_items.childItems(); |
|
129 | 123 | |
|
130 | 124 | for (int i = 0; i < points.size(); i++) { |
|
131 |
|
|
|
125 | QGraphicsItem* item = items.at(i); | |
|
132 | 126 | const QPointF& point = points.at(i); |
|
133 | 127 | const QRectF& rect = item->boundingRect(); |
|
134 | item->setPoint(point); | |
|
128 | m_markerMap[item]=point; | |
|
135 | 129 | item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2); |
|
136 | 130 | if(!m_visible || !clipRect().contains(point)) { |
|
137 | 131 | item->setVisible(false); |
@@ -156,14 +150,14 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * | |||
|
156 | 150 | void ScatterChartItem::setPen(const QPen& pen) |
|
157 | 151 | { |
|
158 | 152 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
159 |
static_cast< |
|
|
153 | static_cast<QAbstractGraphicsShapeItem*>(item)->setPen(pen); | |
|
160 | 154 | } |
|
161 | 155 | } |
|
162 | 156 | |
|
163 | 157 | void ScatterChartItem::setBrush(const QBrush& brush) |
|
164 | 158 | { |
|
165 | 159 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
166 |
static_cast< |
|
|
160 | static_cast<QAbstractGraphicsShapeItem*>(item)->setBrush(brush); | |
|
167 | 161 | } |
|
168 | 162 | } |
|
169 | 163 | |
@@ -195,12 +189,6 void ScatterChartItem::handleUpdated() | |||
|
195 | 189 | update(); |
|
196 | 190 | } |
|
197 | 191 | |
|
198 | void ScatterChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
|
199 | { | |
|
200 | emit XYChart::clicked(calculateDomainPoint(event->pos())); | |
|
201 | QGraphicsItem::mousePressEvent(event); | |
|
202 | } | |
|
203 | ||
|
204 | 192 | #include "moc_scatterchartitem_p.cpp" |
|
205 | 193 | |
|
206 | 194 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -38,7 +38,6 | |||
|
38 | 38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | class QScatterSeries; |
|
41 | class Marker; | |
|
42 | 41 | |
|
43 | 42 | class ScatterChartItem : public XYChart, public QGraphicsItem |
|
44 | 43 | { |
@@ -55,7 +54,7 public: | |||
|
55 | 54 | void setPen(const QPen &pen); |
|
56 | 55 | void setBrush(const QBrush &brush); |
|
57 | 56 | |
|
58 |
void markerSelected( |
|
|
57 | void markerSelected(QGraphicsItem *item); | |
|
59 | 58 | |
|
60 | 59 | public Q_SLOTS: |
|
61 | 60 | void handleUpdated(); |
@@ -66,7 +65,6 private: | |||
|
66 | 65 | |
|
67 | 66 | protected: |
|
68 | 67 | void updateGeometry(); |
|
69 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
|
70 | 68 | |
|
71 | 69 | private: |
|
72 | 70 | QScatterSeries *m_series; |
@@ -75,76 +73,47 private: | |||
|
75 | 73 | int m_shape; |
|
76 | 74 | int m_size; |
|
77 | 75 | QRectF m_rect; |
|
76 | QMap<QGraphicsItem *, QPointF> m_markerMap; | |
|
78 | 77 | }; |
|
79 | 78 | |
|
80 | ||
|
81 | class Marker: public QAbstractGraphicsShapeItem | |
|
79 | class CircleMarker: public QGraphicsEllipseItem | |
|
82 | 80 | { |
|
83 | 81 | |
|
84 | 82 | public: |
|
85 | ||
|
86 | Marker(QAbstractGraphicsShapeItem *item , ScatterChartItem *parent) : QAbstractGraphicsShapeItem(0) ,m_item(item), m_parent(parent) | |
|
87 | { | |
|
88 | } | |
|
89 | ||
|
90 | ~Marker() | |
|
91 | { | |
|
92 | delete m_item; | |
|
93 | } | |
|
94 | ||
|
95 | void setPoint(const QPointF& point) | |
|
96 | { | |
|
97 | m_point=point; | |
|
98 | } | |
|
99 | ||
|
100 | QPointF point() const | |
|
101 | { | |
|
102 | return m_point; | |
|
103 | } | |
|
104 | ||
|
105 | QPainterPath shape() const | |
|
106 | { | |
|
107 | return m_item->shape(); | |
|
108 | } | |
|
109 | ||
|
110 | QRectF boundingRect() const | |
|
83 | CircleMarker(qreal x, qreal y, qreal w, qreal h, ScatterChartItem *parent) : QGraphicsEllipseItem(x,y,w,h,parent), | |
|
84 | m_parent(parent) | |
|
111 | 85 | { |
|
112 | return m_item->boundingRect(); | |
|
113 | 86 | } |
|
114 | 87 | |
|
115 | bool contains(const QPointF &point) const | |
|
88 | protected: | |
|
89 | void mousePressEvent(QGraphicsSceneMouseEvent *event) | |
|
116 | 90 | { |
|
117 | return m_item->contains(point); | |
|
91 | m_parent->markerSelected(this); | |
|
92 | QGraphicsEllipseItem::mousePressEvent(event); | |
|
118 | 93 | } |
|
119 | 94 | |
|
120 | void setPen(const QPen &pen) | |
|
121 | { | |
|
122 | m_item->setPen(pen); | |
|
123 | } | |
|
95 | private: | |
|
96 | ScatterChartItem* m_parent; | |
|
97 | }; | |
|
124 | 98 | |
|
125 | void setBrush(const QBrush &brush) | |
|
126 | { | |
|
127 | m_item->setBrush(brush); | |
|
128 | } | |
|
99 | class RectangleMarker: public QGraphicsRectItem | |
|
100 | { | |
|
129 | 101 | |
|
130 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
102 | public: | |
|
103 | RectangleMarker(qreal x, qreal y, qreal w, qreal h, ScatterChartItem *parent) : QGraphicsRectItem(x,y,w,h,parent), | |
|
104 | m_parent(parent) | |
|
131 | 105 | { |
|
132 | m_item->paint(painter,option,widget); | |
|
133 | 106 | } |
|
134 | 107 | |
|
135 | 108 | protected: |
|
136 | ||
|
137 | 109 | void mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
138 | 110 | { |
|
139 | Q_UNUSED(event) | |
|
140 | 111 | m_parent->markerSelected(this); |
|
141 |
Q |
|
|
112 | QGraphicsRectItem::mousePressEvent(event); | |
|
142 | 113 | } |
|
143 | 114 | |
|
144 | 115 | private: |
|
145 | QAbstractGraphicsShapeItem* m_item; | |
|
146 | 116 | ScatterChartItem* m_parent; |
|
147 | QPointF m_point; | |
|
148 | 117 | }; |
|
149 | 118 | |
|
150 | 119 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now