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

The QIdentityProxyModel class proxies its source model unmodified. More...

#include <qidentityproxymodel.h>

Inheritance diagram for QIdentityProxyModel:
QAbstractProxyModel QAbstractItemModel QObject

Public Functions

int columnCount (const QModelIndex &parent=QModelIndex()) const
 Reimplemented Function More...
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 Reimplemented Function More...
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Reimplemented Function More...
 
bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 Reimplemented Function More...
 
bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex())
 Reimplemented Function More...
 
QModelIndex mapFromSource (const QModelIndex &sourceIndex) const
 Reimplemented Function More...
 
QItemSelection mapSelectionFromSource (const QItemSelection &selection) const
 Reimplemented Function More...
 
QItemSelection mapSelectionToSource (const QItemSelection &selection) const
 Reimplemented Function More...
 
QModelIndex mapToSource (const QModelIndex &proxyIndex) const
 Reimplemented Function More...
 
QModelIndexList match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
 Reimplemented Function More...
 
QModelIndex parent (const QModelIndex &child) const
 Reimplemented Function More...
 
 QIdentityProxyModel (QObject *parent=0)
 Constructs an identity model with the given parent. More...
 
bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 Reimplemented Function More...
 
bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
 Reimplemented Function More...
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 Reimplemented Function More...
 
void setSourceModel (QAbstractItemModel *sourceModel)
 Reimplemented Function More...
 
 ~QIdentityProxyModel ()
 Destroys this identity model. More...
 
- Public Functions inherited from QAbstractProxyModel
QModelIndex buddy (const QModelIndex &index) const
 Reimplemented Function More...
 
bool canFetchMore (const QModelIndex &parent) const
 Reimplemented Function More...
 
QVariant data (const QModelIndex &proxyIndex, int role=Qt::DisplayRole) const
 Reimplemented Function More...
 
void fetchMore (const QModelIndex &parent)
 Reimplemented Function More...
 
Qt::ItemFlags flags (const QModelIndex &index) const
 Reimplemented Function More...
 
bool hasChildren (const QModelIndex &parent=QModelIndex()) const
 Reimplemented Function More...
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const
 Reimplemented Function More...
 
QMap< int, QVariantitemData (const QModelIndex &index) const
 Reimplemented Function More...
 
QMimeDatamimeData (const QModelIndexList &indexes) const
 Reimplemented Function More...
 
QStringList mimeTypes () const
 Reimplemented Function More...
 
 QAbstractProxyModel (QObject *parent=0)
 Constructs a proxy model with the given parent. More...
 
void revert ()
 Reimplemented Function More...
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 Reimplemented Function More...
 
bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
 Reimplemented Function More...
 
bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles)
 Reimplemented Function More...
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
 Reimplemented Function More...
 
QAbstractItemModelsourceModel () const
 Returns the model that contains the data that is available through the proxy model. More...
 
QSize span (const QModelIndex &index) const
 Reimplemented Function More...
 
bool submit ()
 Reimplemented Function More...
 
Qt::DropActions supportedDropActions () const
 Reimplemented Function More...
 
 ~QAbstractProxyModel ()
 Destroys the proxy model. More...
 
- Public Functions inherited from QAbstractItemModel
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...
 
 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...
 
bool removeRow (int row, const QModelIndex &parent=QModelIndex())
 Removes the given row from the child items of the parent specified. More...
 
const QHash< int, QByteArray > & roleNames () const
 Returns the model's role names. 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

 QIdentityProxyModel (QIdentityProxyModelPrivate &dd, QObject *parent)
 
- Protected Functions inherited from QAbstractProxyModel
 QAbstractProxyModel (QAbstractProxyModelPrivate &, QObject *parent)
 
- 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 QIdentityProxyModel class proxies its source model unmodified.

Since
4.8

QIdentityProxyModel can be used to forward the structure of a source model exactly, with no sorting, filtering or other transformation. This is similar in concept to an identity matrix where A.I = A.

Because it does no sorting or filtering, this class is most suitable to proxy models which transform the data() of the source model. For example, a proxy model could be created to define the font used, or the background colour, or the tooltip etc. This removes the need to implement all data handling in the same class that creates the structure of the model, and can also be used to create re-usable components.

This also provides a way to change the data in the case where a source model is supplied by a third party which can not be modified.

class DateFormatProxyModel : public QIdentityProxyModel
{
// ...
void setDateFormatString(const QString &formatString)
{
m_formatString = formatString;
}
QVariant data(const QModelIndex &index, int role)
{
if (role != Qt::DisplayRole)
return QIdentityProxyModel::data(index, role);
const QDateTime dateTime = sourceModel()->data(SourceClass::DateRole).toDateTime();
return dateTime.toString(m_formatString);
}
private:
QString m_formatString;
};
See also
QAbstractProxyModel, {Model/View Programming}, QAbstractItemModel

Definition at line 58 of file qidentityproxymodel.h.

Constructors and Destructors

◆ QIdentityProxyModel() [1/2]

QIdentityProxyModel::QIdentityProxyModel ( QObject parent = 0)
explicit

Constructs an identity model with the given parent.

Definition at line 120 of file qidentityproxymodel.cpp.

122 {
123 
124 }
QAbstractProxyModel(QObject *parent=0)
Constructs a proxy model with the given parent.

◆ ~QIdentityProxyModel()

QIdentityProxyModel::~QIdentityProxyModel ( )

Destroys this identity model.

Definition at line 137 of file qidentityproxymodel.cpp.

138 {
139 }

◆ QIdentityProxyModel() [2/2]

QIdentityProxyModel::QIdentityProxyModel ( QIdentityProxyModelPrivate dd,
QObject parent 
)
protected
Warning
This function is not part of the public interface.

Definition at line 128 of file qidentityproxymodel.cpp.

129  : QAbstractProxyModel(dd, parent)
130 {
131 
132 }
QAbstractProxyModel(QObject *parent=0)
Constructs a proxy model with the given parent.

Functions

◆ columnCount()

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

Reimplemented Function

Implements QAbstractItemModel.

Definition at line 144 of file qidentityproxymodel.cpp.

Referenced by QAbstractItemModel::sibling().

145 {
146  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
147  Q_D(const QIdentityProxyModel);
148  return d->model->columnCount(mapToSource(parent));
149 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplemented Function
The QIdentityProxyModel class proxies its source model unmodified.

◆ dropMimeData()

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

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 154 of file qidentityproxymodel.cpp.

Referenced by QAbstractItemModel::sibling().

155 {
156  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
158  return d->model->dropMimeData(data, action, row, column, mapToSource(parent));
159 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplemented Function
The QIdentityProxyModel class proxies its source model unmodified.

◆ index()

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

Reimplemented Function

Implements QAbstractItemModel.

Definition at line 164 of file qidentityproxymodel.cpp.

165 {
166  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
167  Q_D(const QIdentityProxyModel);
168  if (!hasIndex(row, column, parent))
169  return QModelIndex();
170  const QModelIndex sourceParent = mapToSource(parent);
171  const QModelIndex sourceIndex = d->model->index(row, column, sourceParent);
172  Q_ASSERT(sourceIndex.isValid());
173  return mapFromSource(sourceIndex);
174 }
double d
Definition: qnumeric_p.h:62
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.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplemented Function
The QModelIndex class is used to locate data in a data model.
The QIdentityProxyModel class proxies its source model unmodified.
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
Reimplemented Function

◆ insertColumns()

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

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 179 of file qidentityproxymodel.cpp.

Referenced by QAbstractItemModel::insertColumn(), and QAbstractItemModel::sibling().

180 {
181  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
183  return d->model->insertColumns(column, count, mapToSource(parent));
184 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplemented Function
The QIdentityProxyModel class proxies its source model unmodified.

◆ insertRows()

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

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 189 of file qidentityproxymodel.cpp.

Referenced by QAbstractItemModel::insertRow(), and QAbstractItemModel::sibling().

190 {
191  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
193  return d->model->insertRows(row, count, mapToSource(parent));
194 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplemented Function
The QIdentityProxyModel class proxies its source model unmodified.

◆ mapFromSource()

QModelIndex QIdentityProxyModel::mapFromSource ( const QModelIndex sourceIndex) const
virtual

Reimplemented Function

Implements QAbstractProxyModel.

Definition at line 199 of file qidentityproxymodel.cpp.

Referenced by index(), mapSelectionFromSource(), match(), and parent().

200 {
201  Q_D(const QIdentityProxyModel);
202  if (!d->model || !sourceIndex.isValid())
203  return QModelIndex();
204 
205  Q_ASSERT(sourceIndex.model() == d->model);
206  return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
207 }
double d
Definition: qnumeric_p.h:62
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
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. ...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
int row() const
Returns the row this model index refers to.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
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.
The QIdentityProxyModel class proxies its source model unmodified.
int column() const
Returns the column this model index refers to.

◆ mapSelectionFromSource()

QItemSelection QIdentityProxyModel::mapSelectionFromSource ( const QItemSelection selection) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 212 of file qidentityproxymodel.cpp.

213 {
214  Q_D(const QIdentityProxyModel);
215  QItemSelection proxySelection;
216 
217  if (!d->model)
218  return proxySelection;
219 
221  const QItemSelection::const_iterator end = selection.constEnd();
222  for ( ; it != end; ++it) {
223  Q_ASSERT(it->model() == d->model);
224  const QItemSelectionRange range(mapFromSource(it->topLeft()), mapFromSource(it->bottomRight()));
225  proxySelection.append(range);
226  }
227 
228  return proxySelection;
229 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
The QItemSelectionRange class manages information about a range of selected items in a model...
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
friend class const_iterator
Definition: qlist.h:264
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QItemSelection class manages information about selected items in a model.
The QIdentityProxyModel class proxies its source model unmodified.
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
Reimplemented Function
static const KeyPair *const end
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ mapSelectionToSource()

QItemSelection QIdentityProxyModel::mapSelectionToSource ( const QItemSelection selection) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 234 of file qidentityproxymodel.cpp.

235 {
236  Q_D(const QIdentityProxyModel);
237  QItemSelection sourceSelection;
238 
239  if (!d->model)
240  return sourceSelection;
241 
243  const QItemSelection::const_iterator end = selection.constEnd();
244  for ( ; it != end; ++it) {
245  Q_ASSERT(it->model() == this);
246  const QItemSelectionRange range(mapToSource(it->topLeft()), mapToSource(it->bottomRight()));
247  sourceSelection.append(range);
248  }
249 
250  return sourceSelection;
251 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
The QItemSelectionRange class manages information about a range of selected items in a model...
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
friend class const_iterator
Definition: qlist.h:264
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplemented Function
The QItemSelection class manages information about selected items in a model.
The QIdentityProxyModel class proxies its source model unmodified.
static const KeyPair *const end
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ mapToSource()

QModelIndex QIdentityProxyModel::mapToSource ( const QModelIndex proxyIndex) const
virtual

Reimplemented Function

Implements QAbstractProxyModel.

Definition at line 256 of file qidentityproxymodel.cpp.

Referenced by columnCount(), dropMimeData(), index(), insertColumns(), insertRows(), mapSelectionToSource(), match(), parent(), removeColumns(), removeRows(), and rowCount().

257 {
258  Q_D(const QIdentityProxyModel);
259  if (!d->model || !proxyIndex.isValid())
260  return QModelIndex();
261  Q_ASSERT(proxyIndex.model() == this);
262  return d->model->createIndex(proxyIndex.row(), proxyIndex.column(), proxyIndex.internalPointer());
263 }
double d
Definition: qnumeric_p.h:62
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
int row() const
Returns the row this model index refers to.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
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.
The QIdentityProxyModel class proxies its source model unmodified.
int column() const
Returns the column this model index refers to.

◆ match()

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

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 268 of file qidentityproxymodel.cpp.

269 {
270  Q_D(const QIdentityProxyModel);
271  Q_ASSERT(start.isValid() ? start.model() == this : true);
272  if (!d->model)
273  return QModelIndexList();
274 
275  const QModelIndexList sourceList = d->model->match(mapToSource(start), role, value, hits, flags);
277  const QModelIndexList::const_iterator end = sourceList.constEnd();
278  QModelIndexList proxyList;
279  for ( ; it != end; ++it)
280  proxyList.append(mapFromSource(*it));
281  return proxyList;
282 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
friend class const_iterator
Definition: qlist.h:264
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplemented Function
QList< QModelIndex > QModelIndexList
The QIdentityProxyModel class proxies its source model unmodified.
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
Reimplemented Function
Qt::ItemFlags flags(const QModelIndex &index) const
Reimplemented Function
static const KeyPair *const end
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ parent()

QModelIndex QIdentityProxyModel::parent ( const QModelIndex child) const
virtual

Reimplemented Function

Implements QAbstractItemModel.

Definition at line 287 of file qidentityproxymodel.cpp.

288 {
289  Q_ASSERT(child.isValid() ? child.model() == this : true);
290  const QModelIndex sourceIndex = mapToSource(child);
291  const QModelIndex sourceParent = sourceIndex.parent();
292  return mapFromSource(sourceParent);
293 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplemented Function
The QModelIndex class is used to locate data in a data model.
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
Reimplemented Function

◆ removeColumns()

bool QIdentityProxyModel::removeColumns ( int  column,
int  count,
const QModelIndex parent = QModelIndex() 
)
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 298 of file qidentityproxymodel.cpp.

Referenced by QAbstractItemModel::removeColumn(), and QAbstractItemModel::sibling().

299 {
300  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
302  return d->model->removeColumns(column, count, mapToSource(parent));
303 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplemented Function
The QIdentityProxyModel class proxies its source model unmodified.

◆ removeRows()

bool QIdentityProxyModel::removeRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 308 of file qidentityproxymodel.cpp.

Referenced by QAbstractItemModel::removeRow(), and QAbstractItemModel::sibling().

309 {
310  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
312  return d->model->removeRows(row, count, mapToSource(parent));
313 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplemented Function
The QIdentityProxyModel class proxies its source model unmodified.

◆ rowCount()

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

Reimplemented Function

Implements QAbstractItemModel.

Definition at line 318 of file qidentityproxymodel.cpp.

Referenced by QAbstractItemModel::sibling().

319 {
320  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
321  Q_D(const QIdentityProxyModel);
322  return d->model->rowCount(mapToSource(parent));
323 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplemented Function
The QIdentityProxyModel class proxies its source model unmodified.

◆ setSourceModel()

void QIdentityProxyModel::setSourceModel ( QAbstractItemModel sourceModel)
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 328 of file qidentityproxymodel.cpp.

329 {
330  beginResetModel();
331 
332  if (sourceModel()) {
334  this, SLOT(_q_sourceRowsAboutToBeInserted(const QModelIndex &, int, int)));
335  disconnect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
336  this, SLOT(_q_sourceRowsInserted(const QModelIndex &, int, int)));
338  this, SLOT(_q_sourceRowsAboutToBeRemoved(const QModelIndex &, int, int)));
339  disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
340  this, SLOT(_q_sourceRowsRemoved(const QModelIndex &, int, int)));
341  disconnect(sourceModel(), SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
342  this, SLOT(_q_sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
343  disconnect(sourceModel(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
344  this, SLOT(_q_sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
346  this, SLOT(_q_sourceColumnsAboutToBeInserted(const QModelIndex &, int, int)));
348  this, SLOT(_q_sourceColumnsInserted(const QModelIndex &, int, int)));
350  this, SLOT(_q_sourceColumnsAboutToBeRemoved(const QModelIndex &, int, int)));
351  disconnect(sourceModel(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)),
352  this, SLOT(_q_sourceColumnsRemoved(const QModelIndex &, int, int)));
353  disconnect(sourceModel(), SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
354  this, SLOT(_q_sourceColumnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
355  disconnect(sourceModel(), SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
356  this, SLOT(_q_sourceColumnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
358  this, SLOT(_q_sourceModelAboutToBeReset()));
360  this, SLOT(_q_sourceModelReset()));
362  this, SLOT(_q_sourceDataChanged(const QModelIndex &, const QModelIndex &)));
364  this, SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int)));
366  this, SLOT(_q_sourceLayoutAboutToBeChanged()));
368  this, SLOT(_q_sourceLayoutChanged()));
369  }
370 
371  QAbstractProxyModel::setSourceModel(newSourceModel);
372 
373  if (sourceModel()) {
375  SLOT(_q_sourceRowsAboutToBeInserted(const QModelIndex &, int, int)));
376  connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
377  SLOT(_q_sourceRowsInserted(const QModelIndex &, int, int)));
379  SLOT(_q_sourceRowsAboutToBeRemoved(const QModelIndex &, int, int)));
380  connect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
381  SLOT(_q_sourceRowsRemoved(const QModelIndex &, int, int)));
382  connect(sourceModel(), SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
383  SLOT(_q_sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
384  connect(sourceModel(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
385  SLOT(_q_sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
387  SLOT(_q_sourceColumnsAboutToBeInserted(const QModelIndex &, int, int)));
388  connect(sourceModel(), SIGNAL(columnsInserted(const QModelIndex &, int, int)),
389  SLOT(_q_sourceColumnsInserted(const QModelIndex &, int, int)));
391  SLOT(_q_sourceColumnsAboutToBeRemoved(const QModelIndex &, int, int)));
392  connect(sourceModel(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)),
393  SLOT(_q_sourceColumnsRemoved(const QModelIndex &, int, int)));
394  connect(sourceModel(), SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
395  SLOT(_q_sourceColumnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
396  connect(sourceModel(), SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
397  SLOT(_q_sourceColumnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
399  SLOT(_q_sourceModelAboutToBeReset()));
401  SLOT(_q_sourceModelReset()));
403  SLOT(_q_sourceDataChanged(const QModelIndex &, const QModelIndex &)));
405  SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int)));
407  SLOT(_q_sourceLayoutAboutToBeChanged()));
409  SLOT(_q_sourceLayoutChanged()));
410  }
411 
412  endResetModel();
413 }
virtual void setSourceModel(QAbstractItemModel *sourceModel)
Sets the given sourceModel to be processed by the proxy model.
#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.
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.
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.
void endResetModel()
Completes a model reset operation.
#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 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.
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
QAbstractItemModel * sourceModel() const
Returns the model that contains the data that is available through the proxy model.
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 modelAboutToBeReset()
This signal is emitted when reset() is called, before the model&#39;s internal state (e.
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 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.
void columnsRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted after columns have been removed from the model.
void beginResetModel()
Begins a model reset operation.

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