mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-02 09:55:55 +00:00
Code clean up
This commit is contained in:
parent
2de4c50d4f
commit
d5898f024d
@ -109,7 +109,7 @@ QVariant TorrentModelItem::data(int column, int role) const
|
|||||||
if(role == Qt::ForegroundRole) {
|
if(role == Qt::ForegroundRole) {
|
||||||
return m_fgColor;
|
return m_fgColor;
|
||||||
}
|
}
|
||||||
if(role != Qt::DisplayRole) return QVariant();
|
if(role != Qt::DisplayRole && role != Qt::UserRole) return QVariant();
|
||||||
switch(column) {
|
switch(column) {
|
||||||
case TR_NAME:
|
case TR_NAME:
|
||||||
return m_name;
|
return m_name;
|
||||||
@ -122,21 +122,10 @@ QVariant TorrentModelItem::data(int column, int role) const
|
|||||||
case TR_STATUS:
|
case TR_STATUS:
|
||||||
return state();
|
return state();
|
||||||
case TR_SEEDS: {
|
case TR_SEEDS: {
|
||||||
// XXX: Probably a better way to do this
|
return (role == Qt::DisplayRole) ? m_torrent.num_seeds() : m_torrent.num_complete();
|
||||||
qulonglong seeds = m_torrent.num_seeds()*1000000;
|
|
||||||
if(m_torrent.num_complete() >= m_torrent.num_seeds())
|
|
||||||
seeds += m_torrent.num_complete()*10;
|
|
||||||
else
|
|
||||||
seeds += 1;
|
|
||||||
return seeds;
|
|
||||||
}
|
}
|
||||||
case TR_PEERS: {
|
case TR_PEERS: {
|
||||||
qulonglong peers = (m_torrent.num_peers()-m_torrent.num_seeds())*1000000;
|
return (role == Qt::DisplayRole) ? (m_torrent.num_peers()-m_torrent.num_seeds()) : m_torrent.num_incomplete();
|
||||||
if(m_torrent.num_incomplete() >= (m_torrent.num_peers()-m_torrent.num_seeds()))
|
|
||||||
peers += m_torrent.num_incomplete()*10;
|
|
||||||
else
|
|
||||||
peers += 1;
|
|
||||||
return peers;
|
|
||||||
}
|
}
|
||||||
case TR_DLSPEED:
|
case TR_DLSPEED:
|
||||||
return m_torrent.download_payload_rate();
|
return m_torrent.download_payload_rate();
|
||||||
|
@ -42,7 +42,7 @@ private:
|
|||||||
QString m_name;
|
QString m_name;
|
||||||
mutable QIcon m_icon;
|
mutable QIcon m_icon;
|
||||||
mutable QColor m_fgColor;
|
mutable QColor m_fgColor;
|
||||||
QString m_hash;
|
QString m_hash; // Cached for safety reasons
|
||||||
};
|
};
|
||||||
|
|
||||||
class TorrentModel : public QAbstractListModel
|
class TorrentModel : public QAbstractListModel
|
||||||
@ -56,7 +56,7 @@ public:
|
|||||||
inline int rowCount(const QModelIndex& index = QModelIndex()) const { Q_UNUSED(index); return m_torrents.size(); }
|
inline int rowCount(const QModelIndex& index = QModelIndex()) const { Q_UNUSED(index); return m_torrents.size(); }
|
||||||
int columnCount(const QModelIndex &parent=QModelIndex()) const { Q_UNUSED(parent); return TorrentModelItem::NB_COLUMNS; }
|
int columnCount(const QModelIndex &parent=QModelIndex()) const { Q_UNUSED(parent); return TorrentModelItem::NB_COLUMNS; }
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole);
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||||
int torrentRow(const QString &hash) const;
|
int torrentRow(const QString &hash) const;
|
||||||
QString torrentHash(int row) const;
|
QString torrentHash(int row) const;
|
||||||
|
@ -73,11 +73,10 @@ public:
|
|||||||
}
|
}
|
||||||
case TorrentModelItem::TR_SEEDS:
|
case TorrentModelItem::TR_SEEDS:
|
||||||
case TorrentModelItem::TR_PEERS: {
|
case TorrentModelItem::TR_PEERS: {
|
||||||
const qulonglong tot_val = index.data().toULongLong();
|
QString display = QString::number(index.data().toLongLong());
|
||||||
QString display = QString::number((qulonglong)tot_val/1000000);
|
if(index.data(Qt::UserRole).toLongLong() > 0) {
|
||||||
if(tot_val%2 == 0) {
|
|
||||||
// Scrape was successful, we have total values
|
// Scrape was successful, we have total values
|
||||||
display += " ("+QString::number((qulonglong)(tot_val%1000000)/10)+")";
|
display += " ("+QString::number(index.data(Qt::UserRole).toLongLong())+")";
|
||||||
}
|
}
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
opt.displayAlignment = Qt::AlignRight;
|
opt.displayAlignment = Qt::AlignRight;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user