diff options
-rw-r--r-- | src/designer/src/lib/shared/actioneditor.cpp | 13 | ||||
-rw-r--r-- | src/designer/src/lib/shared/actionrepository.cpp | 6 | ||||
-rw-r--r-- | src/designer/src/lib/shared/actionrepository_p.h | 2 | ||||
-rw-r--r-- | src/designer/src/lib/shared/newactiondialog.cpp | 17 | ||||
-rw-r--r-- | src/designer/src/lib/shared/newactiondialog.ui | 17 | ||||
-rw-r--r-- | src/designer/src/lib/shared/newactiondialog_p.h | 5 |
6 files changed, 55 insertions, 5 deletions
diff --git a/src/designer/src/lib/shared/actioneditor.cpp b/src/designer/src/lib/shared/actioneditor.cpp index c8fdc43ff..9200b6fc0 100644 --- a/src/designer/src/lib/shared/actioneditor.cpp +++ b/src/designer/src/lib/shared/actioneditor.cpp @@ -53,6 +53,7 @@ static const char *actionEditorViewModeKey = "ActionEditorViewMode"; static const char *iconPropertyC = "icon"; static const char *shortcutPropertyC = "shortcut"; +static const char *menuRolePropertyC = "menuRole"; static const char *toolTipPropertyC = "toolTip"; static const char *checkablePropertyC = "checkable"; static const char *objectNamePropertyC = "objectName"; @@ -447,6 +448,8 @@ void ActionEditor::slotNewAction() sheet->setProperty(sheet->indexOf(QLatin1String(iconPropertyC)), QVariant::fromValue(actionData.icon)); + setInitialProperty(sheet, QLatin1String(menuRolePropertyC), QVariant::fromValue(actionData.menuRole)); + AddActionCommand *cmd = new AddActionCommand(formWindow()); cmd->init(action); formWindow()->commandHistory()->push(cmd); @@ -527,6 +530,7 @@ void ActionEditor::editAction(QAction *action, int column) oldActionData.icon = qvariant_cast<PropertySheetIconValue>(sheet->property(sheet->indexOf(QLatin1String(iconPropertyC)))); oldActionData.keysequence = ActionModel::actionShortCut(sheet); oldActionData.checkable = action->isCheckable(); + oldActionData.menuRole.value = action->menuRole(); dlg.setActionData(oldActionData); switch (column) { @@ -545,6 +549,9 @@ void ActionEditor::editAction(QAction *action, int column) case qdesigner_internal::ActionModel::ToolTipColumn: dlg.focusTooltip(); break; + case qdesigner_internal::ActionModel::MenuRoleColumn: + dlg.focusMenuRole(); + break; } if (!dlg.exec()) @@ -558,7 +565,8 @@ void ActionEditor::editAction(QAction *action, int column) const bool severalChanges = (changeMask != ActionData::TextChanged) && (changeMask != ActionData::NameChanged) && (changeMask != ActionData::ToolTipChanged) && (changeMask != ActionData::IconChanged) - && (changeMask != ActionData::CheckableChanged) && (changeMask != ActionData::KeysequenceChanged); + && (changeMask != ActionData::CheckableChanged) && (changeMask != ActionData::KeysequenceChanged) + && (changeMask != ActionData::MenuRoleChanged); QDesignerFormWindowInterface *fw = formWindow(); QUndoStack *undoStack = fw->commandHistory(); @@ -583,6 +591,9 @@ void ActionEditor::editAction(QAction *action, int column) if (changeMask & ActionData::KeysequenceChanged) undoStack->push(setKeySequencePropertyCommand(newActionData.keysequence, action, fw)); + if (changeMask & ActionData::MenuRoleChanged) + undoStack->push(setPropertyCommand(QLatin1String(menuRolePropertyC), static_cast<QAction::MenuRole>(newActionData.menuRole.value), QAction::NoRole, action, fw)); + if (severalChanges) fw->endCommand(); } diff --git a/src/designer/src/lib/shared/actionrepository.cpp b/src/designer/src/lib/shared/actionrepository.cpp index 40afd50b5..e5e330279 100644 --- a/src/designer/src/lib/shared/actionrepository.cpp +++ b/src/designer/src/lib/shared/actionrepository.cpp @@ -23,6 +23,7 @@ #include <QtCore/qset.h> #include <QtCore/qdebug.h> +#include <QtCore/qmetaobject.h> Q_DECLARE_METATYPE(QAction*) @@ -54,6 +55,7 @@ ActionModel::ActionModel(QWidget *parent ) : headers += tr("Shortcut"); headers += tr("Checkable"); headers += tr("ToolTip"); + headers += tr("MenuRole"); Q_ASSERT(NumColumns == headers.size()); setHorizontalHeaderLabels(headers); } @@ -200,6 +202,10 @@ void ActionModel::setItems(QDesignerFormEditorInterface *core, QAction *action, item = sl[ToolTipColumn]; item->setToolTip(toolTip); item->setText(toolTip.replace(QLatin1Char('\n'), QLatin1Char(' '))); + // menuRole + const auto menuRole = action->menuRole(); + item = sl[MenuRoleColumn]; + item->setText(QLatin1StringView(QMetaEnum::fromType<QAction::MenuRole>().valueToKey(menuRole))); } QMimeData *ActionModel::mimeData(const QModelIndexList &indexes ) const diff --git a/src/designer/src/lib/shared/actionrepository_p.h b/src/designer/src/lib/shared/actionrepository_p.h index f61d851bb..bc31ccd55 100644 --- a/src/designer/src/lib/shared/actionrepository_p.h +++ b/src/designer/src/lib/shared/actionrepository_p.h @@ -39,7 +39,7 @@ class QDESIGNER_SHARED_EXPORT ActionModel: public QStandardItemModel { Q_OBJECT public: - enum Columns { NameColumn, UsedColumn, TextColumn, ShortCutColumn, CheckedColumn, ToolTipColumn, NumColumns }; + enum Columns { NameColumn, UsedColumn, TextColumn, ShortCutColumn, CheckedColumn, ToolTipColumn, MenuRoleColumn, NumColumns }; enum { ActionRole = Qt::UserRole + 1000 }; explicit ActionModel(QWidget *parent = nullptr); diff --git a/src/designer/src/lib/shared/newactiondialog.cpp b/src/designer/src/lib/shared/newactiondialog.cpp index 206406eb3..4f91e7857 100644 --- a/src/designer/src/lib/shared/newactiondialog.cpp +++ b/src/designer/src/lib/shared/newactiondialog.cpp @@ -12,6 +12,7 @@ #include <QtDesigner/abstractformwindow.h> #include <QtDesigner/abstractformeditor.h> +#include <QtCore/QMetaEnum> #include <QtWidgets/qpushbutton.h> QT_BEGIN_NAMESPACE @@ -33,6 +34,8 @@ unsigned ActionData::compare(const ActionData &rhs) const rc |= CheckableChanged; if (keysequence != rhs.keysequence) rc |= KeysequenceChanged ; + if (menuRole.value != rhs.menuRole.value) + rc |= MenuRoleChanged ; return rc; } @@ -52,6 +55,13 @@ NewActionDialog::NewActionDialog(ActionEditor *parent) : connect(m_ui->keysequenceResetToolButton, &QAbstractButton::clicked, this, &NewActionDialog::slotResetKeySequence); + const auto menuRoles = QMetaEnum::fromType<QAction::MenuRole>(); + for (int i = 0; i < menuRoles.keyCount(); i++) { + const auto key = menuRoles.key(i); + const auto value = menuRoles.value(i); + m_ui->menuRole->addItem(QLatin1StringView(key), value); + } + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); focusText(); updateButtons(); @@ -96,6 +106,11 @@ void NewActionDialog::focusCheckable() m_ui->checkableCheckBox->setFocus(); } +void NewActionDialog::focusMenuRole() +{ + m_ui->menuRole->setFocus(); +} + QString NewActionDialog::actionText() const { return m_ui->editActionText->text(); @@ -116,6 +131,7 @@ ActionData NewActionDialog::actionData() const rc.icon.setTheme(m_ui->iconThemeEditor->theme()); rc.checkable = m_ui->checkableCheckBox->checkState() == Qt::Checked; rc.keysequence = PropertySheetKeySequenceValue(m_ui->keySequenceEdit->keySequence()); + rc.menuRole.value = m_ui->menuRole->currentData().toInt(); return rc; } @@ -128,6 +144,7 @@ void NewActionDialog::setActionData(const ActionData &d) m_ui->tooltipEditor->setText(d.toolTip); m_ui->keySequenceEdit->setKeySequence(d.keysequence.value()); m_ui->checkableCheckBox->setCheckState(d.checkable ? Qt::Checked : Qt::Unchecked); + m_ui->menuRole->setCurrentIndex(m_ui->menuRole->findData(d.menuRole.value)); // Suppress updating of the object name from the text for existing actions. m_autoUpdateObjectName = d.name.isEmpty(); diff --git a/src/designer/src/lib/shared/newactiondialog.ui b/src/designer/src/lib/shared/newactiondialog.ui index 78cb2142f..733690d20 100644 --- a/src/designer/src/lib/shared/newactiondialog.ui +++ b/src/designer/src/lib/shared/newactiondialog.ui @@ -9,8 +9,8 @@ <rect> <x>0</x> <y>0</y> - <width>366</width> - <height>270</height> + <width>395</width> + <height>372</height> </rect> </property> <property name="windowTitle"> @@ -177,6 +177,19 @@ </item> </layout> </item> + <item row="7" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>&Menu role:</string> + </property> + <property name="buddy"> + <cstring>menuRole</cstring> + </property> + </widget> + </item> + <item row="7" column="1"> + <widget class="QComboBox" name="menuRole"/> + </item> </layout> </item> <item> diff --git a/src/designer/src/lib/shared/newactiondialog_p.h b/src/designer/src/lib/shared/newactiondialog_p.h index 3a4b3d174..503b2f687 100644 --- a/src/designer/src/lib/shared/newactiondialog_p.h +++ b/src/designer/src/lib/shared/newactiondialog_p.h @@ -34,7 +34,8 @@ struct ActionData { enum ChangeMask { TextChanged = 0x1, NameChanged = 0x2, ToolTipChanged = 0x4, - IconChanged = 0x8, CheckableChanged = 0x10, KeysequenceChanged = 0x20 + IconChanged = 0x8, CheckableChanged = 0x10, KeysequenceChanged = 0x20, + MenuRoleChanged = 0x40 }; // Returns a combination of ChangeMask flags @@ -46,6 +47,7 @@ struct ActionData { PropertySheetIconValue icon; bool checkable{false}; PropertySheetKeySequenceValue keysequence; + PropertySheetFlagValue menuRole; }; inline bool operator==(const ActionData &a1, const ActionData &a2) { return a1.compare(a2) == 0u; } @@ -70,6 +72,7 @@ public slots: void focusTooltip(); void focusShortcut(); void focusCheckable(); + void focusMenuRole(); private slots: void on_editActionText_textEdited(const QString &text); |