Skip to content

Commit

Permalink
#612 - Proof of concept
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed May 23, 2024
1 parent cb44b69 commit fea6097
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/openstudio_lib/SpacesSpacesGridView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
// used on column headers, and other grid widgets

#define NAME "Space Name"
#define DISPLAYNAME "Display Name"
#define CADOBJECTID "CAD Object ID"
#define SELECTED "All"

// GENERAL
Expand Down Expand Up @@ -158,7 +160,7 @@ void SpacesSpacesGridController::onCategorySelected(int index) {

void SpacesSpacesGridController::addColumns(const QString& category, std::vector<QString>& fields) {
// always show name and selected columns
fields.insert(fields.begin(), {NAME, SELECTED});
fields.insert(fields.begin(), {NAME, SELECTED, DISPLAYNAME, CADOBJECTID});

resetBaseConcepts();

Expand All @@ -167,6 +169,20 @@ void SpacesSpacesGridController::addColumns(const QString& category, std::vector
if (field == NAME) {
addParentNameLineEditColumn(Heading(QString(NAME), false, false), false, CastNullAdapter<model::Space>(&model::Space::name),
CastNullAdapter<model::Space>(&model::Space::setName));
} else if (field == DISPLAYNAME) {
addNameLineEditColumn(Heading(QString(DISPLAYNAME), false, true), // heading
false, // isInspectable
false, // isLocked
DisplayNameAdapter<model::Space>(&model::Space::displayName), // getter
DisplayNameAdapter<model::Space>(&model::Space::setDisplayName) // setter
);
} else if (field == CADOBJECTID) {
addNameLineEditColumn(Heading(QString(CADOBJECTID), false, true), // heading
false, // isInspectable
false, // isLocked
DisplayNameAdapter<model::Space>(&model::Space::cadObjectId), // getter
DisplayNameAdapter<model::Space>(&model::Space::setCADObjectId) // setter
);
} else if (field == SELECTED) {
auto checkbox = QSharedPointer<OSSelectAllCheckBox>(new OSSelectAllCheckBox());
checkbox->setToolTip("Check to select all rows");
Expand Down
18 changes: 18 additions & 0 deletions src/shared_gui_components/OSConcepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,24 @@ std::function<RetType(FromDataType*, Param1)> ProxyAdapter(RetType (ToDataType::
return std::bind(&OneParamProxy<RetType, FromDataType, Param1, ToDataType>, std::placeholders::_1, std::placeholders::_2, outter, inner);
}

// Getter: discards the bool parameter it usually expects for IdfObject::name(bool returnDefault)
template <typename DataType>
std::function<boost::optional<std::string>(DataType*, bool)> DisplayNameAdapter(boost::optional<std::string> (DataType::*t_func)() const) {
return std::function<boost::optional<std::string>(DataType*, bool)>([t_func](DataType* obj, bool) { return (obj->*t_func)(); });
}

// Setter: changes a bool setDisplayName(const std::string& displayName) to `optional<string> setDisplayName(const std::string&)`
template <typename DataType>
std::function<boost::optional<std::string>(DataType*, const std::string&)> DisplayNameAdapter(bool (DataType::*t_func)(const std::string&)) {
return std::function<boost::optional<std::string>(DataType*, const std::string&)>([t_func](DataType* obj, std::string p1) {
bool result = (obj->*t_func)(p1);
if (result) {
return boost::optional<std::string>{p1};
}
return boost::optional<std::string>{};
});
}

class ConceptProxy
{
public:
Expand Down

0 comments on commit fea6097

Please sign in to comment.