Fix effect param refresh issue and crash on undo add effect.

Fixes #633
parent 463060ab
......@@ -235,26 +235,22 @@ void AssetParameterView::refresh(const QModelIndex &topLeft, const QModelIndex &
// We are expecting indexes that are children of the root index, which is "invalid"
Q_ASSERT(!topLeft.parent().isValid());
// We make sure the range is valid
if (m_mainKeyframeWidget) {
m_mainKeyframeWidget->slotRefresh();
auto type = m_model->data(m_model->index(topLeft.row(), 0), AssetParameterModel::TypeRole).value<ParamType>();
if (type == ParamType::ColorWheel) {
// Some special widgets, like colorwheel handle multiple params so we can have cases where param index row is greater than the number of widgets.
// Should be better managed
m_widgets[0]->slotRefresh();
return;
}
size_t max;
if (!bottomRight.isValid()) {
max = m_widgets.size() - 1;
} else {
auto type = m_model->data(m_model->index(topLeft.row(), 0), AssetParameterModel::TypeRole).value<ParamType>();
if (type == ParamType::ColorWheel) {
// Some special widgets, like colorwheel handle multiple params so we can have cases where param index row is greater than the number of widgets.
// Should be better managed
m_widgets[0]->slotRefresh();
return;
}
size_t max;
if (!bottomRight.isValid()) {
max = m_widgets.size() - 1;
} else {
max = (size_t)bottomRight.row();
}
Q_ASSERT(max < m_widgets.size());
for (size_t i = (size_t)topLeft.row(); i <= max; ++i) {
m_widgets[i]->slotRefresh();
}
max = (size_t)bottomRight.row();
}
Q_ASSERT(max < m_widgets.size());
for (size_t i = (size_t)topLeft.row(); i <= max; ++i) {
m_widgets[i]->slotRefresh();
}
}
......
......@@ -41,7 +41,8 @@ BoolParamWidget::BoolParamWidget(std::shared_ptr<AssetParameterModel> model, QMo
slotRefresh();
// emit the signal of the base class when appropriate
connect(this->m_checkBox, &QCheckBox::stateChanged, [this](int) { emit valueChanged(m_index, QString::number(m_checkBox->isChecked()), true); });
connect(this->m_checkBox, &QCheckBox::stateChanged, [this](int) {
emit valueChanged(m_index, QString::number(m_checkBox->isChecked()), true); });
}
void BoolParamWidget::slotShowComment(bool show)
......@@ -53,6 +54,7 @@ void BoolParamWidget::slotShowComment(bool show)
void BoolParamWidget::slotRefresh()
{
QSignalBlocker bk(m_checkBox);
bool checked = m_model->data(m_index, AssetParameterModel::ValueRole).toInt();
m_checkBox->setChecked(checked);
}
......
......@@ -134,6 +134,7 @@ void ColorEditWidget::slotShowComment(bool) {}
void ColorEditWidget::slotRefresh()
{
QSignalBlocker bk(this);
QString color = m_model->data(m_index, AssetParameterModel::ValueRole).toString();
m_button->setColor(stringToColor(color));
}
......
......@@ -57,6 +57,7 @@ DoubleParamWidget::DoubleParamWidget(std::shared_ptr<AssetParameterModel> model,
void DoubleParamWidget::slotRefresh()
{
QSignalBlocker bk(m_doubleWidget);
QLocale locale;
locale.setNumberOptions(QLocale::OmitGroupSeparator);
double value = locale.toDouble(m_model->data(m_index, AssetParameterModel::ValueRole).toString());
......
......@@ -48,6 +48,7 @@ void FontParamWidget::slotShowComment(bool show)
void FontParamWidget::slotRefresh()
{
QSignalBlocker bk(fontfamilywidget);
const QString family = m_model->data(m_index, AssetParameterModel::ValueRole).toString();
fontfamilywidget->setCurrentFont(QFont(family));
}
......
......@@ -91,6 +91,7 @@ void PositionEditWidget::slotUpdatePosition()
void PositionEditWidget::slotRefresh()
{
const QSignalBlocker bk(m_slider);
int min = m_model->data(m_index, AssetParameterModel::ParentInRole).toInt();
int max = min + m_model->data(m_index, AssetParameterModel::ParentDurationRole).toInt();
const QSignalBlocker blocker(m_slider);
......
......@@ -59,5 +59,6 @@ void SwitchParamWidget::slotShowComment(bool show)
void SwitchParamWidget::slotRefresh()
{
const QSignalBlocker bk(m_checkBox);
m_checkBox->setChecked(m_model->data(m_index, AssetParameterModel::ValueRole) == m_model->data(m_index, AssetParameterModel::MaxRole));
}
......@@ -66,5 +66,6 @@ void UrlParamWidget::slotShowComment(bool show)
void UrlParamWidget::slotRefresh()
{
const QSignalBlocker bk(urlwidget);
urlwidget->setUrl(QUrl::fromLocalFile(m_model->data(m_index, AssetParameterModel::ValueRole).toString()));
}
......@@ -436,12 +436,14 @@ void EffectStackView::doActivateEffect(int row, QModelIndex activeIx, bool force
// Effect is already active
return;
}
if (row != currentActive && currentActive > -1) {
if (row != currentActive && currentActive > -1 && currentActive < m_model->rowCount()) {
auto item = m_model->getEffectStackRow(currentActive);
QModelIndex ix = m_model->getIndexFromItem(item);
CollapsibleEffectView *w = static_cast<CollapsibleEffectView *>(m_effectsTree->indexWidget(ix));
if (w) {
w->slotActivateEffect(false);
if (item) {
QModelIndex ix = m_model->getIndexFromItem(item);
CollapsibleEffectView *w = static_cast<CollapsibleEffectView *>(m_effectsTree->indexWidget(ix));
if (w) {
w->slotActivateEffect(false);
}
}
}
m_model->setActiveEffect(row);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment