From 9db15b953e070d2ff7377b9d130e4cc64ce7659b Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Sun, 25 Mar 2018 03:13:23 +0200 Subject: [PATCH] Implement selection of recent address --- include/f1x/openauto/autoapp/UI/ConnectDialog.hpp | 1 + src/autoapp/Configuration/RecentAddressesList.cpp | 7 +++++-- src/autoapp/UI/ConnectDialog.cpp | 11 +++++++++++ src/autoapp/UI/connectdialog.ui | 3 +++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/f1x/openauto/autoapp/UI/ConnectDialog.hpp b/include/f1x/openauto/autoapp/UI/ConnectDialog.hpp index dcb33263..9e944aa7 100644 --- a/include/f1x/openauto/autoapp/UI/ConnectDialog.hpp +++ b/include/f1x/openauto/autoapp/UI/ConnectDialog.hpp @@ -36,6 +36,7 @@ private slots: void onConnectButtonClicked(); void onConnectionFailed(const QString& message); void onConnectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer socket, const std::string& ipAddress); + void onRecentAddressClicked(const QModelIndex& index); private: void insertIpAddress(const std::string& ipAddress); diff --git a/src/autoapp/Configuration/RecentAddressesList.cpp b/src/autoapp/Configuration/RecentAddressesList.cpp index 7d8af3ec..ebfa2d14 100644 --- a/src/autoapp/Configuration/RecentAddressesList.cpp +++ b/src/autoapp/Configuration/RecentAddressesList.cpp @@ -46,8 +46,11 @@ void RecentAddressesList::read() void RecentAddressesList::insertAddress(const std::string& address) { - list_.push_front(address); - this->save(); + if(std::find(list_.begin(), list_.end(), address) != list_.end()) + { + list_.push_front(address); + this->save(); + } } RecentAddressesList::RecentAddresses RecentAddressesList::getList() const diff --git a/src/autoapp/UI/ConnectDialog.cpp b/src/autoapp/UI/ConnectDialog.cpp index 5e43c171..127e2165 100644 --- a/src/autoapp/UI/ConnectDialog.cpp +++ b/src/autoapp/UI/ConnectDialog.cpp @@ -24,6 +24,7 @@ ConnectDialog::ConnectDialog(boost::asio::io_service& ioService, aasdk::tcp::ITC ui_->setupUi(this); connect(ui_->pushButtonCancel, &QPushButton::clicked, this, &ConnectDialog::close); connect(ui_->pushButtonConnect, &QPushButton::clicked, this, &ConnectDialog::onConnectButtonClicked); + connect(ui_->listViewRecent, &QListView::clicked, this, &ConnectDialog::onRecentAddressClicked); connect(this, &ConnectDialog::connectionSucceed, this, &ConnectDialog::onConnectionSucceed); connect(this, &ConnectDialog::connectionFailed, this, &ConnectDialog::onConnectionFailed); @@ -81,6 +82,16 @@ void ConnectDialog::onConnectionFailed(const QString& message) errorMessage.exec(); } +void ConnectDialog::onRecentAddressClicked(const QModelIndex& index) +{ + const auto& recentAddressesList = recentAddressesList_.getList(); + + if(static_cast(index.row()) <= recentAddressesList.size()) + { + ui_->lineEditIPAddress->setText(QString::fromStdString(recentAddressesList.at(index.row()))); + } +} + void ConnectDialog::setControlsEnabledStatus(bool status) { ui_->pushButtonConnect->setVisible(status); diff --git a/src/autoapp/UI/connectdialog.ui b/src/autoapp/UI/connectdialog.ui index a9adb5d8..445e962c 100644 --- a/src/autoapp/UI/connectdialog.ui +++ b/src/autoapp/UI/connectdialog.ui @@ -57,6 +57,9 @@ 141 + + QAbstractItemView::NoEditTriggers +