Fixed invalid step being set in some cases.

This commit is contained in:
Leonardo Zide 2019-12-29 11:48:55 -08:00
parent 352a448b63
commit 1f839be310
2 changed files with 12 additions and 10 deletions

View file

@ -19,6 +19,7 @@ lcTimelineWidget::lcTimelineWidget(QWidget* Parent)
invisibleRootItem()->setFlags(invisibleRootItem()->flags() & ~Qt::ItemIsDropEnabled);
connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), SLOT(CurrentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
connect(this, SIGNAL(itemSelectionChanged()), SLOT(ItemSelectionChanged()));
connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(CustomMenuRequested(QPoint)));
}
@ -108,7 +109,6 @@ void lcTimelineWidget::Update(bool Clear, bool UpdateItems)
for (unsigned int TopLevelItemIdx = topLevelItemCount(); TopLevelItemIdx < LastStep; TopLevelItemIdx++)
{
QTreeWidgetItem* StepItem = new QTreeWidgetItem(this, QStringList(tr("Step %1").arg(TopLevelItemIdx + 1)));
StepItem->setData(0, Qt::UserRole, qVariantFromValue<int>(TopLevelItemIdx + 1));
StepItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
addTopLevelItem(StepItem);
StepItem->setExpanded(true);
@ -350,21 +350,20 @@ void lcTimelineWidget::SetCurrentStep()
gMainWindow->GetActiveModel()->SetCurrentStep(Step + 1);
}
void lcTimelineWidget::CurrentItemChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous)
{
Q_UNUSED(Current);
Q_UNUSED(Previous);
SetCurrentStep();
}
void lcTimelineWidget::ItemSelectionChanged()
{
lcArray<lcObject*> Selection;
lcStep LastStep = 1;
QList<QTreeWidgetItem*> SelectedItems = selectedItems();
QTreeWidgetItem* CurrentItem = currentItem();
lcModel* Model = gMainWindow->GetActiveModel();
if (SelectedItems.isEmpty() && CurrentItem)
{
Model->SetCurrentStep(CurrentItem->data(0, Qt::UserRole).value<int>());
return;
}
for (QTreeWidgetItem* PieceItem : SelectedItems)
{
lcPiece* Piece = (lcPiece*)PieceItem->data(0, Qt::UserRole).value<uintptr_t>();
@ -376,11 +375,13 @@ void lcTimelineWidget::ItemSelectionChanged()
}
lcPiece* CurrentPiece = nullptr;
QTreeWidgetItem* CurrentItem = currentItem();
if (CurrentItem && CurrentItem->isSelected())
CurrentPiece = (lcPiece*)CurrentItem->data(0, Qt::UserRole).value<uintptr_t>();
bool Blocked = blockSignals(true);
mIgnoreUpdates = true;
lcModel* Model = gMainWindow->GetActiveModel();
if (LastStep > Model->GetCurrentStep())
Model->SetCurrentStep(LastStep);
Model->SetSelectionAndFocus(Selection, CurrentPiece, LC_PIECE_SECTION_POSITION, false);

View file

@ -17,6 +17,7 @@ public:
void SetCurrentStep();
public slots:
void CurrentItemChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous);
void ItemSelectionChanged();
void CustomMenuRequested(QPoint Pos);