Lubomir,

Now we reuse the Tooltip / Pixmap items without deleting it.
Also a lot of uneeded calls were moved / removed.

It stills uses a high cpu, but in my tests it goes from 25% to ~16%



On Wed, Jan 14, 2015 at 2:52 PM, Tomaz Canabrava <[email protected]> wrote:

>
> in terms of leaks, the profile mouse over is leaking about 1mb every
>> 15 seconds, but that could be Qt related (if we can isolate it in a
>> simple test app that is).
>>
>
> I'v answered lubomir with a 7mbs+ callgrind file data so he can help me
> triage this, in the meantime, another patch to reduce the amount of calls
> uneeded in the mouseMoveEvent calls. :)
> I'm thinkering of a way to reduce the amount of new's and deletes in the
> toolTipItem now.
>
>
From 2c8ffc5af7c7cf5a6686f7e6277ccc0ed96e79da Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 14 Jan 2015 17:11:41 -0200
Subject: [PATCH 4/4] Reuse the Entry tooltip Item and do less fnc calls for
 each mouse move

While analizing the code for the mouse movement I'v discovered that
we did a lot of uneeded things: Set the color, the pen, the size
of a fixed-colored line, twice.

We also deleted-newed the same Pixmap / Text for every mouse movement
so now we reuse the 'entryToolTip' that consists of a huge line and
a pixmap, and after that we add the other tooltips that are not static

Also, reduced a lot the number of calls to expand() ( that did
a lot of math ).

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/divetooltipitem.cpp | 70 ++++++++++++++++++++++-----------------
 qt-ui/profile/divetooltipitem.h   |  1 +
 2 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp
index dbef866..c56286b 100644
--- a/qt-ui/profile/divetooltipitem.cpp
+++ b/qt-ui/profile/divetooltipitem.cpp
@@ -23,27 +23,27 @@ void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QP
 {
 	const IconMetrics& iconMetrics = defaultIconMetrics();
 
-	QGraphicsPixmapItem *iconItem = 0, *pixmapItem = 0;
+	QGraphicsPixmapItem *iconItem = 0;
 	double yValue = title->boundingRect().height() + iconMetrics.spacing;
 	Q_FOREACH (ToolTip t, toolTips) {
 		yValue += t.second->boundingRect().height();
 	}
+	if (entryToolTip.second) {
+		yValue += entryToolTip.second->boundingRect().height();
+	}
+	iconItem = new QGraphicsPixmapItem(this);
 	if (!icon.isNull()) {
-		iconItem = new QGraphicsPixmapItem(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small), this);
-		iconItem->setPos(iconMetrics.spacing, yValue);
-	} else {
-		if (!pixmap.isNull()) {
-			pixmapItem = new QGraphicsPixmapItem(pixmap, this);
-			pixmapItem->setPos(iconMetrics.spacing, yValue);
-		}
+		iconItem->setPixmap(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small));
+	} else if (!pixmap.isNull()) {
+		iconItem->setPixmap(pixmap);
 	}
+	iconItem->setPos(iconMetrics.spacing, yValue);
 
 	QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this);
 	textItem->setPos(iconMetrics.spacing + iconMetrics.sz_small + iconMetrics.spacing, yValue);
 	textItem->setBrush(QBrush(Qt::white));
 	textItem->setFlag(ItemIgnoresTransformations);
 	toolTips.push_back(qMakePair(iconItem, textItem));
-	expand();
 }
 
 void ToolTipItem::clear()
@@ -109,11 +109,18 @@ void ToolTipItem::expand()
 	const IconMetrics& iconMetrics = defaultIconMetrics();
 
 	double width = 0, height = title->boundingRect().height() + iconMetrics.spacing;
-	Q_FOREACH (ToolTip t, toolTips) {
+	Q_FOREACH (const ToolTip& t, toolTips) {
 		if (t.second->boundingRect().width() > width)
 			width = t.second->boundingRect().width();
 		height += t.second->boundingRect().height();
 	}
+
+	if (entryToolTip.first) {
+		if (entryToolTip.second->boundingRect().width() > width)
+			width = entryToolTip.second->boundingRect().width();
+		height += entryToolTip.second->boundingRect().height();
+	}
+
 	/*       Left padding, Icon Size,   space, right padding */
 	width += iconMetrics.spacing + iconMetrics.sz_small + iconMetrics.spacing + iconMetrics.spacing;
 
@@ -144,10 +151,22 @@ ToolTipItem::ToolTipItem(QGraphicsItem *parent) : QGraphicsPathItem(parent),
 	lastTime(-1)
 {
 	memset(&pInfo, 0, sizeof(pInfo));
-
+	entryToolTip.first = NULL;
+	entryToolTip.second = NULL;
 	setFlags(ItemIgnoresTransformations | ItemIsMovable | ItemClipsChildrenToShape);
 	updateTitlePosition();
 	setZValue(99);
+
+	addToolTip(QString(), QIcon(), QPixmap(16,60));
+	entryToolTip = toolTips.first();
+	toolTips.clear();
+
+	separator->setFlag(ItemIgnoresTransformations);
+	separator->setPen(QPen(Qt::white));
+
+	title->setFlag(ItemIgnoresTransformations);
+	title->setPen(QPen(Qt::white, 1));
+	title->setBrush(Qt::white);
 }
 
 ToolTipItem::~ToolTipItem()
@@ -166,23 +185,13 @@ void ToolTipItem::updateTitlePosition()
 	}
 
 	title->setPos(boundingRect().width() / 2 - title->boundingRect().width() / 2 - 1, 0);
-	title->setFlag(ItemIgnoresTransformations);
-	title->setPen(QPen(Qt::white, 1));
-	title->setBrush(Qt::white);
 
-	if (toolTips.size() > 0) {
-		double x1 = 3;
-		double y1 = title->pos().y() + iconMetrics.spacing / 2 + title->boundingRect().height();
-		double x2 = boundingRect().width() - 10;
-		double y2 = y1;
-
-		separator->setLine(x1, y1, x2, y2);
-		separator->setFlag(ItemIgnoresTransformations);
-		separator->setPen(QPen(Qt::white));
-		separator->show();
-	} else {
-		separator->hide();
-	}
+	double x1 = 3;
+	double y1 = title->pos().y() + iconMetrics.spacing / 2 + title->boundingRect().height();
+	double x2 = boundingRect().width() - 10;
+	double y2 = y1;
+
+	separator->setLine(x1, y1, x2, y2);
 }
 
 bool ToolTipItem::isExpanded() const
@@ -230,7 +239,6 @@ void ToolTipItem::setTimeAxis(DiveCartesianAxis *axis)
 
 void ToolTipItem::refresh(const QPointF &pos)
 {
-	int i;
 	struct plot_data *entry;
 	static QPixmap tissues(16,60);
 	static QPainter painter(&tissues);
@@ -257,10 +265,11 @@ void ToolTipItem::refresh(const QPointF &pos)
 		painter.drawLine(0, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2,
 				16, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure /2);
 		painter.setPen(QColor(0, 0, 0, 127));
-		for (i=0; i<16; i++) {
+		for (int i=0; i<16; i++) {
 			painter.drawLine(i, 60, i, 60 - entry->percentages[i] / 2);
 		}
-		addToolTip(QString::fromUtf8(mb.buffer, mb.len),QIcon(), tissues);
+		entryToolTip.first->setPixmap(tissues);
+		entryToolTip.second->setText(QString::fromUtf8(mb.buffer, mb.len));
 	}
 	free_buffer(&mb);
 
@@ -269,6 +278,7 @@ void ToolTipItem::refresh(const QPointF &pos)
 		if (!item->toolTip().isEmpty())
 			addToolTip(item->toolTip());
 	}
+	expand();
 }
 
 void ToolTipItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
diff --git a/qt-ui/profile/divetooltipitem.h b/qt-ui/profile/divetooltipitem.h
index bb3ad84..ca5bc89 100644
--- a/qt-ui/profile/divetooltipitem.h
+++ b/qt-ui/profile/divetooltipitem.h
@@ -50,6 +50,7 @@ slots:
 private:
 	typedef QPair<QGraphicsPixmapItem *, QGraphicsSimpleTextItem *> ToolTip;
 	QVector<ToolTip> toolTips;
+	ToolTip entryToolTip;
 	QGraphicsPathItem *background;
 	QGraphicsLineItem *separator;
 	QGraphicsSimpleTextItem *title;
-- 
2.2.2

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to