summaryrefslogtreecommitdiffstats
path: root/examples/widgets/tools/completer
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2012-11-27 14:18:41 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-28 00:56:34 +0100
commitcb961007c534b260b779ed513d33843a9dce01f4 (patch)
treed780db451451d51ab10aa114a6e01f813e32c852 /examples/widgets/tools/completer
parent3d66b86cb7407201f091d16130b3da73e613cc5f (diff)
Examples: move widgets specific "tools" examples to the correct place
examples/tools -> examples/widgets/tools Change-Id: I8b9e23c45e07ce5cd9da8f24a9a9f7ae10b2b107 Reviewed-by: hjk <qthjk@ovi.com>
Diffstat (limited to 'examples/widgets/tools/completer')
-rw-r--r--examples/widgets/tools/completer/completer.desktop11
-rw-r--r--examples/widgets/tools/completer/completer.pro16
-rw-r--r--examples/widgets/tools/completer/completer.qrc6
-rw-r--r--examples/widgets/tools/completer/fsmodel.cpp63
-rw-r--r--examples/widgets/tools/completer/fsmodel.h60
-rw-r--r--examples/widgets/tools/completer/main.cpp54
-rw-r--r--examples/widgets/tools/completer/mainwindow.cpp281
-rw-r--r--examples/widgets/tools/completer/mainwindow.h89
-rw-r--r--examples/widgets/tools/completer/resources/countries.txt241
-rw-r--r--examples/widgets/tools/completer/resources/wordlist.txt1485
10 files changed, 2306 insertions, 0 deletions
diff --git a/examples/widgets/tools/completer/completer.desktop b/examples/widgets/tools/completer/completer.desktop
new file mode 100644
index 0000000000..f7e2d155d8
--- /dev/null
+++ b/examples/widgets/tools/completer/completer.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Completer
+Exec=/opt/usr/bin/completer
+Icon=completer
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/tools/completer/completer.pro b/examples/widgets/tools/completer/completer.pro
new file mode 100644
index 0000000000..a735b7ceae
--- /dev/null
+++ b/examples/widgets/tools/completer/completer.pro
@@ -0,0 +1,16 @@
+HEADERS = fsmodel.h \
+ mainwindow.h
+SOURCES = fsmodel.cpp \
+ main.cpp \
+ mainwindow.cpp
+RESOURCES = completer.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/completer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS completer.pro resources
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/completer
+INSTALLS += target sources
+
+QT += widgets
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/tools/completer/completer.qrc b/examples/widgets/tools/completer/completer.qrc
new file mode 100644
index 0000000000..4f57e1a824
--- /dev/null
+++ b/examples/widgets/tools/completer/completer.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>resources/countries.txt</file>
+ <file>resources/wordlist.txt</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/tools/completer/fsmodel.cpp b/examples/widgets/tools/completer/fsmodel.cpp
new file mode 100644
index 0000000000..5967f3d3a7
--- /dev/null
+++ b/examples/widgets/tools/completer/fsmodel.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $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/widgets/tools/completer/fsmodel.h b/examples/widgets/tools/completer/fsmodel.h
new file mode 100644
index 0000000000..8b7b8eb6bc
--- /dev/null
+++ b/examples/widgets/tools/completer/fsmodel.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FILESYSTEMMODEL_H
+#define FILESYSTEMMODEL_H
+
+#include <QFileSystemModel>
+
+// 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/widgets/tools/completer/main.cpp b/examples/widgets/tools/completer/main.cpp
new file mode 100644
index 0000000000..3f80523eb7
--- /dev/null
+++ b/examples/widgets/tools/completer/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(completer);
+
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/widgets/tools/completer/mainwindow.cpp b/examples/widgets/tools/completer/mainwindow.cpp
new file mode 100644
index 0000000000..97b5b1b88f
--- /dev/null
+++ b/examples/widgets/tools/completer/mainwindow.cpp
@@ -0,0 +1,281 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include "fsmodel.h"
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent), completer(0), lineEdit(0)
+{
+ createMenu();
+
+ QWidget *centralWidget = new QWidget;
+
+ QLabel *modelLabel = new QLabel;
+ modelLabel->setText(tr("Model"));
+
+ modelCombo = new QComboBox;
+ 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);
+
+ QLabel *modeLabel = new QLabel;
+ modeLabel->setText(tr("Completion Mode"));
+ modeCombo = new QComboBox;
+ modeCombo->addItem(tr("Inline"));
+ modeCombo->addItem(tr("Filtered Popup"));
+ modeCombo->addItem(tr("Unfiltered Popup"));
+ modeCombo->setCurrentIndex(1);
+
+ QLabel *caseLabel = new QLabel;
+ caseLabel->setText(tr("Case Sensitivity"));
+ caseCombo = new QComboBox;
+ caseCombo->addItem(tr("Case Insensitive"));
+ caseCombo->addItem(tr("Case Sensitive"));
+ caseCombo->setCurrentIndex(0);
+//! [0]
+
+//! [1]
+ QLabel *maxVisibleLabel = new QLabel;
+ maxVisibleLabel->setText(tr("Max Visible Items"));
+ maxVisibleSpinBox = new QSpinBox;
+ maxVisibleSpinBox->setRange(3,25);
+ maxVisibleSpinBox->setValue(10);
+
+ wrapCheckBox = new QCheckBox;
+ wrapCheckBox->setText(tr("Wrap around completions"));
+ wrapCheckBox->setChecked(true);
+//! [1]
+
+//! [2]
+ contentsLabel = new QLabel;
+ contentsLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+
+ connect(modelCombo, SIGNAL(activated(int)), this, SLOT(changeModel()));
+ connect(modeCombo, SIGNAL(activated(int)), this, SLOT(changeMode(int)));
+ connect(caseCombo, SIGNAL(activated(int)), this, SLOT(changeCase(int)));
+ connect(maxVisibleSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeMaxVisible(int)));
+//! [2]
+
+//! [3]
+ lineEdit = new QLineEdit;
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(modelLabel, 0, 0); layout->addWidget(modelCombo, 0, 1);
+ layout->addWidget(modeLabel, 1, 0); layout->addWidget(modeCombo, 1, 1);
+ layout->addWidget(caseLabel, 2, 0); layout->addWidget(caseCombo, 2, 1);
+ layout->addWidget(maxVisibleLabel, 3, 0); layout->addWidget(maxVisibleSpinBox, 3, 1);
+ layout->addWidget(wrapCheckBox, 4, 0);
+ layout->addWidget(contentsLabel, 5, 0, 1, 2);
+ layout->addWidget(lineEdit, 6, 0, 1, 2);
+ centralWidget->setLayout(layout);
+ setCentralWidget(centralWidget);
+
+ changeModel();
+
+ setWindowTitle(tr("Completer"));
+ lineEdit->setFocus();
+}
+//! [3]
+
+//! [4]
+void MainWindow::createMenu()
+{
+ QAction *exitAction = new QAction(tr("Exit"), this);
+ QAction *aboutAct = new QAction(tr("About"), this);
+ QAction *aboutQtAct = new QAction(tr("About Qt"), this);
+
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+
+ QMenu* fileMenu = menuBar()->addMenu(tr("File"));
+ fileMenu->addAction(exitAction);
+
+ QMenu* helpMenu = menuBar()->addMenu(tr("About"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+//! [4]
+
+//! [5]
+QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly))
+ return new QStringListModel(completer);
+//! [5]
+
+//! [6]
+#ifndef QT_NO_CURSOR
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+#endif
+ QStringList words;
+
+ while (!file.atEnd()) {
+ QByteArray line = file.readLine();
+ if (!line.isEmpty())
+ words << line.trimmed();
+ }
+
+#ifndef QT_NO_CURSOR
+ QApplication::restoreOverrideCursor();
+#endif
+//! [6]
+
+//! [7]
+ if (!fileName.contains(QLatin1String("countries.txt")))
+ return new QStringListModel(words, completer);
+//! [7]
+
+ // The last two chars of the countries.txt file indicate the country
+ // symbol. We put that in column 2 of a standard item model
+//! [8]
+ QStandardItemModel *m = new QStandardItemModel(words.count(), 2, completer);
+//! [8] //! [9]
+ for (int i = 0; i < words.count(); ++i) {
+ QModelIndex countryIdx = m->index(i, 0);
+ QModelIndex symbolIdx = m->index(i, 1);
+ QString country = words[i].mid(0, words[i].length() - 2).trimmed();
+ QString symbol = words[i].right(2);
+ m->setData(countryIdx, country);
+ m->setData(symbolIdx, symbol);
+ }
+
+ return m;
+}
+//! [9]
+
+//! [10]
+void MainWindow::changeMode(int index)
+{
+ QCompleter::CompletionMode mode;
+ if (index == 0)
+ mode = QCompleter::InlineCompletion;
+ else if (index == 1)
+ mode = QCompleter::PopupCompletion;
+ else
+ mode = QCompleter::UnfilteredPopupCompletion;
+
+ completer->setCompletionMode(mode);
+}
+//! [10]
+
+void MainWindow::changeCase(int cs)
+{
+ completer->setCaseSensitivity(cs ? Qt::CaseSensitive : Qt::CaseInsensitive);
+}
+
+//! [11]
+void MainWindow::changeModel()
+{
+ delete completer;
+ completer = new QCompleter(this);
+ completer->setMaxVisibleItems(maxVisibleSpinBox->value());
+
+ switch (modelCombo->currentIndex()) {
+ default:
+ case 0:
+ { // Unsorted QFileSystemModel
+ QFileSystemModel *fsModel = new QFileSystemModel(completer);
+ fsModel->setRootPath("");
+ completer->setModel(fsModel);
+ contentsLabel->setText(tr("Enter file path"));
+ }
+ break;
+//! [11] //! [12]
+ case 1:
+ { // FileSystemModel that shows full paths
+ FileSystemModel *fsModel = new FileSystemModel(completer);
+ completer->setModel(fsModel);
+ fsModel->setRootPath("");
+ contentsLabel->setText(tr("Enter file path"));
+ }
+ break;
+//! [12] //! [13]
+ case 2:
+ { // Country List
+ completer->setModel(modelFromFile(":/resources/countries.txt"));
+ QTreeView *treeView = new QTreeView;
+ completer->setPopup(treeView);
+ treeView->setRootIsDecorated(false);
+ treeView->header()->hide();
+ treeView->header()->setStretchLastSection(false);
+ treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
+ treeView->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
+ contentsLabel->setText(tr("Enter name of your country"));
+ }
+ break;
+//! [13] //! [14]
+ case 3:
+ { // Word list
+ completer->setModel(modelFromFile(":/resources/wordlist.txt"));
+ completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
+ contentsLabel->setText(tr("Enter a word"));
+ }
+ break;
+ }
+
+ changeMode(modeCombo->currentIndex());
+ changeCase(caseCombo->currentIndex());
+ completer->setWrapAround(wrapCheckBox->isChecked());
+ lineEdit->setCompleter(completer);
+ connect(wrapCheckBox, SIGNAL(clicked(bool)), completer, SLOT(setWrapAround(bool)));
+}
+//! [14]
+
+//! [15]
+void MainWindow::changeMaxVisible(int max)
+{
+ completer->setMaxVisibleItems(max);
+}
+//! [15]
+
+//! [16]
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About"), tr("This example demonstrates the "
+ "different features of the QCompleter class."));
+}
+//! [16]
diff --git a/examples/widgets/tools/completer/mainwindow.h b/examples/widgets/tools/completer/mainwindow.h
new file mode 100644
index 0000000000..b3c57f1a51
--- /dev/null
+++ b/examples/widgets/tools/completer/mainwindow.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
+class QComboBox;
+class QCompleter;
+class QLabel;
+class QLineEdit;
+class QProgressBar;
+class QCheckBox;
+class QSpinBox;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+private slots:
+ void about();
+ void changeCase(int);
+ void changeMode(int);
+ void changeModel();
+ void changeMaxVisible(int);
+//! [0]
+
+//! [1]
+private:
+ void createMenu();
+ QAbstractItemModel *modelFromFile(const QString& fileName);
+
+ QComboBox *caseCombo;
+ QComboBox *modeCombo;
+ QComboBox *modelCombo;
+ QSpinBox *maxVisibleSpinBox;
+ QCheckBox *wrapCheckBox;
+ QCompleter *completer;
+ QLabel *contentsLabel;
+ QLineEdit *lineEdit;
+};
+//! [1]
+
+#endif // MAINWINDOW_H
diff --git a/examples/widgets/tools/completer/resources/countries.txt b/examples/widgets/tools/completer/resources/countries.txt
new file mode 100644
index 0000000000..5854fbc977
--- /dev/null
+++ b/examples/widgets/tools/completer/resources/countries.txt
@@ -0,0 +1,241 @@
+Afghanistan AF
+Albania AL
+Algeria DZ
+American Samoa AS
+Andorra AD
+Angola AO
+Anguilla AI
+Antarctica AQ
+Antigua And Barbuda AG
+Argentina AR
+Armenia AM
+Aruba AW
+Australia AU
+Austria AT
+Azerbaijan AZ
+Bahamas BS
+Bahrain BH
+Bangladesh BD
+Barbados BB
+Belarus BY
+Belgium BE
+Belize BZ
+Benin BJ
+Bermuda BM
+Bhutan BT
+Bolivia BO
+Bosnia And Herzegowina BA
+Botswana BW
+Bouvet Island BV
+Brazil BR
+British Indian Ocean Territory IO
+British Virgin Islands VG
+Brunei Darussalam BN
+Bulgaria BG
+Burkina Faso BF
+Burundi BI
+Cambodia KH
+Cameroon CM
+Canada CA
+Cape Verde CV
+Cayman Islands KY
+Central African Republic CF
+Chad TD
+Chile CL
+China CN
+Christmas Island CX
+Cocos Islands CC
+Colombia CO
+Comoros KM
+Cook Islands CK
+Costa Rica CR
+Croatia HR
+Cuba CU
+Cyprus CY
+Czech Republic CZ
+Democratic Republic Of Congo CD
+Democratic Republic Of Korea KP
+Denmark DK
+Djibouti DJ
+Dominica DM
+Dominican Republic DO
+EastTimor TL
+Ecuador EC
+Egypt EG
+El Salvador SV
+Equatorial Guinea GQ
+Eritrea ER
+Estonia EE
+Ethiopia ET
+Falkland Islands FK
+Faroe Islands FO
+Fiji FJ
+Finland FI
+France FR
+French Guiana GF
+French Polynesia PF
+French Southern Territories TF
+Gabon GA
+Gambia GM
+Georgia GE
+Germany DE
+Ghana GH
+Gibraltar GI
+Greece GR
+Greenland GL
+Grenada GD
+Guadeloupe GP
+Guam GU
+Guatemala GT
+Guinea GN
+Guinea Bissau GW
+Guyana GY
+Haiti HT
+Heard And McDonald Islands HM
+Honduras HN
+Hong Kong HK
+Hungary HU
+Iceland IS
+India IN
+Indonesia ID
+Iran IR
+Iraq IQ
+Ireland IE
+Israel IL
+Italy IT
+Ivory Coast CI
+Jamaica JM
+Japan JP
+Jordan JO
+Kazakhstan KZ
+Kenya KE
+Kiribati KI
+Kuwait KW
+Kyrgyzstan KG
+Lao LA
+Latvia LV
+Lebanon LB
+Lesotho LS
+Liberia LR
+Libyan Arab Jamahiriya LY
+Liechtenstein LI
+Lithuania LT
+Luxembourg LU
+Macau MO
+Macedonia MK
+Madagascar MG
+Malawi MW
+Malaysia MY
+Maldives MV
+Mali ML
+Malta MT
+Marshall Islands MH
+Martinique MQ
+Mauritania MR
+Mauritius MU
+Mayotte YT
+Metropolitan France FX
+Mexico MX
+Micronesia FM
+Moldova MD
+Monaco MC
+Mongolia MN
+Montserrat MS
+Morocco MA
+Mozambique MZ
+Myanmar MM
+Namibia NA
+Nauru NR
+Nepal NP
+Netherlands NL
+Netherlands Antilles AN
+New Caledonia NC
+New Zealand NZ
+Nicaragua NI
+Niger NE
+Nigeria NG
+Niue NU
+Norfolk Island NF
+Northern Mariana Islands MP
+Norway NO
+Oman OM
+Pakistan PK
+Palau PW
+Palestinian Territory PS
+Panama PA
+Papua New Guinea PG
+Paraguay PY
+Peoples Republic Of Congo CG
+Peru PE
+Philippines PH
+Pitcairn PN
+Poland PL
+Portugal PT
+Puerto Rico PR
+Qatar QA
+Republic Of Korea KR
+Reunion RE
+Romania RO
+Russian Federation RU
+Rwanda RW
+Saint Kitts And Nevis KN
+Samoa WS
+San Marino SM
+Sao Tome And Principe ST
+Saudi Arabia SA
+Senegal SN
+Serbia And Montenegro CS
+Seychelles SC
+Sierra Leone SL
+Singapore SG
+Slovakia SK
+Slovenia SI
+Solomon Islands SB
+Somalia SO
+South Africa ZA
+South Georgia And The South Sandwich Islands GS
+Spain ES
+Sri Lanka LK
+St Helena SH
+St Lucia LC
+St Pierre And Miquelon PM
+St Vincent And The Grenadines VC
+Sudan SD
+Suriname SR
+Svalbard And Jan Mayen Islands SJ
+Swaziland SZ
+Sweden SE
+Switzerland CH
+Syrian Arab Republic SY
+Taiwan TW
+Tajikistan TJ
+Tanzania TZ
+Thailand TH
+Togo TG
+Tokelau TK
+Tonga TO
+Trinidad And Tobago TT
+Tunisia TN
+Turkey TR
+Turkmenistan TM
+Turks And Caicos Islands TC
+Tuvalu TV
+US Virgin Islands VI
+Uganda UG
+Ukraine UA
+United Arab Emirates AE
+United Kingdom GB
+United States US
+United States Minor Outlying Islands UM
+Uruguay UY
+Uzbekistan UZ
+Vanuatu VU
+Vatican City State VA
+Venezuela VE
+Viet Nam VN
+Wallis And Futuna Islands WF
+Western Sahara EH
+Yemen YE
+Yugoslavia YU
+Zambia ZM
+Zimbabwe ZW
diff --git a/examples/widgets/tools/completer/resources/wordlist.txt b/examples/widgets/tools/completer/resources/wordlist.txt
new file mode 100644
index 0000000000..1f56e36d47
--- /dev/null
+++ b/examples/widgets/tools/completer/resources/wordlist.txt
@@ -0,0 +1,1485 @@
+A4
+able
+about
+above
+absence
+absolutely
+abstract
+access
+according
+accumulated
+achieve
+achieving
+activity
+acts
+actual
+actually
+add
+added
+adding
+addition
+additionally
+additions
+addresses
+adjust
+adjustments
+advanced
+advice
+after
+afterwards
+again
+agenda
+aim
+algorithm
+all
+allocated
+allow
+allowed
+allowing
+allows
+along
+alpha
+already
+also
+alternative
+alternatively
+although
+American
+an
+and
+announced
+annoy
+another
+answer
+answers
+any
+anything
+anyway
+apart
+API
+appear
+appears
+appendices
+appendix
+appends
+application
+applications
+apply
+approach
+approaches
+appropriate
+Arabic
+arbitrary
+are
+areas
+ARGB
+argument
+arguments
+around
+arrangements
+arrive
+arrived
+Arthur
+article
+articles
+as
+asked
+aspects
+assume
+at
+attachment
+attempt
+attempting
+attend
+attendees
+attributes
+authors
+auto-detect
+auto-detecting
+availability
+available
+avoid
+away
+back
+background
+backgrounds
+bandwidth
+bandwidths
+Barcelona
+base
+based
+basic
+basically
+basics
+be
+because
+been
+before
+behave
+behavior
+behind
+being
+below
+benefits
+Berkeley
+between
+bit
+bits
+bitwise
+black
+blended
+blending
+blends
+block
+blue
+BMP
+body
+bold
+booking
+bool
+Boston
+both
+bottom
+box
+boxes
+braces
+break
+breaks
+broad
+browsers
+buffer
+buffers
+build
+builds
+built
+bundled
+burdens
+busy
+but
+by
+bypass
+bypassing
+bytes
+calendar
+call
+called
+calling
+calls
+Cambridge
+can
+canonical
+canonicalised
+cap
+capabilities
+capacity
+caption
+card
+care
+case
+cast
+catch
+causing
+centre
+certain
+challenges
+chance
+change
+changes
+changing
+channel
+channels
+chapter
+char
+chart
+charts
+check
+checks
+Chicago
+chit-chat
+chosen
+chunk
+circle
+citation
+city
+claim
+class
+classes
+clause
+clauses
+clear
+clearing
+client
+clients
+close
+closed
+co-author
+code
+colon
+color
+color-coded
+colorize
+colorizer
+colors
+colour
+column
+columns
+combine
+combined
+combines
+combining
+comes
+command
+commands
+comment
+common
+communicate
+community
+compiled
+complement
+complete
+completely
+completeness
+completes
+completion
+complex
+compliant
+component
+components
+compositing
+composition
+compression
+computation
+computer
+concepts
+conclusion
+concurrent
+configurable
+congested
+congestion
+connect
+connected
+connection
+connections
+cons
+consider
+consisting
+consists
+construct
+constructed
+constructing
+constructor
+constructs
+consume
+contact
+contain
+containing
+contains
+contents
+contents
+continue
+continued
+contributors
+control
+controlled
+controller
+controller
+controlling
+controls
+controls
+conventions
+cook
+cooperation
+copy
+copyright
+core
+cores
+corollary
+correct
+correctly
+corresponding
+could
+couple
+coworkers
+CPU
+create
+creates
+creating
+cross-platform
+crucial
+cultures
+current
+currently
+custom
+customized
+cut
+data
+database
+datasets
+datum
+day
+days
+deal
+dealing
+decide
+decouple
+decoupled
+deeply
+def
+default
+define
+defines
+definition
+definitions
+delegate
+delete
+demo
+demonstrate
+demonstrations
+deployed
+describe
+describes
+design
+desktop
+desktops
+destination
+destinations
+destructor
+details
+detect
+determine
+determines
+developer
+developers
+development
+developments
+device
+devices
+diagram
+dialogs
+dictionary
+did
+difference
+differences
+different
+differs
+digital
+direct
+direct
+directions
+directly
+directory
+discuss
+display
+displaying
+displays
+distribute
+distribution
+disturbing
+divide
+do
+documentation
+documents
+does
+done
+down
+downLimit
+download
+downloaded
+downloading
+draw
+drawing
+drawn
+drop
+drop-in
+Duff
+during
+DVD
+dynamic
+dynamically
+dynamics
+each
+earlier
+easily
+editing
+editors
+education
+effect
+effectively
+effects
+either
+ellipse
+ellipses
+elliptical
+else
+email
+e-mail
+embedded
+emit
+emits
+empty
+enable
+enables
+encapsulates
+enclose
+end
+endnote
+endnotes
+end-user
+engineer
+engineering
+English
+enjoys
+enough
+ensure
+ensures
+entails
+enter
+entire
+entitled
+entries
+entry
+environment
+erases
+error
+errors
+especially
+established
+etc.
+Europe
+even
+evenly
+event
+events
+eventually
+every
+everyone
+example
+examples
+except
+exception
+excessive
+exclusive
+existing
+exists
+expand
+expected
+expense
+export
+exposes
+extend
+extended
+extending
+extensible
+extension
+external
+extra
+extract
+faces
+facilities
+factory
+fade
+failure
+fairness
+falls
+false
+family
+fashion
+fast
+faster
+features
+February
+feedback
+feel
+fetch
+fetching
+few
+fields
+figure
+figures
+file
+file name
+files
+filled
+filler
+final
+finally
+find
+fine
+finish
+finished
+first
+flow
+fly
+focus
+followed
+following
+font
+foot
+footnote
+footnotes
+for
+form
+format
+formats
+format-specific
+forms
+formula
+formulas
+forum
+found
+framework
+France
+from
+front
+full
+fully
+function
+functionality
+function-based
+functions
+future
+gain
+games
+gap
+general
+generic
+Germany
+get
+gill
+give
+given
+gives
+giving
+global
+go
+goes
+got
+gradient
+gradient-filled
+graph
+graphical
+graphics
+gray
+great
+greatly
+green
+grey
+group
+growing
+gui
+GUI
+hack
+had
+half
+Hamburg
+hand
+handing
+handle
+handler
+handlers
+handles
+handling
+happens
+hardware
+harmonica
+has
+have
+having
+he
+head
+header
+headers
+hear
+height
+help
+helper
+here
+high
+high-complexity
+high-level
+highlight
+highly
+hints
+his
+hold
+holder
+holding
+hole
+home
+horizontal
+host
+hosting
+hours
+Houston
+how
+however
+huge
+hyphen
+ID
+idea
+ideally
+if
+Illinois
+illustrate
+illustrated
+illustrates
+image
+images
+impact
+implement
+implementation
+implementations
+implemented
+implementing
+implements
+import
+important
+improvements
+in
+include
+included
+includes
+including
+inclusion
+incoming
+inconvenient
+indent
+index
+indicate
+inexpensively
+influence
+info
+information
+ingenious
+inherits
+initial
+initially
+inner
+input
+inspired
+install
+installs
+instance
+instead
+instructs
+integer
+integers
+integration
+intended
+intensive
+interest
+interests
+interface
+interfaces
+interfere
+internal
+interval
+into
+intriguing
+intro
+introduce
+introduced
+invalid
+invented
+inverse
+invocation
+involved
+Irish
+irregular
+is
+ISO
+ISPs
+issue
+issues
+it
+items
+iterate
+its
+itself
+job
+join
+JPEG
+jungle
+just
+Karaoke
+keep
+keeping
+key
+kind
+king
+known
+label
+labels
+landscape
+language
+large
+last
+later
+latest
+lawn
+layout
+lead
+leader
+leaders
+lean
+leaves
+leaving
+left
+lemma
+length
+less
+let
+level
+levels
+libraries
+library
+lies
+like
+likely
+limit
+limiting
+limits
+line
+linear
+lines
+linewidth
+link
+linked
+linking
+Linux
+list
+lists
+little
+lives
+load
+loading
+loads
+located
+location
+locations
+logo
+long
+longer
+look
+looked
+looking
+looks
+lookup
+lookups
+loop
+lout
+low
+lower-case
+low-level
+macro
+made
+magazine
+magic
+main
+major
+make
+makes
+making
+manage
+managed
+managing
+mandatory
+manipulate
+manipulation
+manner
+many
+map
+maps
+March
+margin
+mask
+masking
+Massachusetts
+match
+mathematical
+maximum
+may
+means
+meet
+member
+members
+memory
+merged
+method
+might
+milliseconds
+minimize
+minimum
+minor
+mix
+MNG
+mode
+model
+models
+modes
+modified
+module
+moments
+monitored
+monthly
+more
+most
+mostly
+move
+much
+multitude
+Munich
+must
+name
+named
+names
+necessary
+need
+needed
+needs
+network
+new
+news
+newsletter
+next
+nicely
+no
+none
+non-Qt
+non-trivial
+non-zero
+normally
+Norway
+not
+note
+notes
+nothing
+notifies
+notify
+now
+null
+number
+numbered
+numbering
+numbers
+Nydalen
+object
+objects
+obtain
+obtaining
+odd
+of
+off
+office
+offset
+offsets
+often
+old
+on
+once
+one
+ones
+online
+only
+on-screen
+onto
+opacity
+opaque
+open
+opens
+operates
+operating
+operation
+operations
+operator
+opportunity
+opposed
+optimize
+option
+optionally
+options
+or
+OR
+order
+ordinary
+original
+originally
+Oslo
+other
+otherwise
+our
+out
+outer
+outgoing
+output
+outside
+over
+overcoming
+overrides
+overview
+own
+owner
+owners
+pace
+Pacific
+package
+packages
+packets
+page
+pages
+paint
+painted
+painting
+paragraph
+paragraphs
+parameters
+parent
+Paris
+parse
+part
+partial
+partially
+particular
+partners
+parts
+party
+passed
+passing
+patches
+path
+pattern
+patterns
+pause
+PDF
+peek
+pending
+perform
+performed
+performs
+permission
+permutations
+personal
+pick
+pie
+pipe
+pixel
+pixels
+place
+places
+planning
+platform-independent
+platforms
+play
+players
+playing
+please
+pleasing
+plugin
+plugin-enabled
+plugins
+plus
+PNG
+pointer
+pop
+popular
+populates
+porter
+Porter
+portrait
+possibility
+possible
+potential
+potentially
+power
+powers
+preceded
+presence
+present
+prevent
+prevents
+previous
+previously
+primarily
+primary
+primitives
+printed
+printing
+prior
+probably
+problem
+process
+processes
+processing
+produce
+produced
+produces
+products
+programming
+programs
+project
+projects
+proof
+proper
+properly
+properties
+property
+proposed
+proposition
+pros
+protocols
+proud
+provide
+provided
+provides
+provision
+proxy
+public
+published
+punch
+punches
+pursuing
+put
+Qt
+Qtopia
+Qt-related
+quality
+quarter
+quarterly
+queried
+queries
+query
+question
+questions
+radial
+ragged
+range
+rate
+rate-controlled
+rates
+rather
+ratio
+raw
+read
+reader
+reading
+reads
+ready
+real
+realistic
+really
+real-time
+received
+recent
+recognized
+recommended
+recompile
+rectangle
+rectangular
+red
+redistribute
+reducing
+reference
+references
+reflect
+regardless
+regional
+register
+registered
+registration
+reimplement
+reimplementation
+reimplemented
+release
+released
+releases
+reliable
+rely
+remains
+remember
+removed
+removes
+repeatedly
+replace
+report
+represent
+represented
+represents
+reproduced
+requested
+require
+required
+requires
+resetting
+resides
+resolve
+respective
+respectively
+response
+rest
+restart
+result
+resulting
+resume
+return
+returning
+returns
+reuse
+revealing
+rich
+riches
+right
+roadshow
+role
+Roman
+round-trip
+router
+routers
+rule
+run
+runner
+runners
+running
+runs
+run-time
+sake
+sales
+salespeople
+same
+sample
+San Jose
+save
+saved
+saves
+say
+scalable
+scale
+scanline
+scanline-level
+scene
+scenes
+schedule
+school
+script
+seam
+seamless
+search
+searches
+searching
+second
+seconds
+section
+sections
+security
+see
+seen
+selection
+seminar
+seminars
+sending
+separated
+separates
+series
+service
+services
+set
+setting
+setup
+seven
+seventh
+several
+shade
+shadow
+shape
+shares
+shaves
+shine
+shorter
+should
+show
+shown
+shows
+side
+signal
+signals
+signature
+significantly
+similar
+similarily
+similarly
+simple
+simplest
+simplified
+simplifying
+simply
+simulate
+simultaneous
+since
+single
+size
+sizes
+slightly
+slope
+slot
+slowing
+small
+smaller
+so
+socket
+sockets
+software
+solutions
+solved
+some
+soon
+sort
+sorting
+source
+sources
+south
+space
+special
+specialized
+specific
+specifically
+specification
+specifications
+specified
+specify
+speed
+spend
+split
+SQL
+standard
+standards
+start
+starts
+starve
+state
+states
+static
+steady
+stealing
+step
+still
+stop
+stopwatch
+store
+stored
+stores
+straightforward
+stream
+string
+strings
+structure
+structured
+strut
+style
+styles
+styling
+subclass
+subclassing
+subdirectory
+subsection
+subsections
+succeeds
+success
+successful
+successfully
+such
+suggestion
+suggestions
+suitable
+support
+supported
+supports
+suppose
+supposes
+sure
+switch
+switches
+symbol
+symbols
+synonyms
+system
+systems
+table
+tables
+tags
+take
+takes
+tap
+target
+targets
+TCP
+team
+technically-focused
+technique
+technology
+template
+templates
+Texas
+text
+than
+that
+the
+their
+them
+then
+theorem
+there
+these
+they
+thickness
+thin
+third
+this
+those
+three
+throttling
+through
+tightly
+time
+timer
+times
+tiny
+tips
+title
+titles
+to
+together
+too
+top
+torrent
+total
+tour
+trademarks
+traffic
+training
+transaction
+transfer
+transferred
+transferring
+transfers
+translucency
+translucent
+transparency
+transparent
+travel
+traveled
+true
+try
+turn
+twice
+two
+type
+typed
+typical
+typically
+unable
+under
+underlying
+understanding
+undoes
+unique
+united
+unlike
+unpack
+unsigned
+until
+untouched
+up
+update
+updated
+updates
+upload
+uploading
+uploads
+up-to-date
+us
+use
+used
+useful
+user
+user-friendly
+users
+uses
+using
+usual
+usually
+valid
+value
+values
+variable
+variation
+variety
+various
+vector
+venturing
+verifying
+versa
+version
+versions
+vertical
+very
+via
+vice
+virtual
+visual
+void
+VP
+waiting
+Wales
+want
+wants
+was
+way
+ways
+we
+web
+website
+well
+were
+what
+when
+whenever
+where
+whether
+which
+while
+whistle
+white
+who
+whole
+why
+widget
+widgets
+width
+widths
+will
+window
+windows
+wish
+with
+without
+word
+words
+work
+working
+works
+would
+wrap
+wrapper
+write
+writes
+writing
+writings
+written
+X
+X11
+XOR
+year
+years
+yes
+you
+your
+zero