Qt: Fix more Qt6-related warnings.

This commit is contained in:
Gerald Combs 2022-03-25 12:22:08 -07:00
parent a3b76138f0
commit bcd3d05a3e
21 changed files with 69 additions and 23 deletions

View File

@ -37,7 +37,7 @@ void AStringListListModel::appendRow(const QStringList & display_strings, const
int AStringListListModel::rowCount(const QModelIndex &) const
{
return display_data_.count();
return static_cast<int>(display_data_.count());
}
int AStringListListModel::columnCount(const QModelIndex &parent) const
@ -45,7 +45,7 @@ int AStringListListModel::columnCount(const QModelIndex &parent) const
if (rowCount(parent) == 0)
return 0;
return headerColumns().count();
return static_cast<int>(headerColumns().count());
}
QVariant AStringListListModel::headerData(int section, Qt::Orientation orientation, int role) const
@ -114,14 +114,22 @@ void AStringListListSortFilterProxyModel::setFilter(const QString & filter)
static bool AContainsB(const QVariant &a, const QVariant &b, Qt::CaseSensitivity cs)
{
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (! a.canConvert<QString>() || ! b.canConvert<QString>())
#else
if (! a.canConvert(QVariant::String) || ! b.canConvert(QVariant::String))
#endif
return false;
return a.toString().contains(b.toString(), cs);
}
static bool AStartsWithB(const QVariant &a, const QVariant &b, Qt::CaseSensitivity cs)
{
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (! a.canConvert<QString>() || ! b.canConvert<QString>())
#else
if (! a.canConvert(QVariant::String) || ! b.canConvert(QVariant::String))
#endif
return false;
return a.toString().startsWith(b.toString(), cs);
}
@ -267,7 +275,11 @@ QVariant AStringListListUrlProxyModel::data(const QModelIndex &index, int role)
QVariant result = QIdentityProxyModel::data(index, role);
if (role == Qt::ForegroundRole && urls_.contains(index.column())
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
&& result.canConvert<QBrush>())
#else
&& result.canConvert(QVariant::Brush))
#endif
{
QBrush selected = result.value<QBrush>();
selected.setColor(ColorUtils::themeLinkBrush().color());

View File

@ -347,13 +347,21 @@ bool ColoringRulesModel::setData(const QModelIndex &dataIndex, const QVariant &v
}
break;
case Qt::BackgroundRole:
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (!value.canConvert<QColor>())
#else
if (!value.canConvert(QVariant::Color))
#endif
return false;
rule->background_ = QColor(value.toString());
break;
case Qt::ForegroundRole:
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (!value.canConvert<QColor>())
#else
if (!value.canConvert(QVariant::Color))
#endif
return false;
rule->foreground_ = QColor(value.toString());
@ -486,7 +494,7 @@ bool ColoringRulesModel::dropMimeData(const QMimeData *data, Qt::DropAction acti
rules.append(VariantPointer<ColoringRuleItem>::asQVariant(item));
}
insertRows(beginRow, rules.count(), QModelIndex());
insertRows(beginRow, static_cast<int>(rules.count()), QModelIndex());
for (int i = 0; i < rules.count(); i++) {
QModelIndex idx = index(beginRow, 0, QModelIndex());
setData(idx, rules[i], Qt::UserRole);

View File

@ -22,7 +22,7 @@ CredentialsModel::CredentialsModel(QObject *parent)
int CredentialsModel::rowCount(const QModelIndex &) const
{
return credentials_.count();
return static_cast<int>(credentials_.count());
}
int CredentialsModel::columnCount(const QModelIndex &) const

View File

@ -213,7 +213,7 @@ int DecodeAsModel::rowCount(const QModelIndex &parent) const
return 0;
}
return decode_as_items_.count();
return static_cast<int>(decode_as_items_.count());
}
int DecodeAsModel::columnCount(const QModelIndex &parent) const

View File

@ -71,13 +71,13 @@ ExpertPacketItem* ExpertPacketItem::child(QString hash)
int ExpertPacketItem::childCount() const
{
return childItems_.count();
return static_cast<int>(childItems_.count());
}
int ExpertPacketItem::row() const
{
if (parentItem_)
return parentItem_->childItems_.indexOf(const_cast<ExpertPacketItem*>(this));
return static_cast<int>(parentItem_->childItems_.indexOf(const_cast<ExpertPacketItem*>(this)));
return 0;
}

View File

@ -30,7 +30,7 @@ QModelIndex FilesetEntryModel::index(int row, int column, const QModelIndex &) c
int FilesetEntryModel::rowCount(const QModelIndex &) const
{
return entries_.count();
return static_cast<int>(entries_.count());
}
QVariant FilesetEntryModel::data(const QModelIndex &index, int role) const

View File

@ -100,7 +100,7 @@ FilterListModel::FilterListType FilterListModel::filterType() const
int FilterListModel::rowCount(const QModelIndex &/* parent */) const
{
return storage.count();
return static_cast<int>(storage.count());
}
int FilterListModel::columnCount(const QModelIndex &/* parent */) const
@ -291,7 +291,7 @@ bool FilterListModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
int strow = rows[0].toInt(&ok);
if (ok)
{
int storeTo = insertRow;
qsizetype storeTo = insertRow;
if (storeTo < 0 || storeTo >= storage.count())
storeTo = storage.count() - 1;

View File

@ -38,7 +38,7 @@ void InfoProxyModel::clearInfos()
int InfoProxyModel::rowCount(const QModelIndex &parent) const
{
return sourceModel()->rowCount(parent) + infos_.count();
return static_cast<int>(sourceModel()->rowCount(parent) + infos_.count());
}
QVariant InfoProxyModel::data (const QModelIndex &index, int role) const

View File

@ -327,7 +327,7 @@ int InterfaceSortFilterModel::mapSourceToColumn(InterfaceTreeColumns mdlIndex)
if (! _columns.contains(mdlIndex))
return -1;
return _columns.indexOf(mdlIndex, 0);
return static_cast<int>(_columns.indexOf(mdlIndex, 0));
}
QModelIndex InterfaceSortFilterModel::mapToSource(const QModelIndex &proxyIndex) const
@ -353,7 +353,7 @@ QModelIndex InterfaceSortFilterModel::mapFromSource(const QModelIndex &sourceInd
QModelIndex newIndex = QSortFilterProxyModel::mapFromSource(sourceIndex);
return index(newIndex.row(), _columns.indexOf((InterfaceTreeColumns) sourceIndex.column()));
return index(newIndex.row(), static_cast<int>(_columns.indexOf((InterfaceTreeColumns) sourceIndex.column())));
}
QString InterfaceSortFilterModel::interfaceError()

View File

@ -302,7 +302,7 @@ void PacketListRecord::cacheColumnStrings(column_info *cinfo)
}
col_text_ << col_str;
col_lines = col_str.count('\n');
col_lines = static_cast<int>(col_str.count('\n'));
if (col_lines > lines_) {
lines_ = col_lines;
line_count_changed_ = true;

View File

@ -152,7 +152,7 @@ int PrefsModel::rowCount(const QModelIndex &parent) const
if (parent_item == NULL)
return 0;
return parent_item->childCount();
return static_cast<int>(parent_item->childCount());
}
int PrefsModel::columnCount(const QModelIndex&) const

View File

@ -229,7 +229,7 @@ bool ProfileModel::userProfilesExist() const
int ProfileModel::rowCount(const QModelIndex &) const
{
return profiles_.count();
return static_cast<int>(profiles_.count());
}
int ProfileModel::columnCount(const QModelIndex &) const

View File

@ -145,7 +145,7 @@ int VoipCallsInfoModel::rowCount(const QModelIndex &parent) const
return 0;
}
return callinfos_.size();
return static_cast<int>(callinfos_.size());
}
int VoipCallsInfoModel::columnCount(const QModelIndex &parent) const
@ -185,7 +185,7 @@ bool VoipCallsInfoModel::timeOfDay() const
void VoipCallsInfoModel::updateCalls(GQueue *callsinfos)
{
if (callsinfos) {
int calls = callinfos_.count();
qsizetype calls = callinfos_.count();
int cnt = 0;
GList *cur_call;

View File

@ -136,7 +136,7 @@ QString DataPrinter::hexTextDump(const QByteArray printData, bool showASCII)
cnt++;
}
int lines = printData.length() / byteLineLength_;
int lines = static_cast<int>(printData.length()) / byteLineLength_;
if (printData.length() % byteLineLength_ > 0)
lines++;
@ -155,7 +155,7 @@ QString DataPrinter::hexTextDump(const QByteArray printData, bool showASCII)
/* separation bytes last line */
if (cnt == (lines - 1) )
{
int remSpace = byteLineLength_ - dataStr.mid(offset, byteLineLength_).length();
int remSpace = byteLineLength_ - static_cast<int>(dataStr.mid(offset, byteLineLength_).length());
clipboard_text += QString(remSpace * 3, ' ');
}

View File

@ -141,7 +141,7 @@ QString FieldInformation::toString()
QByteArray display_label;
display_label.resize(80); // Arbitrary.
proto_item_fill_display_label(fi_, display_label.data(), display_label.size());
proto_item_fill_display_label(fi_, display_label.data(), static_cast<int>(display_label.size()));
if (display_label.isEmpty()) {
return "[no value for field]";

View File

@ -167,8 +167,12 @@ QString html_escape(const QString plain_string) {
void smooth_font_size(QFont &font) {
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QList<int> size_list = QFontDatabase::smoothSizes(font.family(), font.styleName());
#else
QFontDatabase fdb;
QList<int> size_list = fdb.smoothSizes(font.family(), font.styleName());
#endif
if (size_list.size() < 2) return;

View File

@ -149,7 +149,7 @@ bool WiresharkZipHelper::unzip(QString zipFile, QString directory, bool (*fileCh
{
QByteArray buf;
buf.resize(IO_BUF_SIZE);
while ((err = unzReadCurrentFile(uf, buf.data(), buf.size())) != UNZ_EOF)
while ((err = unzReadCurrentFile(uf, buf.data(), static_cast<int>(buf.size()))) != UNZ_EOF)
file.write(buf.constData(), err);
file.close();

View File

@ -179,7 +179,11 @@ void DragDropToolBar::dragMoveEvent(QDragMoveEvent *event)
if (qobject_cast<const ToolbarEntryMimeData *>(event->mimeData()))
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0 ,0)
QAction * actionAtPos = actionAt(event->position().toPoint());
#else
QAction * actionAtPos = actionAt(event->pos());
#endif
if (actionAtPos)
{
QWidget * widget = widgetForAction(actionAtPos);
@ -226,7 +230,11 @@ void DragDropToolBar::dropEvent(QDropEvent *event)
int oldPos = data->position();
int newPos = -1;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0 ,0)
QAction * action = actionAt(event->position().toPoint());
#else
QAction * action = actionAt(event->pos());
#endif
if (action && actions().at(oldPos))
{
widgetForAction(action)->setStyleSheet("QWidget { border: none; };");

View File

@ -9,6 +9,7 @@
#include <ui/qt/models/url_link_delegate.h>
#include <ui/qt/models/profile_model.h>
#include <ui/qt/utils/qt_ui_utils.h>
#include <ui/qt/widgets/profile_tree_view.h>
#include <QDesktopServices>

View File

@ -447,7 +447,7 @@ void SyntaxLineEdit::insertFieldCompletion(const QString &completion_text)
QString new_text = text().replace(field_coords.x(), field_coords.y(), completion_text);
setText(new_text);
setCursorPosition(field_coords.x() + completion_text.length());
setCursorPosition(field_coords.x() + static_cast<int>(completion_text.length()));
emit textEdited(new_text);
}

View File

@ -109,7 +109,11 @@ static void accumulate_rgb(float rgb[TIMELINE_HEIGHT][3], int height, int dfilte
void WirelessTimeline::mousePressEvent(QMouseEvent *event)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0 ,0)
start_x = last_x = event->position().x();
#else
start_x = last_x = event->localPos().x();
#endif
}
@ -118,8 +122,13 @@ void WirelessTimeline::mouseMoveEvent(QMouseEvent *event)
if (event->buttons() == Qt::NoButton)
return;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0 ,0)
qreal offset = event->position().x() - last_x;
last_x = event->position().x();
#else
qreal offset = event->localPos().x() - last_x;
last_x = event->localPos().x();
#endif
qreal shift = ((qreal) (end_tsf - start_tsf))/width() * offset;
start_tsf -= shift;
@ -135,7 +144,11 @@ void WirelessTimeline::mouseMoveEvent(QMouseEvent *event)
void WirelessTimeline::mouseReleaseEvent(QMouseEvent *event)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0 ,0)
QPointF localPos = event->position();
#else
QPointF localPos = event->localPos();
#endif
qreal offset = localPos.x() - start_x;
/* if this was a drag, ignore it */