diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp index ba162be4fa0..0e03d48fc1d 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp @@ -37,7 +37,7 @@ #include enum { - debug = false + debug = true }; namespace QmlDesigner { @@ -49,7 +49,8 @@ namespace Internal { */ StatesEditorView::StatesEditorView(StatesEditorModel *editorModel, QObject *parent) : QmlModelView(parent), - m_editorModel(editorModel) + m_editorModel(editorModel), + m_attachedToModel(false) { Q_ASSERT(m_editorModel); } @@ -79,7 +80,9 @@ void StatesEditorView::setCurrentState(int index) if (m_modelStates.isEmpty()) return; - Q_ASSERT(index >= 0 && index < m_modelStates.count()); + Q_ASSERT(index < m_modelStates.count()); + if (index == -1) + return; if (m_modelStates.indexOf(currentState()) == index) return; @@ -174,17 +177,19 @@ void StatesEditorView::modelAttached(Model *model) return; m_modelStates.insert(0, baseState()); + m_attachedToModel = true; m_editorModel->insertState(0, baseState().name()); // Add custom states m_stateRootNode = QmlItemNode(rootModelNode()); if (!m_stateRootNode.isValid()) - return; + return; for (int i = 0; i < m_stateRootNode.states().allStates().size(); ++i) { QmlModelState state = QmlItemNode(rootModelNode()).states().allStates().at(i); insertModelState(i, state); } + } void StatesEditorView::modelAboutToBeDetached(Model *model) @@ -192,6 +197,8 @@ void StatesEditorView::modelAboutToBeDetached(Model *model) if (debug) qDebug() << __FUNCTION__; + m_attachedToModel = false; + clearModelStates(); QmlModelView::modelAboutToBeDetached(model); @@ -390,6 +397,9 @@ QPixmap StatesEditorView::renderState(int i) if (debug) qDebug() << __FUNCTION__ << i; + if (!m_attachedToModel) + return QPixmap(); + Q_ASSERT(i >= 0 && i < m_modelStates.size()); nodeInstanceView()->setBlockChangeSignal(true); QmlModelState oldState = currentState(); diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.h b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.h index 003035078f1..44bc5b6ac63 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.h +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.h @@ -53,6 +53,7 @@ public: QPixmap renderState(int i); QmlItemNode stateRootNode() { return m_stateRootNode; } + bool isAttachedToModel() const { return m_attachedToModel; } protected: // AbstractView @@ -95,6 +96,7 @@ private: QList m_updateTimerIdList; QmlModelState m_oldRewriterAmendState; + bool m_attachedToModel; }; } // namespace Internal diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp index b4af3252236..faeb4fd21b4 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp @@ -115,7 +115,8 @@ bool StatesEditorWidgetPrivate::validStateName(const QString &name) const void StatesEditorWidgetPrivate::currentStateChanged() { - statesEditorView->setCurrentState(currentIndex()); + if (statesEditorView->isAttachedToModel()) + statesEditorView->setCurrentState(currentIndex()); } void StatesEditorWidgetPrivate::addState()