itemmodels/qstringlistmodel.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8QStringListModel::QStringListModel(QObject *parent) -
9 : QAbstractListModel(parent) -
10{ -
11}
executed: }
Execution Count:323
323
12 -
13 -
14 -
15 -
16 -
17 -
18QStringListModel::QStringListModel(const QStringList &strings, QObject *parent) -
19 : QAbstractListModel(parent), lst(strings) -
20{ -
21}
executed: }
Execution Count:50
50
22int QStringListModel::rowCount(const QModelIndex &parent) const -
23{ -
24 if (parent.isValid())
evaluated: parent.isValid()
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:86753
18-86753
25 return 0;
executed: return 0;
Execution Count:18
18
26 -
27 return lst.count();
executed: return lst.count();
Execution Count:86753
86753
28} -
29 -
30 -
31 -
32 -
33QModelIndex QStringListModel::sibling(int row, int column, const QModelIndex &idx) const -
34{ -
35 if (!idx.isValid() || column != 0 || row >= lst.count())
evaluated: !idx.isValid()
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:73
partially evaluated: column != 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:73
partially evaluated: row >= lst.count()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:73
0-73
36 return QModelIndex();
executed: return QModelIndex();
Execution Count:5
5
37 -
38 return createIndex(row, 0);
executed: return createIndex(row, 0);
Execution Count:73
73
39} -
40QVariant QStringListModel::data(const QModelIndex &index, int role) const -
41{ -
42 if (index.row() < 0 || index.row() >= lst.size())
evaluated: index.row() < 0
TRUEFALSE
yes
Evaluation Count:4784
yes
Evaluation Count:164920
partially evaluated: index.row() >= lst.size()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:164920
0-164920
43 return QVariant();
executed: return QVariant();
Execution Count:4784
4784
44 -
45 if (role == Qt::DisplayRole || role == Qt::EditRole)
evaluated: role == Qt::DisplayRole
TRUEFALSE
yes
Evaluation Count:21632
yes
Evaluation Count:143288
evaluated: role == Qt::EditRole
TRUEFALSE
yes
Evaluation Count:600
yes
Evaluation Count:142688
600-143288
46 return lst.at(index.row());
executed: return lst.at(index.row());
Execution Count:22232
22232
47 -
48 return QVariant();
executed: return QVariant();
Execution Count:142688
142688
49} -
50Qt::ItemFlags QStringListModel::flags(const QModelIndex &index) const -
51{ -
52 if (!index.isValid())
evaluated: !index.isValid()
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:8640
18-8640
53 return QAbstractItemModel::flags(index) | Qt::ItemIsDropEnabled;
executed: return QAbstractItemModel::flags(index) | Qt::ItemIsDropEnabled;
Execution Count:18
18
54 -
55 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
executed: return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
Execution Count:8640
8640
56} -
57bool QStringListModel::setData(const QModelIndex &index, const QVariant &value, int role) -
58{ -
59 if (index.row() >= 0 && index.row() < lst.size()
evaluated: index.row() >= 0
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:35
partially evaluated: index.row() < lst.size()
TRUEFALSE
yes
Evaluation Count:29
no
Evaluation Count:0
0-35
60 && (role == Qt::EditRole || role == Qt::DisplayRole)) {
partially evaluated: role == Qt::EditRole
TRUEFALSE
yes
Evaluation Count:29
no
Evaluation Count:0
never evaluated: role == Qt::DisplayRole
0-29
61 lst.replace(index.row(), value.toString()); -
62 dataChanged(index, index, QVector<int>() << role); -
63 return true;
executed: return true;
Execution Count:29
29
64 } -
65 return false;
executed: return false;
Execution Count:35
35
66} -
67bool QStringListModel::insertRows(int row, int count, const QModelIndex &parent) -
68{ -
69 if (count < 1 || row < 0 || row > rowCount(parent))
evaluated: count < 1
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:34
evaluated: row < 0
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:30
evaluated: row > rowCount(parent)
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:26
4-34
70 return false;
executed: return false;
Execution Count:24
24
71 -
72 beginInsertRows(QModelIndex(), row, row + count - 1); -
73 -
74 for (int r = 0; r < count; ++r)
evaluated: r < count
TRUEFALSE
yes
Evaluation Count:137
yes
Evaluation Count:26
26-137
75 lst.insert(row, QString());
executed: lst.insert(row, QString());
Execution Count:137
137
76 -
77 endInsertRows(); -
78 -
79 return true;
executed: return true;
Execution Count:26
26
80} -
81bool QStringListModel::removeRows(int row, int count, const QModelIndex &parent) -
82{ -
83 if (count <= 0 || row < 0 || (row + count) > rowCount(parent))
evaluated: count <= 0
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:37
evaluated: row < 0
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:31
evaluated: (row + count) > rowCount(parent)
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:22
6-37
84 return false;
executed: return false;
Execution Count:31
31
85 -
86 beginRemoveRows(QModelIndex(), row, row + count - 1); -
87 -
88 for (int r = 0; r < count; ++r)
evaluated: r < count
TRUEFALSE
yes
Evaluation Count:127
yes
Evaluation Count:22
22-127
89 lst.removeAt(row);
executed: lst.removeAt(row);
Execution Count:127
127
90 -
91 endRemoveRows(); -
92 -
93 return true;
executed: return true;
Execution Count:22
22
94} -
95 -
96static bool ascendingLessThan(const QPair<QString, int> &s1, const QPair<QString, int> &s2) -
97{ -
98 return s1.first < s2.first;
executed: return s1.first < s2.first;
Execution Count:844
844
99} -
100 -
101static bool decendingLessThan(const QPair<QString, int> &s1, const QPair<QString, int> &s2) -
102{ -
103 return s1.first > s2.first;
executed: return s1.first > s2.first;
Execution Count:26
26
104} -
105 -
106 -
107 -
108 -
109void QStringListModel::sort(int, Qt::SortOrder order) -
110{ -
111 layoutAboutToBeChanged(QList<QPersistentModelIndex>(), VerticalSortHint); -
112 -
113 QList<QPair<QString, int> > list; -
114 for (int i = 0; i < lst.count(); ++i)
evaluated: i < lst.count()
TRUEFALSE
yes
Evaluation Count:347
yes
Evaluation Count:19
19-347
115 list.append(QPair<QString, int>(lst.at(i), i));
executed: list.append(QPair<QString, int>(lst.at(i), i));
Execution Count:347
347
116 -
117 if (order == Qt::AscendingOrder)
evaluated: order == Qt::AscendingOrder
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:4
4-15
118 std::sort(list.begin(), list.end(), ascendingLessThan);
executed: std::sort(list.begin(), list.end(), ascendingLessThan);
Execution Count:15
15
119 else -
120 std::sort(list.begin(), list.end(), decendingLessThan);
executed: std::sort(list.begin(), list.end(), decendingLessThan);
Execution Count:4
4
121 -
122 lst.clear(); -
123 QVector<int> forwarding(list.count()); -
124 for (int i = 0; i < list.count(); ++i) {
evaluated: i < list.count()
TRUEFALSE
yes
Evaluation Count:347
yes
Evaluation Count:19
19-347
125 lst.append(list.at(i).first); -
126 forwarding[list.at(i).second] = i; -
127 }
executed: }
Execution Count:347
347
128 -
129 QModelIndexList oldList = persistentIndexList(); -
130 QModelIndexList newList; -
131 for (int i = 0; i < oldList.count(); ++i)
partially evaluated: i < oldList.count()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:19
0-19
132 newList.append(index(forwarding.at(oldList.at(i).row()), 0));
never executed: newList.append(index(forwarding.at(oldList.at(i).row()), 0));
0
133 changePersistentIndexList(oldList, newList); -
134 -
135 layoutChanged(QList<QPersistentModelIndex>(), VerticalSortHint); -
136}
executed: }
Execution Count:19
19
137 -
138 -
139 -
140 -
141QStringList QStringListModel::stringList() const -
142{ -
143 return lst;
executed: return lst;
Execution Count:2514
2514
144} -
145 -
146 -
147 -
148 -
149 -
150 -
151 -
152void QStringListModel::setStringList(const QStringList &strings) -
153{ -
154 beginResetModel(); -
155 lst = strings; -
156 endResetModel(); -
157}
executed: }
Execution Count:829
829
158 -
159 -
160 -
161 -
162Qt::DropActions QStringListModel::supportedDropActions() const -
163{ -
164 return QAbstractItemModel::supportedDropActions() | Qt::MoveAction;
executed: return QAbstractItemModel::supportedDropActions() | Qt::MoveAction;
Execution Count:19
19
165} -
166 -
167 -
168 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial