[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: KConfigBase & TODO
From:       Thomas Braxton <brax108 () cox ! net>
Date:       2005-12-14 17:39:37
Message-ID: 200512141139.37686.brax108 () cox ! net
[Download RAW message or body]

On Tuesday 13 December 2005 02:57, David Faure wrote:
> Well, there was this other thread where it was said that we should clean up
> that API and use only QVariant.
>  resize( config->readSizeEntry( "Bleh", size() ) );
> would become
>  resize( config->readEntry( "Bleh", size() ).toSize() );
>
> but the KConfigBase API would be very much simpler.
> (And I withdraw my comment about speed, kconfig isn't as much used in
> tight loops as e.g. KIO::UDSEntry is).
>
> Maybe we can do this progressively, with a readVariantEntry, marking the
> existing methods as deprecated, and then when most code has been ported
> to readVariantEntry, we can just s/readEntry/readVariantEntry/ everywhere.
we already had most of this with readPropertyEntry, I changed it to readEntry 
and this is a first pass. What do you think? I couldn't include the diff for 
kconfigbase.h, it was too large, almost every read*Entry was deprecated and 
every writeEntry that wasn't for a string, list or QVariant was removed.
The only problems I have are:
1) readEntry("keyName", "defaultValue") is ambiguous, the only way I see to 
disambiguate is at the caller, readEntry("keyName", QString::fromLatin1
("defaultValue")), or merge readEntry(QString,QString) with 
readEntry(QString,QVariant), but I don't think this is the best idea because 
QString needs to pay attention to localization and QVariant shouldn't.
2) KConfigSkeleton::ItemLong is ambiguous, do we need more than 2 ItemInt 
sizes? We could change ItemInt to ItemInt32 and we already have ItemInt64, 
what do you think?

["diff" (text/x-diff)]

Index: kconfigbase.cpp
===================================================================
--- kconfigbase.cpp	(revision 488376)
+++ kconfigbase.cpp	(working copy)
@@ -335,27 +335,23 @@
 }
 
 QVariant KConfigBase::readPropertyEntry( const QString& pKey,
-                                          QVariant::Type type ) const
+                                         const QVariant& aDefault ) const
 {
-  return readPropertyEntry(pKey.toUtf8().data(), type);
+    return readPropertyEntry(pKey.toUtf8().data(), aDefault);
 }
 
-QVariant KConfigBase::readPropertyEntry( const char *pKey,
-                                          QVariant::Type type ) const
+QVariant KConfigBase::readPropertyEntry( const char* pKey,
+                                         const QVariant& aDefault ) const
 {
-  if ( !hasKey( pKey ) )
-    return QVariant();
-  else
-    return readPropertyEntry(pKey, QVariant(type));
+    return readEntry(pKey, aDefault);
 }
-
-QVariant KConfigBase::readPropertyEntry( const QString& pKey,
+QVariant KConfigBase::readEntry( const QString& pKey,
                                          const QVariant &aDefault ) const
 {
-  return readPropertyEntry(pKey.toUtf8().data(), aDefault);
+  return readEntry(pKey.toUtf8().data(), aDefault);
 }
 
-QVariant KConfigBase::readPropertyEntry( const char *pKey,
+QVariant KConfigBase::readEntry( const char *pKey,
                                          const QVariant &aDefault ) const
 {
   if ( !hasKey( pKey ) ) return aDefault;
@@ -366,77 +362,94 @@
   {
       case QVariant::Invalid:
           return QVariant();
+      case QVariant::ByteArray:
       case QVariant::String:
-          return QVariant( readEntry( pKey, aDefault.toString() ) );
+          return readEntry( pKey, aDefault.toString() );
       case QVariant::StringList:
-          return QVariant( readListEntry( pKey ) );
+          return readListEntry( pKey );
       case QVariant::List: {
-          QStringList strList = readListEntry( pKey );
-          QStringList::ConstIterator it = strList.begin();
-          QStringList::ConstIterator end = strList.end();
           QList<QVariant> list;
 
-          for (; it != end; ++it ) {
-              tmp = *it;
-              list.append( tmp );
-          }
-          return QVariant( list );
+          foreach ( QString str, readListEntry( pKey ) )
+              list.append( str );
+          return list;
       }
-      case QVariant::Font: {
-	  QFont tmpf = qvariant_cast<QFont>( tmp );
-          return QVariant( readFontEntry( pKey, &tmpf ) );
-	}
+      case QVariant::Font:
+      case QVariant::Color:
+//      case QVariant::KeySequence:
+      case QVariant::Bool:
+      case QVariant::Double:
+      case QVariant::Int:
+      case QVariant::UInt:
+        {
+            tmp = readEntry(pKey);
+            if ( !tmp.convert(aDefault.type()) )
+                tmp = aDefault;
+            return tmp;
+        }
       case QVariant::Point: {
-          QPoint tmpp = tmp.toPoint();
-          return QVariant( readPointEntry( pKey, &tmpp ) );
-	}
+          QList<int> list = readIntListEntry( pKey );
+  
+          if ( list.count() == 2 )
+              tmp = QPoint(list.at( 0 ), list.at( 1 ));
+          return tmp;
+      }
       case QVariant::Rect: {
-          QRect tmpr = tmp.toRect();
-          return QVariant( readRectEntry( pKey, &tmpr ) );
-	}
+          QList<int> list = readIntListEntry( pKey );
+
+          if ( list.count() == 4)
+              tmp = QRect(list.at( 0 ), list.at( 1 ), list.at( 2 ), list.at( 3 ));
+          return tmp;
+      }
       case QVariant::Size: {
-          QSize tmps = tmp.toSize();
-          return QVariant( readSizeEntry( pKey, &tmps ) );
-	}
-      case QVariant::Color: {
-	  QColor tmpc = qvariant_cast<QColor>( tmp );
-          return QVariant( readColorEntry( pKey, &tmpc ) );
-	}
-      case QVariant::Int:
-          return QVariant( readNumEntry( pKey, aDefault.toInt() ) );
-      case QVariant::UInt:
-          return QVariant( readUnsignedNumEntry( pKey, aDefault.toUInt() ) );
-      case QVariant::LongLong:
-          return QVariant( readNum64Entry( pKey, aDefault.toLongLong() ) );
-      case QVariant::ULongLong:
-          return QVariant( readUnsignedNum64Entry( pKey, aDefault.toULongLong() ) );
-      case QVariant::Bool:
-          return QVariant( readBoolEntry( pKey, aDefault.toBool() ), 0 );
-      case QVariant::Double:
-          return QVariant( readDoubleNumEntry( pKey, aDefault.toDouble() ) );
+          QList<int> list = readIntListEntry( pKey );
+
+          if ( list.count() == 2 )
+              tmp = QSize(list.at( 0 ), list.at( 1 ));
+          return tmp;
+      }
+      case QVariant::LongLong: {
+          QByteArray aValue = readEntryUtf8(pKey);
+
+          if ( !aValue.isEmpty() ) {
+              bool ok;
+              qint64 rc = aValue.toLongLong( &ok );
+              if ( ok )
+                  tmp = rc;
+          }
+          return tmp;
+      }
+      case QVariant::ULongLong: {
+          QByteArray aValue = readEntryUtf8(pKey);
+
+          if( !aValue.isEmpty() ) {
+              bool ok;
+              quint64 rc = aValue.toULongLong( &ok );
+              if ( ok )
+                  tmp = rc;
+          }
+          return tmp;
+      }
       case QVariant::DateTime: {
-          QDateTime tmpdt = tmp.toDateTime();
-          return QVariant( readDateTimeEntry( pKey, &tmpdt ) );
-	}
+          QList<int> list = readIntListEntry( pKey );
+          if ( list.count() == 6 ) {
+              QDate date( list.at( 0 ), list.at( 1 ), list.at( 2 ) );
+              QTime time( list.at( 3 ), list.at( 4 ), list.at( 5 ) );
+              return QDateTime( date, time );
+          }
+          if ( !aDefault.toDateTime().isValid() )
+              tmp = QDateTime::currentDateTime();
+          return tmp;
+      }
       case QVariant::Date: {
-          QDateTime tmpdt = tmp.toDateTime();
-          return QVariant(readDateTimeEntry( pKey, &tmpdt ).date());
-	}
+          QList<int> list = readIntListEntry( pKey );
+          if ( list.count() == 6 )
+              return QDate( list.at( 0 ), list.at( 1 ), list.at( 2 ) );
+          if ( !aDefault.toDate().isValid() )
+              tmp = QDate::currentDate();
+          return tmp;
+      }
 
-      case QVariant::Pixmap:
-      case QVariant::Image:
-      case QVariant::Brush:
-      case QVariant::Palette:
-      case QVariant::Map:
-      case QVariant::Icon:
-      case QVariant::Region:
-      case QVariant::Bitmap:
-      case QVariant::Cursor:
-      case QVariant::SizePolicy:
-      case QVariant::Time:
-      case QVariant::BitArray:
-      case QVariant::KeySequence:
-      case QVariant::Pen:
       default:
           break;
   }
@@ -1294,57 +1307,79 @@
       writeEntry( pKey, prop.toStringList(), ',', bPersistent, bGlobal, bNLS );
       return;
     case QVariant::List: {
-        QList<QVariant> list = prop.toList();
-        QList<QVariant>::ConstIterator it = list.begin();
-        QList<QVariant>::ConstIterator end = list.end();
         QStringList strList;
+        foreach ( QVariant aValue, prop.toList() )
+            strList.append( aValue.toString() );
 
-        for (; it != end; ++it )
-            strList.append( (*it).toString() );
-
         writeEntry( pKey, strList, ',', bPersistent, bGlobal, bNLS );
 
         return;
     }
-    case QVariant::Font:
-      writeEntry( pKey, QFont(prop.toString()), bPersistent, bGlobal, bNLS );
-      return;
-    case QVariant::Point:
-      writeEntry( pKey, prop.toPoint(), bPersistent, bGlobal, bNLS );
-      return;
-    case QVariant::Rect:
-      writeEntry( pKey, prop.toRect(), bPersistent, bGlobal, bNLS );
-      return;
-    case QVariant::Size:
-      writeEntry( pKey, prop.toSize(), bPersistent, bGlobal, bNLS );
-      return;
-    case QVariant::Color:
-      writeEntry( pKey, QColor(prop.toString()), bPersistent, bGlobal, bNLS );
-      return;
+    case QVariant::Point: {
+        QList<int> list;
+        QPoint rPoint = prop.toPoint();
+        list.insert( 0, rPoint.x() );
+        list.insert( 1, rPoint.y() );
+
+        writeEntry( pKey, list, bPersistent, bGlobal, bNLS );
+        return;
+    }
+    case QVariant::Rect:{
+        QList<int> list;
+        QRect rRect = prop.toRect();
+        list.insert( 0, rRect.left() );
+        list.insert( 1, rRect.top() );
+        list.insert( 2, rRect.width() );
+        list.insert( 3, rRect.height() );
+
+        writeEntry( pKey, list, bPersistent, bGlobal, bNLS );
+        return;
+    }
+    case QVariant::Size:{
+        QList<int> list;
+        QSize rSize = prop.toSize();
+        list.insert( 0, rSize.width() );
+        list.insert( 1, rSize.height() );
+
+        writeEntry( pKey, list, bPersistent, bGlobal, bNLS );
+        return;
+    }
     case QVariant::Int:
-      writeEntry( pKey, prop.toInt(), bPersistent, bGlobal, bNLS );
-      return;
     case QVariant::UInt:
-      writeEntry( pKey, prop.toUInt(), bPersistent, bGlobal, bNLS );
-      return;
+    case QVariant::Double:
+    case QVariant::Bool:
+    case QVariant::Color:
+//    case QVariant::KeySequence:
+    case QVariant::Font:
+        writeEntry( pKey, prop.toString(), bPersistent, bGlobal, bNLS );
+        return;
     case QVariant::LongLong:
-      writeEntry( pKey, prop.toLongLong(), bPersistent, bGlobal, bNLS );
+      writeEntry( pKey, QString::number(prop.toLongLong()), bPersistent, bGlobal, \
bNLS );  return;
     case QVariant::ULongLong:
-      writeEntry( pKey, prop.toULongLong(), bPersistent, bGlobal, bNLS );
+      writeEntry( pKey, QString::number(prop.toULongLong()), bPersistent, bGlobal, \
bNLS );  return;
-    case QVariant::Bool:
-      writeEntry( pKey, prop.toBool(), bPersistent, bGlobal, bNLS );
-      return;
-    case QVariant::Double:
-      writeEntry( pKey, prop.toDouble(), bPersistent, bGlobal, 'g', 6, bNLS );
-      return;
-    case QVariant::DateTime:
+    case QVariant::Date:
+    case QVariant::DateTime: {
+        QList<int> list;
+        QDateTime rDateTime = prop.toDateTime();
+
+        QTime time = rDateTime.time();
+        QDate date = rDateTime.date();
+
+        list.insert( 0, date.year() );
+        list.insert( 1, date.month() );
+        list.insert( 2, date.day() );
+
+        list.insert( 3, time.hour() );
+        list.insert( 4, time.minute() );
+        list.insert( 5, time.second() );
+
+        writeEntry( pKey, list, bPersistent, bGlobal, bNLS );
+        return;
+    }
       writeEntry( pKey, prop.toDateTime(), bPersistent, bGlobal, bNLS);
       return;
-    case QVariant::Date:
-      writeEntry( pKey, QDateTime(prop.toDate()), bPersistent, bGlobal, bNLS);
-      return;
 
     case QVariant::Pixmap:
     case QVariant::Image:
@@ -1498,259 +1533,6 @@
     writeEntry(pKey, strlist, ',', bPersistent, bGlobal, bNLS );
 }
 
-void KConfigBase::writeEntry( const QString& pKey, int nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
-}
-
-void KConfigBase::writeEntry( const char *pKey, int nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
-}
-
-
-void KConfigBase::writeEntry( const QString& pKey, unsigned int nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
-}
-
-void KConfigBase::writeEntry( const char *pKey, unsigned int nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
-}
-
-
-void KConfigBase::writeEntry( const QString& pKey, long nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
-}
-
-void KConfigBase::writeEntry( const char *pKey, long nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
-}
-
-
-void KConfigBase::writeEntry( const QString& pKey, unsigned long nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
-}
-
-void KConfigBase::writeEntry( const char *pKey, unsigned long nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
-}
-
-void KConfigBase::writeEntry( const QString& pKey, qint64 nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
-}
-
-void KConfigBase::writeEntry( const char *pKey, qint64 nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
-}
-
-
-void KConfigBase::writeEntry( const QString& pKey, quint64 nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
-}
-
-void KConfigBase::writeEntry( const char *pKey, quint64 nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue), bPersistent, bGlobal, bNLS );
-}
-
-void KConfigBase::writeEntry( const QString& pKey, double nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 char format, int precision,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue, format, precision),
-                     bPersistent, bGlobal, bNLS );
-}
-
-void KConfigBase::writeEntry( const char *pKey, double nValue,
-                                 bool bPersistent, bool bGlobal,
-                                 char format, int precision,
-                                 bool bNLS )
-{
-  writeEntry( pKey, QString::number(nValue, format, precision),
-                     bPersistent, bGlobal, bNLS );
-}
-
-
-void KConfigBase::writeEntry( const QString& pKey, bool bValue,
-                                 bool bPersistent,
-                                 bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry(pKey.toUtf8().data(), bValue, bPersistent, bGlobal, bNLS);
-}
-
-void KConfigBase::writeEntry( const char *pKey, bool bValue,
-                                 bool bPersistent,
-                                 bool bGlobal,
-                                 bool bNLS )
-{
-  QString aValue;
-
-  if( bValue )
-    aValue = "true";
-  else
-    aValue = "false";
-
-  writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );
-}
-
-
-void KConfigBase::writeEntry( const QString& pKey, const QFont& rFont,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry(pKey.toUtf8().data(), rFont, bPersistent, bGlobal, bNLS);
-}
-
-void KConfigBase::writeEntry( const char *pKey, const QFont& rFont,
-                                 bool bPersistent, bool bGlobal,
-                                 bool bNLS )
-{
-  writeEntry( pKey, rFont.toString(), bPersistent, bGlobal, bNLS );
-}
-
-
-void KConfigBase::writeEntry( const QString& pKey, const QRect& rRect,
-                              bool bPersistent, bool bGlobal,
-                              bool bNLS )
-{
-  writeEntry(pKey.toUtf8().data(), rRect, bPersistent, bGlobal, bNLS);
-}
-
-void KConfigBase::writeEntry( const char *pKey, const QRect& rRect,
-                              bool bPersistent, bool bGlobal,
-                              bool bNLS )
-{
-  QStringList list;
-  list.insert( 0, QString::number( rRect.left() ) );
-  list.insert( 1, QString::number( rRect.top() ) );
-  list.insert( 2, QString::number( rRect.width() ) );
-  list.insert( 3, QString::number( rRect.height() ) );
-
-  writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
-}
-
-
-void KConfigBase::writeEntry( const QString& pKey, const QPoint& rPoint,
-                              bool bPersistent, bool bGlobal,
-                              bool bNLS )
-{
-  writeEntry(pKey.toUtf8().data(), rPoint, bPersistent, bGlobal, bNLS);
-}
-
-void KConfigBase::writeEntry( const char *pKey, const QPoint& rPoint,
-                              bool bPersistent, bool bGlobal,
-                              bool bNLS )
-{
-  QStringList list;
-  list.insert( 0, QString::number( rPoint.x() ) );
-  list.insert( 1, QString::number( rPoint.y() ) );
-
-  writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
-}
-
-
-void KConfigBase::writeEntry( const QString& pKey, const QSize& rSize,
-                              bool bPersistent, bool bGlobal,
-                              bool bNLS )
-{
-  writeEntry(pKey.toUtf8().data(), rSize, bPersistent, bGlobal, bNLS);
-}
-
-void KConfigBase::writeEntry( const char *pKey, const QSize& rSize,
-                              bool bPersistent, bool bGlobal,
-                              bool bNLS )
-{
-  QStringList list;
-  list.insert( 0, QString::number( rSize.width() ) );
-  list.insert( 1, QString::number( rSize.height() ) );
-
-  writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
-}
-
-void KConfigBase::writeEntry( const QString& pKey, const QColor& rColor,
-                              bool bPersistent,
-                              bool bGlobal,
-                              bool bNLS  )
-{
-  writeEntry( pKey.toUtf8().data(), rColor, bPersistent, bGlobal, bNLS);
-}
-
-void KConfigBase::writeEntry( const char *pKey, const QColor& rColor,
-                              bool bPersistent,
-                              bool bGlobal,
-                              bool bNLS  )
-{
-  QString aValue;
-  if (rColor.isValid())
-      aValue.sprintf( "%d,%d,%d", rColor.red(), rColor.green(), rColor.blue() );
-  else
-      aValue = "invalid";
-
-  writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );
-}
-
-void KConfigBase::writeEntry( const QString& pKey, const QDateTime& rDateTime,
-                              bool bPersistent, bool bGlobal,
-                              bool bNLS )
-{
-  writeEntry(pKey.toUtf8().data(), rDateTime, bPersistent, bGlobal, bNLS);
-}
-
-void KConfigBase::writeEntry( const char *pKey, const QDateTime& rDateTime,
-                              bool bPersistent, bool bGlobal,
-                              bool bNLS )
-{
-  QStringList list;
-
-  QTime time = rDateTime.time();
-  QDate date = rDateTime.date();
-
-  list.insert( 0, QString::number( date.year() ) );
-  list.insert( 1, QString::number( date.month() ) );
-  list.insert( 2, QString::number( date.day() ) );
-
-  list.insert( 3, QString::number( time.hour() ) );
-  list.insert( 4, QString::number( time.minute() ) );
-  list.insert( 5, QString::number( time.second() ) );
-
-  writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );
-}
-
 void KConfigBase::parseConfigFiles()
 {
   if (!bLocaleInitialized && KGlobal::_locale) {
Index: tests/kconfigtest.cpp
===================================================================
--- tests/kconfigtest.cpp	(revision 488376)
+++ tests/kconfigtest.cpp	(working copy)
@@ -20,7 +20,6 @@
 #include <qttest_kde.h>
 #include "kconfigtest.h"
 #include "kconfigtest.moc"
-#include <qrect.h>
 
 #include <kconfig.h>
 #include <kdebug.h>
@@ -40,9 +39,11 @@
 #define SIZEENTRY QSize( 10, 20 )
 #define RECTENTRY QRect( 10, 23, 5321, 13 )
 #define DATETIMEENTRY QDateTime( QDate( 2002, 06, 23 ), QTime( 12, 55, 40 ) )
-#define STRINGLISTENTRY QStringList( "Hello," )
+#define STRINGLISTENTRY (QStringList( "Hello," ) << " World")
 #define INTLISTENTRY1 QList<int>() << 1 << 2 << 3 << 4
 #define BYTEARRAYLISTENTRY1 QList<QByteArray>() << "" << "1,2" << "end"
+#define COLORENTRY QColor("steelblue")
+#define FONTENTRY QFont("Times", 16, QFont::Normal)
 
 void KConfigTest::writeConfigFile()
 {
@@ -56,7 +57,7 @@
   sc.writeEntry( "boolEntry1", BOOLENTRY1 );
   sc.writeEntry( "boolEntry2", BOOLENTRY2 );
 
-  sc.writeEntry( "Test", QString::fromLocal8Bit( LOCAL8BITENTRY ) );
+  sc.writeEntry( "Test", QByteArray( LOCAL8BITENTRY ) );
   sc.writeEntry( "Test2", "");
   sc.writeEntry( "stringEntry1", STRINGENTRY1 );
   sc.writeEntry( "stringEntry2", STRINGENTRY2 );
@@ -79,6 +80,8 @@
   sc.writeEntry( "byteArrayEntry1", QByteArray( STRINGENTRY1 ), true, true );
   sc.writeEntry( "listOfIntsEntry1", INTLISTENTRY1 );
   sc.writeEntry( "listOfByteArraysEntry1", BYTEARRAYLISTENTRY1 );
+  sc.writeEntry( "colorEntry", COLORENTRY );
+  sc.writeEntry( "fontEntry", FONTENTRY );
   sc.sync();
 }
 
@@ -120,23 +123,23 @@
   QCOMPARE( sc2.readEntry( "stringEntry1" ), QString( STRINGENTRY1 ) );
   QCOMPARE( sc2.entryIsImmutable("stringEntry1"), bImmutable );
   QVERIFY( !sc2.hasKey( "stringEntry2" ) );
-  QCOMPARE( sc2.readEntry( "stringEntry2", "bla" ), QString( "bla" ) );
+  QCOMPARE( sc2.readEntry( "stringEntry2", QString("bla") ), QString( "bla" ) );
 
   QVERIFY( !sc2.hasDefault( "stringEntry1" ) );
 
   sc2.setGroup("Hello");
   QCOMPARE( sc2.readEntry( "Test" ), QString::fromLocal8Bit( LOCAL8BITENTRY ) );
-  QCOMPARE( sc2.readEntry("Test2", "Fietsbel").isEmpty(), true );
+  QCOMPARE( sc2.readEntry("Test2", QString("Fietsbel")).isEmpty(), true );
   QCOMPARE( sc2.readEntry( "stringEntry1" ), QString( STRINGENTRY1 ) );
   QCOMPARE( sc2.readEntry( "stringEntry2" ), QString( STRINGENTRY2 ) );
   QCOMPARE( sc2.readEntry( "stringEntry3" ), QString( STRINGENTRY3 ) );
   QCOMPARE( sc2.readEntry( "stringEntry4" ), QString( STRINGENTRY4 ) );
   QVERIFY( !sc2.hasKey( "stringEntry5" ) );
-  QCOMPARE( sc2.readEntry( "stringEntry5", "test" ), QString( "test" ) );
+  QCOMPARE( sc2.readEntry( "stringEntry5", QString("test") ), QString( "test" ) );
   QVERIFY( !sc2.hasKey( "stringEntry6" ) );
-  QCOMPARE( sc2.readEntry( "stringEntry6", "foo" ), QString( "foo" ) );
-  QCOMPARE( sc2.readBoolEntry( "boolEntry1" ), BOOLENTRY1 );
-  QCOMPARE( sc2.readBoolEntry( "boolEntry2" ), BOOLENTRY2 );
+  QCOMPARE( sc2.readEntry( "stringEntry6", QString("foo") ), QString( "foo" ) );
+  QCOMPARE( sc2.readEntry( "boolEntry1", BOOLENTRY1 ).toBool(), BOOLENTRY1 );
+  QCOMPARE( sc2.readEntry( "boolEntry2", QVariant::Bool ).toBool(), BOOLENTRY2 );
 
 #if 0
   QString s;
@@ -152,17 +155,24 @@
 
   sc2.setGroup("OtherTypes");
 
-  QCOMPARE( sc2.readPointEntry( "pointEntry" ), POINTENTRY );
-  QCOMPARE( sc2.readSizeEntry( "sizeEntry" ), SIZEENTRY);
-  QCOMPARE( sc2.readRectEntry( "rectEntry" ), RECTENTRY );
-  QCOMPARE( sc2.readDateTimeEntry( "dateTimeEntry" ).toString(), \
                DATETIMEENTRY.toString() );
-  QCOMPARE( sc2.readListEntry( "stringListEntry").join( "," ), STRINGLISTENTRY.join( \
"," ) ); +  QCOMPARE( sc2.readEntry( "pointEntry", QPoint() ).toPoint(), POINTENTRY \
); +  QCOMPARE( sc2.readEntry( "sizeEntry", SIZEENTRY ).toSize(), SIZEENTRY);
+  QCOMPARE( sc2.readEntry( "rectEntry", QVariant::Rect ).toRect(), RECTENTRY );
+  QCOMPARE( sc2.readEntry( "dateTimeEntry", QDateTime() ).toString(),
+            DATETIMEENTRY.toString(Qt::ISODate) );
+  QCOMPARE( sc2.readEntry( "dateTimeEntry", QDate() ).toString(),
+            DATETIMEENTRY.date().toString(Qt::ISODate) );
+  QCOMPARE( sc2.readEntry( "stringListEntry", QStringList()).toStringList().join( \
"," ), +            STRINGLISTENTRY.join( "," ) );
+  QCOMPARE( sc2.readEntry( "colorEntry", QColor(Qt::black) ).toString(),
+            QVariant(COLORENTRY).toString() );
+  QCOMPARE( qvariant_cast<QColor>(sc2.readEntry( "colorEntry" )), COLORENTRY );
+  QCOMPARE( sc2.readEntry( "fontEntry", QFont() ).toString(), \
QVariant(FONTENTRY).toString() );  
-  QCOMPARE( sc2.readEntry( "byteArrayEntry1" ).toLatin1(), QByteArray( STRINGENTRY1 \
) ); +  QCOMPARE( sc2.readEntry( "byteArrayEntry1", QVariant::ByteArray \
).toByteArray(), QByteArray( STRINGENTRY1 ) );  QCOMPARE( sc2.readEntry( \
                "listOfIntsEntry1" ), QString::fromLatin1( "1,2,3,4" ) );
-  QList<int> intList = sc2.readIntListEntry( "listOfIntsEntry1" );
   QList<int> expectedIntList = INTLISTENTRY1;
-  QCOMPARE( intList, expectedIntList );
+  QCOMPARE( sc2.readIntListEntry( "listOfIntsEntry1" ), expectedIntList );
 
   QCOMPARE( sc2.readEntry( "listOfByteArraysEntry1" ), QString::fromLatin1( \
",1\\,2,end" ) );  QList<QByteArray> baList = sc2.readByteArrayListEntry( \
"listOfByteArraysEntry1" );



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic