changeset 85:ea730e3f9ace

* Ensure consistent ordering of layer text labels * Fix erroneous SR mismatch warning when adding a wave-file model when no other wave-file model is present (only models that don't assert any particular playback samplerate)
author Chris Cannam
date Thu, 27 Apr 2006 11:49:34 +0000
parents 97e085895524
children e076e676439b
files base/View.cpp base/XmlExportable.cpp base/XmlExportable.h
diffstat 3 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/base/View.cpp	Wed Apr 26 16:27:34 2006 +0000
+++ b/base/View.cpp	Thu Apr 27 11:49:34 2006 +0000
@@ -178,16 +178,21 @@
 int
 View::getTextLabelHeight(const Layer *layer, QPainter &paint) const
 {
-    int y = 15 + paint.fontMetrics().ascent();
+    std::map<int, Layer *> sortedLayers;
 
     for (LayerList::const_iterator i = m_layers.begin();
          i != m_layers.end(); ++i) { 
+        if ((*i)->needsTextLabelHeight()) {
+            sortedLayers[getObjectExportId(*i)] = *i;
+        }
+    }
 
-        if (*i == layer) return y;
+    int y = 15 + paint.fontMetrics().ascent();
 
-        if ((*i)->needsTextLabelHeight()) {
-            y += paint.fontMetrics().height();
-        }
+    for (std::map<int, Layer *>::const_iterator i = sortedLayers.begin();
+         i != sortedLayers.end(); ++i) {
+        if (i->second == layer) return y;
+        y += paint.fontMetrics().height();
     }
 
     return y;
--- a/base/XmlExportable.cpp	Wed Apr 26 16:27:34 2006 +0000
+++ b/base/XmlExportable.cpp	Thu Apr 27 11:49:34 2006 +0000
@@ -15,6 +15,8 @@
 
 #include "XmlExportable.h"
 #include <map>
+#include <QMutex>
+#include <QMutexLocker>
 
 QString
 XmlExportable::encodeEntities(QString s)
@@ -49,6 +51,9 @@
 int
 XmlExportable::getObjectExportId(const void * object)
 {
+    static QMutex mutex;
+    QMutexLocker locker(&mutex);
+
     static std::map<const void *, int> idMap;
     static int maxId = 0;
     
--- a/base/XmlExportable.h	Wed Apr 26 16:27:34 2006 +0000
+++ b/base/XmlExportable.h	Thu Apr 27 11:49:34 2006 +0000
@@ -31,7 +31,7 @@
 
     static QString encodeColour(QColor);
 
-    static int getObjectExportId(const void *); // not thread-safe
+    static int getObjectExportId(const void *); // thread-safe
 };
 
 #endif