Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the crash in schedules view #614

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/openstudio_lib/OSDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,10 @@ boost::optional<BCLMeasure> OSDocument::standardReportMeasure() {

if (m_haveLocalBCL && RemoteBCL::isOnline()) {
RemoteBCL remoteBCL;
result = remoteBCL.getMeasure(uid);
boost::optional<BCLMeasure> onlineResult = remoteBCL.getMeasure(uid);
if (onlineResult) {
result = onlineResult;
}
}

return result;
Expand Down
47 changes: 28 additions & 19 deletions src/openstudio_lib/SchedulesView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,27 +453,30 @@ void SchedulesView::showDefaultScheduleDay(const model::ScheduleRuleset& schedul
void SchedulesView::showSummerScheduleDay(const model::ScheduleRuleset& schedule) {
setUpdatesEnabled(false);

// deleting widgets below (e.g. NewProfileView) may delete the object referenced by schedule, make copy beforehand
const model::ScheduleRuleset scheduleRuleset = schedule;

QLayoutItem* child = nullptr;
while ((child = m_contentLayout->takeAt(0)) != nullptr) {
delete child->widget();

delete child;
}

if (!schedule.isSummerDesignDayScheduleDefaulted()) {
if (!scheduleRuleset.isSummerDesignDayScheduleDefaulted()) {

auto* scheduleView = new SpecialScheduleDayView(m_isIP, schedule, this, SpecialScheduleDayView::SUMMER);
auto* scheduleView = new SpecialScheduleDayView(m_isIP, scheduleRuleset, this, SpecialScheduleDayView::SUMMER);

connect(this, &SchedulesView::toggleUnitsClicked, scheduleView, &SpecialScheduleDayView::toggleUnitsClicked);

m_contentLayout->addWidget(scheduleView);

scheduleView->show();

boost::optional<model::ModelObject> mo = schedule.summerDesignDaySchedule();
boost::optional<model::ModelObject> mo = scheduleRuleset.summerDesignDaySchedule();
emit modelObjectSelected(mo, true);
} else {
auto* newProfileView = new NewProfileView(schedule, this, NewProfileView::SUMMER);
auto* newProfileView = new NewProfileView(scheduleRuleset, this, NewProfileView::SUMMER);

m_contentLayout->addWidget(newProfileView, 100);

Expand All @@ -487,26 +490,29 @@ void SchedulesView::showSummerScheduleDay(const model::ScheduleRuleset& schedule
void SchedulesView::showWinterScheduleDay(const model::ScheduleRuleset& schedule) {
setUpdatesEnabled(false);

// deleting widgets below (e.g. NewProfileView) may delete the object referenced by schedule, make copy beforehand
const model::ScheduleRuleset scheduleRuleset = schedule;

QLayoutItem* child = nullptr;
while ((child = m_contentLayout->takeAt(0)) != nullptr) {
delete child->widget();

delete child;
}

if (!schedule.isWinterDesignDayScheduleDefaulted()) {
auto* scheduleView = new SpecialScheduleDayView(m_isIP, schedule, this, SpecialScheduleDayView::WINTER);
if (!scheduleRuleset.isWinterDesignDayScheduleDefaulted()) {
auto* scheduleView = new SpecialScheduleDayView(m_isIP, scheduleRuleset, this, SpecialScheduleDayView::WINTER);

connect(this, &SchedulesView::toggleUnitsClicked, scheduleView, &SpecialScheduleDayView::toggleUnitsClicked);

m_contentLayout->addWidget(scheduleView);

scheduleView->show();

boost::optional<model::ModelObject> mo = schedule.winterDesignDaySchedule();
boost::optional<model::ModelObject> mo = scheduleRuleset.winterDesignDaySchedule();
emit modelObjectSelected(mo, true);
} else {
auto* newProfileView = new NewProfileView(schedule, this, NewProfileView::WINTER);
auto* newProfileView = new NewProfileView(scheduleRuleset, this, NewProfileView::WINTER);

m_contentLayout->addWidget(newProfileView, 100);

Expand All @@ -520,26 +526,29 @@ void SchedulesView::showWinterScheduleDay(const model::ScheduleRuleset& schedule
void SchedulesView::showHolidayScheduleDay(const model::ScheduleRuleset& schedule) {
setUpdatesEnabled(false);

// deleting widgets below (e.g. NewProfileView) may delete the object referenced by schedule, make copy beforehand
const model::ScheduleRuleset scheduleRuleset = schedule;

QLayoutItem* child = nullptr;
while ((child = m_contentLayout->takeAt(0)) != nullptr) {
delete child->widget();

delete child;
}

if (!schedule.isHolidayScheduleDefaulted()) {
auto* scheduleView = new SpecialScheduleDayView(m_isIP, schedule, this, SpecialScheduleDayView::HOLIDAY);
if (!scheduleRuleset.isHolidayScheduleDefaulted()) {
auto* scheduleView = new SpecialScheduleDayView(m_isIP, scheduleRuleset, this, SpecialScheduleDayView::HOLIDAY);

connect(this, &SchedulesView::toggleUnitsClicked, scheduleView, &SpecialScheduleDayView::toggleUnitsClicked);

m_contentLayout->addWidget(scheduleView);

scheduleView->show();

boost::optional<model::ModelObject> mo = schedule.holidaySchedule();
boost::optional<model::ModelObject> mo = scheduleRuleset.holidaySchedule();
emit modelObjectSelected(mo, true);
} else {
auto* newProfileView = new NewProfileView(schedule, this, NewProfileView::HOLIDAY);
auto* newProfileView = new NewProfileView(scheduleRuleset, this, NewProfileView::HOLIDAY);

m_contentLayout->addWidget(newProfileView, 100);

Expand Down Expand Up @@ -1435,7 +1444,7 @@ DefaultScheduleDayView::DefaultScheduleDayView(bool isIP, const model::ScheduleR

SpecialScheduleDayView::SpecialScheduleDayView(bool isIP, const model::ScheduleRuleset& scheduleRuleset, SchedulesView* schedulesView,
SpecialScheduleDayType type)
: QWidget(schedulesView), m_type(type) {
: QWidget(schedulesView), m_type(type), m_scheduleRuleset(scheduleRuleset) {
// Layout

auto* mainHLayout = new QHBoxLayout();
Expand All @@ -1450,13 +1459,13 @@ SpecialScheduleDayView::SpecialScheduleDayView(bool isIP, const model::ScheduleR

// Name

auto* scheduleRulesetNameWidget = new ScheduleRulesetNameWidget(scheduleRuleset);
auto* scheduleRulesetNameWidget = new ScheduleRulesetNameWidget(m_scheduleRuleset);
mainVLayout->addWidget(scheduleRulesetNameWidget);

// Schedule Day

if (m_type == SUMMER) {
if (!scheduleRuleset.isSummerDesignDayScheduleDefaulted()) {
if (!m_scheduleRuleset.isSummerDesignDayScheduleDefaulted()) {
auto* label = new QLabel("Summer design day profile.");
label->setObjectName("H2");

Expand All @@ -1465,7 +1474,7 @@ SpecialScheduleDayView::SpecialScheduleDayView(bool isIP, const model::ScheduleR
hLayout->addWidget(label);
mainVLayout->addLayout(hLayout);

model::ScheduleDay scheduleDay = scheduleRuleset.summerDesignDaySchedule();
model::ScheduleDay scheduleDay = m_scheduleRuleset.summerDesignDaySchedule();

auto* scheduleDayView = new ScheduleDayView(isIP, scheduleDay, schedulesView);

Expand All @@ -1483,7 +1492,7 @@ SpecialScheduleDayView::SpecialScheduleDayView(bool isIP, const model::ScheduleR
hLayout->addWidget(label);
mainVLayout->addLayout(hLayout);

model::ScheduleDay scheduleDay = scheduleRuleset.winterDesignDaySchedule();
model::ScheduleDay scheduleDay = m_scheduleRuleset.winterDesignDaySchedule();

auto* scheduleDayView = new ScheduleDayView(isIP, scheduleDay, schedulesView);

Expand All @@ -1492,7 +1501,7 @@ SpecialScheduleDayView::SpecialScheduleDayView(bool isIP, const model::ScheduleR
mainVLayout->addWidget(scheduleDayView);
}
} else if (m_type == HOLIDAY) {
if (!scheduleRuleset.isHolidayScheduleDefaulted()) {
if (!m_scheduleRuleset.isHolidayScheduleDefaulted()) {
auto* label = new QLabel("Holiday profile.");
label->setObjectName("H2");

Expand All @@ -1501,7 +1510,7 @@ SpecialScheduleDayView::SpecialScheduleDayView(bool isIP, const model::ScheduleR
hLayout->addWidget(label);
mainVLayout->addLayout(hLayout);

model::ScheduleDay scheduleDay = scheduleRuleset.holidaySchedule();
model::ScheduleDay scheduleDay = m_scheduleRuleset.holidaySchedule();

auto* scheduleDayView = new ScheduleDayView(isIP, scheduleDay, schedulesView);

Expand Down
2 changes: 2 additions & 0 deletions src/openstudio_lib/SchedulesView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,8 @@ class SpecialScheduleDayView : public QWidget

private:
SpecialScheduleDayType m_type;

model::ScheduleRuleset m_scheduleRuleset;
};

// View a schedule rule of a schedule ruleset
Expand Down