[poppler] 9 commits - qt4/src

Pino Toscano pino at kemper.freedesktop.org
Wed Feb 27 06:59:05 PST 2008


 qt4/src/.gitignore                   |    2 
 qt4/src/Makefile.am                  |   13 ++-
 qt4/src/poppler-optcontent-private.h |    7 +
 qt4/src/poppler-optcontent.cc        |  140 ++++++++++++++++++++++-------------
 qt4/src/poppler-optcontent.h         |    2 
 5 files changed, 104 insertions(+), 60 deletions(-)

New commits:
commit 0f4e7791ab6884072a1aee56e9cec212d8cea263
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 15:58:21 2008 +0100

    ignore any generated .moc here

diff --git a/qt4/src/.gitignore b/qt4/src/.gitignore
index 53c9077..3d124dd 100644
--- a/qt4/src/.gitignore
+++ b/qt4/src/.gitignore
@@ -6,4 +6,4 @@ Makefile
 Makefile.in
 APIDOCS-html
 APIDOCS-latex
-moc_poppler-optcontent.cpp
+*.moc
commit 136ae44f155b17d9e8b041b67f75531d8544337c
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 15:56:09 2008 +0100

    keep track of the items changed when toggling an item, so we can update them properly

diff --git a/qt4/src/poppler-optcontent-private.h b/qt4/src/poppler-optcontent-private.h
index f4a4a08..8261839 100644
--- a/qt4/src/poppler-optcontent-private.h
+++ b/qt4/src/poppler-optcontent-private.h
@@ -35,7 +35,7 @@ namespace Poppler
   public:
     RadioButtonGroup( OptContentModelPrivate *ocModel, Array *rbarray);
     ~RadioButtonGroup();
-    void setItemOn( OptContentItem *itemToSetOn );
+    QSet<OptContentItem *> setItemOn( OptContentItem *itemToSetOn );
 
   private:
     QList<OptContentItem*> itemsInGroup;
@@ -53,7 +53,7 @@ namespace Poppler
 
     QString name() const { return m_name; }
     ItemState state() const { return m_state; }
-    bool setState( ItemState state );
+    bool setState(ItemState state, QSet<OptContentItem *> &changedItems);
 
     QList<OptContentItem*> childList() { return m_children; }
 
diff --git a/qt4/src/poppler-optcontent.cc b/qt4/src/poppler-optcontent.cc
index 905fd62..85aaaf6 100644
--- a/qt4/src/poppler-optcontent.cc
+++ b/qt4/src/poppler-optcontent.cc
@@ -25,6 +25,7 @@
 #include "poppler-private.h"
 
 #include <QtCore/QDebug>
+#include <QtCore/QtAlgorithms>
 
 namespace Poppler
 {
@@ -50,14 +51,18 @@ namespace Poppler
   {
   }
 
-  void RadioButtonGroup::setItemOn( OptContentItem *itemToSetOn )
+  QSet<OptContentItem *> RadioButtonGroup::setItemOn( OptContentItem *itemToSetOn )
   {
+    QSet<OptContentItem *> changedItems;
     for (int i = 0; i < itemsInGroup.size(); ++i) {
       OptContentItem *thisItem = itemsInGroup.at(i);
       if (thisItem != itemToSetOn) {
-	thisItem->setState( OptContentItem::Off );
+        QSet<OptContentItem *> newChangedItems;
+        thisItem->setState(OptContentItem::Off, newChangedItems);
+        changedItems += newChangedItems;
       }
     }
+    return changedItems;
   }
 
 
@@ -97,9 +102,10 @@ namespace Poppler
   }
 
 
-  bool OptContentItem::setState( ItemState state )
+  bool OptContentItem::setState(ItemState state, QSet<OptContentItem *> &changedItems)
   {
     m_state = state;
+    changedItems.insert(this);
     if (!m_group) {
       return false;
     }
@@ -107,7 +113,7 @@ namespace Poppler
       m_group->setState( OptionalContentGroup::On );
       for (int i = 0; i < m_rbGroups.size(); ++i) {
 	RadioButtonGroup *rbgroup = m_rbGroups.at(i);
-	rbgroup->setItemOn( this );
+        changedItems += rbgroup->setItemOn( this );
       }
     } else if ( state == OptContentItem::Off ) {
       m_group->setState( OptionalContentGroup::Off );
@@ -322,14 +328,30 @@ namespace Poppler
         const bool newvalue = value.toBool();
         if (newvalue) {
           if (node->state() != OptContentItem::On) {
-            node->setState(OptContentItem::On);
-            emit dataChanged(index, index);
+            QSet<OptContentItem *> changedItems;
+            node->setState(OptContentItem::On, changedItems);
+            QModelIndexList indexes;
+            Q_FOREACH (OptContentItem *item, changedItems) {
+              indexes.append(d->indexFromItem(item, 0));
+            }
+            qStableSort(indexes);
+            Q_FOREACH (const QModelIndex &changedIndex, indexes) {
+              emit dataChanged(changedIndex, changedIndex);
+            }
             return true;
           }
         } else {
           if (node->state() != OptContentItem::Off) {
-            node->setState(OptContentItem::Off);
-            emit dataChanged(index, index);
+            QSet<OptContentItem *> changedItems;
+            node->setState(OptContentItem::Off, changedItems);
+            QModelIndexList indexes;
+            Q_FOREACH (OptContentItem *item, changedItems) {
+              indexes.append(d->indexFromItem(item, 0));
+            }
+            qStableSort(indexes);
+            Q_FOREACH (const QModelIndex &changedIndex, indexes) {
+              emit dataChanged(changedIndex, changedIndex);
+            }
             return true;
           }
         }
commit b73e2afef7e5e1b68d82a10c94bca3c201c5f8b3
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 15:52:06 2008 +0100

    fix indexFromItem once again, and make parent() call it with the right node

diff --git a/qt4/src/poppler-optcontent-private.h b/qt4/src/poppler-optcontent-private.h
index 42feba4..f4a4a08 100644
--- a/qt4/src/poppler-optcontent-private.h
+++ b/qt4/src/poppler-optcontent-private.h
@@ -81,7 +81,7 @@ namespace Poppler
 
     void parseRBGroupsArray( Array *rBGroupArray );
     OptContentItem *nodeFromIndex(const QModelIndex &index, bool canBeNull = false) const;
-    QModelIndex indexFromItem(OptContentItem *childNode, int column) const;
+    QModelIndex indexFromItem(OptContentItem *node, int column) const;
 
     /**
        Get the OptContentItem corresponding to a given reference value.
diff --git a/qt4/src/poppler-optcontent.cc b/qt4/src/poppler-optcontent.cc
index 42cd1c6..905fd62 100644
--- a/qt4/src/poppler-optcontent.cc
+++ b/qt4/src/poppler-optcontent.cc
@@ -244,24 +244,23 @@ namespace Poppler
   QModelIndex OptContentModel::parent(const QModelIndex &child) const
   {
     OptContentItem *childNode = d->nodeFromIndex( child );
-    return d->indexFromItem(childNode, child.column());
+    if (!childNode) {
+      return QModelIndex();
+    }
+    return d->indexFromItem(childNode->parent(), child.column());
   }
 
-  QModelIndex OptContentModelPrivate::indexFromItem(OptContentItem *childNode, int column) const
+  QModelIndex OptContentModelPrivate::indexFromItem(OptContentItem *node, int column) const
   {
-    if (!childNode) {
+    if (!node) {
       return QModelIndex();
     }
-    OptContentItem *parentNode = childNode->parent();
+    OptContentItem *parentNode = node->parent();
     if (!parentNode) {
       return QModelIndex();
     }
-    OptContentItem *grandparentNode = parentNode->parent();
-    if (!grandparentNode) {
-      return QModelIndex();
-    }
-    int row = grandparentNode->childList().indexOf(parentNode);
-    return q->createIndex(row, column, parentNode);
+    const int row = parentNode->childList().indexOf(node);
+    return q->createIndex(row, column, node);
   }
  
   int OptContentModel::rowCount(const QModelIndex &parent) const
commit 803787f763578320aa5f405ed49c64e6b924bad3
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 15:30:18 2008 +0100

    compile with the autotools
    
    (second patch I forgot to apply with the first)

diff --git a/qt4/src/Makefile.am b/qt4/src/Makefile.am
index c18b166..10310a1 100644
--- a/qt4/src/Makefile.am
+++ b/qt4/src/Makefile.am
@@ -5,6 +5,8 @@ INCLUDES =					\
 	$(FONTCONFIG_CFLAGS)			\
 	$(POPPLER_QT4_CFLAGS)
 
+SUFFIXES: .moc
+
 poppler_includedir = $(includedir)/poppler/qt4
 
 poppler_include_HEADERS =			\
@@ -43,6 +45,7 @@ libpoppler_qt4_la_SOURCES =			\
 	poppler-annotation-private.h		\
 	poppler-converter-private.h		\
 	poppler-qiodeviceoutstream-private.h	\
+	poppler-optcontent-private.h		\
 	poppler-export.h			\
 	poppler-private.h
 
@@ -58,8 +61,8 @@ endif
 
 libpoppler_qt4_la_LDFLAGS = -version-info 2:0:0
 
-# This rule lets GNU make create any moc_*.cpp from the equivalent *.h
-moc_%.cpp: %.h
-	moc $< -o $@
+# This rule lets GNU make create any *.moc from the equivalent *.h
+.h.moc:
+	moc -i $< -o $@
 
 poppler-optcontent.$(OBJEXT): poppler-optcontent.moc
commit 0b527a8ed62677bb09df4587f072a310c2959750
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 14:34:13 2008 +0100

    Extract the OptContentItem -> QModelIndex creation in an own function.

diff --git a/qt4/src/poppler-optcontent-private.h b/qt4/src/poppler-optcontent-private.h
index f8f3aa1..42feba4 100644
--- a/qt4/src/poppler-optcontent-private.h
+++ b/qt4/src/poppler-optcontent-private.h
@@ -81,6 +81,7 @@ namespace Poppler
 
     void parseRBGroupsArray( Array *rBGroupArray );
     OptContentItem *nodeFromIndex(const QModelIndex &index, bool canBeNull = false) const;
+    QModelIndex indexFromItem(OptContentItem *childNode, int column) const;
 
     /**
        Get the OptContentItem corresponding to a given reference value.
diff --git a/qt4/src/poppler-optcontent.cc b/qt4/src/poppler-optcontent.cc
index 59b920d..42cd1c6 100644
--- a/qt4/src/poppler-optcontent.cc
+++ b/qt4/src/poppler-optcontent.cc
@@ -244,6 +244,11 @@ namespace Poppler
   QModelIndex OptContentModel::parent(const QModelIndex &child) const
   {
     OptContentItem *childNode = d->nodeFromIndex( child );
+    return d->indexFromItem(childNode, child.column());
+  }
+
+  QModelIndex OptContentModelPrivate::indexFromItem(OptContentItem *childNode, int column) const
+  {
     if (!childNode) {
       return QModelIndex();
     }
@@ -256,7 +261,7 @@ namespace Poppler
       return QModelIndex();
     }
     int row = grandparentNode->childList().indexOf(parentNode);
-    return createIndex(row, child.column(), parentNode);
+    return q->createIndex(row, column, parentNode);
   }
  
   int OptContentModel::rowCount(const QModelIndex &parent) const
commit c94d6cc95c6838f31e27832cb3090389bf4d8227
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 14:30:26 2008 +0100

    Make index(), data() and setData() more safe.
    
    Errors spotted using ModelTest.

diff --git a/qt4/src/poppler-optcontent-private.h b/qt4/src/poppler-optcontent-private.h
index 2462f2a..f8f3aa1 100644
--- a/qt4/src/poppler-optcontent-private.h
+++ b/qt4/src/poppler-optcontent-private.h
@@ -80,7 +80,7 @@ namespace Poppler
     ~OptContentModelPrivate();
 
     void parseRBGroupsArray( Array *rBGroupArray );
-    OptContentItem *nodeFromIndex( const QModelIndex &index ) const;
+    OptContentItem *nodeFromIndex(const QModelIndex &index, bool canBeNull = false) const;
 
     /**
        Get the OptContentItem corresponding to a given reference value.
diff --git a/qt4/src/poppler-optcontent.cc b/qt4/src/poppler-optcontent.cc
index a36c211..59b920d 100644
--- a/qt4/src/poppler-optcontent.cc
+++ b/qt4/src/poppler-optcontent.cc
@@ -230,12 +230,15 @@ namespace Poppler
 
   QModelIndex OptContentModel::index(int row, int column, const QModelIndex &parent) const
   {
-    if (! d->m_rootNode) {
+    if (row < 0 || column != 0) {
       return QModelIndex();
     }
 
     OptContentItem *parentNode = d->nodeFromIndex( parent );
-    return createIndex( row, column, parentNode->childList()[row] );
+    if (row < parentNode->childList().count()) {
+      return createIndex(row, column, parentNode->childList().at(row));
+    }
+    return QModelIndex();
   }
 
   QModelIndex OptContentModel::parent(const QModelIndex &child) const
@@ -274,7 +277,7 @@ namespace Poppler
 
   QVariant OptContentModel::data(const QModelIndex &index, int role) const
   {
-    OptContentItem *node = d->nodeFromIndex( index );
+    OptContentItem *node = d->nodeFromIndex(index, true);
     if (!node) {
       return QVariant();
     }
@@ -304,7 +307,7 @@ namespace Poppler
 
   bool OptContentModel::setData ( const QModelIndex & index, const QVariant & value, int role )
   {
-    OptContentItem *node = d->nodeFromIndex( index );
+    OptContentItem *node = d->nodeFromIndex(index, true);
     if (!node) {
       return false;
     }
@@ -360,12 +363,12 @@ namespace Poppler
     return m_optContentItems[ ref ];
   }
 
-  OptContentItem* OptContentModelPrivate::nodeFromIndex( const QModelIndex &index ) const
+  OptContentItem* OptContentModelPrivate::nodeFromIndex(const QModelIndex &index, bool canBeNull) const
   {
     if (index.isValid()) {
       return static_cast<OptContentItem *>(index.internalPointer());
     } else {
-      return m_rootNode;
+      return canBeNull ? 0 : m_rootNode;
     }
   }
 }
commit b8e833733d84eaa93d6bae522710feb3075ca329
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 14:05:19 2008 +0100

    fix build with the autotools

diff --git a/qt4/src/Makefile.am b/qt4/src/Makefile.am
index cd9af86..c18b166 100644
--- a/qt4/src/Makefile.am
+++ b/qt4/src/Makefile.am
@@ -28,7 +28,7 @@ libpoppler_qt4_la_SOURCES =			\
 	poppler-annotation.cc			\
 	poppler-link-extractor.cc		\
 	poppler-optcontent.cc			\
-	moc_poppler-optcontent.cpp		\
+	poppler-optcontent.h			\
 	../../qt/poppler-page-transition.cc	\
 	poppler-sound.cc			\
 	poppler-form.cc				\
@@ -61,3 +61,5 @@ libpoppler_qt4_la_LDFLAGS = -version-info 2:0:0
 # This rule lets GNU make create any moc_*.cpp from the equivalent *.h
 moc_%.cpp: %.h
 	moc $< -o $@
+
+poppler-optcontent.$(OBJEXT): poppler-optcontent.moc
commit f89ba474bae281f1cdeddb72ac8425dee1087e35
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 13:28:50 2008 +0100

    Put the check states of the optional contents in the same column as the name.
    
    This feels a bit more elegant than changing a value in a different column.
    Cleanup data()/setData() so they can be extended easily.

diff --git a/qt4/src/poppler-optcontent.cc b/qt4/src/poppler-optcontent.cc
index c3522df..a36c211 100644
--- a/qt4/src/poppler-optcontent.cc
+++ b/qt4/src/poppler-optcontent.cc
@@ -268,31 +268,35 @@ namespace Poppler
 
   int OptContentModel::columnCount(const QModelIndex &parent) const
   {
-    return 2;
+    return 1;
   }
 
 
   QVariant OptContentModel::data(const QModelIndex &index, int role) const
   {
-    if ( (role != Qt::DisplayRole) && (role != Qt::EditRole) ) {
-      return QVariant();
-    }
-
     OptContentItem *node = d->nodeFromIndex( index );
     if (!node) {
       return QVariant();
     }
 
-    if (index.column() == 0) {
-      return node->name();
-    } else if (index.column() == 1) {
-      if ( node->state() == OptContentItem::On ) {
-	return true;
-      } else if ( node->state() == OptContentItem::Off ) {
-	return false;
-      } else {
-	return QVariant();
-      }
+    switch (role) {
+      case Qt::DisplayRole:
+        return node->name();
+        break;
+      case Qt::EditRole:
+        if (node->state() == OptContentItem::On) {
+          return true;
+        } else if (node->state() == OptContentItem::Off) {
+          return false;
+        }
+        break;
+      case Qt::CheckStateRole:
+        if (node->state() == OptContentItem::On) {
+          return qVariantFromValue<int>(Qt::Checked);
+        } else if (node->state() == OptContentItem::Off) {
+          return qVariantFromValue<int>(Qt::Unchecked);
+        }
+        break;
     }
 
     return QVariant();
@@ -305,24 +309,24 @@ namespace Poppler
       return false;
     }
 
-    if (index.column() == 0) {
-      // we don't allow setting of the label
-      return false;
-    } else if (index.column() == 1) {
-      if ( value.toBool() == true ) {
-	if ( node->state() != OptContentItem::On ) {
-	  node->setState( OptContentItem::On );
-	  emit dataChanged( index, index );
-	}
-	return true;
-      } else if ( value.toBool() == false ) {
-	if ( node->state() != OptContentItem::Off ) {
-	  node->setState( OptContentItem::Off );
-	  emit dataChanged( index, index );
-	}
-	return true;
-      } else {
-	return false;
+    switch (role) {
+      case Qt::CheckStateRole:
+      {
+        const bool newvalue = value.toBool();
+        if (newvalue) {
+          if (node->state() != OptContentItem::On) {
+            node->setState(OptContentItem::On);
+            emit dataChanged(index, index);
+            return true;
+          }
+        } else {
+          if (node->state() != OptContentItem::Off) {
+            node->setState(OptContentItem::Off);
+            emit dataChanged(index, index);
+            return true;
+          }
+        }
+        break;
       }
     }
 
@@ -332,9 +336,7 @@ namespace Poppler
   Qt::ItemFlags OptContentModel::flags ( const QModelIndex & index ) const
   {
     if (index.column() == 0) {
-      return QAbstractItemModel::flags(index) | Qt::ItemIsSelectable | Qt::ItemIsEnabled;
-    } else if (index.column() == 1) {
-      return QAbstractItemModel::flags(index) | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
+      return QAbstractItemModel::flags(index) | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
     } else {
       return QAbstractItemModel::flags(index);
     }
commit defa0ecb2790402a4069fea3b3c285a50675682d
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 12:24:16 2008 +0100

    Add a skeleton of OptContentModel::headerData().
    
    It does nothing yet, but we can add stuff later on w/o breaking BC.

diff --git a/qt4/src/poppler-optcontent.cc b/qt4/src/poppler-optcontent.cc
index 10a571d..c3522df 100644
--- a/qt4/src/poppler-optcontent.cc
+++ b/qt4/src/poppler-optcontent.cc
@@ -340,6 +340,11 @@ namespace Poppler
     }
   }
 
+  QVariant OptContentModel::headerData( int section, Qt::Orientation orientation, int role ) const
+  {
+    return QAbstractItemModel::headerData( section, orientation, role );
+  }
+
   void OptContentModelPrivate::addChild( OptContentItem *parent, OptContentItem *child )
   {
     parent->addChild( child );
diff --git a/qt4/src/poppler-optcontent.h b/qt4/src/poppler-optcontent.h
index 81dd412..325a8e4 100644
--- a/qt4/src/poppler-optcontent.h
+++ b/qt4/src/poppler-optcontent.h
@@ -51,6 +51,8 @@ namespace Poppler
 
     Qt::ItemFlags flags ( const QModelIndex & index ) const;
 
+    virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
+
     private:
     friend class OptContentModelPrivate;
     OptContentModelPrivate *d;


More information about the poppler mailing list