changeset 3:581f67f370f3

* Beginnings of session save code * Add spline curve mode to time value layer
author Chris Cannam
date Thu, 12 Jan 2006 17:19:08 +0000
parents d86891498eef
children 149bb02a41ba
files base/Layer.cpp base/Layer.h base/Model.cpp base/Model.h base/View.cpp base/View.h base/XmlExportable.cpp base/XmlExportable.h
diffstat 8 files changed, 176 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/base/Layer.cpp	Thu Jan 12 13:45:27 2006 +0000
+++ b/base/Layer.cpp	Thu Jan 12 17:19:08 2006 +0000
@@ -12,6 +12,8 @@
 
 #include <iostream>
 
+#include "layer/LayerFactory.h" //!!! shouldn't be including this here -- does that suggest we need to move this into layer/ ?
+
 Layer::Layer(View *w)
 {
     m_view = w;
@@ -32,6 +34,23 @@
     emit layerNameChanged();
 }
 
+QString
+Layer::toXmlString(QString indent, QString extraAttributes) const
+{
+    QString s;
+    
+    s += indent;
+
+    s += QString("<layer type=\"%1\" id=\"%2\" name=\"%3\" model=\"%4\" %5/>\n")
+	.arg(LayerFactory::instance()->getLayerTypeName
+	     (LayerFactory::instance()->getLayerType(this)))
+	.arg((intptr_t)this)
+	.arg(objectName())
+	.arg((intptr_t)getModel())
+	.arg(extraAttributes);
+
+    return s;
+}
 
 #ifdef INCLUDE_MOCFILES
 #include "Layer.moc.cpp"
--- a/base/Layer.h	Thu Jan 12 13:45:27 2006 +0000
+++ b/base/Layer.h	Thu Jan 12 17:19:08 2006 +0000
@@ -12,6 +12,7 @@
 #define _VIEWER_H_
 
 #include "PropertyContainer.h"
+#include "XmlExportable.h"
 
 #include <QObject>
 #include <QRect>
@@ -28,7 +29,8 @@
  */
 
 class Layer : public QObject,
-	      public PropertyContainer
+	      public PropertyContainer,
+	      public XmlExportable
 {
     Q_OBJECT
 
@@ -86,6 +88,9 @@
 
     virtual void setObjectName(const QString &name);
 
+    virtual QString toXmlString(QString indent = "",
+				QString extraAttributes = "") const;
+
 signals:
     void modelChanged();
     void modelCompletionChanged();
--- a/base/Model.cpp	Thu Jan 12 13:45:27 2006 +0000
+++ b/base/Model.cpp	Thu Jan 12 17:19:08 2006 +0000
@@ -1,8 +1,31 @@
+/* -*- c-basic-offset: 4 -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    A waveform viewer and audio annotation editor.
+    Chris Cannam, Queen Mary University of London, 2005-2006
+    
+    This is experimental software.  Not for distribution.
+*/
 
 #include "Model.h"
 
 const int Model::COMPLETION_UNKNOWN = -1;
 
+QString
+Model::toXmlString(QString indent, QString extraAttributes) const
+{
+    QString s;
+    
+    s += indent;
+
+    s += QString("<model id=\"%1\" name=\"%2\" %3/>\n")
+	.arg((intptr_t)this)
+	.arg(objectName())
+	.arg(extraAttributes);
+
+    return s;
+}
+
 #ifdef INCLUDE_MOCFILES
 #ifdef INCLUDE_MOCFILES
 #include "Model.moc.cpp"
--- a/base/Model.h	Thu Jan 12 13:45:27 2006 +0000
+++ b/base/Model.h	Thu Jan 12 17:19:08 2006 +0000
@@ -13,6 +13,8 @@
 #include <vector>
 #include <QObject>
 
+#include "XmlExportable.h"
+
 typedef std::vector<float> SampleBlock;
 
 /** 
@@ -20,7 +22,8 @@
  * of data on a time scale based on an audio frame rate.
  */
 
-class Model : virtual public QObject
+class Model : virtual public QObject,
+	      public XmlExportable
 {
     Q_OBJECT
 
@@ -82,6 +85,9 @@
     }
     static const int COMPLETION_UNKNOWN;
 
+    virtual QString toXmlString(QString indent = "",
+				QString extraAttributes = "") const;
+
 signals:
     /**
      * Emitted when a model has been edited (or more data retrieved
--- a/base/View.cpp	Thu Jan 12 13:45:27 2006 +0000
+++ b/base/View.cpp	Thu Jan 12 17:19:08 2006 +0000
@@ -953,6 +953,39 @@
     QFrame::paintEvent(e);
 }
 
+QString
+View::toXmlString(QString indent, QString extraAttributes) const
+{
+    QString s;
+
+    s += indent;
+
+    s += QString("<view "
+		 "centre=\"%1\" "
+		 "zoom=\"%2\" "
+		 "followPan=\"%3\" "
+		 "followZoom=\"%4\" "
+		 "tracking=\"%5\" "
+		 "light=\"%6\" %7>\n")
+	.arg(m_centreFrame)
+	.arg(m_zoomLevel)
+	.arg(m_followPan)
+	.arg(m_followZoom)
+	.arg(m_followPlay == PlaybackScrollContinuous ? "scroll" :
+	     m_followPlay == PlaybackScrollPage ? "page" : "ignore")
+	.arg(m_lightBackground)
+	.arg(extraAttributes);
+
+    for (size_t i = 0; i < m_layers.size(); ++i) {
+	s += m_layers[i]->toXmlString(indent + "  ");
+    }
+
+    s += indent + "</view>";
+
+    return s;
+}
+
+
 #ifdef INCLUDE_MOCFILES
 #include "View.moc.cpp"
 #endif
--- a/base/View.h	Thu Jan 12 13:45:27 2006 +0000
+++ b/base/View.h	Thu Jan 12 17:19:08 2006 +0000
@@ -15,6 +15,7 @@
 
 #include "base/ZoomConstraint.h"
 #include "base/PropertyContainer.h"
+#include "base/XmlExportable.h"
 
 class Layer;
 class ViewManager;
@@ -35,7 +36,8 @@
  */
 
 class View : public QFrame,
-	     public PropertyContainer
+	     public PropertyContainer,
+	     public XmlExportable
 {
     Q_OBJECT
 
@@ -148,6 +150,9 @@
 	return objectName();
     }
 
+    virtual QString toXmlString(QString indent = "",
+				QString extraAttributes = "") const;
+
 signals:
     void propertyContainerAdded(PropertyContainer *pc);
     void propertyContainerRemoved(PropertyContainer *pc);
@@ -191,23 +196,23 @@
 
     void checkProgress(void *object);
 
-    size_t m_centreFrame;
-    int m_zoomLevel;
-    bool m_newModel;
-    bool m_followPan;
-    bool m_followZoom;
-    PlaybackFollowMode m_followPlay;
-    size_t m_playPointerFrame;
-    bool m_lightBackground;
-    bool m_showProgress;
+    size_t              m_centreFrame;
+    int                 m_zoomLevel;
+    bool                m_newModel;
+    bool                m_followPan;
+    bool                m_followZoom;
+    PlaybackFollowMode  m_followPlay;
+    size_t              m_playPointerFrame;
+    bool                m_lightBackground;
+    bool                m_showProgress;
 
-    QPixmap *m_cache;
-    size_t m_cacheCentreFrame;
-    int m_cacheZoomLevel;
+    QPixmap            *m_cache;
+    size_t              m_cacheCentreFrame;
+    int                 m_cacheZoomLevel;
 
-    bool m_deleting;
+    bool                m_deleting;
 
-    LayerList m_layers; // I don't own these, but see note in dtor comment above
+    LayerList           m_layers; // I don't own these, but see dtor note above
 
     // caches for use in getScrollableBackLayers, getNonScrollableFrontLayers
     mutable LayerList m_lastScrollableBackLayers;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/XmlExportable.cpp	Thu Jan 12 17:19:08 2006 +0000
@@ -0,0 +1,41 @@
+/* -*- c-basic-offset: 4 -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    A waveform viewer and audio annotation editor.
+    Chris Cannam, Queen Mary University of London, 2005-2006
+    
+    This is experimental software.  Not for distribution.
+*/
+
+#include "XmlExportable.h"
+
+QString
+XmlExportable::encodeEntities(QString s)
+{
+    s
+	.replace("&", "&amp;")
+	.replace("<", "&lt;")
+	.replace(">", "&gt;")
+	.replace("\"", "&quot;")
+	.replace("'", "&apos;");
+
+    return s;
+}
+
+QString
+XmlExportable::encodeColour(QColor c)
+{
+    QString r, g, b;
+
+    r.setNum(c.red(), 16);
+    if (c.red() < 16) r = "0" + r;
+
+    g.setNum(c.green(), 16);
+    if (c.green() < 16) g = "0" + g;
+
+    b.setNum(c.blue(), 16);
+    if (c.blue() < 16) b = "0" + b;
+
+    return "#" + r + g + b;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/XmlExportable.h	Thu Jan 12 17:19:08 2006 +0000
@@ -0,0 +1,27 @@
+/* -*- c-basic-offset: 4 -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    A waveform viewer and audio annotation editor.
+    Chris Cannam, Queen Mary University of London, 2005-2006
+    
+    This is experimental software.  Not for distribution.
+*/
+
+#ifndef _XML_EXPORTABLE_H_
+#define _XML_EXPORTABLE_H_
+
+#include <QString>
+#include <QColor>
+
+class XmlExportable
+{
+public:
+    virtual QString toXmlString(QString indent = "",
+				QString extraAttributes = "") const = 0;
+
+    static QString encodeEntities(QString);
+
+    static QString encodeColour(QColor);
+};
+
+#endif