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%2FQAbstractTableModel</id>
		<title>C++/Qt/QAbstractTableModel - История изменений</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%2FQAbstractTableModel"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QAbstractTableModel&amp;action=history"/>
		<updated>2026-04-18T18:29:04Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QAbstractTableModel&amp;diff=1218&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/QAbstractTableModel&amp;diff=1218&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/QAbstractTableModel&amp;diff=1219&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/QAbstractTableModel&amp;diff=1219&amp;oldid=prev"/>
				<updated>2010-05-25T10:25:12Z</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;==A simple example that shows how selections can be used directly on a 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 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;QAbstractTableModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;
#include &amp;lt;QVariant&amp;gt;&lt;br /&gt;
class TableModel : public QAbstractTableModel&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    TableModel(int rows = 1, int columns = 1, QObject *parent = 0);&lt;br /&gt;
    int rowCount(const QModelIndex &amp;amp;parent = QModelIndex()) const;&lt;br /&gt;
    int columnCount(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;parent = QModelIndex());&lt;br /&gt;
    bool insertColumns(int position, int columns, const QModelIndex &amp;amp;parent = QModelIndex());&lt;br /&gt;
    bool removeRows(int position, int rows, const QModelIndex &amp;amp;parent = QModelIndex());&lt;br /&gt;
    bool removeColumns(int position, int columns, const QModelIndex &amp;amp;parent = QModelIndex());&lt;br /&gt;
private:&lt;br /&gt;
    QList&amp;lt;QStringList&amp;gt; rowList;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
    model.cpp&lt;br /&gt;
    Provides a table model for use in various examples.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;model.h&amp;quot;&lt;br /&gt;
/*!&lt;br /&gt;
    Constructs a table model with at least one row and one column.&lt;br /&gt;
*/&lt;br /&gt;
TableModel::TableModel(int rows, int columns, QObject *parent)&lt;br /&gt;
    : QAbstractTableModel(parent)&lt;br /&gt;
{&lt;br /&gt;
    QStringList newList;&lt;br /&gt;
    for (int column = 0; column &amp;lt; qMax(1, columns); ++column) {&lt;br /&gt;
        newList.append(&amp;quot;&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    for (int row = 0; row &amp;lt; qMax(1, rows); ++row) {&lt;br /&gt;
        rowList.append(newList);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the number of items in the row list as the number of rows&lt;br /&gt;
    in the model.&lt;br /&gt;
*/&lt;br /&gt;
int TableModel::rowCount(const QModelIndex &amp;amp;/*parent*/) const&lt;br /&gt;
{&lt;br /&gt;
    return rowList.size();&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the number of items in the first list item as the number of&lt;br /&gt;
    columns in the model. All rows should have the same number of columns.&lt;br /&gt;
*/&lt;br /&gt;
int TableModel::columnCount(const QModelIndex &amp;amp;/*parent*/) const&lt;br /&gt;
{&lt;br /&gt;
    return rowList[0].size();&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 for the display role; otherwise an invalid variant&lt;br /&gt;
    is returned.&lt;br /&gt;
*/&lt;br /&gt;
QVariant TableModel::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 (role == Qt::DisplayRole)&lt;br /&gt;
        return rowList[index.row()][index.column()];&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 TableModel::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 TableModel::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 Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Changes an item in the model, but only if the following conditions&lt;br /&gt;
    are met:&lt;br /&gt;
    * The index supplied is valid.&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 TableModel::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() || role != Qt::EditRole)&lt;br /&gt;
        return false;&lt;br /&gt;
    rowList[index.row()][index.column()] = value.toString();&lt;br /&gt;
    emit dataChanged(index, index);&lt;br /&gt;
    return true;&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 TableModel::insertRows(int position, int rows, const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    int columns = columnCount();&lt;br /&gt;
    beginInsertRows(parent, position, position + rows - 1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        QStringList items;&lt;br /&gt;
        for (int column = 0; column &amp;lt; columns; ++column)&lt;br /&gt;
            items.append(&amp;quot;&amp;quot;);&lt;br /&gt;
        rowList.insert(position, items);&lt;br /&gt;
    }&lt;br /&gt;
    endInsertRows();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Inserts a number of columns into the model at the specified position.&lt;br /&gt;
    Each entry in the list is extended in turn with the required number of&lt;br /&gt;
    empty strings.&lt;br /&gt;
*/&lt;br /&gt;
bool TableModel::insertColumns(int position, int columns,&lt;br /&gt;
                               const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    int rows = rowCount();&lt;br /&gt;
    beginInsertColumns(parent, position, position + columns - 1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        for (int column = position; column &amp;lt; columns; ++column) {&lt;br /&gt;
            rowList[row].insert(position, &amp;quot;&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    endInsertColumns();&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 TableModel::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;
        rowList.removeAt(position);&lt;br /&gt;
    }&lt;br /&gt;
    endRemoveRows();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Removes a number of columns from the model at the specified position.&lt;br /&gt;
    Each row is shortened by the number of columns specified.&lt;br /&gt;
*/&lt;br /&gt;
bool TableModel::removeColumns(int position, int columns,&lt;br /&gt;
                               const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    int rows = rowCount();&lt;br /&gt;
    beginRemoveColumns(parent, position, position + columns - 1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        for (int column = 0; column &amp;lt; columns; ++column) {&lt;br /&gt;
            rowList[row].removeAt(position);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    endRemoveColumns();&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;
/*&lt;br /&gt;
  main.cpp&lt;br /&gt;
  A simple example that shows how selections can be used directly on a model.&lt;br /&gt;
  It shows the result of some selections made using a table view.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QItemSelection&amp;gt;&lt;br /&gt;
#include &amp;lt;QItemSelectionModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QTableView&amp;gt;&lt;br /&gt;
#include &amp;quot;model.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;
&lt;br /&gt;
    TableModel *model = new TableModel(8, 4, &amp;amp;app);&lt;br /&gt;
    QTableView *table = new QTableView(0);&lt;br /&gt;
    table-&amp;gt;setModel(model);&lt;br /&gt;
    QItemSelectionModel *selectionModel = table-&amp;gt;selectionModel();&lt;br /&gt;
 &lt;br /&gt;
    QModelIndex topLeft;&lt;br /&gt;
    QModelIndex bottomRight;&lt;br /&gt;
    topLeft = model-&amp;gt;index(0, 0, QModelIndex());&lt;br /&gt;
    bottomRight = model-&amp;gt;index(5, 2, QModelIndex());&lt;br /&gt;
&lt;br /&gt;
    QItemSelection selection(topLeft, bottomRight);&lt;br /&gt;
    selectionModel-&amp;gt;select(selection, QItemSelectionModel::Select);&lt;br /&gt;
&lt;br /&gt;
    QItemSelection toggleSelection;&lt;br /&gt;
    topLeft = model-&amp;gt;index(2, 1, QModelIndex());&lt;br /&gt;
    bottomRight = model-&amp;gt;index(7, 3, QModelIndex());&lt;br /&gt;
    toggleSelection.select(topLeft, bottomRight);&lt;br /&gt;
    selectionModel-&amp;gt;select(toggleSelection, QItemSelectionModel::Toggle);&lt;br /&gt;
&lt;br /&gt;
    QItemSelection columnSelection;&lt;br /&gt;
    topLeft = model-&amp;gt;index(0, 1, QModelIndex());&lt;br /&gt;
    bottomRight = model-&amp;gt;index(0, 2, QModelIndex());&lt;br /&gt;
    columnSelection.select(topLeft, bottomRight);&lt;br /&gt;
    selectionModel-&amp;gt;select(columnSelection,&lt;br /&gt;
        QItemSelectionModel::Select | QItemSelectionModel::Columns);&lt;br /&gt;
    QItemSelection rowSelection;&lt;br /&gt;
    topLeft = model-&amp;gt;index(0, 0, QModelIndex());&lt;br /&gt;
    bottomRight = model-&amp;gt;index(1, 0, QModelIndex());&lt;br /&gt;
    rowSelection.select(topLeft, bottomRight);&lt;br /&gt;
    selectionModel-&amp;gt;select(rowSelection,&lt;br /&gt;
        QItemSelectionModel::Select | QItemSelectionModel::Rows);&lt;br /&gt;
&lt;br /&gt;
    table-&amp;gt;setWindowTitle(&amp;quot;Selected items in a table model&amp;quot;);&lt;br /&gt;
    table-&amp;gt;show();&lt;br /&gt;
    table-&amp;gt;resize(460, 280);&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;
==A single model can be shared between multiple views==&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;QAbstractTableModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;
#include &amp;lt;QVariant&amp;gt;&lt;br /&gt;
class TableModel : public QAbstractTableModel&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    TableModel(int rows = 1, int columns = 1, QObject *parent = 0);&lt;br /&gt;
    int rowCount(const QModelIndex &amp;amp;parent = QModelIndex()) const;&lt;br /&gt;
    int columnCount(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;parent = QModelIndex());&lt;br /&gt;
    bool insertColumns(int position, int columns, const QModelIndex &amp;amp;parent = QModelIndex());&lt;br /&gt;
    bool removeRows(int position, int rows, const QModelIndex &amp;amp;parent = QModelIndex());&lt;br /&gt;
    bool removeColumns(int position, int columns, const QModelIndex &amp;amp;parent = QModelIndex());&lt;br /&gt;
private:&lt;br /&gt;
    QList&amp;lt;QStringList&amp;gt; rowList;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
    model.cpp&lt;br /&gt;
    Provides a table model for use in various examples.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;model.h&amp;quot;&lt;br /&gt;
/*!&lt;br /&gt;
    Constructs a table model with at least one row and one column.&lt;br /&gt;
*/&lt;br /&gt;
TableModel::TableModel(int rows, int columns, QObject *parent)&lt;br /&gt;
    : QAbstractTableModel(parent)&lt;br /&gt;
{&lt;br /&gt;
    QStringList newList;&lt;br /&gt;
    for (int column = 0; column &amp;lt; qMax(1, columns); ++column) {&lt;br /&gt;
        newList.append(&amp;quot;&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    for (int row = 0; row &amp;lt; qMax(1, rows); ++row) {&lt;br /&gt;
        rowList.append(newList);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the number of items in the row list as the number of rows&lt;br /&gt;
    in the model.&lt;br /&gt;
*/&lt;br /&gt;
int TableModel::rowCount(const QModelIndex &amp;amp;/*parent*/) const&lt;br /&gt;
{&lt;br /&gt;
    return rowList.size();&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the number of items in the first list item as the number of&lt;br /&gt;
    columns in the model. All rows should have the same number of columns.&lt;br /&gt;
*/&lt;br /&gt;
int TableModel::columnCount(const QModelIndex &amp;amp;/*parent*/) const&lt;br /&gt;
{&lt;br /&gt;
    return rowList[0].size();&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 for the display role; otherwise an invalid variant&lt;br /&gt;
    is returned.&lt;br /&gt;
*/&lt;br /&gt;
QVariant TableModel::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 (role == Qt::DisplayRole)&lt;br /&gt;
        return rowList[index.row()][index.column()];&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 TableModel::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 TableModel::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 Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Changes an item in the model, but only if the following conditions&lt;br /&gt;
    are met:&lt;br /&gt;
    * The index supplied is valid.&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 TableModel::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() || role != Qt::EditRole)&lt;br /&gt;
        return false;&lt;br /&gt;
    rowList[index.row()][index.column()] = value.toString();&lt;br /&gt;
    emit dataChanged(index, index);&lt;br /&gt;
    return true;&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 TableModel::insertRows(int position, int rows, const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    int columns = columnCount();&lt;br /&gt;
    beginInsertRows(parent, position, position + rows - 1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        QStringList items;&lt;br /&gt;
        for (int column = 0; column &amp;lt; columns; ++column)&lt;br /&gt;
            items.append(&amp;quot;&amp;quot;);&lt;br /&gt;
        rowList.insert(position, items);&lt;br /&gt;
    }&lt;br /&gt;
    endInsertRows();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Inserts a number of columns into the model at the specified position.&lt;br /&gt;
    Each entry in the list is extended in turn with the required number of&lt;br /&gt;
    empty strings.&lt;br /&gt;
*/&lt;br /&gt;
bool TableModel::insertColumns(int position, int columns, const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    int rows = rowCount();&lt;br /&gt;
    beginInsertColumns(parent, position, position + columns - 1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        for (int column = position; column &amp;lt; columns; ++column) {&lt;br /&gt;
            rowList[row].insert(position, &amp;quot;&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    endInsertColumns();&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 TableModel::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;
        rowList.removeAt(position);&lt;br /&gt;
    }&lt;br /&gt;
    endRemoveRows();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Removes a number of columns from the model at the specified position.&lt;br /&gt;
    Each row is shortened by the number of columns specified.&lt;br /&gt;
*/&lt;br /&gt;
bool TableModel::removeColumns(int position, int columns, const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    int rows = rowCount();&lt;br /&gt;
    beginRemoveColumns(parent, position, position + columns - 1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        for (int column = 0; column &amp;lt; columns; ++column) {&lt;br /&gt;
            rowList[row].removeAt(position);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    endRemoveColumns();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
  main.cpp&lt;br /&gt;
  A simple example that shows how a single model can be shared between&lt;br /&gt;
  multiple views.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QHeaderView&amp;gt;&lt;br /&gt;
#include &amp;lt;QItemSelectionModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QTableView&amp;gt;&lt;br /&gt;
#include &amp;quot;model.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;
    TableModel *model = new TableModel(4, 2, &amp;amp;app);&lt;br /&gt;
&lt;br /&gt;
    QTableView *firstTableView = new QTableView;&lt;br /&gt;
    QTableView *secondTableView = new QTableView;&lt;br /&gt;
&lt;br /&gt;
    firstTableView-&amp;gt;setModel(model);&lt;br /&gt;
    secondTableView-&amp;gt;setModel(model);&lt;br /&gt;
&lt;br /&gt;
    firstTableView-&amp;gt;horizontalHeader()-&amp;gt;setModel(model);&lt;br /&gt;
    for (int row = 0; row &amp;lt; 4; ++row) {&lt;br /&gt;
        for (int column = 0; column &amp;lt; 2; ++column) {&lt;br /&gt;
            QModelIndex index = model-&amp;gt;index(row, column, QModelIndex());&lt;br /&gt;
            model-&amp;gt;setData(index, QVariant(QString(&amp;quot;(%1, %2)&amp;quot;).arg(row).arg(column)));&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    secondTableView-&amp;gt;setSelectionModel(firstTableView-&amp;gt;selectionModel());&lt;br /&gt;
&lt;br /&gt;
    firstTableView-&amp;gt;setWindowTitle(&amp;quot;First table view&amp;quot;);&lt;br /&gt;
    secondTableView-&amp;gt;setWindowTitle(&amp;quot;Second table view&amp;quot;);&lt;br /&gt;
    firstTableView-&amp;gt;show();&lt;br /&gt;
    secondTableView-&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;
==how selections can be used directly on a 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 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;QAbstractTableModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;
#include &amp;lt;QVariant&amp;gt;&lt;br /&gt;
class TableModel : public QAbstractTableModel&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    TableModel(int rows = 1, int columns = 1, QObject *parent = 0);&lt;br /&gt;
    int rowCount(const QModelIndex &amp;amp;parent = QModelIndex()) const;&lt;br /&gt;
    int columnCount(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;parent = QModelIndex());&lt;br /&gt;
    bool insertColumns(int position, int columns, const QModelIndex &amp;amp;parent = QModelIndex());&lt;br /&gt;
    bool removeRows(int position, int rows, const QModelIndex &amp;amp;parent = QModelIndex());&lt;br /&gt;
    bool removeColumns(int position, int columns, const QModelIndex &amp;amp;parent = QModelIndex());&lt;br /&gt;
private:&lt;br /&gt;
    QList&amp;lt;QStringList&amp;gt; rowList;&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;
    Provides a table model for use in various examples.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;model.h&amp;quot;&lt;br /&gt;
/*!&lt;br /&gt;
    Constructs a table model with at least one row and one column.&lt;br /&gt;
*/&lt;br /&gt;
TableModel::TableModel(int rows, int columns, QObject *parent)&lt;br /&gt;
    : QAbstractTableModel(parent)&lt;br /&gt;
{&lt;br /&gt;
    QStringList newList;&lt;br /&gt;
    for (int column = 0; column &amp;lt; qMax(1, columns); ++column) {&lt;br /&gt;
        newList.append(&amp;quot;&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    for (int row = 0; row &amp;lt; qMax(1, rows); ++row) {&lt;br /&gt;
        rowList.append(newList);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the number of items in the row list as the number of rows&lt;br /&gt;
    in the model.&lt;br /&gt;
*/&lt;br /&gt;
int TableModel::rowCount(const QModelIndex &amp;amp;/*parent*/) const&lt;br /&gt;
{&lt;br /&gt;
    return rowList.size();&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the number of items in the first list item as the number of&lt;br /&gt;
    columns in the model. All rows should have the same number of columns.&lt;br /&gt;
*/&lt;br /&gt;
int TableModel::columnCount(const QModelIndex &amp;amp;/*parent*/) const&lt;br /&gt;
{&lt;br /&gt;
    return rowList[0].size();&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 for the display role; otherwise an invalid variant&lt;br /&gt;
    is returned.&lt;br /&gt;
*/&lt;br /&gt;
QVariant TableModel::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 (role == Qt::DisplayRole)&lt;br /&gt;
        return rowList[index.row()][index.column()];&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 TableModel::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 TableModel::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 Qt::ItemIsEnabled | Qt::ItemIsSelectable;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Changes an item in the model, but only if the following conditions&lt;br /&gt;
    are met:&lt;br /&gt;
    * The index supplied is valid.&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 TableModel::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() || role != Qt::EditRole)&lt;br /&gt;
        return false;&lt;br /&gt;
    rowList[index.row()][index.column()] = value.toString();&lt;br /&gt;
    emit dataChanged(index, index);&lt;br /&gt;
    return true;&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 TableModel::insertRows(int position, int rows, const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    int columns = columnCount();&lt;br /&gt;
    beginInsertRows(parent, position, position + rows - 1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        QStringList items;&lt;br /&gt;
        for (int column = 0; column &amp;lt; columns; ++column)&lt;br /&gt;
            items.append(&amp;quot;&amp;quot;);&lt;br /&gt;
        rowList.insert(position, items);&lt;br /&gt;
    }&lt;br /&gt;
    endInsertRows();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Inserts a number of columns into the model at the specified position.&lt;br /&gt;
    Each entry in the list is extended in turn with the required number of&lt;br /&gt;
    empty strings.&lt;br /&gt;
*/&lt;br /&gt;
bool TableModel::insertColumns(int position, int columns,&lt;br /&gt;
                               const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    int rows = rowCount();&lt;br /&gt;
    beginInsertColumns(parent, position, position + columns - 1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        for (int column = position; column &amp;lt; columns; ++column) {&lt;br /&gt;
            rowList[row].insert(position, &amp;quot;&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    endInsertColumns();&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 TableModel::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;
        rowList.removeAt(position);&lt;br /&gt;
    }&lt;br /&gt;
    endRemoveRows();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Removes a number of columns from the model at the specified position.&lt;br /&gt;
    Each row is shortened by the number of columns specified.&lt;br /&gt;
*/&lt;br /&gt;
bool TableModel::removeColumns(int position, int columns,&lt;br /&gt;
                               const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    int rows = rowCount();&lt;br /&gt;
    beginRemoveColumns(parent, position, position + columns - 1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        for (int column = 0; column &amp;lt; columns; ++column) {&lt;br /&gt;
            rowList[row].removeAt(position);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    endRemoveColumns();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
#ifndef WINDOW_H&lt;br /&gt;
#define WINDOW_H&lt;br /&gt;
#include &amp;lt;QItemSelection&amp;gt;&lt;br /&gt;
#include &amp;lt;QMainWindow&amp;gt;&lt;br /&gt;
#include &amp;lt;QAbstractItemModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QWidget&amp;gt;&lt;br /&gt;
#include &amp;lt;QTableView&amp;gt;&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 fillSelection();&lt;br /&gt;
    void clearSelection();&lt;br /&gt;
    void selectAll();&lt;br /&gt;
private:&lt;br /&gt;
    QAbstractItemModel *model;&lt;br /&gt;
    QItemSelectionModel *selectionModel;&lt;br /&gt;
    QTableView *table;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
  window.cpp&lt;br /&gt;
  A minimal subclass of QTableView with slots to allow the selection model&lt;br /&gt;
  to be monitored.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;QAbstractItemModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QItemSelection&amp;gt;&lt;br /&gt;
#include &amp;lt;QItemSelectionModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QMenu&amp;gt;&lt;br /&gt;
#include &amp;lt;QMenuBar&amp;gt;&lt;br /&gt;
#include &amp;lt;QStatusBar&amp;gt;&lt;br /&gt;
#include &amp;quot;model.h&amp;quot;&lt;br /&gt;
#include &amp;quot;window.h&amp;quot;&lt;br /&gt;
MainWindow::MainWindow(QWidget *parent)&lt;br /&gt;
    : QMainWindow(parent)&lt;br /&gt;
{&lt;br /&gt;
    setWindowTitle(&amp;quot;Selected Items in a Table Model&amp;quot;);&lt;br /&gt;
    model = new TableModel(8, 4, this);&lt;br /&gt;
    table = new QTableView(this);&lt;br /&gt;
    table-&amp;gt;setModel(model);&lt;br /&gt;
    QMenu *actionMenu = new QMenu(tr(&amp;quot;&amp;amp;Actions&amp;quot;), this);&lt;br /&gt;
    QAction *fillAction = actionMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Fill Selection&amp;quot;));&lt;br /&gt;
    QAction *clearAction = actionMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Clear Selection&amp;quot;));&lt;br /&gt;
    QAction *selectAllAction = actionMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Select All&amp;quot;));&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(actionMenu);&lt;br /&gt;
    connect(fillAction, SIGNAL(triggered()), this, SLOT(fillSelection()));&lt;br /&gt;
    connect(clearAction, SIGNAL(triggered()), this, SLOT(clearSelection()));&lt;br /&gt;
    connect(selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()));&lt;br /&gt;
    selectionModel = table-&amp;gt;selectionModel();&lt;br /&gt;
    statusBar();&lt;br /&gt;
    setCentralWidget(table);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::fillSelection()&lt;br /&gt;
{&lt;br /&gt;
    QModelIndexList indexes = selectionModel-&amp;gt;selectedIndexes();&lt;br /&gt;
    QModelIndex index;&lt;br /&gt;
    foreach(index, indexes) {&lt;br /&gt;
        QString text = QString(&amp;quot;(%1,%2)&amp;quot;).arg(index.row()).arg(index.column());&lt;br /&gt;
        model-&amp;gt;setData(index, text);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::clearSelection()&lt;br /&gt;
{&lt;br /&gt;
    QModelIndexList indexes = selectionModel-&amp;gt;selectedIndexes();&lt;br /&gt;
    QModelIndex index;&lt;br /&gt;
    foreach(index, indexes)&lt;br /&gt;
        model-&amp;gt;setData(index, &amp;quot;&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::selectAll()&lt;br /&gt;
{&lt;br /&gt;
    QModelIndex parent = QModelIndex();&lt;br /&gt;
 &lt;br /&gt;
    QModelIndex topLeft = model-&amp;gt;index(0, 0, parent);&lt;br /&gt;
    QModelIndex bottomRight = model-&amp;gt;index(model-&amp;gt;rowCount(parent)-1,&lt;br /&gt;
        model-&amp;gt;columnCount(parent)-1, parent);&lt;br /&gt;
&lt;br /&gt;
    QItemSelection selection(topLeft, bottomRight);&lt;br /&gt;
    selectionModel-&amp;gt;select(selection, QItemSelectionModel::Select);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
  main.cpp&lt;br /&gt;
  A simple example that shows how selections can be used directly on a model.&lt;br /&gt;
  It shows the result of some selections made using a table view.&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;
    QMainWindow *window = new MainWindow;&lt;br /&gt;
    window-&amp;gt;show();&lt;br /&gt;
    window-&amp;gt;resize(640, 480);&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>