diff --git a/soitool/modules/module_phonebook.py b/soitool/modules/module_phonebook.py index 7de9a6ba0a41f12fbd04bdfcbebd536ab045da92..718e102ebfceec59de90edbbeeacddad27b4ac3b 100644 --- a/soitool/modules/module_phonebook.py +++ b/soitool/modules/module_phonebook.py @@ -123,7 +123,7 @@ class PhonebookModule(ModuleBase, QWidget, metaclass=Meta): self.setLayout(layout) if data: - pass + self.load_data_to_module(data) else: self.set_columns() @@ -306,8 +306,31 @@ class PhonebookModule(ModuleBase, QWidget, metaclass=Meta): self.setFixedHeight(height) def load_data_to_module(self, data): - pass - # MÃ¥ oppdatere dict + """Load module content from data. + + Parameters + ---------- + data : dict + Module serialized as dict. + """ + for column_header in self.selected_columns.keys(): + if column_header in data.keys(): + self.selected_columns[column_header] = True + else: + self.selected_columns[column_header] = False + + self.set_columns() + + number_of_rows = len(list(data.values())[0]) + self.table.setRowCount(self.table.rowCount() + number_of_rows - 1) + + for column_header in data.keys(): + column_index = self.get_column_index_by_header(column_header) + for row_index in range(1, number_of_rows + 1): + current_item = QTableWidgetItem( + data[column_header][row_index - 1] + ) + self.table.setItem(row_index, column_index, current_item) def open_popup(self): """Open dialog for editing columns."""