167 QListWidgetItem *item = items.takeAt(row); |
167 QListWidgetItem *item = items.takeAt(row); |
168 endRemoveRows(); |
168 endRemoveRows(); |
169 return item; |
169 return item; |
170 } |
170 } |
171 |
171 |
|
172 void QListModel::move(int srcRow, int dstRow) |
|
173 { |
|
174 if (srcRow == dstRow |
|
175 || srcRow < 0 || srcRow >= items.count() |
|
176 || dstRow < 0 || dstRow > items.count()) |
|
177 return; |
|
178 |
|
179 if (!beginMoveRows(QModelIndex(), srcRow, srcRow, QModelIndex(), dstRow)) |
|
180 return; |
|
181 if (srcRow < dstRow) |
|
182 --dstRow; |
|
183 items.move(srcRow, dstRow); |
|
184 endMoveRows(); |
|
185 } |
|
186 |
172 int QListModel::rowCount(const QModelIndex &parent) const |
187 int QListModel::rowCount(const QModelIndex &parent) const |
173 { |
188 { |
174 return parent.isValid() ? 0 : items.count(); |
189 return parent.isValid() ? 0 : items.count(); |
175 } |
190 } |
176 |
191 |
1802 for (int i = 0; i < selIndexes.count(); i++) |
1817 for (int i = 0; i < selIndexes.count(); i++) |
1803 persIndexes.append(selIndexes.at(i)); |
1818 persIndexes.append(selIndexes.at(i)); |
1804 |
1819 |
1805 if (persIndexes.contains(topIndex)) |
1820 if (persIndexes.contains(topIndex)) |
1806 return; |
1821 return; |
|
1822 qSort(persIndexes); // The dropped items will remain in the same visual order. |
1807 |
1823 |
1808 QPersistentModelIndex dropRow = model()->index(row, col, topIndex); |
1824 QPersistentModelIndex dropRow = model()->index(row, col, topIndex); |
1809 |
1825 |
1810 QList<QListWidgetItem *> taken; |
1826 int r = row == -1 ? count() : (dropRow.row() >= 0 ? dropRow.row() : row); |
1811 for (int i = 0; i < persIndexes.count(); ++i) |
|
1812 taken.append(takeItem(persIndexes.at(i).row())); |
|
1813 |
|
1814 // insert them back in at their new positions |
|
1815 for (int i = 0; i < persIndexes.count(); ++i) { |
1827 for (int i = 0; i < persIndexes.count(); ++i) { |
1816 // Either at a specific point or appended |
1828 const QPersistentModelIndex &pIndex = persIndexes.at(i); |
1817 if (row == -1) { |
1829 d->listModel()->move(pIndex.row(), r); |
1818 insertItem(count(), taken.takeFirst()); |
1830 r = pIndex.row() + 1; // Dropped items are inserted contiguously and in the right order. |
1819 } else { |
|
1820 int r = dropRow.row() >= 0 ? dropRow.row() : row; |
|
1821 insertItem(qMin(r, count()), taken.takeFirst()); |
|
1822 } |
|
1823 } |
1831 } |
1824 |
1832 |
1825 event->accept(); |
1833 event->accept(); |
1826 // Don't want QAbstractItemView to delete it because it was "moved" we already did it |
1834 // Don't want QAbstractItemView to delete it because it was "moved" we already did it |
1827 event->setDropAction(Qt::CopyAction); |
1835 event->setDropAction(Qt::CopyAction); |