00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "omgalgorithmparameter.h"
00021 #include "omgui.h"
00022
00023 #include <QDomDocument>
00024
00025 OmgAlgorithmParameter::OmgAlgorithmParameter() : OmgSerialisable()
00026 {}
00027 OmgAlgorithmParameter::~OmgAlgorithmParameter()
00028 {}
00029 OmgAlgorithmParameter::OmgAlgorithmParameter(
00030 QString theId,
00031 QString theName,
00032 QString theDefault,
00033 QString theOverview,
00034 QString theDescription,
00035 QString theMinimum,
00036 QString theMaximum,
00037 QString theValue) :
00038 OmgSerialisable(),
00039 mId(theId),
00040 mName(theName),
00041 mDefault(theDefault),
00042 mOverview(theOverview),
00043 mDescription(theDescription),
00044 mMinimum(theMinimum),
00045 mMaximum(theMaximum),
00046 mValue(theValue)
00047 {
00048 }
00049 void OmgAlgorithmParameter::setId(QString theId)
00050 {
00051 mId=theId;
00052 }
00053 void OmgAlgorithmParameter::setName(QString theName)
00054 {
00055 mName=theName;
00056 }
00057 void OmgAlgorithmParameter::setType(QString theType)
00058 {
00059 mType=theType;
00060 }
00061 void OmgAlgorithmParameter::setDefault(QString theDefault)
00062 {
00063 mDefault=theDefault;
00064 }
00065 void OmgAlgorithmParameter::setOverview(QString theOverview)
00066 {
00067 mOverview=theOverview;
00068 }
00069 void OmgAlgorithmParameter::setDescription(QString theDescription)
00070 {
00071 mDescription=theDescription;
00072 }
00073 void OmgAlgorithmParameter::setMinimum(QString theMinimum)
00074 {
00075 mMinimum=theMinimum;
00076 }
00077 void OmgAlgorithmParameter::setMaximum(QString theMaximum)
00078 {
00079 mMaximum=theMaximum;
00080 }
00081 void OmgAlgorithmParameter::setValue(QString theValue)
00082 {
00083 mValue=theValue;
00084 }
00085 QString OmgAlgorithmParameter::id() const
00086 {
00087 return mId;
00088 }
00089 QString OmgAlgorithmParameter::name() const
00090 {
00091 return mName;
00092 }
00093 QString OmgAlgorithmParameter::type() const
00094 {
00095 return mType;
00096 }
00097 QString OmgAlgorithmParameter::defaultValue() const
00098 {
00099 return mDefault;
00100 }
00101 QString OmgAlgorithmParameter::overview() const
00102 {
00103 return mOverview;
00104 }
00105 QString OmgAlgorithmParameter::description() const
00106 {
00107 return mDescription;
00108 }
00109 QString OmgAlgorithmParameter::minimum() const
00110 {
00111 return mMinimum;
00112 }
00113 QString OmgAlgorithmParameter::maximum() const
00114 {
00115 return mMaximum;
00116 }
00117 QString OmgAlgorithmParameter::value() const
00118 {
00119 return mValue;
00120 }
00121 QString OmgAlgorithmParameter::toString() const
00122 {
00123 QString myString ("ID : " + mId + "\n");
00124 myString += QString("Name : " + mName + "\n");
00125 myString += QString("Default : " + mDefault + "\n");
00126 myString += QString("Description : " + mDescription + "\n");
00127 myString += QString("Type : " + mType + "\n");
00128 myString += QString("Minimum : " + mMinimum + "\n");
00129 myString += QString("Maximum : " + mMaximum + "\n");
00130 myString += QString("User Value : " + mValue + "\n");
00131 return myString;
00132 }
00133
00134 QString OmgAlgorithmParameter::toXml() const
00135 {
00136 QString myString (" <Parameter Id=\"" + id() + "\">\n");
00137 myString +=QString(" <Name>" + Omgui::xmlEncode(name()) + "</Name>\n");
00138 myString +=QString(" <Type>" + Omgui::xmlEncode(type()) + "</Type>\n");
00139 myString +=QString(" <Overview>" + Omgui::xmlEncode(overview()) + "</Overview>\n");
00140 myString +=QString(" <Description>" + Omgui::xmlEncode(description()) + "</Description>\n");
00141 myString +=QString(" <AcceptedRange Min=\"" + minimum() + "\" Max=\"" + maximum() + "\"/>\n");
00142 myString +=QString(" <Default>" + defaultValue() + "</Default>\n");
00143
00144
00145
00146 if (value().isNull())
00147 {
00148 myString +=QString(" <Value>" + defaultValue() + "</Value>\n");
00149 }
00150 else
00151 {
00152 myString +=QString(" <Value>" + value() + "</Value>\n");
00153 }
00154 myString +=QString(" </Parameter>\n");
00155 return myString;
00156
00157 }
00158 QString OmgAlgorithmParameter::toModelCreationXml() const
00159 {
00160 QString myString (" <Parameter Id=\"" + id() + "\" Value=\"");
00161 if (value().isNull())
00162 {
00163 myString += defaultValue() + "\"/>\n";
00164 }
00165 else
00166 {
00167 myString += value() + "\"/>\n";
00168 }
00169 return myString;
00170
00171 }
00172 bool OmgAlgorithmParameter::fromXml(const QString theXml)
00173 {
00174 QDomDocument myDocument("mydocument");
00175 myDocument.setContent(theXml);
00176 QDomElement myElement = myDocument.firstChildElement("Parameter");
00177 if (myElement.isNull())
00178 {
00179
00180 qDebug("AlgorithmParameter - Element could not be found!");
00181 return false;
00182 }
00183 setId(myElement.attribute("Id"));
00184 setName(myElement.firstChildElement("Name").text());
00185 setOverview(myElement.firstChildElement("Overview").text());
00186 setDescription(myElement.firstChildElement("Description").text());
00187 setType(myElement.firstChildElement("Type").text());
00188 QDomElement myRangeElement = myElement.firstChildElement("AcceptedRange");
00189 setMinimum(myRangeElement.attribute("Min"));
00190 setMaximum(myRangeElement.attribute("Max"));
00191 setDefault(myElement.firstChildElement("Default").text());
00192 setValue(myElement.firstChildElement("Value").text());
00193 return true;
00194 }