• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kdgantt1

KDGanttXMLTools.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002    $Id: KDGanttXMLTools.cpp 836291 2008-07-22 04:34:42Z pradeepto $
00003    KDGantt - a multi-platform charting engine
00004 */
00005 
00006 /****************************************************************************
00007  ** Copyright (C)  2002-2004 Klarälvdalens Datakonsult AB.  All rights reserved.
00008  **
00009  ** This file is part of the KDGantt library.
00010  **
00011  ** This file may be used under the terms of the GNU General Public
00012  ** License versions 2.0 or 3.0 as published by the Free Software
00013  ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
00014  ** included in the packaging of this file.  Alternatively you may (at
00015  ** your option) use any later version of the GNU General Public
00016  ** License if such license has been publicly approved by
00017  ** Klarälvdalens Datakonsult AB (or its successors, if any).
00018  ** 
00019  ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
00020  ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
00021  ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
00022  ** not expressly granted herein.
00023  ** 
00024  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00025  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00026  **
00027  ** As a special exception, permission is given to link this program
00028  ** with any edition of Qt, and distribute the resulting executable,
00029  ** without including the source code for Qt in the source distribution.
00030  **
00031  **********************************************************************/
00032 
00033 #include "KDGanttXMLTools.h"
00034 #include <QBrush>
00035 #include <QBuffer>
00036 #include <QImage>
00037 #include <zlib.h>
00038 
00039 namespace KDGanttXML {
00040 
00041 void createBoolNode( QDomDocument& doc, QDomNode& parent,
00042                      const QString& elementName, bool value )
00043 {
00044     QDomElement newElement =
00045         doc.createElement( elementName );
00046     parent.appendChild( newElement );
00047     QDomText elementContent =
00048         doc.createTextNode( value ? "true" : "false" );
00049     newElement.appendChild( elementContent );
00050 }
00051 
00052 
00053 
00054 void createSizeNode( QDomDocument& doc, QDomNode& parent,
00055                      const QString& elementName, const QSize& value )
00056 {
00057     QDomElement newElement =
00058         doc.createElement( elementName );
00059     parent.appendChild( newElement );
00060     newElement.setAttribute( "Width", value.width() );
00061     newElement.setAttribute( "Height", value.height() );
00062 }
00063 
00064 
00065 void createIntNode( QDomDocument& doc, QDomNode& parent,
00066                     const QString& elementName, int value )
00067 {
00068     QDomElement newElement =
00069         doc.createElement( elementName );
00070     parent.appendChild( newElement );
00071     QDomText elementContent =
00072         doc.createTextNode( QString::number( value ) );
00073     newElement.appendChild( elementContent );
00074 }
00075 
00076 
00077 void createDoubleNode( QDomDocument& doc, QDomNode& parent,
00078                        const QString& elementName, double value )
00079 {
00080     QDomElement newElement =
00081         doc.createElement( elementName );
00082     parent.appendChild( newElement );
00083     QDomText elementContent =
00084         doc.createTextNode( QString::number( value ) );
00085     newElement.appendChild( elementContent );
00086 }
00087 
00088 
00089 void createStringNode( QDomDocument& doc, QDomNode& parent,
00090                        const QString& elementName,
00091                        const QString& text )
00092 {
00093     QDomElement newElement =
00094         doc.createElement( elementName );
00095     parent.appendChild( newElement );
00096     QDomText elementContent =
00097         doc.createTextNode( text );
00098     newElement.appendChild( elementContent );
00099 }
00100 
00101 
00102 void createColorNode( QDomDocument& doc, QDomNode& parent,
00103                       const QString& elementName, const QColor& color )
00104 {
00105     QDomElement colorElement = doc.createElement( elementName );
00106     parent.appendChild( colorElement );
00107     colorElement.setAttribute( "Red",
00108                                QString::number( color.red() ) );
00109     colorElement.setAttribute( "Green",
00110                                QString::number( color.green() ) );
00111     colorElement.setAttribute( "Blue",
00112                                QString::number( color.blue() ) );
00113 }
00114 
00115 
00116 void createBrushNode( QDomDocument& doc, QDomNode& parent,
00117                       const QString& elementName, const QBrush& brush )
00118 
00119 {
00120     QDomElement brushElement = doc.createElement( elementName );
00121     parent.appendChild( brushElement );
00122     createColorNode( doc, brushElement, "Color", brush.color() );
00123     createStringNode( doc, brushElement, "Style",
00124                       KDGanttXML::brushStyleToString( brush.style() ) );
00125     if( brush.style() == Qt::TexturePattern && !brush.texture().isNull() )
00126         createPixmapNode( doc, brushElement, "Pixmap", brush.texture() );
00127 }
00128 
00129 
00130 void createPixmapNode( QDomDocument& doc, QDomNode& parent,
00131                        const QString& elementName, const QPixmap& pixmap, int id )
00132 {
00133     QDomElement pixmapElement = doc.createElement( elementName );
00134     parent.appendChild( pixmapElement );
00135     pixmapElement.setAttribute( "ID", QString::number( id ) );
00136     // Convert the pixmap to an image, save that image to an in-memory
00137     // XPM representation and compress this representation. This
00138     // conforms to the file format Qt Designer uses.
00139     QByteArray ba;
00140 #if QT_VERSION < 0x040000
00141     QBuffer buffer( ba );
00142     buffer.open( IO_WriteOnly );
00143     QImageIO imgio( &buffer, "XPM" );
00144     QImage image = pixmap.convertToImage();
00145     imgio.setImage( image );
00146     imgio.write();
00147     buffer.close();
00148 #else
00149     QBuffer buffer( &ba );
00150     buffer.open( IO_WriteOnly );
00151     QImage image = pixmap.toImage();
00152     image.save( &buffer,  "XPM" );
00153     buffer.close();
00154 #endif
00155     ulong len = ba.size() * 2;
00156     QByteArray bazip( len, '\0' );
00157     ::compress(  (uchar*) bazip.data(), &len, (uchar*) ba.data(), ba.size() );
00158     QString dataString;
00159     static const char hexchars[] = "0123456789abcdef";
00160     for ( int i = 0; i < (int)len; ++i ) {
00161         uchar c = (uchar) bazip[i];
00162         dataString += hexchars[c >> 4];
00163         dataString += hexchars[c & 0x0f];
00164     }
00165 
00166     createStringNode( doc, pixmapElement, "Format", "XPM.GZ" );
00167     createIntNode( doc, pixmapElement, "Length", ba.size() );
00168     createStringNode( doc, pixmapElement, "Data", dataString );
00169 }
00170 
00171 
00172 void createRectNode( QDomDocument& doc, QDomNode& parent,
00173                      const QString& elementName, const QRect& rect )
00174 {
00175     QDomElement rectElement = doc.createElement( elementName );
00176     parent.appendChild( rectElement );
00177     QDomElement xElement = doc.createElement( "X" );
00178     rectElement.appendChild( xElement );
00179     QDomText xContent = doc.createTextNode( QString::number( rect.x() ) );
00180     xElement.appendChild( xContent );
00181     QDomElement yElement = doc.createElement( "Y" );
00182     rectElement.appendChild( yElement );
00183     QDomText yContent = doc.createTextNode( QString::number( rect.y() ) );
00184     yElement.appendChild( yContent );
00185     QDomElement widthElement = doc.createElement( "Width" );
00186     rectElement.appendChild( widthElement );
00187     QDomText widthContent = doc.createTextNode( QString::number( rect.width() ) );
00188     widthElement.appendChild( widthContent );
00189     QDomElement heightElement = doc.createElement( "Height" );
00190     rectElement.appendChild( heightElement );
00191     QDomText heightContent = doc.createTextNode( QString::number( rect.height() ) );
00192     heightElement.appendChild( heightContent );
00193 }
00194 
00195 
00196 void createStringListNodes( QDomDocument& doc, QDomNode& parent,
00197                             const QString& elementName,
00198                             const QStringList* list )
00199 {
00200     if( !list )
00201         return;
00202 
00203     for( QStringList::ConstIterator it = list->begin();
00204          it != list->end(); ++it ) {
00205         QDomElement element = doc.createElement( elementName );
00206         parent.appendChild( element );
00207         QDomText elementContent = doc.createTextNode( *it );
00208         element.appendChild( elementContent );
00209     }
00210 }
00211 
00212 
00213 void createFontNode( QDomDocument& doc, QDomNode& parent,
00214                      const QString& elementName, const QFont& font )
00215 {
00216     QDomElement fontElement = doc.createElement( elementName );
00217     parent.appendChild( fontElement );
00218     createStringNode( doc, fontElement, "Family", font.family() );
00219     createIntNode( doc, fontElement, "PointSize", font.pointSize() );
00220     createIntNode( doc, fontElement, "PixelSize", font.pixelSize() );
00221     createIntNode( doc, fontElement, "Weight", font.weight() );
00222     createBoolNode( doc, fontElement, "Italic", font.italic() );
00223 #if QT_VERSION < 300
00224     // Qt 3 handles the charset internally.
00225     createIntNode( doc, fontElement, "CharSet", font.charSet() );
00226 #endif
00227 }
00228 
00229 
00230 void createPenNode( QDomDocument& doc, QDomNode& parent,
00231                     const QString& elementName, const QPen& pen )
00232 {
00233     QDomElement penElement = doc.createElement( elementName );
00234     parent.appendChild( penElement );
00235     createIntNode( doc, penElement, "Width", pen.width() );
00236     createColorNode( doc, penElement, "Color", pen.color() );
00237     createStringNode( doc, penElement, "Style", penStyleToString( pen.style() ) );
00238 }
00239 
00240 
00241 void createDateTimeNode( QDomDocument& doc, QDomNode& parent,
00242                          const QString& elementName,
00243                          const QDateTime& datetime )
00244 {
00245     QDomElement dateTimeElement = doc.createElement( elementName );
00246     parent.appendChild( dateTimeElement );
00247     createDateNode( doc, dateTimeElement, "Date", datetime.date() );
00248     createTimeNode( doc, dateTimeElement, "Time", datetime.time() );
00249 }
00250 
00251 
00252 void createDateNode( QDomDocument& doc, QDomNode& parent,
00253                      const QString& elementName, const QDate& date )
00254 {
00255     QDomElement dateElement = doc.createElement( elementName );
00256     parent.appendChild( dateElement );
00257     dateElement.setAttribute( "Year", QString::number( date.year() ) );
00258     dateElement.setAttribute( "Month", QString::number( date.month() ) );
00259     dateElement.setAttribute( "Day", QString::number( date.day() ) );
00260 }
00261 
00262 
00263 void createTimeNode( QDomDocument& doc, QDomNode& parent,
00264                       const QString& elementName, const QTime& time )
00265 {
00266     QDomElement timeElement = doc.createElement( elementName );
00267     parent.appendChild( timeElement );
00268     timeElement.setAttribute( "Hour",
00269                                QString::number( time.hour() ) );
00270     timeElement.setAttribute( "Minute",
00271                                QString::number( time.minute() ) );
00272     timeElement.setAttribute( "Second",
00273                                QString::number( time.second() ) );
00274     timeElement.setAttribute( "Millisecond",
00275                                QString::number( time.msec() ) );
00276 }
00277 
00278 
00279 QString penStyleToString( Qt::PenStyle style )
00280 {
00281     switch( style ) {
00282     case Qt::NoPen:
00283         return "NoPen";
00284     case Qt::SolidLine:
00285         return "SolidLine";
00286     case Qt::DashLine:
00287         return "DashLine";
00288     case Qt::DotLine:
00289         return "DotLine";
00290     case Qt::DashDotLine:
00291         return "DashDotLine";
00292     case Qt::DashDotDotLine:
00293         return "DashDotDotLine";
00294     default: // should not happen
00295         return "SolidLine";
00296     }
00297 }
00298 
00299 
00300 
00301 QString brushStyleToString( Qt::BrushStyle style )
00302 {
00303     // PENDING(kalle) Support custom patterns
00304     switch( style ) {
00305     case Qt::NoBrush:
00306         return "NoBrush";
00307     case Qt::SolidPattern:
00308         return "SolidPattern";
00309     case Qt::Dense1Pattern:
00310         return "Dense1Pattern";
00311     case Qt::Dense2Pattern:
00312         return "Dense2Pattern";
00313     case Qt::Dense3Pattern:
00314         return "Dense3Pattern";
00315     case Qt::Dense4Pattern:
00316         return "Dense4Pattern";
00317     case Qt::Dense5Pattern:
00318         return "Dense5Pattern";
00319     case Qt::Dense6Pattern:
00320         return "Dense6Pattern";
00321     case Qt::Dense7Pattern:
00322         return "Dense7Pattern";
00323     case Qt::HorPattern:
00324         return "HorPattern";
00325     case Qt::VerPattern:
00326         return "VerPattern";
00327     case Qt::CrossPattern:
00328         return "CrossPattern";
00329     case Qt::BDiagPattern:
00330         return "BDiagPattern";
00331     case Qt::FDiagPattern:
00332         return "FDiagPattern";
00333     case Qt::DiagCrossPattern:
00334         return "DiagCrossPattern";
00335     default: // should not happen (but can for a custom pattern)
00336         return "SolidPattern";
00337     }
00338 }
00339 
00340 
00341 bool readStringNode( const QDomElement& element, QString& value )
00342 {
00343     value = element.text();
00344     return true;
00345 }
00346 
00347 
00348 bool readIntNode( const QDomElement& element, int& value )
00349 {
00350     bool ok = false;
00351     int temp = element.text().toInt( &ok );
00352     if( ok )
00353         value = temp;
00354     return ok;
00355 }
00356 
00357 
00358 bool readDoubleNode( const QDomElement& element, double& value )
00359 {
00360     bool ok = false;
00361     double temp = element.text().toDouble( &ok );
00362     if( ok )
00363         value = temp;
00364     return ok;
00365 }
00366 
00367 
00368 bool readBoolNode( const QDomElement& element, bool& value )
00369 {
00370     if( element.text() == "true" ) {
00371         value = true;
00372         return true;
00373     } else if( element.text() == "false" ) {
00374         value = false;
00375         return true;
00376     } else
00377         return false;
00378 }
00379 
00380 
00381 bool readColorNode( const QDomElement& element, QColor& value )
00382 {
00383     int ok = 0;
00384     int red = 0, green = 0, blue = 0;
00385     if( element.hasAttribute( "Red" ) ) {
00386         bool redOk = false;
00387         red = element.attribute( "Red" ).toInt( &redOk );
00388     ok += redOk;
00389     }
00390     if( element.hasAttribute( "Green" ) ) {
00391         bool greenOk = false;
00392         green = element.attribute( "Green" ).toInt( &greenOk );
00393         ok += greenOk;
00394     }
00395     if( element.hasAttribute( "Blue" ) ) {
00396         bool blueOk = false;
00397         blue = element.attribute( "Blue" ).toInt( &blueOk );
00398         ok += blueOk;
00399     }
00400 
00401     if( ok == 3 )
00402         value.setRgb( red, green, blue );
00403 
00404     return ok == 3;
00405 }
00406 
00407 
00408 bool readBrushNode( const QDomElement& element, QBrush& brush )
00409 {
00410     bool ok = true;
00411     QColor tempColor;
00412     Qt::BrushStyle tempStyle = Qt::NoBrush;
00413     QPixmap tempPixmap;
00414     QDomNode node = element.firstChild();
00415     while( !node.isNull() ) {
00416         QDomElement element = node.toElement();
00417         if( !element.isNull() ) { // was really an element
00418             QString tagName = element.tagName();
00419             if( tagName == "Color" ) {
00420                 ok = ok & readColorNode( element, tempColor );
00421             } else if( tagName == "Style" ) {
00422         QString value;
00423                 ok = ok & readStringNode( element, value );
00424         tempStyle = stringToBrushStyle( value );
00425             } else if( tagName == "Pixmap" ) {
00426                 ok = ok & readPixmapNode( element, tempPixmap );
00427             } else {
00428                 qDebug( "Unknown tag in brush" );
00429             }
00430         }
00431         node = node.nextSibling();
00432     }
00433 
00434     if( ok ) {
00435     brush.setColor( tempColor );
00436     brush.setStyle( tempStyle );
00437         if( !tempPixmap.isNull() )
00438             brush.setTexture( tempPixmap );
00439     }
00440 
00441     return ok;
00442 }
00443 
00444 
00445 bool readPixmapNode( const QDomElement& element, QPixmap& pixmap )
00446 {
00447     bool ok = true;
00448     ulong tempLength = 0;
00449     QString tempData;
00450     QDomNode node = element.firstChild();
00451     while( !node.isNull() ) {
00452         QDomElement element = node.toElement();
00453         if( !element.isNull() ) { // was really an element
00454             QString tagName = element.tagName();
00455             if( tagName == "Format" ) {
00456                 QString formatName;
00457                 ok = ok & readStringNode( element, formatName );
00458 #ifndef NDEBUG
00459                 if( formatName != "XPM.GZ" )
00460                     qDebug( "Unsupported pixmap format in XML file" );
00461 #endif
00462             } else if( tagName == "Length" ) {
00463         int tempInt;
00464                 ok = ok & readIntNode( element, tempInt );
00465             tempLength = tempInt;
00466             } else if( tagName == "Data" ) {
00467                 ok = ok & readStringNode( element, tempData );
00468             } else {
00469                 qDebug( "Unknown tag in Pixmap" );
00470             }
00471         }
00472         node = node.nextSibling();
00473     }
00474 
00475     if( ok ) {
00476     if( 0 < tempLength ) {
00477             // Decode the image file format in the same way Qt Designer does.
00478             char *ba = new char[ tempData.length() / 2 ];
00479             for ( int i = 0; i < (int)tempData.length() / 2; ++i ) {
00480                 char h = tempData[ 2 * i ].toLatin1();
00481                 char l = tempData[ 2 * i  + 1 ].toLatin1();
00482                 uchar r = 0;
00483                 if ( h <= '9' )
00484                     r += h - '0';
00485                 else
00486                     r += h - 'a' + 10;
00487                 r = r << 4;
00488                 if ( l <= '9' )
00489                     r += l - '0';
00490                 else
00491                     r += l - 'a' + 10;
00492                 ba[ i ] = r;
00493             }
00494 
00495             if( tempLength < tempData.length() * 5UL )
00496                 tempLength = tempData.length() * 5;
00497             QByteArray baunzip( tempLength, '\0' );
00498             ::uncompress( (uchar*) baunzip.data(), &tempLength,
00499                           (uchar*) ba, tempData.length()/2 );
00500             QImage image;
00501             image.loadFromData( (const uchar*)baunzip.data(), tempLength, "XPM" );
00502 
00503             if( image.isNull() )
00504                 pixmap = QPixmap( ); // This is _not_ an error, we just read a NULL pixmap!
00505             else {
00506                 pixmap = QPixmap::fromImage( image );
00507         ok = ok & !pixmap.isNull();
00508         }
00509         } else
00510             pixmap = QPixmap(); // This is _not_ an error, we just read a empty pixmap!
00511     }
00512 
00513     return ok;
00514 }
00515 
00516 
00517 bool readPenNode( const QDomElement& element, QPen& pen )
00518 {
00519     bool ok = true;
00520     int tempWidth;
00521     QColor tempColor;
00522     Qt::PenStyle tempStyle = Qt::NoPen;
00523     QDomNode node = element.firstChild();
00524     while( !node.isNull() ) {
00525         QDomElement element = node.toElement();
00526         if( !element.isNull() ) { // was really an element
00527             QString tagName = element.tagName();
00528             if( tagName == "Width" ) {
00529                 ok = ok & readIntNode( element, tempWidth );
00530             } else if( tagName == "Color" ) {
00531                 ok = ok & readColorNode( element, tempColor );
00532             } else if( tagName == "Style" ) {
00533         QString value;
00534                 ok = ok & readStringNode( element, value );
00535         tempStyle = stringToPenStyle( value );
00536             } else {
00537                 qDebug( "Unknown tag in brush" );
00538             }
00539         }
00540         node = node.nextSibling();
00541     }
00542 
00543     if( ok ) {
00544         pen.setWidth( tempWidth );
00545     pen.setColor( tempColor );
00546     pen.setStyle( tempStyle );
00547     }
00548 
00549     return ok;
00550 }
00551 
00552 bool readFontNode( const QDomElement& element, QFont& font )
00553 {
00554     bool ok = true;
00555     QString family;
00556     int pointSize, pixelSize, weight;
00557     bool italic;
00558     int charSet;
00559     QDomNode node = element.firstChild();
00560     while( !node.isNull() ) {
00561         QDomElement element = node.toElement();
00562         if( !element.isNull() ) { // was really an element
00563             QString tagName = element.tagName();
00564             if( tagName == "Family" ) {
00565                 ok = ok & readStringNode( element, family );
00566             } else if( tagName == "PointSize" ) {
00567                 ok = ok & readIntNode( element, pointSize );
00568             } else if( tagName == "PixelSize" ) {
00569                 ok = ok & readIntNode( element, pixelSize );
00570             } else if( tagName == "Weight" ) {
00571                 ok = ok & readIntNode( element, weight );
00572             } else if( tagName == "Italic" ) {
00573                 ok = ok & readBoolNode( element, italic );
00574             } else if( tagName == "CharSet" ) {
00575                 ok = ok & readIntNode( element, charSet );
00576             } else {
00577                 qDebug( "Unknown tag in color map" );
00578             }
00579         }
00580         node = node.nextSibling();
00581     }
00582 
00583     if( ok ) {
00584         font.setFamily( family );
00585     if ( pointSize > 0 ) font.setPointSize( pointSize );
00586     if ( pixelSize > 0 ) font.setPixelSize( pixelSize );
00587         font.setWeight( weight );
00588         font.setItalic( italic );
00589 #if QT_VERSION < 300
00590         // Qt 3 handles charsets internally.
00591         font.setCharSet( (QFont::CharSet)charSet );
00592 #endif
00593     }
00594 
00595     return ok;
00596 }
00597 
00598 bool readRectNode( const QDomElement& element, QRect& value )
00599 {
00600     bool ok = true;
00601     int width, height, x, y;
00602     QDomNode node = element.firstChild();
00603     while( !node.isNull() ) {
00604         QDomElement element = node.toElement();
00605         if( !element.isNull() ) { // was really an element
00606             QString tagName = element.tagName();
00607             if( tagName == "Width" ) {
00608                 ok = ok & readIntNode( element, width );
00609             } else if( tagName == "Height" ) {
00610                 ok = ok & readIntNode( element, height );
00611             } else if( tagName == "X" ) {
00612                 ok = ok & readIntNode( element, x );
00613             } else if( tagName == "Y" ) {
00614                 ok = ok & readIntNode( element, y );
00615             } else {
00616                 qDebug( "Unknown tag in rect" );
00617             }
00618         }
00619         node = node.nextSibling();
00620     }
00621 
00622     if( ok ) {
00623         value.setX( x );
00624         value.setY( y );
00625         value.setWidth( width );
00626         value.setHeight( height );
00627     }
00628 
00629     return ok;
00630 }
00631 
00632 
00633 
00634 bool readDateTimeNode( const QDomElement& element, QDateTime& datetime )
00635 {
00636     bool ok = true;
00637     QDate tempDate;
00638     QTime tempTime;
00639     QDomNode node = element.firstChild();
00640     while( !node.isNull() ) {
00641         QDomElement element = node.toElement();
00642         if( !element.isNull() ) { // was really an element
00643             QString tagName = element.tagName();
00644             if( tagName == "Date" ) {
00645                 ok = ok & readDateNode( element, tempDate );
00646             } else if( tagName == "Time" ) {
00647                 ok = ok & readTimeNode( element, tempTime );
00648             } else {
00649                 qDebug( "Unknown tag in datetime" );
00650             }
00651         }
00652         node = node.nextSibling();
00653     }
00654 
00655     if( ok ) {
00656         datetime.setDate( tempDate );
00657         datetime.setTime( tempTime );
00658     }
00659 
00660     return ok;
00661 }
00662 
00663 
00664 bool readDateNode( const QDomElement& element, QDate& value )
00665 {
00666     int year = 0, month = 0, day = 0;
00667     if( element.hasAttribute( "Year" ) ) {
00668         bool yearOk = false;
00669         year = element.attribute( "Year" ).toInt( &yearOk );
00670     if (!yearOk) return false;
00671     }
00672     if( element.hasAttribute( "Month" ) ) {
00673         bool monthOk = false;
00674         month = element.attribute( "Month" ).toInt( &monthOk );
00675     if (!monthOk) return false;
00676     }
00677     if( element.hasAttribute( "Day" ) ) {
00678         bool dayOk = false;
00679         day = element.attribute( "Day" ).toInt( &dayOk );
00680         if (!dayOk) return false;
00681     }
00682 
00683     value.setYMD( year, month, day );
00684     return true;
00685 }
00686 
00687 
00688 
00689 bool readTimeNode( const QDomElement& element, QTime& value )
00690 {
00691     int hour = 0, minute = 0, second = 0, msec = 0;
00692     if( element.hasAttribute( "Hour" ) ) {
00693         bool hourOk = false;
00694         hour = element.attribute( "Hour" ).toInt( &hourOk );
00695     if (!hourOk) return false;
00696     }
00697     if( element.hasAttribute( "Minute" ) ) {
00698         bool minuteOk = false;
00699         minute = element.attribute( "Minute" ).toInt( &minuteOk );
00700     if (!minuteOk) return false;
00701     }
00702     if( element.hasAttribute( "Second" ) ) {
00703         bool secondOk = false;
00704         second = element.attribute( "Second" ).toInt( &secondOk );
00705     if (!secondOk) return false;
00706     }
00707     if( element.hasAttribute( "Millisecond" ) ) {
00708         bool msecOk = false;
00709         msec = element.attribute( "Millisecond" ).toInt( &msecOk );
00710     if (!msecOk) return false;
00711     }
00712 
00713     value.setHMS( hour, minute, second, msec );
00714     return true;
00715 }
00716 
00717 
00718 
00719 Qt::PenStyle stringToPenStyle( const QString& style )
00720 {
00721     if( style == "NoPen" )
00722         return Qt::NoPen;
00723     else if( style == "SolidLine" )
00724         return Qt::SolidLine;
00725     else if( style == "DashLine" )
00726         return Qt::DashLine;
00727     else if( style == "DotLine" )
00728         return Qt::DotLine;
00729     else if( style == "DashDotLine" )
00730         return Qt::DashDotLine;
00731     else if( style == "DashDotDotLine" )
00732         return Qt::DashDotDotLine;
00733     else // should not happen
00734         return Qt::SolidLine;
00735 }
00736 
00737 
00738 Qt::BrushStyle stringToBrushStyle( const QString& style )
00739 {
00740     // PENDING(kalle) Support custom patterns
00741     if( style == "NoBrush" )
00742         return Qt::NoBrush;
00743     else if( style == "SolidPattern" )
00744         return Qt::SolidPattern;
00745     else if( style == "Dense1Pattern" )
00746         return Qt::Dense1Pattern;
00747     else if( style == "Dense2Pattern" )
00748         return Qt::Dense2Pattern;
00749     else if( style == "Dense3Pattern" )
00750         return Qt::Dense3Pattern;
00751     else if( style == "Dense4Pattern" )
00752         return Qt::Dense4Pattern;
00753     else if( style == "Dense5Pattern" )
00754         return Qt::Dense5Pattern;
00755     else if( style == "Dense6Pattern" )
00756         return Qt::Dense6Pattern;
00757     else if( style == "Dense7Pattern" )
00758         return Qt::Dense7Pattern;
00759     else if( style == "HorPattern" )
00760         return Qt::HorPattern;
00761     else if( style == "VerPattern" )
00762         return Qt::VerPattern;
00763     else if( style == "CrossPattern" )
00764         return Qt::CrossPattern;
00765     else if( style == "BDiagPattern" )
00766         return Qt::BDiagPattern;
00767     else if( style == "FDiagPattern" )
00768         return Qt::FDiagPattern;
00769     else if( style == "DiagCrossPattern" )
00770         return Qt::DiagCrossPattern;
00771     else // should not happen (but can with custom patterns)
00772         return Qt::SolidPattern;
00773 }
00774 
00775 }

kdgantt1

Skip menu "kdgantt1"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal