Skip to content
Permalink
Browse files

allow editing of links in file widget (#36190)

  • Loading branch information
3nids committed May 6, 2020
1 parent 7e0c438 commit 0d5ea7d4c70652ea12b87713865fa5805a4bc16d
Showing with 65 additions and 14 deletions.
  1. +59 −14 src/gui/qgsfilewidget.cpp
  2. +6 −0 src/gui/qgsfilewidget.h
@@ -51,6 +51,9 @@ QgsFileWidget::QgsFileWidget( QWidget *parent )
mLinkLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
mLinkLabel->setTextFormat( Qt::RichText );
mLinkLabel->hide(); // do not show by default
mLinkEditButton = new QToolButton( this );
mLinkEditButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionToggleEditing.svg" ) ) );
connect( mLinkEditButton, &QToolButton::clicked, this, &QgsFileWidget::editLink );

// otherwise, use the traditional QLineEdit subclass
mLineEdit = new QgsFileDropEdit( this );
@@ -100,8 +103,12 @@ void QgsFileWidget::setFilePath( QString path )

void QgsFileWidget::setReadOnly( bool readOnly )
{
mFileWidgetButton->setEnabled( !readOnly );
mLineEdit->setEnabled( !readOnly );
if ( mReadOnly == readOnly )
return;

mReadOnly = readOnly;

updateLayout();
}

QString QgsFileWidget::dialogTitle() const
@@ -152,26 +159,27 @@ void QgsFileWidget::textEdited( const QString &path )
emit fileChanged( mFilePath );
}

void QgsFileWidget::editLink()
{
if ( !mUseLink || mReadOnly )
return;

mIsLinkEdited = !mIsLinkEdited;
updateLayout();
}

bool QgsFileWidget::useLink() const
{
return mUseLink;
}

void QgsFileWidget::setUseLink( bool useLink )
{
if ( mUseLink == useLink )
return;

mUseLink = useLink;
mLinkLabel->setVisible( mUseLink );
mLineEdit->setVisible( !mUseLink );
if ( mUseLink )
{
mLayout->removeWidget( mLineEdit );
mLayout->insertWidget( 0, mLinkLabel );
}
else
{
mLayout->removeWidget( mLinkLabel );
mLayout->insertWidget( 0, mLineEdit );
}
updateLayout();
}

bool QgsFileWidget::fullUrl() const
@@ -220,6 +228,43 @@ QgsFilterLineEdit *QgsFileWidget::lineEdit()
return mLineEdit;
}

void QgsFileWidget::updateLayout()
{
mLayout->removeWidget( mLineEdit );
mLayout->removeWidget( mLinkLabel );
mLayout->removeWidget( mLinkEditButton );

mLinkEditButton->setVisible( mUseLink && !mReadOnly );

mFileWidgetButton->setEnabled( !mReadOnly );
mLineEdit->setEnabled( !mReadOnly );

if ( mUseLink && !mIsLinkEdited )
{
mLayout->insertWidget( 0, mLinkLabel );
mLineEdit->setVisible( false );
mLinkLabel->setVisible( true );

if ( !mReadOnly )
{
mLayout->insertWidget( 1, mLinkEditButton );
mLinkEditButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionToggleEditing.svg" ) ) );
}
}
else
{
mLayout->insertWidget( 0, mLineEdit );
mLineEdit->setVisible( true );
mLinkLabel->setVisible( false );

if ( mIsLinkEdited )
{
mLayout->insertWidget( 1, mLinkEditButton );
mLinkEditButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionSaveEdits.svg" ) ) );
}
}
}

void QgsFileWidget::openFileDialog()
{
QgsSettings settings;
@@ -200,12 +200,17 @@ class GUI_EXPORT QgsFileWidget : public QWidget
private slots:
void openFileDialog();
void textEdited( const QString &path );
void editLink();

private:
void updateLayout();

QString mFilePath;
bool mButtonVisible = true;
bool mUseLink = false;
bool mFullUrl = false;
bool mReadOnly = false;
bool mIsLinkEdited = false;
QString mDialogTitle;
QString mFilter;
QString mSelectedFilter;
@@ -216,6 +221,7 @@ class GUI_EXPORT QgsFileWidget : public QWidget

QLabel *mLinkLabel = nullptr;
QgsFileDropEdit *mLineEdit = nullptr;
QToolButton *mLinkEditButton = nullptr;
QToolButton *mFileWidgetButton = nullptr;
QHBoxLayout *mLayout = nullptr;

0 comments on commit 0d5ea7d

Please sign in to comment.
You can’t perform that action at this time.