SQL: misc cleanup in QSqlRecord/QSqlField

Cleanup an unused function in QSqlRecordPrivate and use member
initializers for the ctors in QSqlRecord/QSqlField

Change-Id: I7d585e70c83373b3092e9f1425233af42b8c379d
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
Christian Ehrlicher 2022-12-21 17:35:35 +01:00
parent 8b0818235d
commit 5419faebde
2 changed files with 19 additions and 35 deletions

View File

@ -141,20 +141,20 @@ public:
setGenerated(), setReadOnly() setGenerated(), setReadOnly()
*/ */
QSqlField::QSqlField(const QString &fieldName, QMetaType type, const QString &table) QSqlField::QSqlField(const QString &fieldName, QMetaType type, const QString &table)
: val(QVariant(type, nullptr)),
d(new QSqlFieldPrivate(fieldName, type, table))
{ {
d = new QSqlFieldPrivate(fieldName, type, table);
val = QVariant(QMetaType(type), nullptr);
} }
/*! /*!
Constructs a copy of \a other. Constructs a copy of \a other.
*/ */
QSqlField::QSqlField(const QSqlField& other) QSqlField::QSqlField(const QSqlField &other)
: val(other.val),
d(other.d)
{ {
d = other.d;
d->ref.ref(); d->ref.ref();
val = other.val;
} }
/*! /*!

View File

@ -15,36 +15,21 @@ QT_BEGIN_NAMESPACE
class QSqlRecordPrivate class QSqlRecordPrivate
{ {
public: public:
QSqlRecordPrivate(); QSqlRecordPrivate() = default;
QSqlRecordPrivate(const QSqlRecordPrivate &other); QSqlRecordPrivate(const QSqlRecordPrivate &other)
: fields(other.fields)
{
}
inline bool contains(int index) { return index >= 0 && index < fields.size(); } inline bool contains(qsizetype index) const
QString createField(int index, const QString &prefix) const; {
return index >= 0 && index < fields.size();
}
QList<QSqlField> fields; QList<QSqlField> fields;
QAtomicInt ref; QAtomicInt ref{1};
}; };
QSqlRecordPrivate::QSqlRecordPrivate() : ref(1)
{
}
QSqlRecordPrivate::QSqlRecordPrivate(const QSqlRecordPrivate &other): fields(other.fields), ref(1)
{
}
/*! \internal
Just for compat
*/
QString QSqlRecordPrivate::createField(int index, const QString &prefix) const
{
QString f;
if (!prefix.isEmpty())
f = prefix + u'.';
f += fields.at(index).name();
return f;
}
/*! /*!
\class QSqlRecord \class QSqlRecord
\brief The QSqlRecord class encapsulates a database record. \brief The QSqlRecord class encapsulates a database record.
@ -86,8 +71,8 @@ QString QSqlRecordPrivate::createField(int index, const QString &prefix) const
*/ */
QSqlRecord::QSqlRecord() QSqlRecord::QSqlRecord()
: d(new QSqlRecordPrivate)
{ {
d = new QSqlRecordPrivate();
} }
/*! /*!
@ -98,8 +83,8 @@ QSqlRecord::QSqlRecord()
*/ */
QSqlRecord::QSqlRecord(const QSqlRecord& other) QSqlRecord::QSqlRecord(const QSqlRecord& other)
: d(other.d)
{ {
d = other.d;
d->ref.ref(); d->ref.ref();
} }
@ -337,9 +322,8 @@ bool QSqlRecord::contains(const QString& name) const
void QSqlRecord::clearValues() void QSqlRecord::clearValues()
{ {
detach(); detach();
int count = d->fields.size(); for (QSqlField &f : d->fields)
for (int i = 0; i < count; ++i) f.clear();
d->fields[i].clear();
} }
/*! /*!