Skip to content
Permalink
Browse files
model/view for layer/field selectors
  • Loading branch information
3nids committed Apr 3, 2014
1 parent 0b32f2a commit 8b06a16a7518f012ca30f803bdfae165388e6fc1
@@ -68,8 +68,11 @@ public:
QString featureFilter() const;
void setFeatureFilter( const QString& expression );

int sortKeyAttributeIndex() const;
void setSortKeyAttributeIndex( int idx );
QString sortKeyAttributeName() const;
void setSortKeyAttributeName( QString fieldName );

int sortKeyAttributeIndex() const /Deprecated/;
void setSortKeyAttributeIndex( int idx ) /Deprecated/;

/** Begins the rendering. Returns true if successful, false if no matching atlas
features found.*/
@@ -28,6 +28,8 @@
%Include qgsexpressionbuilderdialog.sip
%Include qgsexpressionbuilderwidget.sip
%Include qgsexpressionhighlighter.sip
%Include qgsfieldcombobox.sip
%Include qgsfieldmodel.sip
%Include qgsfieldvalidator.sip
%Include qgsfiledropedit.sip
%Include qgsfilterlineedit.sip
@@ -44,6 +46,9 @@
%Include qgsmapcanvasmap.sip
%Include qgsmapcanvassnapper.sip
%Include qgsmaplayeractionregistry.sip
%Include qgsmaplayercombobox.sip
%Include qgsmaplayermodel.sip
%Include qgsmaplayerproxymodel.sip
%Include qgsmapoverviewcanvas.sip
%Include qgsmaptip.sip
%Include qgsmaptool.sip
@@ -0,0 +1,40 @@
/**
* @brief The QgsFieldComboBox is a combo box which displays the list of fields of a given layer.
* @note added in 2.3
*/
class QgsFieldComboBox : QComboBox
{

%TypeHeaderCode
#include "qgsfieldcombobox.h"
%End

public:
/**
* @brief QgsFieldComboBox creates a combo box to display the fields of a layer.
* The layer can be either manually given or dynamically set by connecting the signal QgsMapLayerComboBox::layerChanged to the slot setLayer.
*/
explicit QgsFieldComboBox( QWidget *parent /TransferThis/ = 0 );

/**
* @brief currentField returns the currently selected field
*/
QString currentField();

signals:
/**
* @brief fieldChanged the signal is emitted when the currently selected field changes
*/
void fieldChanged( QString fieldName );

public slots:
/**
* @brief setLayer sets the layer of which the fields are listed
*/
void setLayer( QgsMapLayer* layer );
/**
* @brief setField sets the currently selected field
*/
void setField( QString fieldName );

};
@@ -0,0 +1,42 @@

/**
* @brief The QgsFieldModel class is a model to display the list of fields of a layer in widgets.
* It can be associated with a QgsMapLayerModel to dynamically display a layer and its fields.
* @note added in 2.3
*/

class QgsFieldModel : QAbstractItemModel
{
%TypeHeaderCode
#include "qgsfieldmodel.h"
%End

public:
static const int FieldNameRole;
static const int FieldIndexRole;

/**
* @brief QgsFieldModel creates a model to display the fields of a given layer
*/
explicit QgsFieldModel( QObject *parent /TransferThis/ = 0 );

/**
* @brief indexFromName returns the index corresponding to a given fieldName
*/
QModelIndex indexFromName( QString fieldName );

public slots:
/**
* @brief setLayer sets the layer of whch fields are displayed
*/
void setLayer( QgsMapLayer *layer );

// QAbstractItemModel interface
public:
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
QModelIndex parent( const QModelIndex &child ) const;
int rowCount( const QModelIndex &parent ) const;
int columnCount( const QModelIndex &parent ) const;
QVariant data( const QModelIndex &index, int role ) const;

};
@@ -0,0 +1,40 @@
/**
* @brief The QgsMapLayerComboBox class is a combo box which displays the list of layers
* @note added in 2.3
*/
class QgsMapLayerComboBox : QComboBox
{

%TypeHeaderCode
#include "qgsmaplayercombobox.h"
%End

public:
/**
* @brief QgsMapLayerComboBox creates a combo box to dislpay the list of layers (currently in the registry).
* The layers can be filtered and/or ordered.
*/
explicit QgsMapLayerComboBox( QWidget *parent /TransferThis/ = 0 );

/**
* @brief setFilters allows fitering according to layer type and/or geometry type.
*/
void setFilters( QgsMapLayerProxyModel::Filters filters );

/**
* @brief currentLayer returns the current layer selected in the combo box
*/
QgsMapLayer* currentLayer();

public slots:
/**
* @brief setLayer set the current layer selected in the combo
*/
void setLayer( QgsMapLayer* layer );

signals:
/**
* @brief layerChanged this signal is emitted whenever the currently selected layer changes
*/
void layerChanged( QgsMapLayer* layer );
};
@@ -0,0 +1,58 @@

/**
* @brief The QgsMapLayerModel class is a model to display layers in widgets.
* @see QgsMapLayerProxyModel to sort and/filter the layers
* @see QgsFieldModel to combine in with a field selector.
* @note added in 2.3
*/
class QgsMapLayerModel : QAbstractItemModel
{

%TypeHeaderCode
#include "qgsmaplayermodel.h"
%End

public:
static const int LayerIdRole;

/**
* @brief QgsMapLayerModel creates a model to display layers in widgets.
*/
explicit QgsMapLayerModel( QObject *parent /TransferThis/ = 0 );
/**
* @brief QgsMapLayerModel creates a model to display a specific list of layers in a widget.
*/
explicit QgsMapLayerModel( QList<QgsMapLayer*> layers, QObject *parent /TransferThis/ = 0 );

/**
* @brief setItemsCheckable defines if layers should be selectable in the widget
*/
void setItemsCheckable( bool checkable );
/**
* @brief checkAll changes the checkstate for all the layers
*/
void checkAll( Qt::CheckState checkState );
/**
* @brief layersChecked returns the list of layers which are checked (or unchecked)
*/
QList<QgsMapLayer*> layersChecked( Qt::CheckState checkState = Qt::Checked );
//! returns if the items can be checked or not
bool itemsCheckable() ;

/**
* @brief indexFromLayer returns the model index for a given layer
*/
QModelIndex indexFromLayer( QgsMapLayer* layer );

// QAbstractItemModel interface
public:
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
QModelIndex parent( const QModelIndex &child ) const;
int rowCount( const QModelIndex &parent ) const;
int columnCount( const QModelIndex &parent ) const;
QVariant data( const QModelIndex &index, int role ) const;
bool setData( const QModelIndex &index, const QVariant &value, int role );
Qt::ItemFlags flags( const QModelIndex &index ) const;
};


@@ -0,0 +1,50 @@
/**
* @brief The QgsMapLayerProxModel class provides an easy to use model to display the list of layers in widgets.
* @note added in 2.3
*/
class QgsMapLayerProxyModel : QSortFilterProxyModel
{

%TypeHeaderCode
#include "qgsmaplayerproxymodel.h"
%End

public:
enum Filter
{
NoFilter = 1,
RasterLayer = 2,
NoGeometry = 4,
PointLayer = 8,
LineLayer = 16,
PolygonLayer = 32,
HasGeometry = 56,
VectorLayer = 60
};
typedef QFlags<QgsMapLayerProxyModel::Filter> Filters;

/**
* @brief QgsMapLayerProxModel creates a proxy model with a QgsMapLayerModel as source model.
* It can be used to filter the layers list in a widget.
*/
explicit QgsMapLayerProxyModel( QObject *parent /TransferThis/ = 0 );

/**
* @brief layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel
*/
QgsMapLayerModel* sourceLayerModel() ;

/**
* @brief setFilters set flags that affect how layers are filtered
* @param filters are Filter flags
* @note added in 2.3
*/
QgsMapLayerProxyModel* setFilters( Filters filters );
const Filters& filters() const ;

// QSortFilterProxyModel interface
public:
bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const;
bool lessThan( const QModelIndex &left, const QModelIndex &right ) const;
};

0 comments on commit 8b06a16

Please sign in to comment.