| 1 | /* |
| 2 | * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) |
| 3 | * |
| 4 | * This program is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation, either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | #ifndef ISSUESTABLE_H |
| 18 | #define ISSUESTABLE_H |
| 19 | |
| 20 | #include <QTableView> |
| 21 | #include <vector> |
| 22 | #include "../common.h" |
| 23 | #include <QAbstractTableModel> |
| 24 | |
| 25 | class IssuesModel : public QAbstractTableModel { |
| 26 | |
| 27 | Q_OBJECT |
| 28 | public: |
| 29 | explicit IssuesModel(QObject *parent = nullptr); |
| 30 | |
| 31 | public slots: |
| 32 | void addIssue(PCompileIssue issue); |
| 33 | void clearIssues(); |
| 34 | |
| 35 | void setErrorColor(QColor color); |
| 36 | void setWarningColor(QColor color); |
| 37 | PCompileIssue issue(int row); |
| 38 | private: |
| 39 | QVector<PCompileIssue> mIssues; |
| 40 | QColor mErrorColor; |
| 41 | QColor mWarningColor; |
| 42 | |
| 43 | // QAbstractItemModel interface |
| 44 | public: |
| 45 | int count(); |
| 46 | int rowCount(const QModelIndex &parent) const override; |
| 47 | int columnCount(const QModelIndex &parent) const override; |
| 48 | QVariant data(const QModelIndex &index, int role) const override; |
| 49 | QVariant (int section, Qt::Orientation orientation, int role) const override; |
| 50 | const QVector<PCompileIssue> &issues() const; |
| 51 | }; |
| 52 | |
| 53 | class IssuesTable : public QTableView |
| 54 | { |
| 55 | Q_OBJECT |
| 56 | public: |
| 57 | |
| 58 | explicit IssuesTable(QWidget* parent = nullptr); |
| 59 | |
| 60 | const QVector<PCompileIssue> & issues() const; |
| 61 | |
| 62 | IssuesModel* issuesModel(); |
| 63 | |
| 64 | void setErrorColor(QColor color); |
| 65 | void setWarningColor(QColor color); |
| 66 | QString toHtml(); |
| 67 | QString toTxt(); |
| 68 | |
| 69 | public slots: |
| 70 | void addIssue(PCompileIssue issue); |
| 71 | |
| 72 | PCompileIssue issue(const QModelIndex& index); |
| 73 | PCompileIssue issue(const int row); |
| 74 | int count(); |
| 75 | |
| 76 | void clearIssues(); |
| 77 | |
| 78 | private: |
| 79 | IssuesModel * mModel; |
| 80 | }; |
| 81 | |
| 82 | #endif // ISSUESTABLE_H |
| 83 | |