2022-10-02 19:45:46 +00:00
|
|
|
#include "component_preview_grid_widget.h"
|
|
|
|
#include "component_list_model.h"
|
2022-10-03 00:06:25 +00:00
|
|
|
#include "document.h"
|
2022-10-18 09:35:04 +00:00
|
|
|
#include <memory>
|
2022-10-02 19:45:46 +00:00
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
ComponentPreviewGridWidget::ComponentPreviewGridWidget(Document* document, QWidget* parent)
|
|
|
|
: PreviewGridView(parent)
|
|
|
|
, m_document(document)
|
2022-10-02 19:45:46 +00:00
|
|
|
{
|
|
|
|
m_componentListModel = std::make_unique<ComponentListModel>(m_document);
|
|
|
|
setModel(m_componentListModel.get());
|
2022-10-03 00:06:25 +00:00
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
connect(this, &ComponentPreviewGridWidget::doubleClicked, [this](const QModelIndex& index) {
|
|
|
|
const SkeletonComponent* component = this->componentListModel()->modelIndexToComponent(index);
|
2022-10-07 21:39:38 +00:00
|
|
|
if (nullptr == component)
|
|
|
|
return;
|
|
|
|
if (component->childrenIds.empty()) {
|
|
|
|
std::vector<dust3d::Uuid> partIds;
|
|
|
|
this->m_document->collectComponentDescendantParts(component->id, partIds);
|
2022-10-18 09:35:04 +00:00
|
|
|
for (const auto& partId : partIds)
|
2022-10-07 21:39:38 +00:00
|
|
|
emit this->selectPartOnCanvas(partId);
|
|
|
|
} else {
|
2022-10-03 00:06:25 +00:00
|
|
|
this->componentListModel()->setListingComponentId(component->id);
|
|
|
|
}
|
|
|
|
});
|
2022-10-02 19:45:46 +00:00
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
ComponentListModel* ComponentPreviewGridWidget::componentListModel()
|
2022-10-02 19:45:46 +00:00
|
|
|
{
|
|
|
|
return m_componentListModel.get();
|
|
|
|
}
|
2022-10-04 09:50:39 +00:00
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
std::vector<const SkeletonComponent*> ComponentPreviewGridWidget::getSelectedComponents() const
|
2022-10-04 09:50:39 +00:00
|
|
|
{
|
2022-10-18 09:35:04 +00:00
|
|
|
std::vector<const SkeletonComponent*> components;
|
2022-10-04 09:50:39 +00:00
|
|
|
QModelIndexList selected = selectionModel()->selectedIndexes();
|
2022-10-18 09:35:04 +00:00
|
|
|
for (const auto& it : selected) {
|
|
|
|
const auto& component = m_componentListModel->modelIndexToComponent(it);
|
2022-10-04 11:45:21 +00:00
|
|
|
if (nullptr == component)
|
|
|
|
continue;
|
|
|
|
components.push_back(component);
|
2022-10-04 09:50:39 +00:00
|
|
|
}
|
|
|
|
return components;
|
|
|
|
}
|
2022-10-04 11:45:21 +00:00
|
|
|
|
|
|
|
std::vector<dust3d::Uuid> ComponentPreviewGridWidget::getSelectedComponentIds() const
|
|
|
|
{
|
|
|
|
std::vector<dust3d::Uuid> componentIds;
|
|
|
|
QModelIndexList selected = selectionModel()->selectedIndexes();
|
2022-10-18 09:35:04 +00:00
|
|
|
for (const auto& it : selected) {
|
|
|
|
const auto& componentId = m_componentListModel->modelIndexToComponentId(it);
|
2022-10-04 11:45:21 +00:00
|
|
|
if (componentId.isNull())
|
|
|
|
continue;
|
|
|
|
componentIds.push_back(componentId);
|
|
|
|
}
|
|
|
|
return componentIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<dust3d::Uuid> ComponentPreviewGridWidget::getSelectedPartIds() const
|
|
|
|
{
|
|
|
|
auto selectedComponents = getSelectedComponents();
|
|
|
|
std::vector<dust3d::Uuid> partIds;
|
2022-10-18 09:35:04 +00:00
|
|
|
for (const auto& component : selectedComponents) {
|
2022-10-04 11:45:21 +00:00
|
|
|
if (component->linkToPartId.isNull())
|
|
|
|
continue;
|
|
|
|
partIds.push_back(component->linkToPartId);
|
|
|
|
}
|
|
|
|
return partIds;
|
|
|
|
}
|