Skip to content

Commit e843f6a

Browse files
author
Charles PIGNEROL
committed
Version 6.3.0. Porting QtPythonConsole3 to Qt6.
1 parent efebdcd commit e843f6a

File tree

8 files changed

+68
-30
lines changed

8 files changed

+68
-30
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.12)
1+
cmake_minimum_required (VERSION 3.15) # CMP0094
22

33
project (QtPython CXX)
44

cmake/version.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
# Pour la bibliothèque QtPython :
66
set (QT_PYTHON_MAJOR_VERSION "6")
7-
set (QT_PYTHON_MINOR_VERSION "3")
8-
set (QT_PYTHON_RELEASE_VERSION "3")
7+
set (QT_PYTHON_MINOR_VERSION "4")
8+
set (QT_PYTHON_RELEASE_VERSION "0")
99
set (QT_PYTHON_VERSION ${QT_PYTHON_MAJOR_VERSION}.${QT_PYTHON_MINOR_VERSION}.${QT_PYTHON_RELEASE_VERSION})
1010

1111
# Pour la bibliothèque QtPython3 :
1212
set (QT_PYTHON_3_MAJOR_VERSION "6")
13-
set (QT_PYTHON_3_MINOR_VERSION "3")
14-
set (QT_PYTHON_3_RELEASE_VERSION "3")
13+
set (QT_PYTHON_3_MINOR_VERSION "4")
14+
set (QT_PYTHON_3_RELEASE_VERSION "0")
1515
set (QT_PYTHON_3_VERSION ${QT_PYTHON_3_MAJOR_VERSION}.${QT_PYTHON_3_MINOR_VERSION}.${QT_PYTHON_3_RELEASE_VERSION})
1616

src/QtPython3/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ find_package (GUIToolkitsVariables)
55

66
include (${CMAKE_SOURCE_DIR}/cmake/version.cmake)
77
include (${GUIToolkitsVariables_CMAKE_DIR}/common.cmake)
8+
include (${GUIToolkitsVariables_CMAKE_DIR}/common_qt.cmake) # QT_MAJOR
89
include (${GUIToolkitsVariables_CMAKE_DIR}/python_binding.cmake)
910
include (${GUIToolkitsVariables_CMAKE_DIR}/workarounds.cmake)
1011

@@ -13,7 +14,7 @@ set (QT_PYTHON_SCRIPTS_DIR "${CMAKE_INSTALL_PREFIX}/${PYTHON_BINDING_DIR}")
1314

1415
find_package (QtUtil 6 REQUIRED)
1516
find_package (PythonUtil 6 REQUIRED)
16-
find_package(Qt5Core NO_CMAKE_SYSTEM_PATH) # In order to enable moc ...
17+
find_package(Qt${QT_MAJOR}Core NO_CMAKE_SYSTEM_PATH) # In order to enable moc ...
1718

1819
file (GLOB HEADERS public/${CURRENT_PACKAGE_NAME}/*.h)
1920
file (GLOB CPP_SOURCES *.cpp *.qrc)
@@ -26,10 +27,10 @@ set_property (TARGET QtPython3 PROPERTY AUTORCC ON)
2627
set (ALL_TARGETS QtPython3)
2728
set_property (TARGET QtPython3 PROPERTY VERSION ${QT_PYTHON_3_VERSION})
2829
set_property (TARGET QtPython3 PROPERTY SOVERSION ${QT_PYTHON_3_MAJOR_VERSION})
29-
set (QT_LIB_DEPENDENCIES Qt5::Widgets Qt5::Gui Qt5::Core)
30-
set (QT_INC_DEPENDENCIES ${Qt5Gui_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS})
30+
set (QT_LIB_DEPENDENCIES Qt${QT_MAJOR}::Widgets Qt${QT_MAJOR}::Gui Qt${QT_MAJOR}::Core)
31+
set (QT_INC_DEPENDENCIES ${Qt${QT_MAJOR}Gui_INCLUDE_DIRS} ${Qt${QT_MAJOR}Core_INCLUDE_DIRS})
3132
# Rem : en Qt v 4.* on utilise -DUSE_QT_WEBKIT
32-
set (QT_PYTHON_3_PUBLIC_FLAGS -DQT_5)
33+
set (QT_PYTHON_3_PUBLIC_FLAGS -DQT_${QT_MAJOR})
3334
set (QT_PYTHON_3_PRIVATE_FLAGS -DQT_PYTHON_VERSION="${QT_PYTHON_3_VERSION}")
3435

3536
# REM : on avait historiquement l'instruction suivante, pour contourner un bogue icpc sur plateforme Bull :

src/QtPython3/QtPythonConsole.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,9 @@
1717

1818
#include <QThread>
1919
#include <QPainter>
20-
#ifndef QT_5
21-
#include <QtGui/QAction>
22-
#include <QtGui/QFileDialog>
23-
#include <QtGui/QMenu>
24-
#else // QT_5
2520
#include <QAction>
2621
#include <QFileDialog>
2722
#include <QMenu>
28-
#endif // QT_5
2923

3024
#include <frameobject.h>// PyFrameObject
3125

@@ -1318,7 +1312,11 @@ void QtPythonConsole::addSwigCompletions (vector<string>& completions, const str
13181312
{
13191313
const string msg = exc.getFullMessage ( ).utf8 ( );
13201314
const QString qmsg (msg.c_str ( ));
1315+
#ifdef QT_5
13211316
QStringList lines = qmsg.split ("\n", QString::KeepEmptyParts);
1317+
#else // QT_5
1318+
QStringList lines = qmsg.split ("\n", Qt::KeepEmptyParts);
1319+
#endif // QT_5
13221320
const size_t num = lines.size ( );
13231321
if (1 == num) // On fait comme on peut ...
13241322
completions.push_back(cppToPython (getSwigCompletion (expression)));
@@ -2722,7 +2720,12 @@ vector<string> QtPythonConsole::getRunnableInstructions (size_t first) const
27222720
{
27232721
vector<string> instructions;
27242722
QString text = document ( )->toPlainText ( );
2723+
#ifdef QT_5
27252724
QStringList lines = QString (text).split ("\n", QString::KeepEmptyParts);
2725+
#else // QT_5
2726+
QStringList lines = QString (text).split ("\n", Qt::KeepEmptyParts);
2727+
#endif // QT_5
2728+
27262729
// On élimine les lignes blanches finales :
27272730
size_t last = lines.size ( );
27282731
for (size_t i = last; i != 0; i--)

src/QtPython3/QtPythonSyntaxHighlighter.cpp

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,53 @@ QtPythonSyntaxHighlighter::QtPythonSyntaxHighlighter (QTextDocument* parent)
3535
<< "\\b__\\*\\b";
3636
foreach (const QString& pattern, keywordPatterns)
3737
{
38+
#ifdef QT_5
3839
rule.pattern = QRegExp (pattern);
40+
#else // QT_5
41+
rule.pattern = QRegularExpression (pattern);
42+
#endif // QT_5
43+
3944
rule.format = keywordFormat;
4045
_highlightingRules.append (rule);
4146
} // foreach (const QString& pattern, keywordPatterns)
4247

4348
quotationFormat.setForeground (Qt::red);
49+
#ifdef QT_5
4450
rule.pattern = QRegExp ("\".*\"");
51+
#else // QT_5
52+
rule.pattern = QRegularExpression ("\".*\"");
53+
#endif // QT_5
4554
rule.format = quotationFormat;
4655
_highlightingRules.append (rule);
4756
quotationFormat.setFontItalic (true);
4857
quotationFormat.setForeground (Qt::cyan);
58+
#ifdef QT_5
4959
rule.pattern = QRegExp ("\\b[A-Za-z0-9__]+(?=\\()");
60+
#else // QT_5
61+
rule.pattern = QRegularExpression ("\\b[A-Za-z0-9__]+(?=\\()");
62+
#endif // QT_5
5063
rule.format = functionFormat;
5164
_highlightingRules.append (rule);
5265
singleLineFormat.setForeground (Qt::blue);
66+
#ifdef QT_5
5367
rule.pattern = QRegExp ("#[^\n]*");
68+
#else // QT_5
69+
rule.pattern = QRegularExpression ("#[^\n]*");
70+
#endif // QT_5
5471
rule.format = singleLineFormat;
5572
_highlightingRules.append (rule);
5673
} // QtPythonSyntaxHighlighter::QtPythonSyntaxHighlighter
5774

5875

5976

60-
QtPythonSyntaxHighlighter::QtPythonSyntaxHighlighter (
61-
const QtPythonSyntaxHighlighter&)
77+
QtPythonSyntaxHighlighter::QtPythonSyntaxHighlighter (const QtPythonSyntaxHighlighter&)
6278
: QSyntaxHighlighter ((QTextDocument*)0)
6379
{
6480
assert (0 && "QtPythonSyntaxHighlighter copy constructor is not allowed.");
6581
} // QtPythonSyntaxHighlighter::QtPythonSyntaxHighlighter
6682

6783

68-
QtPythonSyntaxHighlighter& QtPythonSyntaxHighlighter::operator = (
69-
const QtPythonSyntaxHighlighter&)
84+
QtPythonSyntaxHighlighter& QtPythonSyntaxHighlighter::operator = (const QtPythonSyntaxHighlighter&)
7085
{
7186
assert (0 && "QtPythonSyntaxHighlighter copy constructor is not allowed.");
7287
return *this;
@@ -82,7 +97,9 @@ void QtPythonSyntaxHighlighter::highlightBlock (const QString& text)
8297
{
8398
foreach (const HighlightingRule& rule, _highlightingRules)
8499
{
100+
#ifdef QT_5
85101
QRegExp expression (rule.pattern);
102+
86103
int index = expression.indexIn (text);
87104
while (index >= 0)
88105
{
@@ -93,12 +110,20 @@ void QtPythonSyntaxHighlighter::highlightBlock (const QString& text)
93110
// Sécurité contre une expression mal formulée (=> boucle infinie) :
94111
if (length <= 0)
95112
{
96-
cerr << __FILE__ << ' ' << __LINE__
97-
<< " Erreur de formulation de l'expression régulière "
98-
<< expression.pattern ( ).toStdString ( ) << endl;
113+
cerr << __FILE__ << ' ' << __LINE__ << " Erreur de formulation de l'expression régulière " << expression.pattern ( ).toStdString ( ) << endl;
99114
break;
100115
} // if (length <= 0)
101116
} // while (index >= 0)
117+
#else // QT_5
118+
QRegularExpression expression (rule.pattern);
119+
120+
QRegularExpressionMatchIterator it = expression.globalMatch (text);
121+
while (it.hasNext ( ))
122+
{
123+
QRegularExpressionMatch match = it.next ( );
124+
setFormat (match.capturedStart ( ), match.capturedLength ( ), rule.format);
125+
} // while (it.hasNext ( ))
126+
#endif // QT_5
102127
} // foreach (const HighlightingRule& rule, _highlightingRules)
103128
} // QtPythonSyntaxHighlighter::highlightBlock
104129

src/QtPython3/public/QtPython3/QtPythonConsole.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,9 @@ typedef struct _object PyObject;
1818

1919
#include <QSettings>
2020
#include <QIcon>
21-
#ifndef QT_5
22-
#include <QtGui/QComboBox>
23-
#include <QtGui/QMainWindow>
24-
#include <QtGui/QToolBar>
25-
#else // QT_5
2621
#include <QComboBox>
2722
#include <QMainWindow>
2823
#include <QToolBar>
29-
#endif // QT_5
3024

3125
#include <fstream>
3226
#include <memory>

src/QtPython3/public/QtPython3/QtPythonSyntaxHighlighter.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#define QT_PYTHON_SYNTAX_HIGHLIGHTER_H
33

44
#include <QSyntaxHighlighter>
5-
5+
#ifndef QT_5
6+
# include <QRegularExpression>
7+
#endif // QT_5
68

79
/**
810
* Classe permettant la mise en évidence des mots clés du langage python dans
@@ -46,7 +48,12 @@ class QtPythonSyntaxHighlighter : public QSyntaxHighlighter
4648

4749
struct HighlightingRule
4850
{
49-
QRegExp pattern;
51+
#ifdef QT_5
52+
QRegExp pattern;
53+
#else // QT_5
54+
QRegularExpression pattern;
55+
#endif // QT_5
56+
5057
QTextCharFormat format;
5158
}; // struct HighlightingRule
5259

versions.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Version 6.4.0 : 13/12/23
2+
===============
3+
4+
Portage Qt 6/GUIToolkitsVariables v 1.4.0/QtUtil v 6.4.0 de la console python 3. La console python 2 est consid�r�e obsol�te.
5+
6+
cmake_minimum_required (VERSION 3.15) # CMP0094
7+
8+
19
Version 6.3.3 : 27/10/23
210
===============
311

0 commit comments

Comments
 (0)