Properly destruct added KoPageWidgetItems on destruction of KoDocumentInfoDlg

Fixes crash when semantic items are inserted after the dialog incl. the rdf page was shown & closed

REVIEW: 113664

thanks boud for review
parent 2ba03dc8
...@@ -44,6 +44,25 @@ ...@@ -44,6 +44,25 @@
#include <QPixmap> #include <QPixmap>
#include <QDateTime> #include <QDateTime>
class KoPageWidgetItemAdapter : public KPageWidgetItem
{
public:
KoPageWidgetItemAdapter(KoPageWidgetItem *item)
: KPageWidgetItem(item->widget(), item->name())
, m_item(item)
{
setHeader(item->name());
setIcon(KIcon(item->iconName()));
}
~KoPageWidgetItemAdapter() { delete m_item; }
bool shouldDialogCloseBeVetoed() { return m_item->shouldDialogCloseBeVetoed(); }
void apply() { m_item->apply(); }
private:
KoPageWidgetItem * const m_item;
};
class KoDocumentInfoDlg::KoDocumentInfoDlgPrivate class KoDocumentInfoDlg::KoDocumentInfoDlgPrivate
{ {
...@@ -141,7 +160,7 @@ void KoDocumentInfoDlg::slotButtonClicked(int button) ...@@ -141,7 +160,7 @@ void KoDocumentInfoDlg::slotButtonClicked(int button)
switch (button) { switch (button) {
case Ok: case Ok:
foreach(KPageWidgetItem* item, d->pages) { foreach(KPageWidgetItem* item, d->pages) {
KoPageWidgetItem *page = dynamic_cast<KoPageWidgetItem*>(item); KoPageWidgetItemAdapter *page = dynamic_cast<KoPageWidgetItemAdapter*>(item);
if (page) { if (page) {
if (page->shouldDialogCloseBeVetoed()) { if (page->shouldDialogCloseBeVetoed()) {
return; return;
...@@ -252,7 +271,7 @@ void KoDocumentInfoDlg::slotApply() ...@@ -252,7 +271,7 @@ void KoDocumentInfoDlg::slotApply()
{ {
saveAboutData(); saveAboutData();
foreach(KPageWidgetItem* item, d->pages) { foreach(KPageWidgetItem* item, d->pages) {
KoPageWidgetItem *page = dynamic_cast<KoPageWidgetItem*>(item); KoPageWidgetItemAdapter *page = dynamic_cast<KoPageWidgetItemAdapter*>(item);
if (page) { if (page) {
page->apply(); page->apply();
} }
...@@ -437,9 +456,7 @@ void KoDocumentInfoDlg::setReadOnly(bool ro) ...@@ -437,9 +456,7 @@ void KoDocumentInfoDlg::setReadOnly(bool ro)
void KoDocumentInfoDlg::addPageItem(KoPageWidgetItem *item) void KoDocumentInfoDlg::addPageItem(KoPageWidgetItem *item)
{ {
KPageWidgetItem * page = new KPageWidgetItem(item->widget(), item->name()); KPageWidgetItem * page = new KoPageWidgetItemAdapter(item);
page->setHeader(item->name());
page->setIcon(KIcon(item->iconName()));
addPage(page); addPage(page);
d->pages.append(page); d->pages.append(page);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment