Skip to content

Commit

Permalink
Qt5: fix deprecation warnings for Qt 5.15
Browse files Browse the repository at this point in the history
+ QByteArray::append is deprecated
+ QPixmap* QLabel::pixmap() is deprecated
+ overloaded version of QString::split is deprecated
+ QSysInfo::windowsVersion()/QSysInfo::MacVersion() is deprecated
  • Loading branch information
wwmayer committed Oct 18, 2020
1 parent 34f4b71 commit 2057e15
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/Gui/Application.cpp
Expand Up @@ -1562,13 +1562,21 @@ QStringList Application::workbenches(void) const
QStringList hidden, extra;
if (ht != config.end()) {
QString items = QString::fromLatin1(ht->second.c_str());
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
hidden = items.split(QLatin1Char(';'), Qt::SkipEmptyParts);
#else
hidden = items.split(QLatin1Char(';'), QString::SkipEmptyParts);
#endif
if (hidden.isEmpty())
hidden.push_back(QLatin1String(""));
}
if (et != config.end()) {
QString items = QString::fromLatin1(et->second.c_str());
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
extra = items.split(QLatin1Char(';'), Qt::SkipEmptyParts);
#else
extra = items.split(QLatin1Char(';'), QString::SkipEmptyParts);
#endif
if (extra.isEmpty())
extra.push_back(QLatin1String(""));
}
Expand Down
6 changes: 5 additions & 1 deletion src/Gui/CommandView.cpp
Expand Up @@ -1863,8 +1863,12 @@ void StdViewScreenShot::activated(int iMsg)
// Replace newline escape sequence through '\\n' string to build one big string,
// otherwise Python would interpret it as an invalid command.
// Python does the decoding for us.
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
QStringList lines = comment.split(QLatin1String("\n"), Qt::KeepEmptyParts );
#else
QStringList lines = comment.split(QLatin1String("\n"), QString::KeepEmptyParts );
comment = lines.join(QLatin1String("\\n"));
#endif
comment = lines.join(QLatin1String("\\n"));
doCommand(Gui,"Gui.activeDocument().activeView().saveImage('%s',%d,%d,'%s','%s')",
fn.toUtf8().constData(),w,h,background,comment.toUtf8().constData());
}
Expand Down
4 changes: 4 additions & 0 deletions src/Gui/DlgActionsImp.cpp
Expand Up @@ -252,8 +252,12 @@ void DlgCustomActionsImp::on_buttonAddAction_clicked()
item->setData(1, Qt::UserRole, actionName);
item->setText(1, ui->actionMenu->text());
item->setSizeHint(0, QSize(32, 32));
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
item->setIcon(0, ui->pixmapLabel->pixmap(Qt::ReturnByValue));
#else
if (ui->pixmapLabel->pixmap())
item->setIcon(0, *ui->pixmapLabel->pixmap());
#endif

// Convert input text into utf8
if (!ui->actionWhatsThis->text().isEmpty())
Expand Down
4 changes: 4 additions & 0 deletions src/Gui/DlgCheckableMessageBox.cpp
Expand Up @@ -133,9 +133,13 @@ void DlgCheckableMessageBox::setText(const QString &t)

QPixmap DlgCheckableMessageBox::iconPixmap() const
{
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
return m_d->ui.pixmapLabel->pixmap(Qt::ReturnByValue);
#else
if (const QPixmap *p = m_d->ui.pixmapLabel->pixmap())
return QPixmap(*p);
return QPixmap();
#endif
}

void DlgCheckableMessageBox::setIconPixmap(const QPixmap &p)
Expand Down
4 changes: 4 additions & 0 deletions src/Gui/DlgParameterImp.cpp
Expand Up @@ -396,7 +396,11 @@ void DlgParameterImp::onChangeParameterSet(int itemPos)
ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Preferences");
hGrp = hGrp->GetGroup("ParameterEditor");
QString path = QString::fromUtf8(hGrp->GetASCII("LastParameterGroup").c_str());
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
QStringList paths = path.split(QLatin1String("."), Qt::SkipEmptyParts);
#else
QStringList paths = path.split(QLatin1String("."), QString::SkipEmptyParts);
#endif

QTreeWidgetItem* parent = 0;
for (int index=0; index < paramGroup->topLevelItemCount() && !paths.empty(); index++) {
Expand Down
8 changes: 8 additions & 0 deletions src/Gui/DlgProjectInformationImp.cpp
Expand Up @@ -92,7 +92,11 @@ DlgProjectInformationImp::DlgProjectInformationImp(App::Document* doc, QWidget*
// When saving the text to XML the newlines get lost. So we store also the newlines as '\n'.
// See also accept().
QString comment = QString::fromUtf8(doc->Comment.getValue());
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
QStringList lines = comment.split(QLatin1String("\\n"), Qt::KeepEmptyParts);
#else
QStringList lines = comment.split(QLatin1String("\\n"), QString::KeepEmptyParts);
#endif
QString text = lines.join(QLatin1String("\n"));
ui->textEditComment->setPlainText( text );
connect(ui->pushButtonOpenURL, SIGNAL(clicked()),this, SLOT(open_url()));
Expand Down Expand Up @@ -124,7 +128,11 @@ void DlgProjectInformationImp::accept()

// Replace newline escape sequence through '\\n' string
QStringList lines = ui->textEditComment->toPlainText().split
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
(QLatin1String("\n"), Qt::KeepEmptyParts);
#else
(QLatin1String("\n"), QString::KeepEmptyParts);
#endif
QString text = lines.join(QLatin1String("\\n"));
_doc->Comment.setValue(text.isEmpty() ? "" : text.toUtf8());

Expand Down
8 changes: 8 additions & 0 deletions src/Gui/DlgWorkbenchesImp.cpp
Expand Up @@ -211,7 +211,11 @@ QStringList DlgWorkbenchesImp::load_enabled_workbenches()

hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches");
enabled_wbs = QString::fromStdString(hGrp->GetASCII("Enabled", all_workbenches.toStdString().c_str()).c_str());
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
enabled_wbs_list = enabled_wbs.split(QLatin1String(","), Qt::SkipEmptyParts);
#else
enabled_wbs_list = enabled_wbs.split(QLatin1String(","), QString::SkipEmptyParts);
#endif

if (enabled_wbs_list.at(0) == all_workbenches) {
enabled_wbs_list.removeFirst();
Expand All @@ -232,7 +236,11 @@ QStringList DlgWorkbenchesImp::load_disabled_workbenches()

hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches");
disabled_wbs = QString::fromStdString(hGrp->GetASCII("Disabled", ""));
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
disabled_wbs_list = disabled_wbs.split(QLatin1String(","), Qt::SkipEmptyParts);
#else
disabled_wbs_list = disabled_wbs.split(QLatin1String(","), QString::SkipEmptyParts);
#endif

return disabled_wbs_list;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Gui/Splashscreen.cpp
Expand Up @@ -294,7 +294,8 @@ static QString getOperatingSystem()
{
#if QT_VERSION >= 0x050400
return QSysInfo::prettyProductName();
#endif

#else // < 0x050400

#if defined (Q_OS_WIN32)
switch(QSysInfo::windowsVersion())
Expand Down Expand Up @@ -379,6 +380,8 @@ static QString getOperatingSystem()
#else
return QString();
#endif

#endif // >= 0x050400
}

static int getWordSizeOfOS()
Expand Down
8 changes: 4 additions & 4 deletions src/Mod/TechDraw/Gui/QGIFace.cpp
Expand Up @@ -543,8 +543,8 @@ void QGIFace::buildSvgHatch()
m_rect->centerAt(fCenter);
r = m_rect->rect();
QByteArray before,after;
before.append(QString::fromStdString(SVGCOLPREFIX + SVGCOLDEFAULT));
after.append(QString::fromStdString(SVGCOLPREFIX + m_svgCol));
before = QString::fromStdString(SVGCOLPREFIX + SVGCOLDEFAULT).toUtf8();
after = QString::fromStdString(SVGCOLPREFIX + m_svgCol).toUtf8();
QByteArray colorXML = m_svgXML.replace(before,after);
long int tileCount = 0;
for (int iw = 0; iw < int(nw); iw++) {
Expand Down Expand Up @@ -590,8 +590,8 @@ void QGIFace::buildPixHatch()

r = m_rect->rect();
QByteArray before,after;
before.append(QString::fromStdString(SVGCOLPREFIX + SVGCOLDEFAULT));
after.append(QString::fromStdString(SVGCOLPREFIX + m_svgCol));
before = QString::fromStdString(SVGCOLPREFIX + SVGCOLDEFAULT).toUtf8();
after = QString::fromStdString(SVGCOLPREFIX + m_svgCol).toUtf8();
QByteArray colorXML = m_svgXML.replace(before,after);
QSvgRenderer renderer;
bool success = renderer.load(colorXML);
Expand Down

0 comments on commit 2057e15

Please sign in to comment.