[poppler] 2 commits - qt4/src qt4/tests

Pino Toscano pino at kemper.freedesktop.org
Wed Feb 27 09:51:16 PST 2008


 qt4/src/poppler-optcontent.cc  |   11 ++----
 qt4/tests/check_optcontent.cpp |   66 ++++++++++++++---------------------------
 2 files changed, 27 insertions(+), 50 deletions(-)

New commits:
commit e293bfc384e2dfc4ef04582053ce18d8c0bcb7b3
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 18:50:35 2008 +0100

    small cleanup

diff --git a/qt4/src/poppler-optcontent.cc b/qt4/src/poppler-optcontent.cc
index 85aaaf6..68a44a6 100644
--- a/qt4/src/poppler-optcontent.cc
+++ b/qt4/src/poppler-optcontent.cc
@@ -170,7 +170,7 @@ namespace Poppler
 	Object item;
 	orderArray->getNF(i, &item);
 	if (item.isRef() ) {
-	  OptContentItem *ocItem = m_optContentItems[ QString("%1").arg(item.getRefNum()) ];
+          OptContentItem *ocItem = m_optContentItems.value(QString::number(item.getRefNum()), 0);
 	  if (ocItem) {
 	    addChild( parentNode, ocItem );
 	    lastItem = ocItem;
@@ -305,9 +305,9 @@ namespace Poppler
         break;
       case Qt::CheckStateRole:
         if (node->state() == OptContentItem::On) {
-          return qVariantFromValue<int>(Qt::Checked);
+          return Qt::Checked;
         } else if (node->state() == OptContentItem::Off) {
-          return qVariantFromValue<int>(Qt::Unchecked);
+          return Qt::Unchecked;
         }
         break;
     }
@@ -383,10 +383,7 @@ namespace Poppler
 
   OptContentItem* OptContentModelPrivate::itemFromRef( const QString &ref ) const
   {
-    if ( !m_optContentItems.contains( ref ) ) {
-      return 0;
-    }
-    return m_optContentItems[ ref ];
+    return m_optContentItems.value(ref, 0);
   }
 
   OptContentItem* OptContentModelPrivate::nodeFromIndex(const QModelIndex &index, bool canBeNull) const
commit f11aa0008585e845ce509172d76f72f941be497d
Author: Pino Toscano <pino at kde.org>
Date:   Wed Feb 27 18:44:09 2008 +0100

    adapt the tests to the new layout of the contents model

diff --git a/qt4/tests/check_optcontent.cpp b/qt4/tests/check_optcontent.cpp
index 045ec18..247c67b 100644
--- a/qt4/tests/check_optcontent.cpp
+++ b/qt4/tests/check_optcontent.cpp
@@ -28,12 +28,10 @@ void TestOptionalContent::checkVisPolicy()
     QModelIndex index;
     index = optContent->index( 0, 0, QModelIndex() );
     QCOMPARE( optContent->data( index, Qt::DisplayRole ).toString(), QString( "A" ) );
-    index = optContent->index( 0, 1, QModelIndex() );
-    QCOMPARE( optContent->data( index, Qt::DisplayRole ).toBool(), true );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( index, Qt::CheckStateRole ).toInt() ), Qt::Checked );
     index = optContent->index( 1, 0, QModelIndex() );
     QCOMPARE( optContent->data( index, Qt::DisplayRole ).toString(), QString( "B" ) );
-    index = optContent->index( 1, 1, QModelIndex() );
-    QCOMPARE( optContent->data( index, Qt::DisplayRole ).toBool(), true );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( index, Qt::CheckStateRole ).toInt() ), Qt::Checked );
 
     delete doc;
 }
@@ -51,29 +49,24 @@ void TestOptionalContent::checkNestedLayers()
 
     index = optContent->index( 0, 0, QModelIndex() );
     QCOMPARE( optContent->data( index, Qt::DisplayRole ).toString(), QString( "Black Text and Green Snow" ) );
-    index = optContent->index( 0, 1, QModelIndex() );
-    QCOMPARE( optContent->data( index, Qt::DisplayRole ).toBool(), false );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( index, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
 
     index = optContent->index( 1, 0, QModelIndex() );
     QCOMPARE( optContent->data( index, Qt::DisplayRole ).toString(), QString( "Mountains and Image" ) );
-    index = optContent->index( 1, 1, QModelIndex() );
-    QCOMPARE( optContent->data( index, Qt::DisplayRole ).toBool(), true );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( index, Qt::CheckStateRole ).toInt() ), Qt::Checked );
 
     // This is a sub-item of "Mountains and Image"
     QModelIndex subindex = optContent->index( 0, 0, index );
     QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QString( "Image" ) );
-    subindex = optContent->index( 0, 1, index );
-    QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toBool(), true );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( index, Qt::CheckStateRole ).toInt() ), Qt::Checked );
 
     index = optContent->index( 2, 0, QModelIndex() );
     QCOMPARE( optContent->data( index, Qt::DisplayRole ).toString(), QString( "Starburst" ) );
-    index = optContent->index( 2, 1, QModelIndex() );
-    QCOMPARE( optContent->data( index, Qt::DisplayRole ).toBool(), true );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( index, Qt::CheckStateRole ).toInt() ), Qt::Checked );
 
     index = optContent->index( 3, 0, QModelIndex() );
     QCOMPARE( optContent->data( index, Qt::DisplayRole ).toString(), QString( "Watermark" ) );
-    index = optContent->index( 3, 1, QModelIndex() );
-    QCOMPARE( optContent->data( index, Qt::DisplayRole ).toBool(), false );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( index, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
 
     delete doc;
 }
@@ -416,79 +409,66 @@ void TestOptionalContent::checkRadioButtons()
 
     index = optContent->index( 0, 0, QModelIndex() );
     QCOMPARE( optContent->data( index, Qt::DisplayRole ).toString(), QString( "Languages" ) );
-    index = optContent->index( 0, 1, QModelIndex() );
-    QCOMPARE( optContent->data( index, Qt::DisplayRole ), QVariant() );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( index, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
 
     // These are sub-items of the "Languages" label
     QModelIndex subindex = optContent->index( 0, 0, index );
     QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QString( "English" ) );
-    subindex = optContent->index( 0, 1, index );
-    QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toBool(), true );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Checked );
 
     subindex = optContent->index( 1, 0, index );
     QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QString( "French" ) );
-    subindex = optContent->index( 1, 1, index );
-    QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toBool(), false );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
 
     subindex = optContent->index( 2, 0, index );
     QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QString( "Japanese" ) );
-    subindex = optContent->index( 2, 1, index );
-    QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toBool(), false );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
 
     // RBGroup of languages, so turning on Japanese should turn off English
-    bool result = optContent->setData( subindex, QVariant( true ) );
+    bool result = optContent->setData( subindex, QVariant( true ), Qt::CheckStateRole );
 
     subindex = optContent->index( 0, 0, index );
     QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QString( "English" ) );
-    subindex = optContent->index( 0, 1, index );
-    QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toBool(), false );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
 
     subindex = optContent->index( 2, 0, index );
     QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QString( "Japanese" ) );
-    subindex = optContent->index( 2, 1, index );
-    QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toBool(), true );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Checked );
 
     subindex = optContent->index( 1, 0, index );
     QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QString( "French" ) );
-    subindex = optContent->index( 1, 1, index );
-    QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toBool(), false );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
 
     // and turning on French should turn off Japanese
-    result = optContent->setData( subindex, QVariant( true ) );
+    result = optContent->setData( subindex, QVariant( true ), Qt::CheckStateRole );
 
     subindex = optContent->index( 0, 0, index );
     QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QString( "English" ) );
-    subindex = optContent->index( 0, 1, index );
-    QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toBool(), false );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
 
     subindex = optContent->index( 2, 0, index );
     QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QString( "Japanese" ) );
-    subindex = optContent->index( 2, 1, index );
-    QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toBool(), false );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
 
     subindex = optContent->index( 1, 0, index );
     QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QString( "French" ) );
-    subindex = optContent->index( 1, 1, index );
-    QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toBool(), true );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Checked );
 
 
     // and turning off French should leave them all off
-    result = optContent->setData( subindex, QVariant( false ) );
+    result = optContent->setData( subindex, QVariant( false ), Qt::CheckStateRole );
 
     subindex = optContent->index( 0, 0, index );
     QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QString( "English" ) );
-    subindex = optContent->index( 0, 1, index );
-    QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toBool(), false );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
 
     subindex = optContent->index( 2, 0, index );
     QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QString( "Japanese" ) );
-    subindex = optContent->index( 2, 1, index );
-    QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toBool(), false );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
 
     subindex = optContent->index( 1, 0, index );
     QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QString( "French" ) );
-    subindex = optContent->index( 1, 1, index );
-    QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toBool(), false );
+    QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
 
     delete doc;
 }


More information about the poppler mailing list