changeset 923:defbe5bc47b7 tonioni

Add an experimental cancel button to view progress bars
author Chris Cannam
date Fri, 13 Jun 2014 17:39:01 +0100
parents 9911b8cb53bc
children 85879408f665
files data/model/Model.h transform/FeatureExtractionModelTransformer.cpp
diffstat 2 files changed, 34 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/data/model/Model.h	Fri Jun 13 16:35:15 2014 +0100
+++ b/data/model/Model.h	Fri Jun 13 17:39:01 2014 +0100
@@ -105,7 +105,27 @@
      * Caller owns the returned value.
      */
     virtual Model *clone() const = 0;
-    
+
+    /**
+     * Mark the model as abandoning. This means that the application
+     * no longer needs it, so it can stop doing any background
+     * calculations it may be involved in. Note that as far as the
+     * model API is concerned, this does nothing more than tell the
+     * model to return true from isAbandoning().  The actual response
+     * to this will depend on the model's context -- it's possible
+     * nothing at all will change.
+     */
+    virtual void abandon() {
+        m_abandoning = true;
+    }
+
+    /**
+     * Query whether the model has been marked as abandoning.
+     */
+    virtual bool isAbandoning() const { 
+        return m_abandoning;
+    }
+
     /**
      * Return true if the model has finished loading or calculating
      * all its data, for a model that is capable of calculating in a
@@ -268,7 +288,11 @@
     void aboutToBeDeleted();
 
 protected:
-    Model() : m_sourceModel(0), m_alignment(0), m_aboutToDelete(false) { }
+    Model() : 
+        m_sourceModel(0), 
+        m_alignment(0), 
+        m_abandoning(false), 
+        m_aboutToDelete(false) { }
 
     // Not provided.
     Model(const Model &);
@@ -277,6 +301,7 @@
     Model *m_sourceModel;
     AlignmentModel *m_alignment;
     QString m_typeUri;
+    bool m_abandoning;
     bool m_aboutToDelete;
 };
 
--- a/transform/FeatureExtractionModelTransformer.cpp	Fri Jun 13 16:35:15 2014 +0100
+++ b/transform/FeatureExtractionModelTransformer.cpp	Fri Jun 13 17:39:01 2014 +0100
@@ -1018,6 +1018,7 @@
 	SparseOneDimensionalModel *model =
             getConformingOutput<SparseOneDimensionalModel>(n);
 	if (!model) return;
+        if (model->isAbandoning()) abandon();
 	model->setCompletion(completion, true);
 
     } else if (isOutput<SparseTimeValueModel>(n)) {
@@ -1025,24 +1026,28 @@
 	SparseTimeValueModel *model =
             getConformingOutput<SparseTimeValueModel>(n);
 	if (!model) return;
+        if (model->isAbandoning()) abandon();
 	model->setCompletion(completion, true);
 
     } else if (isOutput<NoteModel>(n)) {
 
 	NoteModel *model = getConformingOutput<NoteModel>(n);
 	if (!model) return;
+        if (model->isAbandoning()) abandon();
 	model->setCompletion(completion, true);
 	
-	} else if (isOutput<FlexiNoteModel>(n)) {
+    } else if (isOutput<FlexiNoteModel>(n)) {
 
 	FlexiNoteModel *model = getConformingOutput<FlexiNoteModel>(n);
 	if (!model) return;
+        if (model->isAbandoning()) abandon();
 	model->setCompletion(completion, true);
 
     } else if (isOutput<RegionModel>(n)) {
 
 	RegionModel *model = getConformingOutput<RegionModel>(n);
 	if (!model) return;
+        if (model->isAbandoning()) abandon();
 	model->setCompletion(completion, true);
 
     } else if (isOutput<EditableDenseThreeDimensionalModel>(n)) {
@@ -1050,6 +1055,7 @@
 	EditableDenseThreeDimensionalModel *model =
             getConformingOutput<EditableDenseThreeDimensionalModel>(n);
 	if (!model) return;
+        if (model->isAbandoning()) abandon();
 	model->setCompletion(completion, true); //!!!m_context.updates);
     }
 }