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
12#include "grid_p.h"
16
17#include <QtDesigner/abstractformeditor.h>
18#include <QtDesigner/container.h>
19#include <QtDesigner/qextensionmanager.h>
20#include <QtDesigner/taskmenu.h>
21#include <QtDesigner/abstractintegration.h>
22
23#include <QtWidgets/qmenu.h>
24#include <QtWidgets/qlistwidget.h>
25#include <QtWidgets/qtreewidget.h>
26#include <QtWidgets/qtablewidget.h>
27#include <QtWidgets/qcombobox.h>
28#include <QtWidgets/qtabwidget.h>
29#include <QtWidgets/qtoolbox.h>
30#include <QtWidgets/qtoolbar.h>
31#include <QtWidgets/qstatusbar.h>
32#include <QtWidgets/qmenu.h>
33#include <QtWidgets/qlabel.h>
34
35#include <QtGui/qaction.h>
36
37#include <QtCore/qdebug.h>
38#include <QtCore/qhash.h>
39#include <QtCore/qlist.h>
40#include <QtCore/qset.h>
41#include <QtCore/qtimer.h>
42
44
45using namespace Qt::StringLiterals;
46
47namespace qdesigner_internal {
48
70
85
87
98
115
120
125
130
135
141
150
161
163{
166 // already connected
167 return;
168 }
170}
171
173{
176 // still need to be connected
177 return;
178 }
180}
181
183{
184 // qobject_cast<QDesignerPropertySheet *>(object)
185 // will fail since the destructor of QDesignerPropertySheet
186 // has already finished
187
188 for (auto it = m_d->m_reloadableResources.begin();
189 it != m_d->m_reloadableResources.end(); ++it) {
190 if (it.key() == object) {
192 break;
193 }
194 }
195
196 for (auto it = m_d->m_reloadablePropertySheets.begin();
198 if (it.key() == object) {
200 break;
201 }
202 }
203}
204
206{
207 pixmapCache()->clear();
208 iconCache()->clear();
211 for (int index : it.value()) {
213 if (qobject_cast<QLabel *>(sheet->object()) && sheet->propertyName(index) == "text"_L1) {
215 // optimize a bit, reset only if the text value might contain a reference to qt resources
216 // (however reloading of icons other than taken from resources might not work here)
217 if (newString.value().contains(":/"_L1)) {
220 }
221 }
223 }
225 const int count = tabWidget->count();
226 const int current = tabWidget->currentIndex();
227 const QString currentTabIcon = u"currentTabIcon"_s;
228 for (int i = 0; i < count; i++) {
230 const int index = sheet->indexOf(currentTabIcon);
232 }
234 } else if (QToolBox *toolBox = qobject_cast<QToolBox *>(sheet->object())) {
235 const int count = toolBox->count();
236 const int current = toolBox->currentIndex();
237 const QString currentItemIcon = u"currentItemIcon"_s;
238 for (int i = 0; i < count; i++) {
240 const int index = sheet->indexOf(currentItemIcon);
242 }
244 }
245 }
248 }
249}
250
261
263{
265 if (m_d->m_hasFormGrid)
267 return rc;
268}
269
277
279{
280 return QPoint(m_d->m_grid.deltaX(), m_d->m_grid.deltaY());
281}
282
284{
287}
288
290{
291 return f & m_d->m_feature;
292}
293
295{
296 w->update();
297
298 for (auto *child : w->children()) {
299 if (QWidget *w = qobject_cast<QWidget*>(child))
300 recursiveUpdate(w);
301 }
302}
303
314
319
321{
322 return m_d->m_grid.visible() && currentTool() == 0;
323}
324
329
334
336{
337 if (m_d->m_grid.snapX() || m_d->m_grid.snapY())
339 else
341}
342
344{
345 m_d->m_grid = grid;
347 recursiveUpdate(this);
348}
349
351{
352 return m_d->m_grid;
353}
354
356{
357 return m_d->m_hasFormGrid;
358}
359
361{
363}
364
369
374
376{
377 return nullptr;
378}
379
380// Widget under mouse for finding the Widget to highlight
381// when doing DnD. Restricts to pages by geometry if a container with
382// a container extension (or one of its helper widgets) is hit; otherwise
383// returns the widget as such (be it managed/unmanaged)
384
386{
387 // widget_under_mouse might be some temporary thing like the dropLine. We need
388 // the actual widget that's part of the edited GUI.
390 if (!rc || qobject_cast<ConnectionEdit*>(rc))
391 return nullptr;
392
393 if (rc == mainContainer()) {
394 // Refuse main container areas if the main container has a container extension,
395 // for example when hitting QToolBox/QTabWidget empty areas.
397 return nullptr;
398 return rc;
399 }
400
401 // If we hit on container extension type container, make sure
402 // we use the top-most current page
403 if (QWidget *container = findContainer(rc, false))
405 // For container that do not have a "stacked" nature (QToolBox, QMdiArea),
406 // make sure the position is within the current page
407 const int ci = c->currentIndex();
408 if (ci < 0)
409 return nullptr;
410 QWidget *page = c->widget(ci);
414 return nullptr;
415 return page;
416 }
417
418 return rc;
419}
420
422{
423 // We need a macro here even for single widgets because the some components (for example,
424 // the signal slot editor are connected to widgetRemoved() and add their
425 // own commands (for example, to delete w's connections)
426 const QString description = widget_list.size() == 1 ?
427 tr("Delete '%1'").arg(widget_list.constFirst()->objectName()) : tr("Delete");
428
430 for (QWidget *w : std::as_const(widget_list)) {
433 cmd->init(w);
435 }
437}
438
440{
441 using ActionList = QList<QAction *>;
443 // 1) Standard public extension
447 if (const auto *intTaskMenu = qobject_cast<QDesignerTaskMenuExtension *>(em->extension(o, u"QDesignerInternalTaskMenuExtension"_s))) {
448 if (!actions.isEmpty()) {
449 QAction *a = new QAction(fw);
450 a->setSeparator(true);
452 }
454 }
455 if (actions.isEmpty())
456 return nullptr;
458 QAction *a = new QAction(fw);
459 a->setSeparator(true);
461 }
462 QMenu *rc = new QMenu;
463 for (auto *a : std::as_const(actions))
464 rc->addAction(a);
465 return rc;
466}
467
472
477
482
487
492
497
502
504{
507}
508
513
518
523
528
530{
532}
533
538
540{
541 if (!mainContainer())
542 return QStringList(tr("Invalid form"));
543 // Test for non-laid toplevel spacers, which will not be saved
544 // as not to throw off uic.
546 const auto &spacers = mainContainer()->findChildren<Spacer *>();
547 for (const Spacer *spacer : spacers) {
548 if (spacer->parentWidget() && !spacer->parentWidget()->layout()) {
549 problems.push_back(tr("<p>This file contains top level spacers.<br/>"
550 "They will <b>not</b> be saved.</p><p>"
551 "Perhaps you forgot to create a layout?</p>"));
552 break;
553 }
554 }
555 return problems;
556}
557
558} // namespace qdesigner_internal
559
560QT_END_NAMESPACE
friend class QWidget
Definition qpainter.h:431
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)
Auxiliary methods to store/retrieve settings.
static void recursiveUpdate(QWidget *w)