void ButtonTaskMenu::createGroup() { QDesignerFormWindowInterface *fw = formWindow(); const ButtonList bl = buttonList(fw->cursor()); // Do we need to remove the buttons from an existing group? QUndoCommand *removeCmd = 0; if (bl.front()->group()) { removeCmd = createRemoveButtonsCommand(fw, bl); if (!removeCmd) return; } // Add cmd CreateButtonGroupCommand *addCmd = new CreateButtonGroupCommand(fw); if (!addCmd->init(bl)) { qWarning("** WARNING Failed to initialize CreateButtonGroupCommand!"); delete addCmd; return; } // Need a macro [even if we only have the add command] since the command might trigger additional commands QUndoStack *history = fw->commandHistory(); history->beginMacro(addCmd->text()); if (removeCmd) history->push(removeCmd); history->push(addCmd); history->endMacro(); }
void ButtonTaskMenu::addToGroup(QAction *a) { QButtonGroup *bg = qvariant_cast<QButtonGroup *>(a->data()); Q_ASSERT(bg); QDesignerFormWindowInterface *fw = formWindow(); const ButtonList bl = buttonList(fw->cursor()); // Do we need to remove the buttons from an existing group? QUndoCommand *removeCmd = 0; if (bl.front()->group()) { removeCmd = createRemoveButtonsCommand(fw, bl); if (!removeCmd) return; } AddButtonsToGroupCommand *addCmd = new AddButtonsToGroupCommand(fw); addCmd->init(bl, bg); QUndoStack *history = fw->commandHistory(); if (removeCmd) { history->beginMacro(addCmd->text()); history->push(removeCmd); history->push(addCmd); history->endMacro(); } else { history->push(addCmd); } }
bool RemoveButtonsFromGroupCommand::init(const ButtonList &bl) { if (bl.empty()) return false; QButtonGroup *group = bl.front()->group(); if (!group) return false; if (bl.size() >= group->buttons().size()) return false; initialize(bl, group); //: Command description for removing buttons from a QButtonGroup setText(QApplication::translate("Command", "Remove '%1' from '%2'").arg(nameList(bl), group->objectName())); return true; }