diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp index 9aae0fd1a150b7092985a47ce059ccdc0ccbf9c1..ba162be4fa0abeb5b3755d1686634dd389469fba 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 0000000000000000000000000000000000000000..8109493c4016de83e978c9c00d4ab823e5bbc5e0 --- /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 } +}