[poppler] 3 commits - qt4/src

Pino Toscano pino at kemper.freedesktop.org
Wed Feb 27 13:10:48 PST 2008


 qt4/src/poppler-optcontent-private.h |   17 +++++++++++--
 qt4/src/poppler-optcontent.cc        |   44 ++++++++++++++++++++++++++++-------
 2 files changed, 50 insertions(+), 11 deletions(-)

New commits:
commit 5b2f8f21fca63508570a0c77c6f7221a322e6e57
Merge: 7e65118... 4254f12...
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 22:10:12 2008 +0100

    Merge branch 'master' of ssh://pino@git.freedesktop.org/git/poppler/poppler

commit 7e651186f483976f9833de245b6c7add38e77a16
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 22:03:17 2008 +0100

    Properly enable/disable the contents when their parents are changed.
    
    Now, the children maintain the "checked state" they had, when their parent is unchecked;
    but, they are really disabled, both in the possibility to be checked and in the drawing of their associated content [applying the same to their children, and so on].

diff --git a/qt4/src/poppler-optcontent-private.h b/qt4/src/poppler-optcontent-private.h
index 351e5e5..3a995f0 100644
--- a/qt4/src/poppler-optcontent-private.h
+++ b/qt4/src/poppler-optcontent-private.h
@@ -58,7 +58,7 @@ namespace Poppler
     ~OptContentItem();
 
     QString name() const { return m_name; }
-    ItemState state() const { return m_state; }
+    ItemState state() const { return m_stateBackup; }
     bool setState(ItemState state, QSet<OptContentItem *> &changedItems);
 
     QList<OptContentItem*> childList() { return m_children; }
@@ -70,13 +70,19 @@ namespace Poppler
 
     void appendRBGroup( RadioButtonGroup *rbgroup );
 
+    bool isEnabled() const { return m_enabled; }
+
+    QSet<OptContentItem*> recurseListChildren(bool includeMe = false) const;
+
     private:
     OptionalContentGroup *m_group;
     QString m_name;
     ItemState m_state; // true for ON, false for OFF
+    ItemState m_stateBackup;
     QList<OptContentItem*> m_children;
     OptContentItem *m_parent;
     QList<RadioButtonGroup*> m_rbGroups;
+    bool m_enabled;
   };
 
   class OptContentModelPrivate
diff --git a/qt4/src/poppler-optcontent.cc b/qt4/src/poppler-optcontent.cc
index 1a10c17..9f5894f 100644
--- a/qt4/src/poppler-optcontent.cc
+++ b/qt4/src/poppler-optcontent.cc
@@ -78,6 +78,8 @@ namespace Poppler
     } else {
       m_state = OptContentItem::Off;
     }
+    m_stateBackup = m_state;
+    m_enabled = true;
   }
 
   OptContentItem::OptContentItem( const QString &label )
@@ -86,10 +88,12 @@ namespace Poppler
     m_name = label;
     m_group = 0;
     m_state = OptContentItem::HeadingOnly;
+    m_stateBackup = m_state;
+    m_enabled = true;
   }
 
   OptContentItem::OptContentItem() :
-    m_parent( 0 )
+    m_parent( 0 ), m_enabled(true)
   {
   }
 
@@ -106,7 +110,15 @@ namespace Poppler
   bool OptContentItem::setState(ItemState state, QSet<OptContentItem *> &changedItems)
   {
     m_state = state;
+    m_stateBackup = m_state;
     changedItems.insert(this);
+    QSet<OptContentItem *> empty;
+    Q_FOREACH (OptContentItem *child, m_children) {
+      ItemState oldState = child->m_stateBackup;
+      child->setState(state == OptContentItem::On ? child->m_stateBackup : OptContentItem::Off, empty);
+      child->m_enabled = state == OptContentItem::On;
+      child->m_stateBackup = oldState;
+    }
     if (!m_group) {
       return false;
     }
@@ -128,6 +140,18 @@ namespace Poppler
     child->setParent( this );
   }
 
+  QSet<OptContentItem*> OptContentItem::recurseListChildren(bool includeMe) const
+  {
+    QSet<OptContentItem*> ret;
+    if (includeMe) {
+      ret.insert(const_cast<OptContentItem*>(this));
+    }
+    Q_FOREACH (OptContentItem *child, m_children) {
+      ret += child->recurseListChildren(true);
+    }
+    return ret;
+  }
+
   OptContentModelPrivate::OptContentModelPrivate( OptContentModel *qq, OCGs *optContent )
     : q(qq)
   {
@@ -330,6 +354,7 @@ namespace Poppler
           if (node->state() != OptContentItem::On) {
             QSet<OptContentItem *> changedItems;
             node->setState(OptContentItem::On, changedItems);
+            changedItems += node->recurseListChildren(false);
             QModelIndexList indexes;
             Q_FOREACH (OptContentItem *item, changedItems) {
               indexes.append(d->indexFromItem(item, 0));
@@ -344,6 +369,7 @@ namespace Poppler
           if (node->state() != OptContentItem::Off) {
             QSet<OptContentItem *> changedItems;
             node->setState(OptContentItem::Off, changedItems);
+            changedItems += node->recurseListChildren(false);
             QModelIndexList indexes;
             Q_FOREACH (OptContentItem *item, changedItems) {
               indexes.append(d->indexFromItem(item, 0));
@@ -364,11 +390,12 @@ namespace Poppler
 
   Qt::ItemFlags OptContentModel::flags ( const QModelIndex & index ) const
   {
-    if (index.column() == 0) {
-      return QAbstractItemModel::flags(index) | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
-    } else {
-      return QAbstractItemModel::flags(index);
+    OptContentItem *node = d->nodeFromIndex(index);
+    Qt::ItemFlags itemFlags = Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
+    if (node->isEnabled()) {
+      itemFlags |= Qt::ItemIsEnabled;
     }
+    return itemFlags;
   }
 
   QVariant OptContentModel::headerData( int section, Qt::Orientation orientation, int role ) const
commit 8d384c06f96ba8cb3e73c275b3c708c64da4595d
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 20:39:09 2008 +0100

    small header cleanup

diff --git a/qt4/src/poppler-optcontent-private.h b/qt4/src/poppler-optcontent-private.h
index 7471a42..351e5e5 100644
--- a/qt4/src/poppler-optcontent-private.h
+++ b/qt4/src/poppler-optcontent-private.h
@@ -20,16 +20,21 @@
 #ifndef POPPLER_OPTCONTENT_PRIVATE_H
 #define POPPLER_OPTCONTENT_PRIVATE_H
 
-#include "poppler-optcontent.h"
-
+#include <QtCore/QMap>
+#include <QtCore/QSet>
 #include <QtCore/QString>
 
 class Array;
+class OCGs;
 class OptionalContentGroup;
 
+class QModelIndex;
+
 namespace Poppler
 {
   class OptContentItem;
+  class OptContentModel;
+  class OptContentModelPrivate;
 
   class RadioButtonGroup
   {
diff --git a/qt4/src/poppler-optcontent.cc b/qt4/src/poppler-optcontent.cc
index 3899970..1a10c17 100644
--- a/qt4/src/poppler-optcontent.cc
+++ b/qt4/src/poppler-optcontent.cc
@@ -17,16 +17,17 @@
  * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include "poppler-optcontent-private.h"
+#include "poppler-optcontent.h"
 
-#include "poppler/OptionalContent.h"
+#include "poppler-optcontent-private.h"
 
-#include "poppler-qt4.h"
 #include "poppler-private.h"
 
 #include <QtCore/QDebug>
 #include <QtCore/QtAlgorithms>
 
+#include "poppler/OptionalContent.h"
+
 namespace Poppler
 {
 


More information about the poppler mailing list