summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmxmlhelper.cpp
blob: 2146c1d636a728e9e8ac156024ac951741f86fd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2000-2002 by Andreas Zehender
    email                : [email protected]
**************************************************************************

**************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/

#include "pmxmlhelper.h"

PMXMLHelper::PMXMLHelper( const TQDomElement& e, PMPart* p, PMParser* par,
                          int majorDocumentFormat, int minorDocumentFormat )
{
   m_e = e;
   m_pPart = p;
   m_pParser = par;
   m_major = majorDocumentFormat;
   m_minor = minorDocumentFormat;
}

bool PMXMLHelper::hasAttribute( const TQString& name ) const
{
   return m_e.hasAttribute( name );
}

int PMXMLHelper::intAttribute( const TQString& name, int def ) const
{
   TQString str = m_e.attribute( name );
   bool ok;
   int res;
   
   if( str.isNull( ) )
      return def;
   res = str.toInt( &ok );
   if( ok )
      return res;
   return def;
}

double PMXMLHelper::doubleAttribute( const TQString& name, double def ) const
{
   TQString str = m_e.attribute( name );
   bool ok;
   double res;
   
   if( str.isNull( ) )
      return def;
   res = str.toDouble( &ok );
   if( ok )
      return res;
   return def;
}

bool PMXMLHelper::boolAttribute( const TQString& name, bool def ) const
{
   TQString str = m_e.attribute( name );
   bool ok;
   int res;
   
   if( str.isNull( ) )
      return def;
   res = str.toInt( &ok );
   if( ok )
      return ( res != 0 );
   return def;
}

PMThreeState PMXMLHelper::threeStateAttribute( const TQString& name ) const
{
   TQString str = m_e.attribute( name );
   bool ok;
   int res;
   
   if( str.isNull( ) )
      return PMUnspecified;
   res = str.toInt( &ok );
   if( ok )
   {
      if( res == 0 )
         return PMFalse;
      else
         return PMTrue;
   }
   return PMUnspecified;
}

TQString PMXMLHelper::stringAttribute( const TQString& name, const TQString& def ) const
{
   return m_e.attribute( name, def );
}

PMVector PMXMLHelper::vectorAttribute( const TQString& name, const PMVector& def ) const
{
   TQString str = m_e.attribute( name );

   if( str.isNull( ) )
      return def;
   else
   {
      PMVector v;
      if( v.loadXML( str ) )
         return v;
   }
   return def;
}

PMMatrix PMXMLHelper::matrixAttribute( const TQString& name, const PMMatrix& def ) const
{
   TQString str = m_e.attribute( name );

   if( str.isNull( ) )
      return def;
   else
   {
      PMMatrix m;
      if( m.loadXML( str ) )
         return m;
   }
   return def;
}

PMColor PMXMLHelper::colorAttribute( const TQString& name, const PMColor& def ) const
{
   TQString str = m_e.attribute( name );

   if( str.isNull( ) )
      return def;
   else
   {
      PMColor c;
      if( c.loadXML( str ) )
         return c;
   }
   return def;
}

TQDomElement PMXMLHelper::extraData( ) const
{
   TQDomNode c = m_e.firstChild( );
   while( !c.isNull( ) )
   {
      if( c.isElement( ) )
      {
         TQDomElement ce = c.toElement( );
         if( ce.tagName( ) == "extra_data" )
            return ce;
      }
      c = c.nextSibling( );
   }
   return TQDomElement( );
}