Skip to content

Commit

Permalink
UI: OptionsWindow: Fix conf usage after applying changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tnodir committed Jan 22, 2020
1 parent bcaf7db commit 597cdd9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
20 changes: 15 additions & 5 deletions src/ui/form/opt/pages/addressespage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -197,15 +202,20 @@ void AddressesPage::setupAddressGroup()

const auto refreshAddressGroup = [&] {
const int tabIndex = m_tabBar->currentIndex();
setAddressGroup(addressGroupByIndex(tabIndex));
setAddressGroupIndex(tabIndex);
};

refreshAddressGroup();

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);
}
9 changes: 6 additions & 3 deletions src/ui/form/opt/pages/addressespage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
26 changes: 18 additions & 8 deletions src/ui/form/opt/pages/applicationspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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());
}

Expand All @@ -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());
}

Expand Down Expand Up @@ -532,22 +537,27 @@ void ApplicationsPage::setupAppGroup()

const auto refreshAppGroup = [&] {
const int tabIndex = m_tabBar->currentIndex();
setAppGroup(appGroupByIndex(tabIndex));
setAppGroupIndex(tabIndex);
};

refreshAppGroup();

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()
Expand Down
9 changes: 6 additions & 3 deletions src/ui/form/opt/pages/applicationspage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit 597cdd9

Please sign in to comment.