diff --git a/src/ui/form/conn/connectionswindow.cpp b/src/ui/form/conn/connectionswindow.cpp index e3ba6a28..8ca294e9 100644 --- a/src/ui/form/conn/connectionswindow.cpp +++ b/src/ui/form/conn/connectionswindow.cpp @@ -29,6 +29,8 @@ ConnectionsWindow::ConnectionsWindow(FortManager *fortManager, QWidget *parent) { setupUi(); setupController(); + + syncAutoScroll(); } void ConnectionsWindow::setupController() @@ -193,27 +195,14 @@ void ConnectionsWindow::setupLogBlockedIp() void ConnectionsWindow::setupAutoScroll() { - const auto syncAutoScroll = [&] { - if (settings()->connAutoScroll()) { - connect(connListModel(), &QAbstractItemModel::rowsInserted, m_connListView, - &QAbstractItemView::scrollToBottom); - } else { - disconnect(connListModel(), &QAbstractItemModel::rowsInserted, m_connListView, - &QAbstractItemView::scrollToBottom); - } - }; + m_cbAutoScroll = ControlUtil::createCheckBox(settings()->connAutoScroll(), [&](bool checked) { + if (settings()->connAutoScroll() == checked) + return; - syncAutoScroll(); + settings()->setConnAutoScroll(checked); - m_cbAutoScroll = ControlUtil::createCheckBox( - settings()->connAutoScroll(), [&, syncAutoScroll](bool checked) { - if (settings()->connAutoScroll() == checked) - return; - - settings()->setConnAutoScroll(checked); - - syncAutoScroll(); - }); + syncAutoScroll(); + }); } void ConnectionsWindow::setupTableConnList() @@ -281,6 +270,19 @@ void ConnectionsWindow::setupTableConnsChanged() connect(m_connListView, &TableView::currentIndexChanged, this, refreshTableConnsChanged); } +void ConnectionsWindow::syncAutoScroll() +{ + if (settings()->connAutoScroll()) { + connect(connListModel(), &QAbstractItemModel::rowsInserted, m_connListView, + &QAbstractItemView::scrollToBottom); + + m_connListView->scrollToBottom(); + } else { + disconnect(connListModel(), &QAbstractItemModel::rowsInserted, m_connListView, + &QAbstractItemView::scrollToBottom); + } +} + void ConnectionsWindow::deleteConn(int row) { const auto connRow = connListModel()->connRowAt(row); diff --git a/src/ui/form/conn/connectionswindow.h b/src/ui/form/conn/connectionswindow.h index f147581c..932238f1 100644 --- a/src/ui/form/conn/connectionswindow.h +++ b/src/ui/form/conn/connectionswindow.h @@ -42,6 +42,8 @@ private: void setupAppInfoRow(); void setupTableConnsChanged(); + void syncAutoScroll(); + void deleteConn(int row); void deleteSelectedConns();