LYN-4863: Item data not copied on drag-n-drop if column is hidden in Asset Browser Tree View. (#1616)

* Fixed: Item returning null in drag and drop when column is hidden

* Added explanation about why this approach is needed

Signed-off-by: John <jonawals@amazon.com>
monroegm-disable-blank-issue-2
IgnacioMartinezGarrido 5 years ago committed by John
parent 1e8465f1cc
commit b87e3eb1d6

@ -185,10 +185,11 @@ namespace AzToolsFramework
void AssetBrowserTreeView::rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end) void AssetBrowserTreeView::rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end)
{ {
// if selected entry is being removed, clear selection so not to select (and attempt to preview) other entries potentially marked for deletion // if selected entry is being removed, clear selection so not to select (and attempt to preview) other entries potentially
if (selectionModel() && selectionModel()->selectedIndexes().size() == 1) // marked for deletion
if (selectionModel() && selectedIndexes().size() == 1)
{ {
QModelIndex selectedIndex = selectionModel()->selectedIndexes().first(); QModelIndex selectedIndex = selectedIndexes().first();
QModelIndex parentSelectedIndex = selectedIndex.parent(); QModelIndex parentSelectedIndex = selectedIndex.parent();
if (parentSelectedIndex == parent && selectedIndex.row() >= start && selectedIndex.row() <= end) if (parentSelectedIndex == parent && selectedIndex.row() >= start && selectedIndex.row() <= end)
{ {
@ -198,6 +199,14 @@ namespace AzToolsFramework
QTreeView::rowsAboutToBeRemoved(parent, start, end); QTreeView::rowsAboutToBeRemoved(parent, start, end);
} }
// Item data for hidden columns normally isn't copied by Qt during drag-and-drop (see QTBUG-30242).
// However, for the AssetBrowser, the hidden columns should get copied. By overriding selectedIndexes() to
// include all selected indices, not just the visible ones, we can get the behavior we're looking for.
QModelIndexList AssetBrowserTreeView::selectedIndexes() const
{
return selectionModel()->selectedIndexes();
}
void AssetBrowserTreeView::SetThumbnailContext(const char* thumbnailContext) const void AssetBrowserTreeView::SetThumbnailContext(const char* thumbnailContext) const
{ {
m_delegate->SetThumbnailContext(thumbnailContext); m_delegate->SetThumbnailContext(thumbnailContext);

@ -95,6 +95,9 @@ namespace AzToolsFramework
void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) override; void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) override;
void rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end) override; void rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end) override;
protected:
QModelIndexList selectedIndexes() const override;
private: private:
QPointer<AssetBrowserModel> m_assetBrowserModel = nullptr; QPointer<AssetBrowserModel> m_assetBrowserModel = nullptr;
QPointer<AssetBrowserFilterModel> m_assetBrowserSortFilterProxyModel = nullptr; QPointer<AssetBrowserFilterModel> m_assetBrowserSortFilterProxyModel = nullptr;

Loading…
Cancel
Save