diff --git a/application/sources/component_list_model.cc b/application/sources/component_list_model.cc index 35f9c413..860e97ad 100644 --- a/application/sources/component_list_model.cc +++ b/application/sources/component_list_model.cc @@ -8,9 +8,33 @@ ComponentListModel::ComponentListModel(const Document *document, QObject *parent m_document(document) { connect(m_document, &Document::componentPreviewPixmapChanged, [this](const dust3d::Uuid &componentId) { - // FIXME: dont refresh the whole layout - emit this->layoutChanged(); + auto findIndex = this->m_componentIdToIndexMap.find(componentId); + if (findIndex != this->m_componentIdToIndexMap.end()) { + //dust3dDebug << "dataChanged:" << findIndex->second.row(); + emit this->dataChanged(findIndex->second, findIndex->second); + } }); + connect(m_document, &Document::cleanup, [this]() { + this->setListingComponentId(dust3d::Uuid()); + this->reload(); + }); + connect(m_document, &Document::componentChildrenChanged, [this](const dust3d::Uuid &componentId) { + if (componentId != this->listingComponentId()) + return; + this->reload(); + }); +} + +void ComponentListModel::reload() +{ + m_componentIdToIndexMap.clear(); + const SkeletonComponent *listingComponent = m_document->findComponent(m_listingComponentId); + if (nullptr != listingComponent) { + for (int i = 0; i < (int)listingComponent->childrenIds.size(); ++i) { + m_componentIdToIndexMap[listingComponent->childrenIds[i]] = index(i); + } + } + emit this->layoutChanged(); } int ComponentListModel::rowCount(const QModelIndex &parent) const @@ -87,8 +111,8 @@ void ComponentListModel::setListingComponentId(const dust3d::Uuid &componentId) if (m_listingComponentId == componentId) return; m_listingComponentId = componentId; + reload(); emit listingComponentChanged(m_listingComponentId); - emit layoutChanged(); } const dust3d::Uuid ComponentListModel::listingComponentId() const diff --git a/application/sources/component_list_model.h b/application/sources/component_list_model.h index 95e3bb8f..35b88eff 100644 --- a/application/sources/component_list_model.h +++ b/application/sources/component_list_model.h @@ -1,8 +1,9 @@ #ifndef DUST3D_APPLICATION_COMPONENT_LIST_MODEL_H_ #define DUST3D_APPLICATION_COMPONENT_LIST_MODEL_H_ -#include +#include #include +#include class Document; class SkeletonComponent; @@ -22,9 +23,11 @@ public: const dust3d::Uuid listingComponentId() const; public slots: void setListingComponentId(const dust3d::Uuid &componentId); + void reload(); private: const Document *m_document = nullptr; dust3d::Uuid m_listingComponentId; + std::unordered_map m_componentIdToIndexMap; }; #endif