6#include <private/qlistview_p.h>
7#include <private/qwidgetitemdata_p.h>
8#include <private/qlistwidget_p.h>
22#include "qlistwidget.moc"
38 for (
int i = 0;
i < items.
size(); ++
i) {
41 items.
at(
i)->view =
nullptr;
62 items.
at(
row)->view =
nullptr;
73 if (
item->view &&
item->view->isSortingEnabled()) {
93 const int count = labels.size();
97 if (
view &&
view->isSortingEnabled()) {
121 if (row < 0 || row >= items.
size())
126 items.
at(
row)->view =
nullptr;
135 || srcRow < 0 || srcRow >= items.
size()
136 || dstRow < 0 || dstRow > items.
size())
143 items.
move(srcRow, dstRow);
159 const int theid =
item->d->theid;
160 if (theid >= 0 && theid < items.
size() && items.
at(theid) ==
item) {
198 const auto beginIter =
item->d->values.cbegin();
199 const auto endIter =
item->d->values.cend();
200 if (std::all_of(beginIter, endIter, [](
const QWidgetItemData&
data) ->
bool {
return !
data.value.isValid(); }))
202 item->d->values.clear();
209 QMap<int, QVariant> roles;
279 fromRow +=
count - 1;
302 QList<QPair<QListWidgetItem *, int>> sorting(items.
size());
303 for (
int i = 0;
i < items.
size(); ++
i) {
305 sorting[
i].first =
item;
306 sorting[
i].second =
i;
310 std::stable_sort(sorting.begin(), sorting.end(),
compare);
313 const int sortingCount = sorting.size();
314 fromIndexes.reserve(sortingCount);
315 toIndexes.reserve(sortingCount);
316 for (
int r = 0;
r < sortingCount; ++
r) {
319 fromIndexes.append(
createIndex(sorting.at(
r).second, 0, sorting.at(
r).first));
320 items[
r] = sorting.at(
r).first;
353 const bool needsSorting = !std::is_sorted(beginChangedIterator, endChangedIterator,
361 const QPair<QListWidgetItem*,int> &
right)
367 const QPair<QListWidgetItem*,int> &
right)
392 return view->mimeTypes();
403 QList<QListWidgetItem*> itemlist;
404 const int indexesCount = indexes.
size();
405 itemlist.reserve(indexesCount);
406 for (
int i = 0;
i < indexesCount; ++
i)
407 itemlist <<
at(indexes.
at(
i).
row());
410 cachedIndexes = indexes;
412 cachedIndexes.
clear();
416#if QT_CONFIG(draganddrop)
433 return view->supportedDropActions();
553 itemFlags(
Qt::ItemIsSelectable
554 |
Qt::ItemIsUserCheckable
556 |
Qt::ItemIsDragEnabled)
580 itemFlags(
Qt::ItemIsSelectable
581 |
Qt::ItemIsUserCheckable
583 |
Qt::ItemIsDragEnabled)
615 itemFlags(
Qt::ItemIsSelectable
616 |
Qt::ItemIsUserCheckable
618 |
Qt::ItemIsDragEnabled)
676 : QList<int>({ role }));
677 model->itemChanged(
this, roles);
706#ifndef QT_NO_DATASTREAM
742 itemFlags(
other.itemFlags)
758 itemFlags =
other.itemFlags;
768 return (view ? qobject_cast<QListModel*>(
view->model()) :
nullptr);
771#ifndef QT_NO_DATASTREAM
961 return view->selectionModel()->isSelected(
index);
975 model->itemChanged(
this);
1160 if (!persistentCurrent.isValid()) {
1161 currentItem =
nullptr;
1165 emit q->currentRowChanged(persistentCurrent.row());
1179 topLeft.
row(), bottomRight.
row());
1382 d->clearConnections();
1398 if (
d->selectionModel) {
1399 d->selectionModelConnections = {
1418 if (row < 0 || row >=
d->model->rowCount())
1420 return d->listModel()->at(
row);
1472 d->listModel()->insert(
row, labels);
1488 if (row < 0 || row >=
d->model->rowCount())
1490 return d->listModel()->take(
row);
1501 return d->model->rowCount();
1566 d->selectionModel->setCurrentIndex(
d->listModel()->index(
row), command);
1609 d->listModel()->sort(0,
order);
1631 return d->sortingEnabled;
1640 return d->sortOrder;
1733 QList<QListWidgetItem*>
items;
1734 const int numIndexes = indexes.
size();
1736 for (
int i = 0;
i < numIndexes; ++
i)
1751 QList<QListWidgetItem*>
items;
1752 const int indexesSize = indexes.
size();
1754 for (
int i = 0;
i < indexesSize; ++
i)
1781 d->listModel()->clear();
1792 return d_func()->listModel()->QAbstractListModel::mimeTypes();
1810 if (cachedIndexes.
isEmpty()) {
1817 cachedIndexes.
clear();
1821 return d->listModel()->internalMimeData();
1824#if QT_CONFIG(draganddrop)
1837 if (dropIndicatorPosition() == QAbstractItemView::OnItem) {
1843 return d_func()->listModel()->QAbstractListModel::dropMimeData(
data, action ,
row,
column, idx);
1847void QListWidget::dropEvent(QDropEvent *
event)
1849 QListView::dropEvent(
event);
1857Qt::DropActions QListWidget::supportedDropActions()
const
1860 return d->listModel()->QAbstractListModel::supportedDropActions() |
Qt::MoveAction;
1874 return QList<QListWidgetItem*>();
1886 return d->listModel()->index(
item);
1896 if (
d->isIndexValid(
index))
1897 return d->listModel()->at(
index.row());
1906 Q_ASSERT(!
"QListWidget::setModel() - Changing the model of the QListWidget is not allowed.");
1919#include "moc_qlistwidget.cpp"
1920#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)
void columnsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after columns have been removed from the model.
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.
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
void activated(const QModelIndex &index)
This signal is emitted when the item specified by index is activated by the user.
QAbstractItemModel * model() const
Returns the model that this view is presenting.
void doubleClicked(const QModelIndex &index)
This signal is emitted when a mouse button is double-clicked.
virtual void setSelectionModel(QItemSelectionModel *selectionModel)
Sets the current selection model to the given selectionModel.
void entered(const QModelIndex &index)
This signal is emitted when the mouse cursor enters the item specified by index.
QModelIndex currentIndex() const
Returns the model index of the current item.
bool isPersistentEditorOpen(const QModelIndex &index) const
void setIndexWidget(const QModelIndex &index, QWidget *widget)
void openPersistentEditor(const QModelIndex &index)
Opens a persistent editor on the item at the given index.
void pressed(const QModelIndex &index)
This signal is emitted when a mouse button is pressed.
ScrollHint
\value EnsureVisible Scroll to ensure that the item is visible.
void clicked(const QModelIndex &index)
This signal is emitted when a mouse button is left-clicked.
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.
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This signal is emitted whenever the selection changes.
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
This signal is emitted whenever the current item changes.
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)
const_iterator constBegin() const noexcept
void reserve(qsizetype size)
void append(parameter_type t)
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}.
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
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
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
Exception-safe wrapper around QObject::blockSignals().
int rowCount(const QModelIndex &parent=QModelIndex()) const override
If the database supports returning the size of a query (see QSqlDriver::hasFeature()),...
\macro QT_RESTRICTED_CAST_FROM_ASCII
QSet< QString >::iterator it
Combined button and popup list for selecting options.
DBusConnection * connection
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLint GLfloat GLfloat GLfloat v2
GLboolean GLboolean GLboolean b
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLsizei const GLchar * label
[43]
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]
myObject disconnect()
[26]
selection select(topLeft, bottomRight)
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
qsizetype lastIndexOf(const AT &t, qsizetype from=-1) const noexcept