Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:28:53

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QSQLFIELD_H
0005 #define QSQLFIELD_H
0006 
0007 #include <QtSql/qtsqlglobal.h>
0008 #include <QtCore/qshareddata.h>
0009 #include <QtCore/qvariant.h>
0010 #include <QtCore/qstring.h>
0011 
0012 QT_BEGIN_NAMESPACE
0013 
0014 
0015 class QSqlFieldPrivate;
0016 QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QSqlFieldPrivate, Q_SQL_EXPORT)
0017 
0018 class Q_SQL_EXPORT QSqlField
0019 {
0020     Q_GADGET
0021     Q_PROPERTY(QVariant value READ value WRITE setValue)
0022     Q_PROPERTY(QVariant defaultValue READ defaultValue WRITE setDefaultValue)
0023     Q_PROPERTY(QString name READ name WRITE setName)
0024     Q_PROPERTY(QString tableName READ tableName WRITE setTableName)
0025     Q_PROPERTY(QMetaType metaType READ metaType WRITE setMetaType)
0026     Q_PROPERTY(RequiredStatus requiredStatus READ requiredStatus WRITE setRequiredStatus)
0027     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
0028     Q_PROPERTY(bool generated READ isGenerated WRITE setGenerated)
0029     Q_PROPERTY(bool autoValue READ isAutoValue WRITE setAutoValue)
0030     Q_PROPERTY(int length READ length WRITE setLength)
0031     Q_PROPERTY(int precision READ precision WRITE setPrecision)
0032 
0033 public:
0034     enum RequiredStatus { Unknown = -1, Optional = 0, Required = 1 };
0035 
0036     explicit QSqlField(const QString& fieldName = QString(), QMetaType type = QMetaType(), const QString &tableName = QString());
0037 
0038     QSqlField(const QSqlField& other);
0039     QSqlField& operator=(const QSqlField& other);
0040     QSqlField(QSqlField &&other) noexcept = default;
0041     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlField)
0042     ~QSqlField();
0043 
0044     void swap(QSqlField &other) noexcept { val.swap(other.val); d.swap(other.d); }
0045 
0046     bool operator==(const QSqlField& other) const;
0047     inline bool operator!=(const QSqlField &other) const { return !operator==(other); }
0048 
0049     void setValue(const QVariant& value);
0050     inline QVariant value() const
0051     { return val; }
0052     void setName(const QString& name);
0053     QString name() const;
0054     void setTableName(const QString &tableName);
0055     QString tableName() const;
0056     bool isNull() const;
0057     void setReadOnly(bool readOnly);
0058     bool isReadOnly() const;
0059     void clear();
0060     bool isAutoValue() const;
0061 
0062     QMetaType metaType() const;
0063     void setMetaType(QMetaType type);
0064 
0065 #if QT_DEPRECATED_SINCE(6, 0)
0066     QT_WARNING_PUSH
0067     QT_WARNING_DISABLE_DEPRECATED
0068     QT_DEPRECATED_VERSION_X_6_0("Use the constructor using a QMetaType instead")
0069     QSqlField(const QString& fieldName, QVariant::Type type, const QString &tableName = QString())
0070         : QSqlField(fieldName, QMetaType(type), tableName)
0071     {}
0072     QT_DEPRECATED_VERSION_X_6_0("Use metaType() instead")
0073     QVariant::Type type() const { return QVariant::Type(metaType().id()); }
0074     QT_DEPRECATED_VERSION_X_6_0("Use setMetaType() instead")
0075     void setType(QVariant::Type type) { setMetaType(QMetaType(int(type))); }
0076     QT_WARNING_POP
0077 #endif
0078 
0079     void setRequiredStatus(RequiredStatus status);
0080     inline void setRequired(bool required)
0081     { setRequiredStatus(required ? Required : Optional); }
0082     void setLength(int fieldLength);
0083     void setPrecision(int precision);
0084     void setDefaultValue(const QVariant &value);
0085 #if QT_DEPRECATED_SINCE(6, 8)
0086     QT_DEPRECATED_VERSION_X_6_8("This internal value is no longer used.")
0087     void setSqlType(int type);
0088 #endif
0089     void setGenerated(bool gen);
0090     void setAutoValue(bool autoVal);
0091 
0092     RequiredStatus requiredStatus() const;
0093     int length() const;
0094     int precision() const;
0095     QVariant defaultValue() const;
0096 #if QT_DEPRECATED_SINCE(6, 8)
0097     QT_DEPRECATED_VERSION_X_6_8("This internal value is no longer used.")
0098     int typeID() const;
0099 #endif
0100     bool isGenerated() const;
0101     bool isValid() const;
0102 
0103 private:
0104     void detach();
0105     // ### Qt7: move to private class
0106     QVariant val;
0107     QExplicitlySharedDataPointer<QSqlFieldPrivate> d;
0108 };
0109 
0110 Q_DECLARE_SHARED(QSqlField)
0111 
0112 #ifndef QT_NO_DEBUG_STREAM
0113 Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlField &);
0114 #endif
0115 
0116 QT_END_NAMESPACE
0117 
0118 #endif // QSQLFIELD_H