Commit a673fb71 authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlDesigner: Fix crash when root item of .qml file not QDeclarativeItem based

Task-number: BAUHAUS-424
Reviewed-by: Lasse Holmstedt
parent 26e4672b
......@@ -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);
......
......@@ -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;
......
import Qt 4.6
ListModel {
id: myModel
ListElement {
content: "foo"
text: "bar"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment