21 #include <QVBoxLayout>
34 : QAbstractListModel( parent ),
mBridge( bridge )
38 int rowCount(
const QModelIndex & )
const override
43 QVariant
data(
const QModelIndex &
index,
int role )
const override
45 QString
id =
mOrder.at( index.row() );
47 if ( role == Qt::DisplayRole )
54 if ( role == Qt::UserRole + 1 )
61 if ( role == Qt::CheckStateRole )
71 bool setData(
const QModelIndex &
index,
const QVariant &value,
int role )
override
73 if ( role == Qt::CheckStateRole )
75 QString
id =
mOrder.at( index.row() );
79 nodeLayer->
setVisible(( Qt::CheckState )value.toInt() );
86 Qt::ItemFlags
flags(
const QModelIndex &
index )
const override
88 if ( !index.isValid() )
89 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
90 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable;
95 return Qt::MoveAction;
101 types <<
"application/qgis.layerorderdata";
105 QMimeData*
mimeData(
const QModelIndexList& indexes )
const override
108 foreach ( QModelIndex
index, indexes )
109 lst <<
data( index, Qt::UserRole + 1 ).toString();
111 QMimeData*
mimeData =
new QMimeData();
112 mimeData->setData(
"application/qgis.layerorderdata", lst.join(
"\n" ).toUtf8() );
116 bool dropMimeData(
const QMimeData *
data, Qt::DropAction action,
int row,
int column,
const QModelIndex &parent )
override
121 if ( action == Qt::IgnoreAction )
124 if ( !data->hasFormat(
"application/qgis.layerorderdata" ) )
127 QByteArray encodedData = data->data(
"application/qgis.layerorderdata" );
128 QStringList lst = QString::fromUtf8( encodedData ).split(
"\n" );
133 beginInsertRows( QModelIndex(), row, row + lst.count() - 1 );
134 for (
int i = 0; i < lst.count(); ++i )
135 mOrder.insert( row + i, lst[i] );
141 bool removeRows(
int row,
int count,
const QModelIndex& parent )
override
147 beginRemoveRows( QModelIndex(), row, row + count - 1 );
148 while ( --count >= 0 )
165 int row =
mOrder.indexOf( layerId );
167 emit dataChanged(
index( row ),
index( row ) );
182 mView =
new QListView(
this );
183 mView->setDragEnabled(
true );
184 mView->setAcceptDrops(
true );
185 mView->setDropIndicatorShown(
true );
186 mView->setDragDropMode( QAbstractItemView::InternalMove );
187 mView->setSelectionMode( QAbstractItemView::ExtendedSelection );
193 connect(
mChkOverride, SIGNAL( toggled(
bool ) ), bridge, SLOT( setHasCustomLayerOrder(
bool ) ) );
198 connect(
mModel, SIGNAL( rowsInserted( QModelIndex,
int,
int ) ),
this, SLOT(
modelUpdated() ) );
199 connect(
mModel, SIGNAL( rowsRemoved( QModelIndex,
int,
int ) ),
this, SLOT(
modelUpdated() ) );
203 QVBoxLayout* l =
new QVBoxLayout;
205 l->addWidget(
mView );
214 mView->setEnabled( state );