1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-17 03:45:56 +01:00

Fix memory leak

This commit is contained in:
David Sansome 2010-05-09 15:53:28 +00:00
parent 6b8d6c93f9
commit 8ce66bcbd2
2 changed files with 15 additions and 5 deletions

View File

@ -25,6 +25,18 @@ MergedProxyModel::MergedProxyModel(QObject* parent)
{
}
MergedProxyModel::~MergedProxyModel() {
DeleteAllMappings();
}
void MergedProxyModel::DeleteAllMappings() {
MappingContainer::index<tag_by_pointer>::type::iterator begin =
mappings_.get<tag_by_pointer>().begin();
MappingContainer::index<tag_by_pointer>::type::iterator end =
mappings_.get<tag_by_pointer>().end();
qDeleteAll(begin, end);
}
void MergedProxyModel::AddSubModel(const QModelIndex& source_parent,
const QAbstractItemModel* submodel) {
merge_points_.insert(submodel, source_parent);
@ -68,11 +80,7 @@ void MergedProxyModel::setSourceModel(QAbstractItemModel* source_model) {
void MergedProxyModel::SourceModelReset() {
// Delete all mappings
MappingContainer::index<tag_by_pointer>::type::iterator begin =
mappings_.get<tag_by_pointer>().begin();
MappingContainer::index<tag_by_pointer>::type::iterator end =
mappings_.get<tag_by_pointer>().end();
qDeleteAll(begin, end);
DeleteAllMappings();
// Clear the containers
mappings_.clear();

View File

@ -39,6 +39,7 @@ class MergedProxyModel : public QAbstractProxyModel {
public:
MergedProxyModel(QObject* parent = 0);
~MergedProxyModel();
void AddSubModel(const QModelIndex& source_parent, const QAbstractItemModel* submodel);
@ -67,6 +68,7 @@ class MergedProxyModel : public QAbstractProxyModel {
private:
QModelIndex GetActualSourceParent(const QModelIndex& source_parent,
const QAbstractItemModel* model) const;
void DeleteAllMappings();
struct Mapping {
Mapping(const QModelIndex& _source_index) : source_index(_source_index) {}