Skip to content
Permalink
Browse files

Ensure that all open code editors respond immediately to color/font c…

…hanges
  • Loading branch information
nyalldawson committed Oct 5, 2020
1 parent 527e885 commit 96db7ad4f3c372a8315a6621fc22ad03df13e56f
@@ -165,6 +165,15 @@ Returns the monospaced font to use for code editors.
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
%End

protected:
virtual void initializeLexer();

};

/************************************************************************
@@ -41,6 +41,11 @@ Will also reload all globally registered functions.
Field names will be added to the API.
%End

protected:

virtual void initializeLexer();


};


@@ -32,6 +32,9 @@ code autocompletion.
Constructor for QgsCodeEditorHTML
%End

protected:
virtual void initializeLexer();

};

/************************************************************************
@@ -29,6 +29,9 @@ code autocompletion.
Constructor for QgsCodeEditorJavascript
%End

protected:
virtual void initializeLexer();

};

/************************************************************************
@@ -52,6 +52,11 @@ Load a script file
:param script: The script file to load
%End

protected:

virtual void initializeLexer();


};

/************************************************************************
@@ -38,6 +38,10 @@ Set field names to be added to the lexer API.
.. versionadded:: 3.14
%End

protected:
virtual void initializeLexer();


};


@@ -18,6 +18,7 @@
#include "qgscodeeditor.h"
#include "qgssettings.h"
#include "qgssymbollayerutils.h"
#include "qgsgui.h"

#include <QLabel>
#include <QWidget>
@@ -82,6 +83,12 @@ QgsCodeEditor::QgsCodeEditor( QWidget *parent, const QString &title, bool foldin
SendScintilla( SCI_SETADDITIONALSELECTIONTYPING, 1 );
SendScintilla( SCI_SETMULTIPASTE, 1 );
SendScintilla( SCI_SETVIRTUALSPACEOPTIONS, SCVS_RECTANGULARSELECTION );

connect( QgsGui::instance(), &QgsGui::optionsChanged, this, [ = ]
{
setSciWidget();
initializeLexer();
} );
}

// Workaround a bug in QScintilla 2.8.X
@@ -128,6 +135,11 @@ void QgsCodeEditor::keyPressEvent( QKeyEvent *event )
}
}

void QgsCodeEditor::initializeLexer()
{

}

void QgsCodeEditor::setSciWidget()
{
QFont font = getMonospaceFont();
@@ -173,6 +173,15 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
void focusOutEvent( QFocusEvent *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:

void setSciWidget();
@@ -31,10 +31,10 @@ QgsCodeEditorCSS::QgsCodeEditorCSS( QWidget *parent )
}
setMarginVisible( false );
setFoldingVisible( true );
setSciLexerCSS();
initializeLexer();
}

void QgsCodeEditorCSS::setSciLexerCSS()
void QgsCodeEditorCSS::initializeLexer()
{
QsciLexerCSS *lexer = new QsciLexerCSS( this );
lexer->setDefaultFont( getMonospaceFont() );
@@ -38,8 +38,8 @@ class GUI_EXPORT QgsCodeEditorCSS : public QgsCodeEditor
//! Constructor for QgsCodeEditorCSS
QgsCodeEditorCSS( QWidget *parent SIP_TRANSFERTHIS = nullptr );

private:
void setSciLexerCSS();
protected:
void initializeLexer() override;
};

#endif
@@ -98,7 +98,6 @@ void QgsCodeEditorExpression::setFields( const QgsFields &fields )
updateApis();
}


void QgsCodeEditorExpression::initializeLexer()
{
QFont font = getMonospaceFont();
@@ -53,8 +53,11 @@ class GUI_EXPORT QgsCodeEditorExpression : public QgsCodeEditor
*/
void setFields( const QgsFields &fields );

protected:

void initializeLexer() override;

private:
void initializeLexer();
void updateApis();
QsciAPIs *mApis = nullptr;
QsciLexerSQL *mSqlLexer;
@@ -32,10 +32,10 @@ QgsCodeEditorHTML::QgsCodeEditorHTML( QWidget *parent )
}
setMarginVisible( false );
setFoldingVisible( true );
setSciLexerHTML();
initializeLexer();
}

void QgsCodeEditorHTML::setSciLexerHTML()
void QgsCodeEditorHTML::initializeLexer()
{
QFont font = getMonospaceFont();
QColor defaultColor = color( ColorRole::Default );
@@ -38,8 +38,8 @@ class GUI_EXPORT QgsCodeEditorHTML : public QgsCodeEditor
//! Constructor for QgsCodeEditorHTML
QgsCodeEditorHTML( QWidget *parent SIP_TRANSFERTHIS = nullptr );

private:
void setSciLexerHTML();
protected:
void initializeLexer() override;
};

#endif
@@ -31,10 +31,10 @@ QgsCodeEditorJavascript::QgsCodeEditorJavascript( QWidget *parent )
}
setMarginVisible( false );
setFoldingVisible( true );
setSciLexerJs();
initializeLexer();
}

void QgsCodeEditorJavascript::setSciLexerJs()
void QgsCodeEditorJavascript::initializeLexer()
{
QsciLexerJavaScript *lexer = new QsciLexerJavaScript( this );
QFont f = getMonospaceFont();
@@ -38,8 +38,8 @@ class GUI_EXPORT QgsCodeEditorJavascript : public QgsCodeEditor
//! Constructor for QgsCodeEditorJavascript
QgsCodeEditorJavascript( QWidget *parent SIP_TRANSFERTHIS = nullptr );

private:
void setSciLexerJs();
protected:
void initializeLexer() override;
};

#endif // QGSCODEEDITORJS_H
@@ -34,10 +34,10 @@ QgsCodeEditorPython::QgsCodeEditorPython( QWidget *parent, const QList<QString>
{
setTitle( tr( "Python Editor" ) );
}
setSciLexerPython();
initializeLexer();
}

void QgsCodeEditorPython::setSciLexerPython()
void QgsCodeEditorPython::initializeLexer()
{
// current line
setCaretWidth( 2 );
@@ -119,7 +119,7 @@ void QgsCodeEditorPython::loadAPIs( const QList<QString> &filenames )
{
mAPISFilesList = filenames;
//QgsDebugMsg( QStringLiteral( "The apis files: %1" ).arg( mAPISFilesList[0] ) );
setSciLexerPython();
initializeLexer();
}

bool QgsCodeEditorPython::loadScript( const QString &script )
@@ -136,6 +136,6 @@ bool QgsCodeEditorPython::loadScript( const QString &script )
setText( in.readAll().trimmed() );
file.close();

setSciLexerPython();
initializeLexer();
return true;
}
@@ -57,10 +57,11 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
*/
bool loadScript( const QString &script );

protected:

void initializeLexer() override;

private:
//QgsCodeEditor *mSciWidget;
//QWidget *mWidget;
void setSciLexerPython();

QList<QString> mAPISFilesList;
QString mPapFile;
@@ -46,11 +46,10 @@ class GUI_EXPORT QgsCodeEditorSQL : public QgsCodeEditor
*/
void setFields( const QgsFields &fields );

protected:
void initializeLexer() override;

private:
//QgsCodeEditor *mSciWidget;
//QWidget *mWidget;
void setSciLexerSQL();
void initializeLexer();
void updateApis();
QsciAPIs *mApis = nullptr;
QsciLexerSQL *mSqlLexer;

0 comments on commit 96db7ad

Please sign in to comment.
You can’t perform that action at this time.