Fix warnings about implicit conversions when compiling against Qt 6

This commit is contained in:
Martchus 2023-07-23 22:17:47 +02:00
parent 1cb6e06f31
commit 4a3aa9c1c1
13 changed files with 64 additions and 40 deletions

View File

@ -189,7 +189,7 @@ QVariant QueryResultsModel::headerData(int section, Qt::Orientation orientation,
int QueryResultsModel::rowCount(const QModelIndex &parent) const int QueryResultsModel::rowCount(const QModelIndex &parent) const
{ {
return parent.isValid() ? 0 : m_results.size(); return parent.isValid() ? 0 : Utility::containerSizeToInt(m_results.size());
} }
int QueryResultsModel::columnCount(const QModelIndex &parent) const int QueryResultsModel::columnCount(const QModelIndex &parent) const

View File

@ -2,6 +2,7 @@
#include "../application/settings.h" #include "../application/settings.h"
#include "../misc/networkaccessmanager.h" #include "../misc/networkaccessmanager.h"
#include "../misc/utility.h"
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkRequest> #include <QNetworkRequest>
@ -141,7 +142,7 @@ void LyricsWikiaResultsModel::parseInitialResults(const QByteArray &data)
iftag("item") { iftag("item") {
songs << SongDescription(); songs << SongDescription();
songs.back().title = text; songs.back().title = text;
songs.back().track = songs.size(); songs.back().track = Utility::containerSizeToInt(songs.size());
} }
else_skip else_skip
} }
@ -157,7 +158,7 @@ void LyricsWikiaResultsModel::parseInitialResults(const QByteArray &data)
&& (!m_initialDescription.track || m_initialDescription.track == song.track)) { && (!m_initialDescription.track || m_initialDescription.track == song.track)) {
song.album = album; song.album = album;
song.year = year; song.year = year;
song.totalTracks = songs.size(); song.totalTracks = Utility::containerSizeToInt(songs.size());
m_results << std::move(song); m_results << std::move(song);
} }
} }
@ -376,14 +377,14 @@ void LyricsWikiaResultsModel::parseAlbumDetailsAndFetchCover(int row, const QByt
SongDescription &assocDesc = m_results[row]; SongDescription &assocDesc = m_results[row];
// convert data to QString // convert data to QString
const QString html(data); const auto html = QString(data);
// parse cover URL from HTML // parse cover URL from HTML
const int coverDivStart = html.indexOf(QLatin1String("<div class=\"plainlinks\" style=\"clear:right; float:right;")) + 56; const auto coverDivStart = html.indexOf(QLatin1String("<div class=\"plainlinks\" style=\"clear:right; float:right;")) + 56;
if (coverDivStart > 56) { if (coverDivStart > 56) {
const int coverHrefStart = html.indexOf(QLatin1String("href=\""), coverDivStart) + 6; const auto coverHrefStart = html.indexOf(QLatin1String("href=\""), coverDivStart) + 6;
if (coverHrefStart > coverDivStart + 6) { if (coverHrefStart > coverDivStart + 6) {
const int coverHrefEnd = html.indexOf(QLatin1String("\""), coverHrefStart); const auto coverHrefEnd = html.indexOf(QLatin1String("\""), coverHrefStart);
if (coverHrefEnd > 0) { if (coverHrefEnd > 0) {
assocDesc.coverUrl = html.mid(coverHrefStart, coverHrefEnd - coverHrefStart); assocDesc.coverUrl = html.mid(coverHrefStart, coverHrefEnd - coverHrefStart);
} }

View File

@ -1,5 +1,7 @@
#include "./attachmentsmodel.h" #include "./attachmentsmodel.h"
#include "../misc/utility.h"
#include <tagparser/abstractattachment.h> #include <tagparser/abstractattachment.h>
#include <c++utilities/conversion/stringconversion.h> #include <c++utilities/conversion/stringconversion.h>
@ -233,7 +235,7 @@ int AttachmentsModel::rowCount(const QModelIndex &parent) const
if (parent.isValid()) { if (parent.isValid()) {
return 0; return 0;
} else { } else {
return m_attachments.size(); return Utility::containerSizeToInt(m_attachments.size());
} }
} }
@ -251,7 +253,7 @@ void AttachmentsModel::revert()
for (auto &item : m_attachments) { for (auto &item : m_attachments) {
item.revert(); item.revert();
} }
emit dataChanged(index(0, 0), index(m_attachments.size() - 1, 0), QVector<int>() << Qt::CheckStateRole); emit dataChanged(index(0, 0), index(Utility::containerSizeToInt(m_attachments.size()) - 1, 0), QVector<int>() << Qt::CheckStateRole);
} }
bool AttachmentsModel::submit() bool AttachmentsModel::submit()
@ -268,7 +270,7 @@ void AttachmentsModel::repealSelection()
for (auto &item : m_attachments) { for (auto &item : m_attachments) {
item.setActivated(false); item.setActivated(false);
} }
emit dataChanged(index(0, 0), index(m_attachments.size() - 1, 0), QVector<int>() << Qt::CheckStateRole); emit dataChanged(index(0, 0), index(Utility::containerSizeToInt(m_attachments.size()) - 1, 0), QVector<int>() << Qt::CheckStateRole);
} }
} }
@ -283,7 +285,7 @@ AbstractAttachment *AttachmentsModel::attachment(const QModelIndex &index)
void AttachmentsModel::addAttachment(int row, AbstractAttachment *attachment, bool activated, const QString &location) void AttachmentsModel::addAttachment(int row, AbstractAttachment *attachment, bool activated, const QString &location)
{ {
if (row < 0 || row > m_attachments.size()) { if (row < 0 || row > m_attachments.size()) {
row = m_attachments.size(); row = Utility::containerSizeToInt(m_attachments.size());
} }
beginInsertRows(QModelIndex(), row, row); beginInsertRows(QModelIndex(), row, row);
m_attachments.insert(row, AttachmentItem(attachment, activated, location)); m_attachments.insert(row, AttachmentItem(attachment, activated, location));

View File

@ -1,5 +1,7 @@
#include "./codeedit.h" #include "./codeedit.h"
#include "../misc/utility.h"
#include <QTextBlock> #include <QTextBlock>
#include <QTextDocumentFragment> #include <QTextDocumentFragment>
@ -49,7 +51,7 @@ void CodeEdit::handleReturn(QKeyEvent *)
if (index < line.size() && line.at(index) == QChar('}')) { if (index < line.size() && line.at(index) == QChar('}')) {
if (index > 0) { if (index > 0) {
int beg = index; int beg = index;
index -= m_indentation.size(); index -= Utility::containerSizeToInt(m_indentation.size());
cursor.select(QTextCursor::BlockUnderCursor); cursor.select(QTextCursor::BlockUnderCursor);
cursor.deleteChar(); cursor.deleteChar();
cursor.insertBlock(); cursor.insertBlock();

View File

@ -279,7 +279,7 @@ void DbQueryWidget::showResults()
if (m_model->results().isEmpty()) { if (m_model->results().isEmpty()) {
m_ui->notificationLabel->setText(tr("No results available")); m_ui->notificationLabel->setText(tr("No results available"));
} else { } else {
m_ui->notificationLabel->setText(tr("%1 result(s) available", nullptr, m_model->results().size()).arg(m_model->results().size())); m_ui->notificationLabel->setText(tr("%1 result(s) available", nullptr, Utility::containerSizeToInt(m_model->results().size())).arg(m_model->results().size()));
} }
} else { } else {
m_ui->notificationLabel->setNotificationType(NotificationType::Critical); m_ui->notificationLabel->setNotificationType(NotificationType::Critical);

View File

@ -1,5 +1,7 @@
#include "./javascripthighlighter.h" #include "./javascripthighlighter.h"
#include "../misc/utility.h"
namespace QtGui { namespace QtGui {
JavaScriptHighlighter::JavaScriptHighlighter(QTextDocument *parent) JavaScriptHighlighter::JavaScriptHighlighter(QTextDocument *parent)
@ -55,8 +57,8 @@ void JavaScriptHighlighter::highlightBlock(const QString &text)
const auto &expression(rule.pattern); const auto &expression(rule.pattern);
auto match = expression.match(text); auto match = expression.match(text);
while (match.hasMatch()) { while (match.hasMatch()) {
const auto index = match.capturedStart(); const auto index = Utility::containerSizeToInt(match.capturedStart());
const auto length = match.capturedLength(); const auto length = Utility::containerSizeToInt(match.capturedLength());
setFormat(index, length, rule.format); setFormat(index, length, rule.format);
match = expression.match(text, index + length); match = expression.match(text, index + length);
} }
@ -65,21 +67,21 @@ void JavaScriptHighlighter::highlightBlock(const QString &text)
auto startIndex = 0; auto startIndex = 0;
if (previousBlockState() != 1) { if (previousBlockState() != 1) {
startIndex = m_commentStartExpression.match(text).capturedStart(); startIndex = Utility::containerSizeToInt(m_commentStartExpression.match(text).capturedStart());
} }
while (startIndex >= 0) { while (startIndex >= 0) {
const auto endMatch = m_commentEndExpression.match(text, startIndex); const auto endMatch = m_commentEndExpression.match(text, startIndex);
const auto endIndex = endMatch.capturedStart(); const auto endIndex = Utility::containerSizeToInt(endMatch.capturedStart());
const auto commentLength = [&] { const auto commentLength = [&] {
if (endIndex >= 0) { if (endIndex >= 0) {
return endIndex - startIndex + endMatch.capturedLength(); return endIndex - startIndex + Utility::containerSizeToInt(endMatch.capturedLength());
} }
setCurrentBlockState(1); setCurrentBlockState(1);
return text.length() - startIndex; return Utility::containerSizeToInt(text.length()) - startIndex;
}(); }();
setFormat(startIndex, commentLength, m_multiLineCommentFormat); setFormat(startIndex, commentLength, m_multiLineCommentFormat);
startIndex = m_commentStartExpression.match(text, startIndex + commentLength).capturedStart(); startIndex = Utility::containerSizeToInt(m_commentStartExpression.match(text, startIndex + commentLength).capturedStart());
} }
} }

View File

@ -191,9 +191,9 @@ void NotificationLabel::applyMaxLineCount()
return; return;
} }
int newStart = 0; auto newStart = QString::size_type();
for (; m_currentLineCount > m_maxLineCount; --m_currentLineCount) { for (; m_currentLineCount > m_maxLineCount; --m_currentLineCount) {
const int nextBullet = m_text.indexOf(s_bulletLine, newStart); const auto nextBullet = m_text.indexOf(s_bulletLine, newStart);
if (nextBullet < 0) { if (nextBullet < 0) {
break; break;
} }

View File

@ -362,14 +362,14 @@ void TagEditorWidget::updateTagEditsAndAttachmentEdits(bool updateUi, PreviousVa
// add/update TagEdit widgets // add/update TagEdit widgets
if (m_tags.size()) { if (m_tags.size()) {
// create a lists of the targets and tags // create a lists of the targets and tags
QList<TagTarget> targets; auto targets = QList<TagTarget>();
QList<QList<Tag *>> tagsByTarget; auto tagsByTarget = QList<QList<Tag *>>();
for (Tag *tag : m_tags) { for (auto *const tag : m_tags) {
const TagTarget &target = tag->target(); const auto &target = tag->target();
int index = targets.indexOf(target); auto index = targets.indexOf(target);
if (index < 0) { if (index < 0) {
targets << target; targets << target;
tagsByTarget << (QList<Tag *>() << tag); tagsByTarget << QList<Tag *>({tag});
} else { } else {
tagsByTarget[index] << tag; tagsByTarget[index] << tag;
} }
@ -379,7 +379,7 @@ void TagEditorWidget::updateTagEditsAndAttachmentEdits(bool updateUi, PreviousVa
switch (Settings::values().editor.multipleTagHandling) { switch (Settings::values().editor.multipleTagHandling) {
case Settings::MultipleTagHandling::SingleEditorPerTarget: case Settings::MultipleTagHandling::SingleEditorPerTarget:
// iterate through all targets in both cases // iterate through all targets in both cases
for (int targetIndex = 0, targetCount = targets.size(); targetIndex < targetCount; ++targetIndex) { for (auto targetIndex = QList<TagTarget>::size_type(), targetCount = targets.size(); targetIndex < targetCount; ++targetIndex) {
fetchNextEdit(); fetchNextEdit();
edit->setTags(tagsByTarget.at(targetIndex), updateUi); // set all tags with the same target to a single edit edit->setTags(tagsByTarget.at(targetIndex), updateUi); // set all tags with the same target to a single edit
if (!hasAutoCorrectionBeenApplied) { if (!hasAutoCorrectionBeenApplied) {
@ -390,7 +390,7 @@ void TagEditorWidget::updateTagEditsAndAttachmentEdits(bool updateUi, PreviousVa
break; break;
case Settings::MultipleTagHandling::SeparateEditors: case Settings::MultipleTagHandling::SeparateEditors:
// iterate through all targets in both cases // iterate through all targets in both cases
for (int targetIndex = 0, targetCount = targets.size(); targetIndex < targetCount; ++targetIndex) { for (auto targetIndex = QList<TagTarget>::size_type(), targetCount = targets.size(); targetIndex < targetCount; ++targetIndex) {
for (Tag *tag : tagsByTarget.at(targetIndex)) { for (Tag *tag : tagsByTarget.at(targetIndex)) {
fetchNextEdit(); fetchNextEdit();
edit->setTag(tag, updateUi); // use a separate edit for each tag edit->setTag(tag, updateUi); // use a separate edit for each tag

View File

@ -165,10 +165,10 @@ QString elementPositionToQString(ElementPosition elementPosition)
QString formatName(const QString &str, bool underscoreToWhitespace) QString formatName(const QString &str, bool underscoreToWhitespace)
{ {
QString res; auto res = QString();
res.reserve(str.size()); res.reserve(str.size());
bool whitespace = true; auto whitespace = true;
for (int i = 0, size = str.size(); i != size; ++i) { for (auto i = QString::size_type(), size = str.size(); i != size; ++i) {
const QChar current = str.at(i); const QChar current = str.at(i);
if (current.isSpace() || current == QChar('(') || current == QChar('[')) { if (current.isSpace() || current == QChar('(') || current == QChar('[')) {
whitespace = true; whitespace = true;
@ -228,7 +228,7 @@ void parseFileName(const QString &fileName, QString &title, int &trackNumber)
{ {
title = fileName.trimmed(); title = fileName.trimmed();
trackNumber = 0; trackNumber = 0;
int lastPoint = title.lastIndexOf(QChar('.')); auto lastPoint = title.lastIndexOf(QChar('.'));
if (lastPoint > 0) { if (lastPoint > 0) {
title.truncate(lastPoint); title.truncate(lastPoint);
} else if (lastPoint == 0) { } else if (lastPoint == 0) {
@ -236,13 +236,13 @@ void parseFileName(const QString &fileName, QString &title, int &trackNumber)
} }
static const QLatin1String delims[] = { QLatin1String(" - "), QLatin1String(", "), QLatin1String("-"), QLatin1String(" ") }; static const QLatin1String delims[] = { QLatin1String(" - "), QLatin1String(", "), QLatin1String("-"), QLatin1String(" ") };
for (const auto &delim : delims) { for (const auto &delim : delims) {
int lastDelimIndex = 0; auto lastDelimIndex = QString::size_type();
int delimIndex = title.indexOf(delim); auto delimIndex = title.indexOf(delim);
while (delimIndex > lastDelimIndex) { while (delimIndex > lastDelimIndex) {
bool ok = false; bool ok = false;
trackNumber = QtUtilities::midRef(title, lastDelimIndex, delimIndex - lastDelimIndex).toInt(&ok); trackNumber = QtUtilities::midRef(title, lastDelimIndex, delimIndex - lastDelimIndex).toInt(&ok);
if (ok) { if (ok) {
int titleStart = delimIndex + delim.size(); auto titleStart = delimIndex + delim.size();
for (const auto &delim2 : delims) { for (const auto &delim2 : delims) {
if (QtUtilities::midRef(title, titleStart).startsWith(delim2)) { if (QtUtilities::midRef(title, titleStart).startsWith(delim2)) {
titleStart += delim2.size(); titleStart += delim2.size();

View File

@ -4,6 +4,10 @@
#include <tagparser/tagvalue.h> #include <tagparser/tagvalue.h>
#include <QString> #include <QString>
#include <QStringList>
#include <type_traits>
#include <limits>
QT_FORWARD_DECLARE_CLASS(QDir) QT_FORWARD_DECLARE_CLASS(QDir)
QT_FORWARD_DECLARE_CLASS(QAbstractItemModel) QT_FORWARD_DECLARE_CLASS(QAbstractItemModel)
@ -35,6 +39,15 @@ constexpr int sizeToInt(std::size_t size)
return size > std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : static_cast<int>(size); return size > std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : static_cast<int>(size);
} }
constexpr int containerSizeToInt(typename QStringList::size_type size)
{
if constexpr (std::is_same_v<decltype(size), int>) {
return size;
} else {
return size > std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : static_cast<int>(size);
}
}
constexpr int trQuandity(quint64 quandity) constexpr int trQuandity(quint64 quandity)
{ {
return quandity > std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : static_cast<int>(quandity); return quandity > std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : static_cast<int>(quandity);

View File

@ -1,6 +1,8 @@
#ifndef FILESYSTEMITEM_H #ifndef FILESYSTEMITEM_H
#define FILESYSTEMITEM_H #define FILESYSTEMITEM_H
#include "../misc/utility.h"
#include <QList> #include <QList>
#include <QString> #include <QString>
@ -188,7 +190,7 @@ inline void FileSystemItem::setCheckable(bool checkable)
inline int FileSystemItem::row() const inline int FileSystemItem::row() const
{ {
return m_parent ? m_parent->children().indexOf(const_cast<FileSystemItem *>(this)) : -1; return m_parent ? Utility::containerSizeToInt(m_parent->children().indexOf(const_cast<FileSystemItem *>(this))) : -1;
} }
} // namespace RenamingUtility } // namespace RenamingUtility

View File

@ -1,6 +1,8 @@
#include "./filesystemitemmodel.h" #include "./filesystemitemmodel.h"
#include "./filesystemitem.h" #include "./filesystemitem.h"
#include "../misc/utility.h"
#include <QApplication> #include <QApplication>
#include <QBrush> #include <QBrush>
#include <QFont> #include <QFont>
@ -232,7 +234,7 @@ QModelIndex FileSystemItemModel::counterpart(const QModelIndex &index, int colum
int FileSystemItemModel::rowCount(const QModelIndex &parent) const int FileSystemItemModel::rowCount(const QModelIndex &parent) const
{ {
if (const auto *const parentItem = (parent.isValid() ? reinterpret_cast<FileSystemItem *>(parent.internalPointer()) : m_rootItem)) { if (const auto *const parentItem = (parent.isValid() ? reinterpret_cast<FileSystemItem *>(parent.internalPointer()) : m_rootItem)) {
return parentItem->children().size(); return Utility::containerSizeToInt(parentItem->children().size());
} else { } else {
return 0; return 0;
} }

View File

@ -294,7 +294,7 @@ void RenamingEngine::applyChangings(FileSystemItem *parentItem)
applyChangings(item); applyChangings(item);
} }
} }
m_itemsProcessed += parentItem->children().size(); m_itemsProcessed += Utility::containerSizeToInt(parentItem->children().size());
emit progress(m_itemsProcessed, m_errorsOccured); emit progress(m_itemsProcessed, m_errorsOccured);
} }