ExamplesListModel: Remove direct access of model items variable

Change-Id: I8dc2833f61fe0267953acfa8746151cea893c7f3
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Eike Ziller
2023-01-16 17:20:56 +01:00
parent e3acf9262b
commit 6c6277bc7d
4 changed files with 55 additions and 28 deletions

View File

@@ -144,9 +144,7 @@ ListModel::ListModel(QObject *parent)
ListModel::~ListModel()
{
if (m_ownsItems)
qDeleteAll(m_items);
m_items.clear();
clear();
}
void ListModel::appendItems(const QList<ListItem *> &items)
@@ -161,6 +159,15 @@ const QList<ListItem *> ListModel::items() const
return m_items;
}
void ListModel::clear()
{
beginResetModel();
if (m_ownsItems)
qDeleteAll(m_items);
m_items.clear();
endResetModel();
}
int ListModel::rowCount(const QModelIndex &) const
{
return m_items.size();
@@ -695,6 +702,7 @@ ListModel *SectionedGridView::addSection(const Section &section, const QList<Lis
const auto it = m_gridViews.insert(section, gridView);
auto sectionLabel = new QLabel(section.name);
m_sectionLabels.append(sectionLabel);
sectionLabel->setContentsMargins(0, Core::WelcomePageHelpers::ItemGap, 0, 0);
sectionLabel->setFont(Core::WelcomePageHelpers::brandFont());
auto scrollArea = qobject_cast<QScrollArea *>(widget(0));
@@ -713,4 +721,16 @@ ListModel *SectionedGridView::addSection(const Section &section, const QList<Lis
return model;
}
void SectionedGridView::clear()
{
auto allProducts = static_cast<ListModel *>(m_filteredAllItemsModel->sourceModel());
allProducts->clear();
qDeleteAll(m_sectionModels);
qDeleteAll(m_sectionLabels);
qDeleteAll(m_gridViews);
m_sectionModels.clear();
m_sectionLabels.clear();
m_gridViews.clear();
}
} // namespace Core