summaryrefslogtreecommitdiffstats
path: root/src/sql/kernel/qsqlindex.h
blob: 409cb463e3f76e082aad2a9716c35b4c249bd2cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 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 QSQLINDEX_H
#define QSQLINDEX_H

#include <QtSql/qtsqlglobal.h>
#include <QtSql/qsqlrecord.h>
#include <QtCore/qlist.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qstring.h>

// clazy:excludeall=qproperty-without-notify
QT_BEGIN_NAMESPACE


class Q_SQL_EXPORT QSqlIndex : public QSqlRecord
{
    Q_GADGET
public:
    Q_PROPERTY(QString name READ name WRITE setName)
    Q_PROPERTY(QString cursorName READ cursorName WRITE setCursorName)

    explicit QSqlIndex(const QString &cursorName = QString(), const QString &name = QString());
    QSqlIndex(const QSqlIndex &other);
    QSqlIndex(QSqlIndex &&other) noexcept = default;
    ~QSqlIndex();
    QSqlIndex &operator=(const QSqlIndex &other);
    QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QSqlIndex)

    void swap(QSqlIndex &other) noexcept {
        QSqlRecord::swap(other);
        cursor.swap(other.cursor);
        nm.swap(other.nm);
        sorts.swap(other.sorts);
    };

    void setCursorName(const QString &cursorName);
    inline QString cursorName() const { return cursor; }
    void setName(const QString& name);
    inline QString name() const { return nm; }

    void append(const QSqlField &field);
    void append(const QSqlField &field, bool desc);

    bool isDescending(int i) const;
    void setDescending(int i, bool desc);

private:
    QString createField(int i, const QString& prefix, bool verbose) const;
    // ### Qt7: move to d-ptr
    QString cursor;
    QString nm;
    QList<bool> sorts;
};

Q_DECLARE_SHARED(QSqlIndex)

QT_END_NAMESPACE

#endif // QSQLINDEX_H