summaryrefslogtreecommitdiffstats
path: root/utils/regtools/qeditor/regedit.h
blob: 2540500f2972c5bc4c7ba0d46e8d8a93cc4632ea (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
305
306
/***************************************************************************
 *             __________               __   ___.
 *   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 <QSpinBox>
#include <QFormLayout>
#include "backend.h"
#include "settings.h"
#include "mainwindow.h"
#include "utils.h"

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

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

signals:
    void OnModified();

protected:
};

class SocEditPanel : public QWidget, public AbstractRegEditPanel
{
    Q_OBJECT
public:
    SocEditPanel(const soc_desc::soc_ref_t& ref, QWidget *parent = 0);

signals:
    void OnModified();

protected slots:
    void OnTextEdited();
    void OnNameEdited(const QString& text);
    void OnTitleEdited(const QString& text);
    void OnVersionEdited(const QString& text);
    void OnIsaEdited(const QString& text);
    void OnAuthorActivated(QTableWidgetItem *);
    void OnAuthorChanged(QTableWidgetItem *);

protected:
    soc_desc::soc_ref_t m_ref;
    QTableWidget *m_authors_list;
    MyTextEditor *m_desc_edit;
};

class NodeInstanceEditPanel : public QWidget
{
    Q_OBJECT
public:
    NodeInstanceEditPanel(const soc_desc::node_ref_t& ref, soc_id_t inst_id,
        QWidget *parent = 0);
    soc_id_t GetId();
    soc_desc::instance_t& GetInstance();

signals:
    void OnModified();

protected slots:
    void OnNameEdited(const QString& text);
    void OnTitleEdited(const QString& text);
    void OnDescEdited(const QString& text);
    void OnTypeChanged(int index);
    void OnAddrChanged(uint addr);
    void OnBaseChanged(uint base);
    void OnStrideChanged(uint stride);
    void OnFirstChanged(int first);
    void OnCountChanged(int count);
    void OnFormulaChanged(const QString& formula);
    void OnVariableChanged(const QString& variable);
    void OnAddressActivated(QTableWidgetItem *);
    void OnAddressChanged(QTableWidgetItem *);

protected:
    void UpdateType(int type);

    soc_desc::node_ref_t m_ref;
    soc_id_t m_id;
    QComboBox *m_type_combo;
    QWidget *m_single_group;
    QWidget *m_range_group;
    QWidget *m_formula_group;
    QWidget *m_stride_group;
    QWidget *m_list_group;
    QStyledItemDelegate *m_table_delegate;
    SocFieldEditorCreator *m_table_edit_factory;
};

class NodeEditPanel : public QWidget, public AbstractRegEditPanel
{
    Q_OBJECT
public:
    NodeEditPanel(const soc_desc::node_ref_t& ref, QWidget *parent = 0);

signals:
    void OnModified();

protected slots:
    void OnNameEdited(const QString& text);
    void OnTitleEdited(const QString& text);
    void OnDescEdited();
    void OnInstRemove(int index);
    void OnInstCreate();
    void OnInstModified();

protected:
    soc_desc::instance_t *GetInstanceById(soc_id_t id);
    soc_desc::instance_t *GetInstanceByRow(int row);
    QString GuessName();

    soc_desc::node_ref_t m_ref;
    MyTextEditor *m_desc_edit;
    YTabWidget *m_instances_tab;
};

class RegFieldEditPanel : public QWidget
{
    Q_OBJECT
public:
    RegFieldEditPanel(const soc_desc::field_ref_t& ref, QWidget *parent = 0);
    soc_desc::field_ref_t GetField();
    void UpdateWidth();

signals:
    void OnModified();

protected slots:
    void OnFieldNameChanged(const QString& name);
    void OnFieldRangeChanged(const QString& range);
    void OnFieldDescChanged(const QString& name);
    void OnFieldValueActivated(QTableWidgetItem *item);
    void OnFieldValueChanged(QTableWidgetItem *item);

protected:

    soc_desc::field_ref_t m_ref;
    QLineEdit *m_name_edit;
    QLineEdit *m_range_edit;
    SocBitRangeValidator *m_range_validator;
    MyTextEditor *m_desc_edit;
    QTableWidget *m_enum_table;
    SocFieldItemDelegate *m_enum_delegate;
    SocFieldEditorCreator *m_enum_editor;
};

class RegEditPanel : public QWidget, public AbstractRegEditPanel
{
    Q_OBJECT
public:
    RegEditPanel(const soc_desc::register_ref_t& ref, QWidget *parent = 0);

signals:
    void OnModified();

protected slots:
    void OnRegFieldActivated(const QModelIndex& index);
    void OnRegDisplayContextMenu(QPoint point);
    void OnRegFieldDelete();
    void OnRegFieldNew();
    void OnWidthChanged(int size);
    void OnFieldModified();
    void OnDescEdited();
    void OnVariantActivated(QTableWidgetItem *item);
    void OnVariantValueChanged(QTableWidgetItem *item);
    void OnFieldRemove(int index);
    void OnFieldCreate();

protected:
    void DoModify();
    int FindFreeBit(int preferred);
    int IndexById(soc_id_t id); // tab index
    void UpdateWidthRestrictions();

    MyTextEditor *m_desc_edit;
    soc_desc::register_ref_t m_ref;
    QFont m_reg_font;
    Unscroll< YRegDisplay > *m_sexy_display2;
    RegFieldTableModel *m_value_model;
    YTabWidget *m_fields_tab;
    QTabWidget *m_view_tab;
    QTableWidget *m_variant_table;
    QAction *m_new_action;
    QAction *m_delete_action;
    QPoint m_menu_point;
    SocFieldItemDelegate *m_variant_delegate;
    SocFieldEditorCreator *m_variant_editor;
    QButtonGroup *m_reg_size_group;
};

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 OnOpen();
    void OnSave();
    void OnSaveAs();
    void OnSocModified();
    void OnNew();
    void OnSocItemDelete();
    void OnSocItemNew();
    void OnSocItemCreate();
    void OnSocTreeContextMenu(QPoint point);

protected:
    void LoadSocFile(const QString& filename);
    void UpdateSocFile();
    void FillSocTree();
    void FillNodeTreeItem(QTreeWidgetItem *item);
    void SetPanel(QWidget *panel);
    void DisplaySoc(const soc_desc::soc_ref_t& ref);
    void DisplayNode(const soc_desc::node_ref_t& ref);
    void DisplayReg(const soc_desc::register_ref_t& 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 FixupItem(QTreeWidgetItem *item);
    QIcon GetIconFromType(int type);
    void MakeItalic(QTreeWidgetItem *item, bool it);
    void AddDevice(QTreeWidgetItem *item);
    void AddRegister(QTreeWidgetItem *_item);
    void UpdateName(QTreeWidgetItem *current);
    void AddField(QTreeWidgetItem *_item);
    void CreateNewNodeItem(QTreeWidgetItem *parent);
    void CreateNewRegisterItem(QTreeWidgetItem *parent);
    void CreateNewFieldItem(QTreeWidgetItem *parent);
    void UpdateTabName();
    bool ValidateName(const QString& name);
    int SetMessage(MessageWidget::MessageType type, const QString& msg);
    void HideMessage(int id);

    QAction *m_delete_action;
    QAction *m_new_action;
    QAction *m_create_action;
    QTreeWidgetItem *m_action_item;
    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;
    MessageWidget *m_msg;
    QVBoxLayout *m_right_panel_layout;
    int m_msg_welcome_id;
    int m_msg_name_error_id;
};

#endif /* REGEDIT_H */