log_database_proxy_model.h
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2015, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL Southwest Research Institute® BE LIABLE 
00021 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00022 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00023 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00024 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00025 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
00026 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00027 // DAMAGE.
00028 //
00029 // *****************************************************************************
00030 
00031 #ifndef SWRI_CONSOLE_LOG_DATABASE_PROXY_MODEL_H_
00032 #define SWRI_CONSOLE_LOG_DATABASE_PROXY_MODEL_H_
00033 
00034 #include <QAbstractListModel>
00035 #include <QColor>
00036 #include <QStringList>
00037 #include <QRegExp>
00038 
00039 #include <stdint.h>
00040 #include <set>
00041 #include <string>
00042 #include <deque>
00043 
00044 namespace swri_console
00045 {
00046 
00047 class LogDatabase;
00048 struct LogEntry;
00049 class LogDatabaseProxyModel : public QAbstractListModel
00050 {
00051   Q_OBJECT
00052  
00053  public:
00054   enum {
00055     ExtendedLogRole = Qt::UserRole + 0
00056   };
00057 
00058   LogDatabaseProxyModel(LogDatabase *db);
00059   ~LogDatabaseProxyModel();
00060 
00061   void setNodeFilter(const std::set<std::string> &names);
00062   void setSeverityFilter(uint8_t severity_mask);
00063   void setIncludeFilters(const QStringList &list);
00064   void setExcludeFilters(const QStringList &list);
00065   void setIncludeRegexpPattern(const QString& pattern);
00066   void setExcludeRegexpPattern(const QString& pattern);
00067   void setDebugColor(const QColor& debug_color);
00068   void setInfoColor(const QColor& info_color);
00069   void setWarnColor(const QColor& warn_color);
00070   void setErrorColor(const QColor& error_color);
00071   void setFatalColor(const QColor& fatal_color);
00072   bool isIncludeValid() const;
00073   bool isExcludeValid() const;
00074   int getItemIndex(const QString searchText, int index, int increment);
00075   void clearSearchFailure();
00076 
00077   virtual int rowCount(const QModelIndex &parent) const;
00078   virtual QVariant data(const QModelIndex &index, int role) const;
00079 
00080   void reset();
00081 
00082   void saveToFile(const QString& filename) const;
00083 
00084  Q_SIGNALS:
00085   void messagesAdded();
00086 
00087  public Q_SLOTS:
00088   void handleDatabaseCleared();
00089   void processNewMessages();
00090   void processOldMessages();
00091   void minTimeUpdated();
00092   void setDisplayTime(bool display);
00093   void setAbsoluteTime(bool absolute);
00094   void setColorizeLogs(bool colorize_logs);
00095   void setUseRegularExpressions(bool useRegexps);
00096 
00097  private:
00098   void saveBagFile(const QString& filename) const;
00099   void saveTextFile(const QString& filename) const;
00100   void scheduleIdleProcessing();
00101   
00102   bool acceptLogEntry(const LogEntry &item);
00103   bool testIncludeFilter(const LogEntry &item);
00104   
00105   std::set<std::string> names_;
00106   uint8_t severity_mask_;
00107   bool colorize_logs_;
00108   bool display_time_;
00109   bool display_absolute_time_;
00110   bool use_regular_expressions_;
00111 
00112   // For performance reasons, the proxy model presents single line
00113   // items, while the underlying log database stores multi-line
00114   // messages.  The LineMap struct is used to map our item indices to
00115   // the log & line that it represents.
00116   struct LineMap {
00117     size_t log_index;
00118     int line_index;
00119 
00120     LineMap() : log_index(0), line_index(0) {}
00121     LineMap(size_t log, int line) : log_index(log), line_index(line) {}
00122   };
00123   
00124   size_t latest_log_index_;
00125   std::deque<LineMap> msg_mapping_;
00126 
00127   size_t earliest_log_index_;
00128   std::deque<LineMap> early_mapping_;
00129 
00130   QRegExp include_regexp_;
00131   QRegExp exclude_regexp_;
00132   QStringList include_strings_;
00133   QStringList exclude_strings_;
00134 
00135   QColor debug_color_;
00136   QColor info_color_;
00137   QColor warn_color_;
00138   QColor error_color_;
00139   QColor fatal_color_;
00140   LogDatabase *db_;
00141 
00142   QString failedSearchText_;  // stores last failed search text, used to minimize looping through full data set, VCM 26 April 2017
00143   int failedSearchIndex_;  // stores last index of failed search text, VCM 26 April 2017
00144 
00145 };
00146 }  // swri_console
00147 #endif  // SWRI_CONSOLE_LOG_DATABASE_PROXY_MODEL_H_


swri_console
Author(s):
autogenerated on Sat Jun 8 2019 18:46:13