Skip to content

Commit b49c5de

Browse files
authored
Merge pull request #795 from openstudiocoalition/dev/anton/166
Issue #166 - Sort measures alphabetically in GUI
2 parents 33cc729 + 0d0a373 commit b49c5de

17 files changed

+95
-55
lines changed

src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include <cstddef>
1717
#include <openstudio/measure/OSArgument.hpp>
18-
1918
#include <openstudio/utilities/bcl/BCL.hpp>
2019
#include <openstudio/utilities/bcl/LocalBCL.hpp>
2120
#include <openstudio/utilities/bcl/RemoteBCL.hpp>
@@ -169,53 +168,90 @@ void BuildingComponentDialogCentralWidget::setTid() {
169168
requestComponents(m_filterType, m_tid, m_pageIdx, m_searchString);
170169
}
171170

171+
std::vector<openstudio::BCLSearchResult> BuildingComponentDialogCentralWidget::fetchAndSortResponses(const std::string& filterType, int tid, const QString& searchString) {
172+
m_allResponses.clear();
173+
174+
RemoteBCL remoteBCL;
175+
remoteBCL.setTimeOutSeconds(m_timeoutSeconds);
176+
177+
std::vector<BCLSearchResult> responses;
178+
int totalPages = 1;
179+
int currentPage = 0;
180+
181+
// Collect all responses from all pages
182+
do {
183+
std::vector<BCLSearchResult> pageResponses;
184+
if (filterType == "components") {
185+
pageResponses = remoteBCL.searchComponentLibrary(searchString.toStdString(), tid, currentPage);
186+
} else if (filterType == "measures") {
187+
pageResponses = remoteBCL.searchMeasureLibrary(searchString.toStdString(), tid, currentPage);
188+
}
189+
responses.insert(responses.end(), pageResponses.begin(), pageResponses.end());
190+
totalPages = remoteBCL.numResultPages();
191+
} while (++currentPage < totalPages);
192+
193+
if (!responses.empty()) {
194+
std::sort(responses.begin(), responses.end(), [](const BCLSearchResult& a, const BCLSearchResult& b) {
195+
return a.name() < b.name();
196+
});
197+
}
198+
199+
return responses;
200+
}
201+
172202
// Note: don't call this directly if the "wait" screen is desired
173203
void BuildingComponentDialogCentralWidget::setTid(const std::string& filterType, int tid, int pageIdx, const QString& title,
174204
const QString& searchString) {
175205

176-
if (m_tid != tid || m_searchString != searchString) {
177-
m_collapsibleComponentList->firstPage();
178-
}
206+
std::string newKey = std::to_string(tid) + filterType + searchString.toStdString();
207+
std::string currentKey = std::to_string(m_tid) + m_filterType + m_searchString.toStdString();
179208

209+
m_searchString = searchString;
180210
m_filterType = filterType;
181-
182211
m_tid = tid;
183212

184-
m_searchString = searchString;
213+
if (newKey != currentKey) {
214+
m_allResponses = fetchAndSortResponses(filterType, tid, searchString);
215+
m_collapsibleComponentList->firstPage();
216+
pageIdx = 0;
217+
}
185218

186-
//std::vector<Component *> components = m_collapsibleComponentList->components();
219+
// Clear existing components
187220
std::vector<Component*> components = m_componentList->components(); // TODO replace with code above
188-
189221
for (auto& comp : components) {
190222
delete comp;
191223
}
192224

193-
RemoteBCL remoteBCL;
194-
remoteBCL.setTimeOutSeconds(m_timeoutSeconds);
195-
std::vector<BCLSearchResult> responses;
196-
if (filterType == "components") {
197-
responses = remoteBCL.searchComponentLibrary(searchString.toStdString(), tid, pageIdx);
198-
} else if (filterType == "measures") {
199-
responses = remoteBCL.searchMeasureLibrary(searchString.toStdString(), tid, pageIdx);
200-
}
201-
202-
for (const auto& response : responses) {
203-
auto* component = new Component(response);
204-
205-
// TODO replace with a componentList owned by m_collapsibleComponentList
206-
m_componentList->addComponent(component);
225+
// Paginate responses
226+
int itemsPerPage = 10; // Assuming 10 items per page
227+
228+
if (!m_allResponses.empty()) {
229+
size_t startIdx = pageIdx * itemsPerPage;
230+
size_t endIdx = std::min(startIdx + itemsPerPage, m_allResponses.size());
231+
std::vector<BCLSearchResult> paginatedResponses(m_allResponses.begin() + startIdx, m_allResponses.begin() + endIdx);
232+
233+
for (const auto& response : paginatedResponses) {
234+
auto* component = new Component(response);
235+
236+
// TODO replace with a componentList owned by m_collapsibleComponentList
237+
m_componentList->addComponent(component);
238+
}
207239
}
208240

209241
// the parent taxonomy
210242
m_collapsibleComponentList->setText(title);
211243

212244
// the total number of results
213-
int lastTotalResults = remoteBCL.lastTotalResults();
245+
int lastTotalResults = m_allResponses.size();
214246
m_collapsibleComponentList->setNumResults(lastTotalResults);
215247

216248
// the number of pages of results
217-
int numResultPages = remoteBCL.numResultPages();
218-
m_collapsibleComponentList->setNumPages(numResultPages);
249+
if (lastTotalResults == 0) {
250+
m_collapsibleComponentList->setNumPages(0);
251+
} else {
252+
int numResultPages = (lastTotalResults % itemsPerPage == 0) ? (lastTotalResults / itemsPerPage) : (lastTotalResults / itemsPerPage) + 1;
253+
m_collapsibleComponentList->setNumPages(numResultPages);
254+
}
219255

220256
// make sure the header is expanded
221257
if (m_collapsibleComponentList->checkedCollapsibleComponent()) {

src/shared_gui_components/BuildingComponentDialogCentralWidget.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <openstudio/nano/nano_signal_slot.hpp> // Signal-Slot replacement
1717
#include <openstudio/utilities/bcl/BCLComponent.hpp>
1818
#include <openstudio/utilities/bcl/BCLMeasure.hpp>
19+
#include <openstudio/utilities/bcl/BCL.hpp>
1920

2021
#include "../shared_gui_components/ProgressBarWithError.hpp"
2122

@@ -54,6 +55,9 @@ class BuildingComponentDialogCentralWidget
5455
void setTid();
5556
void componentDownloadComplete(const std::string& uid, const boost::optional<BCLComponent>& component);
5657
void measureDownloadComplete(const std::string& uid, const boost::optional<BCLMeasure>& measure);
58+
std::vector<openstudio::BCLSearchResult> m_allResponses;
59+
60+
std::vector<openstudio::BCLSearchResult> fetchAndSortResponses(const std::string& filterType, int tid, const QString& searchString);
5761

5862
int m_tid;
5963
CollapsibleComponentList* m_collapsibleComponentList;

src/shared_gui_components/Component.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Component::Component(const BCLMeasure& bclMeasure, bool showAbridgedView, bool s
5454
setCheckBoxEnabled(false);
5555
m_updateAvailable = false;
5656
if (m_msg) {
57-
m_msg->setText("This measure requires a newer version of OpenStudio");
57+
m_msg->setText("This measure is not compatible with the current version of OpenStudio");
5858
m_msg->setVisible(true);
5959
}
6060
}
@@ -131,7 +131,7 @@ Component::Component(const BCLSearchResult& bclSearchResult, bool showAbridgedVi
131131
setCheckBoxEnabled(false);
132132
m_updateAvailable = false;
133133
if (m_msg) {
134-
m_msg->setText("This measure requires a newer version of OpenStudio");
134+
m_msg->setText("This measure is not compatible with the current version of OpenStudio");
135135
m_msg->setVisible(true);
136136
}
137137
}

translations/OpenStudioApp_ar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,12 +727,12 @@ If you would like to see the OpenStudioApplication translated in your language o
727727
<context>
728728
<name>openstudio::MainWindow</name>
729729
<message>
730-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
730+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
731731
<source>Allow Analytics</source>
732732
<translation type="unfinished"></translation>
733733
</message>
734734
<message>
735-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
735+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
736736
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
737737
<translation type="unfinished"></translation>
738738
</message>

translations/OpenStudioApp_ca.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,12 +819,12 @@ Si voleu que OpeStudioApplication estigui a la vostra llengua, esperem la vostra
819819
<translation type="obsolete">S&apos;ha de reiniciar</translation>
820820
</message>
821821
<message>
822-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
822+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
823823
<source>Allow Analytics</source>
824824
<translation type="unfinished"></translation>
825825
</message>
826826
<message>
827-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
827+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
828828
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
829829
<translation type="unfinished"></translation>
830830
</message>

translations/OpenStudioApp_de.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,12 +827,12 @@ Wenn Sie möchten, dass die OpenStudio-Applikation in die Sprache Ihrer Wahl üb
827827
<translation type="obsolete">Neustart erforderlich</translation>
828828
</message>
829829
<message>
830-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
830+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
831831
<source>Allow Analytics</source>
832832
<translation type="unfinished"></translation>
833833
</message>
834834
<message>
835-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
835+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
836836
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
837837
<translation type="unfinished"></translation>
838838
</message>

translations/OpenStudioApp_el.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,12 +817,12 @@ If you would like to see the OpenStudioApplication translated in your language o
817817
<translation type="obsolete">Απαιτείται επανεκκίνηση</translation>
818818
</message>
819819
<message>
820-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
820+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
821821
<source>Allow Analytics</source>
822822
<translation type="unfinished"></translation>
823823
</message>
824824
<message>
825-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
825+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
826826
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
827827
<translation type="unfinished"></translation>
828828
</message>

translations/OpenStudioApp_es.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,12 +818,12 @@ Si le gustaría ver la AplicaciónOpenStudio traducido a algun otro lenguaje, le
818818
<translation type="obsolete">Se requiere reiniciar</translation>
819819
</message>
820820
<message>
821-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
821+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
822822
<source>Allow Analytics</source>
823823
<translation type="unfinished"></translation>
824824
</message>
825825
<message>
826-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
826+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
827827
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
828828
<translation type="unfinished"></translation>
829829
</message>

translations/OpenStudioApp_fa.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,12 +817,12 @@ If you would like to see the OpenStudioApplication translated in your language o
817817
<translation type="obsolete">راه اندازی مجدد لازم است</translation>
818818
</message>
819819
<message>
820-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
820+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
821821
<source>Allow Analytics</source>
822822
<translation type="unfinished"></translation>
823823
</message>
824824
<message>
825-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
825+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
826826
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
827827
<translation type="unfinished"></translation>
828828
</message>

translations/OpenStudioApp_fr.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,12 +817,12 @@ Si vous voulez voir l&apos;Application OpenStudio traduite dans la langue de vot
817817
<translation type="obsolete">Redémarrage requis</translation>
818818
</message>
819819
<message>
820-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
820+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
821821
<source>Allow Analytics</source>
822822
<translation type="unfinished"></translation>
823823
</message>
824824
<message>
825-
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
825+
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
826826
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
827827
<translation type="unfinished"></translation>
828828
</message>

0 commit comments

Comments
 (0)