itemviews/qlistwidget.cpp

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

Generated by Squish Coco Non-Commercial