Gui: Qt6 port

* QString::indexOf() is now marked as [[nodiscard]]
* Replace deprecated methods of QMessageBox
* QMouseEvent::globalPos() is deprecated, use globalPosition().toPoint()
* QWidget::enterEvent() requires a QEnterEvent as argument
* QLibraryInfo::location() is deprecated, use path()
* QVariant::Type is deprecated, use QMetaType::Type
* QVariant::canConvert(int) is deprecated, use QVariant::canConvert(QMetaType) or QVariant::canConvert<T>()
* QMessageBox::standardIcon is deprecated, use QStyle::standardIcon()
* Replace deprecated method QMessageBox::question(), ...
* QApplication::fontMetrics() is deprecated
* QDropEvent::mouseButtons() is deprecated, use buttons()
* QDropEvent::keyboardModifiers() is deprecated, use modifiers()
* Constructor of QFontDatabase is deprecated, use static methods instead
* Qt::AA_DisableHighDpiScaling is deprecated
* Qt::AA_EnableHighDpiScaling is deprecated
* Qt::AA_UseHighDpiPixmaps is deprecated
This commit is contained in:
wmayer
2022-11-05 15:08:58 +01:00
parent 588620fd9f
commit 81d2361d9f
19 changed files with 123 additions and 49 deletions

View File

@@ -1866,18 +1866,24 @@ void Application::runApplication()
#ifdef FC_OS_WIN32
SetProcessDPIAware(); // call before the main event loop
#endif
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
QApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
#endif
}
else {
// Enable automatic scaling based on pixel density of display (added in Qt 5.6)
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
}
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
//Enable support for highres images (added in Qt 5.1, but off by default)
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
// Use software rendering for OpenGL
ParameterGrp::handle hOpenGL = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/OpenGL");

View File

@@ -83,7 +83,11 @@ bool Assistant::startAssistant()
#elif defined(Q_OS_MAC)
QString app = QCoreApplication::applicationDirPath() + QDir::separator();
#else
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator();
#else
QString app = QLibraryInfo::path(QLibraryInfo::BinariesPath) + QDir::separator();
#endif
#endif
app += QLatin1String("assistant");

View File

@@ -48,14 +48,31 @@ QByteArray toParamEntry(QString name)
return name.toLatin1();
}
QPixmap getStandardIcon(QWidget* widget, QStyle::StandardPixmap standardPixmap)
{
int iconSize = widget->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, nullptr, widget);
QIcon icon = widget->style()->standardIcon(standardPixmap);
if (!icon.isNull()) {
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
return icon.pixmap(QSize(iconSize, iconSize));
#else
qreal dpr = widget->devicePixelRatio();
return icon.pixmap(QSize(iconSize, iconSize), dpr);
#endif
}
return QPixmap();
}
void DlgCheckableMessageBox::showMessage(const QString& header, const QString& message, bool check, const QString& checkText)
{
bool checked = App::GetApplication().GetParameterGroupByPath(QByteArray("User parameter:BaseApp/CheckMessages"))->GetBool(toParamEntry(header));
if (!checked) {
auto mb = new DlgCheckableMessageBox(Gui::getMainWindow());
mb->setWindowTitle(header);
mb->setIconPixmap(QMessageBox::standardIcon(QMessageBox::Warning));
mb->setIconPixmap(getStandardIcon(mb, QStyle::SP_MessageBoxWarning));
mb->setText(message);
mb->setPrefEntry(header);
mb->setCheckBoxText(checkText);
@@ -65,6 +82,7 @@ void DlgCheckableMessageBox::showMessage(const QString& header, const QString& m
mb->show();
}
}
void DlgCheckableMessageBox::showMessage(const QString& header, const QString& message, const QString& prefPath, const QString& paramEntry,
bool entryDefault, bool check, const QString& checkText)
{
@@ -72,8 +90,9 @@ void DlgCheckableMessageBox::showMessage(const QString& header, const QString& m
if(checked == entryDefault) {
auto mb = new Gui::Dialog::DlgCheckableMessageBox(Gui::getMainWindow());
mb->setWindowTitle(header);
mb->setIconPixmap(QMessageBox::standardIcon(QMessageBox::Warning));
mb->setIconPixmap(getStandardIcon(mb, QStyle::SP_MessageBoxWarning));
mb->setText(message);
mb->setPrefPath(prefPath);
mb->setPrefEntry(paramEntry);
@@ -239,7 +258,7 @@ QDialogButtonBox::StandardButton
{
DlgCheckableMessageBox mb(parent);
mb.setWindowTitle(title);
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question));
mb.setIconPixmap(getStandardIcon(&mb, QStyle::SP_MessageBoxQuestion));
mb.setText(question);
mb.setCheckBoxText(checkBoxText);
mb.setChecked(*checkBoxSetting);

View File

@@ -65,7 +65,7 @@ DlgExpressionInput::DlgExpressionInput(const App::ObjectIdentifier & _path,
}
else {
QVariant text = parent->property("text");
if (text.canConvert(QMetaType::QString)) {
if (text.canConvert<QString>()) {
ui->expression->setText(text.toString());
}
}

View File

@@ -132,7 +132,11 @@ void Flag::resizeEvent(QResizeEvent* e)
void Flag::mouseMoveEvent(QMouseEvent *e)
{
if (e->buttons() & Qt::LeftButton) {
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
move(e->globalPos() - dragPosition);
#else
move(e->globalPosition().toPoint() - dragPosition);
#endif
e->accept();
auto viewer = dynamic_cast<View3DInventorViewer*>(parentWidget());
if (viewer)
@@ -143,7 +147,11 @@ void Flag::mouseMoveEvent(QMouseEvent *e)
void Flag::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton) {
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
dragPosition = e->globalPos() - frameGeometry().topLeft();
#else
dragPosition = e->globalPosition().toPoint() - frameGeometry().topLeft();
#endif
e->accept();
}
}

View File

@@ -372,7 +372,11 @@ bool Translator::eventFilter(QObject* obj, QEvent* ev)
if ((mod & Qt::KeypadModifier) && (key == Qt::Key_Period || key == Qt::Key_Comma)) {
if (ev->spontaneous()) {
auto dp = QString(QLocale().decimalPoint());
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
int dpcode = QKeySequence(dp)[0];
#else
int dpcode = QKeySequence(dp)[0].key();
#endif
if (kev->text() != dp) {
QKeyEvent modifiedKeyEvent(kev->type(), dpcode, mod, dp, kev->isAutoRepeat(), kev->count());
qApp->sendEvent(obj, &modifiedKeyEvent);

View File

@@ -24,6 +24,7 @@
#ifndef _PreComp_
# include <boost_signals2.hpp>
# include <boost/core/ignore_unused.hpp>
# include <QApplication>
# include <QEvent>
# include <QCloseEvent>
@@ -151,12 +152,12 @@ void MDIView::onRelabel(Gui::Document *pDoc)
QRegularExpression rx(QLatin1String("(\\s\\:\\s\\d+\\[\\*\\])$"));
QRegularExpressionMatch match;
//int pos =
cap.lastIndexOf(rx, -1, &match);
boost::ignore_unused(cap.lastIndexOf(rx, -1, &match));
if (!match.hasMatch()) {
// ... or not
rx.setPattern(QLatin1String("(\\s\\:\\s\\d+)$"));
//pos =
cap.lastIndexOf(rx, -1, &match);
boost::ignore_unused(cap.lastIndexOf(rx, -1, &match));
}
if (match.hasMatch()) {
cap = QString::fromUtf8(pDoc->getDocument()->Label.getValue());

View File

@@ -495,7 +495,7 @@ void StdCmdDownloadOnlineHelp::activated(int iMsg)
if (QMessageBox::critical(getMainWindow(), tr("Non-existing directory"),
tr("The directory '%1' does not exist.\n\n"
"Do you want to specify an existing directory?").arg(fi.filePath()),
QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape) !=
QMessageBox::Yes | QMessageBox::No) !=
QMessageBox::Yes)
{
// exit the command
@@ -513,7 +513,7 @@ void StdCmdDownloadOnlineHelp::activated(int iMsg)
if (QMessageBox::critical(getMainWindow(), tr("Missing permission"),
tr("You don't have write permission to '%1'\n\n"
"Do you want to specify another directory?").arg(fi.filePath()),
QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape) !=
QMessageBox::Yes | QMessageBox::No) !=
QMessageBox::Yes)
{
// exit the command

View File

@@ -486,9 +486,9 @@ void ProgressBar::aboutToHide()
bool ProgressBar::canAbort() const
{
int ret = QMessageBox::question(getMainWindow(),tr("Aborting"),
tr("Do you really want to abort the operation?"), QMessageBox::Yes,
QMessageBox::No|QMessageBox::Default);
auto ret = QMessageBox::question(getMainWindow(),tr("Aborting"),
tr("Do you really want to abort the operation?"), QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
return (ret == QMessageBox::Yes) ? true : false;
}

View File

@@ -319,9 +319,9 @@ void ProgressDialog::onCancel()
bool ProgressDialog::canAbort() const
{
int ret = QMessageBox::question(getMainWindow(),tr("Aborting"),
tr("Do you really want to abort the operation?"), QMessageBox::Yes,
QMessageBox::No|QMessageBox::Default);
auto ret = QMessageBox::question(getMainWindow(),tr("Aborting"),
tr("Do you really want to abort the operation?"), QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
return (ret == QMessageBox::Yes) ? true : false;
}

View File

@@ -852,7 +852,7 @@ void PythonConsole::runSource(const QString& line)
if (check) {
ret = QMessageBox::question(this, tr("System exit"),
tr("The application is still running.\nDo you want to exit without saving your data?"),
QMessageBox::Yes, QMessageBox::No|QMessageBox::Escape|QMessageBox::Default);
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
}
if (ret == QMessageBox::Yes) {
PyErr_Clear();
@@ -1017,7 +1017,11 @@ void PythonConsole::dropEvent (QDropEvent * e)
else {
// always copy text when doing drag and drop
if (mimeData->hasText()) {
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
QTextCursor cursor = this->cursorForPosition(e->pos());
#else
QTextCursor cursor = this->cursorForPosition(e->position().toPoint());
#endif
QTextCursor inputLineBegin = this->inputBegin();
if (!cursorBeyond( cursor, inputLineBegin )) {
@@ -1025,7 +1029,11 @@ void PythonConsole::dropEvent (QDropEvent * e)
QRect newPos = this->cursorRect();
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
QDropEvent newEv(QPoint(newPos.x(), newPos.y()), Qt::CopyAction, mimeData, e->mouseButtons(), e->keyboardModifiers());
#else
QDropEvent newEv(QPoint(newPos.x(), newPos.y()), Qt::CopyAction, mimeData, e->buttons(), e->modifiers());
#endif
e->accept();
QPlainTextEdit::dropEvent(&newEv);
}

View File

@@ -168,7 +168,11 @@ void TaskHeader::animate()
update();
}
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
void TaskHeader::enterEvent ( QEvent * /*event*/ )
#else
void TaskHeader::enterEvent ( QEnterEvent * /*event*/ )
#endif
{
m_over = true;

View File

@@ -47,14 +47,18 @@ protected Q_SLOTS:
void animate();
protected:
virtual void paintEvent ( QPaintEvent * event );
virtual void enterEvent ( QEvent * event );
virtual void leaveEvent ( QEvent * event );
virtual void mouseReleaseEvent ( QMouseEvent * event );
virtual void keyPressEvent ( QKeyEvent * event );
virtual void keyReleaseEvent ( QKeyEvent * event );
void paintEvent ( QPaintEvent * event ) override;
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
void enterEvent ( QEvent * event ) override;
#else
void enterEvent ( QEnterEvent * event ) override;
#endif
void leaveEvent ( QEvent * event ) override;
void mouseReleaseEvent ( QMouseEvent * event ) override;
void keyPressEvent ( QKeyEvent * event ) override;
void keyReleaseEvent ( QKeyEvent * event ) override;
bool eventFilter(QObject *obj, QEvent *event);
bool eventFilter(QObject *obj, QEvent *event) override;
void changeIcons();

View File

@@ -66,7 +66,11 @@ public:
void trackPointerPosition(QMouseEvent * event)
{
assert(this->windowsize[1] != -1);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
this->globalmousepos = event->globalPos();
#else
this->globalmousepos = event->globalPosition().toPoint();
#endif
SbVec2s mousepos(event->pos().x(), this->windowsize[1] - event->pos().y() - 1);
// the following corrects for high-dpi displays (e.g. mac retina)

View File

@@ -79,7 +79,8 @@ void TaskCSysDragger::setupGui()
auto tLabel = new QLabel(tr("Translation Increment:"), incrementsBox);
gridLayout->addWidget(tLabel, 0, 0, Qt::AlignRight);
int spinBoxWidth = QApplication::fontMetrics().averageCharWidth() * 20;
QFontMetrics metrics(QApplication::font());
int spinBoxWidth = metrics.averageCharWidth() * 20;
tSpinBox = new QuantitySpinBox(incrementsBox);
tSpinBox->setMinimum(0.0);
tSpinBox->setMaximum(std::numeric_limits<double>::max());

View File

@@ -1493,7 +1493,11 @@ void TreeWidget::dragMoveEvent(QDragMoveEvent* event)
return;
auto modifier = QApplication::queryKeyboardModifiers();
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
QTreeWidgetItem* targetItem = itemAt(event->pos());
#else
QTreeWidgetItem* targetItem = itemAt(event->position().toPoint());
#endif
if (!targetItem || targetItem->isSelected()) {
leaveEvent(nullptr);
event->ignore();
@@ -1634,7 +1638,11 @@ void TreeWidget::dropEvent(QDropEvent* event)
//FIXME: This should actually be done inside dropMimeData
bool touched = false;
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
QTreeWidgetItem* targetItem = itemAt(event->pos());
#else
QTreeWidgetItem* targetItem = itemAt(event->position().toPoint());
#endif
// not dropped onto an item
if (!targetItem)
return;

View File

@@ -562,9 +562,9 @@ Py::Object PyResource::value(const Py::Tuple& args)
}
Py::Object item = Py::None();
switch (v.type())
switch (v.userType())
{
case QVariant::StringList:
case QMetaType::QStringList:
{
QStringList str = v.toStringList();
int nSize = str.count();
@@ -574,21 +574,21 @@ Py::Object PyResource::value(const Py::Tuple& args)
}
item = slist;
} break;
case QVariant::ByteArray:
case QMetaType::QByteArray:
break;
case QVariant::String:
case QMetaType::QString:
item = Py::String(v.toString().toLatin1());
break;
case QVariant::Double:
case QMetaType::Double:
item = Py::Float(v.toDouble());
break;
case QVariant::Bool:
case QMetaType::Bool:
item = Py::Boolean(v.toBool() ? 1 : 0);
break;
case QVariant::UInt:
case QMetaType::UInt:
item = Py::Long(static_cast<unsigned long>(v.toUInt()));
break;
case QVariant::Int:
case QMetaType::Int:
item = Py::Int(v.toInt());
break;
default:

View File

@@ -760,7 +760,7 @@ QVariant PropertyStringItem::value(const App::Property* prop) const
void PropertyStringItem::setValue(const QVariant& value)
{
if(!hasExpression()) {
if (!value.canConvert(QVariant::String))
if (!value.canConvert<QString>())
return;
QString val = value.toString();
val = QString::fromUtf8(Base::Interpreter().strToPython(val.toUtf8()).c_str());
@@ -813,7 +813,7 @@ QVariant PropertyFontItem::value(const App::Property* prop) const
void PropertyFontItem::setValue(const QVariant& value)
{
if (hasExpression() || !value.canConvert(QVariant::String))
if (hasExpression() || !value.canConvert<QString>())
return;
QString val = value.toString();
QString data = QString::fromLatin1("\"%1\"").arg(val);
@@ -832,8 +832,11 @@ QWidget* PropertyFontItem::createEditor(QWidget* parent, const QObject* receiver
void PropertyFontItem::setEditorData(QWidget *editor, const QVariant& data) const
{
auto cb = qobject_cast<QComboBox*>(editor);
QFontDatabase fdb;
QStringList familyNames = fdb.families(QFontDatabase::Any);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
QStringList familyNames = QFontDatabase().families(QFontDatabase::Any);
#else
QStringList familyNames = QFontDatabase::families(QFontDatabase::Any);
#endif
cb->addItems(familyNames);
int index = familyNames.indexOf(data.toString());
cb->setCurrentIndex(index);
@@ -877,7 +880,7 @@ void PropertyIntegerItem::setValue(const QVariant& value)
{
//if the item has an expression it issues the python code
if (!hasExpression()) {
if (!value.canConvert(QVariant::Int))
if (!value.canConvert<int>())
return;
int val = value.toInt();
QString data = QString::fromLatin1("%1").arg(val);
@@ -944,7 +947,7 @@ void PropertyIntegerConstraintItem::setValue(const QVariant& value)
{
//if the item has an expression it issues the python code
if (!hasExpression()) {
if (!value.canConvert(QVariant::Int))
if (!value.canConvert<int>())
return;
int val = value.toInt();
QString data = QString::fromLatin1("%1").arg(val);
@@ -1038,7 +1041,7 @@ void PropertyFloatItem::setValue(const QVariant& value)
{
//if the item has an expression it issues the python code
if (!hasExpression()) {
if (!value.canConvert(QVariant::Double))
if (!value.canConvert<double>())
return;
double val = value.toDouble();
QString data = QString::fromLatin1("%1").arg(val, 0, 'f', decimals());
@@ -1214,7 +1217,7 @@ void PropertyFloatConstraintItem::setValue(const QVariant& value)
{
//if the item has an expression it issues the python code
if (!hasExpression()) {
if (!value.canConvert(QVariant::Double))
if (!value.canConvert<double>())
return;
double val = value.toDouble();
QString data = QString::fromLatin1("%1").arg(val, 0, 'f', decimals());
@@ -1313,7 +1316,7 @@ QVariant PropertyBoolItem::value(const App::Property* prop) const
void PropertyBoolItem::setValue(const QVariant& value)
{
if (hasExpression() || !value.canConvert(QVariant::Bool))
if (hasExpression() || !value.canConvert<bool>())
return;
bool val = value.toBool();
QString data = (val ? QLatin1String("True") : QLatin1String("False"));
@@ -2827,7 +2830,7 @@ void PropertyEnumItem::setValue(const QVariant& value)
QString data;
if (value.type() == QVariant::StringList) {
if (value.userType() == QMetaType::QStringList) {
QStringList values = value.toStringList();
QTextStream str(&data);
str << "[";
@@ -2841,7 +2844,7 @@ void PropertyEnumItem::setValue(const QVariant& value)
}
str << "]";
}
else if (value.canConvert(QVariant::String)) {
else if (value.canConvert<QString>()) {
QByteArray val = value.toString().toUtf8();
std::string str = Base::Tools::escapedUnicodeFromUtf8(val);
data = QString::fromLatin1("u\"%1\"").arg(QString::fromStdString(str));
@@ -3058,7 +3061,7 @@ QVariant PropertyStringListItem::value(const App::Property* prop) const
void PropertyStringListItem::setValue(const QVariant& value)
{
if (hasExpression() || !value.canConvert(QVariant::StringList))
if (hasExpression() || !value.canConvert<QStringList>())
return;
QStringList values = value.toStringList();
QString data;
@@ -3137,7 +3140,7 @@ QVariant PropertyFloatListItem::value(const App::Property* prop) const
void PropertyFloatListItem::setValue(const QVariant& value)
{
if (hasExpression() || !value.canConvert(QVariant::StringList))
if (hasExpression() || !value.canConvert<QStringList>())
return;
QStringList values = value.toStringList();
QString data;
@@ -3212,7 +3215,7 @@ QVariant PropertyIntegerListItem::value(const App::Property* prop) const
void PropertyIntegerListItem::setValue(const QVariant& value)
{
if (hasExpression() || !value.canConvert(QVariant::StringList))
if (hasExpression() || !value.canConvert<QStringList>())
return;
QStringList values = value.toStringList();
QString data;
@@ -4109,7 +4112,7 @@ QVariant PropertyFileItem::value(const App::Property* prop) const
void PropertyFileItem::setValue(const QVariant& value)
{
if (hasExpression() || !value.canConvert(QVariant::String))
if (hasExpression() || !value.canConvert<QString>())
return;
QString val = value.toString();
QString data = QString::fromLatin1("\"%1\"").arg(val);
@@ -4168,7 +4171,7 @@ QVariant PropertyPathItem::value(const App::Property* prop) const
void PropertyPathItem::setValue(const QVariant& value)
{
if (hasExpression() || !value.canConvert(QVariant::String))
if (hasExpression() || !value.canConvert<QString>())
return;
QString val = value.toString();
QString data = QString::fromLatin1("\"%1\"").arg(val);
@@ -4220,7 +4223,7 @@ QVariant PropertyTransientFileItem::value(const App::Property* prop) const
void PropertyTransientFileItem::setValue(const QVariant& value)
{
if (hasExpression() || !value.canConvert(QVariant::String))
if (hasExpression() || !value.canConvert<QString>())
return;
QString val = value.toString();
QString data = QString::fromLatin1("\"%1\"").arg(val);

View File

@@ -82,7 +82,7 @@ bool PropertyModel::setData(const QModelIndex& index, const QVariant & value, in
if (role == Qt::EditRole) {
auto item = static_cast<PropertyItem*>(index.internalPointer());
QVariant data = item->data(index.column(), role);
if (data.type() == QVariant::Double && value.type() == QVariant::Double) {
if (data.userType() == QMetaType::Double && value.userType() == QMetaType::Double) {
// since we store some properties as floats we get some round-off
// errors here. Thus, we use an epsilon here.
// NOTE: Since 0.14 PropertyFloat uses double precision, so this is maybe unnecessary now?