-------- Original Message --------

Subject:      RwFileDialog: A wrapper class for QFileDialog's (file chooser dialog) static and instance-based APIs
Date:   Mon, 16 Sep 2013 12:34:52 -0600
From:   Phil Weinstein
To:   cadswes software

To: Software Group

See Patrick's e-mail, "File chooser consistency" of 8-14-2013 ... which also addresses a crash problem possibly related to use of the non-static portion of the QFileDialog API (e.g. Marc Sidlow's Gnats 5364).

I've developed an approach to address this issue which will have a minimal impact on the existing RiverWare code.  Since the portions of the QFileDialog API are limited, it was a simple matter to create a class with essentially that API, internally encapsulating which implementation is actually used:
  1. Static / Native Windows File Chooser
  2. QFileDialog Instance / Qt-Implemented File Chooser
I haven't yet modified any of the USES of QFileDialog within RiverWare code (except experimentally, changes not retained).  I've checked in just a new RwFileDialog class, plus test hooks from the Workspace Test menu.

SEE EXTENSIVE NOTES BELOW.  And this GIT commit record:
I will start recoding our uses of QFileDialog.  With this change, we will actually have the ability to toggle all recoded uses between the two types of dialogs.  But the immediate motivation is to operate all file choosers in the Static/Native mode, to see if this avoids the Gnats 5364-type of problem for users which see it (possibly involving Samba in a mixed Windows/Unix file system environment). (We have not been able to reproduce this problem ourselves).

Phil


RwFileDialog: A wrapper class for QFileDialog's static and instance-based APIs
Bug Number: n/a
Release notes (y/n): no
For Release Nums: 6.4

New: class RwFileDialog
 A wrapper class for QFileDialog's static and instance-based APIs.

Documentation Sections Below:
 (1) Background: QFileDialog
 (2) RwFileDialog Wrapper Class
 (3) RwFileDialog Automatic History Support
 (4) Gnats 5364 Notes

(1) Background: QFileDialog

The Qt4 QFileDialog file chooser dialog class has effectively two API:
  1. Static QFileDialog methods: Show and execute a file chooser dialog with a single call. EXAMPLE:
              
QString selectedFileName =
   QFileDialog::getOpenFileName (
      parentWidget, windowTitle, initialSelection,
      nameFilters, &selectedNameFilter, optionFlags);
  1. Qt Instance (QFileDialog instance) API -- broader control of the file chooser dialog's configuration -- including an application-level chooser history. EXAMPLE:
              
QFileDialog dlg (parentWidget);
dlg.setWindowTitle (windowTitle);
dlg.setAcceptMode (QFileDialog::AcceptSave);
dlg.setFileMode (QFileDialog::AnyFile);
dlg.setNameFilters (filterPatterns);
dlg.setHistory (historyList);
const int dialogResult = dlg.exec();  // SHOW AND EXECUTE
const QStringList selFiles = dlg.selectedFiles();

For the most part,

Major Differences between these two QFileDialog interfaces:

  1. The Qt Instance chooser supports application-level history.  For example, showing the most recent six RplSet files when choosing a RplSet file to open. The Static (Native Windows) file chooser supports just a single unified file access history, not specific to RiverWare operation.
     
  2. There is evidence of a possible lockup/crash with the Qt Instance chooser -- but not with the Static/Native chooser. SEE SECTION (4) BELOW.
RiverWare 6.4 development (9-2013) currently has about:
This is mostly an arbitrary and unfortunate inconsistency.

(2) RwFileDialog Wrapper Class

The RwFileDialog has an API which replicates the part of the Qt4 QFileDialog API used by RiverWare -- BOTH the Static/Native functions and the Qt Instance methods.  Its API makes possible a mostly transparent port in RiverWare from QFileDialog toRwFileDialog.

The primary motivation is to (at least in the short term) port all of the 23+ "Instance" uses to the Static/Native implementation to see if this avoids the Gnats 5364 lockup/crash with Samba -- for users who are experiencing this problem -- (we have not been able to reproduce this problem ourselves).

However, this class also provides the ability to GLOBALLY SWITCH between the two QFileDialog implementations (APIs) -- for all uses of this RwFileDialog class (REGARDLESS of which RwFileDialog interface is actually used in RiverWare application code). 

SEE the "Configuration Constants" at the head of RwFileChooser.cpp. Options include:
  1.  Which mode should be the default: "Static" or not (Qt Instance).
  2.  Option to include a terse tag in the file chooser window title to indicate the file chooser mode, initially either: "[WIN]" or "[Qt]".
The RiverWare Workspace TEST MENU now supports these two test functions which (a) operate the RwFileDialog file chooser in the respective mode, and (b) SWITCHES all subsequent RwFileDialog uses to that mode. [The implementations are defined in this class, and also serve as a usage example].
  1. Test File Chooser: Native
  2. Test File Chooser: Qt

(3) RwFileDialog Automatic History Support

With this QFileDialog encapsulation, we have the opportunity to also encapsulate the maintanence of RiverWare's application-level history data.  As noted, this history is not available to the Static/Native file chooser mode. However, even when that mode is used, there is benefit to maintaining this history data -- for construction of the dynamic "Reopen" submenus (e.g. the "Reopen Model" submenu under the Workspace File menu).

Automatic initialization from the application-level history -- and saving of the chosen file within the proper history type (Model, RplSet, etc.) is supported with a "Use Type" parameter added to new versions of the API. (There are also methods which lack this new parameter -- those use and save data to RiverWare's general "recent directory" history).

See the UseType enumerated type, and parameters. The available values correspond to the specific histories supported by the LoadSaveMgr.

(4) Gnats 5364 Notes

See Gnats 5364: (effectively a crash using a QFileDialog instance). "Load model across Samba network, hangs just before presenting file chooser. One fix: native file chooser + no history [QFileDialog::setHistory(), setDirectory() passed in model directory]." [Patrick, 8-23-2013, see e-mails]. [Rw 6.4 development, Qt 4.8.5].

---