Skip to content

Commit

Permalink
Fixed Qt compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
psolstice committed Jul 16, 2024
1 parent 9391c46 commit 88b0aff
Show file tree
Hide file tree
Showing 22 changed files with 144 additions and 64 deletions.
14 changes: 7 additions & 7 deletions src/qt/addresstablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ class AddressTablePriv
// qLowerBound() and qUpperBound() require our cachedAddressTable list to be sorted in asc order
// Even though the map is already sorted this re-sorting step is needed because the originating map
// is sorted by binary address, not by base58() address.
qSort(cachedAddressTable.begin(), cachedAddressTable.end(), AddressTableEntryLessThan());
std::sort(cachedAddressTable.begin(), cachedAddressTable.end(), AddressTableEntryLessThan());
}

void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
{
// Find address / label in model
QList<AddressTableEntry>::iterator lower = qLowerBound(
QList<AddressTableEntry>::iterator lower = std::lower_bound(
cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
QList<AddressTableEntry>::iterator upper = qUpperBound(
QList<AddressTableEntry>::iterator upper = std::upper_bound(
cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
int lowerIndex = (lower - cachedAddressTable.begin());
int upperIndex = (upper - cachedAddressTable.begin());
Expand Down Expand Up @@ -205,9 +205,9 @@ class AddressTablePriv
void updateEntry(const QString &pubCoin, const QString &isUsed, int status)
{
// Find address / label in model
QList<AddressTableEntry>::iterator lower = qLowerBound(
QList<AddressTableEntry>::iterator lower = std::lower_bound(
cachedAddressTable.begin(), cachedAddressTable.end(), pubCoin, AddressTableEntryLessThan());
QList<AddressTableEntry>::iterator upper = qUpperBound(
QList<AddressTableEntry>::iterator upper = std::upper_bound(
cachedAddressTable.begin(), cachedAddressTable.end(), pubCoin, AddressTableEntryLessThan());
int lowerIndex = (lower - cachedAddressTable.begin());
bool inModel = (lower != upper);
Expand Down Expand Up @@ -463,7 +463,7 @@ QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation,
Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
{
if(!index.isValid())
return 0;
return Qt::ItemFlags();
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());

Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
Expand Down Expand Up @@ -822,7 +822,7 @@ bool PcodeAddressTableModel::removeRows(int row, int count, const QModelIndex &)
Qt::ItemFlags PcodeAddressTableModel::flags(const QModelIndex &index) const
{
if(!index.isValid())
return 0;
return Qt::ItemFlags();
Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
if(index.column() == int(ColumnIndex::Label))
{
Expand Down
6 changes: 3 additions & 3 deletions src/qt/bantablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class BanTablePriv

if (sortColumn >= 0)
// sort cachedBanlist (use stable sort to prevent rows jumping around unnecessarily)
qStableSort(cachedBanlist.begin(), cachedBanlist.end(), BannedNodeLessThan(sortColumn, sortOrder));
std::stable_sort(cachedBanlist.begin(), cachedBanlist.end(), BannedNodeLessThan(sortColumn, sortOrder));
}

int size() const
Expand Down Expand Up @@ -127,7 +127,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 All @@ -149,7 +149,7 @@ QVariant BanTableModel::headerData(int section, Qt::Orientation orientation, int
Qt::ItemFlags BanTableModel::flags(const QModelIndex &index) const
{
if(!index.isValid())
return 0;
return Qt::ItemFlags();

Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
return retval;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)

void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
{
SplashScreen *splash = new SplashScreen(QPixmap(), 0);
SplashScreen *splash = new SplashScreen(QPixmap(), Qt::WindowFlags());
// 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
5 changes: 3 additions & 2 deletions src/qt/bitcoinamountfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "bitcoinunits.h"
#include "guiconstants.h"
#include "qvaluecombobox.h"
#include "guiutil.h"

#include <QApplication>
#include <QAbstractSpinBox>
Expand Down Expand Up @@ -102,7 +103,7 @@ class AmountSpinBox: public QAbstractSpinBox

const QFontMetrics fm(fontMetrics());
int h = lineEdit()->minimumSizeHint().height();
int w = fm.width(BitcoinUnits::format(BitcoinUnits::BTC, BitcoinUnits::maxMoney(), false, BitcoinUnits::separatorAlways));
int w = GUIUtil::TextWidth(fm, BitcoinUnits::format(BitcoinUnits::BTC, BitcoinUnits::maxMoney(), false, BitcoinUnits::separatorAlways));
w += 2; // cursor blinking space

QStyleOptionSpinBox opt;
Expand Down Expand Up @@ -174,7 +175,7 @@ class AmountSpinBox: public QAbstractSpinBox
if (text().isEmpty()) // Allow step-up with empty field
return StepUpEnabled;

StepEnabled rv = 0;
StepEnabled rv = StepEnabled();
bool valid = false;
CAmount val = value(&valid);
if(valid)
Expand Down
2 changes: 1 addition & 1 deletion src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *pl
const QFontMetrics fm(font());
for (const BitcoinUnits::Unit unit : units)
{
max_width = qMax(max_width, fm.width(BitcoinUnits::name(unit)));
max_width = qMax(max_width, GUIUtil::TextWidth(fm, BitcoinUnits::name(unit)));
}
setMinimumSize(max_width, 0);
setAlignment(Qt::AlignRight | Qt::AlignVCenter);
Expand Down
38 changes: 37 additions & 1 deletion src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static CCriticalSection cs_css;

QString dateTimeStr(const QDateTime &date)
{
return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + date.toString("hh:mm");
return QLocale::system().toString(date.date(), QLocale::ShortFormat) + QString(" ") + date.toString("hh:mm");
}

QString dateTimeStr(qint64 nTime)
Expand Down Expand Up @@ -894,4 +894,40 @@ void loadTheme()
qApp->setStyleSheet(*stylesheet);
}

int TextWidth(const QFontMetrics& fm, const QString& text)
{
return fm.horizontalAdvance(text);
}

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

bool HasPixmap(const QLabel* label)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
return !label->pixmap(Qt::ReturnByValue).isNull();
#else
return label->pixmap() != nullptr;
#endif
}

QImage GetImage(const QLabel* label)
{
if (!HasPixmap(label)) {
return QImage();
}

#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
return label->pixmap(Qt::ReturnByValue).toImage();
#else
return label->pixmap()->toImage();
#endif
}

} // namespace GUIUtil
44 changes: 44 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,50 @@ namespace GUIUtil
void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override;
};

/**
* 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 5.13.
* In Qt 5.11 the QFontMetrics::horizontalAdvance() was introduced.
*/
int TextWidth(const QFontMetrics& fm, const QString& text);

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

/**
* Returns true if pixmap has been set.
*
* QPixmap* QLabel::pixmap() is deprecated since Qt 5.15.
*/
bool HasPixmap(const QLabel* label);
QImage GetImage(const QLabel* label);

/**
* 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 // BITCOIN_QT_GUIUTIL_H
12 changes: 6 additions & 6 deletions src/qt/lelantusdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ void LelantusDialog::setWalletModel(WalletModel *_walletModel)
connect(ui->sliderSmartFee, &QSlider::valueChanged, this, &LelantusDialog::updateSmartFeeLabel);
connect(ui->sliderSmartFee, &QSlider::valueChanged, this, &LelantusDialog::updateGlobalFeeVariables);
connect(ui->sliderSmartFee, &QSlider::valueChanged, this, &LelantusDialog::coinControlUpdateLabels);
connect(ui->groupFee, qOverload<int>(&QButtonGroup::buttonClicked), this, &LelantusDialog::updateFeeSectionControls);
connect(ui->groupFee, qOverload<int>(&QButtonGroup::buttonClicked), this, &LelantusDialog::updateGlobalFeeVariables);
connect(ui->groupFee, qOverload<int>(&QButtonGroup::buttonClicked), this, &LelantusDialog::coinControlUpdateLabels);
connect(ui->groupCustomFee, qOverload<int>(&QButtonGroup::buttonClicked), this, &LelantusDialog::updateGlobalFeeVariables);
connect(ui->groupCustomFee, qOverload<int>(&QButtonGroup::buttonClicked), this, &LelantusDialog::coinControlUpdateLabels);
connect(ui->groupFee, qOverload<int>(&QButtonGroup::idClicked), this, &LelantusDialog::updateFeeSectionControls);
connect(ui->groupFee, qOverload<int>(&QButtonGroup::idClicked), this, &LelantusDialog::updateGlobalFeeVariables);
connect(ui->groupFee, qOverload<int>(&QButtonGroup::idClicked), this, &LelantusDialog::coinControlUpdateLabels);
connect(ui->groupCustomFee, qOverload<int>(&QButtonGroup::idClicked), this, &LelantusDialog::updateGlobalFeeVariables);
connect(ui->groupCustomFee, qOverload<int>(&QButtonGroup::idClicked), this, &LelantusDialog::coinControlUpdateLabels);
connect(ui->customFee, &BitcoinAmountField::valueChanged, this, &LelantusDialog::updateGlobalFeeVariables);
connect(ui->customFee, &BitcoinAmountField::valueChanged, this, &LelantusDialog::coinControlUpdateLabels);
connect(ui->checkBoxMinimumFee, &QCheckBox::stateChanged, this, &LelantusDialog::setMinimumFee);
Expand Down Expand Up @@ -563,7 +563,7 @@ void LelantusDialog::updateSmartFeeLabel()
int lightness = ui->fallbackFeeWarningLabel->palette().color(QPalette::WindowText).lightness();
QColor warning_colour(255 - (lightness / 5), 176 - (lightness / 3), 48 - (lightness / 14));
ui->fallbackFeeWarningLabel->setStyleSheet("QLabel { color: " + warning_colour.name() + "; }");
ui->fallbackFeeWarningLabel->setIndent(QFontMetrics(ui->fallbackFeeWarningLabel->font()).width("x"));
ui->fallbackFeeWarningLabel->setIndent(GUIUtil::TextWidth(QFontMetrics(ui->fallbackFeeWarningLabel->font()), "x"));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/qt/notifymnemonic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ NotifyMnemonic::~NotifyMnemonic()

void NotifyMnemonic::cancelEvent()
{
if( QMessageBox::question( this, trUtf8( "Warning" ), trUtf8( "Are you sure you wish to proceed without confirming whether you have written down your seed words correctly?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) {
if( QMessageBox::question( this, tr( "Warning" ), tr( "Are you sure you wish to proceed without confirming whether you have written down your seed words correctly?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) {
// allow cancel
reject();
}
Expand Down
16 changes: 8 additions & 8 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,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 = settings.value("addrProxy").toString().split(":", Qt::SkipEmptyParts);
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 = settings.value("addrProxy").toString().split(":", Qt::SkipEmptyParts);
return strlIpPort.at(1);
}

Expand All @@ -253,12 +253,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 = settings.value("addrSeparateProxyTor").toString().split(":", Qt::SkipEmptyParts);
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 = settings.value("addrSeparateProxyTor").toString().split(":", Qt::SkipEmptyParts);
return strlIpPort.at(1);
}

Expand Down Expand Up @@ -333,7 +333,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
break;
case ProxyIP: {
// contains current IP at index 0 and current port at index 1
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", Qt::SkipEmptyParts);
// if that key doesn't exist or has a changed IP
if (!settings.contains("addrProxy") || strlIpPort.at(0) != value.toString()) {
// construct new value from new IP and current port
Expand All @@ -345,7 +345,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
break;
case ProxyPort: {
// contains current IP at index 0 and current port at index 1
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", Qt::SkipEmptyParts);
// if that key doesn't exist or has a changed port
if (!settings.contains("addrProxy") || strlIpPort.at(1) != value.toString()) {
// construct new value from current IP and new port
Expand All @@ -365,7 +365,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
break;
case ProxyIPTor: {
// contains current IP at index 0 and current port at index 1
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", Qt::SkipEmptyParts);
// if that key doesn't exist or has a changed IP
if (!settings.contains("addrSeparateProxyTor") || strlIpPort.at(0) != value.toString()) {
// construct new value from new IP and current port
Expand All @@ -377,7 +377,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
break;
case ProxyPortTor: {
// contains current IP at index 0 and current port at index 1
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", Qt::SkipEmptyParts);
// if that key doesn't exist or has a changed port
if (!settings.contains("addrSeparateProxyTor") || strlIpPort.at(1) != value.toString()) {
// construct new value from current IP and new port
Expand Down
2 changes: 1 addition & 1 deletion src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ MigrateLelantusToSparkDialog::MigrateLelantusToSparkDialog(WalletModel *_model):
layout()->addWidget(wbody);
setContentsMargins(0, 0, 0, 0);
setStyleSheet("margin-right:-30px;");
setStandardButtons(0);
setStandardButtons(StandardButtons());

connect(ignore, &QPushButton::clicked, this, &MigrateLelantusToSparkDialog::onIgnoreClicked);
connect(migrate, &QPushButton::clicked, this, &MigrateLelantusToSparkDialog::onMigrateClicked);
Expand Down
4 changes: 2 additions & 2 deletions src/qt/pcodemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ QModelIndex PcodeModel::index(int row, int column, const QModelIndex &parent) co
Qt::ItemFlags PcodeModel::flags(const QModelIndex & index) const
{
if(!index.isValid())
return 0;
return Qt::ItemFlags();
Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
if(index.column() == int(ColumnIndex::Label))
{
Expand Down Expand Up @@ -245,7 +245,7 @@ void PcodeModel::sort(int column, Qt::SortOrder order)
return std::get<2>(cmp1) < std::get<2>(cmp2);
}
};
qSort(items.begin(), items.end(), sortPred);
std::sort(items.begin(), items.end(), sortPred);
Q_EMIT dataChanged(index(0, 0, QModelIndex()), index(items.size() - 1, int(ColumnIndex::NumberOfColumns) - 1, QModelIndex()));
}

Expand Down
4 changes: 2 additions & 2 deletions src/qt/peertablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class PeerTablePriv

if (sortColumn >= 0)
// sort cacheNodeStats (use stable sort to prevent rows jumping around unnecessarily)
qStableSort(cachedNodeStats.begin(), cachedNodeStats.end(), NodeLessThan(sortColumn, sortOrder));
std::stable_sort(cachedNodeStats.begin(), cachedNodeStats.end(), NodeLessThan(sortColumn, sortOrder));

// build index map
mapNodeRows.clear();
Expand Down Expand Up @@ -197,7 +197,7 @@ QVariant PeerTableModel::headerData(int section, Qt::Orientation orientation, in
Qt::ItemFlags PeerTableModel::flags(const QModelIndex &index) const
{
if(!index.isValid())
return 0;
return Qt::ItemFlags();

Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
return retval;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/receivecoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void ReceiveCoinsDialog::copyColumnToClipboard(int column)
if (!firstIndex.isValid()) {
return;
}
GUIUtil::setClipboard(model->getRecentRequestsTableModel()->data(firstIndex.child(firstIndex.row(), column), Qt::EditRole).toString());
GUIUtil::setClipboard(model->getRecentRequestsTableModel()->index(firstIndex.row(), column).data(Qt::EditRole).toString());
}

// context menu
Expand Down
Loading

0 comments on commit 88b0aff

Please sign in to comment.