Qt: More memory leak fixes

This commit is contained in:
Vicki Pfau 2018-07-05 20:30:47 -07:00
parent 8fdfa130bd
commit cc0d582b38
3 changed files with 12 additions and 6 deletions

View File

@ -45,10 +45,10 @@ LibraryController::LibraryController(QWidget* parent, const QString& path, Confi
mLibraryAttachGameDB(m_library.get(), GBAApp::app()->gameDB()); mLibraryAttachGameDB(m_library.get(), GBAApp::app()->gameDB());
m_libraryTree = new LibraryTree(this); m_libraryTree = std::make_unique<LibraryTree>(this);
addWidget(m_libraryTree->widget()); addWidget(m_libraryTree->widget());
m_libraryGrid = new LibraryGrid(this); m_libraryGrid = std::make_unique<LibraryGrid>(this);
addWidget(m_libraryGrid->widget()); addWidget(m_libraryGrid->widget());
setViewStyle(LibraryStyle::STYLE_LIST); setViewStyle(LibraryStyle::STYLE_LIST);
@ -67,9 +67,9 @@ void LibraryController::setViewStyle(LibraryStyle newStyle) {
AbstractGameList* newCurrentList = nullptr; AbstractGameList* newCurrentList = nullptr;
if (newStyle == LibraryStyle::STYLE_LIST || newStyle == LibraryStyle::STYLE_TREE) { if (newStyle == LibraryStyle::STYLE_LIST || newStyle == LibraryStyle::STYLE_TREE) {
newCurrentList = m_libraryTree; newCurrentList = m_libraryTree.get();
} else { } else {
newCurrentList = m_libraryGrid; newCurrentList = m_libraryGrid.get();
} }
newCurrentList->selectEntry(selectedEntry()); newCurrentList->selectEntry(selectedEntry());
newCurrentList->setViewStyle(newStyle); newCurrentList->setViewStyle(newStyle);

View File

@ -107,8 +107,8 @@ private:
LibraryStyle m_currentStyle; LibraryStyle m_currentStyle;
AbstractGameList* m_currentList = nullptr; AbstractGameList* m_currentList = nullptr;
LibraryGrid* m_libraryGrid = nullptr; std::unique_ptr<LibraryGrid> m_libraryGrid;
LibraryTree* m_libraryTree = nullptr; std::unique_ptr<LibraryTree> m_libraryTree;
}; };
} }

View File

@ -62,6 +62,12 @@ LibraryTree::LibraryTree(LibraryController* parent)
}); });
} }
LibraryTree::~LibraryTree() {
for (QTreeWidgetItem* i : m_items.values()) {
delete i;
}
}
void LibraryTree::resizeAllCols() { void LibraryTree::resizeAllCols() {
for (int i = 0; i < m_widget->columnCount(); i++) { for (int i = 0; i < m_widget->columnCount(); i++) {
m_widget->resizeColumnToContents(i); m_widget->resizeColumnToContents(i);