feat: Automatically select newly added table rows (#4216)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
kornes
2022-12-06 22:52:58 +00:00
committed by GitHub
parent 783b05c103
commit 36c8fffee2
4 changed files with 9 additions and 25 deletions
+8 -10
View File
@@ -82,7 +82,13 @@ EditableModelView::EditableModelView(QAbstractTableModel *model, bool movable)
QObject::connect(this->model_, &QAbstractTableModel::rowsMoved, this,
[this](const QModelIndex &parent, int start, int end,
const QModelIndex &destination, int row) {
this->selectRow(row);
this->tableView_->selectRow(row);
});
// select freshly added row
QObject::connect(this->model_, &QAbstractTableModel::rowsInserted, this,
[this](const QModelIndex &parent, int first, int last) {
this->tableView_->selectRow(last);
});
// add tableview
@@ -149,15 +155,7 @@ void EditableModelView::moveRow(int dir)
model_->moveRows(model_->index(row, 0), row, selected.size(),
model_->index(row + dir, 0), row + dir);
this->selectRow(row + dir);
}
void EditableModelView::selectRow(int row)
{
this->getTableView()->selectionModel()->clear();
this->getTableView()->selectionModel()->select(
this->model_->index(row, 0),
QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
this->tableView_->selectRow(row + dir);
}
} // namespace chatterino
-3
View File
@@ -31,9 +31,6 @@ private:
QHBoxLayout *buttons_{};
void moveRow(int dir);
public:
void selectRow(int row);
};
} // namespace chatterino
@@ -40,13 +40,6 @@ KeyboardSettingsPage::KeyboardSettingsPage()
auto newHotkey = dialog.data();
int vectorIndex = getApp()->hotkeys->hotkeys_.append(newHotkey);
getApp()->hotkeys->save();
// Select and scroll to newly added hotkey
auto modelRow = model->getModelIndexFromVectorIndex(vectorIndex);
auto modelIndex = model->index(modelRow, 0);
view->selectRow(modelRow);
view->getTableView()->scrollTo(modelIndex,
QAbstractItemView::PositionAtCenter);
}
});
@@ -89,11 +82,6 @@ void KeyboardSettingsPage::tableCellClicked(const QModelIndex &clicked,
auto vectorIndex =
getApp()->hotkeys->replaceHotkey(hotkey->name(), newHotkey);
getApp()->hotkeys->save();
// Select the replaced hotkey
auto modelRow = model->getModelIndexFromVectorIndex(vectorIndex);
auto modelIndex = model->index(modelRow, 0);
view->selectRow(modelRow);
}
}