Remember last page of settings category

This commit is contained in:
Martchus 2016-09-08 23:34:39 +02:00
parent 5d9b3e8be4
commit 40fba1a3df
3 changed files with 32 additions and 3 deletions

View File

@ -12,7 +12,8 @@ namespace Dialogs {
* \brief Constructs a option category.
*/
OptionCategory::OptionCategory(QObject *parent) :
QObject(parent)
QObject(parent),
m_currentIndex(0)
{}
/*!

View File

@ -31,6 +31,8 @@ public:
bool applyAllPages();
void resetAllPages();
bool matches(const QString &searchKeyWord) const;
int currentIndex() const;
void setCurrentIndex(int currentIndex);
Q_SIGNALS:
void displayNameChanged();
@ -41,7 +43,7 @@ private:
QString m_displayName;
QIcon m_icon;
QList<OptionPage *> m_pages;
int m_currentIndex;
};
/*!
@ -86,6 +88,25 @@ inline const QList<OptionPage *> OptionCategory::pages() const
return m_pages;
}
/*!
* \brief Returns the index of the currently shown page.
* \remarks The returned index might be invalid/out of range.
* \sa setCurrentIndex()
*/
inline int OptionCategory::currentIndex() const
{
return m_currentIndex;
}
/*!
* \brief Sets the current index.
* \sa currentIndex()
*/
inline void OptionCategory::setCurrentIndex(int currentIndex)
{
m_currentIndex = currentIndex;
}
}
#endif // DIALOGS_OPTIONSCATEGORY_H

View File

@ -129,6 +129,9 @@ void SettingsDialog::currentCategoryChanged(const QModelIndex &index)
*/
void SettingsDialog::showCategory(OptionCategory *category)
{
if(m_currentCategory) {
m_currentCategory->setCurrentIndex(m_ui->pagesTabWidget->currentIndex());
}
if(category) {
if(m_currentCategory != category) {
m_currentCategory = category;
@ -168,7 +171,7 @@ void SettingsDialog::updateTabWidget()
if(m_currentCategory) {
m_ui->pagesTabWidget->setUpdatesEnabled(false);
const QString searchKeyWord = m_ui->filterLineEdit->text();
int index = 0;
int index = 0, pageIndex = 0;
for(OptionPage *page : m_currentCategory->pages()) {
if(page->matches(searchKeyWord)) {
QScrollArea *scrollArea;
@ -192,6 +195,10 @@ void SettingsDialog::updateTabWidget()
scrollArea->setWidget(page->widget());
++index;
}
if(pageIndex == m_currentCategory->currentIndex()) {
m_ui->pagesTabWidget->setCurrentIndex(pageIndex);
}
++pageIndex;
}
while(index < m_ui->pagesTabWidget->count()) {
QScrollArea *scrollArea = qobject_cast<QScrollArea *>(m_ui->pagesTabWidget->widget(index));