kchart

KDChartPropertySet.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002    KDChart - a multi-platform charting engine
00003    */
00004 
00005 /****************************************************************************
00006  ** Copyright (C) 2001-2003 Klarälvdalens Datakonsult AB.  All rights reserved.
00007  **
00008  ** This file is part of the KDChart library.
00009  **
00010  ** This file may be distributed and/or modified under the terms of the
00011  ** GNU General Public License version 2 as published by the Free Software
00012  ** Foundation and appearing in the file LICENSE.GPL included in the
00013  ** packaging of this file.
00014  **
00015  ** Licensees holding valid commercial KDChart licenses may use this file in
00016  ** accordance with the KDChart Commercial License Agreement provided with
00017  ** the Software.
00018  **
00019  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021  **
00022  ** See http://www.klaralvdalens-datakonsult.se/?page=products for
00023  **   information about KDChart Commercial License Agreements.
00024  **
00025  ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
00026  ** licensing are not clear to you.
00027  **
00028  **********************************************************************/
00029 #include "KDChartRingPainter.h"
00030 #include "KDChartParams.h"
00031 #include "KDXMLTools.h"
00032 
00033 #include <qpainter.h>
00034 #include <qvaluestack.h>
00035 
00036 #include <stdlib.h>
00037 
00044 void KDChartPropertySet::deepCopy( const KDChartPropertySet* source )
00045 {
00046     if( !source || this == source )
00047         return;
00048     mOwnID = source->mOwnID;
00049     mName  = source->mName;
00050     mIdShowBar           = source->mIdShowBar;           mShowBar           = source->mShowBar;
00051     mIdBarColor          = source->mIdBarColor;          mBarColor          = source->mBarColor;
00052     mIdAreaBrush         = source->mIdAreaBrush;         mAreaBrush         = source->mAreaBrush;
00053     mIdLineWidth         = source->mIdLineWidth;         mLineWidth         = source->mLineWidth;
00054     mIdLineColor         = source->mIdLineColor;         mLineColor         = source->mLineColor;
00055     mIdLineStyle         = source->mIdLineStyle;         mLineStyle         = source->mLineStyle;
00056     mIdShowMarker        = source->mIdShowMarker;        mShowMarker        = source->mShowMarker;
00057     mIdMarkerSize        = source->mIdMarkerSize;        mMarkerSize        = source->mMarkerSize;
00058     mIdMarkerColor       = source->mIdMarkerColor;       mMarkerColor       = source->mMarkerColor;
00059     mIdMarkerStyle       = source->mIdMarkerStyle;       mMarkerStyle       = source->mMarkerStyle;
00060     mIdMarkerAlign       = source->mIdMarkerAlign;       mMarkerAlign       = source->mMarkerAlign;
00061     mIdExtraLinesAlign   = source->mIdExtraLinesAlign;   mExtraLinesAlign   = source->mExtraLinesAlign;
00062     mIdExtraLinesInFront = source->mIdExtraLinesInFront; mExtraLinesInFront = source->mExtraLinesInFront;
00063     mIdExtraLinesLength  = source->mIdExtraLinesLength;  mExtraLinesLength  = source->mExtraLinesLength;
00064     mIdExtraLinesWidth   = source->mIdExtraLinesWidth;   mExtraLinesWidth   = source->mExtraLinesWidth;
00065     mIdExtraLinesColor   = source->mIdExtraLinesColor;   mExtraLinesColor   = source->mExtraLinesColor;
00066     mIdExtraLinesStyle   = source->mIdExtraLinesStyle;   mExtraLinesStyle   = source->mExtraLinesStyle;
00067     mIdExtraMarkersAlign = source->mIdExtraMarkersAlign; mExtraMarkersAlign = source->mExtraMarkersAlign;
00068     mIdExtraMarkersSize  = source->mIdExtraMarkersSize;  mExtraMarkersSize  = source->mExtraMarkersSize;
00069     mIdExtraMarkersColor = source->mIdExtraMarkersColor; mExtraMarkersColor = source->mExtraMarkersColor;
00070     mIdExtraMarkersStyle = source->mIdExtraMarkersStyle; mExtraMarkersStyle = source->mExtraMarkersStyle;
00071 }
00072 
00073 const KDChartPropertySet* KDChartPropertySet::clone() const
00074 {
00075     KDChartPropertySet* newSet = new KDChartPropertySet();
00076     newSet->deepCopy( this );
00077     return newSet;
00078 }
00079 
00080 void KDChartPropertySet::quickReset( const QString& name, int idParent )
00081 {
00082     // set the name
00083     mName = name;
00084     // fill with idParent
00085     mOwnID =               idParent;
00086     mIdLineWidth =         idParent;
00087     mIdLineColor =         idParent;
00088     mIdLineStyle =         idParent;
00089     mIdShowMarker =        idParent;
00090     mIdMarkerSize =        idParent;
00091     mIdMarkerColor =       idParent;
00092     mIdMarkerStyle =       idParent;
00093     mIdMarkerAlign =       idParent;
00094     mIdExtraLinesAlign =   idParent;
00095     mIdExtraLinesInFront = idParent;
00096     mIdExtraLinesLength =  idParent;
00097     mIdExtraLinesWidth =   idParent;
00098     mIdExtraLinesColor =   idParent;
00099     mIdExtraLinesStyle =   idParent;
00100     mIdExtraMarkersAlign = idParent;
00101     mIdExtraMarkersSize =  idParent;
00102     mIdExtraMarkersColor = idParent;
00103     mIdExtraMarkersStyle = idParent;
00104     mIdShowBar =           idParent;
00105     mIdBarColor =          idParent;
00106     mIdAreaBrush =         idParent;
00107 }
00108 
00109 void KDChartPropertySet::fullReset( const QString& name, int idParent )
00110 {
00111     quickReset( name, idParent );
00112     fillValueMembersWithDummyValues();
00113 }
00114 
00115 void KDChartPropertySet::fillValueMembersWithDummyValues()
00116 {
00117     // fill with dummy values to avoid problems when saving us into a stream
00118     mLineWidth         = 1;
00119     mLineColor         = Qt::black;
00120     mLineStyle         = Qt::SolidLine;
00121     mShowMarker        = true;
00122     mMarkerAlign       = Qt::AlignCenter;
00123     mMarkerSize        = QSize(6,6);
00124     mMarkerColor       = Qt::black;
00125     mMarkerStyle       = 0;
00126     mExtraLinesAlign   = Qt::AlignLeft|Qt::AlignTop;
00127     mExtraLinesInFront = false;
00128     mExtraLinesLength  = -20;
00129     mExtraLinesWidth   = 1;
00130     mExtraLinesColor   = Qt::black;
00131     mExtraLinesStyle   = Qt::SolidLine;
00132     mExtraMarkersAlign = Qt::AlignLeft|Qt::AlignTop;
00133     mExtraMarkersSize  = QSize(6,6);
00134     mExtraMarkersColor = Qt::black;
00135     mExtraMarkersStyle = 0;
00136     mShowBar           = true;
00137     mBarColor          = Qt::black;
00138     mAreaBrush         = QBrush( Qt::blue );
00139 }
00140 
00141 
00142 QDomElement KDChartPropertySet::saveXML(QDomDocument& doc) const
00143 {
00144     QDomElement propertySetElement = doc.createElement( "PropertySet" );
00145     propertySetElement.setAttribute( "OwnID", mOwnID );
00146     KDXML::createStringNode( doc, propertySetElement, "Name", mName );
00147     // normal bar properties:
00148     KDXML::createIntNode(    doc, propertySetElement, "IDShowBar",    mIdShowBar   );
00149     KDXML::createBoolNode(   doc, propertySetElement,   "ShowBar",      mShowBar   );
00150     KDXML::createIntNode(    doc, propertySetElement, "IDBarColor",   mIdBarColor  );
00151     KDXML::createColorNode(  doc, propertySetElement,   "BarColor",     mBarColor  );
00152     // normal area properties:
00153     KDXML::createIntNode(    doc, propertySetElement, "IDAreaBrush",  mIdAreaBrush );
00154     KDXML::createBrushNode(  doc, propertySetElement,   "AreaBrush",    mAreaBrush );
00155     // normal line properties:
00156     KDXML::createIntNode(    doc, propertySetElement, "IDLineWidth",  mIdLineWidth );
00157     KDXML::createIntNode(    doc, propertySetElement,   "LineWidth",    mLineWidth );
00158     KDXML::createIntNode(    doc, propertySetElement, "IDLineColor",  mIdLineColor );
00159     KDXML::createColorNode(  doc, propertySetElement,   "LineColor",    mLineColor );
00160     KDXML::createIntNode(    doc, propertySetElement, "IDLineStyle",  mIdLineStyle );
00161     QDomElement lineStyleElement = doc.createElement(   "LineStyle" );
00162     propertySetElement.appendChild( lineStyleElement );
00163     lineStyleElement.setAttribute( "Style", KDXML::penStyleToString(    mLineStyle));
00164     // normal marker properties:
00165     KDXML::createIntNode(    doc, propertySetElement, "IDShowMarker",  mIdShowMarker);
00166     KDXML::createBoolNode(   doc, propertySetElement,   "ShowMarker",    mShowMarker);
00167     KDXML::createIntNode(    doc, propertySetElement, "IDMarkerAlign", mIdMarkerAlign );
00168     KDXML::createIntNode(    doc, propertySetElement,   "MarkerAlign",   mMarkerAlign );
00169     KDXML::createIntNode(    doc, propertySetElement, "IDMarkerSize",  mIdMarkerSize   );
00170     KDXML::createSizeNode(   doc, propertySetElement,   "MarkerSize",    mMarkerSize  );
00171     KDXML::createIntNode(    doc, propertySetElement, "IDMarkerColor", mIdMarkerColor );
00172     KDXML::createColorNode(  doc, propertySetElement,   "MarkerColor",   mMarkerColor );
00173     KDXML::createIntNode(    doc, propertySetElement, "IDMarkerStyle", mIdMarkerStyle );
00174     QDomElement markerStElem = doc.createElement(       "MarkerStyle" );
00175     propertySetElement.appendChild( markerStElem );
00176     markerStElem.setAttribute("Style",
00177             KDChartParams::lineMarkerStyleToString( (KDChartParams::LineMarkerStyle)mMarkerStyle));
00178     // extra lines:
00179     KDXML::createIntNode(    doc, propertySetElement, "IDExtraLinesAlign",  mIdExtraLinesAlign );
00180     KDXML::createIntNode(    doc, propertySetElement,   "ExtraLinesAlign",    mExtraLinesAlign );
00181     KDXML::createIntNode(    doc, propertySetElement, "IDExtraLinesInFront",mIdExtraLinesInFront );
00182     KDXML::createBoolNode(   doc, propertySetElement,   "ExtraLinesInFront",  mExtraLinesInFront );
00183     KDXML::createIntNode(    doc, propertySetElement, "IDExtraLinesLength", mIdExtraLinesLength );
00184     KDXML::createIntNode(    doc, propertySetElement,   "ExtraLinesLength",   mExtraLinesLength );
00185     KDXML::createIntNode(    doc, propertySetElement, "IDExtraLinesWidth",  mIdExtraLinesWidth );
00186     KDXML::createIntNode(    doc, propertySetElement,   "ExtraLinesWidth",    mExtraLinesWidth );
00187     KDXML::createIntNode(    doc, propertySetElement, "IDExtraLinesColor",  mIdExtraLinesColor );
00188     KDXML::createColorNode(  doc, propertySetElement,   "ExtraLinesColor",    mExtraLinesColor );
00189     KDXML::createIntNode(    doc, propertySetElement, "IDExtraLinesStyle",  mIdExtraLinesStyle );
00190     QDomElement specLineStElem = doc.createElement(     "ExtraLinesStyle" );
00191     propertySetElement.appendChild( specLineStElem );
00192     specLineStElem.setAttribute( "Style", KDXML::penStyleToString(           mExtraLinesStyle));
00193     // extra markers:
00194     KDXML::createIntNode(    doc, propertySetElement, "IDExtraMarkersAlign", mIdExtraMarkersAlign );
00195     KDXML::createIntNode(    doc, propertySetElement,   "ExtraMarkersAlign",   mExtraMarkersAlign );
00196     KDXML::createIntNode(    doc, propertySetElement, "IDExtraMarkersSize",  mIdExtraMarkersSize   );
00197     KDXML::createSizeNode(   doc, propertySetElement,   "ExtraMarkersSize",    mExtraMarkersSize  );
00198     KDXML::createIntNode(    doc, propertySetElement, "IDExtraMarkersColor", mIdExtraMarkersColor );
00199     KDXML::createColorNode(  doc, propertySetElement,   "ExtraMarkersColor",   mExtraMarkersColor );
00200     KDXML::createIntNode(    doc, propertySetElement, "IDExtraMarkersStyle", mIdExtraMarkersStyle );
00201     QDomElement specMarkerStElem = doc.createElement(   "ExtraMarkersStyle" );
00202     propertySetElement.appendChild( specMarkerStElem );
00203     specMarkerStElem.setAttribute("Style",
00204             KDChartParams::lineMarkerStyleToString(    (KDChartParams::LineMarkerStyle)mExtraMarkersStyle));
00205     return propertySetElement;
00206 }
00207 
00208 bool KDChartPropertySet::loadXML( const QDomElement& element, KDChartPropertySet& set )
00209 {
00210     bool bOwnIDFound = false;
00211     QString s;
00212     QColor color;
00213     QBrush brush;
00214     QSize size;
00215     bool bValue;
00216     int i;
00217     // initialize the property set with default values
00218     set.fillValueMembersWithDummyValues();
00219     // parse the element
00220     if( element.hasAttribute("OwnID") ){
00221         i = element.attribute( "OwnID" ).toInt( &bOwnIDFound );
00222         if( bOwnIDFound ){
00223             set.mOwnID = i;
00224             QDomNode node = element.firstChild();
00225             while( !node.isNull() ) {
00226                 QDomElement element = node.toElement();
00227                 if( !element.isNull() ) { // was really an element
00228                     QString tagName = element.tagName();
00229                     if( tagName == "Name" ) {
00230                         if( KDXML::readStringNode( element, s ) )
00231                             set.mName = s;
00232                     } else
00233                     // normal bar properties:
00234                         if( tagName == "IDShowBar" ) {
00235                         if( KDXML::readIntNode( element, i ) )
00236                             set.mIdShowBar = i;
00237                     } else if( tagName ==   "ShowBar" ) {
00238                         if( KDXML::readBoolNode( element, bValue ) )
00239                             set.mShowBar = bValue;
00240                     } else if( tagName == "IDBarColor" ) {
00241                         if( KDXML::readIntNode( element, i ) )
00242                             set.mIdBarColor = i;
00243                     } else if( tagName ==   "BarColor" ) {
00244                         if( KDXML::readColorNode( element, color ) )
00245                             set.mBarColor = color;
00246                     } else
00247                     // normal area properties:
00248                            if( tagName == "IDAreaBrush" ) {
00249                         if( KDXML::readIntNode( element, i ) )
00250                             set.mIdAreaBrush = i;
00251                     } else if( tagName ==   "AreaBrush" ) {
00252                         if( KDXML::readBrushNode( element, brush ) )
00253                             set.mAreaBrush = color;
00254                     } else
00255                     // normal line properties:
00256                         if( tagName == "IDLineWidth" ) {
00257                         if( KDXML::readIntNode( element, i ) )
00258                             set.mIdLineWidth = i;
00259                     } else if( tagName ==   "LineWidth" ) {
00260                         if( KDXML::readIntNode( element, i ) )
00261                             set.mLineWidth = i;
00262                     } else if( tagName == "IDLineColor" ) {
00263                         if( KDXML::readIntNode( element, i ) )
00264                             set.mIdLineColor = i;
00265                     } else if( tagName ==   "LineColor" ) {
00266                         if( KDXML::readColorNode( element, color ) )
00267                             set.mLineColor = color;
00268                     } else if( tagName == "IDLineStyle" ) {
00269                         if( KDXML::readIntNode( element, i ) )
00270                             set.mIdLineStyle = i;
00271                     } else if( tagName ==   "LineStyle" ) {
00272                         if( element.hasAttribute( "Style" ) )
00273                             set.mLineStyle = KDXML::stringToPenStyle( element.attribute( "Style" ) );
00274                     } else
00275                         // normal marker properties:
00276                         if( tagName == "IDShowMarker" ) {
00277                         if( KDXML::readIntNode( element, i ) )
00278                             set.mIdShowMarker = i;
00279                     } else if( tagName ==   "ShowMarker" ) {
00280                         if( KDXML::readBoolNode( element, bValue ) )
00281                             set.mShowMarker = bValue;
00282                     } else if( tagName == "IDMarkerAlign" ) {
00283                         if( KDXML::readIntNode( element, i ) )
00284                             set.mIdMarkerAlign = i;
00285                     } else if( tagName ==   "MarkerAlign" ) {
00286                         if( KDXML::readIntNode( element, i ) )
00287                             set.mMarkerAlign = i;
00288                     } else if( tagName == "IDMarkerSize" ) {
00289                         if( KDXML::readIntNode( element, i ) )
00290                             set.mIdMarkerSize = i;
00291                     } else if( tagName ==   "MarkerSize" ) {
00292                         if( KDXML::readSizeNode( element, size ) )
00293                             set.mMarkerSize = size;
00294                     } else if( tagName == "IDMarkerColor" ) {
00295                         if( KDXML::readIntNode( element, i ) )
00296                             set.mIdMarkerColor = i;
00297                     } else if( tagName ==   "MarkerColor" ) {
00298                         if( KDXML::readColorNode( element, color ) )
00299                             set.mMarkerColor = color;
00300                     } else if( tagName == "IDMarkerStyle" ) {
00301                         if( KDXML::readIntNode( element, i ) )
00302                             set.mIdMarkerStyle = i;
00303                     } else if( tagName ==   "MarkerStyle" ) {
00304                         if( element.hasAttribute( "Style" ) )
00305                             set.mMarkerStyle
00306                                 = KDChartParams::stringToLineMarkerStyle( element.attribute( "Style" ) );
00307                     } else
00308                         // extra lines:
00309                         if( tagName == "IDExtraLinesAlign" ) {
00310                         if( KDXML::readIntNode( element, i ) )
00311                             set.mIdExtraLinesAlign = i;
00312                     } else if( tagName ==   "ExtraLinesAlign" ) {
00313                         if( KDXML::readIntNode( element, i ) )
00314                             set.mExtraLinesAlign = i;
00315                     } else if( tagName == "IDExtraLinesInFront" ) {
00316                         if( KDXML::readIntNode( element, i ) )
00317                             set.mIdExtraLinesInFront = i;
00318                     } else if( tagName ==   "ExtraLinesInFront" ) {
00319                         if( KDXML::readBoolNode( element, bValue ) )
00320                             set.mExtraLinesInFront = bValue;
00321                     } else if( tagName == "IDExtraLinesLength" ) {
00322                         if( KDXML::readIntNode( element, i ) )
00323                             set.mIdExtraLinesLength = i;
00324                     } else if( tagName ==   "ExtraLinesLength" ) {
00325                         if( KDXML::readIntNode( element, i ) )
00326                             set.mExtraLinesLength = i;
00327                     } else if( tagName == "IDExtraLinesWidth" ) {
00328                         if( KDXML::readIntNode( element, i ) )
00329                             set.mIdExtraLinesWidth = i;
00330                     } else if( tagName ==   "ExtraLinesWidth" ) {
00331                         if( KDXML::readIntNode( element, i ) )
00332                             set.mExtraLinesWidth = i;
00333                     } else if( tagName == "IDExtraLinesColor" ) {
00334                         if( KDXML::readIntNode( element, i ) )
00335                             set.mIdExtraLinesColor = i;
00336                     } else if( tagName ==   "ExtraLinesColor" ) {
00337                         if( KDXML::readColorNode( element, color ) )
00338                             set.mExtraLinesColor = color;
00339                     } else if( tagName == "IDExtraLinesStyle" ) {
00340                         if( KDXML::readIntNode( element, i ) )
00341                             set.mIdExtraLinesStyle = i;
00342                     } else if( tagName ==   "ExtraLinesStyle" ) {
00343                         if( element.hasAttribute( "Style" ) )
00344                             set.mExtraLinesStyle = KDXML::stringToPenStyle( element.attribute( "Style" ) );
00345                     } else
00346                         // extra markers:
00347                         if( tagName == "IDExtraMarkersAlign" ) {
00348                         if( KDXML::readIntNode( element, i ) )
00349                             set.mIdExtraMarkersAlign = i;
00350                     } else if( tagName ==   "ExtraMarkersAlign" ) {
00351                         if( KDXML::readIntNode( element, i ) )
00352                             set.mExtraMarkersAlign = i;
00353                     } else if( tagName == "IDExtraMarkersSize" ) {
00354                         if( KDXML::readIntNode( element, i ) )
00355                             set.mIdExtraMarkersSize = i;
00356                     } else if( tagName ==   "ExtraMarkersSize" ) {
00357                         if( KDXML::readSizeNode( element, size ) )
00358                             set.mExtraMarkersSize = size;
00359                     } else if( tagName == "IDExtraMarkersColor" ) {
00360                         if( KDXML::readIntNode( element, i ) )
00361                             set.mIdExtraMarkersColor = i;
00362                     } else if( tagName ==   "ExtraMarkersColor" ) {
00363                         if( KDXML::readColorNode( element, color ) )
00364                             set.mExtraMarkersColor = color;
00365                     } else if( tagName == "IDExtraMarkersStyle" ) {
00366                         if( KDXML::readIntNode( element, i ) )
00367                             set.mIdExtraMarkersStyle = i;
00368                     } else if( tagName ==   "ExtraMarkersStyle" ) {
00369                         if( element.hasAttribute( "Style" ) )
00370                             set.mExtraMarkersStyle
00371                                 = KDChartParams::stringToLineMarkerStyle( element.attribute( "Style" ) );
00372                     } else {
00373                         qDebug( "Unknown subelement of KDChartPropertySet found: %s", tagName.latin1() );
00374                     }
00375                 }
00376                 node = node.nextSibling();
00377             }
00378         }
00379     }
00380     return bOwnIDFound;
00381 }
00382 
00383 #include "KDChartPropertySet.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys