Okular

form.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Pino Toscano <pino@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "form.h"
8#include "form_p.h"
9
10// qt includes
11#include <QVariant>
12
13#include "action.h"
14
15using namespace Okular;
16
17FormFieldPrivate::FormFieldPrivate(FormField::FieldType type)
18 : m_type(type)
19 , m_activateAction(nullptr)
20 , q_ptr(nullptr)
21{
22}
23
24FormFieldPrivate::~FormFieldPrivate()
25{
26 delete m_activateAction;
27 qDeleteAll(m_additionalActions);
28 qDeleteAll(m_additionalAnnotActions);
29}
30
31void FormFieldPrivate::setDefault()
32{
33 m_default = value();
34}
35
36FormField::FormField(FormFieldPrivate &dd)
37 : d_ptr(&dd)
38{
39 d_ptr->q_ptr = this;
40}
41
42FormField::~FormField()
43{
44 delete d_ptr;
45}
46
48{
49 Q_D(const FormField);
50 return d->m_type;
51}
52
54{
55 return false;
56}
57
59{
60}
61
63{
64 return true;
65}
66
68{
69}
70
72{
73 return true;
74}
75
77{
78}
79
80Action *FormField::activationAction() const
81{
82 Q_D(const FormField);
83 return d->m_activateAction;
84}
85
86void FormField::setActivationAction(Action *action)
87{
89 delete d->m_activateAction;
90 d->m_activateAction = action;
91}
92
94{
95 Q_D(const FormField);
96 return d->m_additionalActions.value(type);
97}
98
99void FormField::setAdditionalAction(AdditionalActionType type, Action *action)
100{
101 Q_D(FormField);
102 delete d->m_additionalActions.value(type);
103 d->m_additionalActions[type] = action;
104}
105
107{
108 Q_D(const FormField);
109 return d->m_additionalAnnotActions.value(type);
110}
111
112void FormField::setAdditionalAction(Annotation::AdditionalActionType type, Action *action)
113{
114 Q_D(FormField);
115 delete d->m_additionalAnnotActions.value(type);
116 d->m_additionalAnnotActions[type] = action;
117}
118
120{
121 Q_D(const FormField);
122 // yes, calling values() is not great but it's a list of ~10 elements, we can live with that
123 return d->m_additionalAnnotActions.values() + d->m_additionalActions.values(); // clazy:exclude=container-anti-pattern
124}
125
127{
128 Q_D(const FormField);
129 return d->m_page;
130}
131
132class Okular::FormFieldButtonPrivate : public Okular::FormFieldPrivate
133{
134public:
135 FormFieldButtonPrivate()
136 : FormFieldPrivate(FormField::FormButton)
137 {
138 }
139
140 Q_DECLARE_PUBLIC(FormFieldButton)
141
142 void setValue(const QString &v) override
143 {
144 Q_Q(FormFieldButton);
145 q->setState(QVariant(v).toBool());
146 }
147
148 QString value() const override
149 {
150 Q_Q(const FormFieldButton);
151 return QVariant::fromValue<bool>(q->state()).toString();
152 }
153};
154
155FormFieldButton::FormFieldButton()
156 : FormField(*new FormFieldButtonPrivate())
157{
158}
159
160FormFieldButton::~FormFieldButton()
161{
162}
163
165{
166}
167
171
172class Okular::FormFieldTextPrivate : public Okular::FormFieldPrivate
173{
174public:
175 FormFieldTextPrivate()
176 : FormFieldPrivate(FormField::FormText)
177 {
178 }
179
180 Q_DECLARE_PUBLIC(FormFieldText)
181
182 void setValue(const QString &v) override
183 {
184 Q_Q(FormFieldText);
185 q->setText(v);
186 }
187
188 QString value() const override
189 {
190 Q_Q(const FormFieldText);
191 return q->text();
192 }
193};
194
195FormFieldText::FormFieldText()
196 : FormField(*new FormFieldTextPrivate())
197{
198}
199
200FormFieldText::~FormFieldText()
201{
202}
203
205{
206}
207
209{
210 return false;
211}
212
214{
215 return false;
216}
217
219{
220 return -1;
221}
222
227
229{
230 return false;
231}
232
233class Okular::FormFieldChoicePrivate : public Okular::FormFieldPrivate
234{
235public:
236 FormFieldChoicePrivate()
237 : FormFieldPrivate(FormField::FormChoice)
238 {
239 }
240
241 Q_DECLARE_PUBLIC(FormFieldChoice)
242
243 void setValue(const QString &v) override
244 {
245 Q_Q(FormFieldChoice);
246 const QStringList choices = v.split(QLatin1Char(';'), Qt::SkipEmptyParts);
247 QList<int> newchoices;
248 for (const QString &str : choices) {
249 bool ok = true;
250 int val = str.toInt(&ok);
251 if (ok) {
252 newchoices.append(val);
253 }
254 }
255 if (!newchoices.isEmpty()) {
256 q->setCurrentChoices(newchoices);
257 }
258 }
259
260 QString value() const override
261 {
262 Q_Q(const FormFieldChoice);
263 QList<int> choices = q->currentChoices();
264 std::sort(choices.begin(), choices.end());
266 for (const int c : std::as_const(choices)) {
268 }
269 return list.join(QStringLiteral(";"));
270 }
271
272 QMap<QString, QString> exportValues;
273};
274
275FormFieldChoice::FormFieldChoice()
276 : FormField(*new FormFieldChoicePrivate())
277{
278}
279
280FormFieldChoice::~FormFieldChoice()
281{
282}
283
285{
286 return false;
287}
288
290{
291 return false;
292}
293
297
299{
300 return QString();
301}
302
306
311
313{
314 return false;
315}
316
318{
320 d->exportValues = values;
321}
322
324{
325 Q_D(const FormFieldChoice);
326 return d->exportValues.value(choice, choice);
327}
328
329class Okular::FormFieldSignaturePrivate : public Okular::FormFieldPrivate
330{
331public:
332 FormFieldSignaturePrivate()
333 : FormFieldPrivate(FormField::FormSignature)
334 {
335 }
336
337 Q_DECLARE_PUBLIC(FormFieldSignature)
338
339 void setValue(const QString &v) override
340 {
341 Q_UNUSED(v)
342 }
343
344 QString value() const override
345 {
346 return QString();
347 }
348};
349
350FormFieldSignature::FormFieldSignature()
351 : FormField(*new FormFieldSignaturePrivate())
352{
353}
354
355FormFieldSignature::~FormFieldSignature()
356{
357}
Encapsulates data that describes an action.
Definition action.h:41
AdditionalActionType
Describes the type of additional actions.
Interface of a button form field.
Definition form.h:198
virtual void setState(bool state)
Sets the state of the button to the new state .
Definition form.cpp:164
virtual void setIcon(Okular::FormField *field)
Sets the icon of the Button to the Icon of the field parameter.
Definition form.cpp:168
Interface of a choice form field.
Definition form.h:348
virtual void setCurrentChoices(const QList< int > &choices)
Sets the selected choices to choices .
Definition form.cpp:294
QString exportValueForChoice(const QString &choice) const
Returns the export value for a given choice.
Definition form.cpp:323
virtual void setEditChoice(const QString &text)
Sets the text entered into an editable combo box choice field.
Definition form.cpp:303
virtual QString editChoice() const
The text entered into an editable combo box choice field.
Definition form.cpp:298
virtual Qt::Alignment textAlignment() const
The alignment of the text within the field.
Definition form.cpp:307
virtual bool multiSelect() const
Whether more than one choice of this ListBox can be selected at the same time.
Definition form.cpp:289
void setExportValues(const QMap< QString, QString > &values)
The possible choices of the choice field.
Definition form.cpp:317
virtual bool isEditable() const
Whether this ComboBox is editable, ie the user can type in a custom value.
Definition form.cpp:284
virtual bool canBeSpellChecked() const
Whether the text inserted manually in the field (where possible) can be spell-checked.
Definition form.cpp:312
Interface of a signature form field.
Definition form.h:455
Interface of a text form field.
Definition form.h:261
virtual bool isPassword() const
Whether this text field is a password input, eg its text must be replaced with asterisks.
Definition form.cpp:208
virtual Qt::Alignment textAlignment() const
The alignment of the text within the field.
Definition form.cpp:223
virtual bool isRichText() const
Whether this text field should allow rich text.
Definition form.cpp:213
virtual int maximumLength() const
The maximum length allowed for the text of text field, or -1 if there is no limitation for the text.
Definition form.cpp:218
virtual void setText(const QString &text)
Sets the new text in the text field.
Definition form.cpp:204
virtual bool canBeSpellChecked() const
Whether the text inserted manually in the field (where possible) can be spell-checked.
Definition form.cpp:228
The base interface of a form field.
Definition form.h:40
virtual bool isReadOnly() const
Whether the field is read-only.
Definition form.cpp:53
Action * additionalAction(AdditionalActionType type) const
Returns the additional action of the given type or nullptr if no action has been defined.
Definition form.cpp:93
AdditionalActionType
Describes the type of form additional action.
Definition form.h:139
virtual void setPrintable(bool value)
Set this field printable.
Definition form.cpp:76
virtual void setVisible(bool value)
Whether the field is visible.
Definition form.cpp:67
virtual bool isPrintable() const
Whether this field is printable.
Definition form.cpp:71
FieldType
The types of form field.
Definition form.h:50
FieldType type() const
The type of the field.
Definition form.cpp:47
virtual void setReadOnly(bool value)
Whether the field is read-only.
Definition form.cpp:58
Page * page() const
Returns the page of this form field.
Definition form.cpp:126
virtual bool isVisible() const
Whether this form field is visible.
Definition form.cpp:62
QList< Action * > additionalActions() const
Returns all the additional actions for this form.
Definition form.cpp:119
Collector for all the data belonging to a page.
Definition page.h:48
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
global.h
Definition action.h:17
void append(QList< T > &&value)
iterator begin()
iterator end()
bool isEmpty() const const
QString number(double n, char format, int precision)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString join(QChar separator) const const
typedef Alignment
SkipEmptyParts
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:48:49 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.