Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Feature/pm 140 edit log entries #72

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions march_rqt_note_taker/src/march_rqt_note_taker/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ def time_string(self):
def __str__(self):
"""Returns a string representation of an Entry."""
return '[{0}] {1}'.format(self.date_time.toString(), self.content)

def edit_content(self, content):
self.content = content
12 changes: 9 additions & 3 deletions march_rqt_note_taker/src/march_rqt_note_taker/entry_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def data(self, index, role=Qt.DisplayRole):
if column == 'entry' and entry.is_error:
return QBrush(Qt.darkRed)

if role == Qt.EditRole:
return entry

return None

def remove_rows(self, position, rows=1):
Expand All @@ -56,14 +59,17 @@ def remove_rows(self, position, rows=1):
self._entries = self._entries[:position] + self._entries[position + rows:]
self.endRemoveRows()

def insert_row(self, entry):
def insert_row(self, entry, row=-1):
"""Appends an entry.

:type entry: Entry
:param entry: Entry to append to rows
:param row: Row number at which to add the entry
"""
self.beginInsertRows(QModelIndex(), self.rowCount(), self.rowCount())
self._entries.append(entry)
if row == -1:
row = self.rowCount()
self.beginInsertRows(QModelIndex(), row, row)
self._entries.insert(row, entry)
self.endInsertRows()

def insert_log_msg(self, log_msg):
Expand Down
22 changes: 21 additions & 1 deletion march_rqt_note_taker/src/march_rqt_note_taker/notes_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from python_qt_binding import loadUi, QtCore
from python_qt_binding.QtGui import QKeySequence
from python_qt_binding.QtWidgets import QFileDialog, QShortcut, QWidget
from python_qt_binding.QtWidgets import QFileDialog, QInputDialog, QLineEdit, QShortcut, QWidget
import rospy

from .entry import Entry
Expand Down Expand Up @@ -31,6 +31,7 @@ def __init__(self, model, ui_file):
self._autosave(first, last, self.REMOVE)])

self.table_view.setModel(self._model)
self.table_view.doubleClicked.connect(self._edit_selected)
self.table_view.verticalScrollBar().rangeChanged.connect(self._handle_change_scroll)
self._last_scroll_max = self.table_view.verticalScrollBar().maximum()

Expand Down Expand Up @@ -81,6 +82,25 @@ def _delete_selected(self):
if indices and indices[0].isValid():
self._model.remove_rows(indices[0].row(), len(indices))

def _edit_selected(self):
selection_model = self.table_view.selectionModel()
if self.table_view.hasFocus() and selection_model.hasSelection():
indices = [index for index in selection_model.selectedIndexes() if not index.column()]
if indices and indices[0].isValid():
""" Get the full entry from dataset """
entry = self._model.data(indices[0], QtCore.Qt.EditRole)
""" Get new value for entry """
entry_content, ok = QInputDialog().getText(self, 'Edit Entry', 'Entry:',
QLineEdit.Normal, entry.content)
if ok and entry_content:
entry.edit_content(entry_content)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
entry.edit_content(entry_content)
entry.content = entry_content

The pythonic way is to just directly edit the parameter. Parameters that you want to be "private" should be marked by a leading _, If you need "getters/setters" for these variables, you can use @Property to keep the syntax pythonic.

""" Delete the current data entry and input the new entry """
self._model.remove_rows(indices[0].row())
new_row = indices[0].row()
if new_row < 0:
new_row = 0
self._model.insert_row(entry, new_row)

def _set_saved(self, saved):
self._can_save = not saved
self.save_button.setEnabled(not saved)
Expand Down