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 "default_container.h"
30#include <QtCore/qdebug.h>
31
32QT_BEGIN_NAMESPACE
33
34template <class Container>
35static inline void setCurrentContainerIndex(int index, Container *container)
36{
37 const bool blocked = container->signalsBlocked();
38 container->blockSignals(true);
39 container->setCurrentIndex(index);
40 container->blockSignals(blocked);
41}
42
43static inline void ensureNoParent(QWidget *widget)
44{
45 if (widget->parentWidget())
46 widget->setParent(nullptr);
47}
48
49static const char *PageLabel = "Page";
50
51namespace qdesigner_internal {
52
53// --------- QStackedWidgetContainer
54QStackedWidgetContainer::QStackedWidgetContainer(QStackedWidget *widget, QObject *parent) :
55 QObject(parent),
56 m_widget(widget)
57{
58}
59
60void QStackedWidgetContainer::setCurrentIndex(int index)
61{
62 setCurrentContainerIndex(index, container: m_widget);
63}
64
65void QStackedWidgetContainer::addWidget(QWidget *widget)
66{
67 ensureNoParent(widget);
68 m_widget->addWidget(w: widget);
69}
70
71void QStackedWidgetContainer::insertWidget(int index, QWidget *widget)
72{
73 ensureNoParent(widget);
74 m_widget->insertWidget(index, w: widget);
75}
76
77void QStackedWidgetContainer::remove(int index)
78{
79 m_widget->removeWidget(w: widget(index));
80}
81
82// --------- QTabWidgetContainer
83QTabWidgetContainer::QTabWidgetContainer(QTabWidget *widget, QObject *parent) :
84 QObject(parent),
85 m_widget(widget)
86{
87}
88
89void QTabWidgetContainer::setCurrentIndex(int index)
90{
91 setCurrentContainerIndex(index, container: m_widget);
92}
93
94void QTabWidgetContainer::addWidget(QWidget *widget)
95{
96 ensureNoParent(widget);
97 m_widget->addTab(widget, QString::fromUtf8(str: PageLabel));
98}
99
100void QTabWidgetContainer::insertWidget(int index, QWidget *widget)
101{
102 ensureNoParent(widget);
103 m_widget->insertTab(index, widget, QString::fromUtf8(str: PageLabel));
104}
105
106void QTabWidgetContainer::remove(int index)
107{
108 m_widget->removeTab(index);
109}
110
111// ------------------- QToolBoxContainer
112QToolBoxContainer::QToolBoxContainer(QToolBox *widget, QObject *parent) :
113 QObject(parent),
114 m_widget(widget)
115{
116}
117
118void QToolBoxContainer::setCurrentIndex(int index)
119{
120 setCurrentContainerIndex(index, container: m_widget);
121}
122
123void QToolBoxContainer::addWidget(QWidget *widget)
124{
125 ensureNoParent(widget);
126 m_widget->addItem(item: widget, text: QString::fromUtf8(str: PageLabel));
127}
128
129void QToolBoxContainer::insertWidget(int index, QWidget *widget)
130{
131 ensureNoParent(widget);
132 m_widget->insertItem(index, item: widget, text: QString::fromUtf8(str: PageLabel));
133}
134
135void QToolBoxContainer::remove(int index)
136{
137 m_widget->removeItem(index);
138}
139
140// ------------------- QScrollAreaContainer
141// We pass on active=true only if there are no children yet.
142// If there are children, it is a legacy custom widget QScrollArea that has an internal,
143// unmanaged child, in which case we deactivate the extension (otherwise we crash).
144// The child will then not show up in the task menu
145
146QScrollAreaContainer::QScrollAreaContainer(QScrollArea *widget, QObject *parent) :
147 QObject(parent),
148 SingleChildContainer<QScrollArea>(widget, widget->widget() == nullptr)
149{
150}
151// ------------------- QDockWidgetContainer
152QDockWidgetContainer::QDockWidgetContainer(QDockWidget *widget, QObject *parent) :
153 QObject(parent),
154 SingleChildContainer<QDockWidget>(widget)
155{
156}
157
158}
159
160QT_END_NAMESPACE
161

source code of qttools/src/designer/src/components/formeditor/default_container.cpp