32 : QStandardItemModel(0, 1, parent)
38 void StateItemModel::updateModel(
const std::string& componentName,
const std::vector<StateIceBasePtr>& topLevelBaseStates,
const std::vector<StateIceBasePtr>& topLevelRequestedStates)
40 if (componentName.empty())
45 requestedInstanceList[componentName] = topLevelRequestedStates;
48 markAllForDelete(invisibleRootItem());
51 QStandardItem* componentItem = updateComponent(componentName);
54 updateStates(componentItem->child(0), topLevelBaseStates, componentName,
eBaseStateItem);
55 updateStates(componentItem->child(1), topLevelRequestedStates, componentName,
eInstanceStateItem);
60 deleteUnusedItems(componentItem);
65 std::map<std::string, std::vector< StateIceBasePtr > > ::iterator it = requestedInstanceList.find(componentName);
67 if (it == requestedInstanceList.end())
72 StateIceBasePtr result = NULL;
74 for (
unsigned int i = 0; i < it->second.size(); i++)
76 if (it->second[i]->globalStateIdentifier == globalStateIdStr)
95 for (
unsigned int i = 0; i < state->subStateList.size(); ++i)
97 StateIceBasePtr curState = StateIceBasePtr::dynamicCast(state->subStateList[i]);
99 if (curState->globalStateIdentifier == globalStateIdStr)
101 resultState = curState;
115 QStandardItem* StateItemModel::updateComponent(std::string componentName)
117 QStandardItem* componentItem =
new QStandardItem(QString(componentName.c_str()));
120 componentItem->setData(QVariant(eUndefined),
STATE_TYPE);
122 componentItem = updateOrInsertItem(invisibleRootItem(), componentItem);
128 baseStateItem->setData(QVariant(eUndefined),
STATE_TYPE);
129 baseStateItem = updateOrInsertItem(componentItem, baseStateItem);
135 requestedStateItem->setData(QVariant(eUndefined),
STATE_TYPE);
136 requestedStateItem = updateOrInsertItem(componentItem, requestedStateItem);
138 return componentItem;
142 void StateItemModel::updateStates(QStandardItem* componentItem,
const std::vector<StateIceBasePtr>& topLevelStates, std::string componentName, eItemType itemType)
145 for (
unsigned int i = 0; i < topLevelStates.size(); ++i)
149 insertSubstates(componentItem, topLevelStates[i], componentName, itemType);
157 QStandardItem* StateItemModel::updateOrInsertItem(QStandardItem* parent, QStandardItem*
insert)
160 for (
int r = 0 ; r < parent->rowCount() ; r++)
162 QStandardItem* item = parent->child(r);
173 parent->appendRow(
insert);
180 QVariant StateItemModel::data(
const QModelIndex&
index,
int role)
const
185 if (role == Qt::BackgroundColorRole)
199 brush.setColor(Qt::white);
203 brush.setColor(Qt::blue);
206 case eDynamicRemoteState:
207 brush.setColor(Qt::blue);
208 brush.setColor(brush.color().lighter(120));
212 brush.setColor(Qt::yellow);
216 brush.setColor(Qt::white);
219 brush.setColor(brush.color().lighter(170));
221 return qVariantFromValue(brush.color());
223 else if (role == Qt::ToolTipRole)
234 description =
"Normal State";
238 description =
"Remote State";
241 case eDynamicRemoteState:
242 description =
"Dynamic Remote State";
246 description =
"Final State";
254 description =
"Unknown State Type";
257 if (description.length() > 0)
259 description +=
"; Id: " + globalId +
"; Component Name: " + componentName;
262 return qVariantFromValue(description);
271 void StateItemModel::markAllForDelete(QStandardItem* stateItem)
274 std::list<QStandardItem*> markList;
275 markList.push_back(stateItem);
277 while (markList.size() > 0)
279 QStandardItem* current = markList.front();
280 markList.pop_front();
284 if (current->hasChildren())
286 for (
int r = 0 ; r < current->rowCount() ; r++)
288 markList.push_back(current->child(r));
294 void StateItemModel::deleteUnusedItems(QStandardItem* stateItem)
296 std::list<QStandardItem*> searchList;
297 std::vector<int> removeRows;
299 searchList.push_back(stateItem);
301 while (searchList.size() > 0)
303 QStandardItem* current = searchList.front();
304 searchList.pop_front();
306 if (current->hasChildren())
310 for (
int r = 0 ; r < current->rowCount() ; r++)
314 removeRows.push_back(r);
318 searchList.push_back(current->child(r));
323 std::vector<int>::iterator iter = removeRows.begin();
325 while (iter != removeRows.end())
327 current->removeRow(*iter);
334 void StateItemModel::insertSubstates(QStandardItem* parentStateItem, StateIceBasePtr state, std::string componentName, eItemType itemType)
338 QStandardItem* stateItem =
new QStandardItem(QString(state->stateName.c_str()));
341 stateItem->setData(QVariant(QString(state->globalStateIdentifier.c_str())),
STATE_GLOBALSTATEID);
342 stateItem->setData(QVariant(state->stateType),
STATE_TYPE);
348 componentName = remoteState->proxyName;
355 stateItem = updateOrInsertItem(parentStateItem, stateItem);
357 for (
unsigned int i = 0; i < state->subStateList.size(); ++i)
359 StateIceBasePtr curState = StateIceBasePtr::dynamicCast(state->subStateList[i]);
360 insertSubstates(stateItem, curState, componentName, itemType);
368 if (
index.row() == 0 &&
index.parent() == invisibleRootItem()->
index())
370 if (role == Qt::EditRole)