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

List:       kde-commits
Subject:    kdeextragear-1/datakiosk/src
From:       Adam Treat <manyoso () yahoo ! com>
Date:       2005-04-01 17:59:07
Message-ID: 20050401175907.0FF6B490 () office ! kde ! org
[Download RAW message or body]

CVS commit by treat: 

* Speed up the data report generation quite a lot by only selecting the fields
from the database that are actually in the generated report.


  M +50 -1     datareport.cpp   1.6
  M +1 -0      datareport.h   1.2


--- kdeextragear-1/datakiosk/src/datareport.cpp  #1.5:1.6
@@ -31,4 +31,7 @@
 #include <kmessagebox.h>
 
+#include <kzip.h>
+#include <karchive.h>
+
 #define widget (kapp->mainWidget())
 
@@ -103,4 +106,49 @@ void DataReport::initialize()
 }
 
+QStringList DataReport::readTemplateFields() const
+{
+    if ( m_templateURL == QString::null )
+        return QStringList();
+
+    QStringList templateFields;
+    QDomDocument doc;
+    bool openedDom = false;
+
+    KZip zip( m_templateURL );
+    if ( zip.open( IO_ReadOnly ) )
+    {
+        kdDebug() << m_templateURL << " is a zip file" <<  endl;
+        const KArchiveFile *maindoc = dynamic_cast<const KArchiveFile*>( \
zip.directory()->entry( "maindoc.xml" ) ); +        if ( maindoc )
+            openedDom = doc.setContent( maindoc->data() );
+        zip.close();
+    }
+    else
+    {
+        QFile f( m_templateURL );
+        if ( f.open( IO_ReadOnly ) )
+        {
+            kdDebug() << m_templateURL << " is a regular file" <<  endl;
+            openedDom = doc.setContent( &f );
+            f.close();
+        }
+    }
+
+    if ( !openedDom )
+        return QStringList();
+
+    kdDebug() << "successfully opened the template dom" <<  endl;
+
+    QDomNodeList fields = doc.elementsByTagName( "Field" );
+    for ( uint i = 0; i < fields.length(); i++ )
+    {
+        QDomElement field = fields.item( i ).toElement();
+/*        kdDebug() << field.attribute( "Field" ) << endl;*/
+        templateFields.append( field.attribute( "Field" ) );
+    }
+
+    return templateFields;
+}
+
 void DataReport::refreshReport()
 {
@@ -129,4 +177,5 @@ void DataReport::refreshReport()
     }
 
+    QStringList templateFields = readTemplateFields();
     DataTableList::Iterator it = list.begin();
     for ( ; it != list.end(); ++it )
@@ -155,5 +204,5 @@ void DataReport::refreshReport()
         for ( ; it2 != fields.end(); ++it2 )
         {
-            if ( !( *it2 ) ->hidden() )
+            if ( !( *it2 ) ->hidden() && templateFields.contains( ( *it2 ) \
->fullName() ) )  {
                 select.append( ( *it2 ) ->fullName() );

--- kdeextragear-1/datakiosk/src/datareport.h  #1.1.1.1:1.2
@@ -64,4 +64,5 @@ signals:
 private:
     void setup();
+    QStringList readTemplateFields() const;
 
 private:


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

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