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

QmlDesigner: Fix all states only showing base state in States Editor

Let the State Editor also use the new activateState method from
QmlModelView (stateChanged by default does now nothing). This allowed
us to get rid of the setCurrentStateBack method. Also fix deletion of
states - the "decision" which state should be the new one is now done
in StatesEditorView.

Reviewed-by: Thomas Hartmann
Reviewed-by: Christiaan Janssen
parent 541e8a58
......@@ -62,7 +62,7 @@ void StatesEditorView::setCurrentStateSilent(int index)
return;
if (state == currentState())
return;
QmlModelView::stateChanged(state, currentState());
QmlModelView::activateState(state);
}
void StatesEditorView::setCurrentState(int index)
......@@ -79,18 +79,6 @@ void StatesEditorView::setCurrentState(int index)
QmlModelView::setCurrentState(state);
}
void StatesEditorView::setBackCurrentState(int index, const QmlModelState &oldState)
{
// TODO
QmlModelState state(m_modelStates.at(index));
if (!state.isValid())
return;
if (state == oldState)
return;
QmlModelView::stateChanged(oldState, state);
}
void StatesEditorView::createState(const QString &name)
{
stateRootNode().states().addState(name);
......@@ -101,10 +89,15 @@ void StatesEditorView::removeState(int index)
Q_ASSERT(index > 0 && index < m_modelStates.size());
QmlModelState state = m_modelStates.at(index);
Q_ASSERT(state.isValid());
setCurrentState(0);
m_modelStates.removeAll(state);
m_editorModel->removeState(index);
QmlModelView::setCurrentState(baseState());
state.destroy();
m_editorModel->removeState(index);
int newIndex = (index < m_modelStates.count()) ? index : m_modelStates.count() - 1;
setCurrentState(newIndex);
}
void StatesEditorView::renameState(int index,const QString &newName)
......@@ -356,8 +349,9 @@ QPixmap StatesEditorView::renderState(int i)
painter.drawTiledPixmap(pixmap.rect(), tilePixmap);
nodeInstanceView()->render(&painter, pixmap.rect(), nodeInstanceView()->sceneRect());
setBackCurrentState(i, oldState);
setCurrentState(m_modelStates.indexOf(oldState));
nodeInstanceView()->setBlockChangeSignal(false);
Q_ASSERT(oldState == currentState());
return pixmap.copy(0,0,cutSize.width(),cutSize.height());
......
......@@ -46,7 +46,6 @@ public:
void setCurrentState(int index);
void setCurrentStateSilent(int index);
void setBackCurrentState(int index, const QmlModelState &oldState);
void createState(const QString &name);
void removeState(int index);
void renameState(int index,const QString &newName);
......
......@@ -71,7 +71,7 @@ private:
private slots:
void currentStateChanged();
void addState();
void removeState();
void removeState(int);
void duplicateCurrentState();
private:
......@@ -132,9 +132,9 @@ void StatesEditorWidgetPrivate::addState()
statesEditorView->createState(newStateName);
}
void StatesEditorWidgetPrivate::removeState()
void StatesEditorWidgetPrivate::removeState(int i)
{
statesEditorView->removeState(currentIndex());
statesEditorView->removeState(i);
}
void StatesEditorWidgetPrivate::duplicateCurrentState()
......@@ -175,7 +175,7 @@ StatesEditorWidget::StatesEditorWidget(QWidget *parent):
connect(m_d->listView->rootObject(), SIGNAL(currentStateIndexChanged()), m_d, SLOT(currentStateChanged()));
connect(m_d->listView->rootObject(), SIGNAL(createNewState()), m_d, SLOT(addState()));
connect(m_d->listView->rootObject(), SIGNAL(duplicateCurrentState()), m_d, SLOT(duplicateCurrentState()));
connect(m_d->listView->rootObject(), SIGNAL(deleteCurrentState()), m_d, SLOT(removeState()));
connect(m_d->listView->rootObject(), SIGNAL(deleteState(int)), m_d, SLOT(removeState(int)));
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
......
......@@ -6,7 +6,7 @@ Rectangle {
id: root
property int currentStateIndex : 0
signal createNewState
signal deleteCurrentState
signal deleteState(int index)
signal duplicateCurrentState
color: "#707070";
......@@ -203,13 +203,9 @@ Rectangle {
MouseRegion {
anchors.fill:parent
onClicked: {
var oldindex = root.currentStateIndex;
root.currentStateIndex = index;
root.unFocus();
root.deleteCurrentState();
root.currentStateIndex = oldindex;
if (root.currentStateIndex >= statesEditorModel.count)
root.currentStateIndex = root.currentStateIndex-1;
root.deleteState(index);
horizontalScrollbar.totalLengthDecreased();
}
onPressed: {parent.state="Pressed"}
......
......@@ -306,26 +306,27 @@ void QmlModelView::activateState(const QmlModelState &state)
} else {
newStateInstance.activateState();
}
m_state = state;
stateChanged(state, oldState);
}
void QmlModelView::changeToState(const ModelNode &node, const QString &stateName)
{
QmlItemNode itemNode(node);
QmlModelState newState;
if (stateName.isEmpty())
newState = baseState();
else
newState = itemNode.states().state(stateName);
QmlModelState oldState = m_state;
QmlModelState oldState = m_state;
if (newState.isValid())
m_state = newState;
stateChanged(newState, oldState);
if (newState.isValid() && oldState != newState) {
activateState(newState);
}
}
......
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