Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt, refactor: fix deprecation warnings, remove debug info during build #72

Merged
merged 15 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ qt_komodo_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
endif

if ENABLE_WALLET
$(info $(red)[ Decker ]$(reset) ENABLE_WALLET)
$(info $$EXTRA_LIBRARIES is [${EXTRA_LIBRARIES}])
# $(info $(red)[ Decker ]$(reset) ENABLE_WALLET)
# $(info $$EXTRA_LIBRARIES is [${EXTRA_LIBRARIES}])
# LIBBITCOIN_CLI should be first?
qt_komodo_qt_LDADD += libbitcoin_wallet.a
endif
Expand Down Expand Up @@ -502,15 +502,15 @@ if TARGET_DARWIN
qt_komodo_qt_LDADD += -lc++
endif

$(info $(red)[ Decker ]$(reset) Check the komodo-qt dependencies ...)
#$(info $$qt_komodo_qt_CXXFLAGS is [${qt_komodo_qt_CXXFLAGS}])
$(info $$qt_komodo_qt_CPPFLAGS is [${qt_komodo_qt_CPPFLAGS}])
$(info $$qt_komodo_qt_LDADD is [${qt_komodo_qt_LDADD}])
$(info $$qt_komodo_qt_LDFLAGS is [${qt_komodo_qt_LDFLAGS}])
$(info $(red)[ Decker ]$(reset) Check the komodod dependencies ...)
$(info $$komodod_CPPFLAGS is [${komodod_CPPFLAGS}])
$(info $$komodod_LDADD is [${komodod_LDADD}])
$(info $$komodod_LDFLAGS is [${komodod_LDFLAGS}])
# $(info $(red)[ Decker ]$(reset) Check the komodo-qt dependencies ...)
# #$(info $$qt_komodo_qt_CXXFLAGS is [${qt_komodo_qt_CXXFLAGS}])
# $(info $$qt_komodo_qt_CPPFLAGS is [${qt_komodo_qt_CPPFLAGS}])
# $(info $$qt_komodo_qt_LDADD is [${qt_komodo_qt_LDADD}])
# $(info $$qt_komodo_qt_LDFLAGS is [${qt_komodo_qt_LDFLAGS}])
# $(info $(red)[ Decker ]$(reset) Check the komodod dependencies ...)
# $(info $$komodod_CPPFLAGS is [${komodod_CPPFLAGS}])
# $(info $$komodod_LDADD is [${komodod_LDADD}])
# $(info $$komodod_LDFLAGS is [${komodod_LDFLAGS}])

# $(info $(red)$$QT_LIBS$(reset) is [${QT_LIBS}])
# $(info $(red)$$QT_DBUS_LIBS$(reset) is [${QT_DBUS_LIBS}])
Expand Down
4 changes: 4 additions & 0 deletions src/cryptoconditions/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ AC_CONFIG_MACRO_DIRS([m4])
AC_CONFIG_SUBDIRS([src/include/secp256k1])

AM_INIT_AUTOMAKE([foreign subdir-objects])

dnl make the compilation flags quiet unless V=1 is used
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

LT_INIT

# Checks for programs.
Expand Down
4 changes: 2 additions & 2 deletions src/cryptoconditions/src/asn/asn_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "cryptoconditions-config.h"
#endif

#ifndef _BSD_SOURCE
#define _BSD_SOURCE /* for snprintf() on some linux systems */
#ifndef _DEFAULT_SOURCE
#define _DEFAULT_SOURCE /* for snprintf() on some Linux systems */
#endif

#include <stdio.h> /* For snprintf(3) */
Expand Down
11 changes: 5 additions & 6 deletions src/qt/addresstablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ class AddressTablePriv
QString::fromStdString(EncodeDestination(address))));
}
}
// qLowerBound() and qUpperBound() require our cachedAddressTable list to be sorted in asc order
// std::lower_bound() and std::upper_bound() 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 @@ -366,8 +366,7 @@ QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation,

Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
{
if(!index.isValid())
return 0;
if (!index.isValid()) return Qt::NoItemFlags;
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());

Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
Expand Down
5 changes: 2 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 @@ -148,8 +148,7 @@ QVariant BanTableModel::headerData(int section, Qt::Orientation orientation, int

Qt::ItemFlags BanTableModel::flags(const QModelIndex &index) const
{
if(!index.isValid())
return 0;
if(!index.isValid()) return Qt::NoItemFlags;

Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
return retval;
Expand Down
40 changes: 40 additions & 0 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,4 +1053,44 @@ void LogQtInfo()
}
}

int TextWidth(const QFontMetrics& fm, const QString& text)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
return fm.horizontalAdvance(text);
#else
return fm.width(text);
#endif
}

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
45 changes: 45 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,51 @@ namespace GUIUtil
*/
void LogQtInfo();

/**
* 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.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 // KOMODO_QT_GUIUTIL_H
5 changes: 3 additions & 2 deletions src/qt/komodoamountfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "komodounits.h"
#include "guiconstants.h"
#include "guiutil.h"
#include "qvaluecombobox.h"

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

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

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

StepEnabled rv = 0;
StepEnabled rv = StepNone;
bool valid = false;
CAmount val = value(&valid);
if(valid)
Expand Down
2 changes: 1 addition & 1 deletion src/qt/komodoapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ void KomodoApplication::createWindow(const NetworkStyle *networkStyle)

void KomodoApplication::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
5 changes: 3 additions & 2 deletions src/qt/komodooceangui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <QMessageBox>
#include <QMimeData>
#include <QProgressDialog>
#include <QScreen>
#include <QSettings>
#include <QShortcut>
#include <QStackedWidget>
Expand Down Expand Up @@ -129,7 +130,7 @@ KomodoOceanGUI::KomodoOceanGUI(const PlatformStyle *_platformStyle, const Networ
QSettings settings;
if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
// Restore failed (perhaps missing setting), center the window
move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center());
move(QGuiApplication::primaryScreen()->availableGeometry().center() - frameGeometry().center());
}

QString windowTitle = "[" + QString(chainName.ToString().c_str()) + "] ";
Expand Down Expand Up @@ -1267,7 +1268,7 @@ UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *pl
const QFontMetrics fm(font());
for (const KomodoUnits::Unit unit : units)
{
max_width = qMax(max_width, fm.width(KomodoUnits::name(unit)));
max_width = qMax(max_width, GUIUtil::TextWidth(fm, KomodoUnits::name(unit)));
}
setMinimumSize(max_width, 0);
setAlignment(Qt::AlignRight | Qt::AlignVCenter);
Expand Down
16 changes: 8 additions & 8 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,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 @@ -248,12 +248,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 Expand Up @@ -317,7 +317,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 = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":");
// 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 @@ -329,7 +329,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 = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":");
// 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 @@ -349,7 +349,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 = GUIUtil::SplitSkipEmptyParts(settings.value("addrSeparateProxyTor").toString(), ":");
// 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 @@ -361,7 +361,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 = GUIUtil::SplitSkipEmptyParts(settings.value("addrSeparateProxyTor").toString(), ":");
// 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
5 changes: 2 additions & 3 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 @@ -196,8 +196,7 @@ QVariant PeerTableModel::headerData(int section, Qt::Orientation orientation, in

Qt::ItemFlags PeerTableModel::flags(const QModelIndex &index) const
{
if(!index.isValid())
return 0;
if(!index.isValid()) return Qt::NoItemFlags;

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 @@ -251,7 +251,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
Loading