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
formwindowbase.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// Qt-Security score:significant reason:default
4
13#include "grid_p.h"
17
18#include <QtDesigner/abstractformeditor.h>
19#include <QtDesigner/container.h>
20#include <QtDesigner/qextensionmanager.h>
21#include <QtDesigner/taskmenu.h>
22#include <QtDesigner/abstractintegration.h>
23
24#include <QtWidgets/qmenu.h>
25#include <QtWidgets/qlistwidget.h>
26#include <QtWidgets/qtreewidget.h>
27#include <QtWidgets/qtablewidget.h>
28#include <QtWidgets/qcombobox.h>
29#include <QtWidgets/qtabwidget.h>
30#include <QtWidgets/qtoolbox.h>
31#include <QtWidgets/qtoolbar.h>
32#include <QtWidgets/qstatusbar.h>
33#include <QtWidgets/qmenu.h>
34#include <QtWidgets/qlabel.h>
35
36#include <QtGui/qaction.h>
37
38#include <QtCore/qdebug.h>
39#include <QtCore/qhash.h>
40#include <QtCore/qlist.h>
41#include <QtCore/qset.h>
42#include <QtCore/qtimer.h>
43
45
46using namespace Qt::StringLiterals;
47
48namespace qdesigner_internal {
49
71
86
88
99
116
121
126
131
136
142
151
162
164{
167 // already connected
168 return;
169 }
171}
172
174{
177 // still need to be connected
178 return;
179 }
181}
182
184{
185 // qobject_cast<QDesignerPropertySheet *>(object)
186 // will fail since the destructor of QDesignerPropertySheet
187 // has already finished
188
189 for (auto it = m_d->m_reloadableResources.begin();
190 it != m_d->m_reloadableResources.end(); ++it) {
191 if (it.key() == object) {
193 break;
194 }
195 }
196
197 for (auto it = m_d->m_reloadablePropertySheets.begin();
199 if (it.key() == object) {
201 break;
202 }
203 }
204}
205
207{
208 pixmapCache()->clear();
209 iconCache()->clear();
212 for (int index : it.value()) {
214 if (qobject_cast<QLabel *>(sheet->object()) && sheet->propertyName(index) == "text"_L1) {
216 // optimize a bit, reset only if the text value might contain a reference to qt resources
217 // (however reloading of icons other than taken from resources might not work here)
218 if (newString.value().contains(":/"_L1)) {
221 }
222 }
224 }
226 const int count = tabWidget->count();
227 const int current = tabWidget->currentIndex();
228 const QString currentTabIcon = u"currentTabIcon"_s;
229 for (int i = 0; i < count; i++) {
231 const int index = sheet->indexOf(currentTabIcon);
233 }
235 } else if (QToolBox *toolBox = qobject_cast<QToolBox *>(sheet->object())) {
236 const int count = toolBox->count();
237 const int current = toolBox->currentIndex();
238 const QString currentItemIcon = u"currentItemIcon"_s;
239 for (int i = 0; i < count; i++) {
241 const int index = sheet->indexOf(currentItemIcon);
243 }
245 }
246 }
249 }
250}
251
262
264{
266 if (m_d->m_hasFormGrid)
268 return rc;
269}
270
278
280{
281 return QPoint(m_d->m_grid.deltaX(), m_d->m_grid.deltaY());
282}
283
285{
288}
289
291{
292 return f & m_d->m_feature;
293}
294
296{
297 w->update();
298
299 for (auto *child : w->children()) {
300 if (QWidget *w = qobject_cast<QWidget*>(child))
301 recursiveUpdate(w);
302 }
303}
304
315
320
322{
323 return m_d->m_grid.visible() && currentTool() == 0;
324}
325
330
335
337{
338 if (m_d->m_grid.snapX() || m_d->m_grid.snapY())
340 else
342}
343
345{
346 m_d->m_grid = grid;
348 recursiveUpdate(this);
349}
350
352{
353 return m_d->m_grid;
354}
355
357{
358 return m_d->m_hasFormGrid;
359}
360
362{
364}
365
370
375
377{
378 return nullptr;
379}
380
381// Widget under mouse for finding the Widget to highlight
382// when doing DnD. Restricts to pages by geometry if a container with
383// a container extension (or one of its helper widgets) is hit; otherwise
384// returns the widget as such (be it managed/unmanaged)
385
387{
388 // widget_under_mouse might be some temporary thing like the dropLine. We need
389 // the actual widget that's part of the edited GUI.
391 if (!rc || qobject_cast<ConnectionEdit*>(rc))
392 return nullptr;
393
394 if (rc == mainContainer()) {
395 // Refuse main container areas if the main container has a container extension,
396 // for example when hitting QToolBox/QTabWidget empty areas.
398 return nullptr;
399 return rc;
400 }
401
402 // If we hit on container extension type container, make sure
403 // we use the top-most current page
404 if (QWidget *container = findContainer(rc, false))
406 // For container that do not have a "stacked" nature (QToolBox, QMdiArea),
407 // make sure the position is within the current page
408 const int ci = c->currentIndex();
409 if (ci < 0)
410 return nullptr;
411 QWidget *page = c->widget(ci);
415 return nullptr;
416 return page;
417 }
418
419 return rc;
420}
421
423{
424 // We need a macro here even for single widgets because the some components (for example,
425 // the signal slot editor are connected to widgetRemoved() and add their
426 // own commands (for example, to delete w's connections)
427 const QString description = widget_list.size() == 1 ?
428 tr("Delete '%1'").arg(widget_list.constFirst()->objectName()) : tr("Delete");
429
431 for (QWidget *w : std::as_const(widget_list)) {
434 cmd->init(w);
436 }
438}
439
441{
442 using ActionList = QList<QAction *>;
444 // 1) Standard public extension
448 if (const auto *intTaskMenu = qobject_cast<QDesignerTaskMenuExtension *>(em->extension(o, u"QDesignerInternalTaskMenuExtension"_s))) {
449 if (!actions.isEmpty()) {
450 QAction *a = new QAction(fw);
451 a->setSeparator(true);
453 }
455 }
456 if (actions.isEmpty())
457 return nullptr;
459 QAction *a = new QAction(fw);
460 a->setSeparator(true);
462 }
463 QMenu *rc = new QMenu;
464 for (auto *a : std::as_const(actions))
465 rc->addAction(a);
466 return rc;
467}
468
473
478
483
488
493
498
503
505{
508}
509
514
519
524
529
531{
533}
534
539
541{
542 if (!mainContainer())
543 return QStringList(tr("Invalid form"));
544 // Test for non-laid toplevel spacers, which will not be saved
545 // as not to throw off uic.
547 const auto &spacers = mainContainer()->findChildren<Spacer *>();
548 for (const Spacer *spacer : spacers) {
549 if (spacer->parentWidget() && !spacer->parentWidget()->layout()) {
550 problems.push_back(tr("<p>This file contains top level spacers.<br/>"
551 "They will <b>not</b> be saved.</p><p>"
552 "Perhaps you forgot to create a layout?</p>"));
553 break;
554 }
555 }
556 return problems;
557}
558
559} // namespace qdesigner_internal
560
561QT_END_NAMESPACE
friend class QWidget
Definition qpainter.h:432
FormWindowBase::LineTerminatorMode m_lineTerminatorMode
QHash< QDesignerPropertySheet *, QObject * > m_reloadablePropertySheets
QHash< QDesignerPropertySheet *, QSet< int > > m_reloadableResources
QDesignerFormWindowInterface::Feature m_feature
FormWindowBase::ResourceFileSaveMode m_saveResourcesBehaviour
FormWindowBasePrivate(QDesignerFormEditorInterface *core)
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
static void recursiveUpdate(QWidget *w)