1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #include "selectioncontext.h" 27 28 #include <qmlstate.h> 29 30 namespace QmlDesigner { 31 32 SelectionContext::SelectionContext() = default; 33 SelectionContext(AbstractView * view)34SelectionContext::SelectionContext(AbstractView *view) : 35 m_view(view) 36 { 37 } 38 setTargetNode(const ModelNode & modelNode)39void SelectionContext::setTargetNode(const ModelNode &modelNode) 40 { 41 m_targetNode = modelNode; 42 } 43 targetNode() const44ModelNode SelectionContext::targetNode() const 45 { 46 return m_targetNode; 47 } 48 rootNode() const49ModelNode SelectionContext::rootNode() const 50 { 51 return view()->rootModelNode(); 52 } 53 singleNodeIsSelected() const54bool SelectionContext::singleNodeIsSelected() const 55 { 56 return view()->hasSingleSelectedModelNode(); 57 } 58 isInBaseState() const59bool SelectionContext::isInBaseState() const 60 { 61 return view()->currentState().isBaseState(); 62 } 63 currentSingleSelectedNode() const64ModelNode SelectionContext::currentSingleSelectedNode() const 65 { 66 return view()->singleSelectedModelNode(); 67 } 68 firstSelectedModelNode() const69ModelNode SelectionContext::firstSelectedModelNode() const 70 { 71 return view()->firstSelectedModelNode(); 72 } 73 selectedModelNodes() const74QList<ModelNode> SelectionContext::selectedModelNodes() const 75 { 76 return view()->selectedModelNodes(); 77 } 78 hasSingleSelectedModelNode() const79bool SelectionContext::hasSingleSelectedModelNode() const 80 { 81 return view()->hasSingleSelectedModelNode() 82 && firstSelectedModelNode().isValid(); 83 } 84 view() const85AbstractView *SelectionContext::view() const 86 { 87 return m_view.data(); 88 } 89 setShowSelectionTools(bool show)90void SelectionContext::setShowSelectionTools(bool show) 91 { 92 m_showSelectionTools = show; 93 } 94 showSelectionTools() const95bool SelectionContext::showSelectionTools() const 96 { 97 return m_showSelectionTools; 98 } 99 setScenePosition(const QPointF & postition)100void SelectionContext::setScenePosition(const QPointF &postition) 101 { 102 m_scenePosition = postition; 103 } 104 scenePosition() const105QPointF SelectionContext::scenePosition() const 106 { 107 return m_scenePosition; 108 } 109 setToggled(bool toggled)110void SelectionContext::setToggled(bool toggled) 111 { 112 m_toggled = toggled; 113 } 114 toggled() const115bool SelectionContext::toggled() const 116 { 117 return m_toggled; 118 } 119 isValid() const120bool SelectionContext::isValid() const 121 { 122 return view() && view()->model(); 123 } 124 fastUpdate() const125bool SelectionContext::fastUpdate() const 126 { 127 return m_updateReason != UpdateMode::Normal; 128 } 129 setUpdateMode(UpdateMode mode)130void SelectionContext::setUpdateMode(UpdateMode mode) 131 { 132 m_updateReason = mode; 133 } 134 updateReason() const135SelectionContext::UpdateMode SelectionContext::updateReason() const 136 { 137 return m_updateReason; 138 } 139 140 } //QmlDesigner 141