summaryrefslogtreecommitdiffstats
path: root/qt-ui/profile
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-01-16 17:13:58 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-01-17 08:53:26 +1300
commita6e95511a681043907c2718b19d9d9023af173a9 (patch)
tree3f61e38fac45e76496f5e0686639648e49347af8 /qt-ui/profile
parentabddb3ecb9d93d44bb0071ea369c98499105b9f0 (diff)
downloadsubsurface-a6e95511a681043907c2718b19d9d9023af173a9.tar.gz
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 <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile')
-rw-r--r--qt-ui/profile/divetextitem.cpp29
1 files changed, 12 insertions, 17 deletions
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);
}