mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-08 00:05:09 -04:00
QgsMapLayerModel: allow direct retrieval of map layer
This commit is contained in:
parent
de06cd7612
commit
ee46ece2da
@ -1371,7 +1371,7 @@ INCLUDE_FILE_PATTERNS =
|
|||||||
# undefined via #undef or recursively expanded use the := operator
|
# undefined via #undef or recursively expanded use the := operator
|
||||||
# instead of the = operator.
|
# instead of the = operator.
|
||||||
|
|
||||||
PREDEFINED =
|
PREDEFINED = "QT_VERSION=0x040800"
|
||||||
|
|
||||||
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
|
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
|
||||||
# this tag can be used to specify a list of macro names that should be expanded.
|
# this tag can be used to specify a list of macro names that should be expanded.
|
||||||
|
@ -13,7 +13,11 @@ class QgsMapLayerModel : QAbstractItemModel
|
|||||||
%End
|
%End
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const int LayerIdRole;
|
enum
|
||||||
|
{
|
||||||
|
LayerIdRole,
|
||||||
|
LayerRole
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief QgsMapLayerModel creates a model to display layers in widgets.
|
* @brief QgsMapLayerModel creates a model to display layers in widgets.
|
||||||
@ -56,6 +60,14 @@ class QgsMapLayerModel : QAbstractItemModel
|
|||||||
int rowCount( const QModelIndex &parent ) const;
|
int rowCount( const QModelIndex &parent ) const;
|
||||||
int columnCount( const QModelIndex &parent ) const;
|
int columnCount( const QModelIndex &parent ) const;
|
||||||
QVariant data( const QModelIndex &index, int role ) const;
|
QVariant data( const QModelIndex &index, int role ) const;
|
||||||
|
%If (QT5_SUPPORT)
|
||||||
|
/**
|
||||||
|
* Returns strings for all roles supported by this model.
|
||||||
|
*
|
||||||
|
* @note Available only with Qt5 (python and c++)
|
||||||
|
*/
|
||||||
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
%End
|
||||||
bool setData( const QModelIndex &index, const QVariant &value, int role );
|
bool setData( const QModelIndex &index, const QVariant &value, int role );
|
||||||
Qt::ItemFlags flags( const QModelIndex &index ) const;
|
Qt::ItemFlags flags( const QModelIndex &index ) const;
|
||||||
};
|
};
|
||||||
|
@ -759,4 +759,6 @@ class CORE_EXPORT QgsMapLayer : public QObject
|
|||||||
QgsMapLayerStyleManager* mStyleManager;
|
QgsMapLayerStyleManager* mStyleManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE( QgsMapLayer* )
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,8 +22,6 @@
|
|||||||
#include "qgsvectorlayer.h"
|
#include "qgsvectorlayer.h"
|
||||||
|
|
||||||
|
|
||||||
const int QgsMapLayerModel::LayerIdRole = Qt::UserRole + 1;
|
|
||||||
|
|
||||||
QgsMapLayerModel::QgsMapLayerModel( const QList<QgsMapLayer *>& layers, QObject *parent )
|
QgsMapLayerModel::QgsMapLayerModel( const QList<QgsMapLayer *>& layers, QObject *parent )
|
||||||
: QAbstractItemModel( parent )
|
: QAbstractItemModel( parent )
|
||||||
, mLayersChecked( QMap<QString, Qt::CheckState>() )
|
, mLayersChecked( QMap<QString, Qt::CheckState>() )
|
||||||
@ -151,6 +149,11 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
|
|||||||
return layer->id();
|
return layer->id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( role == LayerRole )
|
||||||
|
{
|
||||||
|
return QVariant::fromValue<QgsMapLayer*>( static_cast<QgsMapLayer*>( index.internalPointer() ) );
|
||||||
|
}
|
||||||
|
|
||||||
if ( role == Qt::CheckStateRole && mItemCheckable )
|
if ( role == Qt::CheckStateRole && mItemCheckable )
|
||||||
{
|
{
|
||||||
QgsMapLayer* layer = static_cast<QgsMapLayer*>( index.internalPointer() );
|
QgsMapLayer* layer = static_cast<QgsMapLayer*>( index.internalPointer() );
|
||||||
@ -213,6 +216,16 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
QHash<int, QByteArray> QgsMapLayerModel::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
|
||||||
|
roles[LayerIdRole] = "layerId";
|
||||||
|
roles[LayerRole] = "layer";
|
||||||
|
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Qt::ItemFlags QgsMapLayerModel::flags( const QModelIndex &index ) const
|
Qt::ItemFlags QgsMapLayerModel::flags( const QModelIndex &index ) const
|
||||||
{
|
{
|
||||||
|
@ -29,11 +29,16 @@ class QgsMapLayer;
|
|||||||
* @see QgsFieldModel to combine in with a field selector.
|
* @see QgsFieldModel to combine in with a field selector.
|
||||||
* @note added in 2.3
|
* @note added in 2.3
|
||||||
*/
|
*/
|
||||||
|
// TODO QGIS3: move to core
|
||||||
class GUI_EXPORT QgsMapLayerModel : public QAbstractItemModel
|
class GUI_EXPORT QgsMapLayerModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static const int LayerIdRole;
|
enum
|
||||||
|
{
|
||||||
|
LayerIdRole = Qt::UserRole + 1,
|
||||||
|
LayerRole
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief QgsMapLayerModel creates a model to display layers in widgets.
|
* @brief QgsMapLayerModel creates a model to display layers in widgets.
|
||||||
@ -81,6 +86,16 @@ class GUI_EXPORT QgsMapLayerModel : public QAbstractItemModel
|
|||||||
int rowCount( const QModelIndex &parent ) const override;
|
int rowCount( const QModelIndex &parent ) const override;
|
||||||
int columnCount( const QModelIndex &parent ) const override;
|
int columnCount( const QModelIndex &parent ) const override;
|
||||||
QVariant data( const QModelIndex &index, int role ) const override;
|
QVariant data( const QModelIndex &index, int role ) const override;
|
||||||
|
///@cond PRIVATE
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
/**
|
||||||
|
* Returns strings for all roles supported by this model.
|
||||||
|
*
|
||||||
|
* @note Available only with Qt5 (python and c++)
|
||||||
|
*/
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
#endif
|
||||||
|
///@endcond
|
||||||
bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
|
bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
|
||||||
Qt::ItemFlags flags( const QModelIndex &index ) const override;
|
Qt::ItemFlags flags( const QModelIndex &index ) const override;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user