26 typedef std::vector< std::pair< QString, std::function< QString(
const QString & ) > > >
CustomResolvers;
30 : mBaseFileName( baseFileName )
40 for (
const auto &resolver : customResolvers )
41 filename = resolver.second( filename );
43 if ( filename.isEmpty() )
46 QString src = filename;
47 if ( src.startsWith( QLatin1String(
"inbuilt:" ) ) )
53 if ( src.startsWith( QLatin1String(
"localized:" ) ) )
59 if ( mBaseFileName.isNull() )
66 if ( ! vsiPrefix.isEmpty() )
70 if ( src.startsWith( QLatin1String(
"/vsi" ), Qt::CaseInsensitive ) )
71 src.remove( 0, vsiPrefix.size() );
77 if ( !src.startsWith( QLatin1String(
"./" ) ) && !src.startsWith( QLatin1String(
"../" ) ) )
80 if ( src.startsWith(
"\\\\" ) ||
81 src.startsWith(
"//" ) ||
82 ( src[0].isLetter() && src[1] ==
':' ) )
85 return vsiPrefix + src;
91 return vsiPrefix + src;
100 QFileInfo pfi( mBaseFileName );
101 QString home = pfi.absolutePath();
102 if ( home.isEmpty() )
103 return vsiPrefix + src;
105 QFileInfo fi( home +
'/' + src );
109 return vsiPrefix + src;
113 return vsiPrefix + fi.canonicalFilePath();
117 QString srcPath = src;
118 QString projPath = mBaseFileName;
120 if ( projPath.isEmpty() )
122 return vsiPrefix + src;
125 #if defined(Q_OS_WIN)
126 srcPath.replace(
'\\',
'/' );
127 projPath.replace(
'\\',
'/' );
129 bool uncPath = projPath.startsWith(
"//" );
133 projPath = QFileInfo( projPath ).absoluteFilePath();
135 QStringList srcElems = srcPath.split(
'/', QString::SkipEmptyParts );
136 QStringList projElems = projPath.split(
'/', QString::SkipEmptyParts );
138 #if defined(Q_OS_WIN)
141 projElems.insert( 0,
"" );
142 projElems.insert( 0,
"" );
147 projElems.removeLast();
150 projElems << srcElems;
151 projElems.removeAll( QStringLiteral(
"." ) );
155 while ( ( pos = projElems.indexOf( QStringLiteral(
".." ) ) ) > 0 )
158 projElems.removeAt( pos - 1 );
159 projElems.removeAt( pos - 1 );
162 #if !defined(Q_OS_WIN)
164 projElems.prepend( QString() );
167 return vsiPrefix + projElems.join( QStringLiteral(
"/" ) );
172 QString
id = QUuid::createUuid().toString();
173 sCustomResolvers()->emplace_back( std::make_pair(
id, processor ) );
179 const size_t prevCount = sCustomResolvers()->size();
180 sCustomResolvers()->erase( std::remove_if( sCustomResolvers()->begin(), sCustomResolvers()->end(), [
id]( std::pair< QString, std::function< QString(
const QString & ) > > &a )
182 return a.first == id;
183 } ), sCustomResolvers()->end() );
184 return prevCount != sCustomResolvers()->size();
195 if ( !localizedPath.isEmpty() )
196 return QStringLiteral(
"localized:" ) + localizedPath;
204 if ( mBaseFileName.isEmpty() )
210 QFileInfo pfi( QFileInfo( mBaseFileName ).path() );
211 QString projPath = pfi.canonicalFilePath();
215 if ( projPath.isEmpty() )
216 projPath = pfi.absoluteFilePath();
218 if ( projPath.isEmpty() )
225 QString srcPath { src };
228 if ( url.isLocalFile( ) )
230 srcPath = url.path();
231 urlQuery = url.query();
234 QFileInfo srcFileInfo( srcPath );
235 if ( srcFileInfo.exists() )
236 srcPath = srcFileInfo.canonicalFilePath();
240 if ( ! vsiPrefix.isEmpty() )
242 srcPath.remove( 0, vsiPrefix.size() );
245 #if defined( Q_OS_WIN )
246 const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
248 srcPath.replace(
'\\',
'/' );
250 if ( srcPath.startsWith(
"//" ) )
253 srcPath =
"\\\\" + srcPath.mid( 2 );
256 projPath.replace(
'\\',
'/' );
257 if ( projPath.startsWith(
"//" ) )
260 projPath =
"\\\\" + projPath.mid( 2 );
263 const Qt::CaseSensitivity cs = Qt::CaseSensitive;
266 QStringList projElems = projPath.split(
'/', QString::SkipEmptyParts );
267 QStringList srcElems = srcPath.split(
'/', QString::SkipEmptyParts );
269 projElems.removeAll( QStringLiteral(
"." ) );
270 srcElems.removeAll( QStringLiteral(
"." ) );
274 while ( !srcElems.isEmpty() &&
275 !projElems.isEmpty() &&
276 srcElems[0].compare( projElems[0], cs ) == 0 )
278 srcElems.removeFirst();
279 projElems.removeFirst();
289 if ( !projElems.isEmpty() )
292 for (
int i = 0; i < projElems.size(); i++ )
294 srcElems.insert( 0, QStringLiteral(
".." ) );
301 srcElems.insert( 0, QStringLiteral(
"." ) );
305 QString returnPath { vsiPrefix + srcElems.join( QStringLiteral(
"/" ) ) };
306 if ( ! urlQuery.isEmpty() )
308 returnPath.append(
'?' );
309 returnPath.append( urlQuery );