From 5149de44ec861fbb1e853d9a106051383d4d3144 2012-09-24 07:26:15 From: Michal Klocek Date: 2012-09-24 07:26:15 Subject: [PATCH] Fix title font resize does not invalidate layout --- diff --git a/src/chartlayout.cpp b/src/chartlayout.cpp index 3a6e371..d508588 100644 --- a/src/chartlayout.cpp +++ b/src/chartlayout.cpp @@ -25,7 +25,6 @@ #include "charttitle_p.h" #include "chartbackground_p.h" #include "legendmarker_p.h" -#include QTCOMMERCIALCHART_BEGIN_NAMESPACE diff --git a/src/legend/legendlayout.cpp b/src/legend/legendlayout.cpp index 921921a..845aea9 100644 --- a/src/legend/legendlayout.cpp +++ b/src/legend/legendlayout.cpp @@ -87,6 +87,14 @@ QPointF LegendLayout::offset() const return QPointF(m_offsetX,m_offsetY); } +void LegendLayout::invalidate() +{ + QGraphicsLayout::invalidate(); + if(m_legend->isAttachedToChart()){ + m_legend->d_ptr->m_presenter->layout()->invalidate(); + } +} + void LegendLayout::setGeometry(const QRectF& rect) { m_legend->d_ptr->items()->setVisible(m_legend->isVisible()); diff --git a/src/legend/legendlayout_p.h b/src/legend/legendlayout_p.h index 5801cf0..9f97d7f 100644 --- a/src/legend/legendlayout_p.h +++ b/src/legend/legendlayout_p.h @@ -39,6 +39,7 @@ public: void setOffset(qreal x, qreal y); QPointF offset() const; + void invalidate(); protected: QSizeF sizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const; int count() const { return 0; } diff --git a/src/legend/legendmarker.cpp b/src/legend/legendmarker.cpp index 3a8c5c3..48c567e 100644 --- a/src/legend/legendmarker.cpp +++ b/src/legend/legendmarker.cpp @@ -77,6 +77,7 @@ void LegendMarker::setFont(const QFont &font) QFontMetrics fn(font); m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2); updateGeometry(); + m_legend->layout()->invalidate(); } QFont LegendMarker::font() const @@ -165,7 +166,6 @@ QSizeF LegendMarker::sizeHint(Qt::SizeHint which, const QSizeF& constraint) cons default: break; } - return sh; } diff --git a/src/legend/qlegend.cpp b/src/legend/qlegend.cpp index d6bbb2b..3d7c632 100644 --- a/src/legend/qlegend.cpp +++ b/src/legend/qlegend.cpp @@ -336,11 +336,7 @@ void QLegend::setAlignment(Qt::Alignment alignment) { if(d_ptr->m_alignment!=alignment) { d_ptr->m_alignment = alignment; - if(isAttachedToChart()){ - d_ptr->m_presenter->layout()->invalidate(); - }else{ - layout()->invalidate(); - } + layout()->invalidate(); } } @@ -355,7 +351,7 @@ Qt::Alignment QLegend::alignment() const void QLegend::detachFromChart() { d_ptr->m_attachedToChart = false; - d_ptr->m_layout->invalidate(); + layout()->invalidate(); setParent(0); } @@ -366,7 +362,7 @@ void QLegend::detachFromChart() void QLegend::attachToChart() { d_ptr->m_attachedToChart = true; - d_ptr->m_presenter->layout()->invalidate(); + layout()->invalidate(); setParent(d_ptr->m_chart); } @@ -406,14 +402,12 @@ void QLegend::hideEvent(QHideEvent *event) if(isAttachedToChart()) d_ptr->m_presenter->layout()->invalidate(); QGraphicsWidget::hideEvent(event); } - /*! \internal \a event see QGraphicsWidget for details */ void QLegend::showEvent(QShowEvent *event) { if(isAttachedToChart()) { - d_ptr->m_presenter->layout()->invalidate(); d_ptr->items()->setVisible(false); layout()->invalidate(); } @@ -478,8 +472,7 @@ void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); m_items->setVisible(false); - q_ptr->layout()->invalidate(); - m_presenter->layout()->invalidate(); + m_layout->invalidate(); } void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) @@ -493,8 +486,7 @@ void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); - - q_ptr->layout()->invalidate(); + m_layout->invalidate(); } void QLegendPrivate::handleSeriesVisibleChanged() @@ -507,8 +499,7 @@ void QLegendPrivate::handleSeriesVisibleChanged() marker->setVisible(series->isVisible()); } } - - q_ptr->layout()->invalidate(); + m_layout->invalidate(); } void QLegendPrivate::handleCountChanged() diff --git a/src/legend/qlegend_p.h b/src/legend/qlegend_p.h index 41e58e0..17b0825 100644 --- a/src/legend/qlegend_p.h +++ b/src/legend/qlegend_p.h @@ -79,6 +79,7 @@ private: bool m_backgroundVisible; friend class QLegend; +friend class LegendLayout; };