Skip to content

Commit

Permalink
Implemented new data field type "longtext"
Browse files Browse the repository at this point in the history
New data field type to display larger text areas in the GUI.
A "longtext" field now spans 25 lines, a text field 10 lines,
a string field 1 line.
  • Loading branch information
jkanev committed Feb 3, 2024
1 parent afedd14 commit af15fc4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
12 changes: 6 additions & 6 deletions data/Work-Plan.trt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ tree "Projects"
child-fields ["Spent Hours"]
sibling-fields []
parent-fields []
field "Team"
field-type "set"
own-fields ["Person"]
child-fields ["Team"]
sibling-fields []
parent-fields []
field "Planned Hours"
field-type "sum-time"
own-fields ["hours planned"]
Expand Down Expand Up @@ -131,12 +137,6 @@ tree "Projects"
child-fields []
sibling-fields []
parent-fields [4]
field "Communication"
field-type "node-name"
own-fields []
child-fields []
sibling-fields []
parent-fields [5]

tree "Status"
field "Planning"
Expand Down
2 changes: 1 addition & 1 deletion treetime/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def changeFieldContent(self, fieldName, fieldContent):
if fieldContent:

# changing the content of a string field - read the string plainly
if type in ("string", "text", "url"):
if type in ("string", "longtext", "text", "url"):
field["content"] = fieldContent

# changing the content of a number - read the string into a value
Expand Down
10 changes: 6 additions & 4 deletions treetime/treetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class TextEdit(QtWidgets.QPlainTextEdit):
Special custom widget class for URL fields
"""

def __init__(self, text, callback, parent=None):
def __init__(self, text, callback, height, parent=None):
"""
Initialise
"""
Expand All @@ -180,6 +180,7 @@ def __init__(self, text, callback, parent=None):
self.callback = callback
self.has_changed = False
self.textChanged.connect(self.notifyChange)
self.setFixedHeight(height * int(self.height()/25))

def notifyChange(self):
self.has_changed = True
Expand Down Expand Up @@ -1310,10 +1311,11 @@ def showContentInDataView(self, treeIndex):
name = QtWidgets.QTableWidgetItem(key)
name.setFlags(nonEditFlags)
name.setTextAlignment(0x82)
if self.currentItem.fields[key]['type'] == 'text':
if self.currentItem.fields[key]['type'] in ('text', 'longtext'):
text = self.currentItem.fields[key]["content"]
text = text and str(text) or "" # display "None" values as empty string
widget = TextEdit(text, lambda row=n: self.tableWidgetCellChanged(row, 3))
height = self.currentItem.fields[key]['type'] == 'text' and 10 or 25
widget = TextEdit(text, lambda row=n: self.tableWidgetCellChanged(row, 3), height)
self.tableWidget.setCellWidget(n, 3, widget)
elif self.currentItem.fields[key]['type'] == 'url':
value = self.currentItem.fields[key]["content"]
Expand Down Expand Up @@ -1557,7 +1559,7 @@ def tableWidgetCellChanged(self, row, column):
else:
fieldName = self.tableWidget.item(row, 1).text()
fieldType = self.currentItem.fields[fieldName]['type']
if fieldType in ('text', 'url'):
if fieldType in ('longtext', 'text', 'url'):
newValue = self.tableWidget.cellWidget(row, 3).toPlainText()
elif fieldType == 'timer':
newValue = (self.tableWidget.cellWidget(row, 3).toPlainText(),
Expand Down

0 comments on commit af15fc4

Please sign in to comment.