Skip to content

Commit 0b0e8a6

Browse files
committedApr 19, 2017
move QgsFieldModel and QgsFieldProxyModel to core and sipify
1 parent bd4f712 commit 0b0e8a6

15 files changed

+246
-188
lines changed
 

‎python/auto_sip.blacklist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,6 @@ gui/qgsexpressionlineedit.sip
361361
gui/qgsexpressionselectiondialog.sip
362362
gui/qgsextentgroupbox.sip
363363
gui/qgsfeatureselectiondlg.sip
364-
gui/qgsfieldmodel.sip
365-
gui/qgsfieldproxymodel.sip
366364
gui/qgsfieldvalidator.sip
367365
gui/qgsfieldvalueslineedit.sip
368366
gui/qgsfiledropedit.sip

‎python/core/core.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
%Include qgstransactiongroup.sip
7575
%Include qgsdartmeasurement.sip
7676
%Include qgsexpressionfieldbuffer.sip
77+
%Include qgsfieldmodel.sip
78+
%Include qgsfieldproxymodel.sip
7779
%Include qgsfontutils.sip
7880
%Include qgslabelsearchtree.sip
7981
%Include qgslegendrenderer.sip

‎python/core/qgsfieldmodel.sip

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/qgsfieldmodel.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
14+
class QgsFieldModel : QAbstractItemModel
15+
{
16+
%Docstring
17+
The QgsFieldModel class is a model to display the list of fields of a layer in widgets.
18+
If allowed, expressions might be added to the end of the model.
19+
It can be associated with a QgsMapLayerModel to dynamically display a layer and its fields.
20+
.. versionadded:: 2.3
21+
%End
22+
23+
%TypeHeaderCode
24+
#include "qgsfieldmodel.h"
25+
%End
26+
public:
27+
28+
enum FieldRoles
29+
{
30+
FieldNameRole
31+
FieldIndexRole
32+
ExpressionRole
33+
IsExpressionRole
34+
ExpressionValidityRole
35+
FieldTypeRole
36+
FieldOriginRole
37+
IsEmptyRole
38+
};
39+
40+
explicit QgsFieldModel( QObject *parent /TransferThis/ = 0 );
41+
%Docstring
42+
Constructor for QgsFieldModel - creates a model to display the fields of a given layer.
43+
%End
44+
45+
QModelIndex indexFromName( const QString &fieldName );
46+
%Docstring
47+
Returns the index corresponding to a given fieldName.
48+
:rtype: QModelIndex
49+
%End
50+
51+
void setAllowExpression( bool allowExpression );
52+
%Docstring
53+
Sets whether custom expressions are accepted and displayed in the model.
54+
\see allowExpression()
55+
\see setExpression()
56+
%End
57+
58+
bool allowExpression();
59+
%Docstring
60+
Returns true if the model allows custom expressions to be created and displayed.
61+
\see setAllowExpression()
62+
:rtype: bool
63+
%End
64+
65+
void setAllowEmptyFieldName( bool allowEmpty );
66+
%Docstring
67+
Sets whether an optional empty field ("not set") option is present in the model.
68+
\see allowEmptyFieldName()
69+
.. versionadded:: 3.0
70+
%End
71+
72+
bool allowEmptyFieldName() const;
73+
%Docstring
74+
Returns true if the model allows the empty field ("not set") choice.
75+
\see setAllowEmptyFieldName()
76+
.. versionadded:: 3.0
77+
:rtype: bool
78+
%End
79+
80+
bool isField( const QString &expression ) const;
81+
%Docstring
82+
Returns true if a string represents a field reference, or false if it is an
83+
expression consisting of more than direct field reference.
84+
:rtype: bool
85+
%End
86+
87+
void setExpression( const QString &expression );
88+
%Docstring
89+
Sets a single expression to be added after the fields at the end of the model.
90+
\see setAllowExpression()
91+
\see allowExpression()
92+
\see removeExpression()
93+
%End
94+
95+
void removeExpression();
96+
%Docstring
97+
Removes any custom expression from the model.
98+
\see setExpression()
99+
\see allowExpression()
100+
%End
101+
102+
QgsVectorLayer *layer();
103+
%Docstring
104+
Returns the layer associated with the model.
105+
\see setLayer()
106+
:rtype: QgsVectorLayer
107+
%End
108+
109+
virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
110+
%Docstring
111+
QAbstractItemModel interface
112+
:rtype: QModelIndex
113+
%End
114+
virtual QModelIndex parent( const QModelIndex &child ) const;
115+
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
116+
virtual int columnCount( const QModelIndex &parent ) const;
117+
virtual QVariant data( const QModelIndex &index, int role ) const;
118+
119+
public slots:
120+
121+
void setLayer( QgsVectorLayer *layer );
122+
%Docstring
123+
Set the layer from which fields are displayed.
124+
\see layer()
125+
%End
126+
127+
protected slots:
128+
129+
virtual void updateModel();
130+
%Docstring
131+
Called when the model must be updated.
132+
%End
133+
134+
protected:
135+
136+
137+
};
138+
139+
/************************************************************************
140+
* This file has been generated automatically from *
141+
* *
142+
* src/core/qgsfieldmodel.h *
143+
* *
144+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
145+
************************************************************************/

‎python/core/qgsfieldproxymodel.sip

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/qgsfieldproxymodel.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
14+
class QgsFieldProxyModel : QSortFilterProxyModel
15+
{
16+
%Docstring
17+
The QgsFieldProxyModel class provides an easy to use model to display the list of fields of a layer.
18+
.. versionadded:: 2.3
19+
%End
20+
21+
%TypeHeaderCode
22+
#include "qgsfieldproxymodel.h"
23+
%End
24+
public:
25+
26+
enum Filter
27+
{
28+
String,
29+
Int,
30+
LongLong,
31+
Double,
32+
Numeric
33+
Date,
34+
Time,
35+
HideReadOnly,
36+
AllTypes
37+
};
38+
typedef QFlags<QgsFieldProxyModel::Filter> Filters;
39+
40+
explicit QgsFieldProxyModel( QObject *parent /TransferThis/ = 0 );
41+
%Docstring
42+
QgsFieldProxModel creates a proxy model with a QgsFieldModel as source model.
43+
It can be used to filter the fields based on their types.
44+
%End
45+
46+
QgsFieldModel *sourceFieldModel();
47+
%Docstring
48+
Returns the QgsFieldModel used in this QSortFilterProxyModel
49+
:rtype: QgsFieldModel
50+
%End
51+
52+
QgsFieldProxyModel *setFilters( QgsFieldProxyModel::Filters filters );
53+
%Docstring
54+
Set flags that affect how fields are filtered in the model.
55+
\param filters are Filter flags
56+
\see filters()
57+
:rtype: QgsFieldProxyModel
58+
%End
59+
60+
const Filters &filters() const;
61+
%Docstring
62+
Returns the filters controlling displayed fields.
63+
\see setFilters()
64+
:rtype: Filters
65+
%End
66+
67+
public:
68+
virtual bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const;
69+
virtual bool lessThan( const QModelIndex &left, const QModelIndex &right ) const;
70+
};
71+
72+
QFlags<QgsFieldProxyModel::Filter> operator|(QgsFieldProxyModel::Filter f1, QFlags<QgsFieldProxyModel::Filter> f2);
73+
74+
/************************************************************************
75+
* This file has been generated automatically from *
76+
* *
77+
* src/core/qgsfieldproxymodel.h *
78+
* *
79+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
80+
************************************************************************/

‎python/gui/gui.sip

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@
7272
%Include qgsfeatureselectiondlg.sip
7373
%Include qgsfieldcombobox.sip
7474
%Include qgsfieldexpressionwidget.sip
75-
%Include qgsfieldmodel.sip
76-
%Include qgsfieldproxymodel.sip
7775
%Include qgsfieldvalidator.sip
7876
%Include qgsfieldvalueslineedit.sip
7977
%Include qgsfiledropedit.sip

‎python/gui/qgsfieldmodel.sip

Lines changed: 0 additions & 114 deletions
This file was deleted.

‎python/gui/qgsfieldproxymodel.sip

Lines changed: 0 additions & 57 deletions
This file was deleted.

‎python/plugins/processing/algs/qgis/ui/InterpolationDataWidget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
QgsProcessingUtils,
4040
QgsProject
4141
)
42-
from qgis.gui import QgsFieldProxyModel
42+
from qgis.core import QgsFieldProxyModel
4343
from qgis.analysis import QgsInterpolator
4444

4545
from processing.gui.wrappers import WidgetWrapper

‎src/core/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ SET(QGIS_CORE_SRCS
141141
qgsfieldconstraints.cpp
142142
qgsfieldformatter.cpp
143143
qgsfieldformatterregistry.cpp
144+
qgsfieldmodel.cpp
145+
qgsfieldproxymodel.cpp
144146
qgsfields.cpp
145147
qgsfontutils.cpp
146148
qgsgeometrycache.cpp
@@ -504,6 +506,8 @@ SET(QGIS_CORE_MOC_HDRS
504506
qgsfield.h
505507
qgsfieldconstraints.h
506508
qgsfieldformatterregistry.h
509+
qgsfieldmodel.h
510+
qgsfieldproxymodel.h
507511
qgsgeometryvalidator.h
508512
qgsgml.h
509513
qgsgmlschema.h
File renamed without changes.

‎src/gui/qgsfieldmodel.h renamed to ‎src/core/qgsfieldmodel.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
#define QGSFIELDMODEL_H
1818

1919
#include <QAbstractItemModel>
20-
#include <QItemSelectionModel>
2120
#include <QComboBox>
21+
#include <QItemSelectionModel>
22+
2223
#include "qgsfields.h"
23-
#include "qgis_gui.h"
24+
#include "qgis_core.h"
25+
26+
#include "qgis.h"
2427

2528
class QgsVectorLayer;
2629

@@ -31,7 +34,7 @@ class QgsVectorLayer;
3134
* It can be associated with a QgsMapLayerModel to dynamically display a layer and its fields.
3235
* \since QGIS 2.3
3336
*/
34-
class GUI_EXPORT QgsFieldModel : public QAbstractItemModel
37+
class CORE_EXPORT QgsFieldModel : public QAbstractItemModel
3538
{
3639
Q_OBJECT
3740

@@ -57,7 +60,7 @@ class GUI_EXPORT QgsFieldModel : public QAbstractItemModel
5760
/**
5861
* Constructor for QgsFieldModel - creates a model to display the fields of a given layer.
5962
*/
60-
explicit QgsFieldModel( QObject *parent = nullptr );
63+
explicit QgsFieldModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
6164

6265
/**
6366
* Returns the index corresponding to a given fieldName.
File renamed without changes.

‎src/gui/qgsfieldproxymodel.h renamed to ‎src/core/qgsfieldproxymodel.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
#define QGSFIELDPROXYMODEL_H
1818

1919
#include <QSortFilterProxyModel>
20-
#include "qgis_gui.h"
20+
21+
#include "qgis_core.h"
22+
23+
#include "qgis.h"
2124

2225
class QgsFieldModel;
2326

2427
/** \ingroup gui
2528
* \brief The QgsFieldProxyModel class provides an easy to use model to display the list of fields of a layer.
2629
* \since QGIS 2.3
2730
*/
28-
class GUI_EXPORT QgsFieldProxyModel : public QSortFilterProxyModel
31+
class CORE_EXPORT QgsFieldProxyModel : public QSortFilterProxyModel
2932
{
3033
Q_OBJECT
3134
Q_FLAGS( Filters )
@@ -51,7 +54,7 @@ class GUI_EXPORT QgsFieldProxyModel : public QSortFilterProxyModel
5154
* \brief QgsFieldProxModel creates a proxy model with a QgsFieldModel as source model.
5255
* It can be used to filter the fields based on their types.
5356
*/
54-
explicit QgsFieldProxyModel( QObject *parent = nullptr );
57+
explicit QgsFieldProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
5558

5659
//! Returns the QgsFieldModel used in this QSortFilterProxyModel
5760
QgsFieldModel *sourceFieldModel() { return mModel; }

‎src/gui/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ SET(QGIS_GUI_SRCS
214214
qgsfeatureselectiondlg.cpp
215215
qgsfieldcombobox.cpp
216216
qgsfieldexpressionwidget.cpp
217-
qgsfieldmodel.cpp
218-
qgsfieldproxymodel.cpp
219217
qgsfieldvalidator.cpp
220218
qgsfieldvalueslineedit.cpp
221219
qgsfiledropedit.cpp
@@ -369,8 +367,6 @@ SET(QGIS_GUI_MOC_HDRS
369367
qgsfeatureselectiondlg.h
370368
qgsfieldcombobox.h
371369
qgsfieldexpressionwidget.h
372-
qgsfieldmodel.h
373-
qgsfieldproxymodel.h
374370
qgsfieldvalidator.h
375371
qgsfieldvalueslineedit.h
376372
qgsfiledropedit.h

‎tests/src/python/test_qgsfieldmodel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import qgis # NOQA
1616

1717
from qgis.core import QgsFields, QgsVectorLayer
18-
from qgis.gui import QgsFieldModel
18+
from qgis.core import QgsFieldModel
1919
from qgis.PyQt.QtCore import QVariant, Qt
2020

2121
from qgis.testing import start_app, unittest

0 commit comments

Comments
 (0)
Please sign in to comment.