/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include namespace AssetBundler { ////////////////////////////////////////////////////////////////////////////////////////////////// // AssetListTableModel ////////////////////////////////////////////////////////////////////////////////////////////////// AssetListTableModel::AssetListTableModel(QObject* parent, const AZStd::string& absolutePath, const AZStd::string& platform) : QAbstractTableModel(parent) { m_seedListManager.reset(new AzToolsFramework::AssetSeedManager()); if (absolutePath.empty() || platform.empty()) { return; } AZ::Outcome outcome = m_seedListManager->LoadAssetFileInfo(absolutePath); if (!outcome.IsSuccess()) { AZ_Error(AssetBundler::AppWindowName, false, "Failed to load the asset file info for %s", absolutePath.c_str()); return; } m_assetFileInfoList = outcome.TakeValue(); m_platformId = static_cast(AzFramework::PlatformHelper::GetPlatformIndexFromName(platform.c_str())); } int AssetListTableModel::rowCount(const QModelIndex& parent) const { return parent.isValid() ? 0 : static_cast(m_assetFileInfoList.m_fileInfoList.size()); } int AssetListTableModel::columnCount(const QModelIndex& parent) const { return parent.isValid() ? 0 : Column::Max; } QVariant AssetListTableModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { switch (section) { case Column::ColumnAssetName: return QString("Asset Name"); case Column::ColumnRelativePath: return QString("Relative Path"); case Column::ColumnAssetId: return QString("Asset ID"); default: break; } } return QVariant(); } QVariant AssetListTableModel::data(const QModelIndex& index, int role) const { auto assetFileInfoOutcome = GetAssetFileInfo(index); if (!assetFileInfoOutcome.IsSuccess()) { return QVariant(); } switch (role) { case Qt::DisplayRole: { switch (index.column()) { case Column::ColumnAssetName: { AZStd::string fileName = assetFileInfoOutcome.GetValue().m_assetRelativePath; AzFramework::StringFunc::Path::GetFullFileName(fileName.c_str(), fileName); return fileName.c_str(); } case Column::ColumnRelativePath: { return assetFileInfoOutcome.GetValue().m_assetRelativePath.c_str(); } case Column::ColumnAssetId: { AZStd::string assetIdStr; assetFileInfoOutcome.GetValue().m_assetId.ToString(assetIdStr); return assetIdStr.c_str(); } default: break; } } default: break; } return QVariant(); } AZ::Outcome AssetListTableModel::GetAssetFileInfo(const QModelIndex& index) const { int row = index.row(); int col = index.column(); if (row >= rowCount() || row < 0 || col >= columnCount() || col < 0) { return AZ::Failure(AZStd::string::format("Selected index (%i, %i) is out of range", row, col)); } return AZ::Success(m_assetFileInfoList.m_fileInfoList.at(row)); } }