From 343a3b8eb4b25e2b9b6c7b8e377885f0bf94f7a6 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 10 Nov 2009 05:42:48 +0000 Subject: [PATCH] This modification is necessary in the child classes in order to have an opportunity to redefine PyConsole_Editor editor for PyConsole_Console. --- src/PyConsole/PyConsole_Console.cxx | 23 ++++++++++++++++++++--- src/PyConsole/PyConsole_Console.h | 2 ++ src/PyConsole/PyConsole_Editor.h | 4 ++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/PyConsole/PyConsole_Console.cxx b/src/PyConsole/PyConsole_Console.cxx index 85df7307a..320753af6 100644 --- a/src/PyConsole/PyConsole_Console.cxx +++ b/src/PyConsole/PyConsole_Console.cxx @@ -60,9 +60,7 @@ PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* interp // create editor console QVBoxLayout* lay = new QVBoxLayout( this ); lay->setMargin( 0 ); - myEditor = new PyConsole_Editor( myInterp, this ); - myEditor->viewport()->installEventFilter( this ); - lay->addWidget( myEditor ); + setEditor( new PyConsole_Editor( myInterp, this ) ); createActions(); } @@ -76,6 +74,25 @@ PyConsole_Console::~PyConsole_Console() { } +/*! + \brief Set python console editor widget + \param editor +*/ +void PyConsole_Console::setEditor( PyConsole_Editor* theEditor ) +{ + QVBoxLayout* lay = dynamic_cast( layout() ); + if ( !lay || theEditor == myEditor ) + return; + + if ( myEditor ) { + lay->removeWidget( myEditor ); + delete myEditor; + } + myEditor = theEditor; + myEditor->viewport()->installEventFilter( this ); + lay->addWidget( myEditor ); +} + /*! \brief Execute python command in the interpreter. \param command string with command and arguments diff --git a/src/PyConsole/PyConsole_Console.h b/src/PyConsole/PyConsole_Console.h index ed1203b83..62df6a45b 100644 --- a/src/PyConsole/PyConsole_Console.h +++ b/src/PyConsole/PyConsole_Console.h @@ -51,6 +51,8 @@ public: PyConsole_Console( QWidget* parent, PyConsole_Interp* interp = 0 ); virtual ~PyConsole_Console(); + void setEditor( PyConsole_Editor* ); + //! \brief Get python interperter PyConsole_Interp* getInterp() { return myInterp; } QFont font() const; diff --git a/src/PyConsole/PyConsole_Editor.h b/src/PyConsole/PyConsole_Editor.h index 222708c6e..a53233a10 100644 --- a/src/PyConsole/PyConsole_Editor.h +++ b/src/PyConsole/PyConsole_Editor.h @@ -63,10 +63,10 @@ public slots: void cut(); void paste(); void clear(); - void handleReturn(); + virtual void handleReturn(); void onPyInterpChanged( PyConsole_Interp* ); -private: +protected: PyConsole_Interp* myInterp; //!< python interpreter QString myCommandBuffer; //!< python comman buffer -- 2.39.2