21 #include <QVBoxLayout> 36 mModel =
new CustomLayerOrderModel( bridge,
this );
49 connect(
mChkOverride, SIGNAL( toggled(
bool ) ), bridge, SLOT( setHasCustomLayerOrder(
bool ) ) );
61 l->addWidget(
mView );
103 int CustomLayerOrderModel::rowCount(
const QModelIndex& )
const 105 return mOrder.count();
112 if ( role == Qt::DisplayRole )
116 return layer->
name();
119 if ( role == Qt::UserRole + 1 )
126 if ( role == Qt::CheckStateRole )
136 bool CustomLayerOrderModel::setData(
const QModelIndex& index,
const QVariant& value,
int role )
138 if ( role == Qt::CheckStateRole )
144 nodeLayer->
setVisible( static_cast< Qt::CheckState >( value.
toInt() ) );
154 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
155 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable;
160 return Qt::CopyAction | Qt::MoveAction;
163 QStringList CustomLayerOrderModel::mimeTypes()
const 166 types <<
"application/qgis.layerorderdata";
170 QMimeData*CustomLayerOrderModel::mimeData(
const QModelIndexList& indexes )
const 174 lst << data( index, Qt::UserRole + 1 ).toString();
177 mimeData->
setData(
"application/qgis.layerorderdata", lst.
join(
"\n" ).
toUtf8() );
181 bool CustomLayerOrderModel::dropMimeData(
const QMimeData* data, Qt::DropAction action,
int row,
int column,
const QModelIndex& parent )
186 if ( action == Qt::IgnoreAction )
189 if ( !data->
hasFormat(
"application/qgis.layerorderdata" ) )
192 QByteArray encodedData = data->
data(
"application/qgis.layerorderdata" );
196 row = mOrder.
count();
199 for (
int i = 0; i < lst.
count(); ++i )
200 mOrder.insert( row + i, lst[i] );
206 bool CustomLayerOrderModel::removeRows(
int row,
int count,
const QModelIndex& parent )
212 beginRemoveRows(
QModelIndex(), row, row + count - 1 );
213 while ( --count >= 0 )
214 mOrder.removeAt( row );
219 void CustomLayerOrderModel::refreshModel(
const QStringList& order )
226 void CustomLayerOrderModel::updateLayerVisibility(
const QString& layerId )
228 int row = mOrder.indexOf( layerId );
230 emit dataChanged(
index( row ),
index( row ) );
Base class for all map layer types.
bool hasCustomLayerOrder() const
void setCustomLayerOrder(const QStringList &order)
QByteArray data(const QString &mimeType) const
void setSelectionMode(QAbstractItemView::SelectionMode mode)
The QgsLayerTreeMapCanvasBridge class takes care of updates of layer set for QgsMapCanvas from a laye...
QgsMapLayer * mapLayer(const QString &theLayerId) const
Retrieve a pointer to a registered layer by layer ID.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
virtual void setModel(QAbstractItemModel *model)
Qt::CheckState isVisible() const
QString join(const QString &separator) const
QString tr(const char *sourceText, const char *disambiguation, int n)
int count(const T &value) const
QString fromUtf8(const char *str, int size)
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
int toInt(bool *ok) const
QStringList customLayerOrder() const
This class is a base class for nodes in a layer tree.
void setVisible(Qt::CheckState visible)
bool isLayer(QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
void setMargin(int margin)
QgsLayerTreeGroup * rootGroup() const
QStringList defaultLayerOrder() const
QgsLayerTreeLayer * findLayer(const QString &layerId) const
Find layer node representing the map layer specified by its ID. Searches recursively the whole sub-tr...
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
QString name
Read property of QString layerName.
void setData(const QString &mimeType, const QByteArray &data)
void setDefaultDropAction(Qt::DropAction dropAction)
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