##// END OF EJS Templates
code inspection round 1 fixes
sauimone -
r2185:7d15b2a5d252
parent child
Show More
@@ -23,8 +23,6
23 #include <QApplication>
23 #include <QApplication>
24 #include <QMainWindow>
24 #include <QMainWindow>
25
25
26 QTCOMMERCIALCHART_USE_NAMESPACE
27
28 int main(int argc, char *argv[])
26 int main(int argc, char *argv[])
29 {
27 {
30 QApplication a(argc, argv);
28 QApplication a(argc, argv);
@@ -44,8 +44,6 public:
44 void showLegendSpinbox();
44 void showLegendSpinbox();
45 void hideLegendSpinbox();
45 void hideLegendSpinbox();
46
46
47 signals:
48
49 public slots:
47 public slots:
50 void toggleAttached();
48 void toggleAttached();
51 void addSlice();
49 void addSlice();
@@ -61,10 +59,8 public slots:
61 void fontSizeChanged();
59 void fontSizeChanged();
62
60
63 void updateLegendLayout();
61 void updateLegendLayout();
64
65 void handleMarkerClicked();
62 void handleMarkerClicked();
66
63
67
68 private:
64 private:
69
65
70 QChart *m_chart;
66 QChart *m_chart;
@@ -26,7 +26,6
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "qvalueaxis.h"
28 #include "qvalueaxis.h"
29
30 #include "qarealegendmarker.h"
29 #include "qarealegendmarker.h"
31
30
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -27,7 +27,6
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "qvalueaxis.h"
28 #include "qvalueaxis.h"
29 #include "qbarcategoryaxis.h"
29 #include "qbarcategoryaxis.h"
30
31 #include "qbarlegendmarker.h"
30 #include "qbarlegendmarker.h"
32
31
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -117,7 +117,7 void LegendLayout::setAttachedGeometry(const QRectF &rect)
117
117
118 QSizeF size(0, 0);
118 QSizeF size(0, 0);
119
119
120 if (m_legend->d_ptr->legendMarkers().isEmpty()) {
120 if (m_legend->d_ptr->markers().isEmpty()) {
121 return;
121 return;
122 }
122 }
123
123
@@ -133,7 +133,7 void LegendLayout::setAttachedGeometry(const QRectF &rect)
133 case Qt::AlignTop:
133 case Qt::AlignTop:
134 case Qt::AlignBottom: {
134 case Qt::AlignBottom: {
135 QPointF point(0,0);
135 QPointF point(0,0);
136 foreach (QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
136 foreach (QLegendMarker* marker, m_legend->d_ptr->markers()) {
137 LegendMarkerItem* item = marker->d_ptr->item();
137 LegendMarkerItem* item = marker->d_ptr->item();
138 if (item->isVisible()) {
138 if (item->isVisible()) {
139 item->setGeometry(geometry);
139 item->setGeometry(geometry);
@@ -155,7 +155,7 void LegendLayout::setAttachedGeometry(const QRectF &rect)
155 case Qt::AlignLeft:
155 case Qt::AlignLeft:
156 case Qt::AlignRight: {
156 case Qt::AlignRight: {
157 QPointF point(0,0);
157 QPointF point(0,0);
158 foreach (QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
158 foreach (QLegendMarker* marker, m_legend->d_ptr->markers()) {
159 LegendMarkerItem* item = marker->d_ptr->item();
159 LegendMarkerItem* item = marker->d_ptr->item();
160 if (item->isVisible()) {
160 if (item->isVisible()) {
161 item->setGeometry(geometry);
161 item->setGeometry(geometry);
@@ -202,7 +202,7 void LegendLayout::setDettachedGeometry(const QRectF &rect)
202
202
203 QSizeF size(0, 0);
203 QSizeF size(0, 0);
204
204
205 QList<QLegendMarker *> markers = m_legend->d_ptr->legendMarkers();
205 QList<QLegendMarker *> markers = m_legend->d_ptr->markers();
206
206
207 if (markers.isEmpty())
207 if (markers.isEmpty())
208 return;
208 return;
@@ -359,7 +359,7 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
359 getContentsMargins(&left, &top, &right, &bottom);
359 getContentsMargins(&left, &top, &right, &bottom);
360
360
361 if(constraint.isValid()) {
361 if(constraint.isValid()) {
362 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
362 foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) {
363 LegendMarkerItem *item = marker->d_ptr->item();
363 LegendMarkerItem *item = marker->d_ptr->item();
364 size = size.expandedTo(item->effectiveSizeHint(which));
364 size = size.expandedTo(item->effectiveSizeHint(which));
365 }
365 }
@@ -368,7 +368,7 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
368 else if (constraint.width() >= 0) {
368 else if (constraint.width() >= 0) {
369 qreal width = 0;
369 qreal width = 0;
370 qreal height = 0;
370 qreal height = 0;
371 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
371 foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) {
372 LegendMarkerItem *item = marker->d_ptr->item();
372 LegendMarkerItem *item = marker->d_ptr->item();
373 width+=item->effectiveSizeHint(which).width();
373 width+=item->effectiveSizeHint(which).width();
374 height=qMax(height,item->effectiveSizeHint(which).height());
374 height=qMax(height,item->effectiveSizeHint(which).height());
@@ -379,7 +379,7 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
379 else if (constraint.height() >= 0) {
379 else if (constraint.height() >= 0) {
380 qreal width = 0;
380 qreal width = 0;
381 qreal height = 0;
381 qreal height = 0;
382 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
382 foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) {
383 LegendMarkerItem *item = marker->d_ptr->item();
383 LegendMarkerItem *item = marker->d_ptr->item();
384 width=qMax(width,item->effectiveSizeHint(which).width());
384 width=qMax(width,item->effectiveSizeHint(which).width());
385 height+=height,item->effectiveSizeHint(which).height();
385 height+=height,item->effectiveSizeHint(which).height();
@@ -387,7 +387,7 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
387 size = QSizeF(width,qMin(constraint.height(),height));
387 size = QSizeF(width,qMin(constraint.height(),height));
388 }
388 }
389 else {
389 else {
390 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
390 foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) {
391 LegendMarkerItem *item = marker->d_ptr->item();
391 LegendMarkerItem *item = marker->d_ptr->item();
392 size = size.expandedTo(item->effectiveSizeHint(which));
392 size = size.expandedTo(item->effectiveSizeHint(which));
393 }
393 }
@@ -63,8 +63,6 QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSe
63
63
64 QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
64 QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
65 {
65 {
66 QObject::disconnect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
67 QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
68 }
66 }
69
67
70 QAreaSeries* QAreaLegendMarkerPrivate::series()
68 QAreaSeries* QAreaLegendMarkerPrivate::series()
@@ -71,9 +71,6 QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractB
71
71
72 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
72 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
73 {
73 {
74 QObject::disconnect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
75 QObject::disconnect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
76 QObject::disconnect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
77 }
74 }
78
75
79 QAbstractBarSeries* QBarLegendMarkerPrivate::series()
76 QAbstractBarSeries* QBarLegendMarkerPrivate::series()
@@ -61,7 +61,7 private:
61 QAbstractBarSeries* m_series;
61 QAbstractBarSeries* m_series;
62 QBarSet* m_barset;
62 QBarSet* m_barset;
63
63
64 friend class QLegendPrivate; // TODO: Is this needed?
64 friend class QLegendPrivate;
65 Q_DECLARE_PUBLIC(QBarLegendMarker)
65 Q_DECLARE_PUBLIC(QBarLegendMarker)
66 };
66 };
67
67
@@ -268,11 +268,11 void QLegend::setFont(const QFont &font)
268 if (d_ptr->m_font != font)
268 if (d_ptr->m_font != font)
269 d_ptr->m_font = font;
269 d_ptr->m_font = font;
270
270
271 foreach (QLegendMarker *marker, d_ptr->legendMarkers()) {
271 foreach (QLegendMarker *marker, d_ptr->markers()) {
272 marker->setFont(d_ptr->m_font);
272 marker->setFont(d_ptr->m_font);
273 layout()->invalidate();
274 emit fontChanged(font);
275 }
273 }
274 layout()->invalidate();
275 emit fontChanged(font);
276 }
276 }
277
277
278 QFont QLegend::font() const
278 QFont QLegend::font() const
@@ -301,7 +301,7 void QLegend::setLabelBrush(const QBrush &brush)
301 {
301 {
302 if (d_ptr->m_labelBrush != brush) {
302 if (d_ptr->m_labelBrush != brush) {
303 d_ptr->m_labelBrush = brush;
303 d_ptr->m_labelBrush = brush;
304 foreach (QLegendMarker *marker, d_ptr->legendMarkers()) {
304 foreach (QLegendMarker *marker, d_ptr->markers()) {
305 marker->setLabelBrush(d_ptr->m_labelBrush);
305 marker->setLabelBrush(d_ptr->m_labelBrush);
306 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
306 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
307 // instead of mapping it from label brush color
307 // instead of mapping it from label brush color
@@ -397,16 +397,14 bool QLegend::isBackgroundVisible() const
397 return d_ptr->m_backgroundVisible;
397 return d_ptr->m_backgroundVisible;
398 }
398 }
399
399
400
401 QList<QLegendMarker*> QLegend::markers() const
400 QList<QLegendMarker*> QLegend::markers() const
402 {
401 {
403 // TODO: name of PIMPL method will change.
402 return d_ptr->markers();
404 return d_ptr->legendMarkers();
405 }
403 }
406
404
407 void QLegend::appendSeries(QAbstractSeries* series)
405 void QLegend::addSeries(QAbstractSeries* series)
408 {
406 {
409 d_ptr->appendSeries(series);
407 d_ptr->addSeries(series);
410 }
408 }
411
409
412 void QLegend::removeSeries(QAbstractSeries* series)
410 void QLegend::removeSeries(QAbstractSeries* series)
@@ -475,7 +473,7 int QLegendPrivate::roundness(qreal size)
475 return 100 * m_diameter / int(size);
473 return 100 * m_diameter / int(size);
476 }
474 }
477
475
478 void QLegendPrivate::appendSeries(QAbstractSeries* series)
476 void QLegendPrivate::addSeries(QAbstractSeries* series)
479 {
477 {
480 // Only allow one instance of series
478 // Only allow one instance of series
481 if (m_series.contains(series)) {
479 if (m_series.contains(series)) {
@@ -532,7 +530,7 void QLegendPrivate::removeSeries(QAbstractSeries* series)
532
530
533 // Find out, which markers to remove
531 // Find out, which markers to remove
534 QList<QLegendMarker *> removed;
532 QList<QLegendMarker *> removed;
535 foreach (QLegendMarker *m, m_legendMarkers) {
533 foreach (QLegendMarker *m, m_markers) {
536 if (m->series() == series) {
534 if (m->series() == series) {
537 removed << m;
535 removed << m;
538 }
536 }
@@ -577,7 +575,7 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series)
577 {
575 {
578 // Moved to appendSeries
576 // Moved to appendSeries
579 // This slot is just to make old code work for now.
577 // This slot is just to make old code work for now.
580 appendSeries(series);
578 addSeries(series);
581 }
579 }
582
580
583 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
581 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
@@ -592,7 +590,7 void QLegendPrivate::handleSeriesVisibleChanged()
592 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
590 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
593 Q_ASSERT(series);
591 Q_ASSERT(series);
594
592
595 foreach (QLegendMarker* marker, m_legendMarkers) {
593 foreach (QLegendMarker* marker, m_markers) {
596 if (marker->series() == series) {
594 if (marker->series() == series) {
597 marker->setVisible(series->isVisible());
595 marker->setVisible(series->isVisible());
598 }
596 }
@@ -610,7 +608,7 void QLegendPrivate::handleCountChanged()
610
608
611 // Find out removed markers and created markers
609 // Find out removed markers and created markers
612 QList<QLegendMarker *> removedMarkers;
610 QList<QLegendMarker *> removedMarkers;
613 foreach (QLegendMarker *oldMarker, m_legendMarkers) {
611 foreach (QLegendMarker *oldMarker, m_markers) {
614 // we have marker, which is related to sender.
612 // we have marker, which is related to sender.
615 if (oldMarker->series() == series) {
613 if (oldMarker->series() == series) {
616 bool found = false;
614 bool found = false;
@@ -642,7 +640,7 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers)
642 {
640 {
643 foreach (QLegendMarker* marker, markers) {
641 foreach (QLegendMarker* marker, markers) {
644 m_items->addToGroup(marker->d_ptr.data()->item());
642 m_items->addToGroup(marker->d_ptr.data()->item());
645 m_legendMarkers << marker;
643 m_markers << marker;
646 }
644 }
647 }
645 }
648
646
@@ -652,7 +650,7 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers)
652 marker->d_ptr->item()->setVisible(false);
650 marker->d_ptr->item()->setVisible(false);
653 m_items->removeFromGroup(marker->d_ptr->item());
651 m_items->removeFromGroup(marker->d_ptr->item());
654 delete marker;
652 delete marker;
655 m_legendMarkers.removeOne(marker);
653 m_markers.removeOne(marker);
656 }
654 }
657 }
655 }
658
656
@@ -81,7 +81,7 public:
81
81
82 // New stuff:
82 // New stuff:
83 QList <QLegendMarker*> markers() const;
83 QList <QLegendMarker*> markers() const;
84 void appendSeries(QAbstractSeries* series);
84 void addSeries(QAbstractSeries* series);
85 void removeSeries(QAbstractSeries* series);
85 void removeSeries(QAbstractSeries* series);
86
86
87 protected:
87 protected:
@@ -55,8 +55,8 public:
55 QGraphicsItemGroup* items() { return m_items; }
55 QGraphicsItemGroup* items() { return m_items; }
56
56
57 // New stuff:
57 // New stuff:
58 QList<QLegendMarker*> legendMarkers() { return m_legendMarkers; }
58 QList<QLegendMarker*> markers() { return m_markers; }
59 void appendSeries(QAbstractSeries* series);
59 void addSeries(QAbstractSeries* series);
60 void removeSeries(QAbstractSeries* series);
60 void removeSeries(QAbstractSeries* series);
61
61
62 public Q_SLOTS:
62 public Q_SLOTS:
@@ -89,7 +89,7 private:
89
89
90 friend class QLegend;
90 friend class QLegend;
91 friend class LegendLayout;
91 friend class LegendLayout;
92 QList<QLegendMarker*> m_legendMarkers; // TODO: rename to m_markers eventually.
92 QList<QLegendMarker*> m_markers;
93 QList<QAbstractSeries*> m_series;
93 QList<QAbstractSeries*> m_series;
94
94
95 friend class QLegend;
95 friend class QLegend;
@@ -71,9 +71,6 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries
71
71
72 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
72 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
73 {
73 {
74 QObject::disconnect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
75 QObject::disconnect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
76 QObject::disconnect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
77 }
74 }
78
75
79 QPieSeries* QPieLegendMarkerPrivate::series()
76 QPieSeries* QPieLegendMarkerPrivate::series()
@@ -63,8 +63,6 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *se
63
63
64 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
64 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
65 {
65 {
66 QObject::disconnect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
67 QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
68 }
66 }
69
67
70 QAbstractSeries* QXYLegendMarkerPrivate::series()
68 QAbstractSeries* QXYLegendMarkerPrivate::series()
General Comments 0
You need to be logged in to leave comments. Login now