summaryrefslogtreecommitdiffstats
path: root/utils/regtools/qeditor/regedit.h
blob: c56f0d90262f8aceb6c137a5fe4eb3c87af5e208 (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2014 by Amaury Pouly
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#ifndef REGEDIT_H
#define REGEDIT_H

#include <QComboBox>
#include <QTreeWidget>
#include <QVBoxLayout>
#include <QTabWidget>
#include <QSplitter>
#include <QLineEdit>
#include <QPushButton>
#include <QLabel>
#include <QListWidget>
#include <QGroupBox>
#include <QToolButton>
#include <QMenu>
#include <QCheckBox>
#include <QRadioButton>
#include <QButtonGroup>
#include <QDebug>
#include <QScrollArea>
#include "backend.h"
#include "settings.h"
#include "mainwindow.h"
#include "utils.h"

class AbstractRegEditPanel
{
public:
    AbstractRegEditPanel() {}
    virtual ~AbstractRegEditPanel() {}
    virtual void OnModified(bool mod) = 0;
};

class EmptyEditPanel : public QWidget, public AbstractRegEditPanel
{
    Q_OBJECT
public:
    EmptyEditPanel(QWidget *parent);

signals:
    void OnModified(bool mod);

protected:
};

class SocEditPanel : public QWidget, public AbstractRegEditPanel
{
    Q_OBJECT
public:
    SocEditPanel(SocRef ref, QWidget *parent = 0);

signals:
    void OnModified(bool mod);

protected slots:
    void OnTextEdited();
    void OnNameEdited(const QString& text);

protected:
    SocRef m_ref;
    QGroupBox *m_name_group;
    QLineEdit *m_name_edit;
    QGroupBox *m_desc_group;
    MyTextEditor *m_desc_edit;
};

class DevEditPanel : public QWidget, public AbstractRegEditPanel
{
    Q_OBJECT
public:
    DevEditPanel(SocDevRef ref, QWidget *parent = 0);

signals:
    void OnModified(bool mod);

protected slots:
    void OnInstActivated(int row, int column);
    void OnInstChanged(int row, int column);
    void OnNameEdited(const QString& text);
    void OnLongNameEdited(const QString& text);
    void OnVersionEdited(const QString& text);
    void OnDescEdited();

protected:
    void FillRow(int row, const soc_dev_addr_t& addr);
    void CreateNewRow(int row);

    enum
    {
        DevInstDeleteType = QTableWidgetItem::UserType,
        DevInstNewType
    };

    enum
    {
        DevInstIconColumn = 0,
        DevInstNameColumn = 1,
        DevInstAddrColumn = 2,
    };

    SocDevRef m_ref;
    QGroupBox *m_name_group;
    QLineEdit *m_name_edit;
    QGroupBox *m_long_name_group;
    QLineEdit *m_long_name_edit;
    QGroupBox *m_version_group;
    QLineEdit *m_version_edit;
    QGroupBox *m_instances_group;
    QTableWidget *m_instances_table;
    QGroupBox *m_desc_group;
    MyTextEditor *m_desc_edit;
};

class RegEditPanel : public QWidget, public AbstractRegEditPanel
{
    Q_OBJECT
public:
    RegEditPanel(SocRegRef ref, QWidget *parent = 0);

signals:
    void OnModified(bool mod);

protected slots:
    void OnInstActivated(int row, int column);
    void OnInstChanged(int row, int column);
    void OnNameEdited(const QString& text);
    void OnDescEdited();
    void OnSctEdited(int state);
    void OnFormulaChanged(int index);
    void OnFormulaStringChanged(const QString& text);
    void OnFormulaGenerate(bool checked);

protected:
    void CreateNewAddrRow(int row);
    void FillRow(int row, const soc_reg_addr_t& addr);
    void UpdateFormula();
    void UpdateWarning(int row);

    enum
    {
        RegInstDeleteType = QTableWidgetItem::UserType,
        RegInstNewType
    };

    enum
    {
        RegInstIconColumn = 0,
        RegInstNameColumn,
        RegInstAddrColumn,
        RegInstNrColumns,
    };

    SocRegRef m_ref;
    QGroupBox *m_name_group;
    QLineEdit *m_name_edit;
    QGroupBox *m_instances_group;
    QTableWidget *m_instances_table;
    QGroupBox *m_desc_group;
    QGroupBox *m_flags_group;
    QCheckBox *m_sct_check;
    QFont m_reg_font;
    QGroupBox *m_formula_group;
    QButtonGroup *m_formula_radio_group;
    QLabel *m_formula_type_label;
    QComboBox *m_formula_combo;
    QLineEdit *m_formula_string_edit;
    QPushButton *m_formula_string_gen;
    Unscroll< RegSexyDisplay2 > *m_sexy_display2;
    MyTextEditor *m_desc_edit;
    QGroupBox *m_field_group;
    QTableView *m_value_table;
    RegFieldTableModel *m_value_model;
    QStyledItemDelegate *m_table_delegate;
};

class FieldEditPanel : public QWidget, public AbstractRegEditPanel
{
    Q_OBJECT
public:
    FieldEditPanel(SocFieldRef ref, QWidget *parent = 0);

signals:
    void OnModified(bool mod);

protected slots:
    void OnDescEdited();
    void OnNameEdited(const QString& text);
    void OnBitRangeEdited(const QString& string);
    void OnValueActivated(int row, int column);
    void OnValueChanged(int row, int column);

protected:
    void CreateNewRow(int row);
    void FillRow(int row, const soc_reg_field_value_t& val);
    void UpdateWarning(int row);
    void UpdateDelegates();

    enum
    {
        FieldValueDeleteType = QTableWidgetItem::UserType,
        FieldValueNewType,
    };

    enum
    {
        FieldValueIconColumn = 0,
        FieldValueNameColumn,
        FieldValueValueColumn,
        FieldValueDescColumn,
        FieldValueNrColumns,
    };

    SocFieldRef m_ref;
    QGroupBox *m_name_group;
    QLineEdit *m_name_edit;
    QGroupBox *m_bitrange_group;
    QLineEdit *m_bitrange_edit;
    QGroupBox *m_desc_group;
    MyTextEditor *m_desc_edit;
    QGroupBox *m_value_group;
    QTableWidget *m_value_table;
};

class RegEdit : public QWidget, public DocumentTab
{
    Q_OBJECT
public:
    RegEdit(Backend *backend, QWidget *parent = 0);
    ~RegEdit();
    virtual bool Quit();
    virtual QWidget *GetWidget();

protected slots:
    void OnSocItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
    void OnSocItemActivated(QTreeWidgetItem *current, int column);
    void OnOpen();
    void OnSave();
    void OnSaveAs();
    void OnSocModified(bool modified);
    void OnNew();
    void OnSocItemDelete();

protected:
    void LoadSocFile(const QString& filename);
    void UpdateSocFile();
    void FillSocTree();
    void FillSocTreeItem(QTreeWidgetItem *_item);
    void FillDevTreeItem(QTreeWidgetItem *_item);
    void FillRegTreeItem(QTreeWidgetItem *_item);
    void SetPanel(QWidget *panel);
    void DisplaySoc(SocRef ref);
    void DisplayDev(SocDevRef ref);
    void DisplayReg(SocRegRef ref);
    void DisplayField(SocFieldRef ref);
    bool CloseSoc();
    bool SaveSoc();
    bool SaveSocAs();
    bool SaveSocFile(const QString& filename);
    bool GetFilename(QString& filename, bool save);
    void SetModified(bool add, bool mod);
    void FixupEmptyItem(QTreeWidgetItem *item);
    void MakeItalic(QTreeWidgetItem *item, bool it);
    void AddDevice(QTreeWidgetItem *item);
    void AddRegister(QTreeWidgetItem *_item);
    void UpdateName(QTreeWidgetItem *current);
    void AddField(QTreeWidgetItem *_item);
    void CreateNewDeviceItem(QTreeWidgetItem *parent);
    void CreateNewRegisterItem(QTreeWidgetItem *parent);
    void CreateNewFieldItem(QTreeWidgetItem *parent);
    void UpdateTabName();

    QGroupBox *m_file_group;
    QToolButton *m_file_open;
    QToolButton *m_file_save;
    QLineEdit *m_file_edit;
    QSplitter *m_splitter;
    QTreeWidget *m_soc_tree;
    Backend *m_backend;
    bool m_modified;
    SocFile m_cur_socfile;
    QWidget *m_right_panel;
};

#endif /* REGEDIT_H */