[PATCH] Support more than one event of the same type in Qt tooltip.

Michael Andreen harv at ruin.nu
Tue Jul 30 14:36:20 PDT 2013


Since the tooltip text was used as key in the map, two events of the
same type, close to eachother, would cause one of them to not be
removed.

Since ToolTip::removeToolTip() isn't used, we don't need a QMap and can
use a QList instead, so all tooltips are properly cleared.

Signed-off-by: Michael Andreen <harv at ruin.nu>
---
 qt-ui/profilegraphics.cpp | 24 +-----------------------
 qt-ui/profilegraphics.h   |  3 +--
 2 files changed, 2 insertions(+), 25 deletions(-)

diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index 020c4b5..6f064ab 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -1190,32 +1190,10 @@ void ToolTipItem::addToolTip(const QString& toolTip, const QIcon& icon)
 	textItem->setPos(SPACING + ICON_SMALL + SPACING, yValue);
 	textItem->setBrush(QBrush(Qt::white));
 	textItem->setFlag(ItemIgnoresTransformations);
-	toolTips[toolTip] = qMakePair(iconItem, textItem);
+	toolTips.push_back(qMakePair(iconItem, textItem));
 	expand();
 }
 
-void ToolTipItem::removeToolTip(const QString& toolTip)
-{
-	ToolTip toBeRemoved = toolTips[toolTip];
-	delete toBeRemoved.first;
-	delete toBeRemoved.second;
-	toolTips.remove(toolTip);
-
-	int toolTipIndex = 0;
-
-	// We removed a toolTip, let's move the others to the correct location
-	Q_FOREACH(ToolTip t, toolTips) {
-		double yValue = title->boundingRect().height() + SPACING + toolTipIndex * ICON_SMALL + SPACING;
-
-		// Icons can be null.
-		if (t.first)
-			t.first->setPos(SPACING, yValue);
-
-		t.second->setPos(SPACING + ICON_SMALL + SPACING, yValue);
-		toolTipIndex++;
-	}
-}
-
 void ToolTipItem::refresh(struct graphics_context *gc, QPointF pos)
 {
 	clear();
diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h
index f030ff1..0bcbf75 100644
--- a/qt-ui/profilegraphics.h
+++ b/qt-ui/profilegraphics.h
@@ -35,7 +35,6 @@ public:
 	void expand();
 	void clear();
 	void addToolTip(const QString& toolTip, const QIcon& icon = QIcon());
-	void removeToolTip(const QString& toolTip);
 	void refresh(struct graphics_context* gc, QPointF pos);
 	bool isExpanded();
 	void persistPos();
@@ -48,7 +47,7 @@ public slots:
 
 private:
 	typedef QPair<QGraphicsPixmapItem*, QGraphicsSimpleTextItem*> ToolTip;
-	QMap<QString, ToolTip > toolTips;
+	QList<ToolTip> toolTips;
 	QGraphicsPathItem *background;
 	QGraphicsLineItem *separator;
 	QGraphicsSimpleTextItem *title;
-- 
1.8.1.5




More information about the subsurface mailing list