mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
Ensure that all open code editors respond immediately to color/font changes
This commit is contained in:
parent
527e8850ef
commit
96db7ad4f3
@ -165,6 +165,15 @@ Returns the monospaced font to use for code editors.
|
|||||||
virtual void keyPressEvent( QKeyEvent *event );
|
virtual void keyPressEvent( QKeyEvent *event );
|
||||||
|
|
||||||
|
|
||||||
|
virtual void initializeLexer();
|
||||||
|
%Docstring
|
||||||
|
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
|
||||||
|
|
||||||
|
The default implementation does nothing.
|
||||||
|
|
||||||
|
.. versionadded:: 3.16
|
||||||
|
%End
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,6 +29,9 @@ code autocompletion.
|
|||||||
Constructor for QgsCodeEditorCSS
|
Constructor for QgsCodeEditorCSS
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void initializeLexer();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
|
@ -41,6 +41,11 @@ Will also reload all globally registered functions.
|
|||||||
Field names will be added to the API.
|
Field names will be added to the API.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void initializeLexer();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,6 +32,9 @@ code autocompletion.
|
|||||||
Constructor for QgsCodeEditorHTML
|
Constructor for QgsCodeEditorHTML
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void initializeLexer();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
|
@ -29,6 +29,9 @@ code autocompletion.
|
|||||||
Constructor for QgsCodeEditorJavascript
|
Constructor for QgsCodeEditorJavascript
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void initializeLexer();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
|
@ -52,6 +52,11 @@ Load a script file
|
|||||||
:param script: The script file to load
|
:param script: The script file to load
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void initializeLexer();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
|
@ -38,6 +38,10 @@ Set field names to be added to the lexer API.
|
|||||||
.. versionadded:: 3.14
|
.. versionadded:: 3.14
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void initializeLexer();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "qgscodeeditor.h"
|
#include "qgscodeeditor.h"
|
||||||
#include "qgssettings.h"
|
#include "qgssettings.h"
|
||||||
#include "qgssymbollayerutils.h"
|
#include "qgssymbollayerutils.h"
|
||||||
|
#include "qgsgui.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@ -82,6 +83,12 @@ QgsCodeEditor::QgsCodeEditor( QWidget *parent, const QString &title, bool foldin
|
|||||||
SendScintilla( SCI_SETADDITIONALSELECTIONTYPING, 1 );
|
SendScintilla( SCI_SETADDITIONALSELECTIONTYPING, 1 );
|
||||||
SendScintilla( SCI_SETMULTIPASTE, 1 );
|
SendScintilla( SCI_SETMULTIPASTE, 1 );
|
||||||
SendScintilla( SCI_SETVIRTUALSPACEOPTIONS, SCVS_RECTANGULARSELECTION );
|
SendScintilla( SCI_SETVIRTUALSPACEOPTIONS, SCVS_RECTANGULARSELECTION );
|
||||||
|
|
||||||
|
connect( QgsGui::instance(), &QgsGui::optionsChanged, this, [ = ]
|
||||||
|
{
|
||||||
|
setSciWidget();
|
||||||
|
initializeLexer();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Workaround a bug in QScintilla 2.8.X
|
// Workaround a bug in QScintilla 2.8.X
|
||||||
@ -128,6 +135,11 @@ void QgsCodeEditor::keyPressEvent( QKeyEvent *event )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsCodeEditor::initializeLexer()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void QgsCodeEditor::setSciWidget()
|
void QgsCodeEditor::setSciWidget()
|
||||||
{
|
{
|
||||||
QFont font = getMonospaceFont();
|
QFont font = getMonospaceFont();
|
||||||
|
@ -173,6 +173,15 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
|
|||||||
void focusOutEvent( QFocusEvent *event ) override;
|
void focusOutEvent( QFocusEvent *event ) override;
|
||||||
void keyPressEvent( QKeyEvent *event ) override;
|
void keyPressEvent( QKeyEvent *event ) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the dialect specific code lexer needs to be initialized (or reinitialized).
|
||||||
|
*
|
||||||
|
* The default implementation does nothing.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.16
|
||||||
|
*/
|
||||||
|
virtual void initializeLexer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void setSciWidget();
|
void setSciWidget();
|
||||||
|
@ -31,10 +31,10 @@ QgsCodeEditorCSS::QgsCodeEditorCSS( QWidget *parent )
|
|||||||
}
|
}
|
||||||
setMarginVisible( false );
|
setMarginVisible( false );
|
||||||
setFoldingVisible( true );
|
setFoldingVisible( true );
|
||||||
setSciLexerCSS();
|
initializeLexer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsCodeEditorCSS::setSciLexerCSS()
|
void QgsCodeEditorCSS::initializeLexer()
|
||||||
{
|
{
|
||||||
QsciLexerCSS *lexer = new QsciLexerCSS( this );
|
QsciLexerCSS *lexer = new QsciLexerCSS( this );
|
||||||
lexer->setDefaultFont( getMonospaceFont() );
|
lexer->setDefaultFont( getMonospaceFont() );
|
||||||
|
@ -38,8 +38,8 @@ class GUI_EXPORT QgsCodeEditorCSS : public QgsCodeEditor
|
|||||||
//! Constructor for QgsCodeEditorCSS
|
//! Constructor for QgsCodeEditorCSS
|
||||||
QgsCodeEditorCSS( QWidget *parent SIP_TRANSFERTHIS = nullptr );
|
QgsCodeEditorCSS( QWidget *parent SIP_TRANSFERTHIS = nullptr );
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
void setSciLexerCSS();
|
void initializeLexer() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -98,7 +98,6 @@ void QgsCodeEditorExpression::setFields( const QgsFields &fields )
|
|||||||
updateApis();
|
updateApis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void QgsCodeEditorExpression::initializeLexer()
|
void QgsCodeEditorExpression::initializeLexer()
|
||||||
{
|
{
|
||||||
QFont font = getMonospaceFont();
|
QFont font = getMonospaceFont();
|
||||||
|
@ -53,8 +53,11 @@ class GUI_EXPORT QgsCodeEditorExpression : public QgsCodeEditor
|
|||||||
*/
|
*/
|
||||||
void setFields( const QgsFields &fields );
|
void setFields( const QgsFields &fields );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void initializeLexer() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initializeLexer();
|
|
||||||
void updateApis();
|
void updateApis();
|
||||||
QsciAPIs *mApis = nullptr;
|
QsciAPIs *mApis = nullptr;
|
||||||
QsciLexerSQL *mSqlLexer;
|
QsciLexerSQL *mSqlLexer;
|
||||||
|
@ -32,10 +32,10 @@ QgsCodeEditorHTML::QgsCodeEditorHTML( QWidget *parent )
|
|||||||
}
|
}
|
||||||
setMarginVisible( false );
|
setMarginVisible( false );
|
||||||
setFoldingVisible( true );
|
setFoldingVisible( true );
|
||||||
setSciLexerHTML();
|
initializeLexer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsCodeEditorHTML::setSciLexerHTML()
|
void QgsCodeEditorHTML::initializeLexer()
|
||||||
{
|
{
|
||||||
QFont font = getMonospaceFont();
|
QFont font = getMonospaceFont();
|
||||||
QColor defaultColor = color( ColorRole::Default );
|
QColor defaultColor = color( ColorRole::Default );
|
||||||
|
@ -38,8 +38,8 @@ class GUI_EXPORT QgsCodeEditorHTML : public QgsCodeEditor
|
|||||||
//! Constructor for QgsCodeEditorHTML
|
//! Constructor for QgsCodeEditorHTML
|
||||||
QgsCodeEditorHTML( QWidget *parent SIP_TRANSFERTHIS = nullptr );
|
QgsCodeEditorHTML( QWidget *parent SIP_TRANSFERTHIS = nullptr );
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
void setSciLexerHTML();
|
void initializeLexer() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,10 +31,10 @@ QgsCodeEditorJavascript::QgsCodeEditorJavascript( QWidget *parent )
|
|||||||
}
|
}
|
||||||
setMarginVisible( false );
|
setMarginVisible( false );
|
||||||
setFoldingVisible( true );
|
setFoldingVisible( true );
|
||||||
setSciLexerJs();
|
initializeLexer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsCodeEditorJavascript::setSciLexerJs()
|
void QgsCodeEditorJavascript::initializeLexer()
|
||||||
{
|
{
|
||||||
QsciLexerJavaScript *lexer = new QsciLexerJavaScript( this );
|
QsciLexerJavaScript *lexer = new QsciLexerJavaScript( this );
|
||||||
QFont f = getMonospaceFont();
|
QFont f = getMonospaceFont();
|
||||||
|
@ -38,8 +38,8 @@ class GUI_EXPORT QgsCodeEditorJavascript : public QgsCodeEditor
|
|||||||
//! Constructor for QgsCodeEditorJavascript
|
//! Constructor for QgsCodeEditorJavascript
|
||||||
QgsCodeEditorJavascript( QWidget *parent SIP_TRANSFERTHIS = nullptr );
|
QgsCodeEditorJavascript( QWidget *parent SIP_TRANSFERTHIS = nullptr );
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
void setSciLexerJs();
|
void initializeLexer() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QGSCODEEDITORJS_H
|
#endif // QGSCODEEDITORJS_H
|
||||||
|
@ -34,10 +34,10 @@ QgsCodeEditorPython::QgsCodeEditorPython( QWidget *parent, const QList<QString>
|
|||||||
{
|
{
|
||||||
setTitle( tr( "Python Editor" ) );
|
setTitle( tr( "Python Editor" ) );
|
||||||
}
|
}
|
||||||
setSciLexerPython();
|
initializeLexer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsCodeEditorPython::setSciLexerPython()
|
void QgsCodeEditorPython::initializeLexer()
|
||||||
{
|
{
|
||||||
// current line
|
// current line
|
||||||
setCaretWidth( 2 );
|
setCaretWidth( 2 );
|
||||||
@ -119,7 +119,7 @@ void QgsCodeEditorPython::loadAPIs( const QList<QString> &filenames )
|
|||||||
{
|
{
|
||||||
mAPISFilesList = filenames;
|
mAPISFilesList = filenames;
|
||||||
//QgsDebugMsg( QStringLiteral( "The apis files: %1" ).arg( mAPISFilesList[0] ) );
|
//QgsDebugMsg( QStringLiteral( "The apis files: %1" ).arg( mAPISFilesList[0] ) );
|
||||||
setSciLexerPython();
|
initializeLexer();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsCodeEditorPython::loadScript( const QString &script )
|
bool QgsCodeEditorPython::loadScript( const QString &script )
|
||||||
@ -136,6 +136,6 @@ bool QgsCodeEditorPython::loadScript( const QString &script )
|
|||||||
setText( in.readAll().trimmed() );
|
setText( in.readAll().trimmed() );
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
setSciLexerPython();
|
initializeLexer();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -57,10 +57,11 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
|
|||||||
*/
|
*/
|
||||||
bool loadScript( const QString &script );
|
bool loadScript( const QString &script );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void initializeLexer() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//QgsCodeEditor *mSciWidget;
|
|
||||||
//QWidget *mWidget;
|
|
||||||
void setSciLexerPython();
|
|
||||||
|
|
||||||
QList<QString> mAPISFilesList;
|
QList<QString> mAPISFilesList;
|
||||||
QString mPapFile;
|
QString mPapFile;
|
||||||
|
@ -46,11 +46,10 @@ class GUI_EXPORT QgsCodeEditorSQL : public QgsCodeEditor
|
|||||||
*/
|
*/
|
||||||
void setFields( const QgsFields &fields );
|
void setFields( const QgsFields &fields );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void initializeLexer() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//QgsCodeEditor *mSciWidget;
|
|
||||||
//QWidget *mWidget;
|
|
||||||
void setSciLexerSQL();
|
|
||||||
void initializeLexer();
|
|
||||||
void updateApis();
|
void updateApis();
|
||||||
QsciAPIs *mApis = nullptr;
|
QsciAPIs *mApis = nullptr;
|
||||||
QsciLexerSQL *mSqlLexer;
|
QsciLexerSQL *mSqlLexer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user