20 #include "modelactionrootstate.h"
21 #include "indicators.h"
23 #include <unitymenumodel.h>
32 ModelActionRootState::ModelActionRootState(QObject *parent)
33 : RootStateObject(parent),
38 ModelActionRootState::~ModelActionRootState()
42 UnityMenuModel* ModelActionRootState::menu()
const
47 void ModelActionRootState::setMenu(UnityMenuModel* menu)
50 bool wasValid = valid();
53 m_menu->disconnect(
this);
58 connect(m_menu, &UnityMenuModel::rowsInserted,
this, &ModelActionRootState::onModelRowsAdded);
59 connect(m_menu, &UnityMenuModel::rowsRemoved,
this, &ModelActionRootState::onModelRowsRemoved);
60 connect(m_menu, &UnityMenuModel::dataChanged,
this, &ModelActionRootState::onModelDataChanged);
62 connect(m_menu, &UnityMenuModel::destroyed,
this, &ModelActionRootState::reset);
67 if (wasValid != valid())
68 Q_EMIT validChanged();
72 bool ModelActionRootState::valid()
const
74 return !currentState().empty();
77 void ModelActionRootState::onModelRowsAdded(
const QModelIndex& parent,
int start,
int end)
80 if (start == 0 && end >= 0) {
85 void ModelActionRootState::onModelRowsRemoved(
const QModelIndex& parent,
int start,
int end)
88 if (start == 0 && end >= 0) {
93 void ModelActionRootState::onModelDataChanged(
const QModelIndex& topLeft,
const QModelIndex& bottomRight,
const QVector<int>& roles)
96 if (!topLeft.isValid() || !bottomRight.isValid()) {
100 if (topLeft.row() <= 0 && bottomRight.row() >= 0) {
105 void ModelActionRootState::reset()
109 Q_EMIT menuChanged();
110 setCurrentState(QVariantMap());
113 void ModelActionRootState::updateActionState()
115 if (m_menu && m_menu->rowCount() > 0) {
116 ActionStateParser* oldParser = m_menu->actionStateParser();
117 m_menu->setActionStateParser(&m_parser);
119 QVariantMap state = m_menu->get(0,
"actionState").toMap();
121 m_menu->setActionStateParser(oldParser);
123 setCurrentState(state);
124 }
else if (!m_menu) {
125 setCurrentState(QVariantMap());