diff --git a/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp b/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp index ade6236e9..8f161f1b2 100644 --- a/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp +++ b/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp @@ -15,7 +15,6 @@ #include #include - #include #include #include @@ -169,53 +168,90 @@ void BuildingComponentDialogCentralWidget::setTid() { requestComponents(m_filterType, m_tid, m_pageIdx, m_searchString); } +std::vector BuildingComponentDialogCentralWidget::fetchAndSortResponses(const std::string& filterType, int tid, const QString& searchString) { + m_allResponses.clear(); + + RemoteBCL remoteBCL; + remoteBCL.setTimeOutSeconds(m_timeoutSeconds); + + std::vector responses; + int totalPages = 1; + int currentPage = 0; + + // Collect all responses from all pages + do { + std::vector pageResponses; + if (filterType == "components") { + pageResponses = remoteBCL.searchComponentLibrary(searchString.toStdString(), tid, currentPage); + } else if (filterType == "measures") { + pageResponses = remoteBCL.searchMeasureLibrary(searchString.toStdString(), tid, currentPage); + } + responses.insert(responses.end(), pageResponses.begin(), pageResponses.end()); + totalPages = remoteBCL.numResultPages(); + } while (++currentPage < totalPages); + + if (!responses.empty()) { + std::sort(responses.begin(), responses.end(), [](const BCLSearchResult& a, const BCLSearchResult& b) { + return a.name() < b.name(); + }); + } + + return responses; +} + // Note: don't call this directly if the "wait" screen is desired void BuildingComponentDialogCentralWidget::setTid(const std::string& filterType, int tid, int pageIdx, const QString& title, const QString& searchString) { - if (m_tid != tid || m_searchString != searchString) { - m_collapsibleComponentList->firstPage(); - } + std::string newKey = std::to_string(tid) + filterType + searchString.toStdString(); + std::string currentKey = std::to_string(m_tid) + m_filterType + m_searchString.toStdString(); + m_searchString = searchString; m_filterType = filterType; - m_tid = tid; - m_searchString = searchString; + if (newKey != currentKey) { + m_allResponses = fetchAndSortResponses(filterType, tid, searchString); + m_collapsibleComponentList->firstPage(); + pageIdx = 0; + } - //std::vector components = m_collapsibleComponentList->components(); + // Clear existing components std::vector components = m_componentList->components(); // TODO replace with code above - for (auto& comp : components) { delete comp; } - RemoteBCL remoteBCL; - remoteBCL.setTimeOutSeconds(m_timeoutSeconds); - std::vector responses; - if (filterType == "components") { - responses = remoteBCL.searchComponentLibrary(searchString.toStdString(), tid, pageIdx); - } else if (filterType == "measures") { - responses = remoteBCL.searchMeasureLibrary(searchString.toStdString(), tid, pageIdx); - } - - for (const auto& response : responses) { - auto* component = new Component(response); - - // TODO replace with a componentList owned by m_collapsibleComponentList - m_componentList->addComponent(component); + // Paginate responses + int itemsPerPage = 10; // Assuming 10 items per page + + if (!m_allResponses.empty()) { + size_t startIdx = pageIdx * itemsPerPage; + size_t endIdx = std::min(startIdx + itemsPerPage, m_allResponses.size()); + std::vector paginatedResponses(m_allResponses.begin() + startIdx, m_allResponses.begin() + endIdx); + + for (const auto& response : paginatedResponses) { + auto* component = new Component(response); + + // TODO replace with a componentList owned by m_collapsibleComponentList + m_componentList->addComponent(component); + } } // the parent taxonomy m_collapsibleComponentList->setText(title); // the total number of results - int lastTotalResults = remoteBCL.lastTotalResults(); + int lastTotalResults = m_allResponses.size(); m_collapsibleComponentList->setNumResults(lastTotalResults); // the number of pages of results - int numResultPages = remoteBCL.numResultPages(); - m_collapsibleComponentList->setNumPages(numResultPages); + if (lastTotalResults == 0) { + m_collapsibleComponentList->setNumPages(0); + } else { + int numResultPages = (lastTotalResults % itemsPerPage == 0) ? (lastTotalResults / itemsPerPage) : (lastTotalResults / itemsPerPage) + 1; + m_collapsibleComponentList->setNumPages(numResultPages); + } // make sure the header is expanded if (m_collapsibleComponentList->checkedCollapsibleComponent()) { diff --git a/src/shared_gui_components/BuildingComponentDialogCentralWidget.hpp b/src/shared_gui_components/BuildingComponentDialogCentralWidget.hpp index b1e1cc2d5..10728ea57 100644 --- a/src/shared_gui_components/BuildingComponentDialogCentralWidget.hpp +++ b/src/shared_gui_components/BuildingComponentDialogCentralWidget.hpp @@ -16,6 +16,7 @@ #include // Signal-Slot replacement #include #include +#include #include "../shared_gui_components/ProgressBarWithError.hpp" @@ -54,6 +55,9 @@ class BuildingComponentDialogCentralWidget void setTid(); void componentDownloadComplete(const std::string& uid, const boost::optional& component); void measureDownloadComplete(const std::string& uid, const boost::optional& measure); + std::vector m_allResponses; + + std::vector fetchAndSortResponses(const std::string& filterType, int tid, const QString& searchString); int m_tid; CollapsibleComponentList* m_collapsibleComponentList; diff --git a/src/shared_gui_components/Component.cpp b/src/shared_gui_components/Component.cpp index 40c2dc07f..a97bc061f 100644 --- a/src/shared_gui_components/Component.cpp +++ b/src/shared_gui_components/Component.cpp @@ -54,7 +54,7 @@ Component::Component(const BCLMeasure& bclMeasure, bool showAbridgedView, bool s setCheckBoxEnabled(false); m_updateAvailable = false; if (m_msg) { - m_msg->setText("This measure requires a newer version of OpenStudio"); + m_msg->setText("This measure is not compatible with the current version of OpenStudio"); m_msg->setVisible(true); } } @@ -131,7 +131,7 @@ Component::Component(const BCLSearchResult& bclSearchResult, bool showAbridgedVi setCheckBoxEnabled(false); m_updateAvailable = false; if (m_msg) { - m_msg->setText("This measure requires a newer version of OpenStudio"); + m_msg->setText("This measure is not compatible with the current version of OpenStudio"); m_msg->setVisible(true); } } diff --git a/translations/OpenStudioApp_ar.ts b/translations/OpenStudioApp_ar.ts index a03391ce0..4bbab43f8 100644 --- a/translations/OpenStudioApp_ar.ts +++ b/translations/OpenStudioApp_ar.ts @@ -727,12 +727,12 @@ If you would like to see the OpenStudioApplication translated in your language o openstudio::MainWindow - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information. diff --git a/translations/OpenStudioApp_ca.ts b/translations/OpenStudioApp_ca.ts index 1545b9a8c..e6f710738 100644 --- a/translations/OpenStudioApp_ca.ts +++ b/translations/OpenStudioApp_ca.ts @@ -819,12 +819,12 @@ Si voleu que OpeStudioApplication estigui a la vostra llengua, esperem la vostra S'ha de reiniciar - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information. diff --git a/translations/OpenStudioApp_de.ts b/translations/OpenStudioApp_de.ts index c51824188..4a2bf5952 100644 --- a/translations/OpenStudioApp_de.ts +++ b/translations/OpenStudioApp_de.ts @@ -827,12 +827,12 @@ Wenn Sie möchten, dass die OpenStudio-Applikation in die Sprache Ihrer Wahl üb Neustart erforderlich - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information. diff --git a/translations/OpenStudioApp_el.ts b/translations/OpenStudioApp_el.ts index 870fe8458..8acdc4eeb 100644 --- a/translations/OpenStudioApp_el.ts +++ b/translations/OpenStudioApp_el.ts @@ -817,12 +817,12 @@ If you would like to see the OpenStudioApplication translated in your language o Απαιτείται επανεκκίνηση - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information. diff --git a/translations/OpenStudioApp_es.ts b/translations/OpenStudioApp_es.ts index ea27702bf..3ca40c79a 100644 --- a/translations/OpenStudioApp_es.ts +++ b/translations/OpenStudioApp_es.ts @@ -818,12 +818,12 @@ Si le gustaría ver la AplicaciónOpenStudio traducido a algun otro lenguaje, le Se requiere reiniciar - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information. diff --git a/translations/OpenStudioApp_fa.ts b/translations/OpenStudioApp_fa.ts index a64abe4c7..5ffbe55dc 100644 --- a/translations/OpenStudioApp_fa.ts +++ b/translations/OpenStudioApp_fa.ts @@ -817,12 +817,12 @@ If you would like to see the OpenStudioApplication translated in your language o راه اندازی مجدد لازم است - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information. diff --git a/translations/OpenStudioApp_fr.ts b/translations/OpenStudioApp_fr.ts index 6dcb7d70a..20109389a 100644 --- a/translations/OpenStudioApp_fr.ts +++ b/translations/OpenStudioApp_fr.ts @@ -817,12 +817,12 @@ Si vous voulez voir l'Application OpenStudio traduite dans la langue de vot Redémarrage requis - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information. diff --git a/translations/OpenStudioApp_he.ts b/translations/OpenStudioApp_he.ts index c11d9e0de..db0b23c60 100644 --- a/translations/OpenStudioApp_he.ts +++ b/translations/OpenStudioApp_he.ts @@ -815,12 +815,12 @@ If you would like to see the OpenStudioApplication translated in your language o אתחול נדרש - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information. diff --git a/translations/OpenStudioApp_hi.ts b/translations/OpenStudioApp_hi.ts index 6e3077677..564674de8 100644 --- a/translations/OpenStudioApp_hi.ts +++ b/translations/OpenStudioApp_hi.ts @@ -818,12 +818,12 @@ If you would like to see the OpenStudioApplication translated in your language o पुनरारंभ करना आवश्यक है - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information. diff --git a/translations/OpenStudioApp_it.ts b/translations/OpenStudioApp_it.ts index 5fa20a3d0..2a4a55c28 100644 --- a/translations/OpenStudioApp_it.ts +++ b/translations/OpenStudioApp_it.ts @@ -819,12 +819,12 @@ Se vuoi vedere OpenStudioApplication tradotto nel tuo linguaggio preferito, appr Riavvio Richiesto - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information. diff --git a/translations/OpenStudioApp_ja.ts b/translations/OpenStudioApp_ja.ts index 218f363b9..62290d82a 100644 --- a/translations/OpenStudioApp_ja.ts +++ b/translations/OpenStudioApp_ja.ts @@ -818,12 +818,12 @@ If you would like to see the OpenStudioApplication translated in your language o 再起動してください - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information. diff --git a/translations/OpenStudioApp_pl.ts b/translations/OpenStudioApp_pl.ts index 8d496100d..4a37222ea 100644 --- a/translations/OpenStudioApp_pl.ts +++ b/translations/OpenStudioApp_pl.ts @@ -818,12 +818,12 @@ Jeśli chcesz zobaczyć aplikację OpenStudio przetłumaczoną na wybrany przez Wymagane jest ponowne uruchomienie - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information. diff --git a/translations/OpenStudioApp_vi.ts b/translations/OpenStudioApp_vi.ts index d1c2e9dd2..98abd4f77 100644 --- a/translations/OpenStudioApp_vi.ts +++ b/translations/OpenStudioApp_vi.ts @@ -815,12 +815,12 @@ Nếu bạn muốn thấy OpenStudioApplication được dịch sang ngôn ngữ Cần khởi động lại - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information. diff --git a/translations/OpenStudioApp_zh_CN.ts b/translations/OpenStudioApp_zh_CN.ts index b3562fb92..ed1e9d4a5 100644 --- a/translations/OpenStudioApp_zh_CN.ts +++ b/translations/OpenStudioApp_zh_CN.ts @@ -818,12 +818,12 @@ If you would like to see the OpenStudioApplication translated in your language o 要求重启 - + Allow Analytics - + Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the <a href="https://openstudiocoalition.org/about/privacy_policy/">privacy policy</a> for more information.