From 31f7c875373ea6fbafd6b3c90182281ebc4232af Mon Sep 17 00:00:00 2001 From: Kai Koehne <kai.koehne@nokia.com> Date: Tue, 9 Mar 2010 12:17:52 +0100 Subject: [PATCH] QmlDesigner: Fix StatesView for switching subcomponents Reviewed-by: Thomas Hartmann --- .../stateseditor/stateseditorview.cpp | 13 ++++++++----- tests/manual/qml/testfiles/subcomponent.qml | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 tests/manual/qml/testfiles/subcomponent.qml diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp index 9aae0fd1a15..ba162be4fa0 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp @@ -75,12 +75,15 @@ void StatesEditorView::setCurrentState(int index) if (debug) qDebug() << __FUNCTION__ << index; + // happens to be the case for an invalid document / no base state + if (m_modelStates.isEmpty()) + return; + Q_ASSERT(index >= 0 && index < m_modelStates.count()); if (m_modelStates.indexOf(currentState()) == index) return; - // TODO QmlModelState state(m_modelStates.at(index)); Q_ASSERT(state.isValid()); QmlModelView::setCurrentState(state); @@ -164,20 +167,20 @@ void StatesEditorView::modelAttached(Model *model) Q_ASSERT(model); QmlModelView::modelAttached(model); - Q_ASSERT(m_editorModel->rowCount(QModelIndex()) == 0); - clearModelStates(); // Add base state + if (!baseState().isValid()) + return; + m_modelStates.insert(0, baseState()); m_editorModel->insertState(0, baseState().name()); - // find top level states + // Add custom states m_stateRootNode = QmlItemNode(rootModelNode()); if (!m_stateRootNode.isValid()) return; - // Add custom states for (int i = 0; i < m_stateRootNode.states().allStates().size(); ++i) { QmlModelState state = QmlItemNode(rootModelNode()).states().allStates().at(i); insertModelState(i, state); diff --git a/tests/manual/qml/testfiles/subcomponent.qml b/tests/manual/qml/testfiles/subcomponent.qml new file mode 100644 index 00000000000..8109493c401 --- /dev/null +++ b/tests/manual/qml/testfiles/subcomponent.qml @@ -0,0 +1,17 @@ +import Qt 4.6 + +Rectangle { + x: 640 + y: 480 + Component { + id: redSquare + Rectangle { + color: "red" + width: 100 + height: 100 + } + } + + Loader { sourceComponent: redSquare;} + Loader { sourceComponent: redSquare; x: 20 } +} -- GitLab