添加【提升/下放】限制,暂定为pre-release | #22

main
karlis 2023-03-27 14:49:21 +08:00
parent c81c7d69d4
commit 4471bb3f79
3 changed files with 63 additions and 4 deletions

View File

@ -485,4 +485,54 @@ void FolderLayerWrapper::markNeedRefresh()
LayerWrapper::markNeedRefresh();
for (auto& child : children)
child->markNeedRefresh();
}
void LayerWrapper::collectDownUsedElements(std::set<GraphicElement*>& elements, bool deep)
{
}
void LeafLayerWrapper::collectDownUsedElements(std::set<GraphicElement*>& elements, bool deep)
{
elements.insert(wrappedElement);
if (deep && typeid(*wrappedElement) == typeid(GroupElement))
{
auto ele = dynamic_cast<GroupElement*>(wrappedElement);
ele->sourceLayer->collectDownUsedElements(elements, deep);
}
}
void FolderLayerWrapper::collectDownUsedElements(std::set<GraphicElement*>& elements, bool deep)
{
LayerWrapper::collectDownUsedElements(elements, deep);
for (auto& child : children)
child->collectDownUsedElements(elements, deep);
}
void LayerWrapper::collectUpProvidedElements(std::set<GraphicElement*>& elements)
{
auto cPos = this;
while (cPos != nullptr)
{
if (typeid(*cPos) == typeid(FolderLayerWrapper))
{
auto ele = elementManager->getElementById(dynamic_cast<FolderLayerWrapper*>(cPos)->getReferencedBy());
if (ele != nullptr)
elements.insert(ele);
}
cPos = cPos->parent;
}
}
bool LayerWrapper::isLegalParent(FolderLayerWrapper* parent)
{
std::set<GraphicElement*> downUsed, upProvided;
this->collectDownUsedElements(downUsed);
parent->collectUpProvidedElements(upProvided);
for (auto& ele : downUsed)
{
if (typeid(*ele) == typeid(GroupElement) && upProvided.find(ele) != upProvided.end())
return false;
}
return true;
}

View File

@ -74,6 +74,8 @@ class LayerWrapper
~LayerWrapper() = default;
virtual void collectUpReachable(std::set<LayerWrapper*>& reachable);
virtual void collectDownReachable(std::set<LayerWrapper*>& reachable);
virtual void collectDownUsedElements(std::set<GraphicElement*>& elements, bool deep = true);
virtual void collectUpProvidedElements(std::set<GraphicElement*>& elements);
virtual void refreshTreeItem();
virtual size_t referencedCount(bool excludeSelf = false) const;
virtual bool deleteable(bool excludeSubTree = false) const;
@ -81,6 +83,7 @@ class LayerWrapper
virtual void paintVisualBounding(QPainter* painter) const;
bool canApplyStyles() const;
virtual void markNeedRefresh();
bool isLegalParent(FolderLayerWrapper* parent);
};
class FolderLayerWrapper : public LayerWrapper
@ -105,6 +108,7 @@ class FolderLayerWrapper : public LayerWrapper
int getReferencedBy()const;
void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false, LayerStyleContainer styles = LayerStyleContainer(ElementType::TYPE_ALL)) override;
void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
void collectDownUsedElements(std::set<GraphicElement*>& elements, bool deep = true) override;
void refreshTreeItem() override;
size_t referencedCount(bool excludeSelf = false) const override;
bool deleteable(bool excludeSubTree = false) const override;
@ -123,6 +127,7 @@ class LeafLayerWrapper : public LayerWrapper
QJsonObject toJson() const override;
void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false, LayerStyleContainer styles = LayerStyleContainer(ElementType::TYPE_ALL)) override;
void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
void collectDownUsedElements(std::set<GraphicElement*>& elements, bool deep = true) override;
QTreeWidgetItem* getQTreeItem() override;
void refreshTreeItem() override;
bool referencingGroupElement() const override;

View File

@ -214,11 +214,12 @@ void LayerTreeWidget::pushDownLayer()
QAction* LayerTreeWidget::getPromoteUpAction()
{
QAction* action = new QAction(QString::fromLocal8Bit("ÌáÉý (experimental)"), this);
QAction* action = new QAction(QString::fromLocal8Bit("ÌáÉý"), this);
QMenu* optionMenu = new QMenu();
QList<QAction*> optionList;
std::vector<FolderLayerWrapper*> layers;
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
auto currentLayer = layer;
layer = layer->getParent();
while (layer != nullptr)
{
@ -238,7 +239,8 @@ QAction* LayerTreeWidget::getPromoteUpAction()
if (layer == nullptr)
continue;
QAction* option = new QAction(QString::fromLocal8Bit("ÌáÉýÖÁ ") + layer->property.name + QString::fromLocal8Bit(" ÏÂ"), this);
option->setData(QVariant::fromValue(std::pair<LayerWrapper*, FolderLayerWrapper*>({this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>(), layer})));
option->setEnabled(currentLayer->isLegalParent(layer));
option->setData(QVariant::fromValue(std::pair<LayerWrapper*, FolderLayerWrapper*>({currentLayer, layer})));
connect(option, &QAction::triggered, this, [this, option]() {
auto pair = option->data().value<std::pair<LayerWrapper*, FolderLayerWrapper*>>();
auto layer = pair.first;
@ -255,11 +257,12 @@ QAction* LayerTreeWidget::getPromoteUpAction()
QAction* LayerTreeWidget::getPromoteDownAction()
{
QAction* action = new QAction(QString::fromLocal8Bit("Ï·Š(experimental)"), this);
QAction* action = new QAction(QString::fromLocal8Bit("Ï·Å"), this);
QMenu* optionMenu = new QMenu();
QList<QAction*> optionList;
std::vector<FolderLayerWrapper*> layers;
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
auto currentLayer = layer;
auto parent = layer->getParent();
if (parent == nullptr)
{
@ -283,7 +286,8 @@ QAction* LayerTreeWidget::getPromoteDownAction()
if (layer == nullptr)
continue;
QAction* option = new QAction(QString::fromLocal8Bit("Ï·ÅÖÁ ") + layer->property.name + QString::fromLocal8Bit(" ÖÐ"), this);
option->setData(QVariant::fromValue(std::pair<LayerWrapper*, FolderLayerWrapper*>({ this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>(), layer })));
option->setEnabled(currentLayer->isLegalParent(layer));
option->setData(QVariant::fromValue(std::pair<LayerWrapper*, FolderLayerWrapper*>({ currentLayer, layer })));
connect(option, &QAction::triggered, this, [this, option]() {
auto pair = option->data().value<std::pair<LayerWrapper*, FolderLayerWrapper*>>();
auto layer = pair.first;