|
| 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 | + |
0 commit comments