44 #ifndef QT_NO_LISTWIDGET 46 #include <private/qlistview_p.h> 47 #include <private/qwidgetitemdata_p.h> 48 #include <private/qlistwidget_p.h> 63 #include "qlistwidget.moc" 133 const int count = labels.
count();
139 for (
int i = 0; i < count; ++i) {
149 for (
int i = 0; i < count; ++i) {
194 if (!item || !item->
view || static_cast<const QListModel *>(item->
view->
model()) !=
this 198 const int theid = item->
d->
theid;
254 for (
int r = row; r < row + count; ++r) {
267 if (count < 1 || row < 0 || (row + count) >
rowCount() || parent.
isValid())
272 for (
int r = row; r < row + count; ++r) {
299 sorting[i].first = item;
300 sorting[i].second = i;
307 for (
int r = 0; r < sorting.count(); ++r) {
310 fromIndexes.append(
createIndex(sorting.at(r).second, 0, sorting.at(r).first));
311 items[r] = sorting.
at(r).first;
330 int count = end - start + 1;
332 for (
int i = 0; i < count; ++i) {
334 sorting[i].second = start + i;
344 bool changed =
false;
345 for (
int i = 0; i < count; ++i) {
346 int oldRow = sorting.
at(i).second;
350 lit = tmp.
insert(lit, item);
351 if (newRow != oldRow) {
353 for (
int j = i + 1; j < count; ++j) {
354 int otherRow = sorting.
at(j).second;
355 if (oldRow < otherRow && newRow >= otherRow)
357 else if (oldRow > otherRow && newRow <= otherRow)
360 for (
int k = 0; k < newPersistentIndexes.
count(); ++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,
427 for (
int i = 0; i < indexes.
count(); ++i)
428 itemlist <<
at(indexes.
at(i).
row());
433 cachedIndexes.
clear();
437 #ifndef QT_NO_DRAGANDDROP 456 #endif // QT_NO_DRAGANDDROP 617 if (
QListModel *model = (view ? qobject_cast<QListModel*>(view->
model()) : 0))
618 model->insert(model->rowCount(),
this);
646 if (
QListModel *model = (view ? qobject_cast<QListModel*>(view->
model()) : 0))
647 model->insert(model->rowCount(),
this);
678 if (
QListModel *model = (view ? qobject_cast<QListModel*>(view->
model()) : 0))
679 model->insert(model->rowCount(),
this);
722 model->itemChanged(
this);
750 #ifndef QT_NO_DATASTREAM 771 #endif // QT_NO_DATASTREAM 809 #ifndef QT_NO_DATASTREAM 847 #endif // QT_NO_DATASTREAM 1024 model->itemChanged(
this);
1178 q,
SIGNAL(itemSelectionChanged()));
1187 emit q->itemPressed(listModel()->
at(index.
row()));
1193 emit q->itemClicked(listModel()->
at(index.
row()));
1199 emit q->itemDoubleClicked(listModel()->
at(index.
row()));
1205 emit q->itemActivated(listModel()->
at(index.
row()));
1211 emit q->itemEntered(listModel()->
at(index.
row()));
1217 emit q->itemChanged(listModel()->
at(index.
row()));
1226 emit q->currentItemChanged(currentItem, listModel()->
at(previous.
row()));
1230 if (!persistentCurrent.
isValid()) {
1234 emit q->currentTextChanged(currentItem ? currentItem->
text() :
QString());
1235 emit q->currentRowChanged(persistentCurrent.
row());
1241 model->sort(0, sortOrder);
1247 if (sortingEnabled && topLeft.
isValid() && bottomRight.
isValid())
1248 listModel()->ensureSorted(topLeft.
column(), sortOrder,
1249 topLeft.
row(), bottomRight.
row());
1483 if (row < 0 || row >=
d->model->rowCount())
1485 return d->listModel()->at(row);
1497 return d->listModel()->index(const_cast<QListWidgetItem*>(item)).row();
1510 if (item && !item->
view)
1511 d->listModel()->insert(row, item);
1537 d->listModel()->insert(row, labels);
1553 if (row < 0 || row >=
d->model->rowCount())
1555 return d->listModel()->take(row);
1569 return d->model->rowCount();
1640 d->selectionModel->setCurrentIndex(
d->listModel()->index(row), command);
1682 d->sortOrder = order;
1683 d->listModel()->sort(0, order);
1702 d->sortingEnabled = enable;
1708 return d->sortingEnabled;
1717 return d->sortOrder;
1727 edit(
d->listModel()->index(item));
1840 for (
int i = 0; i < indexes.
count(); ++i)
1856 for (
int i = 0; i < indexes.
size(); ++i)
1907 d->listModel()->clear();
1918 return d_func()->listModel()->QAbstractListModel::mimeTypes();
1931 return d_func()->listModel()->internalMimeData();
1934 #ifndef QT_NO_DRAGANDDROP 1953 return d_func()->listModel()->QAbstractListModel::dropMimeData(data, action , row, column, idx);
1969 if (
d->dropOn(event, &row, &col, &topIndex)) {
1972 for (
int i = 0; i < selIndexes.
count(); i++)
1973 persIndexes.
append(selIndexes.
at(i));
1975 if (persIndexes.
contains(topIndex))
1981 int r = row == -1 ?
count() : (dropRow.
row() >= 0 ? dropRow.
row() :
row);
1982 for (
int i = 0; i < persIndexes.
count(); ++i) {
1984 d->listModel()->move(pIndex.
row(), r);
1985 r = pIndex.
row() + 1;
2005 return d->listModel()->QAbstractListModel::supportedDropActions() |
Qt::MoveAction;
2007 #endif // QT_NO_DRAGANDDROP 2029 return d->listModel()->index(item);
2039 if (
d->isIndexValid(index))
2040 return d->listModel()->at(index.
row());
2049 Q_ASSERT(!
"QListWidget::setModel() - Changing the model of the QListWidget is not allowed.");
2062 #include "moc_qlistwidget.cpp" 2064 #endif // QT_NO_LISTWIDGET The QVariant class acts like a union for the most common Qt data types.
QListWidgetItem * at(int row) const
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
int row() const
Returns the row this persistent model index refers to.
void openPersistentEditor(const QModelIndex &index)
Opens a persistent editor on the item at the given index.
void remove(QListWidgetItem *item)
virtual void clear()
Clears the selection model.
void setRowHidden(int row, bool hide)
If hide is true, the given row will be hidden; otherwise the row will be shown.
QModelIndexList persistentIndexList() const
Returns the list of indexes stored as persistent indexes in the model.
void clear()
Removes all the MIME type and data entries in the object.
#define QT_END_NAMESPACE
This macro expands to.
QPointer< QWidget > widget
#define it(className, varName)
int count(const T &t) const
Returns the number of occurrences of value in the vector.
void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)
Reimplemented Function
T & first()
Returns a reference to the first item in the vector.
#define at(className, varName)
QModelIndexList selectedIndexes() const
Returns a list of all selected model item indexes.
static bool itemGreaterThan(const QPair< QListWidgetItem *, int > &left, const QPair< QListWidgetItem *, int > &right)
DragDropMode dragDropMode() const
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
void setIndexWidget(const QModelIndex &index, QWidget *widget)
Sets the given widget on the item at the given index, passing the ownership of the widget to the view...
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. ...
QMap< int, QVariant > itemData(const QModelIndex &index) const
Returns a map with values for all predefined roles in the model for the item at the given index...
void insert(int i, const T &t)
Inserts value at index position i in the list.
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
int count(const T &t) const
Returns the number of occurrences of value in the list.
void itemChanged(QListWidgetItem *item)
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 QAbstractListModel class provides an abstract model that can be subclassed to create one-dimensio...
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Reimplemented Function
void endInsertRows()
Ends a row insertion operation.
static bool variantLessThan(const QVariant &v1, const QVariant &v2)
This function is used by our Q{Tree,Widget,Table}WidgetModel classes to sort.
void sort(int column, Qt::SortOrder order)
Sorts the model by column in the given order.
The QString class provides a Unicode character string.
T * qobject_cast(QObject *object)
DropIndicatorPosition dropIndicatorPosition() const
Returns the position of the drop indicator in relation to the closest item.
The QVector class is a template class that provides a dynamic array.
void endMoveRows()
Ends a row move operation.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QWidget * indexWidget(const QModelIndex &index) const
Returns the widget for the item at the given index.
QModelIndex indexAt(const QPoint &p) const
Reimplemented Function
QListModel(QListWidget *parent)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
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...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
bool event(QEvent *e)
Reimplemented Function
void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Sets the model item index to be the current item, and emits currentChanged().
void move(int from, int to)
Moves the item at index position from to index position to.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
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.
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
static bool compare(const QVariant::Private *a, const QVariant::Private *b)
Compares a to b.
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
QStringList mimeTypes() const
Returns a list of MIME types that can be used to describe a list of model indexes.
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...
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
QItemSelectionModel * selectionModel() const
Returns the current selection model.
T value(int i) const
Returns the value at index position i in the vector.
bool isSelected(const QModelIndex &index) const
Returns true if the given model item index is selected.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
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.
QList< QListWidgetItem * > items
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
The QStringList class provides a list of strings.
QModelIndex index(QListWidgetItem *item) const
void append(const T &t)
Inserts value at the end of the vector.
void ensureSorted(int column, Qt::SortOrder order, int start, int end)
int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows under the given parent.
QModelIndex currentIndex() const
Returns the model index of the current item.
T value(int i) const
Returns the value at index position i in the list.
void endRemoveRows()
Ends a row removal operation.
void clear()
Removes all items from the list.
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
Qt::DropActions supportedDropActions() const
Returns the drop actions supported by this model.
The QMimeData class provides a container for data that records information about its MIME type...
void insert(int row, QListWidgetItem *item)
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
void qSort(RandomAccessIterator start, RandomAccessIterator end)
QModelIndexList cachedIndexes
const T & at(int i) const
Returns the item at index position i in the vector.
The QAbstractItemModel class provides the abstract interface for item model classes.
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
static QList< QListWidgetItem * >::iterator sortedInsertionIterator(const QList< QListWidgetItem *>::iterator &begin, const QList< QListWidgetItem *>::iterator &end, Qt::SortOrder order, QListWidgetItem *item)
QListWidgetItem * take(int row)
The QItemSelection class manages information about selected items in a model.
QRect visualRect(const QModelIndex &index) const
Reimplemented Function
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
The QListView class provides a list or icon view onto a model.
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...
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
The QPersistentModelIndex class is used to locate data in a data model.
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
QWidget * source() const
If the source of the drag operation is a widget in this application, this function returns that sourc...
QObject * parent() const
Returns a pointer to the parent object.
The QPoint class defines a point in the plane using integer precision.
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.
int size() const
Returns the number of items in the list.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This signal is emitted whenever the data in an existing item changes.
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.
The QRect class defines a rectangle in the plane using integer precision.
QModelIndexList selectedIndexes() const
Reimplemented Function
void edit(const QModelIndex &index)
Starts editing the item corresponding to the given index if it is editable.
T takeAt(int i)
Removes the item at index position i and returns it.
QMimeData * mimeData(const QModelIndexList &indexes) const
Returns an object that contains serialized items of data corresponding to the list of indexes specifi...
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
QMimeData * internalMimeData() const
void move(int srcRow, int dstRow)
The QDataStream class provides serialization of binary data to a QIODevice.
void closePersistentEditor(const QModelIndex &index)
Closes the persistent editor for the item at the given index.
Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
bool setData(const QModelIndex &index, const QVariant &value, int role)
Sets the role data for the item at index to value.
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Appends a new row to the current test data.
QAbstractItemModel * model() const
Returns the model that this view is presenting.
static const KeyPair *const end
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 QEvent class is the base class of all event classes.
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
bool beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
Begins a row move operation.
The QMap class is a template class that provides a skip-list-based dictionary.
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
Returns an object that contains serialized items of data corresponding to the list of indexes specifi...
void reset()
Resets the model to its original state in any attached views.
void dropEvent(QDropEvent *e)
Reimplemented Function
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.
int column() const
Returns the column this model index refers to.
The QList class is a template class that provides lists.
bool isValid() const
Returns true if this persistent model index is valid; otherwise returns false.
bool isRowHidden(int row) const
Returns true if the row is hidden; otherwise returns false.
static bool itemLessThan(const QPair< QListWidgetItem *, int > &left, const QPair< QListWidgetItem *, int > &right)
The QIcon class provides scalable icons in different modes and states.
void removeAt(int i)
Removes the item at index position i.