Skip to content

Commit

Permalink
add support for Qt6 / C++17
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Aug 20, 2024
1 parent 543c65f commit 147a4ad
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 74 deletions.
18 changes: 15 additions & 3 deletions QtSLiM/QtSLiM.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ QT += core gui opengl

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

# OpenGLWidget moved to openglwidgets in Qt6
greaterThan(QT_MAJOR_VERSION, 5): QT += openglwidgets

# Note that the target is SLiMgui now, but the old QtSLiM name lives on throughout the project
TARGET = SLiMgui
TEMPLATE = app
Expand Down Expand Up @@ -56,9 +59,18 @@ QMAKE_CFLAGS += $$(CFLAGS)
DEFINES += EIDOS_GUI
DEFINES += SLIMGUI=1

CONFIG += c++11
CONFIG += c11
QMAKE_CFLAGS += -std=c11
greaterThan(QT_MAJOR_VERSION, 5) {
# For Qt6 we require C++17 (because Qt6 requires it), but don't use it ourselves
CONFIG += c++17
CONFIG += c17
QMAKE_CFLAGS += -std=c17
} else {
# For Qt5 we require just C++11
CONFIG += c++11
CONFIG += c11
QMAKE_CFLAGS += -std=c11
}

QMAKE_CFLAGS_DEBUG += -g -Og -DDEBUG=1 -DSLIMPROFILING=0
QMAKE_CFLAGS_RELEASE += -O3 -DSLIMPROFILING=1
QMAKE_CXXFLAGS_DEBUG += -g -Og -DDEBUG=1 -DSLIMPROFILING=0
Expand Down
127 changes: 72 additions & 55 deletions QtSLiM/QtSLiMAppDelegate.cpp

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions QtSLiM/QtSLiMChromosomeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,13 +1083,13 @@ void QtSLiMChromosomeWidget::_glDrawRateMapIntervals(QRect &interiorRect, __attr
if (!intervalRect.isEmpty())
{
// color according to how "hot" the region is
double r, g, b, a;
float colorRed, colorGreen, colorBlue, colorAlpha;

if (intervalRate == 0.0)
{
// a recombination or mutation rate of 0.0 comes out as black, whereas the lowest brightness below is 0.5; we want to distinguish this
r = g = b = 0.0;
a = 1.0;
colorRed = colorGreen = colorBlue = 0.0;
colorAlpha = 1.0;
}
else
{
Expand All @@ -1105,11 +1105,22 @@ void QtSLiMChromosomeWidget::_glDrawRateMapIntervals(QRect &interiorRect, __attr
else brightness = 0.5 + lightness; // goes from 1.0 at lightness 0.5 to 0.5 at lightness 0.0

QColor intervalColor = QtSLiMColorWithHSV(hue, saturation, brightness, 1.0);

#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
// In Qt5, getRgbF() expects pointers to qreal, which is double
double r, g, b, a;
intervalColor.getRgbF(&r, &g, &b, &a);

colorRed = static_cast<float>(r);
colorGreen = static_cast<float>(g);
colorBlue = static_cast<float>(b);
colorAlpha = static_cast<float>(a);
#else
// In Qt6, getRgbF() expects pointers to float
intervalColor.getRgbF(&colorRed, &colorGreen, &colorBlue, &colorAlpha);
#endif
}

float colorRed = static_cast<float>(r), colorGreen = static_cast<float>(g), colorBlue = static_cast<float>(b), colorAlpha = static_cast<float>(a);

SLIM_GL_DEFCOORDS(intervalRect);
SLIM_GL_PUSHRECT();
SLIM_GL_PUSHRECT_COLORS();
Expand Down
2 changes: 1 addition & 1 deletion QtSLiM/QtSLiMExtras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ QStringList QtSLiMRunLineEditArrayDialog(QWidget *p_parent, QString title, QStri
QLabel *titleLabel = new QLabel(dialog);
QFont font;
font.setBold(true);
font.setWeight(75);
font.setWeight(QFont::Bold); // used to be 75, which made little sense; fixed for Qt6
titleLabel->setText(title);
titleLabel->setFont(font);
verticalLayout->addWidget(titleLabel);
Expand Down
1 change: 1 addition & 0 deletions QtSLiM/QtSLiMHelpWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <QTextDocumentFragment>
#include <QRegularExpression>
#include <QTextCursor>
#include <QFile>

#include "eidos_interpreter.h"
#include "eidos_call_signature.h"
Expand Down
1 change: 1 addition & 0 deletions QtSLiM/QtSLiMIndividualsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <QMenu>
#include <QAction>
#include <QActionGroup>
#include <QContextMenuEvent>
#include <QtGlobal>
#include <QDebug>
Expand Down
15 changes: 14 additions & 1 deletion QtSLiM/QtSLiMScriptTextEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,18 @@ void QtSLiMTextEdit::fixMouseCursor(void)
}
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void QtSLiMTextEdit::enterEvent(QEnterEvent *p_event)
{
// forward to super
QPlainTextEdit::enterEvent(p_event);

// modifiersChanged() generally keeps our cursor correct, but we do it on enterEvent
// as well just as a fallback; for example, if the mouse is inside us on launch and
// the modifier is already down, enterEvent() will fix out initial cursor
fixMouseCursor();
}
#else
void QtSLiMTextEdit::enterEvent(QEvent *p_event)
{
// forward to super
Expand All @@ -660,6 +672,7 @@ void QtSLiMTextEdit::enterEvent(QEvent *p_event)
// the modifier is already down, enterEvent() will fix out initial cursor
fixMouseCursor();
}
#endif

void QtSLiMTextEdit::modifiersChanged(Qt::KeyboardModifiers __attribute__((unused)) newModifiers)
{
Expand Down Expand Up @@ -2828,7 +2841,7 @@ void QtSLiMScriptTextEdit::toggleDebuggingForLine(int lineNumber)
{
QChar qch = blockText[firstNonWhitespace];

if ((qch != " ") && (qch != "\t"))
if ((qch != ' ') && (qch != '\t'))
break;
}

Expand Down
5 changes: 5 additions & 0 deletions QtSLiM/QtSLiMScriptTextEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <QPlainTextEdit>
#include <QPalette>
#include <QtGlobal> // for QT_VERSION

#include "eidos_interpreter.h"
#include "eidos_type_interpreter.h"
Expand Down Expand Up @@ -122,7 +123,11 @@ public slots:

// used to maintain the correct cursor (pointing hand when option is pressed)
void fixMouseCursor(void);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
virtual void enterEvent(QEnterEvent *p_event) override;
#else
virtual void enterEvent(QEvent *p_event) override;
#endif

// keeping track of undo/redo availability
bool undoAvailable_ = false;
Expand Down
15 changes: 8 additions & 7 deletions QtSLiM/QtSLiMWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
#include <QSettings>
#include <QCheckBox>
#include <QCloseEvent>
#include <QDesktopWidget>
#include <QStandardPaths>
#include <QToolTip>
#include <QHBoxLayout>
Expand All @@ -75,6 +74,7 @@
#include <QScreen>
#include <QMetaMethod>
#include <QLabel>
#include <QActionGroup>

#include <unistd.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -1420,7 +1420,8 @@ void QtSLiMWindow::tile(const QMainWindow *previous)
if (!topFrameWidth)
topFrameWidth = 40;
const QPoint position = previous->pos() + 2 * QPoint(topFrameWidth, topFrameWidth);
if (QApplication::desktop()->availableGeometry(this).contains(rect().bottomRight() + position))

if (this->screen()->availableGeometry().contains(rect().bottomRight() + position))
move(position);
}

Expand Down Expand Up @@ -5280,7 +5281,7 @@ void QtSLiMWindow::jumpToPopupButtonRunMenu(void)

// Exclude comments that contain newlines and similar characters
if ((comment.indexOf(QChar::LineFeed) != -1) ||
(comment.indexOf(0x0C) != -1) ||
(comment.indexOf(QChar::FormFeed) != -1) ||
(comment.indexOf(QChar::CarriageReturn) != -1) ||
(comment.indexOf(QChar::ParagraphSeparator) != -1) ||
(comment.indexOf(QChar::LineSeparator) != -1))
Expand Down Expand Up @@ -5464,8 +5465,8 @@ void QtSLiMWindow::jumpToPopupButtonRunMenu(void)
// Remove everything including and after the first newline
if (decl.indexOf(QChar::LineFeed) != -1)
decl.truncate(decl.indexOf(QChar::LineFeed));
if (decl.indexOf(0x0C) != -1) // form feed; apparently QChar::FormFeed did not exist in older Qt versions
decl.truncate(decl.indexOf(0x0C));
if (decl.indexOf(QChar::FormFeed) != -1) // form feed; apparently QChar::FormFeed did not exist in older Qt versions
decl.truncate(decl.indexOf(QChar::FormFeed));
if (decl.indexOf(QChar::CarriageReturn) != -1)
decl.truncate(decl.indexOf(QChar::CarriageReturn));
if (decl.indexOf(QChar::ParagraphSeparator) != -1)
Expand Down Expand Up @@ -5647,8 +5648,8 @@ void QtSLiMWindow::setScriptBlockLabelTextFromSelection(void)
// Remove everything including and after the first newline
if (decl.indexOf(QChar::LineFeed) != -1)
decl.truncate(decl.indexOf(QChar::LineFeed));
if (decl.indexOf(0x0C) != -1) // form feed; apparently QChar::FormFeed did not exist in older Qt versions
decl.truncate(decl.indexOf(0x0C));
if (decl.indexOf(QChar::FormFeed) != -1) // form feed; apparently QChar::FormFeed did not exist in older Qt versions
decl.truncate(decl.indexOf(QChar::FormFeed));
if (decl.indexOf(QChar::CarriageReturn) != -1)
decl.truncate(decl.indexOf(QChar::CarriageReturn));
if (decl.indexOf(QChar::ParagraphSeparator) != -1)
Expand Down
4 changes: 2 additions & 2 deletions QtSLiM/QtSLiMWindow_glue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ void QtSLiMWindow::glueUI(void)

// menu items that are not visible, for hidden shortcuts
QAction *actionNewWF_commentless = new QAction("New WF (Commentless)", this);
actionNewWF_commentless->setShortcut(Qt::CTRL + Qt::AltModifier + Qt::Key_N);
actionNewWF_commentless->setShortcut(Qt::ControlModifier | Qt::AltModifier | Qt::Key_N);
connect(actionNewWF_commentless, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_newWF_commentless);
addAction(actionNewWF_commentless);

QAction *actionNewNonWF_commentless = new QAction("New nonWF (Commentless)", this);
actionNewNonWF_commentless->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::AltModifier + Qt::Key_N);
actionNewNonWF_commentless->setShortcut(Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier | Qt::Key_N);
connect(actionNewNonWF_commentless, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_newNonWF_commentless);
addAction(actionNewNonWF_commentless);

Expand Down
1 change: 1 addition & 0 deletions VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ development head (in the master branch):
improve recording of subpopulations in the tree-sequence recording population table (#447)
add calcPi() and calcTajimasD() functions thanks to Nick Bailey
extend deviatePositions(), pointDeviated(), sampleNearbyPoint(), and sampleImprovedNearbyPoint() to allow vectorization with a different spatial kernel for each iteration
shift to supporting Qt6 and C++17 to build SLiMgui; Qt5 with C++11 is still supported


version 4.2.2 (Eidos version 3.2.2):
Expand Down

0 comments on commit 147a4ad

Please sign in to comment.