Skip to content

Commit

Permalink
Replace QT Signal/Slot in Model to compile
Browse files Browse the repository at this point in the history
Replace QT's Signal/Slot interface with Nano-Signal-Slot

`Workspace_Impl/RemoveWorkspaceObject` and
`Workspace_Impl/addWorkspaceObject` both have function override
duplicates, preventing them from being converted literally to
nano-signal-slots, implemented as variables instead of functions. As a
result, `Workspace_Impl/RemoveWorkspaceObjectPtr` and
`Workspace_Impl/addWorkspaceObjectPtr` were created to handle slots
requiring `std::shared_ptr<openstudio::detail::WorkspaceObject_Impl>`
instead of `const WorkspaceObject&`.

`onRemoveFromWorkspace` prototype changed from `void(Handle)` to
`void(const Handle &)` in order to homogenize calls.
  • Loading branch information
Chris Martin committed May 31, 2016
1 parent 141ad2a commit 899b5dd
Show file tree
Hide file tree
Showing 78 changed files with 774 additions and 500 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ test_fails.txt
/build-64/
/build_profile/
/build-profile/

*.sublime-workspace

*.sublime-project
1 change: 1 addition & 0 deletions openstudiocore/src/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(target_name openstudio_model)
set(${target_name}_src

mainpage.hpp
nano_signal_slot.hpp
ModelAPI.hpp
Model.hpp
Model_Impl.hpp
Expand Down
33 changes: 18 additions & 15 deletions openstudiocore/src/model/ComponentWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
#include "ComponentWatcher_Impl.hpp"

#include "Model.hpp"
#include "Model_Impl.hpp"
#include "Model_Impl.hpp"

#include "ModelObject.hpp"
#include "ModelObject_Impl.hpp"

#include "ComponentData_Impl.hpp"
#include "nano_signal_slot.hpp"

#include "../utilities/core/Assert.hpp"
#include "../utilities/core/Compare.hpp"
Expand Down Expand Up @@ -55,24 +56,23 @@ namespace detail {
// connect to object's signals
implPtr = object.getImpl<ModelObject_Impl>();
// data change
connect(implPtr.get(), &ModelObject_Impl::onDataChange, this, &ComponentWatcher_Impl::dataChange);
implPtr.get()->ModelObject_Impl::onDataChange.connect<ComponentWatcher_Impl, &ComponentWatcher_Impl::dataChange>(this);
// name change
connect(implPtr.get(), &ModelObject_Impl::onNameChange, this, &ComponentWatcher_Impl::nameChange);
implPtr.get()->ModelObject_Impl::onNameChange.connect<ComponentWatcher_Impl, &ComponentWatcher_Impl::nameChange>(this);
// relationship change
connect(implPtr.get(), &ModelObject_Impl::onRelationshipChange, this, &ComponentWatcher_Impl::relationshipChange);
implPtr.get()->ModelObject_Impl::onRelationshipChange.connect<ComponentWatcher_Impl, &ComponentWatcher_Impl::relationshipChange>(this);
// remove
connect(implPtr.get(), &ModelObject_Impl::onRemoveFromWorkspace, this, &ComponentWatcher_Impl::objectRemove);
implPtr.get()->ModelObject_Impl::onRemoveFromWorkspace.connect<ComponentWatcher_Impl, &ComponentWatcher_Impl::objectRemove>(this);
}
// connect signals for ComponentData, ComponentDataTags, and ComponentDataAttributes
implPtr = componentData.getImpl<ModelObject_Impl>();
// component data change
connect(implPtr.get(), &ModelObject_Impl::onDataChange, this, &ComponentWatcher_Impl::componentDataChange);
implPtr.get()->ModelObject_Impl::onDataChange.connect<ComponentWatcher_Impl, &ComponentWatcher_Impl::componentDataChange>(this);
// component data remove
connect(implPtr.get(), &ModelObject_Impl::onRemoveFromWorkspace, this, &ComponentWatcher_Impl::objectRemove);
implPtr.get()->ModelObject_Impl::onRemoveFromWorkspace.connect<ComponentWatcher_Impl, &ComponentWatcher_Impl::objectRemove>(this);
// connect to addWorkspaceObject signal
std::shared_ptr<Model_Impl> modelImplPtr = m_componentData.model().getImpl<Model_Impl>();
connect(modelImplPtr.get(), static_cast<void (Model_Impl::*)(const WorkspaceObject&, const openstudio::IddObjectType&, const openstudio::UUID&) const>(&Model_Impl::addWorkspaceObject),
this, &ComponentWatcher_Impl::objectAdd);
modelImplPtr.get()->Model_Impl::addWorkspaceObject.connect<ComponentWatcher_Impl, &ComponentWatcher_Impl::objectAdd>(this);
}

ComponentWatcher ComponentWatcher_Impl::componentWatcher() const {
Expand Down Expand Up @@ -111,17 +111,20 @@ namespace detail {
}

void ComponentWatcher_Impl::objectRemove(const Handle& handleOfRemovedObject) {

// no ComponentData means no Component to watch
if (handleOfRemovedObject == m_componentData.handle()) {
emit obsolete(componentWatcher());
this->obsolete.nano_emit(componentWatcher());
return;
}

// if removedObject is the primary componentObject, nullify the component.
OS_ASSERT(m_componentObjects.size() > 0);
if (handleOfRemovedObject == m_componentObjects[0].handle()) {
mf_removeComponent();
return;
}

// if removedObject is a componentObject, remove from the vector and refresh
// component contents
auto it = std::find_if(m_componentObjects.begin(),
Expand All @@ -135,27 +138,27 @@ namespace detail {
return;
}

void ComponentWatcher_Impl::objectAdd(const WorkspaceObject& addedObject) {
void ComponentWatcher_Impl::objectAdd(const WorkspaceObject& addedObject, const openstudio::IddObjectType& type, const openstudio::UUID& uuid) {
/*IddObjectType type =*/ addedObject.iddObject().type();
return;
}

void ComponentWatcher_Impl::mf_changeComponentVersion() {
// disconnect componentDataChange slot to avoid endless loop
std::shared_ptr<ModelObject_Impl> implPtr = m_componentData.getImpl<ModelObject_Impl>();
disconnect(implPtr.get(), &ModelObject_Impl::onDataChange, this, &ComponentWatcher_Impl::componentDataChange);
implPtr.get()->ModelObject_Impl::onDataChange.disconnect<ComponentWatcher_Impl, &ComponentWatcher_Impl::componentDataChange>(this);

// change version UUID
m_componentData.createVersionUUID();

// reconnect componentDataChange
connect(implPtr.get(), &ModelObject_Impl::onDataChange, this, &ComponentWatcher_Impl::componentDataChange);
implPtr.get()->ModelObject_Impl::onDataChange.connect<ComponentWatcher_Impl, &ComponentWatcher_Impl::componentDataChange>(this);
}

void ComponentWatcher_Impl::mf_refreshComponentContents(bool logWarnings) {
// disconnect componentDataChange slot to avoid endless loop
std::shared_ptr<ModelObject_Impl> implPtr = m_componentData.getImpl<ModelObject_Impl>();
disconnect(implPtr.get(), &ModelObject_Impl::onDataChange, this, &ComponentWatcher_Impl::componentDataChange);
implPtr.get()->ModelObject_Impl::onDataChange.disconnect<ComponentWatcher_Impl, &ComponentWatcher_Impl::componentDataChange>(this);

// \todo logWarnings
m_componentData.clearExtensibleGroups();
Expand All @@ -164,7 +167,7 @@ namespace detail {
}

// reconnect componentDataChange
connect(implPtr.get(), &ModelObject_Impl::onDataChange, this, &ComponentWatcher_Impl::componentDataChange);
implPtr.get()->ModelObject_Impl::onDataChange.connect<ComponentWatcher_Impl, &ComponentWatcher_Impl::componentDataChange>(this);
}

void ComponentWatcher_Impl::mf_removeComponent() {
Expand Down
12 changes: 8 additions & 4 deletions openstudiocore/src/model/ComponentWatcher_Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

#include "../utilities/core/Logger.hpp"

// Signals/Slots QT Replacement
#include "nano_signal_slot.hpp"

#include <QObject>

namespace openstudio {
Expand Down Expand Up @@ -54,9 +57,10 @@ namespace detail {
ComponentData componentData() const;

//@}
signals:

void obsolete(const ComponentWatcher& watcher);
/** @name Nano Signals */
//@{

Nano::Signal<void(const ComponentWatcher &)> obsolete;

public slots:

Expand All @@ -70,7 +74,7 @@ namespace detail {

void objectRemove(const Handle& handleOfRemovedObject);

void objectAdd(const WorkspaceObject& addedObject);
void objectAdd(const WorkspaceObject& addedObject, const openstudio::IddObjectType& type, const openstudio::UUID& uuid);

private:
ComponentData m_componentData;
Expand Down
28 changes: 13 additions & 15 deletions openstudiocore/src/model/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ if (_className::iddObjectType() == typeToCreate) { \
boost::optional<Building> result = this->model().getOptionalUniqueModelObject<Building>();
if (result){
m_cachedBuilding = result;
QObject::connect(result->getImpl<Building_Impl>().get(), &Building_Impl::onRemoveFromWorkspace, this, &Model_Impl::clearCachedBuilding);
result->getImpl<Building_Impl>().get()->Building_Impl::onRemoveFromWorkspace.connect<Model_Impl, &Model_Impl::clearCachedBuilding>(const_cast<openstudio::model::detail::Model_Impl *>(this));
}

return m_cachedBuilding;
Expand All @@ -1015,8 +1015,7 @@ if (_className::iddObjectType() == typeToCreate) { \
boost::optional<LifeCycleCostParameters> result = this->model().getOptionalUniqueModelObject<LifeCycleCostParameters>();
if (result){
m_cachedLifeCycleCostParameters = result;
QObject::connect(result->getImpl<LifeCycleCostParameters_Impl>().get(), &LifeCycleCostParameters_Impl::onRemoveFromWorkspace,
this, &Model_Impl::clearCachedLifeCycleCostParameters);
result->getImpl<LifeCycleCostParameters_Impl>().get()->LifeCycleCostParameters_Impl::onRemoveFromWorkspace.connect<Model_Impl, &Model_Impl::clearCachedLifeCycleCostParameters>(const_cast<openstudio::model::detail::Model_Impl *>(this));
}

return m_cachedLifeCycleCostParameters;
Expand All @@ -1031,7 +1030,7 @@ if (_className::iddObjectType() == typeToCreate) { \
boost::optional<RunPeriod> result = this->model().getOptionalUniqueModelObject<RunPeriod>();
if (result){
m_cachedRunPeriod = result;
QObject::connect(result->getImpl<RunPeriod_Impl>().get(), &RunPeriod_Impl::onRemoveFromWorkspace, this, &Model_Impl::clearCachedRunPeriod);
result->getImpl<RunPeriod_Impl>().get()->RunPeriod_Impl::onRemoveFromWorkspace.connect<Model_Impl, &Model_Impl::clearCachedRunPeriod>(const_cast<openstudio::model::detail::Model_Impl *>(this));
}

return m_cachedRunPeriod;
Expand All @@ -1046,8 +1045,7 @@ if (_className::iddObjectType() == typeToCreate) { \
boost::optional<YearDescription> result = this->model().getOptionalUniqueModelObject<YearDescription>();
if (result){
m_cachedYearDescription = result;
QObject::connect(result->getImpl<YearDescription_Impl>().get(), &YearDescription_Impl::onRemoveFromWorkspace,
this, &Model_Impl::clearCachedYearDescription);
result->getImpl<YearDescription_Impl>().get()->YearDescription_Impl::onRemoveFromWorkspace.connect<Model_Impl, &Model_Impl::clearCachedYearDescription>(const_cast<openstudio::model::detail::Model_Impl *>(this));
}

return m_cachedYearDescription;
Expand All @@ -1062,7 +1060,7 @@ if (_className::iddObjectType() == typeToCreate) { \
boost::optional<WeatherFile> result = this->model().getOptionalUniqueModelObject<WeatherFile>();
if (result){
m_cachedWeatherFile = result;
QObject::connect(result->getImpl<WeatherFile_Impl>().get(), &WeatherFile_Impl::onRemoveFromWorkspace, this, &Model_Impl::clearCachedWeatherFile);
result->getImpl<WeatherFile_Impl>().get()->WeatherFile_Impl::onRemoveFromWorkspace.connect<Model_Impl, &Model_Impl::clearCachedWeatherFile>(const_cast<openstudio::model::detail::Model_Impl *>(this));
}

return m_cachedWeatherFile;
Expand Down Expand Up @@ -1472,15 +1470,15 @@ if (_className::iddObjectType() == typeToCreate) { \
void Model_Impl::reportInitialModelObjects()
{
for (const WorkspaceObject& workspaceObject : this->objects()) {
emit initialModelObject(workspaceObject.getImpl<detail::ModelObject_Impl>().get(), workspaceObject.iddObject().type(), workspaceObject.handle());
this->initialModelObject.nano_emit(workspaceObject.getImpl<detail::ModelObject_Impl>().get(), workspaceObject.iddObject().type(), workspaceObject.handle());
}
emit initialReportComplete();
this->initialReportComplete.nano_emit();
}

void Model_Impl::mf_createComponentWatcher(ComponentData& componentData) {
try {
ComponentWatcher watcher(componentData);
QObject::connect(watcher.getImpl().get(), &ComponentWatcher_Impl::obsolete, this, &Model_Impl::obsoleteComponentWatcher);
watcher.getImpl().get()->ComponentWatcher_Impl::obsolete.connect<Model_Impl, &Model_Impl::obsoleteComponentWatcher>(this); // #HASHTAG Problem?
m_componentWatchers.push_back(watcher);
}
catch (...) {
Expand All @@ -1489,27 +1487,27 @@ if (_className::iddObjectType() == typeToCreate) { \
}
}

void Model_Impl::clearCachedBuilding()
void Model_Impl::clearCachedBuilding(const Handle &)
{
m_cachedBuilding.reset();
}

void Model_Impl::clearCachedLifeCycleCostParameters()
void Model_Impl::clearCachedLifeCycleCostParameters(const Handle &handle)
{
m_cachedLifeCycleCostParameters.reset();
}

void Model_Impl::clearCachedRunPeriod()
void Model_Impl::clearCachedRunPeriod(const Handle& handle)
{
m_cachedRunPeriod.reset();
}

void Model_Impl::clearCachedYearDescription()
void Model_Impl::clearCachedYearDescription(const Handle& handle)
{
m_cachedYearDescription.reset();
}

void Model_Impl::clearCachedWeatherFile()
void Model_Impl::clearCachedWeatherFile(const Handle& handle)
{
m_cachedWeatherFile.reset();
}
Expand Down
4 changes: 2 additions & 2 deletions openstudiocore/src/model/ModelObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ namespace detail {
}
properties.insert(*it, value);
}
emit reportProperties(properties);
this->reportProperties.nano_emit(properties);
}

void ModelObject_Impl::setProperties(const QVariantMap& properties)
Expand All @@ -818,7 +818,7 @@ namespace detail {
}

if (anyFailures){
emit onChange();
this->onChange.nano_emit();
}
}

Expand Down
12 changes: 8 additions & 4 deletions openstudiocore/src/model/ModelObject_Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "ModelAPI.hpp"
#include "ModelObject.hpp" // required for Q_PROPERTY
#include "nano_signal_slot.hpp" // Signal-Slot replacement

#include "../utilities/idf/WorkspaceObject_Impl.hpp"

Expand Down Expand Up @@ -229,16 +230,19 @@ namespace detail {
boost::optional<unsigned> connectedObjectPort(unsigned port) const;

//@}
/** @name Nano Signals */
//@{

Nano::Signal<void(const QVariantMap&)> reportProperties;

//@}

public slots:

void requestProperties(const QStringList& names);

void setProperties(const QVariantMap& properties);

signals:

void reportProperties(const QVariantMap& properties);

protected:

ModelObject_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle);
Expand Down
32 changes: 20 additions & 12 deletions openstudiocore/src/model/Model_Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "YearDescription.hpp"
#include "WeatherFile.hpp"

#include "nano_signal_slot.hpp" // Signal-Slot replacement

#include "../utilities/idf/Workspace.hpp"
#include "../utilities/idf/Workspace_Impl.hpp"
#include "../utilities/idf/WorkspaceObject.hpp"
Expand Down Expand Up @@ -197,17 +199,23 @@ namespace detail {

void disconnect(ModelObject object, unsigned port);

public slots :
//@}
/** @name Nano Signals */
//@{

virtual void obsoleteComponentWatcher(const ComponentWatcher& watcher);
Nano::Signal<void(openstudio::model::detail::ModelObject_Impl *, IddObjectType, openstudio::UUID)> initialModelObject;

virtual void reportInitialModelObjects();
Nano::Signal<void()> initialReportComplete;

signals:
//@}

void initialModelObject(openstudio::model::detail::ModelObject_Impl* modelObject, IddObjectType iddObjectType, const openstudio::UUID& handle);
// public slots :

virtual void obsoleteComponentWatcher(const ComponentWatcher& watcher);

virtual void reportInitialModelObjects();

void initialReportComplete();


private:
// explicitly unimplemented copy constructor
Expand Down Expand Up @@ -236,13 +244,13 @@ namespace detail {
mutable boost::optional<YearDescription> m_cachedYearDescription;
mutable boost::optional<WeatherFile> m_cachedWeatherFile;

private slots:
// private slots:

void clearCachedBuilding();
void clearCachedLifeCycleCostParameters();
void clearCachedRunPeriod();
void clearCachedYearDescription();
void clearCachedWeatherFile();
void clearCachedBuilding(const Handle& handle);
void clearCachedLifeCycleCostParameters(const Handle& handle);
void clearCachedRunPeriod(const Handle& handle);
void clearCachedYearDescription(const Handle& handle);
void clearCachedWeatherFile(const Handle& handle);

};

Expand Down
Loading

0 comments on commit 899b5dd

Please sign in to comment.