| 155 | } |
| 156 | |
| 157 | bool StructDetailModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, |
| 158 | int column, const QModelIndex& parent) |
| 159 | { |
| 160 | (void)column; |
| 161 | |
| 162 | if (action != Qt::CopyAction && action != Qt::MoveAction) |
| 163 | return false; |
| 164 | |
| 165 | if (!data->hasFormat("application/x-structfield")) |
| 166 | return false; |
| 167 | |
| 168 | if (QApplication::keyboardModifiers() & Qt::ControlModifier) |
| 169 | action = Qt::CopyAction; |
| 170 | |
| 171 | row = parent.row(); |
| 172 | |
| 173 | QByteArray bytes = data->data("application/x-structfield"); |
| 174 | QDataStream stream(&bytes, QIODevice::ReadOnly); |
| 175 | |
| 176 | int firstRow; |
| 177 | stream >> firstRow; |
| 178 | |
| 179 | int count; |
| 180 | stream >> count; |
| 181 | |
| 182 | int unmovedRowCount = static_cast<int>(m_fields.count()) - count; |
| 183 | |
| 184 | if (row == -1) |
| 185 | row = unmovedRowCount; |
| 186 | |
| 187 | beginResetModel(); |
| 188 | |
| 189 | QList<FieldDef*> fields = m_fields.mid(firstRow, count); |
| 190 | if (action == Qt::MoveAction) |
| 191 | { |
| 192 | m_fields.remove(firstRow, count); |
| 193 | for (int i = count - 1; i >= 0; i--) |
| 194 | { |
| 195 | m_fields.insert(row, fields.takeAt(i)); |
| 196 | } |
| 197 | } |
| 198 | else |
| 199 | { |
| 200 | for (int i = count - 1; i >= 0; i--) |
| 201 | { |
| 202 | FieldDef* newField = new FieldDef(fields[i]); |
| 203 | m_fields.insert(row, newField); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | endResetModel(); |
| 208 | |
| 209 | updateFieldOffsets(); |
| 210 | |
| 211 | return true; |
| 212 | } |
| 213 | |
| 214 | void StructDetailModel::addField(const QModelIndex& index, FieldDef* field) |