Skip to content

Commit

Permalink
add QgsSvgOrImageSourceLineEdit to dynamically switch between SVG and…
Browse files Browse the repository at this point in the history
… Image line edit
  • Loading branch information
3nids committed May 11, 2021
1 parent 05f55f0 commit ab6c969
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 86 deletions.
52 changes: 47 additions & 5 deletions python/gui/auto_generated/qgsfilecontentsourcelineedit.sip.in
Expand Up @@ -95,7 +95,52 @@ Emitted whenever the file source is changed in the widget.

};

class QgsSvgSourceLineEdit : QgsAbstractFileContentSourceLineEdit


class QgsSvgOrImageSourceLineEdit : QgsAbstractFileContentSourceLineEdit
{
%Docstring(signature="appended")
A line edit widget with toolbutton for setting a raster image path.

Designed for use with :py:class:`QgsImageCache`.

.. seealso:: :py:class:`QgsSvgSourceLineEdit`

.. versionadded:: 3.20
%End

%TypeHeaderCode
#include "qgsfilecontentsourcelineedit.h"
%End
public:

enum Format
{
Svg,
Image,
};

QgsSvgOrImageSourceLineEdit( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for :py:class:`QgsImageSourceLineEdit`, with the specified ``parent`` widget.
%End

void setMode( Format format );
%Docstring
Defines the mode of the source line edit
%End

protected:

QgsSvgOrImageSourceLineEdit( Format format, QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for :py:class:`QgsImageSourceLineEdit`, with the specified ``parent`` widget.
%End

};


class QgsSvgSourceLineEdit : QgsSvgOrImageSourceLineEdit
{
%Docstring(signature="appended")
A line edit widget with toolbutton for setting an SVG image path.
Expand All @@ -116,11 +161,9 @@ Designed for use with :py:class:`QgsSvgCache`.
%Docstring
Constructor for QgsSvgSourceLineEdit, with the specified ``parent`` widget.
%End

};


class QgsImageSourceLineEdit : QgsAbstractFileContentSourceLineEdit
class QgsImageSourceLineEdit : QgsSvgOrImageSourceLineEdit
{
%Docstring(signature="appended")
A line edit widget with toolbutton for setting a raster image path.
Expand All @@ -141,7 +184,6 @@ Designed for use with :py:class:`QgsImageCache`.
%Docstring
Constructor for QgsImageSourceLineEdit, with the specified ``parent`` widget.
%End

};

/************************************************************************
Expand Down
118 changes: 61 additions & 57 deletions src/gui/qgsfilecontentsourcelineedit.cpp
Expand Up @@ -269,97 +269,101 @@ QString QgsAbstractFileContentSourceLineEdit::settingsKey() const
return mLastPathKey.isEmpty() ? defaultSettingsKey() : mLastPathKey;
}

//
// QgsSvgSourceLineEdit
//

///@cond PRIVATE

QString QgsSvgSourceLineEdit::fileFilter() const
{
return tr( "SVG files" ) + " (*.svg)";
}

QString QgsSvgSourceLineEdit::selectFileTitle() const
{
return tr( "Select SVG File" );
}

QString QgsSvgSourceLineEdit::fileFromUrlTitle() const
{
return tr( "SVG From URL" );
}

QString QgsSvgSourceLineEdit::fileFromUrlText() const
void QgsAbstractFileContentSourceLineEdit::setMessageBar( QgsMessageBar *bar )
{
return tr( "Enter SVG URL" );
mMessageBar = bar;
}

QString QgsSvgSourceLineEdit::embedFileTitle() const
QgsMessageBar *QgsAbstractFileContentSourceLineEdit::messageBar() const
{
return tr( "Embed SVG File" );
return mMessageBar;
}

QString QgsSvgSourceLineEdit::extractFileTitle() const
{
return tr( "Extract SVG File" );
}

QString QgsSvgSourceLineEdit::defaultSettingsKey() const
{
return QStringLiteral( "/UI/lastSVGDir" );
}
///@endcond

//
// QgsImageSourceLineEdit
// QgsSvgOrImageSourceLineEdit
//

///@cond PRIVATE

QString QgsImageSourceLineEdit::fileFilter() const
QString QgsSvgOrImageSourceLineEdit::fileFilter() const
{
return tr( "All files" ) + " (*.*)";
switch ( mFormat )
{
case Svg:
return tr( "SVG files" ) + " (*.svg)";
case Image:
return tr( "All files" ) + " (*.*)";
}
}

QString QgsImageSourceLineEdit::selectFileTitle() const
QString QgsSvgOrImageSourceLineEdit::selectFileTitle() const
{
return tr( "Select Image File" );
switch ( mFormat )
{
case Svg:
return tr( "Select SVG File" );
case Image:
return tr( "Select Image File" );
}
}

QString QgsImageSourceLineEdit::fileFromUrlTitle() const
QString QgsSvgOrImageSourceLineEdit::fileFromUrlTitle() const
{
return tr( "Image From URL" );
switch ( mFormat )
{
case Svg:
return tr( "SVG From URL" );
case Image:
return tr( "Image From URL" );
}
}

QString QgsImageSourceLineEdit::fileFromUrlText() const
QString QgsSvgOrImageSourceLineEdit::fileFromUrlText() const
{
return tr( "Enter image URL" );
switch ( mFormat )
{
case Svg:
return tr( "Enter SVG URL" );
case Image:
return tr( "Enter image URL" );
}
}

QString QgsImageSourceLineEdit::embedFileTitle() const
QString QgsSvgOrImageSourceLineEdit::embedFileTitle() const
{
return tr( "Embed Image File" );
switch ( mFormat )
{
case Svg:
return tr( "Embed SVG File" );
case Image:
return tr( "Embed Image File" );
}
}

QString QgsImageSourceLineEdit::extractFileTitle() const
QString QgsSvgOrImageSourceLineEdit::extractFileTitle() const
{
return tr( "Extract Image File" );
switch ( mFormat )
{
case Svg:
return tr( "Extract SVG File" );
case Image:
return tr( "Extract Image File" );
}
}

QString QgsImageSourceLineEdit::defaultSettingsKey() const
QString QgsSvgOrImageSourceLineEdit::defaultSettingsKey() const
{
return QStringLiteral( "/UI/lastImageDir" );
switch ( mFormat )
{
case Svg:
return QStringLiteral( "/UI/lastSVGDir" );
case Image:
return QStringLiteral( "/UI/lastImageDir" );
}
}

///@endcond

void QgsAbstractFileContentSourceLineEdit::setMessageBar( QgsMessageBar *bar )
{
mMessageBar = bar;
}

QgsMessageBar *QgsAbstractFileContentSourceLineEdit::messageBar() const
{
return mMessageBar;
}
84 changes: 60 additions & 24 deletions src/gui/qgsfilecontentsourcelineedit.h
Expand Up @@ -176,30 +176,55 @@ class GUI_EXPORT QgsAbstractFileContentSourceLineEdit : public QWidget SIP_ABSTR

};



/**
* \ingroup gui
* \class QgsSvgSourceLineEdit
* \brief A line edit widget with toolbutton for setting an SVG image path.
* \class QgsImageSourceLineEdit
* \brief A line edit widget with toolbutton for setting a raster image path.
*
* Designed for use with QgsSvgCache.
* Designed for use with QgsImageCache.
*
* \see QgsImageSourceLineEdit
* \see QgsSvgSourceLineEdit
*
* \since QGIS 3.4
* \since QGIS 3.20
*/
class GUI_EXPORT QgsSvgSourceLineEdit : public QgsAbstractFileContentSourceLineEdit
class GUI_EXPORT QgsSvgOrImageSourceLineEdit : public QgsAbstractFileContentSourceLineEdit
{
Q_OBJECT
public:

/**
* Constructor for QgsSvgSourceLineEdit, with the specified \a parent widget.
* Format of source image
*/
QgsSvgSourceLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr )
enum Format
{
Svg, //!< SVG image
Image, //!< Raster image
};

/**
* Constructor for QgsImageSourceLineEdit, with the specified \a parent widget.
*/
QgsSvgOrImageSourceLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr )
: QgsAbstractFileContentSourceLineEdit( parent )
{}

//! Defines the mode of the source line edit
void setMode( Format format ) {mFormat = format;}

protected:

/**
* Constructor for QgsImageSourceLineEdit, with the specified \a parent widget.
*/
QgsSvgOrImageSourceLineEdit( Format format, QWidget *parent SIP_TRANSFERTHIS = nullptr )
: QgsAbstractFileContentSourceLineEdit( parent )
, mFormat( format )
{}

private:
Format mFormat = Svg;

#ifndef SIP_RUN
///@cond PRIVATE
Expand All @@ -210,11 +235,35 @@ class GUI_EXPORT QgsSvgSourceLineEdit : public QgsAbstractFileContentSourceLineE
QString embedFileTitle() const override;
QString extractFileTitle() const override;
QString defaultSettingsKey() const override;
///@endcond
///@endcond
#endif
};


/**
* \ingroup gui
* \class QgsSvgSourceLineEdit
* \brief A line edit widget with toolbutton for setting an SVG image path.
*
* Designed for use with QgsSvgCache.
*
* \see QgsImageSourceLineEdit
*
* \since QGIS 3.4
*/
class GUI_EXPORT QgsSvgSourceLineEdit : public QgsSvgOrImageSourceLineEdit
{
Q_OBJECT
public:

/**
* Constructor for QgsSvgSourceLineEdit, with the specified \a parent widget.
*/
QgsSvgSourceLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr )
: QgsSvgOrImageSourceLineEdit( Svg, parent )
{}
};

/**
* \ingroup gui
* \class QgsImageSourceLineEdit
Expand All @@ -226,7 +275,7 @@ class GUI_EXPORT QgsSvgSourceLineEdit : public QgsAbstractFileContentSourceLineE
*
* \since QGIS 3.6
*/
class GUI_EXPORT QgsImageSourceLineEdit : public QgsAbstractFileContentSourceLineEdit
class GUI_EXPORT QgsImageSourceLineEdit : public QgsSvgOrImageSourceLineEdit
{
Q_OBJECT
public:
Expand All @@ -235,21 +284,8 @@ class GUI_EXPORT QgsImageSourceLineEdit : public QgsAbstractFileContentSourceLin
* Constructor for QgsImageSourceLineEdit, with the specified \a parent widget.
*/
QgsImageSourceLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr )
: QgsAbstractFileContentSourceLineEdit( parent )
: QgsSvgOrImageSourceLineEdit( Image, parent )
{}

private:
#ifndef SIP_RUN
///@cond PRIVATE
QString fileFilter() const override;
QString selectFileTitle() const override;
QString fileFromUrlTitle() const override;
QString fileFromUrlText() const override;
QString embedFileTitle() const override;
QString extractFileTitle() const override;
QString defaultSettingsKey() const override;
///@endcond
#endif
};

#endif // QGSFILECONTENTSOURCELINEEDIT_H

0 comments on commit ab6c969

Please sign in to comment.