1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 18:18:10 +00:00
transmission/qt/TorrentModel.h
Mike Gelfand 3e072f9bd4
Fix most of critical issues reported by Sonar (GTK client) (#2309)
* (C++) Macros should not be used to define constants

* (C++) Memory should not be managed manually

* (C++) "void*" should not be used in typedefs, member variables, function parameters or return type

* (C++) When the "Rule-of-Zero" is not applicable, the "Rule-of-Five" should be followed

* (C++) "switch" statements should have "default" clauses

* (C++) "explicit" should be used on single-parameter constructors and conversiosn operators

* (C++) Non-const global variables should not be used
2021-12-14 11:43:27 +03:00

83 lines
1.9 KiB
C++

/*
* This file Copyright (C) 2010-2015 Mnemosyne LLC
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
*
*/
#pragma once
#include <optional>
#include <vector>
#include <QAbstractListModel>
#include <libtransmission/tr-macros.h>
#include "Torrent.h"
#include "Typedefs.h"
class Prefs;
class Speed;
extern "C"
{
struct tr_variant;
}
class TorrentModel : public QAbstractListModel
{
Q_OBJECT
TR_DISABLE_COPY_MOVE(TorrentModel)
public:
enum Role
{
TorrentRole = Qt::UserRole
};
explicit TorrentModel(Prefs const& prefs);
~TorrentModel() override;
void clear();
bool hasTorrent(TorrentHash const& hash) const;
Torrent* getTorrentFromId(int id);
Torrent const* getTorrentFromId(int id) const;
using torrents_t = std::vector<Torrent*>;
torrents_t const& torrents() const
{
return torrents_;
}
// QAbstractItemModel
int rowCount(QModelIndex const& parent = QModelIndex()) const override;
QVariant data(QModelIndex const& index, int role = Qt::DisplayRole) const override;
public slots:
void updateTorrents(tr_variant* torrent_list, bool is_complete_list);
void removeTorrents(tr_variant* torrent_list);
signals:
void torrentsAdded(torrent_ids_t const&);
void torrentsChanged(torrent_ids_t const&, Torrent::fields_t const& fields);
void torrentsCompleted(torrent_ids_t const&);
void torrentsEdited(torrent_ids_t const&);
void torrentsNeedInfo(torrent_ids_t const&);
private:
void rowsAdd(torrents_t const& torrents);
void rowsRemove(torrents_t const& torrents);
void rowsEmitChanged(torrent_ids_t const& ids);
std::optional<int> getRow(int id) const;
using span_t = std::pair<int, int>;
std::vector<span_t> getSpans(torrent_ids_t const& ids) const;
Prefs const& prefs_;
torrent_ids_t already_added_;
torrents_t torrents_;
};