[FEATURE] Better UI for embedding SVG files

Adds a common widget for SVG sources, with a tool button with
some handy options:
- select file (old behaviour), pick a file from disk
- embed file (pick a file from disk, is embedded into project/symbol)
- extract embedded file (for embedded files, allows you to save these
back to a disk based svg file)
- from url (opens a dialog prompting for a url, exposing
the previously hidden functionality that svgs can be retrieved
from a remote url (eg github))

Sponsored by SMEC/SJ
This commit is contained in:
Nyall Dawson 2018-07-18 15:48:42 +10:00
parent 19f8a0078d
commit 1a7ade7575
15 changed files with 966 additions and 677 deletions

View File

@ -0,0 +1,71 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgssvgsourcelineedit.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsSvgSourceLineEdit : QWidget
{
%Docstring
A line edit widget with toolbutton for setting an SVG image path.
.. versionadded:: 3.4
%End
%TypeHeaderCode
#include "qgssvgsourcelineedit.h"
%End
public:
QgsSvgSourceLineEdit( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsSvgSourceLineEdit, with the specified ``parent`` widget.
%End
QString source() const;
%Docstring
Returns the current SVG source.
.. seealso:: :py:func:`setSource`
.. seealso:: :py:func:`sourceChanged`
%End
void setLastPathSettingsKey( const QString &key );
%Docstring
Sets a specific settings ``key`` to use when storing the last
used path for the SVG source.
%End
public slots:
void setSource( const QString &source );
%Docstring
Sets a new ``source`` to show in the widget.
.. seealso:: :py:func:`source`
.. seealso:: :py:func:`sourceChanged`
%End
signals:
void sourceChanged( const QString &source );
%Docstring
Emitted whenever the SVG source is changed in the widget.
%End
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgssvgsourcelineedit.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -195,6 +195,7 @@
%Include auto_generated/qgsstatusbar.sip
%Include auto_generated/qgssublayersdialog.sip
%Include auto_generated/qgssubstitutionlistwidget.sip
%Include auto_generated/qgssvgsourcelineedit.sip
%Include auto_generated/qgssymbolbutton.sip
%Include auto_generated/qgstablewidgetbase.sip
%Include auto_generated/qgstabwidget.sip

View File

@ -359,6 +359,7 @@ SET(QGIS_GUI_SRCS
qgssubstitutionlistwidget.cpp
qgssqlcomposerdialog.cpp
qgsstatusbar.cpp
qgssvgsourcelineedit.cpp
qgssymbolbutton.cpp
qgstablewidgetbase.cpp
qgstabwidget.cpp
@ -526,6 +527,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsstatusbar.h
qgssublayersdialog.h
qgssubstitutionlistwidget.h
qgssvgsourcelineedit.h
qgssymbolbutton.h
qgstablewidgetbase.h
qgstabwidget.h

View File

@ -0,0 +1,212 @@
/***************************************************************************
qgssvgsourcelineedit.cpp
-----------------------
begin : July 2018
copyright : (C) 2018 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgssvgsourcelineedit.h"
#include "qgssettings.h"
#include <QMenu>
#include <QLineEdit>
#include <QToolButton>
#include <QHBoxLayout>
#include <QFileDialog>
#include <QInputDialog>
QgsSvgSourceLineEdit::QgsSvgSourceLineEdit( QWidget *parent )
: QWidget( parent )
{
QHBoxLayout *layout = new QHBoxLayout( this );
mFileLineEdit = new QLineEdit( this );
mFileToolButton = new QToolButton( this );
mFileToolButton->setText( tr( "" ) );
layout->addWidget( mFileLineEdit, 1 );
layout->addWidget( mFileToolButton );
setLayout( layout );
QMenu *sourceMenu = new QMenu( mFileToolButton );
QAction *selectFileAction = new QAction( tr( "Select File…" ), sourceMenu );
connect( selectFileAction, &QAction::triggered, this, &QgsSvgSourceLineEdit::selectFile );
sourceMenu->addAction( selectFileAction );
QAction *embedFileAction = new QAction( tr( "Embed File…" ), sourceMenu );
connect( embedFileAction, &QAction::triggered, this, &QgsSvgSourceLineEdit::embedFile );
sourceMenu->addAction( embedFileAction );
QAction *extractFileAction = new QAction( tr( "Extract Embedded File…" ), sourceMenu );
connect( extractFileAction, &QAction::triggered, this, &QgsSvgSourceLineEdit::extractFile );
sourceMenu->addAction( extractFileAction );
connect( sourceMenu, &QMenu::aboutToShow, this, [this, extractFileAction]
{
extractFileAction->setEnabled( mFileLineEdit->text().startsWith( QStringLiteral( "base64:" ), Qt::CaseInsensitive ) );
} );
QAction *enterUrlAction = new QAction( tr( "From URL…" ), sourceMenu );
connect( enterUrlAction, &QAction::triggered, this, &QgsSvgSourceLineEdit::selectUrl );
sourceMenu->addAction( enterUrlAction );
mFileToolButton->setMenu( sourceMenu );
mFileToolButton->setPopupMode( QToolButton::MenuButtonPopup );
connect( mFileToolButton, &QToolButton::clicked, this, &QgsSvgSourceLineEdit::selectFile );
connect( mFileLineEdit, &QLineEdit::textEdited, this, &QgsSvgSourceLineEdit::mFileLineEdit_textEdited );
connect( mFileLineEdit, &QLineEdit::editingFinished, this, &QgsSvgSourceLineEdit::mFileLineEdit_editingFinished );
}
QString QgsSvgSourceLineEdit::source() const
{
return mFileLineEdit->text();
}
void QgsSvgSourceLineEdit::setLastPathSettingsKey( const QString &key )
{
mLastPathKey = key;
}
void QgsSvgSourceLineEdit::setSource( const QString &source )
{
if ( source == mFileLineEdit->text() )
return;
mFileLineEdit->setText( source );
emit sourceChanged( source );
}
void QgsSvgSourceLineEdit::selectFile()
{
QgsSettings s;
QString file = QFileDialog::getOpenFileName( nullptr,
tr( "Select SVG file" ),
defaultPath(),
tr( "SVG files" ) + " (*.svg)" );
QFileInfo fi( file );
if ( file.isEmpty() || !fi.exists() || file == source() )
{
return;
}
mFileLineEdit->setText( file );
s.setValue( settingsKey(), fi.absolutePath() );
emit sourceChanged( mFileLineEdit->text() );
}
void QgsSvgSourceLineEdit::selectUrl()
{
bool ok = false;
const QString path = QInputDialog::getText( this, tr( "SVG From URL" ), tr( "Enter SVG URL" ), QLineEdit::Normal, mFileLineEdit->text(), &ok );
if ( ok && path != source() )
{
mFileLineEdit->setText( path );
emit sourceChanged( mFileLineEdit->text() );
}
}
void QgsSvgSourceLineEdit::embedFile()
{
QgsSettings s;
QString file = QFileDialog::getOpenFileName( nullptr,
tr( "Embed SVG File" ),
defaultPath(),
tr( "SVG files" ) + " (*.svg)" );
QFileInfo fi( file );
if ( file.isEmpty() || !fi.exists() )
{
return;
}
s.setValue( settingsKey(), fi.absolutePath() );
// encode file as base64
QFile fileSource( file );
if ( !fileSource.open( QIODevice::ReadOnly ) )
{
return;
}
QByteArray blob = fileSource.readAll();
QByteArray encoded = blob.toBase64();
QString path( encoded );
path.prepend( QLatin1String( "base64:" ) );
if ( path == source() )
return;
mFileLineEdit->setText( path );
emit sourceChanged( mFileLineEdit->text() );
}
void QgsSvgSourceLineEdit::extractFile()
{
QgsSettings s;
QString file = QFileDialog::getSaveFileName( nullptr,
tr( "Extract SVG File" ),
defaultPath(),
tr( "SVG files" ) + " (*.svg)" );
if ( file.isEmpty() )
{
return;
}
QFileInfo fi( file );
s.setValue( settingsKey(), fi.absolutePath() );
// decode current base64 embedded file
QString path = mFileLineEdit->text().trimmed();
if ( path.startsWith( QLatin1String( "base64:" ), Qt::CaseInsensitive ) )
{
QByteArray base64 = path.mid( 7 ).toLocal8Bit(); // strip 'base64:' prefix
QByteArray decoded = QByteArray::fromBase64( base64, QByteArray::OmitTrailingEquals );
QFile fileOut( file );
fileOut.open( QIODevice::WriteOnly );
fileOut.write( decoded );
fileOut.close();
}
}
void QgsSvgSourceLineEdit::mFileLineEdit_textEdited( const QString &text )
{
if ( !QFileInfo::exists( text ) )
{
return;
}
emit sourceChanged( text );
}
void QgsSvgSourceLineEdit::mFileLineEdit_editingFinished()
{
if ( !QFileInfo::exists( mFileLineEdit->text() ) )
{
QUrl url( mFileLineEdit->text() );
if ( !url.isValid() )
{
return;
}
}
emit sourceChanged( mFileLineEdit->text() );
}
QString QgsSvgSourceLineEdit::defaultPath() const
{
if ( QFileInfo::exists( source() ) )
return source();
return QgsSettings().value( settingsKey(), QDir::homePath() ).toString();
}
QString QgsSvgSourceLineEdit::settingsKey() const
{
return mLastPathKey.isEmpty() ? QStringLiteral( "/UI/lastSVGDir" ) : mLastPathKey;
}

View File

@ -0,0 +1,92 @@
/***************************************************************************
qgssvgsourcelineedit.h
---------------------
begin : July 2018
copyright : (C) 2018 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSSVGSOURCELINEEDIT_H
#define QGSSVGSOURCELINEEDIT_H
#include "qgis_gui.h"
#include "qgis_sip.h"
#include <QWidget>
class QLineEdit;
class QToolButton;
/**
* \ingroup gui
* \class QgsSvgSourceLineEdit
* A line edit widget with toolbutton for setting an SVG image path.
* \since QGIS 3.4
*/
class GUI_EXPORT QgsSvgSourceLineEdit : public QWidget
{
Q_OBJECT
Q_PROPERTY( QString source READ source WRITE setSource NOTIFY sourceChanged )
public:
/**
* Constructor for QgsSvgSourceLineEdit, with the specified \a parent widget.
*/
QgsSvgSourceLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr );
/**
* Returns the current SVG source.
* \see setSource()
* \see sourceChanged()
*/
QString source() const;
/**
* Sets a specific settings \a key to use when storing the last
* used path for the SVG source.
*/
void setLastPathSettingsKey( const QString &key );
public slots:
/**
* Sets a new \a source to show in the widget.
* \see source()
* \see sourceChanged()
*/
void setSource( const QString &source );
signals:
/**
* Emitted whenever the SVG source is changed in the widget.
*/
void sourceChanged( const QString &source );
private slots:
void selectFile();
void selectUrl();
void embedFile();
void extractFile();
void mFileLineEdit_textEdited( const QString &text );
void mFileLineEdit_editingFinished();
private:
QLineEdit *mFileLineEdit = nullptr;
QToolButton *mFileToolButton = nullptr;
QString mLastPathKey;
QString defaultPath() const;
QString settingsKey() const;
};
#endif

View File

@ -1310,6 +1310,7 @@ void QgsTextFormatWidget::mShapeSVGSelectorBtn_clicked()
if ( !svgPath.isEmpty() )
{
mShapeSVGPathLineEdit->setText( svgPath );
updatePreview();
}
}
}

View File

@ -32,6 +32,7 @@
#include <QPixmapCache>
#include <QStyle>
#include <QTime>
#include <QMenu>
// QgsSvgSelectorLoader
@ -373,8 +374,8 @@ QgsSvgSelectorWidget::QgsSvgSelectorWidget( QWidget *parent )
{
// TODO: in-code gui setup with option to vertically or horizontally stack SVG groups/images widgets
setupUi( this );
connect( mFilePushButton, &QPushButton::clicked, this, &QgsSvgSelectorWidget::mFilePushButton_clicked );
connect( mFileLineEdit, &QLineEdit::textChanged, this, &QgsSvgSelectorWidget::mFileLineEdit_textChanged );
connect( mSvgSourceLineEdit, &QgsSvgSourceLineEdit::sourceChanged, this, &QgsSvgSelectorWidget::svgSourceChanged );
mIconSize = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXX" ) ) ) ) );
mImagesListView->setGridSize( QSize( mIconSize * 1.2, mIconSize * 1.2 ) );
@ -392,9 +393,7 @@ void QgsSvgSelectorWidget::setSvgPath( const QString &svgPath )
{
mCurrentSvgPath = svgPath;
mFileLineEdit->blockSignals( true );
mFileLineEdit->setText( svgPath );
mFileLineEdit->blockSignals( false );
whileBlocking( mSvgSourceLineEdit )->setSource( svgPath );
mImagesListView->selectionModel()->blockSignals( true );
QAbstractItemModel *m = mImagesListView->model();
@ -427,7 +426,7 @@ void QgsSvgSelectorWidget::updateCurrentSvgPath( const QString &svgPath )
void QgsSvgSelectorWidget::svgSelectionChanged( const QModelIndex &idx )
{
QString filePath = idx.data( Qt::UserRole ).toString();
mFileLineEdit->setText( filePath );
whileBlocking( mSvgSourceLineEdit )->setSource( filePath );
updateCurrentSvgPath( filePath );
}
@ -442,57 +441,14 @@ void QgsSvgSelectorWidget::populateIcons( const QModelIndex &idx )
connect( mImagesListView->selectionModel(), &QItemSelectionModel::currentChanged,
this, &QgsSvgSelectorWidget::svgSelectionChanged );
}
void QgsSvgSelectorWidget::mFilePushButton_clicked()
{
QgsSettings settings;
QString openDir = settings.value( QStringLiteral( "UI/lastSVGMarkerDir" ), QDir::homePath() ).toString();
QString lineEditText = mFileLineEdit->text();
if ( !lineEditText.isEmpty() )
{
QFileInfo openDirFileInfo( lineEditText );
openDir = openDirFileInfo.path();
}
QString file = QFileDialog::getOpenFileName( nullptr,
tr( "Select SVG file" ),
openDir,
tr( "SVG files" ) + " (*.svg *.SVG)" );
activateWindow(); // return window focus
if ( file.isNull() )
return;
QFileInfo fi( file );
if ( !fi.exists() || !fi.isReadable() )
{
updateCurrentSvgPath( QString() );
updateLineEditFeedback( false );
return;
}
settings.setValue( QStringLiteral( "UI/lastSVGMarkerDir" ), fi.absolutePath() );
mFileLineEdit->setText( file );
updateCurrentSvgPath( file );
}
void QgsSvgSelectorWidget::updateLineEditFeedback( bool ok, const QString &tip )
{
// draw red text for path field if invalid (path can't be resolved)
mFileLineEdit->setStyleSheet( QString( !ok ? "QLineEdit{ color: rgb(225, 0, 0); }" : "" ) );
mFileLineEdit->setToolTip( !ok ? tr( "File not found" ) : tip );
}
void QgsSvgSelectorWidget::mFileLineEdit_textChanged( const QString &text )
void QgsSvgSelectorWidget::svgSourceChanged( const QString &text )
{
QString resolvedPath = QgsSymbolLayerUtils::svgSymbolNameToPath( text, QgsProject::instance()->pathResolver() );
bool validSVG = !resolvedPath.isNull();
updateLineEditFeedback( validSVG, resolvedPath );
updateCurrentSvgPath( validSVG ? resolvedPath : QString() );
updateCurrentSvgPath( validSVG ? resolvedPath : text );
}
void QgsSvgSelectorWidget::populateList()

View File

@ -276,10 +276,7 @@ class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSel
void populateIcons( const QModelIndex &idx );
void svgSelectionChanged( const QModelIndex &idx );
void updateCurrentSvgPath( const QString &svgPath );
void mFilePushButton_clicked();
void updateLineEditFeedback( bool ok, const QString &tip = QString() );
void mFileLineEdit_textChanged( const QString &text );
void svgSourceChanged( const QString &text );
private:

View File

@ -52,6 +52,9 @@
#include <QStandardItemModel>
#include <QSvgRenderer>
#include <QMessageBox>
#include <QMenu>
#include <QAction>
#include <QInputDialog>
QgsExpressionContext QgsSymbolLayerWidget::createExpressionContext() const
{
@ -1804,9 +1807,10 @@ QgsSvgMarkerSymbolLayerWidget::QgsSvgMarkerSymbolLayerWidget( QgsVectorLayer *vl
mLayer = nullptr;
setupUi( this );
connect( mFileToolButton, &QToolButton::clicked, this, &QgsSvgMarkerSymbolLayerWidget::mFileToolButton_clicked );
connect( mFileLineEdit, &QLineEdit::textEdited, this, &QgsSvgMarkerSymbolLayerWidget::mFileLineEdit_textEdited );
connect( mFileLineEdit, &QLineEdit::editingFinished, this, &QgsSvgMarkerSymbolLayerWidget::mFileLineEdit_editingFinished );
mSvgSourceLineEdit->setLastPathSettingsKey( QStringLiteral( "/UI/lastSVGMarkerDir" ) );
connect( mSvgSourceLineEdit, &QgsSvgSourceLineEdit::sourceChanged, this, &QgsSvgMarkerSymbolLayerWidget::svgSourceChanged );
connect( mChangeColorButton, &QgsColorButton::colorChanged, this, &QgsSvgMarkerSymbolLayerWidget::mChangeColorButton_colorChanged );
connect( mChangeStrokeColorButton, &QgsColorButton::colorChanged, this, &QgsSvgMarkerSymbolLayerWidget::mChangeStrokeColorButton_colorChanged );
connect( mStrokeWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged );
@ -1944,9 +1948,7 @@ void QgsSvgMarkerSymbolLayerWidget::setGuiForSvg( const QgsSvgMarkerSymbolLayer
mChangeStrokeColorButton->setColor( stroke );
}
mFileLineEdit->blockSignals( true );
mFileLineEdit->setText( layer->path() );
mFileLineEdit->blockSignals( false );
whileBlocking( mSvgSourceLineEdit )->setSource( layer->path() );
mStrokeWidthSpinBox->blockSignals( true );
mStrokeWidthSpinBox->setValue( hasDefaultStrokeWidth ? defaultStrokeWidth : layer->strokeWidth() );
@ -2070,7 +2072,7 @@ void QgsSvgMarkerSymbolLayerWidget::setName( const QModelIndex &idx )
{
QString name = idx.data( Qt::UserRole ).toString();
mLayer->setPath( name );
mFileLineEdit->setText( name );
whileBlocking( mSvgSourceLineEdit )->setSource( name );
setGuiForSvg( mLayer );
emit changed();
@ -2154,55 +2156,13 @@ void QgsSvgMarkerSymbolLayerWidget::setOffset()
emit changed();
}
void QgsSvgMarkerSymbolLayerWidget::mFileToolButton_clicked()
void QgsSvgMarkerSymbolLayerWidget::svgSourceChanged( const QString &text )
{
QgsSettings s;
QString file = QFileDialog::getOpenFileName( nullptr,
tr( "Select SVG file" ),
s.value( QStringLiteral( "/UI/lastSVGMarkerDir" ), QDir::homePath() ).toString(),
tr( "SVG files" ) + " (*.svg)" );
QFileInfo fi( file );
if ( file.isEmpty() || !fi.exists() )
{
return;
}
mFileLineEdit->setText( file );
mLayer->setPath( file );
s.setValue( QStringLiteral( "/UI/lastSVGMarkerDir" ), fi.absolutePath() );
setGuiForSvg( mLayer );
emit changed();
}
void QgsSvgMarkerSymbolLayerWidget::mFileLineEdit_textEdited( const QString &text )
{
if ( !QFileInfo::exists( text ) )
{
return;
}
mLayer->setPath( text );
setGuiForSvg( mLayer );
emit changed();
}
void QgsSvgMarkerSymbolLayerWidget::mFileLineEdit_editingFinished()
{
if ( !QFileInfo::exists( mFileLineEdit->text() ) )
{
QUrl url( mFileLineEdit->text() );
if ( !url.isValid() )
{
return;
}
}
QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
mLayer->setPath( mFileLineEdit->text() );
QApplication::restoreOverrideCursor();
setGuiForSvg( mLayer );
emit changed();
}
void QgsSvgMarkerSymbolLayerWidget::mChangeColorButton_colorChanged( const QColor &color )
{
if ( !mLayer )
@ -2288,10 +2248,8 @@ QgsSVGFillSymbolLayerWidget::QgsSVGFillSymbolLayerWidget( QgsVectorLayer *vl, QW
{
mLayer = nullptr;
setupUi( this );
connect( mBrowseToolButton, &QToolButton::clicked, this, &QgsSVGFillSymbolLayerWidget::mBrowseToolButton_clicked );
connect( mTextureWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSVGFillSymbolLayerWidget::mTextureWidthSpinBox_valueChanged );
connect( mSVGLineEdit, &QLineEdit::textEdited, this, &QgsSVGFillSymbolLayerWidget::mSVGLineEdit_textEdited );
connect( mSVGLineEdit, &QLineEdit::editingFinished, this, &QgsSVGFillSymbolLayerWidget::mSVGLineEdit_editingFinished );
connect( mSvgSourceLineEdit, &QgsSvgSourceLineEdit::sourceChanged, this, &QgsSVGFillSymbolLayerWidget::svgSourceChanged );
connect( mRotationSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSVGFillSymbolLayerWidget::mRotationSpinBox_valueChanged );
connect( mChangeColorButton, &QgsColorButton::colorChanged, this, &QgsSVGFillSymbolLayerWidget::mChangeColorButton_colorChanged );
connect( mChangeStrokeColorButton, &QgsColorButton::colorChanged, this, &QgsSVGFillSymbolLayerWidget::mChangeStrokeColorButton_colorChanged );
@ -2335,7 +2293,7 @@ void QgsSVGFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer *layer )
mTextureWidthSpinBox->blockSignals( true );
mTextureWidthSpinBox->setValue( width );
mTextureWidthSpinBox->blockSignals( false );
mSVGLineEdit->setText( mLayer->svgFilePath() );
whileBlocking( mSvgSourceLineEdit )->setSource( mLayer->svgFilePath() );
mRotationSpinBox->blockSignals( true );
mRotationSpinBox->setValue( mLayer->angle() );
mRotationSpinBox->blockSignals( false );
@ -2372,16 +2330,6 @@ QgsSymbolLayer *QgsSVGFillSymbolLayerWidget::symbolLayer()
return mLayer;
}
void QgsSVGFillSymbolLayerWidget::mBrowseToolButton_clicked()
{
QString filePath = QFileDialog::getOpenFileName( nullptr, tr( "Select SVG Texture File" ), QDir::homePath(), tr( "SVG file" ) + " (*.svg);;" + tr( "All files" ) + " (*.*)" );
if ( !filePath.isNull() )
{
mSVGLineEdit->setText( filePath );
emit changed();
}
}
void QgsSVGFillSymbolLayerWidget::mTextureWidthSpinBox_valueChanged( double d )
{
if ( mLayer )
@ -2391,53 +2339,23 @@ void QgsSVGFillSymbolLayerWidget::mTextureWidthSpinBox_valueChanged( double d )
}
}
void QgsSVGFillSymbolLayerWidget::mSVGLineEdit_textEdited( const QString &text )
void QgsSVGFillSymbolLayerWidget::svgSourceChanged( const QString &text )
{
if ( !mLayer )
{
return;
}
QFileInfo fi( text );
if ( !fi.exists() )
{
return;
}
mLayer->setSvgFilePath( text );
updateParamGui();
emit changed();
}
void QgsSVGFillSymbolLayerWidget::mSVGLineEdit_editingFinished()
{
if ( !mLayer )
{
return;
}
QFileInfo fi( mSVGLineEdit->text() );
if ( !fi.exists() )
{
QUrl url( mSVGLineEdit->text() );
if ( !url.isValid() )
{
return;
}
}
QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
mLayer->setSvgFilePath( mSVGLineEdit->text() );
QApplication::restoreOverrideCursor();
updateParamGui();
emit changed();
}
void QgsSVGFillSymbolLayerWidget::setFile( const QModelIndex &item )
{
QString file = item.data( Qt::UserRole ).toString();
mLayer->setSvgFilePath( file );
mSVGLineEdit->setText( file );
whileBlocking( mSvgSourceLineEdit )->setSource( file );
updateParamGui();
emit changed();
@ -2492,7 +2410,7 @@ void QgsSVGFillSymbolLayerWidget::updateParamGui( bool resetValues )
QColor defaultFill, defaultStroke;
double defaultStrokeWidth, defaultFillOpacity, defaultStrokeOpacity;
bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultStrokeColor, hasDefaultStrokeWidth, hasDefaultStrokeOpacity;
QgsApplication::svgCache()->containsParams( mSVGLineEdit->text(), hasFillParam, hasDefaultFillColor, defaultFill,
QgsApplication::svgCache()->containsParams( mSvgSourceLineEdit->source(), hasFillParam, hasDefaultFillColor, defaultFill,
hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
hasStrokeParam, hasDefaultStrokeColor, defaultStroke,
hasStrokeWidthParam, hasDefaultStrokeWidth, defaultStrokeWidth,

View File

@ -546,9 +546,7 @@ class GUI_EXPORT QgsSvgMarkerSymbolLayerWidget : public QgsSymbolLayerWidget, pr
private slots:
void setName( const QModelIndex &idx );
void populateIcons( const QModelIndex &idx );
void mFileToolButton_clicked();
void mFileLineEdit_textEdited( const QString &text );
void mFileLineEdit_editingFinished();
void svgSourceChanged( const QString &text );
void mChangeColorButton_colorChanged( const QColor &color );
void mChangeStrokeColorButton_colorChanged( const QColor &color );
void mStrokeWidthSpinBox_valueChanged( double d );
@ -668,10 +666,8 @@ class GUI_EXPORT QgsSVGFillSymbolLayerWidget : public QgsSymbolLayerWidget, priv
void updateParamGui( bool resetValues = true );
private slots:
void mBrowseToolButton_clicked();
void mTextureWidthSpinBox_valueChanged( double d );
void mSVGLineEdit_textEdited( const QString &text );
void mSVGLineEdit_editingFinished();
void svgSourceChanged( const QString &text );
void setFile( const QModelIndex &item );
void populateIcons( const QModelIndex &item );
void mRotationSpinBox_valueChanged( double d );

View File

@ -7,27 +7,104 @@
<x>0</x>
<y>0</y>
<width>328</width>
<height>497</height>
<height>509</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="10" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item row="3" column="3">
<widget class="QgsPropertyOverrideButton" name="mFilColorDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="mSVGLineEdit"/>
<widget class="QgsDoubleSpinBox" name="mTextureWidthSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>999999999.999999046325684</double>
</property>
<property name="singleStep">
<double>0.200000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="mBrowseToolButton">
<property name="text">
<string>…</string>
<widget class="QgsUnitSelectionWidget" name="mTextureWidthUnitWidget" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="8" column="3">
<widget class="QgsPropertyOverrideButton" name="mRotationDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QgsDoubleSpinBox" name="mRotationSpinBox">
<property name="wrapping">
<bool>true</bool>
</property>
<property name="suffix">
<string> °</string>
</property>
<property name="minimum">
<double>-360.000000000000000</double>
</property>
<property name="maximum">
<double>360.000000000000000</double>
</property>
<property name="singleStep">
<double>0.500000000000000</double>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QgsColorButton" name="mChangeColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="mStrokeColorLabel">
<property name="sizePolicy">
@ -41,7 +118,52 @@
</property>
</widget>
</item>
<item row="6" column="2">
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Fill color</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QgsColorButton" name="mChangeStrokeColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="mRotationLabel">
<property name="text">
<string>Rotation</string>
</property>
</widget>
</item>
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QgsDoubleSpinBox" name="mStrokeWidthSpinBox">
@ -84,40 +206,22 @@
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QgsColorButton" name="mChangeColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="3">
<widget class="QgsPropertyOverrideButton" name="mStrokeColorDDBtn">
<item row="0" column="3">
<widget class="QgsPropertyOverrideButton" name="mTextureWidthDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="6" column="3">
<widget class="QgsPropertyOverrideButton" name="mStrokeWidthDDBtn">
<item row="0" column="0">
<widget class="QLabel" name="mTextureWidthLabel">
<property name="text">
<string>Texture width</string>
</property>
</widget>
</item>
<item row="10" column="3">
<widget class="QgsPropertyOverrideButton" name="mSVGDDBtn">
<property name="text">
<string>…</string>
</property>
@ -194,135 +298,24 @@
</item>
</layout>
</item>
<item row="10" column="3">
<widget class="QgsPropertyOverrideButton" name="mSVGDDBtn">
<item row="6" column="3">
<widget class="QgsPropertyOverrideButton" name="mStrokeWidthDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QgsPropertyOverrideButton" name="mFilColorDDBtn">
<item row="5" column="3">
<widget class="QgsPropertyOverrideButton" name="mStrokeColorDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QgsColorButton" name="mChangeStrokeColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Fill color</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="mRotationLabel">
<property name="text">
<string>Rotation</string>
</property>
</widget>
</item>
<item row="8" column="2">
<widget class="QgsDoubleSpinBox" name="mRotationSpinBox">
<property name="wrapping">
<bool>true</bool>
</property>
<property name="suffix">
<string> °</string>
</property>
<property name="minimum">
<double>-360.000000000000000</double>
</property>
<property name="maximum">
<double>360.000000000000000</double>
</property>
<property name="singleStep">
<double>0.500000000000000</double>
</property>
</widget>
</item>
<item row="8" column="3">
<widget class="QgsPropertyOverrideButton" name="mRotationDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mTextureWidthLabel">
<property name="text">
<string>Texture width</string>
</property>
</widget>
</item>
<item row="0" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QgsDoubleSpinBox" name="mTextureWidthSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>999999999.999999046325684</double>
</property>
<property name="singleStep">
<double>0.200000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QgsUnitSelectionWidget" name="mTextureWidthUnitWidget" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="3">
<widget class="QgsPropertyOverrideButton" name="mTextureWidthDDBtn">
<property name="text">
<string>…</string>
<item row="10" column="0" colspan="3">
<widget class="QgsSvgSourceLineEdit" name="mSvgSourceLineEdit" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
@ -330,15 +323,21 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsPropertyOverrideButton</class>
<extends>QToolButton</extends>
<header>qgspropertyoverridebutton.h</header>
<class>QgsColorButton</class>
<extends>QPushButton</extends>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>qgsdoublespinbox.h</header>
</customwidget>
<customwidget>
<class>QgsPropertyOverrideButton</class>
<extends>QToolButton</extends>
<header>qgspropertyoverridebutton.h</header>
</customwidget>
<customwidget>
<class>QgsUnitSelectionWidget</class>
<extends>QWidget</extends>
@ -346,9 +345,9 @@
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
<class>QgsSvgSourceLineEdit</class>
<extends>QWidget</extends>
<header>qgssvgsourcelineedit.h</header>
<container>1</container>
</customwidget>
</customwidgets>
@ -367,8 +366,7 @@
<tabstop>mRotationDDBtn</tabstop>
<tabstop>mSvgTreeView</tabstop>
<tabstop>mSvgListView</tabstop>
<tabstop>mSVGLineEdit</tabstop>
<tabstop>mBrowseToolButton</tabstop>
<tabstop>mSvgSourceLineEdit</tabstop>
<tabstop>mSVGDDBtn</tabstop>
</tabstops>
<resources/>

View File

@ -13,191 +13,17 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0,0">
<item row="0" column="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QgsPropertyOverrideButton" name="mWidthDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item>
<widget class="QgsPropertyOverrideButton" name="mHeightDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Rotation</string>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0,0,0">
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Offset</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mStrokeWidthLabel">
<property name="text">
<string>Stroke width</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QgsPropertyOverrideButton" name="mStrokeWidthDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="mFileLineEdit"/>
</item>
<item>
<widget class="QToolButton" name="mFileToolButton">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Width</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsDoubleSpinBox" name="spinWidth">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.200000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
<property name="showClearButton">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsDoubleSpinBox" name="spinHeight">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.200000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
<property name="showClearButton">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="2">
<layout class="QHBoxLayout" name="_2">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QgsRatioLockButton" name="mLockAspectRatio">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Lock aspect ratio</string>
</property>
<property name="leftMargin" stdset="0">
<number>13</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="3" rowspan="2">
<widget class="QgsUnitSelectionWidget" name="mSizeUnitWidget" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="10" column="2">
<widget class="QgsPropertyOverrideButton" name="mFilenameDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QgsPropertyOverrideButton" name="mAngleDDBtn">
<property name="text">
<string>…</string>
<string>Fill color</string>
</property>
</widget>
</item>
@ -282,90 +108,41 @@
</item>
</layout>
</item>
<item row="1" column="2">
<widget class="QgsPropertyOverrideButton" name="mFillColorDDBtn">
<property name="text">
<string>…</string>
<item row="5" column="1">
<widget class="QgsDoubleSpinBox" name="spinAngle">
<property name="wrapping">
<bool>true</bool>
</property>
<property name="suffix">
<string> °</string>
</property>
<property name="decimals">
<number>2</number>
</property>
<property name="minimum">
<double>-360.000000000000000</double>
</property>
<property name="maximum">
<double>360.000000000000000</double>
</property>
<property name="singleStep">
<double>0.500000000000000</double>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QgsPropertyOverrideButton" name="mStrokeColorDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mStrokeColorLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Stroke color</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButton" name="mChangeColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Size</string>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item row="0" column="3">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QgsDoubleSpinBox" name="mStrokeWidthSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="specialValueText">
<string>No stroke</string>
</property>
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>999999999.999999046325684</double>
</property>
<property name="singleStep">
<double>0.200000000000000</double>
</property>
<property name="value">
<double>0.200000000000000</double>
</property>
<property name="showClearButton">
<bool>false</bool>
<widget class="QgsPropertyOverrideButton" name="mWidthDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item>
<widget class="QgsUnitSelectionWidget" name="mStrokeWidthUnitWidget" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
<widget class="QgsPropertyOverrideButton" name="mHeightDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
@ -396,67 +173,79 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QgsDoubleSpinBox" name="spinAngle">
<property name="wrapping">
<bool>true</bool>
</property>
<property name="suffix">
<string> °</string>
</property>
<property name="decimals">
<number>2</number>
</property>
<property name="minimum">
<double>-360.000000000000000</double>
</property>
<property name="maximum">
<double>360.000000000000000</double>
</property>
<property name="singleStep">
<double>0.500000000000000</double>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="mHorizontalAnchorComboBox">
<item>
<property name="text">
<string>Left</string>
</property>
</item>
<item>
<property name="text">
<string>HCenter</string>
</property>
</item>
<item>
<property name="text">
<string>Right</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Fill color</string>
</property>
</widget>
</item>
<item row="7" column="2">
<item row="7" column="3">
<widget class="QgsPropertyOverrideButton" name="mVerticalAnchorDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QgsPropertyOverrideButton" name="mFillColorDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Offset</string>
</property>
</widget>
</item>
<item row="10" column="3">
<widget class="QgsPropertyOverrideButton" name="mFilenameDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QgsDoubleSpinBox" name="mStrokeWidthSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="specialValueText">
<string>No stroke</string>
</property>
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>999999999.999999046325684</double>
</property>
<property name="singleStep">
<double>0.200000000000000</double>
</property>
<property name="value">
<double>0.200000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QgsUnitSelectionWidget" name="mStrokeWidthUnitWidget" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="1">
<widget class="QComboBox" name="mVerticalAnchorComboBox">
<item>
@ -476,7 +265,14 @@
</item>
</widget>
</item>
<item row="9" column="0" colspan="3">
<item row="5" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Rotation</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="4">
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -567,13 +363,43 @@
</widget>
</widget>
</item>
<item row="8" column="2">
<widget class="QgsPropertyOverrideButton" name="mHorizontalAnchorDDBtn">
<item row="3" column="3">
<widget class="QgsPropertyOverrideButton" name="mStrokeColorDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Size</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButton" name="mChangeColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mStrokeColorLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Stroke color</string>
</property>
</widget>
</item>
<item row="7" column="0" rowspan="2">
<widget class="QLabel" name="mAnchorPointLabel">
<property name="text">
@ -581,13 +407,180 @@
</property>
</widget>
</item>
<item row="6" column="2">
<item row="6" column="3">
<widget class="QgsPropertyOverrideButton" name="mOffsetDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Width</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsDoubleSpinBox" name="spinWidth">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.200000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsDoubleSpinBox" name="spinHeight">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.200000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="2">
<layout class="QHBoxLayout" name="_2">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QgsRatioLockButton" name="mLockAspectRatio" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Lock aspect ratio</string>
</property>
<property name="leftMargin" stdset="0">
<number>13</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="3" rowspan="2">
<widget class="QgsUnitSelectionWidget" name="mSizeUnitWidget" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="3">
<widget class="QgsPropertyOverrideButton" name="mStrokeWidthDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mStrokeWidthLabel">
<property name="text">
<string>Stroke width</string>
</property>
</widget>
</item>
<item row="8" column="3">
<widget class="QgsPropertyOverrideButton" name="mHorizontalAnchorDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="mHorizontalAnchorComboBox">
<item>
<property name="text">
<string>Left</string>
</property>
</item>
<item>
<property name="text">
<string>HCenter</string>
</property>
</item>
<item>
<property name="text">
<string>Right</string>
</property>
</item>
</widget>
</item>
<item row="5" column="3">
<widget class="QgsPropertyOverrideButton" name="mAngleDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="3">
<widget class="QgsSvgSourceLineEdit" name="mSvgSourceLineEdit" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
@ -613,11 +606,21 @@
<header>qgsunitselectionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsRatioLockButton</class>
<extends>QWidget</extends>
<header>qgsratiolockbutton.h</header>
</customwidget>
<customwidget>
<class>QgsSvgSourceLineEdit</class>
<extends>QWidget</extends>
<header>qgssvgsourcelineedit.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>spinWidth</tabstop>
<tabstop>spinHeight</tabstop>
<tabstop>mLockAspectRatio</tabstop>
<tabstop>mSizeUnitWidget</tabstop>
<tabstop>mWidthDDBtn</tabstop>
<tabstop>mHeightDDBtn</tabstop>
@ -640,8 +643,7 @@
<tabstop>mHorizontalAnchorDDBtn</tabstop>
<tabstop>viewGroups</tabstop>
<tabstop>viewImages</tabstop>
<tabstop>mFileLineEdit</tabstop>
<tabstop>mFileToolButton</tabstop>
<tabstop>mSvgSourceLineEdit</tabstop>
<tabstop>mFilenameDDBtn</tabstop>
</tabstops>
<resources/>

View File

@ -26,20 +26,6 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="1">
<widget class="QLabel" name="mImagesLabel">
<property name="text">
<string>SVG Images</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mGroupsLabel">
<property name="text">
<string>SVG Groups</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QTreeView" name="mGroupsTreeView">
<property name="sizePolicy">
@ -56,6 +42,13 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="mImagesLabel">
<property name="text">
<string>SVG Images</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QListView" name="mImagesListView">
<property name="sizePolicy">
@ -102,33 +95,33 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mGroupsLabel">
<property name="text">
<string>SVG Groups</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="mFileLayout">
<item>
<widget class="QLineEdit" name="mFileLineEdit"/>
</item>
<item>
<widget class="QPushButton" name="mFilePushButton">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>…</string>
</property>
</widget>
</item>
</layout>
<widget class="QgsSvgSourceLineEdit" name="mSvgSourceLineEdit" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsSvgSourceLineEdit</class>
<extends>QWidget</extends>
<header>qgssvgsourcelineedit.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mGroupsTreeView</tabstop>
<tabstop>mImagesListView</tabstop>
<tabstop>mFileLineEdit</tabstop>
<tabstop>mFilePushButton</tabstop>
</tabstops>
<resources/>
<connections/>

View File

@ -183,6 +183,7 @@ ADD_PYTHON_TEST(PyQgsArrowSymbolLayer test_qgsarrowsymbollayer.py)
ADD_PYTHON_TEST(PyQgsSymbolExpressionVariables test_qgssymbolexpressionvariables.py)
ADD_PYTHON_TEST(PyQgsSyntacticSugar test_syntactic_sugar.py)
ADD_PYTHON_TEST(PyQgsStringUtils test_qgsstringutils.py)
ADD_PYTHON_TEST(PyQgsSvgSourceLineEdit test_qgssvgsourcelineedit.py)
ADD_PYTHON_TEST(PyQgsSymbol test_qgssymbol.py)
ADD_PYTHON_TEST(PyQgsSymbolLayerUtils test_qgssymbollayerutils.py)
ADD_PYTHON_TEST(PyQgsTaskManager test_qgstaskmanager.py)

View File

@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsSvgSourceLineEdit
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Nyall Dawson'
__date__ = '19/07/2018'
__copyright__ = 'Copyright 2018, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import qgis # NOQA
from qgis.gui import QgsSvgSourceLineEdit
from qgis.PyQt.QtTest import QSignalSpy
from qgis.testing import start_app, unittest
start_app()
class TestQgsSvgSourceLineEdit(unittest.TestCase):
def testGettersSetters(self):
""" test widget getters/setters """
w = QgsSvgSourceLineEdit()
spy = QSignalSpy(w.sourceChanged)
w.setSource('source')
self.assertEqual(w.source(), 'source')
self.assertEqual(len(spy), 1)
self.assertEqual(spy[0][0], 'source')
# no signal for same value
w.setSource('source')
self.assertEqual(w.source(), 'source')
self.assertEqual(len(spy), 1)
w.setSource('another')
self.assertEqual(w.source(), 'another')
self.assertEqual(len(spy), 2)
self.assertEqual(spy[1][0], 'another')
if __name__ == '__main__':
unittest.main()