diff --git a/felt/core/workspaces_model.py b/felt/core/workspaces_model.py index d929fb4..7a59164 100644 --- a/felt/core/workspaces_model.py +++ b/felt/core/workspaces_model.py @@ -72,8 +72,8 @@ def _reply_finished(self, reply: QNetworkReply): workspaces = result.get('data', []) - self.beginInsertRows(QModelIndex(), len(self.workspaces) + 1, - 1 + len(self.workspaces) + len(workspaces) - 1) + self.beginInsertRows(QModelIndex(), len(self.workspaces), + len(self.workspaces) + len(workspaces) - 1) for workspace_json in workspaces: _workspace = Workspace.from_json(workspace_json) @@ -88,7 +88,7 @@ def index(self, row, column, parent=QModelIndex()): if column < 0 or column >= self.columnCount(): return QModelIndex() - if not parent.isValid() and 0 <= row < 1 + len(self.workspaces): + if not parent.isValid() and 0 <= row < len(self.workspaces): return self.createIndex(row, column) return QModelIndex() @@ -98,7 +98,7 @@ def parent(self, index): def rowCount(self, parent=QModelIndex()): if not parent.isValid(): - return 1 + len(self.workspaces) + return len(self.workspaces) # no child items return 0 @@ -110,12 +110,6 @@ def data(self, index, role=Qt.DisplayRole): - if index.row() == 0 and not index.parent().isValid(): - # special "My workspace" item - if role in (self.NameRole, Qt.DisplayRole, Qt.ToolTipRole): - return self.tr('My Workspace') - return None - _workspace = self.index2workspace(index) if _workspace: if role in (self.NameRole, Qt.DisplayRole, Qt.ToolTipRole): @@ -141,8 +135,8 @@ def index2workspace(self, index: QModelIndex) -> Optional[Workspace]: """ Returns the workspace at the given model index """ - if not index.isValid() or index.row() < 1 or index.row() >= 1 + len( + if not index.isValid() or index.row() < 0 or index.row() >= len( self.workspaces): return None - return self.workspaces[index.row() - 1] + return self.workspaces[index.row()]