|
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"
|
@@ -1817,6 +1818,37 @@ QString QgsVectorLayer::encodedSource( const QString &source, const QgsReadWrite
|
1817 | 1818 | // Refetch the source from the provider, because adding fields actually changes the source for this provider.
|
1818 | 1819 | src = dataProvider()->dataSourceUri();
|
1819 | 1820 | }
|
| 1821 | + else if ( providerType() == QLatin1String( "virtual" ) ) |
| 1822 | + { |
| 1823 | + QUrl urlSource = QUrl::fromEncoded( src.toLatin1() ); |
| 1824 | + QUrl url = QUrl::fromEncoded( src.toLatin1() ); |
| 1825 | + QUrl urlSourceLayer; |
| 1826 | + QStringList theURIParts; |
| 1827 | + |
| 1828 | + QUrlQuery query = QUrlQuery( urlSource.query() ); |
| 1829 | + QList<QPair<QString, QString> > queryItems = query.queryItems(); |
| 1830 | + |
| 1831 | + for ( int i = 0; i < queryItems.size(); i++ ) |
| 1832 | + { |
| 1833 | + QString key = queryItems.at( i ).first; |
| 1834 | + QString value = queryItems.at( i ).second; |
| 1835 | + if ( key == QLatin1String( "layer" ) ) |
| 1836 | + { |
| 1837 | + // syntax: provider:url_encoded_source_URI(:name(:encoding)?)? |
| 1838 | + theURIParts = value.split( ':' ); |
| 1839 | + theURIParts[1] = QUrl::fromPercentEncoding( theURIParts[1].toUtf8() ); |
| 1840 | + theURIParts[1] = context.pathResolver().writePath( theURIParts[1] ); |
| 1841 | + theURIParts[1] = QUrl::toPercentEncoding( theURIParts[1] ); |
| 1842 | + queryItems[i].second = theURIParts.join( QStringLiteral( ":" ) ) ; |
| 1843 | + } |
| 1844 | + } |
| 1845 | + |
| 1846 | + query.setQueryItems( queryItems ); |
| 1847 | + |
| 1848 | + QUrl urlDest = QUrl( urlSource ); |
| 1849 | + urlDest.setQuery( query.query() ); |
| 1850 | + src = QString::fromLatin1( urlDest.toEncoded() ); |
| 1851 | + } |
1820 | 1852 | else
|
1821 | 1853 | {
|
1822 | 1854 | src = context.pathResolver().writePath( src );
|
@@ -1862,6 +1894,37 @@ QString QgsVectorLayer::decodedSource( const QString &source, const QString &pro
|
1862 | 1894 | urlDest.setQueryItems( urlSource.queryItems() );
|
1863 | 1895 | src = QString::fromLatin1( urlDest.toEncoded() );
|
1864 | 1896 | }
|
| 1897 | + else if ( provider == QLatin1String( "virtual" ) ) |
| 1898 | + { |
| 1899 | + QUrl urlSource = QUrl::fromEncoded( src.toLatin1() ); |
| 1900 | + QUrl url = QUrl::fromEncoded( src.toLatin1() ); |
| 1901 | + QUrl urlSourceLayer; |
| 1902 | + QStringList theURIParts; |
| 1903 | + |
| 1904 | + QUrlQuery query = QUrlQuery( urlSource.query() ); |
| 1905 | + QList<QPair<QString, QString> > queryItems = query.queryItems(); |
| 1906 | + |
| 1907 | + for ( int i = 0; i < queryItems.size(); i++ ) |
| 1908 | + { |
| 1909 | + QString key = queryItems.at( i ).first; |
| 1910 | + QString value = queryItems.at( i ).second; |
| 1911 | + if ( key == QLatin1String( "layer" ) ) |
| 1912 | + { |
| 1913 | + // syntax: provider:url_encoded_source_URI(:name(:encoding)?)? |
| 1914 | + theURIParts = value.split( ':' ); |
| 1915 | + theURIParts[1] = QUrl::fromPercentEncoding( theURIParts[1].toUtf8() ); |
| 1916 | + theURIParts[1] = context.pathResolver().readPath( theURIParts[1] ); |
| 1917 | + theURIParts[1] = QUrl::toPercentEncoding( theURIParts[1] ); |
| 1918 | + queryItems[i].second = theURIParts.join( QStringLiteral( ":" ) ) ; |
| 1919 | + } |
| 1920 | + } |
| 1921 | + |
| 1922 | + query.setQueryItems( queryItems ); |
| 1923 | + |
| 1924 | + QUrl urlDest = QUrl( urlSource ); |
| 1925 | + urlDest.setQuery( query.query() ); |
| 1926 | + src = QString::fromLatin1( urlDest.toEncoded() ); |
| 1927 | + } |
1865 | 1928 | else
|
1866 | 1929 | {
|
1867 | 1930 | src = context.pathResolver().readPath( src );
|
|
0 commit comments