Compare commits

..

No commits in common. "6494c2b9af9f00f1b24de194e021d2f7fdf23bd4" and "fd1baf42f68a8451d453904534dde292a90965fc" have entirely different histories.

7 changed files with 6 additions and 98 deletions

View File

@ -1,46 +1,15 @@
#include "LayerCreateWidget.h" #include "LayerCreateWidget.h"
#include <QComboBox> #include <QComboBox>
LayerCreateWidget::LayerCreateWidget(ElementManager* elementManager, FolderLayerWrapper* folderLayer, QWidget* parent) : LayerCreateWidget::LayerCreateWidget(ElementManager* elementManager, QWidget* parent) :
QDialog(parent) QDialog(parent)
{ {
this->elementManager = elementManager;
ui.setupUi(this); ui.setupUi(this);
connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(ui.comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int))); connect(ui.comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
elementPool = new ElementPoolWidget(ui.elementPool); elementPool = new ElementPoolWidget(ui.elementPool);
elements = elementManager->elements; elementPool->setElementList(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() LayerCreateWidget::~LayerCreateWidget()
@ -52,20 +21,8 @@ void LayerCreateWidget::accept()
QJsonObject jsonObj; QJsonObject jsonObj;
jsonObj.insert("name", ui.name->text()); jsonObj.insert("name", ui.name->text());
if (ui.comboBox->currentIndex() == 0) { 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("is-folder", false);
jsonObj.insert("element", index); jsonObj.insert("element", elementPool->currentIndex);
} }
else { else {
jsonObj.insert("is-folder", true); jsonObj.insert("is-folder", true);

View File

@ -11,15 +11,12 @@ class LayerCreateWidget :
Q_OBJECT Q_OBJECT
private: private:
ElementManager* elementManager;
std::vector<GraphicElement*> elements;
Ui::LayerCreateWidget ui; Ui::LayerCreateWidget ui;
ElementPoolWidget* elementPool; ElementPoolWidget* elementPool;
void elementsCheck(FolderLayerWrapper*);
public: public:
LayerCreateWidget(ElementManager* elementManager, FolderLayerWrapper* folderLayer, QWidget* parent = nullptr); LayerCreateWidget(ElementManager* elementManager,QWidget* parent = nullptr);
~LayerCreateWidget(); ~LayerCreateWidget();
void accept() override; void accept() override;

View File

@ -149,11 +149,3 @@ QPixmap GroupElement::getPreview(QSize size)
result = result.copy(rect); result = result.copy(rect);
return result.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation); return result.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
} }
void GroupElement::collectReachable(std::set<LayerWrapper*>& set) const
{
if (sourceLayer != nullptr)
{
sourceLayer->collectDownReachable(set);
}
}

View File

@ -66,7 +66,6 @@ public:
void setSourceLayer(FolderLayerWrapper* sourceLayer); void setSourceLayer(FolderLayerWrapper* sourceLayer);
void paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) override; void paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) override;
QPixmap getPreview(QSize size) override; QPixmap getPreview(QSize size) override;
void collectReachable(std::set<LayerWrapper*>& set) const;
}; };
//******************************** BitmapPath ********************************// //******************************** BitmapPath ********************************//

View File

@ -286,35 +286,3 @@ void LeafLayerWrapper::paint(QPainter* painter, QTransform transform, bool ignor
wrappedElement->paint(painter, transform, styles); 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);
}

View File

@ -68,8 +68,7 @@ class LayerWrapper
virtual void delSelf(); virtual void delSelf();
virtual QJsonObject toJson() const; virtual QJsonObject toJson() const;
~LayerWrapper() = default; ~LayerWrapper() = default;
virtual void collectUpReachable(std::set<LayerWrapper*>& reachable);
virtual void collectDownReachable(std::set<LayerWrapper*>& reachable);
}; };
class FolderLayerWrapper : public LayerWrapper class FolderLayerWrapper : public LayerWrapper
@ -93,7 +92,6 @@ class FolderLayerWrapper : public LayerWrapper
QJsonObject toJson() const override; QJsonObject toJson() const override;
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;
}; };
class LeafLayerWrapper : public LayerWrapper class LeafLayerWrapper : public LayerWrapper
@ -109,7 +107,6 @@ class LeafLayerWrapper : public LayerWrapper
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent); LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
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;
}; };
Q_DECLARE_METATYPE(LayerWrapper *) Q_DECLARE_METATYPE(LayerWrapper *)

View File

@ -50,7 +50,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
if (layer != nullptr) { if (layer != nullptr) {
if (typeid(*layer) == typeid(FolderLayerWrapper)) { if (typeid(*layer) == typeid(FolderLayerWrapper)) {
menu.addAction(QString::fromLocal8Bit("´´½¨×Ó½Úµã"), this, [this, layer]() { menu.addAction(QString::fromLocal8Bit("´´½¨×Ó½Úµã"), this, [this, layer]() {
auto dialog = new LayerCreateWidget(elementManager, dynamic_cast<FolderLayerWrapper*>(layer), this); auto dialog = new LayerCreateWidget(elementManager, this);
connect(dialog, &LayerCreateWidget::LayerInfoReturned, this, [this, layer](QJsonObject jsonObj) { connect(dialog, &LayerCreateWidget::LayerInfoReturned, this, [this, layer](QJsonObject jsonObj) {
auto folderLayer = dynamic_cast<FolderLayerWrapper*>(layer); auto folderLayer = dynamic_cast<FolderLayerWrapper*>(layer);
LayerWrapper* newLayer; LayerWrapper* newLayer;
@ -76,7 +76,6 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
layer->getParent()->removeChild(layer); layer->getParent()->removeChild(layer);
this->refresh(); this->refresh();
emit requireRefreshPreview(); emit requireRefreshPreview();
emit requireRefreshElementWidget();
}); });
menu.addAction(QString::fromLocal8Bit("ÖØÃüÃû"), this, &LayerTreeWidget::onRenameEvent); menu.addAction(QString::fromLocal8Bit("ÖØÃüÃû"), this, &LayerTreeWidget::onRenameEvent);
if(typeid(*layer) == typeid(FolderLayerWrapper)) if(typeid(*layer) == typeid(FolderLayerWrapper))
@ -86,7 +85,6 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
layer->getParent()->removeChild(layer); layer->getParent()->removeChild(layer);
this->refresh(); this->refresh();
emit requireRefreshPreview(); emit requireRefreshPreview();
emit requireRefreshElementWidget();
}); });
} }
if (typeid(*layer) == typeid(FolderLayerWrapper) && ((FolderLayerWrapper*)layer)->getReferencedBy() == -1) { if (typeid(*layer) == typeid(FolderLayerWrapper) && ((FolderLayerWrapper*)layer)->getReferencedBy() == -1) {