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
7#include <qdesigner_command_p.h>
8
9#include <QtDesigner/abstractformwindow.h>
10
11#include <QtWidgets/qstyle.h>
12#include <QtWidgets/qlineedit.h>
13#include <QtWidgets/qfontcombobox.h>
14#include <QtWidgets/qstyleoption.h>
15
16#include <QtGui/qaction.h>
17
18#include <QtCore/qcoreevent.h>
19#include <QtCore/qvariant.h>
20#include <QtCore/qdebug.h>
21
23
24namespace qdesigner_internal {
25
26ComboBoxTaskMenu::ComboBoxTaskMenu(QComboBox *button, QObject *parent)
27 : QDesignerTaskMenu(button, parent),
28 m_comboBox(button)
29{
30 m_editItemsAction = new QAction(this);
31 m_editItemsAction->setText(tr("Edit Items..."));
32 connect(m_editItemsAction, &QAction::triggered, this, &ComboBoxTaskMenu::editItems);
33 m_taskActions.append(m_editItemsAction);
34
35 QAction *sep = new QAction(this);
36 sep->setSeparator(true);
37 m_taskActions.append(sep);
38}
39
41
43{
44 return m_editItemsAction;
45}
46
48{
49 return m_taskActions + QDesignerTaskMenu::taskActions();
50}
51
52void ComboBoxTaskMenu::editItems()
53{
54 m_formWindow = QDesignerFormWindowInterface::findFormWindow(m_comboBox);
55 if (m_formWindow.isNull())
56 return;
57
58 Q_ASSERT(m_comboBox != nullptr);
59
60 ListWidgetEditor dlg(m_formWindow, m_comboBox->window());
61 ListContents oldItems = dlg.fillContentsFromComboBox(m_comboBox);
62 if (dlg.exec() == QDialog::Accepted) {
63 ListContents items = dlg.contents();
64 if (items != oldItems) {
65 ChangeListContentsCommand *cmd = new ChangeListContentsCommand(m_formWindow);
66 cmd->init(m_comboBox, oldItems, items);
67 cmd->setText(tr("Change Combobox Contents"));
68 m_formWindow->commandHistory()->push(cmd);
69 }
70 }
71}
72
73ComboBoxTaskMenuFactory::ComboBoxTaskMenuFactory(const QString &iid, QExtensionManager *extensionManager) :
74 ExtensionFactory<QDesignerTaskMenuExtension, QComboBox, ComboBoxTaskMenu>(iid, extensionManager)
75{
76}
77
78QComboBox *ComboBoxTaskMenuFactory::checkObject(QObject *qObject) const
79{
80 QComboBox *combo = qobject_cast<QComboBox*>(qObject);
81 if (!combo)
82 return nullptr;
83 if (qobject_cast<QFontComboBox*>(combo))
84 return nullptr;
85 return combo;
86}
87
88void ComboBoxTaskMenu::updateSelection()
89{
90 if (m_editor)
91 m_editor->deleteLater();
92}
93
94} // namespace qdesigner_internal
95
96QT_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.