GUI: attachments: fix deleting attachments

The page was removed from the view and deleted, but it wasn't removed
from the model's internal list of pages. Therefore the it got deleted a
second time upon model reset leading to a segfault.
This commit is contained in:
Moritz Bunkus 2016-01-02 10:42:42 +01:00
parent 1dd074c9ea
commit 858b101513
3 changed files with 14 additions and 2 deletions

View File

@ -50,6 +50,18 @@ PageModel::appendPage(PageBase *page,
m_topLevelPages << page;
}
bool
PageModel::deletePage(PageBase *page) {
auto idx = m_pages.indexOf(page);
if (idx == -1)
return false;
m_pages.removeAt(idx);
delete page;
return true;
}
QList<PageBase *> &
PageModel::pages() {
return m_pages;

View File

@ -24,6 +24,7 @@ public:
PageBase *selectedPage(QModelIndex const &idx) const;
void appendPage(PageBase *page, QModelIndex const &parentIdx = {});
bool deletePage(PageBase *page);
QList<PageBase *> &pages();
QList<PageBase *> &topLevelPages();

View File

@ -633,8 +633,7 @@ Tab::removeSelectedAttachment() {
m_model->removeRow(idx.row(), idx.parent());
m_attachmentsPage->m_children.removeAll(selectedPage);
delete selectedPage;
m_model->deletePage(selectedPage);
}
KaxAttachedPtr