From 1b46d1c46d159b914dbf555f751057610aedd2d6 Mon Sep 17 00:00:00 2001 From: sbh Date: Thu, 26 Jul 2012 09:50:51 +0000 Subject: [PATCH] Resolve problems "Enter Handling" in the python console (caused by porting to the Qt v.4.7.2) --- src/PyConsole/PyConsole.h | 5 ++- src/PyConsole/PyConsole_Console.cxx | 5 ++- src/PyConsole/PyConsole_Console.h | 5 ++- src/PyConsole/PyConsole_Editor.cxx | 51 +++++++++++++++-------------- src/PyConsole/PyConsole_Editor.h | 2 +- src/PyConsole/PyConsole_Interp.cxx | 2 +- src/PyConsole/PyConsole_Interp.h | 2 +- 7 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/PyConsole/PyConsole.h b/src/PyConsole/PyConsole.h index d27c40c0f..181e73cf9 100644 --- a/src/PyConsole/PyConsole.h +++ b/src/PyConsole/PyConsole.h @@ -1,4 +1,7 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public diff --git a/src/PyConsole/PyConsole_Console.cxx b/src/PyConsole/PyConsole_Console.cxx index 320753af6..7874a1c17 100644 --- a/src/PyConsole/PyConsole_Console.cxx +++ b/src/PyConsole/PyConsole_Console.cxx @@ -1,4 +1,7 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public diff --git a/src/PyConsole/PyConsole_Console.h b/src/PyConsole/PyConsole_Console.h index 62df6a45b..b1489356f 100644 --- a/src/PyConsole/PyConsole_Console.h +++ b/src/PyConsole/PyConsole_Console.h @@ -1,4 +1,7 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public diff --git a/src/PyConsole/PyConsole_Editor.cxx b/src/PyConsole/PyConsole_Editor.cxx index 449ac23ec..c42530517 100644 --- a/src/PyConsole/PyConsole_Editor.cxx +++ b/src/PyConsole/PyConsole_Editor.cxx @@ -1,6 +1,6 @@ -// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // // This library is free software; you can redistribute it and/or @@ -370,8 +370,11 @@ void PyConsole_Editor::execAndWait( const QString& command ) */ void PyConsole_Editor::handleReturn() { - // get last line - QTextBlock par = document()->end().previous(); + //SBH: Porting to the Qt v4.7.2: Since Qt 4.4. "lastBlock()" is more + //suitable method for retrieving last valid block of text from QTextDocument + //than "document()->end().previous()". Moreover, in the Acheron this + //obsolete construction returns invalid block, which leads to issues. + QTextBlock par = document()->lastBlock(); if ( !par.isValid() ) return; // get command @@ -407,7 +410,7 @@ void PyConsole_Editor::dropEvent( QDropEvent* event ) QPoint pos = event->pos(); QTextCursor cur = cursorForPosition( event->pos() ); // if the position is not in the last line move it to the end of the command line - if ( cur.position() < document()->end().previous().position() + PROMPT_SIZE ) { + if ( cur.position() < document()->lastBlock().position() + PROMPT_SIZE ) { moveCursor( QTextCursor::End ); pos = cursorRect().center(); } @@ -444,7 +447,7 @@ void PyConsole_Editor::mouseReleaseEvent( QMouseEvent* event ) text = QApplication::clipboard()->text( QClipboard::Clipboard ); QTextCursor cur = cursorForPosition( event->pos() ); // if the position is not in the last line move it to the end of the command line - if ( cur.position() < document()->end().previous().position() + PROMPT_SIZE ) { + if ( cur.position() < document()->lastBlock().position() + PROMPT_SIZE ) { moveCursor( QTextCursor::End ); } else { @@ -561,7 +564,7 @@ void PyConsole_Editor::keyPressEvent( QKeyEvent* event ) // set history browsing mode myCmdInHistory = myHistory.count(); // remember current command - QTextBlock par = document()->end().previous(); + QTextBlock par = document()->lastBlock(); myCurrentCommand = par.text().remove( 0, PROMPT_SIZE ); } if ( myCmdInHistory > 0 ) { @@ -705,7 +708,7 @@ void PyConsole_Editor::keyPressEvent( QKeyEvent* event ) // set history browsing mode myCmdInHistory = myHistory.count(); // remember current command - QTextBlock par = document()->end().previous(); + QTextBlock par = document()->lastBlock(); myCurrentCommand = par.text().remove( 0, PROMPT_SIZE ); } if ( myCmdInHistory > 0 ) { @@ -824,13 +827,13 @@ void PyConsole_Editor::keyPressEvent( QKeyEvent* event ) if ( cur.hasSelection() ) { cut(); } - else if ( cur.position() > document()->end().previous().position() + PROMPT_SIZE ) { + else if ( cur.position() > document()->lastBlock().position() + PROMPT_SIZE ) { if ( shftPressed ) { moveCursor( QTextCursor::PreviousWord, QTextCursor::KeepAnchor ); textCursor().removeSelectedText(); } else if ( ctrlPressed ) { - cur.setPosition( document()->end().previous().position() + PROMPT_SIZE, + cur.setPosition( document()->lastBlock().position() + PROMPT_SIZE, QTextCursor::KeepAnchor ); setTextCursor( cur ); textCursor().removeSelectedText(); @@ -840,7 +843,7 @@ void PyConsole_Editor::keyPressEvent( QKeyEvent* event ) } } else { - cur.setPosition( document()->end().previous().position() + PROMPT_SIZE ); + cur.setPosition( document()->lastBlock().position() + PROMPT_SIZE ); setTextCursor( cur ); horizontalScrollBar()->setValue( horizontalScrollBar()->minimum() ); } @@ -856,7 +859,7 @@ void PyConsole_Editor::keyPressEvent( QKeyEvent* event ) if ( cur.hasSelection() ) { cut(); } - else if ( cur.position() > document()->end().previous().position() + PROMPT_SIZE-1 ) { + else if ( cur.position() > document()->lastBlock().position() + PROMPT_SIZE-1 ) { if ( shftPressed ) { moveCursor( QTextCursor::NextWord, QTextCursor::KeepAnchor ); textCursor().removeSelectedText(); @@ -870,7 +873,7 @@ void PyConsole_Editor::keyPressEvent( QKeyEvent* event ) } } else { - cur.setPosition( document()->end().previous().position() + PROMPT_SIZE ); + cur.setPosition( document()->lastBlock().position() + PROMPT_SIZE ); setTextCursor( cur ); horizontalScrollBar()->setValue( horizontalScrollBar()->minimum() ); } @@ -914,7 +917,7 @@ void PyConsole_Editor::customEvent( QEvent* event ) // clear command buffer myCommandBuffer.truncate( 0 ); // add caret return line if necessary - QTextBlock par = document()->end().previous(); + QTextBlock par = document()->lastBlock(); QString txt = par.text(); txt.truncate( txt.length() - 1 ); // IPAL19397 : addText moved to handleReturn() method @@ -935,7 +938,7 @@ void PyConsole_Editor::customEvent( QEvent* event ) // extend command buffer (multi-line command) myCommandBuffer.append( "\n" ); // add caret return line if necessary - QTextBlock par = document()->end().previous(); + QTextBlock par = document()->lastBlock(); QString txt = par.text(); txt.truncate( txt.length() - 1 ); // IPAL19397 : addText moved to handleReturn() method @@ -1022,11 +1025,11 @@ void PyConsole_Editor::cut() if ( cur.hasSelection() ) { QApplication::clipboard()->setText( cur.selectedText() ); int startSelection = cur.selectionStart(); - if ( startSelection < document()->end().previous().position() + PROMPT_SIZE ) - startSelection = document()->end().previous().position() + PROMPT_SIZE; + if ( startSelection < document()->lastBlock().position() + PROMPT_SIZE ) + startSelection = document()->lastBlock().position() + PROMPT_SIZE; int endSelection = cur.selectionEnd(); - if ( endSelection < document()->end().previous().position() + PROMPT_SIZE ) - endSelection = document()->end().previous().position() + PROMPT_SIZE; + if ( endSelection < document()->lastBlock().position() + PROMPT_SIZE ) + endSelection = document()->lastBlock().position() + PROMPT_SIZE; cur.setPosition( startSelection ); cur.setPosition( endSelection, QTextCursor::KeepAnchor ); horizontalScrollBar()->setValue( horizontalScrollBar()->minimum() ); @@ -1046,18 +1049,18 @@ void PyConsole_Editor::paste() QTextCursor cur = textCursor(); if ( cur.hasSelection() ) { int startSelection = cur.selectionStart(); - if ( startSelection < document()->end().previous().position() + PROMPT_SIZE ) - startSelection = document()->end().previous().position() + PROMPT_SIZE; + if ( startSelection < document()->lastBlock().position() + PROMPT_SIZE ) + startSelection = document()->lastBlock().position() + PROMPT_SIZE; int endSelection = cur.selectionEnd(); - if ( endSelection < document()->end().previous().position() + PROMPT_SIZE ) - endSelection = document()->end().previous().position() + PROMPT_SIZE; + if ( endSelection < document()->lastBlock().position() + PROMPT_SIZE ) + endSelection = document()->lastBlock().position() + PROMPT_SIZE; cur.setPosition( startSelection ); cur.setPosition( endSelection, QTextCursor::KeepAnchor ); horizontalScrollBar()->setValue( horizontalScrollBar()->minimum() ); setTextCursor( cur ); textCursor().removeSelectedText(); } - if ( textCursor().position() < document()->end().previous().position() + PROMPT_SIZE ) + if ( textCursor().position() < document()->lastBlock().position() + PROMPT_SIZE ) moveCursor( QTextCursor::End ); QTextEdit::paste(); } diff --git a/src/PyConsole/PyConsole_Editor.h b/src/PyConsole/PyConsole_Editor.h index a53233a10..2947b67b6 100644 --- a/src/PyConsole/PyConsole_Editor.h +++ b/src/PyConsole/PyConsole_Editor.h @@ -1,4 +1,4 @@ -// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS diff --git a/src/PyConsole/PyConsole_Interp.cxx b/src/PyConsole/PyConsole_Interp.cxx index 003d59f39..d3dcb1255 100644 --- a/src/PyConsole/PyConsole_Interp.cxx +++ b/src/PyConsole/PyConsole_Interp.cxx @@ -1,4 +1,4 @@ -// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS diff --git a/src/PyConsole/PyConsole_Interp.h b/src/PyConsole/PyConsole_Interp.h index 5e0b1f645..d4bf34ef3 100644 --- a/src/PyConsole/PyConsole_Interp.h +++ b/src/PyConsole/PyConsole_Interp.h @@ -1,4 +1,4 @@ -// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -- 2.39.2