mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
Add a script language enum
This commit is contained in:
parent
dd4984eb49
commit
04dbee6eb7
@ -2044,3 +2044,16 @@ Qgis.CoordinateDisplayType.CustomCrs.__doc__ = "Custom CRS"
|
||||
Qgis.CoordinateDisplayType.__doc__ = 'Formats for displaying coordinates\n\n.. versionadded:: 3.28\n\n' + '* ``MapCrs``: ' + Qgis.CoordinateDisplayType.MapCrs.__doc__ + '\n' + '* ``MapGeographic``: ' + Qgis.CoordinateDisplayType.MapGeographic.__doc__ + '\n' + '* ``CustomCrs``: ' + Qgis.CoordinateDisplayType.CustomCrs.__doc__
|
||||
# --
|
||||
Qgis.CoordinateDisplayType.baseClass = Qgis
|
||||
# monkey patching scoped based enum
|
||||
Qgis.ScriptLanguage.Css.__doc__ = "CSS"
|
||||
Qgis.ScriptLanguage.QgisExpression.__doc__ = "QGIS expressions"
|
||||
Qgis.ScriptLanguage.Html.__doc__ = "HTML"
|
||||
Qgis.ScriptLanguage.JavaScript.__doc__ = "JavaScript"
|
||||
Qgis.ScriptLanguage.Json.__doc__ = "JSON"
|
||||
Qgis.ScriptLanguage.Python.__doc__ = "Python"
|
||||
Qgis.ScriptLanguage.R.__doc__ = "R Stats"
|
||||
Qgis.ScriptLanguage.Sql.__doc__ = "SQL"
|
||||
Qgis.ScriptLanguage.Unknown.__doc__ = "Unknown/other language"
|
||||
Qgis.ScriptLanguage.__doc__ = 'Scripting languages.\n\n.. versionadded:: 3.30\n\n' + '* ``Css``: ' + Qgis.ScriptLanguage.Css.__doc__ + '\n' + '* ``QgisExpression``: ' + Qgis.ScriptLanguage.QgisExpression.__doc__ + '\n' + '* ``Html``: ' + Qgis.ScriptLanguage.Html.__doc__ + '\n' + '* ``JavaScript``: ' + Qgis.ScriptLanguage.JavaScript.__doc__ + '\n' + '* ``Json``: ' + Qgis.ScriptLanguage.Json.__doc__ + '\n' + '* ``Python``: ' + Qgis.ScriptLanguage.Python.__doc__ + '\n' + '* ``R``: ' + Qgis.ScriptLanguage.R.__doc__ + '\n' + '* ``Sql``: ' + Qgis.ScriptLanguage.Sql.__doc__ + '\n' + '* ``Unknown``: ' + Qgis.ScriptLanguage.Unknown.__doc__
|
||||
# --
|
||||
Qgis.ScriptLanguage.baseClass = Qgis
|
||||
|
@ -1327,6 +1327,19 @@ The development version
|
||||
CustomCrs,
|
||||
};
|
||||
|
||||
enum class ScriptLanguage
|
||||
{
|
||||
Css,
|
||||
QgisExpression,
|
||||
Html,
|
||||
JavaScript,
|
||||
Json,
|
||||
Python,
|
||||
R,
|
||||
Sql,
|
||||
Unknown,
|
||||
};
|
||||
|
||||
static const double DEFAULT_SEARCH_RADIUS_MM;
|
||||
|
||||
static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
class QgsCodeEditor : QsciScintilla
|
||||
{
|
||||
%Docstring(signature="appended")
|
||||
@ -71,6 +72,20 @@ Construct a new code editor.
|
||||
Set the widget title
|
||||
|
||||
:param title: widget title
|
||||
%End
|
||||
|
||||
virtual Qgis::ScriptLanguage language() const;
|
||||
%Docstring
|
||||
Returns the associated scripting language.
|
||||
|
||||
.. versionadded:: 3.30
|
||||
%End
|
||||
|
||||
static QString languageToString( Qgis::ScriptLanguage language );
|
||||
%Docstring
|
||||
Returns a user-friendly, translated name of the specified script ``language``.
|
||||
|
||||
.. versionadded:: 3.30
|
||||
%End
|
||||
|
||||
void setMarginVisible( bool margin ) /Deprecated/;
|
||||
|
@ -30,6 +30,8 @@ code autocompletion.
|
||||
%Docstring
|
||||
Constructor for QgsCodeEditorCSS
|
||||
%End
|
||||
virtual Qgis::ScriptLanguage language() const;
|
||||
|
||||
|
||||
protected:
|
||||
virtual void initializeLexer();
|
||||
|
@ -29,6 +29,9 @@ code autocompletion.
|
||||
Constructor for QgsCodeEditorExpression
|
||||
%End
|
||||
|
||||
virtual Qgis::ScriptLanguage language() const;
|
||||
|
||||
|
||||
void setExpressionContext( const QgsExpressionContext &context );
|
||||
%Docstring
|
||||
Variables and functions from this expression context will be added to
|
||||
|
@ -32,6 +32,9 @@ code autocompletion.
|
||||
Constructor for QgsCodeEditorHTML
|
||||
%End
|
||||
|
||||
virtual Qgis::ScriptLanguage language() const;
|
||||
|
||||
|
||||
protected:
|
||||
virtual void initializeLexer();
|
||||
|
||||
|
@ -28,6 +28,8 @@ code autocompletion.
|
||||
%Docstring
|
||||
Constructor for QgsCodeEditorJavascript
|
||||
%End
|
||||
virtual Qgis::ScriptLanguage language() const;
|
||||
|
||||
|
||||
protected:
|
||||
virtual void initializeLexer();
|
||||
|
@ -29,6 +29,9 @@ code autocompletion.
|
||||
Constructor for QgsCodeEditorJson
|
||||
%End
|
||||
|
||||
virtual Qgis::ScriptLanguage language() const;
|
||||
|
||||
|
||||
protected:
|
||||
virtual void initializeLexer();
|
||||
|
||||
|
@ -38,6 +38,9 @@ Construct a new Python editor.
|
||||
.. versionadded:: 2.6
|
||||
%End
|
||||
|
||||
virtual Qgis::ScriptLanguage language() const;
|
||||
|
||||
|
||||
void loadAPIs( const QList<QString> &filenames );
|
||||
%Docstring
|
||||
Load APIs from one or more files
|
||||
|
@ -28,6 +28,8 @@ code autocompletion.
|
||||
%Docstring
|
||||
Constructor for QgsCodeEditorR
|
||||
%End
|
||||
virtual Qgis::ScriptLanguage language() const;
|
||||
|
||||
|
||||
protected:
|
||||
virtual void initializeLexer();
|
||||
|
@ -31,6 +31,8 @@ code autocompletion.
|
||||
Constructor for QgsCodeEditorSQL
|
||||
%End
|
||||
|
||||
virtual Qgis::ScriptLanguage language() const;
|
||||
|
||||
|
||||
virtual ~QgsCodeEditorSQL();
|
||||
|
||||
|
@ -2285,6 +2285,25 @@ class CORE_EXPORT Qgis
|
||||
};
|
||||
Q_ENUM( CoordinateDisplayType )
|
||||
|
||||
/**
|
||||
* Scripting languages.
|
||||
*
|
||||
* \since QGIS 3.30
|
||||
*/
|
||||
enum class ScriptLanguage : int
|
||||
{
|
||||
Css, //!< CSS
|
||||
QgisExpression, //!< QGIS expressions
|
||||
Html, //!< HTML
|
||||
JavaScript, //!< JavaScript
|
||||
Json, //!< JSON
|
||||
Python, //!< Python
|
||||
R, //!< R Stats
|
||||
Sql, //!< SQL
|
||||
Unknown, //!< Unknown/other language
|
||||
};
|
||||
Q_ENUM( ScriptLanguage )
|
||||
|
||||
/**
|
||||
* Identify search radius in mm
|
||||
* \since QGIS 2.3
|
||||
|
@ -296,6 +296,37 @@ void QgsCodeEditor::setTitle( const QString &title )
|
||||
setWindowTitle( title );
|
||||
}
|
||||
|
||||
Qgis::ScriptLanguage QgsCodeEditor::language() const
|
||||
{
|
||||
return Qgis::ScriptLanguage::Unknown;
|
||||
}
|
||||
|
||||
QString QgsCodeEditor::languageToString( Qgis::ScriptLanguage language )
|
||||
{
|
||||
switch ( language )
|
||||
{
|
||||
case Qgis::ScriptLanguage::Css:
|
||||
return tr( "CSS" );
|
||||
case Qgis::ScriptLanguage::QgisExpression:
|
||||
return tr( "Expression" );
|
||||
case Qgis::ScriptLanguage::Html:
|
||||
return tr( "HTML" );
|
||||
case Qgis::ScriptLanguage::JavaScript:
|
||||
return tr( "JavaScript" );
|
||||
case Qgis::ScriptLanguage::Json:
|
||||
return tr( "JSON" );
|
||||
case Qgis::ScriptLanguage::Python:
|
||||
return tr( "Python" );
|
||||
case Qgis::ScriptLanguage::R:
|
||||
return tr( "R" );
|
||||
case Qgis::ScriptLanguage::Sql:
|
||||
return tr( "SQL" );
|
||||
case Qgis::ScriptLanguage::Unknown:
|
||||
return QString();
|
||||
}
|
||||
BUILTIN_UNREACHABLE
|
||||
}
|
||||
|
||||
void QgsCodeEditor::setMarginVisible( bool margin )
|
||||
{
|
||||
mMargin = margin;
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
#include <QString>
|
||||
#include "qgscodeeditorcolorscheme.h"
|
||||
#include "qgis.h"
|
||||
|
||||
// qscintilla includes
|
||||
#include <Qsci/qsciapis.h>
|
||||
#include "qgis_sip.h"
|
||||
@ -110,6 +112,20 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
|
||||
*/
|
||||
void setTitle( const QString & title );
|
||||
|
||||
/**
|
||||
* Returns the associated scripting language.
|
||||
*
|
||||
* \since QGIS 3.30
|
||||
*/
|
||||
virtual Qgis::ScriptLanguage language() const;
|
||||
|
||||
/**
|
||||
* Returns a user-friendly, translated name of the specified script \a language.
|
||||
*
|
||||
* \since QGIS 3.30
|
||||
*/
|
||||
static QString languageToString( Qgis::ScriptLanguage language );
|
||||
|
||||
/**
|
||||
* Set margin visible state
|
||||
* \param margin Set margin in the editor
|
||||
|
@ -36,6 +36,11 @@ QgsCodeEditorCSS::QgsCodeEditorCSS( QWidget *parent )
|
||||
QgsCodeEditorCSS::initializeLexer();
|
||||
}
|
||||
|
||||
Qgis::ScriptLanguage QgsCodeEditorCSS::language() const
|
||||
{
|
||||
return Qgis::ScriptLanguage::Css;
|
||||
}
|
||||
|
||||
void QgsCodeEditorCSS::initializeLexer()
|
||||
{
|
||||
QsciLexerCSS *lexer = new QgsQsciLexerCSS( this );
|
||||
|
@ -54,6 +54,7 @@ class GUI_EXPORT QgsCodeEditorCSS : public QgsCodeEditor
|
||||
|
||||
//! Constructor for QgsCodeEditorCSS
|
||||
QgsCodeEditorCSS( QWidget *parent SIP_TRANSFERTHIS = nullptr );
|
||||
Qgis::ScriptLanguage language() const override;
|
||||
|
||||
protected:
|
||||
void initializeLexer() override;
|
||||
|
@ -31,6 +31,11 @@ QgsCodeEditorExpression::QgsCodeEditorExpression( QWidget *parent )
|
||||
QgsCodeEditorExpression::initializeLexer(); // avoid cppcheck warning by explicitly specifying namespace
|
||||
}
|
||||
|
||||
Qgis::ScriptLanguage QgsCodeEditorExpression::language() const
|
||||
{
|
||||
return Qgis::ScriptLanguage::QgisExpression;
|
||||
}
|
||||
|
||||
void QgsCodeEditorExpression::setExpressionContext( const QgsExpressionContext &context )
|
||||
{
|
||||
mVariables.clear();
|
||||
|
@ -41,6 +41,8 @@ class GUI_EXPORT QgsCodeEditorExpression : public QgsCodeEditor
|
||||
//! Constructor for QgsCodeEditorExpression
|
||||
QgsCodeEditorExpression( QWidget *parent SIP_TRANSFERTHIS = nullptr );
|
||||
|
||||
Qgis::ScriptLanguage language() const override;
|
||||
|
||||
/**
|
||||
* Variables and functions from this expression context will be added to
|
||||
* the API.
|
||||
|
@ -37,6 +37,11 @@ QgsCodeEditorHTML::QgsCodeEditorHTML( QWidget *parent )
|
||||
QgsCodeEditorHTML::initializeLexer();
|
||||
}
|
||||
|
||||
Qgis::ScriptLanguage QgsCodeEditorHTML::language() const
|
||||
{
|
||||
return Qgis::ScriptLanguage::Html;
|
||||
}
|
||||
|
||||
void QgsCodeEditorHTML::initializeLexer()
|
||||
{
|
||||
QFont font = lexerFont();
|
||||
|
@ -38,6 +38,8 @@ class GUI_EXPORT QgsCodeEditorHTML : public QgsCodeEditor
|
||||
//! Constructor for QgsCodeEditorHTML
|
||||
QgsCodeEditorHTML( QWidget *parent SIP_TRANSFERTHIS = nullptr );
|
||||
|
||||
Qgis::ScriptLanguage language() const override;
|
||||
|
||||
protected:
|
||||
void initializeLexer() override;
|
||||
};
|
||||
|
@ -36,6 +36,11 @@ QgsCodeEditorJavascript::QgsCodeEditorJavascript( QWidget *parent )
|
||||
QgsCodeEditorJavascript::initializeLexer();
|
||||
}
|
||||
|
||||
Qgis::ScriptLanguage QgsCodeEditorJavascript::language() const
|
||||
{
|
||||
return Qgis::ScriptLanguage::JavaScript;
|
||||
}
|
||||
|
||||
void QgsCodeEditorJavascript::initializeLexer()
|
||||
{
|
||||
QsciLexerJavaScript *lexer = new QsciLexerJavaScript( this );
|
||||
|
@ -37,6 +37,7 @@ class GUI_EXPORT QgsCodeEditorJavascript : public QgsCodeEditor
|
||||
|
||||
//! Constructor for QgsCodeEditorJavascript
|
||||
QgsCodeEditorJavascript( QWidget *parent SIP_TRANSFERTHIS = nullptr );
|
||||
Qgis::ScriptLanguage language() const override;
|
||||
|
||||
protected:
|
||||
void initializeLexer() override;
|
||||
|
@ -36,6 +36,11 @@ QgsCodeEditorJson::QgsCodeEditorJson( QWidget *parent )
|
||||
QgsCodeEditorJson::initializeLexer();
|
||||
}
|
||||
|
||||
Qgis::ScriptLanguage QgsCodeEditorJson::language() const
|
||||
{
|
||||
return Qgis::ScriptLanguage::Json;
|
||||
}
|
||||
|
||||
void QgsCodeEditorJson::initializeLexer()
|
||||
{
|
||||
QsciLexerJSON *lexer = new QsciLexerJSON( this );
|
||||
|
@ -38,6 +38,8 @@ class GUI_EXPORT QgsCodeEditorJson : public QgsCodeEditor
|
||||
//! Constructor for QgsCodeEditorJson
|
||||
QgsCodeEditorJson( QWidget *parent SIP_TRANSFERTHIS = nullptr );
|
||||
|
||||
Qgis::ScriptLanguage language() const override;
|
||||
|
||||
protected:
|
||||
void initializeLexer() override;
|
||||
|
||||
|
@ -48,6 +48,11 @@ QgsCodeEditorPython::QgsCodeEditorPython( QWidget *parent, const QList<QString>
|
||||
QgsCodeEditorPython::initializeLexer();
|
||||
}
|
||||
|
||||
Qgis::ScriptLanguage QgsCodeEditorPython::language() const
|
||||
{
|
||||
return Qgis::ScriptLanguage::Python;
|
||||
}
|
||||
|
||||
void QgsCodeEditorPython::initializeLexer()
|
||||
{
|
||||
// current line
|
||||
|
@ -60,6 +60,8 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
|
||||
*/
|
||||
QgsCodeEditorPython( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QList<QString> &filenames = QList<QString>() );
|
||||
|
||||
Qgis::ScriptLanguage language() const override;
|
||||
|
||||
/**
|
||||
* Load APIs from one or more files
|
||||
* \param filenames The list of apis files to load for the Python lexer
|
||||
|
@ -37,6 +37,11 @@ QgsCodeEditorR::QgsCodeEditorR( QWidget *parent, Mode mode )
|
||||
QgsCodeEditorR::initializeLexer();
|
||||
}
|
||||
|
||||
Qgis::ScriptLanguage QgsCodeEditorR::language() const
|
||||
{
|
||||
return Qgis::ScriptLanguage::R;
|
||||
}
|
||||
|
||||
void QgsCodeEditorR::initializeLexer()
|
||||
{
|
||||
QgsQsciLexerR *lexer = new QgsQsciLexerR( this );
|
||||
|
@ -77,6 +77,7 @@ class GUI_EXPORT QgsCodeEditorR : public QgsCodeEditor
|
||||
|
||||
//! Constructor for QgsCodeEditorR
|
||||
QgsCodeEditorR( QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsCodeEditor::Mode mode = QgsCodeEditor::Mode::ScriptEditor );
|
||||
Qgis::ScriptLanguage language() const override;
|
||||
|
||||
protected:
|
||||
void initializeLexer() override;
|
||||
|
@ -33,6 +33,11 @@ QgsCodeEditorSQL::QgsCodeEditorSQL( QWidget *parent )
|
||||
QgsCodeEditorSQL::initializeLexer(); // avoid cppcheck warning by explicitly specifying namespace
|
||||
}
|
||||
|
||||
Qgis::ScriptLanguage QgsCodeEditorSQL::language() const
|
||||
{
|
||||
return Qgis::ScriptLanguage::SQL;
|
||||
}
|
||||
|
||||
QgsCodeEditorSQL::~QgsCodeEditorSQL()
|
||||
{
|
||||
if ( mApis )
|
||||
|
@ -39,6 +39,7 @@ class GUI_EXPORT QgsCodeEditorSQL : public QgsCodeEditor
|
||||
//! Constructor for QgsCodeEditorSQL
|
||||
QgsCodeEditorSQL( QWidget *parent SIP_TRANSFERTHIS = nullptr );
|
||||
|
||||
Qgis::ScriptLanguage language() const override;
|
||||
|
||||
virtual ~QgsCodeEditorSQL();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user