summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdriano Melo <adriano.melo@openbossa.org>2012-04-16 16:36:50 -0300
committerLuis Gabriel Lima <luis.gabriel@openbossa.org>2012-04-27 01:21:46 +0200
commit569d2cddfa5cee740972e0e781190a9cf32d3ee8 (patch)
tree962bd15bcd2a887e44cbe0c61a802db7d16cd1da
parent63d13a671f230fb534fc8245d39a5427ab23461c (diff)
Added UiTextFileModel
Creates a QStandardItemModel from a file. It supports separators like line feed and commas. - UiTextFileModel header and class created - Example using UiCompletionModel - UiTextFileModel added to UiHelpers QML registered types - Simple QML example - Tests with some separators Change-Id: Ie996817f6ed03a83c278eb964233f4668a8f6767 Reviewed-by: Daker Fernandes Pinheiro <daker.pinheiro@openbossa.org>
-rw-r--r--examples/models/models.pro3
-rw-r--r--examples/models/quicktextfilemodel/main.qml64
-rw-r--r--examples/models/quicktextfilemodel/quicktextfilemodel.qmlproject14
-rw-r--r--examples/models/textfilemodel/main.cpp69
-rw-r--r--examples/models/textfilemodel/main.qml86
-rw-r--r--examples/models/textfilemodel/resources.qrc6
-rw-r--r--examples/models/textfilemodel/textfilemodel.pro6
-rw-r--r--examples/shared/README2
-rw-r--r--examples/shared/countries.txt241
-rw-r--r--src/imports/models/plugin.cpp2
-rw-r--r--src/models/models.pri7
-rw-r--r--src/models/uitextfilemodel.cpp138
-rw-r--r--src/models/uitextfilemodel.h92
-rw-r--r--src/models/uitextfilemodel_p.h80
-rw-r--r--sync.profile1
-rw-r--r--tests/auto/models/models.pro3
-rw-r--r--tests/auto/models/uitextfilemodel/tst_uitextfilemodel.cpp134
-rw-r--r--tests/auto/models/uitextfilemodel/uitextfilemodel.pro8
18 files changed, 952 insertions, 4 deletions
diff --git a/examples/models/models.pro b/examples/models/models.pro
index 459bb7a..e1efe4f 100644
--- a/examples/models/models.pro
+++ b/examples/models/models.pro
@@ -1,4 +1,5 @@
TEMPLATE = subdirs
SUBDIRS = \
fsviewer \
- completionmodel
+ completionmodel \
+ textfilemodel
diff --git a/examples/models/quicktextfilemodel/main.qml b/examples/models/quicktextfilemodel/main.qml
new file mode 100644
index 0000000..d93d360
--- /dev/null
+++ b/examples/models/quicktextfilemodel/main.qml
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the UiHelpers playground module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import Playground.UiHelpers.Models 1.0
+
+Rectangle {
+ id: root
+
+ width: 200
+ height: 400
+
+ TextFileModel {
+ id: fileModel
+ source: "../../shared/countries.txt"
+ }
+
+ ListView {
+ anchors.fill: parent
+ model: fileModel
+ delegate: Text {
+ text: display
+ height: 20
+ }
+ }
+}
diff --git a/examples/models/quicktextfilemodel/quicktextfilemodel.qmlproject b/examples/models/quicktextfilemodel/quicktextfilemodel.qmlproject
new file mode 100644
index 0000000..bea5f85
--- /dev/null
+++ b/examples/models/quicktextfilemodel/quicktextfilemodel.qmlproject
@@ -0,0 +1,14 @@
+import QmlProject 1.0
+
+Project {
+ mainFile: "main.qml"
+ QmlFiles {
+ directory: ""
+ }
+ JavaScriptFiles {
+ directory: ""
+ }
+ ImageFiles {
+ directory: ""
+ }
+}
diff --git a/examples/models/textfilemodel/main.cpp b/examples/models/textfilemodel/main.cpp
new file mode 100644
index 0000000..d3ad488
--- /dev/null
+++ b/examples/models/textfilemodel/main.cpp
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT)
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the UiHelpers playground module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QGuiApplication>
+#include <QtQuick/QQuickView>
+#include <UiHelpers/UiCompletionModel>
+#include <UiHelpers/UiTextFileModel>
+#include <QtQml/QQmlContext>
+#include <QObject>
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(resources);
+ QGuiApplication app(argc, argv);
+
+ UiHelpers::UiTextFileModel *fileModel = new UiHelpers::UiTextFileModel();
+ fileModel->setSource(":/countries.txt");
+
+ UiHelpers::UiCompletionModel model;
+ model.setCaseSensitivity(Qt::CaseInsensitive);
+ model.setSourceModel(fileModel);
+
+ QQuickView v;
+ v.rootContext()->setContextProperty("completionModel", &model);
+ v.setWindowTitle(QObject::tr("Completion Model with TextFileModel"));
+ v.setSource(QString("qrc:/main.qml"));
+
+ v.show();
+
+ return app.exec();
+}
diff --git a/examples/models/textfilemodel/main.qml b/examples/models/textfilemodel/main.qml
new file mode 100644
index 0000000..5bef718
--- /dev/null
+++ b/examples/models/textfilemodel/main.qml
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the UiHelpers playground module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+Rectangle {
+ width: 300
+ height: 400
+ color: "blue"
+
+ Rectangle {
+ y: 10
+ anchors {
+ left: parent.left
+ leftMargin: 10
+ right: parent.right
+ rightMargin: 10
+ }
+ height: 20
+ color: "white"
+ TextInput {
+ anchors.fill: parent
+ clip: true
+ onTextChanged: completionModel.setCompletionPrefix(text)
+ }
+ }
+
+ Rectangle {
+ anchors {
+ fill: parent
+ topMargin: 40
+ leftMargin: 10
+ rightMargin: 10
+ bottomMargin: 10
+ }
+ color: "white"
+
+ ListView {
+ anchors.fill: parent
+ model: completionModel
+ clip: true
+ delegate: Text {
+ text: display
+ height: 17
+ }
+ }
+ }
+}
diff --git a/examples/models/textfilemodel/resources.qrc b/examples/models/textfilemodel/resources.qrc
new file mode 100644
index 0000000..24d92c7
--- /dev/null
+++ b/examples/models/textfilemodel/resources.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file alias="main.qml">main.qml</file>
+ <file alias="countries.txt">../../shared/countries.txt</file>
+</qresource>
+</RCC>
diff --git a/examples/models/textfilemodel/textfilemodel.pro b/examples/models/textfilemodel/textfilemodel.pro
new file mode 100644
index 0000000..d0ff25e
--- /dev/null
+++ b/examples/models/textfilemodel/textfilemodel.pro
@@ -0,0 +1,6 @@
+TEMPLATE = app
+QT += uihelpers quick
+
+RESOURCES = resources.qrc
+
+SOURCES = main.cpp
diff --git a/examples/shared/README b/examples/shared/README
new file mode 100644
index 0000000..7764c48
--- /dev/null
+++ b/examples/shared/README
@@ -0,0 +1,2 @@
+These files are shared between multiple examples as a set of common and
+reusuable components.
diff --git a/examples/shared/countries.txt b/examples/shared/countries.txt
new file mode 100644
index 0000000..39e7f3d
--- /dev/null
+++ b/examples/shared/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/src/imports/models/plugin.cpp b/src/imports/models/plugin.cpp
index e6f51c8..83bd220 100644
--- a/src/imports/models/plugin.cpp
+++ b/src/imports/models/plugin.cpp
@@ -42,6 +42,7 @@
#include <QtQml/qqmlextensionplugin.h>
#include <QtQml/qqml.h>
#include "uiquickcompletionmodel_p.h"
+#include "uitextfilemodel.h"
class QmlModelsPlugin : public QQmlExtensionPlugin
{
@@ -56,6 +57,7 @@ void QmlModelsPlugin::registerTypes(const char* uri)
Q_ASSERT(QLatin1String(uri) == QLatin1String("Playground.UiHelpers.Models"));
qmlRegisterType<UiQuickCompletionModel>(uri, 1, 0, "CompletionModel");
+ qmlRegisterType<UiTextFileModel>(uri, 1, 0, "TextFileModel");
}
#include "plugin.moc"
diff --git a/src/models/models.pri b/src/models/models.pri
index 4d53dd7..c0eba60 100644
--- a/src/models/models.pri
+++ b/src/models/models.pri
@@ -7,10 +7,13 @@ HEADERS += \
$$PWD/uicompletionmodel.h \
$$PWD/uicompletionmodel_p.h \
$$PWD/uistandarditemmodel.h \
- $$PWD/uistandarditemmodel_p.h
+ $$PWD/uistandarditemmodel_p.h \
+ $$PWD/uitextfilemodel.h \
+ $$PWD/uitextfilemodel_p.h
SOURCES += \
$$PWD/uifilesystemmodel.cpp \
$$PWD/uifileinfogatherer.cpp \
$$PWD/uicompletionmodel.cpp \
- $$PWD/uistandarditemmodel.cpp
+ $$PWD/uistandarditemmodel.cpp \
+ $$PWD/uitextfilemodel.cpp
diff --git a/src/models/uitextfilemodel.cpp b/src/models/uitextfilemodel.cpp
new file mode 100644
index 0000000..8333199
--- /dev/null
+++ b/src/models/uitextfilemodel.cpp
@@ -0,0 +1,138 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT)
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the UiHelpers playground module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT_NO_TEXTFILEMODEL
+
+#include "uitextfilemodel.h"
+#include "uitextfilemodel_p.h"
+#include "uistandarditemmodel.h"
+#include "QtCore/qfile.h"
+#include "QtCore/qscopedpointer.h"
+#include "QtCore/qstring.h"
+#include "QtCore/qstringlist.h"
+
+QT_BEGIN_NAMESPACE_UIHELPERS
+
+UiTextFileModelPrivate::UiTextFileModelPrivate(UiTextFileModel *qq)
+ : separator("\n"), q_ptr(qq)
+{
+}
+
+UiTextFileModelPrivate::~UiTextFileModelPrivate()
+{
+}
+
+void UiTextFileModelPrivate::reload()
+{
+ Q_Q(UiTextFileModel);
+ q->clear();
+
+ QFile file(source);
+ if (!file.open(QFile::ReadOnly)) {
+ qWarning("UiTextFileModel: Could not open the file (%s)", qPrintable(file.fileName()));
+ return;
+ }
+
+ QString text(file.readAll());
+ file.close();
+
+ if (text.isEmpty())
+ return;
+
+ QStringList list = text.split(separator);
+ foreach (const QString & textItem, list) {
+ UiStandardItem *item = new UiStandardItem(textItem);
+ q->appendRow(item);
+ }
+}
+
+UiTextFileModel::UiTextFileModel(QObject *parent)
+ : UiStandardItemModel(parent), d_ptr(new UiTextFileModelPrivate(this))
+{
+}
+
+UiTextFileModel::~UiTextFileModel()
+{
+}
+
+QString UiTextFileModel::source() const
+{
+ Q_D(const UiTextFileModel);
+ return d->source;
+}
+
+void UiTextFileModel::setSource(const QString &source)
+{
+ Q_D(UiTextFileModel);
+
+ if (d->source == source)
+ return;
+
+ d->source = source;
+ d->reload();
+
+ emit sourceChanged();
+}
+
+QString UiTextFileModel::separator() const
+{
+ Q_D(const UiTextFileModel);
+ return d->separator;
+}
+
+void UiTextFileModel::setSeparator(const QString &separator)
+{
+ Q_D(UiTextFileModel);
+
+ if (d->separator == separator)
+ return;
+
+ d->separator = separator;
+
+ if (!d->source.isEmpty())
+ d->reload();
+
+ emit separatorChanged();
+}
+
+QT_END_NAMESPACE_UIHELPERS
+
+#endif // QT_NO_TEXTFILEMODEL
diff --git a/src/models/uitextfilemodel.h b/src/models/uitextfilemodel.h
new file mode 100644
index 0000000..4b8e999
--- /dev/null
+++ b/src/models/uitextfilemodel.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT)
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the UiHelpers playground module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef UITEXTFILEMODEL_H
+#define UITEXTFILEMODEL_H
+
+#include "uihelpersglobal.h"
+#include "UiHelpers/uistandarditemmodel.h"
+#include "QtCore/qscopedpointer.h"
+#include "QtCore/qurl.h"
+#include "QtCore/qstring.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE_UIHELPERS
+
+#ifndef QT_NO_TEXTFILEMODEL
+
+class UiTextFileModelPrivate;
+
+class UIHELPERS_EXPORT UiTextFileModel : public UiStandardItemModel
+{
+ Q_OBJECT
+ Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(QString separator READ separator WRITE setSeparator NOTIFY separatorChanged)
+
+public:
+ explicit UiTextFileModel(QObject *parent = 0);
+ ~UiTextFileModel();
+
+ QString source() const;
+ void setSource(const QString &source);
+ QString separator() const;
+ void setSeparator(const QString &separator);
+
+Q_SIGNALS:
+ void sourceChanged();
+ void separatorChanged();
+
+private:
+ Q_DISABLE_COPY(UiTextFileModel)
+ Q_DECLARE_PRIVATE(UiTextFileModel)
+
+ QScopedPointer<UiTextFileModelPrivate> d_ptr;
+};
+
+#endif // QT_NO_TEXTFILEMODEL
+
+QT_END_NAMESPACE_UIHELPERS
+
+QT_END_HEADER
+
+#endif // UITEXTFILEMODEL_H
+
diff --git a/src/models/uitextfilemodel_p.h b/src/models/uitextfilemodel_p.h
new file mode 100644
index 0000000..faf2380
--- /dev/null
+++ b/src/models/uitextfilemodel_p.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT)
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the UiHelpers playground module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef UITEXTFILEMODEL_P_H
+#define UITEXTFILEMODEL_P_H
+
+//
+//// W A R N I N G
+//// -------------
+////
+//// This file is not part of the Ui Helpers API. It exists purely as an
+//// implementation detail. This header file may change from version to
+//// version without notice, or even be removed.
+////
+//// We mean it.
+////
+//
+
+#include <QScopedPointer>
+#include "uitextfilemodel.h"
+
+QT_BEGIN_NAMESPACE_UIHELPERS
+
+class UiTextFileModelPrivate
+{
+ Q_DECLARE_PUBLIC(UiTextFileModel)
+
+public:
+ UiTextFileModelPrivate(UiTextFileModel *qq);
+ virtual ~UiTextFileModelPrivate();
+
+ void reload();
+
+ QString source;
+ QString separator;
+ UiTextFileModel *q_ptr;
+};
+
+QT_END_NAMESPACE_UIHELPERS
+
+#endif // UITEXTFILEMODEL_P_H
+
diff --git a/sync.profile b/sync.profile
index 05ede2e..e9703b0 100644
--- a/sync.profile
+++ b/sync.profile
@@ -9,6 +9,7 @@
"uiundogroup.h" => "UiUndoGroup",
"uicompletionmodel.h" => "UiCompletionModel",
"uifilesystemmodel.h" => "UiFileSystemModel",
+ "uitextfilemodel.h" => "UiTextFileModel",
"uistandarditemmodel.h" => "UiStandardItemModel",
"uiaction.h" => "UiAction",
"uiactiongroup.h" => "UiActionGroup",
diff --git a/tests/auto/models/models.pro b/tests/auto/models/models.pro
index 347128e..05cc8ff 100644
--- a/tests/auto/models/models.pro
+++ b/tests/auto/models/models.pro
@@ -1,4 +1,5 @@
TEMPLATE=subdirs
SUBDIRS=\
qfilesystemmodel \
- qstandarditemmodel
+ qstandarditemmodel \
+ uitextfilemodel
diff --git a/tests/auto/models/uitextfilemodel/tst_uitextfilemodel.cpp b/tests/auto/models/uitextfilemodel/tst_uitextfilemodel.cpp
new file mode 100644
index 0000000..4bd3e46
--- /dev/null
+++ b/tests/auto/models/uitextfilemodel/tst_uitextfilemodel.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT)
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the UiHelpers playground module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QTemporaryFile>
+#include <QtCore/QUrl>
+#include <QtTest/QtTest>
+#include <UiHelpers/UiTextFileModel>
+
+class tst_UiTextFileModel: public QObject
+{
+ Q_OBJECT
+
+public slots:
+ void init();
+
+private:
+ int rowsCount;
+ int columnsCount;
+ QTemporaryFile file;
+
+private slots:
+ void commaSeparatorCount();
+ void twoLettersSeparatorCount();
+ void carriageReturnSeparatorCount();
+ void carriageReturnLineFeedSeparatorCount();
+ void specialCharacterSeparatorCount();
+ void withoutSeparatorCount();
+};
+
+void tst_UiTextFileModel::init()
+{
+ rowsCount = 10;
+ columnsCount = 10;
+ file.open();
+ QString text = "Example File";
+ for (int i=0; i < rowsCount; i++) {
+ text.append("\nComeçando nova linha: "); // language: portuguese (test special characters)
+ for (int j=0; j < columnsCount; j++) {
+ text.append(QString::number(j));
+ text.append(", ");
+ }
+ }
+ file.write(text.toAscii());
+ file.flush();
+ file.close();
+}
+
+void tst_UiTextFileModel::commaSeparatorCount()
+{
+ UiHelpers::UiTextFileModel model;
+ model.setSeparator(",");
+ model.setSource(file.fileName());
+ QCOMPARE(model.rowCount(), rowsCount * columnsCount + 1);
+}
+
+void tst_UiTextFileModel::twoLettersSeparatorCount()
+{
+ UiHelpers::UiTextFileModel model;
+ model.setSeparator(", 8, 9");
+ model.setSource(file.fileName());
+ QCOMPARE(model.rowCount(), rowsCount + 1);
+}
+
+void tst_UiTextFileModel::carriageReturnSeparatorCount()
+{
+ UiHelpers::UiTextFileModel model;
+ model.setSeparator("\n");
+ model.setSource(file.fileName());
+ QCOMPARE(model.rowCount(), rowsCount + 1);
+}
+
+void tst_UiTextFileModel::carriageReturnLineFeedSeparatorCount()
+{
+ UiHelpers::UiTextFileModel model;
+ model.setSeparator("\n\r");
+ model.setSource(file.fileName());
+ QCOMPARE(model.rowCount(), 1);
+}
+
+void tst_UiTextFileModel::specialCharacterSeparatorCount()
+{
+ UiHelpers::UiTextFileModel model;
+ model.setSeparator("ç");
+ model.setSource(file.fileName());
+ QCOMPARE(model.rowCount(), rowsCount + 1);
+}
+
+void tst_UiTextFileModel::withoutSeparatorCount()
+{
+ UiHelpers::UiTextFileModel model;
+ model.setSource(file.fileName());
+ QCOMPARE(model.rowCount(), rowsCount + 1);
+}
+
+QTEST_MAIN(tst_UiTextFileModel)
+#include "tst_uitextfilemodel.moc"
diff --git a/tests/auto/models/uitextfilemodel/uitextfilemodel.pro b/tests/auto/models/uitextfilemodel/uitextfilemodel.pro
new file mode 100644
index 0000000..af12821
--- /dev/null
+++ b/tests/auto/models/uitextfilemodel/uitextfilemodel.pro
@@ -0,0 +1,8 @@
+CONFIG += testcase
+TARGET = tst_uitextfilemodel
+
+QT += testlib uihelpers core-private gui-private
+
+SOURCES += tst_uitextfilemodel.cpp
+
+