diff --git a/map/viewport_search_callback.cpp b/map/viewport_search_callback.cpp index a2f9314fec..3952a87c11 100644 --- a/map/viewport_search_callback.cpp +++ b/map/viewport_search_callback.cpp @@ -45,6 +45,9 @@ void ViewportSearchCallback::operator()(Results const & results) if (delegate.IsViewportSearchActive() && (results.IsEndedNormal() || (!results.IsEndMarker() && results.GetCount() != 0))) { + /// @todo This code relies on fact that results order is *NOT* changing with every new batch. + /// I can't say for sure is it true or not, but very optimistic :) + /// Much easier to clear previous marks and make new ones. delegate.ShowViewportSearchResults(results.begin() + lastResultsSize, results.end(), firstCall); } diff --git a/qt/search_panel.cpp b/qt/search_panel.cpp index 42716da7d4..ef71e95a64 100644 --- a/qt/search_panel.cpp +++ b/qt/search_panel.cpp @@ -94,11 +94,16 @@ QTableWidgetItem * CreateItem(QString const & s) } } // namespace -void SearchPanel::ClearResults() +void SearchPanel::ClearTable() { m_pTable->clear(); m_pTable->setRowCount(0); - m_results.clear(); +} + +void SearchPanel::ClearResults() +{ + ClearTable(); + m_results.Clear(); m_pDrawWidget->GetFramework().GetBookmarkManager().GetEditSession().ClearGroup(UserMark::Type::SEARCH); } @@ -120,18 +125,16 @@ void SearchPanel::StopBusyIndicator() void SearchPanel::OnEverywhereSearchResults(uint64_t timestamp, search::Results results) { CHECK(m_threadChecker.CalledOnOriginalThread(), ()); - CHECK_LESS_OR_EQUAL(timestamp, m_timestamp, ()); + CHECK_LESS_OR_EQUAL(timestamp, m_timestamp, ()); if (timestamp != m_timestamp) return; - CHECK_LESS_OR_EQUAL(m_results.size(), results.GetCount(), ()); + m_results = std::move(results); + ClearTable(); - auto const sizeBeforeUpdate = m_results.size(); - - for (size_t i = m_results.size(); i < results.GetCount(); ++i) + for (auto const & res : m_results) { - auto & res = results[i]; QString const name = QString::fromStdString(res.GetString()); QString strHigh; int pos = 0; @@ -158,14 +161,11 @@ void SearchPanel::OnEverywhereSearchResults(uint64_t timestamp, search::Results m_pTable->setItem(rowCount, 0, CreateItem(QString::fromStdString(readableType))); m_pTable->setItem(rowCount, 3, CreateItem(m_pDrawWidget->GetDistance(res).c_str())); } - - m_results.push_back(std::move(res)); } - m_pDrawWidget->GetFramework().FillSearchResultsMarks(m_results.begin() + sizeBeforeUpdate, - m_results.end(), false /* clear */); + m_pDrawWidget->GetFramework().FillSearchResultsMarks(true /* clear */, m_results); - if (results.IsEndMarker()) + if (m_results.IsEndMarker()) StopBusyIndicator(); } @@ -308,7 +308,7 @@ void SearchPanel::RunSearch() void SearchPanel::OnSearchPanelItemClicked(int row, int) { - ASSERT_EQUAL(m_results.size(), static_cast(m_pTable->rowCount()), ()); + ASSERT_EQUAL(m_results.GetCount(), static_cast(m_pTable->rowCount()), ()); if (m_results[row].IsSuggest()) { diff --git a/qt/search_panel.hpp b/qt/search_panel.hpp index 9025e1f442..41aaa6907d 100644 --- a/qt/search_panel.hpp +++ b/qt/search_panel.hpp @@ -33,7 +33,7 @@ class SearchPanel : public QWidget QIcon m_clearIcon; QPixmap m_busyIcon; - std::vector m_results; + search::Results m_results; search::Mode m_mode; uint64_t m_timestamp; @@ -51,6 +51,7 @@ private: virtual void hideEvent(QHideEvent *); void RunSearch(); + void ClearTable(); void ClearResults(); void StartBusyIndicator(); diff --git a/search/search_quality/assessment_tool/main_model.cpp b/search/search_quality/assessment_tool/main_model.cpp index 0d456f71e5..53e877a00f 100644 --- a/search/search_quality/assessment_tool/main_model.cpp +++ b/search/search_quality/assessment_tool/main_model.cpp @@ -1,8 +1,8 @@ -#include "search/search_quality/assessment_tool/main_model.hpp" +#include "main_model.hpp" +#include "view.hpp" #include "search/feature_loader.hpp" #include "search/search_params.hpp" -#include "search/search_quality/assessment_tool/view.hpp" #include "search/search_quality/helpers.hpp" #include "search/search_quality/matcher.hpp" @@ -11,16 +11,12 @@ #include "geometry/algorithm.hpp" #include "geometry/mercator.hpp" -#include "coding/string_utf8_multilang.hpp" - #include "platform/platform.hpp" #include "base/assert.hpp" -#include "base/logging.hpp" #include #include -#include #include using namespace std; @@ -135,7 +131,6 @@ void MainModel::OnSampleSelected(int index) m_view->ShowSample(index, sample, sample.m_pos, context.IsUseless(), context.HasChanges()); m_runner.ResetForegroundSearch(); - m_numShownResults = 0; if (context.m_initialized) { @@ -331,9 +326,7 @@ void MainModel::UpdateViewOnResults(search::Results const & results) { CHECK(m_threadChecker.CalledOnOriginalThread(), ()); - CHECK_LESS_OR_EQUAL(m_numShownResults, results.GetCount(), ()); - m_view->AddFoundResults(results.begin() + m_numShownResults, results.end()); - m_numShownResults = results.GetCount(); + m_view->AddFoundResults(results); if (!results.IsEndedNormal()) return; diff --git a/search/search_quality/assessment_tool/main_model.hpp b/search/search_quality/assessment_tool/main_model.hpp index ba0b8a9ea5..257aaf8c34 100644 --- a/search/search_quality/assessment_tool/main_model.hpp +++ b/search/search_quality/assessment_tool/main_model.hpp @@ -1,21 +1,14 @@ #pragma once +#include "context.hpp" +#include "edits.hpp" +#include "model.hpp" +#include "search_request_runner.hpp" +#include "view.hpp" -#include "search/engine.hpp" #include "search/feature_loader.hpp" -#include "search/search_quality/assessment_tool/context.hpp" -#include "search/search_quality/assessment_tool/edits.hpp" -#include "search/search_quality/assessment_tool/model.hpp" -#include "search/search_quality/assessment_tool/search_request_runner.hpp" -#include "search/search_quality/assessment_tool/view.hpp" -#include "search/search_quality/sample.hpp" #include "base/thread_checker.hpp" -#include -#include -#include -#include - class Framework; class DataSource; @@ -73,7 +66,6 @@ private: std::string m_path; int m_selectedSample = kInvalidIndex; - size_t m_numShownResults = 0; SearchRequestRunner m_runner; diff --git a/search/search_quality/assessment_tool/main_view.cpp b/search/search_quality/assessment_tool/main_view.cpp index ae55abb9d1..b5ca183c8b 100644 --- a/search/search_quality/assessment_tool/main_view.cpp +++ b/search/search_quality/assessment_tool/main_view.cpp @@ -1,11 +1,11 @@ -#include "search/search_quality/assessment_tool/main_view.hpp" +#include "main_view.hpp" -#include "search/search_quality/assessment_tool/feature_info_dialog.hpp" -#include "search/search_quality/assessment_tool/helpers.hpp" -#include "search/search_quality/assessment_tool/model.hpp" -#include "search/search_quality/assessment_tool/results_view.hpp" -#include "search/search_quality/assessment_tool/sample_view.hpp" -#include "search/search_quality/assessment_tool/samples_view.hpp" +#include "feature_info_dialog.hpp" +#include "helpers.hpp" +#include "model.hpp" +#include "results_view.hpp" +#include "sample_view.hpp" +#include "samples_view.hpp" #include "qt/qt_common/map_widget.hpp" #include "qt/qt_common/scale_slider.hpp" @@ -13,8 +13,6 @@ #include "map/framework.hpp" #include "map/place_page_info.hpp" -#include "indexer/feature_algo.hpp" - #include "geometry/mercator.hpp" #include "base/assert.hpp" @@ -127,9 +125,9 @@ void MainView::ShowSample(size_t sampleIndex, search::Sample const & sample, OnSampleChanged(sampleIndex, isUseless, hasEdits); } -void MainView::AddFoundResults(search::Results::ConstIter begin, search::Results::ConstIter end) +void MainView::AddFoundResults(search::Results const & results) { - m_sampleView->AddFoundResults(begin, end); + m_sampleView->AddFoundResults(results); } void MainView::ShowNonFoundResults(std::vector const & results, @@ -140,26 +138,11 @@ void MainView::ShowNonFoundResults(std::vector const & r void MainView::ShowMarks(Context const & context) { - ClearSearchResultMarks(); - ShowFoundResultsMarks(context.m_foundResults.begin(), context.m_foundResults.end()); - ShowNonFoundResultsMarks(context.m_nonFoundResults, context.m_nonFoundResultsEdits.GetEntries()); + m_sampleView->ClearSearchResultMarks(); + m_sampleView->ShowFoundResultsMarks(context.m_foundResults); + m_sampleView->ShowNonFoundResultsMarks(context.m_nonFoundResults, context.m_nonFoundResultsEdits.GetEntries()); } -void MainView::ShowFoundResultsMarks(search::Results::ConstIter begin, - search::Results::ConstIter end) - -{ - m_sampleView->ShowFoundResultsMarks(begin, end); -} - -void MainView::ShowNonFoundResultsMarks(std::vector const & results, - std::vector const & entries) -{ - m_sampleView->ShowNonFoundResultsMarks(results, entries); -} - -void MainView::ClearSearchResultMarks() { m_sampleView->ClearSearchResultMarks(); } - void MainView::MoveViewportToResult(search::Result const & result) { m_skipFeatureInfoDialog = true; @@ -543,7 +526,7 @@ void MainView::AddSelectedFeature(QPoint const & p) QDockWidget * MainView::CreateDock(QWidget & widget) { auto * dock = new QDockWidget(QString(), this /* parent */, Qt::Widget); - dock->setFeatures(QDockWidget::DockWidgetClosable | + dock->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); dock->setWidget(&widget); diff --git a/search/search_quality/assessment_tool/main_view.hpp b/search/search_quality/assessment_tool/main_view.hpp index 6b3109ea71..93a5ff885a 100644 --- a/search/search_quality/assessment_tool/main_view.hpp +++ b/search/search_quality/assessment_tool/main_view.hpp @@ -1,6 +1,5 @@ #pragma once - -#include "search/search_quality/assessment_tool/view.hpp" +#include "view.hpp" #include "indexer/feature_decl.hpp" @@ -36,16 +35,11 @@ public: std::optional const & position, bool isUseless, bool hasEdits) override; - void AddFoundResults(search::Results::ConstIter begin, search::Results::ConstIter end) override; + void AddFoundResults(search::Results const & results) override; void ShowNonFoundResults(std::vector const & results, std::vector const & entries) override; void ShowMarks(Context const & context) override; - void ShowFoundResultsMarks(search::Results::ConstIter begin, - search::Results::ConstIter end) override; - void ShowNonFoundResultsMarks(std::vector const & results, - std::vector const & entries) override; - void ClearSearchResultMarks() override; void MoveViewportToResult(search::Result const & result) override; void MoveViewportToResult(search::Sample::Result const & result) override; diff --git a/search/search_quality/assessment_tool/sample_view.cpp b/search/search_quality/assessment_tool/sample_view.cpp index 77cbd9fc71..3b676c0285 100644 --- a/search/search_quality/assessment_tool/sample_view.cpp +++ b/search/search_quality/assessment_tool/sample_view.cpp @@ -1,6 +1,9 @@ -#include "search/search_quality/assessment_tool/sample_view.hpp" +#include "sample_view.hpp" + +#include "helpers.hpp" +#include "result_view.hpp" +#include "results_view.hpp" -#include "qt/qt_common/helpers.hpp" #include "qt/qt_common/spinner.hpp" #include "map/bookmark_manager.hpp" @@ -8,13 +11,8 @@ #include "map/search_mark.hpp" #include "search/result.hpp" -#include "search/search_quality/assessment_tool/helpers.hpp" -#include "search/search_quality/assessment_tool/result_view.hpp" -#include "search/search_quality/assessment_tool/results_view.hpp" #include "search/search_quality/sample.hpp" -#include "platform/location.hpp" - #include #include #include @@ -242,10 +240,11 @@ void SampleView::OnSearchCompleted() m_markAllAsIrrelevant->setEnabled(resultsAvailable); } -void SampleView::AddFoundResults(SearchResultsIterT begin, SearchResultsIterT end) +void SampleView::AddFoundResults(search::Results const & results) { - for (auto it = begin; it != end; ++it) - m_foundResults->Add(*it /* result */); + /// @todo Should clear previous m_foundResults. + for (auto const & res : results) + m_foundResults->Add(res); } void SampleView::ShowNonFoundResults(std::vector const & results, @@ -266,9 +265,10 @@ void SampleView::ShowNonFoundResults(std::vector const & m_nonFoundResultsBox->show(); } -void SampleView::ShowFoundResultsMarks(SearchResultsIterT begin, SearchResultsIterT end) +void SampleView::ShowFoundResultsMarks(search::Results const & results) { - m_framework.FillSearchResultsMarks(begin, end, false); + /// @todo Should clear previous _found_ results marks, but keep _nonfound_ if any. + m_framework.FillSearchResultsMarks(false /* clear */, results); } void SampleView::ShowNonFoundResultsMarks(std::vector const & results, diff --git a/search/search_quality/assessment_tool/sample_view.hpp b/search/search_quality/assessment_tool/sample_view.hpp index 9219214a74..4231ab74ac 100644 --- a/search/search_quality/assessment_tool/sample_view.hpp +++ b/search/search_quality/assessment_tool/sample_view.hpp @@ -1,7 +1,7 @@ #pragma once +#include "edits.hpp" #include "search/result.hpp" -#include "search/search_quality/assessment_tool/edits.hpp" #include "search/search_quality/sample.hpp" #include "geometry/point2d.hpp" @@ -33,12 +33,11 @@ public: void OnSearchStarted(); void OnSearchCompleted(); - using SearchResultsIterT = search::Results::ConstIter; - void AddFoundResults(SearchResultsIterT begin, SearchResultsIterT end); + void AddFoundResults(search::Results const & results); void ShowNonFoundResults(std::vector const & results, std::vector const & entries); - void ShowFoundResultsMarks(SearchResultsIterT begin, SearchResultsIterT end); + void ShowFoundResultsMarks(search::Results const & results); void ShowNonFoundResultsMarks(std::vector const & results, std::vector const & entries); void ClearSearchResultMarks(); diff --git a/search/search_quality/assessment_tool/view.hpp b/search/search_quality/assessment_tool/view.hpp index 1ef35e1085..8e19e3bd12 100644 --- a/search/search_quality/assessment_tool/view.hpp +++ b/search/search_quality/assessment_tool/view.hpp @@ -1,8 +1,8 @@ #pragma once +#include "context.hpp" +#include "edits.hpp" #include "search/result.hpp" -#include "search/search_quality/assessment_tool/context.hpp" -#include "search/search_quality/assessment_tool/edits.hpp" #include "search/search_quality/sample.hpp" #include "geometry/point2d.hpp" @@ -36,17 +36,11 @@ public: std::optional const & position, bool isUseless, bool hasEdits) = 0; - virtual void AddFoundResults(search::Results::ConstIter begin, - search::Results::ConstIter end) = 0; + virtual void AddFoundResults(search::Results const & results) = 0; virtual void ShowNonFoundResults(std::vector const & results, std::vector const & entries) = 0; virtual void ShowMarks(Context const & context) = 0; - virtual void ShowFoundResultsMarks(search::Results::ConstIter begin, - search::Results::ConstIter end) = 0; - virtual void ShowNonFoundResultsMarks(std::vector const & results, - std::vector const & entries) = 0; - virtual void ClearSearchResultMarks() = 0; virtual void MoveViewportToResult(search::Result const & result) = 0; virtual void MoveViewportToResult(search::Sample::Result const & result) = 0;