From 49a841675caf46243f1863e07b2596df3cfa70c3 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Sat, 18 Nov 2023 20:55:16 +0100 Subject: [PATCH] OMNotebook: Qt6 support --- OMNotebook/CMakeLists.txt | 6 +++++- .../OMNotebook/OMNotebookGUI/CMakeLists.txt | 11 +++++++--- .../OMNotebookGUI/ModelicaTextHighlighter.h | 2 +- OMNotebook/OMNotebook/OMNotebookGUI/cell.cpp | 17 ++++++++-------- .../OMNotebookGUI/cellapplication.cpp | 7 ++++++- .../OMNotebook/OMNotebookGUI/celldocument.cpp | 2 +- .../OMNotebook/OMNotebookGUI/cellgroup.cpp | 2 +- .../OMNotebookGUI/commandcompletion.cpp | 5 +++-- .../OMNotebookGUI/commandcompletion.h | 2 +- .../OMNotebook/OMNotebookGUI/graphcell.cpp | 20 ++++++++++--------- .../OMNotebook/OMNotebookGUI/indent.cpp | 7 ++++++- .../OMNotebook/OMNotebookGUI/inputcell.cpp | 4 ++-- .../OMNotebook/OMNotebookGUI/latexcell.cpp | 6 +++--- .../OMNotebook/OMNotebookGUI/notebook.cpp | 6 +++--- .../OMNotebook/OMNotebookGUI/textcell.cpp | 5 +++-- .../OMNotebook/OMNotebookGUI/xmlparser.cpp | 14 +++++++++++++ 16 files changed, 77 insertions(+), 39 deletions(-) diff --git a/OMNotebook/CMakeLists.txt b/OMNotebook/CMakeLists.txt index 5f186373476..7d7b1a979c9 100644 --- a/OMNotebook/CMakeLists.txt +++ b/OMNotebook/CMakeLists.txt @@ -10,7 +10,11 @@ set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) -find_package(Qt5 COMPONENTS Widgets PrintSupport Xml REQUIRED) +find_package(Qt${OM_QT_MAJOR_VERSION} COMPONENTS Widgets PrintSupport Xml REQUIRED) + +if (OM_QT_MAJOR_VERSION VERSION_GREATER_EQUAL 6) + find_package(Qt6 COMPONENTS Core5Compat REQUIRED) +endif () omc_add_subdirectory(OMNotebook/OMNotebookGUI) diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/CMakeLists.txt b/OMNotebook/OMNotebook/OMNotebookGUI/CMakeLists.txt index 527b6866b6b..d9e61028699 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/CMakeLists.txt +++ b/OMNotebook/OMNotebook/OMNotebookGUI/CMakeLists.txt @@ -105,9 +105,14 @@ target_compile_definitions(OMNotebook PRIVATE OMNOTEBOOKLIB_MOC_INCLUDE) target_include_directories(OMNotebook PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(OMNotebook PUBLIC Qt5::Xml) -target_link_libraries(OMNotebook PUBLIC Qt5::Widgets) -target_link_libraries(OMNotebook PUBLIC Qt5::PrintSupport) +target_link_libraries(OMNotebook PUBLIC Qt${OM_QT_MAJOR_VERSION}::Xml) +target_link_libraries(OMNotebook PUBLIC Qt${OM_QT_MAJOR_VERSION}::Widgets) +target_link_libraries(OMNotebook PUBLIC Qt${OM_QT_MAJOR_VERSION}::PrintSupport) + +if (OM_QT_MAJOR_VERSION VERSION_GREATER_EQUAL 6) + target_link_libraries(OMNotebook PUBLIC Qt6::Core5Compat) +endif () + target_link_libraries(OMNotebook PUBLIC OMPlotLib) target_link_libraries(OMNotebook PUBLIC OpenModelicaCompiler) diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/ModelicaTextHighlighter.h b/OMNotebook/OMNotebook/OMNotebookGUI/ModelicaTextHighlighter.h index 400cd84e116..98f24c83398 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/ModelicaTextHighlighter.h +++ b/OMNotebook/OMNotebook/OMNotebookGUI/ModelicaTextHighlighter.h @@ -35,7 +35,7 @@ //QT Headers #include -#include +#include #include #include diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/cell.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/cell.cpp index 71ab4c1bfd7..e7eae6c7eb0 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/cell.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/cell.cpp @@ -35,6 +35,7 @@ //QT Headers #include #include +#include #include #include @@ -96,7 +97,7 @@ namespace IAEX setEnabled(true); mainlayout_ = new QGridLayout(this); - mainlayout_->setMargin(0); + mainlayout_->setContentsMargins(0, 0, 0, 0); mainlayout_->setSpacing(0); setLayout( mainlayout_ );//AF @@ -117,7 +118,7 @@ namespace IAEX setMouseTracking(true); mainlayout_ = new QGridLayout(this); - mainlayout_->setMargin(0); + mainlayout_->setContentsMargins(0, 0, 0, 0); mainlayout_->setSpacing(0); setLabel(new QLabel(this)); @@ -262,7 +263,7 @@ namespace IAEX { // TODO: DEBUG code: Remove when doing release, // just a check to find new rules - QRegExp expression( "InitializationCell|CellTags|FontSlant|TextAlignment|TextJustification|FontSize|FontWeight|FontFamily|PageWidth|CellMargins|CellDingbat|ImageSize|ImageMargins|ImageRegion|OMNotebook_Margin|OMNotebook_Padding|OMNotebook_Border" ); + QRegularExpression expression("InitializationCell|CellTags|FontSlant|TextAlignment|TextJustification|FontSize|FontWeight|FontFamily|PageWidth|CellMargins|CellDingbat|ImageSize|ImageMargins|ImageRegion|OMNotebook_Margin|OMNotebook_Padding|OMNotebook_Border"); if( 0 > r->attribute().indexOf( expression )) { std::cout << "[NEW] Rule <" << r->attribute().toStdString() << "> <" << r->value().toStdString() << ">" << std::endl; @@ -271,25 +272,25 @@ namespace IAEX { if( r->attribute() == "FontSlant" ) { - QRegExp fontslant( "Italic" ); + QRegularExpression fontslant( "Italic" ); if( 0 > r->value().indexOf( fontslant )) std::cout << "[NEW] Rule Value , VALUE: " << r->value().toStdString() << std::endl; } else if( r->attribute() == "TextAlignment" ) { - QRegExp textalignment( "Right|Left|Center|Justify" ); + QRegularExpression textalignment( "Right|Left|Center|Justify" ); if( 0 > r->value().indexOf( textalignment )) std::cout << "[NEW] Rule Value , VALUE: " << r->value().toStdString() << std::endl; } else if( r->attribute() == "TextJustification" ) { - QRegExp textjustification( "1|0" ); + QRegularExpression textjustification( "1|0" ); if( 0 > r->value().indexOf( textjustification )) std::cout << "[NEW] Rule Value , VALUE: " << r->value().toStdString() << std::endl; } else if( r->attribute() == "FontWeight" ) { - QRegExp fontweight( "Bold|Plain" ); + QRegularExpression fontweight( "Bold|Plain" ); if( 0 > r->value().indexOf( fontweight )) std::cout << "[NEW] Rule Value , VALUE: " << r->value().toStdString() << std::endl; } @@ -304,7 +305,7 @@ namespace IAEX // 2006-02-09 AF, ignore some rules. This rules are not added // to the cell - QRegExp ignoreRules( "PageWidth|CellMargins|CellDingbat|ImageSize|ImageMargins|ImageRegion" ); + QRegularExpression ignoreRules("PageWidth|CellMargins|CellDingbat|ImageSize|ImageMargins|ImageRegion"); if( 0 > r->attribute().indexOf( ignoreRules ) ) { diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/cellapplication.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/cellapplication.cpp index 25f11f6088f..5509eeebc04 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/cellapplication.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/cellapplication.cpp @@ -431,9 +431,14 @@ namespace IAEX ++v_iter; } + v->move(0, 0); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + QScreen *screen = QGuiApplication::primaryScreen(); + v->resize(screen->geometry().width(), screen->geometry().height()); +#else QDesktopWidget dw; - v->move(0, 0); v->resize(dw.geometry().width(),dw.geometry().height()); +#endif // 2005-11-30 AF, apply hide() and show() to closed groupcells // childs in the documentview diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/celldocument.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/celldocument.cpp index e36b11c5c45..164ea2c5d32 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/celldocument.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/celldocument.cpp @@ -135,7 +135,7 @@ namespace IAEX QSizePolicy::Expanding)); mainLayout_ = new QGridLayout(mainFrame_); - mainLayout_->setMargin(0); + mainLayout_->setContentsMargins(0, 0, 0, 0); mainLayout_->setSpacing(0); //Initialize workspace. diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/cellgroup.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/cellgroup.cpp index 6279eb49cf8..5f3fa1a2b80 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/cellgroup.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/cellgroup.cpp @@ -85,7 +85,7 @@ namespace IAEX{ main_ = new QWidget(this); layout_ = new QGridLayout(main_); - layout_->setMargin(0); + layout_->setContentsMargins(0, 0, 0, 0); layout_->setSpacing(0); setMainWidget(main_); diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/commandcompletion.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/commandcompletion.cpp index 78638932957..3df4980609f 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/commandcompletion.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/commandcompletion.cpp @@ -48,6 +48,7 @@ //QT Headers #include #include +#include //IAEX Headers #include "commandcompletion.h" @@ -164,7 +165,7 @@ namespace IAEX QStringList commandList = commandList_; cmds_ = &commands_; QString content = cursor.document()->toPlainText(); - QRegExp key; + QRegularExpression key; // check if alternative list is to be used (depending on keywords in the code) foreach (key, keywords_) { if (content.contains(key)) { @@ -380,7 +381,7 @@ namespace IAEX elementList_.append( unit->fullName() ); } else if( element.tagName() == "keyword" ) { - keywords_.append( QRegExp(element.attribute( "name" )) ); + keywords_.append(QRegularExpression(element.attribute( "name"))); } } node = node.nextSibling(); diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/commandcompletion.h b/OMNotebook/OMNotebook/OMNotebookGUI/commandcompletion.h index 295def53074..9aed4c01e44 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/commandcompletion.h +++ b/OMNotebook/OMNotebook/OMNotebookGUI/commandcompletion.h @@ -79,7 +79,7 @@ namespace IAEX int commandStartPos_; int commandEndPos_; - QList keywords_; + QList keywords_; QStringList *currentList_; QStringList commandList_; diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/graphcell.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/graphcell.cpp index 013933a56c7..b26a664318c 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/graphcell.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/graphcell.cpp @@ -397,7 +397,7 @@ namespace IAEX { { inCommand = false; QTextCursor tc(textCursor()); - int i = toPlainText().indexOf(QRegExp("\\n|$"), tc.position()); + int i = toPlainText().indexOf(QRegularExpression("\\n|$"), tc.position()); if(i -tc.position() > 0) tc.setPosition(i, QTextCursor::KeepAnchor); @@ -422,7 +422,7 @@ namespace IAEX { int k2 = t.blockNumber(); QTextBlock b = t.block(); int k = b.userState(); - int prevLevel = b.text().indexOf(QRegExp("\\S")); + int prevLevel = b.text().indexOf(QRegularExpression("\\S")); while(k2 >= 0 && !indentationStates.contains(k)) { @@ -493,7 +493,7 @@ namespace IAEX { bool MyTextEdit2a::lessIndented(QString s) { - QRegExp l("\\b(equation|algorithm|public|protected|else|elseif)\\b"); + QRegularExpression l("\\b(equation|algorithm|public|protected|else|elseif)\\b"); return s.indexOf(l) >= 0; } @@ -529,7 +529,7 @@ namespace IAEX { void MyTextEdit2a::goToPos(const QUrl& u) { - QRegExp e("/|\\-|:"); + QRegularExpression e("/|\\-|:"); int r=u.path().section(e, 1,1).toInt(); int c=u.path().section(e, 2,2).toInt(); int r2=u.path().section(e, 3,3).toInt(); @@ -704,7 +704,7 @@ namespace IAEX { setMainWidget(main); layout_ = new QGridLayout(mainWidget()); - layout_->setMargin(0); + layout_->setContentsMargins(0, 0, 0, 0); layout_->setSpacing(0); setTreeWidget(new InputTreeView(this)); @@ -1027,7 +1027,7 @@ namespace IAEX { tmp.replace( "    ", " " ); // 2005-12-08 AF, remove any " ); + QRegularExpression spanEnd( "" ); tmp.remove( spanEnd ); int pos = 0; while( true ) @@ -1611,7 +1611,7 @@ namespace IAEX { setState(Finished); output_->selectAll(); - res = res.replace(QRegExp("\\[:([\\d]+):([\\d]+)-([\\d]+):([\\d]+):.*\\](.*)"),"[\\1:\\2-\\3:\\4]\\5"); + res = res.replace(QRegularExpression("\\[:([\\d]+):([\\d]+)-([\\d]+):([\\d]+):.*\\](.*)"),"[\\1:\\2-\\3:\\4]\\5"); output_->textCursor().insertText( res ); QPalette pal = output_->palette(); // define palette for textEdit. @@ -1623,7 +1623,9 @@ namespace IAEX { pal.setColor(QPalette::Base, Qt::white); } output_->setPalette(pal); - +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + // TODO +#else QRegExp e("([\\d]+:[\\d]+-[\\d]+:[\\d]+)|([\\d]+:[\\d]+)"); int cap = 1; int p=0; @@ -1650,7 +1652,7 @@ namespace IAEX { actions.push_back(a); } emit setStatusMenu(actions); - +#endif ++numEvals_; contentChanged(); diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/indent.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/indent.cpp index 85cfca01c92..d29666a83b5 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/indent.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/indent.cpp @@ -32,6 +32,7 @@ #include "indent.h" #include +#include #include #include @@ -222,10 +223,14 @@ bool Indent::lMod() { } QString Indent::indentedText(QMap* states) { - buffer1 = buffer1.replace(QRegExp("(==|:=|<=|>=|<>|=|<|>)"), " \\1 "); + buffer1 = buffer1.replace(QRegularExpression("(==|:=|<=|>=|<>|=|<|>)"), " \\1 "); buffer1 = buffer1.replace('\n', " ") + " " + " "; buffer1 = buffer1.replace("//", " //"); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + QTextStream ts(&buffer1, QIODeviceBase::ReadWrite); +#else QTextStream ts(&buffer1, QIODevice::ReadWrite); +#endif //QString current, next, comment; QString comment; diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/inputcell.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/inputcell.cpp index 77d98cc61ab..b20e20845e4 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/inputcell.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/inputcell.cpp @@ -298,7 +298,7 @@ namespace IAEX setMainWidget(main); layout_ = new QGridLayout(mainWidget()); - layout_->setMargin(0); + layout_->setContentsMargins(0, 0, 0, 0); layout_->setSpacing(0); setTreeWidget(new InputTreeView(this)); @@ -608,7 +608,7 @@ namespace IAEX tmp.replace( "    ", " " ); // 2005-12-08 AF, remove any " ); + QRegularExpression spanEnd(""); tmp.remove( spanEnd ); int pos = 0; while( true ) diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/latexcell.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/latexcell.cpp index 9aee276ce0f..a529e722fb0 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/latexcell.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/latexcell.cpp @@ -170,7 +170,7 @@ namespace IAEX { else if(event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_K) { QTextCursor tc(textCursor()); - int i = toPlainText().indexOf(QRegExp("\\n|$"), tc.position()); + int i = toPlainText().indexOf(QRegularExpression("\\n|$"), tc.position()); if(i -tc.position() > 0) tc.setPosition(i, QTextCursor::KeepAnchor); @@ -245,7 +245,7 @@ namespace IAEX { setMainWidget(main); layout_ = new QGridLayout(mainWidget()); - layout_->setMargin(0); + layout_->setContentsMargins(0, 0, 0, 0); layout_->setSpacing(0); setTreeWidget(new InputTreeView(this)); @@ -486,7 +486,7 @@ namespace IAEX { tmp.replace( "    ", " " ); // 2005-12-08 AF, remove any " ); + QRegularExpression spanEnd( "" ); tmp.remove( spanEnd ); int pos = 0; while( true ) diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/notebook.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/notebook.cpp index 095c75832f7..ebe8817d1eb 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/notebook.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/notebook.cpp @@ -511,7 +511,7 @@ void NotebookWindow::createFileMenu() QString recentFile; for(int i = 0; i < 8; ++i) { - if((recentFile = s.value(QString("Recent")+QString(i), QString()).toString()) != QString()) + if((recentFile = s.value(QString("Recent")+QString(QChar(i)), QString()).toString()) != QString()) { QAction* tmpAction = recentMenu->addAction(recentFile); connect(tmpAction, SIGNAL(triggered()), this, SLOT(recentTriggered())); @@ -2409,7 +2409,7 @@ void NotebookWindow::updateRecentFiles(QString filename) QString tmp; for(int i = 0; i < 8; ++i) { - if((tmp = s.value(QString("Recent") + QString(i), QString()).toString()) != QString()) + if((tmp = s.value(QString("Recent") + QString(QChar(i)), QString()).toString()) != QString()) tmpLst.push_back(tmp); else break; @@ -2421,7 +2421,7 @@ void NotebookWindow::updateRecentFiles(QString filename) tmpLst.push_front(filename); for(int i = 0; i < 8 && i < tmpLst.size(); ++i) - s.setValue(QString("Recent") + QString(i), tmpLst[i]); + s.setValue(QString("Recent") + QString(QChar(i)), tmpLst[i]); } diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/textcell.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/textcell.cpp index 9cb8367a309..c15d1392954 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/textcell.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/textcell.cpp @@ -48,6 +48,7 @@ //QT Headers #include #include +#include //IAEX Headers @@ -414,8 +415,8 @@ namespace IAEX { // check if the text contains html code, if so - set the // text with correct function. - QRegExp expression( " |||||
|
||||||||||||" ); - QRegExp expressionTag( "<.*" ); + QRegularExpression expression( " |||||
|
||||||||||||" ); + QRegularExpression expressionTag( "<.*" ); if( 0 <= text.indexOf( expression )) { // 2005-12-06 AF, ugly way to get the style, when inserting diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/xmlparser.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/xmlparser.cpp index 544b6c42dbc..07c850029c8 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/xmlparser.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/xmlparser.cpp @@ -416,14 +416,27 @@ namespace IAEX QString text = e.text(); // replace all href="...\..." with href=".../..." QString pattern("(href[^=]*=[^\"]*\"[^\"\\\\]*)\\\\([^\"]*\")"); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + QRegularExpression rx(pattern, QRegularExpression::CaseInsensitiveOption); +#else QRegExp rx(pattern); rx.setCaseSensitivity(Qt::CaseInsensitive); rx.setMinimal(true); rx.setPatternSyntax(QRegExp::RegExp); +#endif if (!rx.isValid()) { fprintf(stderr, "Invalid QRegExp(%s)\n", rx.pattern().toStdString().c_str()); } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + QRegularExpressionMatch match = rx.match(text); + while (match.hasMatch()) + { + text = text.replace(rx, match.captured(1) + QString::fromAscii("/") + match.captured(2)); + match = rx.match(text); + } + textcell->setTextHtml(text); +#else int done = rx.indexIn(text); if (done > -1) { @@ -441,6 +454,7 @@ namespace IAEX { textcell->setTextHtml( text ); } +#endif } else if( e.tagName() == XML_RULE ) {