-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
model/view for layer/field selectors
- Loading branch information
Showing
28 changed files
with
1,329 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
|
Oops, something went wrong.