diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-05-06 16:19:14 +0200 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-05-06 16:50:03 +0200 |
commit | 1326cd15f7ba985551f0fddc717e3bfc01ddda85 (patch) | |
tree | 024eb871ed5f4e8c02e21412475e6e9929a2b030 /src/widgets/dialogs | |
parent | fe70367fe06984d1ac84cc276ca3fd3edc4193c7 (diff) | |
parent | beb7258a56b6ec76531b73cc07ee30132a3f548f (diff) |
Merge remote-tracking branch 'origin/stable' into dev
Conflicts:
mkspecs/qnx-x86-qcc/qplatformdefs.h
src/corelib/global/qglobal.h
src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
src/opengl/qgl.cpp
src/opengl/qglpixelbuffer.cpp
src/opengl/qglshaderprogram.cpp
tests/auto/opengl/qglthreads/tst_qglthreads.cpp
Change-Id: Iaba137884d3526a139000ca26fee02bb27b5cdb5
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r-- | src/widgets/dialogs/qfiledialog.cpp | 66 |
1 files changed, 43 insertions, 23 deletions
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 80e8d152ff..bb8cdec896 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -71,6 +71,7 @@ extern bool qt_priv_ptr_valid; #endif #if defined(Q_OS_UNIX) #include <pwd.h> +#include <unistd.h> // for pathconf() on OS X #elif defined(Q_OS_WIN) # include <QtCore/qt_windows.h> #endif @@ -1018,6 +1019,44 @@ QUrl QFileDialog::directoryUrl() const return QUrl::fromLocalFile(directory().absolutePath()); } +// FIXME Qt 5.4: Use upcoming QVolumeInfo class to determine this information? +static inline bool isCaseSensitiveFileSystem(const QString &path) +{ + Q_UNUSED(path) +#if defined(Q_OS_WIN) + // Return case insensitive unconditionally, even if someone has a case sensitive + // file system mounted, wrongly capitalized drive letters will cause mismatches. + return false; +#elif defined(Q_OS_OSX) + return pathconf(QFile::encodeName(path).constData(), _PC_CASE_SENSITIVE); +#else + return true; +#endif +} + +// Determine the file name to be set on the line edit from the path +// passed to selectFile() in mode QFileDialog::AcceptSave. +static inline QString fileFromPath(const QString &rootPath, QString path) +{ + if (!QFileInfo(path).isAbsolute()) + return path; + if (path.startsWith(rootPath, isCaseSensitiveFileSystem(rootPath) ? Qt::CaseSensitive : Qt::CaseInsensitive)) + path.remove(0, rootPath.size()); + + if (path.isEmpty()) + return path; + + if (path.at(0) == QDir::separator() +#ifdef Q_OS_WIN + //On Windows both cases can happen + || path.at(0) == QLatin1Char('/') +#endif + ) { + path.remove(0, 1); + } + return path; +} + /*! Selects the given \a filename in the file dialog. @@ -1049,28 +1088,9 @@ void QFileDialog::selectFile(const QString &filename) } QModelIndex index = d->model->index(filename); - QString file; - if (!index.isValid()) { - // save as dialog where we want to input a default value - QString text = filename; - if (QFileInfo(filename).isAbsolute()) { - QString current = d->rootPath(); - text.remove(current); - if (text.at(0) == QDir::separator() -#ifdef Q_OS_WIN - //On Windows both cases can happen - || text.at(0) == QLatin1Char('/') -#endif - ) - text = text.remove(0,1); - } - file = text; - } else { - file = index.data().toString(); - } d->qFileDialogUi->listView->selectionModel()->clear(); if (!isVisible() || !d->lineEdit()->hasFocus()) - d->lineEdit()->setText(file); + d->lineEdit()->setText(index.isValid() ? index.data().toString() : fileFromPath(d->rootPath(), filename)); } /*! @@ -1255,7 +1275,7 @@ QStringList QFileDialog::selectedFiles() const QStringList files; foreach (const QUrl &file, d->userSelectedFiles()) files.append(file.toLocalFile()); - if (files.isEmpty()) { + if (files.isEmpty() && d->usingWidgets()) { const FileMode fm = fileMode(); if (fm != ExistingFile && fm != ExistingFiles) files.append(d->rootIndex().data(QFileSystemModel::FilePathRole).toString()); @@ -1600,7 +1620,7 @@ QFileDialog::ViewMode QFileDialog::viewMode() const { Q_D(const QFileDialog); if (!d->usingWidgets()) - return QFileDialog::List; + return static_cast<QFileDialog::ViewMode>(d->options->viewMode()); return (d->qFileDialogUi->stackedWidget->currentWidget() == d->qFileDialogUi->listView->parent() ? QFileDialog::List : QFileDialog::Detail); } |