static QString dir( const QString&, const bool = true );
static QString file( const QString&, const bool = true );
static QString extension( const QString&, const bool = false );
+ static QString relativePath( const QString&, const QString& );
+ static QString absolutePath( const QString&, const QString& );
static QString library( const QString& );
lineEdit()->setValidator( v );
}
+/*!
+ \brief Set base path. If thePath is not empty the editor
+ becomes relative path editor.
+ \param thePath the base path. If thePath is not empty the editor become
+ relative path editor. If thePath is empty the editor become absolute path
+ editor
+*/
+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;
+}
+
+/*!
+ \brief Return base path.
+ */
+QString QtxPathEdit::basePath() const
+{
+ return myBasePath;
+}
+
/*!
\brief Called when user clicks "Browse" button.
*/
void QtxPathEdit::onBrowse( bool /*on*/ )
{
+ emit beforeBrowse();
QString path;
- QString initial = QFileInfo( myPath->text() ).path();
+ QString initial = myPath->text();
+ if( !myBasePath.isEmpty() )
+ initial = Qtx::absolutePath( myBasePath, initial );
+ initial = QFileInfo( initial ).path();
switch ( pathType() )
{
case Qtx::PT_OpenFile:
}
if ( !path.isEmpty() ) {
- QString txt = QDir::convertSeparators( path );
+ QString txt = path;
+ if( !myBasePath.isEmpty() )
+ txt = Qtx::relativePath(myBasePath, path );
+ txt = QDir::convertSeparators( txt );
bool block = myPath->signalsBlocked();
myPath->blockSignals( true );
myPath->setText( txt );
const QValidator* validator() const;
void setValidator( QValidator* );
+ void setBasePath( const QString& theBasePath );
+ QString basePath() const;
+
signals:
void returnPressed();
void pathChanged( const QString& );
void pathSelected( const QString& );
+ void beforeBrowse();
private slots:
void onBrowse( bool = false );
QLineEdit* myPath;
Qtx::PathType myType;
QString myFilter;
+ QString myBasePath;
};
#endif