Qt 4.8
Public Functions | Static Public Functions | Properties | List of all members
QListModel Class Reference

#include <qlistwidget_p.h>

Inheritance diagram for QListModel:
QAbstractListModel QAbstractItemModel QObject

Public Functions

QListWidgetItemat (int row) const
 
void clear ()
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 Returns the data stored under the given role for the item referred to by the index. More...
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 Reimplemented Function More...
 
void ensureSorted (int column, Qt::SortOrder order, int start, int end)
 
Qt::ItemFlags flags (const QModelIndex &index) const
 Returns the item flags for the given index. More...
 
QModelIndex index (QListWidgetItem *item) const
 
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...
 
void insert (int row, QListWidgetItem *item)
 
void insert (int row, const QStringList &items)
 
bool insertRows (int row, int count=1, const QModelIndex &parent=QModelIndex())
 On models that support this, inserts count rows into the model before the given row. More...
 
QMimeDatainternalMimeData () const
 
void itemChanged (QListWidgetItem *item)
 
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...
 
QMimeDatamimeData (const QModelIndexList &indexes) const
 Returns an object that contains serialized items of data corresponding to the list of indexes specified. More...
 
QStringList mimeTypes () const
 Returns a list of MIME types that can be used to describe a list of model indexes. More...
 
void move (int srcRow, int dstRow)
 
 QListModel (QListWidget *parent)
 
void remove (QListWidgetItem *item)
 
bool removeRows (int row, int count=1, const QModelIndex &parent=QModelIndex())
 On models that support this, removes count rows starting with the given row under parent parent from the model. More...
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 Returns the number of rows under the given parent. More...
 
bool setData (const QModelIndex &index, const QVariant &value, int role)
 Sets the role data for the item at index to value. More...
 
void sort (int column, Qt::SortOrder order)
 Sorts the model by column in the given order. More...
 
Qt::DropActions supportedDropActions () const
 Returns the drop actions supported by this model. More...
 
QListWidgetItemtake (int row)
 
 ~QListModel ()
 
- Public Functions inherited from QAbstractListModel
 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 void fetchMore (const QModelIndex &parent)
 Fetches any available data for the items with the parent specified by the parent 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 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...
 
 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...
 
const QHash< int, QByteArray > & roleNames () const
 Returns the model's role names. 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 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 ~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...
 

Static Public Functions

static bool itemGreaterThan (const QPair< QListWidgetItem *, int > &left, const QPair< QListWidgetItem *, int > &right)
 
static bool itemLessThan (const QPair< QListWidgetItem *, int > &left, const QPair< QListWidgetItem *, int > &right)
 
static QList< QListWidgetItem * >::iterator sortedInsertionIterator (const QList< QListWidgetItem *>::iterator &begin, const QList< QListWidgetItem *>::iterator &end, Qt::SortOrder order, QListWidgetItem *item)
 
- 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)
 

Properties

QModelIndexList cachedIndexes
 
QList< QListWidgetItem * > items
 

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 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 Functions inherited from QAbstractListModel
 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...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 80 of file qlistwidget_p.h.

Constructors and Destructors

◆ QListModel()

QListModel::QListModel ( QListWidget parent)

Definition at line 66 of file qlistwidget.cpp.

67  : QAbstractListModel(parent)
68 {
69 }
QAbstractListModel(QObject *parent=0)
Constructs an abstract list model with the given parent.

◆ ~QListModel()

QListModel::~QListModel ( )

Definition at line 71 of file qlistwidget.cpp.

72 {
73  clear();
74 }
void clear()
Definition: qlistwidget.cpp:76

Functions

◆ at()

QListWidgetItem * QListModel::at ( int  row) const

Definition at line 89 of file qlistwidget.cpp.

Referenced by mimeData().

90 {
91  return items.value(row);
92 }
QList< QListWidgetItem * > items
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661

◆ clear()

void QListModel::clear ( )

Definition at line 76 of file qlistwidget.cpp.

Referenced by ~QListModel().

77 {
78  for (int i = 0; i < items.count(); ++i) {
79  if (items.at(i)) {
80  items.at(i)->d->theid = -1;
81  items.at(i)->view = 0;
82  delete items.at(i);
83  }
84  }
85  items.clear();
86  reset();
87 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QListWidgetItem * > items
void clear()
Removes all items from the list.
Definition: qlist.h:764
QListWidget * view
Definition: qlistwidget.h:168
void reset()
Resets the model to its original state in any attached views.

◆ data()

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

Returns the data stored under the given role for the item referred to by the index.

Note
If you do not have a value to return, return an invalid QVariant instead of returning 0.
See also
Qt::ItemDataRole, setData(), headerData()

Implements QAbstractItemModel.

Definition at line 217 of file qlistwidget.cpp.

218 {
219  if (!index.isValid() || index.row() >= items.count())
220  return QVariant();
221  return items.at(index.row())->data(role);
222 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
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
QList< QListWidgetItem * > items
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Returns the data stored under the given role for the item referred to by the index.

◆ dropMimeData()

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

Reimplemented Function

Reimplemented from QAbstractListModel.

Definition at line 438 of file qlistwidget.cpp.

Referenced by QListWidget::addItems().

440 {
441  Q_UNUSED(column);
443  if (index.isValid())
444  row = index.row();
445  else if (row == -1)
446  row = items.count();
447 
448  return view->dropMimeData(row, data, action);
449 }
The QListWidget class provides an item-based list widget.
Definition: qlistwidget.h:202
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
T * qobject_cast(QObject *object)
Definition: qobject.h:375
virtual bool dropMimeData(int index, const QMimeData *data, Qt::DropAction action)
Handles data supplied by an external drag and drop operation that ended with the given action in the ...
int row() const
Returns the row this model index refers to.
QList< QListWidgetItem * > items
QModelIndex index(QListWidgetItem *item) const
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ ensureSorted()

void QListModel::ensureSorted ( int  column,
Qt::SortOrder  order,
int  start,
int  end 
)

This function assumes that all items in the model except the items that are between (inclusive) start and end are sorted. With these assumptions, this function can ensure that the model is sorted in a much more efficient way than doing a naive 'sort everything'. (provided that the range is relatively small compared to the total number of items)

Definition at line 325 of file qlistwidget.cpp.

326 {
327  if (column != 0)
328  return;
329 
330  int count = end - start + 1;
331  QVector < QPair<QListWidgetItem*,int> > sorting(count);
332  for (int i = 0; i < count; ++i) {
333  sorting[i].first = items.at(start + i);
334  sorting[i].second = start + i;
335  }
336 
338  qSort(sorting.begin(), sorting.end(), compare);
339 
340  QModelIndexList oldPersistentIndexes = persistentIndexList();
341  QModelIndexList newPersistentIndexes = oldPersistentIndexes;
344  bool changed = false;
345  for (int i = 0; i < count; ++i) {
346  int oldRow = sorting.at(i).second;
347  QListWidgetItem *item = tmp.takeAt(oldRow);
348  lit = sortedInsertionIterator(lit, tmp.end(), order, item);
349  int newRow = qMax(lit - tmp.begin(), 0);
350  lit = tmp.insert(lit, item);
351  if (newRow != oldRow) {
352  changed = true;
353  for (int j = i + 1; j < count; ++j) {
354  int otherRow = sorting.at(j).second;
355  if (oldRow < otherRow && newRow >= otherRow)
356  --sorting[j].second;
357  else if (oldRow > otherRow && newRow <= otherRow)
358  ++sorting[j].second;
359  }
360  for (int k = 0; k < newPersistentIndexes.count(); ++k) {
361  QModelIndex pi = newPersistentIndexes.at(k);
362  int oldPersistentRow = pi.row();
363  int newPersistentRow = oldPersistentRow;
364  if (oldPersistentRow == oldRow)
365  newPersistentRow = newRow;
366  else if (oldRow < oldPersistentRow && newRow >= oldPersistentRow)
367  newPersistentRow = oldPersistentRow - 1;
368  else if (oldRow > oldPersistentRow && newRow <= oldPersistentRow)
369  newPersistentRow = oldPersistentRow + 1;
370  if (newPersistentRow != oldPersistentRow)
371  newPersistentIndexes[k] = createIndex(newPersistentRow,
372  pi.column(), pi.internalPointer());
373  }
374  }
375  }
376 
377  if (changed) {
379  items = tmp;
380  changePersistentIndexList(oldPersistentIndexes, newPersistentIndexes);
382  }
383 }
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
QModelIndexList persistentIndexList() const
Returns the list of indexes stored as persistent indexes in the model.
static bool itemGreaterThan(const QPair< QListWidgetItem *, int > &left, const QPair< QListWidgetItem *, int > &right)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
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. ...
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to)
Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list t...
static bool compare(const QVariant::Private *a, const QVariant::Private *b)
Compares a to b.
Definition: qvariant.cpp:383
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
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
#define emit
Definition: qobjectdefs.h:76
QList< QListWidgetItem * > items
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
The QListWidgetItem class provides an item for use with the QListWidget item view class...
Definition: qlistwidget.h:63
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
Definition: qlist.h:181
static QList< QListWidgetItem * >::iterator sortedInsertionIterator(const QList< QListWidgetItem *>::iterator &begin, const QList< QListWidgetItem *>::iterator &end, Qt::SortOrder order, QListWidgetItem *item)
The QModelIndex class is used to locate data in a data model.
T takeAt(int i)
Removes the item at index position i and returns it.
Definition: qlist.h:484
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Appends a new row to the current test data.
Definition: qtestcase.cpp:2183
bool(* LessThan)(const QPair< QListWidgetItem *, int > &, const QPair< QListWidgetItem *, int > &)
Definition: qlistwidget.cpp:53
static const KeyPair *const end
int column() const
Returns the column this model index refers to.
static bool itemLessThan(const QPair< QListWidgetItem *, int > &left, const QPair< QListWidgetItem *, int > &right)

◆ flags()

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

Returns the item flags for the given index.

The base class implementation returns a combination of flags that enables the item (ItemIsEnabled) and allows it to be selected (ItemIsSelectable).

See also
Qt::ItemFlags

Reimplemented from QAbstractItemModel.

Definition at line 282 of file qlistwidget.cpp.

Referenced by QListWidget::addItems().

283 {
284  if (!index.isValid() || index.row() >= items.count() || index.model() != this)
285  return Qt::ItemIsDropEnabled; // we allow drops outside the items
286  return items.at(index.row())->flags();
287 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
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
QList< QListWidgetItem * > items
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.
Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.

◆ index() [1/2]

QModelIndex QListModel::index ( QListWidgetItem item) const

Definition at line 192 of file qlistwidget.cpp.

Referenced by itemChanged().

193 {
194  if (!item || !item->view || static_cast<const QListModel *>(item->view->model()) != this
195  || items.isEmpty())
196  return QModelIndex();
197  int row;
198  const int theid = item->d->theid;
199  if (theid >= 0 && theid < items.count() && items.at(theid) == item) {
200  row = theid;
201  } else { // we need to search for the item
202  row = items.lastIndexOf(item); // lastIndexOf is an optimization in favor of indexOf
203  if (row == -1) // not found
204  return QModelIndex();
205  item->d->theid = row;
206  }
207  return createIndex(row, 0, item);
208 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
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. ...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
int lastIndexOf(const T &t, int from=-1) const
Returns the index position of the last occurrence of value in the list, searching backward from index...
Definition: qlist.h:862
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QListWidgetItem * > items
The QModelIndex class is used to locate data in a data model.
QListWidget * view
Definition: qlistwidget.h:168
QAbstractItemModel * model() const
Returns the model that this view is presenting.

◆ index() [2/2]

QModelIndex QListModel::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()

Reimplemented from QAbstractListModel.

Definition at line 210 of file qlistwidget.cpp.

211 {
212  if (hasIndex(row, column, parent))
213  return createIndex(row, column, items.at(row));
214  return QModelIndex();
215 }
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.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QListWidgetItem * > items
The QModelIndex class is used to locate data in a data model.

◆ insert() [1/2]

void QListModel::insert ( int  row,
QListWidgetItem item 
)

Definition at line 107 of file qlistwidget.cpp.

Referenced by insert().

108 {
109  if (!item)
110  return;
111 
113  if (item->view && item->view->isSortingEnabled()) {
114  // sorted insertion
117  item->view->sortOrder(), item);
118  row = qMax(it - items.begin(), 0);
119  } else {
120  if (row < 0)
121  row = 0;
122  else if (row > items.count())
123  row = items.count();
124  }
125  beginInsertRows(QModelIndex(), row, row);
126  items.insert(row, item);
127  item->d->theid = row;
128  endInsertRows();
129 }
#define it(className, varName)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
bool isSortingEnabled() const
The QListWidget class provides an item-based list widget.
Definition: qlistwidget.h:202
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void endInsertRows()
Ends a row insertion operation.
T * qobject_cast(QObject *object)
Definition: qobject.h:375
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
QList< QListWidgetItem * > items
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
Definition: qlist.h:181
static QList< QListWidgetItem * >::iterator sortedInsertionIterator(const QList< QListWidgetItem *>::iterator &begin, const QList< QListWidgetItem *>::iterator &end, Qt::SortOrder order, QListWidgetItem *item)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.
QListWidget * view
Definition: qlistwidget.h:168
Qt::SortOrder sortOrder() const
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.

◆ insert() [2/2]

void QListModel::insert ( int  row,
const QStringList items 
)

Definition at line 131 of file qlistwidget.cpp.

132 {
133  const int count = labels.count();
134  if (count <= 0)
135  return;
137  if (view && view->isSortingEnabled()) {
138  // sorted insertion
139  for (int i = 0; i < count; ++i) {
140  QListWidgetItem *item = new QListWidgetItem(labels.at(i));
141  insert(row, item);
142  }
143  } else {
144  if (row < 0)
145  row = 0;
146  else if (row > items.count())
147  row = items.count();
148  beginInsertRows(QModelIndex(), row, row + count - 1);
149  for (int i = 0; i < count; ++i) {
150  QListWidgetItem *item = new QListWidgetItem(labels.at(i));
151  item->d->theid = row;
153  items.insert(row++, item);
154  }
155  endInsertRows();
156  }
157 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
bool isSortingEnabled() const
The QListWidget class provides an item-based list widget.
Definition: qlistwidget.h:202
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void endInsertRows()
Ends a row insertion operation.
T * qobject_cast(QObject *object)
Definition: qobject.h:375
void insert(int row, QListWidgetItem *item)
The QListWidgetItem class provides an item for use with the QListWidget item view class...
Definition: qlistwidget.h:63
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.
QListWidget * view
Definition: qlistwidget.h:168
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.

◆ insertRows()

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

On models that support this, inserts count rows into the model before the given row.

Note
The base class implementation of this function does nothing and returns false.

Items in the new row will be children of the item represented by the parent model index.

If row is 0, the rows are prepended to any existing rows in the parent.

If row is rowCount(), the rows are appended to any existing rows in the parent.

If parent has no children, a single column with count rows is inserted.

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

If you implement your own model, you can reimplement this function if you want to support insertions. Alternatively, you can provide your own API for altering the data. In either case, you will need to call beginInsertRows() and endInsertRows() to notify other components that the model has changed.

See also
insertColumns(), removeRows(), beginInsertRows(), endInsertRows()

Reimplemented from QAbstractItemModel.

Definition at line 245 of file qlistwidget.cpp.

246 {
247  if (count < 1 || row < 0 || row > rowCount() || parent.isValid())
248  return false;
249 
250  beginInsertRows(QModelIndex(), row, row + count - 1);
252  QListWidgetItem *itm = 0;
253 
254  for (int r = row; r < row + count; ++r) {
255  itm = new QListWidgetItem;
256  itm->view = view;
257  itm->d->theid = r;
258  items.insert(r, itm);
259  }
260 
261  endInsertRows();
262  return true;
263 }
The QListWidget class provides an item-based list widget.
Definition: qlistwidget.h:202
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
void endInsertRows()
Ends a row insertion operation.
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QList< QListWidgetItem * > items
int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows under the given parent.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QListWidgetItem class provides an item for use with the QListWidget item view class...
Definition: qlistwidget.h:63
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.
QListWidget * view
Definition: qlistwidget.h:168
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.

◆ internalMimeData()

QMimeData * QListModel::internalMimeData ( ) const

Definition at line 419 of file qlistwidget.cpp.

420 {
422 }
QModelIndexList cachedIndexes
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
Returns an object that contains serialized items of data corresponding to the list of indexes specifi...

◆ itemChanged()

void QListModel::itemChanged ( QListWidgetItem item)

Definition at line 407 of file qlistwidget.cpp.

Referenced by QListWidget::addItems().

408 {
409  QModelIndex idx = index(item);
410  emit dataChanged(idx, idx);
411 }
#define emit
Definition: qobjectdefs.h:76
QModelIndex index(QListWidgetItem *item) const
The QModelIndex class is used to locate data in a data model.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This signal is emitted whenever the data in an existing item changes.

◆ itemData()

QMap< int, QVariant > QListModel::itemData ( const QModelIndex index) const
virtual

Returns a map with values for all predefined roles in the model for the item at the given index.

Reimplement this function if you want to extend the default behavior of this function to include custom roles in the map.

See also
Qt::ItemDataRole, data()

Reimplemented from QAbstractItemModel.

Definition at line 232 of file qlistwidget.cpp.

233 {
234  QMap<int, QVariant> roles;
235  if (!index.isValid() || index.row() >= items.count())
236  return roles;
237  QListWidgetItem *itm = items.at(index.row());
238  for (int i = 0; i < itm->d->values.count(); ++i) {
239  roles.insert(itm->d->values.at(i).role,
240  itm->d->values.at(i).value);
241  }
242  return roles;
243 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
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
QList< QListWidgetItem * > items
QVector< QWidgetItemData > values
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
The QListWidgetItem class provides an item for use with the QListWidget item view class...
Definition: qlistwidget.h:63
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ itemGreaterThan()

bool QListModel::itemGreaterThan ( const QPair< QListWidgetItem *, int > &  left,
const QPair< QListWidgetItem *, int > &  right 
)
static

Definition at line 391 of file qlistwidget.cpp.

Referenced by ensureSorted(), and sort().

393 {
394  return (*right.first) < (*left.first);
395 }
T1 first
Definition: qpair.h:65

◆ itemLessThan()

bool QListModel::itemLessThan ( const QPair< QListWidgetItem *, int > &  left,
const QPair< QListWidgetItem *, int > &  right 
)
static

Definition at line 385 of file qlistwidget.cpp.

Referenced by ensureSorted(), and sort().

387 {
388  return (*left.first) < (*right.first);
389 }
T1 first
Definition: qpair.h:65

◆ mimeData()

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

Returns an object that contains serialized items of data corresponding to the list of indexes specified.

The formats used to describe the encoded data is obtained from the mimeTypes() function.

If the list of indexes is empty, or there are no supported MIME types, 0 is returned rather than a serialized empty list.

See also
mimeTypes(), dropMimeData()

Reimplemented from QAbstractItemModel.

Definition at line 424 of file qlistwidget.cpp.

Referenced by QListWidget::addItems().

425 {
426  QList<QListWidgetItem*> itemlist;
427  for (int i = 0; i < indexes.count(); ++i)
428  itemlist << at(indexes.at(i).row());
429  const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent());
430 
431  cachedIndexes = indexes;
432  QMimeData *mimeData = view->mimeData(itemlist);
433  cachedIndexes.clear();
434  return mimeData;
435 }
QListWidgetItem * at(int row) const
Definition: qlistwidget.cpp:89
void clear()
Removes all the MIME type and data entries in the object.
Definition: qmimedata.cpp:613
The QListWidget class provides an item-based list widget.
Definition: qlistwidget.h:202
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
T * qobject_cast(QObject *object)
Definition: qobject.h:375
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 QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
QModelIndexList cachedIndexes
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
virtual QMimeData * mimeData(const QList< QListWidgetItem *> items) const
Returns an object that contains a serialized description of the specified items.
QMimeData * mimeData(const QModelIndexList &indexes) const
Returns an object that contains serialized items of data corresponding to the list of indexes specifi...
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ mimeTypes()

QStringList QListModel::mimeTypes ( ) const
virtual

Returns a list of MIME types that can be used to describe a list of model indexes.

See also
mimeData()

Reimplemented from QAbstractItemModel.

Definition at line 413 of file qlistwidget.cpp.

Referenced by QListWidget::addItems().

414 {
415  const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent());
416  return view->mimeTypes();
417 }
The QListWidget class provides an item-based list widget.
Definition: qlistwidget.h:202
T * qobject_cast(QObject *object)
Definition: qobject.h:375
virtual QStringList mimeTypes() const
Returns a list of MIME types that can be used to describe a list of listwidget items.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273

◆ move()

void QListModel::move ( int  srcRow,
int  dstRow 
)

Definition at line 172 of file qlistwidget.cpp.

173 {
174  if (srcRow == dstRow
175  || srcRow < 0 || srcRow >= items.count()
176  || dstRow < 0 || dstRow > items.count())
177  return;
178 
179  if (!beginMoveRows(QModelIndex(), srcRow, srcRow, QModelIndex(), dstRow))
180  return;
181  if (srcRow < dstRow)
182  --dstRow;
183  items.move(srcRow, dstRow);
184  endMoveRows();
185 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void endMoveRows()
Ends a row move operation.
void move(int from, int to)
Moves the item at index position from to index position to.
Definition: qlist.h:628
QList< QListWidgetItem * > items
The QModelIndex class is used to locate data in a data model.
bool beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
Begins a row move operation.

◆ remove()

void QListModel::remove ( QListWidgetItem item)

Definition at line 94 of file qlistwidget.cpp.

95 {
96  if (!item)
97  return;
98  int row = items.indexOf(item); // ### use index(item) - it's faster
99  Q_ASSERT(row != -1);
100  beginRemoveRows(QModelIndex(), row, row);
101  items.at(row)->d->theid = -1;
102  items.at(row)->view = 0;
103  items.removeAt(row);
104  endRemoveRows();
105 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QListWidgetItem * > items
void endRemoveRows()
Ends a row removal operation.
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
void beginRemoveRows(const QModelIndex &parent, int first, int last)
Begins a row removal operation.
The QModelIndex class is used to locate data in a data model.
QListWidget * view
Definition: qlistwidget.h:168
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ removeRows()

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

On models that support this, removes count rows starting with the given row under parent parent from the model.

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

The base class implementation does nothing and returns false.

If you implement your own model, you can reimplement this function if you want to support removing. Alternatively, you can provide your own API for altering the data.

See also
removeRow(), removeColumns(), insertColumns(), beginRemoveRows(), endRemoveRows()

Reimplemented from QAbstractItemModel.

Definition at line 265 of file qlistwidget.cpp.

266 {
267  if (count < 1 || row < 0 || (row + count) > rowCount() || parent.isValid())
268  return false;
269 
270  beginRemoveRows(QModelIndex(), row, row + count - 1);
271  QListWidgetItem *itm = 0;
272  for (int r = row; r < row + count; ++r) {
273  itm = items.takeAt(row);
274  itm->view = 0;
275  itm->d->theid = -1;
276  delete itm;
277  }
278  endRemoveRows();
279  return true;
280 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
QList< QListWidgetItem * > items
int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows under the given parent.
void endRemoveRows()
Ends a row removal operation.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QListWidgetItem class provides an item for use with the QListWidget item view class...
Definition: qlistwidget.h:63
void beginRemoveRows(const QModelIndex &parent, int first, int last)
Begins a row removal operation.
The QModelIndex class is used to locate data in a data model.
T takeAt(int i)
Removes the item at index position i and returns it.
Definition: qlist.h:484
QListWidget * view
Definition: qlistwidget.h:168

◆ rowCount()

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

Returns the number of rows under the given parent.

When the parent is valid it means that rowCount is returning the number of children of parent.

Note
When implementing a table based model, rowCount() should return 0 when the parent is valid.
See also
columnCount()

Implements QAbstractItemModel.

Definition at line 187 of file qlistwidget.cpp.

Referenced by insertRows(), and removeRows().

188 {
189  return parent.isValid() ? 0 : items.count();
190 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QList< QListWidgetItem * > items
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ setData()

bool QListModel::setData ( const QModelIndex index,
const QVariant value,
int  role 
)
virtual

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

Returns true if successful; otherwise returns false.

The dataChanged() signal should be emitted if the data was successfully set.

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

See also
Qt::ItemDataRole, data(), itemData()

Reimplemented from QAbstractItemModel.

Definition at line 224 of file qlistwidget.cpp.

225 {
226  if (!index.isValid() || index.row() >= items.count())
227  return false;
228  items.at(index.row())->setData(role, value);
229  return true;
230 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
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
QList< QListWidgetItem * > items
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
bool setData(const QModelIndex &index, const QVariant &value, int role)
Sets the role data for the item at index to value.

◆ sort()

void QListModel::sort ( int  column,
Qt::SortOrder  order 
)
virtual

Sorts the model by column in the given order.

The base class implementation does nothing.

Reimplemented from QAbstractItemModel.

Definition at line 289 of file qlistwidget.cpp.

290 {
291  if (column != 0)
292  return;
293 
295 
297  for (int i = 0; i < items.count(); ++i) {
298  QListWidgetItem *item = items.at(i);
299  sorting[i].first = item;
300  sorting[i].second = i;
301  }
302 
304  qSort(sorting.begin(), sorting.end(), compare);
305  QModelIndexList fromIndexes;
306  QModelIndexList toIndexes;
307  for (int r = 0; r < sorting.count(); ++r) {
308  QListWidgetItem *item = sorting.at(r).first;
309  toIndexes.append(createIndex(r, 0, item));
310  fromIndexes.append(createIndex(sorting.at(r).second, 0, sorting.at(r).first));
311  items[r] = sorting.at(r).first;
312  }
313  changePersistentIndexList(fromIndexes, toIndexes);
314 
316 }
static bool itemGreaterThan(const QPair< QListWidgetItem *, int > &left, const QPair< QListWidgetItem *, int > &right)
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. ...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to)
Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list t...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static bool compare(const QVariant::Private *a, const QVariant::Private *b)
Compares a to b.
Definition: qvariant.cpp:383
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
QList< QListWidgetItem * > items
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
The QListWidgetItem class provides an item for use with the QListWidget item view class...
Definition: qlistwidget.h:63
bool(* LessThan)(const QPair< QListWidgetItem *, int > &, const QPair< QListWidgetItem *, int > &)
Definition: qlistwidget.cpp:53
static bool itemLessThan(const QPair< QListWidgetItem *, int > &left, const QPair< QListWidgetItem *, int > &right)

◆ sortedInsertionIterator()

QList< QListWidgetItem * >::iterator QListModel::sortedInsertionIterator ( const QList< QListWidgetItem *>::iterator &  begin,
const QList< QListWidgetItem *>::iterator &  end,
Qt::SortOrder  order,
QListWidgetItem item 
)
static

Definition at line 397 of file qlistwidget.cpp.

Referenced by ensureSorted(), and insert().

401 {
402  if (order == Qt::AscendingOrder)
403  return qLowerBound(begin, end, item, QListModelLessThan());
404  return qLowerBound(begin, end, item, QListModelGreaterThan());
405 }
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:227

◆ supportedDropActions()

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

Returns the drop actions supported by this model.

Since
4.2

The default implementation returns Qt::CopyAction. Reimplement this function if you wish to support additional actions. You must also reimplement the dropMimeData() function to handle the additional operations.

See also
dropMimeData(), Qt::DropActions, {Using drag and drop with item views}

Reimplemented from QAbstractItemModel.

Definition at line 451 of file qlistwidget.cpp.

Referenced by QListWidget::addItems().

452 {
453  const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent());
454  return view->supportedDropActions();
455 }
The QListWidget class provides an item-based list widget.
Definition: qlistwidget.h:202
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
virtual Qt::DropActions supportedDropActions() const
Returns the drop actions supported by this view.

◆ take()

QListWidgetItem * QListModel::take ( int  row)

Definition at line 159 of file qlistwidget.cpp.

160 {
161  if (row < 0 || row >= items.count())
162  return 0;
163 
164  beginRemoveRows(QModelIndex(), row, row);
165  items.at(row)->d->theid = -1;
166  items.at(row)->view = 0;
167  QListWidgetItem *item = items.takeAt(row);
168  endRemoveRows();
169  return item;
170 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QListWidgetItem * > items
void endRemoveRows()
Ends a row removal operation.
The QListWidgetItem class provides an item for use with the QListWidget item view class...
Definition: qlistwidget.h:63
void beginRemoveRows(const QModelIndex &parent, int first, int last)
Begins a row removal operation.
The QModelIndex class is used to locate data in a data model.
T takeAt(int i)
Removes the item at index position i and returns it.
Definition: qlist.h:484
QListWidget * view
Definition: qlistwidget.h:168

Properties

◆ cachedIndexes

QModelIndexList QListModel::cachedIndexes
mutableprivate

Definition at line 137 of file qlistwidget_p.h.

Referenced by internalMimeData(), and mimeData().

◆ items

QList<QListWidgetItem*> QListModel::items
private

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