Skip to content

Commit 2197a73

Browse files
committed
修改版本提示框按钮和对应逻辑;优化版本忽略文件的路径读取逻辑
1 parent 69572c8 commit 2197a73

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

formatter.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ def analyse_json_obj(json_obj, level=0, res=None, json_key=None):
5454
else:
5555
res.append('%s<%s> : <[list]>9' % (indent * level, json_key))
5656
if len(json_obj) > 0:
57-
analyse_json_obj(json_obj[0], level + 1, res)
57+
json_obj_temp = json_obj[0] if json_obj[0] is not None else {}
58+
if len(list(filter(lambda item: type(item) is dict or item is None, json_obj))) == len(json_obj):
59+
for i in range(1, len(json_obj)):
60+
for k in json_obj[i]:
61+
if json_obj_temp is None or (k not in json_obj_temp or json_obj_temp[k] is None):
62+
json_obj_temp[k] = json_obj[i][k]
63+
json_obj_temp = None if json_obj_temp is {} else json_obj_temp
64+
analyse_json_obj(json_obj_temp, level + 1, res)
5865

5966
else:
6067
# 针对基本数据类型,在插入的键值对数据后再加入类型序号标志位
@@ -207,11 +214,32 @@ def generate_bean():
207214
ui.te_json.setText(res)
208215

209216

217+
def str_to_camel_case(text):
218+
try:
219+
arr = filter(None, text.split('_'))
220+
res = ''
221+
for i in arr:
222+
res = res + i[0].upper() + i[1:]
223+
return res[0].lower() + res[1:]
224+
except IndexError:
225+
return text
226+
227+
228+
def convert_names_to_camel_case(index):
229+
if ui.tv_fields.horizontalHeaderItem(index).text() == 'Name(click to camelCase)':
230+
for i in range(ui.tv_fields.rowCount()):
231+
name_cell = ui.tv_fields.cellWidget(i, 2)
232+
if type(name_cell) is QtWidgets.QTextEdit:
233+
assert isinstance(name_cell, QtWidgets.QTextEdit)
234+
name_cell.setText(str_to_camel_case(name_cell.toPlainText()))
235+
236+
210237
def init_event():
211238
# 绑定json解析按钮事件
212239
ui.btn_format.clicked.connect(json_format)
213240
ui.btn_generate.clicked.connect(generate_bean)
214241
ui.btn_copy.clicked.connect(copy_left_text)
242+
ui.tv_fields.horizontalHeader().sectionClicked.connect(convert_names_to_camel_case)
215243

216244

217245
def copy_left_text():
@@ -223,7 +251,7 @@ def copy_left_text():
223251
# 设置表格基础样式
224252
def init_table():
225253
# 设置表头,表头文字居中
226-
ui.tv_fields.setHorizontalHeaderLabels(['Fields', 'Types', 'Name'])
254+
ui.tv_fields.setHorizontalHeaderLabels(['Fields', 'Types', 'Name(click to camelCase)'])
227255
ui.tv_fields.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignHCenter)
228256
# 表头自动平分宽度
229257
ui.tv_fields.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"code": 0.7,
3-
"desc": "可以通过下拉框将对象类型设置为Map<String, dynamic>来避免该对象字段的解析,参考issue #13\n"
3+
"desc": "1.可以通过下拉框将对象类型设置为Map<String, dynamic>来避免该对象字段的解析,参考issue #13\n2.点击Name栏使字段转为驼峰 & 解析List的时候读取多个元素,参考issue #17"
44
}

0 commit comments

Comments
 (0)