forked from organicmaps/organicmaps
[qt] Simple search by viewport
This commit is contained in:
parent
5ec4286850
commit
fd4578cea9
6 changed files with 104 additions and 7 deletions
|
@ -1056,4 +1056,30 @@ void FrameWork<TModel>::AddRedrawCommandSure()
|
|||
UpdateNow();
|
||||
}
|
||||
|
||||
class SearchProcessor
|
||||
{
|
||||
string const & m_text;
|
||||
SearchCallbackT & m_callback;
|
||||
|
||||
public:
|
||||
SearchProcessor(string const & textToSearch, SearchCallbackT & callback)
|
||||
: m_text(textToSearch), m_callback(callback) {}
|
||||
bool operator() (FeatureType const & f) const
|
||||
{
|
||||
// @TODO search for all languages
|
||||
string name;
|
||||
f.GetName(name);
|
||||
if (!name.empty() && name.find(m_text) != string::npos)
|
||||
m_callback(name, f.GetLimitRect(16)); //@TODO hardcoded scale
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename TModel>
|
||||
void FrameWork<TModel>::Search(string const & text, SearchCallbackT callback) const
|
||||
{
|
||||
SearchProcessor doClass(text, callback);
|
||||
m_model.ForEachFeature(m_navigator.Screen().GlobalRect(), doClass);
|
||||
}
|
||||
|
||||
template class FrameWork<model::FeaturesFetcher>;
|
||||
|
|
|
@ -51,6 +51,8 @@ class redraw_operation_cancelled {};
|
|||
|
||||
struct BenchmarkRectProvider;
|
||||
|
||||
typedef boost::function<void (string const &, m2::RectD const &)> SearchCallbackT;
|
||||
|
||||
namespace fwork
|
||||
{
|
||||
class DrawProcessor
|
||||
|
@ -218,6 +220,9 @@ public:
|
|||
|
||||
public:
|
||||
|
||||
/// @note Stop search if text is empty
|
||||
void Search(string const & text, SearchCallbackT callback) const;
|
||||
|
||||
void SetMaxWorldRect();
|
||||
void UpdateNow();
|
||||
void Invalidate();
|
||||
|
|
|
@ -271,4 +271,14 @@ namespace qt
|
|||
m_pScale->blockSignals(b);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawWidget::Search(const string & text, SearchCallbackT callback)
|
||||
{
|
||||
m_framework.Search(text, callback);
|
||||
}
|
||||
|
||||
void DrawWidget::ShowFeature(m2::RectD const & rect)
|
||||
{
|
||||
m_framework.ShowRect(rect);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,9 +63,8 @@ namespace qt
|
|||
void OnEnableMyPosition(LocationRetrievedCallbackT observer);
|
||||
void OnDisableMyPosition();
|
||||
|
||||
//model_t * GetModel() { return &(m_framework.get_model()); }
|
||||
|
||||
//void ShowFeature(Feature const & p);
|
||||
void Search(string const & text, SearchCallbackT callback);
|
||||
void ShowFeature(m2::RectD const & rect);
|
||||
|
||||
void SaveState();
|
||||
/// @return false if can't load previously saved values
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <QtGui/QMenuBar>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QHeaderView>
|
||||
|
||||
#define IDM_ABOUT_DIALOG 1001
|
||||
#define IDM_PREFERENCES_DIALOG 1002
|
||||
|
@ -43,7 +44,7 @@ MainWindow::MainWindow()
|
|||
|
||||
CreateNavigationBar();
|
||||
|
||||
CreateSearchBar();
|
||||
CreateSearchBarAndPanel();
|
||||
|
||||
#ifdef DEBUG // code removed for desktop releases
|
||||
CreateClassifPanel();
|
||||
|
@ -344,7 +345,44 @@ void MainWindow::OnSearchShortcutPressed()
|
|||
|
||||
void MainWindow::OnSearchTextChanged(QString const & str)
|
||||
{
|
||||
// clear old results
|
||||
QTableWidget * table = static_cast<QTableWidget *>(m_Docks[3]->widget());
|
||||
table->clear();
|
||||
table->setRowCount(0);
|
||||
m_pDrawWidget->Search(str.toUtf8().constData(),
|
||||
boost::bind(&MainWindow::OnSearchResult, this, _1, _2));
|
||||
}
|
||||
|
||||
void MainWindow::OnSearchResult(string const & name, m2::RectD const & rect)
|
||||
{
|
||||
QTableWidget * table = static_cast<QTableWidget *>(m_Docks[3]->widget());
|
||||
table->insertRow(0);
|
||||
QTableWidgetItem * item = new QTableWidgetItem(QString::fromUtf8(name.c_str()));
|
||||
item->setData(Qt::UserRole, QRectF(QPointF(rect.minX(), rect.maxY()),
|
||||
QPointF(rect.maxX(), rect.minY())));
|
||||
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
table->setItem(0, 0, item);
|
||||
|
||||
if (!m_Docks[3]->isVisible())
|
||||
m_Docks[3]->show();
|
||||
}
|
||||
|
||||
void MainWindow::OnSearchPanelShortcutPressed()
|
||||
{
|
||||
if (m_Docks[3]->isVisible())
|
||||
m_Docks[3]->hide();
|
||||
else
|
||||
m_Docks[3]->show();
|
||||
}
|
||||
|
||||
void MainWindow::OnSearchPanelItemClicked(int row, int)
|
||||
{
|
||||
// center viewport on clicked item
|
||||
QTableWidget * table = static_cast<QTableWidget *>(m_Docks[3]->widget());
|
||||
QRectF rect = table->item(row, 0)->data(Qt::UserRole).toRectF();
|
||||
m2::RectD r2(rect.left(), rect.bottom(), rect.right(), rect.top());
|
||||
r2.Inflate(0.0001, 0.0001);
|
||||
m_pDrawWidget->ShowFeature(r2);
|
||||
}
|
||||
|
||||
void MainWindow::OnPreferences()
|
||||
|
@ -398,7 +436,7 @@ void MainWindow::CreateGuidePanel()
|
|||
}
|
||||
#endif // DEBUG
|
||||
|
||||
void MainWindow::CreateSearchBar()
|
||||
void MainWindow::CreateSearchBarAndPanel()
|
||||
{
|
||||
CreatePanelImpl(2, Qt::TopDockWidgetArea, tr("Search Bar"),
|
||||
QKeySequence(Qt::CTRL + Qt::Key_F), SLOT(OnSearchShortcutPressed()));
|
||||
|
@ -409,6 +447,22 @@ void MainWindow::CreateSearchBar()
|
|||
m_Docks[2]->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
||||
// @TODO remove search bar title
|
||||
m_Docks[2]->setWidget(editor);
|
||||
|
||||
// also create search results panel
|
||||
CreatePanelImpl(3, Qt::LeftDockWidgetArea, tr("Search Results"),
|
||||
QKeySequence(Qt::CTRL + Qt::ShiftModifier + Qt::Key_F),
|
||||
SLOT(OnSearchPanelShortcutPressed()));
|
||||
|
||||
QTableWidget * panel = new QTableWidget(0, 2, m_Docks[3]);
|
||||
panel->setAlternatingRowColors(true);
|
||||
panel->setShowGrid(false);
|
||||
panel->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
panel->verticalHeader()->setVisible(false);
|
||||
panel->horizontalHeader()->setVisible(false);
|
||||
panel->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
|
||||
connect(panel, SIGNAL(cellClicked(int,int)), this, SLOT(OnSearchPanelItemClicked(int,int)));
|
||||
m_Docks[3]->setWidget(panel);
|
||||
}
|
||||
|
||||
void MainWindow::CreatePanelImpl(size_t i, Qt::DockWidgetArea area, QString const & name,
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace qt
|
|||
QAction * m_pSearchAction;
|
||||
DrawWidget * m_pDrawWidget;
|
||||
|
||||
QDockWidget * m_Docks[3];
|
||||
QDockWidget * m_Docks[4];
|
||||
|
||||
#ifdef DEBUG // code removed for desktop releases
|
||||
UpdateDialog * m_updateDialog;
|
||||
|
@ -38,6 +38,7 @@ namespace qt
|
|||
|
||||
private:
|
||||
void OnLocationFound();
|
||||
void OnSearchResult(string const & name, m2::RectD const & rect);
|
||||
|
||||
protected:
|
||||
#ifdef DEBUG // code removed for desktop releases
|
||||
|
@ -48,7 +49,7 @@ namespace qt
|
|||
void CreateGuidePanel();
|
||||
#endif // DEBUG
|
||||
void CreateNavigationBar();
|
||||
void CreateSearchBar();
|
||||
void CreateSearchBarAndPanel();
|
||||
|
||||
#if defined(Q_WS_WIN)
|
||||
/// to handle menu messages
|
||||
|
@ -67,5 +68,7 @@ namespace qt
|
|||
void OnMyPosition();
|
||||
void OnSearchButtonClicked();
|
||||
void OnSearchShortcutPressed();
|
||||
void OnSearchPanelShortcutPressed();
|
||||
void OnSearchPanelItemClicked(int row, int column);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue