24 : mBaseFileName( baseFileName )
31 QString src = filename;
33 if ( mBaseFileName.isNull() )
40 if ( ! vsiPrefix.isEmpty() )
44 if ( src.startsWith( QLatin1String(
"/vsi" ), Qt::CaseInsensitive ) )
45 src.remove( 0, vsiPrefix.size() );
51 if ( !src.startsWith( QLatin1String(
"./" ) ) && !src.startsWith( QLatin1String(
"../" ) ) )
54 if ( src.startsWith(
"\\\\" ) ||
55 src.startsWith(
"//" ) ||
56 ( src[0].isLetter() && src[1] ==
':' ) )
59 return vsiPrefix + src;
65 return vsiPrefix + src;
74 QFileInfo pfi( mBaseFileName );
75 QString home = pfi.absolutePath();
77 return vsiPrefix + src;
79 QFileInfo fi( home +
'/' + src );
83 return vsiPrefix + src;
87 return vsiPrefix + fi.canonicalFilePath();
91 QString srcPath = src;
92 QString projPath = mBaseFileName;
94 if ( projPath.isEmpty() )
96 return vsiPrefix + src;
100 srcPath.replace(
'\\',
'/' );
101 projPath.replace(
'\\',
'/' );
103 bool uncPath = projPath.startsWith(
"//" );
106 QStringList srcElems = srcPath.split(
'/', QString::SkipEmptyParts );
107 QStringList projElems = projPath.split(
'/', QString::SkipEmptyParts );
109 #if defined(Q_OS_WIN) 112 projElems.insert( 0,
"" );
113 projElems.insert( 0,
"" );
118 projElems.removeLast();
121 projElems << srcElems;
122 projElems.removeAll( QStringLiteral(
"." ) );
126 while ( ( pos = projElems.indexOf( QStringLiteral(
".." ) ) ) > 0 )
129 projElems.removeAt( pos - 1 );
130 projElems.removeAt( pos - 1 );
133 #if !defined(Q_OS_WIN) 135 projElems.prepend( QLatin1String(
"" ) );
138 return vsiPrefix + projElems.join( QStringLiteral(
"/" ) );
144 if ( mBaseFileName.isEmpty() || src.isEmpty() )
150 QFileInfo pfi( QFileInfo( mBaseFileName ).path() );
151 QString projPath = pfi.canonicalFilePath();
155 if ( projPath.isEmpty() )
156 projPath = pfi.absoluteFilePath();
158 if ( projPath.isEmpty() )
163 QFileInfo srcFileInfo( src );
164 QString srcPath = srcFileInfo.exists() ? srcFileInfo.canonicalFilePath() : src;
168 if ( ! vsiPrefix.isEmpty() )
170 srcPath.remove( 0, vsiPrefix.size() );
173 #if defined( Q_OS_WIN ) 174 const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
176 srcPath.replace(
'\\',
'/' );
178 if ( srcPath.startsWith(
"//" ) )
181 srcPath =
"\\\\" + srcPath.mid( 2 );
184 projPath.replace(
'\\',
'/' );
185 if ( projPath.startsWith(
"//" ) )
188 projPath =
"\\\\" + projPath.mid( 2 );
191 const Qt::CaseSensitivity cs = Qt::CaseSensitive;
194 QStringList projElems = projPath.split(
'/', QString::SkipEmptyParts );
195 QStringList srcElems = srcPath.split(
'/', QString::SkipEmptyParts );
197 projElems.removeAll( QStringLiteral(
"." ) );
198 srcElems.removeAll( QStringLiteral(
"." ) );
202 while ( !srcElems.isEmpty() &&
203 !projElems.isEmpty() &&
204 srcElems[0].compare( projElems[0], cs ) == 0 )
206 srcElems.removeFirst();
207 projElems.removeFirst();
217 if ( !projElems.isEmpty() )
220 for (
int i = 0; i < projElems.size(); i++ )
222 srcElems.insert( 0, QStringLiteral(
".." ) );
229 srcElems.insert( 0, QStringLiteral(
"." ) );
232 return vsiPrefix + srcElems.join( QStringLiteral(
"/" ) );
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...