Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/qt
diff options
context:
space:
mode:
authorAlex Zolotarev <alex@maps.me>2016-02-20 22:13:56 +0300
committerSergey Yershov <yershov@corp.mail.ru>2016-03-23 16:50:53 +0300
commit165af3aa5c2339622a01e04ea726e9181474fb52 (patch)
treef80cc9696ebd2145444465aea43bc5a10195bb8a /qt
parent0eddd0e659bffcf98c22a41402d9b2465291d716 (diff)
[qt] Create new feature dialog.
Diffstat (limited to 'qt')
-rw-r--r--qt/create_feature_dialog.cpp45
-rw-r--r--qt/create_feature_dialog.hpp24
-rw-r--r--qt/draw_widget.cpp21
-rw-r--r--qt/draw_widget.hpp2
-rw-r--r--qt/mainwindow.cpp32
-rw-r--r--qt/mainwindow.hpp2
-rw-r--r--qt/qt.pro2
7 files changed, 124 insertions, 4 deletions
diff --git a/qt/create_feature_dialog.cpp b/qt/create_feature_dialog.cpp
new file mode 100644
index 0000000000..258c95bedd
--- /dev/null
+++ b/qt/create_feature_dialog.cpp
@@ -0,0 +1,45 @@
+#include "qt/create_feature_dialog.hpp"
+
+#include "editor/new_feature_categories.hpp"
+
+#include <QtWidgets/QDialogButtonBox>
+#include <QtWidgets/QListWidget>
+#include <QtWidgets/QVBoxLayout>
+
+CreateFeatureDialog::CreateFeatureDialog(QWidget * parent, osm::NewFeatureCategories const & cats)
+ : QDialog(parent)
+{
+ QListWidget * lastUsedList = new QListWidget();
+ for (auto const & cat : cats.m_lastUsed)
+ {
+ QListWidgetItem * lwi = new QListWidgetItem(cat.m_name.c_str(), lastUsedList);
+ lwi->setData(Qt::UserRole, cat.m_type);
+ }
+ connect(lastUsedList, SIGNAL(clicked(QModelIndex const &)), this, SLOT(OnListItemSelected(QModelIndex const &)));
+
+ QListWidget * allSortedList = new QListWidget();
+ for (auto const & cat : cats.m_allSorted)
+ {
+ QListWidgetItem * lwi = new QListWidgetItem(cat.m_name.c_str(), allSortedList);
+ lwi->setData(Qt::UserRole, cat.m_type);
+ }
+ connect(allSortedList, SIGNAL(clicked(QModelIndex const &)), this, SLOT(OnListItemSelected(QModelIndex const &)));
+
+ QVBoxLayout * vBox = new QVBoxLayout();
+ vBox->addWidget(lastUsedList);
+ vBox->addWidget(allSortedList);
+
+ QDialogButtonBox * dbb = new QDialogButtonBox();
+ dbb->addButton(QDialogButtonBox::Close);
+ connect(dbb, SIGNAL(clicked(QAbstractButton*)), this, SLOT(reject()));
+ vBox->addWidget(dbb);
+
+ setLayout(vBox);
+ setWindowTitle("OSM Editor");
+}
+
+void CreateFeatureDialog::OnListItemSelected(QModelIndex const & i)
+{
+ m_selectedType = static_cast<uint32_t>(i.data(Qt::UserRole).toULongLong());
+ accept();
+}
diff --git a/qt/create_feature_dialog.hpp b/qt/create_feature_dialog.hpp
new file mode 100644
index 0000000000..045b5f1502
--- /dev/null
+++ b/qt/create_feature_dialog.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <QtWidgets/QDialog>
+
+class QModelIndex;
+namespace osm
+{
+struct NewFeatureCategories;
+} // namespace osm
+
+class CreateFeatureDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ CreateFeatureDialog(QWidget * parent, osm::NewFeatureCategories const & cats);
+ /// Valid only if dialog has finished with Accepted code.
+ uint32_t GetSelectedType() const { return m_selectedType; }
+
+private slots:
+ void OnListItemSelected(QModelIndex const & i);
+
+private:
+ uint32_t m_selectedType = 0;
+};
diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp
index b0b5be6228..6aafff96c7 100644
--- a/qt/draw_widget.cpp
+++ b/qt/draw_widget.cpp
@@ -1,3 +1,4 @@
+#include "qt/create_feature_dialog.hpp"
#include "qt/draw_widget.hpp"
#include "qt/editor_dialog.hpp"
#include "qt/place_page_dialog.hpp"
@@ -482,6 +483,26 @@ void DrawWidget::ShowSearchResult(search::Result const & res)
m_framework->ShowSearchResult(res);
}
+void DrawWidget::CreateFeature()
+{
+ CreateFeatureDialog dlg(this, m_framework->GetEditorCategories());
+ if (dlg.exec() == QDialog::Accepted)
+ {
+ osm::EditableMapObject emo;
+ if (m_framework->CreateMapObjectAtViewportCenter(dlg.GetSelectedType(), emo))
+ {
+ EditorDialog dlg(this, emo);
+ int const result = dlg.exec();
+ if (result == QDialog::Accepted)
+ m_framework->SaveEditedMapObject(emo);
+ }
+ else
+ {
+ LOG(LWARNING, ("Error creating new map object."));
+ }
+ }
+}
+
void DrawWidget::OnLocationUpdate(location::GpsInfo const & info)
{
if (!m_emulatingLocation)
diff --git a/qt/draw_widget.hpp b/qt/draw_widget.hpp
index dd9628ac1b..4125ffed22 100644
--- a/qt/draw_widget.hpp
+++ b/qt/draw_widget.hpp
@@ -56,6 +56,8 @@ namespace qt
string GetDistance(search::Result const & res) const;
void ShowSearchResult(search::Result const & res);
+ void CreateFeature();
+
void OnLocationUpdate(location::GpsInfo const & info);
void UpdateAfterSettingsChanged();
diff --git a/qt/mainwindow.cpp b/qt/mainwindow.cpp
index 37108e6ead..7a8b3ef1c4 100644
--- a/qt/mainwindow.cpp
+++ b/qt/mainwindow.cpp
@@ -258,14 +258,14 @@ void MainWindow::CreateNavigationBar()
pToolBar->setIconSize(QSize(32, 32));
{
- // add navigation hot keys
- hotkey_t arr[] = {
+ // Add navigation hot keys.
+ hotkey_t const arr[] = {
{ Qt::Key_Equal, SLOT(ScalePlus()) },
{ Qt::Key_Minus, SLOT(ScaleMinus()) },
{ Qt::ALT + Qt::Key_Equal, SLOT(ScalePlusLight()) },
{ Qt::ALT + Qt::Key_Minus, SLOT(ScaleMinusLight()) },
{ Qt::Key_A, SLOT(ShowAll()) },
- { Qt::Key_N, SLOT(ChoosePositionModeEnable()) },
+ // Use CMD+n (New Item hotkey) to activate Create Feature mode.
{ Qt::Key_Escape, SLOT(ChoosePositionModeDisable()) }
};
@@ -279,7 +279,18 @@ void MainWindow::CreateNavigationBar()
}
{
- // add search button with "checked" behavior
+ // TODO(AlexZ): Replace icon.
+ m_pCreateFeatureAction = pToolBar->addAction(QIcon(":/navig64/select.png"),
+ tr("Create Feature"),
+ this,
+ SLOT(OnCreateFeatureClicked()));
+ m_pCreateFeatureAction->setCheckable(true);
+ m_pCreateFeatureAction->setToolTip(tr("Please select position on a map."));
+ m_pCreateFeatureAction->setShortcut(QKeySequence::New);
+
+ pToolBar->addSeparator();
+
+ // Add search button with "checked" behavior.
m_pSearchAction = pToolBar->addAction(QIcon(":/navig64/search.png"),
tr("Search"),
this,
@@ -453,6 +464,19 @@ void MainWindow::OnMyPosition()
m_pDrawWidget->GetFramework().SwitchMyPositionNextMode();
}
+void MainWindow::OnCreateFeatureClicked()
+{
+ if (m_pCreateFeatureAction->isChecked())
+ {
+ m_pDrawWidget->ChoosePositionModeEnable();
+ }
+ else
+ {
+ m_pDrawWidget->ChoosePositionModeDisable();
+ m_pDrawWidget->CreateFeature();
+ }
+}
+
void MainWindow::OnSearchButtonClicked()
{
if (m_pSearchAction->isChecked())
diff --git a/qt/mainwindow.hpp b/qt/mainwindow.hpp
index d7ca013ee7..b08281159b 100644
--- a/qt/mainwindow.hpp
+++ b/qt/mainwindow.hpp
@@ -27,6 +27,7 @@ namespace qt
class MainWindow : public QMainWindow, location::LocationObserver
{
QAction * m_pMyPositionAction;
+ QAction * m_pCreateFeatureAction;
QAction * m_pSearchAction;
DrawWidget * m_pDrawWidget;
@@ -74,6 +75,7 @@ namespace qt
void OnPreferences();
void OnAbout();
void OnMyPosition();
+ void OnCreateFeatureClicked();
void OnSearchButtonClicked();
void OnLoginMenuItem();
void OnUploadEditsMenuItem();
diff --git a/qt/qt.pro b/qt/qt.pro
index 93d11a65e7..c5d8039d20 100644
--- a/qt/qt.pro
+++ b/qt/qt.pro
@@ -100,6 +100,7 @@ macx-* {
SOURCES += \
about.cpp \
+ create_feature_dialog.cpp \
draw_widget.cpp \
editor_dialog.cpp \
info_dialog.cpp \
@@ -117,6 +118,7 @@ SOURCES += \
HEADERS += \
about.hpp \
+ create_feature_dialog.hpp \
draw_widget.hpp \
editor_dialog.hpp \
info_dialog.hpp \