Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtSql module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qsqlrelationaltablemodel.h" | - |
43 | | - |
44 | #include "qhash.h" | - |
45 | #include "qstringlist.h" | - |
46 | #include "qsqldatabase.h" | - |
47 | #include "qsqldriver.h" | - |
48 | #include "qsqlerror.h" | - |
49 | #include "qsqlfield.h" | - |
50 | #include "qsqlindex.h" | - |
51 | #include "qsqlquery.h" | - |
52 | #include "qsqlrecord.h" | - |
53 | | - |
54 | #include "qsqltablemodel_p.h" | - |
55 | | - |
56 | #include "qdebug.h" | - |
57 | | - |
58 | QT_BEGIN_NAMESPACE | - |
59 | | - |
60 | class QSqlRelationalTableModelSql: public QSqlTableModelSql | - |
61 | { | - |
62 | public: | - |
63 | 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 |
64 | }; | - |
65 | | - |
66 | typedef QSqlRelationalTableModelSql Sql; | - |
67 | | - |
68 | /*! | - |
69 | \class QSqlRelation | - |
70 | \inmodule QtSql | - |
71 | \brief The QSqlRelation class stores information about an SQL foreign key. | - |
72 | | - |
73 | QSqlRelation is a helper class for QSqlRelationalTableModel. See | - |
74 | QSqlRelationalTableModel::setRelation() and | - |
75 | QSqlRelationalTableModel::relation() for details. | - |
76 | | - |
77 | \sa QSqlRelationalTableModel, QSqlRelationalDelegate, | - |
78 | {Relational Table Model Example} | - |
79 | */ | - |
80 | | - |
81 | /*! | - |
82 | \fn QSqlRelation::QSqlRelation() | - |
83 | | - |
84 | Constructs an invalid QSqlRelation object. | - |
85 | | - |
86 | For such an object, the tableName(), indexColumn(), and | - |
87 | displayColumn() functions return an empty string. | - |
88 | | - |
89 | \sa isValid() | - |
90 | */ | - |
91 | | - |
92 | /*! | - |
93 | \fn QSqlRelation::QSqlRelation(const QString &tableName, const QString &indexColumn, | - |
94 | const QString &displayColumn) | - |
95 | | - |
96 | Constructs a QSqlRelation object, where \a tableName is the SQL | - |
97 | table name to which a foreign key refers, \a indexColumn is the | - |
98 | foreign key, and \a displayColumn is the field that should be | - |
99 | presented to the user. | - |
100 | | - |
101 | \sa tableName(), indexColumn(), displayColumn() | - |
102 | */ | - |
103 | | - |
104 | /*! | - |
105 | \fn QString QSqlRelation::tableName() const | - |
106 | | - |
107 | Returns the name of the table to which a foreign key refers. | - |
108 | */ | - |
109 | | - |
110 | /*! | - |
111 | \fn QString QSqlRelation::indexColumn() const | - |
112 | | - |
113 | Returns the index column from table tableName() to which a | - |
114 | foreign key refers. | - |
115 | */ | - |
116 | | - |
117 | /*! | - |
118 | \fn QString QSqlRelation::displayColumn() const | - |
119 | | - |
120 | Returns the column from table tableName() that should be | - |
121 | presented to the user instead of a foreign key. | - |
122 | */ | - |
123 | | - |
124 | /*! | - |
125 | \fn bool QSqlRelation::isValid() const | - |
126 | | - |
127 | Returns true if the QSqlRelation object is valid; otherwise | - |
128 | returns false. | - |
129 | */ | - |
130 | | - |
131 | class QRelatedTableModel; | - |
132 | | - |
133 | struct QRelation | - |
134 | { | - |
135 | public: | - |
136 | QRelation(): model(0), m_parent(0), m_dictInitialized(false) {} executed: } Execution Count:266 | 266 |
137 | void init(QSqlRelationalTableModel *parent, const QSqlRelation &relation); | - |
138 | | - |
139 | void populateModel(); | - |
140 | | - |
141 | bool isDictionaryInitialized(); | - |
142 | void populateDictionary(); | - |
143 | void clearDictionary(); | - |
144 | | - |
145 | void clear(); | - |
146 | bool isValid(); | - |
147 | | - |
148 | QSqlRelation rel; | - |
149 | QRelatedTableModel *model; | - |
150 | QHash<QString, QVariant> dictionary;//maps keys to display values | - |
151 | | - |
152 | private: | - |
153 | QSqlRelationalTableModel *m_parent; | - |
154 | bool m_dictInitialized; | - |
155 | }; | - |
156 | | - |
157 | class QRelatedTableModel : public QSqlTableModel | - |
158 | { | - |
159 | public: | - |
160 | QRelatedTableModel(QRelation *rel, QObject *parent = 0, QSqlDatabase db = QSqlDatabase()); | - |
161 | bool select(); | - |
162 | private: | - |
163 | bool firstSelect; | - |
164 | QRelation *relation; | - |
165 | }; | - |
166 | /* | - |
167 | A QRelation must be initialized before it is considered valid. | - |
168 | Note: population of the model and dictionary are kept separate | - |
169 | from initialization, and are populated on an as needed basis. | - |
170 | */ | - |
171 | void QRelation::init(QSqlRelationalTableModel *parent, const QSqlRelation &relation) | - |
172 | { | - |
173 | Q_ASSERT(parent != NULL); executed (the execution status of this line is deduced): qt_noop(); | - |
174 | m_parent = parent; executed (the execution status of this line is deduced): m_parent = parent; | - |
175 | rel = relation; executed (the execution status of this line is deduced): rel = relation; | - |
176 | } executed: } Execution Count:44 | 44 |
177 | | - |
178 | void QRelation::populateModel() | - |
179 | { | - |
180 | if (!isValid()) partially evaluated: !isValid() no Evaluation Count:0 | yes Evaluation Count:40 |
| 0-40 |
181 | return; | 0 |
182 | Q_ASSERT(m_parent != NULL); executed (the execution status of this line is deduced): qt_noop(); | - |
183 | | - |
184 | if (!model) { partially evaluated: !model yes Evaluation Count:40 | no Evaluation Count:0 |
| 0-40 |
185 | model = new QRelatedTableModel(this, m_parent, m_parent->database()); executed (the execution status of this line is deduced): model = new QRelatedTableModel(this, m_parent, m_parent->database()); | - |
186 | model->setTable(rel.tableName()); executed (the execution status of this line is deduced): model->setTable(rel.tableName()); | - |
187 | model->select(); executed (the execution status of this line is deduced): model->select(); | - |
188 | } executed: } Execution Count:40 | 40 |
189 | } executed: } Execution Count:40 | 40 |
190 | | - |
191 | bool QRelation::isDictionaryInitialized() | - |
192 | { | - |
193 | return m_dictInitialized; executed: return m_dictInitialized; Execution Count:191 | 191 |
194 | } | - |
195 | | - |
196 | void QRelation::populateDictionary() | - |
197 | { | - |
198 | if (!isValid()) partially evaluated: !isValid() no Evaluation Count:0 | yes Evaluation Count:66 |
| 0-66 |
199 | return; | 0 |
200 | | - |
201 | if (model == NULL) evaluated: model == __null yes Evaluation Count:37 | yes Evaluation Count:29 |
| 29-37 |
202 | populateModel(); executed: populateModel(); Execution Count:37 | 37 |
203 | | - |
204 | QSqlRecord record; executed (the execution status of this line is deduced): QSqlRecord record; | - |
205 | QString indexColumn; executed (the execution status of this line is deduced): QString indexColumn; | - |
206 | QString displayColumn; executed (the execution status of this line is deduced): QString displayColumn; | - |
207 | for (int i=0; i < model->rowCount(); ++i) { evaluated: i < model->rowCount() yes Evaluation Count:136 | yes Evaluation Count:66 |
| 66-136 |
208 | record = model->record(i); executed (the execution status of this line is deduced): record = model->record(i); | - |
209 | | - |
210 | indexColumn = rel.indexColumn(); executed (the execution status of this line is deduced): indexColumn = rel.indexColumn(); | - |
211 | 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 |
212 | indexColumn = m_parent->database().driver()->stripDelimiters(indexColumn, QSqlDriver::FieldName); executed: indexColumn = m_parent->database().driver()->stripDelimiters(indexColumn, QSqlDriver::FieldName); Execution Count:14 | 14 |
213 | | - |
214 | displayColumn = rel.displayColumn(); executed (the execution status of this line is deduced): displayColumn = rel.displayColumn(); | - |
215 | 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 |
216 | displayColumn = m_parent->database().driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName); executed: displayColumn = m_parent->database().driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName); Execution Count:18 | 18 |
217 | | - |
218 | dictionary[record.field(indexColumn).value().toString()] = executed (the execution status of this line is deduced): dictionary[record.field(indexColumn).value().toString()] = | - |
219 | record.field(displayColumn).value(); executed (the execution status of this line is deduced): record.field(displayColumn).value(); | - |
220 | } executed: } Execution Count:136 | 136 |
221 | m_dictInitialized = true; executed (the execution status of this line is deduced): m_dictInitialized = true; | - |
222 | } executed: } Execution Count:66 | 66 |
223 | | - |
224 | void QRelation::clearDictionary() | - |
225 | { | - |
226 | dictionary.clear(); executed (the execution status of this line is deduced): dictionary.clear(); | - |
227 | m_dictInitialized = false; executed (the execution status of this line is deduced): m_dictInitialized = false; | - |
228 | } executed: } Execution Count:216 | 216 |
229 | | - |
230 | void QRelation::clear() | - |
231 | { | - |
232 | delete model; executed (the execution status of this line is deduced): delete model; | - |
233 | model = 0; executed (the execution status of this line is deduced): model = 0; | - |
234 | clearDictionary(); executed (the execution status of this line is deduced): clearDictionary(); | - |
235 | } executed: } Execution Count:4 | 4 |
236 | | - |
237 | bool QRelation::isValid() | - |
238 | { | - |
239 | return (rel.isValid() && m_parent != NULL); executed: return (rel.isValid() && m_parent != __null); Execution Count:497 | 497 |
240 | } | - |
241 | | - |
242 | | - |
243 | | - |
244 | QRelatedTableModel::QRelatedTableModel(QRelation *rel, QObject *parent, QSqlDatabase db) : | - |
245 | QSqlTableModel(parent, db), firstSelect(true), relation(rel) | - |
246 | { | - |
247 | } executed: } Execution Count:40 | 40 |
248 | | - |
249 | bool QRelatedTableModel::select() | - |
250 | { | - |
251 | if (firstSelect) { evaluated: firstSelect yes Evaluation Count:40 | yes Evaluation Count:1 |
| 1-40 |
252 | firstSelect = false; executed (the execution status of this line is deduced): firstSelect = false; | - |
253 | return QSqlTableModel::select(); executed: return QSqlTableModel::select(); Execution Count:40 | 40 |
254 | } | - |
255 | relation->clearDictionary(); executed (the execution status of this line is deduced): relation->clearDictionary(); | - |
256 | bool res = QSqlTableModel::select(); executed (the execution status of this line is deduced): bool res = QSqlTableModel::select(); | - |
257 | if (res) partially evaluated: res yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
258 | relation->populateDictionary(); executed: relation->populateDictionary(); Execution Count:1 | 1 |
259 | return res; executed: return res; Execution Count:1 | 1 |
260 | } | - |
261 | | - |
262 | | - |
263 | class QSqlRelationalTableModelPrivate: public QSqlTableModelPrivate | - |
264 | { | - |
265 | Q_DECLARE_PUBLIC(QSqlRelationalTableModel) | - |
266 | public: | - |
267 | QSqlRelationalTableModelPrivate() | - |
268 | : QSqlTableModelPrivate(), | - |
269 | joinMode( QSqlRelationalTableModel::InnerJoin ) | - |
270 | {} executed: } Execution Count:31 | 31 |
271 | QString fullyQualifiedFieldName(const QString &tableName, const QString &fieldName) const; | - |
272 | | - |
273 | int nameToIndex(const QString &name) const; | - |
274 | mutable QVector<QRelation> relations; | - |
275 | QSqlRecord baseRec; // the record without relations | - |
276 | void clearChanges(); | - |
277 | void clearCache(); | - |
278 | void revertCachedRow(int row); | - |
279 | | - |
280 | void translateFieldNames(QSqlRecord &values) const; | - |
281 | QSqlRelationalTableModel::JoinMode joinMode; | - |
282 | }; | - |
283 | | - |
284 | void QSqlRelationalTableModelPrivate::clearChanges() | - |
285 | { | - |
286 | for (int i = 0; i < relations.count(); ++i) { evaluated: i < relations.count() yes Evaluation Count:4 | yes Evaluation Count:32 |
| 4-32 |
287 | QRelation &rel = relations[i]; executed (the execution status of this line is deduced): QRelation &rel = relations[i]; | - |
288 | rel.clear(); executed (the execution status of this line is deduced): rel.clear(); | - |
289 | } executed: } Execution Count:4 | 4 |
290 | } executed: } Execution Count:32 | 32 |
291 | | - |
292 | void QSqlRelationalTableModelPrivate::revertCachedRow(int row) | - |
293 | { | - |
294 | QSqlTableModelPrivate::revertCachedRow(row); executed (the execution status of this line is deduced): QSqlTableModelPrivate::revertCachedRow(row); | - |
295 | } executed: } Execution Count:19 | 19 |
296 | | - |
297 | int QSqlRelationalTableModelPrivate::nameToIndex(const QString &name) const | - |
298 | { | - |
299 | const QString fieldname = strippedFieldName(name); executed (the execution status of this line is deduced): const QString fieldname = strippedFieldName(name); | - |
300 | int idx = baseRec.indexOf(fieldname); executed (the execution status of this line is deduced): int idx = baseRec.indexOf(fieldname); | - |
301 | if (idx == -1) { evaluated: idx == -1 yes Evaluation Count:1 | yes Evaluation Count:16 |
| 1-16 |
302 | // If the name is an alias we can find it here. | - |
303 | idx = QSqlTableModelPrivate::nameToIndex(name); executed (the execution status of this line is deduced): idx = QSqlTableModelPrivate::nameToIndex(name); | - |
304 | } executed: } Execution Count:1 | 1 |
305 | return idx; executed: return idx; Execution Count:17 | 17 |
306 | } | - |
307 | | - |
308 | /*! | - |
309 | \reimp | - |
310 | */ | - |
311 | void QSqlRelationalTableModelPrivate::clearCache() | - |
312 | { | - |
313 | for (int i = 0; i < relations.count(); ++i) evaluated: i < relations.count() yes Evaluation Count:211 | yes Evaluation Count:74 |
| 74-211 |
314 | relations[i].clearDictionary(); executed: relations[i].clearDictionary(); Execution Count:211 | 211 |
315 | | - |
316 | QSqlTableModelPrivate::clearCache(); executed (the execution status of this line is deduced): QSqlTableModelPrivate::clearCache(); | - |
317 | } executed: } Execution Count:74 | 74 |
318 | | - |
319 | /*! | - |
320 | \class QSqlRelationalTableModel | - |
321 | \brief The QSqlRelationalTableModel class provides an editable | - |
322 | data model for a single database table, with foreign key support. | - |
323 | | - |
324 | \ingroup database | - |
325 | \inmodule QtSql | - |
326 | | - |
327 | QSqlRelationalTableModel acts like QSqlTableModel, but allows | - |
328 | columns to be set as foreign keys into other database tables. | - |
329 | | - |
330 | \table | - |
331 | \row \li \inlineimage noforeignkeys.png | - |
332 | \li \inlineimage foreignkeys.png | - |
333 | \endtable | - |
334 | | - |
335 | The screenshot on the left shows a plain QSqlTableModel in a | - |
336 | QTableView. Foreign keys (\c city and \c country) aren't resolved | - |
337 | to human-readable values. The screenshot on the right shows a | - |
338 | QSqlRelationalTableModel, with foreign keys resolved into | - |
339 | human-readable text strings. | - |
340 | | - |
341 | The following code snippet shows how the QSqlRelationalTableModel | - |
342 | was set up: | - |
343 | | - |
344 | \snippet relationaltablemodel/relationaltablemodel.cpp 0 | - |
345 | \codeline | - |
346 | \snippet relationaltablemodel/relationaltablemodel.cpp 1 | - |
347 | \snippet relationaltablemodel/relationaltablemodel.cpp 2 | - |
348 | | - |
349 | The setRelation() function calls establish a relationship between | - |
350 | two tables. The first call specifies that column 2 in table \c | - |
351 | employee is a foreign key that maps with field \c id of table \c | - |
352 | city, and that the view should present the \c{city}'s \c name | - |
353 | field to the user. The second call does something similar with | - |
354 | column 3. | - |
355 | | - |
356 | If you use a read-write QSqlRelationalTableModel, you probably | - |
357 | want to use QSqlRelationalDelegate on the view. Unlike the default | - |
358 | delegate, QSqlRelationalDelegate provides a combobox for fields | - |
359 | that are foreign keys into other tables. To use the class, simply | - |
360 | call QAbstractItemView::setItemDelegate() on the view with an | - |
361 | instance of QSqlRelationalDelegate: | - |
362 | | - |
363 | \snippet relationaltablemodel/relationaltablemodel.cpp 4 | - |
364 | | - |
365 | The \l{relationaltablemodel} example illustrates how to use | - |
366 | QSqlRelationalTableModel in conjunction with | - |
367 | QSqlRelationalDelegate to provide tables with foreign key | - |
368 | support. | - |
369 | | - |
370 | \image relationaltable.png | - |
371 | | - |
372 | Notes: | - |
373 | | - |
374 | \list | - |
375 | \li The table must have a primary key declared. | - |
376 | \li The table's primary key may not contain a relation to | - |
377 | another table. | - |
378 | \li If a relational table contains keys that refer to non-existent | - |
379 | rows in the referenced table, the rows containing the invalid | - |
380 | keys will not be exposed through the model. The user or the | - |
381 | database is responsible for keeping referential integrity. | - |
382 | \li If a relation's display column name is also used as a column | - |
383 | name in the relational table, or if it is used as display column | - |
384 | name in more than one relation it will be aliased. The alias is | - |
385 | the relation's table name, display column name and a unique id | - |
386 | joined by an underscore (e.g. tablename_columnname_id). | - |
387 | QSqlRecord::fieldName() will return the aliased column name. | - |
388 | All occurrences of the duplicate display column name are aliased when | - |
389 | duplication is detected, but no aliasing is done to the column | - |
390 | names in the main table. The aliasing doesn't affect | - |
391 | QSqlRelation, so QSqlRelation::displayColumn() will return the | - |
392 | original display column name. | - |
393 | \li The reference table name is aliased. The alias is the word "relTblAl" | - |
394 | and the relationed column index joined by an underscore | - |
395 | (e.g. relTblAl_2). The alias can be used to filter the table | - |
396 | (For example, setFilter("relTblAl_2='Oslo' OR | - |
397 | relTblAl_3='USA'")). | - |
398 | \li When using setData() the role should always be Qt::EditRole, | - |
399 | and when using data() the role should always be Qt::DisplayRole. | - |
400 | \endlist | - |
401 | | - |
402 | \sa QSqlRelation, QSqlRelationalDelegate, | - |
403 | {Relational Table Model Example} | - |
404 | */ | - |
405 | | - |
406 | | - |
407 | /*! | - |
408 | Creates an empty QSqlRelationalTableModel and sets the parent to \a parent | - |
409 | and the database connection to \a db. If \a db is not valid, the | - |
410 | default database connection will be used. | - |
411 | */ | - |
412 | QSqlRelationalTableModel::QSqlRelationalTableModel(QObject *parent, QSqlDatabase db) | - |
413 | : QSqlTableModel(*new QSqlRelationalTableModelPrivate, parent, db) | - |
414 | { | - |
415 | } executed: } Execution Count:31 | 31 |
416 | | - |
417 | /*! | - |
418 | Destroys the object and frees any allocated resources. | - |
419 | */ | - |
420 | QSqlRelationalTableModel::~QSqlRelationalTableModel() | - |
421 | { | - |
422 | } | - |
423 | | - |
424 | /*! | - |
425 | \reimp | - |
426 | */ | - |
427 | QVariant QSqlRelationalTableModel::data(const QModelIndex &index, int role) const | - |
428 | { | - |
429 | Q_D(const QSqlRelationalTableModel); executed (the execution status of this line is deduced): const QSqlRelationalTableModelPrivate * const d = d_func(); | - |
430 | | - |
431 | 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 |
432 | d->relations.value(index.column()).isValid()) { evaluated: d->relations.value(index.column()).isValid() yes Evaluation Count:147 | yes Evaluation Count:76 |
| 76-147 |
433 | QRelation &relation = d->relations[index.column()]; executed (the execution status of this line is deduced): QRelation &relation = d->relations[index.column()]; | - |
434 | if (!relation.isDictionaryInitialized()) evaluated: !relation.isDictionaryInitialized() yes Evaluation Count:54 | yes Evaluation Count:93 |
| 54-93 |
435 | relation.populateDictionary(); executed: relation.populateDictionary(); Execution Count:54 | 54 |
436 | | - |
437 | //only perform a dictionary lookup for the display value | - |
438 | //when the value at index has been changed or added. | - |
439 | //At an unmodified index, the underlying model will | - |
440 | //already have the correct display value. | - |
441 | if (d->strategy != OnFieldChange) { evaluated: d->strategy != OnFieldChange yes Evaluation Count:146 | yes Evaluation Count:1 |
| 1-146 |
442 | const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row()); executed (the execution status of this line is deduced): const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row()); | - |
443 | 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 |
444 | 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 |
445 | QVariant v = row.rec().value(index.column()); executed (the execution status of this line is deduced): QVariant v = row.rec().value(index.column()); | - |
446 | if (v.isValid()) partially evaluated: v.isValid() yes Evaluation Count:29 | no Evaluation Count:0 |
| 0-29 |
447 | return relation.dictionary[v.toString()]; executed: return relation.dictionary[v.toString()]; Execution Count:29 | 29 |
448 | } | 0 |
449 | } | 0 |
450 | } executed: } Execution Count:117 | 117 |
451 | } executed: } Execution Count:118 | 118 |
452 | return QSqlTableModel::data(index, role); executed: return QSqlTableModel::data(index, role); Execution Count:307 | 307 |
453 | } | - |
454 | | - |
455 | /*! | - |
456 | Sets the data for the \a role in the item with the specified \a | - |
457 | index to the \a value given. Depending on the edit strategy, the | - |
458 | value might be applied to the database at once, or it may be | - |
459 | cached in the model. | - |
460 | | - |
461 | Returns true if the value could be set, or false on error (for | - |
462 | example, if \a index is out of bounds). | - |
463 | | - |
464 | For relational columns, \a value must be the index, not the | - |
465 | display value. The index must also exist in the referenced | - |
466 | table, otherwise the function returns false. | - |
467 | | - |
468 | \sa editStrategy(), data(), submit(), revertRow() | - |
469 | */ | - |
470 | bool QSqlRelationalTableModel::setData(const QModelIndex &index, const QVariant &value, | - |
471 | int role) | - |
472 | { | - |
473 | Q_D(QSqlRelationalTableModel); executed (the execution status of this line is deduced): QSqlRelationalTableModelPrivate * const d = d_func(); | - |
474 | 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 |
475 | && d->relations.value(index.column()).isValid()) { evaluated: d->relations.value(index.column()).isValid() yes Evaluation Count:44 | yes Evaluation Count:15 |
| 15-44 |
476 | QRelation &relation = d->relations[index.column()]; executed (the execution status of this line is deduced): QRelation &relation = d->relations[index.column()]; | - |
477 | if (!relation.isDictionaryInitialized()) evaluated: !relation.isDictionaryInitialized() yes Evaluation Count:11 | yes Evaluation Count:33 |
| 11-33 |
478 | relation.populateDictionary(); executed: relation.populateDictionary(); Execution Count:11 | 11 |
479 | if (!relation.dictionary.contains(value.toString())) evaluated: !relation.dictionary.contains(value.toString()) yes Evaluation Count:2 | yes Evaluation Count:42 |
| 2-42 |
480 | return false; executed: return false; Execution Count:2 | 2 |
481 | } executed: } Execution Count:42 | 42 |
482 | return QSqlTableModel::setData(index, value, role); executed: return QSqlTableModel::setData(index, value, role); Execution Count:83 | 83 |
483 | } | - |
484 | | - |
485 | /*! | - |
486 | Lets the specified \a column be a foreign index specified by \a relation. | - |
487 | | - |
488 | Example: | - |
489 | | - |
490 | \snippet relationaltablemodel/relationaltablemodel.cpp 0 | - |
491 | \codeline | - |
492 | \snippet relationaltablemodel/relationaltablemodel.cpp 1 | - |
493 | | - |
494 | The setRelation() call specifies that column 2 in table \c | - |
495 | employee is a foreign key that maps with field \c id of table \c | - |
496 | city, and that the view should present the \c{city}'s \c name | - |
497 | field to the user. | - |
498 | | - |
499 | Note: The table's primary key may not contain a relation to another table. | - |
500 | | - |
501 | \sa relation() | - |
502 | */ | - |
503 | void QSqlRelationalTableModel::setRelation(int column, const QSqlRelation &relation) | - |
504 | { | - |
505 | Q_D(QSqlRelationalTableModel); executed (the execution status of this line is deduced): QSqlRelationalTableModelPrivate * const d = d_func(); | - |
506 | if (column < 0) partially evaluated: column < 0 no Evaluation Count:0 | yes Evaluation Count:44 |
| 0-44 |
507 | return; | 0 |
508 | if (d->relations.size() <= column) evaluated: d->relations.size() <= column yes Evaluation Count:41 | yes Evaluation Count:3 |
| 3-41 |
509 | d->relations.resize(column + 1); executed: d->relations.resize(column + 1); Execution Count:41 | 41 |
510 | d->relations[column].init(this, relation); executed (the execution status of this line is deduced): d->relations[column].init(this, relation); | - |
511 | } executed: } Execution Count:44 | 44 |
512 | | - |
513 | /*! | - |
514 | Returns the relation for the column \a column, or an invalid | - |
515 | relation if no relation is set. | - |
516 | | - |
517 | \sa setRelation(), QSqlRelation::isValid() | - |
518 | */ | - |
519 | QSqlRelation QSqlRelationalTableModel::relation(int column) const | - |
520 | { | - |
521 | Q_D(const QSqlRelationalTableModel); never executed (the execution status of this line is deduced): const QSqlRelationalTableModelPrivate * const d = d_func(); | - |
522 | return d->relations.value(column).rel; never executed: return d->relations.value(column).rel; | 0 |
523 | } | - |
524 | | - |
525 | QString QSqlRelationalTableModelPrivate::fullyQualifiedFieldName(const QString &tableName, | - |
526 | const QString &fieldName) const | - |
527 | { | - |
528 | QString ret; executed (the execution status of this line is deduced): QString ret; | - |
529 | ret.reserve(tableName.size() + fieldName.size() + 1); executed (the execution status of this line is deduced): ret.reserve(tableName.size() + fieldName.size() + 1); | - |
530 | ret.append(tableName).append(QLatin1Char('.')).append(fieldName); executed (the execution status of this line is deduced): ret.append(tableName).append(QLatin1Char('.')).append(fieldName); | - |
531 | | - |
532 | return ret; executed: return ret; Execution Count:512 | 512 |
533 | } | - |
534 | | - |
535 | /*! | - |
536 | \reimp | - |
537 | */ | - |
538 | QString QSqlRelationalTableModel::selectStatement() const | - |
539 | { | - |
540 | Q_D(const QSqlRelationalTableModel); executed (the execution status of this line is deduced): const QSqlRelationalTableModelPrivate * const d = d_func(); | - |
541 | | - |
542 | if (tableName().isEmpty()) partially evaluated: tableName().isEmpty() no Evaluation Count:0 | yes Evaluation Count:89 |
| 0-89 |
543 | return QString(); never executed: return QString(); | 0 |
544 | if (d->relations.isEmpty()) evaluated: d->relations.isEmpty() yes Evaluation Count:5 | yes Evaluation Count:84 |
| 5-84 |
545 | return QSqlTableModel::selectStatement(); executed: return QSqlTableModel::selectStatement(); Execution Count:5 | 5 |
546 | | - |
547 | // Count how many times each field name occurs in the record | - |
548 | QHash<QString, int> fieldNames; executed (the execution status of this line is deduced): QHash<QString, int> fieldNames; | - |
549 | QStringList fieldList; executed (the execution status of this line is deduced): QStringList fieldList; | - |
550 | for (int i = 0; i < d->baseRec.count(); ++i) { evaluated: i < d->baseRec.count() yes Evaluation Count:302 | yes Evaluation Count:84 |
| 84-302 |
551 | QSqlRelation relation = d->relations.value(i).rel; executed (the execution status of this line is deduced): QSqlRelation relation = d->relations.value(i).rel; | - |
552 | QString name; executed (the execution status of this line is deduced): QString name; | - |
553 | if (relation.isValid()) { evaluated: relation.isValid() yes Evaluation Count:103 | yes Evaluation Count:199 |
| 103-199 |
554 | // Count the display column name, not the original foreign key | - |
555 | name = relation.displayColumn(); executed (the execution status of this line is deduced): name = relation.displayColumn(); | - |
556 | 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 |
557 | name = d->db.driver()->stripDelimiters(name, QSqlDriver::FieldName); executed: name = d->db.driver()->stripDelimiters(name, QSqlDriver::FieldName); Execution Count:10 | 10 |
558 | | - |
559 | const QSqlRecord rec = database().record(relation.tableName()); executed (the execution status of this line is deduced): const QSqlRecord rec = database().record(relation.tableName()); | - |
560 | for (int i = 0; i < rec.count(); ++i) { partially evaluated: i < rec.count() yes Evaluation Count:206 | no Evaluation Count:0 |
| 0-206 |
561 | 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 |
562 | name = rec.fieldName(i); executed (the execution status of this line is deduced): name = rec.fieldName(i); | - |
563 | break; executed: break; Execution Count:103 | 103 |
564 | } | - |
565 | } executed: } Execution Count:103 | 103 |
566 | } executed: } Execution Count:103 | 103 |
567 | else { | - |
568 | name = d->baseRec.fieldName(i); executed (the execution status of this line is deduced): name = d->baseRec.fieldName(i); | - |
569 | } executed: } Execution Count:199 | 199 |
570 | fieldNames[name] = fieldNames.value(name, 0) + 1; executed (the execution status of this line is deduced): fieldNames[name] = fieldNames.value(name, 0) + 1; | - |
571 | fieldList.append(name); executed (the execution status of this line is deduced): fieldList.append(name); | - |
572 | } executed: } Execution Count:302 | 302 |
573 | | - |
574 | QString fList; executed (the execution status of this line is deduced): QString fList; | - |
575 | QString conditions; executed (the execution status of this line is deduced): QString conditions; | - |
576 | QString from = Sql::from(tableName()); executed (the execution status of this line is deduced): QString from = Sql::from(tableName()); | - |
577 | for (int i = 0; i < d->baseRec.count(); ++i) { evaluated: i < d->baseRec.count() yes Evaluation Count:302 | yes Evaluation Count:84 |
| 84-302 |
578 | QSqlRelation relation = d->relations.value(i).rel; executed (the execution status of this line is deduced): QSqlRelation relation = d->relations.value(i).rel; | - |
579 | const QString tableField = d->fullyQualifiedFieldName(tableName(), d->db.driver()->escapeIdentifier(d->baseRec.fieldName(i), QSqlDriver::FieldName)); executed (the execution status of this line is deduced): const QString tableField = d->fullyQualifiedFieldName(tableName(), d->db.driver()->escapeIdentifier(d->baseRec.fieldName(i), QSqlDriver::FieldName)); | - |
580 | if (relation.isValid()) { evaluated: relation.isValid() yes Evaluation Count:103 | yes Evaluation Count:199 |
| 103-199 |
581 | const QString relTableAlias = Sql::relTablePrefix(i); executed (the execution status of this line is deduced): const QString relTableAlias = Sql::relTablePrefix(i); | - |
582 | QString displayTableField = d->fullyQualifiedFieldName(relTableAlias, relation.displayColumn()); executed (the execution status of this line is deduced): QString displayTableField = d->fullyQualifiedFieldName(relTableAlias, relation.displayColumn()); | - |
583 | | - |
584 | // Duplicate field names must be aliased | - |
585 | if (fieldNames.value(fieldList[i]) > 1) { evaluated: fieldNames.value(fieldList[i]) > 1 yes Evaluation Count:23 | yes Evaluation Count:80 |
| 23-80 |
586 | QString relTableName = relation.tableName().section(QChar::fromLatin1('.'), -1, -1); executed (the execution status of this line is deduced): QString relTableName = relation.tableName().section(QChar::fromLatin1('.'), -1, -1); | - |
587 | 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 |
588 | relTableName = d->db.driver()->stripDelimiters(relTableName, QSqlDriver::TableName); never executed: relTableName = d->db.driver()->stripDelimiters(relTableName, QSqlDriver::TableName); | 0 |
589 | QString displayColumn = relation.displayColumn(); executed (the execution status of this line is deduced): QString displayColumn = relation.displayColumn(); | - |
590 | 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 |
591 | displayColumn = d->db.driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName); never executed: displayColumn = d->db.driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName); | 0 |
592 | const QString alias = QString::fromLatin1("%1_%2_%3").arg(relTableName).arg(displayColumn).arg(fieldNames.value(fieldList[i])); executed (the execution status of this line is deduced): const QString alias = QString::fromLatin1("%1_%2_%3").arg(relTableName).arg(displayColumn).arg(fieldNames.value(fieldList[i])); | - |
593 | displayTableField = Sql::as(displayTableField, alias); executed (the execution status of this line is deduced): displayTableField = Sql::as(displayTableField, alias); | - |
594 | --fieldNames[fieldList[i]]; executed (the execution status of this line is deduced): --fieldNames[fieldList[i]]; | - |
595 | } executed: } Execution Count:23 | 23 |
596 | | - |
597 | fList = Sql::comma(fList, displayTableField); executed (the execution status of this line is deduced): fList = Sql::comma(fList, displayTableField); | - |
598 | | - |
599 | // Join related table | - |
600 | const QString tblexpr = Sql::concat(relation.tableName(), relTableAlias); executed (the execution status of this line is deduced): const QString tblexpr = Sql::concat(relation.tableName(), relTableAlias); | - |
601 | const QString relTableField = d->fullyQualifiedFieldName(relTableAlias, relation.indexColumn()); executed (the execution status of this line is deduced): const QString relTableField = d->fullyQualifiedFieldName(relTableAlias, relation.indexColumn()); | - |
602 | const QString cond = Sql::eq(tableField, relTableField); executed (the execution status of this line is deduced): const QString cond = Sql::eq(tableField, relTableField); | - |
603 | if (d->joinMode == QSqlRelationalTableModel::InnerJoin) { evaluated: d->joinMode == QSqlRelationalTableModel::InnerJoin yes Evaluation Count:73 | yes Evaluation Count:30 |
| 30-73 |
604 | // FIXME: InnerJoin code is known to be broken. | - |
605 | // Use LeftJoin mode if you want correct behavior. | - |
606 | from = Sql::comma(from, tblexpr); executed (the execution status of this line is deduced): from = Sql::comma(from, tblexpr); | - |
607 | conditions = Sql::et(conditions, cond); executed (the execution status of this line is deduced): conditions = Sql::et(conditions, cond); | - |
608 | } else { executed: } Execution Count:73 | 73 |
609 | from = Sql::concat(from, Sql::leftJoin(tblexpr)); executed (the execution status of this line is deduced): from = Sql::concat(from, Sql::leftJoin(tblexpr)); | - |
610 | from = Sql::concat(from, Sql::on(cond)); executed (the execution status of this line is deduced): from = Sql::concat(from, Sql::on(cond)); | - |
611 | } executed: } Execution Count:30 | 30 |
612 | } else { | - |
613 | fList = Sql::comma(fList, tableField); executed (the execution status of this line is deduced): fList = Sql::comma(fList, tableField); | - |
614 | } executed: } Execution Count:199 | 199 |
615 | } | - |
616 | | - |
617 | if (fList.isEmpty()) partially evaluated: fList.isEmpty() no Evaluation Count:0 | yes Evaluation Count:84 |
| 0-84 |
618 | return QString(); never executed: return QString(); | 0 |
619 | | - |
620 | const QString stmt = Sql::concat(Sql::select(fList), from); executed (the execution status of this line is deduced): const QString stmt = Sql::concat(Sql::select(fList), from); | - |
621 | const QString where = Sql::where(Sql::et(Sql::paren(conditions), Sql::paren(filter()))); executed (the execution status of this line is deduced): const QString where = Sql::where(Sql::et(Sql::paren(conditions), Sql::paren(filter()))); | - |
622 | return Sql::concat(Sql::concat(stmt, where), orderByClause()); executed: return Sql::concat(Sql::concat(stmt, where), orderByClause()); Execution Count:84 | 84 |
623 | } | - |
624 | | - |
625 | /*! | - |
626 | Returns a QSqlTableModel object for accessing the table for which | - |
627 | \a column is a foreign key, or 0 if there is no relation for the | - |
628 | given \a column. | - |
629 | | - |
630 | The returned object is owned by the QSqlRelationalTableModel. | - |
631 | | - |
632 | \sa setRelation(), relation() | - |
633 | */ | - |
634 | QSqlTableModel *QSqlRelationalTableModel::relationModel(int column) const | - |
635 | { | - |
636 | Q_D(const QSqlRelationalTableModel); executed (the execution status of this line is deduced): const QSqlRelationalTableModelPrivate * const d = d_func(); | - |
637 | 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 |
638 | return 0; executed: return 0; Execution Count:4 | 4 |
639 | | - |
640 | QRelation &relation = const_cast<QSqlRelationalTableModelPrivate *>(d)->relations[column]; executed (the execution status of this line is deduced): QRelation &relation = const_cast<QSqlRelationalTableModelPrivate *>(d)->relations[column]; | - |
641 | if (!relation.isValid()) evaluated: !relation.isValid() yes Evaluation Count:6 | yes Evaluation Count:10 |
| 6-10 |
642 | return 0; executed: return 0; Execution Count:6 | 6 |
643 | | - |
644 | if (!relation.model) evaluated: !relation.model yes Evaluation Count:3 | yes Evaluation Count:7 |
| 3-7 |
645 | relation.populateModel(); executed: relation.populateModel(); Execution Count:3 | 3 |
646 | return relation.model; executed: return relation.model; Execution Count:10 | 10 |
647 | } | - |
648 | | - |
649 | /*! | - |
650 | \reimp | - |
651 | */ | - |
652 | void QSqlRelationalTableModel::revertRow(int row) | - |
653 | { | - |
654 | QSqlTableModel::revertRow(row); executed (the execution status of this line is deduced): QSqlTableModel::revertRow(row); | - |
655 | } executed: } Execution Count:19 | 19 |
656 | | - |
657 | /*! | - |
658 | \reimp | - |
659 | */ | - |
660 | void QSqlRelationalTableModel::clear() | - |
661 | { | - |
662 | Q_D(QSqlRelationalTableModel); executed (the execution status of this line is deduced): QSqlRelationalTableModelPrivate * const d = d_func(); | - |
663 | d->clearChanges(); executed (the execution status of this line is deduced): d->clearChanges(); | - |
664 | d->relations.clear(); executed (the execution status of this line is deduced): d->relations.clear(); | - |
665 | QSqlTableModel::clear(); executed (the execution status of this line is deduced): QSqlTableModel::clear(); | - |
666 | } executed: } Execution Count:32 | 32 |
667 | | - |
668 | | - |
669 | /*! \enum QSqlRelationalTableModel::JoinMode | - |
670 | | - |
671 | \value InnerJoin - Inner join mode, return rows when there is at least one match in both tables. | - |
672 | \value LeftJoin - Left join mode, returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2). | - |
673 | | - |
674 | \sa QSqlRelationalTableModel::setJoinMode | - |
675 | \since 4.8 | - |
676 | */ | - |
677 | | - |
678 | /*! | - |
679 | Sets the SQL \a joinMode to show or hide rows with NULL foreign keys. | - |
680 | In InnerJoin mode (the default) these rows will not be shown: use the | - |
681 | LeftJoin mode if you want to show them. | - |
682 | | - |
683 | \sa QSqlRelationalTableModel::JoinMode | - |
684 | \since 4.8 | - |
685 | */ | - |
686 | void QSqlRelationalTableModel::setJoinMode( QSqlRelationalTableModel::JoinMode joinMode ) | - |
687 | { | - |
688 | Q_D(QSqlRelationalTableModel); executed (the execution status of this line is deduced): QSqlRelationalTableModelPrivate * const d = d_func(); | - |
689 | d->joinMode = joinMode; executed (the execution status of this line is deduced): d->joinMode = joinMode; | - |
690 | } executed: } Execution Count:23 | 23 |
691 | /*! | - |
692 | \reimp | - |
693 | */ | - |
694 | bool QSqlRelationalTableModel::select() | - |
695 | { | - |
696 | return QSqlTableModel::select(); executed: return QSqlTableModel::select(); Execution Count:74 | 74 |
697 | } | - |
698 | | - |
699 | /*! | - |
700 | \reimp | - |
701 | */ | - |
702 | void QSqlRelationalTableModel::setTable(const QString &table) | - |
703 | { | - |
704 | Q_D(QSqlRelationalTableModel); executed (the execution status of this line is deduced): QSqlRelationalTableModelPrivate * const d = d_func(); | - |
705 | | - |
706 | // memorize the table before applying the relations | - |
707 | d->baseRec = d->db.record(table); executed (the execution status of this line is deduced): d->baseRec = d->db.record(table); | - |
708 | | - |
709 | QSqlTableModel::setTable(table); executed (the execution status of this line is deduced): QSqlTableModel::setTable(table); | - |
710 | } executed: } Execution Count:32 | 32 |
711 | | - |
712 | /*! \internal | - |
713 | */ | - |
714 | void QSqlRelationalTableModelPrivate::translateFieldNames(QSqlRecord &values) const | - |
715 | { | - |
716 | for (int i = 0; i < values.count(); ++i) { evaluated: i < values.count() yes Evaluation Count:93 | yes Evaluation Count:26 |
| 26-93 |
717 | if (relations.value(i).isValid()) { evaluated: relations.value(i).isValid() yes Evaluation Count:34 | yes Evaluation Count:59 |
| 34-59 |
718 | QVariant v = values.value(i); executed (the execution status of this line is deduced): QVariant v = values.value(i); | - |
719 | bool gen = values.isGenerated(i); executed (the execution status of this line is deduced): bool gen = values.isGenerated(i); | - |
720 | values.replace(i, baseRec.field(i)); executed (the execution status of this line is deduced): values.replace(i, baseRec.field(i)); | - |
721 | values.setValue(i, v); executed (the execution status of this line is deduced): values.setValue(i, v); | - |
722 | values.setGenerated(i, gen); executed (the execution status of this line is deduced): values.setGenerated(i, gen); | - |
723 | } executed: } Execution Count:34 | 34 |
724 | } executed: } Execution Count:93 | 93 |
725 | } executed: } Execution Count:26 | 26 |
726 | | - |
727 | /*! | - |
728 | \reimp | - |
729 | */ | - |
730 | bool QSqlRelationalTableModel::updateRowInTable(int row, const QSqlRecord &values) | - |
731 | { | - |
732 | Q_D(QSqlRelationalTableModel); executed (the execution status of this line is deduced): QSqlRelationalTableModelPrivate * const d = d_func(); | - |
733 | | - |
734 | QSqlRecord rec = values; executed (the execution status of this line is deduced): QSqlRecord rec = values; | - |
735 | d->translateFieldNames(rec); executed (the execution status of this line is deduced): d->translateFieldNames(rec); | - |
736 | | - |
737 | return QSqlTableModel::updateRowInTable(row, rec); executed: return QSqlTableModel::updateRowInTable(row, rec); Execution Count:19 | 19 |
738 | } | - |
739 | | - |
740 | /*! | - |
741 | \reimp | - |
742 | */ | - |
743 | bool QSqlRelationalTableModel::insertRowIntoTable(const QSqlRecord &values) | - |
744 | { | - |
745 | Q_D(QSqlRelationalTableModel); executed (the execution status of this line is deduced): QSqlRelationalTableModelPrivate * const d = d_func(); | - |
746 | | - |
747 | QSqlRecord rec = values; executed (the execution status of this line is deduced): QSqlRecord rec = values; | - |
748 | d->translateFieldNames(rec); executed (the execution status of this line is deduced): d->translateFieldNames(rec); | - |
749 | | - |
750 | return QSqlTableModel::insertRowIntoTable(rec); executed: return QSqlTableModel::insertRowIntoTable(rec); Execution Count:7 | 7 |
751 | } | - |
752 | | - |
753 | /*! | - |
754 | \reimp | - |
755 | */ | - |
756 | QString QSqlRelationalTableModel::orderByClause() const | - |
757 | { | - |
758 | Q_D(const QSqlRelationalTableModel); executed (the execution status of this line is deduced): const QSqlRelationalTableModelPrivate * const d = d_func(); | - |
759 | | - |
760 | const QSqlRelation rel = d->relations.value(d->sortColumn).rel; executed (the execution status of this line is deduced): const QSqlRelation rel = d->relations.value(d->sortColumn).rel; | - |
761 | if (!rel.isValid()) evaluated: !rel.isValid() yes Evaluation Count:85 | yes Evaluation Count:4 |
| 4-85 |
762 | return QSqlTableModel::orderByClause(); executed: return QSqlTableModel::orderByClause(); Execution Count:85 | 85 |
763 | | - |
764 | QString f = d->fullyQualifiedFieldName(Sql::relTablePrefix(d->sortColumn), rel.displayColumn()); executed (the execution status of this line is deduced): QString f = d->fullyQualifiedFieldName(Sql::relTablePrefix(d->sortColumn), rel.displayColumn()); | - |
765 | 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 |
766 | return Sql::orderBy(f); executed: return Sql::orderBy(f); Execution Count:4 | 4 |
767 | } | - |
768 | | - |
769 | /*! | - |
770 | \reimp | - |
771 | */ | - |
772 | bool QSqlRelationalTableModel::removeColumns(int column, int count, const QModelIndex &parent) | - |
773 | { | - |
774 | Q_D(QSqlRelationalTableModel); executed (the execution status of this line is deduced): QSqlRelationalTableModelPrivate * const d = d_func(); | - |
775 | | - |
776 | 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 |
777 | return false; never executed: return false; | 0 |
778 | | - |
779 | for (int i = 0; i < count; ++i) { evaluated: i < count yes Evaluation Count:6 | yes Evaluation Count:4 |
| 4-6 |
780 | d->baseRec.remove(column); executed (the execution status of this line is deduced): d->baseRec.remove(column); | - |
781 | if (d->relations.count() > column) evaluated: d->relations.count() > column yes Evaluation Count:4 | yes Evaluation Count:2 |
| 2-4 |
782 | d->relations.remove(column); executed: d->relations.remove(column); Execution Count:4 | 4 |
783 | } executed: } Execution Count:6 | 6 |
784 | return QSqlTableModel::removeColumns(column, count, parent); executed: return QSqlTableModel::removeColumns(column, count, parent); Execution Count:4 | 4 |
785 | } | - |
786 | | - |
787 | QT_END_NAMESPACE | - |
788 | | - |
| | |