Ejemplo n.º 1
0
/** \fn KeyBindings::GetConflict(const QString&,const QString&,int&) const
 *  \brief Determine if adding a key would cause a conflict.
 *  \param context_name The name of the context.
 *  \param key The key to add.
 *  \param level The level of conflict if this returns an ActionID
 *  \return pointer to an ActionID if adding the key would cause a conflict.
 *
 *  Conflicts occur if:
 *  \li the key is a jump point, but is bound elsewhere
 *  \li the key is already bound to a jumppoint.
 *  \li the key is bound to something in the global context.
 *  \li the key is bound to something else in the specified context
 *
 *   If the method does not return NULL, check the value given to
 *   level.  Warnings can be ignored (at the users disgression), but
 *   errors should be prevented no matter what.
 *
 *   NOTE: If this returns a non-null pointer, the ActionID returned
 *         must be explicitly deleted with C++ "delete".
 */
ActionID *KeyBindings::GetConflict(
    const QString &context_name, const QString &key, int &level) const
{
    const ActionList ids = m_actionSet.GetActions(key);

    // trying to bind a jumppoint to an already bound key
    if ((context_name == ActionSet::kJumpContext) && (ids.count() > 0))
        return new ActionID(ids[0]);

    // check the contexts of the other bindings
    for (int i = 0; i < ids.count(); i++)
    {
        // jump points, then global, then the same context
        if (ids[i].GetContext() == ActionSet::kJumpContext)
        {
            level = KeyBindings::kKeyBindingError;
            return new ActionID(ids[i]);
        }
        else if (ids[i].GetContext() == context_name)
        {
            level = KeyBindings::kKeyBindingError;
            return new ActionID(ids[i]);
        }
        else if (ids[i].GetContext() == ActionSet::kGlobalContext)
        {
            level = KeyBindings::kKeyBindingWarning;
            return new ActionID(ids[i]);
        }
    }

    return NULL; // no conflicts
}
Ejemplo n.º 2
0
void ToolBarEventFilter::slotRemoveSelectedAction()
{
    QAction *action = qobject_cast<QAction*>(sender());
    if (!action)
        return;

    QAction *a = qvariant_cast<QAction*>(action->data());
    Q_ASSERT(a != 0);

    QDesignerFormWindowInterface *fw = formWindow();
    Q_ASSERT(fw);

    const ActionList actions = m_toolBar->actions();
    const int pos = actions.indexOf(a);
    QAction *action_before = 0;
    if (pos != -1 && actions.count() > pos + 1)
        action_before = actions.at(pos + 1);

    RemoveActionFromCommand *cmd = new RemoveActionFromCommand(fw);
    cmd->init(m_toolBar, a, action_before);
    fw->commandHistory()->push(cmd);
}