qstringlistmodel.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/itemmodels/qstringlistmodel.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the 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 The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40/*-
41 A simple model that uses a QStringList as its data source.-
42*/-
43-
44#include "qstringlistmodel.h"-
45-
46#include <QtCore/qvector.h>-
47-
48#include <algorithm>-
49-
50#ifndef QT_NO_STRINGLISTMODEL-
51-
52QT_BEGIN_NAMESPACE-
53-
54/*!-
55 \class QStringListModel-
56 \inmodule QtCore-
57 \brief The QStringListModel class provides a model that supplies strings to views.-
58-
59 \ingroup model-view-
60-
61 QStringListModel is an editable model that can be used for simple-
62 cases where you need to display a number of strings in a view-
63 widget, such as a QListView or a QComboBox.-
64-
65 The model provides all the standard functions of an editable-
66 model, representing the data in the string list as a model with-
67 one column and a number of rows equal to the number of items in-
68 the list.-
69-
70 Model indexes corresponding to items are obtained with the-
71 \l{QAbstractListModel::index()}{index()} function, and item flags-
72 are obtained with flags(). Item data is read with the data()-
73 function and written with setData(). The number of rows (and-
74 number of items in the string list) can be found with the-
75 rowCount() function.-
76-
77 The model can be constructed with an existing string list, or-
78 strings can be set later with the setStringList() convenience-
79 function. Strings can also be inserted in the usual way with the-
80 insertRows() function, and removed with removeRows(). The contents-
81 of the string list can be retrieved with the stringList()-
82 convenience function.-
83-
84 An example usage of QStringListModel:-
85-
86 \snippet qstringlistmodel/main.cpp 0-
87-
88 \sa QAbstractListModel, QAbstractItemModel, {Model Classes}-
89*/-
90-
91/*!-
92 Constructs a string list model with the given \a parent.-
93*/-
94-
95QStringListModel::QStringListModel(QObject *parent)-
96 : QAbstractListModel(parent)-
97{-
98}
executed 285 times by 13 tests: end of block
Executed by:
  • tst_ModelTest
  • tst_QAbstractItemModel
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontComboBox
  • tst_QFontDialog
  • tst_QGraphicsProxyWidget
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QListView
  • tst_QObject
  • tst_QSortFilterProxyModel
  • tst_QTableView
285
99-
100/*!-
101 Constructs a string list model containing the specified \a strings-
102 with the given \a parent.-
103*/-
104-
105QStringListModel::QStringListModel(const QStringList &strings, QObject *parent)-
106 : QAbstractListModel(parent), lst(strings)-
107{-
108}
executed 67 times by 14 tests: end of block
Executed by:
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCompleter
  • tst_QHeaderView
  • tst_QIdentityProxyModel
  • tst_QItemSelectionModel
  • tst_QLineEdit
  • tst_QListView
  • tst_QListWidget
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
  • tst_QTreeView
67
109-
110/*!-
111 Returns the number of rows in the model. This value corresponds to the-
112 number of items in the model's internal string list.-
113-
114 The optional \a parent argument is in most models used to specify-
115 the parent of the rows to be counted. Because this is a list if a-
116 valid parent is specified, the result will always be 0.-
117-
118 \sa insertRows(), removeRows(), QAbstractItemModel::rowCount()-
119*/-
120-
121int QStringListModel::rowCount(const QModelIndex &parent) const-
122{-
123 if (parent.isValid())
parent.isValid()Description
TRUEevaluated 18 times by 3 tests
Evaluated by:
  • tst_ModelTest
  • tst_QItemModel
  • tst_QSortFilterProxyModel
FALSEevaluated 91991 times by 20 tests
Evaluated by:
  • tst_ModelTest
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontComboBox
  • tst_QFontDialog
  • tst_QGraphicsProxyWidget
  • tst_QHeaderView
  • tst_QIdentityProxyModel
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QLineEdit
  • tst_QListView
  • tst_QListWidget
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
  • tst_QTableView
  • tst_QTreeView
18-91991
124 return 0;
executed 18 times by 3 tests: return 0;
Executed by:
  • tst_ModelTest
  • tst_QItemModel
  • tst_QSortFilterProxyModel
18
125-
126 return lst.count();
executed 91991 times by 20 tests: return lst.count();
Executed by:
  • tst_ModelTest
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontComboBox
  • tst_QFontDialog
  • tst_QGraphicsProxyWidget
  • tst_QHeaderView
  • tst_QIdentityProxyModel
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QLineEdit
  • tst_QListView
  • tst_QListWidget
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
  • tst_QTableView
  • tst_QTreeView
91991
127}-
128-
129/*!-
130 \reimp-
131*/-
132QModelIndex QStringListModel::sibling(int row, int column, const QModelIndex &idx) const-
133{-
134 if (!idx.isValid() || column != 0 || row >= lst.count())
!idx.isValid()Description
TRUEevaluated 5 times by 2 tests
Evaluated by:
  • tst_ModelTest
  • tst_QItemModel
FALSEevaluated 73 times by 3 tests
Evaluated by:
  • tst_ModelTest
  • tst_QItemModel
  • tst_QListView
column != 0Description
TRUEnever evaluated
FALSEevaluated 73 times by 3 tests
Evaluated by:
  • tst_ModelTest
  • tst_QItemModel
  • tst_QListView
row >= lst.count()Description
TRUEnever evaluated
FALSEevaluated 73 times by 3 tests
Evaluated by:
  • tst_ModelTest
  • tst_QItemModel
  • tst_QListView
0-73
135 return QModelIndex();
executed 5 times by 2 tests: return QModelIndex();
Executed by:
  • tst_ModelTest
  • tst_QItemModel
5
136-
137 return createIndex(row, 0);
executed 73 times by 3 tests: return createIndex(row, 0);
Executed by:
  • tst_ModelTest
  • tst_QItemModel
  • tst_QListView
73
138}-
139-
140/*!-
141 Returns data for the specified \a role, from the item with the-
142 given \a index.-
143-
144 If the view requests an invalid index, an invalid variant is returned.-
145-
146 \sa setData()-
147*/-
148-
149QVariant QStringListModel::data(const QModelIndex &index, int role) const-
150{-
151 if (index.row() < 0 || index.row() >= lst.size())
index.row() < 0Description
TRUEevaluated 4739 times by 6 tests
Evaluated by:
  • tst_ModelTest
  • tst_QComboBox
  • tst_QFontComboBox
  • tst_QGraphicsProxyWidget
  • tst_QItemModel
  • tst_QSortFilterProxyModel
FALSEevaluated 132335 times by 17 tests
Evaluated by:
  • tst_ModelTest
  • tst_QAbstractItemView
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontComboBox
  • tst_QFontDialog
  • tst_QGraphicsProxyWidget
  • tst_QIdentityProxyModel
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QLineEdit
  • tst_QListView
  • tst_QListWidget
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
  • tst_QTreeView
index.row() >= lst.size()Description
TRUEnever evaluated
FALSEevaluated 132335 times by 17 tests
Evaluated by:
  • tst_ModelTest
  • tst_QAbstractItemView
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontComboBox
  • tst_QFontDialog
  • tst_QGraphicsProxyWidget
  • tst_QIdentityProxyModel
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QLineEdit
  • tst_QListView
  • tst_QListWidget
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
  • tst_QTreeView
0-132335
152 return QVariant();
executed 4739 times by 6 tests: return QVariant();
Executed by:
  • tst_ModelTest
  • tst_QComboBox
  • tst_QFontComboBox
  • tst_QGraphicsProxyWidget
  • tst_QItemModel
  • tst_QSortFilterProxyModel
4739
153-
154 if (role == Qt::DisplayRole || role == Qt::EditRole)
role == Qt::DisplayRoleDescription
TRUEevaluated 19898 times by 14 tests
Evaluated by:
  • tst_ModelTest
  • tst_QAbstractItemView
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontDialog
  • tst_QIdentityProxyModel
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QLineEdit
  • tst_QListView
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
  • tst_QTreeView
FALSEevaluated 112437 times by 15 tests
Evaluated by:
  • tst_ModelTest
  • tst_QAbstractItemView
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontComboBox
  • tst_QFontDialog
  • tst_QGraphicsProxyWidget
  • tst_QIdentityProxyModel
  • tst_QItemModel
  • tst_QLineEdit
  • tst_QListView
  • tst_QListWidget
  • tst_QSortFilterProxyModel
  • tst_QTreeView
role == Qt::EditRoleDescription
TRUEevaluated 4295 times by 8 tests
Evaluated by:
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontComboBox
  • tst_QGraphicsProxyWidget
  • tst_QIdentityProxyModel
  • tst_QItemModel
  • tst_QLineEdit
  • tst_QListWidget
FALSEevaluated 108142 times by 14 tests
Evaluated by:
  • tst_ModelTest
  • tst_QAbstractItemView
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontComboBox
  • tst_QFontDialog
  • tst_QGraphicsProxyWidget
  • tst_QIdentityProxyModel
  • tst_QItemModel
  • tst_QLineEdit
  • tst_QListView
  • tst_QSortFilterProxyModel
  • tst_QTreeView
4295-112437
155 return lst.at(index.row());
executed 24193 times by 17 tests: return lst.at(index.row());
Executed by:
  • tst_ModelTest
  • tst_QAbstractItemView
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontComboBox
  • tst_QFontDialog
  • tst_QGraphicsProxyWidget
  • tst_QIdentityProxyModel
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QLineEdit
  • tst_QListView
  • tst_QListWidget
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
  • tst_QTreeView
24193
156-
157 return QVariant();
executed 108142 times by 14 tests: return QVariant();
Executed by:
  • tst_ModelTest
  • tst_QAbstractItemView
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontComboBox
  • tst_QFontDialog
  • tst_QGraphicsProxyWidget
  • tst_QIdentityProxyModel
  • tst_QItemModel
  • tst_QLineEdit
  • tst_QListView
  • tst_QSortFilterProxyModel
  • tst_QTreeView
108142
158}-
159-
160/*!-
161 Returns the flags for the item with the given \a index.-
162-
163 Valid items are enabled, selectable, editable, drag enabled and drop enabled.-
164-
165 \sa QAbstractItemModel::flags()-
166*/-
167-
168Qt::ItemFlags QStringListModel::flags(const QModelIndex &index) const-
169{-
170 if (!index.isValid())
!index.isValid()Description
TRUEevaluated 18 times by 3 tests
Evaluated by:
  • tst_ModelTest
  • tst_QItemModel
  • tst_QSortFilterProxyModel
FALSEevaluated 10582 times by 13 tests
Evaluated by:
  • tst_QAbstractItemView
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontComboBox
  • tst_QFontDialog
  • tst_QGraphicsProxyWidget
  • tst_QItemSelectionModel
  • tst_QLineEdit
  • tst_QListView
  • tst_QListWidget
  • tst_QSortFilterProxyModel
  • tst_QTreeView
18-10582
171 return QAbstractListModel::flags(index) | Qt::ItemIsDropEnabled;
executed 18 times by 3 tests: return QAbstractListModel::flags(index) | Qt::ItemIsDropEnabled;
Executed by:
  • tst_ModelTest
  • tst_QItemModel
  • tst_QSortFilterProxyModel
18
172-
173 return QAbstractListModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
executed 10582 times by 13 tests: return QAbstractListModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
Executed by:
  • tst_QAbstractItemView
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontComboBox
  • tst_QFontDialog
  • tst_QGraphicsProxyWidget
  • tst_QItemSelectionModel
  • tst_QLineEdit
  • tst_QListView
  • tst_QListWidget
  • tst_QSortFilterProxyModel
  • tst_QTreeView
10582
174}-
175-
176/*!-
177 Sets the data for the specified \a role in the item with the given-
178 \a index in the model, to the provided \a value.-
179-
180 The dataChanged() signal is emitted if the item is changed.-
181-
182 \sa Qt::ItemDataRole, data()-
183*/-
184-
185bool QStringListModel::setData(const QModelIndex &index, const QVariant &value, int role)-
186{-
187 if (index.row() >= 0 && index.row() < lst.size()
index.row() >= 0Description
TRUEevaluated 37 times by 4 tests
Evaluated by:
  • tst_QAbstractItemView
  • tst_QItemModel
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
FALSEevaluated 35 times by 3 tests
Evaluated by:
  • tst_ModelTest
  • tst_QItemModel
  • tst_QSortFilterProxyModel
index.row() < lst.size()Description
TRUEevaluated 37 times by 4 tests
Evaluated by:
  • tst_QAbstractItemView
  • tst_QItemModel
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
FALSEnever evaluated
0-37
188 && (role == Qt::EditRole || role == Qt::DisplayRole)) {
role == Qt::EditRoleDescription
TRUEevaluated 34 times by 4 tests
Evaluated by:
  • tst_QAbstractItemView
  • tst_QItemModel
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
FALSEevaluated 3 times by 2 tests
Evaluated by:
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
role == Qt::DisplayRoleDescription
TRUEevaluated 3 times by 2 tests
Evaluated by:
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
FALSEnever evaluated
0-34
189 lst.replace(index.row(), value.toString());-
190 QVector<int> roles;-
191 roles.reserve(2);-
192 roles.append(Qt::DisplayRole);-
193 roles.append(Qt::EditRole);-
194 emit dataChanged(index, index, roles);-
195 // once Q_COMPILER_UNIFORM_INIT can be used, change to:-
196 // emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});-
197 return true;
executed 37 times by 4 tests: return true;
Executed by:
  • tst_QAbstractItemView
  • tst_QItemModel
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
37
198 }-
199 return false;
executed 35 times by 3 tests: return false;
Executed by:
  • tst_ModelTest
  • tst_QItemModel
  • tst_QSortFilterProxyModel
35
200}-
201-
202/*!-
203 Inserts \a count rows into the model, beginning at the given \a row.-
204-
205 The \a parent index of the rows is optional and is only used for-
206 consistency with QAbstractItemModel. By default, a null index is-
207 specified, indicating that the rows are inserted in the top level of-
208 the model.-
209-
210 \sa QAbstractItemModel::insertRows()-
211*/-
212-
213bool QStringListModel::insertRows(int row, int count, const QModelIndex &parent)-
214{-
215 if (count < 1 || row < 0 || row > rowCount(parent))
count < 1Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • tst_QItemModel
FALSEevaluated 37 times by 7 tests
Evaluated by:
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QHeaderView
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
row < 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QItemModel
FALSEevaluated 33 times by 7 tests
Evaluated by:
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QHeaderView
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
row > rowCount(parent)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QItemModel
FALSEevaluated 29 times by 7 tests
Evaluated by:
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QHeaderView
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
4-37
216 return false;
executed 24 times by 1 test: return false;
Executed by:
  • tst_QItemModel
24
217-
218 beginInsertRows(QModelIndex(), row, row + count - 1);-
219-
220 for (int r = 0; r < count; ++r)
r < countDescription
TRUEevaluated 140 times by 7 tests
Evaluated by:
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QHeaderView
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
FALSEevaluated 29 times by 7 tests
Evaluated by:
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QHeaderView
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
29-140
221 lst.insert(row, QString());
executed 140 times by 7 tests: lst.insert(row, QString());
Executed by:
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QHeaderView
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
140
222-
223 endInsertRows();-
224-
225 return true;
executed 29 times by 7 tests: return true;
Executed by:
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QHeaderView
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QSortFilterProxyModel
  • tst_QStringListModel
29
226}-
227-
228/*!-
229 Removes \a count rows from the model, beginning at the given \a row.-
230-
231 The \a parent index of the rows is optional and is only used for-
232 consistency with QAbstractItemModel. By default, a null index is-
233 specified, indicating that the rows are removed in the top level of-
234 the model.-
235-
236 \sa QAbstractItemModel::removeRows()-
237*/-
238-
239bool QStringListModel::removeRows(int row, int count, const QModelIndex &parent)-
240{-
241 if (count <= 0 || row < 0 || (row + count) > rowCount(parent))
count <= 0Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • tst_QItemModel
FALSEevaluated 39 times by 5 tests
Evaluated by:
  • tst_QAbstractItemView
  • tst_QHeaderView
  • tst_QItemModel
  • tst_QListView
  • tst_QStringListModel
row < 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_QItemModel
FALSEevaluated 33 times by 5 tests
Evaluated by:
  • tst_QAbstractItemView
  • tst_QHeaderView
  • tst_QItemModel
  • tst_QListView
  • tst_QStringListModel
(row + count) ...wCount(parent)Description
TRUEevaluated 9 times by 2 tests
Evaluated by:
  • tst_QItemModel
  • tst_QStringListModel
FALSEevaluated 24 times by 5 tests
Evaluated by:
  • tst_QAbstractItemView
  • tst_QHeaderView
  • tst_QItemModel
  • tst_QListView
  • tst_QStringListModel
6-39
242 return false;
executed 31 times by 2 tests: return false;
Executed by:
  • tst_QItemModel
  • tst_QStringListModel
31
243-
244 beginRemoveRows(QModelIndex(), row, row + count - 1);-
245-
246 const auto it = lst.begin() + row;-
247 lst.erase(it, it + count);-
248-
249 endRemoveRows();-
250-
251 return true;
executed 24 times by 5 tests: return true;
Executed by:
  • tst_QAbstractItemView
  • tst_QHeaderView
  • tst_QItemModel
  • tst_QListView
  • tst_QStringListModel
24
252}-
253-
254static bool ascendingLessThan(const QPair<QString, int> &s1, const QPair<QString, int> &s2)-
255{-
256 return s1.first < s2.first;
executed 952 times by 2 tests: return s1.first < s2.first;
Executed by:
  • tst_QItemModel
  • tst_QTableView
952
257}-
258-
259static bool decendingLessThan(const QPair<QString, int> &s1, const QPair<QString, int> &s2)-
260{-
261 return s1.first > s2.first;
executed 26 times by 1 test: return s1.first > s2.first;
Executed by:
  • tst_QTableView
26
262}-
263-
264/*!-
265 \reimp-
266*/-
267void QStringListModel::sort(int, Qt::SortOrder order)-
268{-
269 emit layoutAboutToBeChanged(QList<QPersistentModelIndex>(), VerticalSortHint);-
270-
271 QVector<QPair<QString, int> > list;-
272 const int lstCount = lst.count();-
273 list.reserve(lstCount);-
274 for (int i = 0; i < lstCount; ++i)
i < lstCountDescription
TRUEevaluated 347 times by 2 tests
Evaluated by:
  • tst_QItemModel
  • tst_QTableView
FALSEevaluated 19 times by 2 tests
Evaluated by:
  • tst_QItemModel
  • tst_QTableView
19-347
275 list.append(QPair<QString, int>(lst.at(i), i));
executed 347 times by 2 tests: list.append(QPair<QString, int>(lst.at(i), i));
Executed by:
  • tst_QItemModel
  • tst_QTableView
347
276-
277 if (order == Qt::AscendingOrder)
order == Qt::AscendingOrderDescription
TRUEevaluated 15 times by 2 tests
Evaluated by:
  • tst_QItemModel
  • tst_QTableView
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QTableView
4-15
278 std::sort(list.begin(), list.end(), ascendingLessThan);
executed 15 times by 2 tests: std::sort(list.begin(), list.end(), ascendingLessThan);
Executed by:
  • tst_QItemModel
  • tst_QTableView
15
279 else-
280 std::sort(list.begin(), list.end(), decendingLessThan);
executed 4 times by 1 test: std::sort(list.begin(), list.end(), decendingLessThan);
Executed by:
  • tst_QTableView
4
281-
282 lst.clear();-
283 QVector<int> forwarding(lstCount);-
284 for (int i = 0; i < lstCount; ++i) {
i < lstCountDescription
TRUEevaluated 347 times by 2 tests
Evaluated by:
  • tst_QItemModel
  • tst_QTableView
FALSEevaluated 19 times by 2 tests
Evaluated by:
  • tst_QItemModel
  • tst_QTableView
19-347
285 lst.append(list.at(i).first);-
286 forwarding[list.at(i).second] = i;-
287 }
executed 347 times by 2 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QTableView
347
288-
289 QModelIndexList oldList = persistentIndexList();-
290 QModelIndexList newList;-
291 const int numOldIndexes = oldList.count();-
292 newList.reserve(numOldIndexes);-
293 for (int i = 0; i < numOldIndexes; ++i)
i < numOldIndexesDescription
TRUEnever evaluated
FALSEevaluated 19 times by 2 tests
Evaluated by:
  • tst_QItemModel
  • tst_QTableView
0-19
294 newList.append(index(forwarding.at(oldList.at(i).row()), 0));
never executed: newList.append(index(forwarding.at(oldList.at(i).row()), 0));
0
295 changePersistentIndexList(oldList, newList);-
296-
297 emit layoutChanged(QList<QPersistentModelIndex>(), VerticalSortHint);-
298}
executed 19 times by 2 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QTableView
19
299-
300/*!-
301 Returns the string list used by the model to store data.-
302*/-
303QStringList QStringListModel::stringList() const-
304{-
305 return lst;
executed 1498 times by 2 tests: return lst;
Executed by:
  • tst_QFontDialog
  • tst_QTableView
1498
306}-
307-
308/*!-
309 Sets the model's internal string list to \a strings. The model will-
310 notify any attached views that its underlying data has changed.-
311-
312 \sa dataChanged()-
313*/-
314void QStringListModel::setStringList(const QStringList &strings)-
315{-
316 beginResetModel();-
317 lst = strings;-
318 endResetModel();-
319}
executed 628 times by 11 tests: end of block
Executed by:
  • tst_ModelTest
  • tst_QComboBox
  • tst_QCompleter
  • tst_QFontComboBox
  • tst_QFontDialog
  • tst_QGraphicsProxyWidget
  • tst_QItemModel
  • tst_QItemSelectionModel
  • tst_QListView
  • tst_QSortFilterProxyModel
  • tst_QTableView
628
320-
321/*!-
322 \reimp-
323*/-
324Qt::DropActions QStringListModel::supportedDropActions() const-
325{-
326 return QAbstractItemModel::supportedDropActions() | Qt::MoveAction;
executed 19 times by 4 tests: return QAbstractItemModel::supportedDropActions() | Qt::MoveAction;
Executed by:
  • tst_ModelTest
  • tst_QAbstractItemModel
  • tst_QItemModel
  • tst_QSortFilterProxyModel
19
327}-
328-
329QT_END_NAMESPACE-
330-
331#endif // QT_NO_STRINGLISTMODEL-
Source codeSwitch to Preprocessed file

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