Skip to content

Commit

Permalink
[Attachment widget] Respect relative paths settings by drag&drop
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 authored and nyalldawson committed Aug 26, 2021
1 parent 41c32e5 commit 262e0f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/gui/qgsfilewidget.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions src/gui/qgsfilewidget.h
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 262e0f7

Please sign in to comment.