Implement component preview reload
parent
b05066cd96
commit
e9b1c90220
|
@ -8,9 +8,33 @@ ComponentListModel::ComponentListModel(const Document *document, QObject *parent
|
||||||
m_document(document)
|
m_document(document)
|
||||||
{
|
{
|
||||||
connect(m_document, &Document::componentPreviewPixmapChanged, [this](const dust3d::Uuid &componentId) {
|
connect(m_document, &Document::componentPreviewPixmapChanged, [this](const dust3d::Uuid &componentId) {
|
||||||
// FIXME: dont refresh the whole layout
|
auto findIndex = this->m_componentIdToIndexMap.find(componentId);
|
||||||
emit this->layoutChanged();
|
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
|
int ComponentListModel::rowCount(const QModelIndex &parent) const
|
||||||
|
@ -87,8 +111,8 @@ void ComponentListModel::setListingComponentId(const dust3d::Uuid &componentId)
|
||||||
if (m_listingComponentId == componentId)
|
if (m_listingComponentId == componentId)
|
||||||
return;
|
return;
|
||||||
m_listingComponentId = componentId;
|
m_listingComponentId = componentId;
|
||||||
|
reload();
|
||||||
emit listingComponentChanged(m_listingComponentId);
|
emit listingComponentChanged(m_listingComponentId);
|
||||||
emit layoutChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const dust3d::Uuid ComponentListModel::listingComponentId() const
|
const dust3d::Uuid ComponentListModel::listingComponentId() const
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#ifndef DUST3D_APPLICATION_COMPONENT_LIST_MODEL_H_
|
#ifndef DUST3D_APPLICATION_COMPONENT_LIST_MODEL_H_
|
||||||
#define DUST3D_APPLICATION_COMPONENT_LIST_MODEL_H_
|
#define DUST3D_APPLICATION_COMPONENT_LIST_MODEL_H_
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <unordered_map>
|
||||||
#include <dust3d/base/uuid.h>
|
#include <dust3d/base/uuid.h>
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
class Document;
|
class Document;
|
||||||
class SkeletonComponent;
|
class SkeletonComponent;
|
||||||
|
@ -22,9 +23,11 @@ public:
|
||||||
const dust3d::Uuid listingComponentId() const;
|
const dust3d::Uuid listingComponentId() const;
|
||||||
public slots:
|
public slots:
|
||||||
void setListingComponentId(const dust3d::Uuid &componentId);
|
void setListingComponentId(const dust3d::Uuid &componentId);
|
||||||
|
void reload();
|
||||||
private:
|
private:
|
||||||
const Document *m_document = nullptr;
|
const Document *m_document = nullptr;
|
||||||
dust3d::Uuid m_listingComponentId;
|
dust3d::Uuid m_listingComponentId;
|
||||||
|
std::unordered_map<dust3d::Uuid, QModelIndex> m_componentIdToIndexMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue