diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2010-01-08 14:33:06 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2010-01-08 15:16:50 (GMT) |
commit | 319b0262418d74cc416a7dd1f620b54ba45bad22 (patch) | |
tree | e4c8b7af34eb0ee8b2970ec54bfe5aea8f861bbd /examples | |
parent | 2e62227f950aac8205f2b67e4d7d046836b2c799 (diff) | |
download | Qt-319b0262418d74cc416a7dd1f620b54ba45bad22.zip Qt-319b0262418d74cc416a7dd1f620b54ba45bad22.tar.gz Qt-319b0262418d74cc416a7dd1f620b54ba45bad22.tar.bz2 |
Obsolete QDirModel and remove it from the doc.
QFileSystemModel provides the same features as QDirModel but in a
efficient way so no need to keep QDirModel around.
This commit mark as obsolete QDirModel. Examples has been ported to
use QFileSystemModel instead. QCompleter also gain the support of
QFileSystemModel to complete nicely a line edit.
This commit also add a new signal in QFileSystemModel when the directory
is loaded, i.e. the thread has finished to read the current dir.
Task-number:QTBUG-3884
Reviewed-by:ogoffart
Reviewed-by:gabi
Reviewed-by:mbm
Diffstat (limited to 'examples')
-rw-r--r-- | examples/itemviews/dirview/main.cpp | 3 | ||||
-rw-r--r-- | examples/tools/completer/dirmodel.cpp | 9 | ||||
-rw-r--r-- | examples/tools/completer/dirmodel.h | 12 | ||||
-rw-r--r-- | examples/tools/completer/mainwindow.cpp | 18 |
4 files changed, 23 insertions, 19 deletions
diff --git a/examples/itemviews/dirview/main.cpp b/examples/itemviews/dirview/main.cpp index 768046a..e7e343e 100644 --- a/examples/itemviews/dirview/main.cpp +++ b/examples/itemviews/dirview/main.cpp @@ -45,7 +45,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - QDirModel model; + QFileSystemModel model; + model.setRootPath(""); QTreeView tree; tree.setModel(&model); diff --git a/examples/tools/completer/dirmodel.cpp b/examples/tools/completer/dirmodel.cpp index 9fd7763..1173d88 100644 --- a/examples/tools/completer/dirmodel.cpp +++ b/examples/tools/completer/dirmodel.cpp @@ -42,14 +42,14 @@ #include "dirmodel.h" //! [0] -DirModel::DirModel(QObject *parent) - : QDirModel(parent) +FileSystemModel::FileSystemModel(QObject *parent) + : QFileSystemModel(parent) { } //! [0] //! [1] -QVariant DirModel::data(const QModelIndex &index, int role) const +QVariant FileSystemModel::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole && index.column() == 0) { QString path = QDir::toNativeSeparators(filePath(index)); @@ -58,6 +58,7 @@ QVariant DirModel::data(const QModelIndex &index, int role) const return path; } - return QDirModel::data(index, role); + return QFileSystemModel::data(index, role); } + //! [1] diff --git a/examples/tools/completer/dirmodel.h b/examples/tools/completer/dirmodel.h index a690f6c..5f4d2a7 100644 --- a/examples/tools/completer/dirmodel.h +++ b/examples/tools/completer/dirmodel.h @@ -39,21 +39,21 @@ ** ****************************************************************************/ -#ifndef DIRMODEL_H -#define DIRMODEL_H +#ifndef FILESYSTEMMODEL_H +#define FILESYSTEMMODEL_H -#include <QDirModel> +#include <QFileSystemModel> -// With a QDirModel, set on a view, you will see "Program Files" in the view +// With a QFileSystemModel, set on a view, you will see "Program Files" in the view // But with this model, you will see "C:\Program Files" in the view. // We acheive this, by having the data() return the entire file path for // the display role. Note that the Qt::EditRole over which the QCompleter // looks for matches is left unchanged //! [0] -class DirModel : public QDirModel +class FileSystemModel : public QFileSystemModel { public: - DirModel(QObject *parent = 0); + FileSystemModel(QObject *parent = 0); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; }; //! [0] diff --git a/examples/tools/completer/mainwindow.cpp b/examples/tools/completer/mainwindow.cpp index 8fe8c37..e5ee68e 100644 --- a/examples/tools/completer/mainwindow.cpp +++ b/examples/tools/completer/mainwindow.cpp @@ -55,8 +55,8 @@ MainWindow::MainWindow(QWidget *parent) modelLabel->setText(tr("Model")); modelCombo = new QComboBox; - modelCombo->addItem(tr("QDirModel")); - modelCombo->addItem(tr("QDirModel that shows full path")); + modelCombo->addItem(tr("QFileSytemModel")); + modelCombo->addItem(tr("QFileSytemModel that shows full path")); modelCombo->addItem(tr("Country list")); modelCombo->addItem(tr("Word list")); modelCombo->setCurrentIndex(0); @@ -218,17 +218,19 @@ void MainWindow::changeModel() switch (modelCombo->currentIndex()) { default: case 0: - { // Unsorted QDirModel - QDirModel *dirModel = new QDirModel(completer); - completer->setModel(dirModel); + { // Unsorted QFileSystemModel + QFileSystemModel *fsModel = new QFileSystemModel(completer); + fsModel->setRootPath(""); + completer->setModel(fsModel); contentsLabel->setText(tr("Enter file path")); } break; //! [11] //! [12] case 1: - { // DirModel that shows full paths - DirModel *dirModel = new DirModel(completer); - completer->setModel(dirModel); + { // FileSystemModel that shows full paths + FileSystemModel *fsModel = new FileSystemModel(completer); + completer->setModel(fsModel); + fsModel->setRootPath(""); contentsLabel->setText(tr("Enter file path")); } break; |