From: sbh Date: Wed, 10 Oct 2012 07:10:49 +0000 (+0000) Subject: MTN: Realtive mode was added to QtxPathEdit X-Git-Tag: V5_2_5~15 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8428143d995a1dffdc7904f2fad361260243afe2;p=modules%2Fgui.git MTN: Realtive mode was added to QtxPathEdit --- diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index 89f7e729c..4867d76f0 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -388,6 +388,42 @@ QString Qtx::extension( const QString& path, const bool full ) return full ? QFileInfo( path ).completeSuffix() : QFileInfo( path ).suffix(); } +/*! + \brief Return path to file relative to theBase directory. + + \param theBase path to base directory + \param theFileName the file name + \return relative file path +*/ +QString Qtx::relativePath( const QString& theBase, const QString& theFileName ) +{ + QString aCanBase; + QFileInfo aBaseFInfo( theBase ); + if( aBaseFInfo.exists() ) + aCanBase = aBaseFInfo.canonicalFilePath(); + else + aCanBase = QDir::cleanPath(theBase); + QFileInfo aFInfo(theFileName); + QString aCanFileName = QDir::cleanPath(theFileName); + QDir aDir(aCanBase); + return aDir.relativeFilePath( aCanFileName ); +} + +/*! + \brief Return avsolute path. + + \param theBase path to base directory + \param theFile the file name + \return absolute file path +*/ +QString Qtx::absolutePath( const QString& theBase, const QString& theFile ) +{ + QFileInfo aFInfo( theBase, theFile ); + QString aPath = QDir::cleanPath( aFInfo.filePath() ); + QFileInfo aCleanFInfo(aPath); + return aCleanFInfo.canonicalFilePath(); +} + /*! \brief Convert the given parameter to the platform-specific library name. diff --git a/src/Qtx/QtxPathEdit.cxx b/src/Qtx/QtxPathEdit.cxx index 8e06601f8..a9f8497e9 100644 --- a/src/Qtx/QtxPathEdit.cxx +++ b/src/Qtx/QtxPathEdit.cxx @@ -205,21 +205,6 @@ void QtxPathEdit::setValidator( QValidator* v ) */ void QtxPathEdit::setBasePath( const QString& theBasePath ) { - if( myBasePath.isEmpty() && !theBasePath.isEmpty() ){ -//Switch to relative path editor - QString aNewPath = Qtx::relativePath( theBasePath, myPath->text() ); - myPath->setText( aNewPath ); - } - if( !myBasePath.isEmpty() && theBasePath.isEmpty() ){ -//Switch to absolute path editor - QString aNewPath = Qtx::relativePath( theBasePath, myPath->text() ); - myPath->setText( aNewPath ); - } - if( !myBasePath.isEmpty() && !theBasePath.isEmpty() ){ - QString anAbsPath = Qtx::absolutePath( myBasePath, myPath->text() ); - QString aNewPath = Qtx::relativePath( theBasePath, anAbsPath ); - myPath->setText( aNewPath ); - } myBasePath = theBasePath; }