21 #include <QVBoxLayout> 36 mModel =
new CustomLayerOrderModel( bridge,
this );
49 connect(
mChkOverride, SIGNAL( toggled(
bool ) ), bridge, SLOT( setHasCustomLayerOrder(
bool ) ) );
61 l->addWidget(
mView );
102 int CustomLayerOrderModel::rowCount(
const QModelIndex& )
const 104 return mOrder.count();
111 if ( role == Qt::DisplayRole )
115 return layer->
name();
118 if ( role == Qt::UserRole + 1 )
125 if ( role == Qt::CheckStateRole )
135 bool CustomLayerOrderModel::setData(
const QModelIndex& index,
const QVariant& value,
int role )
137 if ( role == Qt::CheckStateRole )
143 nodeLayer->
setVisible( static_cast< Qt::CheckState >( value.
toInt() ) );
153 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
154 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable;
159 return Qt::CopyAction | Qt::MoveAction;
162 QStringList CustomLayerOrderModel::mimeTypes()
const 165 types <<
"application/qgis.layerorderdata";
169 QMimeData*CustomLayerOrderModel::mimeData(
const QModelIndexList& indexes )
const 173 lst << data( index, Qt::UserRole + 1 ).toString();
176 mimeData->
setData(
"application/qgis.layerorderdata", lst.
join(
"\n" ).
toUtf8() );
180 bool CustomLayerOrderModel::dropMimeData(
const QMimeData* data, Qt::DropAction action,
int row,
int column,
const QModelIndex& parent )
185 if ( action == Qt::IgnoreAction )
188 if ( !data->
hasFormat(
"application/qgis.layerorderdata" ) )
191 QByteArray encodedData = data->
data(
"application/qgis.layerorderdata" );
195 row = mOrder.
count();
198 for (
int i = 0; i < lst.
count(); ++i )
199 mOrder.insert( row + i, lst[i] );
205 bool CustomLayerOrderModel::removeRows(
int row,
int count,
const QModelIndex& parent )
211 beginRemoveRows(
QModelIndex(), row, row + count - 1 );
212 while ( --count >= 0 )
213 mOrder.removeAt( row );
218 void CustomLayerOrderModel::refreshModel(
const QStringList& order )
225 void CustomLayerOrderModel::updateLayerVisibility(
const QString& layerId )
227 int row = mOrder.indexOf( layerId );
229 emit dataChanged(
index( row ),
index( row ) );
Base class for all map layer types.
void setCustomLayerOrder(const QStringList &order)
QByteArray data(const QString &mimeType) const
void setSelectionMode(QAbstractItemView::SelectionMode mode)
QString name() const
Get the display name of the layer.
The QgsLayerTreeMapCanvasBridge class takes care of updates of layer set for QgsMapCanvas from a laye...
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
virtual void setModel(QAbstractItemModel *model)
QString join(const QString &separator) const
QStringList defaultLayerOrder() const
QString tr(const char *sourceText, const char *disambiguation, int n)
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
QgsLayerTreeGroup * rootGroup() const
Qt::CheckState isVisible() const
int count(const T &value) const
QString fromUtf8(const char *str, int size)
int toInt(bool *ok) const
This class is a base class for nodes in a layer tree.
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
void setVisible(Qt::CheckState visible)
bool isLayer(QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
void setMargin(int margin)
QStringList customLayerOrder() const
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer. No type checking is done - use isLayer() to find out whether this operation is ...
const QChar at(int position) const
QgsLayerTreeLayer * findLayer(const QString &layerId) const
Find layer node representing the map layer specified by its ID. Searches recursively the whole sub-tr...
void setData(const QString &mimeType, const QByteArray &data)
void setDefaultDropAction(Qt::DropAction dropAction)
bool hasCustomLayerOrder() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setDropIndicatorShown(bool enable)
void setDragEnabled(bool enable)
Layer tree node points to a map layer.
QByteArray toUtf8() const