From 7e0a20ef8117a9e73f38633fb6e0f46635731f64 2012-10-17 07:46:32 From: sauimone Date: 2012-10-17 07:46:32 Subject: [PATCH] optional series parameter to markers function. code style fixes --- diff --git a/src/legend/legendlayout.cpp b/src/legend/legendlayout.cpp index 53f0815..9e37c9d 100644 --- a/src/legend/legendlayout.cpp +++ b/src/legend/legendlayout.cpp @@ -133,12 +133,12 @@ void LegendLayout::setAttachedGeometry(const QRectF &rect) case Qt::AlignTop: case Qt::AlignBottom: { QPointF point(0,0); - foreach (QLegendMarker* marker, m_legend->d_ptr->markers()) { - LegendMarkerItem* item = marker->d_ptr->item(); + foreach (QLegendMarker *marker, m_legend->d_ptr->markers()) { + LegendMarkerItem *item = marker->d_ptr->item(); if (item->isVisible()) { item->setGeometry(geometry); item->setPos(point.x(),geometry.height()/2 - item->boundingRect().height()/2); - const QRectF& rect = item->boundingRect(); + const QRectF &rect = item->boundingRect(); size = size.expandedTo(rect.size()); qreal w = rect.width(); m_width+=w; @@ -155,12 +155,12 @@ void LegendLayout::setAttachedGeometry(const QRectF &rect) case Qt::AlignLeft: case Qt::AlignRight: { QPointF point(0,0); - foreach (QLegendMarker* marker, m_legend->d_ptr->markers()) { - LegendMarkerItem* item = marker->d_ptr->item(); + foreach (QLegendMarker *marker, m_legend->d_ptr->markers()) { + LegendMarkerItem *item = marker->d_ptr->item(); if (item->isVisible()) { item->setGeometry(geometry); item->setPos(point); - const QRectF& rect = item->boundingRect(); + const QRectF &rect = item->boundingRect(); qreal h = rect.height(); size = size.expandedTo(rect.size()); m_height+=h; @@ -217,7 +217,7 @@ void LegendLayout::setDettachedGeometry(const QRectF &rect) if (item->isVisible()) { item->setGeometry(geometry); item->setPos(point.x(),point.y()); - const QRectF& boundingRect = item->boundingRect(); + const QRectF &boundingRect = item->boundingRect(); qreal w = boundingRect.width(); qreal h = boundingRect.height(); m_width = qMax(m_width,w); @@ -249,7 +249,7 @@ void LegendLayout::setDettachedGeometry(const QRectF &rect) LegendMarkerItem *item = markers.at(i)->d_ptr->item(); if (item->isVisible()) { item->setGeometry(geometry); - const QRectF& boundingRect = item->boundingRect(); + const QRectF &boundingRect = item->boundingRect(); qreal w = boundingRect.width(); qreal h = boundingRect.height(); m_width = qMax(m_width,w); @@ -283,7 +283,7 @@ void LegendLayout::setDettachedGeometry(const QRectF &rect) LegendMarkerItem *item = markers.at(i)->d_ptr->item(); if (item->isVisible()) { item->setGeometry(geometry); - const QRectF& boundingRect = item->boundingRect(); + const QRectF &boundingRect = item->boundingRect(); qreal w = boundingRect.width(); qreal h = boundingRect.height(); m_height = qMax(m_height,h); @@ -319,7 +319,7 @@ void LegendLayout::setDettachedGeometry(const QRectF &rect) LegendMarkerItem *item = markers.at(i)->d_ptr->item(); if (item->isVisible()) { item->setGeometry(geometry); - const QRectF& boundingRect = item->boundingRect(); + const QRectF &boundingRect = item->boundingRect(); qreal w = boundingRect.width(); qreal h = boundingRect.height(); m_height = qMax(m_height,h); @@ -359,7 +359,7 @@ QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons getContentsMargins(&left, &top, &right, &bottom); if(constraint.isValid()) { - foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) { + foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) { LegendMarkerItem *item = marker->d_ptr->item(); size = size.expandedTo(item->effectiveSizeHint(which)); } @@ -368,7 +368,7 @@ QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons else if (constraint.width() >= 0) { qreal width = 0; qreal height = 0; - foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) { + foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) { LegendMarkerItem *item = marker->d_ptr->item(); width+=item->effectiveSizeHint(which).width(); height=qMax(height,item->effectiveSizeHint(which).height()); @@ -379,7 +379,7 @@ QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons else if (constraint.height() >= 0) { qreal width = 0; qreal height = 0; - foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) { + foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) { LegendMarkerItem *item = marker->d_ptr->item(); width=qMax(width,item->effectiveSizeHint(which).width()); height+=height,item->effectiveSizeHint(which).height(); @@ -387,7 +387,7 @@ QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons size = QSizeF(width,qMin(constraint.height(),height)); } else { - foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) { + foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) { LegendMarkerItem *item = marker->d_ptr->item(); size = size.expandedTo(item->effectiveSizeHint(which)); } diff --git a/src/legend/legendmarkeritem.cpp b/src/legend/legendmarkeritem.cpp index fe8238e..39247db 100644 --- a/src/legend/legendmarkeritem.cpp +++ b/src/legend/legendmarkeritem.cpp @@ -98,7 +98,7 @@ QBrush LegendMarkerItem::labelBrush() const return m_textItem->brush(); } -void LegendMarkerItem::setGeometry(const QRectF& rect) +void LegendMarkerItem::setGeometry(const QRectF &rect) { QFontMetrics fn (m_font); @@ -116,7 +116,7 @@ void LegendMarkerItem::setGeometry(const QRectF& rect) else m_textItem->setText(m_label); - const QRectF& textRect = m_textItem->boundingRect(); + const QRectF &textRect = m_textItem->boundingRect(); m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2); diff --git a/src/legend/legendmarkeritem_p.h b/src/legend/legendmarkeritem_p.h index 4126d5e..351d872 100644 --- a/src/legend/legendmarkeritem_p.h +++ b/src/legend/legendmarkeritem_p.h @@ -65,13 +65,13 @@ public: void setLabelBrush(const QBrush &brush); QBrush labelBrush() const; - void setGeometry(const QRectF& rect); + void setGeometry(const QRectF &rect); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - QSizeF sizeHint (Qt::SizeHint which, const QSizeF& constraint) const; + QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint) const; // Event handlers, logic delegated to MouseEventHandler void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/src/legend/mouseeventhandler.cpp b/src/legend/mouseeventhandler.cpp index 9e9508a..f93e37f 100644 --- a/src/legend/mouseeventhandler.cpp +++ b/src/legend/mouseeventhandler.cpp @@ -39,14 +39,14 @@ void MouseEventHandler::setMoveTreshold(qreal treshold) m_treshold = treshold; } -void MouseEventHandler::handleMousePressEvent(QGraphicsSceneMouseEvent* event) +void MouseEventHandler::handleMousePressEvent(QGraphicsSceneMouseEvent *event) { m_lastPos = event->screenPos(); m_state = Pressed; event->accept(); } -void MouseEventHandler::handleMouseMoveEvent(QGraphicsSceneMouseEvent* event) +void MouseEventHandler::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) { QPointF delta = event->screenPos() - m_lastPos; @@ -75,7 +75,7 @@ void MouseEventHandler::handleMouseMoveEvent(QGraphicsSceneMouseEvent* event) } } -void MouseEventHandler::handleMouseReleaseEvent(QGraphicsSceneMouseEvent* event) +void MouseEventHandler::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event) { m_lastPos = event->screenPos(); diff --git a/src/legend/mouseeventhandler_p.h b/src/legend/mouseeventhandler_p.h index ad18cd8..3c35dab 100644 --- a/src/legend/mouseeventhandler_p.h +++ b/src/legend/mouseeventhandler_p.h @@ -74,9 +74,9 @@ public: virtual void mouseMoved(const QPointF &delta) = 0; virtual void mouseReleased(const QPointF &pos) = 0; - void handleMousePressEvent(QGraphicsSceneMouseEvent* event); - void handleMouseMoveEvent(QGraphicsSceneMouseEvent* event); - void handleMouseReleaseEvent(QGraphicsSceneMouseEvent* event); + void handleMousePressEvent(QGraphicsSceneMouseEvent *event); + void handleMouseMoveEvent(QGraphicsSceneMouseEvent *event); + void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event); private: QPointF m_lastPos; diff --git a/src/legend/qarealegendmarker.cpp b/src/legend/qarealegendmarker.cpp index 5a2a7ea..4866485 100644 --- a/src/legend/qarealegendmarker.cpp +++ b/src/legend/qarealegendmarker.cpp @@ -25,7 +25,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -QAreaLegendMarker::QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent) : +QAreaLegendMarker::QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent) : QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent) { } diff --git a/src/legend/qarealegendmarker.h b/src/legend/qarealegendmarker.h index 5d51d11..cd4f634 100644 --- a/src/legend/qarealegendmarker.h +++ b/src/legend/qarealegendmarker.h @@ -34,7 +34,7 @@ class QTCOMMERCIALCHART_EXPORT QAreaLegendMarker : public QLegendMarker Q_OBJECT public: - explicit QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent = 0); + explicit QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent = 0); virtual ~QAreaLegendMarker(); virtual LegendMarkerType type() { return LegendMarkerTypeArea; } diff --git a/src/legend/qarealegendmarker_p.h b/src/legend/qarealegendmarker_p.h index b83a3f1..7bc1cf3 100644 --- a/src/legend/qarealegendmarker_p.h +++ b/src/legend/qarealegendmarker_p.h @@ -54,7 +54,7 @@ public Q_SLOTS: private: QAreaLegendMarker *q_ptr; - QAreaSeries* m_series; + QAreaSeries *m_series; Q_DECLARE_PUBLIC(QAreaLegendMarker) }; diff --git a/src/legend/qbarlegendmarker.cpp b/src/legend/qbarlegendmarker.cpp index 7d46ed1..e3e6b56 100644 --- a/src/legend/qbarlegendmarker.cpp +++ b/src/legend/qbarlegendmarker.cpp @@ -25,7 +25,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent) : +QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent) : QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent) { } diff --git a/src/legend/qbarlegendmarker.h b/src/legend/qbarlegendmarker.h index 88abc06..fb08e3b 100644 --- a/src/legend/qbarlegendmarker.h +++ b/src/legend/qbarlegendmarker.h @@ -34,7 +34,7 @@ class QTCOMMERCIALCHART_EXPORT QBarLegendMarker : public QLegendMarker { Q_OBJECT public: - explicit QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent = 0); + explicit QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent = 0); virtual ~QBarLegendMarker(); virtual LegendMarkerType type() { return LegendMarkerTypeBar; } diff --git a/src/legend/qbarlegendmarker_p.h b/src/legend/qbarlegendmarker_p.h index 11fbb1d..3f65305 100644 --- a/src/legend/qbarlegendmarker_p.h +++ b/src/legend/qbarlegendmarker_p.h @@ -55,8 +55,8 @@ public Q_SLOTS: private: QBarLegendMarker *q_ptr; - QAbstractBarSeries* m_series; - QBarSet* m_barset; + QAbstractBarSeries *m_series; + QBarSet *m_barset; Q_DECLARE_PUBLIC(QBarLegendMarker) }; diff --git a/src/legend/qlegend.cpp b/src/legend/qlegend.cpp index ad6ddaa..61e917c 100644 --- a/src/legend/qlegend.cpp +++ b/src/legend/qlegend.cpp @@ -24,29 +24,14 @@ #include "qabstractseries_p.h" #include "qchart_p.h" #include "legendlayout_p.h" -#include "qxyseries.h" -#include "qlineseries.h" -#include "qareaseries.h" -#include "qscatterseries.h" -#include "qsplineseries.h" -#include "qabstractbarseries.h" -#include "qstackedbarseries.h" -#include "qpercentbarseries.h" -#include "qbarset.h" -#include "qpieseries.h" -#include "qpieseries_p.h" -#include "qpieslice.h" #include "chartpresenter_p.h" #include "chartlayout_p.h" -#include -#include -#include -#include -#include - #include "qlegendmarker.h" #include "qlegendmarker_p.h" #include "legendmarkeritem_p.h" +#include +#include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -396,17 +381,17 @@ bool QLegend::isBackgroundVisible() const return d_ptr->m_backgroundVisible; } -QList QLegend::markers() const +QList QLegend::markers(QAbstractSeries *series) const { - return d_ptr->markers(); + return d_ptr->markers(series); } -void QLegend::addSeries(QAbstractSeries* series) +void QLegend::addSeries(QAbstractSeries *series) { d_ptr->addSeries(series); } -void QLegend::removeSeries(QAbstractSeries* series) +void QLegend::removeSeries(QAbstractSeries *series) { d_ptr->removeSeries(series); } @@ -472,7 +457,24 @@ int QLegendPrivate::roundness(qreal size) return 100 * m_diameter / int(size); } -void QLegendPrivate::addSeries(QAbstractSeries* series) +QList QLegendPrivate::markers(QAbstractSeries *series) +{ + // Return all markers + if (!series) { + return m_markers; + } + + // Create filtered list + QList markers; + foreach (QLegendMarker *marker, m_markers) { + if (marker->series() == series) { + markers.append(marker); + } + } + return markers; +} + +void QLegendPrivate::addSeries(QAbstractSeries *series) { // Only allow one instance of series if (m_series.contains(series)) { @@ -491,7 +493,7 @@ void QLegendPrivate::addSeries(QAbstractSeries* series) m_layout->invalidate(); } -void QLegendPrivate::removeSeries(QAbstractSeries* series) +void QLegendPrivate::removeSeries(QAbstractSeries *series) { if (m_series.contains(series)) { m_series.removeOne(series); @@ -531,7 +533,7 @@ void QLegendPrivate::handleSeriesVisibleChanged() QAbstractSeries *series = qobject_cast (sender()); Q_ASSERT(series); - foreach (QLegendMarker* marker, m_markers) { + foreach (QLegendMarker *marker, m_markers) { if (marker->series() == series) { marker->setVisible(series->isVisible()); } @@ -579,7 +581,7 @@ void QLegendPrivate::handleCountChanged() void QLegendPrivate::addMarkers(QList markers) { - foreach (QLegendMarker* marker, markers) { + foreach (QLegendMarker *marker, markers) { m_items->addToGroup(marker->d_ptr.data()->item()); m_markers << marker; } @@ -597,7 +599,7 @@ void QLegendPrivate::removeMarkers(QList markers) void QLegendPrivate::decorateMarkers(QList markers) { - foreach (QLegendMarker* marker, markers) { + foreach (QLegendMarker *marker, markers) { marker->setFont(m_font); marker->setLabelBrush(m_labelBrush); } diff --git a/src/legend/qlegend.h b/src/legend/qlegend.h index 1dc45db..a75971f 100644 --- a/src/legend/qlegend.h +++ b/src/legend/qlegend.h @@ -80,9 +80,9 @@ public: bool isBackgroundVisible() const; // New stuff: - QList markers() const; - void addSeries(QAbstractSeries* series); - void removeSeries(QAbstractSeries* series); + QList markers(QAbstractSeries *series = 0) const; + void addSeries(QAbstractSeries *series); + void removeSeries(QAbstractSeries *series); protected: void hideEvent(QHideEvent *event); diff --git a/src/legend/qlegend_p.h b/src/legend/qlegend_p.h index c4a73d7..1c4d85a 100644 --- a/src/legend/qlegend_p.h +++ b/src/legend/qlegend_p.h @@ -55,10 +55,9 @@ public: QGraphicsItemGroup* items() { return m_items; } - // New stuff: - QList markers() { return m_markers; } - void addSeries(QAbstractSeries* series); - void removeSeries(QAbstractSeries* series); + QList markers(QAbstractSeries *series = 0); + void addSeries(QAbstractSeries *series); + void removeSeries(QAbstractSeries *series); public Q_SLOTS: void handleSeriesAdded(QAbstractSeries *series); @@ -76,8 +75,8 @@ private: QLegend *q_ptr; ChartPresenter *m_presenter; LegendLayout *m_layout; - QChart* m_chart; - QGraphicsItemGroup* m_items; + QChart *m_chart; + QGraphicsItemGroup *m_items; Qt::Alignment m_alignment; QBrush m_brush; QPen m_pen; @@ -88,13 +87,12 @@ private: bool m_attachedToChart; bool m_backgroundVisible; - friend class QLegend; - friend class LegendLayout; - QList m_markers; - QList m_series; + QList m_markers; + QList m_series; friend class QLegend; friend class LegendMarkerItem; + friend class LegendLayout; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/legend/qlegendmarker_p.h b/src/legend/qlegendmarker_p.h index 874b929..8c16005 100644 --- a/src/legend/qlegendmarker_p.h +++ b/src/legend/qlegendmarker_p.h @@ -70,7 +70,7 @@ public Q_SLOTS: protected: LegendMarkerItem *m_item; - QLegend* m_legend; + QLegend *m_legend; private: QLegendMarker *q_ptr; diff --git a/src/legend/qpielegendmarker.cpp b/src/legend/qpielegendmarker.cpp index d8479ed..d20447b 100644 --- a/src/legend/qpielegendmarker.cpp +++ b/src/legend/qpielegendmarker.cpp @@ -25,7 +25,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent) : +QPieLegendMarker::QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent) : QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent) { } diff --git a/src/legend/qpielegendmarker.h b/src/legend/qpielegendmarker.h index 467c95d..1801e8c 100644 --- a/src/legend/qpielegendmarker.h +++ b/src/legend/qpielegendmarker.h @@ -35,7 +35,7 @@ class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker Q_OBJECT public: - explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent = 0); + explicit QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent = 0); virtual ~QPieLegendMarker(); virtual LegendMarkerType type() { return LegendMarkerTypePie; } diff --git a/src/legend/qpielegendmarker_p.h b/src/legend/qpielegendmarker_p.h index dbb69c1..f83f3b2 100644 --- a/src/legend/qpielegendmarker_p.h +++ b/src/legend/qpielegendmarker_p.h @@ -57,8 +57,8 @@ public Q_SLOTS: private: QPieLegendMarker *q_ptr; - QPieSeries* m_series; - QPieSlice* m_slice; + QPieSeries *m_series; + QPieSlice *m_slice; Q_DECLARE_PUBLIC(QPieLegendMarker) }; diff --git a/src/legend/qxylegendmarker.cpp b/src/legend/qxylegendmarker.cpp index 71d698e..975cbce 100644 --- a/src/legend/qxylegendmarker.cpp +++ b/src/legend/qxylegendmarker.cpp @@ -25,7 +25,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -QXYLegendMarker::QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent) : +QXYLegendMarker::QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent) : QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent) { } diff --git a/src/legend/qxylegendmarker.h b/src/legend/qxylegendmarker.h index 5a29e48..f381ed5 100644 --- a/src/legend/qxylegendmarker.h +++ b/src/legend/qxylegendmarker.h @@ -33,7 +33,7 @@ class QTCOMMERCIALCHART_EXPORT QXYLegendMarker : public QLegendMarker { Q_OBJECT public: - explicit QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent = 0); + explicit QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent = 0); virtual ~QXYLegendMarker(); virtual LegendMarkerType type() { return LegendMarkerTypeXY; } diff --git a/src/legend/qxylegendmarker_p.h b/src/legend/qxylegendmarker_p.h index af1e513..b00e0c6 100644 --- a/src/legend/qxylegendmarker_p.h +++ b/src/legend/qxylegendmarker_p.h @@ -54,7 +54,7 @@ public Q_SLOTS: private: QXYLegendMarker *q_ptr; - QXYSeries* m_series; + QXYSeries *m_series; Q_DECLARE_PUBLIC(QXYLegendMarker) };