summaryrefslogtreecommitdiffstats
path: root/examples/tools/completer
diff options
context:
space:
mode:
Diffstat (limited to 'examples/tools/completer')
-rw-r--r--examples/tools/completer/completer.pro4
-rw-r--r--examples/tools/completer/fsmodel.cpp (renamed from examples/tools/completer/dirmodel.cpp)11
-rw-r--r--examples/tools/completer/fsmodel.h (renamed from examples/tools/completer/dirmodel.h)12
-rw-r--r--examples/tools/completer/mainwindow.cpp20
4 files changed, 25 insertions, 22 deletions
diff --git a/examples/tools/completer/completer.pro b/examples/tools/completer/completer.pro
index 96d3734..14521b2 100644
--- a/examples/tools/completer/completer.pro
+++ b/examples/tools/completer/completer.pro
@@ -1,6 +1,6 @@
-HEADERS = dirmodel.h \
+HEADERS = fsmodel.h \
mainwindow.h
-SOURCES = dirmodel.cpp \
+SOURCES = fsmodel.cpp \
main.cpp \
mainwindow.cpp
RESOURCES = completer.qrc
diff --git a/examples/tools/completer/dirmodel.cpp b/examples/tools/completer/fsmodel.cpp
index 6279547..9a5a772 100644
--- a/examples/tools/completer/dirmodel.cpp
+++ b/examples/tools/completer/fsmodel.cpp
@@ -39,17 +39,17 @@
**
****************************************************************************/
-#include "dirmodel.h"
+#include "fsmodel.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/fsmodel.h
index 5fbb4a2..0ec9ce9 100644
--- a/examples/tools/completer/dirmodel.h
+++ b/examples/tools/completer/fsmodel.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 f386497..b1f6759 100644
--- a/examples/tools/completer/mainwindow.cpp
+++ b/examples/tools/completer/mainwindow.cpp
@@ -40,7 +40,7 @@
****************************************************************************/
#include <QtGui>
-#include "dirmodel.h"
+#include "fsmodel.h"
#include "mainwindow.h"
//! [0]
@@ -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;