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
listwidget_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/qstyleoption.h>
14
15#include <QtGui/qaction.h>
16
17#include <QtCore/qcoreevent.h>
18#include <QtCore/qvariant.h>
19#include <QtCore/qdebug.h>
20
22
23namespace qdesigner_internal {
24
25ListWidgetTaskMenu::ListWidgetTaskMenu(QListWidget *button, QObject *parent)
26 : QDesignerTaskMenu(button, parent),
27 m_listWidget(button)
28{
29 m_editItemsAction = new QAction(this);
30 m_editItemsAction->setText(tr("Edit Items..."));
31 connect(m_editItemsAction, &QAction::triggered, this, &ListWidgetTaskMenu::editItems);
32 m_taskActions.append(m_editItemsAction);
33
34 QAction *sep = new QAction(this);
35 sep->setSeparator(true);
36 m_taskActions.append(sep);
37}
38
40
42{
43 return m_editItemsAction;
44}
45
47{
48 return m_taskActions + QDesignerTaskMenu::taskActions();
49}
50
51void ListWidgetTaskMenu::editItems()
52{
53 m_formWindow = QDesignerFormWindowInterface::findFormWindow(m_listWidget);
54 if (m_formWindow.isNull())
55 return;
56
57 Q_ASSERT(m_listWidget != nullptr);
58
59 ListWidgetEditor dlg(m_formWindow, m_listWidget->window());
60 ListContents oldItems = dlg.fillContentsFromListWidget(m_listWidget);
61 if (dlg.exec() == QDialog::Accepted) {
62 ListContents items = dlg.contents();
63 if (items != oldItems) {
64 ChangeListContentsCommand *cmd = new ChangeListContentsCommand(m_formWindow);
65 cmd->init(m_listWidget, oldItems, items);
66 cmd->setText(tr("Change List Contents"));
67 m_formWindow->commandHistory()->push(cmd);
68 }
69 }
70}
71
72void ListWidgetTaskMenu::updateSelection()
73{
74 if (m_editor)
75 m_editor->deleteLater();
76}
77
78} // namespace qdesigner_internal
79
80QT_END_NAMESPACE
QAction * preferredEditAction() const override
QList< QAction * > taskActions() const override
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.