log_database_proxy_model.h
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2015, Southwest Research Institute® (SwRI®)
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Southwest Research Institute® (SwRI®) nor the
14 // names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL Southwest Research Institute® BE LIABLE
21 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28 //
29 // *****************************************************************************
30 
31 #ifndef SWRI_CONSOLE_LOG_DATABASE_PROXY_MODEL_H_
32 #define SWRI_CONSOLE_LOG_DATABASE_PROXY_MODEL_H_
33 
34 #include <QAbstractListModel>
35 #include <QColor>
36 #include <QStringList>
37 #include <QRegExp>
38 
39 #include <stdint.h>
40 #include <set>
41 #include <string>
42 #include <deque>
43 
44 namespace swri_console
45 {
46 
47 class LogDatabase;
48 struct LogEntry;
49 class LogDatabaseProxyModel : public QAbstractListModel
50 {
51  Q_OBJECT
52 
53  public:
54  enum {
55  ExtendedLogRole = Qt::UserRole + 0
56  };
57 
60 
61  void setNodeFilter(const std::set<std::string> &names);
62  void setSeverityFilter(uint8_t severity_mask);
63  void setIncludeFilters(const QStringList &list);
64  void setExcludeFilters(const QStringList &list);
65  void setIncludeRegexpPattern(const QString& pattern);
66  void setExcludeRegexpPattern(const QString& pattern);
67  void setDebugColor(const QColor& debug_color);
68  void setInfoColor(const QColor& info_color);
69  void setWarnColor(const QColor& warn_color);
70  void setErrorColor(const QColor& error_color);
71  void setFatalColor(const QColor& fatal_color);
72  bool isIncludeValid() const;
73  bool isExcludeValid() const;
74  int getItemIndex(const QString searchText, int index, int increment);
75  void clearSearchFailure();
76 
77  virtual int rowCount(const QModelIndex &parent) const;
78  virtual QVariant data(const QModelIndex &index, int role) const;
79 
80  void reset();
81 
82  void saveToFile(const QString& filename) const;
83 
84  Q_SIGNALS:
85  void messagesAdded();
86 
87  public Q_SLOTS:
88  void handleDatabaseCleared();
89  void processNewMessages();
90  void processOldMessages();
91  void minTimeUpdated();
92  void setDisplayTime(bool display);
93  void setAbsoluteTime(bool absolute);
94  void setColorizeLogs(bool colorize_logs);
95  void setUseRegularExpressions(bool useRegexps);
96 
97  private:
98  void saveBagFile(const QString& filename) const;
99  void saveTextFile(const QString& filename) const;
100  void scheduleIdleProcessing();
101 
102  bool acceptLogEntry(const LogEntry &item);
103  bool testIncludeFilter(const LogEntry &item);
104 
105  std::set<std::string> names_;
106  uint8_t severity_mask_;
111 
112  // For performance reasons, the proxy model presents single line
113  // items, while the underlying log database stores multi-line
114  // messages. The LineMap struct is used to map our item indices to
115  // the log & line that it represents.
116  struct LineMap {
117  size_t log_index;
119 
120  LineMap() : log_index(0), line_index(0) {}
121  LineMap(size_t log, int line) : log_index(log), line_index(line) {}
122  };
123 
125  std::deque<LineMap> msg_mapping_;
126 
128  std::deque<LineMap> early_mapping_;
129 
132  QStringList include_strings_;
133  QStringList exclude_strings_;
134 
135  QColor debug_color_;
136  QColor info_color_;
137  QColor warn_color_;
138  QColor error_color_;
139  QColor fatal_color_;
141 
142  QString failedSearchText_; // stores last failed search text, used to minimize looping through full data set, VCM 26 April 2017
143  int failedSearchIndex_; // stores last index of failed search text, VCM 26 April 2017
144 
145 };
146 } // swri_console
147 #endif // SWRI_CONSOLE_LOG_DATABASE_PROXY_MODEL_H_
void saveBagFile(const QString &filename) const
void setFatalColor(const QColor &fatal_color)
void setIncludeFilters(const QStringList &list)
virtual QVariant data(const QModelIndex &index, int role) const
void setInfoColor(const QColor &info_color)
void setSeverityFilter(uint8_t severity_mask)
void setWarnColor(const QColor &warn_color)
void setErrorColor(const QColor &error_color)
void setExcludeFilters(const QStringList &list)
virtual int rowCount(const QModelIndex &parent) const
void saveTextFile(const QString &filename) const
void saveToFile(const QString &filename) const
void setNodeFilter(const std::set< std::string > &names)
int getItemIndex(const QString searchText, int index, int increment)
void setDebugColor(const QColor &debug_color)
void setExcludeRegexpPattern(const QString &pattern)
void setIncludeRegexpPattern(const QString &pattern)


swri_console
Author(s):
autogenerated on Fri Apr 3 2020 03:20:03