diff data/model/Model.h @ 319:3ff8f571da09

* Hoist alignment model set/query up to Model, so any models can be aligned * Add Model::aboutToDelete and aboutToBeDeleted for management of models that are contained by or referred to by other models instead of only the document
author Chris Cannam
date Wed, 24 Oct 2007 15:21:38 +0000
parents 70a232b1f12a
children 1afaf98dbf11
line wrap: on
line diff
--- a/data/model/Model.h	Mon Oct 22 09:45:35 2007 +0000
+++ b/data/model/Model.h	Wed Oct 24 15:21:38 2007 +0000
@@ -24,6 +24,7 @@
 typedef std::vector<float> SampleBlock;
 
 class ZoomConstraint;
+class AlignmentModel;
 
 /** 
  * Model is the base class for all data models that represent any sort
@@ -114,7 +115,8 @@
      * If this model was derived from another, return the model it was
      * derived from.  The assumption is that the source model's
      * alignment will also apply to this model, unless some other
-     * property indicates otherwise.
+     * property (such as a specific alignment model set on this model)
+     * indicates otherwise.
      */
     virtual Model *getSourceModel() const {
         return m_sourceModel;
@@ -123,10 +125,40 @@
     /**
      * Set the source model for this model.
      */
-     //!!! No way to handle source model deletion &c yet
-    virtual void setSourceModel(Model *model) {
-        m_sourceModel = model;
-    }
+    virtual void setSourceModel(Model *model);
+
+    /**
+     * Specify an aligment between this model's timeline and that of a
+     * reference model.  The alignment model records both the
+     * reference and the alignment.  This model takes ownership of the
+     * alignment model.
+     */
+    virtual void setAlignment(AlignmentModel *alignment);
+
+    /**
+     * Return the reference model for the current alignment timeline,
+     * if any.
+     */
+    virtual const Model *getAlignmentReference() const;
+
+    /**
+     * Return the frame number of the reference model that corresponds
+     * to the given frame number in this model.
+     */
+    virtual size_t alignToReference(size_t frame) const;
+
+    /**
+     * Return the frame number in this model that corresponds to the
+     * given frame number of the reference model.
+     */
+    virtual size_t alignFromReference(size_t referenceFrame) const;
+
+    /**
+     * Return the completion percentage for the alignment model: 100
+     * if there is no alignment model or it has been entirely
+     * calculated, or less than 100 if it is still being calculated.
+     */
+    virtual int getAlignmentCompletion() const;
 
     virtual void toXml(QTextStream &stream,
                        QString indent = "",
@@ -134,6 +166,10 @@
 
     virtual QString toDelimitedDataString(QString) const { return ""; }
 
+public slots:
+    void aboutToDelete();
+    void sourceModelAboutToBeDeleted();
+
 signals:
     /**
      * Emitted when a model has been edited (or more data retrieved
@@ -155,14 +191,32 @@
      */
     void completionChanged();
 
+    /**
+     * Emitted when the completion percentage changes for the
+     * calculation of this model's alignment model.
+     */
+    void alignmentCompletionChanged();
+
+    /**
+     * Emitted when something notifies this model (through calling
+     * aboutToDelete() that it is about to delete it.  Note that this
+     * depends on an external agent such as a Document object or
+     * owning model telling the model that it is about to delete it;
+     * there is nothing in the model to guarantee that this signal
+     * will be emitted before the actual deletion.
+     */
+    void aboutToBeDeleted();
+
 protected:
-    Model() : m_sourceModel(0) { }
+    Model() : m_sourceModel(0), m_alignment(0), m_aboutToDelete(false) { }
 
     // Not provided.
     Model(const Model &);
     Model &operator=(const Model &); 
 
     Model *m_sourceModel;
+    AlignmentModel *m_alignment;
+    bool m_aboutToDelete;
 };
 
 #endif