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
5#include "formwindow.h"
6
7// sdk
8#include <QtDesigner/propertysheet.h>
9#include <QtDesigner/qextensionmanager.h>
10#include <qdesigner_propertycommand_p.h>
11
12#include <QtCore/qdebug.h>
13
15
16namespace qdesigner_internal {
17
18FormWindowCursor::FormWindowCursor(FormWindow *fw, QObject *parent)
19 : QObject(parent),
20 m_formWindow(fw)
21{
22 update();
23 connect(fw, &QDesignerFormWindowInterface::changed, this, &FormWindowCursor::update);
24}
25
27
28QDesignerFormWindowInterface *FormWindowCursor::formWindow() const
29{
30 return m_formWindow;
31}
32
33bool FormWindowCursor::movePosition(MoveOperation op, MoveMode mode)
34{
35 if (widgetCount() == 0)
36 return false;
37
38 int iterator = position();
39
40 if (mode == MoveAnchor)
41 m_formWindow->clearSelection(false);
42
43 switch (op) {
44 case Next:
45 ++iterator;
46 if (iterator >= widgetCount())
47 iterator = 0;
48
49 m_formWindow->selectWidget(m_formWindow->widgetAt(iterator), true);
50 return true;
51
52 case Prev:
53 --iterator;
54 if (iterator < 0)
55 iterator = widgetCount() - 1;
56
57 if (iterator < 0)
58 return false;
59
60 m_formWindow->selectWidget(m_formWindow->widgetAt(iterator), true);
61 return true;
62
63 default:
64 return false;
65 }
66}
67
69{
70 const int index = m_formWindow->widgets().indexOf(current());
71 return index == -1 ? 0 : index;
72}
73
74void FormWindowCursor::setPosition(int pos, MoveMode mode)
75{
76 if (!widgetCount())
77 return;
78
79 if (mode == MoveAnchor)
80 m_formWindow->clearSelection(false);
81
82 if (pos >= widgetCount())
83 pos = 0;
84
85 m_formWindow->selectWidget(m_formWindow->widgetAt(pos), true);
86}
87
89{
90 return m_formWindow->currentWidget();
91}
92
94{
95 return !m_formWindow->selectedWidgets().isEmpty();
96}
97
99{
100 int N = m_formWindow->selectedWidgets().size();
101 return N ? N : 1;
102}
103
105{
106 return hasSelection()
107 ? m_formWindow->selectedWidgets().at(index)
108 : m_formWindow->mainContainer();
109}
110
111void FormWindowCursor::update()
112{
113 // ### todo
114}
115
117{
118 return m_formWindow->widgetCount();
119}
120
122{
123 return m_formWindow->widgetAt(index);
124}
125
126void FormWindowCursor::setProperty(const QString &name, const QVariant &value)
127{
128
129 // build selection
130 const int N = selectedWidgetCount();
131 Q_ASSERT(N);
132
133 QObjectList selection;
134 for (int i=0; i<N; ++i)
135 selection.push_back(selectedWidget(i));
136
137
138 SetPropertyCommand* setPropertyCommand = new SetPropertyCommand(m_formWindow);
139 if (setPropertyCommand->init(selection, name, value, current())) {
140 m_formWindow->commandHistory()->push(setPropertyCommand);
141 } else {
142 delete setPropertyCommand;
143 qDebug() << "Unable to set property " << name << '.';
144 }
145}
146
147void FormWindowCursor::setWidgetProperty(QWidget *widget, const QString &name, const QVariant &value)
148{
149 SetPropertyCommand *cmd = new SetPropertyCommand(m_formWindow);
150 if (cmd->init(widget, name, value)) {
151 m_formWindow->commandHistory()->push(cmd);
152 } else {
153 delete cmd;
154 qDebug() << "Unable to set property " << name << '.';
155 }
156}
157
158void FormWindowCursor::resetWidgetProperty(QWidget *widget, const QString &name)
159{
160 ResetPropertyCommand *cmd = new ResetPropertyCommand(m_formWindow);
161 if (cmd->init(widget, name)) {
162 m_formWindow->commandHistory()->push(cmd);
163 } else {
164 delete cmd;
165 qDebug() << "Unable to reset property " << name << '.';
166 }
167}
168
169}
170
171QT_END_NAMESPACE
friend class QWidget
Definition qpainter.h:421
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:128
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.