QmlDesginer.statesEditor: avoid crashes during reattaching model

This commit is contained in:
Thomas Hartmann
2010-03-22 11:32:21 +01:00
parent e1e8e9fdf3
commit 6579d1d8c3
3 changed files with 18 additions and 5 deletions

View File

@@ -37,7 +37,7 @@
#include <math.h>
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();

View File

@@ -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<int> m_updateTimerIdList;
QmlModelState m_oldRewriterAmendState;
bool m_attachedToModel;
};
} // namespace Internal

View File

@@ -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()