qlistwidget.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9