Skip to content

Commit fc925bf

Browse files
committed
Hide borders on cells when deleted, update select all check box when objects are deleted
1 parent ee66ca9 commit fc925bf

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

src/shared_gui_components/OSCellWrapper.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
#include <iostream>
4545
#include <algorithm>
46+
#include <bitset>
4647
#include <map>
4748
#include <set>
4849
#include <string>
@@ -63,13 +64,14 @@ OSCellWrapper::OSCellWrapper(OSGridView* gridView, QSharedPointer<BaseConcept> b
6364
m_layout->setSpacing(0);
6465
m_layout->setVerticalSpacing(0);
6566
m_layout->setHorizontalSpacing(0);
66-
m_layout->setContentsMargins(0, 0, 1, 1);
6767
this->setLayout(m_layout);
6868
this->setAttribute(Qt::WA_StyledBackground);
6969
this->setObjectName("OSCellWrapper");
70-
setStyleSheet("QWidget#OSCellWrapper { border: none; border-right: 1px solid gray; border-bottom: 1px solid gray; }"
71-
"QWidget#OSCellWrapper[header=\"true\"]{ border: none; border-top: 1px solid black; border-right: 1px solid gray; border-bottom: 1px "
70+
setStyleSheet("QWidget#OSCellWrapper[style=\"01\"] { border: none; border-right: 1px solid gray; border-bottom: 1px solid gray; }" // header = false, visible = true
71+
"QWidget#OSCellWrapper[style=\"00\"] { border: none; border-right: none; border-bottom: none; }" // header = false, visible = false
72+
"QWidget#OSCellWrapper[style=\"11\"]{ border: none; border-top: 1px solid black; border-right: 1px solid gray; border-bottom: 1px " // header = true, visible = true
7273
"solid black; }");
74+
updateStyle();
7375

7476
connect(this, &OSCellWrapper::rowNeedsStyle, objectSelector, &OSObjectSelector::onRowNeedsStyle);
7577
}
@@ -175,6 +177,8 @@ void OSCellWrapper::setCellProperties(const GridCellLocation& location, const Gr
175177
for (auto* holder : m_holders) {
176178
holder->setCellProperties(location, info);
177179
}
180+
m_visible = info.isVisible();
181+
updateStyle();
178182
}
179183
}
180184

@@ -570,10 +574,32 @@ void OSCellWrapper::disconnectModelSignals() {
570574
}
571575

572576
void OSCellWrapper::makeHeader() {
573-
m_layout->setContentsMargins(0, 1, 1, 1);
574-
setProperty("header", true);
575-
this->style()->unpolish(this);
576-
this->style()->polish(this);
577+
m_header = true;
578+
m_visible = true;
579+
updateStyle();
580+
}
581+
582+
void OSCellWrapper::updateStyle() {
583+
// Locked, Focused, Defaulted
584+
std::bitset<3> style;
585+
style[0] = m_header;
586+
style[1] = m_visible;
587+
QString thisStyle = QString::fromStdString(style.to_string());
588+
589+
QVariant currentStyle = property("style");
590+
if (currentStyle.isNull() || currentStyle.toString() != thisStyle) {
591+
if (m_header) {
592+
m_layout->setContentsMargins(0, 1, 1, 1);
593+
} else if (m_visible) {
594+
m_layout->setContentsMargins(0, 0, 1, 1);
595+
} else {
596+
m_layout->setContentsMargins(0, 0, 0, 0);
597+
}
598+
599+
this->setProperty("style", thisStyle);
600+
this->style()->unpolish(this);
601+
this->style()->polish(this);
602+
}
577603
}
578604

579605
void OSCellWrapper::onRemoveWorkspaceObject(const WorkspaceObject& object, const openstudio::IddObjectType& iddObjectType,

src/shared_gui_components/OSCellWrapper.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class OSCellWrapper : public QWidget
7575
void connectModelSignals();
7676
void disconnectModelSignals();
7777
void makeHeader();
78+
void updateStyle();
7879

7980
OSGridView* m_gridView;
8081
QGridLayout* m_layout;
@@ -86,6 +87,8 @@ class OSCellWrapper : public QWidget
8687
int m_column = 0;
8788
bool m_hasSubRows = false;
8889
int m_refreshCount = 0;
90+
bool m_header = false;
91+
bool m_visible = true;
8992

9093
// only has these members if not a header cell
9194
boost::optional<model::ModelObject> m_modelObject;

src/shared_gui_components/OSObjectSelector.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,29 @@ void OSObjectSelector::setObjectRemoved(const openstudio::Handle& handle) {
279279
const PropertyChange visible = ChangeToFalse;
280280
const PropertyChange selected = ChangeToFalse;
281281
const PropertyChange locked = ChangeToTrue;
282+
int numSelected = 0;
283+
int numSelectable = 0;
282284
for (auto* const location : m_selectorCellLocations) {
283285
GridCellInfo* info = getGridCellInfo(location);
284-
if ((info != nullptr) && info->modelObject && info->modelObject->handle() == handle) {
286+
if (info == nullptr) {
287+
continue;
288+
}
289+
if (info->modelObject && info->modelObject->handle() == handle) {
285290
if (location->subrow) {
286291
setSubrowProperties(location->gridRow, location->subrow.get(), visible, selected, locked);
287292
} else {
288293
setRowProperties(location->gridRow, visible, selected, locked);
289294
}
295+
} else {
296+
if (info->isSelected()) {
297+
++numSelected;
298+
}
299+
if (info->isSelectable()) {
300+
++numSelectable;
301+
}
290302
}
291303
}
304+
emit gridRowSelectionChanged(numSelected, numSelectable);
292305
}
293306

294307
//bool OSObjectSelector::containsObject(const openstudio::model::ModelObject& t_obj) const {

0 commit comments

Comments
 (0)