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->setDragEnabled( true );
mLineEdit->setToolTip( tr( "Full path to the file(s), including name and extension" ) ); mLineEdit->setToolTip( tr( "Full path to the file(s), including name and extension" ) );
connect( mLineEdit, &QLineEdit::textChanged, this, &QgsFileWidget::textEdited ); connect( mLineEdit, &QLineEdit::textChanged, this, &QgsFileWidget::textEdited );
connect( mLineEdit, &QgsFileDropEdit::fileDropped, this, &QgsFileWidget::fileDropped );
mLayout->addWidget( mLineEdit ); mLayout->addWidget( mLineEdit );


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


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

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

setHighlighted( false );
} }


///@endcond ///@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 openFileDialog();
void textEdited( const QString &path ); void textEdited( const QString &path );
void editLink(); void editLink();
void fileDropped( const QString &filePath );


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


void setFilters( const QString &filters ); void setFilters( const QString &filters );


signals:

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

protected: protected:


void dragEnterEvent( QDragEnterEvent *event ) override; void dragEnterEvent( QDragEnterEvent *event ) override;
Expand Down

0 comments on commit 262e0f7

Please sign in to comment.