Allow reordering elements in list settings (#1595)
* Add move up, down buttons to list settings Channel notifications, moderation buttons etc. have a move up and move down button now for reordering. * Selection follows moved rows, refactor Also fixed rows past the 2nd one not moving * Update selection property with more than 1 column * Fix crash when moving without a row selected * Move rows with drag and drop Right now it's a little iffy registering the row to be moved, but I wanna go to bed :) * Remove EditableTableView, move to SignalVectorModel Replace my ghetto drag and drop solution in EditableTableView with small patches to the stuff already written in SignalVectorModel::dropMimeData
This commit is contained in:
@@ -239,6 +239,32 @@ public:
|
||||
this->vector_->removeAt(signalVectorRow);
|
||||
}
|
||||
|
||||
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count,
|
||||
const QModelIndex &destinationParent, int destinationChild)
|
||||
{
|
||||
if (count != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(sourceRow >= 0 && sourceRow < this->rows_.size());
|
||||
|
||||
int signalVectorRow = this->getVectorIndexFromModelIndex(sourceRow);
|
||||
this->beginMoveRows(sourceParent, sourceRow, sourceRow,
|
||||
destinationParent, destinationChild);
|
||||
|
||||
TVectorItem item =
|
||||
this->getItemFromRow(this->rows_[sourceRow].items,
|
||||
this->rows_[sourceRow].original.get());
|
||||
this->vector_->removeAt(signalVectorRow);
|
||||
this->vector_->insert(
|
||||
item, this->getVectorIndexFromModelIndex(destinationChild));
|
||||
|
||||
this->endMoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool removeRows(int row, int count, const QModelIndex &parent) override
|
||||
{
|
||||
(void)parent;
|
||||
@@ -289,17 +315,18 @@ public:
|
||||
int from = data->data("chatterino_row_id").toInt();
|
||||
int to = parent.row();
|
||||
|
||||
if (from < 0 || from > this->vector_->raw().size() || to < 0 ||
|
||||
to > this->vector_->raw().size())
|
||||
int vectorFrom = this->getVectorIndexFromModelIndex(from);
|
||||
int vectorTo = this->getVectorIndexFromModelIndex(to);
|
||||
|
||||
if (vectorFrom < 0 || vectorFrom > this->vector_->raw().size() ||
|
||||
vectorTo < 0 || vectorTo > this->vector_->raw().size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (from != to)
|
||||
{
|
||||
auto item = this->vector_->raw()[from];
|
||||
this->vector_->removeAt(from);
|
||||
this->vector_->insert(item, to);
|
||||
this->moveRow(this->index(from, to), from, parent, to);
|
||||
}
|
||||
|
||||
// We return false since we remove items ourselves.
|
||||
|
||||
Reference in New Issue
Block a user