Skip to content

Commit

Permalink
Mitigate crashes when user quickly rearranges pipeline views.
Browse files Browse the repository at this point in the history
There is some minimal flashing of the SVPipelineView at the start/end of the animation
but by disabling the SVPipelineView we stop the user from putting the PipelineModel
into a state that will cause crashes.

updates BlueQuartzSoftware#315

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Feb 10, 2019
1 parent 4f1ddcf commit 1b71e5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
14 changes: 11 additions & 3 deletions Source/SVWidgetsLib/Widgets/util/AddFilterCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ void AddFilterCommand::redo()
// -----------------------------------------------------------------------------
void AddFilterCommand::addFilter(const AbstractFilter::Pointer &filter, int insertionIndex)
{
m_PipelineView->setDisabled(true);
// Reset the filter's Removing property
filter->setRemoving(false);

Expand All @@ -229,6 +230,7 @@ void AddFilterCommand::addFilter(const AbstractFilter::Pointer &filter, int inse
{
QSize size = model->data(filterIndex, Qt::SizeHintRole).toSize();
model->setData(filterIndex, size.height(), PipelineModel::Roles::HeightRole);
m_PipelineView->setEnabled(true);
}
else
{
Expand All @@ -238,8 +240,10 @@ void AddFilterCommand::addFilter(const AbstractFilter::Pointer &filter, int inse
new PipelineItemSlideAnimation(model, QPersistentModelIndex(filterIndex), filterRect.width(), PipelineItemSlideAnimation::AnimationDirection::EnterRight);
model->setData(QPersistentModelIndex(filterIndex), PipelineItem::AnimationType::Add, PipelineModel::Roles::AnimationTypeRole);

QObject::connect(slideAnimation, &PipelineItemSlideAnimation::finished,
[=] { model->setData(QPersistentModelIndex(filterIndex), PipelineItem::AnimationType::None, PipelineModel::Roles::AnimationTypeRole); });
QObject::connect(slideAnimation, &PipelineItemSlideAnimation::finished, [=] {
model->setData(QPersistentModelIndex(filterIndex), PipelineItem::AnimationType::None, PipelineModel::Roles::AnimationTypeRole);
m_PipelineView->setEnabled(true);
});
slideAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
}
Expand All @@ -258,14 +262,18 @@ void AddFilterCommand::removeFilter(const QPersistentModelIndex& index)
return;
}

m_PipelineView->setDisabled(true);
disconnectFilterSignalsSlots(filter);

QRect filterRect = m_PipelineView->visualRect(index);

PipelineItemSlideAnimation* animation = new PipelineItemSlideAnimation(model, QPersistentModelIndex(index), filterRect.width(), PipelineItemSlideAnimation::AnimationDirection::ExitRight);
model->setData(QPersistentModelIndex(index), PipelineItem::AnimationType::Remove, PipelineModel::Roles::AnimationTypeRole);

QObject::connect(animation, &PipelineItemSlideAnimation::finished, [=]() mutable { model->removeRow(index.row()); });
QObject::connect(animation, &PipelineItemSlideAnimation::finished, [=]() mutable {
model->removeRow(index.row());
m_PipelineView->setEnabled(true);
});
animation->start(QAbstractAnimation::DeleteWhenStopped);
}

Expand Down
15 changes: 11 additions & 4 deletions Source/SVWidgetsLib/Widgets/util/RemoveFilterCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void RemoveFilterCommand::redo()
void RemoveFilterCommand::addFilter(const AbstractFilter::Pointer& filter, int insertionIndex)
{
filter->setRemoving(false);

m_PipelineView->setDisabled(true);
PipelineModel* model = m_PipelineView->getPipelineModel();

model->insertRow(insertionIndex);
Expand All @@ -217,8 +217,10 @@ void RemoveFilterCommand::addFilter(const AbstractFilter::Pointer& filter, int i
PipelineItemSlideAnimation* animation = new PipelineItemSlideAnimation(model, QPersistentModelIndex(filterIndex), filterRect.width(), PipelineItemSlideAnimation::AnimationDirection::EnterRight);
model->setData(QPersistentModelIndex(filterIndex), PipelineItem::AnimationType::Add, PipelineModel::Roles::AnimationTypeRole);

QObject::connect(animation, &PipelineItemSlideAnimation::finished,
[=] { model->setData(QPersistentModelIndex(filterIndex), PipelineItem::AnimationType::None, PipelineModel::Roles::AnimationTypeRole); });
QObject::connect(animation, &PipelineItemSlideAnimation::finished, [=] {
model->setData(QPersistentModelIndex(filterIndex), PipelineItem::AnimationType::None, PipelineModel::Roles::AnimationTypeRole);
m_PipelineView->setEnabled(true);
});
animation->start(QAbstractAnimation::DeleteWhenStopped);
}

Expand All @@ -233,6 +235,7 @@ void RemoveFilterCommand::removeFilter(const AbstractFilter::Pointer& filter)
{
return;
}
m_PipelineView->setDisabled(true);
filter->setRemoving(true);

PipelineModel* model = m_PipelineView->getPipelineModel();
Expand All @@ -248,13 +251,17 @@ void RemoveFilterCommand::removeFilter(const AbstractFilter::Pointer& filter)
if(!m_UseAnimationOnFirstRun && m_FirstRun)
{
model->removeRow(persistentIndex.row());
m_PipelineView->setEnabled(true);
}
else
{
PipelineItemSlideAnimation* animation = new PipelineItemSlideAnimation(model, persistentIndex, filterRect.width(), PipelineItemSlideAnimation::AnimationDirection::ExitRight);
model->setData(persistentIndex, PipelineItem::AnimationType::Remove, PipelineModel::Roles::AnimationTypeRole);

QObject::connect(animation, &PipelineItemSlideAnimation::finished, [=] { model->removeRow(persistentIndex.row()); });
QObject::connect(animation, &PipelineItemSlideAnimation::finished, [=] {
model->removeRow(persistentIndex.row());
m_PipelineView->setEnabled(true);
});
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
}
Expand Down

0 comments on commit 1b71e5d

Please sign in to comment.