Skip to content

Commit

Permalink
fix buttons in SVG source line edit (#39519)
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Oct 21, 2020
1 parent 454a095 commit 2d82ef9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
11 changes: 9 additions & 2 deletions python/gui/auto_generated/qgsfilecontentsourcelineedit.sip.in
Expand Up @@ -61,9 +61,16 @@ Sets a specific settings ``key`` to use when storing the last
used path for the file source.
%End

QgsPropertyOverrideButton *fileToolButton() const;
QgsPropertyOverrideButton *propertyOverrideToolButton() const;
%Docstring
Returns the file tool button
Returns the property override tool button

.. versionadded:: 3.16
%End

void setPropertyOverrideToolButtonVisible( bool visible );
%Docstring
Sets the visibility of the property override tool button

.. versionadded:: 3.16
%End
Expand Down
12 changes: 11 additions & 1 deletion src/gui/qgsfilecontentsourcelineedit.cpp
Expand Up @@ -36,10 +36,12 @@ QgsAbstractFileContentSourceLineEdit::QgsAbstractFileContentSourceLineEdit( QWid
layout->setContentsMargins( 0, 0, 0, 0 );
mFileLineEdit = new QgsFilterLineEdit( this );
mFileLineEdit->setShowClearButton( true );
mFileToolButton = new QgsPropertyOverrideButton( this );
mFileToolButton = new QToolButton( this );
mFileToolButton->setText( QString( QChar( 0x2026 ) ) );
mPropertyOverrideButton = new QgsPropertyOverrideButton( this );
layout->addWidget( mFileLineEdit, 1 );
layout->addWidget( mFileToolButton );
layout->addWidget( mPropertyOverrideButton );
setLayout( layout );

QMenu *sourceMenu = new QMenu( mFileToolButton );
Expand Down Expand Up @@ -78,6 +80,8 @@ QgsAbstractFileContentSourceLineEdit::QgsAbstractFileContentSourceLineEdit( QWid
emit sourceChanged( QString() );
} );

mPropertyOverrideButton->setVisible( mPropertyOverrideButtonVisible );

}

QString QgsAbstractFileContentSourceLineEdit::source() const
Expand All @@ -99,6 +103,12 @@ void QgsAbstractFileContentSourceLineEdit::setLastPathSettingsKey( const QString
mLastPathKey = key;
}

void QgsAbstractFileContentSourceLineEdit::setPropertyOverrideToolButtonVisible( bool visible )
{
mPropertyOverrideButtonVisible = visible;
mPropertyOverrideButton->setVisible( visible );
}

void QgsAbstractFileContentSourceLineEdit::setSource( const QString &source )
{
const bool isBase64 = source.startsWith( QLatin1String( "base64:" ), Qt::CaseInsensitive );
Expand Down
14 changes: 11 additions & 3 deletions src/gui/qgsfilecontentsourcelineedit.h
Expand Up @@ -76,10 +76,16 @@ class GUI_EXPORT QgsAbstractFileContentSourceLineEdit : public QWidget SIP_ABSTR
void setLastPathSettingsKey( const QString &key );

/**
* Returns the file tool button
* Returns the property override tool button
* \since QGIS 3.16
*/
QgsPropertyOverrideButton *fileToolButton() const {return mFileToolButton;}
QgsPropertyOverrideButton *propertyOverrideToolButton() const {return mPropertyOverrideButton;}

/**
* Sets the visibility of the property override tool button
* \since QGIS 3.16
*/
void setPropertyOverrideToolButtonVisible( bool visible );

public slots:

Expand Down Expand Up @@ -156,9 +162,11 @@ class GUI_EXPORT QgsAbstractFileContentSourceLineEdit : public QWidget SIP_ABSTR
};

Mode mMode = ModeFile;
bool mPropertyOverrideButtonVisible = false;

QgsFilterLineEdit *mFileLineEdit = nullptr;
QgsPropertyOverrideButton *mFileToolButton = nullptr;
QToolButton *mFileToolButton = nullptr;
QgsPropertyOverrideButton *mPropertyOverrideButton = nullptr;
QString mLastPathKey;
QString mBase64;
QgsMessageBar *mMessageBar = nullptr;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/symbology/qgssymbollayerwidget.cpp
Expand Up @@ -2314,6 +2314,7 @@ QgsSvgMarkerSymbolLayerWidget::QgsSvgMarkerSymbolLayerWidget( QgsVectorLayer *vl

setupUi( this );

mSvgSelectorWidget->sourceLineEdit()->setPropertyOverrideToolButtonVisible( true );
mSvgSelectorWidget->sourceLineEdit()->setLastPathSettingsKey( QStringLiteral( "/UI/lastSVGMarkerDir" ) );

connect( mSvgSelectorWidget->sourceLineEdit(), &QgsSvgSourceLineEdit::sourceChanged, this, &QgsSvgMarkerSymbolLayerWidget::svgSourceChanged );
Expand Down Expand Up @@ -2518,7 +2519,7 @@ void QgsSvgMarkerSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer *layer )
registerDataDefinedButton( mHorizontalAnchorDDBtn, QgsSymbolLayer::PropertyHorizontalAnchor );
registerDataDefinedButton( mVerticalAnchorDDBtn, QgsSymbolLayer::PropertyVerticalAnchor );

registerDataDefinedButton( mSvgSelectorWidget->sourceLineEdit()->fileToolButton(), QgsSymbolLayer::PropertyName );
registerDataDefinedButton( mSvgSelectorWidget->sourceLineEdit()->propertyOverrideToolButton(), QgsSymbolLayer::PropertyName );

updateAssistantSymbol();
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/symbollayer/widget_svgselector.ui
Expand Up @@ -137,7 +137,7 @@
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
Expand Down

0 comments on commit 2d82ef9

Please sign in to comment.