From 8f3ef0bc9f94cfc87cbc75eb5d46e72266a49a1e Mon Sep 17 00:00:00 2001 From: Sergey Magidovich Date: Wed, 7 Feb 2018 12:49:37 +0300 Subject: [PATCH] [OpenLR] Assessment tool fix. --- .../openlr_assessment_tool/CMakeLists.txt | 4 - .../openlr_assessment_tool/main.cpp | 9 +- .../openlr_assessment_tool/mainwindow.cpp | 11 +- .../openlr_assessment_tool/mainwindow.hpp | 4 +- .../openlr_assessment_tool/web_view.cpp | 141 ------------------ .../openlr_assessment_tool/web_view.hpp | 43 ------ 6 files changed, 6 insertions(+), 206 deletions(-) delete mode 100644 openlr/openlr_match_quality/openlr_assessment_tool/web_view.cpp delete mode 100644 openlr/openlr_match_quality/openlr_assessment_tool/web_view.hpp diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/CMakeLists.txt b/openlr/openlr_match_quality/openlr_assessment_tool/CMakeLists.txt index 358890e139..5d34b62614 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/CMakeLists.txt +++ b/openlr/openlr_match_quality/openlr_assessment_tool/CMakeLists.txt @@ -26,8 +26,6 @@ set( traffic_panel.hpp trafficmodeinitdlg.cpp trafficmodeinitdlg.h - web_view.cpp - web_view.hpp ) omim_add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${SRC}) @@ -79,8 +77,6 @@ omim_link_libraries( link_opengl(${PROJECT_NAME}) link_qt5_core(${PROJECT_NAME}) -link_qt5_network(${PROJECT_NAME}) -link_qt5_webengine(${PROJECT_NAME}) if (PLATFORM_MAC) set_target_properties( diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/main.cpp b/openlr/openlr_match_quality/openlr_assessment_tool/main.cpp index 3dfaa29997..0ea1edeb00 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/main.cpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/main.cpp @@ -14,9 +14,6 @@ namespace { DEFINE_string(resources_path, "", "Path to resources directory"); DEFINE_string(data_path, "", "Path to data directory"); -DEFINE_string(login, "", "Login string"); -DEFINE_string(password, "", "Password string"); -DEFINE_string(url, "", "Url to a partner map"); bool ValidateStringFlag(char const * flagName, std::string const & val) { @@ -30,10 +27,6 @@ bool ValidateStringFlag(char const * flagName, std::string const & val) int main(int argc, char * argv[]) { - ::google::RegisterFlagValidator(&FLAGS_login, &ValidateStringFlag); - ::google::RegisterFlagValidator(&FLAGS_password, &ValidateStringFlag); - ::google::RegisterFlagValidator(&FLAGS_url, &ValidateStringFlag); - google::SetUsageMessage("Visualize and check matched routes."); google::ParseCommandLineFlags(&argc, &argv, true); @@ -50,7 +43,7 @@ int main(int argc, char * argv[]) params.m_enableLocalAds = false; Framework framework(params); - MainWindow mainWindow(framework, FLAGS_url, FLAGS_login, FLAGS_password); + MainWindow mainWindow(framework); mainWindow.showMaximized(); diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp b/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp index f71a108f36..e27da7c1a6 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp @@ -5,7 +5,6 @@ #include "openlr/openlr_match_quality/openlr_assessment_tool/traffic_drawer_delegate_base.hpp" #include "openlr/openlr_match_quality/openlr_assessment_tool/traffic_panel.hpp" #include "openlr/openlr_match_quality/openlr_assessment_tool/trafficmodeinitdlg.h" -#include "openlr/openlr_match_quality/openlr_assessment_tool/web_view.hpp" #include "map/framework.hpp" @@ -21,6 +20,8 @@ #include "geometry/mercator.hpp" #include "geometry/point2d.hpp" +#include +#include #include #include #include @@ -237,18 +238,14 @@ private: namespace openlr { -MainWindow::MainWindow(Framework & framework, std::string const & url, std::string const & login, - std::string const & password) +MainWindow::MainWindow(Framework & framework) : m_framework(framework) { m_mapWidget = new MapWidget( m_framework, false /* apiOpenGLES3 */, this /* parent */ ); - m_webView = new WebView(url, login, password); - m_layout = new QHBoxLayout(); - m_layout->addWidget(m_webView); m_layout->addWidget(m_mapWidget); auto * window = new QWidget(); @@ -323,7 +320,7 @@ void MainWindow::CreateTrafficPanel(string const & dataFilePath) connect(m_trafficMode, &TrafficMode::EditingStopped, this, &MainWindow::OnPathEditingStop); connect(m_trafficMode, &TrafficMode::SegmentSelected, - m_webView, &WebView::SetCurrentSegment); + [](int segmentId) { QApplication::clipboard()->setText(QString::number(segmentId)); }); m_docWidget = new QDockWidget(tr("Routes"), this); addDockWidget(Qt::DockWidgetArea::RightDockWidgetArea, m_docWidget); diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.hpp b/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.hpp index 2777fd6f6c..c2108e3963 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.hpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.hpp @@ -32,8 +32,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - MainWindow(Framework & framework, std::string const & url, std::string const & login, - std::string const & paswd); + explicit MainWindow(Framework & framework); private: void CreateTrafficPanel(std::string const & dataFilePath); @@ -59,6 +58,5 @@ private: openlr::MapWidget * m_mapWidget = nullptr; QHBoxLayout * m_layout = nullptr; - openlr::WebView * m_webView = nullptr; }; } // namespace openlr diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/web_view.cpp b/openlr/openlr_match_quality/openlr_assessment_tool/web_view.cpp deleted file mode 100644 index fdb64b6350..0000000000 --- a/openlr/openlr_match_quality/openlr_assessment_tool/web_view.cpp +++ /dev/null @@ -1,141 +0,0 @@ -#include "openlr/openlr_match_quality/openlr_assessment_tool/web_view.hpp" - -#include "base/assert.hpp" -#include "base/logging.hpp" - -#include -#include -#include -#include -#include - -namespace -{ -bool IsLoginUrl(QString const & url) -{ - return url.contains("Login"); -} -} // namespace - -namespace openlr -{ -WebView::WebView(std::string const & url, std::string const & login, std::string const & password) - : QWebEngineView(nullptr), m_loadProgress(0), m_url(url), m_login(login), m_password(password) -{ - connect(this, &QWebEngineView::loadProgress, [this](int progress) { m_loadProgress = progress; }); - connect(this, &QWebEngineView::loadFinished, [this](bool success) { - if (!success) - { - m_loadProgress = 0; - } - }); - - connect(this, &QWebEngineView::renderProcessTerminated, - [this](QWebEnginePage::RenderProcessTerminationStatus termStatus, int statusCode) { - QString status; - switch (termStatus) - { - case QWebEnginePage::NormalTerminationStatus: - status = "Render process normal exit"; - break; - case QWebEnginePage::AbnormalTerminationStatus: - status = "Render process abnormal exit"; - break; - case QWebEnginePage::CrashedTerminationStatus: - status = "Render process crashed"; - break; - case QWebEnginePage::KilledTerminationStatus: - status = "Render process killed"; - break; - } - QMessageBox::StandardButton btn = - QMessageBox::question(window(), status, - tr("Render process exited with code: %1\n" - "Do you want to reload the page ?") - .arg(statusCode)); - if (btn == QMessageBox::Yes) - QTimer::singleShot(0, [this] { reload(); }); - }); - - connect(this, &QWebEngineView::loadFinished, this, &WebView::OnLoadFinished); - load(QString(m_url.data())); -} - -int WebView::loadProgress() const { return m_loadProgress; } - -void WebView::SetCurrentSegment(int segmentId) -{ - m_requestedSegmentId = segmentId; - LOG(LDEBUG, ("SegmentID seg to", segmentId)); - if (!IsLoginUrl(url().toString())) - GoToSegment(); -} - -bool WebView::isWebActionEnabled(QWebEnginePage::WebAction webAction) const -{ - return page()->action(webAction)->isEnabled(); -} - -QWebEngineView * WebView::createWindow(QWebEnginePage::WebWindowType type) -{ - CHECK(false, ("We are not going to use but one window.")); - return nullptr; -} - -void WebView::contextMenuEvent(QContextMenuEvent * event) -{ - CHECK(false, ("No context menu is necessary.")); -} - -void WebView::OnLoadFinished(bool ok) -{ - if (!ok) - { - LOG(LDEBUG, ("Page is not loaded properly, giving up")); - return; - } - - if (IsLoginUrl(url().toString())) - Login(); - else - GoToSegment(); -} - -void WebView::GoToSegment() -{ - CHECK(!IsLoginUrl(url().toString()), ("Can't go to a segment on the login page.")); - if (m_requestedSegmentId == kInvalidId) - return; - - auto const script = QString(R"EOT( - function s(ctx, arg) { return ctx.querySelector(arg); } - function uncheck(cb) { if (cb.checked) cb.click(); } - uncheck(s(document, "#inrix\\:filters\\:traffic\\:trafficflowvisible")); - uncheck(s(document, "#inrix\\:filters\\:traffic\\:incidentsvisible")); - var navSpan = s(document, "#inrix\\:navigation\\:contextual"); - var input = s(navSpan, "input.FreeFormInput"); - input.value = %1; - input.classList.remove("WaterMark"); - s(navSpan, "button.LocationSearchButton").click(); - )EOT").arg(m_requestedSegmentId); - - page()->runJavaScript(script, [](QVariant const & v) { - LOG(LDEBUG, ("DEMO JS is done:", v.toString().toStdString())); - }); - m_requestedSegmentId = kInvalidId; -} - -void WebView::Login() -{ - auto const script = QString(R"EOT( - function select(arg) { return document.querySelector(arg); } - select("#ctl00_BodyPlaceHolder_LoginControl_UserName").value = "%1"; - select("#ctl00_BodyPlaceHolder_LoginControl_Password").value = "%2"; - select("#ctl00_BodyPlaceHolder_LoginControl_LoginButton").click(); - )EOT").arg(m_login.data()).arg(m_password.data()); - - page()->runJavaScript(script, [](QVariant const & v) { - LOG(LDEBUG, ("Login JS is done:", v.toString().toStdString())); - }); -} -} // namespace openlr diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/web_view.hpp b/openlr/openlr_match_quality/openlr_assessment_tool/web_view.hpp deleted file mode 100644 index 2f0a95f66b..0000000000 --- a/openlr/openlr_match_quality/openlr_assessment_tool/web_view.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include - -namespace openlr -{ -class WebView : public QWebEngineView -{ - Q_OBJECT - - int static constexpr kInvalidId = -1; - -public: - WebView(std::string const & url, std::string const & login, std::string const & paswd); - - int loadProgress() const; - bool isWebActionEnabled(QWebEnginePage::WebAction webAction) const; - -public slots: - void SetCurrentSegment(int segmentId); - -signals: - void webActionEnabledChanged(QWebEnginePage::WebAction webAction, bool enabled); - -protected: - void contextMenuEvent(QContextMenuEvent * event) override; - QWebEngineView * createWindow(QWebEnginePage::WebWindowType type) override; - -private slots: - void OnLoadFinished(bool ok); - -private: - void GoToSegment(); - void Login(); - - int m_loadProgress; - int m_requestedSegmentId = kInvalidId; - - std::string m_url; - std::string m_login; - std::string m_password; -}; -} // namespace openlr