Skip to content

Commit

Permalink
Server UI: Add Select All menu button and shortcut, set row size to f…
Browse files Browse the repository at this point in the history
…it headers names on start
  • Loading branch information
goldarte committed Sep 19, 2019
1 parent 56fb329 commit da5cc5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Server/copter_table_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, parent=None):
super(CopterDataModel, self).__init__(parent)
self.headers = ('copter ID', 'animation ID', 'battery V', 'battery %', 'system status', 'calibration status', 'selfcheck', 'time delta')
self.data_contents = []
self.first_col_is_checked = False

def insertRows(self, contents, position='last', parent=QtCore.QModelIndex()):
rows = len(contents)
Expand Down Expand Up @@ -131,6 +132,13 @@ def setData(self, index, value, role=Qt.EditRole):

return True

def select_all(self):
self.first_col_is_checked = not self.first_col_is_checked
for copter in self.data_contents:
copter.checked = int(self.first_col_is_checked)*2
for row in range(len(self.data_contents)):
self.update_model(self.index(row, 0))

def flags(self, index):
roles = Qt.ItemIsSelectable | Qt.ItemIsEnabled
if index.column() == 0:
Expand Down
6 changes: 4 additions & 2 deletions Server/server_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self):
self.signals = SignalManager()
self.gyro_calibrated = {}
self.level_calibrated = {}
self.first_col_is_checked = False

self.init_model()

Expand All @@ -64,8 +65,7 @@ def init_model(self):

# Initiate table and table self.model
self.ui.tableView.setModel(self.proxy_model)
#self.ui.tableView.horizontalHeader().setStretchLastSection(True)
#self.ui.tableView.setSortingEnabled(True)
self.ui.tableView.resizeColumnsToContents()

# Connect signals to manipulate model from threads
self.signals.update_data_signal.connect(self.model.update_item)
Expand All @@ -88,6 +88,8 @@ def init_model(self):
self.model.selected_calibration_ready_signal.connect(self.ui.calibrate_gyro.setEnabled)
self.model.selected_calibration_ready_signal.connect(self.ui.calibrate_level.setEnabled)

self.ui.action_select_all_rows.triggered.connect(self.model.select_all)


def client_connected(self, client: Client):
self.signals.add_client_signal.emit(CopterData(copter_id=client.copter_id, client=client))
Expand Down

0 comments on commit da5cc5b

Please sign in to comment.