重写刷新信号及逻辑

dev-yyq
karlis 2023-03-19 16:07:35 +08:00
parent 8bf6835c23
commit b3bbf6c1be
7 changed files with 36 additions and 38 deletions

View File

@ -19,6 +19,15 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
elementInfoDisplayWidget->enableEdit(); elementInfoDisplayWidget->enableEdit();
qDebug() << layerInfoDisplayWidget; qDebug() << layerInfoDisplayWidget;
qDebug() << elementInfoDisplayWidget; qDebug() << elementInfoDisplayWidget;
auto centralRefresh = [this]() {
layerInfoDisplayWidget->refresh();
elementInfoDisplayWidget->refresh();
treeWidget->refresh();
previewWindow->refresh();
};
connect(layerInfoDisplayWidget, &InfoDisplayWidget::triggerCentralRefresh, centralRefresh);
connect(elementInfoDisplayWidget, &ElementPoolWidget::triggerCentralRefresh, centralRefresh);
connect(treeWidget, &LayerTreeWidget::triggerCentralRefresh, centralRefresh);
connect(editorSettingWidget, &EditorSettingWidget::backgroundColorChanged, this, &EditorWidgetItem::handleBackgroundColorChange); connect(editorSettingWidget, &EditorSettingWidget::backgroundColorChanged, this, &EditorWidgetItem::handleBackgroundColorChange);
connect(editorSettingWidget, &EditorSettingWidget::projectNameChanged, this, &EditorWidgetItem::handleProjectNameChange); connect(editorSettingWidget, &EditorSettingWidget::projectNameChanged, this, &EditorWidgetItem::handleProjectNameChange);
connect(previewWindow, &PreviewWindow::refreshElementPreviewByIndex, elementInfoDisplayWidget, &ElementPoolWidget::refreshPictureByIndex); connect(previewWindow, &PreviewWindow::refreshElementPreviewByIndex, elementInfoDisplayWidget, &ElementPoolWidget::refreshPictureByIndex);

View File

@ -67,7 +67,6 @@ 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();
} }
@ -113,12 +112,12 @@ void ElementPoolWidget::popMenu(const QPoint& pos)
if (bOk && !sName.isEmpty()) if (bOk && !sName.isEmpty())
{ {
currentElement->name = sName; currentElement->name = sName;
refresh(); emit triggerCentralRefresh();
} }
}); });
menu->addAction(QString::fromLocal8Bit("ɾ³ý"), this, [this, currentElement]() { menu->addAction(QString::fromLocal8Bit("ɾ³ý"), this, [this, currentElement]() {
this->elementManager->removeElement(currentElement); this->elementManager->removeElement(currentElement);
refresh(); emit triggerCentralRefresh();
}); });
menu->actions().last()->setDisabled(currentElement->referencedCount > 0); menu->actions().last()->setDisabled(currentElement->referencedCount > 0);
} }
@ -130,7 +129,7 @@ void ElementPoolWidget::popMenu(const QPoint& pos)
QString fileName = fileInfo.fileName(); QString fileName = fileInfo.fileName();
qDebug() << fileName << " " << filePath; qDebug() << fileName << " " << filePath;
this->elementManager->createSimpleElement(fileName, filePath); this->elementManager->createSimpleElement(fileName, filePath);
refresh(); emit triggerCentralRefresh();
}); });
} }
menu->popup(mapToGlobal(pos)); menu->popup(mapToGlobal(pos));

View File

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

View File

@ -45,32 +45,27 @@ void InfoDisplayWidget::generateLayerForm()
rotation->setValidator(new QIntValidator(-10000, 10000, this)); rotation->setValidator(new QIntValidator(-10000, 10000, this));
connect(rotation, &QLineEdit::textChanged, [=](QString content) { connect(rotation, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.rotation = content.toDouble(); this->displayLayer->property.rotation = content.toDouble();
emit requireRefreshElementWidget(); emit triggerCentralRefresh();
emit requireRefreshPreview();
}); });
offsetX->setValidator(new QIntValidator(-10000, 10000, this)); offsetX->setValidator(new QIntValidator(-10000, 10000, this));
connect(offsetX, &QLineEdit::textChanged, [=](QString content) { connect(offsetX, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.offset = {content.toDouble(), this->displayLayer->property.offset.y()}; this->displayLayer->property.offset = {content.toDouble(), this->displayLayer->property.offset.y()};
emit requireRefreshElementWidget(); emit triggerCentralRefresh();
emit requireRefreshPreview();
}); });
offsetY->setValidator(new QIntValidator(-10000, 10000, this)); offsetY->setValidator(new QIntValidator(-10000, 10000, this));
connect(offsetY, &QLineEdit::textChanged, [=](QString content) { connect(offsetY, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.offset = {this->displayLayer->property.offset.x(), content.toDouble()}; this->displayLayer->property.offset = {this->displayLayer->property.offset.x(), content.toDouble()};
emit requireRefreshElementWidget(); emit triggerCentralRefresh();
emit requireRefreshPreview();
}); });
scaleX->setValidator(new QDoubleValidator(-1000, 1000, 4, this)); scaleX->setValidator(new QDoubleValidator(-1000, 1000, 4, this));
connect(scaleX, &QLineEdit::textChanged, [=](QString content) { connect(scaleX, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.scale = {content.toDouble(), this->displayLayer->property.scale.y()}; this->displayLayer->property.scale = {content.toDouble(), this->displayLayer->property.scale.y()};
emit requireRefreshElementWidget(); emit triggerCentralRefresh();
emit requireRefreshPreview();
}); });
scaleY->setValidator(new QDoubleValidator(-1000, 1000, 4, this)); scaleY->setValidator(new QDoubleValidator(-1000, 1000, 4, this));
connect(scaleY, &QLineEdit::textChanged, [=](QString content) { connect(scaleY, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.scale = {this->displayLayer->property.scale.x(), content.toDouble()}; this->displayLayer->property.scale = {this->displayLayer->property.scale.x(), content.toDouble()};
emit requireRefreshElementWidget(); emit triggerCentralRefresh();
emit requireRefreshPreview();
}); });
layout->addRow("layer name:", name); layout->addRow("layer name:", name);
@ -108,10 +103,7 @@ void InfoDisplayWidget::generateLayerForm()
{ {
leafP->styles.useStyle(dialog->layerStyle); leafP->styles.useStyle(dialog->layerStyle);
leafP->styles.computeNewHash(); leafP->styles.computeNewHash();
emit triggerCentralRefresh();
emit requireRefreshPreview();
emit requireSelfRefresh();
emit requireRefreshElementWidget();
} }
}); });
} }
@ -153,10 +145,7 @@ void InfoDisplayWidget::generateLayerForm()
{ {
styleIterator->second = dialog->layerStyle; styleIterator->second = dialog->layerStyle;
styles->computeNewHash(); styles->computeNewHash();
emit triggerCentralRefresh();
emit requireRefreshPreview();
emit requireSelfRefresh();
emit requireRefreshElementWidget();
} }
}); });
@ -165,10 +154,7 @@ void InfoDisplayWidget::generateLayerForm()
{ {
styles->dropStyle(styleIterator->first); styles->dropStyle(styleIterator->first);
styles->computeNewHash(); styles->computeNewHash();
emit triggerCentralRefresh();
emit requireRefreshPreview();
emit requireSelfRefresh();
emit requireRefreshElementWidget();
}); });
QWidget* styleDisplayWidget = styleIterator->second->getListDisplayWidget(); QWidget* styleDisplayWidget = styleIterator->second->getListDisplayWidget();
@ -190,6 +176,12 @@ void InfoDisplayWidget::generateLayerForm()
} }
void InfoDisplayWidget::triggerSelfRefresh() void InfoDisplayWidget::triggerSelfRefresh()
{
if (this->displayLayer != nullptr)
this->generateLayerForm();
}
void InfoDisplayWidget::refresh()
{ {
if (this->displayLayer != nullptr) if (this->displayLayer != nullptr)
this->generateLayerForm(); this->generateLayerForm();

View File

@ -16,11 +16,13 @@ class InfoDisplayWidget : public QWidget
public: public:
void setLayer(LayerWrapper *layer); void setLayer(LayerWrapper *layer);
void generateLayerForm(); void generateLayerForm();
void refresh();
public slots: public slots:
void triggerSelfRefresh(); void triggerSelfRefresh();
signals: signals:
void triggerCentralRefresh();
void requireRefreshPreview(); void requireRefreshPreview();
void requireSelfRefresh(); void requireSelfRefresh();
void requireRefreshElementWidget(); void requireRefreshElementWidget();

View File

@ -24,7 +24,7 @@ LayerTreeWidget::LayerTreeWidget(QWidget *parent)
else { else {
emit displayLayerChange(nullptr); emit displayLayerChange(nullptr);
} }
emit requireRefreshPreview(); emit triggerCentralRefresh();
}); });
// connect(this, &QTreeWidget::itemDoubleClicked, this, &LayerTreeWidget::onItemDoubleClicked); // connect(this, &QTreeWidget::itemDoubleClicked, this, &LayerTreeWidget::onItemDoubleClicked);
} }
@ -62,9 +62,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
folderLayer->addChild(std::shared_ptr<LayerWrapper>(newLayer)); folderLayer->addChild(std::shared_ptr<LayerWrapper>(newLayer));
folderLayer->qTreeWidgetItem->addChild(newLayer->getQTreeItem()); folderLayer->qTreeWidgetItem->addChild(newLayer->getQTreeItem());
qDebug() << jsonObj<<"----------------------"; qDebug() << jsonObj<<"----------------------";
this->refresh(); emit triggerCentralRefresh();
emit requireRefreshPreview();
emit requireRefreshElementWidget();
}); });
dialog->exec(); dialog->exec();
}); });
@ -74,9 +72,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>(); auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
layer->del(); layer->del();
layer->getParent()->removeChild(layer); layer->getParent()->removeChild(layer);
this->refresh(); emit triggerCentralRefresh();
emit requireRefreshPreview();
emit requireRefreshElementWidget();
}); });
menu.actions().last()->setEnabled(layer->deleteable()); menu.actions().last()->setEnabled(layer->deleteable());
menu.addAction(QString::fromLocal8Bit("ÖØÃüÃû"), this, &LayerTreeWidget::onRenameEvent); menu.addAction(QString::fromLocal8Bit("ÖØÃüÃû"), this, &LayerTreeWidget::onRenameEvent);
@ -86,9 +82,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>(); auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
layer->delSelf(); layer->delSelf();
layer->getParent()->removeChild(layer); layer->getParent()->removeChild(layer);
this->refresh(); emit triggerCentralRefresh();
emit requireRefreshPreview();
emit requireRefreshElementWidget();
}); });
menu.actions().last()->setEnabled(layer->deleteable(true)); menu.actions().last()->setEnabled(layer->deleteable(true));
} }
@ -103,7 +97,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
"", &ok); "", &ok);
if (ok && !name.isEmpty()) { if (ok && !name.isEmpty()) {
elementManager->createGroupElement(name, layer); elementManager->createGroupElement(name, layer);
emit requireRefreshElementWidget(); emit triggerCentralRefresh();
} }
} }
}); });

View File

@ -21,6 +21,7 @@ class LayerTreeWidget : public QTreeWidget
// void onItemDoubleClicked(QTreeWidgetItem *item, int column = 0); // void onItemDoubleClicked(QTreeWidgetItem *item, int column = 0);
signals: signals:
void triggerCentralRefresh();
void displayLayerChange(LayerWrapper *); void displayLayerChange(LayerWrapper *);
void requireRefreshPreview(); void requireRefreshPreview();
void requireRefreshElementWidget(); void requireRefreshElementWidget();