Skip to content

Commit

Permalink
qt, refactor: Fix 'QDateTime is deprecated' warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Aug 26, 2020
1 parent 93ab136 commit b02264c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct BlockAndHeaderTipInfo;
QT_BEGIN_NAMESPACE
class QAction;
class QComboBox;
class QDateTime;
class QMenu;
class QProgressBar;
class QProgressDialog;
Expand Down
9 changes: 9 additions & 0 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,4 +920,13 @@ void PopupMenu(QMenu* menu, const QPoint& point, QAction* at_action)
menu->popup(point, at_action);
}

QDateTime StartOfDay(const QDate& date)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
return date.startOfDay();
#else
return QDateTime(date);
#endif
}

} // namespace GUIUtil
11 changes: 10 additions & 1 deletion src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ namespace GUIUtil
/**
* Returns the distance in pixels appropriate for drawing a subsequent character after text.
*
* In Qt 5.12 and before the QFontMetrics::width() is used and it is deprecated since Qt 13.0.
* In Qt 5.12 and before the QFontMetrics::width() is used and it is deprecated since Qt 5.13.
* In Qt 5.11 the QFontMetrics::horizontalAdvance() was introduced.
*/
int TextWidth(const QFontMetrics& fm, const QString& text);
Expand All @@ -303,6 +303,15 @@ namespace GUIUtil
* Call QMenu::popup() only on supported QT_QPA_PLATFORM.
*/
void PopupMenu(QMenu* menu, const QPoint& point, QAction* at_action = nullptr);

/**
* Returns the start-moment of the day in local time.
*
* QDateTime::QDateTime(const QDate& date) is deprecated since Qt 5.15.
* QDate::startOfDay() was introduced in Qt 5.14.
*/
QDateTime StartOfDay(const QDate& date);

} // namespace GUIUtil

#endif // BITCOIN_QT_GUIUTIL_H
1 change: 1 addition & 0 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <QAbstractItemDelegate>
#include <QApplication>
#include <QDateTime>
#include <QPainter>
#include <QStatusTipEvent>

Expand Down
1 change: 0 additions & 1 deletion src/qt/paymentserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <QApplication>
#include <QByteArray>
#include <QDataStream>
#include <QDateTime>
#include <QDebug>
#include <QFile>
#include <QFileOpenEvent>
Expand Down
1 change: 1 addition & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <wallet/wallet.h>
#endif

#include <QDateTime>
#include <QFont>
#include <QKeyEvent>
#include <QMenu>
Expand Down
1 change: 1 addition & 0 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace Ui {
}

QT_BEGIN_NAMESPACE
class QDateTime;
class QMenu;
class QItemSelection;
QT_END_NAMESPACE
Expand Down
16 changes: 8 additions & 8 deletions src/qt/transactionview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,30 +275,30 @@ void TransactionView::chooseDate(int idx)
break;
case Today:
transactionProxyModel->setDateRange(
QDateTime(current),
GUIUtil::StartOfDay(current),
TransactionFilterProxy::MAX_DATE);
break;
case ThisWeek: {
// Find last Monday
QDate startOfWeek = current.addDays(-(current.dayOfWeek()-1));
transactionProxyModel->setDateRange(
QDateTime(startOfWeek),
GUIUtil::StartOfDay(startOfWeek),
TransactionFilterProxy::MAX_DATE);

} break;
case ThisMonth:
transactionProxyModel->setDateRange(
QDateTime(QDate(current.year(), current.month(), 1)),
GUIUtil::StartOfDay(QDate(current.year(), current.month(), 1)),
TransactionFilterProxy::MAX_DATE);
break;
case LastMonth:
transactionProxyModel->setDateRange(
QDateTime(QDate(current.year(), current.month(), 1).addMonths(-1)),
QDateTime(QDate(current.year(), current.month(), 1)));
GUIUtil::StartOfDay(QDate(current.year(), current.month(), 1).addMonths(-1)),
GUIUtil::StartOfDay(QDate(current.year(), current.month(), 1)));
break;
case ThisYear:
transactionProxyModel->setDateRange(
QDateTime(QDate(current.year(), 1, 1)),
GUIUtil::StartOfDay(QDate(current.year(), 1, 1)),
TransactionFilterProxy::MAX_DATE);
break;
case Range:
Expand Down Expand Up @@ -583,8 +583,8 @@ void TransactionView::dateRangeChanged()
if(!transactionProxyModel)
return;
transactionProxyModel->setDateRange(
QDateTime(dateFrom->date()),
QDateTime(dateTo->date()).addDays(1));
GUIUtil::StartOfDay(dateFrom->date()),
GUIUtil::StartOfDay(dateTo->date()).addDays(1));
}

void TransactionView::focusTransaction(const QModelIndex &idx)
Expand Down

0 comments on commit b02264c

Please sign in to comment.