mirror of https://github.com/AxioDL/amuse.git
Revert "Editor/LayersEditor: Simplify moveRows implementation"
This commit is contained in:
parent
80da83eb16
commit
4fdb2bde8c
|
@ -1,13 +1,8 @@
|
||||||
#include "LayersEditor.hpp"
|
#include "LayersEditor.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include <QMimeData>
|
|
||||||
#include <QScrollBar>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
|
|
||||||
#include "MainWindow.hpp"
|
#include "MainWindow.hpp"
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QScrollBar>
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
class LayerDataChangeUndoCommand : public EditorUndoCommand {
|
class LayerDataChangeUndoCommand : public EditorUndoCommand {
|
||||||
QModelIndex m_index;
|
QModelIndex m_index;
|
||||||
|
@ -451,27 +446,29 @@ bool LayersModel::insertRows(int row, int count, const QModelIndex& parent) {
|
||||||
|
|
||||||
bool LayersModel::moveRows(const QModelIndex& sourceParent, int sourceRow, int count,
|
bool LayersModel::moveRows(const QModelIndex& sourceParent, int sourceRow, int count,
|
||||||
const QModelIndex& destinationParent, int destinationChild) {
|
const QModelIndex& destinationParent, int destinationChild) {
|
||||||
if (!m_node) {
|
if (!m_node)
|
||||||
return false;
|
return false;
|
||||||
}
|
bool moving = beginMoveRows(sourceParent, sourceRow, sourceRow + count - 1, destinationParent, destinationChild);
|
||||||
|
|
||||||
const bool moving =
|
|
||||||
beginMoveRows(sourceParent, sourceRow, sourceRow + count - 1, destinationParent, destinationChild);
|
|
||||||
std::vector<amuse::LayerMapping>& layers = *m_node->m_obj;
|
std::vector<amuse::LayerMapping>& layers = *m_node->m_obj;
|
||||||
|
|
||||||
const auto pivot = std::make_move_iterator(layers.begin() + sourceRow);
|
|
||||||
const auto begin = std::make_move_iterator(layers.begin() + destinationChild);
|
|
||||||
const auto end = pivot + count;
|
|
||||||
|
|
||||||
if (destinationChild < sourceRow) {
|
if (destinationChild < sourceRow) {
|
||||||
std::rotate(begin, pivot, end);
|
for (int i = 0; i < count; ++i) {
|
||||||
|
amuse::LayerMapping tmp = std::move(layers[sourceRow]);
|
||||||
|
for (int j = sourceRow; j != destinationChild; --j)
|
||||||
|
layers[j] = std::move(layers[j - 1]);
|
||||||
|
layers[destinationChild] = std::move(tmp);
|
||||||
|
++sourceRow;
|
||||||
|
++destinationChild;
|
||||||
|
}
|
||||||
} else if (destinationChild > sourceRow) {
|
} else if (destinationChild > sourceRow) {
|
||||||
std::rotate(pivot, end, begin);
|
for (int i = 0; i < count; ++i) {
|
||||||
|
amuse::LayerMapping tmp = std::move(layers[sourceRow]);
|
||||||
|
for (int j = sourceRow; j != destinationChild - 1; ++j)
|
||||||
|
layers[j] = std::move(layers[j + 1]);
|
||||||
|
layers[destinationChild - 1] = std::move(tmp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (moving)
|
||||||
if (moving) {
|
|
||||||
endMoveRows();
|
endMoveRows();
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue