From 9d62a840b30e2b2c52fd02e0f993c10c55609ab0 Mon Sep 17 00:00:00 2001 From: akl Date: Fri, 24 Nov 2017 12:20:56 +0300 Subject: [PATCH] Add setCurrentLine to PyEditor API. --- tools/PyEditor/src/PyEditor_Editor.cxx | 15 +++++++++++++++ tools/PyEditor/src/PyEditor_Editor.h | 1 + tools/PyEditor/src/PyEditor_Widget.cxx | 9 +++++++++ tools/PyEditor/src/PyEditor_Widget.h | 2 ++ tools/PyEditor/src/python/PyEditorPy.sip | 3 +++ 5 files changed, 30 insertions(+) diff --git a/tools/PyEditor/src/PyEditor_Editor.cxx b/tools/PyEditor/src/PyEditor_Editor.cxx index 7e62c6f7b..3368ddfb5 100644 --- a/tools/PyEditor/src/PyEditor_Editor.cxx +++ b/tools/PyEditor/src/PyEditor_Editor.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -920,3 +921,17 @@ PyEditor_Keywords* PyEditor_Editor::standardKeywords() const { return myStdKeywords; } + +/*! + \brief Change current line number to the given one. + \param line new line number +*/ +void PyEditor_Editor::setCurrentLine( int line ) +{ + // set cursor to the given line + QTextCursor cursor( document()->findBlockByLineNumber( line - 1 ) ); + setTextCursor(cursor); + // change scroll bar position in order to center current line + QScrollBar *vScrollBar = verticalScrollBar(); + vScrollBar->setValue( line * 99 / document()->lineCount() ); +} diff --git a/tools/PyEditor/src/PyEditor_Editor.h b/tools/PyEditor/src/PyEditor_Editor.h index 8ec688366..daae2fe2f 100644 --- a/tools/PyEditor/src/PyEditor_Editor.h +++ b/tools/PyEditor/src/PyEditor_Editor.h @@ -47,6 +47,7 @@ public: void setSettings( const PyEditor_Settings& ); const PyEditor_Settings& settings() const; QString text() const; + void setCurrentLine( int ); QStringList keywords() const; void appendKeywords( const QStringList&, int, const QColor& = QColor() ); diff --git a/tools/PyEditor/src/PyEditor_Widget.cxx b/tools/PyEditor/src/PyEditor_Widget.cxx index 58d4c285c..a1f3628b0 100644 --- a/tools/PyEditor/src/PyEditor_Widget.cxx +++ b/tools/PyEditor/src/PyEditor_Widget.cxx @@ -267,3 +267,12 @@ const PyEditor_Settings& PyEditor_Widget::settings() const { return myEditor->settings(); } + +/*! + \brief Sets editor's current line. + \param line new line number +*/ +void PyEditor_Widget::setCurrentLine( int line ) +{ + myEditor->setCurrentLine( line ); +} diff --git a/tools/PyEditor/src/PyEditor_Widget.h b/tools/PyEditor/src/PyEditor_Widget.h index f7ba95977..1b72bf08a 100644 --- a/tools/PyEditor/src/PyEditor_Widget.h +++ b/tools/PyEditor/src/PyEditor_Widget.h @@ -55,6 +55,8 @@ public: int completionPolicy() const; void setCompletionPolicy( int ); + void setCurrentLine( int ); + public slots: void find(); void replace(); diff --git a/tools/PyEditor/src/python/PyEditorPy.sip b/tools/PyEditor/src/python/PyEditorPy.sip index 854e7a86b..e52be5189 100644 --- a/tools/PyEditor/src/python/PyEditorPy.sip +++ b/tools/PyEditor/src/python/PyEditorPy.sip @@ -84,6 +84,7 @@ public: void setSettings( const PyEditor_Settings& ); const PyEditor_Settings& settings() const; QString text() const; + void setCurrentLine( int ); QStringList keywords() const; void appendKeywords( const QStringList&, int, const QColor& = QColor() ); @@ -137,6 +138,8 @@ public: void setSettings( const PyEditor_Settings& ); const PyEditor_Settings& settings() const; + void setCurrentLine( int ); + bool isModified(); QString text() const; -- 2.39.2