24 : mBaseFileName( baseFileName )
31 if ( filename.isEmpty() )
34 QString src = filename;
36 if ( mBaseFileName.isNull() )
43 if ( ! vsiPrefix.isEmpty() )
47 if ( src.startsWith( QLatin1String(
"/vsi" ), Qt::CaseInsensitive ) )
48 src.remove( 0, vsiPrefix.size() );
54 if ( !src.startsWith( QLatin1String(
"./" ) ) && !src.startsWith( QLatin1String(
"../" ) ) )
57 if ( src.startsWith(
"\\\\" ) ||
58 src.startsWith(
"//" ) ||
59 ( src[0].isLetter() && src[1] ==
':' ) )
62 return vsiPrefix + src;
68 return vsiPrefix + src;
77 QFileInfo pfi( mBaseFileName );
78 QString home = pfi.absolutePath();
80 return vsiPrefix + src;
82 QFileInfo fi( home +
'/' + src );
86 return vsiPrefix + src;
90 return vsiPrefix + fi.canonicalFilePath();
94 QString srcPath = src;
95 QString projPath = mBaseFileName;
97 if ( projPath.isEmpty() )
99 return vsiPrefix + src;
102 #if defined(Q_OS_WIN) 103 srcPath.replace(
'\\',
'/' );
104 projPath.replace(
'\\',
'/' );
106 bool uncPath = projPath.startsWith(
"//" );
109 QStringList srcElems = srcPath.split(
'/', QString::SkipEmptyParts );
110 QStringList projElems = projPath.split(
'/', QString::SkipEmptyParts );
112 #if defined(Q_OS_WIN) 115 projElems.insert( 0,
"" );
116 projElems.insert( 0,
"" );
121 projElems.removeLast();
124 projElems << srcElems;
125 projElems.removeAll( QStringLiteral(
"." ) );
129 while ( ( pos = projElems.indexOf( QStringLiteral(
".." ) ) ) > 0 )
132 projElems.removeAt( pos - 1 );
133 projElems.removeAt( pos - 1 );
136 #if !defined(Q_OS_WIN) 138 projElems.prepend( QString() );
141 return vsiPrefix + projElems.join( QStringLiteral(
"/" ) );
147 if ( mBaseFileName.isEmpty() || src.isEmpty() )
153 QFileInfo pfi( QFileInfo( mBaseFileName ).path() );
154 QString projPath = pfi.canonicalFilePath();
158 if ( projPath.isEmpty() )
159 projPath = pfi.absoluteFilePath();
161 if ( projPath.isEmpty() )
167 QFileInfo srcFileInfo( src.startsWith( QStringLiteral(
"file://" ) ) ? src.mid( 7 ) : src );
168 QString srcPath = srcFileInfo.exists() ? srcFileInfo.canonicalFilePath() : src;
172 if ( ! vsiPrefix.isEmpty() )
174 srcPath.remove( 0, vsiPrefix.size() );
177 #if defined( Q_OS_WIN ) 178 const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
180 srcPath.replace(
'\\',
'/' );
182 if ( srcPath.startsWith(
"//" ) )
185 srcPath =
"\\\\" + srcPath.mid( 2 );
188 projPath.replace(
'\\',
'/' );
189 if ( projPath.startsWith(
"//" ) )
192 projPath =
"\\\\" + projPath.mid( 2 );
195 const Qt::CaseSensitivity cs = Qt::CaseSensitive;
198 QStringList projElems = projPath.split(
'/', QString::SkipEmptyParts );
199 QStringList srcElems = srcPath.split(
'/', QString::SkipEmptyParts );
201 projElems.removeAll( QStringLiteral(
"." ) );
202 srcElems.removeAll( QStringLiteral(
"." ) );
206 while ( !srcElems.isEmpty() &&
207 !projElems.isEmpty() &&
208 srcElems[0].compare( projElems[0], cs ) == 0 )
210 srcElems.removeFirst();
211 projElems.removeFirst();
221 if ( !projElems.isEmpty() )
224 for (
int i = 0; i < projElems.size(); i++ )
226 srcElems.insert( 0, QStringLiteral(
".." ) );
233 srcElems.insert( 0, QStringLiteral(
"." ) );
236 return vsiPrefix + srcElems.join( QStringLiteral(
"/" ) );
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
QString qgsVsiPrefix(const QString &path)
QgsPathResolver(const QString &baseFileName=QString())
Initialize path resolver with a base filename. Null filename means no conversion between relative/abs...