@@ -1,4 +1,5 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
|
2 | #include "qlegend.h" | |||
2 | #include "qchartaxis.h" |
|
3 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
4 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
5 | #include "chartdataset_p.h" | |
@@ -57,8 +58,12 void ChartPresenter::createConnections() | |||||
57 |
|
58 | |||
58 | void ChartPresenter::handleGeometryChanged() |
|
59 | void ChartPresenter::handleGeometryChanged() | |
59 | { |
|
60 | { | |
|
61 | qDebug() << "legend h:" << m_chart->legend()->size().height(); | |||
60 | QRectF rect(QPoint(0,0),m_chart->size()); |
|
62 | QRectF rect(QPoint(0,0),m_chart->size()); | |
61 |
rect.adjust(m_padding, |
|
63 | rect.adjust(m_padding, | |
|
64 | m_padding + m_chart->legend()->size().height(), | |||
|
65 | -m_padding, | |||
|
66 | -m_padding); | |||
62 |
|
67 | |||
63 | //rewrite zoom stack |
|
68 | //rewrite zoom stack | |
64 | /* |
|
69 | /* | |
@@ -273,7 +278,7 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) | |||||
273 | m_themeForce = force; |
|
278 | m_themeForce = force; | |
274 | m_chartTheme = ChartTheme::createTheme(theme); |
|
279 | m_chartTheme = ChartTheme::createTheme(theme); | |
275 | m_chartTheme->decorate(m_chart,m_themeForce); |
|
280 | m_chartTheme->decorate(m_chart,m_themeForce); | |
276 |
m_chartTheme->decorate( |
|
281 | m_chartTheme->decorate(m_chart->legend(),m_themeForce); | |
277 | resetAllElements(); |
|
282 | resetAllElements(); | |
278 | } |
|
283 | } | |
279 |
|
284 |
@@ -94,7 +94,7 void ChartTheme::decorate(QLegend* legend,bool force) | |||||
94 | QBrush brush; |
|
94 | QBrush brush; | |
95 |
|
95 | |||
96 | if (pen == legend->pen() || force){ |
|
96 | if (pen == legend->pen() || force){ | |
97 |
|
|
97 | legend->setPen(Qt::NoPen); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 |
|
100 |
@@ -264,39 +264,9 QChartAxis* QChart::axisY() const | |||||
264 | /*! |
|
264 | /*! | |
265 | Returns the legend object of the chart. Ownership stays in chart. |
|
265 | Returns the legend object of the chart. Ownership stays in chart. | |
266 | */ |
|
266 | */ | |
267 |
QLegend |
|
267 | QLegend* QChart::legend() const | |
268 | { |
|
268 | { | |
269 |
return |
|
269 | return d_ptr->m_legend; | |
270 | } |
|
|||
271 |
|
||||
272 | /*! |
|
|||
273 | Gives ownership of legend to user. |
|
|||
274 | */ |
|
|||
275 | QLegend* QChart::takeLegend() |
|
|||
276 | { |
|
|||
277 | QLegend* l = d_ptr->m_legend; |
|
|||
278 | d_ptr->m_legend = 0; |
|
|||
279 | return l; |
|
|||
280 | } |
|
|||
281 |
|
||||
282 | /*! |
|
|||
283 | Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one |
|
|||
284 | */ |
|
|||
285 | void QChart::giveLegend(QLegend *legend) |
|
|||
286 | { |
|
|||
287 | if (d_ptr->m_legend) { |
|
|||
288 | // Should not happen. |
|
|||
289 | qDebug() << "Warning! Giving more than one legend to chart."; |
|
|||
290 | delete d_ptr->m_legend; |
|
|||
291 | } |
|
|||
292 |
|
||||
293 | d_ptr->m_legend = legend; |
|
|||
294 |
|
||||
295 | // Reconnect legend, in case not already connected. |
|
|||
296 | disconnect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
|||
297 | disconnect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
|||
298 | connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
|||
299 | connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
|||
300 | } |
|
270 | } | |
301 |
|
271 | |||
302 | /*! |
|
272 | /*! | |
@@ -424,7 +394,18 void QChartPrivate::updateLegendLayout() | |||||
424 | } |
|
394 | } | |
425 |
|
395 | |||
426 | m_legend->setMaximumSize(legendRect.size()); |
|
396 | m_legend->setMaximumSize(legendRect.size()); | |
427 | m_legend->setPos(legendRect.topLeft()); |
|
397 | ||
|
398 | qreal width = legendRect.width() - m_legend->size().width(); | |||
|
399 | qreal height = legendRect.height() - m_legend->size().height(); | |||
|
400 | ||||
|
401 | QPointF pos = legendRect.topLeft(); | |||
|
402 | if (width > 0) { | |||
|
403 | pos.setX(pos.x() + width/2); | |||
|
404 | } | |||
|
405 | if (height > 0) { | |||
|
406 | pos.setY(pos.y() + height/2); | |||
|
407 | } | |||
|
408 | m_legend->setPos(pos); | |||
428 | } |
|
409 | } | |
429 |
|
410 | |||
430 | void QChartPrivate::updateLayout() |
|
411 | void QChartPrivate::updateLayout() |
@@ -75,9 +75,9 public: | |||||
75 | QFont titleFont() const; |
|
75 | QFont titleFont() const; | |
76 | void setTitleBrush(const QBrush &brush); |
|
76 | void setTitleBrush(const QBrush &brush); | |
77 | QBrush titleBrush() const; |
|
77 | QBrush titleBrush() const; | |
78 |
void setBackgroundBrush(const QBrush& |
|
78 | void setBackgroundBrush(const QBrush &brush); | |
79 | QBrush backgroundBrush() const; |
|
79 | QBrush backgroundBrush() const; | |
80 |
void setBackgroundPen(const QPen& |
|
80 | void setBackgroundPen(const QPen &pen); | |
81 | QPen backgroundPen() const; |
|
81 | QPen backgroundPen() const; | |
82 |
|
82 | |||
83 | void setBackgroundVisible(bool visible); |
|
83 | void setBackgroundVisible(bool visible); | |
@@ -87,7 +87,7 public: | |||||
87 | AnimationOptions animationOptions() const; |
|
87 | AnimationOptions animationOptions() const; | |
88 |
|
88 | |||
89 | void zoomIn(); |
|
89 | void zoomIn(); | |
90 |
void zoomIn(const QRectF& |
|
90 | void zoomIn(const QRectF &rect); | |
91 | void zoomOut(); |
|
91 | void zoomOut(); | |
92 | void scrollLeft(); |
|
92 | void scrollLeft(); | |
93 | void scrollRight(); |
|
93 | void scrollRight(); | |
@@ -97,9 +97,7 public: | |||||
97 | QChartAxis* axisX() const; |
|
97 | QChartAxis* axisX() const; | |
98 | QChartAxis* axisY() const; |
|
98 | QChartAxis* axisY() const; | |
99 |
|
99 | |||
100 |
QLegend |
|
100 | QLegend* legend() const; | |
101 | QLegend* takeLegend(); |
|
|||
102 | void giveLegend(QLegend* legend); |
|
|||
103 |
|
101 | |||
104 | protected: |
|
102 | protected: | |
105 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
103 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
@@ -67,14 +67,14 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
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(QGraphicsItem *parent) : QGraphicsObject(parent), | |
|
70 | m_margin(5), | |||
70 | m_pos(0,0), |
|
71 | m_pos(0,0), | |
71 | m_size(0,0), |
|
|||
72 | m_minimumSize(50,20), // TODO: magic numbers |
|
72 | m_minimumSize(50,20), // TODO: magic numbers | |
73 | m_maximumSize(150,100), |
|
73 | m_maximumSize(150,100), | |
74 | m_brush(Qt::darkGray), // TODO: from theme? |
|
74 | m_size(m_minimumSize), | |
|
75 | m_brush(Qt::darkGray), | |||
75 | m_alignment(QLegend::LayoutTop), |
|
76 | m_alignment(QLegend::LayoutTop), | |
76 |
mFirstMarker(0) |
|
77 | mFirstMarker(0) | |
77 | m_margin(5) |
|
|||
78 | { |
|
78 | { | |
79 | m_scrollButtonLeft = new LegendScrollButton(LegendScrollButton::ScrollButtonIdLeft, this); |
|
79 | m_scrollButtonLeft = new LegendScrollButton(LegendScrollButton::ScrollButtonIdLeft, this); | |
80 | m_scrollButtonRight = new LegendScrollButton(LegendScrollButton::ScrollButtonIdRight, this); |
|
80 | m_scrollButtonRight = new LegendScrollButton(LegendScrollButton::ScrollButtonIdRight, this); |
@@ -84,10 +84,11 private: | |||||
84 | void checkFirstMarkerBounds(); |
|
84 | void checkFirstMarkerBounds(); | |
85 | bool scrollButtonsVisible(); |
|
85 | bool scrollButtonsVisible(); | |
86 |
|
86 | |||
|
87 | qreal m_margin; | |||
87 | QPointF m_pos; |
|
88 | QPointF m_pos; | |
88 | QSizeF m_size; |
|
|||
89 | QSizeF m_minimumSize; |
|
89 | QSizeF m_minimumSize; | |
90 | QSizeF m_maximumSize; |
|
90 | QSizeF m_maximumSize; | |
|
91 | QSizeF m_size; | |||
91 |
|
92 | |||
92 | QList<LegendMarker *> m_markers; |
|
93 | QList<LegendMarker *> m_markers; | |
93 |
|
94 | |||
@@ -102,7 +103,6 private: | |||||
102 | LegendScrollButton *m_scrollButtonUp; |
|
103 | LegendScrollButton *m_scrollButtonUp; | |
103 | LegendScrollButton *m_scrollButtonDown; |
|
104 | LegendScrollButton *m_scrollButtonDown; | |
104 |
|
105 | |||
105 | qreal m_margin; |
|
|||
106 | // <--- PIMPL |
|
106 | // <--- PIMPL | |
107 | }; |
|
107 | }; | |
108 |
|
108 |
General Comments 0
You need to be logged in to leave comments.
Login now