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 "tablewidget_taskmenu.h"
30#include "tablewidgeteditor.h"
31
32#include <QtDesigner/abstractformwindow.h>
33
34#include <QtWidgets/qtablewidget.h>
35#include <QtWidgets/qaction.h>
36#include <QtWidgets/qlineedit.h>
37#include <QtWidgets/qstyle.h>
38#include <QtWidgets/qstyleoption.h>
39
40#include <QtCore/qcoreevent.h>
41#include <QtCore/qvariant.h>
42#include <QtCore/qdebug.h>
43
44QT_BEGIN_NAMESPACE
45
46using namespace qdesigner_internal;
47
48TableWidgetTaskMenu::TableWidgetTaskMenu(QTableWidget *button, QObject *parent)
49 : QDesignerTaskMenu(button, parent),
50 m_tableWidget(button),
51 m_editItemsAction(new QAction(tr(s: "Edit Items..."), this))
52{
53 connect(sender: m_editItemsAction, signal: &QAction::triggered, receiver: this, slot: &TableWidgetTaskMenu::editItems);
54 m_taskActions.append(t: m_editItemsAction);
55
56 QAction *sep = new QAction(this);
57 sep->setSeparator(true);
58 m_taskActions.append(t: sep);
59}
60
61
62TableWidgetTaskMenu::~TableWidgetTaskMenu() = default;
63
64QAction *TableWidgetTaskMenu::preferredEditAction() const
65{
66 return m_editItemsAction;
67}
68
69QList<QAction*> TableWidgetTaskMenu::taskActions() const
70{
71 return m_taskActions + QDesignerTaskMenu::taskActions();
72}
73
74void TableWidgetTaskMenu::editItems()
75{
76 m_formWindow = QDesignerFormWindowInterface::findFormWindow(w: m_tableWidget);
77 if (m_formWindow.isNull())
78 return;
79
80 Q_ASSERT(m_tableWidget != nullptr);
81
82 TableWidgetEditorDialog dlg(m_formWindow, m_tableWidget->window());
83 TableWidgetContents oldCont = dlg.fillContentsFromTableWidget(tableWidget: m_tableWidget);
84 if (dlg.exec() == QDialog::Accepted) {
85 TableWidgetContents newCont = dlg.contents();
86 if (newCont != oldCont) {
87 ChangeTableContentsCommand *cmd = new ChangeTableContentsCommand(m_formWindow);
88 cmd->init(tableWidget: m_tableWidget, oldCont, newCont);
89 m_formWindow->commandHistory()->push(cmd);
90 }
91 }
92}
93
94void TableWidgetTaskMenu::updateSelection()
95{
96 if (m_editor)
97 m_editor->deleteLater();
98}
99
100QT_END_NAMESPACE
101

source code of qttools/src/designer/src/components/taskmenu/tablewidget_taskmenu.cpp