From 1f839be310132c6fd07c098960dc9d6bf585fb2d Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sun, 29 Dec 2019 11:48:55 -0800 Subject: [PATCH] Fixed invalid step being set in some cases. --- common/lc_timelinewidget.cpp | 21 +++++++++++---------- common/lc_timelinewidget.h | 1 + 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/common/lc_timelinewidget.cpp b/common/lc_timelinewidget.cpp index 7dd4b2e3..992a56cb 100644 --- a/common/lc_timelinewidget.cpp +++ b/common/lc_timelinewidget.cpp @@ -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(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 Selection; lcStep LastStep = 1; QList SelectedItems = selectedItems(); - QTreeWidgetItem* CurrentItem = currentItem(); - lcModel* Model = gMainWindow->GetActiveModel(); - - if (SelectedItems.isEmpty() && CurrentItem) - { - Model->SetCurrentStep(CurrentItem->data(0, Qt::UserRole).value()); - return; - } - for (QTreeWidgetItem* PieceItem : SelectedItems) { lcPiece* Piece = (lcPiece*)PieceItem->data(0, Qt::UserRole).value(); @@ -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(); 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); diff --git a/common/lc_timelinewidget.h b/common/lc_timelinewidget.h index 893fbced..13f96f86 100644 --- a/common/lc_timelinewidget.h +++ b/common/lc_timelinewidget.h @@ -17,6 +17,7 @@ public: void SetCurrentStep(); public slots: + void CurrentItemChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous); void ItemSelectionChanged(); void CustomMenuRequested(QPoint Pos);