| 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 | |
| 4 | #include "treewidget_taskmenu.h" |
| 5 | #include "treewidgeteditor.h" |
| 6 | |
| 7 | #include <QtDesigner/abstractformwindow.h> |
| 8 | |
| 9 | #include <QtWidgets/qstyle.h> |
| 10 | #include <QtWidgets/qlineedit.h> |
| 11 | #include <QtWidgets/qstyleoption.h> |
| 12 | |
| 13 | #include <QtGui/qaction.h> |
| 14 | |
| 15 | #include <QtCore/qcoreevent.h> |
| 16 | #include <QtCore/qvariant.h> |
| 17 | #include <QtCore/qdebug.h> |
| 18 | |
| 19 | QT_BEGIN_NAMESPACE |
| 20 | |
| 21 | namespace qdesigner_internal { |
| 22 | |
| 23 | TreeWidgetTaskMenu::(QTreeWidget *button, QObject *parent) |
| 24 | : QDesignerTaskMenu(button, parent), |
| 25 | m_treeWidget(button), |
| 26 | m_editItemsAction(new QAction(tr(s: "Edit Items..." ), this)) |
| 27 | { |
| 28 | connect(sender: m_editItemsAction, signal: &QAction::triggered, context: this, slot: &TreeWidgetTaskMenu::editItems); |
| 29 | m_taskActions.append(t: m_editItemsAction); |
| 30 | |
| 31 | QAction *sep = new QAction(this); |
| 32 | sep->setSeparator(true); |
| 33 | m_taskActions.append(t: sep); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | TreeWidgetTaskMenu::() = default; |
| 38 | |
| 39 | QAction *TreeWidgetTaskMenu::() const |
| 40 | { |
| 41 | return m_editItemsAction; |
| 42 | } |
| 43 | |
| 44 | QList<QAction*> TreeWidgetTaskMenu::() const |
| 45 | { |
| 46 | return m_taskActions + QDesignerTaskMenu::taskActions(); |
| 47 | } |
| 48 | |
| 49 | void TreeWidgetTaskMenu::() |
| 50 | { |
| 51 | m_formWindow = QDesignerFormWindowInterface::findFormWindow(w: m_treeWidget); |
| 52 | if (m_formWindow.isNull()) |
| 53 | return; |
| 54 | |
| 55 | Q_ASSERT(m_treeWidget != nullptr); |
| 56 | |
| 57 | TreeWidgetEditorDialog dlg(m_formWindow, m_treeWidget->window()); |
| 58 | TreeWidgetContents oldCont = dlg.fillContentsFromTreeWidget(treeWidget: m_treeWidget); |
| 59 | if (dlg.exec() == QDialog::Accepted) { |
| 60 | TreeWidgetContents newCont = dlg.contents(); |
| 61 | if (newCont != oldCont) { |
| 62 | ChangeTreeContentsCommand *cmd = new ChangeTreeContentsCommand(m_formWindow); |
| 63 | cmd->init(treeWidget: m_treeWidget, oldState: oldCont, newState: newCont); |
| 64 | m_formWindow->commandHistory()->push(cmd); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | void TreeWidgetTaskMenu::() |
| 70 | { |
| 71 | if (m_editor) |
| 72 | m_editor->deleteLater(); |
| 73 | } |
| 74 | |
| 75 | } // namespace qdesigner_internal |
| 76 | |
| 77 | QT_END_NAMESPACE |
| 78 | |