[poppler] 4 commits - qt4/src

Pino Toscano pino at kemper.freedesktop.org
Wed Feb 27 02:54:04 PST 2008


 qt4/src/poppler-document.cc          |    4 +-
 qt4/src/poppler-optcontent-private.h |   55 +++++++++++++++++++++++++++++++++--
 qt4/src/poppler-optcontent.cc        |   33 ++++++++++-----------
 qt4/src/poppler-optcontent.h         |   50 -------------------------------
 qt4/src/poppler-private.h            |    6 +--
 5 files changed, 75 insertions(+), 73 deletions(-)

New commits:
commit f17dd5539501a996479b903ac9b8aceb3c4cfafe
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 11:53:32 2008 +0100

    cleanup

diff --git a/qt4/src/poppler-optcontent-private.h b/qt4/src/poppler-optcontent-private.h
index 705220e..2462f2a 100644
--- a/qt4/src/poppler-optcontent-private.h
+++ b/qt4/src/poppler-optcontent-private.h
@@ -24,7 +24,8 @@
 
 #include <QtCore/QString>
 
-#include "goo/GooList.h"
+class Array;
+class OptionalContentGroup;
 
 namespace Poppler
 {
diff --git a/qt4/src/poppler-optcontent.h b/qt4/src/poppler-optcontent.h
index 833059c..81dd412 100644
--- a/qt4/src/poppler-optcontent.h
+++ b/qt4/src/poppler-optcontent.h
@@ -21,11 +21,8 @@
 #define POPPLER_OPTCONTENT_H
 
 #include <QtCore/QAbstractListModel>
-#include <QtCore/QStringList>
 
-class OptionalContentGroup;
 class OCGs;
-class Array;
 
 namespace Poppler
 {
@@ -55,6 +52,7 @@ namespace Poppler
     Qt::ItemFlags flags ( const QModelIndex & index ) const;
 
     private:
+    friend class OptContentModelPrivate;
     OptContentModelPrivate *d;
   };
 }
commit f3cc894559f10dbd4277fa9f30de9931ed69dfd4
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 11:43:34 2008 +0100

    OptContentModel::itemFromRef() and OptContentItem are private API.
    
    Hide them in the implementation.

diff --git a/qt4/src/poppler-optcontent-private.h b/qt4/src/poppler-optcontent-private.h
index 1cdafa6..705220e 100644
--- a/qt4/src/poppler-optcontent-private.h
+++ b/qt4/src/poppler-optcontent-private.h
@@ -22,6 +22,8 @@
 
 #include "poppler-optcontent.h"
 
+#include <QtCore/QString>
+
 #include "goo/GooList.h"
 
 namespace Poppler
@@ -38,6 +40,38 @@ namespace Poppler
     QList<OptContentItem*> itemsInGroup;
   };
 
+  class OptContentItem
+  {
+    public:
+    enum ItemState { On, Off, HeadingOnly };
+
+    OptContentItem( OptionalContentGroup *group );
+    OptContentItem( const QString &label );
+    OptContentItem();
+    ~OptContentItem();
+
+    QString name() const { return m_name; }
+    ItemState state() const { return m_state; }
+    bool setState( ItemState state );
+
+    QList<OptContentItem*> childList() { return m_children; }
+
+    void setParent( OptContentItem* parent) { m_parent = parent; }
+    OptContentItem* parent() { return m_parent; }
+
+    void addChild( OptContentItem *child );
+
+    void appendRBGroup( RadioButtonGroup *rbgroup );
+
+    private:
+    OptionalContentGroup *m_group;
+    QString m_name;
+    ItemState m_state; // true for ON, false for OFF
+    QList<OptContentItem*> m_children;
+    OptContentItem *m_parent;
+    QList<RadioButtonGroup*> m_rbGroups;
+  };
+
   class OptContentModelPrivate
   {
     public:
@@ -47,6 +81,15 @@ namespace Poppler
     void parseRBGroupsArray( Array *rBGroupArray );
     OptContentItem *nodeFromIndex( const QModelIndex &index ) const;
 
+    /**
+       Get the OptContentItem corresponding to a given reference value.
+
+       \param ref the reference number (e.g. from Object.getRefNum()) to look up
+
+       \return the matching optional content item, or null if the reference wasn't found
+    */
+    OptContentItem *itemFromRef( const QString &ref ) const;
+
     OptContentModel *q;
 
     QMap<QString, OptContentItem*> m_optContentItems;
diff --git a/qt4/src/poppler-optcontent.cc b/qt4/src/poppler-optcontent.cc
index 79b96f4..10a571d 100644
--- a/qt4/src/poppler-optcontent.cc
+++ b/qt4/src/poppler-optcontent.cc
@@ -37,7 +37,7 @@ namespace Poppler
       if ( ! ref.isRef() ) {
 	qDebug() << "expected ref, but got:" << ref.getType();
       }
-      OptContentItem *item = ocModel->q->itemFromRef( QString::number(ref.getRefNum() ) );
+      OptContentItem *item = ocModel->itemFromRef( QString::number(ref.getRefNum() ) );
       itemsInGroup.append( item );
     }
     for (int i = 0; i < itemsInGroup.size(); ++i) {
@@ -345,12 +345,12 @@ namespace Poppler
     parent->addChild( child );
   }
 
-  OptContentItem* OptContentModel::itemFromRef( const QString &ref ) const
+  OptContentItem* OptContentModelPrivate::itemFromRef( const QString &ref ) const
   {
-    if ( ! d->m_optContentItems.contains( ref ) ) {
+    if ( !m_optContentItems.contains( ref ) ) {
       return 0;
     }
-    return d->m_optContentItems[ ref ];
+    return m_optContentItems[ ref ];
   }
 
   OptContentItem* OptContentModelPrivate::nodeFromIndex( const QModelIndex &index ) const
diff --git a/qt4/src/poppler-optcontent.h b/qt4/src/poppler-optcontent.h
index 03f1252..833059c 100644
--- a/qt4/src/poppler-optcontent.h
+++ b/qt4/src/poppler-optcontent.h
@@ -32,39 +32,6 @@ namespace Poppler
   class OptContentItem;
   class OptContentModel;
   class OptContentModelPrivate;
-  class RadioButtonGroup;
-
-  class OptContentItem
-  {
-    public:
-    enum ItemState { On, Off, HeadingOnly };
-
-    OptContentItem( OptionalContentGroup *group );
-    OptContentItem( const QString &label );
-    OptContentItem();
-    ~OptContentItem();
-
-    QString name() const { return m_name; };
-    ItemState state() const { return m_state; };
-    bool setState( ItemState state );
-
-    QList<OptContentItem*> childList() { return m_children; };
-
-    void setParent( OptContentItem* parent) { m_parent = parent; };
-    OptContentItem* parent() { return m_parent; };
-
-    void addChild( OptContentItem *child );
-
-    void appendRBGroup( RadioButtonGroup *rbgroup );
-
-    private:
-    OptionalContentGroup *m_group;
-    QString m_name;
-    ItemState m_state; // true for ON, false for OFF
-    QList<OptContentItem*> m_children;
-    OptContentItem *m_parent;
-    QList<RadioButtonGroup*> m_rbGroups;
-  };
 
   class OptContentModel : public QAbstractItemModel
   {
@@ -87,15 +54,6 @@ namespace Poppler
 
     Qt::ItemFlags flags ( const QModelIndex & index ) const;
 
-    /**
-       Get the OptContentItem corresponding to a given reference value.
-
-       \param ref the reference number (e.g. from Object.getRefNum()) to look up
-
-       \return the matching optional content item, or null if the reference wasn't found
-    */
-    OptContentItem *itemFromRef( const QString &ref ) const;
-
     private:
     OptContentModelPrivate *d;
   };
commit 48e8b2105cf8f177ca655b969470e45e2407db82
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 11:28:16 2008 +0100

    move all the private stuff of OptContentModel into its d-pointer

diff --git a/qt4/src/poppler-optcontent-private.h b/qt4/src/poppler-optcontent-private.h
index b805f34..1cdafa6 100644
--- a/qt4/src/poppler-optcontent-private.h
+++ b/qt4/src/poppler-optcontent-private.h
@@ -30,7 +30,7 @@ namespace Poppler
   class RadioButtonGroup
   {
   public:
-    RadioButtonGroup( OptContentModel *ocModel, Array *rbarray);
+    RadioButtonGroup( OptContentModelPrivate *ocModel, Array *rbarray);
     ~RadioButtonGroup();
     void setItemOn( OptContentItem *itemToSetOn );
 
@@ -41,9 +41,14 @@ namespace Poppler
   class OptContentModelPrivate
   {
     public:
-    OptContentModelPrivate( OCGs *optContent );
+    OptContentModelPrivate( OptContentModel *qq, OCGs *optContent );
     ~OptContentModelPrivate();
 
+    void parseRBGroupsArray( Array *rBGroupArray );
+    OptContentItem *nodeFromIndex( const QModelIndex &index ) const;
+
+    OptContentModel *q;
+
     QMap<QString, OptContentItem*> m_optContentItems;
     QList<RadioButtonGroup*> m_rbgroups;
     OptContentItem *m_rootNode;
diff --git a/qt4/src/poppler-optcontent.cc b/qt4/src/poppler-optcontent.cc
index c7b48c3..79b96f4 100644
--- a/qt4/src/poppler-optcontent.cc
+++ b/qt4/src/poppler-optcontent.cc
@@ -29,7 +29,7 @@
 namespace Poppler
 {
 
-  RadioButtonGroup::RadioButtonGroup( OptContentModel *ocModel, Array *rbarray )
+  RadioButtonGroup::RadioButtonGroup( OptContentModelPrivate *ocModel, Array *rbarray )
   {
     for (int i = 0; i < rbarray->getLength(); ++i) {
       Object ref;
@@ -37,7 +37,7 @@ namespace Poppler
       if ( ! ref.isRef() ) {
 	qDebug() << "expected ref, but got:" << ref.getType();
       }
-      OptContentItem *item = ocModel->itemFromRef( QString::number(ref.getRefNum() ) );
+      OptContentItem *item = ocModel->q->itemFromRef( QString::number(ref.getRefNum() ) );
       itemsInGroup.append( item );
     }
     for (int i = 0; i < itemsInGroup.size(); ++i) {
@@ -121,7 +121,8 @@ namespace Poppler
     child->setParent( this );
   }
 
-  OptContentModelPrivate::OptContentModelPrivate( OCGs *optContent )
+  OptContentModelPrivate::OptContentModelPrivate( OptContentModel *qq, OCGs *optContent )
+    : q(qq)
   {
     m_rootNode = new OptContentItem();
     GooList *ocgs = optContent->getOCGs();
@@ -187,7 +188,7 @@ namespace Poppler
     }
   }
 
-  void OptContentModel::parseRBGroupsArray( Array *rBGroupArray )
+  void OptContentModelPrivate::parseRBGroupsArray( Array *rBGroupArray )
   {
     if (! rBGroupArray) {
       return;
@@ -202,7 +203,7 @@ namespace Poppler
       }
       Array *rbarray = rbObj.getArray();
       RadioButtonGroup *rbg = new RadioButtonGroup( this, rbarray );
-      d->m_rbgroups.append( rbg );
+      m_rbgroups.append( rbg );
       rbObj.free();
     }
   }
@@ -210,9 +211,9 @@ namespace Poppler
   OptContentModel::OptContentModel( OCGs *optContent, QObject *parent)
     : QAbstractItemModel(parent)
   {
-    d = new OptContentModelPrivate( optContent );
+    d = new OptContentModelPrivate( this, optContent );
 
-    parseRBGroupsArray( optContent->getRBGroupsArray() );
+    d->parseRBGroupsArray( optContent->getRBGroupsArray() );
   }
 
   OptContentModel::~OptContentModel()
@@ -233,13 +234,13 @@ namespace Poppler
       return QModelIndex();
     }
 
-    OptContentItem *parentNode = nodeFromIndex( parent );
+    OptContentItem *parentNode = d->nodeFromIndex( parent );
     return createIndex( row, column, parentNode->childList()[row] );
   }
 
   QModelIndex OptContentModel::parent(const QModelIndex &child) const
   {
-    OptContentItem *childNode = nodeFromIndex( child );
+    OptContentItem *childNode = d->nodeFromIndex( child );
     if (!childNode) {
       return QModelIndex();
     }
@@ -257,7 +258,7 @@ namespace Poppler
  
   int OptContentModel::rowCount(const QModelIndex &parent) const
   {
-    OptContentItem *parentNode = nodeFromIndex( parent );
+    OptContentItem *parentNode = d->nodeFromIndex( parent );
     if (!parentNode) {
       return 0;
     } else {
@@ -277,7 +278,7 @@ namespace Poppler
       return QVariant();
     }
 
-    OptContentItem *node = nodeFromIndex( index );
+    OptContentItem *node = d->nodeFromIndex( index );
     if (!node) {
       return QVariant();
     }
@@ -299,7 +300,7 @@ namespace Poppler
 
   bool OptContentModel::setData ( const QModelIndex & index, const QVariant & value, int role )
   {
-    OptContentItem *node = nodeFromIndex( index );
+    OptContentItem *node = d->nodeFromIndex( index );
     if (!node) {
       return false;
     }
@@ -352,12 +353,12 @@ namespace Poppler
     return d->m_optContentItems[ ref ];
   }
 
-  OptContentItem* OptContentModel::nodeFromIndex( const QModelIndex &index ) const
+  OptContentItem* OptContentModelPrivate::nodeFromIndex( const QModelIndex &index ) const
   {
     if (index.isValid()) {
       return static_cast<OptContentItem *>(index.internalPointer());
     } else {
-      return d->m_rootNode;
+      return m_rootNode;
     }
   }
 }
diff --git a/qt4/src/poppler-optcontent.h b/qt4/src/poppler-optcontent.h
index d1c2aa1..03f1252 100644
--- a/qt4/src/poppler-optcontent.h
+++ b/qt4/src/poppler-optcontent.h
@@ -97,10 +97,6 @@ namespace Poppler
     OptContentItem *itemFromRef( const QString &ref ) const;
 
     private:
-    void parseRBGroupsArray( Array *rBGroupArray );
-
-    OptContentItem *nodeFromIndex( const QModelIndex &index ) const;
-
     OptContentModelPrivate *d;
   };
 }
commit b78a7f7a0e8d5a9c22014d34754090d863030e0d
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 11:06:57 2008 +0100

    use a QPointer for the OptContentModel, so we are safe about ownership.

diff --git a/qt4/src/poppler-document.cc b/qt4/src/poppler-document.cc
index 6e353cb..e18ea8b 100644
--- a/qt4/src/poppler-document.cc
+++ b/qt4/src/poppler-document.cc
@@ -472,10 +472,10 @@ namespace Poppler {
 
     OptContentModel *Document::optionalContentModel()
     {
-        if (!m_doc->m_optContentModel) {
+        if (m_doc->m_optContentModel.isNull()) {
 	    m_doc->m_optContentModel = new OptContentModel(m_doc->doc->getOptContentConfig(), 0);
 	}
-	return (m_doc->m_optContentModel);
+        return (OptContentModel *)m_doc->m_optContentModel;
     }
 
     QDateTime convertDate( char *dateString )
diff --git a/qt4/src/poppler-private.h b/qt4/src/poppler-private.h
index e663312..6b88009 100644
--- a/qt4/src/poppler-private.h
+++ b/qt4/src/poppler-private.h
@@ -23,6 +23,7 @@
 #ifndef _POPPLER_PRIVATE_H_
 #define _POPPLER_PRIVATE_H_
 
+#include <QtCore/QPointer>
 #include <QtCore/QVariant>
 #include <QtCore/QVector>
 
@@ -110,8 +111,7 @@ namespace Poppler {
 	~DocumentData()
 	{
 		qDeleteAll(m_embeddedFiles);
-		delete m_optContentModel;
-		m_optContentModel = 0;
+		delete (OptContentModel *)m_optContentModel;
 		delete doc;
 		delete m_outputDev;
 		delete m_fontInfoScanner;
@@ -257,7 +257,7 @@ namespace Poppler {
 	Document::RenderBackend m_backend;
 	OutputDev *m_outputDev;
 	QList<EmbeddedFile*> m_embeddedFiles;
-	OptContentModel *m_optContentModel;
+	QPointer<OptContentModel> m_optContentModel;
 	QColor paperColor;
 	int m_hints;
 	static int count;


More information about the poppler mailing list