Qt 4.8
Public Functions | Protected Functions | List of all members
QProxyModel Class Reference

The QProxyModel class provides support for processing data passed between another model and a view. More...

#include <qproxymodel.h>

Inheritance diagram for QProxyModel:
QAbstractItemModel QObject

Public Functions

int columnCount (const QModelIndex &parent=QModelIndex()) const
 Returns the number of columns for the given parent. More...
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 Returns the data stored in the item with the given index under the specified role. More...
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 Returns true if the model accepts the data dropped onto an attached view for the specified action; otherwise returns false. More...
 
void fetchMore (const QModelIndex &parent)
 Fetches more child items of the given parent. More...
 
Qt::ItemFlags flags (const QModelIndex &index) const
 Returns the item flags for the given index. More...
 
bool hasChildren (const QModelIndex &parent=QModelIndex()) const
 Returns true if the item corresponding to the parent index has child items; otherwise returns false. More...
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 Returns the data stored in the section of the header with specified orientation under the given role. More...
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Returns the model index with the given row, column, and parent. More...
 
bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 Inserts count columns into the model, creating new items as children of the given parent. More...
 
bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex())
 Inserts count rows into the model, creating new items as children of the given parent. More...
 
QModelIndexList match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
 Returns a list of model indexes that each contain the given value for the role specified. More...
 
QMimeDatamimeData (const QModelIndexList &indexes) const
 Returns MIME data for the specified indexes in the model. More...
 
QStringList mimeTypes () const
 Returns a list of MIME types that are supported by the model. More...
 
QAbstractItemModelmodel () const
 Returns the model that contains the data that is available through the proxy model. More...
 
QModelIndex parent (const QModelIndex &child) const
 Returns the model index that corresponds to the parent of the given child index. More...
 
 QProxyModel (QObject *parent=0)
 Constructs a proxy model with the given parent. More...
 
void revert ()
 Lets the model know that it should discard cached information. More...
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 Returns the number of rows for the given parent. More...
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 Sets the role data for the item at index to value. More...
 
bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
 Sets the role data in the section of the header with the specified orientation to the value given. More...
 
virtual void setModel (QAbstractItemModel *model)
 Sets the given model to be processed by the proxy model. More...
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
 Sorts the child items in the specified column according to the sort order defined by order. More...
 
QSize span (const QModelIndex &index) const
 Returns the size of the item that corresponds to the specified index. More...
 
bool submit ()
 Lets the model know that it should submit cached information to permanent storage. More...
 
Qt::DropActions supportedDropActions () const
 Returns the drop actions that are supported by the model; this is a combination of the individual actions defined in Qt::DropActions . More...
 
 ~QProxyModel ()
 Destroys the proxy model. More...
 
- Public Functions inherited from QAbstractItemModel
virtual QModelIndex buddy (const QModelIndex &index) const
 Returns a model index for the buddy of the item represented by index. More...
 
virtual bool canFetchMore (const QModelIndex &parent) const
 Returns true if there is more data available for parent; otherwise returns false. More...
 
bool hasIndex (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Returns true if the model returns a valid QModelIndex for row and column with parent, otherwise returns false. More...
 
bool insertColumn (int column, const QModelIndex &parent=QModelIndex())
 Inserts a single column before the given column in the child items of the parent specified. More...
 
bool insertRow (int row, const QModelIndex &parent=QModelIndex())
 Inserts a single row before the given row in the child items of the parent specified. More...
 
virtual QMap< int, QVariantitemData (const QModelIndex &index) const
 Returns a map with values for all predefined roles in the model for the item at the given index. More...
 
 QAbstractItemModel (QObject *parent=0)
 Constructs an abstract item model with the given parent. More...
 
bool removeColumn (int column, const QModelIndex &parent=QModelIndex())
 Removes the given column from the child items of the parent specified. More...
 
virtual bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, removes count columns starting with the given column under parent parent from the model. More...
 
bool removeRow (int row, const QModelIndex &parent=QModelIndex())
 Removes the given row from the child items of the parent specified. More...
 
virtual bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, removes count rows starting with the given row under parent parent from the model. More...
 
const QHash< int, QByteArray > & roleNames () const
 Returns the model's role names. More...
 
virtual bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles)
 Sets the role data for the item at index to the associated value in roles, for every Qt::ItemDataRole. More...
 
void setSupportedDragActions (Qt::DropActions)
 Sets the supported drag actions for the items in the model. More...
 
QModelIndex sibling (int row, int column, const QModelIndex &idx) const
 Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location. More...
 
Qt::DropActions supportedDragActions () const
 Returns the actions supported by the data in this model. More...
 
virtual ~QAbstractItemModel ()
 Destroys the abstract item model. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

void connectToModel (const QAbstractItemModel *model) const
 Connect to all the signals emitted by given model. More...
 
void disconnectFromModel (const QAbstractItemModel *model) const
 Disconnect from all the signals emitted by the given model. More...
 
 QProxyModel (QProxyModelPrivate &, QObject *parent=0)
 
QModelIndex setProxyModel (const QModelIndex &source_index) const
 Change the model pointer in the given source_index to point to the proxy model. More...
 
QModelIndex setSourceModel (const QModelIndex &proxy_index) const
 Change the model pointer in the given proxy_index to point to the source model. More...
 
- Protected Functions inherited from QAbstractItemModel
void beginInsertColumns (const QModelIndex &parent, int first, int last)
 Begins a column insertion operation. More...
 
void beginInsertRows (const QModelIndex &parent, int first, int last)
 Begins a row insertion operation. More...
 
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn)
 Begins a column move operation. More...
 
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
 Begins a row move operation. More...
 
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 Begins a column removal operation. More...
 
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 Begins a row removal operation. More...
 
void beginResetModel ()
 Begins a model reset operation. More...
 
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
 Changes the QPersistentModelIndex that is equal to the given from model index to the given to model index. More...
 
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
 Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list to the given to model index list. More...
 
QModelIndex createIndex (int row, int column, void *data=0) const
 Creates a model index for the given row and column with the internal pointer ptr. More...
 
QModelIndex createIndex (int row, int column, int id) const
 Use QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) instead. More...
 
QModelIndex createIndex (int row, int column, quint32 id) const
 Creates a model index for the given row and column with the internal identifier, id. More...
 
bool decodeData (int row, int column, const QModelIndex &parent, QDataStream &stream)
 
void encodeData (const QModelIndexList &indexes, QDataStream &stream) const
 
void endInsertColumns ()
 Ends a column insertion operation. More...
 
void endInsertRows ()
 Ends a row insertion operation. More...
 
void endMoveColumns ()
 Ends a column move operation. More...
 
void endMoveRows ()
 Ends a row move operation. More...
 
void endRemoveColumns ()
 Ends a column removal operation. More...
 
void endRemoveRows ()
 Ends a row removal operation. More...
 
void endResetModel ()
 Completes a model reset operation. More...
 
QModelIndexList persistentIndexList () const
 Returns the list of indexes stored as persistent indexes in the model. More...
 
 QAbstractItemModel (QAbstractItemModelPrivate &dd, QObject *parent=0)
 
void reset ()
 Resets the model to its original state in any attached views. More...
 
void setRoleNames (const QHash< int, QByteArray > &roleNames)
 Sets the model's role names to roleNames. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Additional Inherited Members

- Public Slots inherited from QAbstractItemModel
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QAbstractItemModel
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted just before columns are inserted into the model. More...
 
void columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 This signal is emitted just before columns are moved within the model. More...
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted just before columns are removed from the model. More...
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted after columns have been inserted into the model. More...
 
void columnsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
 This signal is emitted after columns have been moved within the model. More...
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted after columns have been removed from the model. More...
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 This signal is emitted whenever the data in an existing item changes. More...
 
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 This signal is emitted whenever a header is changed. More...
 
void layoutAboutToBeChanged ()
 This signal is emitted just before the layout of a model is changed. More...
 
void layoutChanged ()
 This signal is emitted whenever the layout of items exposed by the model has changed; for example, when the model has been sorted. More...
 
void modelAboutToBeReset ()
 This signal is emitted when reset() is called, before the model's internal state (e. More...
 
void modelReset ()
 This signal is emitted when reset() is called, after the model's internal state (e. More...
 
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted just before rows are inserted into the model. More...
 
void rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 This signal is emitted just before rows are moved within the model. More...
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted just before rows are removed from the model. More...
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted after rows have been inserted into the model. More...
 
void rowsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
 This signal is emitted after rows have been moved within the model. More...
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted after rows have been removed from the model. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QAbstractItemModel
void resetInternalData ()
 This slot is called just after the internal data of a model is cleared while it is being reset. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QProxyModel class provides support for processing data passed between another model and a 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 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.

See also
Model/View Programming QAbstractItemModel

Definition at line 57 of file qproxymodel.h.

Constructors and Destructors

◆ QProxyModel() [1/2]

QProxyModel::QProxyModel ( QObject parent = 0)
explicit

Constructs a proxy model with the given parent.

Definition at line 87 of file qproxymodel.cpp.

89 {
91  setModel(&d->empty);
92 }
double d
Definition: qnumeric_p.h:62
virtual void setModel(QAbstractItemModel *model)
Sets the given model to be processed by the proxy model.
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57
QAbstractItemModel(QObject *parent=0)
Constructs an abstract item model with the given parent.

◆ ~QProxyModel()

QProxyModel::~QProxyModel ( )

Destroys the proxy model.

Definition at line 107 of file qproxymodel.cpp.

108 {
109 }

◆ QProxyModel() [2/2]

QProxyModel::QProxyModel ( QProxyModelPrivate dd,
QObject parent = 0 
)
protected
Warning
This function is not part of the public interface.

Definition at line 97 of file qproxymodel.cpp.

98  : QAbstractItemModel(dd, parent)
99 {
100  Q_D(QProxyModel);
101  setModel(&d->empty);
102 }
double d
Definition: qnumeric_p.h:62
virtual void setModel(QAbstractItemModel *model)
Sets the given model to be processed by the proxy model.
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57
QAbstractItemModel(QObject *parent=0)
Constructs an abstract item model with the given parent.

Functions

◆ columnCount()

int QProxyModel::columnCount ( const QModelIndex parent = QModelIndex()) const
virtual

Returns the number of columns for the given parent.

See also
QAbstractItemModel::columnCount()

Implements QAbstractItemModel.

Definition at line 174 of file qproxymodel.cpp.

175 {
176  Q_D(const QProxyModel);
177  return d->model->columnCount(setSourceModel(parent));
178 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex setSourceModel(const QModelIndex &proxy_index) const
Change the model pointer in the given proxy_index to point to the source model.
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ connectToModel()

void QProxyModel::connectToModel ( const QAbstractItemModel model) const
protected

Connect to all the signals emitted by given model.

Warning
This function is not part of the public interface.

Definition at line 437 of file qproxymodel.cpp.

Referenced by setModel().

438 {
440  this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex)));
442  this, SIGNAL(headerDataChanged(Qt::Orientation,int,int))); // signal to signal
444  this, SLOT(_q_sourceRowsAboutToBeInserted(QModelIndex,int,int)));
445  connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
446  this, SLOT(_q_sourceRowsInserted(QModelIndex,int,int)));
448  this, SLOT(_q_sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
449  connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
450  this, SLOT(_q_sourceRowsRemoved(QModelIndex,int,int)));
452  this, SLOT(_q_sourceColumnsAboutToBeInserted(QModelIndex,int,int)));
453  connect(model, SIGNAL(columnsInserted(QModelIndex,int,int)),
454  this, SLOT(_q_sourceColumnsInserted(QModelIndex,int,int)));
456  this, SLOT(_q_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)));
457  connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
458  this, SLOT(_q_sourceColumnsRemoved(QModelIndex,int,int)));
459  connect(model, SIGNAL(modelReset()), this, SIGNAL(modelReset())); // signal to signal
460  connect(model, SIGNAL(layoutAboutToBeChanged()), this, SIGNAL(layoutAboutToBeChanged())); // signal to signal
461  connect(model, SIGNAL(layoutChanged()), this, SIGNAL(layoutChanged())); // signal to signal
462 }
#define SLOT(a)
Definition: qobjectdefs.h:226
void columnsInserted(const QModelIndex &parent, int first, int last)
This signal is emitted after columns have been inserted into the model.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last)
This signal is emitted just before columns are inserted into the model.
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last)
This signal is emitted just before rows are inserted into the model.
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted just before columns are removed from the model.
void headerDataChanged(Qt::Orientation orientation, int first, int last)
This signal is emitted whenever a header is changed.
void rowsInserted(const QModelIndex &parent, int first, int last)
This signal is emitted after rows have been inserted into the model.
The QModelIndex class is used to locate data in a data model.
void modelReset()
This signal is emitted when reset() is called, after the model&#39;s internal state (e.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This signal is emitted whenever the data in an existing item changes.
void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted just before rows are removed from the model.
Orientation
Definition: qnamespace.h:174
void rowsRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted after rows have been removed from the model.
void columnsRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted after columns have been removed from the model.

◆ data()

QVariant QProxyModel::data ( const QModelIndex index,
int  role = Qt::DisplayRole 
) const
virtual

Returns the data stored in the item with the given index under the specified role.

Implements QAbstractItemModel.

Definition at line 196 of file qproxymodel.cpp.

197 {
198  Q_D(const QProxyModel);
199  return d->model->data(setSourceModel(index), role);
200 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex setSourceModel(const QModelIndex &proxy_index) const
Change the model pointer in the given proxy_index to point to the source model.
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ disconnectFromModel()

void QProxyModel::disconnectFromModel ( const QAbstractItemModel model) const
protected

Disconnect from all the signals emitted by the given model.

Warning
This function is not part of the public interface.

Definition at line 471 of file qproxymodel.cpp.

Referenced by setModel().

472 {
474  this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex)));
476  this, SIGNAL(headerDataChanged(Qt::Orientation,int,int))); // signal to signal
478  this, SLOT(_q_sourceRowsAboutToBeInserted(QModelIndex,int,int)));
479  disconnect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
480  this, SLOT(rowsInserted(QModelIndex,int,int)));
482  this, SLOT(_q_sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
483  disconnect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
484  this, SLOT(_q_sourceRowsRemoved(QModelIndex,int,int)));
486  this, SLOT(_q_sourceColumnsAboutToBeInserted(QModelIndex,int,int)));
487  disconnect(model, SIGNAL(columnsInserted(QModelIndex,int,int)),
488  this, SLOT(_q_sourceColumnsInserted(QModelIndex,int,int)));
490  this, SLOT(_q_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)));
491  disconnect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
492  this, SLOT(_q_sourceColumnsRemoved(QModelIndex,int,int)));
493  disconnect(model, SIGNAL(modelReset()), this, SIGNAL(modelReset())); // signal to signal
494  disconnect(model, SIGNAL(layoutAboutToBeChanged()), this, SIGNAL(layoutAboutToBeChanged())); // signal to signal
495  disconnect(model, SIGNAL(layoutChanged()), this, SIGNAL(layoutChanged())); // signal to signal
496 }
#define SLOT(a)
Definition: qobjectdefs.h:226
void columnsInserted(const QModelIndex &parent, int first, int last)
This signal is emitted after columns have been inserted into the model.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last)
This signal is emitted just before columns are inserted into the model.
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last)
This signal is emitted just before rows are inserted into the model.
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted just before columns are removed from the model.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
void headerDataChanged(Qt::Orientation orientation, int first, int last)
This signal is emitted whenever a header is changed.
void rowsInserted(const QModelIndex &parent, int first, int last)
This signal is emitted after rows have been inserted into the model.
The QModelIndex class is used to locate data in a data model.
void modelReset()
This signal is emitted when reset() is called, after the model&#39;s internal state (e.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This signal is emitted whenever the data in an existing item changes.
void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted just before rows are removed from the model.
Orientation
Definition: qnamespace.h:174
void rowsRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted after rows have been removed from the model.
void columnsRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted after columns have been removed from the model.

◆ dropMimeData()

bool QProxyModel::dropMimeData ( const QMimeData data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex parent 
)
virtual

Returns true if the model accepts the data dropped onto an attached view for the specified action; otherwise returns false.

The parent, row, and 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.

Reimplemented from QAbstractItemModel.

Definition at line 269 of file qproxymodel.cpp.

271 {
272  Q_D(const QProxyModel);
273  return d->model->dropMimeData(data, action, row, column, setSourceModel(parent));
274 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex setSourceModel(const QModelIndex &proxy_index) const
Change the model pointer in the given proxy_index to point to the source model.
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ fetchMore()

void QProxyModel::fetchMore ( const QModelIndex parent)
virtual

Fetches more child items of the given parent.

This function is used by views to tell the model that they can display more data than the model has provided.

See also
QAbstractItemModel::fetchMore()

Reimplemented from QAbstractItemModel.

Definition at line 330 of file qproxymodel.cpp.

331 {
332  Q_D(const QProxyModel);
333  d->model->fetchMore(parent);
334 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ flags()

Qt::ItemFlags QProxyModel::flags ( const QModelIndex index) const
virtual

Returns the item flags for the given index.

Reimplemented from QAbstractItemModel.

Definition at line 339 of file qproxymodel.cpp.

Referenced by QModelIndex::internalId().

340 {
341  Q_D(const QProxyModel);
342  return d->model->flags(setSourceModel(index));
343 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex setSourceModel(const QModelIndex &proxy_index) const
Change the model pointer in the given proxy_index to point to the source model.
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ hasChildren()

bool QProxyModel::hasChildren ( const QModelIndex parent = QModelIndex()) const
virtual

Returns true if the item corresponding to the parent index has child items; otherwise returns false.

See also
QAbstractItemModel::hasChildren()

Reimplemented from QAbstractItemModel.

Definition at line 186 of file qproxymodel.cpp.

187 {
188  Q_D(const QProxyModel);
189  return d->model->hasChildren(setSourceModel(parent));
190 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex setSourceModel(const QModelIndex &proxy_index) const
Change the model pointer in the given proxy_index to point to the source model.
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ headerData()

QVariant QProxyModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Returns the data stored in the section of the header with specified orientation under the given role.

Reimplemented from QAbstractItemModel.

Definition at line 221 of file qproxymodel.cpp.

222 {
223  Q_D(const QProxyModel);
224  return d->model->headerData(section, orientation, role);
225 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ index()

QModelIndex QProxyModel::index ( int  row,
int  column,
const QModelIndex parent = QModelIndex() 
) const
virtual

Returns the model index with the given row, column, and parent.

See also
QAbstractItemModel::index()

Implements QAbstractItemModel.

Definition at line 142 of file qproxymodel.cpp.

143 {
144  Q_D(const QProxyModel);
145  return setProxyModel(d->model->index(row, column, setSourceModel(parent)));
146 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex setSourceModel(const QModelIndex &proxy_index) const
Change the model pointer in the given proxy_index to point to the source model.
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57
QModelIndex setProxyModel(const QModelIndex &source_index) const
Change the model pointer in the given source_index to point to the proxy model.

◆ insertColumns()

bool QProxyModel::insertColumns ( int  column,
int  count,
const QModelIndex parent = QModelIndex() 
)
virtual

Inserts count columns into the model, creating new items as children of the given parent.

The new columns are inserted before the column specified. If the parent item has no children, a single row is created to contain the required number of columns.

Returns true if the columns were successfully inserted; otherwise returns false.

See also
QAbstractItemModel::insertColumns()

Reimplemented from QAbstractItemModel.

Definition at line 318 of file qproxymodel.cpp.

319 {
320  Q_D(const QProxyModel);
321  return d->model->insertColumns(column, count, setSourceModel(parent));
322 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex setSourceModel(const QModelIndex &proxy_index) const
Change the model pointer in the given proxy_index to point to the source model.
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ insertRows()

bool QProxyModel::insertRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
virtual

Inserts count rows into the model, creating new items as children of the given parent.

The new rows are inserted before the row specified. If the parent item has no children, a single column is created to contain the required number of rows.

Returns true if the rows were successfully inserted; otherwise returns false.

See also
QAbstractItemModel::insertRows()

Reimplemented from QAbstractItemModel.

Definition at line 301 of file qproxymodel.cpp.

302 {
303  Q_D(const QProxyModel);
304  return d->model->insertRows(row, count, setSourceModel(parent));
305 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex setSourceModel(const QModelIndex &proxy_index) const
Change the model pointer in the given proxy_index to point to the source model.
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ match()

QModelIndexList QProxyModel::match ( const QModelIndex start,
int  role,
const QVariant value,
int  hits = 1,
Qt::MatchFlags  flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap) 
) const
virtual

Returns a list of model indexes that each contain the given value for the role specified.

The search begins at the start index and is performed according to the specified flags. The search continues until the number of matching data items equals hits, the last row is reached, or the search reaches start again, depending on whether MatchWrap is specified in flags.

See also
QAbstractItemModel::match()

Reimplemented from QAbstractItemModel.

Definition at line 367 of file qproxymodel.cpp.

370 {
371  Q_D(const QProxyModel);
372  return d->model->match(start, role, value, hits, flags);
373 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57
Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.

◆ mimeData()

QMimeData * QProxyModel::mimeData ( const QModelIndexList indexes) const
virtual

Returns MIME data for the specified indexes in the model.

Reimplemented from QAbstractItemModel.

Definition at line 252 of file qproxymodel.cpp.

253 {
254  Q_D(const QProxyModel);
255  QModelIndexList lst;
256  for (int i = 0; i < indexes.count(); ++i)
257  lst.append(setSourceModel(indexes.at(i)));
258  return d->model->mimeData(lst);
259 }
double d
Definition: qnumeric_p.h:62
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex setSourceModel(const QModelIndex &proxy_index) const
Change the model pointer in the given proxy_index to point to the source model.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468

◆ mimeTypes()

QStringList QProxyModel::mimeTypes ( ) const
virtual

Returns a list of MIME types that are supported by the model.

Reimplemented from QAbstractItemModel.

Definition at line 243 of file qproxymodel.cpp.

244 {
245  Q_D(const QProxyModel);
246  return d->model->mimeTypes();
247 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ model()

QAbstractItemModel * QProxyModel::model ( ) const

Returns the model that contains the data that is available through the proxy model.

Definition at line 131 of file qproxymodel.cpp.

Referenced by QModelIndex::operator<(), and setModel().

132 {
133  Q_D(const QProxyModel);
134  return d->model;
135 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ parent()

QObject * QProxyModel::parent ( const QModelIndex child) const
virtual

Returns the model index that corresponds to the parent of the given child index.

Warning
This function is not part of the public interface.

Implements QAbstractItemModel.

Definition at line 152 of file qproxymodel.cpp.

153 {
154  Q_D(const QProxyModel);
155  return setProxyModel(d->model->parent(setSourceModel(child)));
156 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex setSourceModel(const QModelIndex &proxy_index) const
Change the model pointer in the given proxy_index to point to the source model.
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57
QModelIndex setProxyModel(const QModelIndex &source_index) const
Change the model pointer in the given source_index to point to the proxy model.

◆ revert()

void QProxyModel::revert ( )
virtual

Lets the model know that it should discard cached information.

This function is typically used for row editing.

See also
submit()

Reimplemented from QAbstractItemModel.

Definition at line 394 of file qproxymodel.cpp.

395 {
396  Q_D(QProxyModel);
397  d->model->revert();
398 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ rowCount()

int QProxyModel::rowCount ( const QModelIndex parent = QModelIndex()) const
virtual

Returns the number of rows for the given parent.

See also
QAbstractItemModel::rowCount()

Implements QAbstractItemModel.

Definition at line 163 of file qproxymodel.cpp.

164 {
165  Q_D(const QProxyModel);
166  return d->model->rowCount(setSourceModel(parent));
167 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex setSourceModel(const QModelIndex &proxy_index) const
Change the model pointer in the given proxy_index to point to the source model.
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ setData()

bool QProxyModel::setData ( const QModelIndex index,
const QVariant value,
int  role = Qt::EditRole 
)
virtual

Sets the role data for the item at index to value.

Returns true if successful; otherwise returns false.

The base class implementation returns false. This function and data() must be reimplemented for editable models.

See also
data() itemData() QAbstractItemModel::setData()

Reimplemented from QAbstractItemModel.

Definition at line 211 of file qproxymodel.cpp.

212 {
213  Q_D(const QProxyModel);
214  return d->model->setData(setSourceModel(index), value, role);
215 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex setSourceModel(const QModelIndex &proxy_index) const
Change the model pointer in the given proxy_index to point to the source model.
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ setHeaderData()

bool QProxyModel::setHeaderData ( int  section,
Qt::Orientation  orientation,
const QVariant value,
int  role = Qt::EditRole 
)
virtual

Sets the role data in the section of the header with the specified orientation to the value given.

See also
QAbstractItemModel::setHeaderData()

Reimplemented from QAbstractItemModel.

Definition at line 233 of file qproxymodel.cpp.

235 {
236  Q_D(const QProxyModel);
237  return d->model->setHeaderData(section, orientation, value, role);
238 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ setModel()

void QProxyModel::setModel ( QAbstractItemModel model)
virtual

Sets the given model to be processed by the proxy model.

Definition at line 114 of file qproxymodel.cpp.

Referenced by QProxyModel().

115 {
116  Q_D(QProxyModel);
117  if (d->model && d->model != &d->empty)
118  disconnectFromModel(d->model);
119  if (model) {
120  d->model = model;
121  connectToModel(model);
122  } else {
123  d->model = &d->empty;
124  }
125 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57
QAbstractItemModel * model() const
Returns the model that contains the data that is available through the proxy model.
void disconnectFromModel(const QAbstractItemModel *model) const
Disconnect from all the signals emitted by the given model.
void connectToModel(const QAbstractItemModel *model) const
Connect to all the signals emitted by given model.

◆ setProxyModel()

QModelIndex QProxyModel::setProxyModel ( const QModelIndex source_index) const
protected

Change the model pointer in the given source_index to point to the proxy model.

Warning
This function is not part of the public interface.

Definition at line 407 of file qproxymodel.cpp.

Referenced by index(), and parent().

408 {
409  QModelIndex proxy_index = source_index;
410  if (proxy_index.isValid())
411  proxy_index.m = this;
412  return proxy_index;
413 }
const QAbstractItemModel * m
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QModelIndex class is used to locate data in a data model.

◆ setSourceModel()

QModelIndex QProxyModel::setSourceModel ( const QModelIndex proxy_index) const
protected

Change the model pointer in the given proxy_index to point to the source model.

Warning
This function is not part of the public interface.

Definition at line 422 of file qproxymodel.cpp.

Referenced by columnCount(), data(), dropMimeData(), flags(), hasChildren(), index(), insertColumns(), insertRows(), mimeData(), parent(), rowCount(), setData(), and span().

423 {
424  Q_D(const QProxyModel);
425  QModelIndex source_index = proxy_index;
426  source_index.m = d->model;
427  return source_index;
428 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57
const QAbstractItemModel * m
The QModelIndex class is used to locate data in a data model.

◆ sort()

void QProxyModel::sort ( int  column,
Qt::SortOrder  order = Qt::AscendingOrder 
)
virtual

Sorts the child items in the specified column according to the sort order defined by order.

See also
QAbstractItemModel::sort()

Reimplemented from QAbstractItemModel.

Definition at line 351 of file qproxymodel.cpp.

352 {
353  Q_D(QProxyModel);
354  d->model->sort(column, order);
355 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ span()

QSize QProxyModel::span ( const QModelIndex index) const
virtual

Returns the size of the item that corresponds to the specified index.

Reimplemented from QAbstractItemModel.

Definition at line 378 of file qproxymodel.cpp.

379 {
380  Q_D(const QProxyModel);
381  return d->model->span(setSourceModel(index));
382 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex setSourceModel(const QModelIndex &proxy_index) const
Change the model pointer in the given proxy_index to point to the source model.
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ submit()

bool QProxyModel::submit ( )
virtual

Lets the model know that it should submit cached information to permanent storage.

This function is typically used for row editing.

Returns true if there is no error; otherwise returns false.

See also
revert()

Reimplemented from QAbstractItemModel.

Definition at line 386 of file qproxymodel.cpp.

387 {
388  Q_D(QProxyModel);
389  return d->model->submit();
390 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

◆ supportedDropActions()

Qt::DropActions QProxyModel::supportedDropActions ( ) const
virtual

Returns the drop actions that are supported by the model; this is a combination of the individual actions defined in Qt::DropActions .

The selection of drop actions provided by the model will influence the behavior of the component that started the drag and drop operation.

See also
Drag and Drop

Reimplemented from QAbstractItemModel.

Definition at line 285 of file qproxymodel.cpp.

286 {
287  Q_D(const QProxyModel);
288  return d->model->supportedDropActions();
289 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QProxyModel class provides support for processing data passed between another model and a view...
Definition: qproxymodel.h:57

The documentation for this class was generated from the following files: