kstars
scriptfunction.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <kdebug.h>
00019
00020 #include "scriptfunction.h"
00021
00022
00023 ScriptFunction::ScriptFunction( QString name, QString desc, bool clockfcn,
00024 QString at1, QString an1, QString at2, QString an2, QString at3, QString an3,
00025 QString at4, QString an4, QString at5, QString an5, QString at6, QString an6 ) : INDIProp("") {
00026 Name = name;
00027 ClockFunction = clockfcn;
00028
00029 ArgType[0] = at1; ArgName[0] = an1;
00030 ArgType[1] = at2; ArgName[1] = an2;
00031 ArgType[2] = at3; ArgName[2] = an3;
00032 ArgType[3] = at4; ArgName[3] = an4;
00033 ArgType[4] = at5; ArgName[4] = an5;
00034 ArgType[5] = at6; ArgName[5] = an6;
00035
00036
00037 QString nameStyle = "<span style=\"font-family:monospace;font-weight:600\">%1</span>";
00038 QString typeStyle = "<span style=\"font-family:monospace;color:#009d00\">%1</span>";
00039 QString paramStyle = "<span style=\"font-family:monospace;color:#00007f\">%1</span>";
00040
00041 Description = "<html><head><meta name=\"qrichtext\" content=\"1\" /></head>";
00042 Description += "<body style=\"font-size:11pt;font-family:sans\">";
00043 Description += "<p>" + nameStyle.arg( Name + "(" );
00044
00045 NumArgs = 0;
00046 if ( ! at1.isEmpty() && ! an1.isEmpty() ) {
00047 Description += " " + typeStyle.arg( at1 );
00048 Description += " " + paramStyle.arg( an1 );
00049 NumArgs++;
00050 }
00051
00052 if ( ! at2.isEmpty() && ! an2.isEmpty() ) {
00053 Description += ", " + typeStyle.arg( at2 );
00054 Description += " " + paramStyle.arg( an2 );
00055 NumArgs++;
00056 }
00057
00058 if ( ! at3.isEmpty() && ! an3.isEmpty() ) {
00059 Description += ", " + typeStyle.arg( at3 );
00060 Description += " " + paramStyle.arg( an3 );
00061 NumArgs++;
00062 }
00063
00064 if ( ! at4.isEmpty() && ! an4.isEmpty() ) {
00065 Description += ", " + typeStyle.arg( at4 );
00066 Description += " " + paramStyle.arg( an4 );
00067 NumArgs++;
00068 }
00069
00070 if ( ! at5.isEmpty() && ! an5.isEmpty() ) {
00071 Description += ", " + typeStyle.arg( at5 );
00072 Description += " " + paramStyle.arg( an5 );
00073 NumArgs++;
00074 }
00075
00076 if ( ! at6.isEmpty() && ! an6.isEmpty() ) {
00077 Description += ", " + typeStyle.arg( at6 );
00078 Description += " " + paramStyle.arg( an6 );
00079 NumArgs++;
00080 }
00081
00082
00083 Valid = true;
00084 if ( NumArgs ) Valid = false;
00085
00086
00087 if ( NumArgs ) Description += " ";
00088 Description += nameStyle.arg( ")" ) + "</p><p>";
00089
00090
00091
00092
00093 int narg = desc.contains( '%' );
00094 switch (narg ) {
00095 case 1:
00096 Description += desc.arg( paramStyle.arg( an1 ) );
00097 break;
00098 case 2:
00099 Description +=
00100 desc.arg( paramStyle.arg( an1 ) )
00101 .arg( paramStyle.arg( an2 ) );
00102 break;
00103 case 3:
00104 Description +=
00105 desc.arg( paramStyle.arg( an1 ) )
00106 .arg( paramStyle.arg( an2 ) )
00107 .arg( paramStyle.arg( an3 ) );
00108 break;
00109 case 4:
00110 Description +=
00111 desc.arg( paramStyle.arg( an1 ) )
00112 .arg( paramStyle.arg( an2 ) )
00113 .arg( paramStyle.arg( an3 ) )
00114 .arg( paramStyle.arg( an4 ) );
00115 break;
00116 case 5:
00117 Description +=
00118 desc.arg( paramStyle.arg( an1 ) )
00119 .arg( paramStyle.arg( an2 ) )
00120 .arg( paramStyle.arg( an3 ) )
00121 .arg( paramStyle.arg( an4 ) )
00122 .arg( paramStyle.arg( an5 ) );
00123 break;
00124 case 6:
00125 Description +=
00126 desc.arg( paramStyle.arg( an1 ) )
00127 .arg( paramStyle.arg( an2 ) )
00128 .arg( paramStyle.arg( an3 ) )
00129 .arg( paramStyle.arg( an4 ) )
00130 .arg( paramStyle.arg( an5 ) )
00131 .arg( paramStyle.arg( an6 ) );
00132 break;
00133 default:
00134 Description += desc;
00135 break;
00136 }
00137
00138
00139 Description += "</p></body></html>";
00140 }
00141
00142
00143 ScriptFunction::ScriptFunction( ScriptFunction *sf )
00144 {
00145 Name = sf->name();
00146 Description = sf->description();
00147 ClockFunction = sf->isClockFunction();
00148 NumArgs = sf->numArgs();
00149 INDIProp = sf->INDIProperty();
00150 Valid = sf->valid();
00151
00152 for ( unsigned int i=0; i<6; i++ ) {
00153 ArgType[i] = sf->argType(i);
00154 ArgName[i] = sf->argName(i);
00155 ArgVal[i] = "";
00156 }
00157 }
00158
00159 ScriptFunction::~ScriptFunction()
00160 {
00161 }
00162
00163 QString ScriptFunction::prototype() const {
00164 QString p = Name + "(";
00165
00166 bool args( false );
00167 if ( ! ArgType[0].isEmpty() && ! ArgName[0].isEmpty() ) {
00168 p += " " + ArgType[0];
00169 p += " " + ArgName[0];
00170 args = true;
00171 }
00172
00173 if ( ! ArgType[1].isEmpty() && ! ArgName[1].isEmpty() ) {
00174 p += ", " + ArgType[1];
00175 p += " " + ArgName[1];
00176 }
00177
00178 if ( ! ArgType[2].isEmpty() && ! ArgName[2].isEmpty() ) {
00179 p += ", " + ArgType[2];
00180 p += " " + ArgName[2];
00181 }
00182
00183 if ( ! ArgType[3].isEmpty() && ! ArgName[3].isEmpty() ) {
00184 p += ", " + ArgType[3];
00185 p += " " + ArgName[3];
00186 }
00187
00188 if ( ! ArgType[4].isEmpty() && ! ArgName[4].isEmpty() ) {
00189 p += ", " + ArgType[4];
00190 p += " " + ArgName[4];
00191 }
00192
00193 if ( ! ArgType[5].isEmpty() && ! ArgName[5].isEmpty() ) {
00194 p += ", " + ArgType[5];
00195 p += " " + ArgName[5];
00196 }
00197
00198 if ( args ) p += " ";
00199 p += ")";
00200
00201 return p;
00202 }
00203
00204 QString ScriptFunction::scriptLine() const {
00205 QString out( Name );
00206 unsigned int i=0;
00207 while ( ! ArgName[i].isEmpty() && i < 6 ) {
00208
00209 if ( ArgVal[i].contains(" ") ) {
00210 out += " \"" + ArgVal[i] + "\"";
00211 } else {
00212 out += " " + ArgVal[i];
00213 }
00214 ++i;
00215 }
00216
00217 return out;
00218 }