Skip to content
Permalink
Browse files
[Attachment widget] Respect relative paths settings by drag&drop
  • Loading branch information
domi4484 authored and github-actions committed Aug 25, 2021
1 parent 41c32e5 commit 7a3c68973375b656b7e98353b7c3cb1a3ab5c3e4
Showing with 19 additions and 4 deletions.
  1. +11 −4 src/gui/qgsfilewidget.cpp
  2. +8 −0 src/gui/qgsfilewidget.h
@@ -62,6 +62,7 @@ QgsFileWidget::QgsFileWidget( QWidget *parent )
mLineEdit->setDragEnabled( true );
mLineEdit->setToolTip( tr( "Full path to the file(s), including name and extension" ) );
connect( mLineEdit, &QLineEdit::textChanged, this, &QgsFileWidget::textEdited );
connect( mLineEdit, &QgsFileDropEdit::fileDropped, this, &QgsFileWidget::fileDropped );
mLayout->addWidget( mLineEdit );

mFileWidgetButton = new QToolButton( this );
@@ -178,6 +179,13 @@ void QgsFileWidget::editLink()
updateLayout();
}

void QgsFileWidget::fileDropped( const QString &filePath )
{
setSelectedFileNames( QStringList() << filePath );
mLineEdit->selectAll();
mLineEdit->setFocus( Qt::MouseFocusReason );
}

bool QgsFileWidget::useLink() const
{
return mUseLink;
@@ -585,12 +593,11 @@ void QgsFileDropEdit::dropEvent( QDropEvent *event )
QString filePath = acceptableFilePath( event );
if ( !filePath.isEmpty() )
{
setText( filePath );
selectAll();
setFocus( Qt::MouseFocusReason );
event->acceptProposedAction();
setHighlighted( false );
emit fileDropped( filePath );
}

setHighlighted( false );
}

///@endcond
@@ -206,6 +206,7 @@ class GUI_EXPORT QgsFileWidget : public QWidget
void openFileDialog();
void textEdited( const QString &path );
void editLink();
void fileDropped( const QString &filePath );

private:
void updateLayout();
@@ -266,6 +267,13 @@ class GUI_EXPORT QgsFileDropEdit: public QgsHighlightableLineEdit

void setFilters( const QString &filters );

signals:

/**
* Emitted when the file \a filePath is droppen onto the line edit.
*/
void fileDropped( const QString &filePath );

protected:

void dragEnterEvent( QDragEnterEvent *event ) override;

0 comments on commit 7a3c689

Please sign in to comment.