diff options
Diffstat (limited to 'src/sql/models/qsqlquerymodel.cpp')
-rw-r--r-- | src/sql/models/qsqlquerymodel.cpp | 92 |
1 files changed, 34 insertions, 58 deletions
diff --git a/src/sql/models/qsqlquerymodel.cpp b/src/sql/models/qsqlquerymodel.cpp index c0b1061c6b..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) @@ -113,7 +79,7 @@ int QSqlQueryModelPrivate::columnInQuery(int modelColumn) const the lower-level QSqlQuery and can be used to provide data to view classes such as QTableView. For example: - \snippet sqldatabase/sqldatabase.cpp 16 + \snippet sqldatabase/sqldatabase_snippet.cpp 16 We set the model's query, then we set up the labels displayed in the view header. @@ -124,8 +90,8 @@ int QSqlQueryModelPrivate::columnInQuery(int modelColumn) const \snippet sqldatabase/sqldatabase.cpp 21 The code snippet above extracts the \c salary field from record 4 in - the result set of the query \c{SELECT * from employee}. Assuming - that \c salary is column 2, we can rewrite the last line as follows: + the result set of the \c SELECT query. Since \c salary is the 2nd + column (or column index 1), we can rewrite the last line as follows: \snippet sqldatabase/sqldatabase.cpp 22 @@ -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" |