1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Designer of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include "treewidget_taskmenu.h" |
30 | #include "treewidgeteditor.h" |
31 | |
32 | #include <QtDesigner/abstractformwindow.h> |
33 | |
34 | #include <QtWidgets/qaction.h> |
35 | #include <QtWidgets/qstyle.h> |
36 | #include <QtWidgets/qlineedit.h> |
37 | #include <QtWidgets/qstyleoption.h> |
38 | |
39 | #include <QtCore/qcoreevent.h> |
40 | #include <QtCore/qvariant.h> |
41 | #include <QtCore/qdebug.h> |
42 | |
43 | QT_BEGIN_NAMESPACE |
44 | |
45 | using namespace qdesigner_internal; |
46 | |
47 | TreeWidgetTaskMenu::(QTreeWidget *button, QObject *parent) |
48 | : QDesignerTaskMenu(button, parent), |
49 | m_treeWidget(button), |
50 | m_editItemsAction(new QAction(tr(s: "Edit Items..." ), this)) |
51 | { |
52 | connect(sender: m_editItemsAction, signal: &QAction::triggered, receiver: this, slot: &TreeWidgetTaskMenu::editItems); |
53 | m_taskActions.append(t: m_editItemsAction); |
54 | |
55 | QAction *sep = new QAction(this); |
56 | sep->setSeparator(true); |
57 | m_taskActions.append(t: sep); |
58 | } |
59 | |
60 | |
61 | TreeWidgetTaskMenu::() = default; |
62 | |
63 | QAction *TreeWidgetTaskMenu::() const |
64 | { |
65 | return m_editItemsAction; |
66 | } |
67 | |
68 | QList<QAction*> TreeWidgetTaskMenu::() const |
69 | { |
70 | return m_taskActions + QDesignerTaskMenu::taskActions(); |
71 | } |
72 | |
73 | void TreeWidgetTaskMenu::() |
74 | { |
75 | m_formWindow = QDesignerFormWindowInterface::findFormWindow(w: m_treeWidget); |
76 | if (m_formWindow.isNull()) |
77 | return; |
78 | |
79 | Q_ASSERT(m_treeWidget != nullptr); |
80 | |
81 | TreeWidgetEditorDialog dlg(m_formWindow, m_treeWidget->window()); |
82 | TreeWidgetContents oldCont = dlg.fillContentsFromTreeWidget(treeWidget: m_treeWidget); |
83 | if (dlg.exec() == QDialog::Accepted) { |
84 | TreeWidgetContents newCont = dlg.contents(); |
85 | if (newCont != oldCont) { |
86 | ChangeTreeContentsCommand *cmd = new ChangeTreeContentsCommand(m_formWindow); |
87 | cmd->init(treeWidget: m_treeWidget, oldState: oldCont, newState: newCont); |
88 | m_formWindow->commandHistory()->push(cmd); |
89 | } |
90 | } |
91 | } |
92 | |
93 | void TreeWidgetTaskMenu::() |
94 | { |
95 | if (m_editor) |
96 | m_editor->deleteLater(); |
97 | } |
98 | |
99 | QT_END_NAMESPACE |
100 | |