models/qsqltablemodel.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7typedef QSqlTableModelSql Sql; -
8 -
9 -
10 -
11 -
12QSqlRecord QSqlTableModelPrivate::record(const QVector<QVariant> &values) const -
13{ -
14 QSqlRecord r = rec; -
15 for (int i = 0; i < r.count() && i < values.count(); ++i)
never evaluated: i < r.count()
never evaluated: i < values.count()
0
16 r.setValue(i, values.at(i));
never executed: r.setValue(i, values.at(i));
0
17 return r;
never executed: return r;
0
18} -
19 -
20int QSqlTableModelPrivate::nameToIndex(const QString &name) const -
21{ -
22 return rec.indexOf(strippedFieldName(name));
executed: return rec.indexOf(strippedFieldName(name));
Execution Count:116
116
23} -
24 -
25QString QSqlTableModelPrivate::strippedFieldName(const QString &name) const -
26{ -
27 QString fieldname = name; -
28 if (db.driver()->isIdentifierEscaped(fieldname, QSqlDriver::FieldName))
evaluated: db.driver()->isIdentifierEscaped(fieldname, QSqlDriver::FieldName)
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:129
4-129
29 fieldname = db.driver()->stripDelimiters(fieldname, QSqlDriver::FieldName);
executed: fieldname = db.driver()->stripDelimiters(fieldname, QSqlDriver::FieldName);
Execution Count:4
4
30 return fieldname;
executed: return fieldname;
Execution Count:133
133
31} -
32 -
33int QSqlTableModelPrivate::insertCount(int maxRow) const -
34{ -
35 int cnt = 0; -
36 CacheMap::ConstIterator i = cache.constBegin(); -
37 const CacheMap::ConstIterator e = cache.constEnd(); -
38 for ( ; i != e && (maxRow < 0 || i.key() <= maxRow); ++i)
evaluated: i != e
TRUEFALSE
yes
Evaluation Count:2172
yes
Evaluation Count:12804
evaluated: maxRow < 0
TRUEFALSE
yes
Evaluation Count:1714
yes
Evaluation Count:458
evaluated: i.key() <= maxRow
TRUEFALSE
yes
Evaluation Count:380
yes
Evaluation Count:78
78-12804
39 if (i.value().insert())
evaluated: i.value().insert()
TRUEFALSE
yes
Evaluation Count:1278
yes
Evaluation Count:816
816-1278
40 ++cnt;
executed: ++cnt;
Execution Count:1278
1278
41 -
42 return cnt;
executed: return cnt;
Execution Count:12882
12882
43} -
44 -
45void QSqlTableModelPrivate::initRecordAndPrimaryIndex() -
46{ -
47 rec = db.record(tableName); -
48 primaryIndex = db.primaryIndex(tableName); -
49 initColOffsets(rec.count()); -
50}
executed: }
Execution Count:185
185
51 -
52void QSqlTableModelPrivate::clear() -
53{ -
54 sortColumn = -1; -
55 sortOrder = Qt::AscendingOrder; -
56 tableName.clear(); -
57 editQuery.clear(); -
58 cache.clear(); -
59 primaryIndex.clear(); -
60 rec.clear(); -
61 filter.clear(); -
62}
executed: }
Execution Count:190
190
63 -
64void QSqlTableModelPrivate::clearCache() -
65{ -
66 cache.clear(); -
67}
executed: }
Execution Count:315
315
68 -
69void QSqlTableModelPrivate::revertCachedRow(int row) -
70{ -
71 QSqlTableModel * const q = q_func(); -
72 ModifiedRow r = cache.value(row); -
73 -
74 switch (r.op()) { -
75 case QSqlTableModelPrivate::None: -
76 qt_noop(); -
77 return;
never executed: return;
0
78 case QSqlTableModelPrivate::Update: -
79 case QSqlTableModelPrivate::Delete: -
80 if (!r.submitted()) {
evaluated: !r.submitted()
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:3
3-17
81 cache[row].revert(); -
82 q->dataChanged(q->createIndex(row, 0), -
83 q->createIndex(row, q->columnCount() - 1)); -
84 }
executed: }
Execution Count:17
17
85 break;
executed: break;
Execution Count:20
20
86 case QSqlTableModelPrivate::Insert: { -
87 QMap<int, QSqlTableModelPrivate::ModifiedRow>::Iterator it = cache.find(row); -
88 if (it == cache.end())
partially evaluated: it == cache.end()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:32
0-32
89 return;
never executed: return;
0
90 q->beginRemoveRows(QModelIndex(), row, row); -
91 it = cache.erase(it); -
92 while (it != cache.end()) {
evaluated: it != cache.end()
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:32
5-32
93 int oldKey = it.key(); -
94 const QSqlTableModelPrivate::ModifiedRow oldValue = it.value(); -
95 cache.erase(it); -
96 it = cache.insert(oldKey - 1, oldValue); -
97 ++it; -
98 }
executed: }
Execution Count:5
5
99 q->endRemoveRows(); -
100 break; }
executed: break;
Execution Count:32
32
101 } -
102}
executed: }
Execution Count:52
52
103 -
104bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement, -
105 const QSqlRecord &rec, const QSqlRecord &whereValues) -
106{ -
107 if (stmt.isEmpty())
partially evaluated: stmt.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
108 return false;
never executed: return false;
0
109 -
110 -
111 if (editQuery.driver() != db.driver())
evaluated: editQuery.driver() != db.driver()
TRUEFALSE
yes
Evaluation Count:51
yes
Evaluation Count:72
51-72
112 editQuery = QSqlQuery(db);
executed: editQuery = QSqlQuery(db);
Execution Count:51
51
113 -
114 -
115 -
116 if (db.driver()->hasFeature(QSqlDriver::SimpleLocking))
partially evaluated: db.driver()->hasFeature(QSqlDriver::SimpleLocking)
TRUEFALSE
yes
Evaluation Count:123
no
Evaluation Count:0
0-123
117 const_cast<QSqlResult *>(query.result())->detachFromResultSet();
executed: const_cast<QSqlResult *>(query.result())->detachFromResultSet();
Execution Count:123
123
118 -
119 if (prepStatement) {
partially evaluated: prepStatement
TRUEFALSE
yes
Evaluation Count:123
no
Evaluation Count:0
0-123
120 if (editQuery.lastQuery() != stmt) {
evaluated: editQuery.lastQuery() != stmt
TRUEFALSE
yes
Evaluation Count:79
yes
Evaluation Count:44
44-79
121 if (!editQuery.prepare(stmt)) {
partially evaluated: !editQuery.prepare(stmt)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:79
0-79
122 error = editQuery.lastError(); -
123 return false;
never executed: return false;
0
124 } -
125 }
executed: }
Execution Count:79
79
126 int i; -
127 for (i = 0; i < rec.count(); ++i)
evaluated: i < rec.count()
TRUEFALSE
yes
Evaluation Count:298
yes
Evaluation Count:123
123-298
128 if (rec.isGenerated(i))
evaluated: rec.isGenerated(i)
TRUEFALSE
yes
Evaluation Count:192
yes
Evaluation Count:106
106-192
129 editQuery.addBindValue(rec.value(i));
executed: editQuery.addBindValue(rec.value(i));
Execution Count:192
192
130 for (i = 0; i < whereValues.count(); ++i)
evaluated: i < whereValues.count()
TRUEFALSE
yes
Evaluation Count:156
yes
Evaluation Count:123
123-156
131 if (whereValues.isGenerated(i) && !whereValues.isNull(i))
partially evaluated: whereValues.isGenerated(i)
TRUEFALSE
yes
Evaluation Count:156
no
Evaluation Count:0
evaluated: !whereValues.isNull(i)
TRUEFALSE
yes
Evaluation Count:150
yes
Evaluation Count:6
0-156
132 editQuery.addBindValue(whereValues.value(i));
executed: editQuery.addBindValue(whereValues.value(i));
Execution Count:150
150
133 -
134 if (!editQuery.exec()) {
evaluated: !editQuery.exec()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:117
6-117
135 error = editQuery.lastError(); -
136 return false;
executed: return false;
Execution Count:6
6
137 } -
138 } else {
executed: }
Execution Count:117
117
139 if (!editQuery.exec(stmt)) {
never evaluated: !editQuery.exec(stmt)
0
140 error = editQuery.lastError(); -
141 return false;
never executed: return false;
0
142 } -
143 }
never executed: }
0
144 return true;
executed: return true;
Execution Count:117
117
145} -
146 -
147QSqlRecord QSqlTableModelPrivate::primaryValues(const QSqlRecord &rec, const QSqlRecord &pIndex) -
148{ -
149 QSqlRecord pValues(pIndex); -
150 -
151 for (int i = pValues.count() - 1; i >= 0; --i)
evaluated: i >= 0
TRUEFALSE
yes
Evaluation Count:278
yes
Evaluation Count:133
133-278
152 pValues.setValue(i, rec.value(pValues.fieldName(i)));
executed: pValues.setValue(i, rec.value(pValues.fieldName(i)));
Execution Count:278
278
153 -
154 return pValues;
executed: return pValues;
Execution Count:133
133
155} -
156 -
157QSqlRecord QSqlTableModelPrivate::primaryValues(int row) const -
158{ -
159 const QSqlTableModel * const q = q_func(); -
160 -
161 const QSqlRecord &pIndex = primaryIndex.isEmpty() ? rec : primaryIndex;
evaluated: primaryIndex.isEmpty()
TRUEFALSE
yes
Evaluation Count:73
yes
Evaluation Count:60
60-73
162 -
163 ModifiedRow mr = cache.value(row); -
164 if (mr.op() != None)
evaluated: mr.op() != None
TRUEFALSE
yes
Evaluation Count:131
yes
Evaluation Count:2
2-131
165 return mr.primaryValues(pIndex);
executed: return mr.primaryValues(pIndex);
Execution Count:131
131
166 else -
167 return primaryValues(q->QSqlQueryModel::record(row), pIndex);
executed: return primaryValues(q->QSqlQueryModel::record(row), pIndex);
Execution Count:2
2
168} -
169QSqlTableModel::QSqlTableModel(QObject *parent, QSqlDatabase db) -
170 : QSqlQueryModel(*new QSqlTableModelPrivate, parent) -
171{ -
172 QSqlTableModelPrivate * const d = d_func(); -
173 d->db = db.isValid() ? db : QSqlDatabase::database();
evaluated: db.isValid()
TRUEFALSE
yes
Evaluation Count:92
yes
Evaluation Count:51
51-92
174}
executed: }
Execution Count:143
143
175 -
176 -
177 -
178QSqlTableModel::QSqlTableModel(QSqlTableModelPrivate &dd, QObject *parent, QSqlDatabase db) -
179 : QSqlQueryModel(dd, parent) -
180{ -
181 QSqlTableModelPrivate * const d = d_func(); -
182 d->db = db.isValid() ? db : QSqlDatabase::database();
partially evaluated: db.isValid()
TRUEFALSE
yes
Evaluation Count:31
no
Evaluation Count:0
0-31
183}
executed: }
Execution Count:31
31
184 -
185 -
186 -
187 -
188QSqlTableModel::~QSqlTableModel() -
189{ -
190} -
191void QSqlTableModel::setTable(const QString &tableName) -
192{ -
193 QSqlTableModelPrivate * const d = d_func(); -
194 clear(); -
195 d->tableName = tableName; -
196 d->initRecordAndPrimaryIndex(); -
197 -
198 if (d->rec.count() == 0)
evaluated: d->rec.count() == 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:182
1-182
199 d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), 1
200 QSqlError::StatementError);
executed: d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), QSqlError::StatementError);
Execution Count:1
1
201 -
202 -
203 -
204 d->autoColumn.clear(); -
205 for (int c = 0; c < d->rec.count(); ++c) {
evaluated: c < d->rec.count()
TRUEFALSE
yes
Evaluation Count:450
yes
Evaluation Count:178
178-450
206 if (d->rec.field(c).isAutoValue()) {
evaluated: d->rec.field(c).isAutoValue()
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:445
5-445
207 d->autoColumn = d->rec.fieldName(c); -
208 break;
executed: break;
Execution Count:5
5
209 } -
210 }
executed: }
Execution Count:445
445
211}
executed: }
Execution Count:183
183
212 -
213 -
214 -
215 -
216QString QSqlTableModel::tableName() const -
217{ -
218 const QSqlTableModelPrivate * const d = d_func(); -
219 return d->tableName;
executed: return d->tableName;
Execution Count:475
475
220} -
221bool QSqlTableModel::select() -
222{ -
223 QSqlTableModelPrivate * const d = d_func(); -
224 const QString query = selectStatement(); -
225 if (query.isEmpty())
evaluated: query.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:315
1-315
226 return false;
executed: return false;
Execution Count:1
1
227 -
228 beginResetModel(); -
229 -
230 d->clearCache(); -
231 -
232 QSqlQuery qu(query, d->db); -
233 setQuery(qu); -
234 -
235 if (!qu.isActive() || lastError().isValid()) {
evaluated: !qu.isActive()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:313
partially evaluated: lastError().isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:313
0-313
236 -
237 d->initRecordAndPrimaryIndex(); -
238 endResetModel(); -
239 return false;
executed: return false;
Execution Count:2
2
240 } -
241 endResetModel(); -
242 return true;
executed: return true;
Execution Count:313
313
243} -
244bool QSqlTableModel::selectRow(int row) -
245{ -
246 QSqlTableModelPrivate * const d = d_func(); -
247 -
248 if (row < 0 || row >= rowCount())
partially evaluated: row < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:62
partially evaluated: row >= rowCount()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:62
0-62
249 return false;
never executed: return false;
0
250 -
251 const int table_sort_col = d->sortColumn; -
252 d->sortColumn = -1; -
253 const QString table_filter = d->filter; -
254 d->filter = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, -
255 d->tableName, -
256 d->primaryValues(row), -
257 false); -
258 static const QString wh = Sql::where() + Sql::sp(); -
259 if (d->filter.startsWith(wh, Qt::CaseInsensitive))
partially evaluated: d->filter.startsWith(wh, Qt::CaseInsensitive)
TRUEFALSE
yes
Evaluation Count:62
no
Evaluation Count:0
0-62
260 d->filter.remove(0, wh.length());
executed: d->filter.remove(0, wh.length());
Execution Count:62
62
261 -
262 QString stmt; -
263 -
264 if (!d->filter.isEmpty())
partially evaluated: !d->filter.isEmpty()
TRUEFALSE
yes
Evaluation Count:62
no
Evaluation Count:0
0-62
265 stmt = selectStatement();
executed: stmt = selectStatement();
Execution Count:62
62
266 -
267 d->sortColumn = table_sort_col; -
268 d->filter = table_filter; -
269 -
270 if (stmt.isEmpty())
partially evaluated: stmt.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:62
0-62
271 return false;
never executed: return false;
0
272 -
273 bool exists; -
274 QSqlRecord newValues; -
275 -
276 { -
277 QSqlQuery q(d->db); -
278 q.setForwardOnly(true); -
279 if (!q.exec(stmt))
partially evaluated: !q.exec(stmt)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:62
0-62
280 return false;
never executed: return false;
0
281 -
282 exists = q.next(); -
283 newValues = q.record(); -
284 } -
285 -
286 bool needsAddingToCache = !exists || d->cache.contains(row);
evaluated: !exists
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:53
evaluated: d->cache.contains(row)
TRUEFALSE
yes
Evaluation Count:51
yes
Evaluation Count:2
2-53
287 -
288 if (!needsAddingToCache) {
evaluated: !needsAddingToCache
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:60
2-60
289 const QSqlRecord curValues = record(row); -
290 needsAddingToCache = curValues.count() != newValues.count(); -
291 if (!needsAddingToCache) {
partially evaluated: !needsAddingToCache
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
292 -
293 -
294 for (int f = curValues.count() - 1; f >= 0; --f) {
partially evaluated: f >= 0
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
295 if (curValues.value(f) != newValues.value(f))
evaluated: curValues.value(f) != newValues.value(f)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
296 needsAddingToCache = true;
executed: needsAddingToCache = true;
Execution Count:1
1
297 break;
executed: break;
Execution Count:2
2
298 } -
299 }
executed: }
Execution Count:2
2
300 }
executed: }
Execution Count:2
2
301 -
302 if (needsAddingToCache) {
evaluated: needsAddingToCache
TRUEFALSE
yes
Evaluation Count:61
yes
Evaluation Count:1
1-61
303 d->cache[row].refresh(exists, newValues); -
304 headerDataChanged(Qt::Vertical, row, row); -
305 dataChanged(createIndex(row, 0), createIndex(row, columnCount() - 1)); -
306 }
executed: }
Execution Count:61
61
307 -
308 return true;
executed: return true;
Execution Count:62
62
309} -
310 -
311 -
312 -
313 -
314QVariant QSqlTableModel::data(const QModelIndex &index, int role) const -
315{ -
316 const QSqlTableModelPrivate * const d = d_func(); -
317 if (!index.isValid() || (role != Qt::DisplayRole && role != Qt::EditRole))
evaluated: !index.isValid()
TRUEFALSE
yes
Evaluation Count:318
yes
Evaluation Count:2596
evaluated: role != Qt::DisplayRole
TRUEFALSE
yes
Evaluation Count:868
yes
Evaluation Count:1728
evaluated: role != Qt::EditRole
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:859
9-2596
318 return QVariant();
executed: return QVariant();
Execution Count:327
327
319 -
320 const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(index.row()); -
321 if (mrow.op() != QSqlTableModelPrivate::None)
evaluated: mrow.op() != QSqlTableModelPrivate::None
TRUEFALSE
yes
Evaluation Count:392
yes
Evaluation Count:2195
392-2195
322 return mrow.rec().value(index.column());
executed: return mrow.rec().value(index.column());
Execution Count:392
392
323 -
324 return QSqlQueryModel::data(index, role);
executed: return QSqlQueryModel::data(index, role);
Execution Count:2195
2195
325} -
326 -
327 -
328 -
329 -
330QVariant QSqlTableModel::headerData(int section, Qt::Orientation orientation, int role) const -
331{ -
332 const QSqlTableModelPrivate * const d = d_func(); -
333 if (orientation == Qt::Vertical && role == Qt::DisplayRole) {
partially evaluated: orientation == Qt::Vertical
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
never evaluated: role == Qt::DisplayRole
0-4
334 const QSqlTableModelPrivate::Op op = d->cache.value(section).op(); -
335 if (op == QSqlTableModelPrivate::Insert)
never evaluated: op == QSqlTableModelPrivate::Insert
0
336 return QLatin1String("*");
never executed: return QLatin1String("*");
0
337 else if (op == QSqlTableModelPrivate::Delete)
never evaluated: op == QSqlTableModelPrivate::Delete
0
338 return QLatin1String("!");
never executed: return QLatin1String("!");
0
339 } -
340 return QSqlQueryModel::headerData(section, orientation, role);
executed: return QSqlQueryModel::headerData(section, orientation, role);
Execution Count:4
4
341} -
342bool QSqlTableModel::isDirty() const -
343{ -
344 const QSqlTableModelPrivate * const d = d_func(); -
345 QSqlTableModelPrivate::CacheMap::ConstIterator i = d->cache.constBegin(); -
346 const QSqlTableModelPrivate::CacheMap::ConstIterator e = d->cache.constEnd(); -
347 for (; i != e; i++)
evaluated: i != e
TRUEFALSE
yes
Evaluation Count:74
yes
Evaluation Count:144
74-144
348 if (!i.value().submitted())
evaluated: !i.value().submitted()
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:38
36-38
349 return true;
executed: return true;
Execution Count:36
36
350 return false;
executed: return false;
Execution Count:144
144
351} -
352bool QSqlTableModel::isDirty(const QModelIndex &index) const -
353{ -
354 const QSqlTableModelPrivate * const d = d_func(); -
355 if (!index.isValid())
partially evaluated: !index.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:79
0-79
356 return false;
never executed: return false;
0
357 -
358 const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row()); -
359 if (row.submitted())
evaluated: row.submitted()
TRUEFALSE
yes
Evaluation Count:57
yes
Evaluation Count:22
22-57
360 return false;
executed: return false;
Execution Count:57
57
361 -
362 return row.op() == QSqlTableModelPrivate::Insert 22
363 || row.op() == QSqlTableModelPrivate::Delete 22
364 || (row.op() == QSqlTableModelPrivate::Update 22
365 && row.rec().isGenerated(index.column()));
executed: return row.op() == QSqlTableModelPrivate::Insert || row.op() == QSqlTableModelPrivate::Delete || (row.op() == QSqlTableModelPrivate::Update && row.rec().isGenerated(index.column()));
Execution Count:22
22
366} -
367bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, int role) -
368{ -
369 QSqlTableModelPrivate * const d = d_func(); -
370 if (d->busyInsertingRows)
partially evaluated: d->busyInsertingRows
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:270
0-270
371 return false;
never executed: return false;
0
372 -
373 if (role != Qt::EditRole)
evaluated: role != Qt::EditRole
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:268
2-268
374 return QSqlQueryModel::setData(index, value, role);
executed: return QSqlQueryModel::setData(index, value, role);
Execution Count:2
2
375 -
376 if (!index.isValid() || index.column() >= d->rec.count() || index.row() >= rowCount())
evaluated: !index.isValid()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:265
partially evaluated: index.column() >= d->rec.count()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:265
partially evaluated: index.row() >= rowCount()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:265
0-265
377 return false;
executed: return false;
Execution Count:3
3
378 -
379 if (!(flags(index) & Qt::ItemIsEditable))
evaluated: !(flags(index) & Qt::ItemIsEditable)
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:262
3-262
380 return false;
executed: return false;
Execution Count:3
3
381 -
382 const QVariant oldValue = QSqlTableModel::data(index, role); -
383 if (value == oldValue
evaluated: value == oldValue
TRUEFALSE
yes
Evaluation Count:33
yes
Evaluation Count:229
33-229
384 && value.isNull() == oldValue.isNull()
evaluated: value.isNull() == oldValue.isNull()
TRUEFALSE
yes
Evaluation Count:30
yes
Evaluation Count:3
3-30
385 && d->cache.value(index.row()).op() != QSqlTableModelPrivate::Insert)
evaluated: d->cache.value(index.row()).op() != QSqlTableModelPrivate::Insert
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:7
7-23
386 return true;
executed: return true;
Execution Count:23
23
387 -
388 QSqlTableModelPrivate::ModifiedRow &row = d->cache[index.row()]; -
389 -
390 if (row.op() == QSqlTableModelPrivate::None)
evaluated: row.op() == QSqlTableModelPrivate::None
TRUEFALSE
yes
Evaluation Count:47
yes
Evaluation Count:192
47-192
391 row = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, 47
392 QSqlQueryModel::record(index.row()));
executed: row = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, QSqlQueryModel::record(index.row()));
Execution Count:47
47
393 -
394 row.setValue(index.column(), value); -
395 dataChanged(index, index); -
396 -
397 if (d->strategy == OnFieldChange && row.op() != QSqlTableModelPrivate::Insert)
evaluated: d->strategy == OnFieldChange
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:224
evaluated: row.op() != QSqlTableModelPrivate::Insert
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:7
7-224
398 return submit();
executed: return submit();
Execution Count:8
8
399 -
400 return true;
executed: return true;
Execution Count:231
231
401} -
402void QSqlTableModel::setQuery(const QSqlQuery &query) -
403{ -
404 QSqlQueryModel::setQuery(query); -
405}
executed: }
Execution Count:315
315
406bool QSqlTableModel::updateRowInTable(int row, const QSqlRecord &values) -
407{ -
408 QSqlTableModelPrivate * const d = d_func(); -
409 QSqlRecord rec(values); -
410 beforeUpdate(row, rec); -
411 -
412 const QSqlRecord whereValues = d->primaryValues(row); -
413 const bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); -
414 const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::UpdateStatement, d->tableName, -
415 rec, prepStatement); -
416 const QString where = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, d->tableName, -
417 whereValues, prepStatement); -
418 -
419 if (stmt.isEmpty() || where.isEmpty() || row < 0 || row >= rowCount()) {
partially evaluated: stmt.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49
partially evaluated: where.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49
partially evaluated: row < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49
partially evaluated: row >= rowCount()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49
0-49
420 d->error = QSqlError(QLatin1String("No Fields to update"), QString(), -
421 QSqlError::StatementError); -
422 return false;
never executed: return false;
0
423 } -
424 -
425 return d->exec(Sql::concat(stmt, where), prepStatement, rec, whereValues);
executed: return d->exec(Sql::concat(stmt, where), prepStatement, rec, whereValues);
Execution Count:49
49
426} -
427bool QSqlTableModel::insertRowIntoTable(const QSqlRecord &values) -
428{ -
429 QSqlTableModelPrivate * const d = d_func(); -
430 QSqlRecord rec = values; -
431 beforeInsert(rec); -
432 -
433 const bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); -
434 const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::InsertStatement, d->tableName, -
435 rec, prepStatement); -
436 -
437 if (stmt.isEmpty()) {
evaluated: stmt.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:52
1-52
438 d->error = QSqlError(QLatin1String("No Fields to update"), QString(), -
439 QSqlError::StatementError); -
440 return false;
executed: return false;
Execution Count:1
1
441 } -
442 -
443 return d->exec(stmt, prepStatement, rec, QSqlRecord() );
executed: return d->exec(stmt, prepStatement, rec, QSqlRecord() );
Execution Count:52
52
444} -
445bool QSqlTableModel::deleteRowFromTable(int row) -
446{ -
447 QSqlTableModelPrivate * const d = d_func(); -
448 beforeDelete(row); -
449 -
450 const QSqlRecord whereValues = d->primaryValues(row); -
451 const bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); -
452 const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::DeleteStatement, -
453 d->tableName, -
454 QSqlRecord(), -
455 prepStatement); -
456 const QString where = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, -
457 d->tableName, -
458 whereValues, -
459 prepStatement); -
460 -
461 if (stmt.isEmpty() || where.isEmpty()) {
partially evaluated: stmt.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:22
partially evaluated: where.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:22
0-22
462 d->error = QSqlError(QLatin1String("Unable to delete row"), QString(), -
463 QSqlError::StatementError); -
464 return false;
never executed: return false;
0
465 } -
466 -
467 return d->exec(Sql::concat(stmt, where), prepStatement, QSqlRecord() , whereValues);
executed: return d->exec(Sql::concat(stmt, where), prepStatement, QSqlRecord() , whereValues);
Execution Count:22
22
468} -
469bool QSqlTableModel::submitAll() -
470{ -
471 QSqlTableModelPrivate * const d = d_func(); -
472 -
473 bool success = true; -
474 -
475 for (QForeachContainer<__typeof__(d->cache.keys())> _container_(d->cache.keys()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (int row = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
476 -
477 QSqlTableModelPrivate::CacheMap::iterator it = d->cache.find(row); -
478 if (it == d->cache.end())
partially evaluated: it == d->cache.end()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:160
0-160
479 continue;
never executed: continue;
0
480 -
481 QSqlTableModelPrivate::ModifiedRow &mrow = it.value(); -
482 if (mrow.submitted())
evaluated: mrow.submitted()
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:124
36-124
483 continue;
executed: continue;
Execution Count:36
36
484 -
485 switch (mrow.op()) { -
486 case QSqlTableModelPrivate::Insert: -
487 success = insertRowIntoTable(mrow.rec()); -
488 break;
executed: break;
Execution Count:53
53
489 case QSqlTableModelPrivate::Update: -
490 success = updateRowInTable(row, mrow.rec()); -
491 break;
executed: break;
Execution Count:49
49
492 case QSqlTableModelPrivate::Delete: -
493 success = deleteRowFromTable(row); -
494 break;
executed: break;
Execution Count:22
22
495 case QSqlTableModelPrivate::None: -
496 qt_noop(); -
497 break;
never executed: break;
0
498 } -
499 -
500 if (success) {
evaluated: success
TRUEFALSE
yes
Evaluation Count:117
yes
Evaluation Count:7
7-117
501 if (d->strategy != OnManualSubmit && mrow.op() == QSqlTableModelPrivate::Insert) {
evaluated: d->strategy != OnManualSubmit
TRUEFALSE
yes
Evaluation Count:60
yes
Evaluation Count:57
evaluated: mrow.op() == QSqlTableModelPrivate::Insert
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:37
23-60
502 int c = mrow.rec().indexOf(d->autoColumn); -
503 if (c != -1 && !mrow.rec().isGenerated(c))
evaluated: c != -1
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:17
partially evaluated: !mrow.rec().isGenerated(c)
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-17
504 mrow.setValue(c, d->editQuery.lastInsertId());
executed: mrow.setValue(c, d->editQuery.lastInsertId());
Execution Count:6
6
505 }
executed: }
Execution Count:23
23
506 mrow.setSubmitted(); -
507 if (d->strategy != OnManualSubmit)
evaluated: d->strategy != OnManualSubmit
TRUEFALSE
yes
Evaluation Count:60
yes
Evaluation Count:57
57-60
508 success = selectRow(row);
executed: success = selectRow(row);
Execution Count:60
60
509 }
executed: }
Execution Count:117
117
510 -
511 if (!success)
evaluated: !success
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:117
7-117
512 break;
executed: break;
Execution Count:7
7
513 }
executed: }
Execution Count:117
117
514 -
515 if (success) {
evaluated: success
TRUEFALSE
yes
Evaluation Count:118
yes
Evaluation Count:7
7-118
516 if (d->strategy == OnManualSubmit)
evaluated: d->strategy == OnManualSubmit
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:82
36-82
517 success = select();
executed: success = select();
Execution Count:36
36
518 }
executed: }
Execution Count:118
118
519 -
520 return success;
executed: return success;
Execution Count:125
125
521} -
522bool QSqlTableModel::submit() -
523{ -
524 QSqlTableModelPrivate * const d = d_func(); -
525 if (d->strategy == OnRowChange || d->strategy == OnFieldChange)
evaluated: d->strategy == OnRowChange
TRUEFALSE
yes
Evaluation Count:32
yes
Evaluation Count:25
evaluated: d->strategy == OnFieldChange
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:1
1-32
526 return submitAll();
executed: return submitAll();
Execution Count:56
56
527 return true;
executed: return true;
Execution Count:1
1
528} -
529void QSqlTableModel::revert() -
530{ -
531 QSqlTableModelPrivate * const d = d_func(); -
532 if (d->strategy == OnRowChange || d->strategy == OnFieldChange)
evaluated: d->strategy == OnRowChange
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:9
evaluated: d->strategy == OnFieldChange
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:5
4-9
533 revertAll();
executed: revertAll();
Execution Count:8
8
534}
executed: }
Execution Count:13
13
535void QSqlTableModel::setEditStrategy(EditStrategy strategy) -
536{ -
537 QSqlTableModelPrivate * const d = d_func(); -
538 revertAll(); -
539 d->strategy = strategy; -
540}
executed: }
Execution Count:108
108
541 -
542 -
543 -
544 -
545 -
546 -
547QSqlTableModel::EditStrategy QSqlTableModel::editStrategy() const -
548{ -
549 const QSqlTableModelPrivate * const d = d_func(); -
550 return d->strategy;
executed: return d->strategy;
Execution Count:13
13
551} -
552 -
553 -
554 -
555 -
556 -
557 -
558void QSqlTableModel::revertAll() -
559{ -
560 QSqlTableModelPrivate * const d = d_func(); -
561 -
562 const QList<int> rows(d->cache.keys()); -
563 for (int i = rows.size() - 1; i >= 0; --i)
evaluated: i >= 0
TRUEFALSE
yes
Evaluation Count:35
yes
Evaluation Count:134
35-134
564 revertRow(rows.value(i));
executed: revertRow(rows.value(i));
Execution Count:35
35
565}
executed: }
Execution Count:134
134
566 -
567 -
568 -
569 -
570 -
571 -
572void QSqlTableModel::revertRow(int row) -
573{ -
574 if (row < 0)
partially evaluated: row < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:52
0-52
575 return;
never executed: return;
0
576 -
577 QSqlTableModelPrivate * const d = d_func(); -
578 d->revertCachedRow(row); -
579}
executed: }
Execution Count:52
52
580 -
581 -
582 -
583 -
584 -
585 -
586 -
587QSqlIndex QSqlTableModel::primaryKey() const -
588{ -
589 const QSqlTableModelPrivate * const d = d_func(); -
590 return d->primaryIndex;
executed: return d->primaryIndex;
Execution Count:1
1
591} -
592void QSqlTableModel::setPrimaryKey(const QSqlIndex &key) -
593{ -
594 QSqlTableModelPrivate * const d = d_func(); -
595 d->primaryIndex = key; -
596}
never executed: }
0
597 -
598 -
599 -
600 -
601QSqlDatabase QSqlTableModel::database() const -
602{ -
603 const QSqlTableModelPrivate * const d = d_func(); -
604 return d->db;
executed: return d->db;
Execution Count:447
447
605} -
606void QSqlTableModel::sort(int column, Qt::SortOrder order) -
607{ -
608 setSort(column, order); -
609 select(); -
610}
executed: }
Execution Count:12
12
611void QSqlTableModel::setSort(int column, Qt::SortOrder order) -
612{ -
613 QSqlTableModelPrivate * const d = d_func(); -
614 d->sortColumn = column; -
615 d->sortOrder = order; -
616}
executed: }
Execution Count:72
72
617 -
618 -
619 -
620 -
621 -
622 -
623 -
624QString QSqlTableModel::orderByClause() const -
625{ -
626 const QSqlTableModelPrivate * const d = d_func(); -
627 QSqlField f = d->rec.field(d->sortColumn); -
628 if (!f.isValid())
evaluated: !f.isValid()
TRUEFALSE
yes
Evaluation Count:235
yes
Evaluation Count:138
138-235
629 return QString();
executed: return QString();
Execution Count:235
235
630 -
631 -
632 -
633 QString field = d->db.driver()->escapeIdentifier(f.name(), QSqlDriver::FieldName); -
634 field.prepend(QLatin1Char('.')).prepend(d->tableName); -
635 field = d->sortOrder == Qt::AscendingOrder ? Sql::asc(field) : Sql::desc(field);
evaluated: d->sortOrder == Qt::AscendingOrder
TRUEFALSE
yes
Evaluation Count:133
yes
Evaluation Count:5
5-133
636 return Sql::orderBy(field);
executed: return Sql::orderBy(field);
Execution Count:138
138
637} -
638 -
639 -
640 -
641 -
642 -
643int QSqlTableModel::fieldIndex(const QString &fieldName) const -
644{ -
645 const QSqlTableModelPrivate * const d = d_func(); -
646 return d->rec.indexOf(fieldName);
never executed: return d->rec.indexOf(fieldName);
0
647} -
648QString QSqlTableModel::selectStatement() const -
649{ -
650 const QSqlTableModelPrivate * const d = d_func(); -
651 if (d->tableName.isEmpty()) {
partially evaluated: d->tableName.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:294
0-294
652 d->error = QSqlError(QLatin1String("No table name given"), QString(), -
653 QSqlError::StatementError); -
654 return QString();
never executed: return QString();
0
655 } -
656 if (d->rec.isEmpty()) {
evaluated: d->rec.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:293
1-293
657 d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), -
658 QSqlError::StatementError); -
659 return QString();
executed: return QString();
Execution Count:1
1
660 } -
661 -
662 const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::SelectStatement, -
663 d->tableName, -
664 d->rec, -
665 false); -
666 if (stmt.isEmpty()) {
partially evaluated: stmt.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:293
0-293
667 d->error = QSqlError(QLatin1String("Unable to select fields from table ") + d->tableName, -
668 QString(), QSqlError::StatementError); -
669 return stmt;
never executed: return stmt;
0
670 } -
671 return Sql::concat(Sql::concat(stmt, Sql::where(d->filter)), orderByClause());
executed: return Sql::concat(Sql::concat(stmt, Sql::where(d->filter)), orderByClause());
Execution Count:293
293
672} -
673bool QSqlTableModel::removeColumns(int column, int count, const QModelIndex &parent) -
674{ -
675 QSqlTableModelPrivate * const d = d_func(); -
676 if (parent.isValid() || column < 0 || column + count > d->rec.count())
partially evaluated: parent.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
partially evaluated: column < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
partially evaluated: column + count > d->rec.count()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
677 return false;
never executed: return false;
0
678 for (int i = 0; i < count; ++i)
evaluated: i < count
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:5
5-7
679 d->rec.remove(column);
executed: d->rec.remove(column);
Execution Count:7
7
680 if (d->query.isActive())
partially evaluated: d->query.isActive()
TRUEFALSE
yes
Evaluation Count:5
no
Evaluation Count:0
0-5
681 return select();
executed: return select();
Execution Count:5
5
682 return true;
never executed: return true;
0
683} -
684bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent) -
685{ -
686 QSqlTableModelPrivate * const d = d_func(); -
687 if (parent.isValid() || row < 0 || count <= 0)
evaluated: parent.isValid()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:41
evaluated: row < 0
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:37
evaluated: count <= 0
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:35
2-41
688 return false;
executed: return false;
Execution Count:8
8
689 else if (row + count > rowCount())
evaluated: row + count > rowCount()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:33
2-33
690 return false;
executed: return false;
Execution Count:2
2
691 else if (!count)
partially evaluated: !count
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:33
0-33
692 return true;
never executed: return true;
0
693 -
694 if (d->strategy != OnManualSubmit)
evaluated: d->strategy != OnManualSubmit
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:16
16-17
695 if (count > 1 || (d->cache.value(row).submitted() && isDirty()))
evaluated: count > 1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:16
evaluated: d->cache.value(row).submitted()
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:2
evaluated: isDirty()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:11
1-16
696 return false;
executed: return false;
Execution Count:4
4
697 -
698 -
699 -
700 for (int idx = row + count - 1; idx >= row; --idx) {
evaluated: idx >= row
TRUEFALSE
yes
Evaluation Count:37
yes
Evaluation Count:29
29-37
701 QSqlTableModelPrivate::ModifiedRow& mrow = d->cache[idx]; -
702 if (mrow.op() == QSqlTableModelPrivate::Insert) {
evaluated: mrow.op() == QSqlTableModelPrivate::Insert
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:24
13-24
703 revertRow(idx); -
704 } else {
executed: }
Execution Count:13
13
705 if (mrow.op() == QSqlTableModelPrivate::None)
evaluated: mrow.op() == QSqlTableModelPrivate::None
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:2
2-22
706 mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete, 22
707 QSqlQueryModel::record(idx));
executed: mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete, QSqlQueryModel::record(idx));
Execution Count:22
22
708 else -
709 mrow.setOp(QSqlTableModelPrivate::Delete);
executed: mrow.setOp(QSqlTableModelPrivate::Delete);
Execution Count:2
2
710 if (d->strategy == OnManualSubmit)
evaluated: d->strategy == OnManualSubmit
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:11
11-13
711 headerDataChanged(Qt::Vertical, idx, idx);
executed: headerDataChanged(Qt::Vertical, idx, idx);
Execution Count:13
13
712 }
executed: }
Execution Count:24
24
713 } -
714 -
715 if (d->strategy != OnManualSubmit)
evaluated: d->strategy != OnManualSubmit
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:16
13-16
716 return submit();
executed: return submit();
Execution Count:13
13
717 -
718 return true;
executed: return true;
Execution Count:16
16
719} -
720bool QSqlTableModel::insertRows(int row, int count, const QModelIndex &parent) -
721{ -
722 QSqlTableModelPrivate * const d = d_func(); -
723 if (row < 0 || count <= 0 || row > rowCount() || parent.isValid())
partially evaluated: row < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:76
partially evaluated: count <= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:76
partially evaluated: row > rowCount()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:76
partially evaluated: parent.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:76
0-76
724 return false;
never executed: return false;
0
725 -
726 if (d->strategy != OnManualSubmit)
evaluated: d->strategy != OnManualSubmit
TRUEFALSE
yes
Evaluation Count:34
yes
Evaluation Count:42
34-42
727 if (count != 1 || isDirty())
partially evaluated: count != 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:34
evaluated: isDirty()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:31
0-34
728 return false;
executed: return false;
Execution Count:3
3
729 -
730 d->busyInsertingRows = true; -
731 beginInsertRows(parent, row, row + count - 1); -
732 -
733 if (d->strategy != OnManualSubmit)
evaluated: d->strategy != OnManualSubmit
TRUEFALSE
yes
Evaluation Count:31
yes
Evaluation Count:42
31-42
734 d->cache.empty();
executed: d->cache.empty();
Execution Count:31
31
735 -
736 if (!d->cache.isEmpty()) {
evaluated: !d->cache.isEmpty()
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:49
24-49
737 QMap<int, QSqlTableModelPrivate::ModifiedRow>::Iterator it = d->cache.end(); -
738 while (it != d->cache.begin() && (--it).key() >= row) {
evaluated: it != d->cache.begin()
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:7
evaluated: (--it).key() >= row
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:17
7-28
739 int oldKey = it.key(); -
740 const QSqlTableModelPrivate::ModifiedRow oldValue = it.value(); -
741 d->cache.erase(it); -
742 it = d->cache.insert(oldKey + count, oldValue); -
743 }
executed: }
Execution Count:11
11
744 }
executed: }
Execution Count:24
24
745 -
746 for (int i = 0; i < count; ++i) {
evaluated: i < count
TRUEFALSE
yes
Evaluation Count:91
yes
Evaluation Count:73
73-91
747 d->cache[row + i] = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Insert, -
748 d->rec); -
749 primeInsert(row + i, d->cache[row + i].recRef()); -
750 }
executed: }
Execution Count:91
91
751 -
752 endInsertRows(); -
753 d->busyInsertingRows = false; -
754 return true;
executed: return true;
Execution Count:73
73
755} -
756bool QSqlTableModel::insertRecord(int row, const QSqlRecord &record) -
757{ -
758 if (row < 0)
evaluated: row < 0
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:22
7-22
759 row = rowCount();
executed: row = rowCount();
Execution Count:7
7
760 if (!insertRow(row, QModelIndex()))
partially evaluated: !insertRow(row, QModelIndex())
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:29
0-29
761 return false;
never executed: return false;
0
762 if (!setRecord(row, record)) {
partially evaluated: !setRecord(row, record)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:29
0-29
763 revertRow(row); -
764 return false;
never executed: return false;
0
765 } -
766 return true;
executed: return true;
Execution Count:29
29
767} -
768 -
769 -
770 -
771int QSqlTableModel::rowCount(const QModelIndex &parent) const -
772{ -
773 const QSqlTableModelPrivate * const d = d_func(); -
774 -
775 if (parent.isValid())
evaluated: parent.isValid()
TRUEFALSE
yes
Evaluation Count:1028
yes
Evaluation Count:10705
1028-10705
776 return 0;
executed: return 0;
Execution Count:1028
1028
777 -
778 return QSqlQueryModel::rowCount() + d->insertCount();
executed: return QSqlQueryModel::rowCount() + d->insertCount();
Execution Count:10705
10705
779} -
780QModelIndex QSqlTableModel::indexInQuery(const QModelIndex &item) const -
781{ -
782 const QSqlTableModelPrivate * const d = d_func(); -
783 if (d->cache.value(item.row()).insert())
partially evaluated: d->cache.value(item.row()).insert()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2177
0-2177
784 return QModelIndex();
never executed: return QModelIndex();
0
785 -
786 const int rowOffset = d->insertCount(item.row()); -
787 return QSqlQueryModel::indexInQuery(createIndex(item.row() - rowOffset, item.column(), item.internalPointer()));
executed: return QSqlQueryModel::indexInQuery(createIndex(item.row() - rowOffset, item.column(), item.internalPointer()));
Execution Count:2177
2177
788} -
789 -
790 -
791 -
792 -
793 -
794 -
795QString QSqlTableModel::filter() const -
796{ -
797 const QSqlTableModelPrivate * const d = d_func(); -
798 return d->filter;
executed: return d->filter;
Execution Count:86
86
799} -
800void QSqlTableModel::setFilter(const QString &filter) -
801{ -
802 QSqlTableModelPrivate * const d = d_func(); -
803 d->filter = filter; -
804 if (d->query.isActive())
evaluated: d->query.isActive()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:4
3-4
805 select();
executed: select();
Execution Count:3
3
806}
executed: }
Execution Count:7
7
807 -
808 -
809 -
810void QSqlTableModel::clear() -
811{ -
812 QSqlTableModelPrivate * const d = d_func(); -
813 d->clear(); -
814 QSqlQueryModel::clear(); -
815}
executed: }
Execution Count:190
190
816 -
817 -
818 -
819Qt::ItemFlags QSqlTableModel::flags(const QModelIndex &index) const -
820{ -
821 const QSqlTableModelPrivate * const d = d_func(); -
822 if (index.internalPointer() || index.column() < 0 || index.column() >= d->rec.count()
partially evaluated: index.internalPointer()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:267
evaluated: index.column() < 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:266
partially evaluated: index.column() >= d->rec.count()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:266
0-267
823 || index.row() < 0)
partially evaluated: index.row() < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:266
0-266
824 return 0;
executed: return 0;
Execution Count:1
1
825 -
826 bool editable = true; -
827 -
828 if (d->rec.field(index.column()).isReadOnly()) {
partially evaluated: d->rec.field(index.column()).isReadOnly()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:266
0-266
829 editable = false; -
830 }
never executed: }
0
831 else { -
832 const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(index.row()); -
833 if (mrow.op() == QSqlTableModelPrivate::Delete) {
partially evaluated: mrow.op() == QSqlTableModelPrivate::Delete
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:266
0-266
834 editable = false; -
835 }
never executed: }
0
836 else if (d->strategy == OnFieldChange) {
evaluated: d->strategy == OnFieldChange
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:249
17-249
837 if (mrow.op() != QSqlTableModelPrivate::Insert)
evaluated: mrow.op() != QSqlTableModelPrivate::Insert
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:7
7-10
838 if (!isDirty(index) && isDirty())
partially evaluated: !isDirty(index)
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
evaluated: isDirty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:9
0-10
839 editable = false;
executed: editable = false;
Execution Count:1
1
840 }
executed: }
Execution Count:17
17
841 else if (d->strategy == OnRowChange) {
evaluated: d->strategy == OnRowChange
TRUEFALSE
yes
Evaluation Count:48
yes
Evaluation Count:201
48-201
842 if (mrow.submitted() && isDirty())
evaluated: mrow.submitted()
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:19
evaluated: isDirty()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:26
3-29
843 editable = false;
executed: editable = false;
Execution Count:3
3
844 }
executed: }
Execution Count:48
48
845 } -
846 -
847 if (!editable)
evaluated: !editable
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:262
4-262
848 return QSqlQueryModel::flags(index);
executed: return QSqlQueryModel::flags(index);
Execution Count:4
4
849 else -
850 return QSqlQueryModel::flags(index) | Qt::ItemIsEditable;
executed: return QSqlQueryModel::flags(index) | Qt::ItemIsEditable;
Execution Count:262
262
851} -
852 -
853QSqlRecord QSqlTableModel::record() const -
854{ -
855 return QSqlQueryModel::record();
executed: return QSqlQueryModel::record();
Execution Count:13
13
856} -
857QSqlRecord QSqlTableModel::record(int row) const -
858{ -
859 const QSqlTableModelPrivate * const d = d_func(); -
860 -
861 -
862 QSqlRecord rec = QSqlQueryModel::record(row); -
863 -
864 -
865 const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(row); -
866 if (mrow.op() != QSqlTableModelPrivate::None) {
evaluated: mrow.op() != QSqlTableModelPrivate::None
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:160
5-160
867 const QSqlRecord crec = mrow.rec(); -
868 for (int i = 0, cnt = rec.count(); i < cnt; ++i)
evaluated: i < cnt
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:5
5-15
869 rec.setGenerated(i, crec.isGenerated(i));
executed: rec.setGenerated(i, crec.isGenerated(i));
Execution Count:15
15
870 }
executed: }
Execution Count:5
5
871 -
872 return rec;
executed: return rec;
Execution Count:165
165
873} -
874bool QSqlTableModel::setRecord(int row, const QSqlRecord &values) -
875{ -
876 QSqlTableModelPrivate * const d = d_func(); -
877 qt_noop(); -
878 if (d->busyInsertingRows)
partially evaluated: d->busyInsertingRows
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:50
0-50
879 return false;
never executed: return false;
0
880 -
881 if (row >= rowCount())
partially evaluated: row >= rowCount()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:50
0-50
882 return false;
never executed: return false;
0
883 -
884 if (d->cache.value(row).op() == QSqlTableModelPrivate::Delete)
partially evaluated: d->cache.value(row).op() == QSqlTableModelPrivate::Delete
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:50
0-50
885 return false;
never executed: return false;
0
886 -
887 if (d->strategy != OnManualSubmit && d->cache.value(row).submitted() && isDirty())
evaluated: d->strategy != OnManualSubmit
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:26
evaluated: d->cache.value(row).submitted()
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:14
evaluated: isDirty()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:7
3-26
888 return false;
executed: return false;
Execution Count:3
3
889 -
890 -
891 typedef QMap<int, int> Map; -
892 Map map; -
893 for (int i = 0; i < values.count(); ++i) {
evaluated: i < values.count()
TRUEFALSE
yes
Evaluation Count:132
yes
Evaluation Count:47
47-132
894 int idx = d->nameToIndex(values.fieldName(i)); -
895 if (idx == -1)
partially evaluated: idx == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:132
0-132
896 return false;
never executed: return false;
0
897 map[i] = idx; -
898 }
executed: }
Execution Count:132
132
899 -
900 QSqlTableModelPrivate::ModifiedRow &mrow = d->cache[row]; -
901 if (mrow.op() == QSqlTableModelPrivate::None)
evaluated: mrow.op() == QSqlTableModelPrivate::None
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:34
13-34
902 mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, 13
903 QSqlQueryModel::record(row));
executed: mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, QSqlQueryModel::record(row));
Execution Count:13
13
904 -
905 Map::const_iterator i = map.constBegin(); -
906 const Map::const_iterator e = map.constEnd(); -
907 for ( ; i != e; ++i) {
evaluated: i != e
TRUEFALSE
yes
Evaluation Count:132
yes
Evaluation Count:47
47-132
908 -
909 EditStrategy strategy = d->strategy; -
910 d->strategy = OnManualSubmit; -
911 QModelIndex cIndex = createIndex(row, i.value()); -
912 setData(cIndex, values.value(i.key())); -
913 d->strategy = strategy; -
914 -
915 if (!values.isGenerated(i.key()))
evaluated: !values.isGenerated(i.key())
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:129
3-129
916 mrow.recRef().setGenerated(i.value(), false);
executed: mrow.recRef().setGenerated(i.value(), false);
Execution Count:3
3
917 }
executed: }
Execution Count:132
132
918 -
919 if (d->strategy != OnManualSubmit)
evaluated: d->strategy != OnManualSubmit
TRUEFALSE
yes
Evaluation Count:21
yes
Evaluation Count:26
21-26
920 return submit();
executed: return submit();
Execution Count:21
21
921 -
922 return true;
executed: return true;
Execution Count:26
26
923} -
924 -
925 -
926 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial