From e6b744fb4be6e975f0336a86bd1a0cd5c60cd85e Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 10 Jun 2011 11:48:16 +0200 Subject: simplify relative path generation instead of hand-crafting the logic, simply use QDir::relativeFilePath() Change-Id: I5a495ad6bdfa8ec126741180770934e7ebee0495 Reviewed-on: http://codereview.qt.nokia.com/512 Reviewed-by: Qt Sanity Bot Reviewed-by: Olivier Goffart --- src/tools/moc/main.cpp | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) (limited to 'src/tools') diff --git a/src/tools/moc/main.cpp b/src/tools/moc/main.cpp index 41a3a4fc93..eaafd0a9fd 100644 --- a/src/tools/moc/main.cpp +++ b/src/tools/moc/main.cpp @@ -67,34 +67,7 @@ static QByteArray combinePath(const char *infile, const char *outfile) { QFileInfo inFileInfo(QDir::current(), QFile::decodeName(infile)); QFileInfo outFileInfo(QDir::current(), QFile::decodeName(outfile)); - int numCommonComponents = 0; - - QStringList inSplitted = inFileInfo.dir().canonicalPath().split(QLatin1Char('/')); - QStringList outSplitted = outFileInfo.dir().canonicalPath().split(QLatin1Char('/')); - - while (!inSplitted.isEmpty() && !outSplitted.isEmpty() && - inSplitted.first() == outSplitted.first()) { - inSplitted.removeFirst(); - outSplitted.removeFirst(); - numCommonComponents++; - } - - if (numCommonComponents < 2) - /* - The paths don't have the same drive, or they don't have the - same root directory. Use an absolute path. - */ - return QFile::encodeName(inFileInfo.absoluteFilePath()); - /* - The paths have something in common. Use a path relative to - the output file. - */ - while (!outSplitted.isEmpty()) { - outSplitted.removeFirst(); - inSplitted.prepend(QLatin1String("..")); - } - inSplitted.append(inFileInfo.fileName()); - return QFile::encodeName(inSplitted.join(QLatin1String("/"))); + return QFile::encodeName(outFileInfo.dir().relativeFilePath(inFileInfo.filePath())); } -- cgit v1.2.3