File indexing completed on 2024-05-05 05:48:57

0001 /*
0002     SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 
0011 #include "analyzer.h"
0012 #include "globals.h"
0013 
0014 class LogLine;
0015 class LogViewWidget;
0016 
0017 class LogViewModel : public QObject
0018 {
0019     Q_OBJECT
0020 
0021 public:
0022     explicit LogViewModel(LogViewWidget *logViewWidget);
0023 
0024     ~LogViewModel() override;
0025 
0026     /**
0027      * Clear the model
0028      */
0029     void clear();
0030 
0031     bool insertNewLogLine(LogLine *line);
0032 
0033     int itemCount() const;
0034     bool isEmpty() const;
0035 
0036     bool isProcessingMultipleInsertions() const;
0037 
0038     void startingMultipleInsertions();
0039     void endingMultipleInsertions(Analyzer::ReadingMode readingMode, int insertedLogLineCount);
0040 
0041     QList<LogLine *> logLines() const;
0042 
0043 Q_SIGNALS:
0044     void processingMultipleInsertions(bool currentlyInserting);
0045 
0046 private:
0047     /**
0048      * Prevent crossed multiple insertions between each LogFileReaders
0049      */
0050     bool lockMultipleInsertions();
0051 
0052     bool logLineAlreadyExists(LogLine *line) const;
0053 
0054     bool isNewer(LogLine *line) const;
0055 
0056     /**
0057      * Remove the oldest line
0058      */
0059     void removeOldestLogLine();
0060 
0061     /**
0062      * Insert this line
0063      */
0064     void insert(LogLine *line);
0065 
0066     /**
0067      * Remove recent status on previously new log lines
0068      */
0069     void removeRecentStatusOfLogLines();
0070 
0071     LogViewWidget *mLogViewWidget = nullptr;
0072 
0073     LogViewWidgetItem *mOldestItem = nullptr;
0074 
0075     int mConcurrentMultipleInsertions = 0;
0076 };