A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQAbstractListModel</id>
		<title>C++/Qt/QAbstractListModel - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQAbstractListModel"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QAbstractListModel&amp;action=history"/>
		<updated>2026-04-18T18:30:35Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QAbstractListModel&amp;diff=1138&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QAbstractListModel&amp;diff=1138&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QAbstractListModel&amp;diff=1139&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QAbstractListModel&amp;diff=1139&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:55Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==extends QAbstractListModel to create file list model==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the examples of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef FILELISTMODEL_H&lt;br /&gt;
#define FILELISTMODEL_H&lt;br /&gt;
#include &amp;lt;QAbstractListModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QList&amp;gt;&lt;br /&gt;
#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class FileListModel : public QAbstractListModel&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    FileListModel(QObject *parent = 0);&lt;br /&gt;
    int rowCount(const QModelIndex &amp;amp;parent = QModelIndex()) const;&lt;br /&gt;
    QVariant data(const QModelIndex &amp;amp;index, int role = Qt::DisplayRole) const;&lt;br /&gt;
signals:&lt;br /&gt;
    void numberPopulated(int number);&lt;br /&gt;
public slots:&lt;br /&gt;
    void setDirPath(const QString &amp;amp;path);&lt;br /&gt;
protected:&lt;br /&gt;
    bool canFetchMore(const QModelIndex &amp;amp;parent) const;&lt;br /&gt;
    void fetchMore(const QModelIndex &amp;amp;parent);&lt;br /&gt;
private:&lt;br /&gt;
    QStringList fileList;&lt;br /&gt;
    int fileCount;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the examples of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#include &amp;quot;filelistmodel.h&amp;quot;&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QPalette&amp;gt;&lt;br /&gt;
#include &amp;lt;QBrush&amp;gt;&lt;br /&gt;
#include &amp;lt;QDir&amp;gt;&lt;br /&gt;
FileListModel::FileListModel(QObject *parent)&lt;br /&gt;
    : QAbstractListModel(parent)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int FileListModel::rowCount(const QModelIndex &amp;amp; /* parent */) const&lt;br /&gt;
{&lt;br /&gt;
    return fileCount;&lt;br /&gt;
}&lt;br /&gt;
QVariant FileListModel::data(const QModelIndex &amp;amp;index, int role) const&lt;br /&gt;
{&lt;br /&gt;
    if (!index.isValid())&lt;br /&gt;
        return QVariant();&lt;br /&gt;
    &lt;br /&gt;
    if (index.row() &amp;gt;= fileList.size() || index.row() &amp;lt; 0)&lt;br /&gt;
        return QVariant();&lt;br /&gt;
    &lt;br /&gt;
    if (role == Qt::DisplayRole)&lt;br /&gt;
        return fileList.at(index.row());&lt;br /&gt;
    else if (role == Qt::BackgroundRole) {&lt;br /&gt;
        int batch = (index.row() / 100) % 2;&lt;br /&gt;
        if (batch == 0)&lt;br /&gt;
            return qApp-&amp;gt;palette().base();&lt;br /&gt;
        else&lt;br /&gt;
            return qApp-&amp;gt;palette().alternateBase();&lt;br /&gt;
    }&lt;br /&gt;
    return QVariant();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
bool FileListModel::canFetchMore(const QModelIndex &amp;amp; /* index */) const&lt;br /&gt;
{&lt;br /&gt;
    if (fileCount &amp;lt; fileList.size())&lt;br /&gt;
        return true;&lt;br /&gt;
    else&lt;br /&gt;
        return false;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void FileListModel::fetchMore(const QModelIndex &amp;amp; /* index */)&lt;br /&gt;
{&lt;br /&gt;
    int remainder = fileList.size() - fileCount;&lt;br /&gt;
    int itemsToFetch = qMin(100, remainder);&lt;br /&gt;
    beginInsertRows(QModelIndex(), fileCount, fileCount+itemsToFetch);&lt;br /&gt;
    &lt;br /&gt;
    fileCount += itemsToFetch;&lt;br /&gt;
    endInsertRows();&lt;br /&gt;
    emit numberPopulated(itemsToFetch);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void FileListModel::setDirPath(const QString &amp;amp;path)&lt;br /&gt;
{&lt;br /&gt;
    QDir dir(path);&lt;br /&gt;
    fileList = dir.entryList();&lt;br /&gt;
    fileCount = 0;&lt;br /&gt;
    reset();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#ifndef WINDOW_H&lt;br /&gt;
#define WINDOW_H&lt;br /&gt;
#include &amp;lt;QWidget&amp;gt;&lt;br /&gt;
QT_BEGIN_NAMESPACE&lt;br /&gt;
class QTextBrowser;&lt;br /&gt;
QT_END_NAMESPACE&lt;br /&gt;
class Window : public QWidget&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    Window(QWidget *parent = 0);&lt;br /&gt;
public slots:&lt;br /&gt;
    void updateLog(int number);&lt;br /&gt;
private:&lt;br /&gt;
    QTextBrowser *logViewer;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;filelistmodel.h&amp;quot;&lt;br /&gt;
#include &amp;quot;window.h&amp;quot;&lt;br /&gt;
Window::Window(QWidget *parent)&lt;br /&gt;
    : QWidget(parent)&lt;br /&gt;
{&lt;br /&gt;
    FileListModel *model = new FileListModel(this);&lt;br /&gt;
    model-&amp;gt;setDirPath(QLibraryInfo::location(QLibraryInfo::PrefixPath));&lt;br /&gt;
    QLabel *label = new QLabel(tr(&amp;quot;&amp;amp;Directory:&amp;quot;));&lt;br /&gt;
    QLineEdit *lineEdit = new QLineEdit;&lt;br /&gt;
    label-&amp;gt;setBuddy(lineEdit);&lt;br /&gt;
    QListView *view = new QListView;&lt;br /&gt;
    view-&amp;gt;setModel(model);&lt;br /&gt;
    logViewer = new QTextBrowser;&lt;br /&gt;
    logViewer-&amp;gt;setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));&lt;br /&gt;
    connect(lineEdit, SIGNAL(textChanged(const QString &amp;amp;)),&lt;br /&gt;
            model, SLOT(setDirPath(const QString &amp;amp;)));&lt;br /&gt;
    connect(lineEdit, SIGNAL(textChanged(const QString &amp;amp;)),&lt;br /&gt;
            logViewer, SLOT(clear()));&lt;br /&gt;
    connect(model, SIGNAL(numberPopulated(int)),&lt;br /&gt;
            this, SLOT(updateLog(int)));&lt;br /&gt;
    &lt;br /&gt;
    QGridLayout *layout = new QGridLayout;&lt;br /&gt;
    layout-&amp;gt;addWidget(label, 0, 0);&lt;br /&gt;
    layout-&amp;gt;addWidget(lineEdit, 0, 1);&lt;br /&gt;
    layout-&amp;gt;addWidget(view, 1, 0, 1, 2);&lt;br /&gt;
    layout-&amp;gt;addWidget(logViewer, 2, 0, 1, 2);&lt;br /&gt;
    setLayout(layout);&lt;br /&gt;
    setWindowTitle(tr(&amp;quot;Fetch More Example&amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
void Window::updateLog(int number)&lt;br /&gt;
{&lt;br /&gt;
    logViewer-&amp;gt;append(tr(&amp;quot;%1 items added.&amp;quot;).arg(number));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;quot;window.h&amp;quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    Window window;&lt;br /&gt;
    window.show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==persistent indexes==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the documentation of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef MODEL_H&lt;br /&gt;
#define MODEL_H&lt;br /&gt;
#include &amp;lt;QAbstractListModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QObject&amp;gt;&lt;br /&gt;
#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;
class StringListModel : public QAbstractListModel&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    StringListModel(const QStringList &amp;amp;strings, QObject *parent = 0)&lt;br /&gt;
        : QAbstractListModel(parent), stringList(strings) {}&lt;br /&gt;
    int rowCount(const QModelIndex &amp;amp;parent = QModelIndex()) const;&lt;br /&gt;
    QVariant data(const QModelIndex &amp;amp;index, int role) const;&lt;br /&gt;
    QVariant headerData(int section, Qt::Orientation orientation,&lt;br /&gt;
                        int role = Qt::DisplayRole) const;&lt;br /&gt;
    Qt::ItemFlags flags(const QModelIndex &amp;amp;index) const;&lt;br /&gt;
    bool setData(const QModelIndex &amp;amp;index, const QVariant &amp;amp;value,&lt;br /&gt;
                 int role = Qt::EditRole);&lt;br /&gt;
    bool insertRows(int position, int rows, const QModelIndex &amp;amp;index = QModelIndex());&lt;br /&gt;
    bool removeRows(int position, int rows, const QModelIndex &amp;amp;index = QModelIndex());&lt;br /&gt;
private:&lt;br /&gt;
    QStringList stringList;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
  model.cpp&lt;br /&gt;
  A simple model that uses a QStringList as its data source.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;qdebug.h&amp;gt;&lt;br /&gt;
#include &amp;quot;model.h&amp;quot;&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the number of items in the string list as the number of rows&lt;br /&gt;
    in the model.&lt;br /&gt;
*/&lt;br /&gt;
int StringListModel::rowCount(const QModelIndex &amp;amp;parent) const&lt;br /&gt;
{&lt;br /&gt;
    return stringList.count();&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns an appropriate value for the requested data.&lt;br /&gt;
    If the view requests an invalid index, an invalid variant is returned.&lt;br /&gt;
    If a header is requested then we just return the column or row number,&lt;br /&gt;
    depending on the orientation of the header.&lt;br /&gt;
    Any valid index that corresponds to a string in the list causes that&lt;br /&gt;
    string to be returned.&lt;br /&gt;
*/&lt;br /&gt;
QVariant StringListModel::data(const QModelIndex &amp;amp;index, int role) const&lt;br /&gt;
{&lt;br /&gt;
    if (!index.isValid())&lt;br /&gt;
        return QVariant();&lt;br /&gt;
    if (index.row() &amp;lt; 0 || index.row() &amp;gt;= stringList.size())&lt;br /&gt;
        return QVariant();&lt;br /&gt;
    if (role == Qt::DisplayRole)&lt;br /&gt;
        return stringList.at(index.row());&lt;br /&gt;
    else&lt;br /&gt;
        return QVariant();&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the appropriate header string depending on the orientation of&lt;br /&gt;
    the header and the section. If anything other than the display role is&lt;br /&gt;
    requested, we return an invalid variant.&lt;br /&gt;
*/&lt;br /&gt;
QVariant StringListModel::headerData(int section, Qt::Orientation orientation,&lt;br /&gt;
                                     int role) const&lt;br /&gt;
{&lt;br /&gt;
    if (role != Qt::DisplayRole)&lt;br /&gt;
        return QVariant();&lt;br /&gt;
    if (orientation == Qt::Horizontal)&lt;br /&gt;
        return QString(&amp;quot;Column %1&amp;quot;).arg(section);&lt;br /&gt;
    else&lt;br /&gt;
        return QString(&amp;quot;Row %1&amp;quot;).arg(section);&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns an appropriate value for the item&amp;quot;s flags. Valid items are&lt;br /&gt;
    enabled, selectable, and editable.&lt;br /&gt;
*/&lt;br /&gt;
Qt::ItemFlags StringListModel::flags(const QModelIndex &amp;amp;index) const&lt;br /&gt;
{&lt;br /&gt;
    if (!index.isValid())&lt;br /&gt;
        return Qt::ItemIsEnabled;&lt;br /&gt;
    return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Changes an item in the string list, but only if the following conditions&lt;br /&gt;
    are met:&lt;br /&gt;
    * The index supplied is valid.&lt;br /&gt;
    * The index corresponds to an item to be shown in a view.&lt;br /&gt;
    * The role associated with editing text is specified.&lt;br /&gt;
    The dataChanged() signal is emitted if the item is changed.&lt;br /&gt;
*/&lt;br /&gt;
bool StringListModel::setData(const QModelIndex &amp;amp;index,&lt;br /&gt;
                              const QVariant &amp;amp;value, int role)&lt;br /&gt;
{&lt;br /&gt;
    if (index.isValid() &amp;amp;&amp;amp; role == Qt::EditRole) {&lt;br /&gt;
        stringList.replace(index.row(), value.toString());&lt;br /&gt;
        emit dataChanged(index, index);&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
    return false;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Inserts a number of rows into the model at the specified position.&lt;br /&gt;
*/&lt;br /&gt;
bool StringListModel::insertRows(int position, int rows, const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    beginInsertRows(parent, position, position + rows - 1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        stringList.insert(position, &amp;quot;&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    endInsertRows();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Removes a number of rows from the model at the specified position.&lt;br /&gt;
*/&lt;br /&gt;
bool StringListModel::removeRows(int position, int rows, const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    beginRemoveRows(parent, position, position + rows - 1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        stringList.removeAt(position);&lt;br /&gt;
    }&lt;br /&gt;
    endRemoveRows();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#ifndef MAINWINDOW_H&lt;br /&gt;
#define MAINWINDOW_H&lt;br /&gt;
#include &amp;lt;QMainWindow&amp;gt;&lt;br /&gt;
#include &amp;lt;QModelIndex&amp;gt;&lt;br /&gt;
class QAbstractItemModel;&lt;br /&gt;
class QAction;&lt;br /&gt;
class QItemSelectionModel;&lt;br /&gt;
class MainWindow : public QMainWindow&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    MainWindow(QWidget *parent = 0);&lt;br /&gt;
private slots:&lt;br /&gt;
    void insertItem();&lt;br /&gt;
    void removeItem();&lt;br /&gt;
    void updateMenus(const QModelIndex &amp;amp;currentIndex);&lt;br /&gt;
private:&lt;br /&gt;
    QAbstractItemModel *model;&lt;br /&gt;
    QAction *insertAction;&lt;br /&gt;
    QAction *removeAction;&lt;br /&gt;
    QItemSelectionModel *selectionModel;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
#include &amp;quot;model.h&amp;quot;&lt;br /&gt;
/*!&lt;br /&gt;
    The main window constructor creates and populates a model with values&lt;br /&gt;
    from a string list then displays the contents of the model using a&lt;br /&gt;
    QListView widget.&lt;br /&gt;
*/&lt;br /&gt;
MainWindow::MainWindow(QWidget *parent)&lt;br /&gt;
    : QMainWindow(parent)&lt;br /&gt;
{&lt;br /&gt;
    QMenu *fileMenu = new QMenu(tr(&amp;quot;&amp;amp;File&amp;quot;));&lt;br /&gt;
    QAction *quitAction = fileMenu-&amp;gt;addAction(tr(&amp;quot;E&amp;amp;xit&amp;quot;));&lt;br /&gt;
    quitAction-&amp;gt;setShortcut(tr(&amp;quot;Ctrl+Q&amp;quot;));&lt;br /&gt;
    QMenu *itemsMenu = new QMenu(tr(&amp;quot;&amp;amp;Items&amp;quot;));&lt;br /&gt;
    insertAction = itemsMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Insert Item&amp;quot;));&lt;br /&gt;
    removeAction = itemsMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Remove Item&amp;quot;));&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(fileMenu);&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(itemsMenu);&lt;br /&gt;
    QStringList numbers;&lt;br /&gt;
    numbers &amp;lt;&amp;lt; tr(&amp;quot;One&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Two&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Three&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Four&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Five&amp;quot;)&lt;br /&gt;
            &amp;lt;&amp;lt; tr(&amp;quot;Six&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Seven&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Eight&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Nine&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Ten&amp;quot;);&lt;br /&gt;
    model = new StringListModel(numbers);&lt;br /&gt;
    QListView *view = new QListView(this);&lt;br /&gt;
    view-&amp;gt;setModel(model);&lt;br /&gt;
    selectionModel = view-&amp;gt;selectionModel();&lt;br /&gt;
    connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));&lt;br /&gt;
    connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem()));&lt;br /&gt;
    connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem()));&lt;br /&gt;
    connect(selectionModel,&lt;br /&gt;
            SIGNAL(currentChanged(const QModelIndex &amp;amp;, const QModelIndex &amp;amp;)),&lt;br /&gt;
            this, SLOT(updateMenus(const QModelIndex &amp;amp;)));&lt;br /&gt;
    &lt;br /&gt;
    setCentralWidget(view);&lt;br /&gt;
    setWindowTitle(&amp;quot;View onto a string list model&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::insertItem()&lt;br /&gt;
{&lt;br /&gt;
    if (!selectionModel-&amp;gt;currentIndex().isValid())&lt;br /&gt;
        return;&lt;br /&gt;
    QString itemText = QInputDialog::getText(this, tr(&amp;quot;Insert Item&amp;quot;),&lt;br /&gt;
        tr(&amp;quot;Input text for the new item:&amp;quot;));&lt;br /&gt;
    if (itemText.isNull())&lt;br /&gt;
        return;&lt;br /&gt;
    int row = selectionModel-&amp;gt;currentIndex().row();&lt;br /&gt;
    if (model-&amp;gt;insertRows(row, 1))&lt;br /&gt;
        model-&amp;gt;setData(model-&amp;gt;index(row, 0), itemText, Qt::EditRole);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::removeItem()&lt;br /&gt;
{&lt;br /&gt;
    if (!selectionModel-&amp;gt;currentIndex().isValid())&lt;br /&gt;
        return;&lt;br /&gt;
    int row = selectionModel-&amp;gt;currentIndex().row();&lt;br /&gt;
    model-&amp;gt;removeRows(row, 1);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::updateMenus(const QModelIndex &amp;amp;currentIndex)&lt;br /&gt;
{&lt;br /&gt;
    insertAction-&amp;gt;setEnabled(currentIndex.isValid());&lt;br /&gt;
    removeAction-&amp;gt;setEnabled(currentIndex.isValid());&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    MainWindow *window = new MainWindow;&lt;br /&gt;
    window-&amp;gt;show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==string list model example==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the documentation of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef MODEL_H&lt;br /&gt;
#define MODEL_H&lt;br /&gt;
#include &amp;lt;QAbstractListModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QObject&amp;gt;&lt;br /&gt;
#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class StringListModel : public QAbstractListModel&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    StringListModel(const QStringList &amp;amp;strings, QObject *parent = 0)&lt;br /&gt;
        : QAbstractListModel(parent), stringList(strings) {}&lt;br /&gt;
    int rowCount(const QModelIndex &amp;amp;parent = QModelIndex()) const;&lt;br /&gt;
    QVariant data(const QModelIndex &amp;amp;index, int role) const;&lt;br /&gt;
    QVariant headerData(int section, Qt::Orientation orientation,&lt;br /&gt;
 &lt;br /&gt;
                        int role = Qt::DisplayRole) const;&lt;br /&gt;
&lt;br /&gt;
    Qt::ItemFlags flags(const QModelIndex &amp;amp;index) const;&lt;br /&gt;
    bool setData(const QModelIndex &amp;amp;index, const QVariant &amp;amp;value,&lt;br /&gt;
 &lt;br /&gt;
                 int role = Qt::EditRole);&lt;br /&gt;
&lt;br /&gt;
    bool insertRows(int position, int rows, const QModelIndex &amp;amp;index = QModelIndex());&lt;br /&gt;
    bool removeRows(int position, int rows, const QModelIndex &amp;amp;index = QModelIndex());&lt;br /&gt;
&lt;br /&gt;
private:&lt;br /&gt;
    QStringList stringList;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
  model.cpp&lt;br /&gt;
  A simple model that uses a QStringList as its data source.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;quot;model.h&amp;quot;&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the number of items in the string list as the number of rows&lt;br /&gt;
    in the model.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
int StringListModel::rowCount(const QModelIndex &amp;amp;parent) const&lt;br /&gt;
{&lt;br /&gt;
    return stringList.count();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*!&lt;br /&gt;
    Returns an appropriate value for the requested data.&lt;br /&gt;
    If the view requests an invalid index, an invalid variant is returned.&lt;br /&gt;
    Any valid index that corresponds to a string in the list causes that&lt;br /&gt;
    string to be returned.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
QVariant StringListModel::data(const QModelIndex &amp;amp;index, int role) const&lt;br /&gt;
{&lt;br /&gt;
    if (!index.isValid())&lt;br /&gt;
        return QVariant();&lt;br /&gt;
    if (index.row() &amp;gt;= stringList.size())&lt;br /&gt;
        return QVariant();&lt;br /&gt;
    if (role == Qt::DisplayRole)&lt;br /&gt;
        return stringList.at(index.row());&lt;br /&gt;
    else&lt;br /&gt;
        return QVariant();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the appropriate header string depending on the orientation of&lt;br /&gt;
    the header and the section. If anything other than the display role is&lt;br /&gt;
    requested, we return an invalid variant.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
QVariant StringListModel::headerData(int section, Qt::Orientation orientation,&lt;br /&gt;
                                     int role) const&lt;br /&gt;
{&lt;br /&gt;
    if (role != Qt::DisplayRole)&lt;br /&gt;
        return QVariant();&lt;br /&gt;
    if (orientation == Qt::Horizontal)&lt;br /&gt;
        return QString(&amp;quot;Column %1&amp;quot;).arg(section);&lt;br /&gt;
    else&lt;br /&gt;
        return QString(&amp;quot;Row %1&amp;quot;).arg(section);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*!&lt;br /&gt;
    Returns an appropriate value for the item&amp;quot;s flags. Valid items are&lt;br /&gt;
    enabled, selectable, and editable.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
Qt::ItemFlags StringListModel::flags(const QModelIndex &amp;amp;index) const&lt;br /&gt;
{&lt;br /&gt;
    if (!index.isValid())&lt;br /&gt;
        return Qt::ItemIsEnabled;&lt;br /&gt;
    return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*!&lt;br /&gt;
    Changes an item in the string list, but only if the following conditions&lt;br /&gt;
    are met:&lt;br /&gt;
    * The index supplied is valid.&lt;br /&gt;
    * The index corresponds to an item to be shown in a view.&lt;br /&gt;
    * The role associated with editing text is specified.&lt;br /&gt;
    The dataChanged() signal is emitted if the item is changed.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
bool StringListModel::setData(const QModelIndex &amp;amp;index,&lt;br /&gt;
                              const QVariant &amp;amp;value, int role)&lt;br /&gt;
{&lt;br /&gt;
    if (index.isValid() &amp;amp;&amp;amp; role == Qt::EditRole) {&lt;br /&gt;
        stringList.replace(index.row(), value.toString());&lt;br /&gt;
        emit dataChanged(index, index);&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    return false;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*!&lt;br /&gt;
    Inserts a number of rows into the model at the specified position.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
bool StringListModel::insertRows(int position, int rows, const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    beginInsertRows(QModelIndex(), position, position+rows-1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        stringList.insert(position, &amp;quot;&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    endInsertRows();&lt;br /&gt;
    return true;&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*!&lt;br /&gt;
    Removes a number of rows from the model at the specified position.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
bool StringListModel::removeRows(int position, int rows, const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    beginRemoveRows(QModelIndex(), position, position+rows-1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        stringList.removeAt(position);&lt;br /&gt;
    }&lt;br /&gt;
    endRemoveRows();&lt;br /&gt;
    return true;&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*!&lt;br /&gt;
    The main function for the string list model example. This creates and&lt;br /&gt;
    populates a model with values from a string list then displays the&lt;br /&gt;
    contents of the model using a QListView widget.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;QAbstractItemModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QListView&amp;gt;&lt;br /&gt;
#include &amp;quot;model.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
// Unindented for quoting purposes:&lt;br /&gt;
QStringList numbers;&lt;br /&gt;
numbers &amp;lt;&amp;lt; &amp;quot;One&amp;quot; &amp;lt;&amp;lt; &amp;quot;Two&amp;quot; &amp;lt;&amp;lt; &amp;quot;Three&amp;quot; &amp;lt;&amp;lt; &amp;quot;Four&amp;quot; &amp;lt;&amp;lt; &amp;quot;Five&amp;quot;;&lt;br /&gt;
QAbstractItemModel *model = new StringListModel(numbers);&lt;br /&gt;
   &lt;br /&gt;
QListView *view = new QListView;&lt;br /&gt;
view-&amp;gt;setWindowTitle(&amp;quot;View onto a string list model&amp;quot;);&lt;br /&gt;
view-&amp;gt;setModel(model);&lt;br /&gt;
 &lt;br /&gt;
    model-&amp;gt;insertRows(5, 7, QModelIndex());&lt;br /&gt;
    for (int row = 5; row &amp;lt; 12; ++row) {&lt;br /&gt;
        QModelIndex index = model-&amp;gt;index(row, 0, QModelIndex());&lt;br /&gt;
        model-&amp;gt;setData(index, QString::number(row+1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    view-&amp;gt;show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>