filters
ImportHelpers.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qstringlist.h>
00021 #include <qregexp.h>
00022
00023 #include <kdebug.h>
00024
00025 #include "ImportHelpers.h"
00026
00027 bool AbiPropsMap::setProperty(const QString& newName, const QString& newValue)
00028 {
00029 replace(newName,AbiProps(newValue));
00030 return true;
00031 }
00032
00033
00034 void AbiPropsMap::splitAndAddAbiProps(const QString& strProps)
00035 {
00036 if (strProps.isEmpty())
00037 return;
00038
00039 QStringList list=QStringList::split(';',strProps,false);
00040 QString name,value;
00041
00042 QStringList::ConstIterator it;
00043 QStringList::ConstIterator end(list.end());
00044 for (it=list.begin();it!=end;++it)
00045 {
00046 const int result=(*it).find(':');
00047 if (result==-1)
00048 {
00049 name=(*it);
00050 value=QString::null;
00051 kdWarning(30506) << "Property without value: " << name << endl;
00052 }
00053 else
00054 {
00055 name=(*it).left(result);
00056 value=(*it).mid(result+1);
00057 }
00058
00059
00060 setProperty(name.stripWhiteSpace(),value.stripWhiteSpace());
00061 }
00062 }
00063
00064 double ValueWithLengthUnit( const QString& _str, bool* atleast )
00065 {
00066 if ( atleast )
00067 *atleast = false;
00068
00069 double result;
00070
00071 QRegExp unitExp("([a-z]+)\\s*(\\+?)");
00072 const int pos=unitExp.search(_str);
00073 if (pos==-1)
00074 {
00075 bool flag=false;
00076 result=_str.toDouble(&flag);
00077 if (!flag)
00078 kdWarning(30506) << "Unknown value: " << _str << " (ValueWithLengthUnit)" << endl;
00079 }
00080 else
00081 {
00082 const double rawValue=_str.left(pos).toDouble();
00083 const QString strUnit ( unitExp.cap(1) );
00084 if (strUnit=="cm")
00085 result=CentimetresToPoints(rawValue);
00086 else if (strUnit=="in")
00087 result=InchesToPoints(rawValue);
00088 else if (strUnit=="mm")
00089 result=MillimetresToPoints(rawValue);
00090 else if (strUnit=="pt")
00091 result=rawValue;
00092 else if(strUnit=="pi")
00093 result=PicaToPoints(rawValue);
00094 else
00095 {
00096 kdWarning(30506) << "Value " << _str << " has non-supported unit: "
00097 << strUnit << " (ValueWithLengthUnit)" << endl;
00098 result=rawValue;
00099 }
00100
00101 if ( atleast )
00102 {
00103 *atleast = ( unitExp.cap(2) == "+" );
00104 }
00105
00106
00107 }
00108 return result;
00109 }
|