/** * @brief Step avatar for one circle. * * Note: if there are no more actions for an avatar to perform, the step will return -1 which means the end is reached. * @return 0 on success, -1 if reach the end * @see loop() * @see teach() */ int Avatar::step() { ++ava_loop_count; // increase count /* Perceive state */ Agent::State cs = perceiveState(); // get current state dbgmoreprt("Launch():", "Avatar %d, State: %" ST_FMT "\n", id, cs); /* Process */ OSpace acts = availableActions(cs); // get all action candidates of a state Agent::Action act = myagent->process(cs, acts); // choose an action from candidates // check validation if (act == Agent::INVALID_ACTION) // no valid actions available, reach a dead end, quit. !!!: be sure to check this before update stage return -1; /* Update memory */ myagent->update(originalPayoff(cs)); // agent update inner states /* Perform action */ performAction(act); // perform the action return 0; }
void StatusBar::loadChangeableActions(const QStringList &action_names) { clear(); QList<QAction*> available_actions = availableActions(); // Iterate action names and add respectable actions into the toolbar. foreach (const QString &action_name, action_names) { QAction *matching_action = findMatchingAction(action_name, available_actions); QAction *action_to_add; QWidget *widget_to_add; if (matching_action == m_barProgressDownloadAction) { widget_to_add = m_barProgressDownload; action_to_add = m_barProgressDownloadAction; widget_to_add->setVisible(false); } else if (matching_action == m_barProgressFeedsAction) { widget_to_add = m_barProgressFeeds; action_to_add = m_barProgressFeedsAction; widget_to_add->setVisible(false); } else if (matching_action == m_lblProgressDownloadAction) { widget_to_add = m_lblProgressDownload; action_to_add = m_lblProgressDownloadAction; widget_to_add->setVisible(false); } else if (matching_action == m_lblProgressFeedsAction) { widget_to_add = m_lblProgressFeeds; action_to_add = m_lblProgressFeedsAction; widget_to_add->setVisible(false); } else { if (action_name == SEPARATOR_ACTION_NAME) { QLabel *lbl = new QLabel(QString::fromUtf8("•")); widget_to_add = lbl; action_to_add = new QAction(this); action_to_add->setSeparator(true); action_to_add->setProperty("should_remove_action", true); } else if (action_name == SPACER_ACTION_NAME) { QLabel *lbl = new QLabel(QSL("\t\t")); widget_to_add = lbl; action_to_add = new QAction(this); action_to_add->setProperty("should_remove_action", true); action_to_add->setIcon(qApp->icons()->fromTheme(QSL("system-search"))); action_to_add->setProperty("type", SPACER_ACTION_NAME); action_to_add->setProperty("name", tr("Toolbar spacer")); } else if (matching_action != nullptr) { // Add originally toolbar action. PlainToolButton *tool_button = new PlainToolButton(this); tool_button->reactOnActionChange(matching_action); widget_to_add = tool_button; action_to_add = matching_action; connect(tool_button, SIGNAL(clicked(bool)), matching_action, SLOT(trigger())); connect(matching_action, SIGNAL(changed()), tool_button, SLOT(reactOnActionChange())); } else { action_to_add = nullptr; widget_to_add = nullptr; } if (action_to_add != nullptr) { action_to_add->setProperty("should_remove_widget", true); } } if (action_to_add != nullptr && widget_to_add != nullptr) { action_to_add->setProperty("widget", QVariant::fromValue((void*) widget_to_add)); addPermanentWidget(widget_to_add); addAction(action_to_add); } }