Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
combobox_taskmenu.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant reason:default
4
8#include <qdesigner_command_p.h>
9
10#include <QtDesigner/abstractformwindow.h>
11
12#include <QtWidgets/qstyle.h>
13#include <QtWidgets/qlineedit.h>
14#include <QtWidgets/qfontcombobox.h>
15#include <QtWidgets/qstyleoption.h>
16
17#include <QtGui/qaction.h>
18
19#include <QtCore/qcoreevent.h>
20#include <QtCore/qvariant.h>
21#include <QtCore/qdebug.h>
22
24
25namespace qdesigner_internal {
26
27ComboBoxTaskMenu::ComboBoxTaskMenu(QComboBox *button, QObject *parent)
28 : QDesignerTaskMenu(button, parent),
29 m_comboBox(button)
30{
31 m_editItemsAction = new QAction(this);
32 m_editItemsAction->setText(tr("Edit Items..."));
33 connect(m_editItemsAction, &QAction::triggered, this, &ComboBoxTaskMenu::editItems);
34 m_taskActions.append(m_editItemsAction);
35
36 QAction *sep = new QAction(this);
37 sep->setSeparator(true);
38 m_taskActions.append(sep);
39}
40
42
44{
45 return m_editItemsAction;
46}
47
49{
50 return m_taskActions + QDesignerTaskMenu::taskActions();
51}
52
53void ComboBoxTaskMenu::editItems()
54{
55 m_formWindow = QDesignerFormWindowInterface::findFormWindow(m_comboBox);
56 if (m_formWindow.isNull())
57 return;
58
59 Q_ASSERT(m_comboBox != nullptr);
60
61 ListWidgetEditor dlg(m_formWindow, m_comboBox->window());
62 ListContents oldItems = dlg.fillContentsFromComboBox(m_comboBox);
63 if (dlg.exec() == QDialog::Accepted) {
64 ListContents items = dlg.contents();
65 if (items != oldItems) {
66 ChangeListContentsCommand *cmd = new ChangeListContentsCommand(m_formWindow);
67 cmd->init(m_comboBox, oldItems, items);
68 cmd->setText(tr("Change Combobox Contents"));
69 m_formWindow->commandHistory()->push(cmd);
70 }
71 }
72}
73
74ComboBoxTaskMenuFactory::ComboBoxTaskMenuFactory(const QString &iid, QExtensionManager *extensionManager) :
75 ExtensionFactory<QDesignerTaskMenuExtension, QComboBox, ComboBoxTaskMenu>(iid, extensionManager)
76{
77}
78
79QComboBox *ComboBoxTaskMenuFactory::checkObject(QObject *qObject) const
80{
81 QComboBox *combo = qobject_cast<QComboBox*>(qObject);
82 if (!combo)
83 return nullptr;
84 if (qobject_cast<QFontComboBox*>(combo))
85 return nullptr;
86 return combo;
87}
88
89void ComboBoxTaskMenu::updateSelection()
90{
91 if (m_editor)
92 m_editor->deleteLater();
93}
94
95} // namespace qdesigner_internal
96
97QT_END_NAMESPACE
QComboBox * checkObject(QObject *qObject) const override
QList< QAction * > taskActions() const override
QAction * preferredEditAction() const override
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.