void IToolBar::actionTriggeredSlot(bool checked) { IAction* action = dynamic_cast<IAction*> (sender()); if(action) { action->execute(); } }
void Console::execute(const string& line) { vector<string> parts = StringUtil::split(line, ' '); if(parts.size() > 0) { string command = parts[0]; IAction* action = basicLanguage[command]; if(action) { string param; if(parts.size() > 1) { param = parts[1]; } else { param = ""; } action->execute(param); } } }
QSharedPointer<QAction> QtMenu::createSharedQAction(IAction& action) { auto qAction = getSharedQAction(action); if (qAction) { return qAction; } qAction.reset(new QForwardingAction(action.text(), QApplication::instance()), &QObject::deleteLater); sharedQActions_[&action] = qAction; qAction->setProperty("order", action.order()); qAction->setEnabled(action.enabled()); qAction->setVisible(action.visible()); if (action.isSeparator()) { qAction->setSeparator(true); } else { std::vector<QIcon> qIcons; auto icons = StringUtils::split(std::string(action.icon()), '|'); for(auto& icon : icons) { StringUtils::trim_string(icon); qIcons.push_back(QtMenu_Locals::generateIcon(icon.c_str())); } if(!qIcons.empty()) { qAction->setIcon(qIcons[0]); } qAction->setShortcut(QKeySequence(action.shortcut())); if (action.isCheckable()) { qAction->setCheckable(true); qAction->setChecked(action.checked()); } QObject::connect(qAction.data(), &QAction::triggered, [&action]() { if (!action.enabled()) { return; } action.execute(); }); connections_[&action] = action.signalShortcutChanged.connect([qAction](const char* shortcut) { TF_ASSERT(qAction != nullptr); qAction->setShortcut(QKeySequence(shortcut)); }); connections_[&action] = action.signalTextChanged.connect([qAction](const char* text) { TF_ASSERT(qAction != nullptr); qAction->setText(text); }); connections_[&action] = action.signalVisibilityChanged.connect([qAction](bool visible) { TF_ASSERT(qAction != nullptr); qAction->setVisible(visible); }); connections_[&action] = action.signalIconChanged.connect([qAction, qIcons](int index) { TF_ASSERT(qAction != nullptr); if(index >= 0 && index < (int)qIcons.size()) { qAction->setIcon(qIcons[index]); } }); const std::string groupID(action.group()); if (!groupID.empty()) { auto itr = groups_.find(groupID); if (itr == groups_.end()) { groups_[groupID].reset(new QActionGroup(&menu_)); } groups_.at(groupID)->addAction(qAction.data()); TF_ASSERT(qAction->actionGroup()); } } return qAction; }