From 192d1abb1ba47ce90e52255bcb2ec63fd3515ec3 Mon Sep 17 00:00:00 2001 From: zhuohy <1445643474@qq.com> Date: Fri, 11 Aug 2023 11:03:47 +0800 Subject: [PATCH 1/8] import subgrahs # Conflicts: # ui/zenoio/reader/zsgreader.cpp --- ui/zenoedit/acceptor/transferacceptor.cpp | 32 +++++ ui/zenoedit/acceptor/transferacceptor.h | 1 + ui/zenoedit/nodesys/zenosubgraphscene.cpp | 2 +- ui/zenoio/acceptor/iacceptor.h | 1 + ui/zenoio/reader/zsgreader.cpp | 13 +- ui/zenoio/reader/zsgreader.h | 2 +- ui/zenomodel/include/igraphsmodel.h | 2 +- ui/zenomodel/src/graphsmanagment.cpp | 2 +- ui/zenomodel/src/graphsmodel.cpp | 7 +- ui/zenomodel/src/graphsmodel.h | 2 +- ui/zenomodel/src/modelacceptor.cpp | 166 +++++++++++++++++++++- ui/zenomodel/src/modelacceptor.h | 1 + 12 files changed, 215 insertions(+), 16 deletions(-) diff --git a/ui/zenoedit/acceptor/transferacceptor.cpp b/ui/zenoedit/acceptor/transferacceptor.cpp index c679217cb6..9cd0940477 100644 --- a/ui/zenoedit/acceptor/transferacceptor.cpp +++ b/ui/zenoedit/acceptor/transferacceptor.cpp @@ -565,3 +565,35 @@ void TransferAcceptor::getDumpData(QMap& nodes, QList links() const; void getDumpData(QMap& nodes, QList& links); void setIOVersion(zenoio::ZSG_VERSION versio) override; + void endNode(const QString& id, const QString& nodeCls, const rapidjson::Value& objValue) override; private: IGraphsModel* m_pModel; diff --git a/ui/zenoedit/nodesys/zenosubgraphscene.cpp b/ui/zenoedit/nodesys/zenosubgraphscene.cpp index 74eacc447a..23c99f692a 100644 --- a/ui/zenoedit/nodesys/zenosubgraphscene.cpp +++ b/ui/zenoedit/nodesys/zenosubgraphscene.cpp @@ -949,7 +949,7 @@ void ZenoSubGraphScene::focusOutEvent(QFocusEvent* event) void ZenoSubGraphScene::clearLayout(const QModelIndex& subGpIdx) { - if (subGpIdx != m_subgIdx) + if (subGpIdx == m_subgIdx) { m_nodes.clear(); m_links.clear(); diff --git a/ui/zenoio/acceptor/iacceptor.h b/ui/zenoio/acceptor/iacceptor.h index 920d2fb2b9..7ca74af590 100644 --- a/ui/zenoio/acceptor/iacceptor.h +++ b/ui/zenoio/acceptor/iacceptor.h @@ -79,6 +79,7 @@ class IAcceptor virtual QObject* currGraphObj() = 0; virtual void addCustomUI(const QString& id, const VPARAM_INFO& invisibleRoot) = 0; virtual void setIOVersion(zenoio::ZSG_VERSION version) = 0; + virtual void endNode(const QString& id, const QString& nodeCls, const rapidjson::Value& objValue) = 0; virtual ~IAcceptor() = default; }; diff --git a/ui/zenoio/reader/zsgreader.cpp b/ui/zenoio/reader/zsgreader.cpp index 875e560b46..e4ad31c2b1 100644 --- a/ui/zenoio/reader/zsgreader.cpp +++ b/ui/zenoio/reader/zsgreader.cpp @@ -52,7 +52,7 @@ bool ZsgReader::importNodes(IGraphsModel* pModel, const QModelIndex& subgIdx, co return true; } -bool ZsgReader::openFile(const QString& fn, IAcceptor* pAcceptor) +bool ZsgReader::openFile(const QString& fn, IAcceptor* pAcceptor, bool bImport) { QFile file(fn); bool ret = file.open(QIODevice::ReadOnly | QIODevice::Text); @@ -90,12 +90,17 @@ bool ZsgReader::openFile(const QString& fn, IAcceptor* pAcceptor) for (const auto& subgraph : graph.GetObject()) { const QString& graphName = subgraph.name.GetString(); + if (bImport && graphName == "main") + continue; if (!_parseSubGraph(graphName, subgraph.value, nodesDescs, pAcceptor)) return false; } pAcceptor->EndGraphs(); pAcceptor->switchSubGraph("main"); + if (bImport) + return true; + if (doc.HasMember("views")) { _parseViews(doc["views"], pAcceptor); @@ -286,7 +291,7 @@ bool ZsgReader::_parseNode(const QString& nodeid, const rapidjson::Value& nodeOb pAcceptor->setBlackboard(nodeid, blackboard); } - + pAcceptor->endNode(nodeid, name, objValue); return true; } @@ -476,10 +481,6 @@ void ZsgReader::_parseOutputs(const QString &id, const QString &nodeName, const if (sockObj.HasMember("dictlist-panel")) { _parseDictPanel(false, sockObj["dictlist-panel"], id, outSock, nodeName, pAcceptor); } - if (sockObj.HasMember("tooltip")) { - QString toolTip = QString::fromUtf8(sockObj["tooltip"].GetString()); - pAcceptor->setToolTip(PARAM_OUTPUT, id, outSock, toolTip); - } } } } diff --git a/ui/zenoio/reader/zsgreader.h b/ui/zenoio/reader/zsgreader.h index fba24ca7b0..d16f98aa13 100644 --- a/ui/zenoio/reader/zsgreader.h +++ b/ui/zenoio/reader/zsgreader.h @@ -16,7 +16,7 @@ class ZsgReader { public: static ZsgReader& getInstance(); - bool openFile(const QString& fn, IAcceptor* pAcceptor); + bool openFile(const QString& fn, IAcceptor* pAcceptor, bool bImport = false); bool importNodes(IGraphsModel* pModel, const QModelIndex& subgIdx, const QString& nodeJson, const QPointF& targetPos, IAcceptor* pAcceptor); private: diff --git a/ui/zenomodel/include/igraphsmodel.h b/ui/zenomodel/include/igraphsmodel.h index 8339930291..5c29101d34 100644 --- a/ui/zenomodel/include/igraphsmodel.h +++ b/ui/zenomodel/include/igraphsmodel.h @@ -66,7 +66,7 @@ class IGraphsModel : public QAbstractItemModel virtual void setName(const QString& name, const QModelIndex& subGpIdx) = 0; virtual NODE_DESCS descriptors() const = 0; - virtual bool appendSubnetDescsFromZsg(const QList& descs) = 0; + virtual bool appendSubnetDescsFromZsg(const QList& descs, bool bImport = false) = 0; virtual bool getDescriptor(const QString& descName, NODE_DESC& desc) = 0; virtual bool updateSubgDesc(const QString& descName, const NODE_DESC& desc) = 0; virtual void clearSubGraph(const QModelIndex& subGpIdx) = 0; diff --git a/ui/zenomodel/src/graphsmanagment.cpp b/ui/zenomodel/src/graphsmanagment.cpp index f83320dbf4..2ad16dcf91 100644 --- a/ui/zenomodel/src/graphsmanagment.cpp +++ b/ui/zenomodel/src/graphsmanagment.cpp @@ -138,7 +138,7 @@ void GraphsManagment::importGraph(const QString& fn) IOBreakingScope batch(m_model); std::shared_ptr acceptor(zeno_model::createIOAcceptor(m_model, true)); - if (!ZsgReader::getInstance().openFile(fn, acceptor.get())) + if (!ZsgReader::getInstance().openFile(fn, acceptor.get(), true)) { zeno::log_error("failed to open zsg file: {}", fn.toStdString()); return; diff --git a/ui/zenomodel/src/graphsmodel.cpp b/ui/zenomodel/src/graphsmodel.cpp index d0076c7ca4..5e229ad772 100644 --- a/ui/zenomodel/src/graphsmodel.cpp +++ b/ui/zenomodel/src/graphsmodel.cpp @@ -603,7 +603,7 @@ NODE_DESCS GraphsModel::descriptors() const return descs; } -bool GraphsModel::appendSubnetDescsFromZsg(const QList& zsgSubnets) +bool GraphsModel::appendSubnetDescsFromZsg(const QList& zsgSubnets, bool bImport) { for (NODE_DESC desc : zsgSubnets) { @@ -613,6 +613,11 @@ bool GraphsModel::appendSubnetDescsFromZsg(const QList& zsgSubnets) m_subgsDesc.insert(desc.name, desc); registerCate(desc); } + else if (bImport) + { + desc.is_subgraph = true; + m_subgsDesc[desc.name] = desc; + } else { zeno::log_error("The graph \"{}\" exists!", desc.name.toStdString()); diff --git a/ui/zenomodel/src/graphsmodel.h b/ui/zenomodel/src/graphsmodel.h index a14a9fdc7c..4cba2cd583 100644 --- a/ui/zenomodel/src/graphsmodel.h +++ b/ui/zenomodel/src/graphsmodel.h @@ -37,7 +37,7 @@ class GraphsModel : public IGraphsModel void renameSubGraph(const QString& oldName, const QString& newName) override; QItemSelectionModel* selectionModel() const; NODE_DESCS descriptors() const override; - bool appendSubnetDescsFromZsg(const QList& descs) override; + bool appendSubnetDescsFromZsg(const QList& descs, bool bImport = false) override; bool getDescriptor(const QString& descName, NODE_DESC& desc) override; bool updateSubgDesc(const QString& descName, const NODE_DESC& desc) override; //NODE_DESC diff --git a/ui/zenomodel/src/modelacceptor.cpp b/ui/zenomodel/src/modelacceptor.cpp index f485a2c7cb..b6b47c892e 100644 --- a/ui/zenomodel/src/modelacceptor.cpp +++ b/ui/zenomodel/src/modelacceptor.cpp @@ -11,6 +11,7 @@ #include "uihelper.h" #include "variantptr.h" #include "dictkeymodel.h" +#include ModelAcceptor::ModelAcceptor(GraphsModel* pModel, bool bImport) @@ -40,7 +41,7 @@ bool ModelAcceptor::setLegacyDescs(const rapidjson::Value& graphObj, const NODE_ } subnetDescs.append(legacyDescs[name]); } - bool ret = m_pModel->appendSubnetDescsFromZsg(subnetDescs); + bool ret = m_pModel->appendSubnetDescsFromZsg(subnetDescs, m_bImport); return ret; } @@ -69,9 +70,21 @@ void ModelAcceptor::BeginSubgraph(const QString& name) zeno::log_info("Importing subgraph {}", name.toStdString()); ZASSERT_EXIT(m_pModel && !m_currentGraph); - SubGraphModel* pSubModel = new SubGraphModel(m_pModel); - pSubModel->setName(name); - m_pModel->appendSubGraph(pSubModel); + SubGraphModel* pSubModel = m_pModel->subGraph(name); + if (pSubModel) + { + if (m_bImport) + { + pSubModel->clear(); + zeno::log_warn("override subgraph {}", name.toStdString()); + } + } + else + { + pSubModel = new SubGraphModel(m_pModel); + pSubModel->setName(name); + m_pModel->appendSubGraph(pSubModel); + } m_currentGraph = pSubModel; } @@ -137,6 +150,119 @@ void ModelAcceptor::EndSubgraph() if (!m_currentGraph) return; m_currentGraph->onModelInited(); + if (m_bImport) + { + NODE_DESC desc; + QString name = m_currentGraph->name(); + m_pModel->getDescriptor(name, desc); + QModelIndexList subgNodes = m_pModel->findSubgraphNode(name); + NodeParamModel* pNodeParamModel = nullptr; + for (const QModelIndex& subgNode : subgNodes) + { + NodeParamModel* nodeParams = QVariantPtr::asPtr(subgNode.data(ROLE_NODE_PARAMS)); + if (!nodeParams) + continue; + //nodeParams->clearParams(); + int row = 0; + for (const auto& input : desc.inputs) + { + nodeParams->setAddParam( + PARAM_INPUT, + input.second.info.name, + input.second.info.type, + input.second.info.defaultValue, + input.second.info.control, + input.second.info.ctrlProps, + SOCKPROP_NORMAL, + DICTPANEL_INFO(), + input.second.info.toolTip + ); + int srcRow = 0; + VParamItem *pGroup = nodeParams->getInputs(); + if (pGroup) + { + pGroup->getItem(input.second.info.name, &srcRow); + if (srcRow != row) + { + nodeParams->moveRow(pGroup->index(), srcRow, pGroup->index(), row); + } + } + row++; + } + row = 0; + for (const auto& output : desc.outputs) + { + nodeParams->setAddParam( + PARAM_OUTPUT, + output.second.info.name, + output.second.info.type, + output.second.info.defaultValue, + output.second.info.control, + output.second.info.ctrlProps, + SOCKPROP_NORMAL, + DICTPANEL_INFO(), + output.second.info.toolTip + ); + int srcRow = 0; + VParamItem* pGroup = nodeParams->getOutputs(); + if (pGroup) + { + pGroup->getItem(output.second.info.name, &srcRow); + if (srcRow != row) + { + nodeParams->moveRow(pGroup->index(), srcRow, pGroup->index(), row); + } + } + row++; + } + row = 0; + for (const auto& param : desc.params) + { + nodeParams->setAddParam( + PARAM_PARAM, + param.name, + param.typeDesc, + param.defaultValue, + param.control, + param.controlProps, + SOCKPROP_NORMAL, + DICTPANEL_INFO(), + param.toolTip + ); + int srcRow = 0; + VParamItem* pGroup = nodeParams->getParams(); + if (pGroup) + { + pGroup->getItem(param.name, &srcRow); + if (srcRow != row) + { + nodeParams->moveRow(pGroup->index(), srcRow, pGroup->index(), row); + } + } + row++; + } + INPUT_SOCKETS inputs; + nodeParams->getInputSockets(inputs); + for (const auto& input : inputs) + { + QString name = input.key(); + if (!desc.inputs.contains(name)) + { + nodeParams->removeParam(PARAM_INPUT, name); + } + } + OUTPUT_SOCKETS outputs; + nodeParams->getOutputSockets(outputs); + for (const auto& output : outputs) + { + if (!desc.inputs.contains(output.key())) + { + nodeParams->removeParam(PARAM_INPUT, output.key()); + } + } + } + + } m_currentGraph = nullptr; } @@ -512,6 +638,38 @@ void ModelAcceptor::setIOVersion(zenoio::ZSG_VERSION versio) m_pModel->setIOVersion(versio); } +void ModelAcceptor::endNode(const QString& id, const QString& nodeCls, const rapidjson::Value& objValue) +{ + if (objValue.HasMember("outputs")) + { + const rapidjson::Value& outputs = objValue["outputs"]; + for (const auto& outObj : outputs.GetObject()) + { + const QString& outSock = outObj.name.GetString(); + const auto& sockObj = outObj.value; + if (sockObj.IsObject()) + { + if (sockObj.HasMember("tooltip")) { + QString toolTip = QString::fromUtf8(sockObj["tooltip"].GetString()); + setToolTip(PARAM_OUTPUT, id, outSock, toolTip); + } + bool bLinkRef = false; + if (sockObj.HasMember("link-ref")) + { + bLinkRef = sockObj["link-ref"].GetBool(); + } + QString type; + if (sockObj.HasMember("type")) + { + type = sockObj["type"].GetString(); + } + if (bLinkRef || !type.isEmpty()) + setOutputSocket(id, outSock, bLinkRef, type); + } + } + } +} + void ModelAcceptor::endParams(const QString& id, const QString& nodeCls) { if (nodeCls == "SubInput" || nodeCls == "SubOutput") diff --git a/ui/zenomodel/src/modelacceptor.h b/ui/zenomodel/src/modelacceptor.h index c6e3f3a0f0..dadd367ce6 100644 --- a/ui/zenomodel/src/modelacceptor.h +++ b/ui/zenomodel/src/modelacceptor.h @@ -81,6 +81,7 @@ class ModelAcceptor : public IAcceptor void endParams(const QString& id, const QString& nodeCls) override; void addCustomUI(const QString& id, const VPARAM_INFO& invisibleRoot) override; void setIOVersion(zenoio::ZSG_VERSION versio) override; + void endNode(const QString& id, const QString& nodeCls, const rapidjson::Value& objValue) override; private: void resolveAllLinks(); From 91e21bf282d66f1bbf40a77b7f57b588f5a6224f Mon Sep 17 00:00:00 2001 From: zhuohy <1445643474@qq.com> Date: Mon, 14 Aug 2023 14:38:31 +0800 Subject: [PATCH 2/8] import subgraphs optimization # Conflicts: # ui/zenoedit/zenomainwindow.cpp --- ui/zenoedit/res/stylesheet/pushbutton.qss | 8 +++ ui/zenoedit/res/stylesheet/qwidget.qss | 32 +++++++++++ ui/zenoedit/zenomainwindow.cpp | 65 ++++++++++++++++++++++- ui/zenoio/reader/zsgreader.cpp | 65 ++++++++++++++++++++--- ui/zenoio/reader/zsgreader.h | 3 +- ui/zenomodel/include/graphsmanagment.h | 1 + ui/zenomodel/include/igraphsmodel.h | 1 + ui/zenomodel/src/graphsmanagment.cpp | 16 +++++- ui/zenomodel/src/graphsmodel.cpp | 5 ++ ui/zenomodel/src/graphsmodel.h | 1 + ui/zenomodel/src/modelacceptor.cpp | 30 +++++++---- 11 files changed, 208 insertions(+), 19 deletions(-) diff --git a/ui/zenoedit/res/stylesheet/pushbutton.qss b/ui/zenoedit/res/stylesheet/pushbutton.qss index 54aaf4f4f1..9a91bb37e3 100644 --- a/ui/zenoedit/res/stylesheet/pushbutton.qss +++ b/ui/zenoedit/res/stylesheet/pushbutton.qss @@ -332,3 +332,11 @@ QPushButton[cssClass="CoreParam"] color: #FFFFFF; padding:3px 3px; } + +QPushButton[cssClass="select_subgraph"] +{ + background-color: transparent; + color: #FFFFFF; + border:0; + text-align:left; +} \ No newline at end of file diff --git a/ui/zenoedit/res/stylesheet/qwidget.qss b/ui/zenoedit/res/stylesheet/qwidget.qss index 8b1f6e2eb8..6015a33bec 100644 --- a/ui/zenoedit/res/stylesheet/qwidget.qss +++ b/ui/zenoedit/res/stylesheet/qwidget.qss @@ -116,6 +116,38 @@ QDialog QTableWidget::item:selected background-color: #344361; } +QTableWidget[cssClass="select_subgraph"] +{ + background-color: transparent; + color: #FFFFFF; + font-size: 9pt; + gridline-color:rgb(115,123,133); + show-grid: false; +} + +QTableWidget[cssClass="select_subgraph"] QHeaderView +{ + background-color: rgb(45,50,57); +} + +QTableWidget[cssClass="select_subgraph"] QHeaderView:section +{ + background-color: rgb(45,50,57); + border:0; + border-bottom: 1px solid rgb(115,123,133); +} + +QTableWidget[cssClass="select_subgraph"]::item +{ + background-color: transparent; + border-bottom: 1px solid rgb(115,123,133); +} + +QTableWidget[cssClass="select_subgraph"]::item:selected +{ + background-color: transparent; +} + QDialog QFrame#line { color:#737B85; diff --git a/ui/zenoedit/zenomainwindow.cpp b/ui/zenoedit/zenomainwindow.cpp index 1ef3127011..dfd895516f 100644 --- a/ui/zenoedit/zenomainwindow.cpp +++ b/ui/zenoedit/zenomainwindow.cpp @@ -53,6 +53,7 @@ #include #include #include +#include "dialog/ZImportSubgraphsDlg.h" const QString g_latest_layout = "LatestLayout"; @@ -1319,7 +1320,69 @@ void ZenoMainWindow::importGraph() { //todo: path validation auto pGraphs = zenoApp->graphsManagment(); - pGraphs->importGraph(filePath); + QMap subgraphNames;//old name: new name + QFile file(filePath); + bool ret = file.open(QIODevice::ReadOnly | QIODevice::Text); + if (ret) { + rapidjson::Document doc; + QByteArray bytes = file.readAll(); + doc.Parse(bytes); + + if (doc.IsObject() && doc.HasMember("graph")) + { + const rapidjson::Value& graph = doc["graph"]; + if (!graph.IsNull()) { + IGraphsModel *pModel = pGraphs->currentModel(); + if (pModel) + { + QStringList subgraphLst = pModel->subgraphsName(); + QStringList duplicateLst; + for (const auto& subgraph : graph.GetObject()) + { + const QString& graphName = subgraph.name.GetString(); + if (graphName == "main") + continue; + if (subgraphLst.contains(graphName)) + { + duplicateLst << graphName; + } + else + { + subgraphNames[graphName] = graphName; + } + } + if (!duplicateLst.isEmpty()) + { + ZImportSubgraphsDlg dlg(duplicateLst, this); + connect(&dlg, &ZImportSubgraphsDlg::selectedSignal, this, [&subgraphNames, pModel](const QStringList& lst, bool bRename) mutable { + if (!lst.isEmpty()) + { + for (const QString name : lst) + { + if (bRename) + { + QString newName = name; + int i = 1; + while (pModel->getDescriptor(newName, NODE_DESC())) + { + newName = name + QString("_%1").arg(i); + i++; + } + subgraphNames[name] = newName; + } + else + subgraphNames[name] = name; + } + } + }); + dlg.exec(); + } + } + } + } + } + if (!subgraphNames.isEmpty()) + pGraphs->importSubGraphs(filePath, subgraphNames); } static bool saveContent(const QString &strContent, QString filePath) { diff --git a/ui/zenoio/reader/zsgreader.cpp b/ui/zenoio/reader/zsgreader.cpp index e4ad31c2b1..7d7b700c9f 100644 --- a/ui/zenoio/reader/zsgreader.cpp +++ b/ui/zenoio/reader/zsgreader.cpp @@ -52,7 +52,7 @@ bool ZsgReader::importNodes(IGraphsModel* pModel, const QModelIndex& subgIdx, co return true; } -bool ZsgReader::openFile(const QString& fn, IAcceptor* pAcceptor, bool bImport) +bool ZsgReader::openFile(const QString& fn, IAcceptor* pAcceptor) { QFile file(fn); bool ret = file.open(QIODevice::ReadOnly | QIODevice::Text); @@ -90,17 +90,12 @@ bool ZsgReader::openFile(const QString& fn, IAcceptor* pAcceptor, bool bImport) for (const auto& subgraph : graph.GetObject()) { const QString& graphName = subgraph.name.GetString(); - if (bImport && graphName == "main") - continue; if (!_parseSubGraph(graphName, subgraph.value, nodesDescs, pAcceptor)) return false; } pAcceptor->EndGraphs(); pAcceptor->switchSubGraph("main"); - if (bImport) - return true; - if (doc.HasMember("views")) { _parseViews(doc["views"], pAcceptor); @@ -117,6 +112,64 @@ bool ZsgReader::openFile(const QString& fn, IAcceptor* pAcceptor, bool bImport) return true; } +bool ZsgReader::importSubgraphs(const QString& fn, IAcceptor* pAcceptor, const QMap& subGraphNames, IGraphsModel* pModel) +{ + QFile file(fn); + bool ret = file.open(QIODevice::ReadOnly | QIODevice::Text); + if (!ret) { + zeno::log_error("cannot open zsg file: {} ({})", fn.toStdString(), + file.errorString().toStdString()); + return false; + } + + pAcceptor->setFilePath(fn); + + rapidjson::Document doc; + QByteArray bytes = file.readAll(); + doc.Parse(bytes); + + if (!doc.IsObject() || !doc.HasMember("graph")) + { + zeno::log_error("zsg json file is corrupted"); + return false; + } + + const rapidjson::Value& graph = doc["graph"]; + if (graph.IsNull()) { + zeno::log_error("json format incorrect in zsg file: {}", fn.toStdString()); + return false; + } + + ZASSERT_EXIT(doc.HasMember("descs"), false); + NODE_DESCS nodesDescs = _parseDescs(doc["descs"], pAcceptor); + NODE_DESCS subgDesc; + for (const auto& name : subGraphNames.keys()) + { + QString newName = subGraphNames[name]; + NODE_DESC desc = nodesDescs[name]; + desc.name = newName; + subgDesc[desc.name] = desc; + } + ret = pAcceptor->setLegacyDescs(graph, subgDesc); + if (!ret) { + return false; + } + + for (const auto& subgraph : graph.GetObject()) + { + QString graphName = subgraph.name.GetString(); + if (!subGraphNames.contains(graphName)) + continue; + else + graphName = subGraphNames[graphName]; + + if (!_parseSubGraph(graphName, subgraph.value, nodesDescs, pAcceptor)) + return false; + } + pAcceptor->EndGraphs(); + return true; +} + bool ZsgReader::_parseSubGraph(const QString& name, const rapidjson::Value& subgraph, const NODE_DESCS& descriptors, IAcceptor* pAcceptor) { if (!subgraph.IsObject() || !subgraph.HasMember("nodes")) diff --git a/ui/zenoio/reader/zsgreader.h b/ui/zenoio/reader/zsgreader.h index d16f98aa13..7b80bb973a 100644 --- a/ui/zenoio/reader/zsgreader.h +++ b/ui/zenoio/reader/zsgreader.h @@ -16,7 +16,8 @@ class ZsgReader { public: static ZsgReader& getInstance(); - bool openFile(const QString& fn, IAcceptor* pAcceptor, bool bImport = false); + bool openFile(const QString& fn, IAcceptor* pAcceptor); + bool importSubgraphs(const QString& fn, IAcceptor* pAcceptor, const QMap& graphs, IGraphsModel* pModel); bool importNodes(IGraphsModel* pModel, const QModelIndex& subgIdx, const QString& nodeJson, const QPointF& targetPos, IAcceptor* pAcceptor); private: diff --git a/ui/zenomodel/include/graphsmanagment.h b/ui/zenomodel/include/graphsmanagment.h index 54793a3ccb..161f61a367 100644 --- a/ui/zenomodel/include/graphsmanagment.h +++ b/ui/zenomodel/include/graphsmanagment.h @@ -19,6 +19,7 @@ class GraphsManagment : public QObject bool saveFile(const QString& filePath, APP_SETTINGS settings); IGraphsModel* newFile(); void importGraph(const QString& fn); + void importSubGraphs(const QString& fn, const QMap& map); void clear(); void removeCurrent(); void appendLog(QtMsgType type, QString fileName, int ln, const QString &msg); diff --git a/ui/zenomodel/include/igraphsmodel.h b/ui/zenomodel/include/igraphsmodel.h index 5c29101d34..23a563e2ed 100644 --- a/ui/zenomodel/include/igraphsmodel.h +++ b/ui/zenomodel/include/igraphsmodel.h @@ -118,6 +118,7 @@ class IGraphsModel : public QAbstractItemModel virtual bool setCustomName(const QModelIndex &subgIdx, const QModelIndex& Idx, const QString &value) const = 0; virtual void markNodeDataChanged(const QModelIndex& idx) = 0; virtual void clearNodeDataChanged() = 0; + virtual QStringList subgraphsName() const = 0; signals: void clearLayout2(); diff --git a/ui/zenomodel/src/graphsmanagment.cpp b/ui/zenomodel/src/graphsmanagment.cpp index 2ad16dcf91..e467f2b306 100644 --- a/ui/zenomodel/src/graphsmanagment.cpp +++ b/ui/zenomodel/src/graphsmanagment.cpp @@ -138,13 +138,27 @@ void GraphsManagment::importGraph(const QString& fn) IOBreakingScope batch(m_model); std::shared_ptr acceptor(zeno_model::createIOAcceptor(m_model, true)); - if (!ZsgReader::getInstance().openFile(fn, acceptor.get(), true)) + if (!ZsgReader::getInstance().openFile(fn, acceptor.get())) { zeno::log_error("failed to open zsg file: {}", fn.toStdString()); return; } } +void GraphsManagment::importSubGraphs(const QString& fn, const QMap& map) +{ + if (!m_model) + return; + + IOBreakingScope batch(m_model); + std::shared_ptr acceptor(zeno_model::createIOAcceptor(m_model, true)); + if (!ZsgReader::getInstance().importSubgraphs(fn, acceptor.get(), map, m_model)) + { + zeno::log_error("failed to open zsg file: {}", fn.toStdString()); + return; + } +} + void GraphsManagment::clear() { if (m_model) diff --git a/ui/zenomodel/src/graphsmodel.cpp b/ui/zenomodel/src/graphsmodel.cpp index 5e229ad772..2a99159c14 100644 --- a/ui/zenomodel/src/graphsmodel.cpp +++ b/ui/zenomodel/src/graphsmodel.cpp @@ -1533,6 +1533,11 @@ void GraphsModel::clearNodeDataChanged() m_changedNodes.clear(); } +QStringList GraphsModel::subgraphsName() const +{ + return m_subGraphs.keys(); +} + void GraphsModel::updateNodeStatus(const QString& nodeid, STATUS_UPDATE_INFO info, const QModelIndex& subgIdx, bool enableTransaction) { QModelIndex nodeIdx = index(nodeid, subgIdx); diff --git a/ui/zenomodel/src/graphsmodel.h b/ui/zenomodel/src/graphsmodel.h index 4cba2cd583..9938c21f92 100644 --- a/ui/zenomodel/src/graphsmodel.h +++ b/ui/zenomodel/src/graphsmodel.h @@ -141,6 +141,7 @@ class GraphsModel : public IGraphsModel bool setCustomName(const QModelIndex &subgIdx, const QModelIndex &Idx, const QString &value) const override; void markNodeDataChanged(const QModelIndex& idx) override; void clearNodeDataChanged() override; + QStringList subgraphsName() const override; signals: void graphRenamed(const QString& oldName, const QString& newName); diff --git a/ui/zenomodel/src/modelacceptor.cpp b/ui/zenomodel/src/modelacceptor.cpp index b6b47c892e..ed0268a519 100644 --- a/ui/zenomodel/src/modelacceptor.cpp +++ b/ui/zenomodel/src/modelacceptor.cpp @@ -24,22 +24,32 @@ ModelAcceptor::ModelAcceptor(GraphsModel* pModel, bool bImport) bool ModelAcceptor::setLegacyDescs(const rapidjson::Value& graphObj, const NODE_DESCS& legacyDescs) { //discard legacy desc except subnet desc. - QStringList subgraphs; - for (const auto& subgraph : graphObj.GetObject()) + QList subnetDescs; + if (m_bImport) { - if (subgraph.name != "main") { - subgraphs.append(QString::fromUtf8(subgraph.name.GetString())); + for (const NODE_DESC& desc : legacyDescs) + { + subnetDescs.append(desc); } } - QList subnetDescs; - for (QString name : subgraphs) + else { - if (legacyDescs.find(name) == legacyDescs.end()) + QStringList subgraphs; + for (const auto& subgraph : graphObj.GetObject()) { - zeno::log_warn("subgraph {} isn't described by the file descs.", name.toStdString()); - continue; + if (subgraph.name != "main") { + subgraphs.append(QString::fromUtf8(subgraph.name.GetString())); + } + } + for (QString name : subgraphs) + { + if (legacyDescs.find(name) == legacyDescs.end()) + { + zeno::log_warn("subgraph {} isn't described by the file descs.", name.toStdString()); + continue; + } + subnetDescs.append(legacyDescs[name]); } - subnetDescs.append(legacyDescs[name]); } bool ret = m_pModel->appendSubnetDescsFromZsg(subnetDescs, m_bImport); return ret; From 33ce5bc684b8b0009483317921d55824f2023bcc Mon Sep 17 00:00:00 2001 From: zhuohy <1445643474@qq.com> Date: Mon, 14 Aug 2023 15:00:34 +0800 Subject: [PATCH 3/8] fix merge error --- ui/zenoedit/acceptor/transferacceptor.cpp | 12 ------------ ui/zenomodel/src/modelacceptor.cpp | 12 ------------ 2 files changed, 24 deletions(-) diff --git a/ui/zenoedit/acceptor/transferacceptor.cpp b/ui/zenoedit/acceptor/transferacceptor.cpp index 9cd0940477..b0b64acf21 100644 --- a/ui/zenoedit/acceptor/transferacceptor.cpp +++ b/ui/zenoedit/acceptor/transferacceptor.cpp @@ -581,18 +581,6 @@ void TransferAcceptor::endNode(const QString& id, const QString& nodeCls, const QString toolTip = QString::fromUtf8(sockObj["tooltip"].GetString()); setToolTip(PARAM_OUTPUT, id, outSock, toolTip); } - bool bLinkRef = false; - if (sockObj.HasMember("link-ref")) - { - bLinkRef = sockObj["link-ref"].GetBool(); - } - QString type; - if (sockObj.HasMember("type")) - { - type = sockObj["type"].GetString(); - } - if (bLinkRef || !type.isEmpty()) - setOutputSocket(id, outSock, bLinkRef, type); } } } diff --git a/ui/zenomodel/src/modelacceptor.cpp b/ui/zenomodel/src/modelacceptor.cpp index ed0268a519..fafe5ea9ac 100644 --- a/ui/zenomodel/src/modelacceptor.cpp +++ b/ui/zenomodel/src/modelacceptor.cpp @@ -663,18 +663,6 @@ void ModelAcceptor::endNode(const QString& id, const QString& nodeCls, const rap QString toolTip = QString::fromUtf8(sockObj["tooltip"].GetString()); setToolTip(PARAM_OUTPUT, id, outSock, toolTip); } - bool bLinkRef = false; - if (sockObj.HasMember("link-ref")) - { - bLinkRef = sockObj["link-ref"].GetBool(); - } - QString type; - if (sockObj.HasMember("type")) - { - type = sockObj["type"].GetString(); - } - if (bLinkRef || !type.isEmpty()) - setOutputSocket(id, outSock, bLinkRef, type); } } } From b0951851e10192da8c21e5b42d4ad3f6b0045ac8 Mon Sep 17 00:00:00 2001 From: zhuohy <1445643474@qq.com> Date: Mon, 14 Aug 2023 16:57:10 +0800 Subject: [PATCH 4/8] fix bug about importing subgraph --- ui/zenoedit/zenomainwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/zenoedit/zenomainwindow.cpp b/ui/zenoedit/zenomainwindow.cpp index cc0388551b..a8c7ed1ab8 100644 --- a/ui/zenoedit/zenomainwindow.cpp +++ b/ui/zenoedit/zenomainwindow.cpp @@ -1357,7 +1357,7 @@ void ZenoMainWindow::importGraph() { if (!duplicateLst.isEmpty()) { ZImportSubgraphsDlg dlg(duplicateLst, this); - connect(&dlg, &ZImportSubgraphsDlg::selectedSignal, this, [&subgraphNames, pModel](const QStringList& lst, bool bRename) mutable { + connect(&dlg, &ZImportSubgraphsDlg::selectedSignal, this, [&subgraphNames, subgraphLst](const QStringList& lst, bool bRename) mutable { if (!lst.isEmpty()) { for (const QString name : lst) @@ -1366,7 +1366,7 @@ void ZenoMainWindow::importGraph() { { QString newName = name; int i = 1; - while (pModel->getDescriptor(newName, NODE_DESC())) + while (subgraphLst.contains(newName)) { newName = name + QString("_%1").arg(i); i++; From 9de4e563ad925b7dbf5758040ba4a5c05fae76a5 Mon Sep 17 00:00:00 2001 From: zhuohy <1445643474@qq.com> Date: Mon, 14 Aug 2023 17:47:29 +0800 Subject: [PATCH 5/8] upload files of subgraphs importing --- ui/zenoedit/dialog/ZImportSubgraphsDlg.cpp | 232 +++++++++++++++++++++ ui/zenoedit/dialog/ZImportSubgraphsDlg.h | 60 ++++++ ui/zenoedit/dialog/ZImportSubgraphsDlg.ui | 50 +++++ 3 files changed, 342 insertions(+) create mode 100644 ui/zenoedit/dialog/ZImportSubgraphsDlg.cpp create mode 100644 ui/zenoedit/dialog/ZImportSubgraphsDlg.h create mode 100644 ui/zenoedit/dialog/ZImportSubgraphsDlg.ui diff --git a/ui/zenoedit/dialog/ZImportSubgraphsDlg.cpp b/ui/zenoedit/dialog/ZImportSubgraphsDlg.cpp new file mode 100644 index 0000000000..2353da0de7 --- /dev/null +++ b/ui/zenoedit/dialog/ZImportSubgraphsDlg.cpp @@ -0,0 +1,232 @@ +#include "ZImportSubgraphsDlg.h" +#include + +CheckBoxHeaderView::CheckBoxHeaderView(Qt::Orientation orientation, QWidget* parent) : QHeaderView(orientation, parent) +{ +} + +void CheckBoxHeaderView::setCheckState(QVector columns, bool state) +{ + for (const auto &col : columns) + { + m_checkedMap[col] = state; + } + update(); +} + +void CheckBoxHeaderView::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const +{ + painter->save(); + if (m_checkedMap.contains(logicalIndex)) + { + QStyleOptionButton option; + int size = ZenoStyle::dpiScaled(20); + option.rect = QRect(rect.x(), rect.y(), size, size); + if (m_checkedMap[logicalIndex]) + { + option.state = QStyle::State_On; + } + else + { + option.state = QStyle::State_Off; + } + QCheckBox* check = new QCheckBox; + this->style()->drawControl(QStyle::CE_CheckBox, &option, painter, check); + int diff = size + ZenoStyle::dpiScaled(4); + painter->drawText(rect.adjusted(diff, 0, diff, 0), model()->headerData(logicalIndex, Qt::Horizontal).toString()); + QPen pen; + pen.setColor(QColor(115, 123, 133)); + pen.setWidthF(ZenoStyle::dpiScaled(1)); + painter->setPen(pen); + painter->drawLine(rect.bottomLeft(), rect.bottomRight()); + } + else + { + QHeaderView::paintSection(painter, rect, logicalIndex); + } +} + +void CheckBoxHeaderView::mousePressEvent(QMouseEvent* event) +{ + int index = visualIndexAt(event->pos().x()); + if (m_checkedMap.contains(index)) + { + m_checkedMap[index] = !m_checkedMap[index]; + this->updateSection(index); + emit signalCheckStateChanged(index, m_checkedMap[index]); + } + emit QHeaderView::sectionClicked(visualIndexAt(event->pos().x())); + QHeaderView::mousePressEvent(event); +} + +//SubgraphsListDlg +ZSubgraphsListDlg::ZSubgraphsListDlg(const QStringList& lst, QWidget* parent) + : QDialog(parent) + , m_pTableWidget(nullptr) +{ + initUI(lst); +} + +ZSubgraphsListDlg::~ZSubgraphsListDlg() +{ +} + +void ZSubgraphsListDlg::initUI(const QStringList& subgraphs) +{ + setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + setWindowTitle(tr("List of subgraphs")); + setAttribute(Qt::WA_DeleteOnClose, true); + setMinimumHeight(ZenoStyle::dpiScaled(500)); + QVBoxLayout* layout = new QVBoxLayout(this); + + //inti TableWIdget + m_pTableWidget = new QTableWidget(this); + m_pTableWidget->setProperty("cssClass", "select_subgraph"); + CheckBoxHeaderView* pHeaderView = new CheckBoxHeaderView(Qt::Horizontal, m_pTableWidget); + m_pTableWidget->setHorizontalHeader(pHeaderView); + m_pTableWidget->verticalHeader()->setVisible(false); + m_pTableWidget->setColumnCount(3); + QStringList labels = { tr("Name"), tr("Replace"), tr("Rename") }; + m_pTableWidget->setHorizontalHeaderLabels(labels); + pHeaderView->setCheckState(QVector() << 1 << 2, false); + connect(pHeaderView, &CheckBoxHeaderView::signalCheckStateChanged, this, [=](int col, bool bChecked) { + updateCheckState(col, bChecked); + if (bChecked) + pHeaderView->setCheckState(QVector() << (col == 1 ? 2 : 1), false); + }); + m_pTableWidget->setShowGrid(false); + m_pTableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); + m_pTableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); + m_pTableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed); + m_pTableWidget->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed); + m_pTableWidget->horizontalHeader()->setDefaultSectionSize(ZenoStyle::dpiScaled(80)); + m_pTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); + for (const auto& subgraph : subgraphs) + { + int row = m_pTableWidget->rowCount(); + m_pTableWidget->insertRow(row); + QTableWidgetItem* pItem = new QTableWidgetItem(subgraph); + m_pTableWidget->setItem(row, 0, pItem); + QCheckBox* pReplaceCheckBox = new QCheckBox(m_pTableWidget); + m_pTableWidget->setCellWidget(row, 1, pReplaceCheckBox); + QCheckBox* pRenameCheckBox = new QCheckBox(m_pTableWidget); + m_pTableWidget->setCellWidget(row, 2, pRenameCheckBox); + connect(pReplaceCheckBox, &QCheckBox::stateChanged, this, [=]() { + if (pReplaceCheckBox->isChecked() && pRenameCheckBox->isChecked()) + pRenameCheckBox->setChecked(false); + }); + connect(pRenameCheckBox, &QCheckBox::stateChanged, this, [=]() { + if (pRenameCheckBox->isChecked() && pReplaceCheckBox->isChecked()) + pReplaceCheckBox->setChecked(false); + }); + } + //update table width + int width = 0; + for (int col = 0; col < m_pTableWidget->columnCount(); col++) + { + width += m_pTableWidget->columnWidth(col); + } + m_pTableWidget->setMinimumWidth(width + ZenoStyle::dpiScaled(15)); + layout->addWidget(m_pTableWidget); + + //init Ok & Cancel button + QHBoxLayout* pBtnLayout = new QHBoxLayout; + QPushButton* pOk = new QPushButton(tr("OK"), this); + QPushButton* pCancel = new QPushButton(tr("Cancel"), this); + QSize size(ZenoStyle::dpiScaledSize(QSize(100, 30))); + pOk->setFixedSize(size); + pCancel->setFixedSize(size); + pBtnLayout->addWidget(pOk); + pBtnLayout->addWidget(pCancel); + layout->addLayout(pBtnLayout); + connect(pOk, &QPushButton::clicked, this, &ZSubgraphsListDlg::onOkBtnClicked); + connect(pCancel, &QPushButton::clicked, this, &QDialog::reject); +} + +void ZSubgraphsListDlg::onOkBtnClicked() +{ + QStringList replaceLst; + QStringList renameLst; + for (int row = 0; row < m_pTableWidget->rowCount(); row++) + { + if (QWidget* pReplaceWidget = m_pTableWidget->cellWidget(row, 1)) + { + if (QCheckBox* pCheckBox = dynamic_cast(pReplaceWidget)) + { + pCheckBox->isChecked(); + } + } + if (QWidget* pRenameWidget = m_pTableWidget->cellWidget(row, 2)) + { + if (QCheckBox* pCheckBox = dynamic_cast(pRenameWidget)) + { + QString name = m_pTableWidget->item(row, 0)->data(Qt::DisplayRole).toString(); + if (pCheckBox->isChecked()) + { + renameLst << name; + } + else if (QWidget* pReplaceWidget = m_pTableWidget->cellWidget(row, 1)) + { + if (QCheckBox* pReplaceCheckBox = dynamic_cast(pReplaceWidget)) + { + if (pReplaceCheckBox->isChecked()) + { + replaceLst << name; + } + } + } + } + } + } + emit this->selectedSignal(renameLst, true); + emit this->selectedSignal(replaceLst, false); + this->accept(); +} + +void ZSubgraphsListDlg::updateCheckState(int col, bool state) +{ + for (int row = 0; row < m_pTableWidget->rowCount(); row++) + { + if (QCheckBox* pCheckBox = dynamic_cast(m_pTableWidget->cellWidget(row, col))) + { + pCheckBox->setChecked(state); + } + } +} + + +ZImportSubgraphsDlg::ZImportSubgraphsDlg(const QStringList& lst, QWidget *parent) + : QDialog(parent) + , m_subgraphs(lst) +{ + m_ui = new Ui::ZImportSubgraphsDlg; + m_ui->setupUi(this); + this->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + m_ui->m_replaceBtn->setProperty("cssClass", "select_subgraph"); + m_ui->m_skipBtn->setProperty("cssClass", "select_subgraph"); + m_ui->m_selectBtn->setProperty("cssClass", "select_subgraph"); + m_ui->m_tipLabel->setText(tr("include %1 subgraphs with the same name").arg(lst.size())); + connect(m_ui->m_replaceBtn, &QPushButton::clicked, this, [=]() { + emit selectedSignal(lst, false); + accept(); + }); + connect(m_ui->m_skipBtn, &QPushButton::clicked, this, [=]() { + emit selectedSignal(QStringList(), false); + accept(); + }); + connect(m_ui->m_selectBtn, &QPushButton::clicked, this, &ZImportSubgraphsDlg::onSelectBtnClicked); +} + +ZImportSubgraphsDlg::~ZImportSubgraphsDlg() +{ +} + +void ZImportSubgraphsDlg::onSelectBtnClicked() +{ + ZSubgraphsListDlg*dlg = new ZSubgraphsListDlg(m_subgraphs, this); + connect(dlg, &ZSubgraphsListDlg::selectedSignal, this, &ZImportSubgraphsDlg::selectedSignal); + if (dlg->exec() == QDialog::Accepted) + { + this->accept(); + } +} \ No newline at end of file diff --git a/ui/zenoedit/dialog/ZImportSubgraphsDlg.h b/ui/zenoedit/dialog/ZImportSubgraphsDlg.h new file mode 100644 index 0000000000..78828ace37 --- /dev/null +++ b/ui/zenoedit/dialog/ZImportSubgraphsDlg.h @@ -0,0 +1,60 @@ +#ifndef __ZIMPORT_SUBGRAPHS_DLG_H__ +#define __ZIMPORT_SUBGRAPHS_DLG_H__ + +#include +#include "ui_ZImportSubgraphsDlg.h" + +class CheckBoxHeaderView : public QHeaderView +{ + Q_OBJECT + +public: + CheckBoxHeaderView(Qt::Orientation orientation, QWidget* parent = nullptr); + void setCheckState(QVector columns, bool state); + +signals: + void signalCheckStateChanged(int col, bool state); + +protected: + void paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const; + void mousePressEvent(QMouseEvent* event); + +private: + QMap m_checkedMap; //¹´Ñ¡¿ò״̬ +}; + +class ZSubgraphsListDlg : public QDialog +{ + Q_OBJECT + +public: + ZSubgraphsListDlg(const QStringList& lst, QWidget* parent = nullptr); + ~ZSubgraphsListDlg(); +signals: + void selectedSignal(const QStringList& lst, bool isRename); +private: + void initUI(const QStringList& lst); + void updateCheckState(int col, bool state); +private slots: + void onOkBtnClicked(); +private: + QTableWidget* m_pTableWidget; +}; + +class ZImportSubgraphsDlg : public QDialog +{ + Q_OBJECT + +public: + ZImportSubgraphsDlg(const QStringList &lst, QWidget *parent = nullptr); + ~ZImportSubgraphsDlg(); +signals: + void selectedSignal(const QStringList& lst, bool isRename); +private slots: + void onSelectBtnClicked(); +private: + Ui::ZImportSubgraphsDlg* m_ui; + const QStringList& m_subgraphs; +}; + +#endif diff --git a/ui/zenoedit/dialog/ZImportSubgraphsDlg.ui b/ui/zenoedit/dialog/ZImportSubgraphsDlg.ui new file mode 100644 index 0000000000..74bfe9ef39 --- /dev/null +++ b/ui/zenoedit/dialog/ZImportSubgraphsDlg.ui @@ -0,0 +1,50 @@ + + + ZImportSubgraphsDlg + + + + 0 + 0 + 202 + 154 + + + + Replace or Skip + + + + + + + + + + + + + Replace All + + + + + + + Skip All + + + + + + + Select Subgraphs + + + + + + + + + From 45f894b05ff59adacb1ca153b75a74814c70c6c8 Mon Sep 17 00:00:00 2001 From: zhuohy <1445643474@qq.com> Date: Tue, 15 Aug 2023 10:29:50 +0800 Subject: [PATCH 6/8] fix bugs about importing subgraphs when renaming --- ui/zenoedit/acceptor/transferacceptor.cpp | 2 +- ui/zenoedit/acceptor/transferacceptor.h | 2 +- ui/zenoio/acceptor/iacceptor.h | 2 +- ui/zenoio/reader/zsgreader.cpp | 4 ++-- ui/zenomodel/src/modelacceptor.cpp | 25 +++++++++++++++++++---- ui/zenomodel/src/modelacceptor.h | 3 ++- 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/ui/zenoedit/acceptor/transferacceptor.cpp b/ui/zenoedit/acceptor/transferacceptor.cpp index b0b64acf21..866b7e96cd 100644 --- a/ui/zenoedit/acceptor/transferacceptor.cpp +++ b/ui/zenoedit/acceptor/transferacceptor.cpp @@ -53,7 +53,7 @@ void TransferAcceptor::switchSubGraph(const QString& graphName) } -bool TransferAcceptor::addNode(const QString& nodeid, const QString& name, const QString& customName, const NODE_DESCS& descriptors) +bool TransferAcceptor::addNode(QString& nodeid, const QString& name, const QString& customName, const NODE_DESCS& descriptors) { if (m_nodes.find(nodeid) != m_nodes.end()) return false; diff --git a/ui/zenoedit/acceptor/transferacceptor.h b/ui/zenoedit/acceptor/transferacceptor.h index e29776184d..15378a25df 100644 --- a/ui/zenoedit/acceptor/transferacceptor.h +++ b/ui/zenoedit/acceptor/transferacceptor.h @@ -16,7 +16,7 @@ class TransferAcceptor : public IAcceptor bool setCurrentSubGraph(IGraphsModel *pModel, const QModelIndex &subgIdx) override; void setFilePath(const QString &fileName) override; void switchSubGraph(const QString &graphName) override; - bool addNode(const QString &nodeid, const QString &name, const QString& customName, const NODE_DESCS &descriptors) override; + bool addNode(QString &nodeid, const QString &name, const QString& customName, const NODE_DESCS &descriptors) override; void setViewRect(const QRectF &rc) override; void setSocketKeys(const QString &id, const QStringList &keys) override; void initSockets(const QString &id, const QString &name, const NODE_DESCS &legacyDescs) override; diff --git a/ui/zenoio/acceptor/iacceptor.h b/ui/zenoio/acceptor/iacceptor.h index 7ca74af590..468e73fc76 100644 --- a/ui/zenoio/acceptor/iacceptor.h +++ b/ui/zenoio/acceptor/iacceptor.h @@ -18,7 +18,7 @@ class IAcceptor virtual bool setCurrentSubGraph(IGraphsModel* pModel, const QModelIndex& subgIdx) = 0; virtual void setFilePath(const QString& fileName) = 0; virtual void switchSubGraph(const QString& graphName) = 0; - virtual bool addNode(const QString& nodeid, const QString& name, const QString& customName, const NODE_DESCS& descriptors) = 0; + virtual bool addNode(QString& nodeid, const QString& name, const QString& customName, const NODE_DESCS& descriptors) = 0; virtual void setViewRect(const QRectF& rc) = 0; virtual void setSocketKeys(const QString& id, const QStringList& keys) = 0; virtual void initSockets(const QString& id, const QString& name, const NODE_DESCS& legacyDescs) = 0; diff --git a/ui/zenoio/reader/zsgreader.cpp b/ui/zenoio/reader/zsgreader.cpp index 7d7b700c9f..49496ed699 100644 --- a/ui/zenoio/reader/zsgreader.cpp +++ b/ui/zenoio/reader/zsgreader.cpp @@ -226,7 +226,7 @@ bool ZsgReader::_parseSubGraph(const QString& name, const rapidjson::Value& subg return true; } -bool ZsgReader::_parseNode(const QString& nodeid, const rapidjson::Value& nodeObj, const NODE_DESCS& legacyDescs, IAcceptor* pAcceptor) +bool ZsgReader::_parseNode(const QString& ident, const rapidjson::Value& nodeObj, const NODE_DESCS& legacyDescs, IAcceptor* pAcceptor) { const auto& objValue = nodeObj; const rapidjson::Value& nameValue = objValue["name"]; @@ -237,7 +237,7 @@ bool ZsgReader::_parseNode(const QString& nodeid, const rapidjson::Value& nodeOb const QString &tmp = objValue["customName"].GetString(); customName = tmp; } - + QString nodeid = ident; bool bSucceed = pAcceptor->addNode(nodeid, name, customName, legacyDescs); if (!bSucceed) { return false; diff --git a/ui/zenomodel/src/modelacceptor.cpp b/ui/zenomodel/src/modelacceptor.cpp index fafe5ea9ac..981b3b70bc 100644 --- a/ui/zenomodel/src/modelacceptor.cpp +++ b/ui/zenomodel/src/modelacceptor.cpp @@ -118,6 +118,18 @@ void ModelAcceptor::resolveAllLinks() //add links on this subgraph. for (EdgeInfo link : m_subgLinks) { + for (const auto &newId : m_oldToNewNodeIds.keys()) + { + QString oldId = m_oldToNewNodeIds[newId]; + if (link.outSockPath.contains(oldId)) + { + QString subgName = UiHelper::getSockSubgraph(link.inSockPath); + QString paramPath = UiHelper::getParamPath(link.outSockPath); + QString outSockPath = UiHelper::constructObjPath(subgName, newId, paramPath); + link.outSockPath = outSockPath; + break; + } + } QModelIndex inSock, outSock, inNode, outNode; QString subgName, inNodeCls, outNodeCls, inSockName, outSockName, paramCls; @@ -172,7 +184,6 @@ void ModelAcceptor::EndSubgraph() NodeParamModel* nodeParams = QVariantPtr::asPtr(subgNode.data(ROLE_NODE_PARAMS)); if (!nodeParams) continue; - //nodeParams->clearParams(); int row = 0; for (const auto& input : desc.inputs) { @@ -265,9 +276,9 @@ void ModelAcceptor::EndSubgraph() nodeParams->getOutputSockets(outputs); for (const auto& output : outputs) { - if (!desc.inputs.contains(output.key())) + if (!desc.outputs.contains(output.key())) { - nodeParams->removeParam(PARAM_INPUT, output.key()); + nodeParams->removeParam(PARAM_OUTPUT, output.key()); } } } @@ -287,7 +298,7 @@ void ModelAcceptor::switchSubGraph(const QString& graphName) m_pModel->switchSubGraph(graphName); } -bool ModelAcceptor::addNode(const QString& nodeid, const QString& name, const QString& customName, const NODE_DESCS& legacyDescs) +bool ModelAcceptor::addNode(QString& nodeid, const QString& name, const QString& customName, const NODE_DESCS& legacyDescs) { if (!m_currentGraph) return false; @@ -298,6 +309,12 @@ bool ModelAcceptor::addNode(const QString& nodeid, const QString& name, const QS } NODE_DATA data; + if (m_bImport) + { + QString newId = UiHelper::generateUuid(name); + m_oldToNewNodeIds[newId] = nodeid; + nodeid = newId; + } data[ROLE_OBJID] = nodeid; data[ROLE_OBJNAME] = name; data[ROLE_CUSTOM_OBJNAME] = customName; diff --git a/ui/zenomodel/src/modelacceptor.h b/ui/zenomodel/src/modelacceptor.h index dadd367ce6..f383323eb2 100644 --- a/ui/zenomodel/src/modelacceptor.h +++ b/ui/zenomodel/src/modelacceptor.h @@ -21,7 +21,7 @@ class ModelAcceptor : public IAcceptor void EndGraphs() override; void setFilePath(const QString& fileName) override; void switchSubGraph(const QString& graphName) override; - bool addNode(const QString& nodeid, const QString& name, const QString& customName, const NODE_DESCS& descriptors) override; + bool addNode(QString& nodeid, const QString& name, const QString& customName, const NODE_DESCS& descriptors) override; void setViewRect(const QRectF& rc) override; void setSocketKeys(const QString& id, const QStringList& keys) override; void initSockets(const QString& id, const QString& name, const NODE_DESCS& descs) override; @@ -91,6 +91,7 @@ class ModelAcceptor : public IAcceptor SubGraphModel* m_currentGraph; GraphsModel* m_pModel; bool m_bImport; + QMap m_oldToNewNodeIds; // }; From fa69677a982fa5d59195eacf6df3ab8432aae2db Mon Sep 17 00:00:00 2001 From: zhuohy <1445643474@qq.com> Date: Tue, 15 Aug 2023 16:11:09 +0800 Subject: [PATCH 7/8] fix bug about painting checkbox header view --- ui/zenoedit/dialog/ZImportSubgraphsDlg.cpp | 9 +++++---- ui/zenoedit/res/stylesheet/qwidget.qss | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/zenoedit/dialog/ZImportSubgraphsDlg.cpp b/ui/zenoedit/dialog/ZImportSubgraphsDlg.cpp index 2353da0de7..b848e8a02a 100644 --- a/ui/zenoedit/dialog/ZImportSubgraphsDlg.cpp +++ b/ui/zenoedit/dialog/ZImportSubgraphsDlg.cpp @@ -16,7 +16,6 @@ void CheckBoxHeaderView::setCheckState(QVector columns, bool state) void CheckBoxHeaderView::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const { - painter->save(); if (m_checkedMap.contains(logicalIndex)) { QStyleOptionButton option; @@ -30,11 +29,13 @@ void CheckBoxHeaderView::paintSection(QPainter* painter, const QRect& rect, int { option.state = QStyle::State_Off; } - QCheckBox* check = new QCheckBox; - this->style()->drawControl(QStyle::CE_CheckBox, &option, painter, check); + this->style()->drawControl(QStyle::CE_CheckBox, &option, painter, &QCheckBox()); int diff = size + ZenoStyle::dpiScaled(4); - painter->drawText(rect.adjusted(diff, 0, diff, 0), model()->headerData(logicalIndex, Qt::Horizontal).toString()); QPen pen; + pen.setColor(QColor(166, 166, 166)); + painter->setPen(pen); + painter->drawText(rect.adjusted(diff, 0, diff, 0), model()->headerData(logicalIndex, Qt::Horizontal).toString()); + pen.setColor(QColor(115, 123, 133)); pen.setWidthF(ZenoStyle::dpiScaled(1)); painter->setPen(pen); diff --git a/ui/zenoedit/res/stylesheet/qwidget.qss b/ui/zenoedit/res/stylesheet/qwidget.qss index 6015a33bec..caa7be6bbd 100644 --- a/ui/zenoedit/res/stylesheet/qwidget.qss +++ b/ui/zenoedit/res/stylesheet/qwidget.qss @@ -122,7 +122,6 @@ QTableWidget[cssClass="select_subgraph"] color: #FFFFFF; font-size: 9pt; gridline-color:rgb(115,123,133); - show-grid: false; } QTableWidget[cssClass="select_subgraph"] QHeaderView From c044b2f28d25c36d80c394ca19cc1d76a8188b4a Mon Sep 17 00:00:00 2001 From: zhuohy <1445643474@qq.com> Date: Sat, 7 Oct 2023 17:50:06 +0800 Subject: [PATCH 8/8] create the first searching node after pressing the enter key --- ui/zenoedit/nodesys/searchview.cpp | 2 +- ui/zenoedit/nodesys/zenonewmenu.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ui/zenoedit/nodesys/searchview.cpp b/ui/zenoedit/nodesys/searchview.cpp index 731fcc3cff..3a6fc2a9b6 100644 --- a/ui/zenoedit/nodesys/searchview.cpp +++ b/ui/zenoedit/nodesys/searchview.cpp @@ -110,8 +110,8 @@ void SearchResultWidget::resizeCount(int count) void SearchResultWidget::moveToTop() { - setCurrentIndex(model()->index(0, 0)); clearSelection(); + setCurrentIndex(model()->index(0, 0)); } void SearchResultWidget::keyPressEvent(QKeyEvent* event) diff --git a/ui/zenoedit/nodesys/zenonewmenu.cpp b/ui/zenoedit/nodesys/zenonewmenu.cpp index e09cf38eb6..6867c2c15d 100644 --- a/ui/zenoedit/nodesys/zenonewmenu.cpp +++ b/ui/zenoedit/nodesys/zenonewmenu.cpp @@ -104,6 +104,13 @@ bool ZenoNewnodeMenu::eventFilter(QObject* watched, QEvent* event) return true; } } + else if (watched == m_searchEdit && (pKeyEvent->key() == Qt::Key_Return || pKeyEvent->key() == Qt::Key_Enter)) + { + if (m_searchView->isVisible() && m_searchView->count() > 0) + { + emit m_searchView->pressed(m_searchView->currentIndex()); + } + } } else if (watched == m_searchEdit && event->type() == QEvent::Show) {