Skip to content
Permalink
Browse files

Re-write MimeData Uri concat and split function to deal with layer na…

…mes and urls that contain the ':' character
  • Loading branch information
palmerj committed Jul 14, 2013
1 parent 2db4f35 commit 731ac4f141d5e468404685d88bbcd90c7cdb80ac
Showing with 39 additions and 7 deletions.
  1. +39 −7 src/core/qgsmimedatautils.cpp
@@ -12,6 +12,8 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include <QStringList>

#include "qgsmimedatautils.h"

#include "qgsdataitem.h"
@@ -39,20 +41,50 @@ QgsMimeDataUtils::Uri::Uri( QgsLayerItem* layerItem )

QgsMimeDataUtils::Uri::Uri( QString& encData )
{
QRegExp rx( "^([^:]+):([^:]+):([^:]+):(.+)" );
if ( rx.indexIn( encData ) != -1 )
QStringList parts;
QChar split = ':';
QChar escape = '\\';
QString part;
bool inEscape = false;
for (int i = 0; i < encData.length(); ++i)
{
if (encData.at(i) == escape && !inEscape)
{
inEscape = true;
}
else if (encData.at(i) == split && !inEscape)
{
parts << part;
part = "";
}
else
{
part += encData.at(i);
inEscape = false;
}
}
if (!part.isEmpty())
{
parts << part;
}

if ( parts.size() == 4 )
{
layerType = rx.cap( 1 );
providerKey = rx.cap( 2 );
name = rx.cap( 3 );
uri = rx.cap( 4 );
layerType = parts[0];
providerKey = parts[1];
name = parts[2];
uri = parts[3];
QgsDebugMsg( "type: " + layerType + " key: " + providerKey + " name: " + name + " uri: " + uri );
}
}

QString QgsMimeDataUtils::Uri::data() const
{
return layerType + ":" + providerKey + ":" + name + ":" + uri;
QString escapedName = name;
QString escapeUri = uri;
escapedName.replace(":", "\\:");
escapeUri.replace(":", "\\:");
return layerType + ":" + providerKey + ":" + escapedName + ":" + escapeUri;
}

// -----

0 comments on commit 731ac4f

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