From 001bc2f7048715ae76d91475a213c2b588b3f818 2013-09-12 06:59:50 From: Titta Heikkala Date: 2013-09-12 06:59:50 Subject: [PATCH] Fix setting the axis title The axis title text needs to be set in the ChartAxisElement only if the new title is empty or the title is hidden. In other cases the title will be set in updateGeometry() of the axis. Removed redundancy of setting title information. The title information needs to be set only once when creating items for axis. Task-number: QTRD-2104 Change-Id: Ie29c94215bdbab412a3dbb8368309abbd15aa4d1 Reviewed-by: Miikka Heikkinen --- diff --git a/src/axis/cartesianchartaxis.cpp b/src/axis/cartesianchartaxis.cpp index 522223d..6353807 100644 --- a/src/axis/cartesianchartaxis.cpp +++ b/src/axis/cartesianchartaxis.cpp @@ -59,20 +59,21 @@ void CartesianChartAxis::createItems(int count) } } + QGraphicsTextItem *title = titleItem(); + title->setFont(axis()->titleFont()); + title->setDefaultTextColor(axis()->titleBrush().color()); + title->setHtml(axis()->titleText()); + for (int i = 0; i < count; ++i) { QGraphicsLineItem *arrow = new QGraphicsLineItem(this); QGraphicsLineItem *grid = new QGraphicsLineItem(this); QGraphicsTextItem *label = new QGraphicsTextItem(this); label->document()->setDocumentMargin(ChartPresenter::textMargin()); - QGraphicsTextItem *title = titleItem(); arrow->setPen(axis()->linePen()); grid->setPen(axis()->gridLinePen()); label->setFont(axis()->labelsFont()); label->setDefaultTextColor(axis()->labelsBrush().color()); label->setRotation(axis()->labelsAngle()); - title->setFont(axis()->titleFont()); - title->setDefaultTextColor(axis()->titleBrush().color()); - title->setHtml(axis()->titleText()); arrowGroup()->addToGroup(arrow); gridGroup()->addToGroup(grid); labelGroup()->addToGroup(label); diff --git a/src/axis/chartaxiselement.cpp b/src/axis/chartaxiselement.cpp index 1fa133d..51bd2af 100644 --- a/src/axis/chartaxiselement.cpp +++ b/src/axis/chartaxiselement.cpp @@ -152,7 +152,8 @@ void ChartAxisElement::handleTitleTextChanged(const QString &title) { QGraphicsLayoutItem::updateGeometry(); presenter()->layout()->invalidate(); - m_title->setHtml(title); + if (title.isEmpty() || !m_title->isVisible()) + m_title->setHtml(title); } void ChartAxisElement::handleTitlePenChanged(const QPen &pen) diff --git a/src/axis/polarchartaxisangular.cpp b/src/axis/polarchartaxisangular.cpp index 9fa99ac..25f28f9 100644 --- a/src/axis/polarchartaxisangular.cpp +++ b/src/axis/polarchartaxisangular.cpp @@ -253,20 +253,21 @@ void PolarChartAxisAngular::createItems(int count) arrowGroup()->addToGroup(arrow); } + QGraphicsTextItem *title = titleItem(); + title->setFont(axis()->titleFont()); + title->setDefaultTextColor(axis()->titleBrush().color()); + title->setHtml(axis()->titleText()); + for (int i = 0; i < count; ++i) { QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem()); QGraphicsLineItem *grid = new QGraphicsLineItem(presenter()->rootItem()); QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem()); label->document()->setDocumentMargin(ChartPresenter::textMargin()); - QGraphicsTextItem *title = titleItem(); arrow->setPen(axis()->linePen()); grid->setPen(axis()->gridLinePen()); label->setFont(axis()->labelsFont()); label->setDefaultTextColor(axis()->labelsBrush().color()); label->setRotation(axis()->labelsAngle()); - title->setFont(axis()->titleFont()); - title->setDefaultTextColor(axis()->titleBrush().color()); - title->setHtml(axis()->titleText()); arrowGroup()->addToGroup(arrow); gridGroup()->addToGroup(grid); labelGroup()->addToGroup(label); diff --git a/src/axis/polarchartaxisradial.cpp b/src/axis/polarchartaxisradial.cpp index 53544fd..d4fc1c9 100644 --- a/src/axis/polarchartaxisradial.cpp +++ b/src/axis/polarchartaxisradial.cpp @@ -238,20 +238,21 @@ void PolarChartAxisRadial::createItems(int count) arrowGroup()->addToGroup(arrow); } + QGraphicsTextItem *title = titleItem(); + title->setFont(axis()->titleFont()); + title->setDefaultTextColor(axis()->titleBrush().color()); + title->setHtml(axis()->titleText()); + for (int i = 0; i < count; ++i) { QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem()); QGraphicsEllipseItem *grid = new QGraphicsEllipseItem(presenter()->rootItem()); QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem()); label->document()->setDocumentMargin(ChartPresenter::textMargin()); - QGraphicsTextItem *title = titleItem(); arrow->setPen(axis()->linePen()); grid->setPen(axis()->gridLinePen()); label->setFont(axis()->labelsFont()); label->setDefaultTextColor(axis()->labelsBrush().color()); label->setRotation(axis()->labelsAngle()); - title->setFont(axis()->titleFont()); - title->setDefaultTextColor(axis()->titleBrush().color()); - title->setHtml(axis()->titleText()); arrowGroup()->addToGroup(arrow); gridGroup()->addToGroup(grid); labelGroup()->addToGroup(label);