Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug about preset material subgraphs #1601

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions ui/zenoedit/dialog/zforksubgraphdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void ZForkSubgraphDlg::initUi()

QTableWidgetItem* pMatItem = new QTableWidgetItem(subgraph);
m_pTableWidget->setItem(row, 2, pMatItem);
pMatItem->setData(Qt::UserRole, subgraph);

}
pLayout->addWidget(m_pTableWidget);
Expand All @@ -61,16 +62,32 @@ void ZForkSubgraphDlg::initUi()
this->setMainWidget(pWidget);

connect(pOkBtn, &QPushButton::clicked, this, [=]() {
for (int row = 0; row < m_pTableWidget->rowCount(); row++)
int count = m_pTableWidget->rowCount();
int rowNum = qSqrt(count);
int colunmNum = count / (rowNum > 0 ? rowNum : 1);
QPointF pos;
for (int row = 0; row < count; row++)
{
QString subgName = m_pTableWidget->item(row, 0)->data(Qt::DisplayRole).toString();
QString name = m_pTableWidget->item(row, 1)->data(Qt::DisplayRole).toString();
QString mtlid = m_pTableWidget->item(row, 2)->data(Qt::DisplayRole).toString();
IGraphsModel* pGraphsModel = zenoApp->graphsManagment()->currentModel();
const QModelIndex& index = pGraphsModel->forkMaterial(pGraphsModel->index(subgName), name, mtlid, m_subgsMap.key(subgName));
QString old_mtlid = m_pTableWidget->item(row, 2)->data(Qt::UserRole).toString();
IGraphsModel* pGraphsModel = zenoApp->graphsManagment()->currentModel();
const QModelIndex& index = pGraphsModel->forkMaterial(pGraphsModel->index(subgName), name, mtlid, old_mtlid);
if (!index.isValid())
{
QMessageBox::warning(this, tr("warring"), tr("fork preset subgraph '%1' failed.").arg(subgName));
QMessageBox::warning(this, tr("warring"), tr("fork preset subgraph '%1' failed.").arg(name));
}
if (row > 0)
{
int currC = row / rowNum;
int currR = row % rowNum;
QPointF newPos(pos.x() + currC * 600, pos.y() + currR * 600);
pGraphsModel->ModelSetData(index, newPos, ROLE_OBJPOS);
}
else
{
pos = index.data(ROLE_OBJPOS).toPointF();
}
}
accept();
Expand Down
18 changes: 10 additions & 8 deletions ui/zenomodel/src/graphsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,15 +880,17 @@ QModelIndex GraphsModel::forkMaterial(const QModelIndex& subnetNodeIdx, const QS
auto paramIdx = pSubgModel->nodeParamIndex(result.targetIdx, PARAM_INPUT, "mtlid");
ModelSetData(paramIdx, mtlid, ROLE_PARAM_VALUE);
}
vec.clear();
vec << currentGraph();
resLst = search(mtlid_old, SEARCH_ARGS, SEARCH_MATCH_EXACTLY, vec);
for (const auto& res : resLst)
//update mtlid of BindMeterial node
if (mtlid != mtlid_old)
{
QPointF pos = res.targetIdx.data(ROLE_OBJPOS).toPointF();
ModelSetData(index, pos + QPointF(800, 0), ROLE_OBJPOS);
auto paramIdx = currentGraph()->nodeParamIndex(res.targetIdx, PARAM_INPUT, "mtlid");
ModelSetData(paramIdx, mtlid, ROLE_PARAM_VALUE);
vec.clear();
vec << currentGraph();
resLst = search(mtlid_old, SEARCH_ARGS, SEARCH_MATCH_EXACTLY, vec);
for (const auto& res : resLst)
{
auto paramIdx = currentGraph()->nodeParamIndex(res.targetIdx, PARAM_INPUT, "mtlid");
ModelSetData(paramIdx, mtlid, ROLE_PARAM_VALUE);
}
}
}
QModelIndex subgIdx = this->index(subgName);
Expand Down
Loading