Skip to content

Commit

Permalink
Cleanup raw margin manipulation used to hide holding controls, use pr…
Browse files Browse the repository at this point in the history
…oper methods
  • Loading branch information
nyalldawson committed Oct 13, 2020
1 parent 66226f6 commit 8d3e028
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 26 deletions.
8 changes: 5 additions & 3 deletions python/console/console_output.py
Expand Up @@ -149,16 +149,18 @@ def insertInitText(self):
else:
self.setText(txtInit + '\n')

def initializeLexer(self):
super().initializeLexer()
self.setFoldingVisible(False)
self.setEdgeMode(QsciScintilla.EdgeNone)

def refreshSettingsOutput(self):
# Set Python lexer
self.initializeLexer()
self.setReadOnly(True)

self.setCaretWidth(0) # NO (blinking) caret in the output

self.setFoldingVisible(False)
self.setEdgeMode(QsciScintilla.EdgeNone)

def clearConsole(self):
self.setText('')
self.insertInitText()
Expand Down
23 changes: 12 additions & 11 deletions python/console/console_sci.py
Expand Up @@ -107,6 +107,18 @@ def __init__(self, parent=None):
self.newShortcutCAS.activated.connect(self.autoComplete)
self.newShortcutCSS.activated.connect(self.showHistory)

def initializeLexer(self):
super().initializeLexer()
self.setCaretLineVisible(False)
self.setLineNumbersVisible(False) # NO linenumbers for the input line
self.setFoldingVisible(False)
# Margin 1 is used for the '>>>' prompt (console input)
self.setMarginLineNumbers(1, True)
self.setMarginWidth(1, "00000")
self.setMarginType(1, 5) # TextMarginRightJustified=5
self.setMarginsBackgroundColor(self.color(QgsCodeEditorColorScheme.ColorRole.Background))
self.setEdgeMode(QsciScintilla.EdgeNone)

def _setMinimumHeight(self):
font = self.lexer().defaultFont(0)
fm = QFontMetrics(font)
Expand All @@ -120,17 +132,6 @@ def refreshSettingsShell(self):
# Sets minimum height for input area based of font metric
self._setMinimumHeight()

self.setCaretLineVisible(False)
self.setLineNumbersVisible(False) # NO linenumbers for the input line
self.setMarginWidth(QgsCodeEditor.FoldingControls, 0)
# Margin 1 is used for the '>>>' prompt (console input)
self.setMarginLineNumbers(1, True)
self.setMarginWidth(1, "00000")
self.setMarginType(1, 5) # TextMarginRightJustified=5
self.setMarginsBackgroundColor(self.color(QgsCodeEditorColorScheme.ColorRole.Background))
self.setFoldingVisible(False)
self.setEdgeMode(QsciScintilla.EdgeNone)

def showHistory(self):
if not self.historyDlg.isVisible():
self.historyDlg.show()
Expand Down
10 changes: 8 additions & 2 deletions python/gui/auto_generated/codeeditors/qgscodeeditor.sip.in
Expand Up @@ -96,11 +96,17 @@ Returns whether line numbers are visible in the editor.

void setFoldingVisible( bool folding );
%Docstring
Set folding visible state
Set whether the folding controls are visible in the editor.

:param folding: Set folding in the editor
.. seealso:: :py:func:`foldingVisible`
%End

bool foldingVisible();
%Docstring
Returns ``True`` if the folding controls are visible in the editor.

.. seealso:: :py:func:`setFoldingVisible`
%End

void insertText( const QString &text );
%Docstring
Expand Down
6 changes: 5 additions & 1 deletion src/gui/codeeditors/qgscodeeditor.cpp
Expand Up @@ -230,9 +230,9 @@ void QgsCodeEditor::setSciWidget()
setMatchedBraceBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceBackground ) );

setLineNumbersVisible( false );
setFoldingVisible( false );

setMarginWidth( QgsCodeEditor::MarginRole::ErrorIndicators, 0 );
setMarginWidth( QgsCodeEditor::MarginRole::FoldingControls, 0 );

setMarginsForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginForeground ) );
setMarginsBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginBackground ) );
Expand Down Expand Up @@ -311,11 +311,15 @@ void QgsCodeEditor::setFoldingVisible( bool folding )
mFolding = folding;
if ( folding )
{
setMarginWidth( QgsCodeEditor::MarginRole::FoldingControls, "0" );
setMarginsForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginForeground ) );
setMarginsBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginBackground ) );
setFolding( QsciScintilla::PlainFoldStyle );
}
else
{
setFolding( QsciScintilla::NoFoldStyle );
setMarginWidth( QgsCodeEditor::MarginRole::FoldingControls, 0 );
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/gui/codeeditors/qgscodeeditor.h
Expand Up @@ -107,10 +107,15 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
bool lineNumbersVisible() const;

/**
* Set folding visible state
* \param folding Set folding in the editor
* Set whether the folding controls are visible in the editor.
* \see foldingVisible()
*/
void setFoldingVisible( bool folding );

/**
* Returns TRUE if the folding controls are visible in the editor.
* \see setFoldingVisible()
*/
bool foldingVisible() { return mFolding; }

/**
Expand Down
6 changes: 0 additions & 6 deletions src/gui/codeeditors/qgscodeeditorpython.cpp
Expand Up @@ -169,12 +169,6 @@ void QgsCodeEditorPython::initializeLexer()
}

setLineNumbersVisible( true );

// Margin 2 is used for the 'folding'
setMarginWidth( QgsCodeEditor::MarginRole::FoldingControls, "0" );
setMarginsForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginForeground ) );
setMarginsBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginBackground ) );

setFoldingVisible( true );
setIndentationsUseTabs( false );
setIndentationGuides( true );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsexpressionbuilderwidget.cpp
Expand Up @@ -203,7 +203,7 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )

setExpectedOutputFormat( QString() );
mFunctionBuilderHelp->setLineNumbersVisible( false );
mFunctionBuilderHelp->setMarginWidth( QgsCodeEditor::MarginRole::FoldingControls, 0 );
mFunctionBuilderHelp->setFoldingVisible( false );
mFunctionBuilderHelp->setEdgeMode( QsciScintilla::EdgeNone );
mFunctionBuilderHelp->setEdgeColumn( 0 );
mFunctionBuilderHelp->setReadOnly( true );
Expand Down

0 comments on commit 8d3e028

Please sign in to comment.