Modal Dialogs

From ParaQ Wiki
Jump to navigationJump to search

A modal dialog is one that prevents the user from interacting with the rest of the application user interface while open, see http://doc.trolltech.com/4.0/qdialog.html#modal-dialogs

Modal dialogs are normally implemented using their own event loop - the developer calls a function which displays the dialog, enters the loop, and does not return until the dialog is closed. This simplifies coding because the modal dialog acts like a "black box" function that immediately returns data from the user for subsequent processing. The dialog itself can be created on the stack, and no further management of object lifetime is necessary. In Qt, this type of modality is invoked by calling QDialog::exec().

Unfortunately, this type of modal dialog interferes with the execution of UI test cases. A test case that programmatically displays the modal dialog will wait forever in the dialog's event loop, or until a user intervenes. Once the call to display the modal dialog returns, the dialog is already gone, so even with human intervention the test case cannot test the functionality of the dialog itself.

Accordingly, modal dialogs in ParaQ should never be invoked using QDialog::exec(). All dialogs should be coded as *modeless* dialogs, and made visible using QDialog::show(). A call to QDialog::setModal(true) will providal modal *behavior* while a dialog is visible (the rest of the UI is disabled), without executing in a separate event loop.

See pqServerBrowser.h/.cxx and pqFileDialog.h/.cxx for examples of non-modal dialogs that manage their own lifetimes and communicate user input back to the caller using the Qt signals & slots mechanism.

See the pqTestFileMenu class for an example of a test case that creates and interacts with a modeless dialog.