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

Commit d3c495a

Browse files
author
sszllx
committed
When initiating a connection, there is no need to disconnect the previous connection.
1 parent 32efa49 commit d3c495a

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/connectiontablemodel.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,15 @@ void ConnectionTableModel::onConnectionLatencyChanged()
149149
int row = items.indexOf(item);
150150
emit dataChanged(this->index(row, 3), this->index(row, 3));
151151
}
152+
153+
ConnectionItem* ConnectionTableModel::getRunningItem() const
154+
{
155+
for (auto &i : items) {
156+
Connection *conn = i->getConnection();
157+
if (conn && conn->isRunning()) {
158+
return i;
159+
}
160+
}
161+
162+
return NULL;
163+
}

src/connectiontablemodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ConnectionTableModel : public QAbstractTableModel
3232
~ConnectionTableModel();
3333

3434
ConnectionItem *getItem(const int &row) const;
35+
ConnectionItem* getRunningItem() const;
3536
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
3637
int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
3738
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;

src/mainwindow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ void MainWindow::onConnect()
296296
{
297297
int row = proxyModel->mapToSource(ui->connectionView->currentIndex()).row();
298298
Connection *con = model->getItem(row)->getConnection();
299+
300+
ConnectionItem* item = model->getRunningItem();
301+
if (item && item != model->getItem(row)) {
302+
item->getConnection()->stop();
303+
}
304+
299305
if (con->isValid()) {
300306
con->start();
301307
} else {

0 commit comments

Comments
 (0)