|
78 | 78 | #include "qgsvectorlayerrenderer.h"
|
79 | 79 | #include "qgsvectorlayerundocommand.h"
|
80 | 80 | #include "qgsvectorlayerfeaturecounter.h"
|
| 81 | +#include "qgsvirtuallayerdefinition.h" |
81 | 82 | #include "qgspoint.h"
|
82 | 83 | #include "qgsrenderer.h"
|
83 | 84 | #include "qgssymbollayer.h"
|
@@ -1833,6 +1834,37 @@ QString QgsVectorLayer::encodedSource( const QString &source, const QgsReadWrite
|
1833 | 1834 | // Refetch the source from the provider, because adding fields actually changes the source for this provider.
|
1834 | 1835 | src = dataProvider()->dataSourceUri();
|
1835 | 1836 | }
|
| 1837 | + else if ( providerType() == QLatin1String( "virtual" ) ) |
| 1838 | + { |
| 1839 | + QUrl urlSource = QUrl::fromEncoded( src.toLatin1() ); |
| 1840 | + QUrl url = QUrl::fromEncoded( src.toLatin1() ); |
| 1841 | + QUrl urlSourceLayer; |
| 1842 | + QStringList theURIParts; |
| 1843 | + |
| 1844 | + QUrlQuery query = QUrlQuery( urlSource.query() ); |
| 1845 | + QList<QPair<QString, QString> > queryItems = query.queryItems(); |
| 1846 | + |
| 1847 | + for ( int i = 0; i < queryItems.size(); i++ ) |
| 1848 | + { |
| 1849 | + QString key = queryItems.at( i ).first; |
| 1850 | + QString value = queryItems.at( i ).second; |
| 1851 | + if ( key == QLatin1String( "layer" ) ) |
| 1852 | + { |
| 1853 | + // syntax: provider:url_encoded_source_URI(:name(:encoding)?)? |
| 1854 | + theURIParts = value.split( ':' ); |
| 1855 | + theURIParts[1] = QUrl::fromPercentEncoding( theURIParts[1].toUtf8() ); |
| 1856 | + theURIParts[1] = context.pathResolver().writePath( theURIParts[1] ); |
| 1857 | + theURIParts[1] = QUrl::toPercentEncoding( theURIParts[1] ); |
| 1858 | + queryItems[i].second = theURIParts.join( QStringLiteral( ":" ) ) ; |
| 1859 | + } |
| 1860 | + } |
| 1861 | + |
| 1862 | + query.setQueryItems( queryItems ); |
| 1863 | + |
| 1864 | + QUrl urlDest = QUrl( urlSource ); |
| 1865 | + urlDest.setQuery( query.query() ); |
| 1866 | + src = QString::fromLatin1( urlDest.toEncoded() ); |
| 1867 | + } |
1836 | 1868 | else
|
1837 | 1869 | {
|
1838 | 1870 | src = context.pathResolver().writePath( src );
|
@@ -1878,6 +1910,37 @@ QString QgsVectorLayer::decodedSource( const QString &source, const QString &pro
|
1878 | 1910 | urlDest.setQueryItems( urlSource.queryItems() );
|
1879 | 1911 | src = QString::fromLatin1( urlDest.toEncoded() );
|
1880 | 1912 | }
|
| 1913 | + else if ( provider == QLatin1String( "virtual" ) ) |
| 1914 | + { |
| 1915 | + QUrl urlSource = QUrl::fromEncoded( src.toLatin1() ); |
| 1916 | + QUrl url = QUrl::fromEncoded( src.toLatin1() ); |
| 1917 | + QUrl urlSourceLayer; |
| 1918 | + QStringList theURIParts; |
| 1919 | + |
| 1920 | + QUrlQuery query = QUrlQuery( urlSource.query() ); |
| 1921 | + QList<QPair<QString, QString> > queryItems = query.queryItems(); |
| 1922 | + |
| 1923 | + for ( int i = 0; i < queryItems.size(); i++ ) |
| 1924 | + { |
| 1925 | + QString key = queryItems.at( i ).first; |
| 1926 | + QString value = queryItems.at( i ).second; |
| 1927 | + if ( key == QLatin1String( "layer" ) ) |
| 1928 | + { |
| 1929 | + // syntax: provider:url_encoded_source_URI(:name(:encoding)?)? |
| 1930 | + theURIParts = value.split( ':' ); |
| 1931 | + theURIParts[1] = QUrl::fromPercentEncoding( theURIParts[1].toUtf8() ); |
| 1932 | + theURIParts[1] = context.pathResolver().readPath( theURIParts[1] ); |
| 1933 | + theURIParts[1] = QUrl::toPercentEncoding( theURIParts[1] ); |
| 1934 | + queryItems[i].second = theURIParts.join( QStringLiteral( ":" ) ) ; |
| 1935 | + } |
| 1936 | + } |
| 1937 | + |
| 1938 | + query.setQueryItems( queryItems ); |
| 1939 | + |
| 1940 | + QUrl urlDest = QUrl( urlSource ); |
| 1941 | + urlDest.setQuery( query.query() ); |
| 1942 | + src = QString::fromLatin1( urlDest.toEncoded() ); |
| 1943 | + } |
1881 | 1944 | else
|
1882 | 1945 | {
|
1883 | 1946 | src = context.pathResolver().readPath( src );
|
|
0 commit comments