Skip to content

Commit

Permalink
Merge pull request #2275 from barton2526/qt_deprecated
Browse files Browse the repository at this point in the history
refactor: Replace deprecated Qt::SystemLocale{Short,Long}Date, Fix 'QDateTime is deprecated' warnings
  • Loading branch information
jamescowens authored Aug 15, 2021
2 parents 3349bd4 + 355e393 commit 0115164
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/qt/bantablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <QDebug>
#include <QList>
#include <QDateTime>
#include <QLocale>

bool BannedNodeLessThan::operator()(const CCombinedBan& left, const CCombinedBan& right) const
{
Expand Down Expand Up @@ -125,7 +126,7 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const
case Bantime:
QDateTime date = QDateTime::fromMSecsSinceEpoch(0);
date = date.addSecs(rec->banEntry.nBanUntil);
return date.toString(Qt::SystemLocaleLongDate);
return QLocale::system().toString(date, QLocale::LongFormat);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,4 +719,13 @@ void HelpMessageBox::showOrPrint()
#endif
}

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

} // namespace GUIUtil
8 changes: 8 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ namespace GUIUtil
QString options;
};

/**
* 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 // GUIUTIL_H
16 changes: 8 additions & 8 deletions src/qt/transactionview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,30 +215,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, 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 @@ -435,8 +435,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 0115164

Please sign in to comment.