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
formwindowcursor.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
6#include "formwindow.h"
7
8// sdk
9#include <QtDesigner/propertysheet.h>
10#include <QtDesigner/qextensionmanager.h>
11#include <qdesigner_propertycommand_p.h>
12
13#include <QtCore/qdebug.h>
14
16
17namespace qdesigner_internal {
18
19FormWindowCursor::FormWindowCursor(FormWindow *fw, QObject *parent)
20 : QObject(parent),
21 m_formWindow(fw)
22{
23 update();
24 connect(fw, &QDesignerFormWindowInterface::changed, this, &FormWindowCursor::update);
25}
26
28
29QDesignerFormWindowInterface *FormWindowCursor::formWindow() const
30{
31 return m_formWindow;
32}
33
34bool FormWindowCursor::movePosition(MoveOperation op, MoveMode mode)
35{
36 if (widgetCount() == 0)
37 return false;
38
39 int iterator = position();
40
41 if (mode == MoveAnchor)
42 m_formWindow->clearSelection(false);
43
44 switch (op) {
45 case Next:
46 ++iterator;
47 if (iterator >= widgetCount())
48 iterator = 0;
49
50 m_formWindow->selectWidget(m_formWindow->widgetAt(iterator), true);
51 return true;
52
53 case Prev:
54 --iterator;
55 if (iterator < 0)
56 iterator = widgetCount() - 1;
57
58 if (iterator < 0)
59 return false;
60
61 m_formWindow->selectWidget(m_formWindow->widgetAt(iterator), true);
62 return true;
63
64 default:
65 return false;
66 }
67}
68
70{
71 const int index = m_formWindow->widgets().indexOf(current());
72 return index == -1 ? 0 : index;
73}
74
75void FormWindowCursor::setPosition(int pos, MoveMode mode)
76{
77 if (!widgetCount())
78 return;
79
80 if (mode == MoveAnchor)
81 m_formWindow->clearSelection(false);
82
83 if (pos >= widgetCount())
84 pos = 0;
85
86 m_formWindow->selectWidget(m_formWindow->widgetAt(pos), true);
87}
88
90{
91 return m_formWindow->currentWidget();
92}
93
95{
96 return !m_formWindow->selectedWidgets().isEmpty();
97}
98
100{
101 int N = m_formWindow->selectedWidgets().size();
102 return N ? N : 1;
103}
104
106{
107 return hasSelection()
108 ? m_formWindow->selectedWidgets().at(index)
109 : m_formWindow->mainContainer();
110}
111
112void FormWindowCursor::update()
113{
114 // ### todo
115}
116
118{
119 return m_formWindow->widgetCount();
120}
121
123{
124 return m_formWindow->widgetAt(index);
125}
126
127void FormWindowCursor::setProperty(const QString &name, const QVariant &value)
128{
129
130 // build selection
131 const int N = selectedWidgetCount();
132 Q_ASSERT(N);
133
134 QObjectList selection;
135 for (int i=0; i<N; ++i)
136 selection.push_back(selectedWidget(i));
137
138
139 SetPropertyCommand* setPropertyCommand = new SetPropertyCommand(m_formWindow);
140 if (setPropertyCommand->init(selection, name, value, current())) {
141 m_formWindow->commandHistory()->push(setPropertyCommand);
142 } else {
143 delete setPropertyCommand;
144 qDebug() << "Unable to set property " << name << '.';
145 }
146}
147
148void FormWindowCursor::setWidgetProperty(QWidget *widget, const QString &name, const QVariant &value)
149{
150 SetPropertyCommand *cmd = new SetPropertyCommand(m_formWindow);
151 if (cmd->init(widget, name, value)) {
152 m_formWindow->commandHistory()->push(cmd);
153 } else {
154 delete cmd;
155 qDebug() << "Unable to set property " << name << '.';
156 }
157}
158
159void FormWindowCursor::resetWidgetProperty(QWidget *widget, const QString &name)
160{
161 ResetPropertyCommand *cmd = new ResetPropertyCommand(m_formWindow);
162 if (cmd->init(widget, name)) {
163 m_formWindow->commandHistory()->push(cmd);
164 } else {
165 delete cmd;
166 qDebug() << "Unable to reset property " << name << '.';
167 }
168}
169
170}
171
172QT_END_NAMESPACE
friend class QWidget
Definition qpainter.h:432
void setProperty(const QString &name, const QVariant &value) override
Sets the property with the given name for the currently selected widget to the specified value.
QWidget * current() const override
Returns the currently selected widget in the form window.
int position() const override
Returns the cursor position.
void setPosition(int pos, MoveMode mode) override
Sets the position of the cursor to the given position using the mode to specify how it is moved there...
void resetWidgetProperty(QWidget *widget, const QString &name) override
Resets the property with the given name for the specified widget to its default value.
int selectedWidgetCount() const override
Returns the number of selected widgets in the form window.
QWidget * selectedWidget(int index) const override
Returns the widget with the given index in the list of selected widgets.
QWidget * widget(int index) const override
Returns the widget with the given index in the list of widgets in the form window.
bool hasSelection() const override
Returns true if the form window contains a selection; otherwise returns false.
bool movePosition(MoveOperation op, MoveMode mode) override
Performs the given operation on the cursor using the specified mode, and returns true if it completed...
int widgetCount() const override
Returns the number of widgets in the form window.
QDesignerFormWindowInterface * formWindow() const override
Returns the form window interface associated with this cursor interface.
void setWidgetProperty(QWidget *widget, const QString &name, const QVariant &value) override
Sets the property with the given name for the given widget to the specified value.
QWidget * mainContainer() const override
Returns the main container widget for the form window.
QWidget * currentWidget() const
void clearSelection(bool changePropertyDisplay=true) override
Clears the current selection in the form window.
QWidget * widgetAt(int index) const
Definition formwindow.h:129
void selectWidget(QWidget *w, bool select=true) override
If select is true, the given widget is selected; otherwise the widget is deselected.
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.