-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAUTRE] Import of vectors to SpatiaLite in browser + move MIME type…
… stuff to a separate file
- Loading branch information
Showing
10 changed files
with
246 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "qgsmimedatautils.h" | ||
|
||
#include "qgsdataitem.h" | ||
#include "qgslogger.h" | ||
|
||
static const char* QGIS_URILIST_MIMETYPE = "application/x-vnd.qgis.qgis.uri"; | ||
|
||
QgsMimeDataUtils::Uri::Uri( QgsLayerItem* layerItem ) | ||
: providerKey( layerItem->providerKey() ), name( layerItem->name() ), uri( layerItem->uri() ) | ||
{ | ||
switch ( layerItem->mapLayerType() ) | ||
{ | ||
case QgsMapLayer::VectorLayer: | ||
layerType = "vector"; | ||
break; | ||
case QgsMapLayer::RasterLayer: | ||
layerType = "raster"; | ||
break; | ||
} | ||
|
||
} | ||
|
||
QgsMimeDataUtils::Uri::Uri( QString& encData ) | ||
{ | ||
QRegExp rx( "^([^:]+):([^:]+):([^:]+):(.+)" ); | ||
if ( rx.indexIn( encData ) != -1 ) | ||
{ | ||
layerType = rx.cap( 1 ); | ||
providerKey = rx.cap( 2 ); | ||
name = rx.cap( 3 ); | ||
uri = rx.cap( 4 ); | ||
QgsDebugMsg( "type: " + layerType + " key: " + providerKey + " name: " + name + " uri: " + uri ); | ||
} | ||
} | ||
|
||
QString QgsMimeDataUtils::Uri::data() const | ||
{ | ||
return layerType + ":" + providerKey + ":" + name + ":" + uri; | ||
} | ||
|
||
// ----- | ||
|
||
bool QgsMimeDataUtils::isUriList( const QMimeData* data ) | ||
{ | ||
return data->hasFormat( QGIS_URILIST_MIMETYPE ); | ||
} | ||
|
||
QMimeData* QgsMimeDataUtils::encodeUriList( QgsMimeDataUtils::UriList layers ) | ||
{ | ||
QMimeData *mimeData = new QMimeData(); | ||
QByteArray encodedData; | ||
|
||
QDataStream stream( &encodedData, QIODevice::WriteOnly ); | ||
foreach( const QgsMimeDataUtils::Uri& u, layers ) | ||
{ | ||
stream << u.data(); | ||
} | ||
|
||
mimeData->setData( QGIS_URILIST_MIMETYPE, encodedData ); | ||
return mimeData; | ||
} | ||
|
||
|
||
QgsMimeDataUtils::UriList QgsMimeDataUtils::decodeUriList( const QMimeData* data ) | ||
{ | ||
QByteArray encodedData = data->data( QGIS_URILIST_MIMETYPE ); | ||
QDataStream stream( &encodedData, QIODevice::ReadOnly ); | ||
QString xUri; // extended uri: layer_type:provider_key:uri | ||
QgsMimeDataUtils::UriList list; | ||
while ( !stream.atEnd() ) | ||
{ | ||
stream >> xUri; | ||
QgsDebugMsg( xUri ); | ||
list.append( QgsMimeDataUtils::Uri( xUri ) ); | ||
} | ||
return list; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef QGSMIMEDATAUTILS_H | ||
#define QGSMIMEDATAUTILS_H | ||
|
||
#include <QMimeData> | ||
|
||
class QgsLayerItem; | ||
|
||
class QgsMimeDataUtils | ||
{ | ||
public: | ||
|
||
struct Uri | ||
{ | ||
Uri( QgsLayerItem* layer ); | ||
Uri( QString& encData ); | ||
|
||
QString data() const; | ||
|
||
QString layerType; | ||
QString providerKey; | ||
QString name; | ||
QString uri; | ||
}; | ||
typedef QList<Uri> UriList; | ||
|
||
static QMimeData* encodeUriList( UriList layers ); | ||
|
||
static bool isUriList( const QMimeData* data ); | ||
|
||
static UriList decodeUriList( const QMimeData* data ); | ||
|
||
}; | ||
|
||
#endif // QGSMIMEDATAUTILS_H |
Oops, something went wrong.