diff base/Event.h @ 1674:69ab62d378bf osc-script

Ensure image & text models get the proper attribute names (which are not the same as the default event ones)
author Chris Cannam
date Wed, 27 Mar 2019 16:06:35 +0000
parents a77a7e8c085c
children 4ca784e5033e
line wrap: on
line diff
--- a/base/Event.h	Wed Mar 27 14:15:21 2019 +0000
+++ b/base/Event.h	Wed Mar 27 16:06:35 2019 +0000
@@ -256,21 +256,44 @@
         return m_uri < p.m_uri;
     }
 
+    struct ExportNameOptions {
+
+        ExportNameOptions() :
+            valueAtttributeName("value"),
+            uriAttributeName("uri") { }
+
+        QString valueAtttributeName;
+        QString uriAttributeName;
+    };
+    
     void toXml(QTextStream &stream,
                QString indent = "",
-               QString extraAttributes = "") const {
+               QString extraAttributes = "",
+               ExportNameOptions opts = ExportNameOptions()) const {
 
         // For I/O purposes these are points, not events
         stream << indent << QString("<point frame=\"%1\" ").arg(m_frame);
-        if (m_haveValue) stream << QString("value=\"%1\" ").arg(m_value);
-        if (m_haveDuration) stream << QString("duration=\"%1\" ").arg(m_duration);
-        if (m_haveLevel) stream << QString("level=\"%1\" ").arg(m_level);
-        if (m_haveReferenceFrame) stream << QString("referenceFrame=\"%1\" ")
-                                      .arg(m_referenceFrame);
-        stream << QString("label=\"%1\" ")
-            .arg(XmlExportable::encodeEntities(m_label));
+        if (m_haveValue) {
+            stream << QString("%1=\"%2\" ")
+                .arg(opts.valueAtttributeName).arg(m_value);
+        }
+        if (m_haveDuration) {
+            stream << QString("duration=\"%1\" ").arg(m_duration);
+        }
+        if (m_haveLevel) {
+            stream << QString("level=\"%1\" ").arg(m_level);
+        }
+        if (m_haveReferenceFrame) {
+            stream << QString("referenceFrame=\"%1\" ")
+                .arg(m_referenceFrame);
+        }
+        if (m_label != "") {
+            stream << QString("label=\"%1\" ")
+                .arg(XmlExportable::encodeEntities(m_label));
+        }
         if (m_uri != QString()) {
-            stream << QString("uri=\"%1\" ")
+            stream << QString("%1=\"%2\" ")
+                .arg(opts.uriAttributeName)
                 .arg(XmlExportable::encodeEntities(m_uri));
         }
         stream << extraAttributes << "/>\n";