Skip to content

Commit

Permalink
Display AdditionalProps for InspectorGadget
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed May 24, 2024
1 parent 538a879 commit 22e0ba8
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 92 deletions.
62 changes: 62 additions & 0 deletions src/model_editor/InspectorGadget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <openstudio/model/Model.hpp>
#include <openstudio/model/ParentObject.hpp>
#include <openstudio/model/ParentObject_Impl.hpp>
#include <openstudio/model/AdditionalProperties.hpp>

#include "../model_editor/Utilities.hpp"

Expand All @@ -58,6 +59,7 @@

#include <iostream>
#include <limits>
#include <utilities/idd/IddEnums.hpp>
#include <vector>

#include <QDoubleValidator>
Expand Down Expand Up @@ -165,6 +167,7 @@ InspectorGadget::~InspectorGadget() {

void InspectorGadget::connectSignalsAndSlots() {
connect(this, &InspectorGadget::toggleUnitsClicked, this, &InspectorGadget::toggleUnits);
connect(this, &InspectorGadget::toggleDisplayAdditionalPropsClicked, this, &InspectorGadget::toggleDisplayAdditionalProps);
}

void InspectorGadget::rebuild(bool recursive) {
Expand Down Expand Up @@ -367,6 +370,51 @@ void InspectorGadget::layoutItems(QVBoxLayout* masterLayout, QWidget* parent, bo
}
} // if(p)

if (m_displayAdditionalProps) {
// m_workspaceObj->getSources(IddObjectType::OS_AdditionalProperties)
if (auto mo_ = m_workspaceObj->optionalCast<model::ModelObject>(); mo_.has_value() && mo_->hasAdditionalProperties()) {
auto addProps = mo_->additionalProperties();
auto igChildItr = m_childMap.find(addProps);
if (igChildItr != m_childMap.end()) {
InspectorGadget* igchild = igChildItr->second;
layout->addWidget(igchild);
} else {
bool showComment = false;
bool showFields = true;
if (m_recursive) {
showComment = m_showComments;
showFields = m_showAllFields;
}
auto* igChild = new InspectorGadget(addProps, m_indent, m_comboBridge, showComment, showFields, m_recursive, m_locked);

igChild->setUnitSystem(m_unitSystem);
layout->addWidget(igChild);
m_childMap[addProps] = igChild;
}

#if 0
for (const auto& name : addProps.featureNames()) {
auto propType_ = addProps.getFeatureDataType(name);
OS_ASSERT(propType_);
auto propType = std::move(*propType_);
if (propType == "String") {
boost::optional<std::string> val_ = addProps.getFeatureAsString(name);
OS_ASSERT(val_);
} else if (propType == "Double") {
boost::optional<double> val_ = addProps.getFeatureAsDouble(name);
OS_ASSERT(val_);
} else if (propType == "Integer") {
boost::optional<int> val_ = addProps.getFeatureAsInteger(name);
OS_ASSERT(val_);
} else if (propType == "Double") {
boost::optional<bool> val_ = addProps.getFeatureAsBoolean(name);
OS_ASSERT(val_);
}
}
#endif
}
}

if (m_stretch) {
masterLayout->addStretch();
}
Expand Down Expand Up @@ -1148,3 +1196,17 @@ void InspectorGadget::setUnitSystem(const InspectorGadget::UNIT_SYSTEM unitSyste
m_unitSystem = unitSystem;
rebuild(true);
}

void InspectorGadget::toggleDisplayAdditionalProps(bool displayAdditionalProps) {
qDebug() << "InspectorGadget::toggleDisplayAdditionalProps";
setDisplayAdditionalProps(displayAdditionalProps);
}

void InspectorGadget::setDisplayAdditionalProps(bool displayAdditionalProps) {
qDebug() << "InspectorGadget::setDisplayAdditionalProps=" << displayAdditionalProps;
openstudio::OptionalWorkspaceObject currentObject = m_workspaceObj;
clear(true);
m_workspaceObj = currentObject;
m_displayAdditionalProps = displayAdditionalProps;
rebuild(true);
}
7 changes: 7 additions & 0 deletions src/model_editor/InspectorGadget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,16 @@ class MODELEDITOR_API InspectorGadget

void setUnitSystem(const UNIT_SYSTEM unitSystem);

void setDisplayAdditionalProps(bool displayAdditionalProps);

void removeWorkspaceObject(const openstudio::Handle&); // Middleman nano slot to emit QT signal to simulate signal chaining

public slots:

void toggleUnits(bool displayIP);

void toggleDisplayAdditionalProps(bool displayAdditionalProps);

/*! \brief lays out the last object again.
*
*\param recursive if true, apply the change to the children
Expand Down Expand Up @@ -228,6 +232,8 @@ class MODELEDITOR_API InspectorGadget

void toggleUnitsClicked(bool);

void toggleDisplayAdditionalPropsClicked(bool);

/*!
*This signal is emitted when the IG changes the model. If your program
*uses IG, then you should connect to this so that you know if the file needs saving or not
Expand Down Expand Up @@ -317,6 +323,7 @@ class MODELEDITOR_API InspectorGadget
bool m_recursive;
UNIT_SYSTEM m_unitSystem;
bool m_workspaceObjectChanged;
bool m_displayAdditionalProps = false;

typedef std::map<openstudio::model::ModelObject, InspectorGadget*> MODELMAP;
MODELMAP m_childMap;
Expand Down
4 changes: 3 additions & 1 deletion src/openstudio_lib/InspectorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ InspectorController::InspectorController() : QObject() {

connect(this, &InspectorController::toggleUnitsClicked, m_inspectorView, &InspectorView::toggleUnitsClicked);

connect(this, &InspectorController::toggleDisplayAdditionalPropsClicked, m_inspectorView, &InspectorView::toggleDisplayAdditionalPropsClicked);
connect(m_inspectorView, &InspectorView::removeZoneClicked, this, &InspectorController::removeBranchForZone);

connect(m_inspectorView, &InspectorView::addToLoopClicked, this, &InspectorController::addToLoop);
Expand Down Expand Up @@ -108,8 +109,9 @@ InspectorView* InspectorController::inspectorView() {

void InspectorController::layoutModelObject(model::OptionalModelObject& modelObject, bool readOnly) {
bool displayIP = OSAppBase::instance()->currentDocument()->mainWindow()->displayIP();
bool displayAdditionalProps = OSAppBase::instance()->currentDocument()->mainWindow()->displayAdditionalProps();

m_inspectorView->layoutModelObject(modelObject, readOnly, displayIP);
m_inspectorView->layoutModelObject(modelObject, readOnly, displayIP, displayAdditionalProps);

m_modelObject = modelObject;
}
Expand Down
2 changes: 2 additions & 0 deletions src/openstudio_lib/InspectorController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class InspectorController : public QObject

void toggleUnitsClicked(bool displayIP);

void toggleDisplayAdditionalPropsClicked(bool displayAdditionalProps);

void itemRemoveClicked(OSItem*);

void removeButtonClicked(bool);
Expand Down
Loading

0 comments on commit 22e0ba8

Please sign in to comment.