Move and rename functions
This commit is contained in:
parent
405c020125
commit
042eb067a0
|
|
@ -11,7 +11,7 @@
|
|||
BufferField::BufferField(ShaderGraph& graph) :
|
||||
ShaderNode(graph)
|
||||
{
|
||||
m_onBufferListUpdateSlot.Connect(GetGraph().OnBufferListUpdate, [&](ShaderGraph*) { UpdateCurrentBufferIndex(); });
|
||||
m_onBufferListUpdateSlot.Connect(GetGraph().OnBufferListUpdate, [&](ShaderGraph*) { UpdateBufferIndex(); });
|
||||
m_onBufferUpdateSlot.Connect(GetGraph().OnBufferUpdate, [&](ShaderGraph*, std::size_t bufferIndex)
|
||||
{
|
||||
if (m_currentBufferIndex == bufferIndex)
|
||||
|
|
@ -57,7 +57,48 @@ bool BufferField::ComputePreview(QPixmap& pixmap)
|
|||
return true;*/
|
||||
}
|
||||
|
||||
void BufferField::UpdateCurrentBufferIndex()
|
||||
void BufferField::PopulateField(QComboBox* fieldList, std::size_t structIndex, const std::string& prefix)
|
||||
{
|
||||
const auto& s = GetGraph().GetStruct(structIndex);
|
||||
for (const auto& member : s.members)
|
||||
{
|
||||
std::visit([&](auto&& arg)
|
||||
{
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, PrimitiveType>)
|
||||
fieldList->addItem(QString::fromStdString(prefix + member.name));
|
||||
else if constexpr (std::is_same_v<T, std::size_t>)
|
||||
PopulateField(fieldList, arg, prefix + member.name + ".");
|
||||
else
|
||||
static_assert(AlwaysFalse<T>::value, "non-exhaustive visitor");
|
||||
},
|
||||
member.type);
|
||||
}
|
||||
}
|
||||
|
||||
const ShaderGraph::StructMemberEntry& BufferField::RetrieveNestedMember() const
|
||||
{
|
||||
const ShaderGraph& graph = GetGraph();
|
||||
auto& buffer = graph.GetBuffer(*m_currentBufferIndex);
|
||||
|
||||
assert(m_currentFieldIndex);
|
||||
const CurrentField& currentField = *m_currentFieldIndex;
|
||||
|
||||
const ShaderGraph::StructEntry* structEntry = &graph.GetStruct(buffer.structIndex);
|
||||
for (std::size_t nestedIndex : currentField.nestedFields)
|
||||
{
|
||||
assert(nestedIndex < structEntry->members.size());
|
||||
const auto& memberEntry = structEntry->members[nestedIndex];
|
||||
assert(std::holds_alternative<std::size_t>(memberEntry.type));
|
||||
|
||||
std::size_t nestedStructIndex = std::get<std::size_t>(memberEntry.type);
|
||||
structEntry = &graph.GetStruct(nestedStructIndex);
|
||||
}
|
||||
|
||||
return structEntry->members[currentField.finalFieldIndex];
|
||||
}
|
||||
|
||||
void BufferField::UpdateBufferIndex()
|
||||
{
|
||||
Nz::CallOnExit resetIfNotFound([&]
|
||||
{
|
||||
|
|
@ -84,7 +125,79 @@ void BufferField::UpdateCurrentBufferIndex()
|
|||
}
|
||||
}
|
||||
|
||||
void BufferField::UpdateCurrentFieldIndex()
|
||||
void BufferField::UpdateBufferText()
|
||||
{
|
||||
if (m_currentBufferIndex)
|
||||
{
|
||||
auto& buffer = GetGraph().GetBuffer(*m_currentBufferIndex);
|
||||
m_currentBufferText = buffer.name;
|
||||
}
|
||||
else
|
||||
m_currentBufferText.clear();
|
||||
}
|
||||
|
||||
void BufferField::BuildNodeEdition(QFormLayout* layout)
|
||||
{
|
||||
ShaderNode::BuildNodeEdition(layout);
|
||||
|
||||
QComboBox* fieldSelection = new QComboBox;
|
||||
connect(fieldSelection, qOverload<int>(&QComboBox::currentIndexChanged), [=](int index)
|
||||
{
|
||||
if (index >= 0)
|
||||
m_currentFieldText = fieldSelection->itemText(index).toStdString();
|
||||
else
|
||||
m_currentFieldText.clear();
|
||||
|
||||
UpdateFieldIndex();
|
||||
UpdatePreview();
|
||||
|
||||
Q_EMIT dataUpdated(0);
|
||||
});
|
||||
|
||||
QComboBox* bufferSelection = new QComboBox;
|
||||
for (const auto& inputEntry : GetGraph().GetBuffers())
|
||||
bufferSelection->addItem(QString::fromStdString(inputEntry.name));
|
||||
|
||||
connect(bufferSelection, qOverload<int>(&QComboBox::currentIndexChanged), [=](int index)
|
||||
{
|
||||
fieldSelection->clear();
|
||||
fieldSelection->setCurrentIndex(-1);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
m_currentBufferIndex = static_cast<std::size_t>(index);
|
||||
|
||||
const ShaderGraph& graph = GetGraph();
|
||||
const auto& buffer = graph.GetBuffer(*m_currentBufferIndex);
|
||||
PopulateField(fieldSelection, buffer.structIndex);
|
||||
}
|
||||
else
|
||||
m_currentBufferIndex.reset();
|
||||
|
||||
UpdateBufferText();
|
||||
});
|
||||
|
||||
if (m_currentBufferIndex)
|
||||
{
|
||||
int index = int(*m_currentBufferIndex);
|
||||
QString currentFieldText = QString::fromStdString(m_currentFieldText);
|
||||
|
||||
bufferSelection->setCurrentIndex(-1);
|
||||
bufferSelection->setCurrentIndex(index);
|
||||
|
||||
fieldSelection->setCurrentText(currentFieldText);
|
||||
}
|
||||
else
|
||||
{
|
||||
bufferSelection->setCurrentIndex(-1);
|
||||
fieldSelection->setCurrentIndex(-1);
|
||||
}
|
||||
|
||||
layout->addRow(tr("Buffer"), bufferSelection);
|
||||
layout->addRow(tr("Field"), fieldSelection);
|
||||
}
|
||||
|
||||
void BufferField::UpdateFieldIndex()
|
||||
{
|
||||
Nz::CallOnExit resetIfNotFound([&]
|
||||
{
|
||||
|
|
@ -153,119 +266,6 @@ void BufferField::UpdateCurrentFieldIndex()
|
|||
resetIfNotFound.Reset();
|
||||
}
|
||||
|
||||
void BufferField::PopulateField(QComboBox* fieldList, std::size_t structIndex, const std::string& prefix)
|
||||
{
|
||||
const auto& s = GetGraph().GetStruct(structIndex);
|
||||
for (const auto& member : s.members)
|
||||
{
|
||||
std::visit([&](auto&& arg)
|
||||
{
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, PrimitiveType>)
|
||||
fieldList->addItem(QString::fromStdString(prefix + member.name));
|
||||
else if constexpr (std::is_same_v<T, std::size_t>)
|
||||
PopulateField(fieldList, arg, prefix + member.name + ".");
|
||||
else
|
||||
static_assert(AlwaysFalse<T>::value, "non-exhaustive visitor");
|
||||
},
|
||||
member.type);
|
||||
}
|
||||
}
|
||||
|
||||
const ShaderGraph::StructMemberEntry& BufferField::RetrieveNestedMember() const
|
||||
{
|
||||
const ShaderGraph& graph = GetGraph();
|
||||
auto& buffer = graph.GetBuffer(*m_currentBufferIndex);
|
||||
|
||||
assert(m_currentFieldIndex);
|
||||
const CurrentField& currentField = *m_currentFieldIndex;
|
||||
|
||||
const ShaderGraph::StructEntry* structEntry = &graph.GetStruct(buffer.structIndex);
|
||||
for (std::size_t nestedIndex : currentField.nestedFields)
|
||||
{
|
||||
assert(nestedIndex < structEntry->members.size());
|
||||
const auto& memberEntry = structEntry->members[nestedIndex];
|
||||
assert(std::holds_alternative<std::size_t>(memberEntry.type));
|
||||
|
||||
std::size_t nestedStructIndex = std::get<std::size_t>(memberEntry.type);
|
||||
structEntry = &graph.GetStruct(nestedStructIndex);
|
||||
}
|
||||
|
||||
return structEntry->members[currentField.finalFieldIndex];
|
||||
}
|
||||
|
||||
void BufferField::UpdateBufferText()
|
||||
{
|
||||
if (m_currentBufferIndex)
|
||||
{
|
||||
auto& buffer = GetGraph().GetBuffer(*m_currentBufferIndex);
|
||||
m_currentBufferText = buffer.name;
|
||||
}
|
||||
else
|
||||
m_currentBufferText.clear();
|
||||
}
|
||||
|
||||
void BufferField::BuildNodeEdition(QFormLayout* layout)
|
||||
{
|
||||
ShaderNode::BuildNodeEdition(layout);
|
||||
|
||||
QComboBox* fieldSelection = new QComboBox;
|
||||
connect(fieldSelection, qOverload<int>(&QComboBox::currentIndexChanged), [=](int index)
|
||||
{
|
||||
if (index >= 0)
|
||||
m_currentFieldText = fieldSelection->itemText(index).toStdString();
|
||||
else
|
||||
m_currentFieldText.clear();
|
||||
|
||||
UpdateCurrentFieldIndex();
|
||||
UpdatePreview();
|
||||
|
||||
Q_EMIT dataUpdated(0);
|
||||
});
|
||||
|
||||
QComboBox* bufferSelection = new QComboBox;
|
||||
for (const auto& inputEntry : GetGraph().GetBuffers())
|
||||
bufferSelection->addItem(QString::fromStdString(inputEntry.name));
|
||||
|
||||
connect(bufferSelection, qOverload<int>(&QComboBox::currentIndexChanged), [=](int index)
|
||||
{
|
||||
fieldSelection->clear();
|
||||
fieldSelection->setCurrentIndex(-1);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
m_currentBufferIndex = static_cast<std::size_t>(index);
|
||||
|
||||
const ShaderGraph& graph = GetGraph();
|
||||
const auto& buffer = graph.GetBuffer(*m_currentBufferIndex);
|
||||
PopulateField(fieldSelection, buffer.structIndex);
|
||||
}
|
||||
else
|
||||
m_currentBufferIndex.reset();
|
||||
|
||||
UpdateBufferText();
|
||||
});
|
||||
|
||||
if (m_currentBufferIndex)
|
||||
{
|
||||
int index = int(*m_currentBufferIndex);
|
||||
QString currentFieldText = QString::fromStdString(m_currentFieldText);
|
||||
|
||||
bufferSelection->setCurrentIndex(-1);
|
||||
bufferSelection->setCurrentIndex(index);
|
||||
|
||||
fieldSelection->setCurrentText(currentFieldText);
|
||||
}
|
||||
else
|
||||
{
|
||||
bufferSelection->setCurrentIndex(-1);
|
||||
fieldSelection->setCurrentIndex(-1);
|
||||
}
|
||||
|
||||
layout->addRow(tr("Buffer"), bufferSelection);
|
||||
layout->addRow(tr("Field"), fieldSelection);
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::ExpressionPtr BufferField::GetExpression(Nz::ShaderNodes::ExpressionPtr* /*expressions*/, std::size_t count) const
|
||||
{
|
||||
assert(count == 0);
|
||||
|
|
@ -394,7 +394,7 @@ void BufferField::restore(const QJsonObject& data)
|
|||
{
|
||||
m_currentBufferText = data["buffer"].toString().toStdString();
|
||||
m_currentFieldText = data["field"].toString().toStdString();
|
||||
UpdateCurrentBufferIndex();
|
||||
UpdateBufferIndex();
|
||||
|
||||
ShaderNode::restore(data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ class BufferField : public ShaderNode
|
|||
|
||||
private:
|
||||
bool ComputePreview(QPixmap& pixmap) override;
|
||||
void UpdateCurrentBufferIndex();
|
||||
void UpdateCurrentFieldIndex();
|
||||
void PopulateField(QComboBox* fieldList, std::size_t structIndex, const std::string& prefix = "");
|
||||
const ShaderGraph::StructMemberEntry& RetrieveNestedMember() const;
|
||||
void UpdateBufferIndex();
|
||||
void UpdateBufferText();
|
||||
void UpdateFieldIndex();
|
||||
|
||||
void restore(const QJsonObject& data) override;
|
||||
QJsonObject save() const override;
|
||||
|
|
|
|||
Loading…
Reference in New Issue