Avoid repeating the return type

This commit is contained in:
thalieht
2019-02-14 19:16:42 +02:00
parent 9959a901fe
commit 8c944bd4e1
34 changed files with 123 additions and 123 deletions

View File

@@ -71,7 +71,7 @@ QString AutoExpandableDialog::getText(QWidget *parent, const QString &title, con
if (ok)
*ok = res;
if (!res) return QString();
if (!res) return {};
return d.m_ui->textEdit->text();
}

View File

@@ -207,7 +207,7 @@ int CategoryFilterModel::columnCount(const QModelIndex &) const
QVariant CategoryFilterModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) return QVariant();
if (!index.isValid()) return {};
auto item = static_cast<CategoryModelItem *>(index.internalPointer());
@@ -224,7 +224,7 @@ QVariant CategoryFilterModel::data(const QModelIndex &index, int role) const
return item->torrentsCount();
}
return QVariant();
return {};
}
Qt::ItemFlags CategoryFilterModel::flags(const QModelIndex &index) const
@@ -240,32 +240,32 @@ QVariant CategoryFilterModel::headerData(int section, Qt::Orientation orientatio
if (section == 0)
return tr("Categories");
return QVariant();
return {};
}
QModelIndex CategoryFilterModel::index(int row, int column, const QModelIndex &parent) const
{
if (column > 0)
return QModelIndex();
return {};
if (parent.isValid() && (parent.column() != 0))
return QModelIndex();
return {};
auto parentItem = parent.isValid() ? static_cast<CategoryModelItem *>(parent.internalPointer())
: m_rootItem;
if (row < parentItem->childCount())
return createIndex(row, column, parentItem->childAt(row));
return QModelIndex();
return {};
}
QModelIndex CategoryFilterModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
return {};
auto item = static_cast<CategoryModelItem *>(index.internalPointer());
if (!item) return QModelIndex();
if (!item) return {};
return this->index(item->parent());
}
@@ -291,13 +291,13 @@ QModelIndex CategoryFilterModel::index(const QString &categoryName) const
QString CategoryFilterModel::categoryName(const QModelIndex &index) const
{
if (!index.isValid()) return QString();
if (!index.isValid()) return {};
return static_cast<CategoryModelItem *>(index.internalPointer())->fullName();
}
QModelIndex CategoryFilterModel::index(CategoryModelItem *item) const
{
if (!item || !item->parent()) return QModelIndex();
if (!item || !item->parent()) return {};
return index(item->pos(), 0, index(item->parent()));
}

View File

@@ -58,7 +58,7 @@ QVariant CookiesModel::headerData(int section, Qt::Orientation orientation, int
}
}
return QVariant();
return {};
}
QModelIndex CookiesModel::index(int row, int column, const QModelIndex &parent) const
@@ -66,7 +66,7 @@ QModelIndex CookiesModel::index(int row, int column, const QModelIndex &parent)
if (parent.isValid() // no items with valid parent
|| (row < 0) || (row >= m_cookies.size())
|| (column < 0) || (column >= NB_COLUMNS))
return QModelIndex();
return {};
return createIndex(row, column, &m_cookies[row]);
}
@@ -74,7 +74,7 @@ QModelIndex CookiesModel::index(int row, int column, const QModelIndex &parent)
QModelIndex CookiesModel::parent(const QModelIndex &index) const
{
Q_UNUSED(index);
return QModelIndex();
return {};
}
int CookiesModel::rowCount(const QModelIndex &parent) const
@@ -94,7 +94,7 @@ QVariant CookiesModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || (index.row() >= m_cookies.size())
|| ((role != Qt::DisplayRole) && (role != Qt::EditRole)))
return QVariant();
return {};
switch (index.column()) {
case COL_DOMAIN:
@@ -109,7 +109,7 @@ QVariant CookiesModel::data(const QModelIndex &index, int role) const
return m_cookies[index.row()].expirationDate();
}
return QVariant();
return {};
}
bool CookiesModel::setData(const QModelIndex &index, const QVariant &value, int role)

View File

@@ -311,7 +311,7 @@ QString Private::FileLineEdit::warningText(FileSystemPathValidator::TestResult r
case TestResult::CantWrite:
return tr("Does not have write permission in '%1'");
default:
return QString();
return {};
}
}

View File

@@ -90,7 +90,7 @@ QIcon GuiIconProvider::getIcon(const QString &iconId, const QString &fallback) c
QIcon GuiIconProvider::getFlagIcon(const QString &countryIsoCode) const
{
if (countryIsoCode.isEmpty()) return QIcon();
if (countryIsoCode.isEmpty()) return {};
return QIcon(":/icons/flags/" + countryIsoCode.toLower() + ".svg");
}

View File

@@ -1447,14 +1447,14 @@ QString OptionsDialog::getTorrentExportDir() const
{
if (m_ui->checkExportDir->isChecked())
return Utils::Fs::expandPathAbs(m_ui->textExportDir->selectedPath());
return QString();
return {};
}
QString OptionsDialog::getFinishedTorrentExportDir() const
{
if (m_ui->checkExportDirFin->isChecked())
return Utils::Fs::expandPathAbs(m_ui->textExportDirFin->selectedPath());
return QString();
return {};
}
// Return action on double-click on a downloading torrent set in options

View File

@@ -166,6 +166,6 @@ namespace
if (xml.isCharacters() && !xml.isWhitespace())
return xml.text().toString();
return QString();
return {};
}
}

View File

@@ -80,7 +80,7 @@ QVariant HtmlBrowser::loadResource(int type, const QUrl &name)
m_netManager->get(req);
}
return QVariant();
return {};
}
return QTextBrowser::loadResource(type, name);

View File

@@ -385,7 +385,7 @@ QString SearchJobWidget::statusText(SearchJobWidget::Status st)
case Status::NoResults:
return tr("Search returned no results");
default:
return QString();
return {};
}
}

View File

@@ -83,7 +83,7 @@ namespace
case SearchJobWidget::Status::NoResults:
return QLatin1String("task-attention");
default:
return QString();
return {};
}
}
}

View File

@@ -114,7 +114,7 @@ bool TagFilterModel::isSpecialItem(const QModelIndex &index)
QVariant TagFilterModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || (index.column() != 0))
return QVariant();
return {};
const int row = index.internalId();
Q_ASSERT(isValidRow(row));
@@ -129,7 +129,7 @@ QVariant TagFilterModel::data(const QModelIndex &index, int role) const
case Qt::UserRole:
return item.torrentsCount();
default:
return QVariant();
return {};
}
}
@@ -145,13 +145,13 @@ QVariant TagFilterModel::headerData(int section, Qt::Orientation orientation, in
if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole))
if (section == 0)
return tr("Tags");
return QVariant();
return {};
}
QModelIndex TagFilterModel::index(int row, int, const QModelIndex &) const
{
if (!isValidRow(row))
return QModelIndex();
return {};
return createIndex(row, 0, row);
}
@@ -171,14 +171,14 @@ QModelIndex TagFilterModel::index(const QString &tag) const
{
const int row = findRow(tag);
if (!isValidRow(row))
return QModelIndex();
return {};
return index(row, 0, QModelIndex());
}
QString TagFilterModel::tag(const QModelIndex &index) const
{
if (!index.isValid())
return QString();
return {};
const int row = index.internalId();
Q_ASSERT(isValidRow(row));
return m_tagItems[row].tag();

View File

@@ -66,10 +66,10 @@ int TorrentContentFilterModel::getFileIndex(const QModelIndex &index) const
QModelIndex TorrentContentFilterModel::parent(const QModelIndex &child) const
{
if (!child.isValid()) return QModelIndex();
if (!child.isValid()) return {};
QModelIndex sourceParent = m_model->parent(mapToSource(child));
if (!sourceParent.isValid()) return QModelIndex();
if (!sourceParent.isValid()) return {};
return mapFromSource(sourceParent);
}

View File

@@ -113,12 +113,12 @@ namespace
const QString ext = info.suffix();
if (!ext.isEmpty()) {
QPixmap cached;
if (QPixmapCache::find(ext, &cached)) return QIcon(cached);
if (QPixmapCache::find(ext, &cached)) return {cached};
const QPixmap pixmap = pixmapForExtension(ext);
if (!pixmap.isNull()) {
QPixmapCache::insert(ext, pixmap);
return QIcon(pixmap);
return {pixmap};
}
}
return UnifiedFileIconProvider::icon(info);
@@ -140,7 +140,7 @@ namespace
HRESULT hr = ::SHGetFileInfoW(extWithDot.toStdWString().c_str(),
FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES);
if (FAILED(hr))
return QPixmap();
return {};
QPixmap iconPixmap = QtWin::fromHICON(sfi.hIcon);
::DestroyIcon(sfi.hIcon);
@@ -354,7 +354,7 @@ int TorrentContentModel::getFileIndex(const QModelIndex &index)
QVariant TorrentContentModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
return {};
auto *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
@@ -376,7 +376,7 @@ QVariant TorrentContentModel::data(const QModelIndex &index, int role) const
if (role == Qt::DisplayRole)
return item->data(index.column());
return QVariant();
return {};
}
Qt::ItemFlags TorrentContentModel::flags(const QModelIndex &index) const
@@ -395,16 +395,16 @@ QVariant TorrentContentModel::headerData(int section, Qt::Orientation orientatio
if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole))
return m_rootItem->data(section);
return QVariant();
return {};
}
QModelIndex TorrentContentModel::index(int row, int column, const QModelIndex &parent) const
{
if (parent.isValid() && (parent.column() != 0))
return QModelIndex();
return {};
if (column >= TorrentContentModelItem::NB_COL)
return QModelIndex();
return {};
TorrentContentModelFolder *parentItem;
if (!parent.isValid())
@@ -414,26 +414,26 @@ QModelIndex TorrentContentModel::index(int row, int column, const QModelIndex &p
Q_ASSERT(parentItem);
if (row >= parentItem->childCount())
return QModelIndex();
return {};
TorrentContentModelItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
return QModelIndex();
return {};
}
QModelIndex TorrentContentModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
return {};
auto *childItem = static_cast<TorrentContentModelItem*>(index.internalPointer());
if (!childItem)
return QModelIndex();
return {};
TorrentContentModelItem *parentItem = childItem->parent();
if (parentItem == m_rootItem)
return QModelIndex();
return {};
return createIndex(parentItem->row(), 0, parentItem);
}

View File

@@ -121,7 +121,7 @@ QVariant TorrentContentModelItem::data(int column) const
return availability();
default:
Q_ASSERT(false);
return QVariant();
return {};
}
}

View File

@@ -81,7 +81,7 @@ QModelIndex TorrentContentTreeView::currentNameCell()
QModelIndex current = currentIndex();
if (!current.isValid()) {
Q_ASSERT(false);
return QModelIndex();
return {};
}
return model()->index(current.row(), TorrentContentModelItem::COL_NAME, current.parent());

View File

@@ -125,7 +125,7 @@ QVariant TransferListModel::headerData(int section, Qt::Orientation orientation,
case TR_LAST_ACTIVITY: return tr("Last Activity", "Time passed since a chunk was downloaded/uploaded");
case TR_TOTAL_SIZE: return tr("Total Size", "i.e. Size including unwanted data");
default:
return QVariant();
return {};
}
}
else if (role == Qt::TextAlignmentRole) {
@@ -149,22 +149,22 @@ QVariant TransferListModel::headerData(int section, Qt::Orientation orientation,
case TR_RATIO:
case TR_PRIORITY:
case TR_LAST_ACTIVITY:
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
return {Qt::AlignRight | Qt::AlignVCenter};
default:
return QAbstractListModel::headerData(section, orientation, role);
}
}
}
return QVariant();
return {};
}
QVariant TransferListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) return QVariant();
if (!index.isValid()) return {};
BitTorrent::TorrentHandle *const torrent = m_torrents.value(index.row());
if (!torrent) return QVariant();
if (!torrent) return {};
if ((role == Qt::DecorationRole) && (index.column() == TR_NAME))
return getIconByState(torrent->state());
@@ -173,7 +173,7 @@ QVariant TransferListModel::data(const QModelIndex &index, int role) const
return getColorByState(torrent->state());
if ((role != Qt::DisplayRole) && (role != Qt::UserRole))
return QVariant();
return {};
switch (index.column()) {
case TR_NAME:
@@ -243,7 +243,7 @@ QVariant TransferListModel::data(const QModelIndex &index, int role) const
return torrent->totalSize();
}
return QVariant();
return {};
}
bool TransferListModel::setData(const QModelIndex &index, const QVariant &value, int role)
@@ -366,32 +366,32 @@ QColor getColorByState(BitTorrent::TorrentState state)
case BitTorrent::TorrentState::ForcedDownloading:
case BitTorrent::TorrentState::DownloadingMetadata:
if (!dark)
return QColor(34, 139, 34); // Forest Green
return {34, 139, 34}; // Forest Green
else
return QColor(50, 205, 50); // Lime Green
return {50, 205, 50}; // Lime Green
case BitTorrent::TorrentState::Allocating:
case BitTorrent::TorrentState::StalledDownloading:
case BitTorrent::TorrentState::StalledUploading:
if (!dark)
return QColor(0, 0, 0); // Black
return {0, 0, 0}; // Black
else
return QColor(204, 204, 204); // Gray 80
return {204, 204, 204}; // Gray 80
case BitTorrent::TorrentState::Uploading:
case BitTorrent::TorrentState::ForcedUploading:
if (!dark)
return QColor(65, 105, 225); // Royal Blue
return {65, 105, 225}; // Royal Blue
else
return QColor(99, 184, 255); // Steel Blue 1
return {99, 184, 255}; // Steel Blue 1
case BitTorrent::TorrentState::PausedDownloading:
return QColor(250, 128, 114); // Salmon
return {250, 128, 114}; // Salmon
case BitTorrent::TorrentState::PausedUploading:
if (!dark)
return QColor(0, 0, 139); // Dark Blue
return {0, 0, 139}; // Dark Blue
else
return QColor(79, 148, 205); // Steel Blue 3
return {79, 148, 205}; // Steel Blue 3
case BitTorrent::TorrentState::Error:
case BitTorrent::TorrentState::MissingFiles:
return QColor(255, 0, 0); // red
return {255, 0, 0}; // red
case BitTorrent::TorrentState::QueuedDownloading:
case BitTorrent::TorrentState::QueuedUploading:
case BitTorrent::TorrentState::CheckingDownloading:
@@ -399,14 +399,14 @@ QColor getColorByState(BitTorrent::TorrentState state)
case BitTorrent::TorrentState::CheckingResumeData:
case BitTorrent::TorrentState::Moving:
if (!dark)
return QColor(0, 128, 128); // Teal
return {0, 128, 128}; // Teal
else
return QColor(0, 205, 205); // Cyan 3
return {0, 205, 205}; // Cyan 3
case BitTorrent::TorrentState::Unknown:
return QColor(255, 0, 0); // red
return {255, 0, 0}; // red
default:
Q_ASSERT(false);
return QColor(255, 0, 0); // red
return {255, 0, 0}; // red
}
}

View File

@@ -101,7 +101,7 @@ namespace
QSize CheckBoxIconHelper::sizeHint() const
{
const int dim = QCheckBox::sizeHint().height();
return QSize(dim, dim);
return {dim, dim};
}
void CheckBoxIconHelper::initStyleOption(QStyleOptionButton *opt) const
@@ -812,7 +812,7 @@ QStringList TransferListWidget::askTagsForSelection(const QString &dialogTitle)
const QString tagsInput = AutoExpandableDialog::getText(
this, dialogTitle, tr("Comma-separated tags:"), QLineEdit::Normal, "", &ok).trimmed();
if (!ok || tagsInput.isEmpty())
return QStringList();
return {};
tags = tagsInput.split(',', QString::SkipEmptyParts);
for (QString &tag : tags) {
tag = tag.trimmed();

View File

@@ -96,7 +96,7 @@ QSize Utils::Gui::smallIconSize(const QWidget *widget)
// Get DPI scaled icon size (device-dependent), see QT source
// under a 1080p screen is usually 16x16
const int s = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, widget);
return QSize(s, s);
return {s, s};
}
QSize Utils::Gui::mediumIconSize(const QWidget *widget)
@@ -110,5 +110,5 @@ QSize Utils::Gui::largeIconSize(const QWidget *widget)
// Get DPI scaled icon size (device-dependent), see QT source
// under a 1080p screen is usually 32x32
const int s = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize, nullptr, widget);
return QSize(s, s);
return {s, s};
}