Changeset 561 for trunk/src/gui/dialogs/qfiledialog.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/dialogs/qfiledialog.cpp
r172 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 59 59 #include <qapplication.h> 60 60 #include <qstylepainter.h> 61 #if ndef Q_OS_WINCE61 #if !defined(Q_WS_WINCE) && !defined(Q_OS_SYMBIAN) 62 62 #include "ui_qfiledialog.h" 63 63 #else 64 #include "ui_qfiledialog_wince.h" 64 #define Q_EMBEDDED_SMALLSCREEN 65 #include "ui_qfiledialog_embedded.h" 66 #if defined(Q_OS_WINCE) 65 67 extern bool qt_priv_ptr_valid; 68 #endif 66 69 #endif 67 70 … … 90 93 \class QFileDialog 91 94 \brief The QFileDialog class provides a dialog that allow users to select files or directories. 92 \ingroup dialogs93 \mainclass 95 \ingroup standard-dialogs 96 94 97 95 98 The QFileDialog class enables a user to traverse the file system in … … 97 100 98 101 The easiest way to create a QFileDialog is to use the static 99 functions. On Windows, these static functions will call the native 100 Windows file dialog, and on Mac OS X these static function will call 101 the native Mac OS X file dialog. 102 functions. On Windows, Mac OS X, KDE and GNOME, these static functions will 103 call the native file dialog when possible. 102 104 103 105 \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 0 … … 211 213 \enum QFileDialog::Option 212 214 213 \value ShowDirsOnly Only show directories in the file dialog. By default both files and 214 directories are shown. (Valid only in the \l Directory file mode.) 215 \value DontResolveSymlinks Don't resolve symlinks in the file dialog. By default symlinks 216 are resolved. 217 \value DontConfirmOverwrite Don't ask for confirmation if an existing file is selected. 218 By default confirmation is requested. 219 \value DontUseNativeDialog Don't use the native file dialog. By default on Mac OS X and Windows, 220 the native file dialog is used unless you use a subclass of QFileDialog that contains the 221 Q_OBJECT macro. 215 \value ShowDirsOnly Only show directories in the file dialog. By 216 default both files and directories are shown. (Valid only in the 217 \l Directory file mode.) 218 219 \value DontResolveSymlinks Don't resolve symlinks in the file 220 dialog. By default symlinks are resolved. 221 222 \value DontConfirmOverwrite Don't ask for confirmation if an 223 existing file is selected. By default confirmation is requested. 224 225 \value DontUseNativeDialog Don't use the native file dialog. By 226 default, the native file dialog is used unless you use a subclass 227 of QFileDialog that contains the Q_OBJECT macro. 228 222 229 \value ReadOnly Indicates that the model is readonly. 230 223 231 \value HideNameFilterDetails Indicates if the is hidden or not. 224 225 232 This value is obsolete and does nothing since Qt 4.5: 226 233 227 \value DontUseSheet In previous versions of Qt, the static functions would228 create a sheet by default if the static function was given a parent. This229 is no longer supported in Qt 4.5, The static functions will always be an230 application modal dialog. If you want to use sheets, use231 QFileDialog::open() instead.234 \value DontUseSheet In previous versions of Qt, the static 235 functions would create a sheet by default if the static function 236 was given a parent. This is no longer supported in Qt 4.5, The 237 static functions will always be an application modal dialog. If 238 you want to use sheets, use QFileDialog::open() instead. 232 239 233 240 */ … … 311 318 Q_D(QFileDialog); 312 319 d->init(); 320 d->lineEdit()->selectAll(); 313 321 } 314 322 … … 328 336 Q_D(QFileDialog); 329 337 d->init(directory, filter, caption); 338 d->lineEdit()->selectAll(); 330 339 } 331 340 … … 355 364 settings.setValue(QLatin1String("filedialog"), saveState()); 356 365 #endif 357 delete d->qFileDialogUi;358 366 d->deleteNativeDialog_sys(); 359 367 } … … 390 398 391 399 static const qint32 QFileDialogMagic = 0xbe; 400 401 const char *qt_file_dialog_filter_reg_exp = 402 "^(.*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$"; 392 403 393 404 /*! … … 487 498 } 488 499 500 QFileDialogPrivate::QFileDialogPrivate() 501 : 502 #ifndef QT_NO_PROXYMODEL 503 proxyModel(0), 504 #endif 505 model(0), 506 fileMode(QFileDialog::AnyFile), 507 acceptMode(QFileDialog::AcceptOpen), 508 currentHistoryLocation(-1), 509 renameAction(0), 510 deleteAction(0), 511 showHiddenAction(0), 512 useDefaultCaption(true), 513 defaultFileTypes(true), 514 fileNameLabelExplicitlySat(false), 515 nativeDialogInUse(false), 516 #ifdef Q_WS_MAC 517 mDelegate(0), 518 #ifndef QT_MAC_USE_COCOA 519 mDialog(0), 520 mDialogStarted(false), 521 mDialogClosed(true), 522 #endif 523 #endif 524 qFileDialogUi(0) 525 { 526 } 527 528 QFileDialogPrivate::~QFileDialogPrivate() 529 { 530 } 531 489 532 void QFileDialogPrivate::retranslateWindowTitle() 490 533 { … … 567 610 568 611 /*! 569 Sets the given \a option to be enabled if \a on is true; 570 otherwise, clears the given \a option. 612 \since 4.5 613 Sets the given \a option to be enabled if \a on is true; otherwise, 614 clears the given \a option. 571 615 572 616 \sa options, testOption() … … 639 683 \since 4.5 640 684 641 Opens the dialog and connects its accepted() signal to the slot specified 642 by \a receiver and \a member. 685 This function connects one of its signals to the slot specified by \a receiver 686 and \a member. The specific signal depends is filesSelected() if fileMode is 687 ExistingFiles and fileSelected() if fileMode is anything else. 643 688 644 689 The signal will be disconnected from the slot when the dialog is closed. … … 647 692 { 648 693 Q_D(QFileDialog); 649 const char *signal = (fileMode() == ExistingFiles) ? SIGNAL(filesSelected( const QStringList&))650 : SIGNAL(fileSelected( const QString&));694 const char *signal = (fileMode() == ExistingFiles) ? SIGNAL(filesSelected(QStringList)) 695 : SIGNAL(fileSelected(QString)); 651 696 connect(this, signal, receiver, member); 652 697 d->signalToDisconnectOnClose = signal; … … 694 739 void QFileDialogPrivate::_q_goToUrl(const QUrl &url) 695 740 { 696 QModelIndex idx = model->index(url.toLocalFile()); 741 //The shortcut in the side bar may have a parent that is not fetched yet (e.g. an hidden file) 742 //so we force the fetching 743 QFileSystemModelPrivate::QFileSystemNode *node = model->d_func()->node(url.toLocalFile(), true); 744 QModelIndex idx = model->d_func()->index(node); 697 745 _q_enterDirectory(idx); 698 746 } … … 730 778 d->qFileDialogUi->newFolderButton->setEnabled(d->model->flags(root) & Qt::ItemIsDropEnabled); 731 779 if (root != d->rootIndex()) { 732 #ifndef QT_NO_ COMPLETER780 #ifndef QT_NO_FSCOMPLETER 733 781 if (directory.endsWith(QLatin1Char('/'))) 734 782 d->completer->setCompletionPrefix(newDirectory); … … 775 823 776 824 QModelIndex index = d->model->index(filename); 825 QString file; 777 826 if (!index.isValid()) { 778 827 // save as dialog where we want to input a default value … … 789 838 text = text.remove(0,1); 790 839 } 791 if (!isVisible() || !d->lineEdit()->hasFocus()) 792 d->lineEdit()->setText(text); 840 file = text; 793 841 } else { 794 d->qFileDialogUi->listView->selectionModel()->clear(); 795 if (!isVisible() || !d->lineEdit()->hasFocus()) 796 d->lineEdit()->setText(index.data().toString()); 797 } 842 file = index.data().toString(); 843 } 844 d->qFileDialogUi->listView->selectionModel()->clear(); 845 if (!isVisible() || !d->lineEdit()->hasFocus()) 846 d->lineEdit()->setText(file); 798 847 } 799 848 … … 836 885 // and on Windows it already ends with slash. 837 886 QString path = rootPath(); 838 if (!path.endsWith(QLatin1 String("/")))839 path += QLatin1 String("/");887 if (!path.endsWith(QLatin1Char('/'))) 888 path += QLatin1Char('/'); 840 889 path += name; 841 890 files.append(path); … … 958 1007 Q_D(QFileDialog); 959 1008 d->defaultFileTypes = (filters == QStringList(QFileDialog::tr("All Files (*)"))); 960 d->nameFilters = filters; 1009 QStringList cleanedFilters; 1010 for (int i = 0; i < filters.count(); ++i) { 1011 cleanedFilters << filters[i].simplified(); 1012 } 1013 d->nameFilters = cleanedFilters; 961 1014 962 1015 if (d->nativeDialogInUse){ 963 d->setNameFilters_sys( filters);1016 d->setNameFilters_sys(cleanedFilters); 964 1017 return; 965 1018 } 966 1019 967 1020 d->qFileDialogUi->fileTypeCombo->clear(); 968 if ( filters.isEmpty())1021 if (cleanedFilters.isEmpty()) 969 1022 return; 970 1023 971 1024 if (testOption(HideNameFilterDetails)) { 972 1025 QStringList strippedFilters; 973 for (int i = 0; i < filters.count(); ++i) { 974 strippedFilters.append(filters[i].mid(0, filters[i].indexOf(QLatin1String(" (")))); 1026 QRegExp r(QString::fromLatin1(qt_file_dialog_filter_reg_exp)); 1027 for (int i = 0; i < cleanedFilters.count(); ++i) { 1028 QString filterName; 1029 int index = r.indexIn(cleanedFilters[i]); 1030 if (index >= 0) 1031 filterName = r.cap(1); 1032 strippedFilters.append(filterName.simplified()); 975 1033 } 976 1034 d->qFileDialogUi->fileTypeCombo->addItems(strippedFilters); 977 1035 } else { 978 d->qFileDialogUi->fileTypeCombo->addItems( filters);1036 d->qFileDialogUi->fileTypeCombo->addItems(cleanedFilters); 979 1037 } 980 1038 d->_q_useNameFilter(0); … … 1434 1492 Q_D(QFileDialog); 1435 1493 d->model->setIconProvider(provider); 1494 //It forces the refresh of all entries in the side bar, then we can get new icons 1495 d->qFileDialogUi->sidebar->setUrls(d->qFileDialogUi->sidebar->urls()); 1436 1496 } 1437 1497 … … 1530 1590 1531 1591 /*! 1532 This is a convenience static function that returns an existing file 1533 selected by the user. If the user presses Cancel, it returns a null 1534 string. 1535 1536 \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 8 1537 1538 The function creates a modal file dialog with the given \a parent widget. 1539 If the parent is not 0, the dialog will be shown centered over the 1540 parent widget. 1541 1542 The file dialog's working directory will be set to \a dir. If \a 1543 dir includes a file name, the file will be selected. Only files 1544 that match the given \a filter are shown. The filter selected is 1545 set to \a selectedFilter. The parameters \a dir, \a 1546 selectedFilter, and \a filter may be empty strings. If you want 1547 multiple filters, separate them with ';;', for example: 1548 1549 \code 1592 This is a convenience static function that returns an existing file 1593 selected by the user. If the user presses Cancel, it returns a null string. 1594 1595 \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 8 1596 1597 The function creates a modal file dialog with the given \a parent widget. 1598 If \a parent is not 0, the dialog will be shown centered over the parent 1599 widget. 1600 1601 The file dialog's working directory will be set to \a dir. If \a dir 1602 includes a file name, the file will be selected. Only files that match the 1603 given \a filter are shown. The filter selected is set to \a selectedFilter. 1604 The parameters \a dir, \a selectedFilter, and \a filter may be empty 1605 strings. If you want multiple filters, separate them with ';;', for 1606 example: 1607 1608 \code 1550 1609 "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" 1551 \endcode1552 1553 The \a options argument holds various1554 options about how to run the dialog, see the QFileDialog::Option enum for1555 more information on the flags you canpass.1556 1557 The dialog's caption is set to \a caption. If \a caption is not1558 specifiedthen a default caption will be used.1559 1560 Under Windows and Mac OS X, this static function will use the native1561 filedialog and not a QFileDialog.1562 1563 Note that on Windows the dialog will spin a blocking modal event loop1564 that will not dispatch any QTimers, and if parent is not 0 then it will1565 position the dialog just underthe parent's title bar.1566 1567 Under Unix/X11, the normal behavior of the file dialog is to resolve1568 and follow symlinks. For example, if \c{/usr/tmp} is a symlink to1569 \c{/var/tmp}, the file dialog will change to \c{/var/tmp} after1570 entering \c{/usr/tmp}. If \a options includes DontResolveSymlinks,1571 the file dialog will treatsymlinks as regular directories.1572 1573 \warning Do not delete \a parent during the execution of the dialog.1574 If you want to do this, you should create the dialog1575 yourself using one of theQFileDialog constructors.1576 1577 \sa getOpenFileNames(), getSaveFileName(), getExistingDirectory()1610 \endcode 1611 1612 The \a options argument holds various options about how to run the dialog, 1613 see the QFileDialog::Option enum for more information on the flags you can 1614 pass. 1615 1616 The dialog's caption is set to \a caption. If \a caption is not specified 1617 then a default caption will be used. 1618 1619 On Windows and Mac OS X, this static function will use the native file 1620 dialog and not a QFileDialog. 1621 1622 On Windows the dialog will spin a blocking modal event loop that will not 1623 dispatch any QTimers, and if \a parent is not 0 then it will position the 1624 dialog just below the parent's title bar. 1625 1626 On Unix/X11, the normal behavior of the file dialog is to resolve and 1627 follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp}, 1628 the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If 1629 \a options includes DontResolveSymlinks, the file dialog will treat 1630 symlinks as regular directories. 1631 1632 \warning Do not delete \a parent during the execution of the dialog. If you 1633 want to do this, you should create the dialog yourself using one of the 1634 QFileDialog constructors. 1635 1636 \sa getOpenFileNames(), getSaveFileName(), getExistingDirectory() 1578 1637 */ 1579 1638 QString QFileDialog::getOpenFileName(QWidget *parent, … … 1613 1672 1614 1673 /*! 1615 This is a convenience static function that will return one or more1616 existingfiles selected by the user.1617 1618 \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 91619 1620 This function creates a modal file dialog with the given \a parent1621 widget. If the parent is not 0, the dialog will be shown centered1622 over the parentwidget.1623 1624 The file dialog's working directory will be set to \a dir. If \a1625 dir includes a file name, the file will be selected. The filter1626 is set to \a filter so that only those files which match the filter1627 are shown. The filter selected is set to \a selectedFilter. The parameters1628 \a dir, \a selectedFilter and \a filter may be empty strings. If you1629 need multiplefilters, separate them with ';;', for instance:1630 1631 \code1674 This is a convenience static function that will return one or more existing 1675 files selected by the user. 1676 1677 \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 9 1678 1679 This function creates a modal file dialog with the given \a parent widget. 1680 If \a parent is not 0, the dialog will be shown centered over the parent 1681 widget. 1682 1683 The file dialog's working directory will be set to \a dir. If \a dir 1684 includes a file name, the file will be selected. The filter is set to 1685 \a filter so that only those files which match the filter are shown. The 1686 filter selected is set to \a selectedFilter. The parameters \a dir, 1687 \a selectedFilter and \a filter may be empty strings. If you need multiple 1688 filters, separate them with ';;', for instance: 1689 1690 \code 1632 1691 "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" 1633 \endcode 1634 1635 The dialog's caption is set to \a caption. If \a caption is not 1636 specified then a default caption will be used. 1637 1638 Under Windows and Mac OS X, this static function will use the native 1639 file dialog and not a QFileDialog. On Mac OS X, the \a dir argument 1640 is ignored, the native dialog always displays the last visited directory. 1641 1642 Note that on Windows the dialog will spin a blocking modal event loop 1643 that will not dispatch any QTimers, and if parent is not 0 then it will 1644 position the dialog just under the parent's title bar. 1645 1646 Under Unix/X11, the normal behavior of the file dialog is to resolve 1647 and follow symlinks. For example, if \c{/usr/tmp} is a symlink to 1648 \c{/var/tmp}, the file dialog will change to \c{/var/tmp} after 1649 entering \c{/usr/tmp}. The \a options argument holds various 1650 options about how to run the dialog, see the QFileDialog::Option enum for 1651 more information on the flags you can pass. 1652 1653 Note that if you want to iterate over the list of files, you should 1654 iterate over a copy. For example: 1692 \endcode 1693 1694 The dialog's caption is set to \a caption. If \a caption is not specified 1695 then a default caption will be used. 1696 1697 On Windows and Mac OS X, this static function will use the native file 1698 dialog and not a QFileDialog. 1699 1700 On Windows the dialog will spin a blocking modal event loop that will not 1701 dispatch any QTimers, and if \a parent is not 0 then it will position the 1702 dialog just below the parent's title bar. 1703 1704 On Unix/X11, the normal behavior of the file dialog is to resolve and 1705 follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp}, 1706 the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. 1707 The \a options argument holds various options about how to run the dialog, 1708 see the QFileDialog::Option enum for more information on the flags you can 1709 pass. 1710 1711 \note If you want to iterate over the list of files, you should iterate 1712 over a copy. For example: 1655 1713 1656 1714 \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 10 1657 1715 1658 \warning Do not delete \a parent during the execution of the dialog.1659 If you want to do this, you should create the dialog1660 yourself using one of theQFileDialog constructors.1661 1662 \sa getOpenFileName(), getSaveFileName(), getExistingDirectory()1716 \warning Do not delete \a parent during the execution of the dialog. If you 1717 want to do this, you should create the dialog yourself using one of the 1718 QFileDialog constructors. 1719 1720 \sa getOpenFileName(), getSaveFileName(), getExistingDirectory() 1663 1721 */ 1664 1722 QStringList QFileDialog::getOpenFileNames(QWidget *parent, … … 1669 1727 Options options) 1670 1728 { 1671 if (qt_filedialog_open_filenames_hook )1729 if (qt_filedialog_open_filenames_hook && !(options & DontUseNativeDialog)) 1672 1730 return qt_filedialog_open_filenames_hook(parent, caption, dir, filter, selectedFilter, options); 1673 1731 QFileDialogArgs args; … … 1699 1757 1700 1758 /*! 1701 This is a convenience static function that will return a file name 1702 selected by the user. The file does not have to exist. 1703 1704 It creates a modal file dialog with the given \a parent widget. If the 1705 parent is not 0, the dialog will be shown centered over the parent 1706 widget. 1707 1708 \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 11 1709 1710 The file dialog's working directory will be set to \a dir. If \a 1711 dir includes a file name, the file will be selected. Only files that 1712 match the \a filter are shown. The filter selected is set to 1713 \a selectedFilter. The parameters \a dir, \a selectedFilter, and 1714 \a filter may be empty strings. Multiple filters are separated with ';;'. 1715 For instance: 1716 1717 \code 1759 This is a convenience static function that will return a file name selected 1760 by the user. The file does not have to exist. 1761 1762 It creates a modal file dialog with the given \a parent widget. If 1763 \a parent is not 0, the dialog will be shown centered over the parent 1764 widget. 1765 1766 \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 11 1767 1768 The file dialog's working directory will be set to \a dir. If \a dir 1769 includes a file name, the file will be selected. Only files that match the 1770 \a filter are shown. The filter selected is set to \a selectedFilter. The 1771 parameters \a dir, \a selectedFilter, and \a filter may be empty strings. 1772 Multiple filters are separated with ';;'. For instance: 1773 1774 \code 1718 1775 "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" 1719 \endcode 1720 1721 The \a options argument holds various 1722 options about how to run the dialog, see the QFileDialog::Option enum for 1723 more information on the flags you can pass. 1724 1725 The default filter can be chosen by setting \a selectedFilter to the desired value. 1726 1727 The dialog's caption is set to \a caption. If \a caption is not 1728 specified then a default caption will be used. 1729 1730 Under Windows and Mac OS X, this static function will use the native 1731 file dialog and not a QFileDialog. 1732 1733 Note that on Windows the dialog will spin a blocking modal event loop 1734 that will not dispatch any QTimers, and if parent is not 0 then it will 1735 position the dialog just under the parent's title bar. 1736 On Mac OS X, the filter argument is ignored. 1737 1738 Under Unix/X11, the normal behavior of the file dialog is to resolve 1739 and follow symlinks. For example, if \c{/usr/tmp} is a symlink to 1740 \c{/var/tmp}, the file dialog will change to \c{/var/tmp} after 1741 entering \c{/usr/tmp}. If \a options includes DontResolveSymlinks, 1742 the file dialog will treat symlinks as regular directories. 1743 1744 \warning Do not delete \a parent during the execution of the dialog. 1745 If you want to do this, you should create the dialog 1746 yourself using one of the QFileDialog constructors. 1747 1748 \sa getOpenFileName(), getOpenFileNames(), getExistingDirectory() 1776 \endcode 1777 1778 The \a options argument holds various options about how to run the dialog, 1779 see the QFileDialog::Option enum for more information on the flags you can 1780 pass. 1781 1782 The default filter can be chosen by setting \a selectedFilter to the 1783 desired value. 1784 1785 The dialog's caption is set to \a caption. If \a caption is not specified, 1786 a default caption will be used. 1787 1788 On Windows and Mac OS X, this static function will use the native file 1789 dialog and not a QFileDialog. 1790 1791 On Windows the dialog will spin a blocking modal event loop that will not 1792 dispatch any QTimers, and if \a parent is not 0 then it will position the 1793 dialog just below the parent's title bar. On Mac OS X, with its native file 1794 dialog, the filter argument is ignored. 1795 1796 On Unix/X11, the normal behavior of the file dialog is to resolve and 1797 follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp}, 1798 the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If 1799 \a options includes DontResolveSymlinks the file dialog will treat symlinks 1800 as regular directories. 1801 1802 \warning Do not delete \a parent during the execution of the dialog. If you 1803 want to do this, you should create the dialog yourself using one of the 1804 QFileDialog constructors. 1805 1806 \sa getOpenFileName(), getOpenFileNames(), getExistingDirectory() 1749 1807 */ 1750 1808 QString QFileDialog::getSaveFileName(QWidget *parent, … … 1755 1813 Options options) 1756 1814 { 1757 if (qt_filedialog_save_filename_hook )1815 if (qt_filedialog_save_filename_hook && !(options & DontUseNativeDialog)) 1758 1816 return qt_filedialog_save_filename_hook(parent, caption, dir, filter, selectedFilter, options); 1759 1817 QFileDialogArgs args; … … 1787 1845 1788 1846 /*! 1789 This is a convenience static function that will return an existing 1790 directory selected by the user. 1791 1792 \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 12 1793 1794 This function creates a modal file dialog with the given \a parent 1795 widget. If the parent is not 0, the dialog will be shown centered over 1796 the parent widget. 1797 1798 The dialog's working directory is set to \a dir, and the caption is 1799 set to \a caption. Either of these may be an empty string in which case 1800 the current directory and a default caption will be used 1801 respectively. 1802 1803 The \a options argument holds various 1804 options about how to run the dialog, see the QFileDialog::Option enum for 1805 more information on the flags you can pass. Note that \l{QFileDialog::}{ShowDirsOnly} 1806 must be set to ensure a native file dialog. 1807 1808 Under Windows and Mac OS X, this static function will use the native 1809 file dialog and not a QFileDialog. On Mac OS X, the \a dir argument 1810 is ignored, the native dialog always displays the last visited directory. 1811 On Windows CE, if the device has no native file dialog, a QFileDialog 1812 will be used. 1813 1814 Under Unix/X11, the normal behavior of the file dialog is to resolve 1815 and follow symlinks. For example, if \c{/usr/tmp} is a symlink to 1816 \c{/var/tmp}, the file dialog will change to \c{/var/tmp} after 1817 entering \c{/usr/tmp}. If \a options includes DontResolveSymlinks, 1818 the file dialog will treat symlinks as regular directories. 1819 1820 Note that on Windows the dialog will spin a blocking modal event loop 1821 that will not dispatch any QTimers, and if parent is not 0 then it will 1822 position the dialog just under the parent's title bar. 1823 1824 \warning Do not delete \a parent during the execution of the dialog. 1825 If you want to do this, you should create the dialog 1826 yourself using one of the QFileDialog constructors. 1827 1828 \sa getOpenFileName(), getOpenFileNames(), getSaveFileName() 1847 This is a convenience static function that will return an existing 1848 directory selected by the user. 1849 1850 \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 12 1851 1852 This function creates a modal file dialog with the given \a parent widget. 1853 If \a parent is not 0, the dialog will be shown centered over the parent 1854 widget. 1855 1856 The dialog's working directory is set to \a dir, and the caption is set to 1857 \a caption. Either of these may be an empty string in which case the 1858 current directory and a default caption will be used respectively. 1859 1860 The \a options argument holds various options about how to run the dialog, 1861 see the QFileDialog::Option enum for more information on the flags you can 1862 pass. To ensure a native file dialog, \l{QFileDialog::}{ShowDirsOnly} must 1863 be set. 1864 1865 On Windows and Mac OS X, this static function will use the native file 1866 dialog and not a QFileDialog. On Windows CE, if the device has no native 1867 file dialog, a QFileDialog will be used. 1868 1869 On Unix/X11, the normal behavior of the file dialog is to resolve and 1870 follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp}, 1871 the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If 1872 \a options includes DontResolveSymlinks, the file dialog will treat 1873 symlinks as regular directories. 1874 1875 On Windows the dialog will spin a blocking modal event loop that will not 1876 dispatch any QTimers, and if \a parent is not 0 then it will position the 1877 dialog just below the parent's title bar. 1878 1879 \warning Do not delete \a parent during the execution of the dialog. If you 1880 want to do this, you should create the dialog yourself using one of the 1881 QFileDialog constructors. 1882 1883 \sa getOpenFileName(), getOpenFileNames(), getSaveFileName() 1829 1884 */ 1830 1885 QString QFileDialog::getExistingDirectory(QWidget *parent, … … 1833 1888 Options options) 1834 1889 { 1835 if (qt_filedialog_existing_directory_hook )1890 if (qt_filedialog_existing_directory_hook && !(options & DontUseNativeDialog)) 1836 1891 return qt_filedialog_existing_directory_hook(parent, caption, dir, options); 1837 1892 QFileDialogArgs args; … … 1844 1899 #if defined(Q_WS_WIN) 1845 1900 if (qt_use_native_dialogs && !(args.options & DontUseNativeDialog) && (options & ShowDirsOnly) 1846 #if defined(Q_ OS_WINCE)1901 #if defined(Q_WS_WINCE) 1847 1902 && qt_priv_ptr_valid 1848 1903 #endif … … 2058 2113 #endif 2059 2114 2060 #if def Q_OS_WINCE2115 #if defined(Q_EMBEDDED_SMALLSCREEN) 2061 2116 qFileDialogUi->lookInLabel->setVisible(false); 2062 2117 qFileDialogUi->fileNameLabel->setVisible(false); … … 2090 2145 model->setNameFilterDisables(false); 2091 2146 #endif 2092 QFileDialog::connect(model, SIGNAL(fileRenamed(const QString &, const QString &, const QString &)), q, SLOT(_q_fileRenamed(const QString &, const QString &, const QString &))); 2093 QFileDialog::connect(model, SIGNAL(rootPathChanged(const QString &)), 2094 q, SLOT(_q_pathChanged(const QString &))); 2095 QFileDialog::connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), 2096 q, SLOT(_q_rowsInserted(const QModelIndex &))); 2147 model->d_func()->disableRecursiveSort = true; 2148 QFileDialog::connect(model, SIGNAL(fileRenamed(QString,QString,QString)), q, SLOT(_q_fileRenamed(QString,QString,QString))); 2149 QFileDialog::connect(model, SIGNAL(rootPathChanged(QString)), 2150 q, SLOT(_q_pathChanged(QString))); 2151 QFileDialog::connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), 2152 q, SLOT(_q_rowsInserted(QModelIndex))); 2097 2153 model->setReadOnly(false); 2098 2154 2099 qFileDialogUi = new Ui_QFileDialog();2155 qFileDialogUi.reset(new Ui_QFileDialog()); 2100 2156 qFileDialogUi->setupUi(q); 2101 2157 … … 2104 2160 << QUrl::fromLocalFile(QDir::homePath()); 2105 2161 qFileDialogUi->sidebar->init(model, initialBookmarks); 2106 QFileDialog::connect(qFileDialogUi->sidebar, SIGNAL(goToUrl( const QUrl &)),2107 q, SLOT(_q_goToUrl( const QUrl &)));2162 QFileDialog::connect(qFileDialogUi->sidebar, SIGNAL(goToUrl(QUrl)), 2163 q, SLOT(_q_goToUrl(QUrl))); 2108 2164 2109 2165 QObject::connect(qFileDialogUi->buttonBox, SIGNAL(accepted()), q, SLOT(accept())); … … 2122 2178 qFileDialogUi->fileNameLabel->setBuddy(qFileDialogUi->fileNameEdit); 2123 2179 #endif 2124 #ifndef QT_NO_ COMPLETER2125 completer = new QFSComplet or(model, q);2180 #ifndef QT_NO_FSCOMPLETER 2181 completer = new QFSCompleter(model, q); 2126 2182 qFileDialogUi->fileNameEdit->setCompleter(completer); 2127 completer->sourceModel = model;2128 2183 QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(textChanged(QString)), 2129 2184 q, SLOT(_q_autoCompleteFileName(QString))); 2130 #endif // QT_NO_ COMPLETER2185 #endif // QT_NO_FSCOMPLETER 2131 2186 QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(textChanged(QString)), 2132 2187 q, SLOT(_q_updateOkButton())); … … 2140 2195 QObject::connect(qFileDialogUi->fileTypeCombo, SIGNAL(activated(int)), 2141 2196 q, SLOT(_q_useNameFilter(int))); 2142 QObject::connect(qFileDialogUi->fileTypeCombo, SIGNAL(activated( const QString &)),2143 q, SIGNAL(filterSelected( const QString &)));2197 QObject::connect(qFileDialogUi->fileTypeCombo, SIGNAL(activated(QString)), 2198 q, SIGNAL(filterSelected(QString))); 2144 2199 2145 2200 qFileDialogUi->listView->init(this); … … 2167 2222 QActionGroup *showActionGroup = new QActionGroup(q); 2168 2223 showActionGroup->setExclusive(false); 2169 QObject::connect(showActionGroup, SIGNAL(triggered(QAction 2170 q, SLOT(_q_showHeader(QAction 2224 QObject::connect(showActionGroup, SIGNAL(triggered(QAction*)), 2225 q, SLOT(_q_showHeader(QAction*)));; 2171 2226 2172 2227 QAbstractItemModel *abstractModel = model; … … 2182 2237 } 2183 2238 2184 Q ItemSelectionModel *selModel = qFileDialogUi->treeView->selectionModel();2239 QScopedPointer<QItemSelectionModel> selModel(qFileDialogUi->treeView->selectionModel()); 2185 2240 qFileDialogUi->treeView->setSelectionModel(qFileDialogUi->listView->selectionModel()); 2186 delete selModel; 2241 2187 2242 QObject::connect(qFileDialogUi->treeView, SIGNAL(activated(QModelIndex)), 2188 2243 q, SLOT(_q_enterDirectory(QModelIndex))); … … 2197 2252 // Selections 2198 2253 QItemSelectionModel *selections = qFileDialogUi->listView->selectionModel(); 2199 QObject::connect(selections, SIGNAL(selectionChanged( const QItemSelection &, const QItemSelection &)),2254 QObject::connect(selections, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), 2200 2255 q, SLOT(_q_selectionChanged())); 2201 2256 QObject::connect(selections, SIGNAL(currentChanged(QModelIndex,QModelIndex)), … … 2235 2290 QModelIndex idx = d->rootIndex(); 2236 2291 if (d->proxyModel) { 2237 disconnect(d->proxyModel, SIGNAL(rowsInserted( const QModelIndex &, int,int)),2238 this, SLOT(_q_rowsInserted( const QModelIndex &)));2292 disconnect(d->proxyModel, SIGNAL(rowsInserted(QModelIndex,int,int)), 2293 this, SLOT(_q_rowsInserted(QModelIndex))); 2239 2294 } else { 2240 disconnect(d->model, SIGNAL(rowsInserted( const QModelIndex &, int,int)),2241 this, SLOT(_q_rowsInserted( const QModelIndex &)));2295 disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), 2296 this, SLOT(_q_rowsInserted(QModelIndex))); 2242 2297 } 2243 2298 … … 2248 2303 d->qFileDialogUi->listView->setModel(d->proxyModel); 2249 2304 d->qFileDialogUi->treeView->setModel(d->proxyModel); 2250 #ifndef QT_NO_ COMPLETER2305 #ifndef QT_NO_FSCOMPLETER 2251 2306 d->completer->setModel(d->proxyModel); 2252 2307 d->completer->proxyModel = d->proxyModel; 2253 2308 #endif 2254 connect(d->proxyModel, SIGNAL(rowsInserted( const QModelIndex &, int,int)),2255 this, SLOT(_q_rowsInserted( const QModelIndex &)));2309 connect(d->proxyModel, SIGNAL(rowsInserted(QModelIndex,int,int)), 2310 this, SLOT(_q_rowsInserted(QModelIndex))); 2256 2311 } else { 2257 2312 d->proxyModel = 0; 2258 2313 d->qFileDialogUi->listView->setModel(d->model); 2259 2314 d->qFileDialogUi->treeView->setModel(d->model); 2260 #ifndef QT_NO_ COMPLETER2315 #ifndef QT_NO_FSCOMPLETER 2261 2316 d->completer->setModel(d->model); 2262 2317 d->completer->sourceModel = d->model; 2263 2318 d->completer->proxyModel = 0; 2264 2319 #endif 2265 connect(d->model, SIGNAL(rowsInserted( const QModelIndex &, int,int)),2266 this, SLOT(_q_rowsInserted( const QModelIndex &)));2267 } 2268 Q ItemSelectionModel *selModel = d->qFileDialogUi->treeView->selectionModel();2320 connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), 2321 this, SLOT(_q_rowsInserted(QModelIndex))); 2322 } 2323 QScopedPointer<QItemSelectionModel> selModel(d->qFileDialogUi->treeView->selectionModel()); 2269 2324 d->qFileDialogUi->treeView->setSelectionModel(d->qFileDialogUi->listView->selectionModel()); 2270 delete selModel; 2325 2271 2326 d->setRootIndex(idx); 2272 2327 2273 2328 // reconnect selection 2274 2329 QItemSelectionModel *selections = d->qFileDialogUi->listView->selectionModel(); 2275 QObject::connect(selections, SIGNAL(selectionChanged( const QItemSelection &, const QItemSelection &)),2330 QObject::connect(selections, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), 2276 2331 this, SLOT(_q_selectionChanged())); 2277 2332 QObject::connect(selections, SIGNAL(currentChanged(QModelIndex,QModelIndex)), … … 2633 2688 void QFileDialogPrivate::_q_autoCompleteFileName(const QString &text) 2634 2689 { 2635 if (text.startsWith(QLatin1String("//")) || text.startsWith(QLatin1 String("\\"))) {2690 if (text.startsWith(QLatin1String("//")) || text.startsWith(QLatin1Char('\\'))) { 2636 2691 qFileDialogUi->listView->selectionModel()->clearSelection(); 2637 2692 return; … … 2675 2730 QString lineEditText = lineEdit()->text(); 2676 2731 2677 if (lineEditText.startsWith(QLatin1String("//")) || lineEditText.startsWith(QLatin1 String("\\"))) {2732 if (lineEditText.startsWith(QLatin1String("//")) || lineEditText.startsWith(QLatin1Char('\\'))) { 2678 2733 button->setEnabled(true); 2679 2734 if (acceptMode == QFileDialog::AcceptSave) 2680 button->setText( isOpenDirectory ? QFileDialog::tr("&Open") :acceptLabel);2735 button->setText(acceptLabel); 2681 2736 return; 2682 2737 } … … 2775 2830 Q_Q(QFileDialog); 2776 2831 // My Computer or a directory 2777 QModelIndex sourceIndex = mapToSource(index);2832 QModelIndex sourceIndex = index.model() == proxyModel ? mapToSource(index) : index; 2778 2833 QString path = sourceIndex.data(QFileSystemModel::FilePathRole).toString(); 2779 2834 if (path.isEmpty() || model->isDir(sourceIndex)) { … … 2827 2882 } 2828 2883 2829 const char *qt_file_dialog_filter_reg_exp =2830 "^([^()]*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";2831 2832 2884 // Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)" 2833 2885 QStringList qt_clean_filter_list(const QString &filter) … … 3088 3140 void QFileDialogListView::keyPressEvent(QKeyEvent *e) 3089 3141 { 3090 if (!d_ptr->itemViewKeyboardEvent(e)) { 3142 #ifdef QT_KEYPAD_NAVIGATION 3143 if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { 3091 3144 QListView::keyPressEvent(e); 3092 } 3145 return; 3146 } 3147 #endif // QT_KEYPAD_NAVIGATION 3148 3149 if (!d_ptr->itemViewKeyboardEvent(e)) 3150 QListView::keyPressEvent(e); 3093 3151 e->accept(); 3094 3152 } … … 3117 3175 void QFileDialogTreeView::keyPressEvent(QKeyEvent *e) 3118 3176 { 3119 if (!d_ptr->itemViewKeyboardEvent(e)) { 3177 #ifdef QT_KEYPAD_NAVIGATION 3178 if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { 3120 3179 QTreeView::keyPressEvent(e); 3121 } 3180 return; 3181 } 3182 #endif // QT_KEYPAD_NAVIGATION 3183 3184 if (!d_ptr->itemViewKeyboardEvent(e)) 3185 QTreeView::keyPressEvent(e); 3122 3186 e->accept(); 3123 3187 } … … 3136 3200 void QFileDialogLineEdit::keyPressEvent(QKeyEvent *e) 3137 3201 { 3202 #ifdef QT_KEYPAD_NAVIGATION 3203 if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { 3204 QLineEdit::keyPressEvent(e); 3205 return; 3206 } 3207 #endif // QT_KEYPAD_NAVIGATION 3208 3138 3209 int key = e->key(); 3139 3210 QLineEdit::keyPressEvent(e); … … 3147 3218 } 3148 3219 3149 #ifndef QT_NO_ COMPLETER3150 3151 QString QFSComplet or::pathFromIndex(const QModelIndex &index) const3220 #ifndef QT_NO_FSCOMPLETER 3221 3222 QString QFSCompleter::pathFromIndex(const QModelIndex &index) const 3152 3223 { 3153 3224 const QFileSystemModel *dirModel; … … 3164 3235 } 3165 3236 3166 QStringList QFSComplet or::splitPath(const QString &path) const3237 QStringList QFSCompleter::splitPath(const QString &path) const 3167 3238 { 3168 3239 if (path.isEmpty()) … … 3171 3242 QString pathCopy = QDir::toNativeSeparators(path); 3172 3243 QString sep = QDir::separator(); 3173 #if defined(Q_OS_WIN) || defined(Q_OS_OS2) 3244 #if defined(Q_OS_SYMBIAN) 3245 if (pathCopy == QLatin1String("\\")) 3246 return QStringList(pathCopy); 3247 #elif defined(Q_OS_WIN) || defined(Q_OS_OS2) 3174 3248 if (pathCopy == QLatin1String("\\") || pathCopy == QLatin1String("\\\\")) 3175 3249 return QStringList(pathCopy); … … 3181 3255 #endif 3182 3256 3183 QRegExp re(QLatin1String("[") + QRegExp::escape(sep) + QLatin1String("]")); 3184 3185 #if defined(Q_OS_WIN) || defined(Q_OS_OS2) 3257 QRegExp re(QLatin1Char('[') + QRegExp::escape(sep) + QLatin1Char(']')); 3258 3259 #if defined(Q_OS_SYMBIAN) 3260 QStringList parts = pathCopy.split(re, QString::SkipEmptyParts); 3261 if (pathCopy.endsWith(sep)) 3262 parts.append(QString()); 3263 #elif defined(Q_OS_WIN) || defined(Q_OS_OS2) 3186 3264 QStringList parts = pathCopy.split(re, QString::SkipEmptyParts); 3187 3265 if (!doubleSlash.isEmpty() && !parts.isEmpty()) … … 3195 3273 #endif 3196 3274 3197 #if defined(Q_OS_WIN) || defined(Q_OS_ OS2)3275 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) || defined(Q_OS_OS2) 3198 3276 bool startsFromRoot = !parts.isEmpty() && parts[0].endsWith(QLatin1Char(':')); 3199 3277 #else
Note:
See TracChangeset
for help on using the changeset viewer.