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 setHumanReadableTime(bool human_readable_time);
95  void setDisplayLogger(bool logger_name);
96  void setDisplayFunction(bool function_name);
97  void setColorizeLogs(bool colorize_logs);
98  void setUseRegularExpressions(bool useRegexps);
99 
100  private:
101  void saveBagFile(const QString& filename) const;
102  void saveTextFile(const QString& filename) const;
103  void scheduleIdleProcessing();
104 
105  bool acceptLogEntry(const LogEntry &item);
106  bool testIncludeFilter(const LogEntry &item);
107 
108  std::set<std::string> names_;
109  uint8_t severity_mask_;
117 
118  // For performance reasons, the proxy model presents single line
119  // items, while the underlying log database stores multi-line
120  // messages. The LineMap struct is used to map our item indices to
121  // the log & line that it represents.
122  struct LineMap {
123  size_t log_index;
125 
127  LineMap(size_t log, int line) : log_index(log), line_index(line) {}
128  };
129 
131  std::deque<LineMap> msg_mapping_;
132 
134  std::deque<LineMap> early_mapping_;
135 
138  QStringList include_strings_;
139  QStringList exclude_strings_;
140 
141  QColor debug_color_;
142  QColor info_color_;
143  QColor warn_color_;
144  QColor error_color_;
145  QColor fatal_color_;
147 
148  QString failedSearchText_; // stores last failed search text, used to minimize looping through full data set, VCM 26 April 2017
149  int failedSearchIndex_; // stores last index of failed search text, VCM 26 April 2017
150 
151 };
152 } // swri_console
153 #endif // SWRI_CONSOLE_LOG_DATABASE_PROXY_MODEL_H_
swri_console::LogDatabaseProxyModel::setExcludeFilters
void setExcludeFilters(const QStringList &list)
Definition: log_database_proxy_model.cpp:212
swri_console::LogDatabaseProxyModel::include_regexp_
QRegExp include_regexp_
Definition: log_database_proxy_model.h:136
swri_console::LogDatabaseProxyModel::LineMap::LineMap
LineMap()
Definition: log_database_proxy_model.h:126
swri_console::LogDatabaseProxyModel::saveToFile
void saveToFile(const QString &filename) const
Definition: log_database_proxy_model.cpp:566
swri_console::LogDatabaseProxyModel::reset
void reset()
Definition: log_database_proxy_model.cpp:554
swri_console::LogDatabaseProxyModel::failedSearchIndex_
int failedSearchIndex_
Definition: log_database_proxy_model.h:149
swri_console::LogDatabaseProxyModel::use_regular_expressions_
bool use_regular_expressions_
Definition: log_database_proxy_model.h:116
swri_console::LogDatabaseProxyModel::rowCount
virtual int rowCount(const QModelIndex &parent) const
Definition: log_database_proxy_model.cpp:278
swri_console::LogDatabaseProxyModel::human_readable_time_
bool human_readable_time_
Definition: log_database_proxy_model.h:113
swri_console::LogDatabaseProxyModel::getItemIndex
int getItemIndex(const QString searchText, int index, int increment)
Definition: log_database_proxy_model.cpp:308
swri_console::LogDatabaseProxyModel::include_strings_
QStringList include_strings_
Definition: log_database_proxy_model.h:138
swri_console::LogDatabaseProxyModel::setIncludeFilters
void setIncludeFilters(const QStringList &list)
Definition: log_database_proxy_model.cpp:203
swri_console::LogDatabaseProxyModel::fatal_color_
QColor fatal_color_
Definition: log_database_proxy_model.h:145
swri_console::LogDatabaseProxyModel::LineMap::log_index
size_t log_index
Definition: log_database_proxy_model.h:123
swri_console::LogDatabaseProxyModel::display_logger_
bool display_logger_
Definition: log_database_proxy_model.h:114
swri_console::LogDatabaseProxyModel::saveTextFile
void saveTextFile(const QString &filename) const
Definition: log_database_proxy_model.cpp:615
swri_console::LogDatabaseProxyModel::setExcludeRegexpPattern
void setExcludeRegexpPattern(const QString &pattern)
Definition: log_database_proxy_model.cpp:230
swri_console::LogDatabaseProxyModel::isIncludeValid
bool isIncludeValid() const
Definition: log_database_proxy_model.cpp:288
swri_console::LogDatabaseProxyModel::setFatalColor
void setFatalColor(const QColor &fatal_color)
Definition: log_database_proxy_model.cpp:270
swri_console::LogDatabaseProxyModel::setDebugColor
void setDebugColor(const QColor &debug_color)
Definition: log_database_proxy_model.cpp:238
swri_console::LogDatabaseProxyModel::display_absolute_time_
bool display_absolute_time_
Definition: log_database_proxy_model.h:112
swri_console::LogDatabaseProxyModel::LogDatabaseProxyModel
LogDatabaseProxyModel(LogDatabase *db)
Definition: log_database_proxy_model.cpp:54
swri_console::LogDatabaseProxyModel::messagesAdded
void messagesAdded()
swri_console::LogDatabaseProxyModel::setWarnColor
void setWarnColor(const QColor &warn_color)
Definition: log_database_proxy_model.cpp:254
swri_console::LogDatabaseProxyModel::exclude_strings_
QStringList exclude_strings_
Definition: log_database_proxy_model.h:139
swri_console::LogDatabaseProxyModel::testIncludeFilter
bool testIncludeFilter(const LogEntry &item)
Definition: log_database_proxy_model.cpp:755
swri_console::LogDatabaseProxyModel::saveBagFile
void saveBagFile(const QString &filename) const
Definition: log_database_proxy_model.cpp:576
swri_console::LogEntry
Definition: log_database.h:43
swri_console::LogDatabaseProxyModel::ExtendedLogRole
@ ExtendedLogRole
Definition: log_database_proxy_model.h:55
swri_console::LogDatabaseProxyModel::warn_color_
QColor warn_color_
Definition: log_database_proxy_model.h:143
swri_console::LogDatabaseProxyModel::names_
std::set< std::string > names_
Definition: log_database_proxy_model.h:108
swri_console::LogDatabaseProxyModel::display_time_
bool display_time_
Definition: log_database_proxy_model.h:111
swri_console::LogDatabaseProxyModel::setAbsoluteTime
void setAbsoluteTime(bool absolute)
Definition: log_database_proxy_model.cpp:97
swri_console::LogDatabaseProxyModel::handleDatabaseCleared
void handleDatabaseCleared()
Definition: log_database_proxy_model.cpp:629
swri_console::LogDatabaseProxyModel::severity_mask_
uint8_t severity_mask_
Definition: log_database_proxy_model.h:109
swri_console::LogDatabaseProxyModel::~LogDatabaseProxyModel
~LogDatabaseProxyModel()
Definition: log_database_proxy_model.cpp:81
swri_console::LogDatabaseProxyModel::setColorizeLogs
void setColorizeLogs(bool colorize_logs)
Definition: log_database_proxy_model.cpp:128
swri_console::LogDatabaseProxyModel::setIncludeRegexpPattern
void setIncludeRegexpPattern(const QString &pattern)
Definition: log_database_proxy_model.cpp:222
swri_console::LogDatabaseProxyModel::minTimeUpdated
void minTimeUpdated()
Definition: log_database_proxy_model.cpp:774
swri_console::LogDatabaseProxyModel::error_color_
QColor error_color_
Definition: log_database_proxy_model.h:144
swri_console::LogDatabaseProxyModel::clearSearchFailure
void clearSearchFailure()
Definition: log_database_proxy_model.cpp:377
swri_console::LogDatabaseProxyModel::display_function_
bool display_function_
Definition: log_database_proxy_model.h:115
swri_console::LogDatabaseProxyModel::setDisplayFunction
void setDisplayFunction(bool function_name)
Definition: log_database_proxy_model.cpp:175
swri_console::LogDatabaseProxyModel::setUseRegularExpressions
void setUseRegularExpressions(bool useRegexps)
Definition: log_database_proxy_model.cpp:191
swri_console::LogDatabaseProxyModel::LineMap::LineMap
LineMap(size_t log, int line)
Definition: log_database_proxy_model.h:127
swri_console::LogDatabase
Definition: log_database.h:55
swri_console::LogDatabaseProxyModel::failedSearchText_
QString failedSearchText_
Definition: log_database_proxy_model.h:148
swri_console::LogDatabaseProxyModel::setSeverityFilter
void setSeverityFilter(uint8_t severity_mask)
Definition: log_database_proxy_model.cpp:91
swri_console::LogDatabaseProxyModel::isExcludeValid
bool isExcludeValid() const
Definition: log_database_proxy_model.cpp:296
swri_console::LogDatabaseProxyModel::acceptLogEntry
bool acceptLogEntry(const LogEntry &item)
Definition: log_database_proxy_model.cpp:720
swri_console::LogDatabaseProxyModel::earliest_log_index_
size_t earliest_log_index_
Definition: log_database_proxy_model.h:133
swri_console::LogDatabaseProxyModel::colorize_logs_
bool colorize_logs_
Definition: log_database_proxy_model.h:110
swri_console
Definition: bag_reader.h:40
swri_console::LogDatabaseProxyModel::setDisplayTime
void setDisplayTime(bool display)
Definition: log_database_proxy_model.cpp:143
swri_console::LogDatabaseProxyModel::early_mapping_
std::deque< LineMap > early_mapping_
Definition: log_database_proxy_model.h:134
swri_console::LogDatabaseProxyModel
Definition: log_database_proxy_model.h:49
swri_console::LogDatabaseProxyModel::processOldMessages
void processOldMessages()
Definition: log_database_proxy_model.cpp:668
swri_console::LogDatabaseProxyModel::LineMap::line_index
int line_index
Definition: log_database_proxy_model.h:124
swri_console::LogDatabaseProxyModel::setErrorColor
void setErrorColor(const QColor &error_color)
Definition: log_database_proxy_model.cpp:262
swri_console::LogDatabaseProxyModel::processNewMessages
void processNewMessages()
Definition: log_database_proxy_model.cpp:635
swri_console::LogDatabaseProxyModel::latest_log_index_
size_t latest_log_index_
Definition: log_database_proxy_model.h:130
swri_console::LogDatabaseProxyModel::setDisplayLogger
void setDisplayLogger(bool logger_name)
Definition: log_database_proxy_model.cpp:159
swri_console::LogDatabaseProxyModel::scheduleIdleProcessing
void scheduleIdleProcessing()
Definition: log_database_proxy_model.cpp:711
swri_console::LogDatabaseProxyModel::info_color_
QColor info_color_
Definition: log_database_proxy_model.h:142
swri_console::LogDatabaseProxyModel::setNodeFilter
void setNodeFilter(const std::set< std::string > &names)
Definition: log_database_proxy_model.cpp:85
swri_console::LogDatabaseProxyModel::setInfoColor
void setInfoColor(const QColor &info_color)
Definition: log_database_proxy_model.cpp:246
swri_console::LogDatabaseProxyModel::db_
LogDatabase * db_
Definition: log_database_proxy_model.h:146
swri_console::LogDatabaseProxyModel::msg_mapping_
std::deque< LineMap > msg_mapping_
Definition: log_database_proxy_model.h:131
swri_console::LogDatabaseProxyModel::exclude_regexp_
QRegExp exclude_regexp_
Definition: log_database_proxy_model.h:137
swri_console::LogDatabaseProxyModel::debug_color_
QColor debug_color_
Definition: log_database_proxy_model.h:141
swri_console::LogDatabaseProxyModel::setHumanReadableTime
void setHumanReadableTime(bool human_readable_time)
Definition: log_database_proxy_model.cpp:112
swri_console::LogDatabaseProxyModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: log_database_proxy_model.cpp:384
swri_console::LogDatabaseProxyModel::LineMap
Definition: log_database_proxy_model.h:122


swri_console
Author(s): P. J. Reed , Jerry Towler , David Anthony
autogenerated on Sat Sep 23 2023 02:55:36