7#include <private/qlistview_p.h>
8#include <private/qwidgetitemdata_p.h>
9#include <private/qlistwidget_p.h>
23#include "qlistwidget.moc"
39 for (
int i = 0;
i < items.
size(); ++
i) {
42 items.
at(
i)->view =
nullptr;
63 items.
at(
row)->view =
nullptr;
74 if (
item->view &&
item->view->isSortingEnabled()) {
94 const int count = labels.size();
98 if (
view &&
view->isSortingEnabled()) {
122 if (row < 0 || row >= items.
size())
127 items.
at(
row)->view =
nullptr;
136 || srcRow < 0 || srcRow >= items.
size()
137 || dstRow < 0 || dstRow > items.
size())
144 items.
move(srcRow, dstRow);
160 const int theid =
item->d->theid;
161 if (theid >= 0 && theid < items.
size() && items.
at(theid) ==
item) {
199 const auto beginIter =
item->d->values.cbegin();
200 const auto endIter =
item->d->values.cend();
201 if (std::all_of(beginIter, endIter, [](
const QWidgetItemData&
data) ->
bool {
return !
data.value.isValid(); }))
203 item->d->values.clear();
280 fromRow +=
count - 1;
304 for (
int i = 0;
i < items.
size(); ++
i) {
306 sorting[
i].first =
item;
307 sorting[
i].second =
i;
311 std::sort(sorting.begin(), sorting.end(),
compare);
314 const int sortingCount = sorting.
size();
315 fromIndexes.
reserve(sortingCount);
316 toIndexes.
reserve(sortingCount);
317 for (
int r = 0;
r < sortingCount; ++
r) {
321 items[
r] = sorting.
at(
r).first;
354 bool changed =
false;
356 int oldRow = sorting.
at(
i).second;
357 int tmpitepos = lit - tmp.
begin();
359 if (tmpitepos > tmp.
size())
361 lit = tmp.
begin() + tmpitepos;
363 int newRow = qMax<qsizetype>(lit - tmp.
begin(), 0);
365 if (newRow != oldRow) {
369 newPersistentIndexes = oldPersistentIndexes;
373 int otherRow = sorting.
at(
j).second;
374 if (oldRow < otherRow && newRow >= otherRow)
376 else if (oldRow > otherRow && newRow <= otherRow)
379 for (
int k = 0; k < newPersistentIndexes.
size(); ++k) {
381 int oldPersistentRow =
pi.row();
382 int newPersistentRow = oldPersistentRow;
383 if (oldPersistentRow == oldRow)
384 newPersistentRow = newRow;
385 else if (oldRow < oldPersistentRow && newRow >= oldPersistentRow)
386 newPersistentRow = oldPersistentRow - 1;
387 else if (oldRow > oldPersistentRow && newRow <= oldPersistentRow)
388 newPersistentRow = oldPersistentRow + 1;
389 if (newPersistentRow != oldPersistentRow)
390 newPersistentIndexes[k] =
createIndex(newPersistentRow,
391 pi.column(),
pi.internalPointer());
435 return view->mimeTypes();
447 const int indexesCount = indexes.
size();
448 itemlist.
reserve(indexesCount);
449 for (
int i = 0;
i < indexesCount; ++
i)
450 itemlist <<
at(indexes.
at(
i).
row());
453 cachedIndexes = indexes;
455 cachedIndexes.
clear();
459#if QT_CONFIG(draganddrop)
476 return view->supportedDropActions();
596 itemFlags(
Qt::ItemIsSelectable
597 |
Qt::ItemIsUserCheckable
599 |
Qt::ItemIsDragEnabled)
623 itemFlags(
Qt::ItemIsSelectable
624 |
Qt::ItemIsUserCheckable
626 |
Qt::ItemIsDragEnabled)
658 itemFlags(
Qt::ItemIsSelectable
659 |
Qt::ItemIsUserCheckable
661 |
Qt::ItemIsDragEnabled)
720 model->itemChanged(
this, roles);
749#ifndef QT_NO_DATASTREAM
785 itemFlags(
other.itemFlags)
801 itemFlags =
other.itemFlags;
811 return (view ? qobject_cast<QListModel*>(
view->model()) :
nullptr);
814#ifndef QT_NO_DATASTREAM
1004 return view->selectionModel()->isSelected(
index);
1018 model->itemChanged(
this);
1189 if (!persistentCurrent.
isValid()) {
1190 currentItem =
nullptr;
1194 emit q->currentRowChanged(persistentCurrent.
row());
1208 topLeft.
row(), bottomRight.
row());
1420 if (
d->selectionModel) {
1429 if (
d->selectionModel) {
1447 if (row < 0 || row >=
d->model->rowCount())
1449 return d->listModel()->at(
row);
1501 d->listModel()->insert(
row, labels);
1517 if (row < 0 || row >=
d->model->rowCount())
1519 return d->listModel()->take(
row);
1530 return d->model->rowCount();
1595 d->selectionModel->setCurrentIndex(
d->listModel()->index(
row), command);
1638 d->listModel()->sort(0,
order);
1660 return d->sortingEnabled;
1669 return d->sortOrder;
1763 const int numIndexes = indexes.
size();
1765 for (
int i = 0;
i < numIndexes; ++
i)
1781 const int indexesSize = indexes.
size();
1783 for (
int i = 0;
i < indexesSize; ++
i)
1810 d->listModel()->clear();
1821 return d_func()->listModel()->QAbstractListModel::mimeTypes();
1839 if (cachedIndexes.
isEmpty()) {
1846 cachedIndexes.
clear();
1850 return d->listModel()->internalMimeData();
1853#if QT_CONFIG(draganddrop)
1866 if (dropIndicatorPosition() == QAbstractItemView::OnItem) {
1872 return d_func()->listModel()->QAbstractListModel::dropMimeData(
data, action ,
row,
column, idx);
1876void QListWidget::dropEvent(QDropEvent *
event)
1878 QListView::dropEvent(
event);
1886Qt::DropActions QListWidget::supportedDropActions()
const
1889 return d->listModel()->QAbstractListModel::supportedDropActions() |
Qt::MoveAction;
1915 return d->listModel()->index(
item);
1925 if (
d->isIndexValid(
index))
1926 return d->listModel()->at(
index.row());
1935 Q_ASSERT(!
"QListWidget::setModel() - Changing the model of the QListWidget is not allowed.");
1948#include "moc_qlistwidget.cpp"
1949#include "moc_qlistwidget_p.cpp"
static bool variantLessThan(const QVariant &v1, const QVariant &v2)
virtual Qt::DropActions supportedDropActions() const
void endResetModel()
Completes a model reset operation.
bool beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
Q_INVOKABLE 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,...
void endRemoveRows()
Ends a row removal operation.
QModelIndexList persistentIndexList() const
void endMoveRows()
Ends a row move operation.
Q_INVOKABLE int int const QModelIndex & destinationParent
void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to)
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Handles the data supplied by a drag and drop operation that ended with the given action.
void layoutAboutToBeChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
Returns an object that contains serialized items of data corresponding to the list of indexes specifi...
Q_INVOKABLE int int const QModelIndex int destinationChild
void layoutChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
bool checkIndex(const QModelIndex &index, CheckIndexOptions options=CheckIndexOption::NoOption) const
Q_INVOKABLE int sourceRow
void endInsertRows()
Ends a row insertion operation.
void beginResetModel()
Begins a model reset operation.
QModelIndex createIndex(int row, int column, const void *data=nullptr) const
Creates a model index for the given row and column with the internal pointer ptr.
void beginRemoveRows(const QModelIndex &parent, int first, int last)
Begins a row removal operation.
virtual Q_INVOKABLE 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.
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.
QAbstractItemModel * model
SelectionMode
This enum indicates how the view responds to user selections:
QWidget * indexWidget(const QModelIndex &index) const
QAbstractItemModel * model() const
Returns the model that this view is presenting.
virtual void setSelectionModel(QItemSelectionModel *selectionModel)
Sets the current selection model to the given selectionModel.
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This slot is called when the selection is changed.
QModelIndex currentIndex() const
Returns the model index of the current item.
bool isPersistentEditorOpen(const QModelIndex &index) const
void setIndexWidget(const QModelIndex &index, QWidget *widget)
virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
This slot is called when a new item becomes the current item.
void openPersistentEditor(const QModelIndex &index)
Opens a persistent editor on the item at the given index.
ScrollHint
\value EnsureVisible Scroll to ensure that the item is visible.
void edit(const QModelIndex &index)
Starts editing the item corresponding to the given index if it is editable.
QItemSelectionModel * selectionModel() const
Returns the current selection model.
void closePersistentEditor(const QModelIndex &index)
Closes the persistent editor for the item at the given index.
QObject * parent() const
Returns a pointer to the parent object.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the index of the data in row and column with parent.
\inmodule QtCore\reentrant
The QIcon class provides scalable icons in different modes and states.
QModelIndexList selectedIndexes
virtual void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Sets the model item index to be the current item, and emits currentChanged().
virtual void clear()
Clears the selection model.
QMimeData * internalMimeData() const
void ensureSorted(int column, Qt::SortOrder order, int start, int end)
QModelIndex index(const QListWidgetItem *item) const
bool insertRows(int row, int count=1, const QModelIndex &parent=QModelIndex()) override
void insert(int row, QListWidgetItem *item)
QMap< int, QVariant > itemData(const QModelIndex &index) const override
Returns a map with values for all predefined roles in the model for the item at the given index.
QListModel(QListWidget *parent)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override
void sort(int column, Qt::SortOrder order) override
QStringList mimeTypes() const override
Returns the list of allowed MIME types.
static bool itemLessThan(const QPair< QListWidgetItem *, int > &left, const QPair< QListWidgetItem *, int > &right)
QListWidgetItem * take(int row)
void remove(QListWidgetItem *item)
void move(int srcRow, int dstRow)
void itemChanged(QListWidgetItem *item, const QList< int > &roles=QList< int >())
static bool itemGreaterThan(const QPair< QListWidgetItem *, int > &left, const QPair< QListWidgetItem *, int > &right)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Sets the role data for the item at index to value.
QListWidgetItem * at(int row) const
bool removeRows(int row, int count=1, const QModelIndex &parent=QModelIndex()) override
Qt::ItemFlags flags(const QModelIndex &index) const override
\reimp
QMimeData * mimeData(const QModelIndexList &indexes) const override
Returns an object that contains serialized items of data corresponding to the list of indexes specifi...
static QList< QListWidgetItem * >::iterator sortedInsertionIterator(const QList< QListWidgetItem * >::iterator &begin, const QList< QListWidgetItem * >::iterator &end, Qt::SortOrder order, QListWidgetItem *item)
bool clearItemData(const QModelIndex &index) override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns the data stored under the given role for the item referred to by the index.
The QListView class provides a list or icon view onto a model.
void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible) override
\reimp
bool event(QEvent *e) override
\reimp
QRect visualRect(const QModelIndex &index) const override
\reimp
QModelIndex indexAt(const QPoint &p) const override
\reimp
qsizetype size() const noexcept
bool isEmpty() const noexcept
void removeAt(qsizetype i)
iterator insert(qsizetype i, parameter_type t)
const_reference at(qsizetype i) const noexcept
T value(qsizetype i) const
void move(qsizetype from, qsizetype to)
void reserve(qsizetype size)
void append(parameter_type t)
iterator insert(const Key &key, const T &value)
constexpr int row() const noexcept
Returns the row this model index refers to.
constexpr int column() const noexcept
Returns the column this model index refers to.
constexpr bool isValid() const noexcept
Returns {true} if this model index is valid; otherwise returns {false}.
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
bool isValid() const
Returns {true} if this persistent model index is valid; otherwise returns {false}.
int row() const
Returns the row this persistent model index refers to.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
Exception-safe wrapper around QObject::blockSignals().
int rowCount(const QModelIndex &parent=QModelIndex()) const override
\macro QT_RESTRICTED_CAST_FROM_ASCII
QSet< QString >::iterator it
Combined button and popup list for selecting options.
std::pair< T1, T2 > QPair
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLint GLfloat GLfloat GLfloat v2
GLboolean GLboolean GLboolean b
GLenum GLenum GLsizei count
GLuint GLsizei const GLchar * label
[43]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei void GLsizei void * column
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLsizei void * row
GLfixed GLfixed GLint GLint order
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define QT_BEGIN_INCLUDE_NAMESPACE
#define QT_END_INCLUDE_NAMESPACE
static int compare(quint64 a, quint64 b)
QSqlQueryModel * model
[16]
QTextStream out(stdout)
[7]
selection select(topLeft, bottomRight)
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
qsizetype lastIndexOf(const AT &t, qsizetype from=-1) const noexcept
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent