forked from qt-creator/qt-creator
QmlDesginer.statesEditor: avoid crashes during reattaching model
This commit is contained in:
@@ -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,6 +177,7 @@ void StatesEditorView::modelAttached(Model *model)
|
||||
return;
|
||||
|
||||
m_modelStates.insert(0, baseState());
|
||||
m_attachedToModel = true;
|
||||
m_editorModel->insertState(0, baseState().name());
|
||||
|
||||
// Add custom states
|
||||
@@ -185,6 +189,7 @@ void StatesEditorView::modelAttached(Model *model)
|
||||
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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user