@@ -187,10 +187,11 @@ std::vector<openstudio::BCLSearchResult> BuildingComponentDialogCentralWidget::f
187
187
totalPages = remoteBCL.numResultPages ();
188
188
} while (++currentPage < totalPages);
189
189
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
+ }
194
195
195
196
return responses;
196
197
}
@@ -199,8 +200,12 @@ std::vector<openstudio::BCLSearchResult> BuildingComponentDialogCentralWidget::f
199
200
void BuildingComponentDialogCentralWidget::setTid (const std::string& filterType, int tid, int pageIdx, const QString& title,
200
201
const QString& searchString) {
201
202
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) {
204
209
m_allResponses = fetchAndSortResponses (filterType, tid, searchString);
205
210
}
206
211
@@ -216,15 +221,18 @@ void BuildingComponentDialogCentralWidget::setTid(const std::string& filterType,
216
221
217
222
// Paginate responses
218
223
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
+ }
228
236
}
229
237
230
238
// the parent taxonomy
@@ -235,8 +243,12 @@ void BuildingComponentDialogCentralWidget::setTid(const std::string& filterType,
235
243
m_collapsibleComponentList->setNumResults (lastTotalResults);
236
244
237
245
// 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
+ }
240
252
241
253
// make sure the header is expanded
242
254
if (m_collapsibleComponentList->checkedCollapsibleComponent ()) {
0 commit comments