Code review.

This commit is contained in:
Sergey Magidovich 2017-10-02 14:50:51 +03:00 committed by Yuri Gorshenin
parent 498435dbc6
commit dfb2f263c2
18 changed files with 104 additions and 38 deletions

View file

@ -47,6 +47,7 @@ void FeatureIdFromXML(pugi::xml_node const & node, Index const & index, FeatureI
THROW_IF_NODE_IS_EMPTY(node, openlr::DecodedPathLoadError, ("Can't parse CountryName"));
auto const countryName = node.child("CountryName").text().as_string();
fid.m_mwmId = index.GetMwmIdByCountryFile(platform::CountryFile(countryName));
CHECK(fid.m_mwmId.IsAlive(), ("Can't get mwm id for country", countryName));
fid.m_index = node.child("Index").text().as_uint();
}

View file

@ -4,14 +4,18 @@
#include "3party/gflags/src/gflags/gflags.h"
#include <cstdio>
#include <QApplication>
using namespace openlr;
namespace
{
DEFINE_string(resources_path, "", "Path to resources directory");
DEFINE_string(data_path, "", "Path to data directory");
DEFINE_string(login, "", "Login string");
DEFINE_string(paswd, "", "Password string");
DEFINE_string(password, "", "Password string");
DEFINE_string(url, "", "Url to a partner map");
bool ValidateStringFlag(char const * flagName, std::string const & val)
@ -19,7 +23,7 @@ bool ValidateStringFlag(char const * flagName, std::string const & val)
if (!val.empty())
return true;
LOG(LERROR, (flagName, "cannot be empty. Please specify a proper", flagName));
fprintf(stderr, "%1$s cannot be empty. Please specify a proper %1$s\n", flagName);
return false;
}
} // namespace
@ -27,7 +31,7 @@ bool ValidateStringFlag(char const * flagName, std::string const & val)
int main(int argc, char * argv[])
{
::google::RegisterFlagValidator(&FLAGS_login, &ValidateStringFlag);
::google::RegisterFlagValidator(&FLAGS_paswd, &ValidateStringFlag);
::google::RegisterFlagValidator(&FLAGS_password, &ValidateStringFlag);
::google::RegisterFlagValidator(&FLAGS_url, &ValidateStringFlag);
google::SetUsageMessage("Visualize and check matched routes.");
@ -46,7 +50,7 @@ int main(int argc, char * argv[])
params.m_enableLocalAds = false;
Framework framework(params);
MainWindow mainWindow(framework, FLAGS_url, FLAGS_login, FLAGS_paswd);
MainWindow mainWindow(framework, FLAGS_url, FLAGS_login, FLAGS_password);
mainWindow.showMaximized();

View file

@ -35,6 +35,8 @@
#include <cstring>
#include <vector>
using namespace openlr;
namespace
{
class TrafficDrawerDelegate : public TrafficDrawerDelegateBase
@ -233,16 +235,17 @@ private:
};
} // namespace
namespace openlr
{
MainWindow::MainWindow(Framework & framework, std::string const & url, std::string const & login,
std::string const & paswd)
std::string const & password)
: m_framework(framework)
{
m_mapWidget = new MapWidget(
m_framework, false /* apiOpenGLES3 */, this /* parent */
);
m_webView = new WebView(url, login, paswd);
m_webView = new WebView(url, login, password);
m_layout = new QHBoxLayout();
m_layout->addWidget(m_webView);
@ -401,3 +404,4 @@ void MainWindow::OnPathEditingStop()
m_cancelPathAction->setEnabled(false /* enabled */);
m_cancelPathAction->setEnabled(false /* enabled */);
}
} // namespace openlr

View file

@ -9,10 +9,14 @@
#include <QMainWindow>
class Framework;
class MapWidget;
class QHBoxLayout;
namespace openlr
{
class MapWidget;
class TrafficMode;
class WebView;
}
namespace df
{
@ -21,6 +25,8 @@ class DrapeApi;
class QDockWidget;
namespace openlr
{
class MainWindow : public QMainWindow
{
Q_OBJECT
@ -40,7 +46,7 @@ private:
Framework & m_framework;
TrafficMode * m_trafficMode = nullptr;
openlr::TrafficMode * m_trafficMode = nullptr;
QDockWidget * m_docWidget = nullptr;
QAction * m_saveTrafficSampleAction = nullptr;
@ -50,7 +56,8 @@ private:
QAction * m_cancelPathAction = nullptr;
QAction * m_ignorePathAction = nullptr;
MapWidget * m_mapWidget = nullptr;
openlr::MapWidget * m_mapWidget = nullptr;
QHBoxLayout * m_layout = nullptr;
WebView * m_webView = nullptr;
openlr::WebView * m_webView = nullptr;
};
} // namespace openlr

View file

@ -4,6 +4,8 @@
#include <QMouseEvent>
namespace openlr
{
MapWidget::MapWidget(Framework & framework, bool apiOpenGLES3, QWidget * parent)
: Base(framework, apiOpenGLES3, parent)
{
@ -19,3 +21,4 @@ void MapWidget::mousePressEvent(QMouseEvent * e)
emit TrafficMarkupClick(m_framework.PtoG(pt), e->button());
}
}
} // namespace openlr

View file

@ -9,6 +9,8 @@ class PointsController;
class Framework;
namespace openlr
{
class MapWidget : public qt::common::MapWidget
{
Q_OBJECT
@ -41,3 +43,4 @@ protected:
private:
Mode m_mode = Mode::Normal;
};
} // namespace openlr

View file

@ -4,8 +4,11 @@
#include "geometry/point2d.hpp"
#include <cstddef>
#include <vector>
namespace openlr
{
using FeaturePoint = std::pair<FeatureID, size_t>;
/// This class is responsible for collecting junction points and
@ -25,9 +28,11 @@ public:
/// point index in the feature.
virtual std::pair<std::vector<FeaturePoint>, m2::PointD> GetCandidatePoints(
m2::PointD const & p) const = 0;
// Returns all points that are one step reachable from |p|.
virtual std::vector<m2::PointD> GetReachablePoints(m2::PointD const & p) const = 0;
virtual ClickType CheckClick(m2::PointD const & clickPoint,
m2::PointD const & lastClickedPoint,
std::vector<m2::PointD> const & reachablePoints) const = 0;
};
} // namespace openlr

View file

@ -1,5 +1,7 @@
#include "openlr/openlr_match_quality/openlr_assessment_tool/segment_correspondence.hpp"
namespace openlr
{
SegmentCorrespondence::SegmentCorrespondence(SegmentCorrespondence const & sc)
{
m_partnerSegment = sc.m_partnerSegment;
@ -41,3 +43,4 @@ void SegmentCorrespondence::Ignore()
m_status = Status::Ignored;
m_goldenPath.clear();
}
} // namespace openlr

View file

@ -5,6 +5,8 @@
#include "3party/pugixml/src/pugixml.hpp"
namespace openlr
{
class SegmentCorrespondence
{
public:
@ -23,9 +25,13 @@ public:
pugi::xml_node const & partnerSegmentXML);
openlr::Path const & GetMatchedPath() const { return m_matchedPath; }
bool HasMatchedPath() const { return !m_matchedPath.empty(); }
openlr::Path const & GetFakePath() const { return m_fakePath; }
bool HasFakePath() const { return !m_fakePath.empty(); }
openlr::Path const & GetGoldenPath() const { return m_goldenPath; }
bool HasGoldenPath() const { return !m_goldenPath.empty(); }
void SetGoldenPath(openlr::Path const & p);
openlr::LinearSegment const & GetPartnerSegment() const { return m_partnerSegment; }
@ -55,3 +61,4 @@ private:
Status m_status = Status::Untouched;
};
} // namespace openlr

View file

@ -2,6 +2,8 @@
#include <geometry/point2d.hpp>
namespace openlr
{
/// This class is used to delegate segments drawing to the DrapeEngine.
class TrafficDrawerDelegateBase
{
@ -20,3 +22,4 @@ public:
virtual void VisualizePoints(std::vector<m2::PointD> const & points) = 0;
virtual void ClearAllVisualizedPoints() = 0;
};
} // namespace openlr

View file

@ -14,6 +14,8 @@
#include <tuple>
using namespace openlr;
namespace
{
void RemovePointFromPull(m2::PointD const & toBeRemoved, std::vector<m2::PointD> & pool)
@ -37,7 +39,7 @@ std::vector<m2::PointD> GetReachablePoints(m2::PointD const & srcPoint,
}
return reachablePoints;
}
}
} // namespace
namespace impl
{
@ -97,6 +99,8 @@ void RoadPointCandidate::SetActivePoint(FeatureID const & fid)
}
} // namespace impl
namespace openlr
{
// TrafficMode -------------------------------------------------------------------------------------
TrafficMode::TrafficMode(std::string const & dataFileName,
Index const & index,
@ -172,17 +176,17 @@ bool TrafficMode::SaveSampleAs(std::string const & fileName) const
{
result.append_child("Ignored").text() = true;
}
if (!sc.GetMatchedPath().empty())
if (sc.HasMatchedPath())
{
auto node = segment.append_child("Route");
openlr::PathToXML(sc.GetMatchedPath(), node);
}
if (!sc.GetFakePath().empty())
if (sc.HasFakePath())
{
auto node = segment.append_child("FakeRoute");
openlr::PathToXML(sc.GetFakePath(), node);
}
if (!sc.GetGoldenPath().empty())
if (sc.HasGoldenPath())
{
auto node = segment.append_child("GoldenRoute");
openlr::PathToXML(sc.GetGoldenPath(), node);
@ -235,9 +239,9 @@ void TrafficMode::OnItemSelected(QItemSelection const & selected, QItemSelection
// TODO(mgsergio): Use a better way to set viewport and scale.
m_drawerDelegate->SetViewportCenter(viewportCenter);
m_drawerDelegate->DrawEncodedSegment(partnerSegmentPoints);
if (!m_currentSegment->GetMatchedPath().empty())
if (m_currentSegment->HasMatchedPath())
m_drawerDelegate->DrawDecodedSegments(GetPoints(m_currentSegment->GetMatchedPath()));
if (!m_currentSegment->GetGoldenPath().empty())
if (m_currentSegment->HasGoldenPath())
m_drawerDelegate->DrawGoldenPath(GetPoints(m_currentSegment->GetGoldenPath()));
emit SegmentSelected(static_cast<int>(partnerSegment.m_segmentId));
@ -258,7 +262,7 @@ void TrafficMode::StartBuildingPath()
if (m_buildingPath)
MYTHROW(TrafficModeError, ("Path building already in progress."));
if (!m_currentSegment->GetGoldenPath().empty())
if (m_currentSegment->HasGoldenPath())
{
auto const btn = QMessageBox::question(
nullptr,
@ -352,7 +356,7 @@ void TrafficMode::RollBackPath()
// TODO(mgsergio): Add a method for common visual manipulations.
m_drawerDelegate->ClearAllVisualizedPoints();
m_drawerDelegate->ClearGoldenPath();
if (!m_currentSegment->GetGoldenPath().empty())
if (m_currentSegment->HasGoldenPath())
m_drawerDelegate->DrawGoldenPath(GetPoints(m_currentSegment->GetGoldenPath()));
m_goldenPath.clear();
@ -363,7 +367,7 @@ void TrafficMode::IgnorePath()
{
CHECK(m_currentSegment, ("No segments selected"));
if (!m_currentSegment->GetGoldenPath().empty())
if (m_currentSegment->HasGoldenPath())
{
auto const btn = QMessageBox::question(
nullptr,
@ -485,3 +489,4 @@ void TrafficMode::HandlePoint(m2::PointD clickPoint, Qt::MouseButton const butto
return;
}
}
} // namespace openlr

View file

@ -35,11 +35,11 @@ namespace impl
class RoadPointCandidate
{
public:
RoadPointCandidate(std::vector<FeaturePoint> const & points,
RoadPointCandidate(std::vector<openlr::FeaturePoint> const & points,
m2::PointD const & coord);
void ActivateCommonPoint(RoadPointCandidate const & rpc);
FeaturePoint const & GetPoint() const;
openlr::FeaturePoint const & GetPoint() const;
m2::PointD const & GetCoordinate() const;
private:
@ -48,7 +48,7 @@ private:
void SetActivePoint(FeatureID const & fid);
m2::PointD m_coord = m2::PointD::Zero();
std::vector<FeaturePoint> m_points;
std::vector<openlr::FeaturePoint> m_points;
size_t m_activePointIndex = kInvalidId;
};
@ -56,6 +56,8 @@ private:
class BookmarkManager;
namespace openlr
{
/// This class is used to map sample ids to real data
/// and change sample evaluations.
class TrafficMode : public QAbstractTableModel
@ -120,3 +122,4 @@ private:
bool m_buildingPath = false;
std::vector<impl::RoadPointCandidate> m_goldenPath;
};
} // namespace openlr

View file

@ -8,6 +8,8 @@
#include <QtWidgets/QStyledItemDelegate>
#include <QtWidgets/QTableView>
namespace openlr
{
// ComboBoxDelegate --------------------------------------------------------------------------------
ComboBoxDelegate::ComboBoxDelegate(QObject * parent)
: QStyledItemDelegate(parent)
@ -77,3 +79,4 @@ void TrafficPanel::CreateTable(QAbstractItemModel * trafficModel)
SIGNAL(selectionChanged(QItemSelection const &, QItemSelection const &)),
trafficModel, SLOT(OnItemSelected(QItemSelection const &, QItemSelection const &)));
}
} // namespace openlr

View file

@ -7,6 +7,8 @@ class QComboBox;
class QTableView;
class QWidget;
namespace openlr
{
class ComboBoxDelegate : public QStyledItemDelegate
{
Q_OBJECT
@ -45,3 +47,4 @@ public slots:
private:
QTableView * m_table = Q_NULLPTR;
};
} // namespace openlr

View file

@ -10,6 +10,8 @@ namespace
string const kDataFilePath = "LastOpenlrAssessmentDataFilePath";
} // namespace
namespace openlr
{
TrafficModeInitDlg::TrafficModeInitDlg(QWidget * parent) :
QDialog(parent),
m_ui(new Ui::TrafficModeInitDlg)
@ -47,3 +49,4 @@ void TrafficModeInitDlg::SetFilePathViaDialog(QLineEdit & dest, QString const &
dest.setText(openFileDlg.selectedFiles().first());
}
} // namespace openlr

View file

@ -10,6 +10,8 @@ namespace Ui {
class TrafficModeInitDlg;
}
namespace openlr
{
class TrafficModeInitDlg : public QDialog
{
Q_OBJECT
@ -31,3 +33,4 @@ private:
std::string m_dataFileName;
};
} // namespace openlr

View file

@ -17,8 +17,10 @@ bool IsLoginUrl(QString const & url)
}
} // namespace
WebView::WebView(std::string const & url, std::string const & login, std::string const & paswd)
: QWebEngineView(nullptr), m_loadProgress(0), m_url(url), m_login(login), m_paswd(paswd)
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) {
@ -34,16 +36,16 @@ WebView::WebView(std::string const & url, std::string const & login, std::string
switch (termStatus)
{
case QWebEnginePage::NormalTerminationStatus:
status = tr("Render process normal exit");
status = "Render process normal exit";
break;
case QWebEnginePage::AbnormalTerminationStatus:
status = tr("Render process abnormal exit");
status = "Render process abnormal exit";
break;
case QWebEnginePage::CrashedTerminationStatus:
status = tr("Render process crashed");
status = "Render process crashed";
break;
case QWebEnginePage::KilledTerminationStatus:
status = tr("Render process killed");
status = "Render process killed";
break;
}
QMessageBox::StandardButton btn =
@ -107,9 +109,9 @@ void WebView::GoToSegment()
auto const script = QString(R"EOT(
function s(ctx, arg) { return ctx.querySelector(arg); }
function turnOff(cb) { if (cb.checked) cb.click(); }
turnOff(s(document, "#inrix\\:filters\\:traffic\\:trafficflowvisible"));
turnOff(s(document, "#inrix\\:filters\\:traffic\\:incidentsvisible"));
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;
@ -126,13 +128,14 @@ void WebView::GoToSegment()
void WebView::Login()
{
auto const script = QString(R"EOT(
function s(arg) { return document.querySelector(arg); }
s("#ctl00_BodyPlaceHolder_LoginControl_UserName").value = "%1"
s("#ctl00_BodyPlaceHolder_LoginControl_Password").value = "%2"
s("#ctl00_BodyPlaceHolder_LoginControl_LoginButton").click();
)EOT").arg(m_login.data()).arg(m_paswd.data());
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

View file

@ -2,6 +2,8 @@
#include <QWebEngineView>
namespace openlr
{
class WebView : public QWebEngineView
{
Q_OBJECT
@ -36,5 +38,6 @@ private:
std::string m_url;
std::string m_login;
std::string m_paswd;
std::string m_password;
};
} // namespace openlr