Skip to content

Commit

Permalink
OMNotebook: Qt6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed May 21, 2024
1 parent 2b6b7f9 commit 49a8416
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 39 deletions.
6 changes: 5 additions & 1 deletion OMNotebook/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 8 additions & 3 deletions OMNotebook/OMNotebook/OMNotebookGUI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

//QT Headers
#include <QtCore/QString>
#include <QtCore/QRegExp>
#include <QRegExp>
#include <QtGui/QTextCharFormat>
#include <QSyntaxHighlighter>

Expand Down
17 changes: 9 additions & 8 deletions OMNotebook/OMNotebook/OMNotebookGUI/cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
//QT Headers
#include <QtGlobal>
#include <QtWidgets>
#include <QRegExp>

#include <exception>
#include <stdexcept>
Expand Down Expand Up @@ -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
Expand All @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -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 <FontSlant>, 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 <TextAlignment>, 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 <TextJustification>, 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 <FontWeight>, VALUE: " << r->value().toStdString() << std::endl;
}
Expand All @@ -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 ) )
{
Expand Down
7 changes: 6 additions & 1 deletion OMNotebook/OMNotebook/OMNotebookGUI/cellapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion OMNotebook/OMNotebook/OMNotebookGUI/celldocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion OMNotebook/OMNotebook/OMNotebookGUI/cellgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down
5 changes: 3 additions & 2 deletions OMNotebook/OMNotebook/OMNotebookGUI/commandcompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
//QT Headers
#include <QtCore/QFile>
#include <QtGui/QTextDocument>
#include <QRegularExpression>

//IAEX Headers
#include "commandcompletion.h"
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion OMNotebook/OMNotebook/OMNotebookGUI/commandcompletion.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace IAEX
int commandStartPos_;
int commandEndPos_;

QList<QRegExp> keywords_;
QList<QRegularExpression> keywords_;

QStringList *currentList_;
QStringList commandList_;
Expand Down
20 changes: 11 additions & 9 deletions OMNotebook/OMNotebook/OMNotebookGUI/graphcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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))
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -1027,7 +1027,7 @@ namespace IAEX {
tmp.replace( "&nbsp;&nbsp;&nbsp;&nbsp;", " " );

// 2005-12-08 AF, remove any <span style tag
QRegExp spanEnd( "</span>" );
QRegularExpression spanEnd( "</span>" );
tmp.remove( spanEnd );
int pos = 0;
while( true )
Expand Down Expand Up @@ -1611,7 +1611,7 @@ namespace IAEX {
setState(Finished);

output_->selectAll();
res = res.replace(QRegExp("\\[<interactive>:([\\d]+):([\\d]+)-([\\d]+):([\\d]+):.*\\](.*)"),"[\\1:\\2-\\3:\\4]\\5");
res = res.replace(QRegularExpression("\\[<interactive>:([\\d]+):([\\d]+)-([\\d]+):([\\d]+):.*\\](.*)"),"[\\1:\\2-\\3:\\4]\\5");
output_->textCursor().insertText( res );

QPalette pal = output_->palette(); // define palette for textEdit.
Expand All @@ -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;
Expand All @@ -1650,7 +1652,7 @@ namespace IAEX {
actions.push_back(a);
}
emit setStatusMenu(actions);

#endif
++numEvals_;
contentChanged();

Expand Down
7 changes: 6 additions & 1 deletion OMNotebook/OMNotebook/OMNotebookGUI/indent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "indent.h"
#include <QRegExp>
#include <QRegularExpression>
#include <QMessageBox>
#include <QDebug>

Expand Down Expand Up @@ -222,10 +223,14 @@ bool Indent::lMod() {
}

QString Indent::indentedText(QMap<int, IndentationState*>* states) {
buffer1 = buffer1.replace(QRegExp("(==|:=|<=|>=|<>|=|<|>)"), " \\1 ");
buffer1 = buffer1.replace(QRegularExpression("(==|:=|<=|>=|<>|=|<|>)"), " \\1 ");
buffer1 = buffer1.replace('\n', " <newLine> ") + " <newLine> " + " <newLine> ";
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;
Expand Down
4 changes: 2 additions & 2 deletions OMNotebook/OMNotebook/OMNotebookGUI/inputcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -608,7 +608,7 @@ namespace IAEX
tmp.replace( "&nbsp;&nbsp;&nbsp;&nbsp;", " " );

// 2005-12-08 AF, remove any <span style tag
QRegExp spanEnd( "</span>" );
QRegularExpression spanEnd("</span>");
tmp.remove( spanEnd );
int pos = 0;
while( true )
Expand Down
6 changes: 3 additions & 3 deletions OMNotebook/OMNotebook/OMNotebookGUI/latexcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -486,7 +486,7 @@ namespace IAEX {
tmp.replace( "&nbsp;&nbsp;&nbsp;&nbsp;", " " );

// 2005-12-08 AF, remove any <span style tag
QRegExp spanEnd( "</span>" );
QRegularExpression spanEnd( "</span>" );
tmp.remove( spanEnd );
int pos = 0;
while( true )
Expand Down
6 changes: 3 additions & 3 deletions OMNotebook/OMNotebook/OMNotebookGUI/notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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;
Expand All @@ -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]);

}

Expand Down
5 changes: 3 additions & 2 deletions OMNotebook/OMNotebook/OMNotebookGUI/textcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
//QT Headers
#include <QtGlobal>
#include <QtWidgets>
#include <QRegExp>


//IAEX Headers
Expand Down Expand Up @@ -414,8 +415,8 @@ namespace IAEX
{
// check if the text contains html code, if so - set the
// text with correct function.
QRegExp expression( "&nbsp;|<b>|<B>|</b>|</B>|<br>|<BR>|</a>|</A>|<sup>|<SUP>|</sup>|</SUP>|<sub>|<SUP>|</sub>|</SUB>|<span|<SPAN|</span>|</SPAN>" );
QRegExp expressionTag( "<.*" );
QRegularExpression expression( "&nbsp;|<b>|<B>|</b>|</B>|<br>|<BR>|</a>|</A>|<sup>|<SUP>|</sup>|</SUP>|<sub>|<SUP>|</sub>|</SUB>|<span|<SPAN|</span>|</SPAN>" );
QRegularExpression expressionTag( "<.*" );
if( 0 <= text.indexOf( expression ))
{
// 2005-12-06 AF, ugly way to get the style, when inserting
Expand Down

0 comments on commit 49a8416

Please sign in to comment.