Setup Table model and Table view

This commit is contained in:
igarri
2021-04-22 13:19:39 +01:00
parent c66e2f4bcf
commit 0ebe6c6079
14 changed files with 492 additions and 186 deletions
@@ -0,0 +1,36 @@
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
#include <AzToolsFramework/AssetBrowser/Entries/AssetBrowserEntry.h>
#include <AzToolsFramework/AssetBrowser/Search/Filter.h>
#include <AzCore/Asset/AssetCommon.h>
#include <AzCore/std/containers/fixed_unordered_set.h>
#include <AzCore/std/containers/vector.h>
AZ_PUSH_DISABLE_WARNING(
4251, "-Wunknown-warning-option") // 4251: class '...' needs to have dll-interface to be used by clients of class '...'
#include <QCollator>
#include <QSharedPointer>
#include <QSortFilterProxyModel>
#endif
AZ_POP_DISABLE_WARNING
namespace AzToolsFramework
{
namespace AssetBrowser
{
class AssetBrowserTableModel
: public QSortFilterProxyModel
{
Q_OBJECT
public:
AZ_CLASS_ALLOCATOR(AssetBrowserTableModel, AZ::SystemAllocator, 0);
explicit AssetBrowserTableModel(QObject* parent = nullptr);
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
};
}
}
@@ -0,0 +1,37 @@
#include "AssetBrowserTableModel.h"
namespace AzToolsFramework
{
namespace AssetBrowser
{
AssetBrowserTableModel::AssetBrowserTableModel(QObject* parent /* = nullptr */)
: QSortFilterProxyModel(parent)
{
}
QModelIndex AssetBrowserTableModel::mapToSource(const QModelIndex& proxyIndex) const
{
AZ_UNUSED(proxyIndex);
return QModelIndex();
}
QModelIndex AssetBrowserTableModel::mapFromSource(const QModelIndex& sourceIndex) const
{
AZ_UNUSED(sourceIndex);
return QModelIndex();
}
QModelIndex AssetBrowserTableModel::index(int row, int column, const QModelIndex& parent) const
{
AZ_UNUSED(row);
AZ_UNUSED(column);
AZ_UNUSED(parent);
return QModelIndex();
}
QVariant AssetBrowserTableModel::data(const QModelIndex& index, int role) const
{
AZ_UNUSED(index);
AZ_UNUSED(role);
return QVariant();
}
} // namespace AssetBrowser
} // namespace AzToolsFramework
#include "AssetBrowser/moc_AssetBrowserTableModel.cpp"
@@ -0,0 +1,36 @@
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
#include <AzToolsFramework/AssetBrowser/Entries/AssetBrowserEntry.h>
#include <AzToolsFramework/AssetBrowser/Search/Filter.h>
#include <AzCore/Asset/AssetCommon.h>
#include <AzCore/std/containers/fixed_unordered_set.h>
#include <AzCore/std/containers/vector.h>
AZ_PUSH_DISABLE_WARNING(
4251, "-Wunknown-warning-option") // 4251: class '...' needs to have dll-interface to be used by clients of class '...'
#include <QCollator>
#include <QSharedPointer>
#include <QSortFilterProxyModel>
#endif
AZ_POP_DISABLE_WARNING
namespace AzToolsFramework
{
namespace AssetBrowser
{
class AssetBrowserTableModel
: public QSortFilterProxyModel
{
Q_OBJECT
public:
AZ_CLASS_ALLOCATOR(AssetBrowserTableModel, AZ::SystemAllocator, 0);
explicit AssetBrowserTableModel(QObject* parent = nullptr);
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
};
}
}
@@ -46,6 +46,7 @@ namespace AzToolsFramework
const char* AssetBrowserEntry::m_columnNames[] =
{
"Name",
"Path",
"Source ID",
"Fingerprint",
"Guid",
@@ -128,6 +129,8 @@ namespace AzToolsFramework
return QString::fromUtf8(m_name.c_str());
case Column::DisplayName:
return m_displayName;
case Column::Path:
return m_displayPath;
default:
return QVariant();
}
@@ -283,4 +286,4 @@ namespace AzToolsFramework
} // namespace AssetBrowser
} // namespace AzToolsFramework
#include "AssetBrowser/Entries/moc_AssetBrowserEntry.cpp"
#include "AssetBrowser/Entries/moc_AssetBrowserEntry.cpp"
@@ -68,6 +68,7 @@ namespace AzToolsFramework
enum class Column
{
Name,
Path,
SourceID,
Fingerprint,
Guid,
@@ -135,6 +136,7 @@ namespace AzToolsFramework
protected:
AZStd::string m_name;
QString m_displayName;
QString m_displayPath;
AZStd::string m_relativePath;
AZStd::string m_fullPath;
AZStd::vector<AssetBrowserEntry*> m_children;
@@ -43,6 +43,7 @@ namespace AzToolsFramework
void FolderAssetBrowserEntry::UpdateChildPaths(AssetBrowserEntry* child) const
{
child->m_relativePath = m_relativePath + AZ_CORRECT_DATABASE_SEPARATOR + child->m_name;
child->m_displayPath = QString::fromUtf8(child->m_relativePath.c_str());
child->m_fullPath = m_fullPath + AZ_CORRECT_DATABASE_SEPARATOR + child->m_name;
AssetBrowserEntry::UpdateChildPaths(child);
}
@@ -292,6 +292,9 @@ namespace AzToolsFramework
product->m_assetType = productWithUuidDatabaseEntry.second.m_assetType;
product->m_assetType.ToString(product->m_assetTypeString);
AZ::Data::AssetCatalogRequestBus::BroadcastResult(product->m_relativePath, &AZ::Data::AssetCatalogRequests::GetAssetPathById, assetId);
QString displayPath = QString::fromUtf8(product->m_relativePath.c_str());
displayPath.remove(QString("/" + QString::fromUtf8(product->m_name.c_str())));
product->m_displayPath = displayPath;
EntryCache::GetInstance()->m_productAssetIdMap[assetId] = product;
if (needsAdd)
@@ -0,0 +1,65 @@
#include "AssetBrowserTableView.h"
#pragma optimize("", off)
namespace AzToolsFramework
{
namespace AssetBrowser
{
AssetBrowserTableView::AssetBrowserTableView(QWidget* parent)
: QTableView(parent)
{
AssetBrowserViewRequestBus::Handler::BusConnect();
AssetBrowserComponentNotificationBus::Handler::BusConnect();
}
AssetBrowserTableView::~AssetBrowserTableView()
{
AssetBrowserViewRequestBus::Handler::BusDisconnect();
AssetBrowserComponentNotificationBus::Handler::BusDisconnect();
}
void AssetBrowserTableView::setModel(QAbstractItemModel* model)
{
//m_assetBrowserSortFilterProxyModel = qobject_cast<AssetBrowserTableFilterModel*>(model);
//AZ_Assert(m_assetBrowserSortFilterProxyModel, "Expecting AssetBrowserTableFilterModel");
//m_assetBrowserModel = qobject_cast<AssetBrowserModel*>(m_assetBrowserSortFilterProxyModel->sourceModel());
QTableView::setModel(model);
}
void AssetBrowserTableView::SetName(const QString& name)
{
m_name = name;
bool isAssetBrowserComponentReady = false;
AssetBrowserComponentRequestBus::BroadcastResult(isAssetBrowserComponentReady, &AssetBrowserComponentRequests::AreEntriesReady);
if (isAssetBrowserComponentReady)
{
OnAssetBrowserComponentReady();
}
}
AZStd::vector<AssetBrowserEntry*> AssetBrowserTableView::GetSelectedAssets() const
{
return AZStd::vector<AssetBrowserEntry*>();
}
void AssetBrowserTableView::SelectProduct(AZ::Data::AssetId assetID)
{
AZ_UNUSED(assetID);
}
void AssetBrowserTableView::SelectFileAtPath(const AZStd::string& assetPath)
{
AZ_UNUSED(assetPath);
}
void AssetBrowserTableView::ClearFilter()
{
}
void AssetBrowserTableView::Update()
{
}
//void AssetBrowserTableView::OnAssetBrowserComponentReady()
//{
//}
} // namespace AssetBrowser
} // namespace AzToolsFramework
#pragma optimize("", on)
#include "AssetBrowser/Views/moc_AssetBrowserTableView.cpp"
@@ -0,0 +1,56 @@
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzCore/Asset/AssetCommon.h>
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/std/containers/vector.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
//#include <AzToolsFramework/AssetBrowser/AssetBrowserTableFilterModel.h>
#include <QModelIndex>
#include <QPointer>
#include <QTableView>
#endif
namespace AzToolsFramework
{
namespace AssetBrowser
{
class AssetBrowserEntry;
class AssetBrowserModel;
class AssetBrowserFilterModel;
class EntryDelegate;
class AssetBrowserTableView
: public QTableView
, public AssetBrowserViewRequestBus::Handler
, public AssetBrowserComponentNotificationBus::Handler
{
Q_OBJECT
public:
explicit AssetBrowserTableView(QWidget* parent = nullptr);
~AssetBrowserTableView() override;
void setModel(QAbstractItemModel *model) override;
void SetName(const QString& name);
AZStd::vector<AssetBrowserEntry*> GetSelectedAssets() const;
//////////////////////////////////////////////////////////////////////////
// AssetBrowserViewRequestBus
virtual void SelectProduct(AZ::Data::AssetId assetID) override;
virtual void SelectFileAtPath(const AZStd::string& assetPath) override;
virtual void ClearFilter() override;
virtual void Update() override;
//////////////////////////////////////////////////////////////////////////
// AssetBrowserComponentNotificationBus
//void OnAssetBrowserComponentReady() override;
//////////////////////////////////////////////////////////////////////////
private:
QString m_name;
};
} // namespace AssetBrowser
} // namespace AzToolsFramework
@@ -74,34 +74,34 @@ namespace AzToolsFramework
QPoint iconTopLeft(remainingRect.x(), remainingRect.y() + (remainingRect.height() / 2) - (m_iconSize / 2));
auto sourceEntry = azrtti_cast<const SourceAssetBrowserEntry*>(entry);
int thumbX = DrawThumbnail(painter, iconTopLeft, iconSize, entry->GetThumbnailKey());
QPalette actualPalette(option.palette);
if (sourceEntry)
if (index.column() == static_cast<int>(AssetBrowserEntry::Column::Name))
{
if (m_showSourceControl)
int thumbX = DrawThumbnail(painter, iconTopLeft, iconSize, entry->GetThumbnailKey());
if (sourceEntry)
{
DrawThumbnail(painter, iconTopLeft, iconSize, sourceEntry->GetSourceControlThumbnailKey());
}
// sources with no children should be greyed out.
if (sourceEntry->GetChildCount() == 0)
{
isEnabled = false; // draw in disabled style.
actualPalette.setCurrentColorGroup(QPalette::Disabled);
if (m_showSourceControl)
{
DrawThumbnail(painter, iconTopLeft, iconSize, sourceEntry->GetSourceControlThumbnailKey());
}
// sources with no children should be greyed out.
if (sourceEntry->GetChildCount() == 0)
{
isEnabled = false; // draw in disabled style.
actualPalette.setCurrentColorGroup(QPalette::Disabled);
}
}
remainingRect.adjust(thumbX, 0, 0, 0); // bump it to the right by the size of the thumbnail
remainingRect.adjust(ENTRY_SPACING_LEFT_PIXELS, 0, 0, 0); // bump it to the right by the spacing.
}
QString displayString = qvariant_cast<QString>(index.data(index.column()));
remainingRect.adjust(thumbX, 0, 0, 0); // bump it to the right by the size of the thumbnail
remainingRect.adjust(ENTRY_SPACING_LEFT_PIXELS, 0, 0, 0); // bump it to the right by the spacing.
style->drawItemText(painter,
remainingRect,
option.displayAlignment,
actualPalette,
isEnabled,
entry->GetDisplayName(),
style->drawItemText(
painter, remainingRect, option.displayAlignment, actualPalette, isEnabled,
index.column() == static_cast<int>(AssetBrowserEntry::Column::Name)
? qvariant_cast<QString>(entry->data(static_cast<int>(AssetBrowserEntry::Column::Name)))
: qvariant_cast<QString>(entry->data(static_cast<int>(AssetBrowserEntry::Column::Path))),
isSelected ? QPalette::HighlightedText : QPalette::Text);
}
}
@@ -545,6 +545,8 @@ set(FILES
AssetBrowser/AssetBrowserEntry.h
AssetBrowser/AssetBrowserFilterModel.cpp
AssetBrowser/AssetBrowserFilterModel.h
AssetBrowser/AssetBrowserTableModel.cpp
AssetBrowser/AssetBrowserTableModel.h
AssetBrowser/AssetBrowserModel.cpp
AssetBrowser/AssetBrowserModel.h
AssetBrowser/AssetEntryChange.h
@@ -555,6 +557,8 @@ set(FILES
AssetBrowser/EBusFindAssetTypeByName.h
AssetBrowser/Views/AssetBrowserTreeView.cpp
AssetBrowser/Views/AssetBrowserTreeView.h
AssetBrowser/Views/AssetBrowserTableView.cpp
AssetBrowser/Views/AssetBrowserTableView.h
AssetBrowser/Views/EntryDelegate.cpp
AssetBrowser/Views/EntryDelegate.h
AssetBrowser/Views/AssetBrowserFolderWidget.cpp