QString QgsProject::homePath() const { QFileInfo pfi( fileName() ); if ( !pfi.exists() ) return QString::null; return pfi.canonicalPath(); }
void QgsSymbol::setNamedPointSymbol( QString name ) { if ( name.startsWith( "svg:" ) ) { // do some sanity checking for svgs... QString myTempName = name; myTempName.replace( "svg:", "" ); QFile myFile( myTempName ); if ( !myFile.exists() ) { QgsDebugMsg( "\n\n\n *** Svg Symbol not found on fs ***" ); QgsDebugMsg( "Name: " + name ); //see if we can resolve the problem... // QStringList svgPaths = QgsApplication::svgPaths(); for ( int i = 0; i < svgPaths.size(); i++ ) { QgsDebugMsg( "SvgPath: " + svgPaths[i] ); QFileInfo myInfo( myTempName ); QString myFileName = myInfo.fileName(); // foo.svg QString myLowestDir = myInfo.dir().dirName(); QString myLocalPath = svgPaths[i] + "/" + myLowestDir + "/" + myFileName; QgsDebugMsg( "Alternative svg path: " + myLocalPath ); if ( QFile( myLocalPath ).exists() ) { name = "svg:" + myLocalPath; QgsDebugMsg( "Svg found in alternative path" ); } else if ( myInfo.isRelative() ) { QFileInfo pfi( QgsProject::instance()->fileName() ); if ( pfi.exists() && QFile( pfi.canonicalPath() + QDir::separator() + myTempName ).exists() ) { name = "svg:" + pfi.canonicalPath() + QDir::separator() + myTempName; QgsDebugMsg( "Svg found in alternative path" ); break; } else { QgsDebugMsg( "Svg not found in project path" ); } } else { //couldnt find the file, no happy ending :-( QgsDebugMsg( "Computed alternate path but no svg there either" ); } } } } mPointSymbolName = name; mCacheUpToDate = mCacheUpToDate2 = false; }
int main() { pfd(2.0); CHECK_GOOD(3); pfi(2); CHECK_GOOD(3+4); rfi(2); CHECK_GOOD(3+4+4); rfd(2.0); CHECK_GOOD(3+4+4+3); return errors != 0; }
void UmlArtifact::gen_app(const Q3CString & path) { Q3CString target; Q3CString pro; propertyValue("genpro target", target); propertyValue("genpro pro", pro); if (target.isEmpty()) { if ((target = name()) == "executable") target = UmlPackage::getProject()->name(); #ifdef WIN32 target += ".exe"; #endif } if (pro.isEmpty()) { pro = target; #ifdef WIN32 if (pro.right(4) == ".exe") pro.resize(pro.length() - 4); #endif QDir d(path); pro = d.absFilePath(pro + ".pro"); } Q3CString tmplt; Q3CString config; Q3CString defines; Q3CString includepath; Q3CString dependpath; Q3CString objectsdir; Q3CString footer; if (!propertyValue("genpro tmplt", tmplt)) tmplt = "app"; if (!propertyValue("genpro config", config)) config = "debug warn_on qt"; if (!propertyValue("genpro defines", defines)) defines = "WITHCPP WITHJAVA WITHPHP WITHPYTHON WITHIDL"; else if (defines.find("WITHPHP") == -1) { int n = 0; if (defines.find("WITHCPP") != -1) n += 1; if (defines.find("WITHJAVA") != -1) n += 1; if (defines.find("WITHIDL") != -1) n += 1; if (n > 1) defines += " WITHPHP WITHPYTHON"; } else if (defines.find("WITHPYTHON") == -1) { int n = 0; if (defines.find("WITHCPP") != -1) n += 1; if (defines.find("WITHJAVA") != -1) n += 1; if (defines.find("WITHIDL") != -1) n += 1; if (defines.find("WITHPHP") != -1) n += 1; if (n > 1) defines += " WITHPYTHON"; } propertyValue("genpro includepath", includepath); propertyValue("genpro dependpath", dependpath); propertyValue("genpro objectsdir", objectsdir); propertyValue("genpro footer", footer); for (;;) { Dialog dialog(this, path, pro, target, tmplt, config, defines, includepath, dependpath, objectsdir, footer); if (dialog.exec() != QDialog::Accepted) return; set_PropertyValue("genpro pro", pro); set_PropertyValue("genpro path", path); set_PropertyValue("genpro target", target); set_PropertyValue("genpro tmplt", tmplt); set_PropertyValue("genpro config", config); set_PropertyValue("genpro defines", defines); set_PropertyValue("genpro includepath", includepath); set_PropertyValue("genpro dependpath", dependpath); set_PropertyValue("genpro objectsdir", objectsdir); set_PropertyValue("genpro footer", footer); QFile f(pro); if (! f.open(QIODevice::WriteOnly)) QMessageBox::critical((QWidget *) 0, "Error", "Cannot open " + QString(pro)); else { Q3TextStream t(&f); QFileInfo tfi(target); QFileInfo pfi(pro); t << "TEMPLATE\t= " << tmplt << '\n'; t << "TARGET\t\t= " << tfi.fileName() << '\n'; if ((target.find('/') != -1) && (pro.find('/') != -1) && (tfi.dirPath(TRUE) != pfi.dirPath(TRUE))) t << "DESTDIR\t\t= " << tfi.dirPath(TRUE) << '\n'; if (! objectsdir.isEmpty()) t << "OBJECTS_DIR\t= " << objectsdir << '\n'; t << "CONFIG\t\t+= " << config << '\n'; if (!includepath.isEmpty()) t << "INCLUDEPATH\t= " << includepath << '\n'; if (!dependpath.isEmpty()) t << "DEPENDPATH\t= " << dependpath << '\n'; if (!defines.isEmpty()) t << "DEFINES\t\t= " << defines << '\n'; QString prodir = pfi.dirPath(TRUE); const Q3PtrVector<UmlArtifact> & arts = associatedArtifacts(); unsigned index; const char * sep; Q3CString ext; ext = CppSettings::headerExtension(); sep = "HEADERS\t\t= "; for (index = 0; index != arts.count(); index += 1) { UmlArtifact * art = arts[index]; if ((art->stereotype() == "source") && !art->cppHeader().isEmpty()) { QString s = art->way(prodir, TRUE); if (! s.isEmpty()) { t << sep << s << art->name() << '.' << ext; sep = " \\\n\t\t "; } } } t << '\n'; ext = CppSettings::sourceExtension(); sep = "SOURCES\t\t= "; for (index = 0; index != arts.count(); index += 1) { UmlArtifact * art = arts[index]; if ((art->stereotype() != "source") || !art->cppSource().isEmpty()) { QString s = art->way(prodir, FALSE); if (! s.isEmpty()) { t << sep << s << art->name(); if (art->stereotype() == "source") t << '.' << ext; sep = " \\\n\t\t "; } } } t << '\n' << footer << '\n'; f.close(); return; } } }
QString QgsPathResolver::readPath( const QString &filename ) const { QString src = filename; if ( mBaseFileName.isNull() ) { return src; } // if this is a VSIFILE, remove the VSI prefix and append to final result QString vsiPrefix = qgsVsiPrefix( src ); if ( ! vsiPrefix.isEmpty() ) { // unfortunately qgsVsiPrefix returns prefix also for files like "/x/y/z.gz" // so we need to check if we really have the prefix if ( src.startsWith( QLatin1String( "/vsi" ), Qt::CaseInsensitive ) ) src.remove( 0, vsiPrefix.size() ); else vsiPrefix.clear(); } // relative path should always start with ./ or ../ if ( !src.startsWith( QLatin1String( "./" ) ) && !src.startsWith( QLatin1String( "../" ) ) ) { #if defined(Q_OS_WIN) if ( src.startsWith( "\\\\" ) || src.startsWith( "//" ) || ( src[0].isLetter() && src[1] == ':' ) ) { // UNC or absolute path return vsiPrefix + src; } #else if ( src[0] == '/' ) { // absolute path return vsiPrefix + src; } #endif // so this one isn't absolute, but also doesn't start // with ./ or ../. // That means that it was saved with an earlier version of "relative path support", // where the source file had to exist and only the project directory was stripped // from the filename. QFileInfo pfi( mBaseFileName ); QString home = pfi.absoluteFilePath(); if ( home.isEmpty() ) return vsiPrefix + src; QFileInfo fi( home + '/' + src ); if ( !fi.exists() ) { return vsiPrefix + src; } else { return vsiPrefix + fi.canonicalFilePath(); } } QString srcPath = src; QString projPath = mBaseFileName; if ( projPath.isEmpty() ) { return vsiPrefix + src; } #if defined(Q_OS_WIN) srcPath.replace( '\\', '/' ); projPath.replace( '\\', '/' ); bool uncPath = projPath.startsWith( "//" ); #endif QStringList srcElems = srcPath.split( '/', QString::SkipEmptyParts ); QStringList projElems = projPath.split( '/', QString::SkipEmptyParts ); #if defined(Q_OS_WIN) if ( uncPath ) { projElems.insert( 0, "" ); projElems.insert( 0, "" ); } #endif // remove project file element projElems.removeLast(); // append source path elements projElems << srcElems; projElems.removeAll( QStringLiteral( "." ) ); // resolve .. int pos; while ( ( pos = projElems.indexOf( QStringLiteral( ".." ) ) ) > 0 ) { // remove preceding element and .. projElems.removeAt( pos - 1 ); projElems.removeAt( pos - 1 ); } #if !defined(Q_OS_WIN) // make path absolute projElems.prepend( QLatin1String( "" ) ); #endif return vsiPrefix + projElems.join( QStringLiteral( "/" ) ); }
QString QgsPathResolver::writePath( const QString &src ) const { if ( mBaseFileName.isEmpty() || src.isEmpty() ) { return src; } QFileInfo pfi( mBaseFileName ); QString projPath = pfi.absoluteFilePath(); if ( projPath.isEmpty() ) { return src; } QFileInfo srcFileInfo( src ); QString srcPath = srcFileInfo.exists() ? srcFileInfo.canonicalFilePath() : src; // if this is a VSIFILE, remove the VSI prefix and append to final result QString vsiPrefix = qgsVsiPrefix( src ); if ( ! vsiPrefix.isEmpty() ) { srcPath.remove( 0, vsiPrefix.size() ); } #if defined( Q_OS_WIN ) const Qt::CaseSensitivity cs = Qt::CaseInsensitive; srcPath.replace( '\\', '/' ); if ( srcPath.startsWith( "//" ) ) { // keep UNC prefix srcPath = "\\\\" + srcPath.mid( 2 ); } projPath.replace( '\\', '/' ); if ( projPath.startsWith( "//" ) ) { // keep UNC prefix projPath = "\\\\" + projPath.mid( 2 ); } #else const Qt::CaseSensitivity cs = Qt::CaseSensitive; #endif QStringList projElems = mBaseFileName.split( '/', QString::SkipEmptyParts ); QStringList srcElems = srcPath.split( '/', QString::SkipEmptyParts ); // remove project file element projElems.removeLast(); projElems.removeAll( QStringLiteral( "." ) ); srcElems.removeAll( QStringLiteral( "." ) ); // remove common part int n = 0; while ( !srcElems.isEmpty() && !projElems.isEmpty() && srcElems[0].compare( projElems[0], cs ) == 0 ) { srcElems.removeFirst(); projElems.removeFirst(); n++; } if ( n == 0 ) { // no common parts; might not even by a file return src; } if ( !projElems.isEmpty() ) { // go up to the common directory for ( int i = 0; i < projElems.size(); i++ ) { srcElems.insert( 0, QStringLiteral( ".." ) ); } } else { // let it start with . nevertheless, // so relative path always start with either ./ or ../ srcElems.insert( 0, QStringLiteral( "." ) ); } return vsiPrefix + srcElems.join( QStringLiteral( "/" ) ); }
/** * @brief ProjectFile::Open * @param path * @return -2:unknown format, -1:open error, 0:no content, more than zero:number of files. */ int ProjectFile::Open(const QString &path) { fc_.clear(); updatedlist_.clear(); bapppath_ = True; bcmdline_ = True; bparser_ = True; QFile file(path); if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) return -1; QFileInfo pfi(path); QDir::setCurrent(pfi.absolutePath()); QByteArray ba = file.readLine(); int fileformat = FORMAT_UNKNOWN; switch (ba[0]) { case '#': fileformat = FORMAT_PLAIN; break; case '<': fileformat = FORMAT_XML; break; default: return -2; } file.seek(0); if (fileformat == FORMAT_PLAIN) { for ( ; ; ) { QByteArray ba = file.readLine(); if (ba.size() == 0) break; if (ba[0] == '#') { continue; } ba[ba.size()-1] = '\0'; // remove \n Add(QString::fromLocal8Bit(ba)); updatedlist_.push_back(QDateTime()); } } else if (fileformat == FORMAT_XML) { file.close(); ProjectXML prjxml; if (prjxml.readFile(&file)) { #ifdef _DEBUG prjxml.dump(); #endif bapppath_ = prjxml.IsDefaultAppPath(); if (bapppath_ == False) apppath_ = prjxml.AppPath(); bcmdline_ = prjxml.IsDefaultCmdLine(); if (bcmdline_ == False) cmdline_ = prjxml.CmdLine(); bparser_ = prjxml.IsDefaultParser(); if (bparser_ == False) parser_ = prjxml.Parser(); Copy(prjxml.Files()); } } return fc_.size(); }
// return the absolute path from a filename read from project file QString QgsProject::readPath( QString src ) const { if ( readBoolEntry( "Paths", "/Absolute", false ) ) { return src; } // relative path should always start with ./ or ../ if ( !src.startsWith( "./" ) && !src.startsWith( "../" ) ) { #if defined(Q_OS_WIN) if ( src.startsWith( "\\\\" ) || src.startsWith( "//" ) || ( src[0].isLetter() && src[1] == ':' ) ) { // UNC or absolute path return src; } #else if ( src[0] == '/' ) { // absolute path return src; } #endif // so this one isn't absolute, but also doesn't start // with ./ or ../. // That means that it was saved with an earlier version of "relative path support", // where the source file had to exist and only the project directory was stripped // from the filename. QFileInfo pfi( fileName() ); if ( !pfi.exists() ) return src; QFileInfo fi( pfi.canonicalPath() + "/" + src ); if ( !fi.exists() ) { return src; } else { return fi.canonicalFilePath(); } } QString srcPath = src; QString projPath = fileName(); if ( projPath.isEmpty() ) { return src; } #if defined(Q_OS_WIN) srcPath.replace( "\\", "/" ); projPath.replace( "\\", "/" ); bool uncPath = projPath.startsWith( "//" ); #endif QStringList srcElems = srcPath.split( "/", QString::SkipEmptyParts ); QStringList projElems = projPath.split( "/", QString::SkipEmptyParts ); #if defined(Q_OS_WIN) if ( uncPath ) { projElems.insert( 0, "" ); projElems.insert( 0, "" ); } #endif // remove project file element projElems.removeLast(); // append source path elements projElems << srcElems; projElems.removeAll( "." ); // resolve .. int pos; while (( pos = projElems.indexOf( ".." ) ) > 0 ) { // remove preceding element and .. projElems.removeAt( pos - 1 ); projElems.removeAt( pos - 1 ); } #if !defined(Q_OS_WIN) // make path absolute projElems.prepend( "" ); #endif return projElems.join( "/" ); }