Skip to content

Commit 8b06a16

Browse files
committed
model/view for layer/field selectors
1 parent 0b32f2a commit 8b06a16

28 files changed

+1329
-188
lines changed

python/core/composer/qgsatlascomposition.sip

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ public:
6868
QString featureFilter() const;
6969
void setFeatureFilter( const QString& expression );
7070

71-
int sortKeyAttributeIndex() const;
72-
void setSortKeyAttributeIndex( int idx );
71+
QString sortKeyAttributeName() const;
72+
void setSortKeyAttributeName( QString fieldName );
73+
74+
int sortKeyAttributeIndex() const /Deprecated/;
75+
void setSortKeyAttributeIndex( int idx ) /Deprecated/;
7376

7477
/** Begins the rendering. Returns true if successful, false if no matching atlas
7578
features found.*/

python/gui/gui.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
%Include qgsexpressionbuilderdialog.sip
2929
%Include qgsexpressionbuilderwidget.sip
3030
%Include qgsexpressionhighlighter.sip
31+
%Include qgsfieldcombobox.sip
32+
%Include qgsfieldmodel.sip
3133
%Include qgsfieldvalidator.sip
3234
%Include qgsfiledropedit.sip
3335
%Include qgsfilterlineedit.sip
@@ -44,6 +46,9 @@
4446
%Include qgsmapcanvasmap.sip
4547
%Include qgsmapcanvassnapper.sip
4648
%Include qgsmaplayeractionregistry.sip
49+
%Include qgsmaplayercombobox.sip
50+
%Include qgsmaplayermodel.sip
51+
%Include qgsmaplayerproxymodel.sip
4752
%Include qgsmapoverviewcanvas.sip
4853
%Include qgsmaptip.sip
4954
%Include qgsmaptool.sip

python/gui/qgsfieldcombobox.sip

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @brief The QgsFieldComboBox is a combo box which displays the list of fields of a given layer.
3+
* @note added in 2.3
4+
*/
5+
class QgsFieldComboBox : QComboBox
6+
{
7+
8+
%TypeHeaderCode
9+
#include "qgsfieldcombobox.h"
10+
%End
11+
12+
public:
13+
/**
14+
* @brief QgsFieldComboBox creates a combo box to display the fields of a layer.
15+
* The layer can be either manually given or dynamically set by connecting the signal QgsMapLayerComboBox::layerChanged to the slot setLayer.
16+
*/
17+
explicit QgsFieldComboBox( QWidget *parent /TransferThis/ = 0 );
18+
19+
/**
20+
* @brief currentField returns the currently selected field
21+
*/
22+
QString currentField();
23+
24+
signals:
25+
/**
26+
* @brief fieldChanged the signal is emitted when the currently selected field changes
27+
*/
28+
void fieldChanged( QString fieldName );
29+
30+
public slots:
31+
/**
32+
* @brief setLayer sets the layer of which the fields are listed
33+
*/
34+
void setLayer( QgsMapLayer* layer );
35+
/**
36+
* @brief setField sets the currently selected field
37+
*/
38+
void setField( QString fieldName );
39+
40+
};

python/gui/qgsfieldmodel.sip

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
/**
3+
* @brief The QgsFieldModel class is a model to display the list of fields of a layer in widgets.
4+
* It can be associated with a QgsMapLayerModel to dynamically display a layer and its fields.
5+
* @note added in 2.3
6+
*/
7+
8+
class QgsFieldModel : QAbstractItemModel
9+
{
10+
%TypeHeaderCode
11+
#include "qgsfieldmodel.h"
12+
%End
13+
14+
public:
15+
static const int FieldNameRole;
16+
static const int FieldIndexRole;
17+
18+
/**
19+
* @brief QgsFieldModel creates a model to display the fields of a given layer
20+
*/
21+
explicit QgsFieldModel( QObject *parent /TransferThis/ = 0 );
22+
23+
/**
24+
* @brief indexFromName returns the index corresponding to a given fieldName
25+
*/
26+
QModelIndex indexFromName( QString fieldName );
27+
28+
public slots:
29+
/**
30+
* @brief setLayer sets the layer of whch fields are displayed
31+
*/
32+
void setLayer( QgsMapLayer *layer );
33+
34+
// QAbstractItemModel interface
35+
public:
36+
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
37+
QModelIndex parent( const QModelIndex &child ) const;
38+
int rowCount( const QModelIndex &parent ) const;
39+
int columnCount( const QModelIndex &parent ) const;
40+
QVariant data( const QModelIndex &index, int role ) const;
41+
42+
};

python/gui/qgsmaplayercombobox.sip

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @brief The QgsMapLayerComboBox class is a combo box which displays the list of layers
3+
* @note added in 2.3
4+
*/
5+
class QgsMapLayerComboBox : QComboBox
6+
{
7+
8+
%TypeHeaderCode
9+
#include "qgsmaplayercombobox.h"
10+
%End
11+
12+
public:
13+
/**
14+
* @brief QgsMapLayerComboBox creates a combo box to dislpay the list of layers (currently in the registry).
15+
* The layers can be filtered and/or ordered.
16+
*/
17+
explicit QgsMapLayerComboBox( QWidget *parent /TransferThis/ = 0 );
18+
19+
/**
20+
* @brief setFilters allows fitering according to layer type and/or geometry type.
21+
*/
22+
void setFilters( QgsMapLayerProxyModel::Filters filters );
23+
24+
/**
25+
* @brief currentLayer returns the current layer selected in the combo box
26+
*/
27+
QgsMapLayer* currentLayer();
28+
29+
public slots:
30+
/**
31+
* @brief setLayer set the current layer selected in the combo
32+
*/
33+
void setLayer( QgsMapLayer* layer );
34+
35+
signals:
36+
/**
37+
* @brief layerChanged this signal is emitted whenever the currently selected layer changes
38+
*/
39+
void layerChanged( QgsMapLayer* layer );
40+
};

python/gui/qgsmaplayermodel.sip

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
/**
3+
* @brief The QgsMapLayerModel class is a model to display layers in widgets.
4+
* @see QgsMapLayerProxyModel to sort and/filter the layers
5+
* @see QgsFieldModel to combine in with a field selector.
6+
* @note added in 2.3
7+
*/
8+
class QgsMapLayerModel : QAbstractItemModel
9+
{
10+
11+
%TypeHeaderCode
12+
#include "qgsmaplayermodel.h"
13+
%End
14+
15+
public:
16+
static const int LayerIdRole;
17+
18+
/**
19+
* @brief QgsMapLayerModel creates a model to display layers in widgets.
20+
*/
21+
explicit QgsMapLayerModel( QObject *parent /TransferThis/ = 0 );
22+
/**
23+
* @brief QgsMapLayerModel creates a model to display a specific list of layers in a widget.
24+
*/
25+
explicit QgsMapLayerModel( QList<QgsMapLayer*> layers, QObject *parent /TransferThis/ = 0 );
26+
27+
/**
28+
* @brief setItemsCheckable defines if layers should be selectable in the widget
29+
*/
30+
void setItemsCheckable( bool checkable );
31+
/**
32+
* @brief checkAll changes the checkstate for all the layers
33+
*/
34+
void checkAll( Qt::CheckState checkState );
35+
/**
36+
* @brief layersChecked returns the list of layers which are checked (or unchecked)
37+
*/
38+
QList<QgsMapLayer*> layersChecked( Qt::CheckState checkState = Qt::Checked );
39+
//! returns if the items can be checked or not
40+
bool itemsCheckable() ;
41+
42+
/**
43+
* @brief indexFromLayer returns the model index for a given layer
44+
*/
45+
QModelIndex indexFromLayer( QgsMapLayer* layer );
46+
47+
// QAbstractItemModel interface
48+
public:
49+
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
50+
QModelIndex parent( const QModelIndex &child ) const;
51+
int rowCount( const QModelIndex &parent ) const;
52+
int columnCount( const QModelIndex &parent ) const;
53+
QVariant data( const QModelIndex &index, int role ) const;
54+
bool setData( const QModelIndex &index, const QVariant &value, int role );
55+
Qt::ItemFlags flags( const QModelIndex &index ) const;
56+
};
57+
58+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @brief The QgsMapLayerProxModel class provides an easy to use model to display the list of layers in widgets.
3+
* @note added in 2.3
4+
*/
5+
class QgsMapLayerProxyModel : QSortFilterProxyModel
6+
{
7+
8+
%TypeHeaderCode
9+
#include "qgsmaplayerproxymodel.h"
10+
%End
11+
12+
public:
13+
enum Filter
14+
{
15+
NoFilter = 1,
16+
RasterLayer = 2,
17+
NoGeometry = 4,
18+
PointLayer = 8,
19+
LineLayer = 16,
20+
PolygonLayer = 32,
21+
HasGeometry = 56,
22+
VectorLayer = 60
23+
};
24+
typedef QFlags<QgsMapLayerProxyModel::Filter> Filters;
25+
26+
/**
27+
* @brief QgsMapLayerProxModel creates a proxy model with a QgsMapLayerModel as source model.
28+
* It can be used to filter the layers list in a widget.
29+
*/
30+
explicit QgsMapLayerProxyModel( QObject *parent /TransferThis/ = 0 );
31+
32+
/**
33+
* @brief layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel
34+
*/
35+
QgsMapLayerModel* sourceLayerModel() ;
36+
37+
/**
38+
* @brief setFilters set flags that affect how layers are filtered
39+
* @param filters are Filter flags
40+
* @note added in 2.3
41+
*/
42+
QgsMapLayerProxyModel* setFilters( Filters filters );
43+
const Filters& filters() const ;
44+
45+
// QSortFilterProxyModel interface
46+
public:
47+
bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const;
48+
bool lessThan( const QModelIndex &left, const QModelIndex &right ) const;
49+
};
50+

0 commit comments

Comments
 (0)