Skip to content

Commit b02264c

Browse files
committed
qt, refactor: Fix 'QDateTime is deprecated' warnings
1 parent 93ab136 commit b02264c

File tree

8 files changed

+31
-10
lines changed

8 files changed

+31
-10
lines changed

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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,4 +920,13 @@ 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+
923932
} // namespace GUIUtil

src/qt/guiutil.h

Lines changed: 10 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,15 @@ 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+
306315
} // namespace GUIUtil
307316

308317
#endif // BITCOIN_QT_GUIUTIL_H

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/rpcconsole.cpp

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

31+
#include <QDateTime>
3132
#include <QFont>
3233
#include <QKeyEvent>
3334
#include <QMenu>

src/qt/rpcconsole.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace Ui {
2828
}
2929

3030
QT_BEGIN_NAMESPACE
31+
class QDateTime;
3132
class QMenu;
3233
class QItemSelection;
3334
QT_END_NAMESPACE

src/qt/transactionview.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,30 +275,30 @@ void TransactionView::chooseDate(int idx)
275275
break;
276276
case Today:
277277
transactionProxyModel->setDateRange(
278-
QDateTime(current),
278+
GUIUtil::StartOfDay(current),
279279
TransactionFilterProxy::MAX_DATE);
280280
break;
281281
case ThisWeek: {
282282
// Find last Monday
283283
QDate startOfWeek = current.addDays(-(current.dayOfWeek()-1));
284284
transactionProxyModel->setDateRange(
285-
QDateTime(startOfWeek),
285+
GUIUtil::StartOfDay(startOfWeek),
286286
TransactionFilterProxy::MAX_DATE);
287287

288288
} break;
289289
case ThisMonth:
290290
transactionProxyModel->setDateRange(
291-
QDateTime(QDate(current.year(), current.month(), 1)),
291+
GUIUtil::StartOfDay(QDate(current.year(), current.month(), 1)),
292292
TransactionFilterProxy::MAX_DATE);
293293
break;
294294
case LastMonth:
295295
transactionProxyModel->setDateRange(
296-
QDateTime(QDate(current.year(), current.month(), 1).addMonths(-1)),
297-
QDateTime(QDate(current.year(), current.month(), 1)));
296+
GUIUtil::StartOfDay(QDate(current.year(), current.month(), 1).addMonths(-1)),
297+
GUIUtil::StartOfDay(QDate(current.year(), current.month(), 1)));
298298
break;
299299
case ThisYear:
300300
transactionProxyModel->setDateRange(
301-
QDateTime(QDate(current.year(), 1, 1)),
301+
GUIUtil::StartOfDay(QDate(current.year(), 1, 1)),
302302
TransactionFilterProxy::MAX_DATE);
303303
break;
304304
case Range:
@@ -583,8 +583,8 @@ void TransactionView::dateRangeChanged()
583583
if(!transactionProxyModel)
584584
return;
585585
transactionProxyModel->setDateRange(
586-
QDateTime(dateFrom->date()),
587-
QDateTime(dateTo->date()).addDays(1));
586+
GUIUtil::StartOfDay(dateFrom->date()),
587+
GUIUtil::StartOfDay(dateTo->date()).addDays(1));
588588
}
589589

590590
void TransactionView::focusTransaction(const QModelIndex &idx)

0 commit comments

Comments
 (0)