Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | class QSqlRelationalTableModelSql: public QSqlTableModelSql | - |
8 | { | - |
9 | public: | - |
10 | inline const static QString relTablePrefix(int i) { return QString::number(i).prepend(QLatin1String("relTblAl_")); } executed: return QString::number(i).prepend(QLatin1String("relTblAl_")); Execution Count:107 | 107 |
11 | }; | - |
12 | | - |
13 | typedef QSqlRelationalTableModelSql Sql; | - |
14 | class QRelatedTableModel; | - |
15 | | - |
16 | struct QRelation | - |
17 | { | - |
18 | public: | - |
19 | QRelation(): model(0), m_parent(0), m_dictInitialized(false) {} executed: } Execution Count:266 | 266 |
20 | void init(QSqlRelationalTableModel *parent, const QSqlRelation &relation); | - |
21 | | - |
22 | void populateModel(); | - |
23 | | - |
24 | bool isDictionaryInitialized(); | - |
25 | void populateDictionary(); | - |
26 | void clearDictionary(); | - |
27 | | - |
28 | void clear(); | - |
29 | bool isValid(); | - |
30 | | - |
31 | QSqlRelation rel; | - |
32 | QRelatedTableModel *model; | - |
33 | QHash<QString, QVariant> dictionary; | - |
34 | | - |
35 | private: | - |
36 | QSqlRelationalTableModel *m_parent; | - |
37 | bool m_dictInitialized; | - |
38 | }; | - |
39 | | - |
40 | class QRelatedTableModel : public QSqlTableModel | - |
41 | { | - |
42 | public: | - |
43 | QRelatedTableModel(QRelation *rel, QObject *parent = 0, QSqlDatabase db = QSqlDatabase()); | - |
44 | bool select(); | - |
45 | private: | - |
46 | bool firstSelect; | - |
47 | QRelation *relation; | - |
48 | }; | - |
49 | | - |
50 | | - |
51 | | - |
52 | | - |
53 | | - |
54 | void QRelation::init(QSqlRelationalTableModel *parent, const QSqlRelation &relation) | - |
55 | { | - |
56 | qt_noop(); | - |
57 | m_parent = parent; | - |
58 | rel = relation; | - |
59 | } executed: } Execution Count:44 | 44 |
60 | | - |
61 | void QRelation::populateModel() | - |
62 | { | - |
63 | if (!isValid()) partially evaluated: !isValid() no Evaluation Count:0 | yes Evaluation Count:40 |
| 0-40 |
64 | return; | 0 |
65 | qt_noop(); | - |
66 | | - |
67 | if (!model) { partially evaluated: !model yes Evaluation Count:40 | no Evaluation Count:0 |
| 0-40 |
68 | model = new QRelatedTableModel(this, m_parent, m_parent->database()); | - |
69 | model->setTable(rel.tableName()); | - |
70 | model->select(); | - |
71 | } executed: } Execution Count:40 | 40 |
72 | } executed: } Execution Count:40 | 40 |
73 | | - |
74 | bool QRelation::isDictionaryInitialized() | - |
75 | { | - |
76 | return m_dictInitialized; executed: return m_dictInitialized; Execution Count:191 | 191 |
77 | } | - |
78 | | - |
79 | void QRelation::populateDictionary() | - |
80 | { | - |
81 | if (!isValid()) partially evaluated: !isValid() no Evaluation Count:0 | yes Evaluation Count:66 |
| 0-66 |
82 | return; | 0 |
83 | | - |
84 | if (model == __null) evaluated: model == __null yes Evaluation Count:37 | yes Evaluation Count:29 |
| 29-37 |
85 | populateModel(); executed: populateModel(); Execution Count:37 | 37 |
86 | | - |
87 | QSqlRecord record; | - |
88 | QString indexColumn; | - |
89 | QString displayColumn; | - |
90 | for (int i=0; i < model->rowCount(); ++i) { evaluated: i < model->rowCount() yes Evaluation Count:136 | yes Evaluation Count:66 |
| 66-136 |
91 | record = model->record(i); | - |
92 | | - |
93 | indexColumn = rel.indexColumn(); | - |
94 | if (m_parent->database().driver()->isIdentifierEscaped(indexColumn, QSqlDriver::FieldName)) evaluated: m_parent->database().driver()->isIdentifierEscaped(indexColumn, QSqlDriver::FieldName) yes Evaluation Count:14 | yes Evaluation Count:122 |
| 14-122 |
95 | indexColumn = m_parent->database().driver()->stripDelimiters(indexColumn, QSqlDriver::FieldName); executed: indexColumn = m_parent->database().driver()->stripDelimiters(indexColumn, QSqlDriver::FieldName); Execution Count:14 | 14 |
96 | | - |
97 | displayColumn = rel.displayColumn(); | - |
98 | if (m_parent->database().driver()->isIdentifierEscaped(displayColumn, QSqlDriver::FieldName)) evaluated: m_parent->database().driver()->isIdentifierEscaped(displayColumn, QSqlDriver::FieldName) yes Evaluation Count:18 | yes Evaluation Count:118 |
| 18-118 |
99 | displayColumn = m_parent->database().driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName); executed: displayColumn = m_parent->database().driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName); Execution Count:18 | 18 |
100 | | - |
101 | dictionary[record.field(indexColumn).value().toString()] = | - |
102 | record.field(displayColumn).value(); | - |
103 | } executed: } Execution Count:136 | 136 |
104 | m_dictInitialized = true; | - |
105 | } executed: } Execution Count:66 | 66 |
106 | | - |
107 | void QRelation::clearDictionary() | - |
108 | { | - |
109 | dictionary.clear(); | - |
110 | m_dictInitialized = false; | - |
111 | } executed: } Execution Count:216 | 216 |
112 | | - |
113 | void QRelation::clear() | - |
114 | { | - |
115 | delete model; | - |
116 | model = 0; | - |
117 | clearDictionary(); | - |
118 | } executed: } Execution Count:4 | 4 |
119 | | - |
120 | bool QRelation::isValid() | - |
121 | { | - |
122 | return (rel.isValid() && m_parent != __null); executed: return (rel.isValid() && m_parent != __null); Execution Count:497 | 497 |
123 | } | - |
124 | | - |
125 | | - |
126 | | - |
127 | QRelatedTableModel::QRelatedTableModel(QRelation *rel, QObject *parent, QSqlDatabase db) : | - |
128 | QSqlTableModel(parent, db), firstSelect(true), relation(rel) | - |
129 | { | - |
130 | } executed: } Execution Count:40 | 40 |
131 | | - |
132 | bool QRelatedTableModel::select() | - |
133 | { | - |
134 | if (firstSelect) { evaluated: firstSelect yes Evaluation Count:40 | yes Evaluation Count:1 |
| 1-40 |
135 | firstSelect = false; | - |
136 | return QSqlTableModel::select(); executed: return QSqlTableModel::select(); Execution Count:40 | 40 |
137 | } | - |
138 | relation->clearDictionary(); | - |
139 | bool res = QSqlTableModel::select(); | - |
140 | if (res) partially evaluated: res yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
141 | relation->populateDictionary(); executed: relation->populateDictionary(); Execution Count:1 | 1 |
142 | return res; executed: return res; Execution Count:1 | 1 |
143 | } | - |
144 | | - |
145 | | - |
146 | class QSqlRelationalTableModelPrivate: public QSqlTableModelPrivate | - |
147 | { | - |
148 | inline QSqlRelationalTableModel* q_func() { return static_cast<QSqlRelationalTableModel *>(q_ptr); } inline const QSqlRelationalTableModel* q_func() const { return static_cast<const QSqlRelationalTableModel *>(q_ptr); } friend class QSqlRelationalTableModel; | - |
149 | public: | - |
150 | QSqlRelationalTableModelPrivate() | - |
151 | : QSqlTableModelPrivate(), | - |
152 | joinMode( QSqlRelationalTableModel::InnerJoin ) | - |
153 | {} executed: } Execution Count:31 | 31 |
154 | QString fullyQualifiedFieldName(const QString &tableName, const QString &fieldName) const; | - |
155 | | - |
156 | int nameToIndex(const QString &name) const; | - |
157 | mutable QVector<QRelation> relations; | - |
158 | QSqlRecord baseRec; | - |
159 | void clearChanges(); | - |
160 | void clearCache(); | - |
161 | void revertCachedRow(int row); | - |
162 | | - |
163 | void translateFieldNames(QSqlRecord &values) const; | - |
164 | QSqlRelationalTableModel::JoinMode joinMode; | - |
165 | }; | - |
166 | | - |
167 | void QSqlRelationalTableModelPrivate::clearChanges() | - |
168 | { | - |
169 | for (int i = 0; i < relations.count(); ++i) { evaluated: i < relations.count() yes Evaluation Count:4 | yes Evaluation Count:32 |
| 4-32 |
170 | QRelation &rel = relations[i]; | - |
171 | rel.clear(); | - |
172 | } executed: } Execution Count:4 | 4 |
173 | } executed: } Execution Count:32 | 32 |
174 | | - |
175 | void QSqlRelationalTableModelPrivate::revertCachedRow(int row) | - |
176 | { | - |
177 | QSqlTableModelPrivate::revertCachedRow(row); | - |
178 | } executed: } Execution Count:19 | 19 |
179 | | - |
180 | int QSqlRelationalTableModelPrivate::nameToIndex(const QString &name) const | - |
181 | { | - |
182 | const QString fieldname = strippedFieldName(name); | - |
183 | int idx = baseRec.indexOf(fieldname); | - |
184 | if (idx == -1) { evaluated: idx == -1 yes Evaluation Count:1 | yes Evaluation Count:16 |
| 1-16 |
185 | | - |
186 | idx = QSqlTableModelPrivate::nameToIndex(name); | - |
187 | } executed: } Execution Count:1 | 1 |
188 | return idx; executed: return idx; Execution Count:17 | 17 |
189 | } | - |
190 | | - |
191 | | - |
192 | | - |
193 | | - |
194 | void QSqlRelationalTableModelPrivate::clearCache() | - |
195 | { | - |
196 | for (int i = 0; i < relations.count(); ++i) evaluated: i < relations.count() yes Evaluation Count:211 | yes Evaluation Count:74 |
| 74-211 |
197 | relations[i].clearDictionary(); executed: relations[i].clearDictionary(); Execution Count:211 | 211 |
198 | | - |
199 | QSqlTableModelPrivate::clearCache(); | - |
200 | } executed: } Execution Count:74 | 74 |
201 | QSqlRelationalTableModel::QSqlRelationalTableModel(QObject *parent, QSqlDatabase db) | - |
202 | : QSqlTableModel(*new QSqlRelationalTableModelPrivate, parent, db) | - |
203 | { | - |
204 | } executed: } Execution Count:31 | 31 |
205 | | - |
206 | | - |
207 | | - |
208 | | - |
209 | QSqlRelationalTableModel::~QSqlRelationalTableModel() | - |
210 | { | - |
211 | } | - |
212 | | - |
213 | | - |
214 | | - |
215 | | - |
216 | QVariant QSqlRelationalTableModel::data(const QModelIndex &index, int role) const | - |
217 | { | - |
218 | const QSqlRelationalTableModelPrivate * const d = d_func(); | - |
219 | | - |
220 | if (role == Qt::DisplayRole && index.column() >= 0 && index.column() < d->relations.count() && evaluated: role == Qt::DisplayRole yes Evaluation Count:248 | yes Evaluation Count:88 |
evaluated: index.column() >= 0 yes Evaluation Count:243 | yes Evaluation Count:5 |
evaluated: index.column() < d->relations.count() yes Evaluation Count:223 | yes Evaluation Count:20 |
| 5-248 |
221 | d->relations.value(index.column()).isValid()) { evaluated: d->relations.value(index.column()).isValid() yes Evaluation Count:147 | yes Evaluation Count:76 |
| 76-147 |
222 | QRelation &relation = d->relations[index.column()]; | - |
223 | if (!relation.isDictionaryInitialized()) evaluated: !relation.isDictionaryInitialized() yes Evaluation Count:54 | yes Evaluation Count:93 |
| 54-93 |
224 | relation.populateDictionary(); executed: relation.populateDictionary(); Execution Count:54 | 54 |
225 | | - |
226 | | - |
227 | | - |
228 | | - |
229 | | - |
230 | if (d->strategy != OnFieldChange) { evaluated: d->strategy != OnFieldChange yes Evaluation Count:146 | yes Evaluation Count:1 |
| 1-146 |
231 | const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row()); | - |
232 | if (row.op() != QSqlTableModelPrivate::None && row.rec().isGenerated(index.column())) { evaluated: row.op() != QSqlTableModelPrivate::None yes Evaluation Count:60 | yes Evaluation Count:86 |
evaluated: row.rec().isGenerated(index.column()) yes Evaluation Count:29 | yes Evaluation Count:31 |
| 29-86 |
233 | if (d->strategy == OnManualSubmit || row.op() != QSqlTableModelPrivate::Delete) { evaluated: d->strategy == OnManualSubmit yes Evaluation Count:16 | yes Evaluation Count:13 |
partially evaluated: row.op() != QSqlTableModelPrivate::Delete yes Evaluation Count:13 | no Evaluation Count:0 |
| 0-16 |
234 | QVariant v = row.rec().value(index.column()); | - |
235 | if (v.isValid()) partially evaluated: v.isValid() yes Evaluation Count:29 | no Evaluation Count:0 |
| 0-29 |
236 | return relation.dictionary[v.toString()]; executed: return relation.dictionary[v.toString()]; Execution Count:29 | 29 |
237 | } | 0 |
238 | } | 0 |
239 | } executed: } Execution Count:117 | 117 |
240 | } executed: } Execution Count:118 | 118 |
241 | return QSqlTableModel::data(index, role); executed: return QSqlTableModel::data(index, role); Execution Count:307 | 307 |
242 | } | - |
243 | bool QSqlRelationalTableModel::setData(const QModelIndex &index, const QVariant &value, | - |
244 | int role) | - |
245 | { | - |
246 | QSqlRelationalTableModelPrivate * const d = d_func(); | - |
247 | if ( role == Qt::EditRole && index.column() > 0 && index.column() < d->relations.count() partially evaluated: role == Qt::EditRole yes Evaluation Count:85 | no Evaluation Count:0 |
evaluated: index.column() > 0 yes Evaluation Count:63 | yes Evaluation Count:22 |
evaluated: index.column() < d->relations.count() yes Evaluation Count:59 | yes Evaluation Count:4 |
| 0-85 |
248 | && d->relations.value(index.column()).isValid()) { evaluated: d->relations.value(index.column()).isValid() yes Evaluation Count:44 | yes Evaluation Count:15 |
| 15-44 |
249 | QRelation &relation = d->relations[index.column()]; | - |
250 | if (!relation.isDictionaryInitialized()) evaluated: !relation.isDictionaryInitialized() yes Evaluation Count:11 | yes Evaluation Count:33 |
| 11-33 |
251 | relation.populateDictionary(); executed: relation.populateDictionary(); Execution Count:11 | 11 |
252 | if (!relation.dictionary.contains(value.toString())) evaluated: !relation.dictionary.contains(value.toString()) yes Evaluation Count:2 | yes Evaluation Count:42 |
| 2-42 |
253 | return false; executed: return false; Execution Count:2 | 2 |
254 | } executed: } Execution Count:42 | 42 |
255 | return QSqlTableModel::setData(index, value, role); executed: return QSqlTableModel::setData(index, value, role); Execution Count:83 | 83 |
256 | } | - |
257 | void QSqlRelationalTableModel::setRelation(int column, const QSqlRelation &relation) | - |
258 | { | - |
259 | QSqlRelationalTableModelPrivate * const d = d_func(); | - |
260 | if (column < 0) partially evaluated: column < 0 no Evaluation Count:0 | yes Evaluation Count:44 |
| 0-44 |
261 | return; | 0 |
262 | if (d->relations.size() <= column) evaluated: d->relations.size() <= column yes Evaluation Count:41 | yes Evaluation Count:3 |
| 3-41 |
263 | d->relations.resize(column + 1); executed: d->relations.resize(column + 1); Execution Count:41 | 41 |
264 | d->relations[column].init(this, relation); | - |
265 | } executed: } Execution Count:44 | 44 |
266 | | - |
267 | | - |
268 | | - |
269 | | - |
270 | | - |
271 | | - |
272 | | - |
273 | QSqlRelation QSqlRelationalTableModel::relation(int column) const | - |
274 | { | - |
275 | const QSqlRelationalTableModelPrivate * const d = d_func(); | - |
276 | return d->relations.value(column).rel; never executed: return d->relations.value(column).rel; | 0 |
277 | } | - |
278 | | - |
279 | QString QSqlRelationalTableModelPrivate::fullyQualifiedFieldName(const QString &tableName, | - |
280 | const QString &fieldName) const | - |
281 | { | - |
282 | QString ret; | - |
283 | ret.reserve(tableName.size() + fieldName.size() + 1); | - |
284 | ret.append(tableName).append(QLatin1Char('.')).append(fieldName); | - |
285 | | - |
286 | return ret; executed: return ret; Execution Count:512 | 512 |
287 | } | - |
288 | | - |
289 | | - |
290 | | - |
291 | | - |
292 | QString QSqlRelationalTableModel::selectStatement() const | - |
293 | { | - |
294 | const QSqlRelationalTableModelPrivate * const d = d_func(); | - |
295 | | - |
296 | if (tableName().isEmpty()) partially evaluated: tableName().isEmpty() no Evaluation Count:0 | yes Evaluation Count:89 |
| 0-89 |
297 | return QString(); never executed: return QString(); | 0 |
298 | if (d->relations.isEmpty()) evaluated: d->relations.isEmpty() yes Evaluation Count:5 | yes Evaluation Count:84 |
| 5-84 |
299 | return QSqlTableModel::selectStatement(); executed: return QSqlTableModel::selectStatement(); Execution Count:5 | 5 |
300 | | - |
301 | | - |
302 | QHash<QString, int> fieldNames; | - |
303 | QStringList fieldList; | - |
304 | for (int i = 0; i < d->baseRec.count(); ++i) { evaluated: i < d->baseRec.count() yes Evaluation Count:302 | yes Evaluation Count:84 |
| 84-302 |
305 | QSqlRelation relation = d->relations.value(i).rel; | - |
306 | QString name; | - |
307 | if (relation.isValid()) { evaluated: relation.isValid() yes Evaluation Count:103 | yes Evaluation Count:199 |
| 103-199 |
308 | | - |
309 | name = relation.displayColumn(); | - |
310 | if (d->db.driver()->isIdentifierEscaped(name, QSqlDriver::FieldName)) evaluated: d->db.driver()->isIdentifierEscaped(name, QSqlDriver::FieldName) yes Evaluation Count:10 | yes Evaluation Count:93 |
| 10-93 |
311 | name = d->db.driver()->stripDelimiters(name, QSqlDriver::FieldName); executed: name = d->db.driver()->stripDelimiters(name, QSqlDriver::FieldName); Execution Count:10 | 10 |
312 | | - |
313 | const QSqlRecord rec = database().record(relation.tableName()); | - |
314 | for (int i = 0; i < rec.count(); ++i) { partially evaluated: i < rec.count() yes Evaluation Count:206 | no Evaluation Count:0 |
| 0-206 |
315 | if (name.compare(rec.fieldName(i), Qt::CaseInsensitive) == 0) { evaluated: name.compare(rec.fieldName(i), Qt::CaseInsensitive) == 0 yes Evaluation Count:103 | yes Evaluation Count:103 |
| 103 |
316 | name = rec.fieldName(i); | - |
317 | break; executed: break; Execution Count:103 | 103 |
318 | } | - |
319 | } executed: } Execution Count:103 | 103 |
320 | } executed: } Execution Count:103 | 103 |
321 | else { | - |
322 | name = d->baseRec.fieldName(i); | - |
323 | } executed: } Execution Count:199 | 199 |
324 | fieldNames[name] = fieldNames.value(name, 0) + 1; | - |
325 | fieldList.append(name); | - |
326 | } executed: } Execution Count:302 | 302 |
327 | | - |
328 | QString fList; | - |
329 | QString conditions; | - |
330 | QString from = Sql::from(tableName()); | - |
331 | for (int i = 0; i < d->baseRec.count(); ++i) { evaluated: i < d->baseRec.count() yes Evaluation Count:302 | yes Evaluation Count:84 |
| 84-302 |
332 | QSqlRelation relation = d->relations.value(i).rel; | - |
333 | const QString tableField = d->fullyQualifiedFieldName(tableName(), d->db.driver()->escapeIdentifier(d->baseRec.fieldName(i), QSqlDriver::FieldName)); | - |
334 | if (relation.isValid()) { evaluated: relation.isValid() yes Evaluation Count:103 | yes Evaluation Count:199 |
| 103-199 |
335 | const QString relTableAlias = Sql::relTablePrefix(i); | - |
336 | QString displayTableField = d->fullyQualifiedFieldName(relTableAlias, relation.displayColumn()); | - |
337 | | - |
338 | | - |
339 | if (fieldNames.value(fieldList[i]) > 1) { evaluated: fieldNames.value(fieldList[i]) > 1 yes Evaluation Count:23 | yes Evaluation Count:80 |
| 23-80 |
340 | QString relTableName = relation.tableName().section(QChar::fromLatin1('.'), -1, -1); | - |
341 | if (d->db.driver()->isIdentifierEscaped(relTableName, QSqlDriver::TableName)) partially evaluated: d->db.driver()->isIdentifierEscaped(relTableName, QSqlDriver::TableName) no Evaluation Count:0 | yes Evaluation Count:23 |
| 0-23 |
342 | relTableName = d->db.driver()->stripDelimiters(relTableName, QSqlDriver::TableName); never executed: relTableName = d->db.driver()->stripDelimiters(relTableName, QSqlDriver::TableName); | 0 |
343 | QString displayColumn = relation.displayColumn(); | - |
344 | if (d->db.driver()->isIdentifierEscaped(displayColumn, QSqlDriver::FieldName)) partially evaluated: d->db.driver()->isIdentifierEscaped(displayColumn, QSqlDriver::FieldName) no Evaluation Count:0 | yes Evaluation Count:23 |
| 0-23 |
345 | displayColumn = d->db.driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName); never executed: displayColumn = d->db.driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName); | 0 |
346 | const QString alias = QString::fromLatin1("%1_%2_%3").arg(relTableName).arg(displayColumn).arg(fieldNames.value(fieldList[i])); | - |
347 | displayTableField = Sql::as(displayTableField, alias); | - |
348 | --fieldNames[fieldList[i]]; | - |
349 | } executed: } Execution Count:23 | 23 |
350 | | - |
351 | fList = Sql::comma(fList, displayTableField); | - |
352 | | - |
353 | | - |
354 | const QString tblexpr = Sql::concat(relation.tableName(), relTableAlias); | - |
355 | const QString relTableField = d->fullyQualifiedFieldName(relTableAlias, relation.indexColumn()); | - |
356 | const QString cond = Sql::eq(tableField, relTableField); | - |
357 | if (d->joinMode == QSqlRelationalTableModel::InnerJoin) { evaluated: d->joinMode == QSqlRelationalTableModel::InnerJoin yes Evaluation Count:73 | yes Evaluation Count:30 |
| 30-73 |
358 | | - |
359 | | - |
360 | from = Sql::comma(from, tblexpr); | - |
361 | conditions = Sql::et(conditions, cond); | - |
362 | } else { executed: } Execution Count:73 | 73 |
363 | from = Sql::concat(from, Sql::leftJoin(tblexpr)); | - |
364 | from = Sql::concat(from, Sql::on(cond)); | - |
365 | } executed: } Execution Count:30 | 30 |
366 | } else { | - |
367 | fList = Sql::comma(fList, tableField); | - |
368 | } executed: } Execution Count:199 | 199 |
369 | } | - |
370 | | - |
371 | if (fList.isEmpty()) partially evaluated: fList.isEmpty() no Evaluation Count:0 | yes Evaluation Count:84 |
| 0-84 |
372 | return QString(); never executed: return QString(); | 0 |
373 | | - |
374 | const QString stmt = Sql::concat(Sql::select(fList), from); | - |
375 | const QString where = Sql::where(Sql::et(Sql::paren(conditions), Sql::paren(filter()))); | - |
376 | return Sql::concat(Sql::concat(stmt, where), orderByClause()); executed: return Sql::concat(Sql::concat(stmt, where), orderByClause()); Execution Count:84 | 84 |
377 | } | - |
378 | QSqlTableModel *QSqlRelationalTableModel::relationModel(int column) const | - |
379 | { | - |
380 | const QSqlRelationalTableModelPrivate * const d = d_func(); | - |
381 | if ( column < 0 || column >= d->relations.count()) partially evaluated: column < 0 no Evaluation Count:0 | yes Evaluation Count:20 |
evaluated: column >= d->relations.count() yes Evaluation Count:4 | yes Evaluation Count:16 |
| 0-20 |
382 | return 0; executed: return 0; Execution Count:4 | 4 |
383 | | - |
384 | QRelation &relation = const_cast<QSqlRelationalTableModelPrivate *>(d)->relations[column]; | - |
385 | if (!relation.isValid()) evaluated: !relation.isValid() yes Evaluation Count:6 | yes Evaluation Count:10 |
| 6-10 |
386 | return 0; executed: return 0; Execution Count:6 | 6 |
387 | | - |
388 | if (!relation.model) evaluated: !relation.model yes Evaluation Count:3 | yes Evaluation Count:7 |
| 3-7 |
389 | relation.populateModel(); executed: relation.populateModel(); Execution Count:3 | 3 |
390 | return relation.model; executed: return relation.model; Execution Count:10 | 10 |
391 | } | - |
392 | | - |
393 | | - |
394 | | - |
395 | | - |
396 | void QSqlRelationalTableModel::revertRow(int row) | - |
397 | { | - |
398 | QSqlTableModel::revertRow(row); | - |
399 | } executed: } Execution Count:19 | 19 |
400 | | - |
401 | | - |
402 | | - |
403 | | - |
404 | void QSqlRelationalTableModel::clear() | - |
405 | { | - |
406 | QSqlRelationalTableModelPrivate * const d = d_func(); | - |
407 | d->clearChanges(); | - |
408 | d->relations.clear(); | - |
409 | QSqlTableModel::clear(); | - |
410 | } executed: } Execution Count:32 | 32 |
411 | void QSqlRelationalTableModel::setJoinMode( QSqlRelationalTableModel::JoinMode joinMode ) | - |
412 | { | - |
413 | QSqlRelationalTableModelPrivate * const d = d_func(); | - |
414 | d->joinMode = joinMode; | - |
415 | } executed: } Execution Count:23 | 23 |
416 | | - |
417 | | - |
418 | | - |
419 | bool QSqlRelationalTableModel::select() | - |
420 | { | - |
421 | return QSqlTableModel::select(); executed: return QSqlTableModel::select(); Execution Count:74 | 74 |
422 | } | - |
423 | | - |
424 | | - |
425 | | - |
426 | | - |
427 | void QSqlRelationalTableModel::setTable(const QString &table) | - |
428 | { | - |
429 | QSqlRelationalTableModelPrivate * const d = d_func(); | - |
430 | | - |
431 | | - |
432 | d->baseRec = d->db.record(table); | - |
433 | | - |
434 | QSqlTableModel::setTable(table); | - |
435 | } executed: } Execution Count:32 | 32 |
436 | | - |
437 | | - |
438 | | - |
439 | void QSqlRelationalTableModelPrivate::translateFieldNames(QSqlRecord &values) const | - |
440 | { | - |
441 | for (int i = 0; i < values.count(); ++i) { evaluated: i < values.count() yes Evaluation Count:93 | yes Evaluation Count:26 |
| 26-93 |
442 | if (relations.value(i).isValid()) { evaluated: relations.value(i).isValid() yes Evaluation Count:34 | yes Evaluation Count:59 |
| 34-59 |
443 | QVariant v = values.value(i); | - |
444 | bool gen = values.isGenerated(i); | - |
445 | values.replace(i, baseRec.field(i)); | - |
446 | values.setValue(i, v); | - |
447 | values.setGenerated(i, gen); | - |
448 | } executed: } Execution Count:34 | 34 |
449 | } executed: } Execution Count:93 | 93 |
450 | } executed: } Execution Count:26 | 26 |
451 | | - |
452 | | - |
453 | | - |
454 | | - |
455 | bool QSqlRelationalTableModel::updateRowInTable(int row, const QSqlRecord &values) | - |
456 | { | - |
457 | QSqlRelationalTableModelPrivate * const d = d_func(); | - |
458 | | - |
459 | QSqlRecord rec = values; | - |
460 | d->translateFieldNames(rec); | - |
461 | | - |
462 | return QSqlTableModel::updateRowInTable(row, rec); executed: return QSqlTableModel::updateRowInTable(row, rec); Execution Count:19 | 19 |
463 | } | - |
464 | | - |
465 | | - |
466 | | - |
467 | | - |
468 | bool QSqlRelationalTableModel::insertRowIntoTable(const QSqlRecord &values) | - |
469 | { | - |
470 | QSqlRelationalTableModelPrivate * const d = d_func(); | - |
471 | | - |
472 | QSqlRecord rec = values; | - |
473 | d->translateFieldNames(rec); | - |
474 | | - |
475 | return QSqlTableModel::insertRowIntoTable(rec); executed: return QSqlTableModel::insertRowIntoTable(rec); Execution Count:7 | 7 |
476 | } | - |
477 | | - |
478 | | - |
479 | | - |
480 | | - |
481 | QString QSqlRelationalTableModel::orderByClause() const | - |
482 | { | - |
483 | const QSqlRelationalTableModelPrivate * const d = d_func(); | - |
484 | | - |
485 | const QSqlRelation rel = d->relations.value(d->sortColumn).rel; | - |
486 | if (!rel.isValid()) evaluated: !rel.isValid() yes Evaluation Count:85 | yes Evaluation Count:4 |
| 4-85 |
487 | return QSqlTableModel::orderByClause(); executed: return QSqlTableModel::orderByClause(); Execution Count:85 | 85 |
488 | | - |
489 | QString f = d->fullyQualifiedFieldName(Sql::relTablePrefix(d->sortColumn), rel.displayColumn()); | - |
490 | f = d->sortOrder == Qt::AscendingOrder ? Sql::asc(f) : Sql::desc(f); evaluated: d->sortOrder == Qt::AscendingOrder yes Evaluation Count:2 | yes Evaluation Count:2 |
| 2 |
491 | return Sql::orderBy(f); executed: return Sql::orderBy(f); Execution Count:4 | 4 |
492 | } | - |
493 | | - |
494 | | - |
495 | | - |
496 | | - |
497 | bool QSqlRelationalTableModel::removeColumns(int column, int count, const QModelIndex &parent) | - |
498 | { | - |
499 | QSqlRelationalTableModelPrivate * const d = d_func(); | - |
500 | | - |
501 | if (parent.isValid() || column < 0 || column + count > d->rec.count()) partially evaluated: parent.isValid() no Evaluation Count:0 | yes Evaluation Count:4 |
partially evaluated: column < 0 no Evaluation Count:0 | yes Evaluation Count:4 |
partially evaluated: column + count > d->rec.count() no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
502 | return false; never executed: return false; | 0 |
503 | | - |
504 | for (int i = 0; i < count; ++i) { evaluated: i < count yes Evaluation Count:6 | yes Evaluation Count:4 |
| 4-6 |
505 | d->baseRec.remove(column); | - |
506 | if (d->relations.count() > column) evaluated: d->relations.count() > column yes Evaluation Count:4 | yes Evaluation Count:2 |
| 2-4 |
507 | d->relations.remove(column); executed: d->relations.remove(column); Execution Count:4 | 4 |
508 | } executed: } Execution Count:6 | 6 |
509 | return QSqlTableModel::removeColumns(column, count, parent); executed: return QSqlTableModel::removeColumns(column, count, parent); Execution Count:4 | 4 |
510 | } | - |
511 | | - |
512 | | - |
513 | | - |
| | |