Merge pull request #57166 from nirvn/fields_gadget

[qml] Make QgsFields a QGadet and make some functions Q_INVOKABLE
This commit is contained in:
Mathieu Pellerin 2024-04-21 05:53:41 +07:00 committed by GitHub
commit b9898d0fa1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 6 deletions

View File

@ -28,6 +28,9 @@ In addition to storing a list of :py:class:`QgsField` instances, it also:
%TypeHeaderCode
#include "qgsfields.h"
%End
public:
static const QMetaObject staticMetaObject;
public:
enum FieldOrigin /BaseType=IntEnum/
@ -289,7 +292,7 @@ name of the field.
.. seealso:: :py:func:`lookupField`
%End
int lookupField( const QString &fieldName ) const;
int lookupField( const QString &fieldName ) const;
%Docstring
Looks up field's index from the field name.
This method matches in the following order:

View File

@ -28,6 +28,9 @@ In addition to storing a list of :py:class:`QgsField` instances, it also:
%TypeHeaderCode
#include "qgsfields.h"
%End
public:
static const QMetaObject staticMetaObject;
public:
enum FieldOrigin
@ -289,7 +292,7 @@ name of the field.
.. seealso:: :py:func:`lookupField`
%End
int lookupField( const QString &fieldName ) const;
int lookupField( const QString &fieldName ) const;
%Docstring
Looks up field's index from the field name.
This method matches in the following order:

View File

@ -43,6 +43,12 @@ class QgsFieldsPrivate;
*/
class CORE_EXPORT QgsFields
{
Q_GADGET
Q_PROPERTY( bool isEmpty READ isEmpty )
Q_PROPERTY( int count READ count )
Q_PROPERTY( QStringList names READ names )
public:
enum FieldOrigin
@ -173,7 +179,7 @@ class CORE_EXPORT QgsFields
* \param i Index of the field which needs to be checked
* \returns TRUE if the field exists
*/
bool exists( int i ) const;
Q_INVOKABLE bool exists( int i ) const;
#ifndef SIP_RUN
//! Gets field at particular index (must be in range 0..N-1)
@ -354,7 +360,7 @@ class CORE_EXPORT QgsFields
* \returns The field index if found or -1 in case it cannot be found.
* \see lookupField For a more tolerant alternative.
*/
int indexFromName( const QString &fieldName ) const;
Q_INVOKABLE int indexFromName( const QString &fieldName ) const;
/**
* Gets the field index from the field name.
@ -367,7 +373,7 @@ class CORE_EXPORT QgsFields
* \returns The field index if found or -1 in case it cannot be found.
* \see lookupField For a more tolerant alternative.
*/
int indexOf( const QString &fieldName ) const;
Q_INVOKABLE int indexOf( const QString &fieldName ) const;
/**
* Looks up field's index from the field name.
@ -382,7 +388,7 @@ class CORE_EXPORT QgsFields
* \returns The field index if found or -1 in case it cannot be found.
* \see indexFromName For a more performant and precise but less tolerant alternative.
*/
int lookupField( const QString &fieldName ) const;
Q_INVOKABLE int lookupField( const QString &fieldName ) const;
/**
* Utility function to get list of attribute indexes

View File

@ -405,6 +405,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
Q_PROPERTY( QgsEditFormConfig editFormConfig READ editFormConfig WRITE setEditFormConfig NOTIFY editFormConfigChanged )
Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged )
Q_PROPERTY( bool supportsEditing READ supportsEditing NOTIFY supportsEditingChanged )
Q_PROPERTY( QgsFields fields READ fields NOTIFY updatedFields )
public: