Salome HOME
Copyright update 2022
[modules/gui.git] / tools / PyConsole / src / PyConsole_Editor.cxx
index 7ec727292b4a936526c2f8e0883212ee54059f88..62e1e6d56b0ba9d3ce234ebbda9b562323bc283f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  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
@@ -88,8 +88,8 @@
   - <Ctrl><Tab>          : undoes auto-completion
 */
 
-#include "PyConsole_Editor.h"
 #include "PyConsole_Interp.h"
+#include "PyConsole_Editor.h"
 #include "PyConsole_Event.h"
 #include "PyInterp_Dispatcher.h"
 #include "PyConsole_Request.h"
 #include <QChar>
 #include <QFileDialog>
 #include <QMessageBox>
+#include <QtGlobal>
 
 //VSR: uncomment below macro to support unicode text properly in SALOME
 //     current commented out due to regressions
@@ -155,9 +156,10 @@ void PyConsole_CallbackStderr( void* data, char* c )
 PyConsole_Editor::PyConsole_Editor( QWidget* parent )
   : QTextEdit( parent )
 {
-  PyConsole_Interp* interp = new PyConsole_Interp();
+  PyConsole_Interp *interp(new PyConsole_Interp);
   interp->initialize();
-  init( interp );
+  myInterp=interp;
+  init();
 }
 
 /*!
@@ -171,13 +173,13 @@ PyConsole_Editor::PyConsole_Editor( QWidget*          parent,
                                     PyConsole_Interp* interp )
   : QTextEdit( parent )
 {
-  init( interp );
+  myInterp.takeRef(interp);
+  init();
 }
 
 
-void PyConsole_Editor::init( PyConsole_Interp* interp )
+void PyConsole_Editor::init()
 {
-  myInterp = interp;
   myCmdInHistory = -1;
   myEventLoop = 0;
   myShowBanner = true;
@@ -219,15 +221,14 @@ void PyConsole_Editor::init( PyConsole_Interp* interp )
 */
 PyConsole_Editor::~PyConsole_Editor()
 {
-  myInterp = 0;
 }
 
 /*!
   \brief Get Python interpreter
 */
-PyConsole_InterpPyConsole_Editor::getInterp() const
+PyConsole_Interp *PyConsole_Editor::getInterp() const
 {
-  return myInterp;
+  return myInterp.iAmATrollConstCast();
 }
 
 /*!
@@ -1175,7 +1176,7 @@ void PyConsole_Editor::keyPressEvent( QKeyEvent* event )
 */
 void PyConsole_Editor::customEvent( QEvent* event )
 {
-  switch( event->type() )
+  switch( (int) event->type() )
   {
   case PyConsole_PrintEvent::EVENT_ID:
   {
@@ -1392,7 +1393,11 @@ bool PyConsole_Editor::dump( const QString& fileName )
     if ( file.open( QFile::WriteOnly ) ) {
       QTextStream out( &file );
       for ( int i = 0; i < myHistory.count(); i++ ) {
+#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
+        out << myHistory[i] << Qt::endl;
+#else
         out << myHistory[i] << endl;
+#endif
       }
       file.close();
       ok = true;
@@ -1561,7 +1566,11 @@ void PyConsole_Editor::multilinePaste( const QString& s )
   // Split string data to lines
   QString s2 = s;
   s2.replace( "\r", "" ); // Windows string format converted to Unix style
+#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
+  QStringList lst = s2.split( QChar('\n'), Qt::KeepEmptyParts );
+#else
   QStringList lst = s2.split( QChar('\n'), QString::KeepEmptyParts );
+#endif
 
   // Perform the proper paste operation for the first line to handle the case where
   // something was already there