Skip to content

Commit 1005c12

Browse files
committed
This is a better approach only update responses if searchString filterType or tid has changed
1 parent 1a36e84 commit 1005c12

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,31 +199,25 @@ std::vector<openstudio::BCLSearchResult> BuildingComponentDialogCentralWidget::f
199199
void BuildingComponentDialogCentralWidget::setTid(const std::string& filterType, int tid, int pageIdx, const QString& title,
200200
const QString& searchString) {
201201

202-
if (m_tid != tid || m_searchString != searchString) {
202+
if (m_tid != tid || m_searchString != searchString || m_filterType != filterType) {
203203
m_collapsibleComponentList->firstPage();
204+
m_allResponses = fetchAndSortResponses(filterType, tid, searchString);
204205
}
205206

207+
m_searchString = searchString;
206208
m_filterType = filterType;
207-
208209
m_tid = tid;
209210

210-
m_searchString = searchString;
211-
212-
//std::vector<Component *> components = m_collapsibleComponentList->components();
211+
// Clear existing components
213212
std::vector<Component*> components = m_componentList->components(); // TODO replace with code above
214-
215213
for (auto& comp : components) {
216214
delete comp;
217215
}
218216

219-
if (pageIdx == 0 || m_allResponses.empty()) {
220-
m_allResponses = fetchAndSortResponses(filterType, tid, searchString);
221-
}
222-
223217
// Paginate responses
224218
int itemsPerPage = 10; // Assuming 10 items per page
225219
size_t startIdx = pageIdx * itemsPerPage;
226-
size_t endIdx = std::min(startIdx + itemsPerPage, static_cast<int>(m_allResponses.size()));
220+
size_t endIdx = std::min(startIdx + itemsPerPage, m_allResponses.size());
227221
std::vector<BCLSearchResult> paginatedResponses(m_allResponses.begin() + startIdx, m_allResponses.begin() + endIdx);
228222

229223
for (const auto& response : paginatedResponses) {

0 commit comments

Comments
 (0)