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

The QAbstractListModel class provides an abstract model that can be subclassed to create one-dimensional list models. More...

#include <qabstractitemmodel.h>

Inheritance diagram for QAbstractListModel:
QAbstractItemModel QObject ControlList QDeclarativeFolderListModel QListModel QStringListModel

Public Functions

bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 Reimplemented Function More...
 
QModelIndex index (int row, int column=0, const QModelIndex &parent=QModelIndex()) const
 Returns the index of the data in row and column with parent. More...
 
 QAbstractListModel (QObject *parent=0)
 Constructs an abstract list model with the given parent. More...
 
 ~QAbstractListModel ()
 Destroys the abstract list 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...
 
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const =0
 Returns the data stored under the given role for the item referred to by the index. More...
 
virtual void fetchMore (const QModelIndex &parent)
 Fetches any available data for the items with the parent specified by the parent index. More...
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const
 Returns the item flags for the given index. 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...
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 Returns the data for the given role and section in the header with the specified orientation. 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...
 
virtual bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, inserts count new columns into the model before the given column. 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 bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, inserts count rows into the model before the given row. 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...
 
virtual 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 indexes for the items in the column of the start index where data stored under the given role matches the specified value. More...
 
virtual QMimeDatamimeData (const QModelIndexList &indexes) const
 Returns an object that contains serialized items of data corresponding to the list of indexes specified. More...
 
virtual QStringList mimeTypes () const
 Returns a list of MIME types that can be used to describe a list of model indexes. 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 int rowCount (const QModelIndex &parent=QModelIndex()) const =0
 Returns the number of rows under the given parent. More...
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 Sets the role data for the item at index to value. More...
 
virtual bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
 Sets the data for the given role and section in the header with the specified orientation to the value supplied. 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...
 
virtual void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
 Sorts the model by column in the given order. More...
 
virtual QSize span (const QModelIndex &index) const
 Returns the row and column span of the item represented by index. More...
 
Qt::DropActions supportedDragActions () const
 Returns the actions supported by the data in this model. More...
 
virtual Qt::DropActions supportedDropActions () const
 Returns the drop actions supported by 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

 QAbstractListModel (QAbstractItemModelPrivate &dd, QObject *parent)
 Constructs an abstract list model with dd and the given parent. 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...
 

Private Functions

int columnCount (const QModelIndex &parent) const
 Returns the number of columns in the list with the given parent. More...
 
bool hasChildren (const QModelIndex &parent) const
 Returns true if parent has any children; otherwise returns false. More...
 
QModelIndex parent (const QModelIndex &child) const
 Returns the parent of the model item with the given index. More...
 

Additional Inherited Members

- Public Slots inherited from QAbstractItemModel
virtual void revert ()
 Lets the model know that it should discard cached information. More...
 
virtual bool submit ()
 Lets the model know that it should submit cached information to permanent storage. More...
 
- 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 QAbstractListModel class provides an abstract model that can be subclassed to create one-dimensional list models.

QAbstractListModel provides a standard interface for models that represent their data as a simple non-hierarchical sequence of items. It is not used directly, but must be subclassed.

Since the model provides a more specialized interface than QAbstractItemModel, it is not suitable for use with tree views; you will need to subclass QAbstractItemModel if you want to provide a model for that purpose. If you need to use a number of list models to manage data, it may be more appropriate to subclass QAbstractTableModel class instead.

Simple models can be created by subclassing this class and implementing the minimum number of required functions. For example, we could implement a simple read-only QStringList-based model that provides a list of strings to a QListView widget. In such a case, we only need to implement the rowCount() function to return the number of items in the list, and the data() function to retrieve items from the list.

Since the model represents a one-dimensional structure, the rowCount() function returns the total number of items in the model. The columnCount() function is implemented for interoperability with all kinds of views, but by default informs views that the model contains only one column.

Subclassing

When subclassing QAbstractListModel, you must provide implementations of the rowCount() and data() functions. Well behaved models also provide a headerData() implementation.

For editable list models, you must also provide an implementation of setData(), implement the flags() function so that it returns a value containing Qt::ItemIsEditable.

Note that QAbstractListModel provides a default implementation of columnCount() that informs views that there is only a single column of items in this model.

Models that provide interfaces to resizable list-like data structures can provide implementations of insertRows() and removeRows(). When implementing these functions, it is important to call the appropriate functions so that all connected views are aware of any changes:

Note
Some general guidelines for subclassing models are available in the Model Subclassing Reference.
See also
{Model Classes}, {Model Subclassing Reference}, QAbstractItemView, QAbstractTableModel, {Item Views Puzzle Example}

Definition at line 365 of file qabstractitemmodel.h.

Constructors and Destructors

◆ QAbstractListModel() [1/2]

QAbstractListModel::QAbstractListModel ( QObject parent = 0)
explicit

Constructs an abstract list model with the given parent.

Definition at line 3448 of file qabstractitemmodel.cpp.

3449  : QAbstractItemModel(parent)
3450 {
3451 
3452 }
QAbstractItemModel(QObject *parent=0)
Constructs an abstract item model with the given parent.

◆ ~QAbstractListModel()

QAbstractListModel::~QAbstractListModel ( )

Destroys the abstract list model.

Definition at line 3473 of file qabstractitemmodel.cpp.

3474 {
3475 
3476 }

◆ QAbstractListModel() [2/2]

QAbstractListModel::QAbstractListModel ( QAbstractItemModelPrivate dd,
QObject parent 
)
protected

Constructs an abstract list model with dd and the given parent.

Warning
This function is not part of the public interface.

Definition at line 3463 of file qabstractitemmodel.cpp.

3464  : QAbstractItemModel(dd, parent)
3465 {
3466 
3467 }
QAbstractItemModel(QObject *parent=0)
Constructs an abstract item model with the given parent.

Functions

◆ columnCount()

int QAbstractListModel::columnCount ( const QModelIndex parent) const
privatevirtual

Returns the number of columns in the list with the given parent.

Warning
This function is not part of the public interface.
See also
rowCount()

Implements QAbstractItemModel.

Definition at line 3516 of file qabstractitemmodel.cpp.

3517 {
3518  return parent.isValid() ? 0 : 1;
3519 }
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ dropMimeData()

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

Reimplemented Function

Reimplemented from QAbstractItemModel.

Reimplemented in QListModel.

Definition at line 3590 of file qabstractitemmodel.cpp.

3592 {
3593  if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
3594  return false;
3595 
3597  if (types.isEmpty())
3598  return false;
3599  QString format = types.at(0);
3600  if (!data->hasFormat(format))
3601  return false;
3602 
3603  QByteArray encoded = data->data(format);
3605 
3606  // if the drop is on an item, replace the data in the items
3607  if (parent.isValid() && row == -1 && column == -1) {
3608  int top = INT_MAX;
3609  int left = INT_MAX;
3610  QVector<int> rows, columns;
3612 
3613  while (!stream.atEnd()) {
3614  int r, c;
3616  stream >> r >> c >> v;
3617  rows.append(r);
3618  columns.append(c);
3619  data.append(v);
3620  top = qMin(r, top);
3621  left = qMin(c, left);
3622  }
3623 
3624  for (int i = 0; i < data.size(); ++i) {
3625  int r = (rows.at(i) - top) + parent.row();
3626  if (columns.at(i) == left && hasIndex(r, 0))
3627  setItemData(index(r), data.at(i));
3628  }
3629 
3630  return true;
3631  }
3632 
3633  if (row == -1)
3634  row = rowCount(parent);
3635 
3636  // otherwise insert new rows for the data
3637  return decodeData(row, column, parent, stream);
3638 }
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
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...
virtual QStringList mimeTypes() const
Returns a list of MIME types that can be used to describe a list of model indexes.
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.
QByteArray data(const QString &mimetype) const
Returns the data stored in the object in the format described by the MIME type specified by mimeType...
Definition: qmimedata.cpp:524
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool decodeData(int row, int column, const QModelIndex &parent, QDataStream &stream)
QModelIndex index(int row, int column=0, const QModelIndex &parent=QModelIndex()) const
Returns the index of the data in row and column with parent.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
static FILE * stream
int row() const
Returns the row this model index refers to.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
virtual bool hasFormat(const QString &mimetype) const
Returns true if the object can return data for the MIME type specified by mimeType; otherwise returns...
Definition: qmimedata.cpp:563
static const struct @32 types[]
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
#define INT_MAX
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ hasChildren()

bool QAbstractListModel::hasChildren ( const QModelIndex parent) const
privatevirtual

Returns true if parent has any children; otherwise returns false.

Use rowCount() on the parent to find out the number of children.

See also
parent() index()

Reimplemented from QAbstractItemModel.

Definition at line 3521 of file qabstractitemmodel.cpp.

3522 {
3523  return parent.isValid() ? false : (rowCount() > 0);
3524 }
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ index()

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

Returns the index of the data in row and column with parent.

See also
parent()

Implements QAbstractItemModel.

Reimplemented in QListModel.

Definition at line 3489 of file qabstractitemmodel.cpp.

Referenced by ControlList::ControlList(), QAbstractTableModel::dropMimeData(), dropMimeData(), QDeclarativeFolderListModel::handleDataChanged(), ControlList::rowCount(), QDeclarativeFolderListModel::setFolder(), and QStringListModel::sort().

3490 {
3491  return hasIndex(row, column, parent) ? createIndex(row, column, 0) : QModelIndex();
3492 }
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. ...
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.
The QModelIndex class is used to locate data in a data model.

◆ parent()

QModelIndex QAbstractListModel::parent ( const QModelIndex child) const
privatevirtual

Returns the parent of the model item with the given index.

See also
index() hasChildren()

Implements QAbstractItemModel.

Definition at line 3500 of file qabstractitemmodel.cpp.

3501 {
3502  return QModelIndex();
3503 }
The QModelIndex class is used to locate data in a data model.

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