Skip to content

Commit

Permalink
Merge pull request #57166 from nirvn/fields_gadget
Browse files Browse the repository at this point in the history
[qml] Make QgsFields a QGadet and make some functions Q_INVOKABLE
  • Loading branch information
nirvn authored Apr 20, 2024
2 parents a979931 + 37af25e commit b9898d0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
5 changes: 4 additions & 1 deletion python/PyQt6/core/auto_generated/qgsfields.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion python/core/auto_generated/qgsfields.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 10 additions & 4 deletions src/core/qgsfields.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/core/vector/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit b9898d0

Please sign in to comment.