forked from qt-creator/qt-creator
ExamplesListModel: Remove direct access of model items variable
Change-Id: I8dc2833f61fe0267953acfa8746151cea893c7f3 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -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 §ion, 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 §ion, 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
|
||||
|
||||
Reference in New Issue
Block a user