Commit dd1e4cf3 authored by John Tourtellott's avatar John Tourtellott
Browse files

Clear qtProjectRuntime when project is closed

* Thanks Ryan
* Also put qtProjectRuntime in namespace (oops)
* Note that we also need code to clear the analysis panel
parent ba6cfb98
......@@ -49,7 +49,8 @@ pqACE3PCloseReaction::pqACE3PCloseReaction(QAction* parentObject)
void pqACE3PCloseReaction::closeProject()
{
// Get current project
auto project = qtProjectRuntime::instance()->project();
auto runtime = smtk::simulation::ace3p::qtProjectRuntime::instance();
auto project = runtime->project();
if (project == nullptr)
{
qWarning() << "Internal error - no active project.";
......@@ -88,6 +89,9 @@ void pqACE3PCloseReaction::closeProject()
resManager->remove(resource);
}
// Todo clear analysis panel
runtime->unsetProject(project);
// Must remove project from *both* resource manager & project manager
resManager->remove(project);
projectManager->remove(project);
......
......@@ -101,7 +101,7 @@ void pqACE3PExportBehavior::exportProject()
auto exportOp = opManager->create<smtk::simulation::ace3p::Export>();
InternalCheckMacro(exportOp != nullptr, "Internal Error: Export operation not created.");
auto project = qtProjectRuntime::instance()->project();
auto project = smtk::simulation::ace3p::qtProjectRuntime::instance()->project();
exportOp->parameters()->associate(project);
//Check for single analysis resource
......
......@@ -145,7 +145,7 @@ bool pqACE3PLoader::load(pqServer* server, const QString& directoryPath)
auto project = std::dynamic_pointer_cast<smtk::project::Project>(resource);
assert(project != nullptr);
qtProjectRuntime::instance()->setProject(project);
smtk::simulation::ace3p::qtProjectRuntime::instance()->setProject(project);
qInfo() << "Opened project" << project->name().c_str();
emit this->projectOpened(project);
......
......@@ -68,7 +68,7 @@ void pqACE3PNewAnalysisReaction::createNewAnalysis()
assert(newAnalysisOp != nullptr);
// connect to the current project
auto project = qtProjectRuntime::instance()->project();
auto project = smtk::simulation::ace3p::qtProjectRuntime::instance()->project();
newAnalysisOp->parameters()->associate(project);
// Construct a modal dialog for the operation spec
......
......@@ -279,7 +279,7 @@ void pqACE3PNewBehavior::newProject()
auto project = std::dynamic_pointer_cast<smtk::project::Project>(resource);
assert(project != nullptr);
qtProjectRuntime::instance()->setProject(project);
smtk::simulation::ace3p::qtProjectRuntime::instance()->setProject(project);
emit this->projectCreated(project);
return;
}
......
......@@ -51,7 +51,7 @@ pqACE3PSaveReaction::pqACE3PSaveReaction(QAction* parentObject)
void pqACE3PSaveReaction::saveProject()
{
// Get current project
auto project = qtProjectRuntime::instance()->project();
auto project = smtk::simulation::ace3p::qtProjectRuntime::instance()->project();
if (project == nullptr)
{
qWarning() << "Internal error - no active project.";
......
......@@ -11,8 +11,18 @@
//=============================================================================
#include "smtk/simulation/ace3p/qt/qtProjectRuntime.h"
namespace
{
// Static var to store the singleton instance
static qtProjectRuntime* g_instance = nullptr;
static smtk::simulation::ace3p::qtProjectRuntime* g_instance = nullptr;
} // namespace
namespace smtk
{
namespace simulation
{
namespace ace3p
{
qtProjectRuntime* qtProjectRuntime::instance(QObject* parent)
{
......@@ -38,3 +48,19 @@ qtProjectRuntime::~qtProjectRuntime()
QObject::disconnect(this);
}
bool qtProjectRuntime::unsetProject(std::shared_ptr<smtk::project::Project> p)
{
if (m_project == p)
{
m_project.reset();
return true;
}
// (else)
return false;
}
}
}
}
......@@ -24,6 +24,14 @@
* paraview "manager" for access by other plugins.
*
*/
namespace smtk
{
namespace simulation
{
namespace ace3p
{
class SMTKACE3PQTEXT_EXPORT qtProjectRuntime : public QObject
{
Q_OBJECT
......@@ -33,6 +41,7 @@ public:
static qtProjectRuntime* instance(QObject* parent = nullptr);
std::shared_ptr<smtk::project::Project> project() const { return m_project; }
void setProject(std::shared_ptr<smtk::project::Project> p) { m_project = p; }
bool unsetProject(std::shared_ptr<smtk::project::Project> p);
protected:
qtProjectRuntime(QObject* parent = nullptr)
......@@ -47,4 +56,7 @@ private:
std::shared_ptr<smtk::project::Project> m_project;
};
}
}
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment