📄 qproxymodel.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.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 GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qproxymodel.h"#ifndef QT_NO_PROXYMODEL#include <private/qproxymodel_p.h>#include <qsize.h>#include <qstringlist.h>/*! \class QProxyModel \obsolete \brief The QProxyModel class provides support for processing data passed between another model and a view. \ingroup model-view If you want to do filtering and sorting, see QSortFilterProxyModel. Proxy models provide a standard model interface that can be used to manipulate the data retrieved through an underlying model. They can be used to perform operations such as sorting and filtering on the data obtained without changing the contents of the model. Just as with subclasses of QAbstractItemView, QProxyModel provides the setModel() function that is used to specify the model to be acted on by the proxy. Views can be connected to either the underlying model or the proxy model with \l QAbstractItemView::setModel(). Since views rely on the information provided in model indexes to identify items of data from models, and to position these items in some visual representation, proxy models must create their own model indexes instead of supplying model indexes from their underlying models. \sa \link model-view-programming.html Model/View Programming\endlink QAbstractItemModel*//*! Constructs a proxy model with the given \a parent.*/QProxyModel::QProxyModel(QObject *parent) : QAbstractItemModel(*new QProxyModelPrivate, parent){ Q_D(QProxyModel); setModel(&d->empty);}/*! \internal*/QProxyModel::QProxyModel(QProxyModelPrivate &dd, QObject *parent) : QAbstractItemModel(dd, parent){ Q_D(QProxyModel); setModel(&d->empty);}/*! Destroys the proxy model.*/QProxyModel::~QProxyModel(){}/*! Sets the given \a model to be processed by the proxy model.*/void QProxyModel::setModel(QAbstractItemModel *model){ Q_D(QProxyModel); if (d->model && d->model != &d->empty) disconnectFromModel(d->model); if (model) { d->model = model; connectToModel(model); } else { d->model = &d->empty; }}/*! Returns the model that contains the data that is available through the proxy model.*/QAbstractItemModel *QProxyModel::model() const{ Q_D(const QProxyModel); return d->model;}/*! Returns the model index with the given \a row, \a column, and \a parent. \sa QAbstractItemModel::index()*/QModelIndex QProxyModel::index(int row, int column, const QModelIndex &parent) const{ Q_D(const QProxyModel); return setProxyModel(d->model->index(row, column, setSourceModel(parent)));}/*! Returns the model index that corresponds to the parent of the given \a child index.*/QModelIndex QProxyModel::parent(const QModelIndex &child) const{ Q_D(const QProxyModel); return setProxyModel(d->model->parent(setSourceModel(child)));}/*! Returns the number of rows for the given \a parent. \sa QAbstractItemModel::rowCount()*/int QProxyModel::rowCount(const QModelIndex &parent) const{ Q_D(const QProxyModel); return d->model->rowCount(setSourceModel(parent));}/*! Returns the number of columns for the given \a parent. \sa QAbstractItemModel::columnCount()*/int QProxyModel::columnCount(const QModelIndex &parent) const{ Q_D(const QProxyModel); return d->model->columnCount(setSourceModel(parent));}/*! Returns true if the item corresponding to the \a parent index has child items; otherwise returns false. \sa QAbstractItemModel::hasChildren()*/bool QProxyModel::hasChildren(const QModelIndex &parent) const{ Q_D(const QProxyModel); return d->model->hasChildren(setSourceModel(parent));}/*! Returns the data stored in the item with the given \a index under the specified \a role.*/QVariant QProxyModel::data(const QModelIndex &index, int role) const{ Q_D(const QProxyModel); return d->model->data(setSourceModel(index), role);}/*! Sets the \a role data for the item at \a index to \a value. Returns true if successful; otherwise returns false. The base class implementation returns false. This function and data() must be reimplemented for editable models. \sa data() itemData() QAbstractItemModel::setData()*/bool QProxyModel::setData(const QModelIndex &index, const QVariant &value, int role){ Q_D(const QProxyModel); return d->model->setData(setSourceModel(index), value, role);}/*! Returns the data stored in the \a section of the header with specified \a orientation under the given \a role.*/QVariant QProxyModel::headerData(int section, Qt::Orientation orientation, int role) const{ Q_D(const QProxyModel); return d->model->headerData(section, orientation, role);}/*! Sets the \a role data in the \a section of the header with the specified \a orientation to the \a value given. \sa QAbstractItemModel::setHeaderData()*/bool QProxyModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role){ Q_D(const QProxyModel); return d->model->setHeaderData(section, orientation, value, role);}/*! Returns a list of MIME types that are supported by the model.*/QStringList QProxyModel::mimeTypes() const{ Q_D(const QProxyModel); return d->model->mimeTypes();}/*! Returns MIME data for the specified \a indexes in the model.*/QMimeData *QProxyModel::mimeData(const QModelIndexList &indexes) const{ Q_D(const QProxyModel); QModelIndexList lst; for (int i = 0; i < indexes.count(); ++i) lst.append(setSourceModel(indexes.at(i))); return d->model->mimeData(lst);}/*! Returns true if the model accepts the \a data dropped onto an attached view for the specified \a action; otherwise returns false. The \a parent, \a row, and \a column details can be used to control which MIME types are acceptable to different parts of a model when received via the drag and drop system.*/bool QProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent){ Q_D(const QProxyModel); return d->model->dropMimeData(data, action, row, column, setSourceModel(parent));}/*! Returns the drop actions that are supported by the model; this is a combination of the individual actions defined in \l Qt::DropActions.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -