Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qlistwidget.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
16 | ** | - | ||||||||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
29 | ** | - | ||||||||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
31 | ** | - | ||||||||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||
34 | #include "qlistwidget.h" | - | ||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||
36 | #ifndef QT_NO_LISTWIDGET | - | ||||||||||||||||||||||||
37 | #include <qitemdelegate.h> | - | ||||||||||||||||||||||||
38 | #include <private/qlistview_p.h> | - | ||||||||||||||||||||||||
39 | #include <private/qwidgetitemdata_p.h> | - | ||||||||||||||||||||||||
40 | #include <private/qlistwidget_p.h> | - | ||||||||||||||||||||||||
41 | - | |||||||||||||||||||||||||
42 | #include <algorithm> | - | ||||||||||||||||||||||||
43 | - | |||||||||||||||||||||||||
44 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
45 | - | |||||||||||||||||||||||||
46 | // workaround for VC++ 6.0 linker bug (?) | - | ||||||||||||||||||||||||
47 | typedef bool(*LessThan)(const QPair<QListWidgetItem*,int>&,const QPair<QListWidgetItem*,int>&); | - | ||||||||||||||||||||||||
48 | - | |||||||||||||||||||||||||
49 | class QListWidgetMimeData : public QMimeData | - | ||||||||||||||||||||||||
50 | { | - | ||||||||||||||||||||||||
51 | Q_OBJECT | - | ||||||||||||||||||||||||
52 | public: | - | ||||||||||||||||||||||||
53 | QList<QListWidgetItem*> items; | - | ||||||||||||||||||||||||
54 | }; | - | ||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | QT_BEGIN_INCLUDE_NAMESPACE | - | ||||||||||||||||||||||||
57 | #include "qlistwidget.moc" | - | ||||||||||||||||||||||||
58 | QT_END_INCLUDE_NAMESPACE | - | ||||||||||||||||||||||||
59 | - | |||||||||||||||||||||||||
60 | QListModel::QListModel(QListWidget *parent) | - | ||||||||||||||||||||||||
61 | : QAbstractListModel(parent) | - | ||||||||||||||||||||||||
62 | { | - | ||||||||||||||||||||||||
63 | } never executed: end of block | 0 | ||||||||||||||||||||||||
64 | - | |||||||||||||||||||||||||
65 | QListModel::~QListModel() | - | ||||||||||||||||||||||||
66 | { | - | ||||||||||||||||||||||||
67 | clear(); | - | ||||||||||||||||||||||||
68 | } never executed: end of block | 0 | ||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||
70 | void QListModel::clear() | - | ||||||||||||||||||||||||
71 | { | - | ||||||||||||||||||||||||
72 | beginResetModel(); | - | ||||||||||||||||||||||||
73 | for (int i = 0; i < items.count(); ++i) {
| 0 | ||||||||||||||||||||||||
74 | if (items.at(i)) {
| 0 | ||||||||||||||||||||||||
75 | items.at(i)->d->theid = -1; | - | ||||||||||||||||||||||||
76 | items.at(i)->view = 0; | - | ||||||||||||||||||||||||
77 | delete items.at(i); | - | ||||||||||||||||||||||||
78 | } never executed: end of block | 0 | ||||||||||||||||||||||||
79 | } never executed: end of block | 0 | ||||||||||||||||||||||||
80 | items.clear(); | - | ||||||||||||||||||||||||
81 | endResetModel(); | - | ||||||||||||||||||||||||
82 | } never executed: end of block | 0 | ||||||||||||||||||||||||
83 | - | |||||||||||||||||||||||||
84 | QListWidgetItem *QListModel::at(int row) const | - | ||||||||||||||||||||||||
85 | { | - | ||||||||||||||||||||||||
86 | return items.value(row); never executed: return items.value(row); | 0 | ||||||||||||||||||||||||
87 | } | - | ||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||
89 | void QListModel::remove(QListWidgetItem *item) | - | ||||||||||||||||||||||||
90 | { | - | ||||||||||||||||||||||||
91 | if (!item)
| 0 | ||||||||||||||||||||||||
92 | return; never executed: return; | 0 | ||||||||||||||||||||||||
93 | int row = items.indexOf(item); // ### use index(item) - it's faster | - | ||||||||||||||||||||||||
94 | Q_ASSERT(row != -1); | - | ||||||||||||||||||||||||
95 | beginRemoveRows(QModelIndex(), row, row); | - | ||||||||||||||||||||||||
96 | items.at(row)->d->theid = -1; | - | ||||||||||||||||||||||||
97 | items.at(row)->view = 0; | - | ||||||||||||||||||||||||
98 | items.removeAt(row); | - | ||||||||||||||||||||||||
99 | endRemoveRows(); | - | ||||||||||||||||||||||||
100 | } never executed: end of block | 0 | ||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||
102 | void QListModel::insert(int row, QListWidgetItem *item) | - | ||||||||||||||||||||||||
103 | { | - | ||||||||||||||||||||||||
104 | if (!item)
| 0 | ||||||||||||||||||||||||
105 | return; never executed: return; | 0 | ||||||||||||||||||||||||
106 | - | |||||||||||||||||||||||||
107 | item->view = qobject_cast<QListWidget*>(QObject::parent()); | - | ||||||||||||||||||||||||
108 | if (item->view && item->view->isSortingEnabled()) {
| 0 | ||||||||||||||||||||||||
109 | // sorted insertion | - | ||||||||||||||||||||||||
110 | QList<QListWidgetItem*>::iterator it; | - | ||||||||||||||||||||||||
111 | it = sortedInsertionIterator(items.begin(), items.end(), | - | ||||||||||||||||||||||||
112 | item->view->sortOrder(), item); | - | ||||||||||||||||||||||||
113 | row = qMax(it - items.begin(), 0); | - | ||||||||||||||||||||||||
114 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
115 | if (row < 0)
| 0 | ||||||||||||||||||||||||
116 | row = 0; never executed: row = 0; | 0 | ||||||||||||||||||||||||
117 | else if (row > items.count())
| 0 | ||||||||||||||||||||||||
118 | row = items.count(); never executed: row = items.count(); | 0 | ||||||||||||||||||||||||
119 | } never executed: end of block | 0 | ||||||||||||||||||||||||
120 | beginInsertRows(QModelIndex(), row, row); | - | ||||||||||||||||||||||||
121 | items.insert(row, item); | - | ||||||||||||||||||||||||
122 | item->d->theid = row; | - | ||||||||||||||||||||||||
123 | endInsertRows(); | - | ||||||||||||||||||||||||
124 | } never executed: end of block | 0 | ||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||
126 | void QListModel::insert(int row, const QStringList &labels) | - | ||||||||||||||||||||||||
127 | { | - | ||||||||||||||||||||||||
128 | const int count = labels.count(); | - | ||||||||||||||||||||||||
129 | if (count <= 0)
| 0 | ||||||||||||||||||||||||
130 | return; never executed: return; | 0 | ||||||||||||||||||||||||
131 | QListWidget *view = qobject_cast<QListWidget*>(QObject::parent()); | - | ||||||||||||||||||||||||
132 | if (view && view->isSortingEnabled()) {
| 0 | ||||||||||||||||||||||||
133 | // sorted insertion | - | ||||||||||||||||||||||||
134 | for (int i = 0; i < count; ++i) {
| 0 | ||||||||||||||||||||||||
135 | QListWidgetItem *item = new QListWidgetItem(labels.at(i)); | - | ||||||||||||||||||||||||
136 | insert(row, item); | - | ||||||||||||||||||||||||
137 | } never executed: end of block | 0 | ||||||||||||||||||||||||
138 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
139 | if (row < 0)
| 0 | ||||||||||||||||||||||||
140 | row = 0; never executed: row = 0; | 0 | ||||||||||||||||||||||||
141 | else if (row > items.count())
| 0 | ||||||||||||||||||||||||
142 | row = items.count(); never executed: row = items.count(); | 0 | ||||||||||||||||||||||||
143 | beginInsertRows(QModelIndex(), row, row + count - 1); | - | ||||||||||||||||||||||||
144 | for (int i = 0; i < count; ++i) {
| 0 | ||||||||||||||||||||||||
145 | QListWidgetItem *item = new QListWidgetItem(labels.at(i)); | - | ||||||||||||||||||||||||
146 | item->d->theid = row; | - | ||||||||||||||||||||||||
147 | item->view = qobject_cast<QListWidget*>(QObject::parent()); | - | ||||||||||||||||||||||||
148 | items.insert(row++, item); | - | ||||||||||||||||||||||||
149 | } never executed: end of block | 0 | ||||||||||||||||||||||||
150 | endInsertRows(); | - | ||||||||||||||||||||||||
151 | } never executed: end of block | 0 | ||||||||||||||||||||||||
152 | } | - | ||||||||||||||||||||||||
153 | - | |||||||||||||||||||||||||
154 | QListWidgetItem *QListModel::take(int row) | - | ||||||||||||||||||||||||
155 | { | - | ||||||||||||||||||||||||
156 | if (row < 0 || row >= items.count())
| 0 | ||||||||||||||||||||||||
157 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
158 | - | |||||||||||||||||||||||||
159 | beginRemoveRows(QModelIndex(), row, row); | - | ||||||||||||||||||||||||
160 | items.at(row)->d->theid = -1; | - | ||||||||||||||||||||||||
161 | items.at(row)->view = 0; | - | ||||||||||||||||||||||||
162 | QListWidgetItem *item = items.takeAt(row); | - | ||||||||||||||||||||||||
163 | endRemoveRows(); | - | ||||||||||||||||||||||||
164 | return item; never executed: return item; | 0 | ||||||||||||||||||||||||
165 | } | - | ||||||||||||||||||||||||
166 | - | |||||||||||||||||||||||||
167 | void QListModel::move(int srcRow, int dstRow) | - | ||||||||||||||||||||||||
168 | { | - | ||||||||||||||||||||||||
169 | if (srcRow == dstRow
| 0 | ||||||||||||||||||||||||
170 | || srcRow < 0 || srcRow >= items.count()
| 0 | ||||||||||||||||||||||||
171 | || dstRow < 0 || dstRow > items.count())
| 0 | ||||||||||||||||||||||||
172 | return; never executed: return; | 0 | ||||||||||||||||||||||||
173 | - | |||||||||||||||||||||||||
174 | if (!beginMoveRows(QModelIndex(), srcRow, srcRow, QModelIndex(), dstRow))
| 0 | ||||||||||||||||||||||||
175 | return; never executed: return; | 0 | ||||||||||||||||||||||||
176 | if (srcRow < dstRow)
| 0 | ||||||||||||||||||||||||
177 | --dstRow; never executed: --dstRow; | 0 | ||||||||||||||||||||||||
178 | items.move(srcRow, dstRow); | - | ||||||||||||||||||||||||
179 | endMoveRows(); | - | ||||||||||||||||||||||||
180 | } never executed: end of block | 0 | ||||||||||||||||||||||||
181 | - | |||||||||||||||||||||||||
182 | int QListModel::rowCount(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
183 | { | - | ||||||||||||||||||||||||
184 | return parent.isValid() ? 0 : items.count(); never executed: return parent.isValid() ? 0 : items.count();
| 0 | ||||||||||||||||||||||||
185 | } | - | ||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||
187 | QModelIndex QListModel::index(QListWidgetItem *item) const | - | ||||||||||||||||||||||||
188 | { | - | ||||||||||||||||||||||||
189 | if (!item || !item->view || static_cast<const QListModel *>(item->view->model()) != this
| 0 | ||||||||||||||||||||||||
190 | || items.isEmpty())
| 0 | ||||||||||||||||||||||||
191 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
192 | int row; | - | ||||||||||||||||||||||||
193 | const int theid = item->d->theid; | - | ||||||||||||||||||||||||
194 | if (theid >= 0 && theid < items.count() && items.at(theid) == item) {
| 0 | ||||||||||||||||||||||||
195 | row = theid; | - | ||||||||||||||||||||||||
196 | } else { // we need to search for the item never executed: end of block | 0 | ||||||||||||||||||||||||
197 | row = items.lastIndexOf(item); // lastIndexOf is an optimization in favor of indexOf | - | ||||||||||||||||||||||||
198 | if (row == -1) // not found
| 0 | ||||||||||||||||||||||||
199 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
200 | item->d->theid = row; | - | ||||||||||||||||||||||||
201 | } never executed: end of block | 0 | ||||||||||||||||||||||||
202 | return createIndex(row, 0, item); never executed: return createIndex(row, 0, item); | 0 | ||||||||||||||||||||||||
203 | } | - | ||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||
205 | QModelIndex QListModel::index(int row, int column, const QModelIndex &parent) const | - | ||||||||||||||||||||||||
206 | { | - | ||||||||||||||||||||||||
207 | if (hasIndex(row, column, parent))
| 0 | ||||||||||||||||||||||||
208 | return createIndex(row, column, items.at(row)); never executed: return createIndex(row, column, items.at(row)); | 0 | ||||||||||||||||||||||||
209 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
210 | } | - | ||||||||||||||||||||||||
211 | - | |||||||||||||||||||||||||
212 | QVariant QListModel::data(const QModelIndex &index, int role) const | - | ||||||||||||||||||||||||
213 | { | - | ||||||||||||||||||||||||
214 | if (!index.isValid() || index.row() >= items.count())
| 0 | ||||||||||||||||||||||||
215 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||
216 | return items.at(index.row())->data(role); never executed: return items.at(index.row())->data(role); | 0 | ||||||||||||||||||||||||
217 | } | - | ||||||||||||||||||||||||
218 | - | |||||||||||||||||||||||||
219 | bool QListModel::setData(const QModelIndex &index, const QVariant &value, int role) | - | ||||||||||||||||||||||||
220 | { | - | ||||||||||||||||||||||||
221 | if (!index.isValid() || index.row() >= items.count())
| 0 | ||||||||||||||||||||||||
222 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
223 | items.at(index.row())->setData(role, value); | - | ||||||||||||||||||||||||
224 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
225 | } | - | ||||||||||||||||||||||||
226 | - | |||||||||||||||||||||||||
227 | QMap<int, QVariant> QListModel::itemData(const QModelIndex &index) const | - | ||||||||||||||||||||||||
228 | { | - | ||||||||||||||||||||||||
229 | QMap<int, QVariant> roles; | - | ||||||||||||||||||||||||
230 | if (!index.isValid() || index.row() >= items.count())
| 0 | ||||||||||||||||||||||||
231 | return roles; never executed: return roles; | 0 | ||||||||||||||||||||||||
232 | QListWidgetItem *itm = items.at(index.row()); | - | ||||||||||||||||||||||||
233 | for (int i = 0; i < itm->d->values.count(); ++i) {
| 0 | ||||||||||||||||||||||||
234 | roles.insert(itm->d->values.at(i).role, | - | ||||||||||||||||||||||||
235 | itm->d->values.at(i).value); | - | ||||||||||||||||||||||||
236 | } never executed: end of block | 0 | ||||||||||||||||||||||||
237 | return roles; never executed: return roles; | 0 | ||||||||||||||||||||||||
238 | } | - | ||||||||||||||||||||||||
239 | - | |||||||||||||||||||||||||
240 | bool QListModel::insertRows(int row, int count, const QModelIndex &parent) | - | ||||||||||||||||||||||||
241 | { | - | ||||||||||||||||||||||||
242 | if (count < 1 || row < 0 || row > rowCount() || parent.isValid())
| 0 | ||||||||||||||||||||||||
243 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
244 | - | |||||||||||||||||||||||||
245 | beginInsertRows(QModelIndex(), row, row + count - 1); | - | ||||||||||||||||||||||||
246 | QListWidget *view = qobject_cast<QListWidget*>(QObject::parent()); | - | ||||||||||||||||||||||||
247 | QListWidgetItem *itm = 0; | - | ||||||||||||||||||||||||
248 | - | |||||||||||||||||||||||||
249 | for (int r = row; r < row + count; ++r) {
| 0 | ||||||||||||||||||||||||
250 | itm = new QListWidgetItem; | - | ||||||||||||||||||||||||
251 | itm->view = view; | - | ||||||||||||||||||||||||
252 | itm->d->theid = r; | - | ||||||||||||||||||||||||
253 | items.insert(r, itm); | - | ||||||||||||||||||||||||
254 | } never executed: end of block | 0 | ||||||||||||||||||||||||
255 | - | |||||||||||||||||||||||||
256 | endInsertRows(); | - | ||||||||||||||||||||||||
257 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
258 | } | - | ||||||||||||||||||||||||
259 | - | |||||||||||||||||||||||||
260 | bool QListModel::removeRows(int row, int count, const QModelIndex &parent) | - | ||||||||||||||||||||||||
261 | { | - | ||||||||||||||||||||||||
262 | if (count < 1 || row < 0 || (row + count) > rowCount() || parent.isValid())
| 0 | ||||||||||||||||||||||||
263 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
264 | - | |||||||||||||||||||||||||
265 | beginRemoveRows(QModelIndex(), row, row + count - 1); | - | ||||||||||||||||||||||||
266 | QListWidgetItem *itm = 0; | - | ||||||||||||||||||||||||
267 | for (int r = row; r < row + count; ++r) {
| 0 | ||||||||||||||||||||||||
268 | itm = items.takeAt(row); | - | ||||||||||||||||||||||||
269 | itm->view = 0; | - | ||||||||||||||||||||||||
270 | itm->d->theid = -1; | - | ||||||||||||||||||||||||
271 | delete itm; | - | ||||||||||||||||||||||||
272 | } never executed: end of block | 0 | ||||||||||||||||||||||||
273 | endRemoveRows(); | - | ||||||||||||||||||||||||
274 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
275 | } | - | ||||||||||||||||||||||||
276 | - | |||||||||||||||||||||||||
277 | Qt::ItemFlags QListModel::flags(const QModelIndex &index) const | - | ||||||||||||||||||||||||
278 | { | - | ||||||||||||||||||||||||
279 | if (!index.isValid() || index.row() >= items.count() || index.model() != this)
| 0 | ||||||||||||||||||||||||
280 | return Qt::ItemIsDropEnabled; // we allow drops outside the items never executed: return Qt::ItemIsDropEnabled; | 0 | ||||||||||||||||||||||||
281 | return items.at(index.row())->flags(); never executed: return items.at(index.row())->flags(); | 0 | ||||||||||||||||||||||||
282 | } | - | ||||||||||||||||||||||||
283 | - | |||||||||||||||||||||||||
284 | void QListModel::sort(int column, Qt::SortOrder order) | - | ||||||||||||||||||||||||
285 | { | - | ||||||||||||||||||||||||
286 | if (column != 0)
| 0 | ||||||||||||||||||||||||
287 | return; never executed: return; | 0 | ||||||||||||||||||||||||
288 | - | |||||||||||||||||||||||||
289 | emit layoutAboutToBeChanged(); | - | ||||||||||||||||||||||||
290 | - | |||||||||||||||||||||||||
291 | QVector < QPair<QListWidgetItem*,int> > sorting(items.count()); | - | ||||||||||||||||||||||||
292 | for (int i = 0; i < items.count(); ++i) {
| 0 | ||||||||||||||||||||||||
293 | QListWidgetItem *item = items.at(i); | - | ||||||||||||||||||||||||
294 | sorting[i].first = item; | - | ||||||||||||||||||||||||
295 | sorting[i].second = i; | - | ||||||||||||||||||||||||
296 | } never executed: end of block | 0 | ||||||||||||||||||||||||
297 | - | |||||||||||||||||||||||||
298 | LessThan compare = (order == Qt::AscendingOrder ? &itemLessThan : &itemGreaterThan);
| 0 | ||||||||||||||||||||||||
299 | std::sort(sorting.begin(), sorting.end(), compare); | - | ||||||||||||||||||||||||
300 | QModelIndexList fromIndexes; | - | ||||||||||||||||||||||||
301 | QModelIndexList toIndexes; | - | ||||||||||||||||||||||||
302 | const int sortingCount = sorting.count(); | - | ||||||||||||||||||||||||
303 | fromIndexes.reserve(sortingCount); | - | ||||||||||||||||||||||||
304 | toIndexes.reserve(sortingCount); | - | ||||||||||||||||||||||||
305 | for (int r = 0; r < sortingCount; ++r) {
| 0 | ||||||||||||||||||||||||
306 | QListWidgetItem *item = sorting.at(r).first; | - | ||||||||||||||||||||||||
307 | toIndexes.append(createIndex(r, 0, item)); | - | ||||||||||||||||||||||||
308 | fromIndexes.append(createIndex(sorting.at(r).second, 0, sorting.at(r).first)); | - | ||||||||||||||||||||||||
309 | items[r] = sorting.at(r).first; | - | ||||||||||||||||||||||||
310 | } never executed: end of block | 0 | ||||||||||||||||||||||||
311 | changePersistentIndexList(fromIndexes, toIndexes); | - | ||||||||||||||||||||||||
312 | - | |||||||||||||||||||||||||
313 | emit layoutChanged(); | - | ||||||||||||||||||||||||
314 | } never executed: end of block | 0 | ||||||||||||||||||||||||
315 | - | |||||||||||||||||||||||||
316 | /** | - | ||||||||||||||||||||||||
317 | * This function assumes that all items in the model except the items that are between | - | ||||||||||||||||||||||||
318 | * (inclusive) start and end are sorted. | - | ||||||||||||||||||||||||
319 | * With these assumptions, this function can ensure that the model is sorted in a | - | ||||||||||||||||||||||||
320 | * much more efficient way than doing a naive 'sort everything'. | - | ||||||||||||||||||||||||
321 | * (provided that the range is relatively small compared to the total number of items) | - | ||||||||||||||||||||||||
322 | */ | - | ||||||||||||||||||||||||
323 | void QListModel::ensureSorted(int column, Qt::SortOrder order, int start, int end) | - | ||||||||||||||||||||||||
324 | { | - | ||||||||||||||||||||||||
325 | if (column != 0)
| 0 | ||||||||||||||||||||||||
326 | return; never executed: return; | 0 | ||||||||||||||||||||||||
327 | - | |||||||||||||||||||||||||
328 | int count = end - start + 1; | - | ||||||||||||||||||||||||
329 | QVector < QPair<QListWidgetItem*,int> > sorting(count); | - | ||||||||||||||||||||||||
330 | for (int i = 0; i < count; ++i) {
| 0 | ||||||||||||||||||||||||
331 | sorting[i].first = items.at(start + i); | - | ||||||||||||||||||||||||
332 | sorting[i].second = start + i; | - | ||||||||||||||||||||||||
333 | } never executed: end of block | 0 | ||||||||||||||||||||||||
334 | - | |||||||||||||||||||||||||
335 | LessThan compare = (order == Qt::AscendingOrder ? &itemLessThan : &itemGreaterThan);
| 0 | ||||||||||||||||||||||||
336 | std::sort(sorting.begin(), sorting.end(), compare); | - | ||||||||||||||||||||||||
337 | - | |||||||||||||||||||||||||
338 | QModelIndexList oldPersistentIndexes = persistentIndexList(); | - | ||||||||||||||||||||||||
339 | QModelIndexList newPersistentIndexes = oldPersistentIndexes; | - | ||||||||||||||||||||||||
340 | QList<QListWidgetItem*> tmp = items; | - | ||||||||||||||||||||||||
341 | QList<QListWidgetItem*>::iterator lit = tmp.begin(); | - | ||||||||||||||||||||||||
342 | bool changed = false; | - | ||||||||||||||||||||||||
343 | for (int i = 0; i < count; ++i) {
| 0 | ||||||||||||||||||||||||
344 | int oldRow = sorting.at(i).second; | - | ||||||||||||||||||||||||
345 | int tmpitepos = lit - tmp.begin(); | - | ||||||||||||||||||||||||
346 | QListWidgetItem *item = tmp.takeAt(oldRow); | - | ||||||||||||||||||||||||
347 | if (tmpitepos > tmp.size())
| 0 | ||||||||||||||||||||||||
348 | --tmpitepos; never executed: --tmpitepos; | 0 | ||||||||||||||||||||||||
349 | lit = tmp.begin() + tmpitepos; | - | ||||||||||||||||||||||||
350 | lit = sortedInsertionIterator(lit, tmp.end(), order, item); | - | ||||||||||||||||||||||||
351 | int newRow = qMax(lit - tmp.begin(), 0); | - | ||||||||||||||||||||||||
352 | lit = tmp.insert(lit, item); | - | ||||||||||||||||||||||||
353 | if (newRow != oldRow) {
| 0 | ||||||||||||||||||||||||
354 | changed = true; | - | ||||||||||||||||||||||||
355 | for (int j = i + 1; j < count; ++j) {
| 0 | ||||||||||||||||||||||||
356 | int otherRow = sorting.at(j).second; | - | ||||||||||||||||||||||||
357 | if (oldRow < otherRow && newRow >= otherRow)
| 0 | ||||||||||||||||||||||||
358 | --sorting[j].second; never executed: --sorting[j].second; | 0 | ||||||||||||||||||||||||
359 | else if (oldRow > otherRow && newRow <= otherRow)
| 0 | ||||||||||||||||||||||||
360 | ++sorting[j].second; never executed: ++sorting[j].second; | 0 | ||||||||||||||||||||||||
361 | } never executed: end of block | 0 | ||||||||||||||||||||||||
362 | for (int k = 0; k < newPersistentIndexes.count(); ++k) {
| 0 | ||||||||||||||||||||||||
363 | QModelIndex pi = newPersistentIndexes.at(k); | - | ||||||||||||||||||||||||
364 | int oldPersistentRow = pi.row(); | - | ||||||||||||||||||||||||
365 | int newPersistentRow = oldPersistentRow; | - | ||||||||||||||||||||||||
366 | if (oldPersistentRow == oldRow)
| 0 | ||||||||||||||||||||||||
367 | newPersistentRow = newRow; never executed: newPersistentRow = newRow; | 0 | ||||||||||||||||||||||||
368 | else if (oldRow < oldPersistentRow && newRow >= oldPersistentRow)
| 0 | ||||||||||||||||||||||||
369 | newPersistentRow = oldPersistentRow - 1; never executed: newPersistentRow = oldPersistentRow - 1; | 0 | ||||||||||||||||||||||||
370 | else if (oldRow > oldPersistentRow && newRow <= oldPersistentRow)
| 0 | ||||||||||||||||||||||||
371 | newPersistentRow = oldPersistentRow + 1; never executed: newPersistentRow = oldPersistentRow + 1; | 0 | ||||||||||||||||||||||||
372 | if (newPersistentRow != oldPersistentRow)
| 0 | ||||||||||||||||||||||||
373 | newPersistentIndexes[k] = createIndex(newPersistentRow, never executed: newPersistentIndexes[k] = createIndex(newPersistentRow, pi.column(), pi.internalPointer()); | 0 | ||||||||||||||||||||||||
374 | pi.column(), pi.internalPointer()); never executed: newPersistentIndexes[k] = createIndex(newPersistentRow, pi.column(), pi.internalPointer()); | 0 | ||||||||||||||||||||||||
375 | } never executed: end of block | 0 | ||||||||||||||||||||||||
376 | } never executed: end of block | 0 | ||||||||||||||||||||||||
377 | } never executed: end of block | 0 | ||||||||||||||||||||||||
378 | - | |||||||||||||||||||||||||
379 | if (changed) {
| 0 | ||||||||||||||||||||||||
380 | emit layoutAboutToBeChanged(); | - | ||||||||||||||||||||||||
381 | items = tmp; | - | ||||||||||||||||||||||||
382 | changePersistentIndexList(oldPersistentIndexes, newPersistentIndexes); | - | ||||||||||||||||||||||||
383 | emit layoutChanged(); | - | ||||||||||||||||||||||||
384 | } never executed: end of block | 0 | ||||||||||||||||||||||||
385 | } never executed: end of block | 0 | ||||||||||||||||||||||||
386 | - | |||||||||||||||||||||||||
387 | bool QListModel::itemLessThan(const QPair<QListWidgetItem*,int> &left, | - | ||||||||||||||||||||||||
388 | const QPair<QListWidgetItem*,int> &right) | - | ||||||||||||||||||||||||
389 | { | - | ||||||||||||||||||||||||
390 | return (*left.first) < (*right.first); never executed: return (*left.first) < (*right.first); | 0 | ||||||||||||||||||||||||
391 | } | - | ||||||||||||||||||||||||
392 | - | |||||||||||||||||||||||||
393 | bool QListModel::itemGreaterThan(const QPair<QListWidgetItem*,int> &left, | - | ||||||||||||||||||||||||
394 | const QPair<QListWidgetItem*,int> &right) | - | ||||||||||||||||||||||||
395 | { | - | ||||||||||||||||||||||||
396 | return (*right.first) < (*left.first); never executed: return (*right.first) < (*left.first); | 0 | ||||||||||||||||||||||||
397 | } | - | ||||||||||||||||||||||||
398 | - | |||||||||||||||||||||||||
399 | QList<QListWidgetItem*>::iterator QListModel::sortedInsertionIterator( | - | ||||||||||||||||||||||||
400 | const QList<QListWidgetItem*>::iterator &begin, | - | ||||||||||||||||||||||||
401 | const QList<QListWidgetItem*>::iterator &end, | - | ||||||||||||||||||||||||
402 | Qt::SortOrder order, QListWidgetItem *item) | - | ||||||||||||||||||||||||
403 | { | - | ||||||||||||||||||||||||
404 | if (order == Qt::AscendingOrder)
| 0 | ||||||||||||||||||||||||
405 | return std::lower_bound(begin, end, item, QListModelLessThan()); never executed: return std::lower_bound(begin, end, item, QListModelLessThan()); | 0 | ||||||||||||||||||||||||
406 | return std::lower_bound(begin, end, item, QListModelGreaterThan()); never executed: return std::lower_bound(begin, end, item, QListModelGreaterThan()); | 0 | ||||||||||||||||||||||||
407 | } | - | ||||||||||||||||||||||||
408 | - | |||||||||||||||||||||||||
409 | void QListModel::itemChanged(QListWidgetItem *item) | - | ||||||||||||||||||||||||
410 | { | - | ||||||||||||||||||||||||
411 | QModelIndex idx = index(item); | - | ||||||||||||||||||||||||
412 | emit dataChanged(idx, idx); | - | ||||||||||||||||||||||||
413 | } never executed: end of block | 0 | ||||||||||||||||||||||||
414 | - | |||||||||||||||||||||||||
415 | QStringList QListModel::mimeTypes() const | - | ||||||||||||||||||||||||
416 | { | - | ||||||||||||||||||||||||
417 | const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent()); | - | ||||||||||||||||||||||||
418 | return view->mimeTypes(); never executed: return view->mimeTypes(); | 0 | ||||||||||||||||||||||||
419 | } | - | ||||||||||||||||||||||||
420 | - | |||||||||||||||||||||||||
421 | QMimeData *QListModel::internalMimeData() const | - | ||||||||||||||||||||||||
422 | { | - | ||||||||||||||||||||||||
423 | return QAbstractItemModel::mimeData(cachedIndexes); never executed: return QAbstractItemModel::mimeData(cachedIndexes); | 0 | ||||||||||||||||||||||||
424 | } | - | ||||||||||||||||||||||||
425 | - | |||||||||||||||||||||||||
426 | QMimeData *QListModel::mimeData(const QModelIndexList &indexes) const | - | ||||||||||||||||||||||||
427 | { | - | ||||||||||||||||||||||||
428 | QList<QListWidgetItem*> itemlist; | - | ||||||||||||||||||||||||
429 | const int indexesCount = indexes.count(); | - | ||||||||||||||||||||||||
430 | itemlist.reserve(indexesCount); | - | ||||||||||||||||||||||||
431 | for (int i = 0; i < indexesCount; ++i)
| 0 | ||||||||||||||||||||||||
432 | itemlist << at(indexes.at(i).row()); never executed: itemlist << at(indexes.at(i).row()); | 0 | ||||||||||||||||||||||||
433 | const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent()); | - | ||||||||||||||||||||||||
434 | - | |||||||||||||||||||||||||
435 | cachedIndexes = indexes; | - | ||||||||||||||||||||||||
436 | QMimeData *mimeData = view->mimeData(itemlist); | - | ||||||||||||||||||||||||
437 | cachedIndexes.clear(); | - | ||||||||||||||||||||||||
438 | return mimeData; never executed: return mimeData; | 0 | ||||||||||||||||||||||||
439 | } | - | ||||||||||||||||||||||||
440 | - | |||||||||||||||||||||||||
441 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
442 | bool QListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||||||||||||||
443 | int row, int column, const QModelIndex &index) | - | ||||||||||||||||||||||||
444 | { | - | ||||||||||||||||||||||||
445 | Q_UNUSED(column); | - | ||||||||||||||||||||||||
446 | QListWidget *view = qobject_cast<QListWidget*>(QObject::parent()); | - | ||||||||||||||||||||||||
447 | if (index.isValid())
| 0 | ||||||||||||||||||||||||
448 | row = index.row(); never executed: row = index.row(); | 0 | ||||||||||||||||||||||||
449 | else if (row == -1)
| 0 | ||||||||||||||||||||||||
450 | row = items.count(); never executed: row = items.count(); | 0 | ||||||||||||||||||||||||
451 | - | |||||||||||||||||||||||||
452 | return view->dropMimeData(row, data, action); never executed: return view->dropMimeData(row, data, action); | 0 | ||||||||||||||||||||||||
453 | } | - | ||||||||||||||||||||||||
454 | - | |||||||||||||||||||||||||
455 | Qt::DropActions QListModel::supportedDropActions() const | - | ||||||||||||||||||||||||
456 | { | - | ||||||||||||||||||||||||
457 | const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent()); | - | ||||||||||||||||||||||||
458 | return view->supportedDropActions(); never executed: return view->supportedDropActions(); | 0 | ||||||||||||||||||||||||
459 | } | - | ||||||||||||||||||||||||
460 | #endif // QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
461 | - | |||||||||||||||||||||||||
462 | /*! | - | ||||||||||||||||||||||||
463 | \class QListWidgetItem | - | ||||||||||||||||||||||||
464 | \brief The QListWidgetItem class provides an item for use with the | - | ||||||||||||||||||||||||
465 | QListWidget item view class. | - | ||||||||||||||||||||||||
466 | - | |||||||||||||||||||||||||
467 | \ingroup model-view | - | ||||||||||||||||||||||||
468 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
469 | - | |||||||||||||||||||||||||
470 | A QListWidgetItem represents a single item in a QListWidget. Each item can | - | ||||||||||||||||||||||||
471 | hold several pieces of information, and will display them appropriately. | - | ||||||||||||||||||||||||
472 | - | |||||||||||||||||||||||||
473 | The item view convenience classes use a classic item-based interface rather | - | ||||||||||||||||||||||||
474 | than a pure model/view approach. For a more flexible list view widget, | - | ||||||||||||||||||||||||
475 | consider using the QListView class with a standard model. | - | ||||||||||||||||||||||||
476 | - | |||||||||||||||||||||||||
477 | List items can be inserted automatically into a list, when they are | - | ||||||||||||||||||||||||
478 | constructed, by specifying the list widget: | - | ||||||||||||||||||||||||
479 | - | |||||||||||||||||||||||||
480 | \snippet qlistwidget-using/mainwindow.cpp 2 | - | ||||||||||||||||||||||||
481 | - | |||||||||||||||||||||||||
482 | Alternatively, list items can also be created without a parent widget, and | - | ||||||||||||||||||||||||
483 | later inserted into a list using QListWidget::insertItem(). | - | ||||||||||||||||||||||||
484 | - | |||||||||||||||||||||||||
485 | List items are typically used to display text() and an icon(). These are | - | ||||||||||||||||||||||||
486 | set with the setText() and setIcon() functions. The appearance of the text | - | ||||||||||||||||||||||||
487 | can be customized with setFont(), setForeground(), and setBackground(). | - | ||||||||||||||||||||||||
488 | Text in list items can be aligned using the setTextAlignment() function. | - | ||||||||||||||||||||||||
489 | Tooltips, status tips and "What's This?" help can be added to list items | - | ||||||||||||||||||||||||
490 | with setToolTip(), setStatusTip(), and setWhatsThis(). | - | ||||||||||||||||||||||||
491 | - | |||||||||||||||||||||||||
492 | By default, items are enabled, selectable, checkable, and can be the source | - | ||||||||||||||||||||||||
493 | of drag and drop operations. | - | ||||||||||||||||||||||||
494 | - | |||||||||||||||||||||||||
495 | Each item's flags can be changed by calling setFlags() with the appropriate | - | ||||||||||||||||||||||||
496 | value (see Qt::ItemFlags). Checkable items can be checked, unchecked and | - | ||||||||||||||||||||||||
497 | partially checked with the setCheckState() function. The corresponding | - | ||||||||||||||||||||||||
498 | checkState() function indicates the item's current check state. | - | ||||||||||||||||||||||||
499 | - | |||||||||||||||||||||||||
500 | The isHidden() function can be used to determine whether the item is | - | ||||||||||||||||||||||||
501 | hidden. To hide an item, use setHidden(). | - | ||||||||||||||||||||||||
502 | - | |||||||||||||||||||||||||
503 | - | |||||||||||||||||||||||||
504 | \section1 Subclassing | - | ||||||||||||||||||||||||
505 | - | |||||||||||||||||||||||||
506 | When subclassing QListWidgetItem to provide custom items, it is possible to | - | ||||||||||||||||||||||||
507 | define new types for them enabling them to be distinguished from standard | - | ||||||||||||||||||||||||
508 | items. For subclasses that require this feature, ensure that you call the | - | ||||||||||||||||||||||||
509 | base class constructor with a new type value equal to or greater than | - | ||||||||||||||||||||||||
510 | \l UserType, within \e your constructor. | - | ||||||||||||||||||||||||
511 | - | |||||||||||||||||||||||||
512 | \sa QListWidget, {Model/View Programming}, QTreeWidgetItem, QTableWidgetItem | - | ||||||||||||||||||||||||
513 | */ | - | ||||||||||||||||||||||||
514 | - | |||||||||||||||||||||||||
515 | /*! | - | ||||||||||||||||||||||||
516 | \enum QListWidgetItem::ItemType | - | ||||||||||||||||||||||||
517 | - | |||||||||||||||||||||||||
518 | This enum describes the types that are used to describe list widget items. | - | ||||||||||||||||||||||||
519 | - | |||||||||||||||||||||||||
520 | \value Type The default type for list widget items. | - | ||||||||||||||||||||||||
521 | \value UserType The minimum value for custom types. Values below UserType are | - | ||||||||||||||||||||||||
522 | reserved by Qt. | - | ||||||||||||||||||||||||
523 | - | |||||||||||||||||||||||||
524 | You can define new user types in QListWidgetItem subclasses to ensure that | - | ||||||||||||||||||||||||
525 | custom items are treated specially. | - | ||||||||||||||||||||||||
526 | - | |||||||||||||||||||||||||
527 | \sa type() | - | ||||||||||||||||||||||||
528 | */ | - | ||||||||||||||||||||||||
529 | - | |||||||||||||||||||||||||
530 | /*! | - | ||||||||||||||||||||||||
531 | \fn int QListWidgetItem::type() const | - | ||||||||||||||||||||||||
532 | - | |||||||||||||||||||||||||
533 | Returns the type passed to the QListWidgetItem constructor. | - | ||||||||||||||||||||||||
534 | */ | - | ||||||||||||||||||||||||
535 | - | |||||||||||||||||||||||||
536 | /*! | - | ||||||||||||||||||||||||
537 | \fn QListWidget *QListWidgetItem::listWidget() const | - | ||||||||||||||||||||||||
538 | - | |||||||||||||||||||||||||
539 | Returns the list widget containing the item. | - | ||||||||||||||||||||||||
540 | */ | - | ||||||||||||||||||||||||
541 | - | |||||||||||||||||||||||||
542 | /*! | - | ||||||||||||||||||||||||
543 | \fn void QListWidgetItem::setSelected(bool select) | - | ||||||||||||||||||||||||
544 | \since 4.2 | - | ||||||||||||||||||||||||
545 | - | |||||||||||||||||||||||||
546 | Sets the selected state of the item to \a select. | - | ||||||||||||||||||||||||
547 | - | |||||||||||||||||||||||||
548 | \sa isSelected() | - | ||||||||||||||||||||||||
549 | */ | - | ||||||||||||||||||||||||
550 | - | |||||||||||||||||||||||||
551 | /*! | - | ||||||||||||||||||||||||
552 | \fn bool QListWidgetItem::isSelected() const | - | ||||||||||||||||||||||||
553 | \since 4.2 | - | ||||||||||||||||||||||||
554 | - | |||||||||||||||||||||||||
555 | Returns \c true if the item is selected; otherwise returns \c false. | - | ||||||||||||||||||||||||
556 | - | |||||||||||||||||||||||||
557 | \sa setSelected() | - | ||||||||||||||||||||||||
558 | */ | - | ||||||||||||||||||||||||
559 | - | |||||||||||||||||||||||||
560 | /*! | - | ||||||||||||||||||||||||
561 | \fn void QListWidgetItem::setHidden(bool hide) | - | ||||||||||||||||||||||||
562 | \since 4.2 | - | ||||||||||||||||||||||||
563 | - | |||||||||||||||||||||||||
564 | Hides the item if \a hide is true; otherwise shows the item. | - | ||||||||||||||||||||||||
565 | - | |||||||||||||||||||||||||
566 | \sa isHidden() | - | ||||||||||||||||||||||||
567 | */ | - | ||||||||||||||||||||||||
568 | - | |||||||||||||||||||||||||
569 | /*! | - | ||||||||||||||||||||||||
570 | \fn bool QListWidgetItem::isHidden() const | - | ||||||||||||||||||||||||
571 | \since 4.2 | - | ||||||||||||||||||||||||
572 | - | |||||||||||||||||||||||||
573 | Returns \c true if the item is hidden; otherwise returns \c false. | - | ||||||||||||||||||||||||
574 | - | |||||||||||||||||||||||||
575 | \sa setHidden() | - | ||||||||||||||||||||||||
576 | */ | - | ||||||||||||||||||||||||
577 | - | |||||||||||||||||||||||||
578 | /*! | - | ||||||||||||||||||||||||
579 | \fn QListWidgetItem::QListWidgetItem(QListWidget *parent, int type) | - | ||||||||||||||||||||||||
580 | - | |||||||||||||||||||||||||
581 | Constructs an empty list widget item of the specified \a type with the | - | ||||||||||||||||||||||||
582 | given \a parent. If \a parent is not specified, the item will need to be | - | ||||||||||||||||||||||||
583 | inserted into a list widget with QListWidget::insertItem(). | - | ||||||||||||||||||||||||
584 | - | |||||||||||||||||||||||||
585 | This constructor inserts the item into the model of the parent that is | - | ||||||||||||||||||||||||
586 | passed to the constructor. If the model is sorted then the behavior of the | - | ||||||||||||||||||||||||
587 | insert is undetermined since the model will call the \c '<' operator method | - | ||||||||||||||||||||||||
588 | on the item which, at this point, is not yet constructed. To avoid the | - | ||||||||||||||||||||||||
589 | undetermined behavior, we recommend not to specify the parent and use | - | ||||||||||||||||||||||||
590 | QListWidget::insertItem() instead. | - | ||||||||||||||||||||||||
591 | - | |||||||||||||||||||||||||
592 | \sa type() | - | ||||||||||||||||||||||||
593 | */ | - | ||||||||||||||||||||||||
594 | QListWidgetItem::QListWidgetItem(QListWidget *view, int type) | - | ||||||||||||||||||||||||
595 | : rtti(type), view(view), d(new QListWidgetItemPrivate(this)), | - | ||||||||||||||||||||||||
596 | itemFlags(Qt::ItemIsSelectable | - | ||||||||||||||||||||||||
597 | |Qt::ItemIsUserCheckable | - | ||||||||||||||||||||||||
598 | |Qt::ItemIsEnabled | - | ||||||||||||||||||||||||
599 | |Qt::ItemIsDragEnabled) | - | ||||||||||||||||||||||||
600 | { | - | ||||||||||||||||||||||||
601 | if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
| 0 | ||||||||||||||||||||||||
602 | model->insert(model->rowCount(), this); never executed: model->insert(model->rowCount(), this); | 0 | ||||||||||||||||||||||||
603 | } never executed: end of block | 0 | ||||||||||||||||||||||||
604 | - | |||||||||||||||||||||||||
605 | /*! | - | ||||||||||||||||||||||||
606 | \fn QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *parent, int type) | - | ||||||||||||||||||||||||
607 | - | |||||||||||||||||||||||||
608 | Constructs an empty list widget item of the specified \a type with the | - | ||||||||||||||||||||||||
609 | given \a text and \a parent. If the parent is not specified, the item will | - | ||||||||||||||||||||||||
610 | need to be inserted into a list widget with QListWidget::insertItem(). | - | ||||||||||||||||||||||||
611 | - | |||||||||||||||||||||||||
612 | This constructor inserts the item into the model of the parent that is | - | ||||||||||||||||||||||||
613 | passed to the constructor. If the model is sorted then the behavior of the | - | ||||||||||||||||||||||||
614 | insert is undetermined since the model will call the \c '<' operator method | - | ||||||||||||||||||||||||
615 | on the item which, at this point, is not yet constructed. To avoid the | - | ||||||||||||||||||||||||
616 | undetermined behavior, we recommend not to specify the parent and use | - | ||||||||||||||||||||||||
617 | QListWidget::insertItem() instead. | - | ||||||||||||||||||||||||
618 | - | |||||||||||||||||||||||||
619 | \sa type() | - | ||||||||||||||||||||||||
620 | */ | - | ||||||||||||||||||||||||
621 | QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *view, int type) | - | ||||||||||||||||||||||||
622 | : rtti(type), view(0), d(new QListWidgetItemPrivate(this)), | - | ||||||||||||||||||||||||
623 | itemFlags(Qt::ItemIsSelectable | - | ||||||||||||||||||||||||
624 | |Qt::ItemIsUserCheckable | - | ||||||||||||||||||||||||
625 | |Qt::ItemIsEnabled | - | ||||||||||||||||||||||||
626 | |Qt::ItemIsDragEnabled) | - | ||||||||||||||||||||||||
627 | { | - | ||||||||||||||||||||||||
628 | setData(Qt::DisplayRole, text); | - | ||||||||||||||||||||||||
629 | this->view = view; | - | ||||||||||||||||||||||||
630 | if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
| 0 | ||||||||||||||||||||||||
631 | model->insert(model->rowCount(), this); never executed: model->insert(model->rowCount(), this); | 0 | ||||||||||||||||||||||||
632 | } never executed: end of block | 0 | ||||||||||||||||||||||||
633 | - | |||||||||||||||||||||||||
634 | /*! | - | ||||||||||||||||||||||||
635 | \fn QListWidgetItem::QListWidgetItem(const QIcon &icon, const QString &text, QListWidget *parent, int type) | - | ||||||||||||||||||||||||
636 | - | |||||||||||||||||||||||||
637 | Constructs an empty list widget item of the specified \a type with the | - | ||||||||||||||||||||||||
638 | given \a icon, \a text and \a parent. If the parent is not specified, the | - | ||||||||||||||||||||||||
639 | item will need to be inserted into a list widget with | - | ||||||||||||||||||||||||
640 | QListWidget::insertItem(). | - | ||||||||||||||||||||||||
641 | - | |||||||||||||||||||||||||
642 | This constructor inserts the item into the model of the parent that is | - | ||||||||||||||||||||||||
643 | passed to the constructor. If the model is sorted then the behavior of the | - | ||||||||||||||||||||||||
644 | insert is undetermined since the model will call the \c '<' operator method | - | ||||||||||||||||||||||||
645 | on the item which, at this point, is not yet constructed. To avoid the | - | ||||||||||||||||||||||||
646 | undetermined behavior, we recommend not to specify the parent and use | - | ||||||||||||||||||||||||
647 | QListWidget::insertItem() instead. | - | ||||||||||||||||||||||||
648 | - | |||||||||||||||||||||||||
649 | \sa type() | - | ||||||||||||||||||||||||
650 | */ | - | ||||||||||||||||||||||||
651 | QListWidgetItem::QListWidgetItem(const QIcon &icon,const QString &text, | - | ||||||||||||||||||||||||
652 | QListWidget *view, int type) | - | ||||||||||||||||||||||||
653 | : rtti(type), view(0), d(new QListWidgetItemPrivate(this)), | - | ||||||||||||||||||||||||
654 | itemFlags(Qt::ItemIsSelectable | - | ||||||||||||||||||||||||
655 | |Qt::ItemIsUserCheckable | - | ||||||||||||||||||||||||
656 | |Qt::ItemIsEnabled | - | ||||||||||||||||||||||||
657 | |Qt::ItemIsDragEnabled) | - | ||||||||||||||||||||||||
658 | { | - | ||||||||||||||||||||||||
659 | setData(Qt::DisplayRole, text); | - | ||||||||||||||||||||||||
660 | setData(Qt::DecorationRole, icon); | - | ||||||||||||||||||||||||
661 | this->view = view; | - | ||||||||||||||||||||||||
662 | if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
| 0 | ||||||||||||||||||||||||
663 | model->insert(model->rowCount(), this); never executed: model->insert(model->rowCount(), this); | 0 | ||||||||||||||||||||||||
664 | } never executed: end of block | 0 | ||||||||||||||||||||||||
665 | - | |||||||||||||||||||||||||
666 | /*! | - | ||||||||||||||||||||||||
667 | Destroys the list item. | - | ||||||||||||||||||||||||
668 | */ | - | ||||||||||||||||||||||||
669 | QListWidgetItem::~QListWidgetItem() | - | ||||||||||||||||||||||||
670 | { | - | ||||||||||||||||||||||||
671 | if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
| 0 | ||||||||||||||||||||||||
672 | model->remove(this); never executed: model->remove(this); | 0 | ||||||||||||||||||||||||
673 | delete d; | - | ||||||||||||||||||||||||
674 | } never executed: end of block | 0 | ||||||||||||||||||||||||
675 | - | |||||||||||||||||||||||||
676 | /*! | - | ||||||||||||||||||||||||
677 | Creates an exact copy of the item. | - | ||||||||||||||||||||||||
678 | */ | - | ||||||||||||||||||||||||
679 | QListWidgetItem *QListWidgetItem::clone() const | - | ||||||||||||||||||||||||
680 | { | - | ||||||||||||||||||||||||
681 | return new QListWidgetItem(*this); never executed: return new QListWidgetItem(*this); | 0 | ||||||||||||||||||||||||
682 | } | - | ||||||||||||||||||||||||
683 | - | |||||||||||||||||||||||||
684 | /*! | - | ||||||||||||||||||||||||
685 | Sets the data for a given \a role to the given \a value. Reimplement this | - | ||||||||||||||||||||||||
686 | function if you need extra roles or special behavior for certain roles. | - | ||||||||||||||||||||||||
687 | - | |||||||||||||||||||||||||
688 | \sa Qt::ItemDataRole, data() | - | ||||||||||||||||||||||||
689 | */ | - | ||||||||||||||||||||||||
690 | void QListWidgetItem::setData(int role, const QVariant &value) | - | ||||||||||||||||||||||||
691 | { | - | ||||||||||||||||||||||||
692 | bool found = false; | - | ||||||||||||||||||||||||
693 | role = (role == Qt::EditRole ? Qt::DisplayRole : role);
| 0 | ||||||||||||||||||||||||
694 | for (int i = 0; i < d->values.count(); ++i) {
| 0 | ||||||||||||||||||||||||
695 | if (d->values.at(i).role == role) {
| 0 | ||||||||||||||||||||||||
696 | if (d->values.at(i).value == value)
| 0 | ||||||||||||||||||||||||
697 | return; never executed: return; | 0 | ||||||||||||||||||||||||
698 | d->values[i].value = value; | - | ||||||||||||||||||||||||
699 | found = true; | - | ||||||||||||||||||||||||
700 | break; never executed: break; | 0 | ||||||||||||||||||||||||
701 | } | - | ||||||||||||||||||||||||
702 | } never executed: end of block | 0 | ||||||||||||||||||||||||
703 | if (!found)
| 0 | ||||||||||||||||||||||||
704 | d->values.append(QWidgetItemData(role, value)); never executed: d->values.append(QWidgetItemData(role, value)); | 0 | ||||||||||||||||||||||||
705 | if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
| 0 | ||||||||||||||||||||||||
706 | model->itemChanged(this); never executed: model->itemChanged(this); | 0 | ||||||||||||||||||||||||
707 | } never executed: end of block | 0 | ||||||||||||||||||||||||
708 | - | |||||||||||||||||||||||||
709 | /*! | - | ||||||||||||||||||||||||
710 | Returns the item's data for a given \a role. Reimplement this function if | - | ||||||||||||||||||||||||
711 | you need extra roles or special behavior for certain roles. | - | ||||||||||||||||||||||||
712 | - | |||||||||||||||||||||||||
713 | \sa Qt::ItemDataRole, setData() | - | ||||||||||||||||||||||||
714 | */ | - | ||||||||||||||||||||||||
715 | QVariant QListWidgetItem::data(int role) const | - | ||||||||||||||||||||||||
716 | { | - | ||||||||||||||||||||||||
717 | role = (role == Qt::EditRole ? Qt::DisplayRole : role);
| 0 | ||||||||||||||||||||||||
718 | for (int i = 0; i < d->values.count(); ++i)
| 0 | ||||||||||||||||||||||||
719 | if (d->values.at(i).role == role)
| 0 | ||||||||||||||||||||||||
720 | return d->values.at(i).value; never executed: return d->values.at(i).value; | 0 | ||||||||||||||||||||||||
721 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||
722 | } | - | ||||||||||||||||||||||||
723 | - | |||||||||||||||||||||||||
724 | /*! | - | ||||||||||||||||||||||||
725 | Returns \c true if this item's text is less then \a other item's text; | - | ||||||||||||||||||||||||
726 | otherwise returns \c false. | - | ||||||||||||||||||||||||
727 | */ | - | ||||||||||||||||||||||||
728 | bool QListWidgetItem::operator<(const QListWidgetItem &other) const | - | ||||||||||||||||||||||||
729 | { | - | ||||||||||||||||||||||||
730 | const QVariant v1 = data(Qt::DisplayRole), v2 = other.data(Qt::DisplayRole); | - | ||||||||||||||||||||||||
731 | return QAbstractItemModelPrivate::variantLessThan(v1, v2); never executed: return QAbstractItemModelPrivate::variantLessThan(v1, v2); | 0 | ||||||||||||||||||||||||
732 | } | - | ||||||||||||||||||||||||
733 | - | |||||||||||||||||||||||||
734 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
735 | - | |||||||||||||||||||||||||
736 | /*! | - | ||||||||||||||||||||||||
737 | Reads the item from stream \a in. | - | ||||||||||||||||||||||||
738 | - | |||||||||||||||||||||||||
739 | \sa write() | - | ||||||||||||||||||||||||
740 | */ | - | ||||||||||||||||||||||||
741 | void QListWidgetItem::read(QDataStream &in) | - | ||||||||||||||||||||||||
742 | { | - | ||||||||||||||||||||||||
743 | in >> d->values; | - | ||||||||||||||||||||||||
744 | } never executed: end of block | 0 | ||||||||||||||||||||||||
745 | - | |||||||||||||||||||||||||
746 | /*! | - | ||||||||||||||||||||||||
747 | Writes the item to stream \a out. | - | ||||||||||||||||||||||||
748 | - | |||||||||||||||||||||||||
749 | \sa read() | - | ||||||||||||||||||||||||
750 | */ | - | ||||||||||||||||||||||||
751 | void QListWidgetItem::write(QDataStream &out) const | - | ||||||||||||||||||||||||
752 | { | - | ||||||||||||||||||||||||
753 | out << d->values; | - | ||||||||||||||||||||||||
754 | } never executed: end of block | 0 | ||||||||||||||||||||||||
755 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
756 | - | |||||||||||||||||||||||||
757 | /*! | - | ||||||||||||||||||||||||
758 | \since 4.1 | - | ||||||||||||||||||||||||
759 | - | |||||||||||||||||||||||||
760 | Constructs a copy of \a other. Note that type() and listWidget() are not | - | ||||||||||||||||||||||||
761 | copied. | - | ||||||||||||||||||||||||
762 | - | |||||||||||||||||||||||||
763 | This function is useful when reimplementing clone(). | - | ||||||||||||||||||||||||
764 | - | |||||||||||||||||||||||||
765 | \sa data(), flags() | - | ||||||||||||||||||||||||
766 | */ | - | ||||||||||||||||||||||||
767 | QListWidgetItem::QListWidgetItem(const QListWidgetItem &other) | - | ||||||||||||||||||||||||
768 | : rtti(Type), view(0), | - | ||||||||||||||||||||||||
769 | d(new QListWidgetItemPrivate(this)), | - | ||||||||||||||||||||||||
770 | itemFlags(other.itemFlags) | - | ||||||||||||||||||||||||
771 | { | - | ||||||||||||||||||||||||
772 | d->values = other.d->values; | - | ||||||||||||||||||||||||
773 | } never executed: end of block | 0 | ||||||||||||||||||||||||
774 | - | |||||||||||||||||||||||||
775 | /*! | - | ||||||||||||||||||||||||
776 | Assigns \a other's data and flags to this item. Note that type() and | - | ||||||||||||||||||||||||
777 | listWidget() are not copied. | - | ||||||||||||||||||||||||
778 | - | |||||||||||||||||||||||||
779 | This function is useful when reimplementing clone(). | - | ||||||||||||||||||||||||
780 | - | |||||||||||||||||||||||||
781 | \sa data(), flags() | - | ||||||||||||||||||||||||
782 | */ | - | ||||||||||||||||||||||||
783 | QListWidgetItem &QListWidgetItem::operator=(const QListWidgetItem &other) | - | ||||||||||||||||||||||||
784 | { | - | ||||||||||||||||||||||||
785 | d->values = other.d->values; | - | ||||||||||||||||||||||||
786 | itemFlags = other.itemFlags; | - | ||||||||||||||||||||||||
787 | return *this; never executed: return *this; | 0 | ||||||||||||||||||||||||
788 | } | - | ||||||||||||||||||||||||
789 | - | |||||||||||||||||||||||||
790 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
791 | - | |||||||||||||||||||||||||
792 | /*! | - | ||||||||||||||||||||||||
793 | \relates QListWidgetItem | - | ||||||||||||||||||||||||
794 | - | |||||||||||||||||||||||||
795 | Writes the list widget item \a item to stream \a out. | - | ||||||||||||||||||||||||
796 | - | |||||||||||||||||||||||||
797 | This operator uses QListWidgetItem::write(). | - | ||||||||||||||||||||||||
798 | - | |||||||||||||||||||||||||
799 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||||||||
800 | */ | - | ||||||||||||||||||||||||
801 | QDataStream &operator<<(QDataStream &out, const QListWidgetItem &item) | - | ||||||||||||||||||||||||
802 | { | - | ||||||||||||||||||||||||
803 | item.write(out); | - | ||||||||||||||||||||||||
804 | return out; never executed: return out; | 0 | ||||||||||||||||||||||||
805 | } | - | ||||||||||||||||||||||||
806 | - | |||||||||||||||||||||||||
807 | /*! | - | ||||||||||||||||||||||||
808 | \relates QListWidgetItem | - | ||||||||||||||||||||||||
809 | - | |||||||||||||||||||||||||
810 | Reads a list widget item from stream \a in into \a item. | - | ||||||||||||||||||||||||
811 | - | |||||||||||||||||||||||||
812 | This operator uses QListWidgetItem::read(). | - | ||||||||||||||||||||||||
813 | - | |||||||||||||||||||||||||
814 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||||||||
815 | */ | - | ||||||||||||||||||||||||
816 | QDataStream &operator>>(QDataStream &in, QListWidgetItem &item) | - | ||||||||||||||||||||||||
817 | { | - | ||||||||||||||||||||||||
818 | item.read(in); | - | ||||||||||||||||||||||||
819 | return in; never executed: return in; | 0 | ||||||||||||||||||||||||
820 | } | - | ||||||||||||||||||||||||
821 | - | |||||||||||||||||||||||||
822 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
823 | - | |||||||||||||||||||||||||
824 | /*! | - | ||||||||||||||||||||||||
825 | \fn Qt::ItemFlags QListWidgetItem::flags() const | - | ||||||||||||||||||||||||
826 | - | |||||||||||||||||||||||||
827 | Returns the item flags for this item (see \l{Qt::ItemFlags}). | - | ||||||||||||||||||||||||
828 | */ | - | ||||||||||||||||||||||||
829 | - | |||||||||||||||||||||||||
830 | /*! | - | ||||||||||||||||||||||||
831 | \fn QString QListWidgetItem::text() const | - | ||||||||||||||||||||||||
832 | - | |||||||||||||||||||||||||
833 | Returns the list item's text. | - | ||||||||||||||||||||||||
834 | - | |||||||||||||||||||||||||
835 | \sa setText() | - | ||||||||||||||||||||||||
836 | */ | - | ||||||||||||||||||||||||
837 | - | |||||||||||||||||||||||||
838 | /*! | - | ||||||||||||||||||||||||
839 | \fn QIcon QListWidgetItem::icon() const | - | ||||||||||||||||||||||||
840 | - | |||||||||||||||||||||||||
841 | Returns the list item's icon. | - | ||||||||||||||||||||||||
842 | - | |||||||||||||||||||||||||
843 | \sa setIcon(), {QAbstractItemView::iconSize}{iconSize} | - | ||||||||||||||||||||||||
844 | */ | - | ||||||||||||||||||||||||
845 | - | |||||||||||||||||||||||||
846 | /*! | - | ||||||||||||||||||||||||
847 | \fn QString QListWidgetItem::statusTip() const | - | ||||||||||||||||||||||||
848 | - | |||||||||||||||||||||||||
849 | Returns the list item's status tip. | - | ||||||||||||||||||||||||
850 | - | |||||||||||||||||||||||||
851 | \sa setStatusTip() | - | ||||||||||||||||||||||||
852 | */ | - | ||||||||||||||||||||||||
853 | - | |||||||||||||||||||||||||
854 | /*! | - | ||||||||||||||||||||||||
855 | \fn QString QListWidgetItem::toolTip() const | - | ||||||||||||||||||||||||
856 | - | |||||||||||||||||||||||||
857 | Returns the list item's tooltip. | - | ||||||||||||||||||||||||
858 | - | |||||||||||||||||||||||||
859 | \sa setToolTip(), statusTip(), whatsThis() | - | ||||||||||||||||||||||||
860 | */ | - | ||||||||||||||||||||||||
861 | - | |||||||||||||||||||||||||
862 | /*! | - | ||||||||||||||||||||||||
863 | \fn QString QListWidgetItem::whatsThis() const | - | ||||||||||||||||||||||||
864 | - | |||||||||||||||||||||||||
865 | Returns the list item's "What's This?" help text. | - | ||||||||||||||||||||||||
866 | - | |||||||||||||||||||||||||
867 | \sa setWhatsThis(), statusTip(), toolTip() | - | ||||||||||||||||||||||||
868 | */ | - | ||||||||||||||||||||||||
869 | - | |||||||||||||||||||||||||
870 | /*! | - | ||||||||||||||||||||||||
871 | \fn QFont QListWidgetItem::font() const | - | ||||||||||||||||||||||||
872 | - | |||||||||||||||||||||||||
873 | Returns the font used to display this list item's text. | - | ||||||||||||||||||||||||
874 | */ | - | ||||||||||||||||||||||||
875 | - | |||||||||||||||||||||||||
876 | /*! | - | ||||||||||||||||||||||||
877 | \fn int QListWidgetItem::textAlignment() const | - | ||||||||||||||||||||||||
878 | - | |||||||||||||||||||||||||
879 | Returns the text alignment for the list item. | - | ||||||||||||||||||||||||
880 | - | |||||||||||||||||||||||||
881 | \sa Qt::AlignmentFlag | - | ||||||||||||||||||||||||
882 | */ | - | ||||||||||||||||||||||||
883 | - | |||||||||||||||||||||||||
884 | /*! | - | ||||||||||||||||||||||||
885 | \fn QColor QListWidgetItem::backgroundColor() const | - | ||||||||||||||||||||||||
886 | \obsolete | - | ||||||||||||||||||||||||
887 | - | |||||||||||||||||||||||||
888 | This function is deprecated. Use background() instead. | - | ||||||||||||||||||||||||
889 | */ | - | ||||||||||||||||||||||||
890 | - | |||||||||||||||||||||||||
891 | /*! | - | ||||||||||||||||||||||||
892 | \fn QBrush QListWidgetItem::background() const | - | ||||||||||||||||||||||||
893 | \since 4.2 | - | ||||||||||||||||||||||||
894 | - | |||||||||||||||||||||||||
895 | Returns the brush used to display the list item's background. | - | ||||||||||||||||||||||||
896 | - | |||||||||||||||||||||||||
897 | \sa setBackground(), foreground() | - | ||||||||||||||||||||||||
898 | */ | - | ||||||||||||||||||||||||
899 | - | |||||||||||||||||||||||||
900 | /*! | - | ||||||||||||||||||||||||
901 | \fn QColor QListWidgetItem::textColor() const | - | ||||||||||||||||||||||||
902 | \obsolete | - | ||||||||||||||||||||||||
903 | - | |||||||||||||||||||||||||
904 | Returns the color used to display the list item's text. | - | ||||||||||||||||||||||||
905 | - | |||||||||||||||||||||||||
906 | This function is deprecated. Use foreground() instead. | - | ||||||||||||||||||||||||
907 | */ | - | ||||||||||||||||||||||||
908 | - | |||||||||||||||||||||||||
909 | /*! | - | ||||||||||||||||||||||||
910 | \fn QBrush QListWidgetItem::foreground() const | - | ||||||||||||||||||||||||
911 | \since 4.2 | - | ||||||||||||||||||||||||
912 | - | |||||||||||||||||||||||||
913 | Returns the brush used to display the list item's foreground (e.g. text). | - | ||||||||||||||||||||||||
914 | - | |||||||||||||||||||||||||
915 | \sa setForeground(), background() | - | ||||||||||||||||||||||||
916 | */ | - | ||||||||||||||||||||||||
917 | - | |||||||||||||||||||||||||
918 | /*! | - | ||||||||||||||||||||||||
919 | \fn Qt::CheckState QListWidgetItem::checkState() const | - | ||||||||||||||||||||||||
920 | - | |||||||||||||||||||||||||
921 | Returns the checked state of the list item (see \l{Qt::CheckState}). | - | ||||||||||||||||||||||||
922 | - | |||||||||||||||||||||||||
923 | \sa flags() | - | ||||||||||||||||||||||||
924 | */ | - | ||||||||||||||||||||||||
925 | - | |||||||||||||||||||||||||
926 | /*! | - | ||||||||||||||||||||||||
927 | \fn QSize QListWidgetItem::sizeHint() const | - | ||||||||||||||||||||||||
928 | \since 4.1 | - | ||||||||||||||||||||||||
929 | - | |||||||||||||||||||||||||
930 | Returns the size hint set for the list item. | - | ||||||||||||||||||||||||
931 | */ | - | ||||||||||||||||||||||||
932 | - | |||||||||||||||||||||||||
933 | /*! | - | ||||||||||||||||||||||||
934 | \fn void QListWidgetItem::setSizeHint(const QSize &size) | - | ||||||||||||||||||||||||
935 | \since 4.1 | - | ||||||||||||||||||||||||
936 | - | |||||||||||||||||||||||||
937 | Sets the size hint for the list item to be \a size. If no size hint is set, | - | ||||||||||||||||||||||||
938 | the item delegate will compute the size hint based on the item data. | - | ||||||||||||||||||||||||
939 | */ | - | ||||||||||||||||||||||||
940 | - | |||||||||||||||||||||||||
941 | /*! | - | ||||||||||||||||||||||||
942 | \fn void QListWidgetItem::setFlags(Qt::ItemFlags flags) | - | ||||||||||||||||||||||||
943 | - | |||||||||||||||||||||||||
944 | Sets the item flags for the list item to \a flags. | - | ||||||||||||||||||||||||
945 | - | |||||||||||||||||||||||||
946 | \sa Qt::ItemFlags | - | ||||||||||||||||||||||||
947 | */ | - | ||||||||||||||||||||||||
948 | void QListWidgetItem::setFlags(Qt::ItemFlags aflags) { | - | ||||||||||||||||||||||||
949 | itemFlags = aflags; | - | ||||||||||||||||||||||||
950 | if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
| 0 | ||||||||||||||||||||||||
951 | model->itemChanged(this); never executed: model->itemChanged(this); | 0 | ||||||||||||||||||||||||
952 | } never executed: end of block | 0 | ||||||||||||||||||||||||
953 | - | |||||||||||||||||||||||||
954 | - | |||||||||||||||||||||||||
955 | /*! | - | ||||||||||||||||||||||||
956 | \fn void QListWidgetItem::setText(const QString &text) | - | ||||||||||||||||||||||||
957 | - | |||||||||||||||||||||||||
958 | Sets the text for the list widget item's to the given \a text. | - | ||||||||||||||||||||||||
959 | - | |||||||||||||||||||||||||
960 | \sa text() | - | ||||||||||||||||||||||||
961 | */ | - | ||||||||||||||||||||||||
962 | - | |||||||||||||||||||||||||
963 | /*! | - | ||||||||||||||||||||||||
964 | \fn void QListWidgetItem::setIcon(const QIcon &icon) | - | ||||||||||||||||||||||||
965 | - | |||||||||||||||||||||||||
966 | Sets the icon for the list item to the given \a icon. | - | ||||||||||||||||||||||||
967 | - | |||||||||||||||||||||||||
968 | \sa icon(), text(), {QAbstractItemView::iconSize}{iconSize} | - | ||||||||||||||||||||||||
969 | */ | - | ||||||||||||||||||||||||
970 | - | |||||||||||||||||||||||||
971 | /*! | - | ||||||||||||||||||||||||
972 | \fn void QListWidgetItem::setStatusTip(const QString &statusTip) | - | ||||||||||||||||||||||||
973 | - | |||||||||||||||||||||||||
974 | Sets the status tip for the list item to the text specified by | - | ||||||||||||||||||||||||
975 | \a statusTip. QListWidget mouseTracking needs to be enabled for this | - | ||||||||||||||||||||||||
976 | feature to work. | - | ||||||||||||||||||||||||
977 | - | |||||||||||||||||||||||||
978 | \sa statusTip(), setToolTip(), setWhatsThis(), QWidget::setMouseTracking() | - | ||||||||||||||||||||||||
979 | */ | - | ||||||||||||||||||||||||
980 | - | |||||||||||||||||||||||||
981 | /*! | - | ||||||||||||||||||||||||
982 | \fn void QListWidgetItem::setToolTip(const QString &toolTip) | - | ||||||||||||||||||||||||
983 | - | |||||||||||||||||||||||||
984 | Sets the tooltip for the list item to the text specified by \a toolTip. | - | ||||||||||||||||||||||||
985 | - | |||||||||||||||||||||||||
986 | \sa toolTip(), setStatusTip(), setWhatsThis() | - | ||||||||||||||||||||||||
987 | */ | - | ||||||||||||||||||||||||
988 | - | |||||||||||||||||||||||||
989 | /*! | - | ||||||||||||||||||||||||
990 | \fn void QListWidgetItem::setWhatsThis(const QString &whatsThis) | - | ||||||||||||||||||||||||
991 | - | |||||||||||||||||||||||||
992 | Sets the "What's This?" help for the list item to the text specified by | - | ||||||||||||||||||||||||
993 | \a whatsThis. | - | ||||||||||||||||||||||||
994 | - | |||||||||||||||||||||||||
995 | \sa whatsThis(), setStatusTip(), setToolTip() | - | ||||||||||||||||||||||||
996 | */ | - | ||||||||||||||||||||||||
997 | - | |||||||||||||||||||||||||
998 | /*! | - | ||||||||||||||||||||||||
999 | \fn void QListWidgetItem::setFont(const QFont &font) | - | ||||||||||||||||||||||||
1000 | - | |||||||||||||||||||||||||
1001 | Sets the font used when painting the item to the given \a font. | - | ||||||||||||||||||||||||
1002 | */ | - | ||||||||||||||||||||||||
1003 | - | |||||||||||||||||||||||||
1004 | /*! | - | ||||||||||||||||||||||||
1005 | \fn void QListWidgetItem::setTextAlignment(int alignment) | - | ||||||||||||||||||||||||
1006 | - | |||||||||||||||||||||||||
1007 | Sets the list item's text alignment to \a alignment. | - | ||||||||||||||||||||||||
1008 | - | |||||||||||||||||||||||||
1009 | \sa Qt::AlignmentFlag | - | ||||||||||||||||||||||||
1010 | */ | - | ||||||||||||||||||||||||
1011 | - | |||||||||||||||||||||||||
1012 | /*! | - | ||||||||||||||||||||||||
1013 | \fn void QListWidgetItem::setBackgroundColor(const QColor &color) | - | ||||||||||||||||||||||||
1014 | \obsolete | - | ||||||||||||||||||||||||
1015 | - | |||||||||||||||||||||||||
1016 | This function is deprecated. Use setBackground() instead. | - | ||||||||||||||||||||||||
1017 | */ | - | ||||||||||||||||||||||||
1018 | - | |||||||||||||||||||||||||
1019 | /*! | - | ||||||||||||||||||||||||
1020 | \fn void QListWidgetItem::setBackground(const QBrush &brush) | - | ||||||||||||||||||||||||
1021 | \since 4.2 | - | ||||||||||||||||||||||||
1022 | - | |||||||||||||||||||||||||
1023 | Sets the background brush of the list item to the given \a brush. | - | ||||||||||||||||||||||||
1024 | - | |||||||||||||||||||||||||
1025 | \sa background(), setForeground() | - | ||||||||||||||||||||||||
1026 | */ | - | ||||||||||||||||||||||||
1027 | - | |||||||||||||||||||||||||
1028 | /*! | - | ||||||||||||||||||||||||
1029 | \fn void QListWidgetItem::setTextColor(const QColor &color) | - | ||||||||||||||||||||||||
1030 | \obsolete | - | ||||||||||||||||||||||||
1031 | - | |||||||||||||||||||||||||
1032 | This function is deprecated. Use setForeground() instead. | - | ||||||||||||||||||||||||
1033 | */ | - | ||||||||||||||||||||||||
1034 | - | |||||||||||||||||||||||||
1035 | /*! | - | ||||||||||||||||||||||||
1036 | \fn void QListWidgetItem::setForeground(const QBrush &brush) | - | ||||||||||||||||||||||||
1037 | \since 4.2 | - | ||||||||||||||||||||||||
1038 | - | |||||||||||||||||||||||||
1039 | Sets the foreground brush of the list item to the given \a brush. | - | ||||||||||||||||||||||||
1040 | - | |||||||||||||||||||||||||
1041 | \sa foreground(), setBackground() | - | ||||||||||||||||||||||||
1042 | */ | - | ||||||||||||||||||||||||
1043 | - | |||||||||||||||||||||||||
1044 | /*! | - | ||||||||||||||||||||||||
1045 | \fn void QListWidgetItem::setCheckState(Qt::CheckState state) | - | ||||||||||||||||||||||||
1046 | - | |||||||||||||||||||||||||
1047 | Sets the check state of the list item to \a state. | - | ||||||||||||||||||||||||
1048 | - | |||||||||||||||||||||||||
1049 | \sa checkState() | - | ||||||||||||||||||||||||
1050 | */ | - | ||||||||||||||||||||||||
1051 | - | |||||||||||||||||||||||||
1052 | void QListWidgetPrivate::setup() | - | ||||||||||||||||||||||||
1053 | { | - | ||||||||||||||||||||||||
1054 | Q_Q(QListWidget); | - | ||||||||||||||||||||||||
1055 | q->QListView::setModel(new QListModel(q)); | - | ||||||||||||||||||||||||
1056 | // view signals | - | ||||||||||||||||||||||||
1057 | QObject::connect(q, SIGNAL(pressed(QModelIndex)), q, SLOT(_q_emitItemPressed(QModelIndex))); | - | ||||||||||||||||||||||||
1058 | QObject::connect(q, SIGNAL(clicked(QModelIndex)), q, SLOT(_q_emitItemClicked(QModelIndex))); | - | ||||||||||||||||||||||||
1059 | QObject::connect(q, SIGNAL(doubleClicked(QModelIndex)), | - | ||||||||||||||||||||||||
1060 | q, SLOT(_q_emitItemDoubleClicked(QModelIndex))); | - | ||||||||||||||||||||||||
1061 | QObject::connect(q, SIGNAL(activated(QModelIndex)), | - | ||||||||||||||||||||||||
1062 | q, SLOT(_q_emitItemActivated(QModelIndex))); | - | ||||||||||||||||||||||||
1063 | QObject::connect(q, SIGNAL(entered(QModelIndex)), q, SLOT(_q_emitItemEntered(QModelIndex))); | - | ||||||||||||||||||||||||
1064 | QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||||||||
1065 | q, SLOT(_q_emitItemChanged(QModelIndex))); | - | ||||||||||||||||||||||||
1066 | QObject::connect(q->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||||||||
1067 | q, SLOT(_q_emitCurrentItemChanged(QModelIndex,QModelIndex))); | - | ||||||||||||||||||||||||
1068 | QObject::connect(q->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), | - | ||||||||||||||||||||||||
1069 | q, SIGNAL(itemSelectionChanged())); | - | ||||||||||||||||||||||||
1070 | QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||||||||
1071 | q, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); | - | ||||||||||||||||||||||||
1072 | QObject::connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), q, SLOT(_q_sort())); | - | ||||||||||||||||||||||||
1073 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1074 | - | |||||||||||||||||||||||||
1075 | void QListWidgetPrivate::_q_emitItemPressed(const QModelIndex &index) | - | ||||||||||||||||||||||||
1076 | { | - | ||||||||||||||||||||||||
1077 | Q_Q(QListWidget); | - | ||||||||||||||||||||||||
1078 | emit q->itemPressed(listModel()->at(index.row())); | - | ||||||||||||||||||||||||
1079 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1080 | - | |||||||||||||||||||||||||
1081 | void QListWidgetPrivate::_q_emitItemClicked(const QModelIndex &index) | - | ||||||||||||||||||||||||
1082 | { | - | ||||||||||||||||||||||||
1083 | Q_Q(QListWidget); | - | ||||||||||||||||||||||||
1084 | emit q->itemClicked(listModel()->at(index.row())); | - | ||||||||||||||||||||||||
1085 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1086 | - | |||||||||||||||||||||||||
1087 | void QListWidgetPrivate::_q_emitItemDoubleClicked(const QModelIndex &index) | - | ||||||||||||||||||||||||
1088 | { | - | ||||||||||||||||||||||||
1089 | Q_Q(QListWidget); | - | ||||||||||||||||||||||||
1090 | emit q->itemDoubleClicked(listModel()->at(index.row())); | - | ||||||||||||||||||||||||
1091 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1092 | - | |||||||||||||||||||||||||
1093 | void QListWidgetPrivate::_q_emitItemActivated(const QModelIndex &index) | - | ||||||||||||||||||||||||
1094 | { | - | ||||||||||||||||||||||||
1095 | Q_Q(QListWidget); | - | ||||||||||||||||||||||||
1096 | emit q->itemActivated(listModel()->at(index.row())); | - | ||||||||||||||||||||||||
1097 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1098 | - | |||||||||||||||||||||||||
1099 | void QListWidgetPrivate::_q_emitItemEntered(const QModelIndex &index) | - | ||||||||||||||||||||||||
1100 | { | - | ||||||||||||||||||||||||
1101 | Q_Q(QListWidget); | - | ||||||||||||||||||||||||
1102 | emit q->itemEntered(listModel()->at(index.row())); | - | ||||||||||||||||||||||||
1103 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1104 | - | |||||||||||||||||||||||||
1105 | void QListWidgetPrivate::_q_emitItemChanged(const QModelIndex &index) | - | ||||||||||||||||||||||||
1106 | { | - | ||||||||||||||||||||||||
1107 | Q_Q(QListWidget); | - | ||||||||||||||||||||||||
1108 | emit q->itemChanged(listModel()->at(index.row())); | - | ||||||||||||||||||||||||
1109 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1110 | - | |||||||||||||||||||||||||
1111 | void QListWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex ¤t, | - | ||||||||||||||||||||||||
1112 | const QModelIndex &previous) | - | ||||||||||||||||||||||||
1113 | { | - | ||||||||||||||||||||||||
1114 | Q_Q(QListWidget); | - | ||||||||||||||||||||||||
1115 | QPersistentModelIndex persistentCurrent = current; | - | ||||||||||||||||||||||||
1116 | QListWidgetItem *currentItem = listModel()->at(persistentCurrent.row()); | - | ||||||||||||||||||||||||
1117 | emit q->currentItemChanged(currentItem, listModel()->at(previous.row())); | - | ||||||||||||||||||||||||
1118 | - | |||||||||||||||||||||||||
1119 | //persistentCurrent is invalid if something changed the model in response | - | ||||||||||||||||||||||||
1120 | //to the currentItemChanged signal emission and the item was removed | - | ||||||||||||||||||||||||
1121 | if (!persistentCurrent.isValid()) {
| 0 | ||||||||||||||||||||||||
1122 | currentItem = 0; | - | ||||||||||||||||||||||||
1123 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1124 | - | |||||||||||||||||||||||||
1125 | emit q->currentTextChanged(currentItem ? currentItem->text() : QString()); | - | ||||||||||||||||||||||||
1126 | emit q->currentRowChanged(persistentCurrent.row()); | - | ||||||||||||||||||||||||
1127 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1128 | - | |||||||||||||||||||||||||
1129 | void QListWidgetPrivate::_q_sort() | - | ||||||||||||||||||||||||
1130 | { | - | ||||||||||||||||||||||||
1131 | if (sortingEnabled)
| 0 | ||||||||||||||||||||||||
1132 | model->sort(0, sortOrder); never executed: model->sort(0, sortOrder); | 0 | ||||||||||||||||||||||||
1133 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1134 | - | |||||||||||||||||||||||||
1135 | void QListWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft, | - | ||||||||||||||||||||||||
1136 | const QModelIndex &bottomRight) | - | ||||||||||||||||||||||||
1137 | { | - | ||||||||||||||||||||||||
1138 | if (sortingEnabled && topLeft.isValid() && bottomRight.isValid())
| 0 | ||||||||||||||||||||||||
1139 | listModel()->ensureSorted(topLeft.column(), sortOrder, never executed: listModel()->ensureSorted(topLeft.column(), sortOrder, topLeft.row(), bottomRight.row()); | 0 | ||||||||||||||||||||||||
1140 | topLeft.row(), bottomRight.row()); never executed: listModel()->ensureSorted(topLeft.column(), sortOrder, topLeft.row(), bottomRight.row()); | 0 | ||||||||||||||||||||||||
1141 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1142 | - | |||||||||||||||||||||||||
1143 | /*! | - | ||||||||||||||||||||||||
1144 | \class QListWidget | - | ||||||||||||||||||||||||
1145 | \brief The QListWidget class provides an item-based list widget. | - | ||||||||||||||||||||||||
1146 | - | |||||||||||||||||||||||||
1147 | \ingroup model-view | - | ||||||||||||||||||||||||
1148 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
1149 | - | |||||||||||||||||||||||||
1150 | QListWidget is a convenience class that provides a list view similar to the | - | ||||||||||||||||||||||||
1151 | one supplied by QListView, but with a classic item-based interface for | - | ||||||||||||||||||||||||
1152 | adding and removing items. QListWidget uses an internal model to manage | - | ||||||||||||||||||||||||
1153 | each QListWidgetItem in the list. | - | ||||||||||||||||||||||||
1154 | - | |||||||||||||||||||||||||
1155 | For a more flexible list view widget, use the QListView class with a | - | ||||||||||||||||||||||||
1156 | standard model. | - | ||||||||||||||||||||||||
1157 | - | |||||||||||||||||||||||||
1158 | List widgets are constructed in the same way as other widgets: | - | ||||||||||||||||||||||||
1159 | - | |||||||||||||||||||||||||
1160 | \snippet qlistwidget-using/mainwindow.cpp 0 | - | ||||||||||||||||||||||||
1161 | - | |||||||||||||||||||||||||
1162 | The selectionMode() of a list widget determines how many of the items in | - | ||||||||||||||||||||||||
1163 | the list can be selected at the same time, and whether complex selections | - | ||||||||||||||||||||||||
1164 | of items can be created. This can be set with the setSelectionMode() | - | ||||||||||||||||||||||||
1165 | function. | - | ||||||||||||||||||||||||
1166 | - | |||||||||||||||||||||||||
1167 | There are two ways to add items to the list: they can be constructed with | - | ||||||||||||||||||||||||
1168 | the list widget as their parent widget, or they can be constructed with no | - | ||||||||||||||||||||||||
1169 | parent widget and added to the list later. If a list widget already exists | - | ||||||||||||||||||||||||
1170 | when the items are constructed, the first method is easier to use: | - | ||||||||||||||||||||||||
1171 | - | |||||||||||||||||||||||||
1172 | \snippet qlistwidget-using/mainwindow.cpp 1 | - | ||||||||||||||||||||||||
1173 | - | |||||||||||||||||||||||||
1174 | If you need to insert a new item into the list at a particular position, | - | ||||||||||||||||||||||||
1175 | then it should be constructed without a parent widget. The insertItem() | - | ||||||||||||||||||||||||
1176 | function should then be used to place it within the list. The list widget | - | ||||||||||||||||||||||||
1177 | will take ownership of the item. | - | ||||||||||||||||||||||||
1178 | - | |||||||||||||||||||||||||
1179 | \snippet qlistwidget-using/mainwindow.cpp 6 | - | ||||||||||||||||||||||||
1180 | \snippet qlistwidget-using/mainwindow.cpp 7 | - | ||||||||||||||||||||||||
1181 | - | |||||||||||||||||||||||||
1182 | For multiple items, insertItems() can be used instead. The number of items | - | ||||||||||||||||||||||||
1183 | in the list is found with the count() function. To remove items from the | - | ||||||||||||||||||||||||
1184 | list, use takeItem(). | - | ||||||||||||||||||||||||
1185 | - | |||||||||||||||||||||||||
1186 | The current item in the list can be found with currentItem(), and changed | - | ||||||||||||||||||||||||
1187 | with setCurrentItem(). The user can also change the current item by | - | ||||||||||||||||||||||||
1188 | navigating with the keyboard or clicking on a different item. When the | - | ||||||||||||||||||||||||
1189 | current item changes, the currentItemChanged() signal is emitted with the | - | ||||||||||||||||||||||||
1190 | new current item and the item that was previously current. | - | ||||||||||||||||||||||||
1191 | - | |||||||||||||||||||||||||
1192 | \table 100% | - | ||||||||||||||||||||||||
1193 | \row \li \inlineimage windowsvista-listview.png Screenshot of a Windows Vista style list widget | - | ||||||||||||||||||||||||
1194 | \li \inlineimage macintosh-listview.png Screenshot of a Macintosh style table widget | - | ||||||||||||||||||||||||
1195 | \li \inlineimage fusion-listview.png Screenshot of a Fusion style table widget | - | ||||||||||||||||||||||||
1196 | \row \li A \l{Windows Vista Style Widget Gallery}{Windows Vista style} list widget. | - | ||||||||||||||||||||||||
1197 | \li A \l{Macintosh Style Widget Gallery}{Macintosh style} list widget. | - | ||||||||||||||||||||||||
1198 | \li A \l{Fusion Style Widget Gallery}{Fusion style} list widget. | - | ||||||||||||||||||||||||
1199 | \endtable | - | ||||||||||||||||||||||||
1200 | - | |||||||||||||||||||||||||
1201 | \sa QListWidgetItem, QListView, QTreeView, {Model/View Programming}, | - | ||||||||||||||||||||||||
1202 | {Config Dialog Example} | - | ||||||||||||||||||||||||
1203 | */ | - | ||||||||||||||||||||||||
1204 | - | |||||||||||||||||||||||||
1205 | /*! | - | ||||||||||||||||||||||||
1206 | \fn void QListWidget::addItem(QListWidgetItem *item) | - | ||||||||||||||||||||||||
1207 | - | |||||||||||||||||||||||||
1208 | Inserts the \a item at the end of the list widget. | - | ||||||||||||||||||||||||
1209 | - | |||||||||||||||||||||||||
1210 | \warning A QListWidgetItem can only be added to a QListWidget once. Adding | - | ||||||||||||||||||||||||
1211 | the same QListWidgetItem multiple times to a QListWidget will result in | - | ||||||||||||||||||||||||
1212 | undefined behavior. | - | ||||||||||||||||||||||||
1213 | - | |||||||||||||||||||||||||
1214 | \sa insertItem() | - | ||||||||||||||||||||||||
1215 | */ | - | ||||||||||||||||||||||||
1216 | - | |||||||||||||||||||||||||
1217 | /*! | - | ||||||||||||||||||||||||
1218 | \fn void QListWidget::addItem(const QString &label) | - | ||||||||||||||||||||||||
1219 | - | |||||||||||||||||||||||||
1220 | Inserts an item with the text \a label at the end of the list widget. | - | ||||||||||||||||||||||||
1221 | */ | - | ||||||||||||||||||||||||
1222 | - | |||||||||||||||||||||||||
1223 | /*! | - | ||||||||||||||||||||||||
1224 | \fn void QListWidget::addItems(const QStringList &labels) | - | ||||||||||||||||||||||||
1225 | - | |||||||||||||||||||||||||
1226 | Inserts items with the text \a labels at the end of the list widget. | - | ||||||||||||||||||||||||
1227 | - | |||||||||||||||||||||||||
1228 | \sa insertItems() | - | ||||||||||||||||||||||||
1229 | */ | - | ||||||||||||||||||||||||
1230 | - | |||||||||||||||||||||||||
1231 | /*! | - | ||||||||||||||||||||||||
1232 | \fn void QListWidget::itemPressed(QListWidgetItem *item) | - | ||||||||||||||||||||||||
1233 | - | |||||||||||||||||||||||||
1234 | This signal is emitted with the specified \a item when a mouse button is | - | ||||||||||||||||||||||||
1235 | pressed on an item in the widget. | - | ||||||||||||||||||||||||
1236 | - | |||||||||||||||||||||||||
1237 | \sa itemClicked(), itemDoubleClicked() | - | ||||||||||||||||||||||||
1238 | */ | - | ||||||||||||||||||||||||
1239 | - | |||||||||||||||||||||||||
1240 | /*! | - | ||||||||||||||||||||||||
1241 | \fn void QListWidget::itemClicked(QListWidgetItem *item) | - | ||||||||||||||||||||||||
1242 | - | |||||||||||||||||||||||||
1243 | This signal is emitted with the specified \a item when a mouse button is | - | ||||||||||||||||||||||||
1244 | clicked on an item in the widget. | - | ||||||||||||||||||||||||
1245 | - | |||||||||||||||||||||||||
1246 | \sa itemPressed(), itemDoubleClicked() | - | ||||||||||||||||||||||||
1247 | */ | - | ||||||||||||||||||||||||
1248 | - | |||||||||||||||||||||||||
1249 | /*! | - | ||||||||||||||||||||||||
1250 | \fn void QListWidget::itemDoubleClicked(QListWidgetItem *item) | - | ||||||||||||||||||||||||
1251 | - | |||||||||||||||||||||||||
1252 | This signal is emitted with the specified \a item when a mouse button is | - | ||||||||||||||||||||||||
1253 | double clicked on an item in the widget. | - | ||||||||||||||||||||||||
1254 | - | |||||||||||||||||||||||||
1255 | \sa itemClicked(), itemPressed() | - | ||||||||||||||||||||||||
1256 | */ | - | ||||||||||||||||||||||||
1257 | - | |||||||||||||||||||||||||
1258 | /*! | - | ||||||||||||||||||||||||
1259 | \fn void QListWidget::itemActivated(QListWidgetItem *item) | - | ||||||||||||||||||||||||
1260 | - | |||||||||||||||||||||||||
1261 | This signal is emitted when the \a item is activated. The \a item is | - | ||||||||||||||||||||||||
1262 | activated when the user clicks or double clicks on it, depending on the | - | ||||||||||||||||||||||||
1263 | system configuration. It is also activated when the user presses the | - | ||||||||||||||||||||||||
1264 | activation key (on Windows and X11 this is the \uicontrol Return key, on Mac OS | - | ||||||||||||||||||||||||
1265 | X it is \uicontrol{Command+O}). | - | ||||||||||||||||||||||||
1266 | */ | - | ||||||||||||||||||||||||
1267 | - | |||||||||||||||||||||||||
1268 | /*! | - | ||||||||||||||||||||||||
1269 | \fn void QListWidget::itemEntered(QListWidgetItem *item) | - | ||||||||||||||||||||||||
1270 | - | |||||||||||||||||||||||||
1271 | This signal is emitted when the mouse cursor enters an item. The \a item is | - | ||||||||||||||||||||||||
1272 | the item entered. This signal is only emitted when mouseTracking is turned | - | ||||||||||||||||||||||||
1273 | on, or when a mouse button is pressed while moving into an item. | - | ||||||||||||||||||||||||
1274 | - | |||||||||||||||||||||||||
1275 | \sa QWidget::setMouseTracking() | - | ||||||||||||||||||||||||
1276 | */ | - | ||||||||||||||||||||||||
1277 | - | |||||||||||||||||||||||||
1278 | /*! | - | ||||||||||||||||||||||||
1279 | \fn void QListWidget::itemChanged(QListWidgetItem *item) | - | ||||||||||||||||||||||||
1280 | - | |||||||||||||||||||||||||
1281 | This signal is emitted whenever the data of \a item has changed. | - | ||||||||||||||||||||||||
1282 | */ | - | ||||||||||||||||||||||||
1283 | - | |||||||||||||||||||||||||
1284 | /*! | - | ||||||||||||||||||||||||
1285 | \fn void QListWidget::currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) | - | ||||||||||||||||||||||||
1286 | - | |||||||||||||||||||||||||
1287 | This signal is emitted whenever the current item changes. | - | ||||||||||||||||||||||||
1288 | - | |||||||||||||||||||||||||
1289 | \a previous is the item that previously had the focus; \a current is the | - | ||||||||||||||||||||||||
1290 | new current item. | - | ||||||||||||||||||||||||
1291 | */ | - | ||||||||||||||||||||||||
1292 | - | |||||||||||||||||||||||||
1293 | /*! | - | ||||||||||||||||||||||||
1294 | \fn void QListWidget::currentTextChanged(const QString ¤tText) | - | ||||||||||||||||||||||||
1295 | - | |||||||||||||||||||||||||
1296 | This signal is emitted whenever the current item changes. | - | ||||||||||||||||||||||||
1297 | - | |||||||||||||||||||||||||
1298 | \a currentText is the text data in the current item. If there is no current | - | ||||||||||||||||||||||||
1299 | item, the \a currentText is invalid. | - | ||||||||||||||||||||||||
1300 | */ | - | ||||||||||||||||||||||||
1301 | - | |||||||||||||||||||||||||
1302 | /*! | - | ||||||||||||||||||||||||
1303 | \fn void QListWidget::currentRowChanged(int currentRow) | - | ||||||||||||||||||||||||
1304 | - | |||||||||||||||||||||||||
1305 | This signal is emitted whenever the current item changes. | - | ||||||||||||||||||||||||
1306 | - | |||||||||||||||||||||||||
1307 | \a currentRow is the row of the current item. If there is no current item, | - | ||||||||||||||||||||||||
1308 | the \a currentRow is -1. | - | ||||||||||||||||||||||||
1309 | */ | - | ||||||||||||||||||||||||
1310 | - | |||||||||||||||||||||||||
1311 | /*! | - | ||||||||||||||||||||||||
1312 | \fn void QListWidget::itemSelectionChanged() | - | ||||||||||||||||||||||||
1313 | - | |||||||||||||||||||||||||
1314 | This signal is emitted whenever the selection changes. | - | ||||||||||||||||||||||||
1315 | - | |||||||||||||||||||||||||
1316 | \sa selectedItems(), QListWidgetItem::isSelected(), currentItemChanged() | - | ||||||||||||||||||||||||
1317 | */ | - | ||||||||||||||||||||||||
1318 | - | |||||||||||||||||||||||||
1319 | /*! | - | ||||||||||||||||||||||||
1320 | \since 4.3 | - | ||||||||||||||||||||||||
1321 | - | |||||||||||||||||||||||||
1322 | \fn void QListWidget::removeItemWidget(QListWidgetItem *item) | - | ||||||||||||||||||||||||
1323 | - | |||||||||||||||||||||||||
1324 | Removes the widget set on the given \a item. | - | ||||||||||||||||||||||||
1325 | - | |||||||||||||||||||||||||
1326 | To remove an item (row) from the list entirely, either delete the item or | - | ||||||||||||||||||||||||
1327 | use takeItem(). | - | ||||||||||||||||||||||||
1328 | - | |||||||||||||||||||||||||
1329 | \sa itemWidget(), setItemWidget() | - | ||||||||||||||||||||||||
1330 | */ | - | ||||||||||||||||||||||||
1331 | - | |||||||||||||||||||||||||
1332 | /*! | - | ||||||||||||||||||||||||
1333 | Constructs an empty QListWidget with the given \a parent. | - | ||||||||||||||||||||||||
1334 | */ | - | ||||||||||||||||||||||||
1335 | - | |||||||||||||||||||||||||
1336 | QListWidget::QListWidget(QWidget *parent) | - | ||||||||||||||||||||||||
1337 | : QListView(*new QListWidgetPrivate(), parent) | - | ||||||||||||||||||||||||
1338 | { | - | ||||||||||||||||||||||||
1339 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1340 | d->setup(); | - | ||||||||||||||||||||||||
1341 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1342 | - | |||||||||||||||||||||||||
1343 | /*! | - | ||||||||||||||||||||||||
1344 | Destroys the list widget and all its items. | - | ||||||||||||||||||||||||
1345 | */ | - | ||||||||||||||||||||||||
1346 | - | |||||||||||||||||||||||||
1347 | QListWidget::~QListWidget() | - | ||||||||||||||||||||||||
1348 | { | - | ||||||||||||||||||||||||
1349 | } | - | ||||||||||||||||||||||||
1350 | - | |||||||||||||||||||||||||
1351 | /*! | - | ||||||||||||||||||||||||
1352 | Returns the item that occupies the given \a row in the list if one has been | - | ||||||||||||||||||||||||
1353 | set; otherwise returns 0. | - | ||||||||||||||||||||||||
1354 | - | |||||||||||||||||||||||||
1355 | \sa row() | - | ||||||||||||||||||||||||
1356 | */ | - | ||||||||||||||||||||||||
1357 | - | |||||||||||||||||||||||||
1358 | QListWidgetItem *QListWidget::item(int row) const | - | ||||||||||||||||||||||||
1359 | { | - | ||||||||||||||||||||||||
1360 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1361 | if (row < 0 || row >= d->model->rowCount())
| 0 | ||||||||||||||||||||||||
1362 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1363 | return d->listModel()->at(row); never executed: return d->listModel()->at(row); | 0 | ||||||||||||||||||||||||
1364 | } | - | ||||||||||||||||||||||||
1365 | - | |||||||||||||||||||||||||
1366 | /*! | - | ||||||||||||||||||||||||
1367 | Returns the row containing the given \a item. | - | ||||||||||||||||||||||||
1368 | - | |||||||||||||||||||||||||
1369 | \sa item() | - | ||||||||||||||||||||||||
1370 | */ | - | ||||||||||||||||||||||||
1371 | - | |||||||||||||||||||||||||
1372 | int QListWidget::row(const QListWidgetItem *item) const | - | ||||||||||||||||||||||||
1373 | { | - | ||||||||||||||||||||||||
1374 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1375 | return d->listModel()->index(const_cast<QListWidgetItem*>(item)).row(); never executed: return d->listModel()->index(const_cast<QListWidgetItem*>(item)).row(); | 0 | ||||||||||||||||||||||||
1376 | } | - | ||||||||||||||||||||||||
1377 | - | |||||||||||||||||||||||||
1378 | - | |||||||||||||||||||||||||
1379 | /*! | - | ||||||||||||||||||||||||
1380 | Inserts the \a item at the position in the list given by \a row. | - | ||||||||||||||||||||||||
1381 | - | |||||||||||||||||||||||||
1382 | \sa addItem() | - | ||||||||||||||||||||||||
1383 | */ | - | ||||||||||||||||||||||||
1384 | - | |||||||||||||||||||||||||
1385 | void QListWidget::insertItem(int row, QListWidgetItem *item) | - | ||||||||||||||||||||||||
1386 | { | - | ||||||||||||||||||||||||
1387 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1388 | if (item && !item->view)
| 0 | ||||||||||||||||||||||||
1389 | d->listModel()->insert(row, item); never executed: d->listModel()->insert(row, item); | 0 | ||||||||||||||||||||||||
1390 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1391 | - | |||||||||||||||||||||||||
1392 | /*! | - | ||||||||||||||||||||||||
1393 | Inserts an item with the text \a label in the list widget at the position | - | ||||||||||||||||||||||||
1394 | given by \a row. | - | ||||||||||||||||||||||||
1395 | - | |||||||||||||||||||||||||
1396 | \sa addItem() | - | ||||||||||||||||||||||||
1397 | */ | - | ||||||||||||||||||||||||
1398 | - | |||||||||||||||||||||||||
1399 | void QListWidget::insertItem(int row, const QString &label) | - | ||||||||||||||||||||||||
1400 | { | - | ||||||||||||||||||||||||
1401 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1402 | d->listModel()->insert(row, new QListWidgetItem(label)); | - | ||||||||||||||||||||||||
1403 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1404 | - | |||||||||||||||||||||||||
1405 | /*! | - | ||||||||||||||||||||||||
1406 | Inserts items from the list of \a labels into the list, starting at the | - | ||||||||||||||||||||||||
1407 | given \a row. | - | ||||||||||||||||||||||||
1408 | - | |||||||||||||||||||||||||
1409 | \sa insertItem(), addItem() | - | ||||||||||||||||||||||||
1410 | */ | - | ||||||||||||||||||||||||
1411 | - | |||||||||||||||||||||||||
1412 | void QListWidget::insertItems(int row, const QStringList &labels) | - | ||||||||||||||||||||||||
1413 | { | - | ||||||||||||||||||||||||
1414 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1415 | d->listModel()->insert(row, labels); | - | ||||||||||||||||||||||||
1416 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1417 | - | |||||||||||||||||||||||||
1418 | /*! | - | ||||||||||||||||||||||||
1419 | Removes and returns the item from the given \a row in the list widget; | - | ||||||||||||||||||||||||
1420 | otherwise returns 0. | - | ||||||||||||||||||||||||
1421 | - | |||||||||||||||||||||||||
1422 | Items removed from a list widget will not be managed by Qt, and will need | - | ||||||||||||||||||||||||
1423 | to be deleted manually. | - | ||||||||||||||||||||||||
1424 | - | |||||||||||||||||||||||||
1425 | \sa insertItem(), addItem() | - | ||||||||||||||||||||||||
1426 | */ | - | ||||||||||||||||||||||||
1427 | - | |||||||||||||||||||||||||
1428 | QListWidgetItem *QListWidget::takeItem(int row) | - | ||||||||||||||||||||||||
1429 | { | - | ||||||||||||||||||||||||
1430 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1431 | if (row < 0 || row >= d->model->rowCount())
| 0 | ||||||||||||||||||||||||
1432 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1433 | return d->listModel()->take(row); never executed: return d->listModel()->take(row); | 0 | ||||||||||||||||||||||||
1434 | } | - | ||||||||||||||||||||||||
1435 | - | |||||||||||||||||||||||||
1436 | /*! | - | ||||||||||||||||||||||||
1437 | \property QListWidget::count | - | ||||||||||||||||||||||||
1438 | \brief the number of items in the list including any hidden items. | - | ||||||||||||||||||||||||
1439 | */ | - | ||||||||||||||||||||||||
1440 | - | |||||||||||||||||||||||||
1441 | int QListWidget::count() const | - | ||||||||||||||||||||||||
1442 | { | - | ||||||||||||||||||||||||
1443 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1444 | return d->model->rowCount(); never executed: return d->model->rowCount(); | 0 | ||||||||||||||||||||||||
1445 | } | - | ||||||||||||||||||||||||
1446 | - | |||||||||||||||||||||||||
1447 | /*! | - | ||||||||||||||||||||||||
1448 | Returns the current item. | - | ||||||||||||||||||||||||
1449 | */ | - | ||||||||||||||||||||||||
1450 | QListWidgetItem *QListWidget::currentItem() const | - | ||||||||||||||||||||||||
1451 | { | - | ||||||||||||||||||||||||
1452 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1453 | return d->listModel()->at(currentIndex().row()); never executed: return d->listModel()->at(currentIndex().row()); | 0 | ||||||||||||||||||||||||
1454 | } | - | ||||||||||||||||||||||||
1455 | - | |||||||||||||||||||||||||
1456 | - | |||||||||||||||||||||||||
1457 | /*! | - | ||||||||||||||||||||||||
1458 | Sets the current item to \a item. | - | ||||||||||||||||||||||||
1459 | - | |||||||||||||||||||||||||
1460 | Unless the selection mode is \l{QAbstractItemView::}{NoSelection}, | - | ||||||||||||||||||||||||
1461 | the item is also selected. | - | ||||||||||||||||||||||||
1462 | */ | - | ||||||||||||||||||||||||
1463 | void QListWidget::setCurrentItem(QListWidgetItem *item) | - | ||||||||||||||||||||||||
1464 | { | - | ||||||||||||||||||||||||
1465 | setCurrentRow(row(item)); | - | ||||||||||||||||||||||||
1466 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1467 | - | |||||||||||||||||||||||||
1468 | /*! | - | ||||||||||||||||||||||||
1469 | \since 4.4 | - | ||||||||||||||||||||||||
1470 | Set the current item to \a item, using the given \a command. | - | ||||||||||||||||||||||||
1471 | */ | - | ||||||||||||||||||||||||
1472 | void QListWidget::setCurrentItem(QListWidgetItem *item, QItemSelectionModel::SelectionFlags command) | - | ||||||||||||||||||||||||
1473 | { | - | ||||||||||||||||||||||||
1474 | setCurrentRow(row(item), command); | - | ||||||||||||||||||||||||
1475 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1476 | - | |||||||||||||||||||||||||
1477 | /*! | - | ||||||||||||||||||||||||
1478 | \property QListWidget::currentRow | - | ||||||||||||||||||||||||
1479 | \brief the row of the current item. | - | ||||||||||||||||||||||||
1480 | - | |||||||||||||||||||||||||
1481 | Depending on the current selection mode, the row may also be selected. | - | ||||||||||||||||||||||||
1482 | */ | - | ||||||||||||||||||||||||
1483 | - | |||||||||||||||||||||||||
1484 | int QListWidget::currentRow() const | - | ||||||||||||||||||||||||
1485 | { | - | ||||||||||||||||||||||||
1486 | return currentIndex().row(); never executed: return currentIndex().row(); | 0 | ||||||||||||||||||||||||
1487 | } | - | ||||||||||||||||||||||||
1488 | - | |||||||||||||||||||||||||
1489 | void QListWidget::setCurrentRow(int row) | - | ||||||||||||||||||||||||
1490 | { | - | ||||||||||||||||||||||||
1491 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1492 | QModelIndex index = d->listModel()->index(row); | - | ||||||||||||||||||||||||
1493 | if (d->selectionMode == SingleSelection)
| 0 | ||||||||||||||||||||||||
1494 | selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); never executed: selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); | 0 | ||||||||||||||||||||||||
1495 | else if (d->selectionMode == NoSelection)
| 0 | ||||||||||||||||||||||||
1496 | selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate); never executed: selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate); | 0 | ||||||||||||||||||||||||
1497 | else | - | ||||||||||||||||||||||||
1498 | selectionModel()->setCurrentIndex(index, QItemSelectionModel::SelectCurrent); never executed: selectionModel()->setCurrentIndex(index, QItemSelectionModel::SelectCurrent); | 0 | ||||||||||||||||||||||||
1499 | } | - | ||||||||||||||||||||||||
1500 | - | |||||||||||||||||||||||||
1501 | /*! | - | ||||||||||||||||||||||||
1502 | \since 4.4 | - | ||||||||||||||||||||||||
1503 | - | |||||||||||||||||||||||||
1504 | Sets the current row to be the given \a row, using the given \a command, | - | ||||||||||||||||||||||||
1505 | */ | - | ||||||||||||||||||||||||
1506 | void QListWidget::setCurrentRow(int row, QItemSelectionModel::SelectionFlags command) | - | ||||||||||||||||||||||||
1507 | { | - | ||||||||||||||||||||||||
1508 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1509 | d->selectionModel->setCurrentIndex(d->listModel()->index(row), command); | - | ||||||||||||||||||||||||
1510 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1511 | - | |||||||||||||||||||||||||
1512 | /*! | - | ||||||||||||||||||||||||
1513 | Returns a pointer to the item at the coordinates \a p. The coordinates | - | ||||||||||||||||||||||||
1514 | are relative to the list widget's \l{QAbstractScrollArea::}{viewport()}. | - | ||||||||||||||||||||||||
1515 | - | |||||||||||||||||||||||||
1516 | */ | - | ||||||||||||||||||||||||
1517 | QListWidgetItem *QListWidget::itemAt(const QPoint &p) const | - | ||||||||||||||||||||||||
1518 | { | - | ||||||||||||||||||||||||
1519 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1520 | return d->listModel()->at(indexAt(p).row()); never executed: return d->listModel()->at(indexAt(p).row()); | 0 | ||||||||||||||||||||||||
1521 | - | |||||||||||||||||||||||||
1522 | } | - | ||||||||||||||||||||||||
1523 | - | |||||||||||||||||||||||||
1524 | /*! | - | ||||||||||||||||||||||||
1525 | \fn QListWidgetItem *QListWidget::itemAt(int x, int y) const | - | ||||||||||||||||||||||||
1526 | \overload | - | ||||||||||||||||||||||||
1527 | - | |||||||||||||||||||||||||
1528 | Returns a pointer to the item at the coordinates (\a x, \a y). | - | ||||||||||||||||||||||||
1529 | The coordinates are relative to the list widget's | - | ||||||||||||||||||||||||
1530 | \l{QAbstractScrollArea::}{viewport()}. | - | ||||||||||||||||||||||||
1531 | - | |||||||||||||||||||||||||
1532 | */ | - | ||||||||||||||||||||||||
1533 | - | |||||||||||||||||||||||||
1534 | - | |||||||||||||||||||||||||
1535 | /*! | - | ||||||||||||||||||||||||
1536 | Returns the rectangle on the viewport occupied by the item at \a item. | - | ||||||||||||||||||||||||
1537 | */ | - | ||||||||||||||||||||||||
1538 | QRect QListWidget::visualItemRect(const QListWidgetItem *item) const | - | ||||||||||||||||||||||||
1539 | { | - | ||||||||||||||||||||||||
1540 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1541 | QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item)); | - | ||||||||||||||||||||||||
1542 | return visualRect(index); never executed: return visualRect(index); | 0 | ||||||||||||||||||||||||
1543 | } | - | ||||||||||||||||||||||||
1544 | - | |||||||||||||||||||||||||
1545 | /*! | - | ||||||||||||||||||||||||
1546 | Sorts all the items in the list widget according to the specified \a order. | - | ||||||||||||||||||||||||
1547 | */ | - | ||||||||||||||||||||||||
1548 | void QListWidget::sortItems(Qt::SortOrder order) | - | ||||||||||||||||||||||||
1549 | { | - | ||||||||||||||||||||||||
1550 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1551 | d->sortOrder = order; | - | ||||||||||||||||||||||||
1552 | d->listModel()->sort(0, order); | - | ||||||||||||||||||||||||
1553 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1554 | - | |||||||||||||||||||||||||
1555 | /*! | - | ||||||||||||||||||||||||
1556 | \since 4.2 | - | ||||||||||||||||||||||||
1557 | \property QListWidget::sortingEnabled | - | ||||||||||||||||||||||||
1558 | \brief whether sorting is enabled | - | ||||||||||||||||||||||||
1559 | - | |||||||||||||||||||||||||
1560 | If this property is \c true, sorting is enabled for the list; if the property | - | ||||||||||||||||||||||||
1561 | is false, sorting is not enabled. | - | ||||||||||||||||||||||||
1562 | - | |||||||||||||||||||||||||
1563 | The default value is false. | - | ||||||||||||||||||||||||
1564 | */ | - | ||||||||||||||||||||||||
1565 | void QListWidget::setSortingEnabled(bool enable) | - | ||||||||||||||||||||||||
1566 | { | - | ||||||||||||||||||||||||
1567 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1568 | d->sortingEnabled = enable; | - | ||||||||||||||||||||||||
1569 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1570 | - | |||||||||||||||||||||||||
1571 | bool QListWidget::isSortingEnabled() const | - | ||||||||||||||||||||||||
1572 | { | - | ||||||||||||||||||||||||
1573 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1574 | return d->sortingEnabled; never executed: return d->sortingEnabled; | 0 | ||||||||||||||||||||||||
1575 | } | - | ||||||||||||||||||||||||
1576 | - | |||||||||||||||||||||||||
1577 | /*! | - | ||||||||||||||||||||||||
1578 | \internal | - | ||||||||||||||||||||||||
1579 | */ | - | ||||||||||||||||||||||||
1580 | Qt::SortOrder QListWidget::sortOrder() const | - | ||||||||||||||||||||||||
1581 | { | - | ||||||||||||||||||||||||
1582 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1583 | return d->sortOrder; never executed: return d->sortOrder; | 0 | ||||||||||||||||||||||||
1584 | } | - | ||||||||||||||||||||||||
1585 | - | |||||||||||||||||||||||||
1586 | /*! | - | ||||||||||||||||||||||||
1587 | Starts editing the \a item if it is editable. | - | ||||||||||||||||||||||||
1588 | */ | - | ||||||||||||||||||||||||
1589 | - | |||||||||||||||||||||||||
1590 | void QListWidget::editItem(QListWidgetItem *item) | - | ||||||||||||||||||||||||
1591 | { | - | ||||||||||||||||||||||||
1592 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1593 | edit(d->listModel()->index(item)); | - | ||||||||||||||||||||||||
1594 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1595 | - | |||||||||||||||||||||||||
1596 | /*! | - | ||||||||||||||||||||||||
1597 | Opens an editor for the given \a item. The editor remains open after | - | ||||||||||||||||||||||||
1598 | editing. | - | ||||||||||||||||||||||||
1599 | - | |||||||||||||||||||||||||
1600 | \sa closePersistentEditor() | - | ||||||||||||||||||||||||
1601 | */ | - | ||||||||||||||||||||||||
1602 | void QListWidget::openPersistentEditor(QListWidgetItem *item) | - | ||||||||||||||||||||||||
1603 | { | - | ||||||||||||||||||||||||
1604 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1605 | QModelIndex index = d->listModel()->index(item); | - | ||||||||||||||||||||||||
1606 | QAbstractItemView::openPersistentEditor(index); | - | ||||||||||||||||||||||||
1607 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1608 | - | |||||||||||||||||||||||||
1609 | /*! | - | ||||||||||||||||||||||||
1610 | Closes the persistent editor for the given \a item. | - | ||||||||||||||||||||||||
1611 | - | |||||||||||||||||||||||||
1612 | \sa openPersistentEditor() | - | ||||||||||||||||||||||||
1613 | */ | - | ||||||||||||||||||||||||
1614 | void QListWidget::closePersistentEditor(QListWidgetItem *item) | - | ||||||||||||||||||||||||
1615 | { | - | ||||||||||||||||||||||||
1616 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1617 | QModelIndex index = d->listModel()->index(item); | - | ||||||||||||||||||||||||
1618 | QAbstractItemView::closePersistentEditor(index); | - | ||||||||||||||||||||||||
1619 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1620 | - | |||||||||||||||||||||||||
1621 | /*! | - | ||||||||||||||||||||||||
1622 | \since 4.1 | - | ||||||||||||||||||||||||
1623 | - | |||||||||||||||||||||||||
1624 | Returns the widget displayed in the given \a item. | - | ||||||||||||||||||||||||
1625 | - | |||||||||||||||||||||||||
1626 | \sa setItemWidget(), removeItemWidget() | - | ||||||||||||||||||||||||
1627 | */ | - | ||||||||||||||||||||||||
1628 | QWidget *QListWidget::itemWidget(QListWidgetItem *item) const | - | ||||||||||||||||||||||||
1629 | { | - | ||||||||||||||||||||||||
1630 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1631 | QModelIndex index = d->listModel()->index(item); | - | ||||||||||||||||||||||||
1632 | return QAbstractItemView::indexWidget(index); never executed: return QAbstractItemView::indexWidget(index); | 0 | ||||||||||||||||||||||||
1633 | } | - | ||||||||||||||||||||||||
1634 | - | |||||||||||||||||||||||||
1635 | /*! | - | ||||||||||||||||||||||||
1636 | \since 4.1 | - | ||||||||||||||||||||||||
1637 | - | |||||||||||||||||||||||||
1638 | Sets the \a widget to be displayed in the given \a item. | - | ||||||||||||||||||||||||
1639 | - | |||||||||||||||||||||||||
1640 | This function should only be used to display static content in the place of | - | ||||||||||||||||||||||||
1641 | a list widget item. If you want to display custom dynamic content or | - | ||||||||||||||||||||||||
1642 | implement a custom editor widget, use QListView and subclass QItemDelegate | - | ||||||||||||||||||||||||
1643 | instead. | - | ||||||||||||||||||||||||
1644 | - | |||||||||||||||||||||||||
1645 | \sa itemWidget(), removeItemWidget(), {Delegate Classes} | - | ||||||||||||||||||||||||
1646 | */ | - | ||||||||||||||||||||||||
1647 | void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget) | - | ||||||||||||||||||||||||
1648 | { | - | ||||||||||||||||||||||||
1649 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1650 | QModelIndex index = d->listModel()->index(item); | - | ||||||||||||||||||||||||
1651 | QAbstractItemView::setIndexWidget(index, widget); | - | ||||||||||||||||||||||||
1652 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1653 | - | |||||||||||||||||||||||||
1654 | /*! | - | ||||||||||||||||||||||||
1655 | Returns \c true if \a item is selected; otherwise returns \c false. | - | ||||||||||||||||||||||||
1656 | - | |||||||||||||||||||||||||
1657 | \obsolete | - | ||||||||||||||||||||||||
1658 | - | |||||||||||||||||||||||||
1659 | This function is deprecated. Use QListWidgetItem::isSelected() instead. | - | ||||||||||||||||||||||||
1660 | */ | - | ||||||||||||||||||||||||
1661 | bool QListWidget::isItemSelected(const QListWidgetItem *item) const | - | ||||||||||||||||||||||||
1662 | { | - | ||||||||||||||||||||||||
1663 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1664 | QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item)); | - | ||||||||||||||||||||||||
1665 | return selectionModel()->isSelected(index); never executed: return selectionModel()->isSelected(index); | 0 | ||||||||||||||||||||||||
1666 | } | - | ||||||||||||||||||||||||
1667 | - | |||||||||||||||||||||||||
1668 | /*! | - | ||||||||||||||||||||||||
1669 | Selects or deselects the given \a item depending on whether \a select is | - | ||||||||||||||||||||||||
1670 | true of false. | - | ||||||||||||||||||||||||
1671 | - | |||||||||||||||||||||||||
1672 | \obsolete | - | ||||||||||||||||||||||||
1673 | - | |||||||||||||||||||||||||
1674 | This function is deprecated. Use QListWidgetItem::setSelected() instead. | - | ||||||||||||||||||||||||
1675 | */ | - | ||||||||||||||||||||||||
1676 | void QListWidget::setItemSelected(const QListWidgetItem *item, bool select) | - | ||||||||||||||||||||||||
1677 | { | - | ||||||||||||||||||||||||
1678 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1679 | QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item)); | - | ||||||||||||||||||||||||
1680 | - | |||||||||||||||||||||||||
1681 | if (d->selectionMode == SingleSelection) {
| 0 | ||||||||||||||||||||||||
1682 | selectionModel()->select(index, select | - | ||||||||||||||||||||||||
1683 | ? QItemSelectionModel::ClearAndSelect | - | ||||||||||||||||||||||||
1684 | : QItemSelectionModel::Deselect); | - | ||||||||||||||||||||||||
1685 | } else if (d->selectionMode != NoSelection) { never executed: end of block
| 0 | ||||||||||||||||||||||||
1686 | selectionModel()->select(index, select | - | ||||||||||||||||||||||||
1687 | ? QItemSelectionModel::Select | - | ||||||||||||||||||||||||
1688 | : QItemSelectionModel::Deselect); | - | ||||||||||||||||||||||||
1689 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1690 | - | |||||||||||||||||||||||||
1691 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1692 | - | |||||||||||||||||||||||||
1693 | /*! | - | ||||||||||||||||||||||||
1694 | Returns a list of all selected items in the list widget. | - | ||||||||||||||||||||||||
1695 | */ | - | ||||||||||||||||||||||||
1696 | - | |||||||||||||||||||||||||
1697 | QList<QListWidgetItem*> QListWidget::selectedItems() const | - | ||||||||||||||||||||||||
1698 | { | - | ||||||||||||||||||||||||
1699 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1700 | QModelIndexList indexes = selectionModel()->selectedIndexes(); | - | ||||||||||||||||||||||||
1701 | QList<QListWidgetItem*> items; | - | ||||||||||||||||||||||||
1702 | const int numIndexes = indexes.count(); | - | ||||||||||||||||||||||||
1703 | items.reserve(numIndexes); | - | ||||||||||||||||||||||||
1704 | for (int i = 0; i < numIndexes; ++i)
| 0 | ||||||||||||||||||||||||
1705 | items.append(d->listModel()->at(indexes.at(i).row())); never executed: items.append(d->listModel()->at(indexes.at(i).row())); | 0 | ||||||||||||||||||||||||
1706 | return items; never executed: return items; | 0 | ||||||||||||||||||||||||
1707 | } | - | ||||||||||||||||||||||||
1708 | - | |||||||||||||||||||||||||
1709 | /*! | - | ||||||||||||||||||||||||
1710 | Finds items with the text that matches the string \a text using the given | - | ||||||||||||||||||||||||
1711 | \a flags. | - | ||||||||||||||||||||||||
1712 | */ | - | ||||||||||||||||||||||||
1713 | - | |||||||||||||||||||||||||
1714 | QList<QListWidgetItem*> QListWidget::findItems(const QString &text, Qt::MatchFlags flags) const | - | ||||||||||||||||||||||||
1715 | { | - | ||||||||||||||||||||||||
1716 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1717 | QModelIndexList indexes = d->listModel()->match(model()->index(0, 0, QModelIndex()), | - | ||||||||||||||||||||||||
1718 | Qt::DisplayRole, text, -1, flags); | - | ||||||||||||||||||||||||
1719 | QList<QListWidgetItem*> items; | - | ||||||||||||||||||||||||
1720 | const int indexesSize = indexes.size(); | - | ||||||||||||||||||||||||
1721 | items.reserve(indexesSize); | - | ||||||||||||||||||||||||
1722 | for (int i = 0; i < indexesSize; ++i)
| 0 | ||||||||||||||||||||||||
1723 | items.append(d->listModel()->at(indexes.at(i).row())); never executed: items.append(d->listModel()->at(indexes.at(i).row())); | 0 | ||||||||||||||||||||||||
1724 | return items; never executed: return items; | 0 | ||||||||||||||||||||||||
1725 | } | - | ||||||||||||||||||||||||
1726 | - | |||||||||||||||||||||||||
1727 | /*! | - | ||||||||||||||||||||||||
1728 | Returns \c true if the \a item is explicitly hidden; otherwise returns \c false. | - | ||||||||||||||||||||||||
1729 | - | |||||||||||||||||||||||||
1730 | \obsolete | - | ||||||||||||||||||||||||
1731 | - | |||||||||||||||||||||||||
1732 | This function is deprecated. Use QListWidgetItem::isHidden() instead. | - | ||||||||||||||||||||||||
1733 | */ | - | ||||||||||||||||||||||||
1734 | bool QListWidget::isItemHidden(const QListWidgetItem *item) const | - | ||||||||||||||||||||||||
1735 | { | - | ||||||||||||||||||||||||
1736 | return isRowHidden(row(item)); never executed: return isRowHidden(row(item)); | 0 | ||||||||||||||||||||||||
1737 | } | - | ||||||||||||||||||||||||
1738 | - | |||||||||||||||||||||||||
1739 | /*! | - | ||||||||||||||||||||||||
1740 | If \a hide is true, the \a item will be hidden; otherwise it will be shown. | - | ||||||||||||||||||||||||
1741 | - | |||||||||||||||||||||||||
1742 | \obsolete | - | ||||||||||||||||||||||||
1743 | - | |||||||||||||||||||||||||
1744 | This function is deprecated. Use QListWidgetItem::setHidden() instead. | - | ||||||||||||||||||||||||
1745 | */ | - | ||||||||||||||||||||||||
1746 | void QListWidget::setItemHidden(const QListWidgetItem *item, bool hide) | - | ||||||||||||||||||||||||
1747 | { | - | ||||||||||||||||||||||||
1748 | setRowHidden(row(item), hide); | - | ||||||||||||||||||||||||
1749 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1750 | - | |||||||||||||||||||||||||
1751 | /*! | - | ||||||||||||||||||||||||
1752 | Scrolls the view if necessary to ensure that the \a item is visible. | - | ||||||||||||||||||||||||
1753 | - | |||||||||||||||||||||||||
1754 | \a hint specifies where the \a item should be located after the operation. | - | ||||||||||||||||||||||||
1755 | */ | - | ||||||||||||||||||||||||
1756 | - | |||||||||||||||||||||||||
1757 | void QListWidget::scrollToItem(const QListWidgetItem *item, QAbstractItemView::ScrollHint hint) | - | ||||||||||||||||||||||||
1758 | { | - | ||||||||||||||||||||||||
1759 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1760 | QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item)); | - | ||||||||||||||||||||||||
1761 | QListView::scrollTo(index, hint); | - | ||||||||||||||||||||||||
1762 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1763 | - | |||||||||||||||||||||||||
1764 | /*! | - | ||||||||||||||||||||||||
1765 | Removes all items and selections in the view. | - | ||||||||||||||||||||||||
1766 | - | |||||||||||||||||||||||||
1767 | \warning All items will be permanently deleted. | - | ||||||||||||||||||||||||
1768 | */ | - | ||||||||||||||||||||||||
1769 | void QListWidget::clear() | - | ||||||||||||||||||||||||
1770 | { | - | ||||||||||||||||||||||||
1771 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1772 | selectionModel()->clear(); | - | ||||||||||||||||||||||||
1773 | d->listModel()->clear(); | - | ||||||||||||||||||||||||
1774 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1775 | - | |||||||||||||||||||||||||
1776 | /*! | - | ||||||||||||||||||||||||
1777 | Returns a list of MIME types that can be used to describe a list of | - | ||||||||||||||||||||||||
1778 | listwidget items. | - | ||||||||||||||||||||||||
1779 | - | |||||||||||||||||||||||||
1780 | \sa mimeData() | - | ||||||||||||||||||||||||
1781 | */ | - | ||||||||||||||||||||||||
1782 | QStringList QListWidget::mimeTypes() const | - | ||||||||||||||||||||||||
1783 | { | - | ||||||||||||||||||||||||
1784 | return d_func()->listModel()->QAbstractListModel::mimeTypes(); never executed: return d_func()->listModel()->QAbstractListModel::mimeTypes(); | 0 | ||||||||||||||||||||||||
1785 | } | - | ||||||||||||||||||||||||
1786 | - | |||||||||||||||||||||||||
1787 | /*! | - | ||||||||||||||||||||||||
1788 | Returns an object that contains a serialized description of the specified | - | ||||||||||||||||||||||||
1789 | \a items. The format used to describe the items is obtained from the | - | ||||||||||||||||||||||||
1790 | mimeTypes() function. | - | ||||||||||||||||||||||||
1791 | - | |||||||||||||||||||||||||
1792 | If the list of items is empty, 0 is returned instead of a serialized empty | - | ||||||||||||||||||||||||
1793 | list. | - | ||||||||||||||||||||||||
1794 | */ | - | ||||||||||||||||||||||||
1795 | #if QT_VERSION >= QT_VERSION_CHECK(6,0,0) | - | ||||||||||||||||||||||||
1796 | QMimeData *QListWidget::mimeData(const QList<QListWidgetItem *> &items) const | - | ||||||||||||||||||||||||
1797 | #else | - | ||||||||||||||||||||||||
1798 | QMimeData *QListWidget::mimeData(const QList<QListWidgetItem*> items) const | - | ||||||||||||||||||||||||
1799 | #endif | - | ||||||||||||||||||||||||
1800 | { | - | ||||||||||||||||||||||||
1801 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1802 | - | |||||||||||||||||||||||||
1803 | QModelIndexList &cachedIndexes = d->listModel()->cachedIndexes; | - | ||||||||||||||||||||||||
1804 | - | |||||||||||||||||||||||||
1805 | // if non empty, it's called from the model's own mimeData | - | ||||||||||||||||||||||||
1806 | if (cachedIndexes.isEmpty()) {
| 0 | ||||||||||||||||||||||||
1807 | cachedIndexes.reserve(items.count()); | - | ||||||||||||||||||||||||
1808 | foreach (QListWidgetItem *item, items) | - | ||||||||||||||||||||||||
1809 | cachedIndexes << indexFromItem(item); never executed: cachedIndexes << indexFromItem(item); | 0 | ||||||||||||||||||||||||
1810 | - | |||||||||||||||||||||||||
1811 | QMimeData *result = d->listModel()->internalMimeData(); | - | ||||||||||||||||||||||||
1812 | - | |||||||||||||||||||||||||
1813 | cachedIndexes.clear(); | - | ||||||||||||||||||||||||
1814 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
1815 | } | - | ||||||||||||||||||||||||
1816 | - | |||||||||||||||||||||||||
1817 | return d->listModel()->internalMimeData(); never executed: return d->listModel()->internalMimeData(); | 0 | ||||||||||||||||||||||||
1818 | } | - | ||||||||||||||||||||||||
1819 | - | |||||||||||||||||||||||||
1820 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
1821 | /*! | - | ||||||||||||||||||||||||
1822 | Handles \a data supplied by an external drag and drop operation that ended | - | ||||||||||||||||||||||||
1823 | with the given \a action in the given \a index. Returns \c true if \a data and | - | ||||||||||||||||||||||||
1824 | \a action can be handled by the model; otherwise returns \c false. | - | ||||||||||||||||||||||||
1825 | - | |||||||||||||||||||||||||
1826 | \sa supportedDropActions() | - | ||||||||||||||||||||||||
1827 | */ | - | ||||||||||||||||||||||||
1828 | bool QListWidget::dropMimeData(int index, const QMimeData *data, Qt::DropAction action) | - | ||||||||||||||||||||||||
1829 | { | - | ||||||||||||||||||||||||
1830 | QModelIndex idx; | - | ||||||||||||||||||||||||
1831 | int row = index; | - | ||||||||||||||||||||||||
1832 | int column = 0; | - | ||||||||||||||||||||||||
1833 | if (dropIndicatorPosition() == QAbstractItemView::OnItem) {
| 0 | ||||||||||||||||||||||||
1834 | // QAbstractListModel::dropMimeData will overwrite on the index if row == -1 and column == -1 | - | ||||||||||||||||||||||||
1835 | idx = model()->index(row, column); | - | ||||||||||||||||||||||||
1836 | row = -1; | - | ||||||||||||||||||||||||
1837 | column = -1; | - | ||||||||||||||||||||||||
1838 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1839 | return d_func()->listModel()->QAbstractListModel::dropMimeData(data, action , row, column, idx); never executed: return d_func()->listModel()->QAbstractListModel::dropMimeData(data, action , row, column, idx); | 0 | ||||||||||||||||||||||||
1840 | } | - | ||||||||||||||||||||||||
1841 | - | |||||||||||||||||||||||||
1842 | /*! \reimp */ | - | ||||||||||||||||||||||||
1843 | void QListWidget::dropEvent(QDropEvent *event) { | - | ||||||||||||||||||||||||
1844 | Q_D(QListWidget); | - | ||||||||||||||||||||||||
1845 | if (event->source() == this && d->movement != Static) {
| 0 | ||||||||||||||||||||||||
1846 | QListView::dropEvent(event); | - | ||||||||||||||||||||||||
1847 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1848 | } | - | ||||||||||||||||||||||||
1849 | - | |||||||||||||||||||||||||
1850 | if (event->source() == this && (event->dropAction() == Qt::MoveAction ||
| 0 | ||||||||||||||||||||||||
1851 | dragDropMode() == QAbstractItemView::InternalMove)) {
| 0 | ||||||||||||||||||||||||
1852 | QModelIndex topIndex; | - | ||||||||||||||||||||||||
1853 | int col = -1; | - | ||||||||||||||||||||||||
1854 | int row = -1; | - | ||||||||||||||||||||||||
1855 | if (d->dropOn(event, &row, &col, &topIndex)) {
| 0 | ||||||||||||||||||||||||
1856 | QList<QModelIndex> selIndexes = selectedIndexes(); | - | ||||||||||||||||||||||||
1857 | QList<QPersistentModelIndex> persIndexes; | - | ||||||||||||||||||||||||
1858 | const int selIndexesCount = selIndexes.count(); | - | ||||||||||||||||||||||||
1859 | persIndexes.reserve(selIndexesCount); | - | ||||||||||||||||||||||||
1860 | for (int i = 0; i < selIndexesCount; i++)
| 0 | ||||||||||||||||||||||||
1861 | persIndexes.append(selIndexes.at(i)); never executed: persIndexes.append(selIndexes.at(i)); | 0 | ||||||||||||||||||||||||
1862 | - | |||||||||||||||||||||||||
1863 | if (persIndexes.contains(topIndex))
| 0 | ||||||||||||||||||||||||
1864 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1865 | std::sort(persIndexes.begin(), persIndexes.end()); // The dropped items will remain in the same visual order. | - | ||||||||||||||||||||||||
1866 | - | |||||||||||||||||||||||||
1867 | QPersistentModelIndex dropRow = model()->index(row, col, topIndex); | - | ||||||||||||||||||||||||
1868 | - | |||||||||||||||||||||||||
1869 | int r = row == -1 ? count() : (dropRow.row() >= 0 ? dropRow.row() : row);
| 0 | ||||||||||||||||||||||||
1870 | for (int i = 0; i < persIndexes.count(); ++i) {
| 0 | ||||||||||||||||||||||||
1871 | const QPersistentModelIndex &pIndex = persIndexes.at(i); | - | ||||||||||||||||||||||||
1872 | d->listModel()->move(pIndex.row(), r); | - | ||||||||||||||||||||||||
1873 | r = pIndex.row() + 1; // Dropped items are inserted contiguously and in the right order. | - | ||||||||||||||||||||||||
1874 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1875 | - | |||||||||||||||||||||||||
1876 | event->accept(); | - | ||||||||||||||||||||||||
1877 | // Don't want QAbstractItemView to delete it because it was "moved" we already did it | - | ||||||||||||||||||||||||
1878 | event->setDropAction(Qt::CopyAction); | - | ||||||||||||||||||||||||
1879 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1880 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1881 | - | |||||||||||||||||||||||||
1882 | QListView::dropEvent(event); | - | ||||||||||||||||||||||||
1883 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1884 | - | |||||||||||||||||||||||||
1885 | /*! | - | ||||||||||||||||||||||||
1886 | Returns the drop actions supported by this view. | - | ||||||||||||||||||||||||
1887 | - | |||||||||||||||||||||||||
1888 | \sa Qt::DropActions | - | ||||||||||||||||||||||||
1889 | */ | - | ||||||||||||||||||||||||
1890 | Qt::DropActions QListWidget::supportedDropActions() const | - | ||||||||||||||||||||||||
1891 | { | - | ||||||||||||||||||||||||
1892 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1893 | return d->listModel()->QAbstractListModel::supportedDropActions() | Qt::MoveAction; never executed: return d->listModel()->QAbstractListModel::supportedDropActions() | Qt::MoveAction; | 0 | ||||||||||||||||||||||||
1894 | } | - | ||||||||||||||||||||||||
1895 | #endif // QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
1896 | - | |||||||||||||||||||||||||
1897 | /*! | - | ||||||||||||||||||||||||
1898 | Returns a list of pointers to the items contained in the \a data object. If | - | ||||||||||||||||||||||||
1899 | the object was not created by a QListWidget in the same process, the list | - | ||||||||||||||||||||||||
1900 | is empty. | - | ||||||||||||||||||||||||
1901 | */ | - | ||||||||||||||||||||||||
1902 | QList<QListWidgetItem*> QListWidget::items(const QMimeData *data) const | - | ||||||||||||||||||||||||
1903 | { | - | ||||||||||||||||||||||||
1904 | const QListWidgetMimeData *lwd = qobject_cast<const QListWidgetMimeData*>(data); | - | ||||||||||||||||||||||||
1905 | if (lwd)
| 0 | ||||||||||||||||||||||||
1906 | return lwd->items; never executed: return lwd->items; | 0 | ||||||||||||||||||||||||
1907 | return QList<QListWidgetItem*>(); never executed: return QList<QListWidgetItem*>(); | 0 | ||||||||||||||||||||||||
1908 | } | - | ||||||||||||||||||||||||
1909 | - | |||||||||||||||||||||||||
1910 | /*! | - | ||||||||||||||||||||||||
1911 | Returns the QModelIndex assocated with the given \a item. | - | ||||||||||||||||||||||||
1912 | */ | - | ||||||||||||||||||||||||
1913 | - | |||||||||||||||||||||||||
1914 | QModelIndex QListWidget::indexFromItem(QListWidgetItem *item) const | - | ||||||||||||||||||||||||
1915 | { | - | ||||||||||||||||||||||||
1916 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1917 | return d->listModel()->index(item); never executed: return d->listModel()->index(item); | 0 | ||||||||||||||||||||||||
1918 | } | - | ||||||||||||||||||||||||
1919 | - | |||||||||||||||||||||||||
1920 | /*! | - | ||||||||||||||||||||||||
1921 | Returns a pointer to the QListWidgetItem assocated with the given \a index. | - | ||||||||||||||||||||||||
1922 | */ | - | ||||||||||||||||||||||||
1923 | - | |||||||||||||||||||||||||
1924 | QListWidgetItem *QListWidget::itemFromIndex(const QModelIndex &index) const | - | ||||||||||||||||||||||||
1925 | { | - | ||||||||||||||||||||||||
1926 | Q_D(const QListWidget); | - | ||||||||||||||||||||||||
1927 | if (d->isIndexValid(index))
| 0 | ||||||||||||||||||||||||
1928 | return d->listModel()->at(index.row()); never executed: return d->listModel()->at(index.row()); | 0 | ||||||||||||||||||||||||
1929 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1930 | } | - | ||||||||||||||||||||||||
1931 | - | |||||||||||||||||||||||||
1932 | /*! | - | ||||||||||||||||||||||||
1933 | \internal | - | ||||||||||||||||||||||||
1934 | */ | - | ||||||||||||||||||||||||
1935 | void QListWidget::setModel(QAbstractItemModel * /*model*/) | - | ||||||||||||||||||||||||
1936 | { | - | ||||||||||||||||||||||||
1937 | Q_ASSERT(!"QListWidget::setModel() - Changing the model of the QListWidget is not allowed."); | - | ||||||||||||||||||||||||
1938 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1939 | - | |||||||||||||||||||||||||
1940 | /*! | - | ||||||||||||||||||||||||
1941 | \reimp | - | ||||||||||||||||||||||||
1942 | */ | - | ||||||||||||||||||||||||
1943 | bool QListWidget::event(QEvent *e) | - | ||||||||||||||||||||||||
1944 | { | - | ||||||||||||||||||||||||
1945 | return QListView::event(e); never executed: return QListView::event(e); | 0 | ||||||||||||||||||||||||
1946 | } | - | ||||||||||||||||||||||||
1947 | - | |||||||||||||||||||||||||
1948 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
1949 | - | |||||||||||||||||||||||||
1950 | #include "moc_qlistwidget.cpp" | - | ||||||||||||||||||||||||
1951 | #include "moc_qlistwidget_p.cpp" | - | ||||||||||||||||||||||||
1952 | - | |||||||||||||||||||||||||
1953 | #endif // QT_NO_LISTWIDGET | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |