Improve parameter-passing in settings classes
* Pass QList by const ref * Construct QList/QVector from initializer list
This commit is contained in:
parent
9908190722
commit
2772bad471
|
@ -79,11 +79,10 @@ bool OptionCategory::matches(const QString &searchKeyWord) const
|
||||||
* Previously assigned pages get deleted. The pagesChanged() signal is emitted.
|
* Previously assigned pages get deleted. The pagesChanged() signal is emitted.
|
||||||
* The category takes ownership over the given \a pages.
|
* The category takes ownership over the given \a pages.
|
||||||
*/
|
*/
|
||||||
void OptionCategory::assignPages(const QList<OptionPage *> pages)
|
void OptionCategory::assignPages(const QList<OptionPage *> &pages)
|
||||||
{
|
{
|
||||||
qDeleteAll(m_pages);
|
qDeleteAll(m_pages);
|
||||||
m_pages = pages;
|
emit pagesChanged(m_pages = pages);
|
||||||
emit pagesChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -25,8 +25,8 @@ public:
|
||||||
void setDisplayName(const QString &displayName);
|
void setDisplayName(const QString &displayName);
|
||||||
const QIcon &icon() const;
|
const QIcon &icon() const;
|
||||||
void setIcon(const QIcon &icon);
|
void setIcon(const QIcon &icon);
|
||||||
const QList<OptionPage *> pages() const;
|
const QList<OptionPage *> &pages() const;
|
||||||
void assignPages(const QList<OptionPage *> pages);
|
void assignPages(const QList<OptionPage *> &pages);
|
||||||
bool applyAllPages();
|
bool applyAllPages();
|
||||||
void resetAllPages();
|
void resetAllPages();
|
||||||
bool matches(const QString &searchKeyWord) const;
|
bool matches(const QString &searchKeyWord) const;
|
||||||
|
@ -34,9 +34,9 @@ public:
|
||||||
void setCurrentIndex(int currentIndex);
|
void setCurrentIndex(int currentIndex);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void displayNameChanged();
|
void displayNameChanged(const QString &displayName);
|
||||||
void iconChanged();
|
void iconChanged(const QIcon &icon);
|
||||||
void pagesChanged();
|
void pagesChanged(const QList<OptionPage *> &pages);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_displayName;
|
QString m_displayName;
|
||||||
|
@ -58,8 +58,7 @@ inline const QString &OptionCategory::displayName() const
|
||||||
*/
|
*/
|
||||||
inline void OptionCategory::setDisplayName(const QString &displayName)
|
inline void OptionCategory::setDisplayName(const QString &displayName)
|
||||||
{
|
{
|
||||||
m_displayName = displayName;
|
emit displayNameChanged(m_displayName = displayName);
|
||||||
emit displayNameChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -75,14 +74,13 @@ inline const QIcon &OptionCategory::icon() const
|
||||||
*/
|
*/
|
||||||
inline void OptionCategory::setIcon(const QIcon &icon)
|
inline void OptionCategory::setIcon(const QIcon &icon)
|
||||||
{
|
{
|
||||||
m_icon = icon;
|
emit iconChanged(m_icon = icon);
|
||||||
emit iconChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Returns the assigned pages.
|
* \brief Returns the assigned pages.
|
||||||
*/
|
*/
|
||||||
inline const QList<OptionPage *> OptionCategory::pages() const
|
inline const QList<OptionPage *> &OptionCategory::pages() const
|
||||||
{
|
{
|
||||||
return m_pages;
|
return m_pages;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ OptionCategoryModel::~OptionCategoryModel()
|
||||||
*
|
*
|
||||||
* The model takes ownership over the given \a categories.
|
* The model takes ownership over the given \a categories.
|
||||||
*/
|
*/
|
||||||
void OptionCategoryModel::setCategories(const QList<OptionCategory *> categories)
|
void OptionCategoryModel::setCategories(const QList<OptionCategory *> &categories)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
qDeleteAll(m_categories);
|
qDeleteAll(m_categories);
|
||||||
|
@ -97,7 +97,7 @@ void OptionCategoryModel::categoryChangedName()
|
||||||
for (int i = 0, end = m_categories.size(); i < end; ++i) {
|
for (int i = 0, end = m_categories.size(); i < end; ++i) {
|
||||||
if (senderCategory == m_categories.at(i)) {
|
if (senderCategory == m_categories.at(i)) {
|
||||||
QModelIndex index = this->index(i);
|
QModelIndex index = this->index(i);
|
||||||
emit dataChanged(index, index, QVector<int>() << Qt::DisplayRole);
|
emit dataChanged(index, index, QVector<int>({ Qt::DisplayRole }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ void OptionCategoryModel::categoryChangedIcon()
|
||||||
for (int i = 0, end = m_categories.size(); i < end; ++i) {
|
for (int i = 0, end = m_categories.size(); i < end; ++i) {
|
||||||
if (senderCategory == m_categories.at(i)) {
|
if (senderCategory == m_categories.at(i)) {
|
||||||
QModelIndex index = this->index(i);
|
QModelIndex index = this->index(i);
|
||||||
emit dataChanged(index, index, QVector<int>() << Qt::DecorationRole);
|
emit dataChanged(index, index, QVector<int>({ Qt::DecorationRole }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public:
|
||||||
const QList<OptionCategory *> &categories() const;
|
const QList<OptionCategory *> &categories() const;
|
||||||
OptionCategory *category(const QModelIndex &index) const;
|
OptionCategory *category(const QModelIndex &index) const;
|
||||||
OptionCategory *category(int row) const;
|
OptionCategory *category(int row) const;
|
||||||
void setCategories(const QList<OptionCategory *> categories);
|
void setCategories(const QList<OptionCategory *> &categories);
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
|
|
|
@ -172,7 +172,7 @@ void SettingsDialog::setSingleCategory(OptionCategory *singleCategory)
|
||||||
m_ui->headingLabel->setHidden(hasSingleCategory);
|
m_ui->headingLabel->setHidden(hasSingleCategory);
|
||||||
if (hasSingleCategory) {
|
if (hasSingleCategory) {
|
||||||
m_ui->filterLineEdit->clear();
|
m_ui->filterLineEdit->clear();
|
||||||
categoryModel()->setCategories(QList<OptionCategory *>() << singleCategory);
|
categoryModel()->setCategories(QList<OptionCategory *>({ singleCategory }));
|
||||||
showCategory(singleCategory);
|
showCategory(singleCategory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue