Skip to content
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
3 changes: 2 additions & 1 deletion .github/workflows/clangformat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
run: |
echo "GITHUB_REF=$GITHUB_REF GITHUB_BASE_REF=$GITHUB_BASE_REF GITHUB_HEAD_REF=$GITHUB_HEAD_REF"
git fetch --all
./ci/clang-format.sh remotes/origin/$GITHUB_HEAD_REF remotes/origin/$GITHUB_BASE_REF
echo "Using clang-format: $(clang-format --version)"
./ci/clang-format.sh HEAD remotes/origin/$GITHUB_BASE_REF

- name: Upload clang-format patch as artifact
if: ${{ failure() }}
Expand Down
3 changes: 3 additions & 0 deletions src/openstudio_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ set(${target_name}_SRC
OpenStudioAPI.hpp
OSAppBase.cpp
OSAppBase.hpp
OSCategoryPlaceholder.cpp
OSCategoryPlaceholder.hpp
OSCollapsibleItem.cpp
OSCollapsibleItem.hpp
OSCollapsibleItemHeader.cpp
Expand Down Expand Up @@ -571,6 +573,7 @@ set(${target_name}_moc
ModelSubTabController.hpp
ModelSubTabView.hpp
OSAppBase.hpp
OSCategoryPlaceholder.hpp
OSCollapsibleItem.hpp
OSCollapsibleItemHeader.hpp
OSCollapsibleItemList.hpp
Expand Down
122 changes: 106 additions & 16 deletions src/openstudio_lib/MainRightColumnController.cpp

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/openstudio_lib/ModelObjectTypeListView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "ModelObjectItem.hpp"
#include "ModelObjectListView.hpp"
#include "OSCollapsibleItemHeader.hpp"
#include "OSCategoryPlaceholder.hpp"
#include "OSItem.hpp"

#include <openstudio/model/Model.hpp>
Expand Down Expand Up @@ -68,6 +69,12 @@ void ModelObjectTypeListView::addModelObjectType(const IddObjectType& iddObjectT
addCollapsibleItem(modelObjectTypeItem);
}

void ModelObjectTypeListView::addModelObjectCategoryPlaceholder(const std::string& name) {

auto* categoryPlaceholderItem = new OSCategoryPlaceholder(name);
addCategoryPlaceholderItem(categoryPlaceholderItem);
}

IddObjectType ModelObjectTypeListView::currentIddObjectType() const {
OSCollapsibleItem* selectedCollapsibleItem = this->selectedCollapsibleItem();
auto* modelObjectTypeItem = qobject_cast<ModelObjectTypeItem*>(selectedCollapsibleItem);
Expand Down
3 changes: 3 additions & 0 deletions src/openstudio_lib/ModelObjectTypeListView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define OPENSTUDIO_MODELOBJECTTYPELISTVIEW_HPP

#include "OSCollapsibleItemList.hpp"
#include "OSCategoryPlaceholder.hpp"

#include <openstudio/model/Model.hpp>
#include <openstudio/model/ModelObject.hpp>
Expand All @@ -57,6 +58,8 @@ class ModelObjectTypeListView : public OSCollapsibleItemList

void addModelObjectType(const IddObjectType& iddObjectType, const std::string& name);

void addModelObjectCategoryPlaceholder(const std::string& name);

virtual IddObjectType currentIddObjectType() const;

virtual boost::optional<openstudio::model::ModelObject> selectedModelObject() const;
Expand Down
77 changes: 77 additions & 0 deletions src/openstudio_lib/OSCategoryPlaceholder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/***********************************************************************************************************************
* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer.
*
* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the distribution.
*
* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products
* derived from this software without specific prior written permission from the respective party.
*
* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works
* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior
* written permission from Alliance for Sustainable Energy, LLC.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED
* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************************************************************/

#include "OSCategoryPlaceholder.hpp"

#include <openstudio/utilities/core/Assert.hpp>

#include <QBoxLayout>
#include <QLabel>
#include <QPainter>
#include <QStyleOption>

#include <iostream>

namespace openstudio {

OSCategoryPlaceholder::OSCategoryPlaceholder(const std::string& text, QWidget* parent) : QWidget(parent) {
setFixedHeight(40);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
setObjectName("OSCategoryPlaceholder");

this->setProperty("style", "0");
this->setStyleSheet("QWidget#OSCategoryPlaceholder[style=\"0\"] { background-color: #95B3DE; border-bottom: 1px solid black; }");
Comment on lines +48 to +49
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a side note than anything, but I wonder when we should just inline styles versus using the qss stylesheet. @macumber do you have rules for this?

QWidget#NavigatorWidget {
background: #808080;
border-bottom: 1px solid black;
/*
border-right: 1px solid #C0C0C0;
*/
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always torn between trying to write documentation and rules for what exists vs burn it all down and start over. I think it would make the most sense to have all styes in qss files, but that would require a sensible naming hierarchy everywhere. It gets hard when a name changes and the styles don't apply to some tab anymore.


auto* mainHLayout = new QHBoxLayout();
mainHLayout->setContentsMargins(9, 0, 9, 0);
setLayout(mainHLayout);

// Label

m_textLabel = new QLabel(QString::fromStdString(text));
m_textLabel->setWordWrap(true);
m_textLabel->setObjectName("OSCategoryPlaceholderText");
m_textLabel->setStyleSheet("QLabel#OSCategoryPlaceholderText { font-size: 14px; color: white; }");
mainHLayout->addWidget(m_textLabel, 10);

mainHLayout->addStretch();
}

QString OSCategoryPlaceholder::text() const {
return m_textLabel->text();
}

void OSCategoryPlaceholder::paintEvent(QPaintEvent* event) {
QStyleOption opt;
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

} // namespace openstudio
61 changes: 61 additions & 0 deletions src/openstudio_lib/OSCategoryPlaceholder.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/***********************************************************************************************************************
* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer.
*
* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the distribution.
*
* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products
* derived from this software without specific prior written permission from the respective party.
*
* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works
* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior
* written permission from Alliance for Sustainable Energy, LLC.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED
* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************************************************************/

#ifndef OPENSTUDIO_OSCATEGORYPLACEHOLDER_HPP
#define OPENSTUDIO_OSCATEGORYPLACEHOLDER_HPP

#include <QWidget>

class QVBoxLayout;
class QHBoxLayout;
class QLabel;

namespace openstudio {

class OSCategoryPlaceholder : public QWidget
{
Q_OBJECT

public:
explicit OSCategoryPlaceholder(const std::string& text, QWidget* parent = nullptr);

virtual ~OSCategoryPlaceholder() = default;

QString text() const;

protected:
void paintEvent(QPaintEvent* event) override;

private:
QLabel* m_textLabel;
};

} // namespace openstudio

#endif // OPENSTUDIO_OSCATEGORYPLACEHOLDER_HPP
12 changes: 8 additions & 4 deletions src/openstudio_lib/OSCollapsibleItemHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ OSCollapsibleItemHeader::OSCollapsibleItemHeader(const std::string& text, const

// Label

auto* textLabel = new QLabel(QString::fromStdString(text));
textLabel->setWordWrap(true);
textLabel->setObjectName("H2");
mainHLayout->addWidget(textLabel, 10);
m_textLabel = new QLabel(QString::fromStdString(text));
m_textLabel->setWordWrap(true);
m_textLabel->setObjectName("H2");
mainHLayout->addWidget(m_textLabel, 10);

mainHLayout->addStretch();

Expand All @@ -80,6 +80,10 @@ QSize OSCollapsibleItemHeader::sizeHint() const {
return QSize(150, 50);
}

QString OSCollapsibleItemHeader::text() const {
return m_textLabel->text();
}

bool OSCollapsibleItemHeader::expanded() const {
return m_expanded;
}
Expand Down
5 changes: 4 additions & 1 deletion src/openstudio_lib/OSCollapsibleItemHeader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class OSCollapsibleItemHeader : public QWidget
OSCollapsibleItemHeader(const std::string& text, const OSItemId& itemId, OSItemType type = OSItemType::CollapsibleListHeader,
QWidget* parent = nullptr);

virtual ~OSCollapsibleItemHeader() {}
virtual ~OSCollapsibleItemHeader() = default;

QString text() const;

bool expanded() const;
void setExpanded(bool isExpanded);
Expand All @@ -70,6 +72,7 @@ class OSCollapsibleItemHeader : public QWidget
void setImage(bool expanded);

QLabel* m_arrowLabel;
QLabel* m_textLabel;

bool m_expanded;
bool m_selected;
Expand Down
35 changes: 34 additions & 1 deletion src/openstudio_lib/OSCollapsibleItemList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "OSItemList.hpp"
#include "OSCollapsibleItem.hpp"
#include "OSCollapsibleItemHeader.hpp"
#include "OSCategoryPlaceholder.hpp"

#include <openstudio/utilities/core/Assert.hpp>

Expand All @@ -41,6 +42,7 @@
#include <QPushButton>
#include <QResizeEvent>
#include <QScrollArea>
#include <QStringBuilder>
#include <QStyleOption>
#include <QVBoxLayout>

Expand Down Expand Up @@ -167,6 +169,12 @@ void OSCollapsibleItemList::addCollapsibleItem(OSCollapsibleItem* collapsibleIte
connect(collapsibleItem, &OSCollapsibleItem::openLibDlgClicked, this, &OSCollapsibleItemList::openLibDlgClicked);
}

void OSCollapsibleItemList::addCategoryPlaceholderItem(OSCategoryPlaceholder* categoryPlaceholderItem) {

m_placeholderItems.push_back(categoryPlaceholderItem);
m_vLayout->insertWidget(0, categoryPlaceholderItem);
}
Comment on lines +172 to +176
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macumber This makes me realize we have a std::vector<OSCollapsibleItem*> m_collapsibleItems; but our void OSCollapsibleItemList::addCollapsibleItem(OSCollapsibleItem* collapsibleItem) does not add to it... even though other functions loop on it...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah looks like we never add anything to m_collapsibleItems so it's kind of useless.


void OSCollapsibleItemList::onCollapsableItemSelected(OSCollapsibleItem* selectedItem) {
QLayoutItem* layoutItem = nullptr;
OSCollapsibleItem* collapsibleItem = nullptr;
Expand Down Expand Up @@ -239,23 +247,32 @@ void OSCollapsibleItemList::onSearchTextEdited(const QString& text) {
m_searchActive = !text.isEmpty();

OSItem* newSelectedItem = nullptr;
OSCategoryPlaceholder* placeholderItem = nullptr;
QString searchText, categoryText, placeholderText;
for (int i = 0; i < m_vLayout->count(); ++i) {

QLayoutItem* layoutItem = m_vLayout->itemAt(i);
QWidget* widget = layoutItem->widget();

// filter collapsible items
OSCollapsibleItem* collapsibleItem = qobject_cast<OSCollapsibleItem*>(widget);
if (collapsibleItem) {
categoryText = collapsibleItem->collapsibleItemHeader()->text();
std::vector<OSItem*> items = collapsibleItem->itemList()->items();
unsigned numVisible = 0;
for (const auto& item : items) {
if (m_searchActive) {
if (item->text().contains(text, Qt::CaseInsensitive)) {
searchText = item->text() % " " % categoryText % " " % placeholderText;
if (searchText.contains(text, Qt::CaseInsensitive)) {
item->setVisible(true);
if (!newSelectedItem) {
newSelectedItem = item;
collapsibleItem->itemList()->selectItem(newSelectedItem);
}
// show the last category placeholder item
if (placeholderItem) {
placeholderItem->setVisible(true);
}
++numVisible;
} else {
item->setVisible(false);
Expand All @@ -273,6 +290,22 @@ void OSCollapsibleItemList::onSearchTextEdited(const QString& text) {
collapsibleItem->setExpanded(numVisible > 0);
collapsibleItem->setVisible(numVisible > 0);
}
} else {

// filter category placeholder items
placeholderItem = qobject_cast<OSCategoryPlaceholder*>(widget);
if (placeholderItem) {
placeholderText = placeholderItem->text();
if (m_searchActive) {
if (placeholderText.contains(text, Qt::CaseInsensitive)) {
placeholderItem->setVisible(true);
} else {
placeholderItem->setVisible(false);
}
} else {
placeholderItem->setVisible(true);
}
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/openstudio_lib/OSCollapsibleItemList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "OSItemSelector.hpp"
#include "OSItem.hpp"
#include "OSCategoryPlaceholder.hpp"

class QVBoxLayout;
class QHBoxLayout;
Expand All @@ -51,9 +52,10 @@ class OSCollapsibleItemList : public OSItemSelector
public:
explicit OSCollapsibleItemList(bool addScrollArea, QWidget* parent = nullptr);

virtual ~OSCollapsibleItemList() {}
virtual ~OSCollapsibleItemList() = default;

void addCollapsibleItem(OSCollapsibleItem* collapsibleItem);
void addCategoryPlaceholderItem(OSCategoryPlaceholder* categoryPlaceholderItem);

OSCollapsibleItem* selectedCollapsibleItem() const;

Expand Down Expand Up @@ -89,6 +91,7 @@ class OSCollapsibleItemList : public OSItemSelector
QHBoxLayout* m_contentLayout;
OSCollapsibleItem* m_selectedCollapsibleItem;
std::vector<OSCollapsibleItem*> m_collapsibleItems;
std::vector<OSCategoryPlaceholder*> m_placeholderItems;
bool m_searchActive;
bool m_itemsDraggable;
bool m_itemsRemoveable;
Expand Down
Loading