Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsqltablemodel_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QSQLTABLEMODEL_P_H
5#define QSQLTABLEMODEL_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of qsql*model.h . This header file may change from version to version
13// without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtSql/private/qtsqlglobal_p.h>
19#include "private/qsqlquerymodel_p.h"
20#include "QtSql/qsqlindex.h"
21#include "QtCore/qmap.h"
22
24
26
28{
29 Q_DECLARE_PUBLIC(QSqlTableModel)
30
31public:
33 : sortColumn(-1),
34 sortOrder(Qt::AscendingOrder),
35 strategy(QSqlTableModel::OnRowChange),
36 busyInsertingRows(false)
37 {}
39
40 void clear();
41 virtual void clearCache();
42 QSqlRecord record(const QList<QVariant> &values) const;
43
44 bool exec(const QString &stmt, bool prepStatement,
45 const QSqlRecord &rec, const QSqlRecord &whereValues);
46 virtual void revertCachedRow(int row);
47 virtual int nameToIndex(const QString &name) const;
48 QString strippedFieldName(const QString &name) const;
49 int insertCount(int maxRow = -1) const;
50 void initRecordAndPrimaryIndex();
51
53
56
59
60 QSqlQuery editQuery = { QSqlQuery(nullptr) };
65
66 enum Op { None, Insert, Update, Delete };
67
69 {
70 public:
71 inline ModifiedRow(Op o = None, const QSqlRecord &r = QSqlRecord())
72 : m_op(None), m_db_values(r), m_insert(o == Insert)
73 { setOp(o); }
74 inline Op op() const { return m_op; }
75 inline void setOp(Op o)
76 {
77 if (o == None)
78 m_submitted = true;
79 if (o == m_op)
80 return;
81 m_submitted = (o != Insert && o != Delete);
82 m_op = o;
83 m_rec = m_db_values;
84 setGenerated(m_rec, m_op == Delete);
85 }
86 inline const QSqlRecord &rec() const { return m_rec; }
87 inline QSqlRecord& recRef() { return m_rec; }
88 inline void setValue(int c, const QVariant &v)
89 {
90 m_submitted = false;
91 m_rec.setValue(c, v);
92 m_rec.setGenerated(c, true);
93 }
94 inline bool submitted() const { return m_submitted; }
95 inline void setSubmitted()
96 {
97 m_submitted = true;
98 setGenerated(m_rec, false);
99 if (m_op == Delete) {
100 m_rec.clearValues();
101 }
102 else {
103 m_op = Update;
104 m_db_values = m_rec;
105 setGenerated(m_db_values, true);
106 }
107 }
108 inline void refresh(bool exists, const QSqlRecord& newvals)
109 {
110 m_submitted = true;
111 if (exists) {
112 m_op = Update;
113 m_db_values = newvals;
114 m_rec = newvals;
115 setGenerated(m_rec, false);
116 } else {
117 m_op = Delete;
118 m_rec.clear();
119 m_db_values.clear();
120 }
121 }
122 inline bool insert() const { return m_insert; }
123 inline void revert()
124 {
125 if (m_submitted)
126 return;
127 if (m_op == Delete)
128 m_op = Update;
129 m_rec = m_db_values;
130 setGenerated(m_rec, false);
131 m_submitted = true;
132 }
133 inline QSqlRecord primaryValues(const QSqlRecord& pi) const
134 {
135 if (m_op == None || m_op == Insert)
136 return QSqlRecord();
137
138 return m_db_values.keyValues(pi);
139 }
140 private:
141 inline static void setGenerated(QSqlRecord& r, bool g)
142 {
143 for (int i = r.count() - 1; i >= 0; --i)
144 r.setGenerated(i, g);
145 }
146 Op m_op;
147 QSqlRecord m_rec;
148 QSqlRecord m_db_values;
149 bool m_submitted;
150 bool m_insert;
151 };
152
153 typedef QMap<int, ModifiedRow> CacheMap;
155};
156
158{
159public:
160};
161
163
164#endif // QSQLTABLEMODEL_P_H
The QSqlDatabase class handles a connection to a database.
The QSqlIndex class provides functions to manipulate and describe database indexes.
Definition qsqlindex.h:18
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition qsqlquery.h:24
The QSqlRecord class encapsulates a database record.
Definition qsqlrecord.h:20
const QSqlRecord & rec() const
QSqlRecord primaryValues(const QSqlRecord &pi) const
void setValue(int c, const QVariant &v)
void refresh(bool exists, const QSqlRecord &newvals)
ModifiedRow(Op o=None, const QSqlRecord &r=QSqlRecord())
QMap< int, ModifiedRow > CacheMap
QSqlTableModel::EditStrategy strategy
The QSqlTableModel class provides an editable data model for a single database table.
EditStrategy
This enum type describes which strategy to choose when editing values in the database.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
b clear()
Combined button and popup list for selecting options.
Definition qcompare.h:63
SortOrder
Definition qnamespace.h:121
@ None
Definition qhash.cpp:531
GLenum GLsizei GLsizei GLint * values
[15]
GLsizei const GLfloat * v
[13]
GLboolean r
[2]
GLboolean GLboolean g
GLuint name
const GLubyte * c
GLenum GLenum GLsizei void * row
#define Q_AUTOTEST_EXPORT
#define QT_REQUIRE_CONFIG(feature)
MyRecord record(int row) const
[0]
dialog exec()