static QStringList objectNameList(QDesignerFormWindowInterface *form) { typedef QList<QAction*> ActionList; typedef QList<QButtonGroup *> ButtonGroupList; QStringList result; QWidget *mainContainer = form->mainContainer(); if (!mainContainer) return result; // Add main container container pages (QStatusBar, QWizardPages) etc. // to the list. Pages of containers on the form are not added, however. if (const QDesignerContainerExtension *c = qt_extension<QDesignerContainerExtension *>(form->core()->extensionManager(), mainContainer)) { const int count = c->count(); for (int i = 0 ; i < count; i++) addWidgetToObjectList(c->widget(i), result); } const QDesignerFormWindowCursorInterface *cursor = form->cursor(); const int widgetCount = cursor->widgetCount(); for (int i = 0; i < widgetCount; ++i) addWidgetToObjectList(cursor->widget(i), result); const QDesignerMetaDataBaseInterface *mdb = form->core()->metaDataBase(); // Add managed actions and actions with managed menus const ActionList actions = mainContainer->findChildren<QAction*>(); if (!actions.empty()) { const ActionList::const_iterator cend = actions.constEnd(); for (ActionList::const_iterator it = actions.constBegin(); it != cend; ++it) { QAction *a = *it; if (!a->isSeparator()) { if (QMenu *menu = a->menu()) { if (mdb->item(menu)) result.push_back(menu->objectName()); } else { if (mdb->item(a)) result.push_back(a->objectName()); } } } } // Add managed buttons groups const ButtonGroupList buttonGroups = mainContainer->findChildren<QButtonGroup *>(); if (!buttonGroups.empty()) { const ButtonGroupList::const_iterator cend = buttonGroups.constEnd(); for (ButtonGroupList::const_iterator it = buttonGroups.constBegin(); it != cend; ++it) if (mdb->item(*it)) result.append((*it)->objectName()); } result.sort(); return result; }
bool ButtonTaskMenu::refreshAssignMenu(const QDesignerFormWindowInterface *fw, int buttonCount, SelectionType st, QButtonGroup *currentGroup) { // clear if (m_assignActionGroup) { delete m_assignActionGroup; m_assignActionGroup = 0; } m_assignGroupSubMenu->clear(); if (st == OtherSelection) return false; // Assign to new: Need several const bool canAssignToNewGroup = buttonCount > 1; m_createGroupAction->setEnabled(canAssignToNewGroup); if (canAssignToNewGroup) m_assignGroupSubMenu->addAction(m_createGroupAction); // Assign to other const ButtonGroupList bl = ButtonGroupCommand::managedButtonGroups(fw); // Groups: Any groups to add to except the current? const int groupCount = bl.size(); const bool hasAddGroups = groupCount > 1 || (groupCount == 1 && !bl.contains(currentGroup)); if (hasAddGroups) { if (!m_assignGroupSubMenu->isEmpty()) m_assignGroupSubMenu->addSeparator(); // Create a new action group m_assignActionGroup = new QActionGroup(this); connect(m_assignActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(addToGroup(QAction*))); const ButtonGroupList::const_iterator cend = bl.constEnd(); for (ButtonGroupList::const_iterator it = bl.constBegin(); it != cend; ++it) { QButtonGroup *bg = *it; if (*it != currentGroup) { QAction *a = new QAction(bg->objectName(), m_assignGroupSubMenu); a->setData(QVariant::fromValue(bg)); m_assignActionGroup->addAction(a); m_assignGroupSubMenu->addAction(a); } } } // Can remove: A homogenous selection of another group that does not completely break it. const bool canRemoveFromGroup = st == GroupedButtonSelection; m_removeFromGroupAction->setEnabled(canRemoveFromGroup); if (canRemoveFromGroup) { if (!m_assignGroupSubMenu->isEmpty()) m_assignGroupSubMenu->addSeparator(); m_assignGroupSubMenu->addAction(m_removeFromGroupAction); } return !m_assignGroupSubMenu->isEmpty(); }
ButtonGroupList ButtonGroupCommand::managedButtonGroups(const QDesignerFormWindowInterface *formWindow) { const QDesignerMetaDataBaseInterface *mdb = formWindow->core()->metaDataBase(); ButtonGroupList bl; // Check 1st order children for managed button groups const QObjectList children = formWindow->mainContainer()->children(); const QObjectList::const_iterator cend = children.constEnd(); for (QObjectList::const_iterator it = children.constBegin(); it != cend; ++it) { if (!(*it)->isWidgetType()) if (QButtonGroup *bg = qobject_cast<QButtonGroup *>(*it)) if (mdb->item(bg)) bl.push_back(bg); } return bl; }