[poppler] glib/poppler-form-field.cc poppler/Annot.cc poppler/Form.cc poppler/Form.h qt5/src

Albert Astals Cid aacid at kemper.freedesktop.org
Thu Apr 5 10:28:44 UTC 2018


 glib/poppler-form-field.cc |    6 +++---
 poppler/Annot.cc           |    4 ++--
 poppler/Form.cc            |   18 +++++++++---------
 poppler/Form.h             |   32 ++++++++++++++++----------------
 qt5/src/poppler-form.cc    |    3 ++-
 5 files changed, 32 insertions(+), 31 deletions(-)

New commits:
commit 2bf6f2275c49f94e84f935653d6c42f6b5f9b364
Author: Albert Astals Cid <albert.astals.cid at kdab.com>
Date:   Thu Apr 5 12:21:38 2018 +0200

    Make some Form methods const

diff --git a/glib/poppler-form-field.cc b/glib/poppler-form-field.cc
index a6cb8209..b5b15995 100644
--- a/glib/poppler-form-field.cc
+++ b/glib/poppler-form-field.cc
@@ -360,7 +360,7 @@ gchar *
 poppler_form_field_text_get_text (PopplerFormField *field)
 {
   FormWidgetText *text_field;
-  GooString      *tmp;
+  const GooString *tmp;
 
   g_return_val_if_fail (field->widget->getType () == formText, NULL);
 
@@ -571,7 +571,7 @@ gchar *
 poppler_form_field_choice_get_item (PopplerFormField *field,
 				    gint              index)
 {
-  GooString *tmp;
+  const GooString *tmp;
   
   g_return_val_if_fail (field->widget->getType () == formChoice, NULL);
   g_return_val_if_fail (index >= 0 && index < poppler_form_field_choice_get_n_items (field), NULL);
@@ -682,7 +682,7 @@ poppler_form_field_choice_set_text (PopplerFormField *field,
 gchar *
 poppler_form_field_choice_get_text (PopplerFormField *field)
 {
-  GooString *tmp;
+  const GooString *tmp;
   
   g_return_val_if_fail (field->widget->getType () == formChoice, NULL);
 
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index e79b6174..dc07f880 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -4787,7 +4787,7 @@ void AnnotWidget::drawFormFieldButton(GfxResources *resources, GooString *da) {
 
 void AnnotWidget::drawFormFieldText(GfxResources *resources, GooString *da) {
   VariableTextQuadding quadding;
-  GooString *contents;
+  const GooString *contents;
   FormFieldText *fieldText = static_cast<FormFieldText *>(field);
 
   contents = fieldText->getContent();
@@ -4804,7 +4804,7 @@ void AnnotWidget::drawFormFieldText(GfxResources *resources, GooString *da) {
 }
 
 void AnnotWidget::drawFormFieldChoice(GfxResources *resources, GooString *da) {
-  GooString *selected;
+  const GooString *selected;
   VariableTextQuadding quadding;
   FormFieldChoice *fieldChoice = static_cast<FormFieldChoice *>(field);
 
diff --git a/poppler/Form.cc b/poppler/Form.cc
index d1677c19..8e6ca9a4 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -267,7 +267,7 @@ FormWidgetText::FormWidgetText (PDFDoc *docA, Object *aobj, unsigned num, Ref re
   type = formText;
 }
 
-GooString* FormWidgetText::getContent ()
+const GooString* FormWidgetText::getContent () const
 {
   return parent()->getContent();
 }
@@ -353,7 +353,7 @@ FormWidgetChoice::~FormWidgetChoice()
 {
 }
 
-bool FormWidgetChoice::_checkRange (int i)
+bool FormWidgetChoice::_checkRange (int i) const
 {
   if (i < 0 || i >= parent()->getNumChoices()) {
     error(errInternal, -1, "FormWidgetChoice::_checkRange i out of range : {0:d}", i);
@@ -379,7 +379,7 @@ void FormWidgetChoice::deselectAll ()
   parent()->deselectAll();
 }
 
-GooString* FormWidgetChoice::getEditChoice ()
+const GooString* FormWidgetChoice::getEditChoice () const
 {
   if (!hasEdit()) {
     error(errInternal, -1, "FormFieldChoice::getEditChoice called on a non-editable choice\n");
@@ -394,7 +394,7 @@ void FormWidgetChoice::updateWidgetAppearance()
     widget->updateAppearanceStream();
 }
 
-bool FormWidgetChoice::isSelected (int i)
+bool FormWidgetChoice::isSelected (int i) const
 {
   if (!_checkRange(i)) return false;
   return parent()->isSelected(i);
@@ -410,12 +410,12 @@ void FormWidgetChoice::setEditChoice (GooString* new_content)
   parent()->setEditChoice(new_content);
 }
 
-int FormWidgetChoice::getNumChoices() 
+int FormWidgetChoice::getNumChoices() const
 { 
   return parent()->getNumChoices();
 }
 
-GooString* FormWidgetChoice::getChoice(int i) 
+const GooString* FormWidgetChoice::getChoice(int i) const
 { 
   return parent()->getChoice(i);
 }
@@ -1122,7 +1122,7 @@ GBool FormFieldButton::setState(char *state)
   return gTrue;
 }
 
-GBool FormFieldButton::getState(char *state) {
+GBool FormFieldButton::getState(const char *state) const {
   if (appearanceState.isName(state))
     return gTrue;
 
@@ -1579,7 +1579,7 @@ void FormFieldChoice::setEditChoice (GooString* new_content)
   updateSelection();
 }
 
-GooString* FormFieldChoice::getEditChoice ()
+const GooString* FormFieldChoice::getEditChoice () const
 {
   return editedChoice;
 }
@@ -1594,7 +1594,7 @@ int FormFieldChoice::getNumSelected ()
   return cnt;
 }
 
-GooString *FormFieldChoice::getSelectedChoice() {
+const GooString *FormFieldChoice::getSelectedChoice() const {
   if (edit && editedChoice)
     return editedChoice;
 
diff --git a/poppler/Form.h b/poppler/Form.h
index 069f1597..83aaeb03 100644
--- a/poppler/Form.h
+++ b/poppler/Form.h
@@ -195,7 +195,7 @@ class FormWidgetText: public FormWidget {
 public:
   FormWidgetText(PDFDoc *docA, Object *dict, unsigned num, Ref ref, FormField *p);
   //return the field's content (UTF16BE)
-  GooString* getContent() ;
+  const GooString* getContent() const;
   //return a copy of the field's content (UTF16BE)
   GooString* getContentCopy();
 
@@ -230,9 +230,9 @@ public:
   FormWidgetChoice(PDFDoc *docA, Object *dict, unsigned num, Ref ref, FormField *p);
   ~FormWidgetChoice();
 
-  int getNumChoices();
+  int getNumChoices() const;
   //return the display name of the i-th choice (UTF16BE)
-  GooString* getChoice(int i);
+  const GooString* getChoice(int i) const;
   //select the i-th choice
   void select (int i); 
 
@@ -246,10 +246,10 @@ public:
   //only work for editable combo box, set the user-entered text as the current choice
   void setEditChoice(GooString* new_content);
 
-  GooString* getEditChoice ();
+  const GooString* getEditChoice () const;
 
   void updateWidgetAppearance() override;
-  bool isSelected (int i);
+  bool isSelected (int i) const;
 
   bool isCombo () const; 
   bool hasEdit () const; 
@@ -258,7 +258,7 @@ public:
   bool commitOnSelChange () const; 
   bool isListBox () const;
 protected:
-  bool _checkRange (int i);
+  bool _checkRange (int i) const;
   FormFieldChoice *parent() const;
 };
 
@@ -299,7 +299,7 @@ public:
   virtual ~FormField();
 
   // Accessors.
-  FormFieldType getType() { return type; }
+  FormFieldType getType() const { return type; }
   Object* getObj() { return &obj; }
   Ref getRef() { return ref; }
 
@@ -371,13 +371,13 @@ class FormFieldButton: public FormField {
 public:
   FormFieldButton(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents);
 
-  FormButtonType getButtonType () { return btype; }
+  FormButtonType getButtonType () const { return btype; }
 
   bool noToggleToOff () const { return noAllOff; }
 
   // returns gTrue if the state modification is accepted
   GBool setState (char *state);
-  GBool getState(char *state);
+  GBool getState(const char *state) const;
 
   char *getAppearanceState() { return appearanceState.isName() ? appearanceState.getName() : NULL; }
 
@@ -417,7 +417,7 @@ class FormFieldText: public FormField {
 public:
   FormFieldText(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents);
   
-  GooString* getContent () { return content; }
+  const GooString* getContent () const { return content; }
   GooString* getContentCopy ();
   void setContentCopy (GooString* new_content);
   ~FormFieldText();
@@ -467,11 +467,11 @@ public:
 
   ~FormFieldChoice();
 
-  int getNumChoices() { return numChoices; }
-  GooString* getChoice(int i) { return choices ? choices[i].optionName : NULL; }
-  GooString* getExportVal (int i) { return choices ? choices[i].exportVal : NULL; }
+  int getNumChoices() const { return numChoices; }
+  const GooString* getChoice(int i) const { return choices ? choices[i].optionName : NULL; }
+  const GooString* getExportVal (int i) const  { return choices ? choices[i].exportVal : NULL; }
   // For multi-select choices it returns the first one
-  GooString* getSelectedChoice();
+  const GooString* getSelectedChoice() const;
 
   //select the i-th choice
   void select (int i); 
@@ -485,9 +485,9 @@ public:
   //only work for editable combo box, set the user-entered text as the current choice
   void setEditChoice(GooString* new_content);
 
-  GooString* getEditChoice ();
+  const GooString* getEditChoice () const;
 
-  bool isSelected (int i) { return choices[i].selected; }
+  bool isSelected (int i) const { return choices[i].selected; }
 
   int getNumSelected ();
 
diff --git a/qt5/src/poppler-form.cc b/qt5/src/poppler-form.cc
index eee504b3..9c6e119c 100644
--- a/qt5/src/poppler-form.cc
+++ b/qt5/src/poppler-form.cc
@@ -6,6 +6,7 @@
  * Copyright (C) 2016, Hanno Meyer-Thurow <h.mth at web.de>
  * Copyright (C) 2017, Hans-Ulrich Jüttner <huj at froreich-bioscientia.de>
  * Copyright (C) 2018, Andre Heinecke <aheinecke at intevation.de>
+ * Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -311,7 +312,7 @@ FormFieldText::TextType FormFieldText::textType() const
 
 QString FormFieldText::text() const
 {
-  GooString *goo = static_cast<FormWidgetText*>(m_formData->fm)->getContent();
+  const GooString *goo = static_cast<FormWidgetText*>(m_formData->fm)->getContent();
   return UnicodeParsedString(goo);
 }
 


More information about the poppler mailing list