| 139 | } |
| 140 | |
| 141 | bool MacroStepTableModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) |
| 142 | { |
| 143 | // Source code for this has been copied from QStringListModel::moveRows() |
| 144 | |
| 145 | if (sourceRow < 0 |
| 146 | || sourceRow + count - 1 >= rowCount(sourceParent) |
| 147 | || destinationChild <= 0 |
| 148 | || destinationChild > rowCount(destinationParent) |
| 149 | || sourceRow == destinationChild - 1 |
| 150 | || count <= 0) { |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | if (!beginMoveRows(QModelIndex(), sourceRow, sourceRow + count - 1, QModelIndex(), destinationChild)) |
| 155 | return false; |
| 156 | /* |
| 157 | QList::move assumes that the second argument is the index where the item will end up to |
| 158 | i.e. the valid range for that argument is from 0 to QList::size()-1 |
| 159 | QAbstractItemModel::moveRows when source and destinations have the same parent assumes that |
| 160 | the item will end up being in the row BEFORE the one indicated by destinationChild |
| 161 | i.e. the valid range for that argument is from 1 to QList::size() |
| 162 | For this reason we remove 1 from destinationChild when using it inside QList |
| 163 | */ |
| 164 | |
| 165 | destinationChild--; |
| 166 | |
| 167 | const int fromRow = destinationChild < sourceRow ? (sourceRow + count - 1) : sourceRow; |
| 168 | while (count--) |
| 169 | macro->getSteps().move(fromRow, destinationChild); |
| 170 | |
| 171 | endMoveRows(); |
| 172 | |
| 173 | return true; |
| 174 | } |
| 175 | |
| 176 | Qt::ItemFlags MacroStepTableModel::flags(const QModelIndex &index) const |
| 177 | { |
nothing calls this directly
no outgoing calls
no test coverage detected