Skip to content
Snippets Groups Projects
Commit a5531d6c authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

MaterialModel subscription decision moved to MaterialModel

parent 6989b274
No related branches found
No related tags found
No related merge requests found
...@@ -20,16 +20,17 @@ ...@@ -20,16 +20,17 @@
#include "MaterialDataItem.h" #include "MaterialDataItem.h"
#include "AppSvc.h" #include "AppSvc.h"
MaterialModel::MaterialModel(QObject* parent) : SessionModel(SessionXML::MaterialModelTag, parent) MaterialModel::MaterialModel(QObject* parent) : SessionModel(SessionXML::MaterialModelTag, parent)
{ {
setObjectName(SessionXML::MaterialModelTag); setObjectName(SessionXML::MaterialModelTag);
AppSvc::subscribe(this); if (AppSvc::materialModel() == nullptr)
AppSvc::subscribe(this);
} }
MaterialModel::~MaterialModel() MaterialModel::~MaterialModel()
{ {
AppSvc::unsubscribe(this); if (AppSvc::materialModel() == this)
AppSvc::unsubscribe(this);
} }
MaterialModel* MaterialModel::createCopy(SessionItem* parent) MaterialModel* MaterialModel::createCopy(SessionItem* parent)
......
...@@ -88,9 +88,9 @@ void AppSvc::this_unsubscribe(ProjectManager* projectManager) ...@@ -88,9 +88,9 @@ void AppSvc::this_unsubscribe(ProjectManager* projectManager)
void AppSvc::this_subscribe(MaterialModel* materialModel) void AppSvc::this_subscribe(MaterialModel* materialModel)
{ {
// MaterialModel created first will be subscribed
if (m_materialModel) if (m_materialModel)
return; throw GUIHelpers::Error("AppSvc::projectManager() -> Error. Attempt to subscribe "
"MaterialModel twice.");
m_materialModel = materialModel; m_materialModel = materialModel;
} }
...@@ -98,7 +98,8 @@ void AppSvc::this_subscribe(MaterialModel* materialModel) ...@@ -98,7 +98,8 @@ void AppSvc::this_subscribe(MaterialModel* materialModel)
void AppSvc::this_unsubscribe(MaterialModel* materialModel) void AppSvc::this_unsubscribe(MaterialModel* materialModel)
{ {
if (m_materialModel != materialModel) if (m_materialModel != materialModel)
return; throw GUIHelpers::Error("AppSvc::projectManager() -> Error. Attempt to unsubscribe "
"MaterialModel before it was subscribed.");
m_materialModel = nullptr; m_materialModel = nullptr;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment