实现显示/隐藏图层功能 | #16

dev-LayerStyle
karlis 2023-03-20 15:52:27 +08:00
parent f06fbbaef6
commit 8a34f57251
6 changed files with 39 additions and 21 deletions

View File

@ -180,6 +180,12 @@
<property name="accessibleName">
<string/>
</property>
<property name="iconSize">
<size>
<width>10</width>
<height>10</height>
</size>
</property>
<column>
<property name="text">
<string>图层名</string>
@ -190,6 +196,11 @@
<string>关联图元</string>
</property>
</column>
<column>
<property name="text">
<string>可见</string>
</property>
</column>
</widget>
</item>
</layout>

View File

@ -74,9 +74,10 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
this->projectName = source.value("project-name").toString();
qDebug() << this->backgroundColor;
qDebug() << this->projectName;
QTimer::singleShot(300, this, [this]() {
QTimer::singleShot(300, this, [this, centralRefresh]() {
handleBackgroundColorChange(this->backgroundColor);
handleProjectNameChange(this->projectName);
centralRefresh();
});
}

View File

@ -127,7 +127,7 @@ bool SimpleElement::isClosed() const
void GroupElement::paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles)
{
sourceLayer->paint(painter, transform);
sourceLayer->paint(painter, transform, true);
}
bool GroupElement::isClosed() const

View File

@ -47,6 +47,7 @@ LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementM
transformJson.value("scale").toObject().value("y").toDouble()};
property.rotation = {transformJson.value("rotation").toDouble()};
selected = false;
hidden = false;
}
FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent)
@ -199,6 +200,7 @@ void FolderLayerWrapper::delSelf() {
QTreeWidgetItem* LayerWrapper::getQTreeItem()
{
this->qTreeWidgetItem->setData(0, Qt::UserRole, QVariant::fromValue(this));
this->qTreeWidgetItem->setCheckState(0, Qt::Checked);
return this->qTreeWidgetItem;
}
@ -280,31 +282,27 @@ int FolderLayerWrapper::getReferencedBy()const
return -1;
}
void LayerWrapper::paint(QPainter* painter, QTransform transform, bool ignoreSelected)
void LayerWrapper::paint(QPainter* painter, QTransform transform, bool force)
{
if (!ignoreSelected && this->selected)
{
painter->save();
painter->setTransform(transform, ignoreSelected);
painter->setPen(QPen(Qt::gray, 2));
painter->setPen(Qt::DashLine);
painter->drawRect(cache.getBoundingRect());
painter->restore();
}
}
void FolderLayerWrapper::paint(QPainter* painter, QTransform transform, bool ignoreSelected)
void FolderLayerWrapper::paint(QPainter* painter, QTransform transform, bool force)
{
LayerWrapper::paint(painter, transform, ignoreSelected);
if (hidden && !force)
return;
LayerWrapper::paint(painter, transform, force);
transform = property.transform * transform;
//qDebug() << transform;
for (auto& child : children)
child->paint(painter, transform, ignoreSelected);
child->paint(painter, transform, force);
}
void LeafLayerWrapper::paint(QPainter* painter, QTransform transform, bool ignoreSelected)
void LeafLayerWrapper::paint(QPainter* painter, QTransform transform, bool force)
{
LayerWrapper::paint(painter, transform, ignoreSelected);
if (hidden && !force)
return;
LayerWrapper::paint(painter, transform, force);
transform = property.transform * transform;
//qDebug() << transform;
if (wrappedElement != nullptr)
@ -347,11 +345,12 @@ void FolderLayerWrapper::collectDownReachable(std::set<LayerWrapper*>& reachable
void LayerWrapper::refreshTreeItem()
{
hidden = qTreeWidgetItem->checkState(0) == Qt::Unchecked;
}
void LeafLayerWrapper::refreshTreeItem()
{
LayerWrapper::refreshTreeItem();
if (typeid(*wrappedElement) == typeid(GroupElement))
{
this->qTreeWidgetItem->setText(0, "@ " + this->property.name);
@ -366,6 +365,7 @@ void LeafLayerWrapper::refreshTreeItem()
void FolderLayerWrapper::refreshTreeItem()
{
LayerWrapper::refreshTreeItem();
for (auto& child : this->children) {
child->refreshTreeItem();
}

View File

@ -37,6 +37,7 @@ class LayerWrapper
public:
QTreeWidgetItem* qTreeWidgetItem;
bool selected;
bool hidden;
struct SimpleProperty
{
QString name = "";
@ -58,7 +59,7 @@ class LayerWrapper
FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles
LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager=nullptr);
LayerWrapper() = default;
virtual void paint(QPainter* painter, QTransform transform=QTransform(), bool ignoreSelected = false);
virtual void paint(QPainter* painter, QTransform transform=QTransform(), bool force = false);
// TODO : export Function
// virtual LayerWrapper *addChild() = 0; // Leaf Child Only
// virtual LayerWrapper *addParent() = 0; // Folder Parent Only
@ -97,7 +98,7 @@ class FolderLayerWrapper : public LayerWrapper
QTreeWidgetItem* getQTreeItem() override;
QJsonObject toJson() const override;
int getReferencedBy()const;
void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override;
void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false) override;
void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
void refreshTreeItem() override;
size_t referencedCount(bool excludeSelf = false) const override;
@ -115,7 +116,7 @@ class LeafLayerWrapper : public LayerWrapper
void refresh(LayerWrapper* layer = nullptr) override;
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
QJsonObject toJson() const override;
void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override;
void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false) override;
void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
QTreeWidgetItem* getQTreeItem() override;
void refreshTreeItem() override;

View File

@ -2,6 +2,7 @@
#include <QInputDialog>
#include <QMenu>
#include "./EditorWidgetComponent/LayerCreateWidget.h"
#include <QTimer>
LayerTreeWidget::LayerTreeWidget(QWidget *parent)
{
@ -26,6 +27,10 @@ LayerTreeWidget::LayerTreeWidget(QWidget *parent)
}
emit triggerCentralRefresh();
});
connect(this, &QTreeWidget::itemChanged, this, [=]() {
emit triggerCentralRefresh();
});
// connect(this, &QTreeWidget::itemDoubleClicked, this, &LayerTreeWidget::onItemDoubleClicked);
}