LogTableModel.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::
17* @author Mirko Waechter ( mirko.waechter at kit dot edu)
18* @date 2012
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#pragma once
24
25#include <QAbstractTableModel>
26
27// ArmarX
30#include <ArmarXCore/interface/core/Log.h>
31
32// C++
33#include <mutex>
34#include <vector>
35
36namespace armarx
37{
38 class LogTableModel : public QAbstractTableModel
39 {
40 Q_OBJECT
41 public:
42 enum class UserRoles : int
43 {
44 FullMsgRole = Qt::UserRole + 1
45 };
46
47 explicit LogTableModel(QObject* parent = 0);
48 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
49 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
50 QVariant data(const QModelIndex& index, int role) const override;
51 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
52 bool setData(const QModelIndex& index, const QVariant& value, int role) override;
53 Qt::ItemFlags flags(const QModelIndex& index) const override;
54 void updateView();
55 bool insertRows(int row, int count, const QModelIndex& parent) override;
56
57 void addFilter(const std::string& columnName, const std::string& filter);
58 void reapplyAllFilters();
59 void resetFilters();
60 bool rowContainsString(int row, const QString& searchStr) const;
61 bool msgContainsString(const LogMessage& logMsg, QString searchStr) const;
62 bool rowContainsSameContent(int row, const LogMessage& logMsg) const;
63
64 void search(const QString& searchStr);
65
66 QString
68 {
69 return activeSearchStr;
70 }
71
72 MessageType
74 {
75 return maxNewLogLevelType;
76 }
77
78 int getColumn(const std::string& columnName) const;
79 int clearData();
80
81 const std::vector<std::pair<std::string, std::string>>&
82 getFilters() const
83 {
84 return activeFilters;
85 }
86
87 // thread-unsafe access!
88 const LogMessage& getLogEntry(size_t row) const;
89
90
91 signals:
92
93 protected slots:
94
95 public slots:
96 bool addEntry(const LogMessage& entry, int* entriesAdded = NULL);
97 int addEntries(const std::vector<LogMessage>& entryList, const QString& filterStr);
98
99 protected:
100 bool applyFilter(std::pair<std::string, std::string> filter, const LogMessage& logMsg);
101 // bool applyFilter(std::pair<std::string, std::string> filter, int row);
102 bool applyFilter(std::string filter, int row, int column);
103 bool applyFilters(int row);
104 bool applyFilters(const LogMessage& logMsg);
105
106 private:
107 QString activeSearchStr;
108 int newEntryCount;
109 MessageType maxNewLogLevelType;
110 std::vector<std::pair<std::string, std::string>> activeFilters;
111
112 std::vector<LogMessage> logEntries;
113 std::vector<bool> rowMatchesSearch;
114 mutable std::mutex logEntriesMutex;
115
117 };
118} // namespace armarx
uint8_t index
MessageType getMaxNewLogLevelType()
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
LogTableModel(QObject *parent=0)
const std::vector< std::pair< std::string, std::string > > & getFilters() const
bool setData(const QModelIndex &index, const QVariant &value, int role) override
int addEntries(const std::vector< LogMessage > &entryList, const QString &filterStr)
bool insertRows(int row, int count, const QModelIndex &parent) override
void addFilter(const std::string &columnName, const std::string &filter)
bool rowContainsSameContent(int row, const LogMessage &logMsg) const
QString getCurrentSearchStr()
const LogMessage & getLogEntry(size_t row) const
int columnCount(const QModelIndex &parent=QModelIndex()) const override
int getColumn(const std::string &columnName) const
bool addEntry(const LogMessage &entry, int *entriesAdded=NULL)
bool msgContainsString(const LogMessage &logMsg, QString searchStr) const
bool rowContainsString(int row, const QString &searchStr) const
bool applyFilter(std::pair< std::string, std::string > filter, const LogMessage &logMsg)
void search(const QString &searchStr)
IceUtil::Handle< RunningTask< T > > pointer_type
Shared pointer type for convenience.
This file offers overloads of toIce() and fromIce() functions for STL container types.