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