Commit 2080bc1d authored by Vishesh Handa's avatar Vishesh Handa

KEditTagsDialog: Avoid using QDialog::exec

QDialog::exec runs an event loop at waits for the dialog to be closed.
Running another event loop is generally not recommended cause it can
result in *other* events being process which one might not want.

In this particular case the ResourceLoader, which runs in another
thread, would emit the finished signal would result in the
FileMetadataWidget deleting all its previous content, which would
delete the TagWidget and its children aka the KEditTagsDialog => CRASH

Instead we now set the windowModality and use QDialog::open, which
returns immediately and then connect to the finished signal.

BUG: 281342
REVIEW: 108354
parent 7b1b1519
......@@ -120,6 +120,7 @@ void FileMetaDataWidget::Private::deleteRows()
delete row.label;
delete row.value;
}
m_rows.clear();
}
......
......@@ -54,6 +54,7 @@ void Nepomuk2::TagWidgetPrivate::init( TagWidget* parent )
m_flags = TagWidget::StandardMode;
m_blockSelectionChangedSignal = false;
m_showAllLinkLabel = 0;
m_editTagsDialog = 0;
QGridLayout* mainLayout = new QGridLayout( q );
mainLayout->setMargin(0);
......@@ -398,11 +399,21 @@ void Nepomuk2::TagWidget::slotTagUpdateDone()
void Nepomuk2::TagWidget::slotShowAll()
{
KEditTagsDialog dlg( selectedTags(), this );
if( dlg.exec() ) {
setSelectedTags( dlg.tags() );
d->m_editTagsDialog = new KEditTagsDialog( selectedTags(), this );
d->m_editTagsDialog->setWindowModality( Qt::ApplicationModal );
connect( d->m_editTagsDialog, SIGNAL(finished(int)), this, SLOT(slotKEditTagDialogFinished(int)) );
d->m_editTagsDialog->open();
}
void Nepomuk2::TagWidget::slotKEditTagDialogFinished(int result)
{
if( result == QDialog::Accepted ) {
setSelectedTags( d->m_editTagsDialog->tags() );
emit selectionChanged( selectedTags() );
}
d->m_editTagsDialog->deleteLater();
d->m_editTagsDialog = 0;
}
......
......@@ -230,6 +230,7 @@ namespace Nepomuk2 {
void slotShowAll();
void slotTagUpdateDone();
void slotTagStateChanged( const Nepomuk2::Tag&, int );
void slotKEditTagDialogFinished( int result );
private:
TagWidgetPrivate* const d;
......
......@@ -30,6 +30,7 @@
class QPushButton;
class QLabel;
class KBlockLayout;
class KEditTagsDialog;
namespace Nepomuk2 {
......@@ -64,6 +65,8 @@ public:
QLabel* m_showAllLinkLabel;
KBlockLayout* m_flowLayout;
TagWidget* q;
KEditTagsDialog* m_editTagsDialog;
};
}
......
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