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.
|
||||
* 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);
|
||||
m_pages = pages;
|
||||
emit pagesChanged();
|
||||
emit pagesChanged(m_pages = pages);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -25,8 +25,8 @@ public:
|
|||
void setDisplayName(const QString &displayName);
|
||||
const QIcon &icon() const;
|
||||
void setIcon(const QIcon &icon);
|
||||
const QList<OptionPage *> pages() const;
|
||||
void assignPages(const QList<OptionPage *> pages);
|
||||
const QList<OptionPage *> &pages() const;
|
||||
void assignPages(const QList<OptionPage *> &pages);
|
||||
bool applyAllPages();
|
||||
void resetAllPages();
|
||||
bool matches(const QString &searchKeyWord) const;
|
||||
|
@ -34,9 +34,9 @@ public:
|
|||
void setCurrentIndex(int currentIndex);
|
||||
|
||||
Q_SIGNALS:
|
||||
void displayNameChanged();
|
||||
void iconChanged();
|
||||
void pagesChanged();
|
||||
void displayNameChanged(const QString &displayName);
|
||||
void iconChanged(const QIcon &icon);
|
||||
void pagesChanged(const QList<OptionPage *> &pages);
|
||||
|
||||
private:
|
||||
QString m_displayName;
|
||||
|
@ -58,8 +58,7 @@ inline const QString &OptionCategory::displayName() const
|
|||
*/
|
||||
inline void OptionCategory::setDisplayName(const QString &displayName)
|
||||
{
|
||||
m_displayName = displayName;
|
||||
emit displayNameChanged();
|
||||
emit displayNameChanged(m_displayName = displayName);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -75,14 +74,13 @@ inline const QIcon &OptionCategory::icon() const
|
|||
*/
|
||||
inline void OptionCategory::setIcon(const QIcon &icon)
|
||||
{
|
||||
m_icon = icon;
|
||||
emit iconChanged();
|
||||
emit iconChanged(m_icon = icon);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the assigned pages.
|
||||
*/
|
||||
inline const QList<OptionPage *> OptionCategory::pages() const
|
||||
inline const QList<OptionPage *> &OptionCategory::pages() const
|
||||
{
|
||||
return m_pages;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ OptionCategoryModel::~OptionCategoryModel()
|
|||
*
|
||||
* The model takes ownership over the given \a categories.
|
||||
*/
|
||||
void OptionCategoryModel::setCategories(const QList<OptionCategory *> categories)
|
||||
void OptionCategoryModel::setCategories(const QList<OptionCategory *> &categories)
|
||||
{
|
||||
beginResetModel();
|
||||
qDeleteAll(m_categories);
|
||||
|
@ -97,7 +97,7 @@ void OptionCategoryModel::categoryChangedName()
|
|||
for (int i = 0, end = m_categories.size(); i < end; ++i) {
|
||||
if (senderCategory == m_categories.at(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) {
|
||||
if (senderCategory == m_categories.at(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;
|
||||
OptionCategory *category(const QModelIndex &index) 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;
|
||||
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);
|
||||
if (hasSingleCategory) {
|
||||
m_ui->filterLineEdit->clear();
|
||||
categoryModel()->setCategories(QList<OptionCategory *>() << singleCategory);
|
||||
categoryModel()->setCategories(QList<OptionCategory *>({ singleCategory }));
|
||||
showCategory(singleCategory);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue