aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-09-23 18:41:15 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-09-23 18:41:15 +0200
commit74a9ba6419669fa4ca0b32bb50345e48e8f8ad46 (patch)
treedea335b86779590e69de03928174edae88b64954 /libqmenumodel/src
parent23dee12d54a17b9a883d02e03ffcff45f439e188 (diff)
downloadqmenumodel-74a9ba6419669fa4ca0b32bb50345e48e8f8ad46.tar.gz
qmenumodel-74a9ba6419669fa4ca0b32bb50345e48e8f8ad46.tar.bz2
qmenumodel-74a9ba6419669fa4ca0b32bb50345e48e8f8ad46.zip
QStateAction: try to maintain the type of the action's state
QML likes to convert doubles to integers if the number is close enough to an integer. This tries to circumvent that by explicitly casting to the right action type, because that's what exporters of GActionGroups expect.
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r--libqmenumodel/src/qstateaction.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/libqmenumodel/src/qstateaction.cpp b/libqmenumodel/src/qstateaction.cpp
index 1861aea..40d70a5 100644
--- a/libqmenumodel/src/qstateaction.cpp
+++ b/libqmenumodel/src/qstateaction.cpp
@@ -92,9 +92,11 @@ bool QStateAction::isValid() const
Request for the state of action to be changed to \a paramenter.
This call merely requests a change. The action may refuse to change its state or may change its state to something other than \a paramenter.
*/
-void QStateAction::updateState(const QVariant &parameter)
+void QStateAction::updateState(const QVariant &state)
{
- m_group->updateActionState(m_name, parameter);
+ QVariant v = state;
+ if (v.convert(m_state.type()))
+ m_group->updateActionState(m_name, v);
}
/*!
@@ -124,8 +126,9 @@ void QStateAction::setValid(bool valid)
/*! \internal */
void QStateAction::setState(const QVariant &state)
{
- if (m_state != state) {
- m_state = state;
+ QVariant v = state;
+ if (!m_state.isValid() || (v.convert(m_state.type()) && v != m_state)) {
+ m_state = v;
Q_EMIT stateChanged(m_state);
}
}