Skip to content

Commit 4fbb3a2

Browse files
authored
Merge pull request #824 from openstudiocoalition/revert_pr_795
Revert changes to BuildingComponentDialogCentralWidget from PR #795
2 parents bdc7665 + 92929d2 commit 4fbb3a2

File tree

2 files changed

+23
-62
lines changed

2 files changed

+23
-62
lines changed

src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp

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

1616
#include <cstddef>
1717
#include <openstudio/measure/OSArgument.hpp>
18+
1819
#include <openstudio/utilities/bcl/BCL.hpp>
1920
#include <openstudio/utilities/bcl/LocalBCL.hpp>
2021
#include <openstudio/utilities/bcl/RemoteBCL.hpp>
@@ -168,89 +169,53 @@ void BuildingComponentDialogCentralWidget::setTid() {
168169
requestComponents(m_filterType, m_tid, m_pageIdx, m_searchString);
169170
}
170171

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

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

208-
m_searchString = searchString;
209180
m_filterType = filterType;
181+
210182
m_tid = tid;
211183

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

218-
// Clear existing components
186+
//std::vector<Component *> components = m_collapsibleComponentList->components();
219187
std::vector<Component*> components = m_componentList->components(); // TODO replace with code above
188+
220189
for (auto& comp : components) {
221190
delete comp;
222191
}
223192

224-
// Paginate responses
225-
int itemsPerPage = 10; // Assuming 10 items per page
226-
227-
if (!m_allResponses.empty()) {
228-
size_t startIdx = pageIdx * itemsPerPage;
229-
size_t endIdx = std::min(startIdx + itemsPerPage, m_allResponses.size());
230-
std::vector<BCLSearchResult> paginatedResponses(m_allResponses.begin() + startIdx, m_allResponses.begin() + endIdx);
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+
}
231201

232-
for (const auto& response : paginatedResponses) {
233-
auto* component = new Component(response);
202+
for (const auto& response : responses) {
203+
auto* component = new Component(response);
234204

235-
// TODO replace with a componentList owned by m_collapsibleComponentList
236-
m_componentList->addComponent(component);
237-
}
205+
// TODO replace with a componentList owned by m_collapsibleComponentList
206+
m_componentList->addComponent(component);
238207
}
239208

240209
// the parent taxonomy
241210
m_collapsibleComponentList->setText(title);
242211

243212
// the total number of results
244-
int lastTotalResults = m_allResponses.size();
213+
int lastTotalResults = remoteBCL.lastTotalResults();
245214
m_collapsibleComponentList->setNumResults(lastTotalResults);
246215

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

255220
// make sure the header is expanded
256221
if (m_collapsibleComponentList->checkedCollapsibleComponent()) {

src/shared_gui_components/BuildingComponentDialogCentralWidget.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
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>
2019

2120
#include "../shared_gui_components/ProgressBarWithError.hpp"
2221

@@ -55,9 +54,6 @@ class BuildingComponentDialogCentralWidget
5554
void setTid();
5655
void componentDownloadComplete(const std::string& uid, const boost::optional<BCLComponent>& component);
5756
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);
6157

6258
int m_tid;
6359
CollapsibleComponentList* m_collapsibleComponentList;

0 commit comments

Comments
 (0)