diff --git a/src/ui/form/opt/pages/addressespage.cpp b/src/ui/form/opt/pages/addressespage.cpp index 9979c76d0..9460ea3c7 100644 --- a/src/ui/form/opt/pages/addressespage.cpp +++ b/src/ui/form/opt/pages/addressespage.cpp @@ -28,10 +28,15 @@ AddressesPage::AddressesPage(OptionsController *ctrl, setupAddressGroup(); } -void AddressesPage::setAddressGroup(AddressGroup *v) +AddressGroup *AddressesPage::addressGroup() const { - if (m_addressGroup != v) { - m_addressGroup = v; + return addressGroupByIndex(addressGroupIndex()); +} + +void AddressesPage::setAddressGroupIndex(int v) +{ + if (m_addressGroupIndex != v) { + m_addressGroupIndex = v; emit addressGroupChanged(); } } @@ -197,7 +202,7 @@ void AddressesPage::setupAddressGroup() const auto refreshAddressGroup = [&] { const int tabIndex = m_tabBar->currentIndex(); - setAddressGroup(addressGroupByIndex(tabIndex)); + setAddressGroupIndex(tabIndex); }; refreshAddressGroup(); @@ -205,7 +210,12 @@ void AddressesPage::setupAddressGroup() connect(m_tabBar, &QTabBar::currentChanged, this, refreshAddressGroup); } +const QList<AddressGroup *> &AddressesPage::addressGroups() const +{ + return conf()->addressGroups(); +} + AddressGroup *AddressesPage::addressGroupByIndex(int index) const { - return conf()->addressGroups().at(index); + return addressGroups().at(index); } diff --git a/src/ui/form/opt/pages/addressespage.h b/src/ui/form/opt/pages/addressespage.h index b73213204..1930245e8 100644 --- a/src/ui/form/opt/pages/addressespage.h +++ b/src/ui/form/opt/pages/addressespage.h @@ -14,8 +14,10 @@ class AddressesPage : public BasePage explicit AddressesPage(OptionsController *ctrl = nullptr, QWidget *parent = nullptr); - AddressGroup *addressGroup() const { return m_addressGroup; } - void setAddressGroup(AddressGroup *v); + AddressGroup *addressGroup() const; + + int addressGroupIndex() const { return m_addressGroupIndex; } + void setAddressGroupIndex(int v); signals: void addressGroupChanged(); @@ -37,10 +39,11 @@ protected slots: void updateGroup(); void setupAddressGroup(); + const QList<AddressGroup *> &addressGroups() const; AddressGroup *addressGroupByIndex(int index) const; private: - AddressGroup *m_addressGroup = nullptr; + int m_addressGroupIndex = -1; QTabBar *m_tabBar = nullptr; AddressesColumn *m_includeAddresses = nullptr; diff --git a/src/ui/form/opt/pages/applicationspage.cpp b/src/ui/form/opt/pages/applicationspage.cpp index 7ea8e6642..a7c8e3050 100644 --- a/src/ui/form/opt/pages/applicationspage.cpp +++ b/src/ui/form/opt/pages/applicationspage.cpp @@ -44,10 +44,15 @@ ApplicationsPage::ApplicationsPage(OptionsController *ctrl, setupAppGroup(); } -void ApplicationsPage::setAppGroup(AppGroup *v) +AppGroup *ApplicationsPage::appGroup() const { - if (m_appGroup != v) { - m_appGroup = v; + return appGroupByIndex(appGroupIndex()); +} + +void ApplicationsPage::setAppGroupIndex(int v) +{ + if (m_appGroupIndex != v) { + m_appGroupIndex = v; emit appGroupChanged(); } } @@ -253,7 +258,7 @@ void ApplicationsPage::setupTabBar() m_tabBar->setTabsClosable(true); m_tabBar->setMovable(true); - for (const auto appGroup : conf()->appGroups()) { + for (const auto appGroup : appGroups()) { addTab(appGroup->name()); } @@ -264,7 +269,7 @@ void ApplicationsPage::setupTabBar() m_tabBar->removeTab(index); } else { // Reset alone tab to default one - setAppGroup(appGroupByIndex(0)); + setAppGroupIndex(0); m_tabBar->setTabText(0, appGroup()->name()); } @@ -532,7 +537,7 @@ void ApplicationsPage::setupAppGroup() const auto refreshAppGroup = [&] { const int tabIndex = m_tabBar->currentIndex(); - setAppGroup(appGroupByIndex(tabIndex)); + setAppGroupIndex(tabIndex); }; refreshAppGroup(); @@ -540,14 +545,19 @@ void ApplicationsPage::setupAppGroup() connect(m_tabBar, &QTabBar::currentChanged, this, refreshAppGroup); } +const QList<AppGroup *> &ApplicationsPage::appGroups() const +{ + return conf()->appGroups(); +} + int ApplicationsPage::appGroupsCount() const { - return conf()->appGroups().size(); + return appGroups().size(); } AppGroup *ApplicationsPage::appGroupByIndex(int index) const { - return conf()->appGroups().at(index); + return appGroups().at(index); } void ApplicationsPage::resetGroupName() diff --git a/src/ui/form/opt/pages/applicationspage.h b/src/ui/form/opt/pages/applicationspage.h index ae280cbf9..26e756817 100644 --- a/src/ui/form/opt/pages/applicationspage.h +++ b/src/ui/form/opt/pages/applicationspage.h @@ -18,8 +18,10 @@ class ApplicationsPage : public BasePage explicit ApplicationsPage(OptionsController *ctrl = nullptr, QWidget *parent = nullptr); - AppGroup *appGroup() const { return m_appGroup; } - void setAppGroup(AppGroup *v); + AppGroup *appGroup() const; + + int appGroupIndex() const { return m_appGroupIndex; } + void setAppGroupIndex(int v); signals: void appGroupChanged(); @@ -56,6 +58,7 @@ protected slots: void updateGroup(); void setupAppGroup(); + const QList<AppGroup *> &appGroups() const; int appGroupsCount() const; AppGroup *appGroupByIndex(int index) const; void resetGroupName(); @@ -65,7 +68,7 @@ protected slots: static QString formatSpeed(int kbytes); private: - AppGroup *m_appGroup = nullptr; + int m_appGroupIndex = -1; QLineEdit *m_editGroupName = nullptr; QPushButton *m_btAddGroup = nullptr;