-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabwidgetcell.h
More file actions
234 lines (173 loc) · 5.53 KB
/
tabwidgetcell.h
File metadata and controls
234 lines (173 loc) · 5.53 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
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
#ifndef TABWIDGETCELL_H
#define TABWIDGETCELL_H
#include <QWidget>
#include <QHBoxLayout>
#include <QTableView>
#include <QListWidget>
#include <QStandardItemModel>
#include <QPushButton>
#include <QDebug>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QMenu>
#include <QUndoStack>
#include <QUndoView>
#include <QAction>
#include <QItemSelectionModel>
#include <QScrollBar>
#include "mainwindow.h"
#include "annonationeditwidget.h"
#include <google/protobuf/text_format.h>
//红色的是删除的行
//黄色的是修改的单元格
//绿色的是增加的行
//调整过位置的列的列头就是黄色
class QUndoStack;
class QUndoView;
class QTableView;
class QStandardItemModel;
class MainWindow;
namespace Ui {
class TabWidgetCell;
}
typedef struct fieldInfo
{
QString sFieldName; //字段名字
QString sFieldAnnonation; //字段的备注
QString sFieldLink; //字段的关联
friend QDebug& operator << (QDebug out, const fieldInfo& info)
{
out << info.sFieldName << info.sFieldAnnonation << info.sFieldLink;
return out;
};
}FIELDINFO;
//表的字段信息
typedef struct fieldSquence
{
QString sIndex; //索引
QVector<FIELDINFO> vSFieldSquences; //对应的字段顺序
friend QDebug& operator << (QDebug out, const fieldSquence& info)
{
out << info.sIndex << info.vSFieldSquences;
return out;
};
}FIELDSQUENCE;
enum TabWidgetType
{
enTabWidgetTable = 1,
enTabWidgetList = 2,
};
class TabWidgetCell : public QWidget
{
Q_OBJECT
public:
TabWidgetCell(QWidget *parent = nullptr);
virtual ~TabWidgetCell();
void SetType(TabWidgetType type)
{
m_type = type;
}
TabWidgetType GetType()
{
return m_type;
}
void SetName(QString sName)
{
m_sName = sName;
}
QString GetName()
{
return m_sName;
}
//把tabwidget对象的指针也带进来
void SetTabWidget(QTabWidget* tabwidget)
{
m_tabWidget = tabwidget;
}
//把tabwidget对象的指针也带进来
void SetManWindows(MainWindow* mainWindows)
{
m_mainWindow = mainWindows;
}
//请求保存数据
virtual bool OnRequestSaveData();
void SetDataModify()
{
m_bTableDataChange = true;
ChangeDataModify();
}
virtual inline bool IsTableDataChange()
{
return m_bTableDataChange;
}
virtual void SetFieldLink(QString sIndex, QString sField, QString sFieldLink){};
//设置数据有改变
void ChangeDataModify();
//改变一个modelIndex的数据
void ChangeModelIndexData(QModelIndex index, QString sData);
//mainwindow传过来的键盘事件
virtual void GlobalKeyPressEevent(QKeyEvent *ev){}
void clearUndoStack()
{
undoStack->clear();
}
//撤销
void undo();
//返回撤销
void redo();
//复制单元格的内容
void copy();
//粘贴全局剪切板的内容
void paste();
//设置行高和列宽
void SetRowAndColParam();
virtual void OnSaveAnnonations(QString sIndex, QString str, QString sField){}
virtual void CheckItemDataTypeIsCorrect(QStandardItem *item){};
void SortVerticalHeaderNumber();
public slots:
//刷新界面
virtual void Flush() {};
//item改变
virtual void OnItemDataChange(QStandardItem *item);
//行大小改变
virtual void OnRowResized(int logicalIndex, int oldSize, int newSize);
//列大小改变
virtual void OnColResized(int logicalIndex, int oldSize, int newSize);
protected:
virtual void keyPressEvent(QKeyEvent *ev);
void resizeEvent(QResizeEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
private slots:
virtual void AddAnnotation() {};
// void onCurrentChanged(const QModelIndex& current, const QModelIndex& previous);
void OnSaveButtonClicked();
void OnShowAllRow();
public:
Ui::TabWidgetCell *ui;
TabWidgetType m_type;
QTabWidget* m_tabWidget; //所在的tabwidget
MainWindow* m_mainWindow; //所在的mainWindow
QWidget* m_topWidget; //上面的widget
QTableView* m_tableView; //展示数据的二维表
QListWidget* m_rightButtonList; //右边的操作按钮
QStandardItemModel* m_standardItemModel; //view对应的model
QHBoxLayout* hlayout_top; //上面的水平布局
QListWidget* m_bottomButtonList; //底部的显示按钮列表
QVBoxLayout* vlayout_all; //整个TabWidget类的垂直布局
QMap<QString, FIELDSQUENCE> m_mFieldSquence; //表的外围信息
QMenu* m_tableCellMenu; //二维表数据的菜单栏
bool m_bTableDataChange; //表的数据是否被更改
QPushButton* m_saveDataButton; //保存数据的按钮
QString m_sName; //表的名字
//实现撤销功能
QAction *undoAction;
QAction *redoAction;
QUndoStack *undoStack;
QUndoView *undoView;
QVector<int> m_vRowHeight; //行高
QVector<int> m_vColWidth; //列宽
int m_currentVSlider; //记录之前的垂直滑动条位置
int m_currentHSlider; //记录之前的水平滑动条位置
QMap<int, bool> m_mTypeCheck; //存储错误格式的类型的单元格row * 10000 + col, 是否出错
};
#endif // TABWIDGETCELL_H