Skip to content
This repository has been archived by the owner on Dec 10, 2019. It is now read-only.

Optimize the connection steps #624

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/connectiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,15 @@ void ConnectionTableModel::onConnectionLatencyChanged()
int row = items.indexOf(item);
emit dataChanged(this->index(row, 3), this->index(row, 3));
}

ConnectionItem* ConnectionTableModel::getRunningItem() const
{
for (auto &i : items) {
Connection *conn = i->getConnection();
if (conn && conn->isRunning()) {
return i;
}
}

return NULL;
}
1 change: 1 addition & 0 deletions src/connectiontablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ConnectionTableModel : public QAbstractTableModel
~ConnectionTableModel();

ConnectionItem *getItem(const int &row) const;
ConnectionItem* getRunningItem() const;
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 = Qt::DisplayRole) const Q_DECL_OVERRIDE;
Expand Down
6 changes: 6 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ void MainWindow::onConnect()
{
int row = proxyModel->mapToSource(ui->connectionView->currentIndex()).row();
Connection *con = model->getItem(row)->getConnection();

ConnectionItem* item = model->getRunningItem();
if (item && item != model->getItem(row)) {
item->getConnection()->stop();
}

if (con->isValid()) {
con->start();
} else {
Expand Down