Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qlistwidget.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qlistwidget.h"
5
6#include <private/qlistview_p.h>
7#include <private/qwidgetitemdata_p.h>
8#include <private/qlistwidget_p.h>
9
10#include <algorithm>
11
13
15{
17public:
18 QList<QListWidgetItem*> items;
19};
20
22#include "qlistwidget.moc"
24
29
34
36{
38 for (int i = 0; i < items.size(); ++i) {
39 if (items.at(i)) {
40 items.at(i)->d->theid = -1;
41 items.at(i)->view = nullptr;
42 delete items.at(i);
43 }
44 }
45 items.clear();
47}
48
50{
51 return items.value(row);
52}
53
55{
56 if (!item)
57 return;
58 int row = items.indexOf(item); // ### use index(item) - it's faster
59 Q_ASSERT(row != -1);
61 items.at(row)->d->theid = -1;
62 items.at(row)->view = nullptr;
63 items.removeAt(row);
65}
66
68{
69 if (!item)
70 return;
71
72 item->view = qobject_cast<QListWidget*>(QObject::parent());
73 if (item->view && item->view->isSortingEnabled()) {
74 // sorted insertion
76 it = sortedInsertionIterator(items.begin(), items.end(),
77 item->view->sortOrder(), item);
78 row = qMax<qsizetype>(it - items.begin(), 0);
79 } else {
80 if (row < 0)
81 row = 0;
82 else if (row > items.size())
83 row = items.size();
84 }
86 items.insert(row, item);
87 item->d->theid = row;
89}
90
91void QListModel::insert(int row, const QStringList &labels)
92{
93 const int count = labels.size();
94 if (count <= 0)
95 return;
96 QListWidget *view = qobject_cast<QListWidget*>(QObject::parent());
97 if (view && view->isSortingEnabled()) {
98 // sorted insertion
99 for (int i = 0; i < count; ++i) {
100 QListWidgetItem *item = new QListWidgetItem(labels.at(i));
101 insert(row, item);
102 }
103 } else {
104 if (row < 0)
105 row = 0;
106 else if (row > items.size())
107 row = items.size();
109 for (int i = 0; i < count; ++i) {
110 QListWidgetItem *item = new QListWidgetItem(labels.at(i));
111 item->d->theid = row;
112 item->view = qobject_cast<QListWidget*>(QObject::parent());
113 items.insert(row++, item);
114 }
116 }
117}
118
120{
121 if (row < 0 || row >= items.size())
122 return nullptr;
123
125 items.at(row)->d->theid = -1;
126 items.at(row)->view = nullptr;
127 QListWidgetItem *item = items.takeAt(row);
129 return item;
130}
131
132void QListModel::move(int srcRow, int dstRow)
133{
134 if (srcRow == dstRow
135 || srcRow < 0 || srcRow >= items.size()
136 || dstRow < 0 || dstRow > items.size())
137 return;
138
139 if (!beginMoveRows(QModelIndex(), srcRow, srcRow, QModelIndex(), dstRow))
140 return;
141 if (srcRow < dstRow)
142 --dstRow;
143 items.move(srcRow, dstRow);
144 endMoveRows();
145}
146
147int QListModel::rowCount(const QModelIndex &parent) const
148{
149 return parent.isValid() ? 0 : items.size();
150}
151
153{
154 QListWidgetItem *item = const_cast<QListWidgetItem *>(item_);
155 if (!item || !item->view || static_cast<const QListModel *>(item->view->model()) != this
156 || items.isEmpty())
157 return QModelIndex();
158 int row;
159 const int theid = item->d->theid;
160 if (theid >= 0 && theid < items.size() && items.at(theid) == item) {
161 row = theid;
162 } else { // we need to search for the item
163 row = items.lastIndexOf(item); // lastIndexOf is an optimization in favor of indexOf
164 if (row == -1) // not found
165 return QModelIndex();
166 item->d->theid = row;
167 }
168 return createIndex(row, 0, item);
169}
170
171QModelIndex QListModel::index(int row, int column, const QModelIndex &parent) const
172{
173 if (hasIndex(row, column, parent))
174 return createIndex(row, column, items.at(row));
175 return QModelIndex();
176}
177
179{
180 if (!index.isValid() || index.row() >= items.size())
181 return QVariant();
182 return items.at(index.row())->data(role);
183}
184
185bool QListModel::setData(const QModelIndex &index, const QVariant &value, int role)
186{
187 if (!index.isValid() || index.row() >= items.size())
188 return false;
189 items.at(index.row())->setData(role, value);
190 return true;
191}
192
194{
196 return false;
197 QListWidgetItem *item = items.at(index.row());
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(); }))
201 return true; //it's already cleared
202 item->d->values.clear();
203 emit dataChanged(index, index, QList<int> {});
204 return true;
205}
206
207QMap<int, QVariant> QListModel::itemData(const QModelIndex &index) const
208{
209 QMap<int, QVariant> roles;
210 if (!index.isValid() || index.row() >= items.size())
211 return roles;
212 QListWidgetItem *itm = items.at(index.row());
213 for (int i = 0; i < itm->d->values.size(); ++i) {
214 roles.insert(itm->d->values.at(i).role,
215 itm->d->values.at(i).value);
216 }
217 return roles;
218}
219
220bool QListModel::insertRows(int row, int count, const QModelIndex &parent)
221{
222 if (count < 1 || row < 0 || row > rowCount() || parent.isValid())
223 return false;
224
226 QListWidget *view = qobject_cast<QListWidget*>(QObject::parent());
227 QListWidgetItem *itm = nullptr;
228
229 for (int r = row; r < row + count; ++r) {
230 itm = new QListWidgetItem;
231 itm->view = view;
232 itm->d->theid = r;
233 items.insert(r, itm);
234 }
235
237 return true;
238}
239
240bool QListModel::removeRows(int row, int count, const QModelIndex &parent)
241{
242 if (count < 1 || row < 0 || (row + count) > rowCount() || parent.isValid())
243 return false;
244
246 QListWidgetItem *itm = nullptr;
247 for (int r = row; r < row + count; ++r) {
248 itm = items.takeAt(row);
249 itm->view = nullptr;
250 itm->d->theid = -1;
251 delete itm;
252 }
254 return true;
255}
256
261bool QListModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
262{
263 if (sourceRow < 0
264 || sourceRow + count - 1 >= rowCount(sourceParent)
265 || destinationChild < 0
269 || count <= 0
270 || sourceParent.isValid()
272 return false;
273 }
275 return false;
276
277 int fromRow = sourceRow;
279 fromRow += count - 1;
280 else
282 while (count--)
283 items.move(fromRow, destinationChild);
284 endMoveRows();
285 return true;
286}
287
288Qt::ItemFlags QListModel::flags(const QModelIndex &index) const
289{
290 if (!index.isValid() || index.row() >= items.size() || index.model() != this)
291 return Qt::ItemIsDropEnabled; // we allow drops outside the items
292 return items.at(index.row())->flags();
293}
294
296{
297 if (column != 0)
298 return;
299
301
302 QList<QPair<QListWidgetItem *, int>> sorting(items.size());
303 for (int i = 0; i < items.size(); ++i) {
304 QListWidgetItem *item = items.at(i);
305 sorting[i].first = item;
306 sorting[i].second = i;
307 }
308
310 std::stable_sort(sorting.begin(), sorting.end(), compare);
311 QModelIndexList fromIndexes;
312 QModelIndexList toIndexes;
313 const int sortingCount = sorting.size();
314 fromIndexes.reserve(sortingCount);
315 toIndexes.reserve(sortingCount);
316 for (int r = 0; r < sortingCount; ++r) {
317 QListWidgetItem *item = sorting.at(r).first;
318 toIndexes.append(createIndex(r, 0, item));
319 fromIndexes.append(createIndex(sorting.at(r).second, 0, sorting.at(r).first));
320 items[r] = sorting.at(r).first;
321 }
322 changePersistentIndexList(fromIndexes, toIndexes);
323
325}
326
332{
333 if (column != 0)
334 return;
335
336 const auto compareLt = [](const QListWidgetItem *left, const QListWidgetItem *right) -> bool {
337 return *left < *right;
338 };
339
340 const auto compareGt = [](const QListWidgetItem *left, const QListWidgetItem *right) -> bool {
341 return *right < *left;
342 };
343
351 const auto beginChangedIterator = items.constBegin() + qMax(start - 1, 0);
352 const auto endChangedIterator = items.constBegin() + qMin(end + 2, items.size());
353 const bool needsSorting = !std::is_sorted(beginChangedIterator, endChangedIterator,
354 order == Qt::AscendingOrder ? compareLt : compareGt);
355
356 if (needsSorting)
357 sort(column, order);
358}
359
360bool QListModel::itemLessThan(const QPair<QListWidgetItem*,int> &left,
361 const QPair<QListWidgetItem*,int> &right)
362{
363 return (*left.first) < (*right.first);
364}
365
366bool QListModel::itemGreaterThan(const QPair<QListWidgetItem*,int> &left,
367 const QPair<QListWidgetItem*,int> &right)
368{
369 return (*right.first) < (*left.first);
370}
371
381
382void QListModel::itemChanged(QListWidgetItem *item, const QList<int> &roles)
383{
384 const QModelIndex idx = index(item);
385 emit dataChanged(idx, idx, roles);
386}
387
389{
390 const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent());
391 if (view)
392 return view->mimeTypes();
393 return {};
394}
395
397{
398 return QAbstractItemModel::mimeData(cachedIndexes);
399}
400
402{
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());
408 const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent());
409
410 cachedIndexes = indexes;
411 QMimeData *mimeData = view->mimeData(itemlist);
412 cachedIndexes.clear();
413 return mimeData;
414}
415
416#if QT_CONFIG(draganddrop)
418 int row, int column, const QModelIndex &index)
419{
421 QListWidget *view = qobject_cast<QListWidget*>(QObject::parent());
422 if (index.isValid())
423 row = index.row();
424 else if (row == -1)
425 row = items.size();
426
427 return view->dropMimeData(row, data, action);
428}
429
430Qt::DropActions QListModel::supportedDropActions() const
431{
432 const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent());
433 return view->supportedDropActions();
434}
435#endif // QT_CONFIG(draganddrop)
436
552 : rtti(type), view(listview), d(new QListWidgetItemPrivate(this)),
553 itemFlags(Qt::ItemIsSelectable
554 |Qt::ItemIsUserCheckable
555 |Qt::ItemIsEnabled
556 |Qt::ItemIsDragEnabled)
557{
558 if (QListModel *model = listModel())
559 model->insert(model->rowCount(), this);
560}
561
579 : rtti(type), view(listview), d(new QListWidgetItemPrivate(this)),
580 itemFlags(Qt::ItemIsSelectable
581 |Qt::ItemIsUserCheckable
582 |Qt::ItemIsEnabled
583 |Qt::ItemIsDragEnabled)
584{
585 QListModel *model = listModel();
586 {
590 }
591 if (model)
592 model->insert(model->rowCount(), this);
593}
594
613 QListWidget *listview, int type)
614 : rtti(type), view(listview), d(new QListWidgetItemPrivate(this)),
615 itemFlags(Qt::ItemIsSelectable
616 |Qt::ItemIsUserCheckable
617 |Qt::ItemIsEnabled
618 |Qt::ItemIsDragEnabled)
619{
620 QListModel *model = listModel();
621 {
626 }
627 if (model)
628 model->insert(model->rowCount(), this);
629}
630
635{
636 if (QListModel *model = listModel())
637 model->remove(this);
638 delete d;
639}
640
645{
646 return new QListWidgetItem(*this);
647}
648
659{
660 bool found = false;
661 role = (role == Qt::EditRole ? Qt::DisplayRole : role);
662 for (int i = 0; i < d->values.size(); ++i) {
663 if (d->values.at(i).role == role) {
664 if (d->values.at(i).value == value)
665 return;
666 d->values[i].value = value;
667 found = true;
668 break;
669 }
670 }
671 if (!found)
673 if (QListModel *model = listModel()) {
674 const QList<int> roles((role == Qt::DisplayRole)
675 ? QList<int>({ Qt::DisplayRole, Qt::EditRole })
676 : QList<int>({ role }));
677 model->itemChanged(this, roles);
678 }
679}
680
688{
689 role = (role == Qt::EditRole ? Qt::DisplayRole : role);
690 for (int i = 0; i < d->values.size(); ++i)
691 if (d->values.at(i).role == role)
692 return d->values.at(i).value;
693 return QVariant();
694}
695
705
706#ifndef QT_NO_DATASTREAM
707
714{
715 in >> d->values;
716}
717
724{
725 out << d->values;
726}
727#endif // QT_NO_DATASTREAM
728
740 : rtti(Type), view(nullptr),
742 itemFlags(other.itemFlags)
743{
744 d->values = other.d->values;
745}
746
756{
757 d->values = other.d->values;
758 itemFlags = other.itemFlags;
759 return *this;
760}
761
766QListModel *QListWidgetItem::listModel() const
767{
768 return (view ? qobject_cast<QListModel*>(view->model()) : nullptr);
769}
770
771#ifndef QT_NO_DATASTREAM
772
783{
784 item.write(out);
785 return out;
786}
787
798{
799 item.read(in);
800 return in;
801}
802
803#endif // QT_NO_DATASTREAM
804
929{
930 const QListModel *model = listModel();
931 if (!model || !view->selectionModel())
932 return;
933 const QAbstractItemView::SelectionMode selectionMode = view->selectionMode();
934 if (selectionMode == QAbstractItemView::NoSelection)
935 return;
936 const QModelIndex index = model->index(this);
937 if (selectionMode == QAbstractItemView::SingleSelection)
938 view->selectionModel()->select(index, select
941 else
942 view->selectionModel()->select(index, select
945}
946
956{
957 const QListModel *model = listModel();
958 if (!model || !view->selectionModel())
959 return false;
960 const QModelIndex index = model->index(this);
961 return view->selectionModel()->isSelected(index);
962}
963
971void QListWidgetItem::setFlags(Qt::ItemFlags aflags)
972{
973 itemFlags = aflags;
974 if (QListModel *model = listModel())
975 model->itemChanged(this);
976}
977
978
1105
1113
1115{
1116 Q_Q(QListWidget);
1117 emit q->itemPressed(listModel()->at(index.row()));
1118}
1119
1121{
1122 Q_Q(QListWidget);
1123 emit q->itemClicked(listModel()->at(index.row()));
1124}
1125
1127{
1128 Q_Q(QListWidget);
1129 emit q->itemDoubleClicked(listModel()->at(index.row()));
1130}
1131
1133{
1134 Q_Q(QListWidget);
1135 emit q->itemActivated(listModel()->at(index.row()));
1136}
1137
1139{
1140 Q_Q(QListWidget);
1141 emit q->itemEntered(listModel()->at(index.row()));
1142}
1143
1145{
1146 Q_Q(QListWidget);
1147 emit q->itemChanged(listModel()->at(index.row()));
1148}
1149
1151 const QModelIndex &previous)
1152{
1153 Q_Q(QListWidget);
1154 QPersistentModelIndex persistentCurrent = current;
1155 QListWidgetItem *currentItem = listModel()->at(persistentCurrent.row());
1156 emit q->currentItemChanged(currentItem, listModel()->at(previous.row()));
1157
1158 //persistentCurrent is invalid if something changed the model in response
1159 //to the currentItemChanged signal emission and the item was removed
1160 if (!persistentCurrent.isValid()) {
1161 currentItem = nullptr;
1162 }
1163
1164 emit q->currentTextChanged(currentItem ? currentItem->text() : QString());
1165 emit q->currentRowChanged(persistentCurrent.row());
1166}
1167
1169{
1170 if (sortingEnabled)
1171 model->sort(0, sortOrder);
1172}
1173
1175 const QModelIndex &bottomRight)
1176{
1177 if (sortingEnabled && topLeft.isValid() && bottomRight.isValid())
1178 listModel()->ensureSorted(topLeft.column(), sortOrder,
1179 topLeft.row(), bottomRight.row());
1180}
1181
1369 : QListView(*new QListWidgetPrivate(), parent)
1370{
1371 Q_D(QListWidget);
1372 d->setup();
1373}
1374
1380{
1381 Q_D(QListWidget);
1382 d->clearConnections();
1383}
1384
1390{
1391 Q_D(QListWidget);
1392
1393 for (const QMetaObject::Connection &connection : d->selectionModelConnections)
1395
1397
1398 if (d->selectionModel) {
1399 d->selectionModelConnections = {
1404 };
1405 }
1406}
1407
1416{
1417 Q_D(const QListWidget);
1418 if (row < 0 || row >= d->model->rowCount())
1419 return nullptr;
1420 return d->listModel()->at(row);
1421}
1422
1430{
1431 Q_D(const QListWidget);
1432 return d->listModel()->index(const_cast<QListWidgetItem*>(item)).row();
1433}
1434
1435
1443{
1444 Q_D(QListWidget);
1445 if (item && !item->view)
1446 d->listModel()->insert(row, item);
1447}
1448
1457{
1458 Q_D(QListWidget);
1459 d->listModel()->insert(row, new QListWidgetItem(label));
1460}
1461
1470{
1471 Q_D(QListWidget);
1472 d->listModel()->insert(row, labels);
1473}
1474
1486{
1487 Q_D(QListWidget);
1488 if (row < 0 || row >= d->model->rowCount())
1489 return nullptr;
1490 return d->listModel()->take(row);
1491}
1492
1499{
1500 Q_D(const QListWidget);
1501 return d->model->rowCount();
1502}
1503
1508{
1509 Q_D(const QListWidget);
1510 return d->listModel()->at(currentIndex().row());
1511}
1512
1513
1524
1529void QListWidget::setCurrentItem(QListWidgetItem *item, QItemSelectionModel::SelectionFlags command)
1530{
1531 setCurrentRow(row(item), command);
1532}
1533
1542{
1543 return currentIndex().row();
1544}
1545
1557
1563void QListWidget::setCurrentRow(int row, QItemSelectionModel::SelectionFlags command)
1564{
1565 Q_D(QListWidget);
1566 d->selectionModel->setCurrentIndex(d->listModel()->index(row), command);
1567}
1568
1575{
1576 Q_D(const QListWidget);
1577 return d->listModel()->at(indexAt(p).row());
1578
1579}
1580
1596{
1597 Q_D(const QListWidget);
1598 QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
1599 return visualRect(index);
1600}
1601
1606{
1607 Q_D(QListWidget);
1608 d->sortOrder = order;
1609 d->listModel()->sort(0, order);
1610}
1611
1623{
1624 Q_D(QListWidget);
1625 d->sortingEnabled = enable;
1626}
1627
1629{
1630 Q_D(const QListWidget);
1631 return d->sortingEnabled;
1632}
1633
1637Qt::SortOrder QListWidget::sortOrder() const
1638{
1639 Q_D(const QListWidget);
1640 return d->sortOrder;
1641}
1642
1648{
1649 Q_D(QListWidget);
1650 edit(d->listModel()->index(item));
1651}
1652
1665
1677
1686{
1687 Q_D(const QListWidget);
1688 const QModelIndex index = d->listModel()->index(item);
1690}
1691
1700{
1701 Q_D(const QListWidget);
1702 QModelIndex index = d->listModel()->index(item);
1704}
1705
1724
1729QList<QListWidgetItem*> QListWidget::selectedItems() const
1730{
1731 Q_D(const QListWidget);
1733 QList<QListWidgetItem*> items;
1734 const int numIndexes = indexes.size();
1735 items.reserve(numIndexes);
1736 for (int i = 0; i < numIndexes; ++i)
1737 items.append(d->listModel()->at(indexes.at(i).row()));
1738 return items;
1739}
1740
1746QList<QListWidgetItem*> QListWidget::findItems(const QString &text, Qt::MatchFlags flags) const
1747{
1748 Q_D(const QListWidget);
1749 QModelIndexList indexes = d->listModel()->match(model()->index(0, 0, QModelIndex()),
1750 Qt::DisplayRole, text, -1, flags);
1751 QList<QListWidgetItem*> items;
1752 const int indexesSize = indexes.size();
1753 items.reserve(indexesSize);
1754 for (int i = 0; i < indexesSize; ++i)
1755 items.append(d->listModel()->at(indexes.at(i).row()));
1756 return items;
1757}
1758
1771
1778{
1779 Q_D(QListWidget);
1780 selectionModel()->clear();
1781 d->listModel()->clear();
1782}
1783
1791{
1792 return d_func()->listModel()->QAbstractListModel::mimeTypes();
1793}
1794
1803QMimeData *QListWidget::mimeData(const QList<QListWidgetItem *> &items) const
1804{
1805 Q_D(const QListWidget);
1806
1807 QModelIndexList &cachedIndexes = d->listModel()->cachedIndexes;
1808
1809 // if non empty, it's called from the model's own mimeData
1810 if (cachedIndexes.isEmpty()) {
1811 cachedIndexes.reserve(items.size());
1812 for (QListWidgetItem *item : items)
1813 cachedIndexes << indexFromItem(item);
1814
1815 QMimeData *result = d->listModel()->internalMimeData();
1816
1817 cachedIndexes.clear();
1818 return result;
1819 }
1820
1821 return d->listModel()->internalMimeData();
1822}
1823
1824#if QT_CONFIG(draganddrop)
1832bool QListWidget::dropMimeData(int index, const QMimeData *data, Qt::DropAction action)
1833{
1834 QModelIndex idx;
1835 int row = index;
1836 int column = 0;
1837 if (dropIndicatorPosition() == QAbstractItemView::OnItem) {
1838 // QAbstractListModel::dropMimeData will overwrite on the index if row == -1 and column == -1
1839 idx = model()->index(row, column);
1840 row = -1;
1841 column = -1;
1842 }
1843 return d_func()->listModel()->QAbstractListModel::dropMimeData(data, action , row, column, idx);
1844}
1845
1847void QListWidget::dropEvent(QDropEvent *event)
1848{
1849 QListView::dropEvent(event);
1850}
1851
1857Qt::DropActions QListWidget::supportedDropActions() const
1858{
1859 Q_D(const QListWidget);
1860 return d->listModel()->QAbstractListModel::supportedDropActions() | Qt::MoveAction;
1861}
1862#endif // QT_CONFIG(draganddrop)
1863
1869QList<QListWidgetItem*> QListWidget::items(const QMimeData *data) const
1870{
1871 const QListWidgetMimeData *lwd = qobject_cast<const QListWidgetMimeData*>(data);
1872 if (lwd)
1873 return lwd->items;
1874 return QList<QListWidgetItem*>();
1875}
1876
1884{
1885 Q_D(const QListWidget);
1886 return d->listModel()->index(item);
1887}
1888
1894{
1895 Q_D(const QListWidget);
1896 if (d->isIndexValid(index))
1897 return d->listModel()->at(index.row());
1898 return nullptr;
1899}
1900
1905{
1906 Q_ASSERT(!"QListWidget::setModel() - Changing the model of the QListWidget is not allowed.");
1907}
1908
1913{
1914 return QListView::event(e);
1915}
1916
1918
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.
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.
Definition qobject.h:346
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
Definition qdatastream.h:46
\inmodule QtCore
Definition qcoreevent.h:45
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This signal is emitted whenever the selection changes.
void currentChanged(const QModelIndex &current, 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.
Definition qlistview.h:17
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
QList< QWidgetItemData > values
The QListWidgetItem class provides an item for use with the QListWidget item view class.
Definition qlistwidget.h:23
QListWidgetItem(QListWidget *listview=nullptr, int type=Type)
Constructs an empty list widget item of the specified type with the given parent.
bool isSelected() const
QString text() const
Returns the list item's text.
Definition qlistwidget.h:48
QDataStream & operator<<(QDataStream &out, const QListWidgetItem &item)
Writes the list widget item item to stream out.
QIcon icon() const
Returns the list item's icon.
Definition qlistwidget.h:52
QDataStream & operator>>(QDataStream &in, QListWidgetItem &item)
Reads a list widget item from stream in into item.
QListWidgetItem & operator=(const QListWidgetItem &other)
Assigns other's data and flags to this item.
virtual void read(QDataStream &in)
Reads the item from stream in.
virtual QListWidgetItem * clone() const
Creates an exact copy of the item.
virtual void write(QDataStream &out) const
Writes the item to stream out.
void setFlags(Qt::ItemFlags flags)
Sets the item flags for the list item to flags.
void setSelected(bool select)
virtual QVariant data(int role) const
Returns the item's data for a given role.
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.
virtual bool operator<(const QListWidgetItem &other) const
Returns true if this item's text is less then other item's text; otherwise returns false.
virtual ~QListWidgetItem()
Destroys the list item.
Qt::ItemFlags flags() const
Returns the item flags for this item (see \l{Qt::ItemFlags}).
Definition qlistwidget.h:45
QList< QListWidgetItem * > items
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void emitItemChanged(const QModelIndex &index)
void emitCurrentItemChanged(const QModelIndex &current, const QModelIndex &previous)
QListModel * listModel() const
std::array< QMetaObject::Connection, 8 > connections
void emitItemEntered(const QModelIndex &index)
std::array< QMetaObject::Connection, 2 > selectionModelConnections
void emitItemClicked(const QModelIndex &index)
void emitItemActivated(const QModelIndex &index)
void emitItemDoubleClicked(const QModelIndex &index)
void emitItemPressed(const QModelIndex &index)
Qt::SortOrder sortOrder
The QListWidget class provides an item-based list widget.
QList< QListWidgetItem * > items(const QMimeData *data) const
Returns a list of pointers to the items contained in the data object.
QModelIndex indexFromItem(const QListWidgetItem *item) const
Returns the QModelIndex associated with the given item.
QListWidgetItem * item(int row) const
Returns the item that occupies the given row in the list if one has been set; otherwise returns \null...
QListWidgetItem * takeItem(int row)
Removes and returns the item from the given row in the list widget; otherwise returns \nullptr.
void openPersistentEditor(QListWidgetItem *item)
Opens an editor for the given item.
QRect visualItemRect(const QListWidgetItem *item) const
Returns the rectangle on the viewport occupied by the item at item.
void setModel(QAbstractItemModel *model) override
void setCurrentRow(int row)
QList< QListWidgetItem * > selectedItems() const
Returns a list of all selected items in the list widget.
QListWidgetItem * itemFromIndex(const QModelIndex &index) const
Returns a pointer to the QListWidgetItem associated with the given index.
QList< QListWidgetItem * > findItems(const QString &text, Qt::MatchFlags flags) const
Finds items with the text that matches the string text using the given flags.
virtual QStringList mimeTypes() const
Returns a list of MIME types that can be used to describe a list of listwidget items.
void insertItem(int row, QListWidgetItem *item)
Inserts the item at the position in the list given by row.
void editItem(QListWidgetItem *item)
Starts editing the item if it is editable.
bool event(QEvent *e) override
\reimp
bool isPersistentEditorOpen(QListWidgetItem *item) const
void sortItems(Qt::SortOrder order=Qt::AscendingOrder)
Sorts all the items in the list widget according to the specified order.
int currentRow
the row of the current item.
friend class QListWidgetItem
void setSortingEnabled(bool enable)
void closePersistentEditor(QListWidgetItem *item)
Closes the persistent editor for the given item.
QListWidgetItem * currentItem() const
Returns the current item.
QListWidgetItem * itemAt(const QPoint &p) const
Returns a pointer to the item at the coordinates p.
void setItemWidget(QListWidgetItem *item, QWidget *widget)
void clear()
Removes all items and selections in the view.
bool isSortingEnabled() const
void setSelectionModel(QItemSelectionModel *selectionModel) override
\reimp
~QListWidget()
Destroys the list widget and all its items.
void setCurrentItem(QListWidgetItem *item)
Sets the current item to item.
void insertItems(int row, const QStringList &labels)
Inserts items from the list of labels into the list, starting at the given row.
int row(const QListWidgetItem *item) const
Returns the row containing the given item.
virtual QMimeData * mimeData(const QList< QListWidgetItem * > &items) const
Returns an object that contains a serialized description of the specified items.
QListWidget(QWidget *parent=nullptr)
Constructs an empty QListWidget with the given parent.
void itemSelectionChanged()
This signal is emitted whenever the selection changes.
int count
the number of items in the list including any hidden items.
QWidget * itemWidget(QListWidgetItem *item) const
void scrollToItem(const QListWidgetItem *item, QAbstractItemView::ScrollHint hint=EnsureVisible)
Scrolls the view if necessary to ensure that the item is visible.
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
void removeAt(qsizetype i)
Definition qlist.h:590
iterator insert(qsizetype i, parameter_type t)
Definition qlist.h:488
iterator end()
Definition qlist.h:626
T takeAt(qsizetype i)
Definition qlist.h:609
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
T value(qsizetype i) const
Definition qlist.h:664
void move(qsizetype from, qsizetype to)
Definition qlist.h:610
const_iterator constBegin() const noexcept
Definition qlist.h:632
iterator begin()
Definition qlist.h:625
void reserve(qsizetype size)
Definition qlist.h:753
void append(parameter_type t)
Definition qlist.h:458
void clear()
Definition qlist.h:434
\inmodule QtCore Represents a handle to a signal-slot (or signal-functor) connection.
\inmodule QtCore
Definition qmimedata.h:16
\inmodule QtCore
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)
Definition qobject_p.h:299
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3236
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
Exception-safe wrapper around QObject::blockSignals().
Definition qobject.h:483
int rowCount(const QModelIndex &parent=QModelIndex()) const override
If the database supports returning the size of a query (see QSqlDriver::hasFeature()),...
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
#define this
Definition dialogs.cpp:9
QOpenGLWidget * widget
[1]
QString text
QSet< QString >::iterator it
Combined button and popup list for selecting options.
Definition qcompare.h:63
@ DecorationRole
@ EditRole
@ DisplayRole
SortOrder
Definition qnamespace.h:121
@ AscendingOrder
Definition qnamespace.h:122
DropAction
@ MoveAction
@ ItemIsDropEnabled
DBusConnection * connection
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLint GLfloat GLfloat GLfloat v2
GLboolean GLboolean GLboolean b
GLuint index
[2]
GLboolean r
[2]
GLuint GLuint end
GLenum GLenum GLsizei count
GLdouble GLdouble right
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint left
GLenum type
GLuint GLsizei const GLchar * label
[43]
GLbitfield flags
GLint GLfloat GLfloat v1
GLboolean enable
GLuint start
GLenum GLenum GLsizei void GLsizei void * column
struct _cl_event * event
GLuint in
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLenum GLenum GLsizei void * row
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
GLfixed GLfixed GLint GLint order
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
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
#define Q_OBJECT
#define emit
#define Q_UNUSED(x)
static int compare(quint64 a, quint64 b)
QSqlQueryModel * model
[16]
QTextStream out(stdout)
[7]
QMimeData * mimeData
QObject::connect nullptr
myObject disconnect()
[26]
QSharedPointer< T > other(t)
[5]
QGraphicsItem * item
selection select(topLeft, bottomRight)
QList< QTreeWidgetItem * > items
QAction * at
QQuickView * view
[0]
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
Definition qlist.h:962
qsizetype lastIndexOf(const AT &t, qsizetype from=-1) const noexcept
Definition qlist.h:969
Definition moc.h:23