qstringlistmodel.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/itemmodels/qstringlistmodel.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8QStringListModel::QStringListModel(QObject *parent)-
9 : QAbstractListModel(parent)-
10{-
11}-
12-
13-
14-
15-
16-
17-
18QStringListModel::QStringListModel(const QStringList &strings, QObject *parent)-
19 : QAbstractListModel(parent), lst(strings)-
20{-
21}-
22int QStringListModel::rowCount(const QModelIndex &parent) const-
23{-
24 if (parent.isValid())-
25 return 0;-
26-
27 return lst.count();-
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())-
36 return QModelIndex();-
37-
38 return createIndex(row, 0);-
39}-
40QVariant QStringListModel::data(const QModelIndex &index, int role) const-
41{-
42 if (index.row() < 0 || index.row() >= lst.size())-
43 return QVariant();-
44-
45 if (role == Qt::DisplayRole || role == Qt::EditRole)-
46 return lst.at(index.row());-
47-
48 return QVariant();-
49}-
50Qt::ItemFlags QStringListModel::flags(const QModelIndex &index) const-
51{-
52 if (!index.isValid())-
53 return QAbstractListModel::flags(index) | Qt::ItemIsDropEnabled;-
54-
55 return QAbstractListModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;-
56}-
57bool QStringListModel::setData(const QModelIndex &index, const QVariant &value, int role)-
58{-
59 if (index.row() >= 0 && index.row() < lst.size()-
60 && (role == Qt::EditRole || role == Qt::DisplayRole)) {-
61 lst.replace(index.row(), value.toString());-
62 QVector<int> roles;-
63 roles.reserve(2);-
64 roles.append(Qt::DisplayRole);-
65 roles.append(Qt::EditRole);-
66 dataChanged(index, index, roles);-
67-
68-
69 return true;-
70 }-
71 return false;-
72}-
73bool QStringListModel::insertRows(int row, int count, const QModelIndex &parent)-
74{-
75 if (count < 1 || row < 0 || row > rowCount(parent))-
76 return false;-
77-
78 beginInsertRows(QModelIndex(), row, row + count - 1);-
79-
80 for (int r = 0; r < count; ++r)-
81 lst.insert(row, QString());-
82-
83 endInsertRows();-
84-
85 return true;-
86}-
87bool QStringListModel::removeRows(int row, int count, const QModelIndex &parent)-
88{-
89 if (count <= 0
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 < 0
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
row + count) > rowCount(parent)
(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
90 return
executed 31 times by 2 tests: return false;
Executed by:
  • tst_QItemModel
  • tst_QStringListModel
false;
executed 31 times by 2 tests: return false;
Executed by:
  • tst_QItemModel
  • tst_QStringListModel
31
91-
92 beginRemoveRows(QModelIndex(), row, row + count - 1);-
93-
94 for (int rconst auto it = 0; r < countlst.begin() + row;-
95 ++r)lst.removeAterase(rowit, it + count);-
96-
97 endRemoveRows();-
98-
99 return
executed 24 times by 5 tests: return true;
Executed by:
  • tst_QAbstractItemView
  • tst_QHeaderView
  • tst_QItemModel
  • tst_QListView
  • tst_QStringListModel
true;
executed 24 times by 5 tests: return true;
Executed by:
  • tst_QAbstractItemView
  • tst_QHeaderView
  • tst_QItemModel
  • tst_QListView
  • tst_QStringListModel
24
100}-
101-
102static bool ascendingLessThan(const QPair<QString, int> &s1, const QPair<QString, int> &s2)-
103{-
104 return s1.first < s2.first;-
105}-
106-
107static bool decendingLessThan(const QPair<QString, int> &s1, const QPair<QString, int> &s2)-
108{-
109 return s1.first > s2.first;-
110}-
111-
112-
113-
114-
115void QStringListModel::sort(int, Qt::SortOrder order)-
116{-
117 layoutAboutToBeChanged(QList<QPersistentModelIndex>(), VerticalSortHint);-
118-
119 QListQVector<QPair<QString, int> > list;-
120 const int lstCount = lst.count();-
121 list.reserve(lstCount);-
122 for (int i = 0; i < lstCount
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
; ++i)
19-347
123 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
124-
125 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
126 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
127 else-
128 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
129-
130 lst.clear();-
131 QVector<int> forwarding(list.count());lstCount);-
132 for (int i = 0; i < list.count();lstCount
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
;
++i) {
19-347
133 lst.append(list.at(i).first);-
134 forwarding[list.at(i).second] = i;-
135 }
executed 347 times by 2 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QTableView
347
136-
137 QModelIndexList oldList = persistentIndexList();-
138 QModelIndexList newList;-
139 const int numOldIndexes = oldList.count();-
140 newList.reserve(numOldIndexes);-
141 for (int i = 0; i < numOldIndexes
i < numOldIndexesDescription
TRUEnever evaluated
FALSEevaluated 19 times by 2 tests
Evaluated by:
  • tst_QItemModel
  • tst_QTableView
; ++i)
0-19
142 newList.append(index(forwarding.at(oldList.at(i).row()), 0));
never executed: newList.append(index(forwarding.at(oldList.at(i).row()), 0));
0
143 changePersistentIndexList(oldList, newList);-
144-
145 layoutChanged(QList<QPersistentModelIndex>(), VerticalSortHint);-
146}
executed 19 times by 2 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QTableView
19
147-
148-
149-
150-
151QStringList QStringListModel::stringList() const-
152{-
153 return lst;-
154}-
155-
156-
157-
158-
159-
160-
161-
162void QStringListModel::setStringList(const QStringList &strings)-
163{-
164 beginResetModel();-
165 lst = strings;-
166 endResetModel();-
167}-
168-
169-
170-
171-
172Qt::DropActions QStringListModel::supportedDropActions() const-
173{-
174 return QAbstractItemModel::supportedDropActions() | Qt::MoveAction;-
175}-
176-
177-
Switch to Source codePreprocessed file

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