From 3a785f12ca3f977b75cd0eb170547b6131008d12 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 25 Jan 2019 14:36:38 +1300 Subject: [PATCH] CellML Text view: make sure that a file is still valid before actually reloading it. --- .../src/cellmltextviewplugin.cpp | 14 ++------------ .../src/cellmltextviewwidget.cpp | 18 ++++++++++++++++-- .../CellMLTextView/src/cellmltextviewwidget.h | 2 ++ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/plugins/editing/CellMLTextView/src/cellmltextviewplugin.cpp b/src/plugins/editing/CellMLTextView/src/cellmltextviewplugin.cpp index 6744fd071b..33e1f067f6 100644 --- a/src/plugins/editing/CellMLTextView/src/cellmltextviewplugin.cpp +++ b/src/plugins/editing/CellMLTextView/src/cellmltextviewplugin.cpp @@ -21,14 +21,10 @@ along with this program. If not, see . // CellML Text view plugin //============================================================================== -#include "cellmleditingviewwidget.h" -#include "cellmlfilemanager.h" #include "cellmlsupportplugin.h" #include "cellmltextviewplugin.h" #include "cellmltextviewwidget.h" -#include "corecliutils.h" #include "coreguiutils.h" -#include "filemanager.h" //============================================================================== @@ -375,16 +371,10 @@ QString CellMLTextViewPlugin::viewDefaultFileExtension() const QWidget * CellMLTextViewPlugin::viewWidget(const QString &pFileName) { - // Make sure that we are dealing with either a new file or a CellML 1.0/1.1 - // file - - CellMLSupport::CellmlFile::Version cellmlVersion = CellMLSupport::CellmlFile::fileVersion(pFileName); + // Make sure that we are dealing with a valid file - if ( !Core::FileManager::instance()->isNew(pFileName) - && (cellmlVersion != CellMLSupport::CellmlFile::Cellml_1_0) - && (cellmlVersion != CellMLSupport::CellmlFile::Cellml_1_1)) { + if (!mViewWidget->isValid(pFileName)) return nullptr; - } // Update and return our CellML Text view widget using the given CellML // file diff --git a/src/plugins/editing/CellMLTextView/src/cellmltextviewwidget.cpp b/src/plugins/editing/CellMLTextView/src/cellmltextviewwidget.cpp index effd5b229f..1d5bdae237 100644 --- a/src/plugins/editing/CellMLTextView/src/cellmltextviewwidget.cpp +++ b/src/plugins/editing/CellMLTextView/src/cellmltextviewwidget.cpp @@ -453,6 +453,19 @@ void CellmlTextViewWidget::retranslateUi() //============================================================================== +bool CellmlTextViewWidget::isValid(const QString &pFileName) const +{ + // Return whether we are dealing with a new file or a CellML 1.0/1.1 file + + CellMLSupport::CellmlFile::Version cellmlVersion = CellMLSupport::CellmlFile::fileVersion(pFileName); + + return Core::FileManager::instance()->isNew(pFileName) + || (cellmlVersion == CellMLSupport::CellmlFile::Cellml_1_0) + || (cellmlVersion == CellMLSupport::CellmlFile::Cellml_1_1); +} + +//============================================================================== + void CellmlTextViewWidget::initialize(const QString &pFileName, bool pUpdate) { // Retrieve the editing widget associated with the given file, if any @@ -667,7 +680,8 @@ void CellmlTextViewWidget::fileSaved(const QString &pFileName) void CellmlTextViewWidget::fileReloaded(const QString &pFileName) { - // The given file has been reloaded, so reload it, should it be managed + // The given file has been reloaded, so reload it, should it be managed and + // still valid // Note: if the view for the given file is not the active view, then to call // finalize() and then initialize() will activate the contents of the // view (but the file tab will still point to the previously active @@ -676,7 +690,7 @@ void CellmlTextViewWidget::fileReloaded(const QString &pFileName) CellmlTextViewWidgetData *data = mData.value(pFileName); - if (data) { + if (data && isValid(pFileName)) { bool update = mEditingWidget == data->editingWidget(); finalize(pFileName); diff --git a/src/plugins/editing/CellMLTextView/src/cellmltextviewwidget.h b/src/plugins/editing/CellMLTextView/src/cellmltextviewwidget.h index dea240b9a4..cb2c316549 100644 --- a/src/plugins/editing/CellMLTextView/src/cellmltextviewwidget.h +++ b/src/plugins/editing/CellMLTextView/src/cellmltextviewwidget.h @@ -139,6 +139,8 @@ class CellmlTextViewWidget : public Core::ViewWidget void retranslateUi() override; + bool isValid(const QString &pFileName) const; + void initialize(const QString &pFileName, bool pUpdate = true); void finalize(const QString &pFileName);