PDA

View Full Version : QFileDialog and file sequences



peterhillman
12th August 2007, 00:57
I need to create a version of QFileDialog that optionally concatentates numbered file sequences into a single entry. So it should combine
image.0001.exr image.0002.exr image.0003.exr
into
image.%04d.exr [1-3]
This string should be displayed in the file list and also be returned by QFileDialog::selectedFile() if it is chosen.

I know in general how to scan a list of file names and turn it into a list of sequences, but I can't work how to do that in a QFileDialog.

Any suggestions on how to do this? Can I use a QAbstractProxyModel to filter out all but the first file in each sequence? How can I change entries in a QFileDialog (so I can change "image.0001.exr" to "image.%04d.exr [1-3]")

marcel
12th August 2007, 01:06
You can use the QFileDialog::fileSelected (http://doc.trolltech.com/latest/qfiledialog.html#fileSelected) signal to see when the selection changes.
This will pass to you a QStringList of selected files absolute paths.

Next, you can use QFileDialog::setLabelText to modify the file name label with your custom name.

I do not think you can actually make the file dialog return that string, but you can store it somewhere and use it afterwards.

Regards

peterhillman
12th August 2007, 02:29
OK - that's a start, but I still need to display sequences rather than individual files in the current directory view. Any ideas?

marcel
12th August 2007, 02:33
The thing about QFileDialog is that it shows you files that already exist.
The model underneath the view takes care of that.

So, if you have image.0001.exr image.0002.exr image.0003.exr, you can't make it in any way to show image.%04d.exr [1-3] instead of those entries. Unless you create your own model and view.
Practically a custom file dialog.

EDIT: however, maybe you can do something with a custom delegate, but again, these operate on single items.

Regards

peterhillman
12th August 2007, 06:41
OK - beginning to get there.

I subclassed QSortFilterProxyModel and reimplemented QSortFilterProxyModel::filterAcceptsRow to check for other files in the sequence.

Somehow QFileDialog::setProxyModel seems to have stopped selected files appearing in the File name LineEdit and I still haven't been able to change the filenames in the current directory view, but it's a start.

EDIT: Seems that even doing
QFileDialog::setProxyModel(new QSortFilterProxyModel() ) prevents files clicked on in the current directory view appearing as the selected file. Everything else seems to work. Any ideas?

peterhillman
24th November 2007, 10:16
Problem solved - more or less, but it isn't very clean.


QT 4.3.2 fixes a bug with the FilterProxyModels which meant that selected files wouldn't appear in the line editor.

Since files don't pass through QSortFilterProxyModel::filterAcceptsRow in any predictable order, a list of files seen in each sequence is required to ensure only the one 'standin file' is accepted for each sequence.

The FileSystemModel doesn't support DisplayRoles (changing the text for the DisplayRole would be the neat way of getting the name of the sequence to display instead of the standin file) - a very ugly workaround was to create a displayDelegate and override displayText to draw the sequence name rather than the standin. Annoyingly, this approach means the sequence name can't be longer than the name of the standin.

A queued signal connection from changedSelection is required to display (via selectFile) the sequence name rather than the standin file when it's clicked.


Not nice, not pretty, but it works.