summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCidorvan Leite <cidorvan.leite@openbossa.org>2012-03-21 15:34:56 -0300
committerAnselmo L. S. Melo <anselmo.melo@openbossa.org>2012-03-22 20:10:38 +0100
commitdd4813f992bb0480cef7948754aab8ce66ee240b (patch)
tree93950e019af3335e6081a93a5a8589064ffe19a1
parentdaf3e63ae52284ab0b384650c5ed43f4fc4bb208 (diff)
Added UiCompletionModel example
Change-Id: I264d91aaa572a270c8ee32230764efb22f89d4af Reviewed-by: Anselmo L. S. Melo <anselmo.melo@openbossa.org>
-rw-r--r--examples/models/completionmodel/completionmodel.pro6
-rw-r--r--examples/models/completionmodel/countries.txt241
-rw-r--r--examples/models/completionmodel/main.cpp40
-rw-r--r--examples/models/completionmodel/main.qml44
-rw-r--r--examples/models/completionmodel/resources.qrc6
-rw-r--r--examples/models/models.pro3
6 files changed, 339 insertions, 1 deletions
diff --git a/examples/models/completionmodel/completionmodel.pro b/examples/models/completionmodel/completionmodel.pro
new file mode 100644
index 0000000..d0ff25e
--- /dev/null
+++ b/examples/models/completionmodel/completionmodel.pro
@@ -0,0 +1,6 @@
+TEMPLATE = app
+QT += uihelpers quick
+
+RESOURCES = resources.qrc
+
+SOURCES = main.cpp
diff --git a/examples/models/completionmodel/countries.txt b/examples/models/completionmodel/countries.txt
new file mode 100644
index 0000000..39e7f3d
--- /dev/null
+++ b/examples/models/completionmodel/countries.txt
@@ -0,0 +1,241 @@
+Afghanistan
+Albania
+Algeria
+American Samoa
+Andorra
+Angola
+Anguilla
+Antarctica
+Antigua And Barbuda
+Argentina
+Armenia
+Aruba
+Australia
+Austria
+Azerbaijan
+Bahamas
+Bahrain
+Bangladesh
+Barbados
+Belarus
+Belgium
+Belize
+Benin
+Bermuda
+Bhutan
+Bolivia
+Bosnia And Herzegowina
+Botswana
+Bouvet Island
+Brazil
+British Indian Ocean Territory
+British Virgin Islands
+Brunei Darussalam
+Bulgaria
+Burkina Faso
+Burundi
+Cambodia
+Cameroon
+Canada
+Cape Verde
+Cayman Islands
+Central African Republic
+Chad
+Chile
+China
+Christmas Island
+Cocos Islands
+Colombia
+Comoros
+Cook Islands
+Costa Rica
+Croatia
+Cuba
+Cyprus
+Czech Republic
+Democratic Republic Of Congo
+Democratic Republic Of Korea
+Denmark
+Djibouti
+Dominica
+Dominican Republic
+EastTimor
+Ecuador
+Egypt
+El Salvador
+Equatorial Guinea
+Eritrea
+Estonia
+Ethiopia
+Falkland Islands
+Faroe Islands
+Fiji
+Finland
+France
+French Guiana
+French Polynesia
+French Southern Territories
+Gabon
+Gambia
+Georgia
+Germany
+Ghana
+Gibraltar
+Greece
+Greenland
+Grenada
+Guadeloupe
+Guam
+Guatemala
+Guinea
+Guinea Bissau
+Guyana
+Haiti
+Heard And McDonald Islands
+Honduras
+Hong Kong
+Hungary
+Iceland
+India
+Indonesia
+Iran
+Iraq
+Ireland
+Israel
+Italy
+Ivory Coast
+Jamaica
+Japan
+Jordan
+Kazakhstan
+Kenya
+Kiribati
+Kuwait
+Kyrgyzstan
+Lao
+Latvia
+Lebanon
+Lesotho
+Liberia
+Libyan Arab Jamahiriya
+Liechtenstein
+Lithuania
+Luxembourg
+Macau
+Macedonia
+Madagascar
+Malawi
+Malaysia
+Maldives
+Mali
+Malta
+Marshall Islands
+Martinique
+Mauritania
+Mauritius
+Mayotte
+Metropolitan France
+Mexico
+Micronesia
+Moldova
+Monaco
+Mongolia
+Montserrat
+Morocco
+Mozambique
+Myanmar
+Namibia
+Nauru
+Nepal
+Netherlands
+Netherlands Antilles
+New Caledonia
+New Zealand
+Nicaragua
+Niger
+Nigeria
+Niue
+Norfolk Island
+Northern Mariana Islands
+Norway
+Oman
+Pakistan
+Palau
+Palestinian Territory
+Panama
+Papua New Guinea
+Paraguay
+Peoples Republic Of Congo
+Peru
+Philippines
+Pitcairn
+Poland
+Portugal
+Puerto Rico
+Qatar
+Republic Of Korea
+Reunion
+Romania
+Russian Federation
+Rwanda
+Saint Kitts And Nevis
+Samoa
+San Marino
+Sao Tome And Principe
+Saudi Arabia
+Senegal
+Serbia And Montenegro
+Seychelles
+Sierra Leone
+Singapore
+Slovakia
+Slovenia
+Solomon Islands
+Somalia
+South Africa
+South Georgia And The South Sandwich Islands
+Spain
+Sri Lanka
+St Helena
+St Lucia
+St Pierre And Miquelon
+St Vincent And The Grenadines
+Sudan
+Suriname
+Svalbard And Jan Mayen Islands
+Swaziland
+Sweden
+Switzerland
+Syrian Arab Republic
+Taiwan
+Tajikistan
+Tanzania
+Thailand
+Togo
+Tokelau
+Tonga
+Trinidad And Tobago
+Tunisia
+Turkey
+Turkmenistan
+Turks And Caicos Islands
+Tuvalu
+US Virgin Islands
+Uganda
+Ukraine
+United Arab Emirates
+United Kingdom
+United States
+United States Minor Outlying Islands
+Uruguay
+Uzbekistan
+Vanuatu
+Vatican City State
+Venezuela
+Viet Nam
+Wallis And Futuna Islands
+Western Sahara
+Yemen
+Yugoslavia
+Zambia
+Zimbabwe
diff --git a/examples/models/completionmodel/main.cpp b/examples/models/completionmodel/main.cpp
new file mode 100644
index 0000000..100f742
--- /dev/null
+++ b/examples/models/completionmodel/main.cpp
@@ -0,0 +1,40 @@
+#include <QtGui/QGuiApplication>
+#include <QtQuick/QQuickView>
+#include <UiHelpers/UiCompletionModel>
+#include <QtQml/QQmlContext>
+#include <QStringListModel>
+
+QStringListModel *modelFromFile(const QString& fileName)
+{
+ QStringList words;
+ QFile file(fileName);
+
+ file.open(QFile::ReadOnly);
+ while (!file.atEnd()) {
+ QByteArray line = file.readLine();
+ if (!line.isEmpty())
+ words << line.trimmed();
+ }
+ file.close();
+
+ return new QStringListModel(words);
+}
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(resources);
+ QGuiApplication app(argc, argv);
+
+ UiHelpers::UiCompletionModel model;
+ model.setCaseSensitivity(Qt::CaseInsensitive);
+ model.setSourceModel(modelFromFile(":/countries.txt"));
+
+ QQuickView v;
+ v.rootContext()->setContextProperty("completionModel", &model);
+ v.setWindowTitle(QObject::tr("Completion Model"));
+ v.setSource(QUrl("qrc:/main.qml"));
+
+ v.show();
+
+ return app.exec();
+}
diff --git a/examples/models/completionmodel/main.qml b/examples/models/completionmodel/main.qml
new file mode 100644
index 0000000..eca1432
--- /dev/null
+++ b/examples/models/completionmodel/main.qml
@@ -0,0 +1,44 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 300
+ height: 400
+ color: "blue"
+
+ Rectangle {
+ y: 10
+ anchors.left: parent.left
+ anchors.leftMargin: 10
+ anchors.right: parent.right
+ anchors.rightMargin: 10
+ height: 20
+ color: "white"
+
+ TextInput {
+ anchors.fill: parent
+ clip: true
+ onTextChanged: completionModel.setCompletionPrefix(text)
+ }
+ }
+
+ Rectangle {
+ anchors.top: parent.top
+ anchors.topMargin: 40
+ anchors.left: parent.left
+ anchors.leftMargin: 10
+ anchors.right: parent.right
+ anchors.rightMargin: 10
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 10
+ color: "white"
+
+ ListView {
+ anchors.fill: parent
+ model: completionModel
+ clip: true
+ delegate: Text {
+ text: display
+ }
+ }
+ }
+}
diff --git a/examples/models/completionmodel/resources.qrc b/examples/models/completionmodel/resources.qrc
new file mode 100644
index 0000000..84c0d3a
--- /dev/null
+++ b/examples/models/completionmodel/resources.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>main.qml</file>
+ <file>countries.txt</file>
+</qresource>
+</RCC>
diff --git a/examples/models/models.pro b/examples/models/models.pro
index 556b6c6..459bb7a 100644
--- a/examples/models/models.pro
+++ b/examples/models/models.pro
@@ -1,3 +1,4 @@
TEMPLATE = subdirs
SUBDIRS = \
- fsviewer
+ fsviewer \
+ completionmodel