From 684e2ce0b9803a99eec2c05e1d92a5db3f060c07 Mon Sep 17 00:00:00 2001 From: Sergey Magidovich Date: Mon, 3 Jul 2017 13:03:51 +0300 Subject: [OPENLR] Cut trafficMode from desktop app. Move it to a subproject. --- qt/CMakeLists.txt | 7 -- qt/mainwindow.cpp | 128 --------------------------- qt/mainwindow.hpp | 22 ++--- qt/qt.pro | 11 +-- qt/traffic_mode.cpp | 215 ---------------------------------------------- qt/traffic_mode.hpp | 75 ---------------- qt/traffic_panel.cpp | 75 ---------------- qt/traffic_panel.hpp | 47 ---------- qt/trafficmodeinitdlg.cpp | 62 ------------- qt/trafficmodeinitdlg.h | 35 -------- qt/trafficmodeinitdlg.ui | 128 --------------------------- 11 files changed, 7 insertions(+), 798 deletions(-) delete mode 100644 qt/traffic_mode.cpp delete mode 100644 qt/traffic_mode.hpp delete mode 100644 qt/traffic_panel.cpp delete mode 100644 qt/traffic_panel.hpp delete mode 100644 qt/trafficmodeinitdlg.cpp delete mode 100644 qt/trafficmodeinitdlg.h delete mode 100644 qt/trafficmodeinitdlg.ui (limited to 'qt') diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index da92a04fa9..e997164c96 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -68,12 +68,6 @@ set( preferences_dialog.hpp search_panel.cpp search_panel.hpp - traffic_mode.cpp - traffic_mode.hpp - traffic_panel.cpp - traffic_panel.hpp - trafficmodeinitdlg.cpp - trafficmodeinitdlg.h update_dialog.cpp update_dialog.hpp ) @@ -113,7 +107,6 @@ omim_link_libraries( pugixml oauthcpp opening_hours - openlr stb_image sdf_image ${Qt5Gui_LIBRARIES} diff --git a/qt/mainwindow.cpp b/qt/mainwindow.cpp index 49cdb7c552..a43ea17100 100644 --- a/qt/mainwindow.cpp +++ b/qt/mainwindow.cpp @@ -6,13 +6,6 @@ #include "qt/qt_common/helpers.hpp" #include "qt/qt_common/scale_slider.hpp" #include "qt/search_panel.hpp" -#include "qt/traffic_mode.hpp" -#include "qt/traffic_panel.hpp" -#include "qt/trafficmodeinitdlg.h" - -#include "drape/debug_rect_renderer.hpp" - -#include "openlr/openlr_sample.hpp" #include "platform/settings.hpp" #include "platform/platform.hpp" @@ -58,60 +51,6 @@ #endif // NO_DOWNLOADER -namespace -{ -// TODO(mgsergio): Consider getting rid of this class: just put everything -// in TrafficMode. -class TrafficDrawerDelegate : public TrafficDrawerDelegateBase -{ -public: - explicit TrafficDrawerDelegate(qt::DrawWidget & drawWidget) - : m_framework(drawWidget.GetFramework()) - , m_drapeApi(m_framework.GetDrapeApi()) - { - } - - void SetViewportCenter(m2::PointD const & center) override - { - m_framework.SetViewportCenter(center); - } - - void DrawDecodedSegments(DecodedSample const & sample, int const sampleIndex) override - { - CHECK(!sample.GetItems().empty(), ("Sample must not be empty.")); - auto const & points = sample.GetPoints(sampleIndex); - - LOG(LINFO, ("Decoded segment", points)); - m_drapeApi.AddLine(NextLineId(), - df::DrapeApiLineData(points, dp::Color(0, 0, 255, 255)) - .Width(3.0f).ShowPoints(true /* markPoints */)); - } - - void DrawEncodedSegment(openlr::LinearSegment const & segment) override - { - auto const & points = segment.GetMercatorPoints(); - - LOG(LINFO, ("Encoded segment", points)); - m_drapeApi.AddLine(NextLineId(), - df::DrapeApiLineData(points, dp::Color(255, 0, 0, 255)) - .Width(3.0f).ShowPoints(true /* markPoints */)); - } - - void Clear() override - { - m_drapeApi.Clear(); - } - -private: - string NextLineId() { return strings::to_string(m_lineId++); } - - uint32_t m_lineId = 0; - - Framework & m_framework; - df::DrapeApi & m_drapeApi; -}; -} // namespace - namespace qt { // Defined in osm_auth_dialog.cpp. @@ -147,21 +86,6 @@ MainWindow::MainWindow(Framework & framework, bool apiOpenGLES3, QString const & setWindowTitle(caption); setWindowIcon(QIcon(":/ui/logo.png")); - QMenu * trafficMarkup = new QMenu(tr("Traffic"), this); - menuBar()->addMenu(trafficMarkup); - trafficMarkup->addAction(tr("Open sample"), this, SLOT(OnOpenTrafficSample())); - m_saveTrafficSampleAction = trafficMarkup->addAction(tr("Save sample"), this, - SLOT(OnSaveTrafficSample())); - m_saveTrafficSampleAction->setEnabled(false); - - m_quitTrafficModeAction = new QAction(tr("Quit traffic mode"), this); - // On macOS actions with names started with quit or exit are treated specially, - // see QMenuBar documentation. - m_quitTrafficModeAction->setMenuRole(QAction::MenuRole::NoRole); - m_quitTrafficModeAction->setEnabled(false); - connect(m_quitTrafficModeAction, SIGNAL(triggered()), this, SLOT(OnQuitTrafficMode())); - trafficMarkup->addAction(m_quitTrafficModeAction); - #ifndef OMIM_OS_WINDOWS QMenu * helpMenu = new QMenu(tr("Help"), this); menuBar()->addMenu(helpMenu); @@ -856,24 +780,6 @@ void MainWindow::CreatePanelImpl(size_t i, Qt::DockWidgetArea area, QString cons } } -void MainWindow::CreateTrafficPanel(string const & dataFilePath, string const & sampleFilePath) -{ - CreatePanelImpl(1, Qt::RightDockWidgetArea, tr("Traffic"), QKeySequence(), nullptr); - - m_trafficMode = new TrafficMode(dataFilePath, sampleFilePath, - m_pDrawWidget->GetFramework().GetIndex(), - make_unique(*m_pDrawWidget)); - m_Docks[1]->setWidget(new TrafficPanel(m_trafficMode, m_Docks[1])); - m_Docks[1]->adjustSize(); -} - -void MainWindow::DestroyTrafficPanel() -{ - removeDockWidget(m_Docks[1]); - delete m_Docks[1]; - m_Docks[1] = nullptr; -} - void MainWindow::closeEvent(QCloseEvent * e) { m_pDrawWidget->PrepareShutdown(); @@ -897,40 +803,6 @@ void MainWindow::OnTrafficEnabled() m_pDrawWidget->GetFramework().SaveTrafficEnabled(enabled); } -void MainWindow::OnOpenTrafficSample() -{ - TrafficModeInitDlg dlg; - dlg.exec(); - if (dlg.result() != QDialog::DialogCode::Accepted) - return; - - LOG(LDEBUG, ("Traffic mode enabled")); - CreateTrafficPanel(dlg.GetDataFilePath(), dlg.GetSampleFilePath()); - m_quitTrafficModeAction->setEnabled(true); - m_saveTrafficSampleAction->setEnabled(true); - m_Docks[1]->show(); -} - -void MainWindow::OnSaveTrafficSample() -{ - auto const & fileName = QFileDialog::getSaveFileName(this, tr("Save sample")); - if (fileName.isEmpty()) - return; - - if (!m_trafficMode->SaveSampleAs(fileName.toStdString())) - ;// TODO(mgsergio): Show error dlg; -} - -void MainWindow::OnQuitTrafficMode() -{ - // If not saved, ask a user if he/she wants to save. - // OnSaveTrafficSample() - m_quitTrafficModeAction->setEnabled(false); - m_saveTrafficSampleAction->setEnabled(false); - DestroyTrafficPanel(); - m_trafficMode = nullptr; -} - void MainWindow::OnStartPointSelected() { m_routePointsToolButton->setIcon(m_selectStartRoutePoint->icon()); diff --git a/qt/mainwindow.hpp b/qt/mainwindow.hpp index 7fe028aef9..10fbfe076c 100644 --- a/qt/mainwindow.hpp +++ b/qt/mainwindow.hpp @@ -18,16 +18,18 @@ class QDockWidget; class QLabel; class QPushButton; class QToolButton; -class TrafficMode; namespace search { class Result; } namespace qt { +class DrawWidget; + class MainWindow : public QMainWindow, location::LocationObserver { - DrawWidget * m_pDrawWidget = nullptr; // TODO(mgsergio): Make indexing more informative. - std::array m_Docks; + DrawWidget * m_pDrawWidget = nullptr; + // TODO(mgsergio): Make indexing more informative. + array m_Docks; QPushButton * m_downloadButton = nullptr; QPushButton * m_retryButton = nullptr; @@ -37,17 +39,12 @@ class MainWindow : public QMainWindow, location::LocationObserver std::unique_ptr const m_locationService; - // This object is managed by Qt memory system. - TrafficMode * m_trafficMode = nullptr; - QAction * m_pMyPositionAction = nullptr; QAction * m_pCreateFeatureAction = nullptr; QAction * m_selectionMode = nullptr; QAction * m_clearSelection = nullptr; QAction * m_pSearchAction = nullptr; QAction * m_trafficEnableAction = nullptr; - QAction * m_saveTrafficSampleAction = nullptr; - QAction * m_quitTrafficModeAction = nullptr; QToolButton * m_routePointsToolButton = nullptr; QAction * m_selectStartRoutePoint = nullptr; QAction * m_selectFinishRoutePoint = nullptr; @@ -82,9 +79,6 @@ protected: void CreateSearchBarAndPanel(); void CreateCountryStatusControls(); - void CreateTrafficPanel(string const & dataFilePath, string const & sampleFilePath); - void DestroyTrafficPanel(); - #if defined(Q_WS_WIN) /// to handle menu messages bool winEvent(MSG * msg, long * result) override; @@ -114,16 +108,12 @@ protected Q_SLOTS: void OnClearSelection(); void OnTrafficEnabled(); - void OnOpenTrafficSample(); - void OnSaveTrafficSample(); - void OnQuitTrafficMode(); - void OnStartPointSelected(); void OnFinishPointSelected(); void OnIntermediatePointSelected(); void OnFollowRoute(); void OnClearRoute(); - + #ifdef BUILD_DESIGNER void OnBuildStyle(); void OnRecalculateGeomIndex(); diff --git a/qt/qt.pro b/qt/qt.pro index e6bc2ffa8e..31f27918ed 100644 --- a/qt/qt.pro +++ b/qt/qt.pro @@ -1,7 +1,7 @@ # Main application in qt. ROOT_DIR = .. -DEPENDENCIES = qt_common map drape_frontend openlr routing search storage tracking traffic routing_common \ +DEPENDENCIES = qt_common map drape_frontend routing search storage tracking traffic routing_common \ indexer drape partners_api local_ads platform editor geometry \ coding base freetype expat gflags jansson protobuf osrm stats_client \ minizip succinct pugixml oauthcpp stb_image sdf_image icu @@ -203,9 +203,6 @@ SOURCES += \ place_page_dialog.cpp \ preferences_dialog.cpp \ search_panel.cpp \ - traffic_mode.cpp \ - traffic_panel.cpp \ - trafficmodeinitdlg.cpp \ update_dialog.cpp \ HEADERS += \ @@ -219,12 +216,6 @@ HEADERS += \ place_page_dialog.hpp \ preferences_dialog.hpp \ search_panel.hpp \ - traffic_mode.hpp \ - traffic_panel.hpp \ - trafficmodeinitdlg.h \ update_dialog.hpp \ RESOURCES += res/resources.qrc - -FORMS += \ - trafficmodeinitdlg.ui diff --git a/qt/traffic_mode.cpp b/qt/traffic_mode.cpp deleted file mode 100644 index 198af76d02..0000000000 --- a/qt/traffic_mode.cpp +++ /dev/null @@ -1,215 +0,0 @@ -#include "qt/traffic_mode.hpp" - -#include "openlr/openlr_simple_parser.hpp" - -#include "indexer/index.hpp" -#include "indexer/scales.hpp" - -#include "base/stl_add.hpp" - -#include "3party/pugixml/src/pugixml.hpp" - -#include - -// DecodedSample ----------------------------------------------------------------------------------- -DecodedSample::DecodedSample(Index const & index, openlr::SamplePool const & sample) -{ - for (auto const & item : sample) - { - m_decodedItems.push_back(item); - for (auto const & mwmSegment : item.m_segments) - { - auto const & fid = mwmSegment.m_fid; - Index::FeaturesLoaderGuard g(index, fid.m_mwmId); - CHECK(fid.m_mwmId.IsAlive(), ("Mwm id is not alive.")); - if (m_points.find(fid) != end(m_points)) - continue; - - FeatureType ft; - CHECK(g.GetFeatureByIndex(fid.m_index, ft), ("Can't read feature", fid)); - ft.ParseGeometry(FeatureType::BEST_GEOMETRY); - - auto & v = m_points[fid]; - v.reserve(ft.GetPointsCount()); - ft.ForEachPoint(MakeBackInsertFunctor(v), scales::GetUpperScale()); - } - } -} - -std::vector DecodedSample::GetPoints(size_t const index) const -{ - std::vector points; - - auto const pushPoint = [&points](m2::PointD const & p) - { - if (points.empty() || !(points.back() - p).IsAlmostZero()) - points.push_back(p); - }; - - auto const & item = m_decodedItems[index]; - for (auto const & seg : item.m_segments) - { - auto const ftIt = m_points.find(seg.m_fid); - CHECK(ftIt != end(m_points), ("Can't find feature with id:", seg.m_fid)); - auto const & ftPoints = ftIt->second; - CHECK_LESS(seg.m_segId + 1, ftPoints.size(), ()); - auto const firstP = ftPoints[seg.m_segId]; - auto const secondP = ftPoints[seg.m_segId + 1]; - if (seg.m_isForward) - { - pushPoint(firstP); - pushPoint(secondP); - } - else - { - pushPoint(secondP); - pushPoint(firstP); - } - } - - return points; -} - -// TrafficMode ------------------------------------------------------------------------------------- -TrafficMode::TrafficMode(std::string const & dataFileName, std::string const & sampleFileName, - Index const & index, std::unique_ptr drawerDelagate, - QObject * parent) - : QAbstractTableModel(parent) - , m_drawerDelegate(move(drawerDelagate)) -{ - try - { - auto const & sample = openlr::LoadSamplePool(sampleFileName, index); - m_decodedSample = make_unique(index, sample); - } - catch (openlr::SamplePoolLoadError const & e) - { - LOG(LERROR, (e.Msg())); - return; - } - - pugi::xml_document doc; - if (!doc.load_file(dataFileName.data())) - { - LOG(LERROR, ("Can't load file:", dataFileName)); - return; - } - - std::vector segments; - if (!ParseOpenlr(doc, segments)) - { - LOG(LERROR, ("Can't parse data:", dataFileName)); - return; - } - for (auto const & segment : segments) - { - CHECK(!segment.m_locationReference.m_points.empty(), ()); - m_partnerSegments[segment.m_segmentId] = segment; - } - - m_valid = true; -} - -bool TrafficMode::SaveSampleAs(std::string const & fileName) const -{ - try - { - auto const & samplePool = m_decodedSample->GetItems(); - openlr::SaveSamplePool(fileName, samplePool, true /* saveEvaluation */); - } - catch (openlr::SamplePoolSaveError const & e) - { - LOG(LERROR, (e.Msg())); - return false; - } - return true; -} - -int TrafficMode::rowCount(const QModelIndex & parent) const -{ - if (!m_decodedSample) - return 0; - return static_cast(m_decodedSample->m_decodedItems.size()); -} - -int TrafficMode::columnCount(const QModelIndex & parent) const -{ - return 2; -} - -QVariant TrafficMode::data(const QModelIndex & index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (index.row() >= rowCount()) - return QVariant(); - - if (role != Qt::DisplayRole && role != Qt::EditRole) - return QVariant(); - - if (index.column() == 0) - return ToString(m_decodedSample->m_decodedItems[index.row()].m_evaluation).data(); - - if (index.column() == 1) - return m_decodedSample->m_decodedItems[index.row()].m_partnerSegmentId.Get(); - - return QVariant(); -} - -void TrafficMode::OnItemSelected(QItemSelection const & selected, QItemSelection const &) -{ - ASSERT(!selected.empty(), ("The selection should not be empty. RTFM for qt5.")); - auto const row = selected.front().top(); - - // TODO(mgsergio): Use algo for center calculation. - // Now viewport is set to the first point of the first segment. - auto const partnerSegmentId = m_decodedSample->m_decodedItems[row].m_partnerSegmentId; - - if (m_decodedSample->m_decodedItems[row].m_segments.empty()) - { - LOG(LERROR, ("Empty mwm segments for partner id", partnerSegmentId.Get())); - return; - } - - auto const & firstSegment = m_decodedSample->m_decodedItems[row].m_segments[0]; - auto const & firstSegmentFeatureId = firstSegment.m_fid; - auto const & firstSegmentFeature = m_decodedSample->m_points.at(firstSegmentFeatureId); - - LOG(LDEBUG, ("PartnerSegmentId:", partnerSegmentId.Get(), - "Segment points:", m_partnerSegments[partnerSegmentId.Get()].GetMercatorPoints(), - "Featrue segment id", firstSegment.m_segId, - "Feature segment points", firstSegmentFeature[firstSegment.m_segId], - firstSegmentFeature[firstSegment.m_segId + 1])); - - m_drawerDelegate->Clear(); - m_drawerDelegate->SetViewportCenter(firstSegmentFeature[firstSegment.m_segId]); - m_drawerDelegate->DrawEncodedSegment(m_partnerSegments.at(partnerSegmentId.Get())); - m_drawerDelegate->DrawDecodedSegments(*m_decodedSample, row); -} - -Qt::ItemFlags TrafficMode::flags(QModelIndex const & index) const -{ - if (!index.isValid()) - return Qt::ItemIsEnabled; - - if (index.column() != 0) - QAbstractItemModel::flags(index); - - return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; -} - -bool TrafficMode::setData(QModelIndex const & index, QVariant const & value, int const role) -{ - if (!index.isValid() || role != Qt::EditRole) - return false; - - auto const newValue = value.toString(); - auto evaluation = openlr::ParseItemEvaluation(newValue.toStdString()); - if (evaluation == openlr::ItemEvaluation::NotAValue) - return false; - - m_decodedSample->m_decodedItems[index.row()].m_evaluation = evaluation; - emit dataChanged(index, index); - return true; -} diff --git a/qt/traffic_mode.hpp b/qt/traffic_mode.hpp deleted file mode 100644 index d8e8bfbacc..0000000000 --- a/qt/traffic_mode.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -#include "indexer/feature.hpp" - -#include "openlr/openlr_model.hpp" -#include "openlr/openlr_sample.hpp" - -#include -#include -#include - -#include - -class Index; -class QItemSelection; - -struct DecodedSample -{ - DecodedSample(Index const & index, openlr::SamplePool const & sample); - - openlr::SamplePool const & GetItems() const { return m_decodedItems; } - std::vector GetPoints(size_t const index) const; - - std::map> m_points; - std::vector m_decodedItems; -}; - -/// This class is used to delegate segments drawing to the DrapeEngine. -class TrafficDrawerDelegateBase -{ -public: - virtual ~TrafficDrawerDelegateBase() = default; - - virtual void SetViewportCenter(m2::PointD const & center) = 0; - - virtual void DrawDecodedSegments(DecodedSample const & sample, int sampleIndex) = 0; - virtual void DrawEncodedSegment(openlr::LinearSegment const & segment) = 0; - virtual void Clear() = 0; -}; - -/// This class is used to map sample ids to real data -/// and change sample evaluations. -class TrafficMode : public QAbstractTableModel -{ - Q_OBJECT - -public: - TrafficMode(std::string const & dataFileName, std::string const & sampleFileName, - Index const & index, std::unique_ptr drawerDelagate, - QObject * parent = Q_NULLPTR); - - bool SaveSampleAs(std::string const & fileName) const; - bool IsValid() const { return m_valid; } - - int rowCount(const QModelIndex & parent = QModelIndex()) const Q_DECL_OVERRIDE; - int columnCount(const QModelIndex & parent = QModelIndex()) const Q_DECL_OVERRIDE; - - QVariant data(const QModelIndex & index, int role) const Q_DECL_OVERRIDE; - // QVariant headerData(int section, Qt::Orientation orientation, - // int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; - - Qt::ItemFlags flags(QModelIndex const & index) const Q_DECL_OVERRIDE; - bool setData(QModelIndex const & index, QVariant const & value, int role = Qt::EditRole) Q_DECL_OVERRIDE; - -public slots: - void OnItemSelected(QItemSelection const & selected, QItemSelection const &); - -private: - std::unique_ptr m_decodedSample; - std::unordered_map m_partnerSegments; - - std::unique_ptr m_drawerDelegate; - - bool m_valid = false; -}; diff --git a/qt/traffic_panel.cpp b/qt/traffic_panel.cpp deleted file mode 100644 index a073a777b9..0000000000 --- a/qt/traffic_panel.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "qt/traffic_panel.hpp" -#include "qt/traffic_mode.hpp" - -#include -#include -#include -#include -#include -#include - -// ComboBoxDelegate -------------------------------------------------------------------------------- -ComboBoxDelegate::ComboBoxDelegate(QObject * parent) - : QStyledItemDelegate(parent) -{ -} - -QWidget * ComboBoxDelegate::createEditor(QWidget * parent, QStyleOptionViewItem const & option, - QModelIndex const & index) const -{ - auto * editor = new QComboBox(parent); - editor->setFrame(false); - editor->setEditable(false); - editor->addItems({"Unevaluated", "Positive", "Negative", "RelPositive", "RelNegative", "Ignore"}); - - return editor; -} - -void ComboBoxDelegate::setEditorData(QWidget * editor, QModelIndex const & index) const -{ - auto const value = index.model()->data(index, Qt::EditRole).toString(); - static_cast(editor)->setCurrentText(value); -} - -void ComboBoxDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, - QModelIndex const & index) const -{ - model->setData(index, static_cast(editor)->currentText(), Qt::EditRole); -} - -void ComboBoxDelegate::updateEditorGeometry(QWidget * editor, QStyleOptionViewItem const & option, - QModelIndex const & index) const -{ - editor->setGeometry(option.rect); -} - -// TrafficPanel ------------------------------------------------------------------------------------ -TrafficPanel::TrafficPanel(QAbstractItemModel * trafficModel, QWidget * parent) - : QWidget(parent) -{ - CreateTable(trafficModel); - - auto * layout = new QVBoxLayout(); - layout->addWidget(m_table); - setLayout(layout); -} - -void TrafficPanel::CreateTable(QAbstractItemModel * trafficModel) -{ - m_table = new QTableView(); - m_table->setFocusPolicy(Qt::NoFocus); - m_table->setAlternatingRowColors(true); - m_table->setShowGrid(false); - m_table->setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows); - m_table->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection); - m_table->verticalHeader()->setVisible(false); - m_table->horizontalHeader()->setVisible(false); - m_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); - - m_table->setModel(trafficModel); - m_table->setItemDelegate(new ComboBoxDelegate()); - - connect(m_table->selectionModel(), - SIGNAL(selectionChanged(QItemSelection const &, QItemSelection const &)), - trafficModel, SLOT(OnItemSelected(QItemSelection const &, QItemSelection const &))); -} diff --git a/qt/traffic_panel.hpp b/qt/traffic_panel.hpp deleted file mode 100644 index 0cf25e3357..0000000000 --- a/qt/traffic_panel.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include - -class QAbstractItemModel; -class QComboBox; -class QTableView; -class QWidget; - -class ComboBoxDelegate : public QStyledItemDelegate -{ - Q_OBJECT - -public: - ComboBoxDelegate(QObject * parent = 0); - - QWidget * createEditor(QWidget * parent, QStyleOptionViewItem const & option, - QModelIndex const & index) const Q_DECL_OVERRIDE; - - void setEditorData(QWidget * editor, QModelIndex const & index) const Q_DECL_OVERRIDE; - - void setModelData(QWidget * editor, QAbstractItemModel * model, - QModelIndex const & index) const Q_DECL_OVERRIDE; - - void updateEditorGeometry(QWidget * editor, QStyleOptionViewItem const & option, - QModelIndex const & index) const Q_DECL_OVERRIDE; -}; - -class TrafficPanel : public QWidget -{ - Q_OBJECT - -public: - explicit TrafficPanel(QAbstractItemModel * trafficModel, QWidget * parent); - -private: - void CreateTable(QAbstractItemModel * trafficModel); - void FillTable(); - -signals: - -public slots: - // void OnCheckBoxClicked(int row, int state); - -private: - QTableView * m_table = Q_NULLPTR; -}; diff --git a/qt/trafficmodeinitdlg.cpp b/qt/trafficmodeinitdlg.cpp deleted file mode 100644 index 2484a2bd34..0000000000 --- a/qt/trafficmodeinitdlg.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "qt/trafficmodeinitdlg.h" -#include "ui_trafficmodeinitdlg.h" - -#include "platform/settings.hpp" - -#include - -namespace -{ -string const kDataFilePath = "LastTrafficDataFilePath"; -string const kSampleFilePath = "LastTrafficSampleFilePath"; -} // namespace - -TrafficModeInitDlg::TrafficModeInitDlg(QWidget * parent) : - QDialog(parent), - m_ui(new Ui::TrafficModeInitDlg) -{ - m_ui->setupUi(this); - - string lastDataFilePath; - string lastSampleFilePath; - if (settings::Get(kDataFilePath, lastDataFilePath)) - m_ui->dataFileName->setText(QString::fromStdString(lastDataFilePath)); - if (settings::Get(kSampleFilePath, lastSampleFilePath)) - m_ui->sampleFileName->setText(QString::fromStdString(lastSampleFilePath)); - - connect(m_ui->chooseDataFileButton, &QPushButton::clicked, [this](bool) - { - SetFilePathViaDialog(*m_ui->dataFileName, tr("Choose traffic data file"), "*.xml"); - }); - connect(m_ui->chooseSampleFileButton, &QPushButton::clicked, [this](bool) - { - SetFilePathViaDialog(*m_ui->sampleFileName, tr("Choose traffic sample file")); - }); -} - -TrafficModeInitDlg::~TrafficModeInitDlg() -{ - delete m_ui; -} - -void TrafficModeInitDlg::accept() -{ - m_dataFileName = m_ui->dataFileName->text().trimmed().toStdString(); - m_sampleFileName = m_ui->sampleFileName->text().trimmed().toStdString(); - - settings::Set(kDataFilePath, m_dataFileName); - settings::Set(kSampleFilePath, m_sampleFileName); - - QDialog::accept(); -} - -void TrafficModeInitDlg::SetFilePathViaDialog(QLineEdit & dest, QString const & title, - QString const & filter) -{ - QFileDialog openFileDlg(nullptr, title, {} /* directory */, filter); - openFileDlg.exec(); - if (openFileDlg.result() != QDialog::DialogCode::Accepted) - return; - - dest.setText(openFileDlg.selectedFiles().first()); -} diff --git a/qt/trafficmodeinitdlg.h b/qt/trafficmodeinitdlg.h deleted file mode 100644 index b790e626d7..0000000000 --- a/qt/trafficmodeinitdlg.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include - -#include - -class QLineEdit; - -namespace Ui { -class TrafficModeInitDlg; -} - -class TrafficModeInitDlg : public QDialog -{ - Q_OBJECT - -public: - explicit TrafficModeInitDlg(QWidget * parent = nullptr); - ~TrafficModeInitDlg(); - - std::string GetDataFilePath() const { return m_dataFileName; } - std::string GetSampleFilePath() const { return m_sampleFileName; } - -private: - void SetFilePathViaDialog(QLineEdit & dest, QString const & title, - QString const & filter = {}); -public slots: - void accept() override; - -private: - Ui::TrafficModeInitDlg * m_ui; - - std::string m_dataFileName; - std::string m_sampleFileName; -}; diff --git a/qt/trafficmodeinitdlg.ui b/qt/trafficmodeinitdlg.ui deleted file mode 100644 index 1ce7c4fe58..0000000000 --- a/qt/trafficmodeinitdlg.ui +++ /dev/null @@ -1,128 +0,0 @@ - - - TrafficModeInitDlg - - - - 0 - 0 - 478 - 130 - - - - Select traffic files - - - true - - - - - 20 - 10 - 441 - 111 - - - - - - - Choose... - - - - - - - true - - - <html><head/><body><p>Traffic data:</p></body></html> - - - - - - - - - - - - - - - - - Ok - - - - - - - Traffic sample: - - - - - - - Choose... - - - - - - - Cancel - - - - - - - - dataFileName - chooseDataFileButton - sampleFileName - chooseSampleFileButton - - - - - cancelButton - clicked() - TrafficModeInitDlg - reject() - - - 290 - 103 - - - 164 - 98 - - - - - okButton - clicked() - TrafficModeInitDlg - accept() - - - 405 - 105 - - - 59 - 94 - - - - - -- cgit v1.2.3