1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #ifndef ENVIRONMENTVIEW_H |
6 | #define ENVIRONMENTVIEW_H |
7 | |
8 | #include <QAbstractTableModel> |
9 | #include <QWidget> |
10 | |
11 | class EnvironmentModelPrivate; |
12 | class EnvironmentModel : public QAbstractTableModel |
13 | { |
14 | Q_OBJECT |
15 | public: |
16 | enum ColumnType |
17 | { |
18 | Key, |
19 | Value, |
20 | ColumnCount |
21 | }; |
22 | |
23 | explicit EnvironmentModel(QObject *parent = nullptr); |
24 | ~EnvironmentModel() override; |
25 | |
26 | int rowCount(const QModelIndex &) const override; |
27 | int columnCount(const QModelIndex &) const override; |
28 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
29 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; |
30 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
31 | QVariant (int section, Qt::Orientation orientation, int role) const override; |
32 | |
33 | void append(const QString &key, const QVariant &value); |
34 | void remove(QModelIndex &index); |
35 | void update(const QMap<QString, QVariant> &data); |
36 | const QMap<QString, QVariant> getEnvironment() const; |
37 | |
38 | private: |
39 | EnvironmentModelPrivate *const d; |
40 | }; |
41 | |
42 | class EnvironmentViewPrivate; |
43 | class EnvironmentView : public QWidget |
44 | { |
45 | Q_OBJECT |
46 | public: |
47 | explicit EnvironmentView(QWidget *parent = nullptr); |
48 | ~EnvironmentView(); |
49 | |
50 | const QMap<QString, QVariant> getEnvironment(); |
51 | void appendRow(); |
52 | void deleteRow(); |
53 | void initModel(); |
54 | void setValue(const QMap<QString, QVariant> &map); |
55 | |
56 | signals: |
57 | void deleteSignal(bool enable); |
58 | |
59 | private: |
60 | |
61 | EnvironmentViewPrivate *const d; |
62 | }; |
63 | |
64 | #endif // ENVIRONMENTVIEW_H |
65 | |