-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwingsquiggleinfomodel.cpp
More file actions
128 lines (114 loc) · 4.23 KB
/
wingsquiggleinfomodel.cpp
File metadata and controls
128 lines (114 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/****************************************************************************
**
** Copyright (C) 2025-2028 WingSummer
**
** This file may be used under the terms of the GNU General Public License
** version 3 as published by the Free Software Foundation.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License version 3
** along with this program. If not, see <https://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "wingsquiggleinfomodel.h"
#include "wingcodeedit.h"
WingSquiggleInfoModel::WingSquiggleInfoModel(WingCodeEdit *editor,
QObject *parent)
: QAbstractListModel(parent), _editor(editor) {
Q_ASSERT(editor);
static_assert(int(SeverityLevel::Error) ==
int(WingCodeEdit::SeverityLevel::Error));
static_assert(int(SeverityLevel::Hint) ==
int(WingCodeEdit::SeverityLevel::Hint));
static_assert(int(SeverityLevel::Information) ==
int(WingCodeEdit::SeverityLevel::Information));
static_assert(int(SeverityLevel::Warning) ==
int(WingCodeEdit::SeverityLevel::Warning));
_icons.resize(int(SeverityLevel::MAX_LEVEL));
connect(editor, &WingCodeEdit::squiggleItemChanged, this,
[this]() { emit layoutChanged(); });
}
WingSquiggleInfoModel::WingSquiggleInfoModel(QObject *parent)
: QAbstractListModel(parent), _editor(nullptr) {
_icons.resize(int(SeverityLevel::MAX_LEVEL));
}
void WingSquiggleInfoModel::setSeverityLevelIcon(SeverityLevel level,
const QIcon &icon) {
if (level != SeverityLevel::MAX_LEVEL) {
_icons[int(level)] = icon;
}
}
QIcon WingSquiggleInfoModel::severityLevelIcon(SeverityLevel level) const {
if (level == SeverityLevel::MAX_LEVEL) {
return {};
}
return _icons[int(level)];
}
QPair<int, int>
WingSquiggleInfoModel::squiggleInfoPosStart(qsizetype index) const {
auto data = _editor->m_squiggles.at(index);
return data.start;
}
QPair<int, int>
WingSquiggleInfoModel::squiggleInfoPosStop(qsizetype index) const {
auto data = _editor->m_squiggles.at(index);
return data.stop;
}
QString WingSquiggleInfoModel::squiggleInfoText(qsizetype index) const {
auto data = _editor->m_squiggles.at(index);
return data.tooltip;
}
WingSquiggleInfoModel::SeverityLevel
WingSquiggleInfoModel::squiggleInfoSeverityLevel(qsizetype index) const {
auto data = _editor->m_squiggles.at(index);
return SeverityLevel(data.level);
}
int WingSquiggleInfoModel::rowCount(const QModelIndex &parent) const {
if (_editor) {
return _editor->m_squiggles.size();
} else {
return 0;
}
}
QVariant WingSquiggleInfoModel::data(const QModelIndex &index, int role) const {
if (_editor) {
auto idx = index.row();
auto data = _editor->m_squiggles.at(idx);
switch (role) {
case Qt::DecorationRole:
return _icons.at(int(data.level));
case Qt::DisplayRole:
return data.tooltip + tr("[row: %1, col: %2]")
.arg(data.start.first)
.arg(data.start.second)
.prepend(' ');
case Qt::ToolTipRole:
return data.tooltip;
}
}
return {};
}
WingCodeEdit *WingSquiggleInfoModel::editor() const { return _editor; }
void WingSquiggleInfoModel::setEditor(WingCodeEdit *newEditor) {
if (_editor == newEditor) {
return;
}
if (_editor) {
_editor->disconnect(this, nullptr);
}
_editor = newEditor;
if (_editor) {
connect(_editor, &WingCodeEdit::squiggleItemChanged, this,
[this]() { emit layoutChanged(); });
connect(_editor, &WingCodeEdit::destroyed, this,
[this](QObject *editor) {
editor->disconnect(this, nullptr);
if (_editor == editor) {
_editor = nullptr;
}
});
}
emit layoutChanged();
}