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