[qet] [1807] Replaced a QMultiMap-based sort with a cleaner qSort().

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 1807
Author:   xavier
Date:     2012-05-11 23:38:50 +0200 (Fri, 11 May 2012)
Log Message:
-----------
Replaced a QMultiMap-based sort with a cleaner qSort().

Modified Paths:
--------------
    trunk/sources/editor/elementscene.cpp
    trunk/sources/editor/elementscene.h

Modified: trunk/sources/editor/elementscene.cpp
===================================================================
--- trunk/sources/editor/elementscene.cpp	2012-05-11 21:27:31 UTC (rev 1806)
+++ trunk/sources/editor/elementscene.cpp	2012-05-11 21:38:50 UTC (rev 1807)
@@ -1039,14 +1039,7 @@
 	}
 	
 	// ordonne les parties par leur zValue
-	QMultiMap<qreal, QGraphicsItem *> mm;
-	foreach(QGraphicsItem *qgi, all_items_list) mm.insert(qgi -> zValue(), qgi);
-	all_items_list.clear();
-	QMapIterator<qreal, QGraphicsItem *> i(mm);
-	while (i.hasNext()) {
-		i.next();
-		all_items_list << i.value();
-	}
+	qSort(all_items_list.begin(), all_items_list.end(), ElementScene::zValueLessThan);
 	
 	// rajoute eventuellement les bornes
 	if (include_terminals) all_items_list += terminals;
@@ -1300,3 +1293,10 @@
 bool ElementScene::mustSnapToGrid(QGraphicsSceneMouseEvent *e) {
 	return(!(e -> modifiers() & Qt::ControlModifier));
 }
+
+/**
+	@return true if \a item1's zValue() is less than \a item2's.
+*/
+bool ElementScene::zValueLessThan(QGraphicsItem *item1, QGraphicsItem *item2) {
+	return(item1-> zValue() < item2 -> zValue());
+}

Modified: trunk/sources/editor/elementscene.h
===================================================================
--- trunk/sources/editor/elementscene.h	2012-05-11 21:27:31 UTC (rev 1806)
+++ trunk/sources/editor/elementscene.h	2012-05-11 21:38:50 UTC (rev 1807)
@@ -159,6 +159,7 @@
 	void initPasteArea();
 	void snapToGrid(QPointF &);
 	bool mustSnapToGrid(QGraphicsSceneMouseEvent *);
+	static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
 	
 	public slots:
 	void slot_move();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/