TaoZhang-Branch
karlis 2023-03-10 19:44:18 +08:00
parent b981056674
commit 3dd7fd7c0f
3 changed files with 15 additions and 14 deletions

View File

@ -33,6 +33,7 @@ PixelPath LayerWrapper::getCache()
LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent)
{
this->parent = parent;
this->qTreeWidgetItem = new QTreeWidgetItem();
auto transformJson = json.value("transform").toObject();
property.name = json.value("name").toString();
property.offset = {transformJson.value("offset").toObject().value("x").toDouble(),
@ -119,22 +120,22 @@ void LayerWrapper::setParent(FolderLayerWrapper* newParent)
void FolderLayerWrapper::removeAllChild()
{
children.clear();
qTreeWidgetItem.takeChildren();
qTreeWidgetItem->takeChildren();
}
void LayerWrapper::del() {
qDebug() << "LayerWrapper::del()";
if (parent != nullptr){
qTreeWidgetItem.takeChildren();
parent->qTreeWidgetItem.removeChild(&qTreeWidgetItem);
qTreeWidgetItem->takeChildren();
parent->qTreeWidgetItem->removeChild(qTreeWidgetItem);
}
}
void LayerWrapper::delSelf() {
qDebug() << "LayerWrapper::delSelf()";
if (parent != nullptr) {
qTreeWidgetItem.takeChildren();
parent->qTreeWidgetItem.removeChild(&qTreeWidgetItem);
qTreeWidgetItem->takeChildren();
parent->qTreeWidgetItem->removeChild(qTreeWidgetItem);
}
}
@ -154,7 +155,7 @@ void FolderLayerWrapper::delSelf() {
qDebug() << this;
for (auto& child : this->children) {
this->parent->addChild(child);
this->parent->qTreeWidgetItem.addChild(&child.get()->qTreeWidgetItem);
this->parent->qTreeWidgetItem->addChild(child.get()->qTreeWidgetItem);
child->setParent(this->parent);
}
while (!this->children.empty()) {
@ -166,18 +167,18 @@ void FolderLayerWrapper::delSelf() {
QTreeWidgetItem* LayerWrapper::getQTreeItem()
{
this->qTreeWidgetItem.setText(0, this->property.name);
this->qTreeWidgetItem.setData(0, Qt::UserRole, QVariant::fromValue(this));
return &this->qTreeWidgetItem;
this->qTreeWidgetItem->setText(0, this->property.name);
this->qTreeWidgetItem->setData(0, Qt::UserRole, QVariant::fromValue(this));
return this->qTreeWidgetItem;
}
QTreeWidgetItem* FolderLayerWrapper::getQTreeItem()
{
while (this->qTreeWidgetItem.childCount() > 0) {
this->qTreeWidgetItem.removeChild(this->qTreeWidgetItem.child(0));
while (this->qTreeWidgetItem->childCount() > 0) {
this->qTreeWidgetItem->removeChild(this->qTreeWidgetItem->child(0));
}
for (auto& child : this->children) {
this->qTreeWidgetItem.addChild(child->getQTreeItem());
this->qTreeWidgetItem->addChild(child->getQTreeItem());
}
return LayerWrapper::getQTreeItem();
}

View File

@ -33,7 +33,7 @@ class LayerWrapper
PixelPath cache;
public:
QTreeWidgetItem qTreeWidgetItem;
QTreeWidgetItem* qTreeWidgetItem;
struct SimpleProperty
{
QString name = "";

View File

@ -51,7 +51,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
else
newLayer = new LeafLayerWrapper(jsonObj, this->elementManager, folderLayer);
folderLayer->addChild(std::shared_ptr<LayerWrapper>(newLayer));
folderLayer->qTreeWidgetItem.addChild(newLayer->getQTreeItem());
folderLayer->qTreeWidgetItem->addChild(newLayer->getQTreeItem());
qDebug() << jsonObj<<"----------------------";
this->refresh();
emit requireRefreshPreview();