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 COMPILERAUTOLINKWIDGET_H
18#define COMPILERAUTOLINKWIDGET_H
19
20#include <QAbstractTableModel>
21#include <QWidget>
22#include "settingswidget.h"
23#include "../autolinkmanager.h"
24
25namespace Ui {
26class CompilerAutolinkWidget;
27}
28
29class CompilerAutolinkWidget;
30class AutolinkModel: public QAbstractTableModel {
31 Q_OBJECT
32public:
33 explicit AutolinkModel(CompilerAutolinkWidget* widget,QObject* parent=nullptr);
34
35 // QAbstractItemModel interface
36public:
37 int rowCount(const QModelIndex &parent) const override;
38 int columnCount(const QModelIndex &parent) const override;
39 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
40 QVariant data(const QModelIndex &index, int role) const override;
41 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
42 Qt::ItemFlags flags(const QModelIndex &index) const override;
43 bool insertRows(int row, int count, const QModelIndex &parent) override;
44 bool removeRows(int row, int count, const QModelIndex &parent) override;
45
46 const QList<PAutolink> &links() const;
47 void setLinks(const QMap<QString, PAutolink> &newLinks);
48private:
49 int findLink(const QString& header);
50private:
51 QList<PAutolink> mLinks;
52 CompilerAutolinkWidget * mWidget;
53
54};
55
56class CompilerAutolinkWidget : public SettingsWidget
57{
58 Q_OBJECT
59
60public:
61 explicit CompilerAutolinkWidget(const QString& name, const QString& group, QWidget *parent = nullptr);
62 ~CompilerAutolinkWidget();
63
64private:
65 AutolinkModel mModel;
66private:
67 Ui::CompilerAutolinkWidget *ui;
68
69 // SettingsWidget interface
70protected:
71 void doLoad() override;
72 void doSave() override;
73private slots:
74 void on_btnAdd_pressed();
75 void on_btnRemove_pressed();
76
77 // SettingsWidget interface
78protected:
79 void updateIcons(const QSize &size) override;
80};
81
82#endif // COMPILERAUTOLINKWIDGET_H
83