John Levon wrote:

> On Sat, May 14, 2005 at 03:52:00PM +0100, Angus Leeming wrote:
> 
>> >> This patch, part I, changes nothing in LyX's operation. Well
>> >> actually, that's not quite true; it enables the Qt Alert dialogs to
>> >> know who their parent is so that dialogs are stacked in the correct
>> >> order.
>> > 
>> > Alarm bells are ringing. Gotta go now, remind me to come back to this
>> > one
>> 
>> Ping!
> 
> Hmm, the bells may have been a little over the top. I wonder why this
> already works (i.e. you get modality for e.g. Load emergency save
> alert). Did you make sure to check that adding a parent doesn't mean
> that the parent GC's the widget? (I don't think so)

GC == GarbageCollect? No, I didn't check that. I'll do some reading...
done. We're OK. See below.

To recap, all I have done is:

    QWidget * const parent =
-       0;
+       qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget();

    int res = QMessageBox::information(parent,
                    toqstr(title),
                    toqstr(formatted(question)),
                    toqstr(b1),
                    toqstr(b2),
                    b3.empty() ? QString::null : toqstr(b3),
                    default_button,
                    cancel_button);

If we look at the QMessageBox code, we see that the "parent" is passed to
the underlying QDialog together with a modal==TRUE flag.

int QMessageBox::information( QWidget *parent,
                              const QString& caption, const QString& text,
                              int button0, int button1, int button2 )
{
    QMessageBox *mb = new QMessageBox( caption, text, Information,
                                       button0, button1, button2,
                                       parent, "qt_msgbox_information",
                                       TRUE, WDestructiveClose);
    Q_CHECK_PTR( mb );
    return mb->exec();
}

QMessageBox::QMessageBox( const QString& caption,
                          const QString &text, Icon icon,
                          int button0, int button1, int button2,
                          QWidget *parent, const char *name,
                          bool modal, WFlags f )
    : QDialog( parent, name, modal, f | WStyle_Customize |
WStyle_DialogBorder | WStyle_Title | WStyle_SysMenu )
{
    init( button0, button1, button2 );
#ifndef QT_NO_WIDGET_TOPEXTRA
    setCaption( caption );
#endif
    setText( text );
    setIcon( icon );
}

>From qdialog.cpp:

    Note that QDialog uses the parent widget slightly differently from
    other classes in Qt. A dialog is always a top-level widget, but if
    it has a parent, its default location is centered on top of the
    parent's top-level widget (if it is not top-level itself). It will
    also share the parent's taskbar entry.

    \target modal
    \section1 Modal Dialogs
    A <b>modal</b> dialog is a dialog that blocks input to other
    visible windows in the same application. Users must finish
    interacting with the dialog and close it before they can access
    any other window in the application. Dialogs that are used to
    request a file name from the user or that are used to set
    application preferences are usually modal.

Given that the QDialog destroys itself (the WDestructiveClose flag is set)
before leaving the exec() function, I don't think that we have anything to
worry about.

Now are you happier?

-- 
Angus

Reply via email to