From 158d63b56da7433ca627ad82635541c3c17c74e1 Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Fri, 8 Jan 2010 16:16:00 +0100 Subject: Rename files in completer example since QDirModel is not used. Doc updated for the example. Reviewed-by:TrustMe --- doc/src/examples/completer.qdoc | 30 ++++++++-------- examples/tools/completer/completer.pro | 4 +-- examples/tools/completer/dirmodel.cpp | 64 ---------------------------------- examples/tools/completer/dirmodel.h | 61 -------------------------------- examples/tools/completer/fsmodel.cpp | 64 ++++++++++++++++++++++++++++++++++ examples/tools/completer/fsmodel.h | 61 ++++++++++++++++++++++++++++++++ 6 files changed, 142 insertions(+), 142 deletions(-) delete mode 100644 examples/tools/completer/dirmodel.cpp delete mode 100644 examples/tools/completer/dirmodel.h create mode 100644 examples/tools/completer/fsmodel.cpp create mode 100644 examples/tools/completer/fsmodel.h diff --git a/doc/src/examples/completer.qdoc b/doc/src/examples/completer.qdoc index d092027..8a743a7 100644 --- a/doc/src/examples/completer.qdoc +++ b/doc/src/examples/completer.qdoc @@ -48,7 +48,7 @@ \image completer-example.png - This example uses a custom item model, \c DirModel, and a QCompleter object. + This example uses a custom item model, \c FileSystemModel, and a QCompleter object. QCompleter is a class that provides completions based on an item model. The type of model, the completion mode, and the case sensitivity can be selected using combo boxes. @@ -61,32 +61,32 @@ \quotefile examples/tools/completer/completer.qrc - \section1 DirModel Class Definition + \section1 FileSystemModel Class Definition - The \c DirModel class is a subclass of QDirModel, which provides a data + The \c FileSystemModel class is a subclass of QFileSystemModel, which provides a data model for the local filesystem. - \snippet examples/tools/completer/dirmodel.h 0 + \snippet examples/tools/completer/fsmodel.h 0 This class only has a constructor and a \c data() function as it is only created to enable \c data() to return the entire file path for the - display role, unlike \l{QDirModel}'s \c data() function that only returns + display role, unlike \l{QFileSystemModel}'s \c data() function that only returns the folder and not the drive label. This is further explained in - \c DirModel's implementation. + \c FileSystemModel's implementation. - \section1 DirModel Class Implementation + \section1 FileSystemModel Class Implementation - The constructor for the \c DirModel class is used to pass \a parent to - QDirModel. + The constructor for the \c FileSystemModel class is used to pass \a parent to + QFileSystemModel. - \snippet examples/tools/completer/dirmodel.cpp 0 + \snippet examples/tools/completer/fsmodel.cpp 0 As mentioned earlier, the \c data() function is reimplemented in order to get it to return the entire file parth for the display role. For example, - with a QDirModel, you will see "Program Files" in the view. However, with - \c DirModel, you will see "C:\\Program Files". + with a QFileSystemModel, you will see "Program Files" in the view. However, with + \c FileSystemModel, you will see "C:\\Program Files". - \snippet examples/tools/completer/dirmodel.cpp 1 + \snippet examples/tools/completer/fsmodel.cpp 1 The screenshots below illustrate this difference: @@ -120,7 +120,7 @@ is then invoked. We set up three QComboBox objects, \c modelComb, \c modeCombo and - \c caseCombo. By default, the \c modelCombo is set to QDirModel, + \c caseCombo. By default, the \c modelCombo is set to QFileSystemModel, the \c modeCombo is set to "Filtered Popup" and the \c caseCombo is set to "Case Insensitive". @@ -202,7 +202,7 @@ model selected by the user. A \c switch statement is used to change the item model based on the index - of \c modelCombo. If \c case is 0, we use an unsorted QDirModel, providing + of \c modelCombo. If \c case is 0, we use an unsorted QFileSystemModel, providing us with a file path excluding the drive label. \snippet examples/tools/completer/mainwindow.cpp 11 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/dirmodel.cpp deleted file mode 100644 index 1173d88..0000000 --- a/examples/tools/completer/dirmodel.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "dirmodel.h" - -//! [0] -FileSystemModel::FileSystemModel(QObject *parent) - : QFileSystemModel(parent) -{ -} -//! [0] - -//! [1] -QVariant FileSystemModel::data(const QModelIndex &index, int role) const -{ - if (role == Qt::DisplayRole && index.column() == 0) { - QString path = QDir::toNativeSeparators(filePath(index)); - if (path.endsWith(QDir::separator())) - path.chop(1); - return path; - } - - return QFileSystemModel::data(index, role); -} - -//! [1] diff --git a/examples/tools/completer/dirmodel.h b/examples/tools/completer/dirmodel.h deleted file mode 100644 index 5f4d2a7..0000000 --- a/examples/tools/completer/dirmodel.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef FILESYSTEMMODEL_H -#define FILESYSTEMMODEL_H - -#include - -// 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 FileSystemModel : public QFileSystemModel -{ -public: - FileSystemModel(QObject *parent = 0); - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; -}; -//! [0] - -#endif diff --git a/examples/tools/completer/fsmodel.cpp b/examples/tools/completer/fsmodel.cpp new file mode 100644 index 0000000..8a50f2d --- /dev/null +++ b/examples/tools/completer/fsmodel.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "fsmodel.h" + +//! [0] +FileSystemModel::FileSystemModel(QObject *parent) + : QFileSystemModel(parent) +{ +} +//! [0] + +//! [1] +QVariant FileSystemModel::data(const QModelIndex &index, int role) const +{ + if (role == Qt::DisplayRole && index.column() == 0) { + QString path = QDir::toNativeSeparators(filePath(index)); + if (path.endsWith(QDir::separator())) + path.chop(1); + return path; + } + + return QFileSystemModel::data(index, role); +} + +//! [1] diff --git a/examples/tools/completer/fsmodel.h b/examples/tools/completer/fsmodel.h new file mode 100644 index 0000000..5f4d2a7 --- /dev/null +++ b/examples/tools/completer/fsmodel.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FILESYSTEMMODEL_H +#define FILESYSTEMMODEL_H + +#include + +// 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 FileSystemModel : public QFileSystemModel +{ +public: + FileSystemModel(QObject *parent = 0); + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; +}; +//! [0] + +#endif -- cgit v0.12