Skip to content

Commit 0a267f4

Browse files
author
MarcoFalke
committed
Merge bitcoin-core/gui#46: refactor: Fix deprecation warnings when building against Qt 5.15
705c1f0 qt, refactor: Fix 'buttonClicked is deprecated' warnings (Hennadii Stepanov) c2f4e5e qt, refactor: Fix 'split is deprecated' warnings (Hennadii Stepanov) 8e12d69 qt, refactor: Fix 'QFlags is deprecated' warnings (Hennadii Stepanov) fa5749c qt, refactor: Fix 'pixmap is deprecated' warnings (Hennadii Stepanov) b02264c qt, refactor: Fix 'QDateTime is deprecated' warnings (Hennadii Stepanov) Pull request description: [What's New in Qt 5.15](https://doc.qt.io/qt-5/whatsnew515.html#deprecated-modules): > To help preparing for the transition to Qt 6, numerous classes and member functions that will be removed from Qt 6.0 have been marked as deprecated in the Qt 5.15 release. Fixes #36 ACKs for top commit: jonasschnelli: utACK 705c1f0 promag: Tested ACK 705c1f0 on macos with Apple clang version 11.0.3 (clang-1103.0.32.62) and brew qt 5.15.1. Tree-SHA512: 29e00535b4583ceec0dfb29612e86ee29bdea13651b548c6d22167917a4a10464af49160a12b05151030699f690f437ebb9c4ae9f130f66a722415222165b44f
2 parents db58b85 + 705c1f0 commit 0a267f4

15 files changed

+101
-25
lines changed

src/qt/bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
263263
void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
264264
{
265265
assert(!m_splash);
266-
m_splash = new SplashScreen(nullptr, networkStyle);
266+
m_splash = new SplashScreen(networkStyle);
267267
// We don't hold a direct pointer to the splash screen after creation, but the splash
268268
// screen will take care of deleting itself when finish() happens.
269269
m_splash->show();

src/qt/bitcoingui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ void BitcoinGUI::updateProxyIcon()
13111311
bool proxy_enabled = clientModel->getProxyInfo(ip_port);
13121312

13131313
if (proxy_enabled) {
1314-
if (labelProxyIcon->pixmap() == nullptr) {
1314+
if (!GUIUtil::HasPixmap(labelProxyIcon)) {
13151315
QString ip_port_q = QString::fromStdString(ip_port);
13161316
labelProxyIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/proxy").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
13171317
labelProxyIcon->setToolTip(tr("Proxy is <b>enabled</b>: %1").arg(ip_port_q));

src/qt/bitcoingui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct BlockAndHeaderTipInfo;
4949
QT_BEGIN_NAMESPACE
5050
class QAction;
5151
class QComboBox;
52+
class QDateTime;
5253
class QMenu;
5354
class QProgressBar;
5455
class QProgressDialog;

src/qt/guiutil.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,4 +920,35 @@ void PopupMenu(QMenu* menu, const QPoint& point, QAction* at_action)
920920
menu->popup(point, at_action);
921921
}
922922

923+
QDateTime StartOfDay(const QDate& date)
924+
{
925+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
926+
return date.startOfDay();
927+
#else
928+
return QDateTime(date);
929+
#endif
930+
}
931+
932+
bool HasPixmap(const QLabel* label)
933+
{
934+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
935+
return !label->pixmap(Qt::ReturnByValue).isNull();
936+
#else
937+
return label->pixmap() != nullptr;
938+
#endif
939+
}
940+
941+
QImage GetImage(const QLabel* label)
942+
{
943+
if (!HasPixmap(label)) {
944+
return QImage();
945+
}
946+
947+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
948+
return label->pixmap(Qt::ReturnByValue).toImage();
949+
#else
950+
return label->pixmap()->toImage();
951+
#endif
952+
}
953+
923954
} // namespace GUIUtil

src/qt/guiutil.h

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ namespace GUIUtil
289289
/**
290290
* Returns the distance in pixels appropriate for drawing a subsequent character after text.
291291
*
292-
* In Qt 5.12 and before the QFontMetrics::width() is used and it is deprecated since Qt 13.0.
292+
* In Qt 5.12 and before the QFontMetrics::width() is used and it is deprecated since Qt 5.13.
293293
* In Qt 5.11 the QFontMetrics::horizontalAdvance() was introduced.
294294
*/
295295
int TextWidth(const QFontMetrics& fm, const QString& text);
@@ -303,6 +303,44 @@ namespace GUIUtil
303303
* Call QMenu::popup() only on supported QT_QPA_PLATFORM.
304304
*/
305305
void PopupMenu(QMenu* menu, const QPoint& point, QAction* at_action = nullptr);
306+
307+
/**
308+
* Returns the start-moment of the day in local time.
309+
*
310+
* QDateTime::QDateTime(const QDate& date) is deprecated since Qt 5.15.
311+
* QDate::startOfDay() was introduced in Qt 5.14.
312+
*/
313+
QDateTime StartOfDay(const QDate& date);
314+
315+
/**
316+
* Returns true if pixmap has been set.
317+
*
318+
* QPixmap* QLabel::pixmap() is deprecated since Qt 5.15.
319+
*/
320+
bool HasPixmap(const QLabel* label);
321+
QImage GetImage(const QLabel* label);
322+
323+
/**
324+
* Splits the string into substrings wherever separator occurs, and returns
325+
* the list of those strings. Empty strings do not appear in the result.
326+
*
327+
* QString::split() signature differs in different Qt versions:
328+
* - QString::SplitBehavior is deprecated since Qt 5.15
329+
* - Qt::SplitBehavior was introduced in Qt 5.14
330+
* If {QString|Qt}::SkipEmptyParts behavior is required, use this
331+
* function instead of QString::split().
332+
*/
333+
template <typename SeparatorType>
334+
QStringList SplitSkipEmptyParts(const QString& string, const SeparatorType& separator)
335+
{
336+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
337+
return string.split(separator, Qt::SkipEmptyParts);
338+
#else
339+
return string.split(separator, QString::SkipEmptyParts);
340+
#endif
341+
}
342+
343+
306344
} // namespace GUIUtil
307345

308346
#endif // BITCOIN_QT_GUIUTIL_H

src/qt/optionsmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static ProxySetting GetProxySetting(QSettings &settings, const QString &name)
219219
return default_val;
220220
}
221221
// contains IP at index 0 and port at index 1
222-
QStringList ip_port = settings.value(name).toString().split(":", QString::SkipEmptyParts);
222+
QStringList ip_port = GUIUtil::SplitSkipEmptyParts(settings.value(name).toString(), ":");
223223
if (ip_port.size() == 2) {
224224
return {true, ip_port.at(0), ip_port.at(1)};
225225
} else { // Invalid: return default

src/qt/overviewpage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <QAbstractItemDelegate>
1919
#include <QApplication>
20+
#include <QDateTime>
2021
#include <QPainter>
2122
#include <QStatusTipEvent>
2223

src/qt/paymentserver.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <QApplication>
2727
#include <QByteArray>
2828
#include <QDataStream>
29-
#include <QDateTime>
3029
#include <QDebug>
3130
#include <QFile>
3231
#include <QFileOpenEvent>

src/qt/qrimagewidget.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,12 @@ bool QRImageWidget::setQR(const QString& data, const QString& text)
9898

9999
QImage QRImageWidget::exportImage()
100100
{
101-
if(!pixmap())
102-
return QImage();
103-
return pixmap()->toImage();
101+
return GUIUtil::GetImage(this);
104102
}
105103

106104
void QRImageWidget::mousePressEvent(QMouseEvent *event)
107105
{
108-
if(event->button() == Qt::LeftButton && pixmap())
109-
{
106+
if (event->button() == Qt::LeftButton && GUIUtil::HasPixmap(this)) {
110107
event->accept();
111108
QMimeData *mimeData = new QMimeData;
112109
mimeData->setImageData(exportImage());
@@ -121,7 +118,7 @@ void QRImageWidget::mousePressEvent(QMouseEvent *event)
121118

122119
void QRImageWidget::saveImage()
123120
{
124-
if(!pixmap())
121+
if (!GUIUtil::HasPixmap(this))
125122
return;
126123
QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(), tr("PNG Image (*.png)"), nullptr);
127124
if (!fn.isEmpty())
@@ -132,14 +129,14 @@ void QRImageWidget::saveImage()
132129

133130
void QRImageWidget::copyImage()
134131
{
135-
if(!pixmap())
132+
if (!GUIUtil::HasPixmap(this))
136133
return;
137134
QApplication::clipboard()->setImage(exportImage());
138135
}
139136

140137
void QRImageWidget::contextMenuEvent(QContextMenuEvent *event)
141138
{
142-
if(!pixmap())
139+
if (!GUIUtil::HasPixmap(this))
143140
return;
144141
contextMenu->exec(event->globalPos());
145142
}

src/qt/rpcconsole.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <wallet/wallet.h>
3030
#endif
3131

32+
#include <QDateTime>
3233
#include <QFont>
3334
#include <QKeyEvent>
3435
#include <QMenu>

0 commit comments

Comments
 (0)