From 0636d842fe777efe4fbd311490b195041e5c5147 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sun, 16 Oct 2022 14:25:54 +1000 Subject: [PATCH] Some more code to base class --- python/console/console_sci.py | 12 ------------ src/app/rstats/qgsrstatsconsole.cpp | 24 +----------------------- src/app/rstats/qgsrstatsconsole.h | 20 +------------------- src/gui/codeeditors/qgscodeeditor.cpp | 12 ++++++++++++ 4 files changed, 14 insertions(+), 54 deletions(-) diff --git a/python/console/console_sci.py b/python/console/console_sci.py index 2c421304780d..3e0c5611b740 100644 --- a/python/console/console_sci.py +++ b/python/console/console_sci.py @@ -172,18 +172,6 @@ def __init__(self, parent=None): self.sessionHistoryCleared.connect(self.on_session_history_cleared) self.persistentHistoryCleared.connect(self.on_persistent_history_cleared) - 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) diff --git a/src/app/rstats/qgsrstatsconsole.cpp b/src/app/rstats/qgsrstatsconsole.cpp index f3d645fffc86..d25a5f50b102 100644 --- a/src/app/rstats/qgsrstatsconsole.cpp +++ b/src/app/rstats/qgsrstatsconsole.cpp @@ -53,7 +53,7 @@ QgsRStatsConsole::QgsRStatsConsole( QWidget *parent, QgsRStatsRunner *runner ) mOutput = new QgsCodeEditorR( nullptr, QgsCodeEditor::Mode::OutputDisplay ); splitter->addWidget( mOutput ); - mInputEdit = new QgsInteractiveRWidget(); + mInputEdit = new QgsCodeEditorR( nullptr, QgsCodeEditor::Mode::CommandInput ); mInputEdit->setInterpreter( mRunner ); mInputEdit->setHistoryFilePath( QgsApplication::qgisSettingsDirPath() + QStringLiteral( "/r_console_history.txt" ) ); @@ -104,25 +104,3 @@ QgsRStatsConsole::~QgsRStatsConsole() delete mDockableWidgetHelper; } - -QgsInteractiveRWidget::QgsInteractiveRWidget( QWidget *parent ) - : QgsCodeEditorR( parent, QgsCodeEditor::Mode::CommandInput ) -{ - QgsInteractiveRWidget::initializeLexer(); - - QgsInteractiveRWidget::updatePrompt(); -} - -void QgsInteractiveRWidget::initializeLexer() -{ - QgsCodeEditorR::initializeLexer(); - - setCaretLineVisible( false ); - setLineNumbersVisible( false ); // NO linenumbers for the input line - // Margin 1 is used for the '>' prompt (console input) - setMarginLineNumbers( 1, true ); - setMarginWidth( 1, "00" ); - setMarginType( 1, QsciScintilla::MarginType::TextMarginRightJustified ); - setMarginsBackgroundColor( color( QgsCodeEditorColorScheme::ColorRole::Background ) ); - setEdgeMode( QsciScintilla::EdgeNone ); -} diff --git a/src/app/rstats/qgsrstatsconsole.h b/src/app/rstats/qgsrstatsconsole.h index ccccb281b461..5c0d3c5721cf 100644 --- a/src/app/rstats/qgsrstatsconsole.h +++ b/src/app/rstats/qgsrstatsconsole.h @@ -27,24 +27,6 @@ class QTextBrowser; class QgsDockableWidgetHelper; -class QgsInteractiveRWidget : public QgsCodeEditorR -{ - Q_OBJECT - public: - - QgsInteractiveRWidget( QWidget *parent = nullptr ); - - protected: - - void initializeLexer() override; - - private: - - bool mMore = false; - - - -}; class QgsRStatsConsole: public QWidget { @@ -55,7 +37,7 @@ class QgsRStatsConsole: public QWidget private: QgsRStatsRunner *mRunner = nullptr; - QgsInteractiveRWidget *mInputEdit = nullptr; + QgsCodeEditorR *mInputEdit = nullptr; QgsCodeEditorR *mOutput = nullptr; QgsDockableWidgetHelper *mDockableWidgetHelper = nullptr; diff --git a/src/gui/codeeditors/qgscodeeditor.cpp b/src/gui/codeeditors/qgscodeeditor.cpp index 3b07823a56af..a12fe0db6160 100644 --- a/src/gui/codeeditors/qgscodeeditor.cpp +++ b/src/gui/codeeditors/qgscodeeditor.cpp @@ -313,6 +313,18 @@ void QgsCodeEditor::runPostLexerConfigurationTasks() SendScintilla( SCI_MARKERSETBACK, SC_MARKNUM_FOLDER, lexerColor( QgsCodeEditorColorScheme::ColorRole::FoldIconForeground ) ); SendScintilla( SCI_STYLESETFORE, STYLE_INDENTGUIDE, lexerColor( QgsCodeEditorColorScheme::ColorRole::IndentationGuide ) ); SendScintilla( SCI_STYLESETBACK, STYLE_INDENTGUIDE, lexerColor( QgsCodeEditorColorScheme::ColorRole::IndentationGuide ) ); + + if ( mMode == QgsCodeEditor::Mode::CommandInput ) + { + setCaretLineVisible( false ); + setLineNumbersVisible( false ); // NO linenumbers for the input line + // Margin 1 is used for the '>' prompt (console input) + setMarginLineNumbers( 1, true ); + setMarginWidth( 1, "00000" ); + setMarginType( 1, QsciScintilla::MarginType::TextMarginRightJustified ); + setMarginsBackgroundColor( color( QgsCodeEditorColorScheme::ColorRole::Background ) ); + setEdgeMode( QsciScintilla::EdgeNone ); + } } void QgsCodeEditor::setSciWidget()