Improve coding style

This commit is contained in:
Vladimir Golovnev (Glassez) 2020-11-16 10:02:11 +03:00
parent acad35c5bc
commit c41df9ffbd
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7
147 changed files with 4454 additions and 2227 deletions

View file

@ -92,7 +92,8 @@ namespace
};
QHash<BitTorrent::TorrentState, QColor> colors;
for (const TorrentStateColorDescriptor &colorDescriptor : colorDescriptors) {
for (const TorrentStateColorDescriptor &colorDescriptor : colorDescriptors)
{
const QColor themeColor = UIThemeManager::instance()->getColor(colorDescriptor.id, QColor());
if (themeColor.isValid())
colors.insert(colorDescriptor.state, themeColor);
@ -105,7 +106,8 @@ namespace
TransferListModel::TransferListModel(QObject *parent)
: QAbstractListModel {parent}
, m_statusStrings {
, m_statusStrings
{
{BitTorrent::TorrentState::Downloading, tr("Downloading")},
{BitTorrent::TorrentState::StalledDownloading, tr("Stalled", "Torrent is waiting for download to begin")},
{BitTorrent::TorrentState::DownloadingMetadata, tr("Downloading metadata", "Used when loading a magnet link")},
@ -158,9 +160,12 @@ int TransferListModel::columnCount(const QModelIndex &) const
QVariant TransferListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal) {
if (role == Qt::DisplayRole) {
switch (section) {
if (orientation == Qt::Horizontal)
{
if (role == Qt::DisplayRole)
{
switch (section)
{
case TR_QUEUE_POSITION: return QChar('#');
case TR_NAME: return tr("Name", "i.e: torrent name");
case TR_SIZE: return tr("Size", "i.e: torrent size");
@ -195,8 +200,10 @@ QVariant TransferListModel::headerData(int section, Qt::Orientation orientation,
default: return {};
}
}
else if (role == Qt::TextAlignmentRole) {
switch (section) {
else if (role == Qt::TextAlignmentRole)
{
switch (section)
{
case TR_AMOUNT_DOWNLOADED:
case TR_AMOUNT_UPLOADED:
case TR_AMOUNT_DOWNLOADED_SESSION:
@ -324,7 +331,8 @@ QString TransferListModel::displayValue(const BitTorrent::TorrentHandle *torrent
: m_statusStrings[state];
};
switch (column) {
switch (column)
{
case TR_NAME:
return torrent->name();
case TR_QUEUE_POSITION:
@ -394,7 +402,8 @@ QString TransferListModel::displayValue(const BitTorrent::TorrentHandle *torrent
QVariant TransferListModel::internalValue(const BitTorrent::TorrentHandle *torrent, const int column, const bool alt) const
{
switch (column) {
switch (column)
{
case TR_NAME:
return torrent->name();
case TR_QUEUE_POSITION:
@ -469,7 +478,8 @@ QVariant TransferListModel::data(const QModelIndex &index, const int role) const
const BitTorrent::TorrentHandle *torrent = m_torrentList.value(index.row());
if (!torrent) return {};
switch (role) {
switch (role)
{
case Qt::ForegroundRole:
return m_stateThemeColors.value(torrent->state(), getDefaultColorByState(torrent->state()));
case Qt::DisplayRole:
@ -483,7 +493,8 @@ QVariant TransferListModel::data(const QModelIndex &index, const int role) const
return getIconByState(torrent->state());
break;
case Qt::ToolTipRole:
switch (index.column()) {
switch (index.column())
{
case TR_NAME:
case TR_STATUS:
case TR_CATEGORY:
@ -494,7 +505,8 @@ QVariant TransferListModel::data(const QModelIndex &index, const int role) const
}
break;
case Qt::TextAlignmentRole:
switch (index.column()) {
switch (index.column())
{
case TR_AMOUNT_DOWNLOADED:
case TR_AMOUNT_UPLOADED:
case TR_AMOUNT_DOWNLOADED_SESSION:
@ -530,7 +542,8 @@ bool TransferListModel::setData(const QModelIndex &index, const QVariant &value,
if (!torrent) return false;
// Category and Name columns can be edited
switch (index.column()) {
switch (index.column())
{
case TR_NAME:
torrent->setName(value.toString());
break;
@ -579,7 +592,8 @@ void TransferListModel::handleTorrentAboutToBeRemoved(BitTorrent::TorrentHandle
beginRemoveRows({}, row, row);
m_torrentList.removeAt(row);
m_torrentMap.remove(torrent);
for (int &value : m_torrentMap) {
for (int &value : m_torrentMap)
{
if (value > row)
--value;
}
@ -598,15 +612,18 @@ void TransferListModel::handleTorrentsUpdated(const QVector<BitTorrent::TorrentH
{
const int columns = (columnCount() - 1);
if (torrents.size() <= (m_torrentList.size() * 0.5)) {
for (BitTorrent::TorrentHandle *const torrent : torrents) {
if (torrents.size() <= (m_torrentList.size() * 0.5))
{
for (BitTorrent::TorrentHandle *const torrent : torrents)
{
const int row = m_torrentMap.value(torrent, -1);
Q_ASSERT(row >= 0);
emit dataChanged(index(row, 0), index(row, columns));
}
}
else {
else
{
// save the overhead when more than half of the torrent list needs update
emit dataChanged(index(0, 0), index((rowCount() - 1), columns));
}
@ -617,14 +634,16 @@ void TransferListModel::configure()
const Preferences *pref = Preferences::instance();
HideZeroValuesMode hideZeroValuesMode = HideZeroValuesMode::Never;
if (pref->getHideZeroValues()) {
if (pref->getHideZeroValues())
{
if (pref->getHideZeroComboValues() == 1)
hideZeroValuesMode = HideZeroValuesMode::Paused;
else
hideZeroValuesMode = HideZeroValuesMode::Always;
}
if (m_hideZeroValuesMode != hideZeroValuesMode) {
if (m_hideZeroValuesMode != hideZeroValuesMode)
{
m_hideZeroValuesMode = hideZeroValuesMode;
emit dataChanged(index(0, 0), index((rowCount() - 1), (columnCount() - 1)));
}
@ -634,7 +653,8 @@ void TransferListModel::configure()
QIcon getIconByState(const BitTorrent::TorrentState state)
{
switch (state) {
switch (state)
{
case BitTorrent::TorrentState::Downloading:
case BitTorrent::TorrentState::ForcedDownloading:
case BitTorrent::TorrentState::DownloadingMetadata:
@ -673,7 +693,8 @@ QColor getDefaultColorByState(const BitTorrent::TorrentState state)
// Color names taken from http://cloford.com/resources/colours/500col.htm
bool dark = isDarkTheme();
switch (state) {
switch (state)
{
case BitTorrent::TorrentState::Downloading:
case BitTorrent::TorrentState::ForcedDownloading:
case BitTorrent::TorrentState::DownloadingMetadata: