|
| 1 | +/*********************************************************************************************************************** |
| 2 | +* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved. |
| 3 | +* |
| 4 | +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the |
| 5 | +* following conditions are met: |
| 6 | +* |
| 7 | +* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following |
| 8 | +* disclaimer. |
| 9 | +* |
| 10 | +* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following |
| 11 | +* disclaimer in the documentation and/or other materials provided with the distribution. |
| 12 | +* |
| 13 | +* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products |
| 14 | +* derived from this software without specific prior written permission from the respective party. |
| 15 | +* |
| 16 | +* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works |
| 17 | +* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior |
| 18 | +* written permission from Alliance for Sustainable Energy, LLC. |
| 19 | +* |
| 20 | +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 21 | +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 | +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED |
| 23 | +* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 | +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 25 | +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 26 | +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 27 | +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | +***********************************************************************************************************************/ |
| 29 | + |
| 30 | +#include "ScheduleCompactInspectorView.hpp" |
| 31 | + |
| 32 | +#include "../shared_gui_components/OSLineEdit.hpp" |
| 33 | +#include "../shared_gui_components/OSDoubleEdit.hpp" |
| 34 | +#include "../model_editor/Utilities.hpp" |
| 35 | + |
| 36 | +#include <openstudio/model/ScheduleCompact.hpp> |
| 37 | +#include <openstudio/model/ScheduleCompact_Impl.hpp> |
| 38 | + |
| 39 | +#include <openstudio/utilities/core/Assert.hpp> |
| 40 | + |
| 41 | +#include <QGridLayout> |
| 42 | +#include <QLabel> |
| 43 | +#include <QStackedWidget> |
| 44 | +#include <QPlainTextEdit> |
| 45 | + |
| 46 | +#include <sstream> |
| 47 | + |
| 48 | +namespace openstudio { |
| 49 | + |
| 50 | +// ScheduleCompactInspectorView |
| 51 | + |
| 52 | +ScheduleCompactInspectorView::ScheduleCompactInspectorView(const openstudio::model::Model& model, QWidget* parent) |
| 53 | + : ModelObjectInspectorView(model, true, parent) { |
| 54 | + createLayout(); |
| 55 | +} |
| 56 | + |
| 57 | +void ScheduleCompactInspectorView::createLayout() { |
| 58 | + auto* hiddenWidget = new QWidget(); |
| 59 | + this->stackedWidget()->addWidget(hiddenWidget); |
| 60 | + |
| 61 | + auto* visibleWidget = new QWidget(); |
| 62 | + this->stackedWidget()->addWidget(visibleWidget); |
| 63 | + |
| 64 | + auto* mainGridLayout = new QGridLayout(); |
| 65 | + mainGridLayout->setContentsMargins(7, 7, 7, 7); |
| 66 | + mainGridLayout->setSpacing(14); |
| 67 | + visibleWidget->setLayout(mainGridLayout); |
| 68 | + |
| 69 | + int row = mainGridLayout->rowCount(); |
| 70 | + |
| 71 | + QLabel* label = nullptr; |
| 72 | + |
| 73 | + // Name |
| 74 | + |
| 75 | + label = new QLabel("Name: "); |
| 76 | + label->setObjectName("H2"); |
| 77 | + mainGridLayout->addWidget(label, row, 0); |
| 78 | + |
| 79 | + ++row; |
| 80 | + |
| 81 | + m_nameEdit = new OSLineEdit2(); |
| 82 | + mainGridLayout->addWidget(m_nameEdit, row, 0, 1, 1); |
| 83 | + |
| 84 | + ++row; |
| 85 | + |
| 86 | + // Value |
| 87 | + |
| 88 | + label = new QLabel("Content: "); |
| 89 | + label->setObjectName("H2"); |
| 90 | + mainGridLayout->addWidget(label, row++, 0); |
| 91 | + |
| 92 | + m_content = new QPlainTextEdit(); |
| 93 | + m_content->setReadOnly(true); |
| 94 | + const QFont f = QFontDatabase::systemFont(QFontDatabase::FixedFont); |
| 95 | + m_content->setFont(f); |
| 96 | + |
| 97 | + mainGridLayout->addWidget(m_content, row++, 0, 1, 2); |
| 98 | + |
| 99 | + // Stretch |
| 100 | + |
| 101 | + mainGridLayout->setRowStretch(100, 100); |
| 102 | + mainGridLayout->setColumnStretch(0, 3); |
| 103 | + mainGridLayout->setColumnStretch(1, 1); |
| 104 | + mainGridLayout->setColumnStretch(2, 1); |
| 105 | +} |
| 106 | + |
| 107 | +void ScheduleCompactInspectorView::onClearSelection() { |
| 108 | + ModelObjectInspectorView::onClearSelection(); // call parent implementation |
| 109 | + detach(); |
| 110 | +} |
| 111 | + |
| 112 | +void ScheduleCompactInspectorView::onSelectModelObject(const openstudio::model::ModelObject& modelObject) { |
| 113 | + detach(); |
| 114 | + auto sch = modelObject.cast<model::ScheduleCompact>(); |
| 115 | + attach(sch); |
| 116 | + refresh(); |
| 117 | +} |
| 118 | + |
| 119 | +void ScheduleCompactInspectorView::onUpdate() { |
| 120 | + refresh(); |
| 121 | +} |
| 122 | + |
| 123 | +void ScheduleCompactInspectorView::attach(openstudio::model::ScheduleCompact& sch) { |
| 124 | + m_sch = sch; |
| 125 | + |
| 126 | + m_nameEdit->bind( |
| 127 | + *m_sch, OptionalStringGetter(std::bind(&model::ScheduleCompact::name, m_sch.get_ptr(), true)), |
| 128 | + boost::optional<StringSetterOptionalStringReturn>(std::bind(&model::ScheduleCompact::setName, m_sch.get_ptr(), std::placeholders::_1))); |
| 129 | + |
| 130 | + std::stringstream ss; |
| 131 | + sch.print(ss); |
| 132 | + |
| 133 | + m_content->setPlainText(toQString(ss.str())); |
| 134 | + |
| 135 | + this->stackedWidget()->setCurrentIndex(1); |
| 136 | +} |
| 137 | + |
| 138 | +void ScheduleCompactInspectorView::detach() { |
| 139 | + this->stackedWidget()->setCurrentIndex(0); |
| 140 | + |
| 141 | + m_nameEdit->unbind(); |
| 142 | + |
| 143 | + m_sch = boost::none; |
| 144 | +} |
| 145 | + |
| 146 | +void ScheduleCompactInspectorView::refresh() {} |
| 147 | + |
| 148 | +} // namespace openstudio |
0 commit comments