1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-17 12:02:48 +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, void MergedProxyModel::AddSubModel(const QModelIndex& source_parent,
const QAbstractItemModel* submodel) { const QAbstractItemModel* submodel) {
merge_points_.insert(submodel, source_parent); merge_points_.insert(submodel, source_parent);
@ -68,11 +80,7 @@ void MergedProxyModel::setSourceModel(QAbstractItemModel* source_model) {
void MergedProxyModel::SourceModelReset() { void MergedProxyModel::SourceModelReset() {
// Delete all mappings // Delete all mappings
MappingContainer::index<tag_by_pointer>::type::iterator begin = DeleteAllMappings();
mappings_.get<tag_by_pointer>().begin();
MappingContainer::index<tag_by_pointer>::type::iterator end =
mappings_.get<tag_by_pointer>().end();
qDeleteAll(begin, end);
// Clear the containers // Clear the containers
mappings_.clear(); mappings_.clear();

View File

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