Mercurial > hg > svapp
changeset 363:f5c914661f6f tonioni
Cancel async layer creation in Tony when selection is changed during it
author | Chris Cannam |
---|---|
date | Mon, 16 Jun 2014 09:28:12 +0100 |
parents | 5302c548adad |
children | c32393c09304 a1b8b6a2cdfc |
files | framework/Document.cpp framework/Document.h |
diffstat | 2 files changed, 44 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/framework/Document.cpp Fri Jun 13 13:51:17 2014 +0100 +++ b/framework/Document.cpp Mon Jun 16 09:28:12 2014 +0100 @@ -275,24 +275,33 @@ } vector<Layer *> layers = m_doc->createLayersForDerivedModels (models, names); - m_handler->layersCreated(m_primary, layers); + m_handler->layersCreated(this, m_primary, layers); delete this; } void noMoreModelsAvailable() { std::cerr << "AdditionalModelConverter::noMoreModelsAvailable" << std::endl; - m_handler->layersCreated(m_primary, vector<Layer *>()); + m_handler->layersCreated(this, m_primary, vector<Layer *>()); delete this; } + void cancel() { + foreach (Layer *layer, m_primary) { + Model *model = layer->getModel(); + if (model) { + model->abandon(); + } + } + } + private: Document *m_doc; vector<Layer *> m_primary; Document::LayerCreationHandler *m_handler; //!!! how to handle destruction of this? }; -void +Document::LayerCreationAsyncHandle Document::createDerivedLayersAsync(const Transforms &transforms, const ModelTransformer::Input &input, LayerCreationHandler *handler) @@ -318,10 +327,21 @@ if (newModels.empty()) { //!!! This identifier may be wrong! emit modelGenerationFailed(transforms[0].getIdentifier(), message); + //!!! what to do with amc? } else if (message != "") { //!!! This identifier may be wrong! emit modelGenerationWarning(transforms[0].getIdentifier(), message); + //!!! what to do with amc? } + + return amc; +} + +void +Document::cancelAsyncLayerCreation(Document::LayerCreationAsyncHandle h) +{ + AdditionalModelConverter *conv = static_cast<AdditionalModelConverter *>(h); + conv->cancel(); } vector<Layer *>
--- a/framework/Document.h Fri Jun 13 13:51:17 2014 +0100 +++ b/framework/Document.h Mon Jun 16 09:28:12 2014 +0100 @@ -128,6 +128,8 @@ std::vector<Layer *> createDerivedLayers(const Transforms &, const ModelTransformer::Input &); + typedef void *LayerCreationAsyncHandle; + class LayerCreationHandler { public: virtual ~LayerCreationHandler() { } @@ -137,9 +139,12 @@ * models, listed in the same order as the input models. The * additional layers vector contains any layers (from all * models) that were returned separately at the end of - * processing. + * processing. The handle indicates which async process this + * callback was initiated by. It must not be used again after + * this function returns. */ - virtual void layersCreated(std::vector<Layer *> primary, + virtual void layersCreated(LayerCreationAsyncHandle handle, + std::vector<Layer *> primary, std::vector<Layer *> additional) = 0; }; @@ -148,11 +153,21 @@ * identical apart from the output (i.e. must use the same plugin * and configuration). This method returns after initialising the * transformer process, and the layers are returned through a - * subsequent call to the provided handler (which must be non-null). + * subsequent call to the provided handler (which must be + * non-null). The handle returned will be passed through to the + * handler callback, and may be also used for cancelling the task. */ - void createDerivedLayersAsync(const Transforms &, - const ModelTransformer::Input &, - LayerCreationHandler *handler); + LayerCreationAsyncHandle createDerivedLayersAsync(const Transforms &, + const ModelTransformer::Input &, + LayerCreationHandler *handler); + + /** + * Indicate that the async layer creation task associated with the + * given handle should be cancelled. There is no guarantee about + * what this will mean, and the handler callback may still be + * called. + */ + void cancelAsyncLayerCreation(LayerCreationAsyncHandle handle); /** * Delete the given layer, and also its associated model if no