25 : mBaseFileName( baseFileName )
32 if ( filename.isEmpty() )
35 QString src = filename;
37 if ( mBaseFileName.isNull() )
44 if ( ! vsiPrefix.isEmpty() )
48 if ( src.startsWith( QLatin1String(
"/vsi" ), Qt::CaseInsensitive ) )
49 src.remove( 0, vsiPrefix.size() );
55 if ( !src.startsWith( QLatin1String(
"./" ) ) && !src.startsWith( QLatin1String(
"../" ) ) )
58 if ( src.startsWith(
"\\\\" ) ||
59 src.startsWith(
"//" ) ||
60 ( src[0].isLetter() && src[1] ==
':' ) )
63 return vsiPrefix + src;
69 return vsiPrefix + src;
78 QFileInfo pfi( mBaseFileName );
79 QString home = pfi.absolutePath();
81 return vsiPrefix + src;
83 QFileInfo fi( home +
'/' + src );
87 return vsiPrefix + src;
91 return vsiPrefix + fi.canonicalFilePath();
95 QString srcPath = src;
96 QString projPath = mBaseFileName;
98 if ( projPath.isEmpty() )
100 return vsiPrefix + src;
103 #if defined(Q_OS_WIN) 104 srcPath.replace(
'\\',
'/' );
105 projPath.replace(
'\\',
'/' );
107 bool uncPath = projPath.startsWith(
"//" );
110 QStringList srcElems = srcPath.split(
'/', QString::SkipEmptyParts );
111 QStringList projElems = projPath.split(
'/', QString::SkipEmptyParts );
113 #if defined(Q_OS_WIN) 116 projElems.insert( 0,
"" );
117 projElems.insert( 0,
"" );
122 projElems.removeLast();
125 projElems << srcElems;
126 projElems.removeAll( QStringLiteral(
"." ) );
130 while ( ( pos = projElems.indexOf( QStringLiteral(
".." ) ) ) > 0 )
133 projElems.removeAt( pos - 1 );
134 projElems.removeAt( pos - 1 );
137 #if !defined(Q_OS_WIN) 139 projElems.prepend( QString() );
142 return vsiPrefix + projElems.join( QStringLiteral(
"/" ) );
148 if ( mBaseFileName.isEmpty() || src.isEmpty() )
154 QFileInfo pfi( QFileInfo( mBaseFileName ).path() );
155 QString projPath = pfi.canonicalFilePath();
159 if ( projPath.isEmpty() )
160 projPath = pfi.absoluteFilePath();
162 if ( projPath.isEmpty() )
169 QString srcPath { src };
172 if ( url.isLocalFile( ) )
174 srcPath = url.path();
175 urlQuery = url.query();
178 QFileInfo srcFileInfo( srcPath );
179 if ( srcFileInfo.exists() )
180 srcPath = srcFileInfo.canonicalFilePath();
184 if ( ! vsiPrefix.isEmpty() )
186 srcPath.remove( 0, vsiPrefix.size() );
189 #if defined( Q_OS_WIN ) 190 const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
192 srcPath.replace(
'\\',
'/' );
194 if ( srcPath.startsWith(
"//" ) )
197 srcPath =
"\\\\" + srcPath.mid( 2 );
200 projPath.replace(
'\\',
'/' );
201 if ( projPath.startsWith(
"//" ) )
204 projPath =
"\\\\" + projPath.mid( 2 );
207 const Qt::CaseSensitivity cs = Qt::CaseSensitive;
210 QStringList projElems = projPath.split(
'/', QString::SkipEmptyParts );
211 QStringList srcElems = srcPath.split(
'/', QString::SkipEmptyParts );
213 projElems.removeAll( QStringLiteral(
"." ) );
214 srcElems.removeAll( QStringLiteral(
"." ) );
218 while ( !srcElems.isEmpty() &&
219 !projElems.isEmpty() &&
220 srcElems[0].compare( projElems[0], cs ) == 0 )
222 srcElems.removeFirst();
223 projElems.removeFirst();
233 if ( !projElems.isEmpty() )
236 for (
int i = 0; i < projElems.size(); i++ )
238 srcElems.insert( 0, QStringLiteral(
".." ) );
245 srcElems.insert( 0, QStringLiteral(
"." ) );
249 QString returnPath { vsiPrefix + srcElems.join( QStringLiteral(
"/" ) ) };
250 if ( ! urlQuery.isEmpty() )
252 returnPath.append(
'?' );
253 returnPath.append( urlQuery );
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
QString qgsVsiPrefix(const QString &path)
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
QgsPathResolver(const QString &baseFileName=QString())
Initialize path resolver with a base filename. Null filename means no conversion between relative/abs...