优化图层列表显示效果 | #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> </property>
<column> <column>
<property name="text"> <property name="text">
<string>图层树</string> <string>图层名</string>
</property>
</column>
<column>
<property name="text">
<string>关联图元</string>
</property> </property>
</column> </column>
</widget> </widget>

View File

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

View File

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

View File

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

View File

@ -192,19 +192,39 @@ void FolderLayerWrapper::delSelf() {
QTreeWidgetItem* LayerWrapper::getQTreeItem() QTreeWidgetItem* LayerWrapper::getQTreeItem()
{ {
this->qTreeWidgetItem->setText(0, this->property.name);
this->qTreeWidgetItem->setData(0, Qt::UserRole, QVariant::fromValue(this)); this->qTreeWidgetItem->setData(0, Qt::UserRole, QVariant::fromValue(this));
return this->qTreeWidgetItem; 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() QTreeWidgetItem* FolderLayerWrapper::getQTreeItem()
{ {
while (this->qTreeWidgetItem->childCount() > 0) { for (auto& child : this->children) {
this->qTreeWidgetItem->removeChild(this->qTreeWidgetItem->child(0));
}
for (auto& child : this->children) {
this->qTreeWidgetItem->addChild(child->getQTreeItem()); 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(); return LayerWrapper::getQTreeItem();
} }
@ -317,4 +337,37 @@ void FolderLayerWrapper::collectDownReachable(std::set<LayerWrapper*>& reachable
LayerWrapper::collectDownReachable(reachable); LayerWrapper::collectDownReachable(reachable);
for (auto& child : children) for (auto& child : children)
child->collectDownReachable(reachable); 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; ~LayerWrapper() = default;
virtual void collectUpReachable(std::set<LayerWrapper*>& reachable); virtual void collectUpReachable(std::set<LayerWrapper*>& reachable);
virtual void collectDownReachable(std::set<LayerWrapper*>& reachable); virtual void collectDownReachable(std::set<LayerWrapper*>& reachable);
virtual void refreshTreeItem();
}; };
class FolderLayerWrapper : public LayerWrapper class FolderLayerWrapper : public LayerWrapper
@ -94,6 +95,7 @@ class FolderLayerWrapper : public LayerWrapper
int getReferencedBy()const; int getReferencedBy()const;
void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override; void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override;
void collectDownReachable(std::set<LayerWrapper*>& reachable) override; void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
void refreshTreeItem() override;
}; };
class LeafLayerWrapper : public LayerWrapper class LeafLayerWrapper : public LayerWrapper
@ -110,6 +112,8 @@ class LeafLayerWrapper : public LayerWrapper
QJsonObject toJson() const override; QJsonObject toJson() const override;
void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override; void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override;
void collectDownReachable(std::set<LayerWrapper*>& reachable) override; void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
QTreeWidgetItem* getQTreeItem() override;
void refreshTreeItem() override;
}; };
Q_DECLARE_METATYPE(LayerWrapper *) Q_DECLARE_METATYPE(LayerWrapper *)

View File

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