From a6e95511a681043907c2718b19d9d9023af173a9 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 16 Jan 2015 17:13:58 -0200 Subject: Reduce the amount of new/delete when setting a new text on DiveTextItem We were recreating the PathItems (one for the outline, other for the real text) for every call to setText. This was a very un-smart move. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/profile/divetextitem.cpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/profile/divetextitem.cpp b/qt-ui/profile/divetextitem.cpp index fad35eb2f..ddaf6efb2 100644 --- a/qt-ui/profile/divetextitem.cpp +++ b/qt-ui/profile/divetextitem.cpp @@ -12,12 +12,16 @@ DiveTextItem::DiveTextItem(QGraphicsItem *parent) : QGraphicsItemGroup(parent), internalAlignFlags(Qt::AlignHCenter | Qt::AlignVCenter), - textBackgroundItem(NULL), - textItem(NULL), + textBackgroundItem(new QGraphicsPathItem(this)), + textItem(new QGraphicsPathItem(this)), colorIndex(SAC_DEFAULT), scale(1.0) { setFlag(ItemIgnoresTransformations); + textBackgroundItem->setBrush(QBrush(getColor(TEXT_BACKGROUND))); + textBackgroundItem->setPen(Qt::NoPen); + textItem->setBrush(brush); + textItem->setPen(Qt::NoPen); } void DiveTextItem::setAlignment(int alignFlags) @@ -51,10 +55,6 @@ const QString &DiveTextItem::text() void DiveTextItem::updateText() { double size; - delete textItem; - textItem = NULL; - delete textBackgroundItem; - textBackgroundItem = NULL; if (internalText.isEmpty()) { return; } @@ -76,21 +76,16 @@ void DiveTextItem::updateText() QRectF rect = fm.boundingRect(internalText); yPos = (internalAlignFlags & Qt::AlignTop) ? 0 : - (internalAlignFlags & Qt::AlignBottom) ? +rect.height() : - /*(internalAlignFlags & Qt::AlignVCenter ? */ +rect.height() / 4; + (internalAlignFlags & Qt::AlignBottom) ? +rect.height() : + /*(internalAlignFlags & Qt::AlignVCenter ? */ +rect.height() / 4; xPos = (internalAlignFlags & Qt::AlignLeft) ? -rect.width() : - (internalAlignFlags & Qt::AlignHCenter) ? -rect.width() / 2 : - /* (internalAlignFlags & Qt::AlignRight) */ 0; + (internalAlignFlags & Qt::AlignHCenter) ? -rect.width() / 2 : + /* (internalAlignFlags & Qt::AlignRight) */ 0; textPath.addText(xPos, yPos, fnt, internalText); QPainterPathStroker stroker; stroker.setWidth(3); - textBackgroundItem = new QGraphicsPathItem(stroker.createStroke(textPath), this); - textBackgroundItem->setBrush(QBrush(getColor(TEXT_BACKGROUND))); - textBackgroundItem->setPen(Qt::NoPen); - - textItem = new QGraphicsPathItem(textPath, this); - textItem->setBrush(brush); - textItem->setPen(Qt::NoPen); + textBackgroundItem->setPath(stroker.createStroke(textPath)); + textItem->setPath(textPath); } -- cgit v1.2.3-70-g09d2