-
Notifications
You must be signed in to change notification settings - Fork 26
Implement support for further grouping by category in Library (HVAC, Schedules, etc) #713
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
Changes from all commits
05425ad
88e8188
fbdc742
9036955
a47618b
77df6a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| 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; }"); | ||
|
|
||
| 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 | ||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| #include "OSItemList.hpp" | ||
| #include "OSCollapsibleItem.hpp" | ||
| #include "OSCollapsibleItemHeader.hpp" | ||
| #include "OSCategoryPlaceholder.hpp" | ||
|
|
||
| #include <openstudio/utilities/core/Assert.hpp> | ||
|
|
||
|
|
@@ -41,6 +42,7 @@ | |
| #include <QPushButton> | ||
| #include <QResizeEvent> | ||
| #include <QScrollArea> | ||
| #include <QStringBuilder> | ||
| #include <QStyleOption> | ||
| #include <QVBoxLayout> | ||
|
|
||
|
|
@@ -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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @macumber This makes me realize we have a
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, yeah looks like we never add anything to |
||
|
|
||
| void OSCollapsibleItemList::onCollapsableItemSelected(OSCollapsibleItem* selectedItem) { | ||
| QLayoutItem* layoutItem = nullptr; | ||
| OSCollapsibleItem* collapsibleItem = nullptr; | ||
|
|
@@ -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); | ||
|
|
@@ -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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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?
OpenStudioApplication/src/openstudio_lib/openstudiolib.qss
Lines 989 to 995 in a9b492b
There was a problem hiding this comment.
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.