Skip to content

Commit 29ebd36

Browse files
committed
I think bug is happening due to
+ // std::sort(responses.begin(), responses.end(), [](const BCLSearchResult& a, const BCLSearchResult& b) { + // return a.name() < b.name(); + // });
1 parent 7b1f59d commit 29ebd36

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,11 @@ std::vector<openstudio::BCLSearchResult> BuildingComponentDialogCentralWidget::f
187187
totalPages = remoteBCL.numResultPages();
188188
} while (++currentPage < totalPages);
189189

190-
// Sort responses alphabetically by name
191-
std::sort(responses.begin(), responses.end(), [](const BCLSearchResult& a, const BCLSearchResult& b) {
192-
return a.name() < b.name();
193-
});
190+
if (!responses.empty()) {
191+
std::sort(responses.begin(), responses.end(), [](const BCLSearchResult& a, const BCLSearchResult& b) {
192+
return a.name() < b.name();
193+
});
194+
}
194195

195196
return responses;
196197
}
@@ -199,8 +200,12 @@ std::vector<openstudio::BCLSearchResult> BuildingComponentDialogCentralWidget::f
199200
void BuildingComponentDialogCentralWidget::setTid(const std::string& filterType, int tid, int pageIdx, const QString& title,
200201
const QString& searchString) {
201202

202-
if (m_tid != tid || m_searchString != searchString || m_filterType != filterType) {
203-
m_collapsibleComponentList->firstPage();
203+
std::string newKey = std::to_string(tid) + filterType + searchString.toStdString();
204+
std::string currentKey = std::to_string(m_tid) + m_filterType + m_searchString.toStdString();
205+
206+
m_collapsibleComponentList->firstPage();
207+
208+
if (newKey != currentKey) {
204209
m_allResponses = fetchAndSortResponses(filterType, tid, searchString);
205210
}
206211

@@ -216,15 +221,18 @@ void BuildingComponentDialogCentralWidget::setTid(const std::string& filterType,
216221

217222
// Paginate responses
218223
int itemsPerPage = 10; // Assuming 10 items per page
219-
size_t startIdx = pageIdx * itemsPerPage;
220-
size_t endIdx = std::min(startIdx + itemsPerPage, m_allResponses.size());
221-
std::vector<BCLSearchResult> paginatedResponses(m_allResponses.begin() + startIdx, m_allResponses.begin() + endIdx);
222-
223-
for (const auto& response : paginatedResponses) {
224-
auto* component = new Component(response);
225-
226-
// TODO replace with a componentList owned by m_collapsibleComponentList
227-
m_componentList->addComponent(component);
224+
225+
if (!m_allResponses.empty()) {
226+
size_t startIdx = pageIdx * itemsPerPage;
227+
size_t endIdx = std::min(startIdx + itemsPerPage, m_allResponses.size());
228+
std::vector<BCLSearchResult> paginatedResponses(m_allResponses.begin() + startIdx, m_allResponses.begin() + endIdx);
229+
230+
for (const auto& response : paginatedResponses) {
231+
auto* component = new Component(response);
232+
233+
// TODO replace with a componentList owned by m_collapsibleComponentList
234+
m_componentList->addComponent(component);
235+
}
228236
}
229237

230238
// the parent taxonomy
@@ -235,8 +243,12 @@ void BuildingComponentDialogCentralWidget::setTid(const std::string& filterType,
235243
m_collapsibleComponentList->setNumResults(lastTotalResults);
236244

237245
// the number of pages of results
238-
int numResultPages = (lastTotalResults / itemsPerPage) + 1;
239-
m_collapsibleComponentList->setNumPages(numResultPages);
246+
if (lastTotalResults == 0) {
247+
m_collapsibleComponentList->setNumPages(0);
248+
} else {
249+
int numResultPages = (lastTotalResults % itemsPerPage == 0) ? (lastTotalResults / itemsPerPage) : (lastTotalResults / itemsPerPage) + 1;
250+
m_collapsibleComponentList->setNumPages(numResultPages);
251+
}
240252

241253
// make sure the header is expanded
242254
if (m_collapsibleComponentList->checkedCollapsibleComponent()) {

0 commit comments

Comments
 (0)