lib/UTIL.cpp

Go to the documentation of this file.
00001 /*
00002  *  Qtstalker stock charter
00003  *
00004  *  Copyright (C) 2001-2007 Stefan S. Stratigakos
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019  *  USA.
00020  */
00021 
00022 #include "UTIL.h"
00023 #include "PrefDialog.h"
00024 #include <qdict.h>
00025 #include <qinputdialog.h>
00026 #include <qobject.h>
00027 #include <math.h>
00028 
00029 UTIL::UTIL ()
00030 {
00031   pluginName = "UTIL";
00032   
00033   methodList.append("ACCUM");
00034   methodList.append("Normal");
00035   methodList.append("ADD");
00036   methodList.append("DIV");
00037   methodList.append("MUL");
00038   methodList.append("SUB");
00039   methodList.append("COMP");
00040   methodList.append("COUNTER");
00041   methodList.append("REF");
00042   methodList.append("PER");
00043   methodList.append("COLOR");
00044   methodList.append("Higher");
00045   methodList.append("Lower");
00046   methodList.append("INRANGE");
00047   methodList.sort();
00048 
00049   helpFile = "math.html";
00050 }
00051 
00052 UTIL::~UTIL ()
00053 {
00054 }
00055 
00056 PlotLine * UTIL::calculateAccum (QString &p, QPtrList<PlotLine> &d)
00057 {
00058   // format: METHOD, INPUT_ARRAY
00059 
00060   formatList.clear();
00061   formatList.append(FormatString);
00062   formatList.append(FormatInputArray);
00063 
00064   if (checkFormat(p, d, 2, 2))
00065     return 0;
00066 
00067   PlotLine *line = new PlotLine;
00068   PlotLine *input = d.at(0);
00069   
00070   int loop;
00071   double accum = 0;
00072   for (loop = 0; loop < (int) input->getSize(); loop++)
00073   {
00074     accum = accum + input->getData(loop);
00075     line->append(accum);
00076   }
00077   
00078   return line;
00079 }
00080 
00081 PlotLine * UTIL::calculateNormal(QString &p, QPtrList<PlotLine> &d)
00082 {
00083   // format: METHOD, INPUT_ARRAY
00084 
00085   formatList.clear();
00086   formatList.append(FormatString);
00087   formatList.append(FormatInputArray);
00088 
00089   if (checkFormat(p, d, 2, 2))
00090     return 0;
00091 
00092   PlotLine *input = d.at(0);
00093 
00094   PlotLine *normal = new PlotLine;
00095   int loop = 0;
00096   double range = 0;
00097   double max = -99999999.0;
00098   double min = 99999999.0;
00099   double norm = 0;
00100   for (loop = 0; loop < input->getSize(); loop++)
00101   {
00102     if (input->getData(loop) > max)
00103       max = input->getData(loop);
00104 
00105     if (input->getData(loop) < min)
00106       min = input->getData(loop);
00107   }
00108         
00109   range = fabs(max) + fabs(min);
00110         
00111   for (loop = 0; loop < input->getSize(); loop++)
00112   {     
00113     norm = ((input->getData(loop) - min) / range) * 100;
00114     input->append(norm);
00115   }
00116         
00117   return normal;
00118 }
00119 
00120 PlotLine * UTIL::calculateCustom (QString &p, QPtrList<PlotLine> &d)
00121 {
00122   QStringList l = QStringList::split(",", p, FALSE);
00123 
00124   if (l.count() > 0)
00125     ;
00126   else
00127   {
00128     qDebug("UTIL::Custom: invalid parm count");
00129     return 0;
00130   }
00131 
00132   if (methodList.findIndex(l[0]) == -1)
00133   {
00134     qDebug("UTIL::Custom: invalid METHOD parm");
00135     return 0;
00136   }
00137 
00138   PlotLine *out = 0;
00139 
00140   while (1)
00141   {
00142     if (! l[0].compare("ACCUM"))
00143     {
00144       out = calculateAccum(p, d);
00145       break;
00146     }
00147 
00148     if (! l[0].compare("Normal"))
00149     {
00150       out = calculateNormal(p, d);
00151       break;
00152     }
00153 
00154     if (! l[0].compare("ADD"))
00155     {
00156       out = calculateADMS(p, d, 0);
00157       break;
00158     }
00159 
00160     if (! l[0].compare("DIV"))
00161     {
00162       out = calculateADMS(p, d, 1);
00163       break;
00164     }
00165 
00166     if (! l[0].compare("MUL"))
00167     {
00168       out = calculateADMS(p, d, 2);
00169       break;
00170     }
00171 
00172     if (! l[0].compare("SUB"))
00173     {
00174       out = calculateADMS(p, d, 3);
00175       break;
00176     }
00177 
00178     if (! l[0].compare("COMP"))
00179     {
00180       out = calculateCOMP(p, d);
00181       break;
00182     }
00183 
00184     if (! l[0].compare("COUNTER"))
00185     {
00186       out = calculateCOUNTER(p, d);
00187       break;
00188     }
00189 
00190     if (! l[0].compare("REF"))
00191     {
00192       out = calculateREF(p, d);
00193       break;
00194     }
00195 
00196     if (! l[0].compare("PER"))
00197     {
00198       out = calculatePER(p, d);
00199       break;
00200     }
00201 
00202     if (! l[0].compare("COLOR"))
00203     {
00204       out = calculateCOLOR(p, d);
00205       break;
00206     }
00207 
00208     if (! l[0].compare("Higher"))
00209     {
00210       out = calculateHL(p, d, 1);
00211       break;
00212     }
00213 
00214     if (! l[0].compare("Lower"))
00215     {
00216       out = calculateHL(p, d, 2);
00217       break;
00218     }
00219 
00220     if (! l[0].compare("INRANGE"))
00221     {
00222       out = calculateINRANGE(p, d);
00223       break;
00224     }
00225 
00226     break;
00227   }
00228 
00229   return out;
00230 }
00231 
00232 PlotLine * UTIL::calculateCOUNTER (QString &p, QPtrList<PlotLine> &d)
00233 {
00234   // format1: METHOD, ARRAY_INPUT
00235   // format2: METHOD, ARRAY_INPUT, ARRAY_INPUT2
00236 
00237   formatList.clear();
00238   QStringList l = QStringList::split(",", p, FALSE);
00239   if (l.count() == 2)
00240   {
00241     formatList.append(FormatString);
00242     formatList.append(FormatInputArray);
00243   }
00244   else
00245   {
00246     if (l.count() == 2)
00247     {
00248       formatList.append(FormatString);
00249       formatList.append(FormatInputArray);
00250       formatList.append(FormatInputArray2);
00251     }
00252     else
00253     {
00254       qDebug("UTIL::COUNTER: invalid parm count");
00255       return 0;
00256     }
00257   }
00258 
00259   if (checkFormat(p, d, 3, 2))
00260     return 0;
00261 
00262   PlotLine *in = d.at(0);
00263   PlotLine *in2 = 0;
00264   if (d.count() == 2)
00265     in2 = d.at(1);
00266 
00267   int inLoop = 0;
00268   int in2Loop = 0;
00269   
00270   if (in2)
00271   {
00272     in2Loop = in2->getSize() - in->getSize();
00273     if (in2Loop < 0)
00274     {
00275       inLoop=-in2Loop;
00276       in2Loop = 0;
00277     }
00278   }
00279 
00280   int t = 0;
00281   PlotLine *counter = new PlotLine;
00282 
00283   while (inLoop < in->getSize())
00284   {
00285     if (in2)
00286     {
00287       if (in2->getData(in2Loop))
00288         t = 0;
00289       if (in->getData(inLoop))
00290         t++;
00291       in2Loop++;
00292     }
00293     else
00294     {
00295       if (in->getData(inLoop))
00296         t = 1;
00297       else
00298         t++;
00299     }
00300     
00301     counter->append(t);
00302     inLoop++;
00303   }
00304 
00305   return counter;
00306 }
00307 
00308 PlotLine * UTIL::calculateCOMP (QString &p, QPtrList<PlotLine> &d)
00309 {
00310   // format1: METHOD, ARRAY_INPUT, DOUBLE, OPERATOR
00311   // format2: METHOD, ARRAY_INPUT, ARRAY_INPUT2, OPERATOR
00312 
00313   QStringList l = QStringList::split(",", p, FALSE);
00314 
00315   if (l.count() == 4)
00316     ;
00317   else
00318   {
00319     qDebug("UTIL::COMP: invalid parm count");
00320     return 0;
00321   }
00322 
00323   PlotLine *input = 0;
00324   PlotLine *input2 = 0;
00325   if (! d.count())
00326   {
00327     qDebug("UTIL::COMP: invalid ARRAY_INPUT parm");
00328     return 0;
00329   }
00330   else
00331     input = d.at(0);
00332 
00333   double inputNum = 0;
00334   if (d.count() == 1)
00335   {
00336     bool ok;
00337     double t = l[2].toDouble(&ok);
00338     if (ok)
00339       inputNum = t;
00340     else
00341     {
00342       qDebug("UTIL::COMP: invalid DOUBLE parm");
00343       return 0;
00344     }
00345   }
00346   else
00347     input2 = d.at(1);
00348 
00349   if (opList.findIndex(l[3]) == -1)
00350   {
00351     qDebug("UTIL::COMP: invalid METHOD parm:%s", l[3].latin1());
00352     return 0;
00353   }
00354 
00355   int loop = input->getSize() - 1;
00356   int loop2 = 0;
00357   if (input2)
00358     loop2 = input2->getSize() - 1;
00359 
00360   PlotLine *line = new PlotLine;
00361   
00362   Operator op = getOperator(l[3]);
00363   
00364   while (loop > -1)
00365   {
00366     double t = 0;
00367     
00368     if (! input2)
00369       t = inputNum;
00370     else
00371       if (loop2 > -1) 
00372         t = input2->getData(loop2);
00373       else 
00374         break;
00375       
00376     switch (op)
00377     {
00378       case Equal:
00379         if (input->getData(loop) == t)
00380           line->prepend(1);
00381         else
00382           line->prepend(0);
00383         break;
00384       case LessThan:
00385         if (input->getData(loop) < t)
00386           line->prepend(1);
00387         else
00388           line->prepend(0);
00389         break;
00390       case LessThanEqual:
00391         if (input->getData(loop) <= t)
00392           line->prepend(1);
00393         else
00394           line->prepend(0);
00395         break;
00396       case GreaterThan:
00397         if (input->getData(loop) > t)
00398           line->prepend(1);
00399         else
00400           line->prepend(0);
00401         break;
00402       case GreaterThanEqual:
00403         if (input->getData(loop) >= t)
00404           line->prepend(1);
00405         else
00406           line->prepend(0);
00407         break;
00408       case And:
00409         if (input->getData(loop) && t)
00410           line->prepend(1);
00411         else
00412           line->prepend(0);
00413         break;
00414       case Or:
00415         if (input->getData(loop) || t)
00416           line->prepend(1);
00417         else
00418           line->prepend(0);
00419         break;
00420       default:
00421         break;
00422     }
00423       
00424     loop--;
00425     
00426     if (input2)
00427       loop2--;
00428   }
00429   
00430   return line;
00431 }
00432 
00433 PlotLine * UTIL::calculateADMS (QString &p, QPtrList<PlotLine> &d, int type)
00434 {
00435   // format1: METHOD, ARRAY_INPUT, DOUBLE
00436   // format2: METHOD, ARRAY_INPUT, ARRAY_INPUT2
00437 
00438   formatList.clear();
00439   formatList.append(FormatString);
00440   formatList.append(FormatInputArray);
00441   formatList.append(FormatString); // dummy cause we dont know what this parm is beforehand
00442 
00443   if (checkFormat(p, d, 3, 3))
00444     return 0;
00445 
00446   PlotLine *input = d.at(0);
00447   PlotLine *input2 = 0;
00448   if (d.count() == 2)
00449     input2 = d.at(1);
00450 
00451   double inputNum = 0;
00452   if (! input2)
00453   {
00454     bool ok;
00455     double t = formatStringList[2].toDouble(&ok);
00456     if (ok)
00457       inputNum = t;
00458     else
00459       return 0;
00460   }
00461 
00462   int loop = input->getSize() - 1;
00463   int loop2 = 0;
00464   if (input2)
00465     loop2 = input2->getSize() - 1;
00466     
00467   PlotLine *line = new PlotLine;
00468   
00469   while (loop > -1)
00470   {
00471     double v = input->getData(loop);
00472     
00473     if (input2)
00474     {
00475       if (loop2 < 0)
00476         break;
00477       switch(type)
00478       {
00479         case 0:
00480           v = v + input2->getData(loop2);
00481           break;
00482         case 1:
00483           v = v / input2->getData(loop2);
00484           break;
00485         case 2:
00486           v = v * input2->getData(loop2);
00487           break;
00488         case 3:
00489           v = v - input2->getData(loop2);
00490           break;
00491         default:
00492           break;
00493       }
00494       loop2--;
00495     }
00496     else
00497     {
00498       switch(type)
00499       {
00500         case 0:
00501           v = v + inputNum;
00502           break;
00503         case 1:
00504           v = v / inputNum;
00505           break;
00506         case 2:
00507           v = v * inputNum;
00508           break;
00509         case 3:
00510           v = v - inputNum;
00511           break;
00512         default:
00513           break;
00514       }
00515     }
00516     
00517     line->prepend(v);
00518     loop--;
00519   }
00520   
00521   return line;
00522 }
00523 
00524 PlotLine * UTIL::calculateREF (QString &p, QPtrList<PlotLine> &d)
00525 {
00526   // format1: METHOD, ARRAY_INPUT, PERIOD
00527   // format2: METHOD, DOUBLE
00528 
00529   PlotLine *line = new PlotLine;
00530 
00531   QStringList l = QStringList::split(",", p, FALSE);
00532 
00533   if (l.count() < 2 || l.count() > 3)
00534   {
00535     qDebug("UTIL::REF: invalid parm count");
00536     return line;
00537   }
00538 
00539   if (l.count() == 2)
00540   {
00541     bool ok;
00542     double t = l[1].toDouble(&ok);
00543     if (! ok)
00544     {
00545       qDebug("UTIL::REF: invalid DOUBLE parm");
00546       return line;
00547     }
00548 
00549     line->append(t);
00550   }
00551   else
00552   {
00553     if (! d.count() && l.count() == 3)
00554     {
00555       qDebug("UTIL::REF: no input");
00556       return line;
00557     }
00558 
00559     bool ok;
00560     int period;
00561     int t = l[2].toInt(&ok);
00562     if (ok)
00563       period = t;
00564     else
00565     {
00566       qDebug("UTIL::REF: invalid PERIOD parm");
00567       return line;
00568     }
00569 
00570     PlotLine *in = d.at(0);
00571   
00572     int loop = 0;
00573     for (loop = 0; loop < in->getSize(); loop++)
00574     {
00575       if (loop - period < 0)
00576         continue;
00577       
00578       line->append(in->getData(loop - period));
00579     }
00580   }
00581   
00582   return line;
00583 }
00584 
00585 PlotLine * UTIL::calculatePER (QString &p, QPtrList<PlotLine> &d)
00586 {
00587   // format: METHOD, INPUT_ARRAY
00588 
00589   formatList.clear();
00590   formatList.append(FormatString);
00591   formatList.append(FormatInputArray);
00592 
00593   if (checkFormat(p, d, 2, 2))
00594     return 0;
00595  
00596   PlotLine *line = new PlotLine();
00597   PlotLine *input = d.at(0);
00598   
00599   double base = input->getData(0);
00600   int loop;
00601   for (loop = 1; loop < (int) input->getSize(); loop++)
00602     line->append(((input->getData(loop) - base) / base) * 100);
00603 
00604   return line;
00605 }
00606 
00607 PlotLine * UTIL::calculateCOLOR (QString &p, QPtrList<PlotLine> &d)
00608 {
00609   // format1: METHOD, INPUT_ARRAY, COLOR_ARRAY, VALUE, COLOR
00610 
00611   formatList.clear();
00612   formatList.append(FormatString);
00613   formatList.append(FormatInputArray);
00614   formatList.append(FormatInputArray2);
00615   formatList.append(FormatInteger);
00616   formatList.append(FormatString);
00617 
00618   if (checkFormat(p, d, 5, 5))
00619     return 0;
00620 
00621   int value = formatStringList[3].toInt();
00622 
00623   QColor c(formatStringList[4]);
00624   if (! c.isValid())
00625   {
00626     qDebug("UTIL::COLOR: invalid COLOR parm");
00627     return 0;
00628   }
00629   
00630   PlotLine *inbool = d.at(0);
00631   int inboolLoop = inbool->getSize() - 1;
00632   PlotLine *incol = d.at(1);
00633   incol->setColorFlag(TRUE);
00634   int incolLoop = incol->getSize() - 1;
00635   while (inboolLoop > -1 && incolLoop > -1)
00636   {
00637     if (inbool->getData(inboolLoop) == value)
00638       incol->setColorBar(incolLoop, c);
00639 
00640     inboolLoop--;
00641     incolLoop--;
00642   }
00643 
00644   PlotLine *line = new PlotLine;
00645   return line;
00646 }
00647 
00648 PlotLine * UTIL::calculateHL (QString &p, QPtrList<PlotLine> &d, int type)
00649 {
00650   // format1: METHOD, ARRAY_INPUT, DOUBLE
00651   // format: METHOD, ARRAY_INPUT, ARRAY_INPUT2
00652 
00653   formatList.clear();
00654   formatList.append(FormatString);
00655   formatList.append(FormatInputArray);
00656   formatList.append(FormatString); // dummy cause we dont know what this parm is beforehand
00657 
00658   if (checkFormat(p, d, 3, 3))
00659     return 0;
00660 
00661   PlotLine *input = d.at(0);
00662   PlotLine *input2 = 0;
00663   if (d.count() == 2)
00664     input2 = d.at(1);
00665 
00666   double inputNum = 0;
00667   if (! input2)
00668   {
00669     bool ok;
00670     double t = formatStringList[2].toDouble(&ok);
00671     if (ok)
00672       inputNum = t;
00673     else
00674       return 0;
00675   }
00676 
00677   int loop = input->getSize() - 1;
00678   int loop2 = 0;
00679   if (input2)
00680     loop2 = input2->getSize() - 1;
00681     
00682   PlotLine *line = new PlotLine;
00683   
00684   while (loop > -1)
00685   {
00686     double v = input->getData(loop);
00687     
00688     if (input2)
00689     {
00690       if (loop2 < 0)
00691         break;
00692 
00693       switch (type)
00694       {
00695         case 1: // higher
00696           if (v < input2->getData(loop2))
00697             v = input2->getData(loop2);
00698           break;
00699         case 2: // lower
00700           if (v > input2->getData(loop2))
00701             v = input2->getData(loop2);
00702           break;
00703         default:
00704           break;
00705       }
00706 
00707       loop2--;
00708     }
00709     else
00710     {
00711       switch(type)
00712       {
00713         case 1:
00714           if (v < inputNum)
00715             v = inputNum;
00716           break;
00717         case 2:
00718           if (v > inputNum)
00719             v = inputNum;
00720           break;
00721         default:
00722           break;
00723       }
00724     }
00725     
00726     line->prepend(v);
00727     loop--;
00728   }
00729   
00730   return line;
00731 }
00732 
00733 PlotLine * UTIL::calculateINRANGE (QString &p, QPtrList<PlotLine> &d)
00734 {
00735   // format: METHOD, INPUT_ARRAY, DOUBLE, DOUBLE
00736   // format: METHOD, INPUT_ARRAY, INPUT_ARRAY2, INPUT_ARRAY3
00737 
00738   QStringList l = QStringList::split(",", p, FALSE);
00739 
00740   if (l.count() != 4)
00741   {
00742     qDebug("UTIL::INRANGE: invalid parm count");
00743     return 0;
00744   }
00745 
00746   PlotLine *input = 0;
00747   if (! d.count())
00748   {
00749     qDebug("UTIL::INRANGE: invalid ARRAY_INPUT parm");
00750     return 0;
00751   }
00752   input = d.at(0);
00753   int loop = input->getSize() - 1;
00754 
00755   PlotLine *input2 = 0;
00756   int loop2 = 0;
00757   bool ok;
00758   double min = l[2].toDouble(&ok);
00759   if (! ok)
00760   {
00761     if (d.count() >= 2)
00762     {
00763       input2 = d.at(1);
00764       loop2 = input2->getSize() - 1;
00765     }
00766     else
00767     {
00768       qDebug("UTIL::INRANGE: invalid MIN parm");
00769       return 0;
00770     }
00771   }
00772 
00773   PlotLine *input3 = 0;
00774   int loop3 = 0;
00775   double max = l[3].toDouble(&ok);
00776   if (! ok)
00777   {
00778     if (d.count() == 3)
00779     {
00780       input3 = d.at(2);
00781       loop3 = input3->getSize() - 1;
00782     }
00783     else
00784     {
00785       qDebug("UTIL::INRANGE: invalid MAX parm");
00786       return 0;
00787     }
00788   }
00789 
00790   PlotLine *line = new PlotLine();
00791   while (loop > -1)
00792   {
00793     if (input2)
00794     {
00795       if (loop2 < 0) 
00796         break;
00797         
00798       min = input2->getData(loop2);
00799       loop2--;
00800     }
00801 
00802     if (input3)
00803     {
00804       if (loop3 < 0)
00805         break;
00806         
00807       max = input3->getData(loop3);
00808       loop3--;
00809     }
00810 
00811     if (input->getData(loop) >= min && input->getData(loop) <= max)
00812       line->prepend(1);
00813     else
00814       line->prepend(0);
00815 
00816     loop--;
00817   }
00818 
00819   return line;
00820 }
00821 
00822 void UTIL::formatDialog (QStringList &vl, QString &rv, QString &rs)
00823 {
00824   rs.truncate(0);
00825   rv.truncate(0);
00826 
00827   bool ok;
00828   QString method = QInputDialog::getItem(QObject::tr("UTIL Indicator Selection"),
00829                                          QObject::tr("Select an indicator:"),
00830                                          methodList,
00831                                          0,
00832                                          TRUE,
00833                                          &ok,
00834                                          0);
00835   if (! ok)
00836     return;
00837 
00838   QString pl = QObject::tr("Parms");
00839   QString vnl = QObject::tr("Variable Name");
00840   QString ai1l = QObject::tr("Array Input");
00841   QString ai2l = QObject::tr("Array Input2");
00842   QString cal = QObject::tr("Color Array");
00843   QString cil = QObject::tr("Constant Input");
00844   QString ol = QObject::tr("Operator");
00845   QString perl = QObject::tr("Period");
00846   QString cl = QObject::tr("Color");
00847   QString minl = QObject::tr("Minimum");
00848   QString maxl = QObject::tr("Maximum");
00849 
00850   PrefDialog *dialog = new PrefDialog(0);
00851   dialog->setCaption(QObject::tr("UTIL Format"));
00852   dialog->createPage (pl);
00853   dialog->setHelpFile(helpFile);
00854 
00855   QString s;
00856   dialog->addTextItem(vnl, pl, s);
00857 
00858   while (1)
00859   {
00860     if (! method.compare("ACCUM") || ! method.compare("Normal") || ! method.compare("PER"))
00861     {
00862       // format: METHOD, INPUT_ARRAY
00863       dialog->addComboItem(ai1l, pl, vl, 0);
00864       break;
00865     }
00866 
00867     if (! method.compare("ADD") || ! method.compare("DIV") || ! method.compare("MUL") ||
00868         ! method.compare("SUB") || ! method.compare("Higher") || ! method.compare("Lower"))
00869     {
00870       // format1: METHOD, ARRAY_INPUT, DOUBLE
00871       // format2: METHOD, ARRAY_INPUT, ARRAY_INPUT2
00872       dialog->addComboItem(ai1l, pl, vl, 0);
00873       QStringList l = vl;
00874       l.append(QObject::tr("None"));
00875       dialog->addComboItem(ai2l, pl, l, l.count() - 1);
00876       dialog->addDoubleItem(cil, pl, 0, -99999999.0, 99999999.0);
00877       break;
00878     }
00879 
00880     if (! method.compare("COMP"))
00881     {
00882       // format1: METHOD, ARRAY_INPUT, DOUBLE, OPERATOR
00883       // format2: METHOD, ARRAY_INPUT, ARRAY_INPUT2, OPERATOR
00884       dialog->addComboItem(ai1l, pl, vl, 0);
00885       QStringList l = vl;
00886       l.append(QObject::tr("None"));
00887       dialog->addComboItem(ai2l, pl, l, l.count() - 1);
00888       dialog->addDoubleItem(cil, pl, 0, -99999999.0, 99999999.0);
00889       dialog->addComboItem(ol, pl, opList, 0);
00890       break;
00891     }
00892 
00893     if (! method.compare("COUNTER"))
00894     {
00895       // format1: METHOD, ARRAY_INPUT
00896       // format2: METHOD, ARRAY_INPUT, ARRAY_INPUT2
00897       dialog->addComboItem(ai1l, pl, vl, 0);
00898       QStringList l = vl;
00899       l.append(QObject::tr("None"));
00900       dialog->addComboItem(ai2l, pl, l, l.count() - 1);
00901       break;
00902     }
00903 
00904     if (! method.compare("REF"))
00905     {
00906       // format1: METHOD, ARRAY_INPUT, PERIOD
00907       // format2: METHOD, DOUBLE
00908       QStringList l = vl;
00909       l.append(QObject::tr("None"));
00910       dialog->addComboItem(ai1l, pl, l, l.count() - 1);
00911       dialog->addDoubleItem(cil, pl, 0, -99999999.0, 99999999.0);
00912       dialog->addIntItem(perl, pl, 1, 0, 999999);
00913       break;
00914     }
00915 
00916     if (! method.compare("COLOR"))
00917     {
00918       // format1: METHOD, INPUT_ARRAY, COLOR_ARRAY, VALUE, COLOR
00919       dialog->addComboItem(ai1l, pl, vl, 0);
00920       dialog->addComboItem(cal, pl, vl, 0);
00921       dialog->addDoubleItem(cil, pl, 0, -99999999.0, 99999999.0);
00922       QColor color("red");
00923       dialog->addColorItem(cl, pl, color);
00924       break;
00925     }
00926 
00927     if (! method.compare("INRANGE"))
00928     {
00929       // format1: METHOD, ARRAY_INPUT, DOUBLE, DOUBLE
00930       // format2: METHOD, ARRAY_INPUT, ARRAY_INPUT2, ARRAY_INPUT3
00931       dialog->addComboItem(ai1l, pl, vl, 0);
00932       QStringList l = vl;
00933       l.append(QObject::tr("None"));
00934       QString s = QObject::tr("Min Array");
00935       dialog->addComboItem(s, pl, l, l.count() - 1);
00936       dialog->addDoubleItem(minl, pl, 0, -99999999.0, 99999999.0);
00937       s = QObject::tr("Max Array");
00938       dialog->addComboItem(s, pl, l, l.count() - 1);
00939       dialog->addDoubleItem(maxl, pl, 0, -99999999.0, 99999999.0);
00940       break;
00941     }
00942 
00943     break;
00944   }
00945 
00946   int rc = dialog->exec();
00947   
00948   if (rc == QDialog::Accepted)
00949   {
00950     dialog->getText(vnl, rv);
00951     rs = method;
00952 
00953     while (1)
00954     {
00955       if (! method.compare("ACCUM") || ! method.compare("Normal") || ! method.compare("PER"))
00956       {
00957         // format: METHOD, INPUT_ARRAY
00958         dialog->getCombo(ai1l, s);
00959         rs.append("," + s);
00960         break;
00961       }
00962 
00963       if (! method.compare("ADD") || ! method.compare("DIV") || ! method.compare("MUL") ||
00964           ! method.compare("SUB") || ! method.compare("Higher") || ! method.compare("Lower"))
00965       {
00966         // format1: METHOD, ARRAY_INPUT, DOUBLE
00967         // format2: METHOD, ARRAY_INPUT, ARRAY_INPUT2
00968         dialog->getCombo(ai1l, s);
00969         rs.append("," + s);
00970 
00971         dialog->getCombo(ai2l, s);
00972         if (! s.compare(QObject::tr("None")))
00973         {
00974           double d = dialog->getDouble(cil);
00975           rs.append("," + QString::number(d));
00976         }
00977         else
00978           rs.append("," + s);
00979         break;
00980       }
00981 
00982       if (! method.compare("COMP"))
00983       {
00984         // format1: METHOD, ARRAY_INPUT, DOUBLE, OPERATOR
00985         // format2: METHOD, ARRAY_INPUT, ARRAY_INPUT2, OPERATOR
00986         dialog->getCombo(ai1l, s);
00987         rs.append("," + s);
00988 
00989         dialog->getCombo(ai2l, s);
00990         if (! s.compare(QObject::tr("None")))
00991         {
00992           double d = dialog->getDouble(cil);
00993           rs.append("," + QString::number(d));
00994         }
00995         else
00996           rs.append("," + s);
00997 
00998         dialog->getCombo(ol, s);
00999         rs.append("," + s);
01000         break;
01001       }
01002 
01003       if (! method.compare("COUNTER"))
01004       {
01005         // format1: METHOD, ARRAY_INPUT
01006         // format2: METHOD, ARRAY_INPUT, ARRAY_INPUT2
01007         dialog->getCombo(ai1l, s);
01008         rs.append("," + s);
01009 
01010         dialog->getCombo(ai2l, s);
01011         if (s.compare(QObject::tr("None")))
01012           rs.append("," + s);
01013         break;
01014       }
01015 
01016       if (! method.compare("REF"))
01017       {
01018         // format1: METHOD, ARRAY_INPUT, PERIOD
01019         // format2: METHOD, DOUBLE
01020         dialog->getCombo(ai1l, s);
01021         if (! s.compare(QObject::tr("None")))
01022         {
01023           double d = dialog->getDouble(cil);
01024           rs.append("," + QString::number(d));
01025         }
01026         else
01027         {
01028           rs.append("," + s);
01029 
01030           int t = dialog->getInt(perl);
01031           rs.append("," + QString::number(t));
01032         }
01033         break;
01034       }
01035 
01036       if (! method.compare("COLOR"))
01037       {
01038         // format1: METHOD, INPUT_ARRAY, COLOR_ARRAY, VALUE, COLOR
01039         dialog->getCombo(ai1l, s);
01040         rs.append("," + s);
01041 
01042         dialog->getCombo(cal, s);
01043         rs.append("," + s);
01044 
01045         double d = dialog->getDouble(cil);
01046         rs.append("," + QString::number(d));
01047 
01048         QColor color;
01049         dialog->getColor(cl, color);
01050         rs.append("," + color.name());
01051         break;
01052       }
01053 
01054       if (! method.compare("INRANGE"))
01055       {
01056         // format1: METHOD, ARRAY_INPUT, DOUBLE, DOUBLE
01057         dialog->getCombo(ai1l, s);
01058 
01059         QString s = QObject::tr("Min Array");
01060         QString s2;
01061         dialog->getCombo(s, s2);
01062         if (! s2.compare(QObject::tr("None")))
01063         {
01064           double d = dialog->getDouble(minl);
01065           rs.append("," + QString::number(d));
01066         }
01067         else
01068           rs.append("," + s2);
01069 
01070         s = QObject::tr("Max Array");
01071         dialog->getCombo(s, s2);
01072         if (! s2.compare(QObject::tr("None")))
01073         {
01074           double d = dialog->getDouble(maxl);
01075           rs.append("," + QString::number(d));
01076         }
01077         else
01078           rs.append("," + s2);
01079 
01080         break;
01081       }
01082 
01083       break;
01084     }
01085   }
01086 
01087   delete dialog;
01088 }
01089