Remove the deprecated QDirModel
QFileSystemModel is the documented replacement. It uses threads to populate the model, which QDirModel doesn't. Change-Id: I7818ecd8f849eb566ac176612f382e17a0471c47 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
5781ef2013
commit
94dcb5454f
Binary file not shown.
Before Width: | Height: | Size: 14 KiB |
Binary file not shown.
Before Width: | Height: | Size: 14 KiB |
@ -75,13 +75,6 @@
|
|||||||
|
|
||||||
\snippet tools/completer/fsmodel.cpp 1
|
\snippet tools/completer/fsmodel.cpp 1
|
||||||
|
|
||||||
The screenshots below illustrate this difference:
|
|
||||||
|
|
||||||
\table
|
|
||||||
\row \li \inlineimage completer-example-qdirmodel.png
|
|
||||||
\li \inlineimage completer-example-dirmodel.png
|
|
||||||
\endtable
|
|
||||||
|
|
||||||
The Qt::EditRole, which QCompleter uses to look for matches, is left
|
The Qt::EditRole, which QCompleter uses to look for matches, is left
|
||||||
unchanged.
|
unchanged.
|
||||||
|
|
||||||
|
@ -2106,8 +2106,8 @@ QDataStream &operator<<(QDataStream &out, const QStandardItem &item)
|
|||||||
that interface (such as QListView, QTableView and QTreeView, and your own
|
that interface (such as QListView, QTableView and QTreeView, and your own
|
||||||
custom views). For performance and flexibility, you may want to subclass
|
custom views). For performance and flexibility, you may want to subclass
|
||||||
QAbstractItemModel to provide support for different kinds of data
|
QAbstractItemModel to provide support for different kinds of data
|
||||||
repositories. For example, the QDirModel provides a model interface to the
|
repositories. For example, the QFileSystemModel provides a model interface
|
||||||
underlying file system.
|
to the underlying file system.
|
||||||
|
|
||||||
When you want a list or tree, you typically create an empty
|
When you want a list or tree, you typically create an empty
|
||||||
QStandardItemModel and use appendRow() to add items to the model, and
|
QStandardItemModel and use appendRow() to add items to the model, and
|
||||||
|
@ -626,7 +626,6 @@ QT_CLASS_LIB(QAbstractItemView, QtWidgets, qabstractitemview.h)
|
|||||||
QT_CLASS_LIB(QAbstractProxyModel, QtWidgets, qabstractproxymodel.h)
|
QT_CLASS_LIB(QAbstractProxyModel, QtWidgets, qabstractproxymodel.h)
|
||||||
QT_CLASS_LIB(QColumnView, QtWidgets, qcolumnview.h)
|
QT_CLASS_LIB(QColumnView, QtWidgets, qcolumnview.h)
|
||||||
QT_CLASS_LIB(QDataWidgetMapper, QtWidgets, qdatawidgetmapper.h)
|
QT_CLASS_LIB(QDataWidgetMapper, QtWidgets, qdatawidgetmapper.h)
|
||||||
QT_CLASS_LIB(QDirModel, QtWidgets, qdirmodel.h)
|
|
||||||
QT_CLASS_LIB(QFileIconProvider, QtWidgets, qfileiconprovider.h)
|
QT_CLASS_LIB(QFileIconProvider, QtWidgets, qfileiconprovider.h)
|
||||||
QT_CLASS_LIB(QHeaderView, QtWidgets, qheaderview.h)
|
QT_CLASS_LIB(QHeaderView, QtWidgets, qheaderview.h)
|
||||||
QT_CLASS_LIB(QItemDelegate, QtWidgets, qitemdelegate.h)
|
QT_CLASS_LIB(QItemDelegate, QtWidgets, qitemdelegate.h)
|
||||||
|
@ -717,11 +717,6 @@ qt_extend_target(Widgets CONDITION QT_FEATURE_datawidgetmapper
|
|||||||
itemviews/qdatawidgetmapper.cpp itemviews/qdatawidgetmapper.h
|
itemviews/qdatawidgetmapper.cpp itemviews/qdatawidgetmapper.h
|
||||||
)
|
)
|
||||||
|
|
||||||
qt_extend_target(Widgets CONDITION QT_FEATURE_dirmodel
|
|
||||||
SOURCES
|
|
||||||
itemviews/qdirmodel.cpp itemviews/qdirmodel.h
|
|
||||||
)
|
|
||||||
|
|
||||||
qt_extend_target(Widgets CONDITION QT_FEATURE_listview
|
qt_extend_target(Widgets CONDITION QT_FEATURE_listview
|
||||||
SOURCES
|
SOURCES
|
||||||
itemviews/qlistview.cpp itemviews/qlistview.h itemviews/qlistview_p.h
|
itemviews/qlistview.cpp itemviews/qlistview.h itemviews/qlistview_p.h
|
||||||
|
@ -719,11 +719,6 @@ qt_extend_target(Widgets CONDITION QT_FEATURE_datawidgetmapper
|
|||||||
itemviews/qdatawidgetmapper.cpp itemviews/qdatawidgetmapper.h
|
itemviews/qdatawidgetmapper.cpp itemviews/qdatawidgetmapper.h
|
||||||
)
|
)
|
||||||
|
|
||||||
qt_extend_target(Widgets CONDITION QT_FEATURE_dirmodel
|
|
||||||
SOURCES
|
|
||||||
itemviews/qdirmodel.cpp itemviews/qdirmodel.h
|
|
||||||
)
|
|
||||||
|
|
||||||
qt_extend_target(Widgets CONDITION QT_FEATURE_listview
|
qt_extend_target(Widgets CONDITION QT_FEATURE_listview
|
||||||
SOURCES
|
SOURCES
|
||||||
itemviews/qlistview.cpp itemviews/qlistview.h itemviews/qlistview_p.h
|
itemviews/qlistview.cpp itemviews/qlistview.h itemviews/qlistview_p.h
|
||||||
|
@ -440,7 +440,7 @@ qt_feature("filedialog" PUBLIC
|
|||||||
SECTION "Dialogs"
|
SECTION "Dialogs"
|
||||||
LABEL "QFileDialog"
|
LABEL "QFileDialog"
|
||||||
PURPOSE "Provides a dialog widget for selecting files or directories."
|
PURPOSE "Provides a dialog widget for selecting files or directories."
|
||||||
CONDITION ( QT_FEATURE_buttongroup ) AND ( QT_FEATURE_combobox ) AND ( QT_FEATURE_dialog ) AND ( QT_FEATURE_dialogbuttonbox ) AND ( QT_FEATURE_dirmodel ) AND ( QT_FEATURE_label ) AND ( QT_FEATURE_proxymodel ) AND ( QT_FEATURE_splitter ) AND ( QT_FEATURE_stackedwidget ) AND ( QT_FEATURE_treeview ) AND ( QT_FEATURE_toolbutton )
|
CONDITION ( QT_FEATURE_buttongroup ) AND ( QT_FEATURE_combobox ) AND ( QT_FEATURE_dialog ) AND ( QT_FEATURE_dialogbuttonbox ) AND ( QT_FEATURE_label ) AND ( QT_FEATURE_proxymodel ) AND ( QT_FEATURE_splitter ) AND ( QT_FEATURE_stackedwidget ) AND ( QT_FEATURE_treeview ) AND ( QT_FEATURE_toolbutton )
|
||||||
)
|
)
|
||||||
qt_feature_definition("filedialog" "QT_NO_FILEDIALOG" NEGATE VALUE "1")
|
qt_feature_definition("filedialog" "QT_NO_FILEDIALOG" NEGATE VALUE "1")
|
||||||
qt_feature("fontdialog" PUBLIC
|
qt_feature("fontdialog" PUBLIC
|
||||||
@ -478,13 +478,6 @@ qt_feature("wizard" PUBLIC
|
|||||||
CONDITION ( QT_FEATURE_dialog ) AND ( QT_FEATURE_pushbutton ) AND ( QT_FEATURE_properties ) AND ( QT_FEATURE_label )
|
CONDITION ( QT_FEATURE_dialog ) AND ( QT_FEATURE_pushbutton ) AND ( QT_FEATURE_properties ) AND ( QT_FEATURE_label )
|
||||||
)
|
)
|
||||||
qt_feature_definition("wizard" "QT_NO_WIZARD" NEGATE VALUE "1")
|
qt_feature_definition("wizard" "QT_NO_WIZARD" NEGATE VALUE "1")
|
||||||
qt_feature("dirmodel" PUBLIC
|
|
||||||
SECTION "ItemViews"
|
|
||||||
LABEL "QDirModel"
|
|
||||||
PURPOSE "Provides a data model for the local filesystem."
|
|
||||||
CONDITION QT_FEATURE_itemviews AND QT_FEATURE_filesystemmodel
|
|
||||||
)
|
|
||||||
qt_feature_definition("dirmodel" "QT_NO_DIRMODEL" NEGATE VALUE "1")
|
|
||||||
qt_feature("listview" PUBLIC
|
qt_feature("listview" PUBLIC
|
||||||
SECTION "ItemViews"
|
SECTION "ItemViews"
|
||||||
LABEL "QListView"
|
LABEL "QListView"
|
||||||
|
@ -496,7 +496,6 @@
|
|||||||
"features.combobox",
|
"features.combobox",
|
||||||
"features.dialog",
|
"features.dialog",
|
||||||
"features.dialogbuttonbox",
|
"features.dialogbuttonbox",
|
||||||
"features.dirmodel",
|
|
||||||
"features.label",
|
"features.label",
|
||||||
"features.proxymodel",
|
"features.proxymodel",
|
||||||
"features.splitter",
|
"features.splitter",
|
||||||
@ -577,13 +576,6 @@
|
|||||||
],
|
],
|
||||||
"output": [ "publicFeature", "feature" ]
|
"output": [ "publicFeature", "feature" ]
|
||||||
},
|
},
|
||||||
"dirmodel": {
|
|
||||||
"label": "QDirModel",
|
|
||||||
"purpose": "Provides a data model for the local filesystem.",
|
|
||||||
"section": "ItemViews",
|
|
||||||
"condition": "features.itemviews && features.filesystemmodel",
|
|
||||||
"output": [ "publicFeature", "feature" ]
|
|
||||||
},
|
|
||||||
"listview": {
|
"listview": {
|
||||||
"label": "QListView",
|
"label": "QListView",
|
||||||
"purpose": "Provides a list or icon view onto a model.",
|
"purpose": "Provides a list or icon view onto a model.",
|
||||||
|
@ -122,10 +122,9 @@ QT_BEGIN_NAMESPACE
|
|||||||
is called. This will prevent any unnecessary querying on the file system
|
is called. This will prevent any unnecessary querying on the file system
|
||||||
until that point such as listing the drives on Windows.
|
until that point such as listing the drives on Windows.
|
||||||
|
|
||||||
Unlike QDirModel, QFileSystemModel uses a separate thread to populate
|
QFileSystemModel uses a separate thread to populate itself so it will not
|
||||||
itself so it will not cause the main thread to hang as the file system
|
cause the main thread to hang as the file system is being queried.
|
||||||
is being queried. Calls to rowCount() will return 0 until the model
|
Calls to rowCount() will return 0 until the model populates a directory.
|
||||||
populates a directory.
|
|
||||||
|
|
||||||
QFileSystemModel keeps a cache with file information. The cache is
|
QFileSystemModel keeps a cache with file information. The cache is
|
||||||
automatically kept up to date using the QFileSystemWatcher.
|
automatically kept up to date using the QFileSystemWatcher.
|
||||||
|
@ -493,8 +493,7 @@
|
|||||||
\li QStandardItemModel
|
\li QStandardItemModel
|
||||||
\li Stores arbitrary hierarchical items
|
\li Stores arbitrary hierarchical items
|
||||||
\row
|
\row
|
||||||
\li QFileSystemModel\br
|
\li QFileSystemModel
|
||||||
QDirModel
|
|
||||||
\li Encapsulate the local file system
|
\li Encapsulate the local file system
|
||||||
\row
|
\row
|
||||||
\li QSqlQueryModel
|
\li QSqlQueryModel
|
||||||
@ -626,12 +625,6 @@
|
|||||||
\li QStringListModel
|
\li QStringListModel
|
||||||
\li
|
\li
|
||||||
\li Book 1, Chapter 10, Figure 10.6
|
\li Book 1, Chapter 10, Figure 10.6
|
||||||
\row
|
|
||||||
\li Directory Viewer
|
|
||||||
\li QTreeView
|
|
||||||
\li QDirModel
|
|
||||||
\li
|
|
||||||
\li Book 1, Chapter 10, Figure 10.7
|
|
||||||
\row
|
\row
|
||||||
\li Color Names
|
\li Color Names
|
||||||
\li QListView
|
\li QListView
|
||||||
@ -666,14 +659,6 @@
|
|||||||
\li Custom delegate providing a custom editor
|
\li Custom delegate providing a custom editor
|
||||||
\li Book 1, Chapter 10, Figure 10.15
|
\li Book 1, Chapter 10, Figure 10.15
|
||||||
|
|
||||||
\row
|
|
||||||
\li Four directory views
|
|
||||||
\li QListView
|
|
||||||
QTableView
|
|
||||||
QTreeView
|
|
||||||
\li QDirModel
|
|
||||||
\li Demonstrates the use of multiple views
|
|
||||||
\li Book2, Chapter 8.2
|
|
||||||
\row
|
\row
|
||||||
\li Address Book
|
\li Address Book
|
||||||
\li QListView
|
\li QListView
|
||||||
|
@ -41,11 +41,6 @@ qtConfig(datawidgetmapper) {
|
|||||||
SOURCES += itemviews/qdatawidgetmapper.cpp
|
SOURCES += itemviews/qdatawidgetmapper.cpp
|
||||||
}
|
}
|
||||||
|
|
||||||
qtConfig(dirmodel) {
|
|
||||||
HEADERS += itemviews/qdirmodel.h
|
|
||||||
SOURCES += itemviews/qdirmodel.cpp
|
|
||||||
}
|
|
||||||
|
|
||||||
qtConfig(listview) {
|
qtConfig(listview) {
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
itemviews/qlistview.h \
|
itemviews/qlistview.h \
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,152 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of the QtWidgets module of the Qt Toolkit.
|
|
||||||
**
|
|
||||||
** $QT_BEGIN_LICENSE:LGPL$
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU Lesser General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
|
||||||
** packaging of this file. Please review the following information to
|
|
||||||
** ensure the GNU Lesser General Public License version 3 requirements
|
|
||||||
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 2.0 or (at your option) the GNU General
|
|
||||||
** Public license version 3 or any later version approved by the KDE Free
|
|
||||||
** Qt Foundation. The licenses are as published by the Free Software
|
|
||||||
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
|
||||||
** https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
** $QT_END_LICENSE$
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef QDIRMODEL_H
|
|
||||||
#define QDIRMODEL_H
|
|
||||||
|
|
||||||
#include <QtWidgets/qtwidgetsglobal.h>
|
|
||||||
#include <QtCore/qabstractitemmodel.h>
|
|
||||||
#include <QtCore/qdir.h>
|
|
||||||
#include <QtWidgets/qfileiconprovider.h>
|
|
||||||
|
|
||||||
#if QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
|
|
||||||
QT_REQUIRE_CONFIG(dirmodel);
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
|
|
||||||
class QDirModelPrivate;
|
|
||||||
|
|
||||||
class Q_WIDGETS_EXPORT QDirModel : public QAbstractItemModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks)
|
|
||||||
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
|
|
||||||
Q_PROPERTY(bool lazyChildCount READ lazyChildCount WRITE setLazyChildCount)
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum Roles {
|
|
||||||
FileIconRole = Qt::DecorationRole,
|
|
||||||
FilePathRole = Qt::UserRole + 1,
|
|
||||||
FileNameRole
|
|
||||||
};
|
|
||||||
|
|
||||||
QT_DEPRECATED_VERSION_X_5_15("Use QFileSystemModel") QDirModel(const QStringList &nameFilters,
|
|
||||||
QDir::Filters filters, QDir::SortFlags sort,
|
|
||||||
QObject *parent = nullptr);
|
|
||||||
QT_DEPRECATED_VERSION_X_5_15("Use QFileSystemModel") explicit QDirModel(QObject *parent = nullptr);
|
|
||||||
~QDirModel();
|
|
||||||
|
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
QModelIndex parent(const QModelIndex &child) const override;
|
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
|
||||||
|
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
|
||||||
|
|
||||||
bool hasChildren(const QModelIndex &index = QModelIndex()) const override;
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
|
||||||
|
|
||||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
|
||||||
|
|
||||||
QStringList mimeTypes() const override;
|
|
||||||
QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
|
||||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
|
|
||||||
int row, int column, const QModelIndex &parent) override;
|
|
||||||
Qt::DropActions supportedDropActions() const override;
|
|
||||||
|
|
||||||
// QDirModel specific API
|
|
||||||
|
|
||||||
void setIconProvider(QFileIconProvider *provider);
|
|
||||||
QFileIconProvider *iconProvider() const;
|
|
||||||
|
|
||||||
void setNameFilters(const QStringList &filters);
|
|
||||||
QStringList nameFilters() const;
|
|
||||||
|
|
||||||
void setFilter(QDir::Filters filters);
|
|
||||||
QDir::Filters filter() const;
|
|
||||||
|
|
||||||
void setSorting(QDir::SortFlags sort);
|
|
||||||
QDir::SortFlags sorting() const;
|
|
||||||
|
|
||||||
void setResolveSymlinks(bool enable);
|
|
||||||
bool resolveSymlinks() const;
|
|
||||||
|
|
||||||
void setReadOnly(bool enable);
|
|
||||||
bool isReadOnly() const;
|
|
||||||
|
|
||||||
void setLazyChildCount(bool enable);
|
|
||||||
bool lazyChildCount() const;
|
|
||||||
|
|
||||||
QModelIndex index(const QString &path, int column = 0) const;
|
|
||||||
|
|
||||||
bool isDir(const QModelIndex &index) const;
|
|
||||||
QModelIndex mkdir(const QModelIndex &parent, const QString &name);
|
|
||||||
bool rmdir(const QModelIndex &index);
|
|
||||||
bool remove(const QModelIndex &index);
|
|
||||||
|
|
||||||
QString filePath(const QModelIndex &index) const;
|
|
||||||
QString fileName(const QModelIndex &index) const;
|
|
||||||
QIcon fileIcon(const QModelIndex &index) const;
|
|
||||||
QFileInfo fileInfo(const QModelIndex &index) const;
|
|
||||||
|
|
||||||
using QObject::parent;
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void refresh(const QModelIndex &parent = QModelIndex());
|
|
||||||
|
|
||||||
protected:
|
|
||||||
QDirModel(QDirModelPrivate &, QObject *parent = nullptr);
|
|
||||||
friend class QFileDialogPrivate;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Q_DECLARE_PRIVATE(QDirModel)
|
|
||||||
Q_DISABLE_COPY(QDirModel)
|
|
||||||
Q_PRIVATE_SLOT(d_func(), void _q_refresh())
|
|
||||||
};
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
#endif // QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
|
|
||||||
#endif // QDIRMODEL_H
|
|
@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
\inmodule QtWidgets
|
\inmodule QtWidgets
|
||||||
|
|
||||||
\brief The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes.
|
\brief The QFileIconProvider class provides file icons for the QFileSystemModel class.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -148,9 +148,6 @@
|
|||||||
#if QT_CONFIG(stringlistmodel)
|
#if QT_CONFIG(stringlistmodel)
|
||||||
#include "QtCore/qstringlistmodel.h"
|
#include "QtCore/qstringlistmodel.h"
|
||||||
#endif
|
#endif
|
||||||
#if QT_CONFIG(dirmodel)
|
|
||||||
#include "QtWidgets/qdirmodel.h"
|
|
||||||
#endif
|
|
||||||
#if QT_CONFIG(filesystemmodel)
|
#if QT_CONFIG(filesystemmodel)
|
||||||
#include "QtWidgets/qfilesystemmodel.h"
|
#include "QtWidgets/qfilesystemmodel.h"
|
||||||
#endif
|
#endif
|
||||||
@ -473,12 +470,6 @@ QMatchData QCompletionEngine::filterHistory()
|
|||||||
if (curParts.count() <= 1 || c->proxy->showAll || !source)
|
if (curParts.count() <= 1 || c->proxy->showAll || !source)
|
||||||
return QMatchData();
|
return QMatchData();
|
||||||
|
|
||||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
const bool isDirModel = (qobject_cast<QDirModel *>(source) != nullptr);
|
|
||||||
#else
|
|
||||||
const bool isDirModel = false;
|
|
||||||
#endif
|
|
||||||
Q_UNUSED(isDirModel)
|
|
||||||
#if QT_CONFIG(filesystemmodel)
|
#if QT_CONFIG(filesystemmodel)
|
||||||
const bool isFsModel = (qobject_cast<QFileSystemModel *>(source) != nullptr);
|
const bool isFsModel = (qobject_cast<QFileSystemModel *>(source) != nullptr);
|
||||||
#else
|
#else
|
||||||
@ -493,7 +484,7 @@ QMatchData QCompletionEngine::filterHistory()
|
|||||||
QString str = source->index(i, c->column).data().toString();
|
QString str = source->index(i, c->column).data().toString();
|
||||||
if (str.startsWith(c->prefix, c->cs)
|
if (str.startsWith(c->prefix, c->cs)
|
||||||
#if !defined(Q_OS_WIN)
|
#if !defined(Q_OS_WIN)
|
||||||
&& ((!isFsModel && !isDirModel) || QDir::toNativeSeparators(str) != QDir::separator())
|
&& (!isFsModel || QDir::toNativeSeparators(str) != QDir::separator())
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
m.indices.append(i);
|
m.indices.append(i);
|
||||||
@ -903,13 +894,6 @@ void QCompleterPrivate::_q_complete(QModelIndex index, bool highlighted)
|
|||||||
QModelIndex si = proxy->mapToSource(index);
|
QModelIndex si = proxy->mapToSource(index);
|
||||||
si = si.sibling(si.row(), column); // for clicked()
|
si = si.sibling(si.row(), column); // for clicked()
|
||||||
completion = q->pathFromIndex(si);
|
completion = q->pathFromIndex(si);
|
||||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
// add a trailing separator in inline
|
|
||||||
if (mode == QCompleter::InlineCompletion) {
|
|
||||||
if (qobject_cast<QDirModel *>(proxy->sourceModel()) && QFileInfo(completion).isDir())
|
|
||||||
completion += QDir::separator();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if QT_CONFIG(filesystemmodel)
|
#if QT_CONFIG(filesystemmodel)
|
||||||
// add a trailing separator in inline
|
// add a trailing separator in inline
|
||||||
if (mode == QCompleter::InlineCompletion) {
|
if (mode == QCompleter::InlineCompletion) {
|
||||||
@ -1125,15 +1109,6 @@ void QCompleter::setModel(QAbstractItemModel *model)
|
|||||||
setPopup(d->popup); // set the model and make new connections
|
setPopup(d->popup); // set the model and make new connections
|
||||||
if (oldModel && oldModel->QObject::parent() == this)
|
if (oldModel && oldModel->QObject::parent() == this)
|
||||||
delete oldModel;
|
delete oldModel;
|
||||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
if (qobject_cast<QDirModel *>(model)) {
|
|
||||||
#if defined(Q_OS_WIN)
|
|
||||||
setCaseSensitivity(Qt::CaseInsensitive);
|
|
||||||
#else
|
|
||||||
setCaseSensitivity(Qt::CaseSensitive);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif // QT_CONFIG(dirmodel)
|
|
||||||
#if QT_CONFIG(filesystemmodel)
|
#if QT_CONFIG(filesystemmodel)
|
||||||
QFileSystemModel *fsModel = qobject_cast<QFileSystemModel *>(model);
|
QFileSystemModel *fsModel = qobject_cast<QFileSystemModel *>(model);
|
||||||
if (fsModel) {
|
if (fsModel) {
|
||||||
@ -1844,26 +1819,19 @@ QString QCompleter::pathFromIndex(const QModelIndex& index) const
|
|||||||
QAbstractItemModel *sourceModel = d->proxy->sourceModel();
|
QAbstractItemModel *sourceModel = d->proxy->sourceModel();
|
||||||
if (!sourceModel)
|
if (!sourceModel)
|
||||||
return QString();
|
return QString();
|
||||||
bool isDirModel = false;
|
|
||||||
bool isFsModel = false;
|
bool isFsModel = false;
|
||||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != nullptr;
|
|
||||||
#endif
|
|
||||||
#if QT_CONFIG(filesystemmodel)
|
#if QT_CONFIG(filesystemmodel)
|
||||||
isFsModel = qobject_cast<QFileSystemModel *>(d->proxy->sourceModel()) != nullptr;
|
isFsModel = qobject_cast<QFileSystemModel *>(d->proxy->sourceModel()) != nullptr;
|
||||||
#endif
|
#endif
|
||||||
if (!isDirModel && !isFsModel)
|
if (!isFsModel)
|
||||||
return sourceModel->data(index, d->role).toString();
|
return sourceModel->data(index, d->role).toString();
|
||||||
|
|
||||||
QModelIndex idx = index;
|
QModelIndex idx = index;
|
||||||
QStringList list;
|
QStringList list;
|
||||||
do {
|
do {
|
||||||
QString t;
|
QString t;
|
||||||
if (isDirModel)
|
|
||||||
t = sourceModel->data(idx, Qt::EditRole).toString();
|
|
||||||
#if QT_CONFIG(filesystemmodel)
|
#if QT_CONFIG(filesystemmodel)
|
||||||
else
|
t = sourceModel->data(idx, QFileSystemModel::FileNameRole).toString();
|
||||||
t = sourceModel->data(idx, QFileSystemModel::FileNameRole).toString();
|
|
||||||
#endif
|
#endif
|
||||||
list.prepend(t);
|
list.prepend(t);
|
||||||
QModelIndex parent = idx.parent();
|
QModelIndex parent = idx.parent();
|
||||||
@ -1893,20 +1861,13 @@ QString QCompleter::pathFromIndex(const QModelIndex& index) const
|
|||||||
*/
|
*/
|
||||||
QStringList QCompleter::splitPath(const QString& path) const
|
QStringList QCompleter::splitPath(const QString& path) const
|
||||||
{
|
{
|
||||||
bool isDirModel = false;
|
|
||||||
bool isFsModel = false;
|
bool isFsModel = false;
|
||||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
Q_D(const QCompleter);
|
|
||||||
isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != nullptr;
|
|
||||||
#endif
|
|
||||||
#if QT_CONFIG(filesystemmodel)
|
#if QT_CONFIG(filesystemmodel)
|
||||||
#if !QT_CONFIG(dirmodel)
|
|
||||||
Q_D(const QCompleter);
|
Q_D(const QCompleter);
|
||||||
#endif
|
|
||||||
isFsModel = qobject_cast<QFileSystemModel *>(d->proxy->sourceModel()) != nullptr;
|
isFsModel = qobject_cast<QFileSystemModel *>(d->proxy->sourceModel()) != nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((!isDirModel && !isFsModel) || path.isEmpty())
|
if (!isFsModel || path.isEmpty())
|
||||||
return QStringList(completionPrefix());
|
return QStringList(completionPrefix());
|
||||||
|
|
||||||
QString pathCopy = QDir::toNativeSeparators(path);
|
QString pathCopy = QDir::toNativeSeparators(path);
|
||||||
|
@ -83,16 +83,13 @@ private:
|
|||||||
Add new tests, they can be the same model, but in a different state.
|
Add new tests, they can be the same model, but in a different state.
|
||||||
|
|
||||||
The name of the model is passed to createModel
|
The name of the model is passed to createModel
|
||||||
If readOnly is true the remove tests will be skipped. Example: QDirModel is disabled.
|
If readOnly is true the remove tests will be skipped. Example: QSqlQueryModel is disabled.
|
||||||
If createModel returns an empty model. Example: QDirModel does not
|
If createModel returns an empty model.
|
||||||
*/
|
*/
|
||||||
ModelsToTest::ModelsToTest()
|
ModelsToTest::ModelsToTest()
|
||||||
{
|
{
|
||||||
setupDatabase();
|
setupDatabase();
|
||||||
|
|
||||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
tests.append(test("QDirModel", ReadOnly, HasData));
|
|
||||||
#endif
|
|
||||||
tests.append(test("QStringListModel", ReadWrite, HasData));
|
tests.append(test("QStringListModel", ReadWrite, HasData));
|
||||||
tests.append(test("QStringListModelEmpty", ReadWrite, Empty));
|
tests.append(test("QStringListModelEmpty", ReadWrite, Empty));
|
||||||
|
|
||||||
@ -167,17 +164,6 @@ QAbstractItemModel *ModelsToTest::createModel(const QString &modelType)
|
|||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
QT_WARNING_PUSH
|
|
||||||
QT_WARNING_DISABLE_DEPRECATED
|
|
||||||
if (modelType == "QDirModel") {
|
|
||||||
QDirModel *model = new QDirModel();
|
|
||||||
model->setReadOnly(false);
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
QT_WARNING_POP
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (modelType == "QSqlQueryModel") {
|
if (modelType == "QSqlQueryModel") {
|
||||||
QSqlQueryModel *model = new QSqlQueryModel();
|
QSqlQueryModel *model = new QSqlQueryModel();
|
||||||
populateTestArea(model);
|
populateTestArea(model);
|
||||||
@ -294,25 +280,6 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model)
|
|||||||
return returnIndex;
|
return returnIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
if (QDirModel *dirModel = qobject_cast<QDirModel *>(model)) {
|
|
||||||
m_dirModelTempDir.reset(new QTemporaryDir);
|
|
||||||
if (!m_dirModelTempDir->isValid())
|
|
||||||
qFatal("Cannot create temporary directory \"%s\": %s",
|
|
||||||
qPrintable(QDir::toNativeSeparators(m_dirModelTempDir->path())),
|
|
||||||
qPrintable(m_dirModelTempDir->errorString()));
|
|
||||||
|
|
||||||
QDir tempDir(m_dirModelTempDir->path());
|
|
||||||
for (int i = 0; i < 26; ++i) {
|
|
||||||
const QString subdir = QLatin1String("foo_") + QString::number(i);
|
|
||||||
if (!tempDir.mkdir(subdir))
|
|
||||||
qFatal("Cannot create directory %s",
|
|
||||||
qPrintable(QDir::toNativeSeparators(tempDir.path() + QLatin1Char('/') +subdir)));
|
|
||||||
}
|
|
||||||
return dirModel->index(tempDir.path());
|
|
||||||
}
|
|
||||||
#endif // QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
|
|
||||||
if (QSqlQueryModel *queryModel = qobject_cast<QSqlQueryModel *>(model)) {
|
if (QSqlQueryModel *queryModel = qobject_cast<QSqlQueryModel *>(model)) {
|
||||||
QSqlQuery q;
|
QSqlQuery q;
|
||||||
q.exec("CREATE TABLE test(id int primary key, name varchar(30))");
|
q.exec("CREATE TABLE test(id int primary key, name varchar(30))");
|
||||||
@ -370,10 +337,6 @@ void ModelsToTest::cleanupTestArea(QAbstractItemModel *model)
|
|||||||
{
|
{
|
||||||
if (qobject_cast<QSqlQueryModel *>(model))
|
if (qobject_cast<QSqlQueryModel *>(model))
|
||||||
QSqlQuery q("DROP TABLE test");
|
QSqlQuery q("DROP TABLE test");
|
||||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
if (qobject_cast<QDirModel *>(model))
|
|
||||||
m_dirModelTempDir.reset();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelsToTest::setupDatabase()
|
void ModelsToTest::setupDatabase()
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
#include <qsharedpointer.h>
|
#include <qsharedpointer.h>
|
||||||
#include <qfiledialog.h>
|
#include <qfiledialog.h>
|
||||||
#include <qabstractitemdelegate.h>
|
#include <qabstractitemdelegate.h>
|
||||||
#include <qdirmodel.h>
|
|
||||||
#include <qitemdelegate.h>
|
#include <qitemdelegate.h>
|
||||||
#include <qlistview.h>
|
#include <qlistview.h>
|
||||||
#include <qcombobox.h>
|
#include <qcombobox.h>
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <qfiledialog.h>
|
#include <qfiledialog.h>
|
||||||
#include <qabstractitemdelegate.h>
|
#include <qabstractitemdelegate.h>
|
||||||
#include <qdirmodel.h>
|
|
||||||
#include <qitemdelegate.h>
|
#include <qitemdelegate.h>
|
||||||
#include <qlistview.h>
|
#include <qlistview.h>
|
||||||
#include <qcombobox.h>
|
#include <qcombobox.h>
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
add_subdirectory(qabstractitemview)
|
add_subdirectory(qabstractitemview)
|
||||||
add_subdirectory(qdatawidgetmapper)
|
add_subdirectory(qdatawidgetmapper)
|
||||||
add_subdirectory(qdirmodel)
|
|
||||||
add_subdirectory(qfileiconprovider)
|
add_subdirectory(qfileiconprovider)
|
||||||
add_subdirectory(qheaderview)
|
add_subdirectory(qheaderview)
|
||||||
add_subdirectory(qitemdelegate)
|
add_subdirectory(qitemdelegate)
|
||||||
|
@ -3,7 +3,6 @@ SUBDIRS=\
|
|||||||
qabstractitemview \
|
qabstractitemview \
|
||||||
qcolumnview \
|
qcolumnview \
|
||||||
qdatawidgetmapper \
|
qdatawidgetmapper \
|
||||||
qdirmodel \
|
|
||||||
qfileiconprovider \
|
qfileiconprovider \
|
||||||
qheaderview \
|
qheaderview \
|
||||||
qitemdelegate \
|
qitemdelegate \
|
||||||
|
@ -1 +0,0 @@
|
|||||||
tst_qdirmodel
|
|
@ -1,49 +0,0 @@
|
|||||||
# Generated from qdirmodel.pro.
|
|
||||||
|
|
||||||
#####################################################################
|
|
||||||
## tst_qdirmodel Test:
|
|
||||||
#####################################################################
|
|
||||||
|
|
||||||
add_qt_test(tst_qdirmodel
|
|
||||||
SOURCES
|
|
||||||
../../../../shared/emulationdetector.h
|
|
||||||
tst_qdirmodel.cpp
|
|
||||||
INCLUDE_DIRECTORIES
|
|
||||||
../../../../shared
|
|
||||||
PUBLIC_LIBRARIES
|
|
||||||
Qt::Gui
|
|
||||||
Qt::Widgets
|
|
||||||
)
|
|
||||||
|
|
||||||
## Scopes:
|
|
||||||
#####################################################################
|
|
||||||
|
|
||||||
extend_target(tst_qdirmodel CONDITION ANDROID
|
|
||||||
DEFINES
|
|
||||||
SRCDIR=\\\"./\\\"
|
|
||||||
)
|
|
||||||
|
|
||||||
extend_target(tst_qdirmodel CONDITION NOT ANDROID
|
|
||||||
DEFINES
|
|
||||||
SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/\\\"
|
|
||||||
)
|
|
||||||
|
|
||||||
if(ANDROID AND NOT ANDROID_EMBEDDED)
|
|
||||||
# Resources:
|
|
||||||
set(testdata_resource_files
|
|
||||||
"dirtest/test1/dummy"
|
|
||||||
"dirtest/test1/test"
|
|
||||||
"test/file01.tst"
|
|
||||||
"test/file02.tst"
|
|
||||||
"test/file03.tst"
|
|
||||||
"test/file04.tst"
|
|
||||||
"tst_qdirmodel.cpp"
|
|
||||||
)
|
|
||||||
|
|
||||||
add_qt_resource(tst_qdirmodel "testdata"
|
|
||||||
PREFIX
|
|
||||||
"/android_testdata"
|
|
||||||
FILES
|
|
||||||
${testdata_resource_files}
|
|
||||||
)
|
|
||||||
endif()
|
|
@ -1 +0,0 @@
|
|||||||
ECHO is on.
|
|
@ -1,18 +0,0 @@
|
|||||||
CONFIG += testcase
|
|
||||||
TARGET = tst_qdirmodel
|
|
||||||
QT += widgets testlib
|
|
||||||
SOURCES += tst_qdirmodel.cpp
|
|
||||||
|
|
||||||
INCLUDEPATH += ../../../../shared/
|
|
||||||
HEADERS += ../../../../shared/emulationdetector.h
|
|
||||||
|
|
||||||
android {
|
|
||||||
DEFINES += SRCDIR=\\\"./\\\"
|
|
||||||
} else {
|
|
||||||
DEFINES += SRCDIR=\\\"$$PWD/\\\"
|
|
||||||
}
|
|
||||||
|
|
||||||
android:!android-embedded {
|
|
||||||
RESOURCES += \
|
|
||||||
testdata.qrc
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
<RCC>
|
|
||||||
<qresource prefix="/android_testdata">
|
|
||||||
<file>dirtest/test1/dummy</file>
|
|
||||||
<file>dirtest/test1/test</file>
|
|
||||||
<file>test/file01.tst</file>
|
|
||||||
<file>test/file02.tst</file>
|
|
||||||
<file>test/file03.tst</file>
|
|
||||||
<file>test/file04.tst</file>
|
|
||||||
<file>tst_qdirmodel.cpp</file>
|
|
||||||
</qresource>
|
|
||||||
</RCC>
|
|
@ -1,722 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
|
||||||
**
|
|
||||||
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
** $QT_END_LICENSE$
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include <QtTest/QtTest>
|
|
||||||
#include <qdirmodel.h>
|
|
||||||
#include <qapplication.h>
|
|
||||||
#include <qtreeview.h>
|
|
||||||
#include <qdir.h>
|
|
||||||
#include <qdebug.h>
|
|
||||||
#include "emulationdetector.h"
|
|
||||||
|
|
||||||
QT_WARNING_DISABLE_DEPRECATED
|
|
||||||
|
|
||||||
class tst_QDirModel : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public slots:
|
|
||||||
void initTestCase();
|
|
||||||
void cleanupTestCase();
|
|
||||||
void init();
|
|
||||||
private slots:
|
|
||||||
void getSetCheck();
|
|
||||||
void unreadable();
|
|
||||||
/*
|
|
||||||
void construct();
|
|
||||||
void rowCount();
|
|
||||||
void columnCount();
|
|
||||||
void t_data();
|
|
||||||
void setData();
|
|
||||||
void hasChildren();
|
|
||||||
void isEditable();
|
|
||||||
void isDragEnabled();
|
|
||||||
void isDropEnabled();
|
|
||||||
void sort();
|
|
||||||
*/
|
|
||||||
bool rowsAboutToBeRemoved_init(const QString &test_path, const QStringList &initial_files);
|
|
||||||
bool rowsAboutToBeRemoved_cleanup(const QString &test_path);
|
|
||||||
void rowsAboutToBeRemoved_data();
|
|
||||||
void rowsAboutToBeRemoved();
|
|
||||||
|
|
||||||
void mkdir_data();
|
|
||||||
void mkdir();
|
|
||||||
|
|
||||||
void rmdir_data();
|
|
||||||
void rmdir();
|
|
||||||
|
|
||||||
void filePath();
|
|
||||||
|
|
||||||
void hidden();
|
|
||||||
|
|
||||||
void fileName();
|
|
||||||
void fileName_data();
|
|
||||||
void task196768_sorting();
|
|
||||||
void filter();
|
|
||||||
|
|
||||||
void task244669_remove();
|
|
||||||
|
|
||||||
void roleNames_data();
|
|
||||||
void roleNames();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Testing get/set functions
|
|
||||||
void tst_QDirModel::getSetCheck()
|
|
||||||
{
|
|
||||||
QDirModel obj1;
|
|
||||||
// QFileIconProvider * QDirModel::iconProvider()
|
|
||||||
// void QDirModel::setIconProvider(QFileIconProvider *)
|
|
||||||
QFileIconProvider *var1 = new QFileIconProvider;
|
|
||||||
obj1.setIconProvider(var1);
|
|
||||||
QCOMPARE(var1, obj1.iconProvider());
|
|
||||||
obj1.setIconProvider((QFileIconProvider *)0);
|
|
||||||
QCOMPARE((QFileIconProvider *)0, obj1.iconProvider());
|
|
||||||
delete var1;
|
|
||||||
|
|
||||||
// bool QDirModel::resolveSymlinks()
|
|
||||||
// void QDirModel::setResolveSymlinks(bool)
|
|
||||||
obj1.setResolveSymlinks(false);
|
|
||||||
QCOMPARE(false, obj1.resolveSymlinks());
|
|
||||||
obj1.setResolveSymlinks(true);
|
|
||||||
QCOMPARE(true, obj1.resolveSymlinks());
|
|
||||||
|
|
||||||
// bool QDirModel::lazyChildCount()
|
|
||||||
// void QDirModel::setLazyChildCount(bool)
|
|
||||||
obj1.setLazyChildCount(false);
|
|
||||||
QCOMPARE(false, obj1.lazyChildCount());
|
|
||||||
obj1.setLazyChildCount(true);
|
|
||||||
QCOMPARE(true, obj1.lazyChildCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::initTestCase()
|
|
||||||
{
|
|
||||||
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
|
|
||||||
QString dataPath = SRCDIR;
|
|
||||||
QString resourceSourcePath = QStringLiteral(":/android_testdata");
|
|
||||||
QDirIterator it(resourceSourcePath, QDirIterator::Subdirectories);
|
|
||||||
while (it.hasNext()) {
|
|
||||||
it.next();
|
|
||||||
|
|
||||||
QFileInfo fileInfo = it.fileInfo();
|
|
||||||
if (!fileInfo.isDir()) {
|
|
||||||
QString destination = dataPath + QLatin1Char('/') + fileInfo.filePath().mid(resourceSourcePath.length());
|
|
||||||
QFileInfo destinationFileInfo(destination);
|
|
||||||
if (!destinationFileInfo.exists()) {
|
|
||||||
QDir().mkpath(destinationFileInfo.path());
|
|
||||||
if (!QFile::copy(fileInfo.filePath(), destination))
|
|
||||||
qWarning("Failed to copy %s", qPrintable(fileInfo.filePath()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::cleanupTestCase()
|
|
||||||
{
|
|
||||||
QDir current;
|
|
||||||
current.rmdir(".qtest_hidden");
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::init()
|
|
||||||
{
|
|
||||||
#ifdef Q_OS_UNIX
|
|
||||||
if (QTest::currentTestFunction() == QLatin1String( "unreadable" )) {
|
|
||||||
// Make sure that the unreadable file created by the unreadable()
|
|
||||||
// test function doesn't already exist.
|
|
||||||
QFile unreadableFile(QDir::currentPath() + "qtest_unreadable");
|
|
||||||
if (unreadableFile.exists()) {
|
|
||||||
unreadableFile.remove();
|
|
||||||
QVERIFY(!unreadableFile.exists());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
tests
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
void tst_QDirModel::construct()
|
|
||||||
{
|
|
||||||
QDirModel model;
|
|
||||||
QModelIndex index = model.index(QDir::currentPath() + "/test");
|
|
||||||
index = model.index(2, 0, index);
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
QFileInfo info(QDir::currentPath() + "/test/file03.tst");
|
|
||||||
QCOMPARE(model.filePath(index), info.absoluteFilePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::rowCount()
|
|
||||||
{
|
|
||||||
QDirModel model;
|
|
||||||
QModelIndex index = model.index(QDir::currentPath() + "/test");
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
QCOMPARE(model.rowCount(index), 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::columnCount()
|
|
||||||
{
|
|
||||||
QDirModel model;
|
|
||||||
QModelIndex index = model.index(QDir::currentPath() + "/test");
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
QCOMPARE(model.columnCount(index), 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::t_data()
|
|
||||||
{
|
|
||||||
QDirModel model;
|
|
||||||
QModelIndex index = model.index(QDir::currentPath() + "/test");
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
QCOMPARE(model.rowCount(index), 4);
|
|
||||||
|
|
||||||
index = model.index(2, 0, index);
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
QCOMPARE(model.data(index).toString(), QString::fromLatin1("file03.tst"));
|
|
||||||
QCOMPARE(model.rowCount(index), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::setData()
|
|
||||||
{
|
|
||||||
QDirModel model;
|
|
||||||
QModelIndex index = model.index(QDir::currentPath() + "/test");
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
|
|
||||||
index = model.index(2, 0, index);
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
QVERIFY(!model.setData(index, "file0X.tst", Qt::EditRole));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::hasChildren()
|
|
||||||
{
|
|
||||||
QDirModel model;
|
|
||||||
QModelIndex index = model.index(QDir::currentPath() + "/test");
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
|
|
||||||
index = model.index(2, 0, index);
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
QVERIFY(!model.hasChildren(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::isEditable()
|
|
||||||
{
|
|
||||||
QDirModel model;
|
|
||||||
QModelIndex index = model.index(QDir::currentPath() + "/test");
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
|
|
||||||
index = model.index(2, 0, index);
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
QVERIFY(!(model.flags(index) & Qt::ItemIsEditable));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::isDragEnabled()
|
|
||||||
{
|
|
||||||
QDirModel model;
|
|
||||||
QModelIndex index = model.index(QDir::currentPath() + "/test");
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
|
|
||||||
index = model.index(2, 0, index);
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
QVERIFY(model.flags(index) & Qt::ItemIsDragEnabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::isDropEnabled()
|
|
||||||
{
|
|
||||||
QDirModel model;
|
|
||||||
QModelIndex index = model.index(QDir::currentPath() + "/test");
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
|
|
||||||
index = model.index(2, 0, index);
|
|
||||||
QVERIFY(!(model.flags(index) & Qt::ItemIsDropEnabled));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::sort()
|
|
||||||
{
|
|
||||||
QDirModel model;
|
|
||||||
QModelIndex parent = model.index(QDir::currentPath() + "/test");
|
|
||||||
QVERIFY(parent.isValid());
|
|
||||||
|
|
||||||
QModelIndex index = model.index(0, 0, parent);
|
|
||||||
QCOMPARE(model.data(index).toString(), QString::fromLatin1("file01.tst"));
|
|
||||||
|
|
||||||
index = model.index(3, 0, parent);
|
|
||||||
QCOMPARE(model.data(index).toString(), QString::fromLatin1("file04.tst"));
|
|
||||||
|
|
||||||
model.sort(0, Qt::DescendingOrder);
|
|
||||||
parent = model.index(QDir::currentPath() + "/test");
|
|
||||||
|
|
||||||
index = model.index(0, 0, parent);
|
|
||||||
QCOMPARE(model.data(index).toString(), QString::fromLatin1("file04.tst"));
|
|
||||||
|
|
||||||
index = model.index(3, 0, parent);
|
|
||||||
QCOMPARE(model.data(index).toString(), QString::fromLatin1("file01.tst"));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void tst_QDirModel::mkdir_data()
|
|
||||||
{
|
|
||||||
QTest::addColumn<QString>("dirName"); // the directory to be made under <currentpath>/dirtest
|
|
||||||
QTest::addColumn<bool>("mkdirSuccess");
|
|
||||||
QTest::addColumn<int>("rowCount");
|
|
||||||
|
|
||||||
QTest::newRow("okDirName") << QString("test2") << true << 2;
|
|
||||||
QTest::newRow("existingDirName") << QString("test1") << false << 1;
|
|
||||||
QTest::newRow("nameWithSpace") << QString("ab cd") << true << 2;
|
|
||||||
QTest::newRow("emptyDirName") << QString("") << false << 1;
|
|
||||||
QTest::newRow("nullDirName") << QString() << false << 1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
QTest::newRow("recursiveDirName") << QString("test2/test3") << false << false;
|
|
||||||
QTest::newRow("singleDotDirName") << QString("./test3") << true << true;
|
|
||||||
QTest::newRow("outOfTreeDirName") << QString("../test4") << false << false;
|
|
||||||
QTest::newRow("insideTreeDirName") << QString("../dirtest/test4") << true << true;
|
|
||||||
QTest::newRow("insideTreeDirName2") << QString("./././././../dirtest/./../dirtest/test4") << true << true;
|
|
||||||
QTest::newRow("absoluteDirName") << QString(QDir::currentPath() + "/dirtest/test5") << true << true;
|
|
||||||
QTest::newRow("outOfTreeDirName") << QString(QDir::currentPath() + "/test5") << false << false;
|
|
||||||
|
|
||||||
// Directory names only illegal on Windows
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
QTest::newRow("illegalDirName") << QString("*") << false << false;
|
|
||||||
QTest::newRow("illegalDirName2") << QString("|") << false << false;
|
|
||||||
QTest::newRow("onlySpace") << QString(" ") << false << false;
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::mkdir()
|
|
||||||
{
|
|
||||||
QFETCH(QString, dirName);
|
|
||||||
QFETCH(bool, mkdirSuccess);
|
|
||||||
QFETCH(int, rowCount);
|
|
||||||
|
|
||||||
QDirModel model;
|
|
||||||
model.setReadOnly(false);
|
|
||||||
|
|
||||||
QModelIndex parent = model.index(SRCDIR "dirtest");
|
|
||||||
#ifdef Q_OS_WINRT
|
|
||||||
QEXPECT_FAIL("", "Sandboxed applications cannot access SRCDIR - QTBUG-68297", Abort);
|
|
||||||
#endif
|
|
||||||
QVERIFY(parent.isValid());
|
|
||||||
QCOMPARE(model.rowCount(parent), 1); // start out with only 'test1' - in's in the depot
|
|
||||||
|
|
||||||
QModelIndex index = model.mkdir(parent, dirName);
|
|
||||||
bool success = index.isValid();
|
|
||||||
int rows = model.rowCount(parent);
|
|
||||||
|
|
||||||
if (success && !model.rmdir(index))
|
|
||||||
QVERIFY(QDir(SRCDIR "dirtests").rmdir(dirName));
|
|
||||||
|
|
||||||
QCOMPARE(rows, rowCount);
|
|
||||||
QCOMPARE(success, mkdirSuccess);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::rmdir_data()
|
|
||||||
{
|
|
||||||
QTest::addColumn<QString>("dirName"); // <currentpath>/dirtest/dirname
|
|
||||||
QTest::addColumn<bool>("rmdirSuccess");
|
|
||||||
QTest::addColumn<int>("rowCount");
|
|
||||||
|
|
||||||
QTest::newRow("okDirName") << QString("test2") << true << 2;
|
|
||||||
QTest::newRow("existingDirName") << QString("test1") << false << 1;
|
|
||||||
QTest::newRow("nameWithSpace") << QString("ab cd") << true << 2;
|
|
||||||
QTest::newRow("emptyDirName") << QString("") << false << 1;
|
|
||||||
QTest::newRow("nullDirName") << QString() << false << 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::rmdir()
|
|
||||||
{
|
|
||||||
QFETCH(QString, dirName);
|
|
||||||
QFETCH(bool, rmdirSuccess);
|
|
||||||
QFETCH(int, rowCount);
|
|
||||||
|
|
||||||
QDirModel model;
|
|
||||||
model.setReadOnly(false);
|
|
||||||
|
|
||||||
QModelIndex parent = model.index(SRCDIR "/dirtest");
|
|
||||||
#ifdef Q_OS_WINRT
|
|
||||||
QEXPECT_FAIL("", "Sandboxed applications cannot access SRCDIR - QTBUG-68297", Abort);
|
|
||||||
#endif
|
|
||||||
QVERIFY(parent.isValid());
|
|
||||||
QCOMPARE(model.rowCount(parent), 1); // start out with only 'test1' - in's in the depot
|
|
||||||
|
|
||||||
QModelIndex index;
|
|
||||||
if (rmdirSuccess) {
|
|
||||||
index = model.mkdir(parent, dirName);
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
int rows = model.rowCount(parent);
|
|
||||||
bool success = model.rmdir(index);
|
|
||||||
|
|
||||||
if (!success) { // cleanup
|
|
||||||
QDir dirtests(SRCDIR "/dirtests/");
|
|
||||||
dirtests.rmdir(dirName);
|
|
||||||
}
|
|
||||||
|
|
||||||
QCOMPARE(rows, rowCount);
|
|
||||||
QCOMPARE(success, rmdirSuccess);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::rowsAboutToBeRemoved_data()
|
|
||||||
{
|
|
||||||
QTest::addColumn<QString>("test_path");
|
|
||||||
QTest::addColumn<QStringList>("initial_files");
|
|
||||||
QTest::addColumn<int>("remove_row");
|
|
||||||
QTest::addColumn<QStringList>("remove_files");
|
|
||||||
QTest::addColumn<QStringList>("expected_files");
|
|
||||||
|
|
||||||
QString test_path = "test2";
|
|
||||||
QStringList initial_files = (QStringList()
|
|
||||||
<< "file1.tst"
|
|
||||||
<< "file2.tst"
|
|
||||||
<< "file3.tst"
|
|
||||||
<< "file4.tst");
|
|
||||||
|
|
||||||
QTest::newRow("removeFirstRow")
|
|
||||||
<< test_path
|
|
||||||
<< initial_files
|
|
||||||
<< 0
|
|
||||||
<< (QStringList() << "file1.tst")
|
|
||||||
<< (QStringList() << "file2.tst" << "file3.tst" << "file4.tst");
|
|
||||||
|
|
||||||
QTest::newRow("removeMiddle")
|
|
||||||
<< test_path
|
|
||||||
<< initial_files
|
|
||||||
<< 1
|
|
||||||
<< (QStringList() << "file2.tst")
|
|
||||||
<< (QStringList() << "file1.tst" << "file3.tst" << "file4.tst");
|
|
||||||
|
|
||||||
QTest::newRow("removeLastRow")
|
|
||||||
<< test_path
|
|
||||||
<< initial_files
|
|
||||||
<< 3
|
|
||||||
<< (QStringList() << "file4.tst")
|
|
||||||
<< (QStringList() << "file1.tst" << "file2.tst" << "file3.tst");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool tst_QDirModel::rowsAboutToBeRemoved_init(const QString &test_path, const QStringList &initial_files)
|
|
||||||
{
|
|
||||||
QString path = QDir::currentPath() + QLatin1Char('/') + test_path;
|
|
||||||
if (!QDir::current().mkdir(test_path) && false) { // FIXME
|
|
||||||
qDebug() << "failed to create dir" << path;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < initial_files.count(); ++i) {
|
|
||||||
QFile file(path + QLatin1Char('/') + initial_files.at(i));
|
|
||||||
if (!file.open(QIODevice::WriteOnly)) {
|
|
||||||
qDebug() << "failed to open file" << initial_files.at(i);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!file.resize(1024)) {
|
|
||||||
qDebug() << "failed to resize file" << initial_files.at(i);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!file.flush()) {
|
|
||||||
qDebug() << "failed to flush file" << initial_files.at(i);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool tst_QDirModel::rowsAboutToBeRemoved_cleanup(const QString &test_path)
|
|
||||||
{
|
|
||||||
QString path = QDir::currentPath() + QLatin1Char('/') + test_path;
|
|
||||||
QDir dir(path, "*", QDir::SortFlags(QDir::Name|QDir::IgnoreCase), QDir::Files);
|
|
||||||
QStringList files = dir.entryList();
|
|
||||||
|
|
||||||
for (int i = 0; i < files.count(); ++i) {
|
|
||||||
if (!dir.remove(files.at(i))) {
|
|
||||||
qDebug() << "failed to remove file" << files.at(i);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!QDir::current().rmdir(test_path) && false) { // FIXME
|
|
||||||
qDebug() << "failed to remove dir" << test_path;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::rowsAboutToBeRemoved()
|
|
||||||
{
|
|
||||||
#ifdef Q_OS_WINRT
|
|
||||||
QSKIP("Test fails on WinRT - QTBUG-68297");
|
|
||||||
#endif
|
|
||||||
QFETCH(QString, test_path);
|
|
||||||
QFETCH(QStringList, initial_files);
|
|
||||||
QFETCH(int, remove_row);
|
|
||||||
QFETCH(QStringList, remove_files);
|
|
||||||
QFETCH(QStringList, expected_files);
|
|
||||||
|
|
||||||
rowsAboutToBeRemoved_cleanup(test_path); // clean up first
|
|
||||||
QVERIFY(rowsAboutToBeRemoved_init(test_path, initial_files));
|
|
||||||
|
|
||||||
QDirModel model;
|
|
||||||
model.setReadOnly(false);
|
|
||||||
|
|
||||||
|
|
||||||
// NOTE: QDirModel will call refresh() when a file is removed. refresh() will reread the entire directory,
|
|
||||||
// and emit layoutAboutToBeChanged and layoutChange. So, instead of checking for
|
|
||||||
// rowsAboutToBeRemoved/rowsRemoved we check for layoutAboutToBeChanged/layoutChanged
|
|
||||||
QSignalSpy spy(&model, SIGNAL(layoutAboutToBeChanged()));
|
|
||||||
|
|
||||||
QModelIndex parent = model.index(test_path);
|
|
||||||
QVERIFY(parent.isValid());
|
|
||||||
|
|
||||||
// remove the file
|
|
||||||
{
|
|
||||||
QModelIndex index = model.index(remove_row, 0, parent);
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
QVERIFY(model.remove(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
QCOMPARE(spy.count(), 1);
|
|
||||||
|
|
||||||
// Compare the result
|
|
||||||
for (int row = 0; row < expected_files.count(); ++row) {
|
|
||||||
QModelIndex index = model.index(row, 0, parent);
|
|
||||||
QString str = index.data().toString();
|
|
||||||
QCOMPARE(str, expected_files.at(row));
|
|
||||||
}
|
|
||||||
|
|
||||||
QVERIFY(rowsAboutToBeRemoved_cleanup(test_path));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::hidden()
|
|
||||||
{
|
|
||||||
#ifndef Q_OS_UNIX
|
|
||||||
QSKIP("Test not implemented on non-Unixes");
|
|
||||||
#else
|
|
||||||
QDir current;
|
|
||||||
current.mkdir(".qtest_hidden");
|
|
||||||
|
|
||||||
QDirModel model;
|
|
||||||
QModelIndex index = model.index(QDir::currentPath() + "/.qtest_hidden");
|
|
||||||
//QVERIFY(!index.isValid()); // hidden items are not listed, but if you specify a valid path, it will give a valid index
|
|
||||||
|
|
||||||
current.mkdir(".qtest_hidden/qtest_visible");
|
|
||||||
QModelIndex index2 = model.index(QDir::currentPath() + "/.qtest_hidden/qtest_visible");
|
|
||||||
QVERIFY(index2.isValid());
|
|
||||||
|
|
||||||
QDirModel model2;
|
|
||||||
model2.setFilter(model2.filter() | QDir::Hidden);
|
|
||||||
index = model2.index(QDir::currentPath() + "/.qtest_hidden");
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::fileName_data()
|
|
||||||
{
|
|
||||||
QTest::addColumn<QString>("path");
|
|
||||||
QTest::addColumn<QString>("result");
|
|
||||||
|
|
||||||
QTest::newRow("invalid") << "" << "";
|
|
||||||
//QTest::newRow("root") << "/" << "/";
|
|
||||||
//QTest::newRow("home") << "/home" << "home";
|
|
||||||
// TODO add symlink test too
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::fileName()
|
|
||||||
{
|
|
||||||
QDirModel model;
|
|
||||||
|
|
||||||
QFETCH(QString, path);
|
|
||||||
QFETCH(QString, result);
|
|
||||||
QCOMPARE(model.fileName(model.index(path)), result);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::unreadable()
|
|
||||||
{
|
|
||||||
#ifndef Q_OS_UNIX
|
|
||||||
QSKIP("Test not implemented on non-Unixes");
|
|
||||||
#else
|
|
||||||
// Create an empty file which has no read permissions (file will be removed by cleanup()).
|
|
||||||
QFile unreadableFile(QDir::currentPath() + "qtest_unreadable");
|
|
||||||
QVERIFY2(unreadableFile.open(QIODevice::WriteOnly | QIODevice::Text), qPrintable(unreadableFile.errorString()));
|
|
||||||
unreadableFile.close();
|
|
||||||
QVERIFY(unreadableFile.exists());
|
|
||||||
QVERIFY2(unreadableFile.setPermissions(QFile::WriteOwner), qPrintable(unreadableFile.errorString()));
|
|
||||||
|
|
||||||
// Check that we can't make a valid model index from an unreadable file.
|
|
||||||
QDirModel model;
|
|
||||||
QModelIndex index = model.index(QDir::currentPath() + "/qtest_unreadable");
|
|
||||||
QVERIFY(!index.isValid());
|
|
||||||
|
|
||||||
// Check that unreadable files are not treated like hidden files.
|
|
||||||
QDirModel model2;
|
|
||||||
model2.setFilter(model2.filter() | QDir::Hidden);
|
|
||||||
index = model2.index(QDir::currentPath() + "/qtest_unreadable");
|
|
||||||
QVERIFY(!index.isValid());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::filePath()
|
|
||||||
{
|
|
||||||
QFile::remove(SRCDIR "test.lnk");
|
|
||||||
#ifdef Q_OS_WINRT
|
|
||||||
QEXPECT_FAIL("", "Sandboxed applications cannot access SRCDIR - QTBUG-68297", Abort);
|
|
||||||
#endif
|
|
||||||
QVERIFY(QFile(SRCDIR "tst_qdirmodel.cpp").link(SRCDIR "test.lnk"));
|
|
||||||
QDirModel model;
|
|
||||||
model.setResolveSymlinks(false);
|
|
||||||
QModelIndex index = model.index(SRCDIR "test.lnk");
|
|
||||||
QVERIFY(index.isValid());
|
|
||||||
#if !defined(Q_OS_ANDROID)
|
|
||||||
QString path = SRCDIR;
|
|
||||||
#else
|
|
||||||
QString path = QFileInfo(SRCDIR).absoluteFilePath();
|
|
||||||
if (!path.endsWith(QLatin1Char('/')))
|
|
||||||
path += QLatin1Char('/');
|
|
||||||
#endif
|
|
||||||
QCOMPARE(model.filePath(index), path + QString( "test.lnk"));
|
|
||||||
model.setResolveSymlinks(true);
|
|
||||||
QCOMPARE(model.filePath(index), path + QString( "tst_qdirmodel.cpp"));
|
|
||||||
QFile::remove(SRCDIR "test.lnk");
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::task196768_sorting()
|
|
||||||
{
|
|
||||||
//this task showed that the persistent model indexes got corrupted when sorting
|
|
||||||
QString path = SRCDIR;
|
|
||||||
|
|
||||||
QDirModel model;
|
|
||||||
|
|
||||||
/* QDirModel has a bug if we show the content of the subdirectory inside a hidden directory
|
|
||||||
and we don't add QDir::Hidden. But as QDirModel is deprecated, we decided not to fix it. */
|
|
||||||
model.setFilter(QDir::AllEntries | QDir::Hidden | QDir::AllDirs);
|
|
||||||
|
|
||||||
QTreeView view;
|
|
||||||
QPersistentModelIndex index = model.index(path);
|
|
||||||
view.setModel(&model);
|
|
||||||
QModelIndex index2 = model.index(path);
|
|
||||||
QCOMPARE(index.data(), index2.data());
|
|
||||||
view.setRootIndex(index);
|
|
||||||
index2 = model.index(path);
|
|
||||||
QCOMPARE(index.data(), index2.data());
|
|
||||||
view.setCurrentIndex(index);
|
|
||||||
index2 = model.index(path);
|
|
||||||
QCOMPARE(index.data(), index2.data());
|
|
||||||
view.setSortingEnabled(true);
|
|
||||||
index2 = model.index(path);
|
|
||||||
|
|
||||||
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
|
|
||||||
QEXPECT_FAIL("", "QTBUG-43818", Continue);
|
|
||||||
#else
|
|
||||||
if (EmulationDetector::isRunningArmOnX86())
|
|
||||||
QEXPECT_FAIL("", "QTBUG-43818", Continue);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QCOMPARE(index.data(), index2.data());
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::filter()
|
|
||||||
{
|
|
||||||
QDirModel model;
|
|
||||||
model.setNameFilters(QStringList() << "*.nada");
|
|
||||||
QModelIndex index = model.index(SRCDIR "test");
|
|
||||||
#ifdef Q_OS_WINRT
|
|
||||||
QEXPECT_FAIL("", "Sandboxed applications cannot access SRCDIR - QTBUG-68297", Abort);
|
|
||||||
#endif
|
|
||||||
QCOMPARE(model.rowCount(index), 0);
|
|
||||||
QModelIndex index2 = model.index(SRCDIR "test/file01.tst");
|
|
||||||
QVERIFY(!index2.isValid());
|
|
||||||
QCOMPARE(model.rowCount(index), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::task244669_remove()
|
|
||||||
{
|
|
||||||
QFile f1(SRCDIR "dirtest/f1.txt");
|
|
||||||
#ifdef Q_OS_WINRT
|
|
||||||
QEXPECT_FAIL("", "Sandboxed applications cannot access SRCDIR - QTBUG-68297", Abort);
|
|
||||||
#endif
|
|
||||||
QVERIFY(f1.open(QIODevice::WriteOnly));
|
|
||||||
f1.close();
|
|
||||||
QFile f2(SRCDIR "dirtest/f2.txt");
|
|
||||||
QVERIFY(f2.open(QIODevice::WriteOnly));
|
|
||||||
f2.close();
|
|
||||||
|
|
||||||
QDirModel model;
|
|
||||||
model.setReadOnly(false);
|
|
||||||
QPersistentModelIndex parent = model.index(SRCDIR "dirtest");
|
|
||||||
QPersistentModelIndex index2 = model.index(SRCDIR "dirtest/f2.txt");
|
|
||||||
QPersistentModelIndex index1 = model.index(SRCDIR "dirtest/f1.txt");
|
|
||||||
|
|
||||||
QVERIFY(parent.isValid());
|
|
||||||
QVERIFY(index1.isValid());
|
|
||||||
QVERIFY(index2.isValid());
|
|
||||||
QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data());
|
|
||||||
QCOMPARE(index1.data() , model.index(SRCDIR "dirtest/f1.txt").data());
|
|
||||||
QCOMPARE(index2.data() , model.index(SRCDIR "dirtest/f2.txt").data());
|
|
||||||
|
|
||||||
QVERIFY(model.remove(index1));
|
|
||||||
|
|
||||||
QVERIFY(parent.isValid());
|
|
||||||
QVERIFY(!index1.isValid());
|
|
||||||
QVERIFY(index2.isValid());
|
|
||||||
QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data());
|
|
||||||
QCOMPARE(index2.data() , model.index(SRCDIR "dirtest/f2.txt").data());
|
|
||||||
|
|
||||||
QVERIFY(model.remove(index2));
|
|
||||||
|
|
||||||
QVERIFY(parent.isValid());
|
|
||||||
QVERIFY(!index2.isValid());
|
|
||||||
QVERIFY(!index1.isValid());
|
|
||||||
QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data());
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::roleNames_data()
|
|
||||||
{
|
|
||||||
QTest::addColumn<int>("role");
|
|
||||||
QTest::addColumn<QByteArray>("roleName");
|
|
||||||
QTest::newRow("decoration") << int(Qt::DecorationRole) << QByteArray("fileIcon");
|
|
||||||
QTest::newRow("display") << int(Qt::DisplayRole) << QByteArray("display");
|
|
||||||
QTest::newRow("fileIcon") << int(QDirModel::FileIconRole) << QByteArray("fileIcon");
|
|
||||||
QTest::newRow("filePath") << int(QDirModel::FilePathRole) << QByteArray("filePath");
|
|
||||||
QTest::newRow("fileName") << int(QDirModel::FileNameRole) << QByteArray("fileName");
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QDirModel::roleNames()
|
|
||||||
{
|
|
||||||
QDirModel model;
|
|
||||||
QHash<int, QByteArray> roles = model.roleNames();
|
|
||||||
|
|
||||||
QFETCH(int, role);
|
|
||||||
QVERIFY(roles.contains(role));
|
|
||||||
|
|
||||||
QFETCH(QByteArray, roleName);
|
|
||||||
QCOMPARE(roles.contains(role), true);
|
|
||||||
QCOMPARE(roles.value(role), roleName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN(tst_QDirModel)
|
|
||||||
#include "tst_qdirmodel.moc"
|
|
@ -107,10 +107,6 @@ private slots:
|
|||||||
void csMatchingOnCiSortedModel_data();
|
void csMatchingOnCiSortedModel_data();
|
||||||
void csMatchingOnCiSortedModel();
|
void csMatchingOnCiSortedModel();
|
||||||
|
|
||||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
void directoryModel_data();
|
|
||||||
void directoryModel();
|
|
||||||
#endif
|
|
||||||
void fileSystemModel_data();
|
void fileSystemModel_data();
|
||||||
void fileSystemModel();
|
void fileSystemModel();
|
||||||
|
|
||||||
@ -153,7 +149,6 @@ private:
|
|||||||
enum ModelType {
|
enum ModelType {
|
||||||
CASE_SENSITIVELY_SORTED_MODEL,
|
CASE_SENSITIVELY_SORTED_MODEL,
|
||||||
CASE_INSENSITIVELY_SORTED_MODEL,
|
CASE_INSENSITIVELY_SORTED_MODEL,
|
||||||
DIRECTORY_MODEL,
|
|
||||||
HISTORY_MODEL,
|
HISTORY_MODEL,
|
||||||
FILESYSTEM_MODEL
|
FILESYSTEM_MODEL
|
||||||
};
|
};
|
||||||
@ -225,16 +220,6 @@ void tst_QCompleter::setSourceModel(ModelType type)
|
|||||||
parent = new QTreeWidgetItem(treeWidget);
|
parent = new QTreeWidgetItem(treeWidget);
|
||||||
parent->setText(completionColumn, QLatin1String("p2,c4p2"));
|
parent->setText(completionColumn, QLatin1String("p2,c4p2"));
|
||||||
break;
|
break;
|
||||||
case DIRECTORY_MODEL:
|
|
||||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
QT_WARNING_PUSH
|
|
||||||
QT_WARNING_DISABLE_DEPRECATED
|
|
||||||
completer->setCsvCompletion(false);
|
|
||||||
completer->setModel(new QDirModel(completer));
|
|
||||||
completer->setCompletionColumn(0);
|
|
||||||
QT_WARNING_POP
|
|
||||||
#endif // QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
break;
|
|
||||||
case FILESYSTEM_MODEL:
|
case FILESYSTEM_MODEL:
|
||||||
completer->setCsvCompletion(false);
|
completer->setCsvCompletion(false);
|
||||||
{
|
{
|
||||||
@ -597,58 +582,6 @@ void tst_QCompleter::csMatchingOnCiSortedModel()
|
|||||||
filter();
|
filter();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
void tst_QCompleter::directoryModel_data()
|
|
||||||
{
|
|
||||||
delete completer;
|
|
||||||
|
|
||||||
completer = new CsvCompleter;
|
|
||||||
completer->setModelSorting(QCompleter::CaseSensitivelySortedModel);
|
|
||||||
setSourceModel(DIRECTORY_MODEL);
|
|
||||||
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
|
||||||
|
|
||||||
QTest::addColumn<QString>("filterText");
|
|
||||||
QTest::addColumn<QString>("step");
|
|
||||||
QTest::addColumn<QString>("completion");
|
|
||||||
QTest::addColumn<QString>("completionText");
|
|
||||||
|
|
||||||
// NOTE: Add tests carefully, ensurely the paths exist on all systems
|
|
||||||
// Output is the sourceText; currentCompletionText()
|
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
if (i == 1)
|
|
||||||
QTest::newRow("FILTERING_OFF") << "FILTERING_OFF" << "" << "" << "";
|
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
|
||||||
QTest::newRow("()") << "C" << "" << "C:" << "C:";
|
|
||||||
QTest::newRow("()") << "C:\\Program" << "" << "Program Files" << "C:\\Program Files";
|
|
||||||
#elif defined (Q_OS_MAC)
|
|
||||||
QTest::newRow("()") << "" << "" << "/" << "/";
|
|
||||||
QTest::newRow("(/a)") << "/a" << "" << "Applications" << "/Applications";
|
|
||||||
QTest::newRow("(/u)") << "/u" << "" << "Users" << "/Users";
|
|
||||||
#elif defined(Q_OS_ANDROID)
|
|
||||||
QTest::newRow("()") << "" << "" << "/" << "/";
|
|
||||||
QTest::newRow("(/et)") << "/et" << "" << "etc" << "/etc";
|
|
||||||
#else
|
|
||||||
QTest::newRow("()") << "" << "" << "/" << "/";
|
|
||||||
#if !defined(Q_OS_AIX) && !defined(Q_OS_HPUX) && !defined(Q_OS_QNX)
|
|
||||||
QTest::newRow("(/h)") << "/h" << "" << "home" << "/home";
|
|
||||||
#endif
|
|
||||||
QTest::newRow("(/et)") << "/et" << "" << "etc" << "/etc";
|
|
||||||
QTest::newRow("(/etc/passw)") << "/etc/passw" << "" << "passwd" << "/etc/passwd";
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QCompleter::directoryModel()
|
|
||||||
{
|
|
||||||
#ifdef Q_OS_WINRT
|
|
||||||
QSKIP("WinRT cannot access directories outside of the application's sandbox");
|
|
||||||
#endif
|
|
||||||
filter();
|
|
||||||
}
|
|
||||||
#endif // QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
|
||||||
|
|
||||||
void tst_QCompleter::fileSystemModel_data()
|
void tst_QCompleter::fileSystemModel_data()
|
||||||
{
|
{
|
||||||
delete completer;
|
delete completer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user