Fix transfer list architecture

Model returns string for DisplayRole.
Text alignment is set by Model (using TextAlignmentRole).
Delegate performs custom painting only where necessary
(i.e. for Progress bar).
This commit is contained in:
Vladimir Golovnev (Glassez)
2019-12-17 21:57:36 +03:00
parent 18de63f743
commit 766cfb67df
6 changed files with 375 additions and 346 deletions

View File

@@ -34,11 +34,11 @@
#include <QColor>
#include <QList>
#include "base/bittorrent/torrenthandle.h"
namespace BitTorrent
{
class InfoHash;
class TorrentHandle;
enum class TorrentState;
}
class TransferListModel : public QAbstractListModel
@@ -84,6 +84,12 @@ public:
NB_COLUMNS
};
enum DataRole
{
UnderlyingDataRole = Qt::UserRole,
AdditionalUnderlyingDataRole
};
explicit TransferListModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = {}) const override;
@@ -105,9 +111,12 @@ private slots:
void handleTorrentsUpdated(const QVector<BitTorrent::TorrentHandle *> &torrents);
private:
QString displayValue(const BitTorrent::TorrentHandle *torrent, int column) const;
QVariant internalValue(const BitTorrent::TorrentHandle *torrent, int column, bool alt = false) const;
QList<BitTorrent::TorrentHandle *> m_torrentList; // maps row number to torrent handle
QHash<BitTorrent::TorrentHandle *, int> m_torrentMap; // maps torrent handle to row number
const QHash<BitTorrent::TorrentState, QString> m_statusStrings;
// row text colors
QHash<BitTorrent::TorrentState, QColor> m_stateForegroundColors;
};