File indexing completed on 2024-05-19 05:42:13

0001 // ct_lvtmdl_debugmodel.h                                -*-C++-*-
0002 
0003 /*
0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>
0005 // SPDX-License-Identifier: Apache-2.0
0006 //
0007 // Licensed under the Apache License, Version 2.0 (the "License");
0008 // you may not use this file except in compliance with the License.
0009 // You may obtain a copy of the License at
0010 //
0011 //     http://www.apache.org/licenses/LICENSE-2.0
0012 //
0013 // Unless required by applicable law or agreed to in writing, software
0014 // distributed under the License is distributed on an "AS IS" BASIS,
0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 // See the License for the specific language governing permissions and
0017 // limitations under the License.
0018 */
0019 
0020 #ifndef DEFINED_CT_LVTMDL_DEBUGMODEL
0021 #define DEFINED_CT_LVTMDL_DEBUGMODEL
0022 
0023 #include <lvtmdl_export.h>
0024 
0025 #include <QAbstractTableModel>
0026 #include <QSortFilterProxyModel>
0027 
0028 #include <QString>
0029 #include <memory>
0030 
0031 #include <ct_lvtshr_graphenums.h>
0032 
0033 namespace Codethink::lvtmdl {
0034 
0035 struct LVTMDL_EXPORT DebugData {
0036     QtMsgType type = QtSystemMsg;
0037     QString file;
0038     QString line;
0039     QString category;
0040     QString function;
0041     int version = 0;
0042     QString message;
0043 };
0044 
0045 class LVTMDL_EXPORT DebugModel : public QAbstractTableModel {
0046     Q_OBJECT
0047   public:
0048     enum Columns { e_TYPE, e_FILE, e_LINE, e_CATEGORY, e_FUNCTION, e_VERSION, e_MESSAGE, COUNT };
0049 
0050     DebugModel();
0051     ~DebugModel() override;
0052 
0053     void clear();
0054     // clear the model.
0055 
0056     void addData(const DebugData& data);
0057     [[nodiscard]] int rowCount(const QModelIndex& parent = QModelIndex()) const override;
0058     [[nodiscard]] int columnCount(const QModelIndex& parent = QModelIndex()) const override;
0059     [[nodiscard]] QVariant data(const QModelIndex& idx, int role) const override;
0060     [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0061     [[nodiscard]] bool saveAs(const QString& filename) const;
0062     static void debugMessageHandler(QtMsgType msgType, const QMessageLogContext& context, const QString& message);
0063     struct Private;
0064     std::unique_ptr<Private> d;
0065 };
0066 
0067 class LVTMDL_EXPORT DebugModelFilter : public QSortFilterProxyModel {
0068   public:
0069     DebugModelFilter();
0070     ~DebugModelFilter() override;
0071 
0072     [[nodiscard]] bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
0073     [[nodiscard]] bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override;
0074 
0075     void setFilterDebug(bool filter);
0076     void setFilterWarning(bool filter);
0077     void setFilterInfo(bool filter);
0078     void setFilterCrtical(bool filter);
0079     void setFilterFatal(bool filter);
0080 
0081     void setIgnoreCategoriesModel(QAbstractItemModel *model);
0082     // Sets the model with the list of strings that will be used to filter
0083     // categories out
0084 
0085     void setFilterString(const QString& str);
0086     // Use this string to match the messages that will be filtered on the view
0087 
0088     void setInvertMessageFilter(bool value);
0089     // If true, return messages that don't match the string
0090     // if false, return messages that match the string.
0091   private:
0092     struct Private;
0093     std::unique_ptr<Private> d;
0094 };
0095 
0096 } // namespace Codethink::lvtmdl
0097 
0098 #endif