From 0e802b71a66b66a114ae4809464cb97db01a02f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= Date: Sun, 25 Aug 2024 02:02:43 +0200 Subject: [PATCH] Graph: use selected properties from timeline Initial implementation for #177 --- src/app/GUI/graphboxeslist.cpp | 36 ++++++++++++++++------------------ src/app/GUI/keysview.cpp | 15 +++++++++++--- src/app/GUI/keysview.h | 5 ++--- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/app/GUI/graphboxeslist.cpp b/src/app/GUI/graphboxeslist.cpp index d57a53168..1a9b9dda4 100644 --- a/src/app/GUI/graphboxeslist.cpp +++ b/src/app/GUI/graphboxeslist.cpp @@ -556,20 +556,15 @@ void KeysView::graphResetValueScaleAndMinShown() { graphUpdateDimensions(); } -void KeysView::graphSetOnlySelectedVisible(const bool selectedOnly) { - if(graph_mOnlySelectedVisible == selectedOnly) return; - graph_mOnlySelectedVisible = selectedOnly; - graphUpdateVisbile(); -} - -bool KeysView::graphValidateVisible(GraphAnimator* const animator) { - if(graph_mOnlySelectedVisible){ - return animator->prp_isParentBoxSelected(); - } - return true; +bool KeysView::graphValidateVisible(GraphAnimator* const animator) +{ + if (animator->prp_isSelected() && + animator->prp_isParentBoxContained()) { return true; } + return false; } void KeysView::graphAddToViewedAnimatorList(GraphAnimator * const animator) { + if (mGraphAnimators.contains(animator)) { return; } auto& connContext = mGraphAnimators.addObj(animator); connContext << connect(animator, &QObject::destroyed, this, [this, animator]() { @@ -577,16 +572,18 @@ void KeysView::graphAddToViewedAnimatorList(GraphAnimator * const animator) { }); } -void KeysView::graphUpdateVisbile() { - mGraphAnimators.clear(); - if(mCurrentScene) { +void KeysView::graphUpdateVisible() +{ + qDebug() << "graphUpdateVisible"; + //mGraphAnimators.clear(); + if (mCurrentScene) { const int id = mBoxesListWidget->getId(); const auto all = mCurrentScene->getSelectedForGraph(id); - if(all) { - for(const auto anim : *all) { - if(graphValidateVisible(anim)) { - graphAddToViewedAnimatorList(anim); - } + if (all) { + qDebug() << "selected for graph" << all->count(); + for (const auto anim : *all) { + if (graphValidateVisible(anim)) { graphAddToViewedAnimatorList(anim); } + else { graphRemoveViewedAnimator(anim); } } } } @@ -608,6 +605,7 @@ void KeysView::graphAddViewedAnimator(GraphAnimator * const animator) { } void KeysView::graphRemoveViewedAnimator(GraphAnimator * const animator) { + if (!mGraphAnimators.contains(animator)) { return; } if(!mCurrentScene) return Q_ASSERT(false); const int id = mBoxesListWidget->getId(); mCurrentScene->removeSelectedForGraph(id, animator); diff --git a/src/app/GUI/keysview.cpp b/src/app/GUI/keysview.cpp index 9077e1bdc..1867fcb80 100644 --- a/src/app/GUI/keysview.cpp +++ b/src/app/GUI/keysview.cpp @@ -91,18 +91,27 @@ void KeysView::setCurrentScene(Canvas * const scene) { if (mCurrentScene) { disconnect(mCurrentScene.data(), &Canvas::objectSelectionChanged, - this, &KeysView::graphUpdateVisbile); + this, &KeysView::graphUpdateVisible); + disconnect(mCurrentScene.data(), &Canvas::requestUpdate, + this, &KeysView::sceneRequestedUpdate); disconnect(mCurrentScene.data(), &Canvas::requestEasingAction, this, &KeysView::graphEasingAction); } mCurrentScene = scene; if (mCurrentScene) { connect(mCurrentScene.data(), &Canvas::objectSelectionChanged, - this, &KeysView::graphUpdateVisbile); + this, &KeysView::graphUpdateVisible); + connect(mCurrentScene.data(), &Canvas::requestUpdate, + this, &KeysView::sceneRequestedUpdate); connect(mCurrentScene.data(), &Canvas::requestEasingAction, this, &KeysView::graphEasingAction); } - graphUpdateVisbile(); + graphUpdateVisible(); +} + +void KeysView::sceneRequestedUpdate() +{ + graphUpdateVisible(); } void KeysView::setGraphViewed(const bool bT) { diff --git a/src/app/GUI/keysview.h b/src/app/GUI/keysview.h index 1472189d4..6c2cd2c5c 100644 --- a/src/app/GUI/keysview.h +++ b/src/app/GUI/keysview.h @@ -67,6 +67,7 @@ class KeysView : public QWidget, public KeyFocusTarget { QWidget *parent = nullptr); void setCurrentScene(Canvas* const scene); + void sceneRequestedUpdate(); void setGraphViewed(const bool bT); @@ -162,8 +163,7 @@ class KeysView : public QWidget, public KeyFocusTarget { int graphGetAnimatorId(GraphAnimator * const anim); QrealPoint *graphGetPointAtPos(const QPointF &pressPos) const; bool graphValidateVisible(GraphAnimator * const animator); - void graphUpdateVisbile(); - void graphSetOnlySelectedVisible(const bool selectedOnly); + void graphUpdateVisible(); bool graphIsSelected(GraphAnimator * const anim); void graphEasingAction(const QString &easing); void graphEasingApply(QrealAnimator *anim, @@ -269,7 +269,6 @@ class KeysView : public QWidget, public KeyFocusTarget { // graph - bool graph_mOnlySelectedVisible = false; bool graph_mValueLinesVisible = true; qreal mPixelsPerValUnit = 0; qreal mMinShownVal = 0;