Skip to content

Commit 8d3e028

Browse files
committedOct 13, 2020
Cleanup raw margin manipulation used to hide holding controls, use proper methods
1 parent 66226f6 commit 8d3e028

File tree

7 files changed

+38
-26
lines changed

7 files changed

+38
-26
lines changed
 

‎python/console/console_output.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,18 @@ def insertInitText(self):
149149
else:
150150
self.setText(txtInit + '\n')
151151

152+
def initializeLexer(self):
153+
super().initializeLexer()
154+
self.setFoldingVisible(False)
155+
self.setEdgeMode(QsciScintilla.EdgeNone)
156+
152157
def refreshSettingsOutput(self):
153158
# Set Python lexer
154159
self.initializeLexer()
155160
self.setReadOnly(True)
156161

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

159-
self.setFoldingVisible(False)
160-
self.setEdgeMode(QsciScintilla.EdgeNone)
161-
162164
def clearConsole(self):
163165
self.setText('')
164166
self.insertInitText()

‎python/console/console_sci.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ def __init__(self, parent=None):
107107
self.newShortcutCAS.activated.connect(self.autoComplete)
108108
self.newShortcutCSS.activated.connect(self.showHistory)
109109

110+
def initializeLexer(self):
111+
super().initializeLexer()
112+
self.setCaretLineVisible(False)
113+
self.setLineNumbersVisible(False) # NO linenumbers for the input line
114+
self.setFoldingVisible(False)
115+
# Margin 1 is used for the '>>>' prompt (console input)
116+
self.setMarginLineNumbers(1, True)
117+
self.setMarginWidth(1, "00000")
118+
self.setMarginType(1, 5) # TextMarginRightJustified=5
119+
self.setMarginsBackgroundColor(self.color(QgsCodeEditorColorScheme.ColorRole.Background))
120+
self.setEdgeMode(QsciScintilla.EdgeNone)
121+
110122
def _setMinimumHeight(self):
111123
font = self.lexer().defaultFont(0)
112124
fm = QFontMetrics(font)
@@ -120,17 +132,6 @@ def refreshSettingsShell(self):
120132
# Sets minimum height for input area based of font metric
121133
self._setMinimumHeight()
122134

123-
self.setCaretLineVisible(False)
124-
self.setLineNumbersVisible(False) # NO linenumbers for the input line
125-
self.setMarginWidth(QgsCodeEditor.FoldingControls, 0)
126-
# Margin 1 is used for the '>>>' prompt (console input)
127-
self.setMarginLineNumbers(1, True)
128-
self.setMarginWidth(1, "00000")
129-
self.setMarginType(1, 5) # TextMarginRightJustified=5
130-
self.setMarginsBackgroundColor(self.color(QgsCodeEditorColorScheme.ColorRole.Background))
131-
self.setFoldingVisible(False)
132-
self.setEdgeMode(QsciScintilla.EdgeNone)
133-
134135
def showHistory(self):
135136
if not self.historyDlg.isVisible():
136137
self.historyDlg.show()

‎python/gui/auto_generated/codeeditors/qgscodeeditor.sip.in

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,17 @@ Returns whether line numbers are visible in the editor.
9696

9797
void setFoldingVisible( bool folding );
9898
%Docstring
99-
Set folding visible state
99+
Set whether the folding controls are visible in the editor.
100100

101-
:param folding: Set folding in the editor
101+
.. seealso:: :py:func:`foldingVisible`
102102
%End
103+
103104
bool foldingVisible();
105+
%Docstring
106+
Returns ``True`` if the folding controls are visible in the editor.
107+
108+
.. seealso:: :py:func:`setFoldingVisible`
109+
%End
104110

105111
void insertText( const QString &text );
106112
%Docstring

‎src/gui/codeeditors/qgscodeeditor.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ void QgsCodeEditor::setSciWidget()
230230
setMatchedBraceBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceBackground ) );
231231

232232
setLineNumbersVisible( false );
233+
setFoldingVisible( false );
233234

234235
setMarginWidth( QgsCodeEditor::MarginRole::ErrorIndicators, 0 );
235-
setMarginWidth( QgsCodeEditor::MarginRole::FoldingControls, 0 );
236236

237237
setMarginsForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginForeground ) );
238238
setMarginsBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginBackground ) );
@@ -311,11 +311,15 @@ void QgsCodeEditor::setFoldingVisible( bool folding )
311311
mFolding = folding;
312312
if ( folding )
313313
{
314+
setMarginWidth( QgsCodeEditor::MarginRole::FoldingControls, "0" );
315+
setMarginsForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginForeground ) );
316+
setMarginsBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginBackground ) );
314317
setFolding( QsciScintilla::PlainFoldStyle );
315318
}
316319
else
317320
{
318321
setFolding( QsciScintilla::NoFoldStyle );
322+
setMarginWidth( QgsCodeEditor::MarginRole::FoldingControls, 0 );
319323
}
320324
}
321325

‎src/gui/codeeditors/qgscodeeditor.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,15 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
107107
bool lineNumbersVisible() const;
108108

109109
/**
110-
* Set folding visible state
111-
* \param folding Set folding in the editor
110+
* Set whether the folding controls are visible in the editor.
111+
* \see foldingVisible()
112112
*/
113113
void setFoldingVisible( bool folding );
114+
115+
/**
116+
* Returns TRUE if the folding controls are visible in the editor.
117+
* \see setFoldingVisible()
118+
*/
114119
bool foldingVisible() { return mFolding; }
115120

116121
/**

‎src/gui/codeeditors/qgscodeeditorpython.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,6 @@ void QgsCodeEditorPython::initializeLexer()
169169
}
170170

171171
setLineNumbersVisible( true );
172-
173-
// Margin 2 is used for the 'folding'
174-
setMarginWidth( QgsCodeEditor::MarginRole::FoldingControls, "0" );
175-
setMarginsForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginForeground ) );
176-
setMarginsBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginBackground ) );
177-
178172
setFoldingVisible( true );
179173
setIndentationsUseTabs( false );
180174
setIndentationGuides( true );

‎src/gui/qgsexpressionbuilderwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
203203

204204
setExpectedOutputFormat( QString() );
205205
mFunctionBuilderHelp->setLineNumbersVisible( false );
206-
mFunctionBuilderHelp->setMarginWidth( QgsCodeEditor::MarginRole::FoldingControls, 0 );
206+
mFunctionBuilderHelp->setFoldingVisible( false );
207207
mFunctionBuilderHelp->setEdgeMode( QsciScintilla::EdgeNone );
208208
mFunctionBuilderHelp->setEdgeColumn( 0 );
209209
mFunctionBuilderHelp->setReadOnly( true );

0 commit comments

Comments
 (0)
Please sign in to comment.