summaryrefslogtreecommitdiffstats
path: root/examples/tools
diff options
context:
space:
mode:
Diffstat (limited to 'examples/tools')
-rw-r--r--examples/tools/completer/dirmodel.cpp9
-rw-r--r--examples/tools/completer/dirmodel.h12
-rw-r--r--examples/tools/completer/mainwindow.cpp18
3 files changed, 21 insertions, 18 deletions
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;