summaryrefslogtreecommitdiffstats
path: root/src/sql/models
diff options
context:
space:
mode:
Diffstat (limited to 'src/sql/models')
-rw-r--r--src/sql/models/qsqlquerymodel.cpp86
-rw-r--r--src/sql/models/qsqlquerymodel.h47
-rw-r--r--src/sql/models/qsqlquerymodel_p.h70
-rw-r--r--src/sql/models/qsqlrelationaldelegate.cpp40
-rw-r--r--src/sql/models/qsqlrelationaldelegate.h40
-rw-r--r--src/sql/models/qsqlrelationaltablemodel.cpp99
-rw-r--r--src/sql/models/qsqlrelationaltablemodel.h46
-rw-r--r--src/sql/models/qsqltablemodel.cpp106
-rw-r--r--src/sql/models/qsqltablemodel.h42
-rw-r--r--src/sql/models/qsqltablemodel_p.h40
10 files changed, 134 insertions, 482 deletions
diff --git a/src/sql/models/qsqlquerymodel.cpp b/src/sql/models/qsqlquerymodel.cpp
index 6d4e2c09c1..6f91fb9739 100644
--- a/src/sql/models/qsqlquerymodel.cpp
+++ b/src/sql/models/qsqlquerymodel.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSql module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsqlquerymodel.h"
#include "qsqlquerymodel_p.h"
@@ -46,6 +10,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
#define QSQL_PREFETCH 255
void QSqlQueryModelPrivate::prefetch(int limit)
@@ -173,8 +139,6 @@ QSqlQueryModel::~QSqlQueryModel()
}
/*!
- \since 4.1
-
Fetches more rows from a database.
This only affects databases that don't report back the size of a query
(see QSqlDriver::hasFeature()).
@@ -196,8 +160,6 @@ void QSqlQueryModel::fetchMore(const QModelIndex &parent)
}
/*!
- \since 4.1
-
Returns \c true if it is possible to read more rows from the database.
This only affects databases that don't report back the size of a query
(see QSqlDriver::hasFeature()).
@@ -329,7 +291,6 @@ void QSqlQueryModel::endResetModel()
}
/*! \fn int QSqlQueryModel::rowCount(const QModelIndex &parent) const
- \since 4.1
If the database supports returning the size of a query
(see QSqlDriver::hasFeature()), the number of rows of the current
@@ -418,6 +379,18 @@ void QSqlQueryModel::queryChange()
// do nothing
}
+#if QT_DEPRECATED_SINCE(6, 2)
+/*!
+ \deprecated [6.2] Use the \c{setQuery(QSqlQuery &&query)} overload instead.
+ \overload
+*/
+void QSqlQueryModel::setQuery(const QSqlQuery &query)
+{
+ QT_IGNORE_DEPRECATIONS(QSqlQuery copy = query;)
+ setQuery(std::move(copy));
+}
+#endif // QT_DEPRECATED_SINCE(6, 2)
+
/*!
Resets the model and sets the data provider to be the given \a
query. Note that the query must be active and must not be
@@ -428,9 +401,11 @@ void QSqlQueryModel::queryChange()
\note Calling setQuery() will remove any inserted columns.
+ \since 6.2
+
\sa query(), QSqlQuery::isActive(), QSqlQuery::setForwardOnly(), lastError()
*/
-void QSqlQueryModel::setQuery(const QSqlQuery &query)
+void QSqlQueryModel::setQuery(QSqlQuery &&query)
{
Q_D(QSqlQueryModel);
beginResetModel();
@@ -443,25 +418,24 @@ void QSqlQueryModel::setQuery(const QSqlQuery &query)
d->bottom = QModelIndex();
d->error = QSqlError();
- d->query = query;
+ d->query = std::move(query);
d->rec = newRec;
d->atEnd = true;
- if (query.isForwardOnly()) {
- d->error = QSqlError(QLatin1String("Forward-only queries "
- "cannot be used in a data model"),
+ if (d->query.isForwardOnly()) {
+ d->error = QSqlError("Forward-only queries cannot be used in a data model"_L1,
QString(), QSqlError::ConnectionError);
endResetModel();
return;
}
- if (!query.isActive()) {
- d->error = query.lastError();
+ if (!d->query.isActive()) {
+ d->error = d->query.lastError();
endResetModel();
return;
}
- if (query.driver()->hasFeature(QSqlDriver::QuerySize) && d->query.size() > 0) {
+ if (d->query.driver()->hasFeature(QSqlDriver::QuerySize) && d->query.size() > 0) {
d->bottom = createIndex(d->query.size() - 1, d->rec.count() - 1);
} else {
d->bottom = createIndex(-1, d->rec.count() - 1);
@@ -541,11 +515,11 @@ bool QSqlQueryModel::setHeaderData(int section, Qt::Orientation orientation,
}
/*!
- Returns the QSqlQuery associated with this model.
+ Returns a reference to the const QSqlQuery object associated with this model.
\sa setQuery()
*/
-QSqlQuery QSqlQueryModel::query() const
+const QSqlQuery &QSqlQueryModel::query(QT6_IMPL_NEW_OVERLOAD) const
{
Q_D(const QSqlQueryModel);
return d->query;
@@ -644,7 +618,7 @@ bool QSqlQueryModel::insertColumns(int column, int count, const QModelIndex &par
d->colOffsets.append(nVal);
Q_ASSERT(d->colOffsets.size() >= d->rec.count());
}
- for (int i = column + 1; i < d->colOffsets.count(); ++i)
+ for (int i = column + 1; i < d->colOffsets.size(); ++i)
++d->colOffsets[i];
}
endInsertColumns();
@@ -673,7 +647,7 @@ bool QSqlQueryModel::removeColumns(int column, int count, const QModelIndex &par
int i;
for (i = 0; i < count; ++i)
d->rec.remove(column);
- for (i = column; i < d->colOffsets.count(); ++i)
+ for (i = column; i < d->colOffsets.size(); ++i)
d->colOffsets[i] -= count;
endRemoveColumns();
@@ -702,3 +676,5 @@ QModelIndex QSqlQueryModel::indexInQuery(const QModelIndex &item) const
}
QT_END_NAMESPACE
+
+#include "moc_qsqlquerymodel.cpp"
diff --git a/src/sql/models/qsqlquerymodel.h b/src/sql/models/qsqlquerymodel.h
index 427b369ae2..73308b79e8 100644
--- a/src/sql/models/qsqlquerymodel.h
+++ b/src/sql/models/qsqlquerymodel.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSql module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSQLQUERYMODEL_H
#define QSQLQUERYMODEL_H
@@ -76,9 +40,16 @@ public:
bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
+#if QT_DEPRECATED_SINCE(6, 2)
+ QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Pass it by move instead.")
void setQuery(const QSqlQuery &query);
+#endif
+ void setQuery(QSqlQuery &&query);
void setQuery(const QString &query, const QSqlDatabase &db = QSqlDatabase());
+#if QT_SQL_REMOVED_SINCE(6, 5)
QSqlQuery query() const;
+#endif
+ const QSqlQuery &query(QT6_DECL_NEW_OVERLOAD) const;
virtual void clear();
diff --git a/src/sql/models/qsqlquerymodel_p.h b/src/sql/models/qsqlquerymodel_p.h
index 3772847eb1..a4c408d081 100644
--- a/src/sql/models/qsqlquerymodel_p.h
+++ b/src/sql/models/qsqlquerymodel_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSql module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSQLQUERYMODEL_P_H
#define QSQLQUERYMODEL_P_H
@@ -90,22 +54,22 @@ class QSqlQueryModelSql
{
public:
// SQL keywords
- inline const static QLatin1String as() { return QLatin1String("AS"); }
- inline const static QLatin1String asc() { return QLatin1String("ASC"); }
- inline const static QLatin1String comma() { return QLatin1String(","); }
- inline const static QLatin1String desc() { return QLatin1String("DESC"); }
- inline const static QLatin1String eq() { return QLatin1String("="); }
+ inline const static QLatin1StringView as() { return QLatin1StringView("AS"); }
+ inline const static QLatin1StringView asc() { return QLatin1StringView("ASC"); }
+ inline const static QLatin1StringView comma() { return QLatin1StringView(","); }
+ inline const static QLatin1StringView desc() { return QLatin1StringView("DESC"); }
+ inline const static QLatin1StringView eq() { return QLatin1StringView("="); }
// "and" is a C++ keyword
- inline const static QLatin1String et() { return QLatin1String("AND"); }
- inline const static QLatin1String from() { return QLatin1String("FROM"); }
- inline const static QLatin1String leftJoin() { return QLatin1String("LEFT JOIN"); }
- inline const static QLatin1String on() { return QLatin1String("ON"); }
- inline const static QLatin1String orderBy() { return QLatin1String("ORDER BY"); }
- inline const static QLatin1String parenClose() { return QLatin1String(")"); }
- inline const static QLatin1String parenOpen() { return QLatin1String("("); }
- inline const static QLatin1String select() { return QLatin1String("SELECT"); }
- inline const static QLatin1String sp() { return QLatin1String(" "); }
- inline const static QLatin1String where() { return QLatin1String("WHERE"); }
+ inline const static QLatin1StringView et() { return QLatin1StringView("AND"); }
+ inline const static QLatin1StringView from() { return QLatin1StringView("FROM"); }
+ inline const static QLatin1StringView leftJoin() { return QLatin1StringView("LEFT JOIN"); }
+ inline const static QLatin1StringView on() { return QLatin1StringView("ON"); }
+ inline const static QLatin1StringView orderBy() { return QLatin1StringView("ORDER BY"); }
+ inline const static QLatin1StringView parenClose() { return QLatin1StringView(")"); }
+ inline const static QLatin1StringView parenOpen() { return QLatin1StringView("("); }
+ inline const static QLatin1StringView select() { return QLatin1StringView("SELECT"); }
+ inline const static QLatin1StringView sp() { return QLatin1StringView(" "); }
+ inline const static QLatin1StringView where() { return QLatin1StringView("WHERE"); }
// Build expressions based on key words
inline const static QString as(const QString &a, const QString &b) { return b.isEmpty() ? a : concat(concat(a, as()), b); }
diff --git a/src/sql/models/qsqlrelationaldelegate.cpp b/src/sql/models/qsqlrelationaldelegate.cpp
index f01548baf9..ee9bc668b6 100644
--- a/src/sql/models/qsqlrelationaldelegate.cpp
+++ b/src/sql/models/qsqlrelationaldelegate.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSql module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qglobal.h"
diff --git a/src/sql/models/qsqlrelationaldelegate.h b/src/sql/models/qsqlrelationaldelegate.h
index 130c82868e..35c534eae4 100644
--- a/src/sql/models/qsqlrelationaldelegate.h
+++ b/src/sql/models/qsqlrelationaldelegate.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSql module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSQLRELATIONALDELEGATE_H
#define QSQLRELATIONALDELEGATE_H
diff --git a/src/sql/models/qsqlrelationaltablemodel.cpp b/src/sql/models/qsqlrelationaltablemodel.cpp
index 8c787eab0c..c086d88ffe 100644
--- a/src/sql/models/qsqlrelationaltablemodel.cpp
+++ b/src/sql/models/qsqlrelationaltablemodel.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSql module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsqlrelationaltablemodel.h"
@@ -55,13 +19,15 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
class QSqlRelationalTableModelSql: public QSqlTableModelSql
{
public:
- inline const static QString relTablePrefix(int i) { return QString::number(i).prepend(QLatin1String("relTblAl_")); }
+ inline const static QString relTablePrefix(int i) { return QString::number(i).prepend("relTblAl_"_L1); }
};
-typedef QSqlRelationalTableModelSql Sql;
+using SqlrTm = QSqlRelationalTableModelSql;
/*!
\class QSqlRelation
@@ -287,7 +253,7 @@ public:
void QSqlRelationalTableModelPrivate::clearChanges()
{
- for (int i = 0; i < relations.count(); ++i) {
+ for (int i = 0; i < relations.size(); ++i) {
QRelation &rel = relations[i];
rel.clear();
}
@@ -311,7 +277,7 @@ int QSqlRelationalTableModelPrivate::nameToIndex(const QString &name) const
void QSqlRelationalTableModelPrivate::clearCache()
{
- for (int i = 0; i < relations.count(); ++i)
+ for (int i = 0; i < relations.size(); ++i)
relations[i].clearDictionary();
QSqlTableModelPrivate::clearCache();
@@ -429,7 +395,7 @@ QVariant QSqlRelationalTableModel::data(const QModelIndex &index, int role) cons
{
Q_D(const QSqlRelationalTableModel);
- if (role == Qt::DisplayRole && index.column() >= 0 && index.column() < d->relations.count() &&
+ if (role == Qt::DisplayRole && index.column() >= 0 && index.column() < d->relations.size() &&
d->relations.value(index.column()).isValid()) {
QRelation &relation = d->relations[index.column()];
if (!relation.isDictionaryInitialized())
@@ -472,7 +438,7 @@ bool QSqlRelationalTableModel::setData(const QModelIndex &index, const QVariant
int role)
{
Q_D(QSqlRelationalTableModel);
- if ( role == Qt::EditRole && index.column() > 0 && index.column() < d->relations.count()
+ if ( role == Qt::EditRole && index.column() > 0 && index.column() < d->relations.size()
&& d->relations.value(index.column()).isValid()) {
QRelation &relation = d->relations[index.column()];
if (!relation.isDictionaryInitialized())
@@ -528,7 +494,7 @@ QString QSqlRelationalTableModelPrivate::fullyQualifiedFieldName(const QString &
{
QString ret;
ret.reserve(tableName.size() + fieldName.size() + 1);
- ret.append(tableName).append(QLatin1Char('.')).append(fieldName);
+ ret.append(tableName).append(u'.').append(fieldName);
return ret;
}
@@ -574,12 +540,12 @@ QString QSqlRelationalTableModel::selectStatement() const
QString fList;
QString conditions;
- QString from = Sql::from(tableName());
+ QString from = SqlrTm::from(tableName());
for (int i = 0; i < d->baseRec.count(); ++i) {
QSqlRelation relation = d->relations.value(i).rel;
const QString tableField = d->fullyQualifiedFieldName(tableName(), d->db.driver()->escapeIdentifier(d->baseRec.fieldName(i), QSqlDriver::FieldName));
if (relation.isValid()) {
- const QString relTableAlias = Sql::relTablePrefix(i);
+ const QString relTableAlias = SqlrTm::relTablePrefix(i);
QString displayTableField = d->fullyQualifiedFieldName(relTableAlias, relation.displayColumn());
// Duplicate field names must be aliased
@@ -593,36 +559,37 @@ QString QSqlRelationalTableModel::selectStatement() const
QString alias = QString::fromLatin1("%1_%2_%3")
.arg(relTableName, displayColumn, QString::number(fieldNames.value(fieldList[i])));
alias.truncate(d->db.driver()->maximumIdentifierLength(QSqlDriver::FieldName));
- displayTableField = Sql::as(displayTableField, alias);
+ alias = d->db.driver()->escapeIdentifier(alias, QSqlDriver::FieldName);
+ displayTableField = SqlrTm::as(displayTableField, alias);
--fieldNames[fieldList[i]];
}
- fList = Sql::comma(fList, displayTableField);
+ fList = SqlrTm::comma(fList, displayTableField);
// Join related table
- const QString tblexpr = Sql::concat(relation.tableName(), relTableAlias);
+ const QString tblexpr = SqlrTm::concat(relation.tableName(), relTableAlias);
const QString relTableField = d->fullyQualifiedFieldName(relTableAlias, relation.indexColumn());
- const QString cond = Sql::eq(tableField, relTableField);
+ const QString cond = SqlrTm::eq(tableField, relTableField);
if (d->joinMode == QSqlRelationalTableModel::InnerJoin) {
// FIXME: InnerJoin code is known to be broken.
// Use LeftJoin mode if you want correct behavior.
- from = Sql::comma(from, tblexpr);
- conditions = Sql::et(conditions, cond);
+ from = SqlrTm::comma(from, tblexpr);
+ conditions = SqlrTm::et(conditions, cond);
} else {
- from = Sql::concat(from, Sql::leftJoin(tblexpr));
- from = Sql::concat(from, Sql::on(cond));
+ from = SqlrTm::concat(from, SqlrTm::leftJoin(tblexpr));
+ from = SqlrTm::concat(from, SqlrTm::on(cond));
}
} else {
- fList = Sql::comma(fList, tableField);
+ fList = SqlrTm::comma(fList, tableField);
}
}
if (fList.isEmpty())
return QString();
- const QString stmt = Sql::concat(Sql::select(fList), from);
- const QString where = Sql::where(Sql::et(Sql::paren(conditions), Sql::paren(filter())));
- return Sql::concat(Sql::concat(stmt, where), orderByClause());
+ const QString stmt = SqlrTm::concat(SqlrTm::select(fList), from);
+ const QString where = SqlrTm::where(SqlrTm::et(SqlrTm::paren(conditions), SqlrTm::paren(filter())));
+ return SqlrTm::concat(SqlrTm::concat(stmt, where), orderByClause());
}
/*!
@@ -637,7 +604,7 @@ QString QSqlRelationalTableModel::selectStatement() const
QSqlTableModel *QSqlRelationalTableModel::relationModel(int column) const
{
Q_D(const QSqlRelationalTableModel);
- if (column < 0 || column >= d->relations.count())
+ if (column < 0 || column >= d->relations.size())
return nullptr;
QRelation &relation = const_cast<QSqlRelationalTableModelPrivate *>(d)->relations[column];
@@ -677,7 +644,6 @@ void QSqlRelationalTableModel::clear()
\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).
\sa QSqlRelationalTableModel::setJoinMode()
- \since 4.8
*/
/*!
@@ -686,7 +652,6 @@ void QSqlRelationalTableModel::clear()
LeftJoin mode if you want to show them.
\sa QSqlRelationalTableModel::JoinMode
- \since 4.8
*/
void QSqlRelationalTableModel::setJoinMode( QSqlRelationalTableModel::JoinMode joinMode )
{
@@ -766,9 +731,9 @@ QString QSqlRelationalTableModel::orderByClause() const
if (!rel.isValid())
return QSqlTableModel::orderByClause();
- QString f = d->fullyQualifiedFieldName(Sql::relTablePrefix(d->sortColumn), rel.displayColumn());
- f = d->sortOrder == Qt::AscendingOrder ? Sql::asc(f) : Sql::desc(f);
- return Sql::orderBy(f);
+ QString f = d->fullyQualifiedFieldName(SqlrTm::relTablePrefix(d->sortColumn), rel.displayColumn());
+ f = d->sortOrder == Qt::AscendingOrder ? SqlrTm::asc(f) : SqlrTm::desc(f);
+ return SqlrTm::orderBy(f);
}
/*!
@@ -783,10 +748,12 @@ bool QSqlRelationalTableModel::removeColumns(int column, int count, const QModel
for (int i = 0; i < count; ++i) {
d->baseRec.remove(column);
- if (d->relations.count() > column)
+ if (d->relations.size() > column)
d->relations.remove(column);
}
return QSqlTableModel::removeColumns(column, count, parent);
}
QT_END_NAMESPACE
+
+#include "moc_qsqlrelationaltablemodel.cpp"
diff --git a/src/sql/models/qsqlrelationaltablemodel.h b/src/sql/models/qsqlrelationaltablemodel.h
index f9e3620eb6..814bae41bb 100644
--- a/src/sql/models/qsqlrelationaltablemodel.h
+++ b/src/sql/models/qsqlrelationaltablemodel.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSql module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSQLRELATIONALTABLEMODEL_H
#define QSQLRELATIONALTABLEMODEL_H
@@ -60,9 +24,9 @@ public:
void swap(QSqlRelation &other) noexcept
{
- qSwap(tName, other.tName);
- qSwap(iColumn, other.iColumn);
- qSwap(dColumn, other.dColumn);
+ tName.swap(other.tName);
+ iColumn.swap(other.iColumn);
+ dColumn.swap(other.dColumn);
}
inline QString tableName() const
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp
index 570101289c..265d7782a0 100644
--- a/src/sql/models/qsqltablemodel.cpp
+++ b/src/sql/models/qsqltablemodel.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSql module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsqltablemodel.h"
@@ -53,7 +17,9 @@
QT_BEGIN_NAMESPACE
-typedef QSqlTableModelSql Sql;
+using namespace Qt::StringLiterals;
+
+using SqlTm = QSqlTableModelSql;
QSqlTableModelPrivate::~QSqlTableModelPrivate()
{
@@ -66,7 +32,7 @@ QSqlTableModelPrivate::~QSqlTableModelPrivate()
QSqlRecord QSqlTableModelPrivate::record(const QList<QVariant> &values) const
{
QSqlRecord r = rec;
- for (int i = 0; i < r.count() && i < values.count(); ++i)
+ for (int i = 0; i < r.count() && i < values.size(); ++i)
r.setValue(i, values.at(i));
return r;
}
@@ -239,7 +205,7 @@ bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement,
want to resolve foreign keys.
\sa QSqlRelationalTableModel, QSqlQuery, {Model/View Programming},
- {Table Model Example}, {Cached Table Example}
+ {Table Model Example}, {Cached SQL Table}
*/
/*!
@@ -333,7 +299,7 @@ void QSqlTableModel::setTable(const QString &tableName)
d->initRecordAndPrimaryIndex();
if (d->rec.count() == 0)
- d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(),
+ d->error = QSqlError("Unable to find table "_L1 + d->tableName, QString(),
QSqlError::StatementError);
// Remember the auto index column if there is one now.
@@ -376,10 +342,9 @@ bool QSqlTableModel::select()
d->clearCache();
- QSqlQuery qu(query, d->db);
- setQuery(qu);
+ this->QSqlQueryModel::setQuery(query, d->db);
- if (!qu.isActive() || lastError().isValid()) {
+ if (!d->query.isActive() || lastError().isValid()) {
// something went wrong - revert to non-select state
d->initRecordAndPrimaryIndex();
endResetModel();
@@ -414,9 +379,9 @@ bool QSqlTableModel::selectRow(int row)
d->tableName,
primaryValues(row),
false);
- static const QString wh = Sql::where() + Sql::sp();
+ static const QString wh = SqlTm::where() + SqlTm::sp();
if (d->filter.startsWith(wh, Qt::CaseInsensitive))
- d->filter.remove(0, wh.length());
+ d->filter.remove(0, wh.size());
QString stmt;
@@ -493,9 +458,9 @@ QVariant QSqlTableModel::headerData(int section, Qt::Orientation orientation, in
if (orientation == Qt::Vertical && role == Qt::DisplayRole) {
const QSqlTableModelPrivate::Op op = d->cache.value(section).op();
if (op == QSqlTableModelPrivate::Insert)
- return QLatin1String("*");
+ return "*"_L1;
else if (op == QSqlTableModelPrivate::Delete)
- return QLatin1String("!");
+ return "!"_L1;
}
return QSqlQueryModel::headerData(section, orientation, role);
}
@@ -616,18 +581,6 @@ bool QSqlTableModel::clearItemData(const QModelIndex &index)
}
/*!
- This function simply calls QSqlQueryModel::setQuery(\a query).
- You should normally not call it on a QSqlTableModel. Instead, use
- setTable(), setSort(), setFilter(), etc., to set up the query.
-
- \sa selectStatement()
-*/
-void QSqlTableModel::setQuery(const QSqlQuery &query)
-{
- QSqlQueryModel::setQuery(query);
-}
-
-/*!
Updates the given \a row in the currently active database table
with the specified \a values. Returns \c true if successful; otherwise
returns \c false.
@@ -657,12 +610,11 @@ bool QSqlTableModel::updateRowInTable(int row, const QSqlRecord &values)
whereValues, prepStatement);
if (stmt.isEmpty() || where.isEmpty() || row < 0 || row >= rowCount()) {
- d->error = QSqlError(QLatin1String("No Fields to update"), QString(),
- QSqlError::StatementError);
+ d->error = QSqlError("No Fields to update"_L1, QString(), QSqlError::StatementError);
return false;
}
- return d->exec(Sql::concat(stmt, where), prepStatement, rec, whereValues);
+ return d->exec(SqlTm::concat(stmt, where), prepStatement, rec, whereValues);
}
@@ -690,8 +642,7 @@ bool QSqlTableModel::insertRowIntoTable(const QSqlRecord &values)
rec, prepStatement);
if (stmt.isEmpty()) {
- d->error = QSqlError(QLatin1String("No Fields to update"), QString(),
- QSqlError::StatementError);
+ d->error = QSqlError("No Fields to update"_L1, QString(), QSqlError::StatementError);
return false;
}
@@ -727,12 +678,11 @@ bool QSqlTableModel::deleteRowFromTable(int row)
prepStatement);
if (stmt.isEmpty() || where.isEmpty()) {
- d->error = QSqlError(QLatin1String("Unable to delete row"), QString(),
- QSqlError::StatementError);
+ d->error = QSqlError("Unable to delete row"_L1, QString(), QSqlError::StatementError);
return false;
}
- return d->exec(Sql::concat(stmt, where), prepStatement, QSqlRecord() /* no new values */, whereValues);
+ return d->exec(SqlTm::concat(stmt, where), prepStatement, QSqlRecord() /* no new values */, whereValues);
}
/*!
@@ -1001,10 +951,11 @@ QString QSqlTableModel::orderByClause() const
//we can safely escape the field because it would have been obtained from the database
//and have the correct case
- QString field = d->tableName + QLatin1Char('.')
+ QString field = d->db.driver()->escapeIdentifier(d->tableName, QSqlDriver::TableName)
+ + u'.'
+ d->db.driver()->escapeIdentifier(f.name(), QSqlDriver::FieldName);
- field = d->sortOrder == Qt::AscendingOrder ? Sql::asc(field) : Sql::desc(field);
- return Sql::orderBy(field);
+ field = d->sortOrder == Qt::AscendingOrder ? SqlTm::asc(field) : SqlTm::desc(field);
+ return SqlTm::orderBy(field);
}
/*!
@@ -1028,12 +979,11 @@ QString QSqlTableModel::selectStatement() const
{
Q_D(const QSqlTableModel);
if (d->tableName.isEmpty()) {
- d->error = QSqlError(QLatin1String("No table name given"), QString(),
- QSqlError::StatementError);
+ d->error = QSqlError("No table name given"_L1, QString(), QSqlError::StatementError);
return QString();
}
if (d->rec.isEmpty()) {
- d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(),
+ d->error = QSqlError("Unable to find table "_L1 + d->tableName, QString(),
QSqlError::StatementError);
return QString();
}
@@ -1043,11 +993,11 @@ QString QSqlTableModel::selectStatement() const
d->rec,
false);
if (stmt.isEmpty()) {
- d->error = QSqlError(QLatin1String("Unable to select fields from table ") + d->tableName,
+ d->error = QSqlError("Unable to select fields from table "_L1 + d->tableName,
QString(), QSqlError::StatementError);
return stmt;
}
- return Sql::concat(Sql::concat(stmt, Sql::where(d->filter)), orderByClause());
+ return SqlTm::concat(SqlTm::concat(stmt, SqlTm::where(d->filter)), orderByClause());
}
/*!
@@ -1465,3 +1415,5 @@ QSqlRecord QSqlTableModel::primaryValues(int row) const
}
QT_END_NAMESPACE
+
+#include "moc_qsqltablemodel.cpp"
diff --git a/src/sql/models/qsqltablemodel.h b/src/sql/models/qsqltablemodel.h
index 90cddd7b61..8af3f84c59 100644
--- a/src/sql/models/qsqltablemodel.h
+++ b/src/sql/models/qsqltablemodel.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSql module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSQLTABLEMODEL_H
#define QSQLTABLEMODEL_H
@@ -135,7 +99,9 @@ protected:
virtual QString selectStatement() const;
void setPrimaryKey(const QSqlIndex &key);
+#if QT_SQL_REMOVED_SINCE(6, 5)
void setQuery(const QSqlQuery &query);
+#endif
QModelIndex indexInQuery(const QModelIndex &item) const override;
QSqlRecord primaryValues(int row) const;
};
diff --git a/src/sql/models/qsqltablemodel_p.h b/src/sql/models/qsqltablemodel_p.h
index d585f71548..9c6425ded4 100644
--- a/src/sql/models/qsqltablemodel_p.h
+++ b/src/sql/models/qsqltablemodel_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSql module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSQLTABLEMODEL_P_H
#define QSQLTABLEMODEL_P_H