Skip to content
Permalink
Browse files

enabled drag-and-drop from qbrowser to qgis, except wms

  • Loading branch information
blazek committed Jun 18, 2011
1 parent bb9e992 commit 9028bf7d7d029e52aad2381898e0ecfc4b6400a3
Showing with 57 additions and 10 deletions.
  1. +27 −1 src/app/qgisapp.cpp
  2. +30 −9 src/browser/qgsbrowsermodel.cpp
@@ -636,7 +636,7 @@ QgisApp::~QgisApp()

void QgisApp::dragEnterEvent( QDragEnterEvent *event )
{
if ( event->mimeData()->hasUrls() )
if ( event->mimeData()->hasUrls() || event->mimeData()->hasFormat( "application/x-vnd.qgis.qgis.uri" ) )
{
event->acceptProposedAction();
}
@@ -657,6 +657,32 @@ void QgisApp::dropEvent( QDropEvent *event )
openFile( fileName );
}
}
if ( event->mimeData()->hasFormat( "application/x-vnd.qgis.qgis.uri" ) )
{
QByteArray encodedData = event->mimeData()->data( "application/x-vnd.qgis.qgis.uri" );
QDataStream stream( &encodedData, QIODevice::ReadOnly );
QString xUri; // extended uri: layer_type:provider_key:uri
stream >> xUri;
QgsDebugMsg( xUri );
QRegExp rx( "^([^:]+):([^:]+):([^:]+):(.+)" );
if ( rx.indexIn( xUri ) != -1 )
{
QString layerType = rx.cap( 1 );
QString providerKey = rx.cap( 2 );
QString name = rx.cap( 3 );
QString uri = rx.cap( 4 );
QgsDebugMsg( "type: " + layerType + " key: " + providerKey + " name: " + name + " uri: " + uri );
if ( layerType == "vector" )
{
addVectorLayer( uri, name, providerKey );
}
else if ( layerType == "raster" )
{
addRasterLayer( uri, name, providerKey, QStringList(), QStringList(), QString(), QString() );
}
}
}

event->acceptProposedAction();
}

@@ -85,7 +85,11 @@ Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex & index ) const
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
if ( ptr->type() == QgsDataItem::Layer )
{
flags |= Qt::ItemIsDragEnabled;
QgsLayerItem *layer = ( QgsLayerItem* ) ptr;
if ( layer->providerKey() != "wms" )
{
flags |= Qt::ItemIsDragEnabled;
}
}
return flags;
}
@@ -272,28 +276,45 @@ void QgsBrowserModel::connectItem( QgsDataItem* item )
QStringList QgsBrowserModel::mimeTypes() const
{
QStringList types;
types << "text/uri-list";
// In theory the mime type convention is: application/x-vnd.<vendor>.<application>.<type>
// but it seems a bit over formalized. Would be an application/x-qgis-uri better?
types << "application/x-vnd.qgis.qgis.uri";
return types;
}

QMimeData * QgsBrowserModel::mimeData(const QModelIndexList &indexes) const
QMimeData * QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
{
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;

QDataStream stream(&encodedData, QIODevice::WriteOnly);
QDataStream stream( &encodedData, QIODevice::WriteOnly );

foreach (const QModelIndex &index, indexes) {
if (index.isValid()) {
foreach( const QModelIndex &index, indexes )
{
if ( index.isValid() )
{
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
if ( ptr->type() != QgsDataItem::Layer ) continue;
QgsLayerItem *layer = ( QgsLayerItem* ) ptr;
QString text = layer->uri();
stream << text;
if ( layer->providerKey() == "wms" ) continue;
QString layerType;
switch ( layer->mapLayerType() )
{
case QgsMapLayer::VectorLayer:
layerType = "vector";
break;
case QgsMapLayer::RasterLayer:
layerType = "raster";
break;
default:
continue;
}
QString xUri = layerType + ":" + layer->providerKey() + ":" + layer->name() + ":" + layer->uri();
stream << xUri;
}
}

mimeData->setData("text/uri-list", encodedData);
mimeData->setData( "application/x-vnd.qgis.qgis.uri", encodedData );
return mimeData;
}

0 comments on commit 9028bf7

Please sign in to comment.
You can’t perform that action at this time.