Okular

form.cpp
1 /*
2  SPDX-FileCopyrightText: 2007 Pino Toscano <[email protected]>
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 
15 using namespace Okular;
16 
17 FormFieldPrivate::FormFieldPrivate(FormField::FieldType type)
18  : m_type(type)
19  , m_activateAction(nullptr)
20  , q_ptr(nullptr)
21 {
22 }
23 
24 FormFieldPrivate::~FormFieldPrivate()
25 {
26  delete m_activateAction;
27  qDeleteAll(m_additionalActions);
28  qDeleteAll(m_additionalAnnotActions);
29 }
30 
31 void FormFieldPrivate::setDefault()
32 {
33  m_default = value();
34 }
35 
36 FormField::FormField(FormFieldPrivate &dd)
37  : d_ptr(&dd)
38 {
39  d_ptr->q_ptr = this;
40 }
41 
42 FormField::~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 
80 Action *FormField::activationAction() const
81 {
82  Q_D(const FormField);
83  return d->m_activateAction;
84 }
85 
86 void FormField::setActivationAction(Action *action)
87 {
88  Q_D(FormField);
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 
99 void 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 
112 void 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 
119 QList<Action *> FormField::additionalActions() const
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 
132 class Okular::FormFieldButtonPrivate : public Okular::FormFieldPrivate
133 {
134 public:
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 
155 FormFieldButton::FormFieldButton()
156  : FormField(*new FormFieldButtonPrivate())
157 {
158 }
159 
160 FormFieldButton::~FormFieldButton()
161 {
162 }
163 
165 {
166 }
167 
169 {
170 }
171 
172 class Okular::FormFieldTextPrivate : public Okular::FormFieldPrivate
173 {
174 public:
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 
195 FormFieldText::FormFieldText()
196  : FormField(*new FormFieldTextPrivate())
197 {
198 }
199 
200 FormFieldText::~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 
224 {
226 }
227 
229 {
230  return false;
231 }
232 
233 class Okular::FormFieldChoicePrivate : public Okular::FormFieldPrivate
234 {
235 public:
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 : qAsConst(choices)) {
268  }
269  return list.join(QStringLiteral(";"));
270  }
271 
272  QMap<QString, QString> exportValues;
273 };
274 
275 FormFieldChoice::FormFieldChoice()
276  : FormField(*new FormFieldChoicePrivate())
277 {
278 }
279 
280 FormFieldChoice::~FormFieldChoice()
281 {
282 }
283 
285 {
286  return false;
287 }
288 
290 {
291  return false;
292 }
293 
295 {
296 }
297 
299 {
300  return QString();
301 }
302 
304 {
305 }
306 
308 {
310 }
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 
329 class Okular::FormFieldSignaturePrivate : public Okular::FormFieldPrivate
330 {
331 public:
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 
350 FormFieldSignature::FormFieldSignature()
351  : FormField(*new FormFieldSignaturePrivate())
352 {
353 }
354 
355 FormFieldSignature::~FormFieldSignature()
356 {
357 }
void append(const T &value)
typedef Alignment
Collector for all the data belonging to a page.
Definition: page.h:47
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
The base interface of a form field.
Definition: form.h:39
virtual void setCurrentChoices(const QList< int > &choices)
Sets the selected choices to choices .
Definition: form.cpp:294
virtual bool isRichText() const
Whether this text field should allow rich text.
Definition: form.cpp:213
virtual bool canBeSpellChecked() const
Whether the text inserted manually in the field (where possible) can be spell-checked.
Definition: form.cpp:312
QString number(int n, int base)
Interface of a button form field.
Definition: form.h:197
The documentation to the global Okular namespace.
Definition: action.h:16
Type type(const QSqlDatabase &db)
virtual void setText(const QString &text)
Sets the new text in the text field.
Definition: form.cpp:204
virtual void setEditChoice(const QString &text)
Sets the text entered into an editable combo box choice field.
Definition: form.cpp:303
Encapsulates data that describes an action.
Definition: action.h:40
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
AdditionalActionType
Describes the type of additional actions.
Definition: annotations.h:190
Interface of a choice form field.
Definition: form.h:347
virtual void setPrintable(bool value)
Set this field printable.
Definition: form.cpp:76
virtual bool isEditable() const
Whether this ComboBox is editable, ie the user can type in a custom value.
Definition: form.cpp:284
virtual bool isReadOnly() const
Whether the field is read-only.
Definition: form.cpp:53
KIOFILEWIDGETS_EXPORT QStringList list(const QString &fileClass)
virtual void setReadOnly(bool value)
Whether the field is read-only.
Definition: form.cpp:58
virtual bool multiSelect() const
Whether more than one choice of this ListBox can be selected at the same time.
Definition: form.cpp:289
virtual void setIcon(Okular::FormField *field)
Sets the icon of the Button to the Icon of the field parameter.
Definition: form.cpp:168
virtual void setVisible(bool value)
Whether the field is visible.
Definition: form.cpp:67
virtual Qt::Alignment textAlignment() const
The alignment of the text within the field.
Definition: form.cpp:307
SkipEmptyParts
virtual bool canBeSpellChecked() const
Whether the text inserted manually in the field (where possible) can be spell-checked.
Definition: form.cpp:228
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
bool isEmpty() const const
Interface of a text form field.
Definition: form.h:260
QString join(const QString &separator) const const
virtual void setState(bool state)
Sets the state of the button to the new state .
Definition: form.cpp:164
virtual bool isPassword() const
Whether this text field is a password input, eg its text must be replaced with asterisks.
Definition: form.cpp:208
void setExportValues(const QMap< QString, QString > &values)
The possible choices of the choice field.
Definition: form.cpp:317
virtual Qt::Alignment textAlignment() const
The alignment of the text within the field.
Definition: form.cpp:223
Page * page() const
Returns the page of this form field.
Definition: form.cpp:126
QList::iterator begin()
FieldType type() const
The type of the field.
Definition: form.cpp:47
QList::iterator end()
Interface of a signature form field.
Definition: form.h:454
QString exportValueForChoice(const QString &choice) const
Returns the export value for a given choice.
Definition: form.cpp:323
virtual bool isPrintable() const
Whether this field is printable.
Definition: form.cpp:71
AdditionalActionType
Describes the type of form additional action.
Definition: form.h:139
QVector< V > values(const QMultiHash< K, V > &c)
Q_D(Todo)
virtual QString editChoice() const
The text entered into an editable combo box choice field.
Definition: form.cpp:298
virtual bool isVisible() const
Whether this form field is visible.
Definition: form.cpp:62
FieldType
The types of form field.
Definition: form.h:50
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 04:06:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.