Add option to auto hide zero status filters
[qBittorrent.git] / src / gui / log / logmodel.h
blob4f88bba6257c08884bff9d91a7464ab77a1be568
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2020 Prince Gupta <jagannatharjun11@gmail.com>
4 * Copyright (C) 2019 sledgehammer999 <hammered999@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, the copyright holders give permission to
21 * link this program with the OpenSSL project's "OpenSSL" library (or with
22 * modified versions of it that use the same license as the "OpenSSL" library),
23 * and distribute the linked executables. You must obey the GNU General Public
24 * License in all respects for all of the code used other than "OpenSSL". If you
25 * modify file(s), you may extend this exception to your version of the file(s),
26 * but you are not obligated to do so. If you do not wish to do so, delete this
27 * exception statement from your version.
30 #pragma once
32 #include <boost/circular_buffer.hpp>
34 #include <QAbstractListModel>
35 #include <QColor>
36 #include <QHash>
38 #include "base/logger.h"
40 class BaseLogModel : public QAbstractListModel
42 Q_DISABLE_COPY_MOVE(BaseLogModel)
44 public:
45 enum MessageTypeRole
47 TimeRole = Qt::UserRole,
48 MessageRole,
49 TimeForegroundRole,
50 MessageForegroundRole,
51 TypeRole
54 explicit BaseLogModel(QObject *parent = nullptr);
56 int rowCount(const QModelIndex &parent = {}) const override;
57 int columnCount(const QModelIndex &parent = {}) const override;
58 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
59 void reset();
61 protected:
62 class Message
64 public:
65 Message(const QString &time, const QString &message, const QColor &foreground, Log::MsgType type);
67 QVariant time() const;
68 QVariant message() const;
69 QVariant foreground() const;
70 QVariant type() const;
72 private:
73 QVariant m_time;
74 QVariant m_message;
75 QVariant m_foreground;
76 QVariant m_type;
79 void addNewMessage(const Message &message);
81 private:
82 boost::circular_buffer_space_optimized<Message> m_messages;
83 const QColor m_timeForeground;
86 class LogMessageModel : public BaseLogModel
88 Q_OBJECT
89 Q_DISABLE_COPY_MOVE(LogMessageModel)
91 public:
92 explicit LogMessageModel(QObject *parent = nullptr);
94 private slots:
95 void handleNewMessage(const Log::Msg &message);
97 private:
98 const QHash<int, QColor> m_foregroundForMessageTypes;
101 class LogPeerModel : public BaseLogModel
103 Q_OBJECT
104 Q_DISABLE_COPY_MOVE(LogPeerModel)
106 public:
107 explicit LogPeerModel(QObject *parent = nullptr);
109 private slots:
110 void handleNewMessage(const Log::Peer &peer);
112 private:
113 const QColor m_bannedPeerForeground;