diff options
author | Mahmoud Badri <mahmoud.badri@qt.io> | 2018-05-15 12:45:20 +0300 |
---|---|---|
committer | Mahmoud Badri <mahmoud.badri@qt.io> | 2018-05-15 11:09:37 +0000 |
commit | 35b12a4edfda4d40d9215de90d2a84945fe01ef0 (patch) | |
tree | 918eb018164054420a781b81ddff21c45d72724b | |
parent | 00c5202d656e1fd8e1b23b63b2d2b186c76e95d2 (diff) |
Fix a crash when DnD from basic objects to timeline
This fixes the crash, but there is still issues with the convertIndex()
method that should be improved in other tasks.
Task-number: QT3DS-1637
Change-Id: I7a74608a19a4f881604cbaf9008aa4c1b45220a1
Reviewed-by: Kaj Grönholm <kaj.gronholm@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
4 files changed, 23 insertions, 29 deletions
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp index 86d31afe..1ec452ae 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp @@ -269,22 +269,6 @@ void TimelineGraphicsScene::commitMoveRows() // updating the UI happens in TimelineWidget.onChildAdded() } -// TODO: not used, remove -bool TimelineGraphicsScene::lastRowInAParent(RowTree *rowAtIndex, int index) -{ - int depth = nextRowDepth(index); - - return depth == -1 || depth < rowAtIndex->depth(); -} - -// not used except in lastRowInAParent() -int TimelineGraphicsScene::nextRowDepth(int index) { - if (index < m_layoutTree->count() - 1) - index ++; - - return static_cast<RowTree *>(m_layoutTree->itemAt(index)->graphicsItem())->depth(); -} - void TimelineGraphicsScene::updateTreeWidth(double treeWidth) { if (m_treeWidth != treeWidth) { @@ -728,7 +712,7 @@ void TimelineGraphicsScene::updateHoverStatus(const QPointF &scenePos) // Used at least for skipping PlayHead and RowTreeLabelItem QGraphicsItem *TimelineGraphicsScene::getItemBelowType(TimelineItem::ItemType type, QGraphicsItem *item, - const QPointF &scenePos) + const QPointF &scenePos) const { if (item->type() == type) { const QList<QGraphicsItem *> hoverItems = items(scenePos); diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h index 10dd8010..4518118b 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h @@ -98,11 +98,9 @@ private: void commitMoveRows(); void updateHoverStatus(const QPointF &scenePos); void snap(double &value, bool snapToPlayHead = true); - int nextRowDepth(int index); - bool lastRowInAParent(RowTree *rowAtIndex, int index); QGraphicsItem *getItemBelowType(TimelineItem::ItemType type, QGraphicsItem *item, - const QPointF &scenePos); + const QPointF &scenePos) const; void handleInsertKeyframe(); void handleDeleteChannelKeyframes(); void handleSetTimeBarTime(); diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp index ff3a9fc1..d00f4bec 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp @@ -450,15 +450,21 @@ int RowTree::indexInLayout() const void RowTree::addChild(RowTree *child) { - int index = 0; - if (child->isProperty() && !m_childProps.empty()) - index = m_childProps.last()->index() + 1; - else if (!child->isProperty() && !m_childRows.empty()) - index = m_childRows.last()->index() + 1; - + int index = getLastChildIndex(child->isProperty()) + 1; addChildAt(child, index); } +int RowTree::getLastChildIndex(bool isProperty) const +{ + int index = -1; + if (isProperty && !m_childProps.empty()) + index = m_childProps.last()->index(); + else if (!isProperty && !m_childRows.empty()) + index = m_childRows.last()->index(); + + return index; +} + int RowTree::getCountDecendentsRecursive() const { int num = m_childProps.count(); @@ -476,6 +482,11 @@ void RowTree::addChildAt(RowTree *child, int index) // Mahmoud_TODO: improvement: implement moving the child (instead of remove/add) if it is added // under the same parent. + int maxIndex = getLastChildIndex(child->isProperty()) + 1; + + if (index > maxIndex) + index = maxIndex; + if (child->parentRow() == this && index == child->m_index) // same place return; @@ -935,7 +946,7 @@ bool RowTree::hasActionButtons() const && m_rowType != OBJTYPE_IMAGE); } -bool RowTree::hasComponentAncestor() +bool RowTree::hasComponentAncestor() const { RowTree *parentRow = m_parentRow; while (parentRow) { diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.h index bf636b4d..9100f892 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.h @@ -134,10 +134,11 @@ private: void updateLabelPosition(); void updateIndices(bool isInsertion, int startIndex, int startIndexInLayout, bool isProperty); bool hasActionButtons() const; - bool hasComponentAncestor(); + bool hasComponentAncestor() const; int removeChildFromLayout(RowTree *child) const; int getCountDecendentsRecursive() const; int addChildToLayout(RowTree *child, int indexInLayout); + int getLastChildIndex(bool isProperty) const; RowTree *m_parentRow = nullptr; RowTimeline *m_rowTimeline = nullptr; @@ -147,12 +148,12 @@ private: bool m_shy = false; bool m_visible = true; bool m_locked = false; - ExpandState m_expandState = ExpandState::HiddenCollapsed; bool m_moveSource = false; bool m_moveTarget = false; bool m_isProperty = false; bool m_isPropertyExpanded = false; bool m_master = false; + ExpandState m_expandState = ExpandState::HiddenCollapsed; TimelineGraphicsScene *m_scene; RowTreeLabelItem m_labelItem; EStudioObjectType m_rowType = OBJTYPE_UNKNOWN; |