QModelIndex dropModelIndex = indexAt(dropEvent->pos());
// Create a previous parent folder ID standard C++ list (which can be sorted and from which duplicates can be removed).
- std::list<double> previousParentFolderIdList;
+ std::list<double> *previousParentFolderIdListPointer = new std::list<double>;
// Process the move according to the drop position.
switch (dropPosition)
{
case QAbstractItemView::OnItem: // This will only ever be called for folders as `BookmarksDialog::populateSubfolders` creates bookmarks without `setDropEnabled`.
{
- // Get the new parent folder ID.
- double newParentFolderId = dropModelIndex.siblingAtColumn(BookmarksDialog::FOLDER_ID_COLUMN).data().toDouble();
+ // Move everything to the beginning of the folder.
+ moveToBeginningOfFolder(dropModelIndex, selectedDatabaseIdsListPointer, rootSelectedDatabaseIdsListPointer, previousParentFolderIdListPointer);
- // Get a list of all the items in the target folder except those selected.
- QList<BookmarkStruct> *itemsInFolderExceptSelectedListPointer = BookmarksDatabase::getBookmarksInFolderExcept(newParentFolderId, selectedDatabaseIdsListPointer);
-
- // Initialize a new display order tracker.
- int newDisplayOrder = 0;
-
- // Move all the items to the top of the target folder.
- for (const int databaseId : *rootSelectedDatabaseIdsListPointer)
- {
- // Get the item's current parent folder ID.
- double currentParentFolderId = BookmarksDatabase::getParentFolderId(databaseId);
-
- // Add the parent folder ID to the list of previous parent folders if the item is from a different folder.
- if (currentParentFolderId != newParentFolderId)
- previousParentFolderIdList.push_back(currentParentFolderId);
-
- // Update the parent folder and display order for each bookmark.
- BookmarksDatabase::updateParentFolderAndDisplayOrder(databaseId, newParentFolderId, newDisplayOrder);
-
- // Increment the new display order.
- ++newDisplayOrder;
- }
-
- // Update the display order of the existing items in the folder.
- for (const BookmarkStruct &bookmarkStruct : *itemsInFolderExceptSelectedListPointer)
- {
- // Set the bookmark's display order if it has changed.
- if (bookmarkStruct.displayOrder != newDisplayOrder)
- BookmarksDatabase::updateDisplayOrder(bookmarkStruct.databaseId, newDisplayOrder);
-
- // Increment the new display order.
- ++newDisplayOrder;
- }
break;
}
// Add the parent folder ID to the list of previous parent folders if the item is from a different folder.
if (currentParentFolderId != dropParentFolderId)
- previousParentFolderIdList.push_back(currentParentFolderId);
+ previousParentFolderIdListPointer->push_back(currentParentFolderId);
// Update the parent folder and display order for each bookmark.
BookmarksDatabase::updateParentFolderAndDisplayOrder(databaseId, dropParentFolderId, newDisplayOrder);
case QAbstractItemView::BelowItem:
{
- // Get the drop display order.
- int dropDisplayOrder = dropModelIndex.siblingAtColumn(BookmarksDialog::DISPLAY_ORDER_COLUMN).data().toInt();
+ // Check to see if the drop model index is an expanded folder.
+ if (dropModelIndex.siblingAtColumn(BookmarksDialog::IS_FOLDER_COLUMN).data().toBool() && isExpanded(dropModelIndex)) // The drop model index is an expanded folder.
+ {
+ // Move everything to the beginning of the folder.
+ moveToBeginningOfFolder(dropModelIndex, selectedDatabaseIdsListPointer, rootSelectedDatabaseIdsListPointer, previousParentFolderIdListPointer);
+ }
+ else // The drop model index is not an expanded folder.
+ {
+ // Get the drop display order.
+ int dropDisplayOrder = dropModelIndex.siblingAtColumn(BookmarksDialog::DISPLAY_ORDER_COLUMN).data().toInt();
- // Get the drop parent folder ID.
- double dropParentFolderId = dropModelIndex.parent().siblingAtColumn(BookmarksDialog::FOLDER_ID_COLUMN).data().toDouble();
+ // Get the drop parent folder ID.
+ double dropParentFolderId = dropModelIndex.parent().siblingAtColumn(BookmarksDialog::FOLDER_ID_COLUMN).data().toDouble();
- // Get a list of all the items in the target folder except those selected.
- QList<BookmarkStruct> *itemsInFolderExceptSelectedListPointer = BookmarksDatabase::getBookmarksInFolderExcept(dropParentFolderId, selectedDatabaseIdsListPointer);
+ // Get a list of all the items in the target folder except those selected.
+ QList<BookmarkStruct> *itemsInFolderExceptSelectedListPointer = BookmarksDatabase::getBookmarksInFolderExcept(dropParentFolderId, selectedDatabaseIdsListPointer);
- // Initialize a new display order tracker.
- int newDisplayOrder = 0;
+ // Initialize a new display order tracker.
+ int newDisplayOrder = 0;
- // Process all the items in the target folder, moving in the new ones.
- for (const BookmarkStruct &bookmarkStruct : *itemsInFolderExceptSelectedListPointer)
- {
- // Set the bookmark's display order if it has changed.
- if (bookmarkStruct.displayOrder != newDisplayOrder)
- BookmarksDatabase::updateDisplayOrder(bookmarkStruct.databaseId, newDisplayOrder);
-
- // Increment the new display order.
- ++newDisplayOrder;
-
- // Check to see if this is the drop display order.
- if (bookmarkStruct.displayOrder == dropDisplayOrder)
+ // Process all the items in the target folder, moving in the new ones.
+ for (const BookmarkStruct &bookmarkStruct : *itemsInFolderExceptSelectedListPointer)
{
- // Add all of the bookmarks being moved to this point.
- for (const int databaseId : *rootSelectedDatabaseIdsListPointer)
- {
- // Get the item's current parent folder ID.
- double currentParentFolderId = BookmarksDatabase::getParentFolderId(databaseId);
+ // Set the bookmark's display order if it has changed.
+ if (bookmarkStruct.displayOrder != newDisplayOrder)
+ BookmarksDatabase::updateDisplayOrder(bookmarkStruct.databaseId, newDisplayOrder);
- // Add the parent folder ID to the list of previous parent folders if the item is from a different folder.
- if (currentParentFolderId != dropParentFolderId)
- previousParentFolderIdList.push_back(currentParentFolderId);
-
- // Update the parent folder and display order for each bookmark.
- BookmarksDatabase::updateParentFolderAndDisplayOrder(databaseId, dropParentFolderId, newDisplayOrder);
+ // Increment the new display order.
+ ++newDisplayOrder;
- // Increment the new display order.
- ++newDisplayOrder;
+ // Check to see if this is the drop display order.
+ if (bookmarkStruct.displayOrder == dropDisplayOrder)
+ {
+ // Add all of the bookmarks being moved to this point.
+ for (const int databaseId : *rootSelectedDatabaseIdsListPointer)
+ {
+ // Get the item's current parent folder ID.
+ double currentParentFolderId = BookmarksDatabase::getParentFolderId(databaseId);
+
+ // Add the parent folder ID to the list of previous parent folders if the item is from a different folder.
+ if (currentParentFolderId != dropParentFolderId)
+ previousParentFolderIdListPointer->push_back(currentParentFolderId);
+
+ // Update the parent folder and display order for each bookmark.
+ BookmarksDatabase::updateParentFolderAndDisplayOrder(databaseId, dropParentFolderId, newDisplayOrder);
+
+ // Increment the new display order.
+ ++newDisplayOrder;
+ }
}
}
}
// Add the parent folder ID to the list of previous parent folders if the item is from a different folder.
if (currentParentFolderId != dropParentFolderId)
- previousParentFolderIdList.push_back(currentParentFolderId);
+ previousParentFolderIdListPointer->push_back(currentParentFolderId);
// Update the parent folder and display order for each bookmark.
BookmarksDatabase::updateParentFolderAndDisplayOrder(databaseId, dropParentFolderId, newDisplayOrder);
}
// Sort the previous parent folder ID list.
- previousParentFolderIdList.sort();
+ previousParentFolderIdListPointer->sort();
// Remove duplicates from the parent folder ID list.
- previousParentFolderIdList.unique();
+ previousParentFolderIdListPointer->unique();
// Update the folder contents display order for each previous parent folder.
- for (const double parentFolderId : previousParentFolderIdList)
+ for (const double parentFolderId : *previousParentFolderIdListPointer)
BookmarksDatabase::updateFolderContentsDisplayOrder(parentFolderId);
// Emit the bookmarks moved signal.
// Return the root selected database IDs list.
return rootSelectedDatabaseIdsListPointer;
}
+
+void DraggableTreeView::moveToBeginningOfFolder(const QModelIndex &dropModelIndex, QList<int> *selectedDatabaseIdsListPointer, QList<int> *rootSelectedDatabaseIdsListPointer,
+ std::list<double> *previousParentFolderIdListPointer) const
+{
+ // Get the new parent folder ID.
+ double newParentFolderId = dropModelIndex.siblingAtColumn(BookmarksDialog::FOLDER_ID_COLUMN).data().toDouble();
+
+ // Get a list of all the items in the target folder except those selected.
+ QList<BookmarkStruct> *itemsInFolderExceptSelectedListPointer = BookmarksDatabase::getBookmarksInFolderExcept(newParentFolderId, selectedDatabaseIdsListPointer);
+
+ // Initialize a new display order tracker.
+ int newDisplayOrder = 0;
+
+ // Move all the items to the top of the target folder.
+ for (const int databaseId : *rootSelectedDatabaseIdsListPointer)
+ {
+ // Get the item's current parent folder ID.
+ double currentParentFolderId = BookmarksDatabase::getParentFolderId(databaseId);
+
+ // Add the parent folder ID to the list of previous parent folders if the item is from a different folder.
+ if (currentParentFolderId != newParentFolderId)
+ previousParentFolderIdListPointer->push_back(currentParentFolderId);
+
+ // Update the parent folder and display order for each bookmark.
+ BookmarksDatabase::updateParentFolderAndDisplayOrder(databaseId, newParentFolderId, newDisplayOrder);
+
+ // Increment the new display order.
+ ++newDisplayOrder;
+ }
+
+ // Update the display order of the existing items in the folder.
+ for (const BookmarkStruct &bookmarkStruct : *itemsInFolderExceptSelectedListPointer)
+ {
+ // Set the bookmark's display order if it has changed.
+ if (bookmarkStruct.displayOrder != newDisplayOrder)
+ BookmarksDatabase::updateDisplayOrder(bookmarkStruct.databaseId, newDisplayOrder);
+
+ // Increment the new display order.
+ ++newDisplayOrder;
+ }
+}