Skip to content

Commit

Permalink
qt: Fix deprecation warnings when building against Qt 5.15
Browse files Browse the repository at this point in the history
    bitcoin-core/gui#46
    + some adjustments for Raven

    qt, refactor: Fix 'QDateTime is Deprecated' warnings.
    qt, refactor: Fix 'QFlags is deprecated' warnings
    qt, refactor: Fix 'split is deprecated' warnings
    qt, refactor: Fix 'buttonClicked is deprecated' warnings
  • Loading branch information
fdoving committed May 15, 2021
1 parent 038da6b commit 1541dc3
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/qt/assetsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,11 @@ void AssetsDialog::setModel(WalletModel *_model)
}
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSmartFeeLabel()));
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(assetControlUpdateLabels()));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
connect(ui->groupFee, &QButtonGroup::idClicked, this, &AssetsDialog::updateFeeSectionControls);
#else
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls()));
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(assetControlUpdateLabels()));
#endif
connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(assetControlUpdateLabels()));
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee()));
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls()));
Expand Down
6 changes: 6 additions & 0 deletions src/qt/createassetdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,14 @@ void CreateAssetDialog::setModel(WalletModel *_model)
}
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSmartFeeLabel()));
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(coinControlUpdateLabels()));

#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
connect(ui->groupFee, &QButtonGroup::idClicked, this, &CreateAssetDialog::updateFeeSectionControls);
connect(ui->groupFee, &QButtonGroup::idClicked, this, &CreateAssetDialog::coinControlUpdateLabels);
#else
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls()));
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels()));
#endif
connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(coinControlUpdateLabels()));
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee()));
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls()));
Expand Down
10 changes: 10 additions & 0 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,4 +1156,14 @@ void concatenate(QPainter* painter, QString& catString, int static_width, int le
catString.append("...");
}

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


} // namespace GUIUtil
29 changes: 29 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,35 @@ namespace GUIUtil
typedef ClickableProgressBar ProgressBar;
#endif

/**
* 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);


/**
* Splits the string into substrings wherever separator occurs, and returns
* the list of those strings. Empty strings do not appear in the result.
*
* QString::split() signature differs in different Qt versions:
* - QString::SplitBehavior is deprecated since Qt 5.15
* - Qt::SplitBehavior was introduced in Qt 5.14
* If {QString|Qt}::SkipEmptyParts behavior is required, use this
* function instead of QString::split().
*/
template <typename SeparatorType>
QStringList SplitSkipEmptyParts(const QString& string, const SeparatorType& separator)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
return string.split(separator, Qt::SkipEmptyParts);
#else
return string.split(separator, QString::SkipEmptyParts);
#endif
}

} // namespace GUIUtil

#endif // RAVEN_QT_GUIUTIL_H
8 changes: 4 additions & 4 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
return settings.value("fUseProxy", false);
case ProxyIP: {
// contains IP at index 0 and port at index 1
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":");
return strlIpPort.at(0);
}
case ProxyPort: {
// contains IP at index 0 and port at index 1
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":");
return strlIpPort.at(1);
}

Expand All @@ -260,12 +260,12 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
return settings.value("fUseSeparateProxyTor", false);
case ProxyIPTor: {
// contains IP at index 0 and port at index 1
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrSeparateProxyTor").toString(), ":");
return strlIpPort.at(0);
}
case ProxyPortTor: {
// contains IP at index 0 and port at index 1
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrSeparateProxyTor").toString(), ":");
return strlIpPort.at(1);
}

Expand Down
1 change: 1 addition & 0 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "assetrecord.h"

#include <QAbstractItemDelegate>
#include <QDateTime>
#include <QPainter>
#include <QDesktopServices>
#include <QMouseEvent>
Expand Down
1 change: 0 additions & 1 deletion src/qt/paymentserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <QApplication>
#include <QByteArray>
#include <QDataStream>
#include <QDateTime>
#include <QDebug>
#include <QFile>
#include <QFileOpenEvent>
Expand Down
2 changes: 1 addition & 1 deletion src/qt/raven.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void RavenApplication::createWindow(const NetworkStyle *networkStyle)

void RavenApplication::createSplashScreen(const NetworkStyle *networkStyle)
{
SplashScreen *splash = new SplashScreen(0, networkStyle);
SplashScreen *splash = new SplashScreen(networkStyle);
// We don't hold a direct pointer to the splash screen after creation, but the splash
// screen will take care of deleting itself when slotFinish happens.
splash->show();
Expand Down
1 change: 1 addition & 0 deletions src/qt/ravengui.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QPoint>
#include <QSystemTrayIcon>
#include <QComboBox>
#include <QDateTime>

class ClientModel;
class NetworkStyle;
Expand Down
6 changes: 6 additions & 0 deletions src/qt/reissueassetdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,14 @@ void ReissueAssetDialog::setModel(WalletModel *_model)
}
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSmartFeeLabel()));
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(coinControlUpdateLabels()));

#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
connect(ui->groupFee, &QButtonGroup::idClicked, this, &ReissueAssetDialog::updateFeeSectionControls);
connect(ui->groupFee, &QButtonGroup::idClicked, this, &ReissueAssetDialog::coinControlUpdateLabels);
#else
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls()));
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels()));
#endif
connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(coinControlUpdateLabels()));
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee()));
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls()));
Expand Down
1 change: 1 addition & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <wallet/wallet.h>
#endif

#include <QDateTime>
#include <QDir>
#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 @@ -24,6 +24,7 @@ namespace Ui {
}

QT_BEGIN_NAMESPACE
class QDateTime;
class QMenu;
class QItemSelection;
QT_END_NAMESPACE
Expand Down
6 changes: 6 additions & 0 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,14 @@ void SendCoinsDialog::setModel(WalletModel *_model)
}
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSmartFeeLabel()));
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(coinControlUpdateLabels()));

#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
connect(ui->groupFee, &QButtonGroup::idClicked, this, &SendCoinsDialog::updateFeeSectionControls);
connect(ui->groupFee, &QButtonGroup::idClicked, this, &SendCoinsDialog::coinControlUpdateLabels);
#else
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls()));
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels()));
#endif
connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(coinControlUpdateLabels()));
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee()));
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls()));
Expand Down
4 changes: 2 additions & 2 deletions src/qt/splashscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#include <boost/bind/bind.hpp>
using namespace boost::placeholders;

SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle) :
QWidget(0, f), curAlignment(0)
SplashScreen::SplashScreen(const NetworkStyle* networkStyle)
: QWidget(), curAlignment(0)
{
// set reference point, paddings
int paddingRight = 50;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/splashscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SplashScreen : public QWidget
Q_OBJECT

public:
explicit SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle);
explicit SplashScreen(const NetworkStyle *networkStyle);
~SplashScreen();

protected:
Expand Down
18 changes: 9 additions & 9 deletions src/qt/transactionview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void TransactionView::setModel(WalletModel *_model)
if (_model->getOptionsModel())
{
// Add third party transaction URLs to context menu
QStringList listUrls = _model->getOptionsModel()->getThirdPartyTxUrls().split("|", QString::SkipEmptyParts);
QStringList listUrls = GUIUtil::SplitSkipEmptyParts(_model->getOptionsModel()->getThirdPartyTxUrls(), "|");
for (int i = 0; i < listUrls.size(); ++i)
{
QString host = QUrl(listUrls[i].trimmed(), QUrl::StrictMode).host();
Expand Down Expand Up @@ -313,30 +313,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 @@ -653,8 +653,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 1541dc3

Please sign in to comment.