summaryrefslogtreecommitdiffstats
path: root/src/gui/dialogs/qfiledialog.cpp
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@trolltech.com>2009-04-03 11:49:13 (GMT)
committerAlexis Menard <alexis.menard@trolltech.com>2009-04-03 11:53:36 (GMT)
commit10f0b31dd1b3193bf4c068edde5979881c82ece7 (patch)
treee1953ca88f33e6cfdc78d599b12ba102194f4d62 /src/gui/dialogs/qfiledialog.cpp
parented9fe24ecce5a21f93c88c08d2034bf175808fa3 (diff)
downloadQt-10f0b31dd1b3193bf4c068edde5979881c82ece7.zip
Qt-10f0b31dd1b3193bf4c068edde5979881c82ece7.tar.gz
Qt-10f0b31dd1b3193bf4c068edde5979881c82ece7.tar.bz2
Fix a crash in QFileDialog with a proxy on it.
The main problem is that enterDirectory received a QModelIndex that can be a proxy index and not a source index if there is a proxy set on the QFileDialog. This fix basically discover some other crashes in the completer. The problem was that we didn't apply the proxy to the completer too. So we basically messed up source and proxy indexes. Both have a proxy set now and convert the model indexes if needed. Task-number:250194 Reviewed-by:jasplin
Diffstat (limited to 'src/gui/dialogs/qfiledialog.cpp')
-rw-r--r--src/gui/dialogs/qfiledialog.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp
index 2ce5563..5131271 100644
--- a/src/gui/dialogs/qfiledialog.cpp
+++ b/src/gui/dialogs/qfiledialog.cpp
@@ -2124,6 +2124,7 @@ void QFileDialogPrivate::createWidgets()
#ifndef QT_NO_COMPLETER
completer = new QFSCompletor(model, q);
qFileDialogUi->fileNameEdit->setCompleter(completer);
+ completer->sourceModel = model;
QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(textChanged(QString)),
q, SLOT(_q_autoCompleteFileName(QString)));
#endif // QT_NO_COMPLETER
@@ -2246,12 +2247,21 @@ void QFileDialog::setProxyModel(QAbstractProxyModel *proxyModel)
proxyModel->setSourceModel(d->model);
d->qFileDialogUi->listView->setModel(d->proxyModel);
d->qFileDialogUi->treeView->setModel(d->proxyModel);
+#ifndef QT_NO_COMPLETER
+ d->completer->setModel(d->proxyModel);
+ d->completer->proxyModel = d->proxyModel;
+#endif
connect(d->proxyModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
this, SLOT(_q_rowsInserted(const QModelIndex &)));
} else {
d->proxyModel = 0;
d->qFileDialogUi->listView->setModel(d->model);
d->qFileDialogUi->treeView->setModel(d->model);
+#ifndef QT_NO_COMPLETER
+ d->completer->setModel(d->model);
+ d->completer->sourceModel = d->model;
+ d->completer->proxyModel = 0;
+#endif
connect(d->model, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
this, SLOT(_q_rowsInserted(const QModelIndex &)));
}
@@ -2764,8 +2774,9 @@ void QFileDialogPrivate::_q_enterDirectory(const QModelIndex &index)
{
Q_Q(QFileDialog);
// My Computer or a directory
- QString path = index.data(QFileSystemModel::FilePathRole).toString();
- if (path.isEmpty() || model->isDir(index)) {
+ QModelIndex sourceIndex = mapToSource(index);
+ QString path = sourceIndex.data(QFileSystemModel::FilePathRole).toString();
+ if (path.isEmpty() || model->isDir(sourceIndex)) {
q->setDirectory(path);
emit q->directoryEntered(path);
if (fileMode == QFileDialog::Directory
@@ -3139,7 +3150,11 @@ void QFileDialogLineEdit::keyPressEvent(QKeyEvent *e)
QString QFSCompletor::pathFromIndex(const QModelIndex &index) const
{
- const QFileSystemModel *dirModel = static_cast<const QFileSystemModel *>(model());
+ const QFileSystemModel *dirModel;
+ if (proxyModel)
+ dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel());
+ else
+ dirModel = sourceModel;
QString currentLocation = dirModel->rootPath();
QString path = index.data(QFileSystemModel::FilePathRole).toString();
if (!currentLocation.isEmpty() && path.startsWith(currentLocation)) {
@@ -3185,7 +3200,11 @@ QStringList QFSCompletor::splitPath(const QString &path) const
bool startsFromRoot = path[0] == sep[0];
#endif
if (parts.count() == 1 || (parts.count() > 1 && !startsFromRoot)) {
- const QFileSystemModel *dirModel = static_cast<const QFileSystemModel *>(model());
+ const QFileSystemModel *dirModel;
+ if (proxyModel)
+ dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel());
+ else
+ dirModel = sourceModel;
QString currentLocation = QDir::toNativeSeparators(dirModel->rootPath());
if (currentLocation.contains(sep) && path != currentLocation) {
QStringList currentLocationList = splitPath(currentLocation);