Place the external items at the end

This commit is contained in:
Aleix Pol 2021-07-14 18:03:03 +02:00 committed by Aleix Pol Gonzalez
parent 9dfac82863
commit a97fe3bc02
2 changed files with 15 additions and 6 deletions

View file

@ -31,16 +31,23 @@ int QuickSettingsModel::rowCount(const QModelIndex &parent) const
if (parent.isValid())
return 0;
return m_children.count();
return m_children.count() + m_external.count();
}
QVariant QuickSettingsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= m_children.count() || role != Qt::UserRole) {
if (!index.isValid() || index.row() >= rowCount({}) || role != Qt::UserRole) {
return {};
}
return QVariant::fromValue<QObject *>(m_children[index.row()]);
QObject *obj = nullptr;
if (index.row() < m_children.count()) {
obj = m_children[index.row()];
} else {
obj = m_external[index.row() - m_children.count()];
}
return QVariant::fromValue<QObject *>(obj);
}
void QuickSettingsModel::classBegin()
@ -64,7 +71,7 @@ void QuickSettingsModel::classBegin()
delete created;
continue;
}
include(createdSetting);
m_external += createdSetting;
}
delete c;
}
@ -123,7 +130,8 @@ QQmlListProperty<QObject> QuickSetting::children()
void QuickSettingsModel::include(QuickSetting *item)
{
beginInsertRows({}, m_children.count(), m_children.count());
m_children.append(item);
const int c = m_children.count() + m_external.count();
beginInsertRows({}, c, c);
m_external.append(item);
endInsertRows();
}

View file

@ -87,6 +87,7 @@ Q_SIGNALS:
private:
QList<QuickSetting *> m_children;
QList<QuickSetting *> m_external;
};
#endif // QUICKSETTINGSMODEL_H