diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp index 5835c0cc6f97158bf2560da8171a79779e91b9bd..bc83beae3b2413cc85080a6a167baf70dcf6ac74 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp @@ -59,7 +59,7 @@ void StatesEditorView::setCurrentStateSilent(int index) if (debug) qDebug() << __FUNCTION__ << index; - Q_ASSERT(index >= 0 && index <= m_modelStates.count()); + Q_ASSERT(index >= 0 && index < m_modelStates.count()); // TODO QmlModelState state(m_modelStates.at(index)); @@ -75,8 +75,7 @@ void StatesEditorView::setCurrentState(int index) if (debug) qDebug() << __FUNCTION__ << index; - if (!(index >= 0 && index <= m_modelStates.count())) - Q_ASSERT(index >= 0 && index <= m_modelStates.count()); + Q_ASSERT(index >= 0 && index < m_modelStates.count()); if (m_modelStates.indexOf(currentState()) == index) return; @@ -167,17 +166,17 @@ void StatesEditorView::modelAttached(Model *model) QmlModelView::modelAttached(model); Q_ASSERT(m_editorModel->rowCount(QModelIndex()) == 0); - // find top level states - m_stateRootNode = QmlItemNode(rootModelNode()); - if (!m_stateRootNode.isValid()) - return; - clearModelStates(); // Add base state m_modelStates.insert(0, baseState()); m_editorModel->insertState(0, baseState().name()); + // find top level 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); diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp index 87b784596297bd17c1cd06625b02330e434556a7..0f82ff95fda5bc94e0148b690753fd33e2da4685 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp @@ -120,7 +120,11 @@ void StatesEditorWidgetPrivate::currentStateChanged() void StatesEditorWidgetPrivate::addState() { - QStringList modelStateNames = statesEditorView->stateRootNode().states().names(); + // can happen when root node is e.g. a ListModel + if (!statesEditorView->stateRootNode().isValid()) + return; + + QStringList modelStateNames = statesEditorView->stateRootNode().states().names(); QString newStateName; int index = 1; diff --git a/tests/manual/qml/testfiles/listmodel.qml b/tests/manual/qml/testfiles/listmodel.qml new file mode 100644 index 0000000000000000000000000000000000000000..eaf6c60396bc7ed4d66ba46d302f0b3dd65fe303 --- /dev/null +++ b/tests/manual/qml/testfiles/listmodel.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +ListModel { + id: myModel + ListElement { + content: "foo" + text: "bar" + } + +}