Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation for Qt6 #1023

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Libs/Core/ctkUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
// Qt includes
#include <QDebug>
#include <QDir>
#if QT_VERSION >= 0x060000
jamesobutler marked this conversation as resolved.
Show resolved Hide resolved
#include <QRegularExpression>
#else
#include <QRegExp>
#endif
#include <QString>
#include <QStringList>

Expand Down Expand Up @@ -109,17 +113,30 @@ const char *ctkValidWildCard =
QStringList ctk::nameFilterToExtensions(const QString& nameFilter)
{
QRegExp regexp(QString::fromLatin1(ctkNameFilterRegExp));
#if QT_VERSION >= 0x060000
int i = nameFilter.indexOf(regexp);
#else
int i = regexp.indexIn(nameFilter);
#endif
if (i < 0)
{
QRegExp isWildCard(QString::fromLatin1(ctkValidWildCard));
#if QT_VERSION >= 0x060000
if (nameFilter.indexOf(isWildCard) >= 0)
#else
if (isWildCard.indexIn(nameFilter) >= 0)
#endif
{
return QStringList(nameFilter);
}
return QStringList();
}
#if QT_VERSION >= 0x060000
QStringList captured = regexp.namedCaptureGroups();
QString f = captured[2];
jamesobutler marked this conversation as resolved.
Show resolved Hide resolved
#else
QString f = regexp.cap(2);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
return f.split(QLatin1Char(' '), Qt::SkipEmptyParts);
#else
Expand All @@ -143,12 +160,22 @@ QString ctk::extensionToRegExp(const QString& extension)
{
// typically *.jpg
QRegExp extensionExtractor("\\*\\.(\\w+)");
#if QT_VERSION >= 0x060000
int pos = extension.indexOf(extensionExtractor);
#else
int pos = extensionExtractor.indexIn(extension);
#endif
if (pos < 0)
{
return QString();
}
return ".*\\." + extensionExtractor.cap(1) + "?$";
#if QT_VERSION >= 0x060000
QStringList captured = extensionExtractor.namedCaptureGroups();
QString cap = captured[1];
jamesobutler marked this conversation as resolved.
Show resolved Hide resolved
#else
QString cap = extensionExtractor.cap(1);
#endif
return ".*\\." + cap + "?$";
}

//-----------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions Libs/Core/ctkUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include <QModelIndex>
#include <QStringList>

#if QT_VERSION >= 0x060000
#define QRegExp QRegularExpression
#endif

// STD includes
#include <vector>

Expand Down
2 changes: 2 additions & 0 deletions Libs/Widgets/ctkBasePopupWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
// Qt includes
#include <QApplication>
#include <QDebug>
#if QT_VERSION < 0x060000
#include <QDesktopWidget>
#endif
#include <QDir>
#include <QEvent>
#include <QLabel>
Expand Down
27 changes: 21 additions & 6 deletions Libs/Widgets/ctkDoubleSpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,22 @@ ::validateAndInterpret(QString &input, int &pos,
// could be because of group separators:
if (!ok && state == QValidator::Acceptable)
{
if (q->locale().groupSeparator().isPrint())
#if QT_VERSION >= 0x060000
QChar groupSeparator;
if ( q->locale().groupSeparator().size() == 1 )
groupSeparator = q->locale().groupSeparator()[0];
jamesobutler marked this conversation as resolved.
Show resolved Hide resolved
else
assert( false );
jamesobutler marked this conversation as resolved.
Show resolved Hide resolved
#else
QChar groupSeparator = q->locale().groupSeparator();
#endif
if (groupSeparator.isPrint())
{
int start = (dec == -1 ? text.size() : dec)- 1;
int lastGroupSeparator = start;
for (int digit = start; digit >= 0; --digit)
{
if (text.at(digit) == q->locale().groupSeparator())
if (text.at(digit) == groupSeparator)
{
if (digit != lastGroupSeparator - 3)
{
Expand Down Expand Up @@ -1101,8 +1110,11 @@ QSize ctkDoubleSpinBox::sizeHint() const

opt.rect = this->rect();
d->CachedSizeHint = this->style()->sizeFromContents(
QStyle::CT_SpinBox, &opt, newSizeHint, this)
.expandedTo(QApplication::globalStrut());
QStyle::CT_SpinBox, &opt, newSizeHint, this
#if QT_VERSION < 0x060000
).expandedTo(QApplication::globalStrut()
#endif
);
return d->CachedSizeHint;
}

Expand Down Expand Up @@ -1157,8 +1169,11 @@ QSize ctkDoubleSpinBox::minimumSizeHint() const

opt.rect = this->rect();
d->CachedMinimumSizeHint = this->style()->sizeFromContents(
QStyle::CT_SpinBox, &opt, newSizeHint, this)
.expandedTo(QApplication::globalStrut());
QStyle::CT_SpinBox, &opt, newSizeHint, this
#if QT_VERSION < 0x060000
).expandedTo(QApplication::globalStrut()
#endif
);
return d->CachedMinimumSizeHint;
}

Expand Down
6 changes: 6 additions & 0 deletions Libs/Widgets/ctkPopupWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

// Qt includes
#include <QApplication>
#if QT_VERSION < 0x060000
#include <QDesktopWidget>
#endif
#include <QDialog>
#include <QDir>
#include <QEvent>
Expand Down Expand Up @@ -416,7 +418,11 @@ void ctkPopupWidget::leaveEvent(QEvent* event)
}

// --------------------------------------------------------------------------
#if QT_VERSION >= 0x060000
void ctkPopupWidget::enterEvent(QEnterEvent* event)
#else
void ctkPopupWidget::enterEvent(QEvent* event)
#endif
{
Q_D(ctkPopupWidget);
QTimer::singleShot(d->ShowDelay, this, SLOT(updatePopup()));
Expand Down
4 changes: 4 additions & 0 deletions Libs/Widgets/ctkPopupWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ public Q_SLOTS:

protected:
virtual void leaveEvent(QEvent* event);
#if QT_VERSION >= 0x060000
virtual void enterEvent(QEnterEvent* event);
#else
virtual void enterEvent(QEvent* event);
#endif
virtual bool eventFilter(QObject* obj, QEvent* event);

/// Widget the popup is attached to. It opens right under \a baseWidget
Expand Down
4 changes: 2 additions & 2 deletions Libs/Widgets/ctkRangeSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ ctkRangeSliderPrivate::ctkRangeSliderPrivate(ctkRangeSlider& object)
this->m_SubclassClickOffset = 0;
this->m_SubclassPosition = 0;
this->m_SubclassWidth = 0.0;
this->m_SelectedHandles = 0;
this->m_SelectedHandles = ctkRangeSliderPrivate::Handles(); // QFlags inits to 0
jamesobutler marked this conversation as resolved.
Show resolved Hide resolved
this->m_SymmetricMoves = false;
}

Expand Down Expand Up @@ -773,7 +773,7 @@ void ctkRangeSlider::mouseReleaseEvent(QMouseEvent* mouseEvent)
this->QSlider::mouseReleaseEvent(mouseEvent);

setSliderDown(false);
d->m_SelectedHandles = 0;
d->m_SelectedHandles = ctkRangeSliderPrivate::Handles(); // sets value to 0
jamesobutler marked this conversation as resolved.
Show resolved Hide resolved

this->update();
}
Expand Down