20 #include <QToolButton> 22 #include <QFileDialog> 24 #include <QGridLayout> 34 , mButtonVisible( true )
40 , mStorageMode( GetFile )
41 , mRelativeStorage( Absolute )
50 mLinkLabel =
new QLabel(
this );
56 mLinkLabel->
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
67 mFileWidgetButton->
setText(
"..." );
68 connect( mFileWidgetButton, SIGNAL( clicked() ),
this, SLOT( openFileDialog() ) );
69 layout->
addWidget( mFileWidgetButton, 0, 1, 2, 1 );
85 if ( path ==
QSettings().value(
"qgis/nullValue",
"NULL" ) )
107 mDialogTitle = title;
122 return mButtonVisible;
131 void QgsFileWidget::textEdited(
const QString& path )
134 mLinkLabel->
setText( toUrl( path ) );
182 return mRelativeStorage;
190 void QgsFileWidget::openFileDialog()
201 else if ( !mFilePath.
isEmpty() )
203 oldPath = relativePath( mFilePath,
false );
215 oldPath = settings.
value(
"/UI/lastExternalResourceWidgetDefaultPath", defPath ).
toString();
223 title = !mDialogTitle.
isEmpty() ? mDialogTitle :
tr(
"Select a file" );
228 title = !mDialogTitle.
isEmpty() ? mDialogTitle :
tr(
"Select a directory" );
241 settings.
setValue(
"/UI/lastFileNameWidgetDir",
QFileInfo( fileName ).absolutePath() );
245 settings.
setValue(
"/UI/lastFileNameWidgetDir", fileName );
249 fileName = relativePath( fileName,
true );
270 if ( removeRelative )
292 QString urlStr = relativePath( path,
false );
303 rep =
QString(
"<a href=\"%1\">%2</a>" ).
arg( pathStr, path );
308 rep =
QString(
"<a href=\"%1\">%2</a>" ).
arg( pathStr, fileName );
QString toNativeSeparators(const QString &pathName)
QString getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, QFlags< QFileDialog::Option > options)
void setOpenExternalLinks(bool open)
QString toString(QFlags< QUrl::FormattingOption > options) const
QString tr(const char *sourceText, const char *disambiguation, int n)
void setValue(const QString &key, const QVariant &value)
void setTextFormat(Qt::TextFormat)
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
void setText(const QString &)
void setMargin(int margin)
QString cleanPath(const QString &path)
QVariant value(const QString &key, const QVariant &defaultValue) const
static QgsProject * instance()
Returns the QgsProject singleton instance.
void setText(const QString &text)
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void setValue(const QString &value)
Sets the current text for the widget with support for handling null values.