优化图层列表显示效果 | #7

dev-LayerStyle
karlis 2023-03-18 23:10:16 +08:00
parent 6494c2b9af
commit 3d8420f617
7 changed files with 74 additions and 13 deletions

View File

@ -182,7 +182,12 @@
</property>
<column>
<property name="text">
<string>图层树</string>
<string>图层名</string>
</property>
</column>
<column>
<property name="text">
<string>关联图元</string>
</property>
</column>
</widget>

View File

@ -32,6 +32,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
connect(treeWidget, &LayerTreeWidget::requireRefreshPreview, this,
&EditorWidgetItem::triggerRefreshPreview);
connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireSelfRefresh, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh);
connect(elementInfoDisplayWidget, &ElementPoolWidget::refreshLayerTree, treeWidget, &LayerTreeWidget::refresh);
// &EditorWidget::triggerRefreshPreview);
// test
QFile settingFile;

View File

@ -67,6 +67,7 @@ void ElementPoolWidget::setElementManager(ElementManager* element)
void ElementPoolWidget::refresh() {
this->setElementList(this->elementManager->elements);
emit refreshLayerTree();
// update();
}

View File

@ -25,6 +25,7 @@ public:
signals:
void elementSelected(GraphicElement* element);
void refreshLayerTree();
public slots:
int pictureItemClicked(QListWidgetItem* item);

View File

@ -192,19 +192,39 @@ 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;
}
QTreeWidgetItem* LeafLayerWrapper::getQTreeItem()
{
if (this->qTreeWidgetItem == nullptr)
this->qTreeWidgetItem = new QTreeWidgetItem();
if (typeid(*wrappedElement) == typeid(GroupElement))
{
this->qTreeWidgetItem->setText(0, "@ "+this->property.name);
}
else
{
this->qTreeWidgetItem->setText(0, this->property.name);
}
this->qTreeWidgetItem->setText(1,">> "+this->wrappedElement->name);
this->qTreeWidgetItem->setTextColor(1, Qt::blue);
return LayerWrapper::getQTreeItem();
}
QTreeWidgetItem* FolderLayerWrapper::getQTreeItem()
{
while (this->qTreeWidgetItem->childCount() > 0) {
this->qTreeWidgetItem->removeChild(this->qTreeWidgetItem->child(0));
}
for (auto& child : this->children) {
this->qTreeWidgetItem->addChild(child->getQTreeItem());
}
this->qTreeWidgetItem->setText(0, this->property.name);
auto ele = this->elementManager->getElementById(this->getReferencedBy());
if (ele != nullptr)
{
this->qTreeWidgetItem->setText(1, "<< " + ele->name);
this->qTreeWidgetItem->setTextColor(1, Qt::darkGreen);
}
return LayerWrapper::getQTreeItem();
}
@ -318,3 +338,36 @@ void FolderLayerWrapper::collectDownReachable(std::set<LayerWrapper*>& reachable
for (auto& child : children)
child->collectDownReachable(reachable);
}
void LayerWrapper::refreshTreeItem()
{
}
void LeafLayerWrapper::refreshTreeItem()
{
if (typeid(*wrappedElement) == typeid(GroupElement))
{
this->qTreeWidgetItem->setText(0, "@ " + this->property.name);
}
else
{
this->qTreeWidgetItem->setText(0, this->property.name);
}
this->qTreeWidgetItem->setText(1, ">> " + this->wrappedElement->name);
this->qTreeWidgetItem->setTextColor(1, Qt::blue);
}
void FolderLayerWrapper::refreshTreeItem()
{
for (auto& child : this->children) {
child->refreshTreeItem();
}
this->qTreeWidgetItem->setText(0, this->property.name);
auto ele = this->elementManager->getElementById(this->getReferencedBy());
if (ele != nullptr)
{
this->qTreeWidgetItem->setText(1, "<< " + ele->name);
this->qTreeWidgetItem->setTextColor(1, Qt::darkGreen);
}
}

View File

@ -70,6 +70,7 @@ class LayerWrapper
~LayerWrapper() = default;
virtual void collectUpReachable(std::set<LayerWrapper*>& reachable);
virtual void collectDownReachable(std::set<LayerWrapper*>& reachable);
virtual void refreshTreeItem();
};
class FolderLayerWrapper : public LayerWrapper
@ -94,6 +95,7 @@ class FolderLayerWrapper : public LayerWrapper
int getReferencedBy()const;
void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override;
void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
void refreshTreeItem() override;
};
class LeafLayerWrapper : public LayerWrapper
@ -110,6 +112,8 @@ class LeafLayerWrapper : public LayerWrapper
QJsonObject toJson() const override;
void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override;
void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
QTreeWidgetItem* getQTreeItem() override;
void refreshTreeItem() override;
};
Q_DECLARE_METATYPE(LayerWrapper *)

View File

@ -9,7 +9,7 @@ LayerTreeWidget::LayerTreeWidget(QWidget *parent)
this->selectedItem = nullptr;
this->copiedItem = nullptr;
this->setContextMenuPolicy(Qt::CustomContextMenu);
this->setHeaderLabel("Layer Content");
this->setColumnWidth(0, 240);
connect(this, &QTreeWidget::customContextMenuRequested, this, &LayerTreeWidget::popMenu);
connect(this, &QTreeWidget::currentItemChanged, [=](QTreeWidgetItem *currentItem) {
if (this->selectedItem != nullptr) {
@ -126,9 +126,5 @@ void LayerTreeWidget::onRenameEvent()
}
void LayerTreeWidget::refresh() {
// if(this->root!=nullptr)
//{
// this->clear();
// this->addTopLevelItem(this->root->getQTreeItem());
//}
this->root->refreshTreeItem();
}