Skip to content

Commit

Permalink
fixes for Qt6 deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Aug 20, 2024
1 parent 4f37d23 commit 47e0a91
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 4 deletions.
4 changes: 3 additions & 1 deletion QtSLiM/QtSLiM.pro
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ DEFINES += GIT_SHA1=$$GIT_HASH


# Warn and error on usage of deprecated Qt APIs; see also -Wno-deprecated-declarations below
# These flags are for development; we don't want production builds warning or erroring due to deprecation
# DEFINES += QT_DEPRECATED_WARNINGS # uncomment this to get warnings about deprecated APIs
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x050F00 # disables all the APIs deprecated before Qt 5.15.0
# DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x050F00 # disables all the APIs deprecated before Qt 5.15.0
# DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060500 # disables all the APIs deprecated before Qt 6.5.0


# Bring in flag settings from the environment; see https://stackoverflow.com/a/17578151/2752221
Expand Down
4 changes: 4 additions & 0 deletions QtSLiM/QtSLiMConsoleTextEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,11 @@ void QtSLiMConsoleTextEdit::adjustSelectionAndReadOnly(void)
void QtSLiMConsoleTextEdit::dragMoveEvent(QDragMoveEvent *p_event)
{
// Figure out where the drop would go
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QTextCursor dropCursor = cursorForPosition(p_event->pos());
#else
QTextCursor dropCursor = cursorForPosition(p_event->position().toPoint());
#endif

//qDebug() << "dragMoveEvent: " << dropCursor.position();

Expand Down
8 changes: 8 additions & 0 deletions QtSLiM/QtSLiMIndividualsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,11 @@ void QtSLiMIndividualsWidget::runContextMenuAtPoint(QPoint globalPoint, Subpopul
std::string mapName;

// If the user has selected a spatial map, extract its name
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
if (static_cast<QMetaType::Type>(action->data().type()) == QMetaType::QString) // for some reason this method's return type is apparently misdeclared; see the doc
#else
if (action->data().typeId() == QMetaType::QString)
#endif
{
QString qMapName = action->data().toString();

Expand Down Expand Up @@ -1960,7 +1964,11 @@ void QtSLiMIndividualsWidget::mousePressEvent(QMouseEvent *p_event)
}

if (subpopForEvent)
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
runContextMenuAtPoint(p_event->globalPos(), subpopForEvent);
#else
runContextMenuAtPoint(p_event->globalPosition().toPoint(), subpopForEvent);
#endif

// redraw to get rid of action button highlight
actionButtonHighlightSubpopID_ = -1;
Expand Down
4 changes: 4 additions & 0 deletions QtSLiM/QtSLiMPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ static QFont &defaultDisplayFont(void)

if (!defaultFont)
{
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QFontDatabase fontdb;
QStringList families = fontdb.families();
#else
QStringList families = QFontDatabase::families();
#endif

// Use filter() to look for matches, since the foundry can be appended after the name (why isn't this easier??)
if (families.filter("Consola").size() > 0) // good on Windows
Expand Down
10 changes: 9 additions & 1 deletion QtSLiM/QtSLiMScriptTextEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,11 @@ void QtSLiMTextEdit::mousePressEvent(QMouseEvent *p_event)
fudgeFactor = std::round(fm.horizontalAdvance(" ") / 2.0) + 1; // added in Qt 5.11
#endif

#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QPoint localPos = p_event->localPos().toPoint();
#else
QPoint localPos = p_event->position().toPoint();
#endif
QPoint fudgedPoint(std::max(0, localPos.x() - fudgeFactor), localPos.y());
int characterPositionClicked = cursorForPosition(fudgedPoint).position();

Expand Down Expand Up @@ -3207,8 +3211,12 @@ void QtSLiMScriptTextEdit::lineNumberAreaMouseEvent(QMouseEvent *p_mouseEvent)
// and return without doing anything. Note that Qt::RightButton is set for control-clicks!
if (p_mouseEvent->button() == Qt::RightButton)
return;


#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QPointF localPos = p_mouseEvent->localPos();
#else
QPointF localPos = p_mouseEvent->position();
#endif
qreal localY = localPos.y();

//qDebug() << "localY ==" << localY;
Expand Down
6 changes: 5 additions & 1 deletion QtSLiM/QtSLiMWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3284,7 +3284,7 @@ void QtSLiMWindow::displayProfileResults(void)

profile_window->setLayout(window_layout);

window_layout->setMargin(0);
window_layout->setContentsMargins(0, 0, 0, 0);
window_layout->setSpacing(0);
window_layout->addWidget(textEdit);

Expand Down Expand Up @@ -3317,8 +3317,12 @@ void QtSLiMWindow::displayProfileResults(void)
QFont optimaFont;
{
// We want a body font of Optima on the Mac; on non-Mac platforms we'll just use the default system font for now
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QFontDatabase fontdb;
QStringList families = fontdb.families();
#else
QStringList families = QFontDatabase::families();
#endif

// Use filter() to look for matches, since the foundry can be appended after the name (why isn't this easier??)
if (families.filter("Optima").size() > 0) // good on Mac
Expand Down
4 changes: 3 additions & 1 deletion QtSLiM/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@ int main(int argc, char *argv[])
linux_ForceDarkMode();
#endif

// Tell Qt to use high-DPI pixmaps for icons
// Tell Qt to use high-DPI pixmaps for icons; not needed in Qt6, which is always high-DPI
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif

// On macOS, turn off the automatic quit on last window close, for Qt 5.15.2.
// Builds against older Qt versions will just quit on the last window close, because
Expand Down

0 comments on commit 47e0a91

Please sign in to comment.