Skip to content

Commit 41bd056

Browse files
authored
qt, refactor: remove build warnings Qt 5.15.x (#1008)
* qt: Fix deprecation warnings when building against Qt 5.15 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 * qt, refactor: Use enum type as switch arguments backport from bitcoin qt, refactor: Use enum type as switch argument in TransactionTableModel qt, refactor: Use enum type as switch argument in PeerTableModel qt, refactor: Use enum type as switch argument in BanTableModel qt, refactor: Use enum type as switch argument in AddressTableModel bitcoin#1d5d832d5c045cbbe3a0f4aa8fc29e52ecadc182 bitcoin#52f122c11f5ac40bc2f7e31cb4da0a79c842f08e bitcoin#a35223f1cdaf6918501faccac1ff94ebfd38c6f6 bitcoin#ab8a747d1ced9f20ca32f9898418be70670da71a * qt, refactor: utilitydialog shutdown window qflag * qt, refactor: BanTableModel replace 0 with Qt::NoItemFlags * qt, refactor: ravenamountfield, StepEnabled * qt, refactor: OptionsModel replace qstring.split() * qt, refactor: Fix 'pixmap is deprecated' warnings backport from bitcoin with adjustments for Raven bitcoin#fa5749c805878304c107bcae0ae5ffa401dc7c4d * qt, refactor: PaymentServer qbytearray deprecation warnings remove check for qt < 5.0, we no longer support 4.x.
1 parent 7b98937 commit 41bd056

23 files changed

+185
-105
lines changed

src/qt/addresstablemodel.cpp

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -196,42 +196,38 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
196196

197197
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
198198

199-
if(role == Qt::DisplayRole || role == Qt::EditRole)
200-
{
201-
switch(index.column())
202-
{
199+
const auto column = static_cast<ColumnIndex>(index.column());
200+
if (role == Qt::DisplayRole || role == Qt::EditRole) {
201+
switch (column) {
203202
case Label:
204-
if(rec->label.isEmpty() && role == Qt::DisplayRole)
205-
{
203+
if (rec->label.isEmpty() && role == Qt::DisplayRole) {
206204
return tr("(no label)");
207-
}
208-
else
209-
{
205+
} else {
210206
return rec->label;
211207
}
212208
case Address:
213209
return rec->address;
214-
}
215-
}
216-
else if (role == Qt::FontRole)
217-
{
218-
QFont font;
219-
if(index.column() == Address)
220-
{
221-
font = GUIUtil::fixedPitchFont();
222-
}
223-
return font;
224-
}
225-
else if (role == TypeRole)
226-
{
210+
} // no default case, so the compiler can warn about missing cases
211+
assert(false);
212+
} else if (role == Qt::FontRole) {
213+
switch (column) {
214+
case Label:
215+
return QFont();
216+
case Address:
217+
return GUIUtil::fixedPitchFont();
218+
} // no default case, so the compiler can warn about missing cases
219+
assert(false);
220+
} else if (role == TypeRole) {
227221
switch(rec->type)
228222
{
229223
case AddressTableEntry::Sending:
230224
return Send;
231225
case AddressTableEntry::Receiving:
232226
return Receive;
233-
default: break;
234-
}
227+
case AddressTableEntry::Hidden:
228+
return {};
229+
} // no default case, so the compiler can warn about missing cases
230+
assert(false);
235231
}
236232
return QVariant();
237233
}
@@ -306,8 +302,7 @@ QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation,
306302

307303
Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
308304
{
309-
if(!index.isValid())
310-
return 0;
305+
if(!index.isValid()) return Qt::NoItemFlags;
311306
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
312307

313308
Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;

src/qt/assetsdialog.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,11 @@ void AssetsDialog::setModel(WalletModel *_model)
178178
}
179179
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSmartFeeLabel()));
180180
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(assetControlUpdateLabels()));
181+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
182+
connect(ui->groupFee, &QButtonGroup::idClicked, this, &AssetsDialog::updateFeeSectionControls);
183+
#else
181184
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls()));
182-
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(assetControlUpdateLabels()));
185+
#endif
183186
connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(assetControlUpdateLabels()));
184187
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee()));
185188
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls()));

src/qt/bantablemodel.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ bool BannedNodeLessThan::operator()(const CCombinedBan& left, const CCombinedBan
2323
if (order == Qt::DescendingOrder)
2424
std::swap(pLeft, pRight);
2525

26-
switch(column)
27-
{
26+
switch (static_cast<BanTableModel::ColumnIndex>(column)) {
2827
case BanTableModel::Address:
2928
return pLeft->subnet.ToString().compare(pRight->subnet.ToString()) < 0;
3029
case BanTableModel::Bantime:
3130
return pLeft->banEntry.nBanUntil < pRight->banEntry.nBanUntil;
32-
}
33-
34-
return false;
31+
} // no default case, so the compiler can warn about missing cases
32+
assert(false);
3533
}
3634

3735
// private implementation
@@ -120,16 +118,17 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const
120118

121119
CCombinedBan *rec = static_cast<CCombinedBan*>(index.internalPointer());
122120

121+
const auto column = static_cast<ColumnIndex>(index.column());
123122
if (role == Qt::DisplayRole) {
124-
switch(index.column())
125-
{
123+
switch (column) {
126124
case Address:
127125
return QString::fromStdString(rec->subnet.ToString());
128126
case Bantime:
129127
QDateTime date = QDateTime::fromMSecsSinceEpoch(0);
130128
date = date.addSecs(rec->banEntry.nBanUntil);
131-
return date.toString(Qt::SystemLocaleLongDate);
132-
}
129+
return QLocale::system().toString(date, QLocale::LongFormat);
130+
} // no default case, so the compiler can warn about missing cases
131+
assert(false);
133132
}
134133

135134
return QVariant();
@@ -149,8 +148,7 @@ QVariant BanTableModel::headerData(int section, Qt::Orientation orientation, int
149148

150149
Qt::ItemFlags BanTableModel::flags(const QModelIndex &index) const
151150
{
152-
if(!index.isValid())
153-
return 0;
151+
if(!index.isValid()) return Qt::NoItemFlags;
154152

155153
Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
156154
return retval;

src/qt/createassetdialog.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,14 @@ void CreateAssetDialog::setModel(WalletModel *_model)
180180
}
181181
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSmartFeeLabel()));
182182
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(coinControlUpdateLabels()));
183+
184+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
185+
connect(ui->groupFee, &QButtonGroup::idClicked, this, &CreateAssetDialog::updateFeeSectionControls);
186+
connect(ui->groupFee, &QButtonGroup::idClicked, this, &CreateAssetDialog::coinControlUpdateLabels);
187+
#else
183188
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls()));
184189
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels()));
190+
#endif
185191
connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(coinControlUpdateLabels()));
186192
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee()));
187193
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls()));

src/qt/guiutil.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,4 +1156,36 @@ void concatenate(QPainter* painter, QString& catString, int static_width, int le
11561156
catString.append("...");
11571157
}
11581158

1159+
QDateTime StartOfDay(const QDate& date)
1160+
{
1161+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
1162+
return date.startOfDay();
1163+
#else
1164+
return QDateTime(date);
1165+
#endif
1166+
}
1167+
1168+
bool HasPixmap(const QLabel* label)
1169+
{
1170+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
1171+
return !label->pixmap(Qt::ReturnByValue).isNull();
1172+
#else
1173+
return label->pixmap() != nullptr;
1174+
#endif
1175+
}
1176+
1177+
QImage GetImage(const QLabel* label)
1178+
{
1179+
if (!HasPixmap(label)) {
1180+
return QImage();
1181+
}
1182+
1183+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
1184+
return label->pixmap(Qt::ReturnByValue).toImage();
1185+
#else
1186+
return label->pixmap()->toImage();
1187+
#endif
1188+
}
1189+
1190+
11591191
} // namespace GUIUtil

src/qt/guiutil.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,43 @@ namespace GUIUtil
270270
typedef ClickableProgressBar ProgressBar;
271271
#endif
272272

273+
/**
274+
* Returns the start-moment of the day in local time.
275+
*
276+
* QDateTime::QDateTime(const QDate& date) is deprecated since Qt 5.15.
277+
* QDate::startOfDay() was introduced in Qt 5.14.
278+
*/
279+
QDateTime StartOfDay(const QDate& date);
280+
281+
282+
/**
283+
* Splits the string into substrings wherever separator occurs, and returns
284+
* the list of those strings. Empty strings do not appear in the result.
285+
*
286+
* QString::split() signature differs in different Qt versions:
287+
* - QString::SplitBehavior is deprecated since Qt 5.15
288+
* - Qt::SplitBehavior was introduced in Qt 5.14
289+
* If {QString|Qt}::SkipEmptyParts behavior is required, use this
290+
* function instead of QString::split().
291+
*/
292+
template <typename SeparatorType>
293+
QStringList SplitSkipEmptyParts(const QString& string, const SeparatorType& separator)
294+
{
295+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
296+
return string.split(separator, Qt::SkipEmptyParts);
297+
#else
298+
return string.split(separator, QString::SkipEmptyParts);
299+
#endif
300+
}
301+
302+
/**
303+
* Returns true if pixmap has been set.
304+
*
305+
* QPixmap* QLabel::pixmap() is deprecated since Qt 5.15.
306+
*/
307+
bool HasPixmap(const QLabel* label);
308+
QImage GetImage(const QLabel* label);
309+
273310
} // namespace GUIUtil
274311

275312
#endif // RAVEN_QT_GUIUTIL_H

src/qt/optionsmodel.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,12 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
246246
return settings.value("fUseProxy", false);
247247
case ProxyIP: {
248248
// contains IP at index 0 and port at index 1
249-
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
249+
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":");
250250
return strlIpPort.at(0);
251251
}
252252
case ProxyPort: {
253253
// contains IP at index 0 and port at index 1
254-
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
254+
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":");
255255
return strlIpPort.at(1);
256256
}
257257

@@ -260,12 +260,12 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
260260
return settings.value("fUseSeparateProxyTor", false);
261261
case ProxyIPTor: {
262262
// contains IP at index 0 and port at index 1
263-
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
263+
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrSeparateProxyTor").toString(), ":");
264264
return strlIpPort.at(0);
265265
}
266266
case ProxyPortTor: {
267267
// contains IP at index 0 and port at index 1
268-
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
268+
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrSeparateProxyTor").toString(), ":");
269269
return strlIpPort.at(1);
270270
}
271271

@@ -341,7 +341,8 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
341341
break;
342342
case ProxyIP: {
343343
// contains current IP at index 0 and current port at index 1
344-
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
344+
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":");
345+
345346
// if that key doesn't exist or has a changed IP
346347
if (!settings.contains("addrProxy") || strlIpPort.at(0) != value.toString()) {
347348
// construct new value from new IP and current port
@@ -353,7 +354,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
353354
break;
354355
case ProxyPort: {
355356
// contains current IP at index 0 and current port at index 1
356-
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
357+
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":");
357358
// if that key doesn't exist or has a changed port
358359
if (!settings.contains("addrProxy") || strlIpPort.at(1) != value.toString()) {
359360
// construct new value from current IP and new port
@@ -373,7 +374,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
373374
break;
374375
case ProxyIPTor: {
375376
// contains current IP at index 0 and current port at index 1
376-
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
377+
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrSeparateProxyTor").toString(), ":");
377378
// if that key doesn't exist or has a changed IP
378379
if (!settings.contains("addrSeparateProxyTor") || strlIpPort.at(0) != value.toString()) {
379380
// construct new value from new IP and current port
@@ -385,7 +386,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
385386
break;
386387
case ProxyPortTor: {
387388
// contains current IP at index 0 and current port at index 1
388-
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
389+
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrSeparateProxyTor").toString(), ":");
389390
// if that key doesn't exist or has a changed port
390391
if (!settings.contains("addrSeparateProxyTor") || strlIpPort.at(1) != value.toString()) {
391392
// construct new value from current IP and new port

src/qt/overviewpage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "assetrecord.h"
2121

2222
#include <QAbstractItemDelegate>
23+
#include <QDateTime>
2324
#include <QPainter>
2425
#include <QDesktopServices>
2526
#include <QMouseEvent>

src/qt/paymentserver.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <QApplication>
2424
#include <QByteArray>
2525
#include <QDataStream>
26-
#include <QDateTime>
2726
#include <QDebug>
2827
#include <QFile>
2928
#include <QFileOpenEvent>
@@ -409,15 +408,11 @@ void PaymentServer::handleURIOrFile(const QString& s)
409408

410409
if (s.startsWith(RAVEN_IPC_PREFIX, Qt::CaseInsensitive)) // raven: URI
411410
{
412-
#if QT_VERSION < 0x050000
413-
QUrl uri(s);
414-
#else
415411
QUrlQuery uri((QUrl(s)));
416-
#endif
417412
if (uri.hasQueryItem("r")) // payment request URI
418413
{
419414
QByteArray temp;
420-
temp.append(uri.queryItemValue("r"));
415+
temp.append(uri.queryItemValue("r").toUtf8());
421416
QString decoded = QUrl::fromPercentEncoding(temp);
422417
QUrl fetchUrl(decoded, QUrl::StrictMode);
423418

0 commit comments

Comments
 (0)