kdgantt Library API Documentation

KDGanttXMLTools.cpp

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