From 0c35eea94a17d33662f8ff472fb3867e975d1964 Mon Sep 17 00:00:00 2001 From: Evan Weaver Date: Sat, 19 Mar 2016 10:07:25 -0600 Subject: [PATCH] [#114600757] Construction Inheritance --- .../src/openstudio_lib/OSDropZone.cpp | 54 +++++++++++++++---- .../src/openstudio_lib/OSDropZone.hpp | 5 +- openstudiocore/src/openstudio_lib/OSItem.cpp | 7 +++ .../SpacesInteriorPartitionsGridView.cpp | 1 + .../openstudio_lib/SpacesShadingGridView.cpp | 1 + .../SpacesSubsurfacesGridView.cpp | 1 + .../openstudio_lib/SpacesSurfacesGridView.cpp | 1 + .../OSGridController.cpp | 16 ++++++ .../OSGridController.hpp | 5 ++ 9 files changed, 79 insertions(+), 12 deletions(-) diff --git a/openstudiocore/src/openstudio_lib/OSDropZone.cpp b/openstudiocore/src/openstudio_lib/OSDropZone.cpp index 6d1fe3d5be0..13c63747594 100644 --- a/openstudiocore/src/openstudio_lib/OSDropZone.cpp +++ b/openstudiocore/src/openstudio_lib/OSDropZone.cpp @@ -712,17 +712,8 @@ void OSDropZone2::mouseReleaseEvent(QMouseEvent * event) if (event->button() == Qt::LeftButton){ event->accept(); - if (!m_item && m_get && *m_get) { - boost::optional modelObject = (*m_get)(); - - if (modelObject) - { - m_item = OSItem::makeItem(modelObjectToItemId(*modelObject, false)); - m_item->setParent(this); - connect(m_item, &OSItem::itemRemoveClicked, this, &OSDropZone2::onItemRemoveClicked); - - connect(modelObject->getImpl().get(), &openstudio::model::detail::ModelObject_Impl::onChange, this, &OSDropZone2::refresh); - } + if (!m_item) { + makeItem(); } if (m_item) { @@ -786,5 +777,46 @@ void OSDropZone2::onItemRemoveClicked() emit objectRemoved(parent); } } +void OSDropZone2::makeItem() +{ + if (!m_item && m_get && *m_get) { + boost::optional modelObject = (*m_get)(); + + if (modelObject) + { + m_item = OSItem::makeItem(modelObjectToItemId(*modelObject, false)); + m_item->setParent(this); + connect(m_item, &OSItem::itemRemoveClicked, this, &OSDropZone2::onItemRemoveClicked); + + connect(modelObject->getImpl().get(), &openstudio::model::detail::ModelObject_Impl::onChange, this, &OSDropZone2::refresh); + } + } +} + +void OSDropZone2::setIsDefaulted(bool defaulted) +{ + if (!m_item) { + makeItem(); + } + + if (m_item) { + m_item->setIsDefaulted(defaulted); + } + + if (defaulted) { + m_label->setStyleSheet("QLabel { color:green }"); // color: #006837 + } else { + m_label->setStyleSheet("QLabel { color:black }"); + } +} + +bool OSDropZone2::isDefaulted() +{ + bool isDefaluted = false; + if (m_item) { + isDefaluted = m_item->isDefaulted(); + } + return isDefaluted; +} } // openstudio diff --git a/openstudiocore/src/openstudio_lib/OSDropZone.hpp b/openstudiocore/src/openstudio_lib/OSDropZone.hpp index 72a68a820f0..bee5348a467 100644 --- a/openstudiocore/src/openstudio_lib/OSDropZone.hpp +++ b/openstudiocore/src/openstudio_lib/OSDropZone.hpp @@ -64,7 +64,8 @@ class OSDropZone2 : public QWidget bool hasData() { return !this->m_label->text().isEmpty(); } void setDeleteObject(bool deleteObject) { m_deleteObject = deleteObject; } bool deleteObject() { return m_deleteObject; } - + void setIsDefaulted(bool defaulted); + bool isDefaulted(); void bind(model::ModelObject & modelObject, OptionalModelObjectGetter get, ModelObjectSetter set, @@ -97,6 +98,8 @@ private slots: private: + void makeItem(); + boost::optional m_get; boost::optional m_set; boost::optional m_reset; diff --git a/openstudiocore/src/openstudio_lib/OSItem.cpp b/openstudiocore/src/openstudio_lib/OSItem.cpp index a4118a2dda6..33a477f1bae 100644 --- a/openstudiocore/src/openstudio_lib/OSItem.cpp +++ b/openstudiocore/src/openstudio_lib/OSItem.cpp @@ -285,6 +285,13 @@ bool OSItem::isDefaulted() const void OSItem::setIsDefaulted(bool isDefaulted) { m_itemId.setIsDefaulted(isDefaulted); + if (isDefaulted) { + m_textLbl->setStyleSheet("QLabel { color: #006837 }"); + this->setRemoveable(false); + } else { + m_textLbl->setStyleSheet("QLabel { color: black }"); + this->setRemoveable(true); + } } QString OSItem::text() const diff --git a/openstudiocore/src/openstudio_lib/SpacesInteriorPartitionsGridView.cpp b/openstudiocore/src/openstudio_lib/SpacesInteriorPartitionsGridView.cpp index 3609047726a..2a22c756da3 100644 --- a/openstudiocore/src/openstudio_lib/SpacesInteriorPartitionsGridView.cpp +++ b/openstudiocore/src/openstudio_lib/SpacesInteriorPartitionsGridView.cpp @@ -235,6 +235,7 @@ namespace openstudio { ); } else if (field == CONSTRUCTIONNAME) { + m_constructionColumn = 4; addDropZoneColumn(Heading(QString(CONSTRUCTIONNAME), true, false), CastNullAdapter(&model::InteriorPartitionSurface::construction), CastNullAdapter(&model::InteriorPartitionSurface::setConstruction), diff --git a/openstudiocore/src/openstudio_lib/SpacesShadingGridView.cpp b/openstudiocore/src/openstudio_lib/SpacesShadingGridView.cpp index 16d51266f7e..bb4063a016a 100644 --- a/openstudiocore/src/openstudio_lib/SpacesShadingGridView.cpp +++ b/openstudiocore/src/openstudio_lib/SpacesShadingGridView.cpp @@ -233,6 +233,7 @@ namespace openstudio { ); } else if (field == CONSTRUCTION) { + m_constructionColumn = 4; addDropZoneColumn(Heading(QString(CONSTRUCTION)), CastNullAdapter(&model::ShadingSurface::construction), CastNullAdapter(&model::ShadingSurface::setConstruction), diff --git a/openstudiocore/src/openstudio_lib/SpacesSubsurfacesGridView.cpp b/openstudiocore/src/openstudio_lib/SpacesSubsurfacesGridView.cpp index d6a3b95b0bf..b95605d4b28 100644 --- a/openstudiocore/src/openstudio_lib/SpacesSubsurfacesGridView.cpp +++ b/openstudiocore/src/openstudio_lib/SpacesSubsurfacesGridView.cpp @@ -480,6 +480,7 @@ namespace openstudio { ); } else if (field == CONSTRUCTION) { + m_constructionColumn = 6; addDropZoneColumn(Heading(QString(CONSTRUCTION)), CastNullAdapter(&model::SubSurface::construction), CastNullAdapter(&model::SubSurface::setConstruction), diff --git a/openstudiocore/src/openstudio_lib/SpacesSurfacesGridView.cpp b/openstudiocore/src/openstudio_lib/SpacesSurfacesGridView.cpp index 86e810c41ab..3b9f82d6165 100644 --- a/openstudiocore/src/openstudio_lib/SpacesSurfacesGridView.cpp +++ b/openstudiocore/src/openstudio_lib/SpacesSurfacesGridView.cpp @@ -218,6 +218,7 @@ namespace openstudio { ); } else if (field == CONSTRUCTION) { + m_constructionColumn = 4; addDropZoneColumn(Heading(QString(CONSTRUCTION)), CastNullAdapter(&model::Surface::construction), CastNullAdapter(&model::Surface::setConstruction), diff --git a/openstudiocore/src/shared_gui_components/OSGridController.cpp b/openstudiocore/src/shared_gui_components/OSGridController.cpp index 0146d161ddc..0bfe84c09fd 100644 --- a/openstudiocore/src/shared_gui_components/OSGridController.cpp +++ b/openstudiocore/src/shared_gui_components/OSGridController.cpp @@ -43,6 +43,8 @@ #include "../model/Model_Impl.hpp" #include "../model/ModelObject_Impl.hpp" +#include "../model/PlanarSurface.hpp" +#include "../model/PlanarSurface_Impl.hpp" #include "../utilities/core/Assert.hpp" @@ -1349,6 +1351,20 @@ namespace openstudio { connect(horizontalHeaderWidget, &HorizontalHeaderWidget::inFocus, holder, &Holder::inFocus); } + // Is this widget's subrow a surface with a defaulted construction? + if (t_obj) { + if (auto planarSurface = t_obj->optionalCast()) { + if (planarSurface && planarSurface->isConstructionDefaulted()) { + // Is this column a construction? + if (column == m_constructionColumn) { + if (OSDropZone2 * dropZone = qobject_cast(t_widget)) { + dropZone->setIsDefaulted(true); + } + } + } + } + } + m_objectSelector->addWidget(t_obj, holder, row, column, hasSubRows ? numWidgets : boost::optional(), t_selector); ++numWidgets; diff --git a/openstudiocore/src/shared_gui_components/OSGridController.hpp b/openstudiocore/src/shared_gui_components/OSGridController.hpp index 517baf4caa6..45ab85ebba8 100644 --- a/openstudiocore/src/shared_gui_components/OSGridController.hpp +++ b/openstudiocore/src/shared_gui_components/OSGridController.hpp @@ -587,6 +587,11 @@ class OSGridController : public QObject OSGridView * gridView(); + // If a column contains information about a construction, it may be an inherited construction + // (as determined by calling PlanarSurface::isConstructionDefaulted). An instantiated gridview + // should set this value, if appropriate. + int m_constructionColumn = -1; + protected: // This function determines the category for