添加创建时递归约束
parent
84bddf4447
commit
aeead9d22e
|
@ -1,15 +1,46 @@
|
|||
#include "LayerCreateWidget.h"
|
||||
#include <QComboBox>
|
||||
|
||||
LayerCreateWidget::LayerCreateWidget(ElementManager* elementManager, QWidget* parent) :
|
||||
LayerCreateWidget::LayerCreateWidget(ElementManager* elementManager, FolderLayerWrapper* folderLayer, QWidget* parent) :
|
||||
QDialog(parent)
|
||||
{
|
||||
this->elementManager = elementManager;
|
||||
ui.setupUi(this);
|
||||
connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
connect(ui.comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
|
||||
elementPool = new ElementPoolWidget(ui.elementPool);
|
||||
elementPool->setElementList(elementManager->elements);
|
||||
elements = elementManager->elements;
|
||||
elementsCheck(folderLayer);
|
||||
elementPool->setElementList(elements);
|
||||
}
|
||||
|
||||
void LayerCreateWidget::elementsCheck(FolderLayerWrapper* parent)
|
||||
{
|
||||
std::set<LayerWrapper*> upSet, downSet;
|
||||
parent->collectUpReachable(upSet);
|
||||
for (auto it = elements.begin(); it != elements.end();)
|
||||
{
|
||||
bool valid = true;
|
||||
auto ele = dynamic_cast<GroupElement*>(*it);
|
||||
if (ele != nullptr)
|
||||
{
|
||||
downSet.clear();
|
||||
ele->collectReachable(downSet);
|
||||
for (auto& layer : downSet)
|
||||
{
|
||||
if (upSet.find(layer) != upSet.end())
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (valid)
|
||||
++it;
|
||||
else
|
||||
it = elements.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
LayerCreateWidget::~LayerCreateWidget()
|
||||
|
@ -21,8 +52,20 @@ void LayerCreateWidget::accept()
|
|||
QJsonObject jsonObj;
|
||||
jsonObj.insert("name", ui.name->text());
|
||||
if (ui.comboBox->currentIndex() == 0) {
|
||||
auto currentEle = elements[elementPool->currentIndex];
|
||||
int index = -1;
|
||||
for (int i = 0; i < elementManager->elements.size(); i++)
|
||||
{
|
||||
if (elementManager->elements[i] == currentEle)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index == -1)
|
||||
return;
|
||||
jsonObj.insert("is-folder", false);
|
||||
jsonObj.insert("element", elementPool->currentIndex);
|
||||
jsonObj.insert("element", index);
|
||||
}
|
||||
else {
|
||||
jsonObj.insert("is-folder", true);
|
||||
|
|
|
@ -11,12 +11,15 @@ class LayerCreateWidget :
|
|||
Q_OBJECT
|
||||
|
||||
private:
|
||||
ElementManager* elementManager;
|
||||
std::vector<GraphicElement*> elements;
|
||||
Ui::LayerCreateWidget ui;
|
||||
ElementPoolWidget* elementPool;
|
||||
void elementsCheck(FolderLayerWrapper*);
|
||||
|
||||
|
||||
public:
|
||||
LayerCreateWidget(ElementManager* elementManager,QWidget* parent = nullptr);
|
||||
LayerCreateWidget(ElementManager* elementManager, FolderLayerWrapper* folderLayer, QWidget* parent = nullptr);
|
||||
~LayerCreateWidget();
|
||||
void accept() override;
|
||||
|
||||
|
|
|
@ -148,4 +148,12 @@ QPixmap GroupElement::getPreview(QSize size)
|
|||
rect.setBottomRight(rect.bottomRight() + QPoint(5, 5));
|
||||
result = result.copy(rect);
|
||||
return result.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
void GroupElement::collectReachable(std::set<LayerWrapper*>& set) const
|
||||
{
|
||||
if (sourceLayer != nullptr)
|
||||
{
|
||||
sourceLayer->collectDownReachable(set);
|
||||
}
|
||||
}
|
|
@ -66,6 +66,7 @@ public:
|
|||
void setSourceLayer(FolderLayerWrapper* sourceLayer);
|
||||
void paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) override;
|
||||
QPixmap getPreview(QSize size) override;
|
||||
void collectReachable(std::set<LayerWrapper*>& set) const;
|
||||
};
|
||||
|
||||
//******************************** BitmapPath ********************************//
|
||||
|
|
|
@ -285,4 +285,36 @@ void LeafLayerWrapper::paint(QPainter* painter, QTransform transform, bool ignor
|
|||
{
|
||||
wrappedElement->paint(painter, transform, styles);
|
||||
}
|
||||
}
|
||||
|
||||
void LayerWrapper::collectUpReachable(std::set<LayerWrapper*>& reachable)
|
||||
{
|
||||
auto cPos = this;
|
||||
while (cPos != nullptr)
|
||||
{
|
||||
reachable.insert(cPos);
|
||||
cPos = cPos->parent;
|
||||
}
|
||||
}
|
||||
|
||||
void LayerWrapper::collectDownReachable(std::set<LayerWrapper*>& reachable)
|
||||
{
|
||||
reachable.insert(this);
|
||||
}
|
||||
|
||||
void LeafLayerWrapper::collectDownReachable(std::set<LayerWrapper*>& reachable)
|
||||
{
|
||||
LayerWrapper::collectDownReachable(reachable);
|
||||
auto ele = dynamic_cast<GroupElement*>(wrappedElement);
|
||||
if (ele != nullptr)
|
||||
{
|
||||
ele->collectReachable(reachable);
|
||||
}
|
||||
}
|
||||
|
||||
void FolderLayerWrapper::collectDownReachable(std::set<LayerWrapper*>& reachable)
|
||||
{
|
||||
LayerWrapper::collectDownReachable(reachable);
|
||||
for (auto& child : children)
|
||||
child->collectDownReachable(reachable);
|
||||
}
|
|
@ -68,7 +68,8 @@ class LayerWrapper
|
|||
virtual void delSelf();
|
||||
virtual QJsonObject toJson() const;
|
||||
~LayerWrapper() = default;
|
||||
|
||||
virtual void collectUpReachable(std::set<LayerWrapper*>& reachable);
|
||||
virtual void collectDownReachable(std::set<LayerWrapper*>& reachable);
|
||||
};
|
||||
|
||||
class FolderLayerWrapper : public LayerWrapper
|
||||
|
@ -92,6 +93,7 @@ class FolderLayerWrapper : public LayerWrapper
|
|||
QJsonObject toJson() const override;
|
||||
int getReferencedBy()const;
|
||||
void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override;
|
||||
void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
|
||||
};
|
||||
|
||||
class LeafLayerWrapper : public LayerWrapper
|
||||
|
@ -107,6 +109,7 @@ class LeafLayerWrapper : public LayerWrapper
|
|||
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
|
||||
QJsonObject toJson() const override;
|
||||
void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override;
|
||||
void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(LayerWrapper *)
|
||||
|
|
|
@ -50,7 +50,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
|||
if (layer != nullptr) {
|
||||
if (typeid(*layer) == typeid(FolderLayerWrapper)) {
|
||||
menu.addAction(QString::fromLocal8Bit("´´½¨×Ó½Úµã"), this, [this, layer]() {
|
||||
auto dialog = new LayerCreateWidget(elementManager, this);
|
||||
auto dialog = new LayerCreateWidget(elementManager, dynamic_cast<FolderLayerWrapper*>(layer), this);
|
||||
connect(dialog, &LayerCreateWidget::LayerInfoReturned, this, [this, layer](QJsonObject jsonObj) {
|
||||
auto folderLayer = dynamic_cast<FolderLayerWrapper*>(layer);
|
||||
LayerWrapper* newLayer;
|
||||
|
@ -76,6 +76,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
|||
layer->getParent()->removeChild(layer);
|
||||
this->refresh();
|
||||
emit requireRefreshPreview();
|
||||
emit requireRefreshElementWidget();
|
||||
});
|
||||
menu.addAction(QString::fromLocal8Bit("ÖØÃüÃû"), this, &LayerTreeWidget::onRenameEvent);
|
||||
if(typeid(*layer) == typeid(FolderLayerWrapper))
|
||||
|
@ -85,6 +86,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
|||
layer->getParent()->removeChild(layer);
|
||||
this->refresh();
|
||||
emit requireRefreshPreview();
|
||||
emit requireRefreshElementWidget();
|
||||
});
|
||||
}
|
||||
if (typeid(*layer) == typeid(FolderLayerWrapper) && ((FolderLayerWrapper*)layer)->getReferencedBy() == -1) {
|
||||
|
|
Loading…
Reference in New Issue