diff --git a/traffxml/traff_assessment_tool/CMakeLists.txt b/traffxml/traff_assessment_tool/CMakeLists.txt index 9b252206f..833b68dd2 100644 --- a/traffxml/traff_assessment_tool/CMakeLists.txt +++ b/traffxml/traff_assessment_tool/CMakeLists.txt @@ -8,8 +8,8 @@ set(SRC map_widget.hpp points_controller_delegate_base.hpp traffic_drawer_delegate_base.hpp - traffic_mode.cpp - traffic_mode.hpp + traffic_model.cpp + traffic_model.hpp traffic_panel.cpp traffic_panel.hpp trafficmodeinitdlg.cpp diff --git a/traffxml/traff_assessment_tool/mainwindow.cpp b/traffxml/traff_assessment_tool/mainwindow.cpp index 3d551a6b5..9741f021c 100644 --- a/traffxml/traff_assessment_tool/mainwindow.cpp +++ b/traffxml/traff_assessment_tool/mainwindow.cpp @@ -274,10 +274,10 @@ MainWindow::MainWindow(Framework & framework) fileMenu->addSeparator(); #ifdef openlr_obsolete - m_goldifyMatchedPathAction = fileMenu->addAction("Goldify", QKeySequence("Ctrl+G"), [this] { m_trafficMode->GoldifyMatchedPath(); }); + m_goldifyMatchedPathAction = fileMenu->addAction("Goldify", QKeySequence("Ctrl+G"), [this] { m_trafficModel->GoldifyMatchedPath(); }); m_startEditingAction = fileMenu->addAction("Edit", QKeySequence("Ctrl+E"), [this] { - m_trafficMode->StartBuildingPath(); + m_trafficModel->StartBuildingPath(); m_mapWidget->SetMode(MapWidget::Mode::TrafficMarkup); m_commitPathAction->setEnabled(true /* enabled */); m_cancelPathAction->setEnabled(true /* enabled */); @@ -285,19 +285,19 @@ MainWindow::MainWindow(Framework & framework) m_commitPathAction = fileMenu->addAction("Accept path", QKeySequence("Ctrl+A"), [this] { - m_trafficMode->CommitPath(); + m_trafficModel->CommitPath(); m_mapWidget->SetMode(MapWidget::Mode::Normal); }); m_cancelPathAction = fileMenu->addAction("Revert path", QKeySequence("Ctrl+R"), [this] { - m_trafficMode->RollBackPath(); + m_trafficModel->RollBackPath(); m_mapWidget->SetMode(MapWidget::Mode::Normal); }); m_ignorePathAction = fileMenu->addAction("Ignore path", QKeySequence("Ctrl+I"), [this] { - m_trafficMode->IgnorePath(); + m_trafficModel->IgnorePath(); m_mapWidget->SetMode(MapWidget::Mode::Normal); }); @@ -313,22 +313,22 @@ MainWindow::MainWindow(Framework & framework) void MainWindow::CreateTrafficPanel(std::string const & dataFilePath) { - m_trafficMode = new TrafficMode(dataFilePath, + m_trafficModel = new TrafficModel(dataFilePath, m_framework.GetDataSource(), std::make_unique(m_framework), std::make_unique(m_framework)); connect(m_mapWidget, &MapWidget::TrafficMarkupClick, - m_trafficMode, &TrafficMode::OnClick); - connect(m_trafficMode, &TrafficMode::EditingStopped, + m_trafficModel, &TrafficModel::OnClick); + connect(m_trafficModel, &TrafficModel::EditingStopped, this, &MainWindow::OnPathEditingStop); - connect(m_trafficMode, &TrafficMode::SegmentSelected, + connect(m_trafficModel, &TrafficModel::SegmentSelected, [](int segmentId) { QApplication::clipboard()->setText(QString::number(segmentId)); }); m_docWidget = new QDockWidget(tr("Routes"), this); addDockWidget(Qt::DockWidgetArea::RightDockWidgetArea, m_docWidget); - m_docWidget->setWidget(new TrafficPanel(m_trafficMode, m_docWidget)); + m_docWidget->setWidget(new TrafficPanel(m_trafficModel, m_docWidget)); m_docWidget->adjustSize(); m_docWidget->setMinimumWidth(400); @@ -341,8 +341,8 @@ void MainWindow::DestroyTrafficPanel() delete m_docWidget; m_docWidget = nullptr; - delete m_trafficMode; - m_trafficMode = nullptr; + delete m_trafficModel; + m_trafficModel = nullptr; m_mapWidget->SetMode(MapWidget::Mode::Normal); } @@ -392,7 +392,7 @@ void MainWindow::OnOpenTrafficSample() { CreateTrafficPanel(dlg.GetDataFilePath()); } - catch (TrafficModeError const & e) + catch (TrafficModelError const & e) { QMessageBox::critical(this, "Data loading error", QString("Can't load data file.")); LOG(LERROR, (e.Msg())); @@ -453,7 +453,7 @@ void MainWindow::OnSaveTrafficSample() document.save_file(fileName.toStdString().data(), " " /* indent */); #ifdef openlr_obsolete - if (!m_trafficMode->SaveSampleAs(fileName.toStdString())) + if (!m_trafficModel->SaveSampleAs(fileName.toStdString())) { QMessageBox::critical( this, "Saving error", diff --git a/traffxml/traff_assessment_tool/mainwindow.hpp b/traffxml/traff_assessment_tool/mainwindow.hpp index 02fa4803f..e3c460df4 100644 --- a/traffxml/traff_assessment_tool/mainwindow.hpp +++ b/traffxml/traff_assessment_tool/mainwindow.hpp @@ -12,7 +12,7 @@ class QHBoxLayout; namespace traffxml { class MapWidget; -class TrafficMode; +class TrafficModel; class WebView; } @@ -56,7 +56,7 @@ private: Framework & m_framework; - traffxml::TrafficMode * m_trafficMode = nullptr; + traffxml::TrafficModel * m_trafficModel = nullptr; QDockWidget * m_docWidget = nullptr; #ifdef openlr_obsolete diff --git a/traffxml/traff_assessment_tool/traffic_mode.cpp b/traffxml/traff_assessment_tool/traffic_model.cpp similarity index 89% rename from traffxml/traff_assessment_tool/traffic_mode.cpp rename to traffxml/traff_assessment_tool/traffic_model.cpp index f0e5511ea..12cb8c9d2 100644 --- a/traffxml/traff_assessment_tool/traffic_mode.cpp +++ b/traffxml/traff_assessment_tool/traffic_model.cpp @@ -1,4 +1,4 @@ -#include "traffic_mode.hpp" +#include "traffic_model.hpp" #ifdef openlr_obsolete #include "openlr/openlr_model_xml.hpp" @@ -99,8 +99,8 @@ void RoadPointCandidate::SetActivePoint(FeatureID const & fid) } // namespace impl #endif -// TrafficMode ------------------------------------------------------------------------------------- -TrafficMode::TrafficMode(std::string const & dataFileName, DataSource const & dataSource, +// TrafficModel ------------------------------------------------------------------------------------- +TrafficModel::TrafficModel(std::string const & dataFileName, DataSource const & dataSource, std::unique_ptr drawerDelegate, std::unique_ptr pointsDelegate, QObject * parent) @@ -112,7 +112,7 @@ TrafficMode::TrafficMode(std::string const & dataFileName, DataSource const & da // TODO(mgsergio): Collect stat how many segments of each kind were parsed. pugi::xml_document doc; if (!doc.load_file(dataFileName.data())) - MYTHROW(TrafficModeError, ("Can't load file:", strerror(errno))); + MYTHROW(TrafficModelError, ("Can't load file:", strerror(errno))); // Save root node without children. { @@ -141,7 +141,7 @@ TrafficMode::TrafficMode(std::string const & dataFileName, DataSource const & da // TODO(mgsergio): Unify error handling interface of openlr_xml_mode and decoded_path parsers. auto const partnerSegmentXML = xmlSegment.child("reportSegments"); if (!openlr::SegmentFromXML(partnerSegmentXML, segment)) - MYTHROW(TrafficModeError, ("An error occurred while parsing: can't parse segment")); + MYTHROW(TrafficModelError, ("An error occurred while parsing: can't parse segment")); if (auto const route = xmlSegment.child("Route")) openlr::PathFromXML(route, m_dataSource, matchedPath); @@ -182,7 +182,7 @@ TrafficMode::TrafficMode(std::string const & dataFileName, DataSource const & da } catch (openlr::DecodedPathLoadError const & e) { - MYTHROW(TrafficModeError, ("An exception occurred while parsing", dataFileName, e.Msg())); + MYTHROW(TrafficModelError, ("An exception occurred while parsing", dataFileName, e.Msg())); } #endif @@ -190,7 +190,7 @@ TrafficMode::TrafficMode(std::string const & dataFileName, DataSource const & da } // TODO(mgsergio): Check if a path was committed, or commit it. -bool TrafficMode::SaveSampleAs(std::string const & fileName) const +bool TrafficModel::SaveSampleAs(std::string const & fileName) const { CHECK(!fileName.empty(), ("Can't save to an empty file.")); @@ -230,7 +230,7 @@ bool TrafficMode::SaveSampleAs(std::string const & fileName) const return true; } -int TrafficMode::rowCount(const QModelIndex & parent) const +int TrafficModel::rowCount(const QModelIndex & parent) const { #ifdef openlr_obsolete return static_cast(m_segments.size()); @@ -240,9 +240,9 @@ int TrafficMode::rowCount(const QModelIndex & parent) const #endif } -int TrafficMode::columnCount(const QModelIndex & parent) const { return 4; } +int TrafficModel::columnCount(const QModelIndex & parent) const { return 4; } -QVariant TrafficMode::data(const QModelIndex & index, int role) const +QVariant TrafficModel::data(const QModelIndex & index, int role) const { if (!index.isValid()) return QVariant(); @@ -270,7 +270,7 @@ QVariant TrafficMode::data(const QModelIndex & index, int role) const return QVariant(); } -QVariant TrafficMode::headerData(int section, Qt::Orientation orientation, +QVariant TrafficModel::headerData(int section, Qt::Orientation orientation, int role /* = Qt::DisplayRole */) const { if (orientation != Qt::Horizontal && role != Qt::DisplayRole) @@ -286,7 +286,7 @@ QVariant TrafficMode::headerData(int section, Qt::Orientation orientation, UNREACHABLE(); } -void TrafficMode::OnItemSelected(QItemSelection const & selected, QItemSelection const &) +void TrafficModel::OnItemSelected(QItemSelection const & selected, QItemSelection const &) { #ifdef openlr_obsolete ASSERT(!selected.empty(), ()); @@ -314,7 +314,7 @@ void TrafficMode::OnItemSelected(QItemSelection const & selected, QItemSelection #endif } -Qt::ItemFlags TrafficMode::flags(QModelIndex const & index) const +Qt::ItemFlags TrafficModel::flags(QModelIndex const & index) const { if (!index.isValid()) return Qt::ItemIsEnabled; @@ -323,7 +323,7 @@ Qt::ItemFlags TrafficMode::flags(QModelIndex const & index) const } #ifdef openlr_obsolete -void TrafficMode::GoldifyMatchedPath() +void TrafficModel::GoldifyMatchedPath() { if (!m_currentSegment->HasMatchedPath()) { @@ -340,7 +340,7 @@ void TrafficMode::GoldifyMatchedPath() m_drawerDelegate->DrawGoldenPath(GetPoints(m_currentSegment->GetGoldenPath())); } -void TrafficMode::StartBuildingPath() +void TrafficModel::StartBuildingPath() { if (!StartBuildingPathChecks()) return; @@ -352,7 +352,7 @@ void TrafficMode::StartBuildingPath() m_drawerDelegate->VisualizePoints(m_pointsDelegate->GetAllJunctionPointsInViewport()); } -void TrafficMode::PushPoint(m2::PointD const & coord, std::vector const & points) +void TrafficModel::PushPoint(m2::PointD const & coord, std::vector const & points) { impl::RoadPointCandidate point(points, coord); if (!m_goldenPath.empty()) @@ -360,18 +360,18 @@ void TrafficMode::PushPoint(m2::PointD const & coord, std::vector m_goldenPath.push_back(point); } -void TrafficMode::PopPoint() +void TrafficModel::PopPoint() { CHECK(!m_goldenPath.empty(), ("Attempt to pop point from an empty path.")); m_goldenPath.pop_back(); } -void TrafficMode::CommitPath() +void TrafficModel::CommitPath() { CHECK(m_currentSegment, ("No segments selected")); if (!m_buildingPath) - MYTHROW(TrafficModeError, ("Path building is not started")); + MYTHROW(TrafficModelError, ("Path building is not started")); SCOPE_GUARD(guard, [this] { emit EditingStopped(); }); @@ -412,7 +412,7 @@ void TrafficMode::CommitPath() m_goldenPath.clear(); } -void TrafficMode::RollBackPath() +void TrafficModel::RollBackPath() { CHECK(m_currentSegment, ("No segments selected")); CHECK(m_buildingPath, ("No path building is in progress.")); @@ -429,7 +429,7 @@ void TrafficMode::RollBackPath() emit EditingStopped(); } -void TrafficMode::IgnorePath() +void TrafficModel::IgnorePath() { CHECK(m_currentSegment, ("No segments selected")); @@ -453,23 +453,23 @@ void TrafficMode::IgnorePath() emit EditingStopped(); } -size_t TrafficMode::GetPointsCount() const +size_t TrafficModel::GetPointsCount() const { return m_goldenPath.size(); } -m2::PointD const & TrafficMode::GetPoint(size_t const index) const +m2::PointD const & TrafficModel::GetPoint(size_t const index) const { return m_goldenPath[index].GetCoordinate(); } -m2::PointD const & TrafficMode::GetLastPoint() const +m2::PointD const & TrafficModel::GetLastPoint() const { CHECK(!m_goldenPath.empty(), ("Attempt to get point from an empty path.")); return m_goldenPath.back().GetCoordinate(); } -std::vector TrafficMode::GetGoldenPathPoints() const +std::vector TrafficModel::GetGoldenPathPoints() const { std::vector coordinates; for (auto const & roadPoint : m_goldenPath) @@ -478,7 +478,7 @@ std::vector TrafficMode::GetGoldenPathPoints() const } // TODO(mgsergio): Draw the first point when the path size is 1. -void TrafficMode::HandlePoint(m2::PointD clickPoint, Qt::MouseButton const button) +void TrafficModel::HandlePoint(m2::PointD clickPoint, Qt::MouseButton const button) { if (!m_buildingPath) return; @@ -555,12 +555,12 @@ void TrafficMode::HandlePoint(m2::PointD clickPoint, Qt::MouseButton const butto } } -bool TrafficMode::StartBuildingPathChecks() const +bool TrafficModel::StartBuildingPathChecks() const { CHECK(m_currentSegment, ("A segment should be selected before path building is started.")); if (m_buildingPath) - MYTHROW(TrafficModeError, ("Path building already in progress.")); + MYTHROW(TrafficModelError, ("Path building already in progress.")); if (m_currentSegment->HasGoldenPath()) { diff --git a/traffxml/traff_assessment_tool/traffic_mode.hpp b/traffxml/traff_assessment_tool/traffic_model.hpp similarity index 95% rename from traffxml/traff_assessment_tool/traffic_mode.hpp rename to traffxml/traff_assessment_tool/traffic_model.hpp index edf31be11..eeccca3e7 100644 --- a/traffxml/traff_assessment_tool/traffic_mode.hpp +++ b/traffxml/traff_assessment_tool/traffic_model.hpp @@ -26,7 +26,7 @@ class QItemSelection; class Selection; -DECLARE_EXCEPTION(TrafficModeError, RootException); +DECLARE_EXCEPTION(TrafficModelError, RootException); namespace traffxml { @@ -62,13 +62,13 @@ private: /// This class is used to map sample ids to real data /// and change sample evaluations. -class TrafficMode : public QAbstractTableModel +class TrafficModel : public QAbstractTableModel { Q_OBJECT public: // TODO(mgsergio): Check we are on the right mwm. I.e. right mwm version and everything. - TrafficMode(std::string const & dataFileName, DataSource const & dataSource, + TrafficModel(std::string const & dataFileName, DataSource const & dataSource, std::unique_ptr drawerDelegate, std::unique_ptr pointsDelegate, QObject * parent = Q_NULLPTR);