|
15 | 15 |
|
16 | 16 | #include <cstddef>
|
17 | 17 | #include <openstudio/measure/OSArgument.hpp>
|
| 18 | + |
18 | 19 | #include <openstudio/utilities/bcl/BCL.hpp>
|
19 | 20 | #include <openstudio/utilities/bcl/LocalBCL.hpp>
|
20 | 21 | #include <openstudio/utilities/bcl/RemoteBCL.hpp>
|
@@ -168,89 +169,53 @@ void BuildingComponentDialogCentralWidget::setTid() {
|
168 | 169 | requestComponents(m_filterType, m_tid, m_pageIdx, m_searchString);
|
169 | 170 | }
|
170 | 171 |
|
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 |
| - |
201 | 172 | // Note: don't call this directly if the "wait" screen is desired
|
202 | 173 | void BuildingComponentDialogCentralWidget::setTid(const std::string& filterType, int tid, int pageIdx, const QString& title,
|
203 | 174 | const QString& searchString) {
|
204 | 175 |
|
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 | + } |
207 | 179 |
|
208 |
| - m_searchString = searchString; |
209 | 180 | m_filterType = filterType;
|
| 181 | + |
210 | 182 | m_tid = tid;
|
211 | 183 |
|
212 |
| - if (newKey != currentKey) { |
213 |
| - m_allResponses = fetchAndSortResponses(filterType, tid, searchString); |
214 |
| - m_collapsibleComponentList->firstPage(); |
215 |
| - pageIdx = 0; |
216 |
| - } |
| 184 | + m_searchString = searchString; |
217 | 185 |
|
218 |
| - // Clear existing components |
| 186 | + //std::vector<Component *> components = m_collapsibleComponentList->components(); |
219 | 187 | std::vector<Component*> components = m_componentList->components(); // TODO replace with code above
|
| 188 | + |
220 | 189 | for (auto& comp : components) {
|
221 | 190 | delete comp;
|
222 | 191 | }
|
223 | 192 |
|
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 | + } |
231 | 201 |
|
232 |
| - for (const auto& response : paginatedResponses) { |
233 |
| - auto* component = new Component(response); |
| 202 | + for (const auto& response : responses) { |
| 203 | + auto* component = new Component(response); |
234 | 204 |
|
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); |
238 | 207 | }
|
239 | 208 |
|
240 | 209 | // the parent taxonomy
|
241 | 210 | m_collapsibleComponentList->setText(title);
|
242 | 211 |
|
243 | 212 | // the total number of results
|
244 |
| - int lastTotalResults = m_allResponses.size(); |
| 213 | + int lastTotalResults = remoteBCL.lastTotalResults(); |
245 | 214 | m_collapsibleComponentList->setNumResults(lastTotalResults);
|
246 | 215 |
|
247 | 216 | // 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); |
254 | 219 |
|
255 | 220 | // make sure the header is expanded
|
256 | 221 | if (m_collapsibleComponentList->checkedCollapsibleComponent()) {
|
|
0 commit comments