1 /***************************************************************************
2 scriptfunction.cpp - description
4 begin : Thu Apr 17 2003
5 copyright : (C) 2003 by Jason Harris
6 email : kstars@30doradus.org
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
20 #include "scriptfunction.h"
23 ScriptFunction::ScriptFunction( QString name
, QString desc
, bool clockfcn
,
24 QString at1
, QString an1
, QString at2
, QString an2
, QString at3
, QString an3
,
25 QString at4
, QString an4
, QString at5
, QString an5
, QString at6
, QString an6
) : INDIProp("") {
27 ClockFunction
= clockfcn
;
29 ArgType
[0] = at1
; ArgName
[0] = an1
;
30 ArgType
[1] = at2
; ArgName
[1] = an2
;
31 ArgType
[2] = at3
; ArgName
[2] = an3
;
32 ArgType
[3] = at4
; ArgName
[3] = an4
;
33 ArgType
[4] = at5
; ArgName
[4] = an5
;
34 ArgType
[5] = at6
; ArgName
[5] = an6
;
36 //Construct a richtext description of the function
37 QString nameStyle
= "<span style=\"font-family:courier;font-weight:600\">%1</span>"; //bold
38 QString typeStyle
= "<span style=\"font-family:courier;color:#009d00\">%1</span>"; //green
39 QString paramStyle
= "<span style=\"font-family:courier;color:#00007f\">%1</span>"; //blue
41 Description
= "<html><head><meta name=\"qrichtext\" content=\"1\" /></head>";
42 Description
+= "<body style=\"font-size:11pt;font-family:Verdana\">";
43 Description
+= "<p>" + nameStyle
.arg( Name
+ "(" );
46 if ( ! at1
.isEmpty() && ! an1
.isEmpty() ) {
47 Description
+= " " + typeStyle
.arg( at1
);
48 Description
+= " " + paramStyle
.arg( an1
);
52 if ( ! at2
.isEmpty() && ! an2
.isEmpty() ) {
53 Description
+= ", " + typeStyle
.arg( at2
);
54 Description
+= " " + paramStyle
.arg( an2
);
58 if ( ! at3
.isEmpty() && ! an3
.isEmpty() ) {
59 Description
+= ", " + typeStyle
.arg( at3
);
60 Description
+= " " + paramStyle
.arg( an3
);
64 if ( ! at4
.isEmpty() && ! an4
.isEmpty() ) {
65 Description
+= ", " + typeStyle
.arg( at4
);
66 Description
+= " " + paramStyle
.arg( an4
);
70 if ( ! at5
.isEmpty() && ! an5
.isEmpty() ) {
71 Description
+= ", " + typeStyle
.arg( at5
);
72 Description
+= " " + paramStyle
.arg( an5
);
76 if ( ! at6
.isEmpty() && ! an6
.isEmpty() ) {
77 Description
+= ", " + typeStyle
.arg( at6
);
78 Description
+= " " + paramStyle
.arg( an6
);
82 //Set Valid=false if there are arguments (indicates that this fcn's args must be filled in)
84 if ( NumArgs
) Valid
= false;
86 //Finish writing function prototype
87 if ( NumArgs
) Description
+= " ";
88 Description
+= nameStyle
.arg( ")" ) + "</p><p>";
90 //before adding description, replace any '%n' instances with the corresponding
91 //argument name in color. For now, assume that the %n's occur in order, with no skips.
92 //Also assume that '%' is *only* used to indicate argument instances
93 int narg
= desc
.contains( '%' );
96 Description
+= desc
.arg( paramStyle
.arg( an1
) );
100 desc
.arg( paramStyle
.arg( an1
) )
101 .arg( paramStyle
.arg( an2
) );
105 desc
.arg( paramStyle
.arg( an1
) )
106 .arg( paramStyle
.arg( an2
) )
107 .arg( paramStyle
.arg( an3
) );
111 desc
.arg( paramStyle
.arg( an1
) )
112 .arg( paramStyle
.arg( an2
) )
113 .arg( paramStyle
.arg( an3
) )
114 .arg( paramStyle
.arg( an4
) );
118 desc
.arg( paramStyle
.arg( an1
) )
119 .arg( paramStyle
.arg( an2
) )
120 .arg( paramStyle
.arg( an3
) )
121 .arg( paramStyle
.arg( an4
) )
122 .arg( paramStyle
.arg( an5
) );
126 desc
.arg( paramStyle
.arg( an1
) )
127 .arg( paramStyle
.arg( an2
) )
128 .arg( paramStyle
.arg( an3
) )
129 .arg( paramStyle
.arg( an4
) )
130 .arg( paramStyle
.arg( an5
) )
131 .arg( paramStyle
.arg( an6
) );
139 Description
+= "</p></body></html>";
143 ScriptFunction::ScriptFunction( ScriptFunction
*sf
)
146 Description
= sf
->description();
147 ClockFunction
= sf
->isClockFunction();
148 NumArgs
= sf
->numArgs();
149 INDIProp
= sf
->INDIProperty();
152 for ( unsigned int i
=0; i
<6; i
++ ) {
153 ArgType
[i
] = sf
->argType(i
);
154 ArgName
[i
] = sf
->argName(i
);
159 ScriptFunction::~ScriptFunction()
163 QString
ScriptFunction::prototype() const {
164 QString p
= Name
+ "(";
167 if ( ! ArgType
[0].isEmpty() && ! ArgName
[0].isEmpty() ) {
168 p
+= " " + ArgType
[0];
169 p
+= " " + ArgName
[0];
170 args
= true; //assume that if any args are present, 1st arg is present
173 if ( ! ArgType
[1].isEmpty() && ! ArgName
[1].isEmpty() ) {
174 p
+= ", " + ArgType
[1];
175 p
+= " " + ArgName
[1];
178 if ( ! ArgType
[2].isEmpty() && ! ArgName
[2].isEmpty() ) {
179 p
+= ", " + ArgType
[2];
180 p
+= " " + ArgName
[2];
183 if ( ! ArgType
[3].isEmpty() && ! ArgName
[3].isEmpty() ) {
184 p
+= ", " + ArgType
[3];
185 p
+= " " + ArgName
[3];
188 if ( ! ArgType
[4].isEmpty() && ! ArgName
[4].isEmpty() ) {
189 p
+= ", " + ArgType
[4];
190 p
+= " " + ArgName
[4];
193 if ( ! ArgType
[5].isEmpty() && ! ArgName
[5].isEmpty() ) {
194 p
+= ", " + ArgType
[5];
195 p
+= " " + ArgName
[5];
198 if ( args
) p
+= " ";
204 QString
ScriptFunction::scriptLine() const {
207 while ( ! ArgName
[i
].isEmpty() && i
< 6 ) {
208 // Wrap arg in quotes if it contains a space
209 if ( ArgVal
[i
].contains(" ") ) {
210 out
+= " \"" + ArgVal
[i
] + "\"";
212 out
+= " " + ArgVal
[i
];