示例#1
0
/*!
  Returns a list of names of all the available font families.
*/
QStringList FontDatabase::families() const
{
#ifndef QT_NO_FONTDATABASE
    return QFontDatabase::families();
#else

#ifndef QWS
   QStringList list;
   return list;
#else
    QStringList list;
    QDict<void> familyDict;
    QDiskFont *qdf;
    for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0;
            qdf=qt_fontmanager->diskfonts.next()) {
	QString familyname = qdf->name;
	if ( !familyDict.find( familyname ) ) {
	    familyDict.insert( familyname, (void *)1 );
	    list.append( familyname );
	}
    }

    QDir dir(fontDir(),"*.qpf");
    for (int i=0; i<(int)dir.count(); i++) {
	QString familyname = fontFamily(dir[i]);
	if ( !familyDict.find( familyname ) ) {
	    familyDict.insert( familyname, (void *)1 );
	    list.append( familyname );
	}
    }

    return list;
#endif
#endif
}
示例#2
0
SlaveConfigProtocol* SlaveConfigPrivate::findProtocolConfig(const QString &_protocol)
{
   SlaveConfigProtocol *scp = protocol.find(_protocol);
   if (!scp)
      scp = readProtocolConfig(_protocol);
   return scp;
}
示例#3
0
// return pixmap for zoom 100%
QPixmap * get_pixmap(const char * path)
{
  QPixmap * px = DiagramPixmap.find(path);
  
  if (px == 0) {
    QString abspath;
    
    if (!QDir::isRelativePath(path))
      abspath = path;
    else if ((UmlWindow::images_root_dir().isEmpty() ||
	      !QFile::exists(abspath = QDir::cleanDirPath(UmlWindow::images_root_dir() + '/' + path))) &&
	     !QFile::exists(abspath = path))
      abspath = BrowserView::get_dir().absFilePath(path);
    
    px = new QPixmap(abspath);
    
    DiagramPixmap.insert(path, px);
    
    if (px->isNull()) {
      msg_critical(TR("Error"),
		   QString(path) + TR("\ndoesn't exist or is not a know image format"));
      return 0;
    }
    
    DiagramScaledPixmap.insert(path, new QPtrDict<QPixmap>());
  }

  return (px->isNull()) ? 0 : px;
}
示例#4
0
ColorSchema* ColorSchema::find(const char* path)
{
  ColorSchema* res = 0;
  QString temp_path;

  // search for a local schema first
  if (path[0] != '/') temp_path = kapp->localkdedir() + "/share/apps/konsole/";
  temp_path += path;
  if (QFile::exists(temp_path) == true)
    res = path2schema.find(temp_path.data());
  else
  {
    temp_path = kapp->kde_datadir() + "/konsole/";
    if (QFile::exists(temp_path) == true)
      res = path2schema.find(temp_path.data());
  }
  return res ? res : numb2schema.find(0);
}
示例#5
0
void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth)
{
    depth++;
    if ( depth > 10 )
  return;

    QDir dir( dr );

    /* Opie got a different approach
     * I guess it's geek vs. consumer
     * in this case to be discussed
     */
    if ( dir.exists( ".Qtopia-ignore" ) )
  return;

    const QFileInfoList *list = dir.entryInfoList();
    if ( list ) {
  QFileInfo* fi;
  for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
      QString bn = fi->fileName();
      if ( bn[0] != '.' ) {
    if ( fi->isDir()  ) {
        if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" )
      findChildren(fi->filePath(), mimeFilters, reference, depth);
    } else {
        if ( fi->extension(FALSE) == "desktop" ) {
      DocLnk* dl = new DocLnk( fi->filePath() );
      QFileInfo fi2(dl->file());
      bool match = FALSE;
      if ( !fi2.exists() ) {
          dir.remove( dl->file() );
      }
      if ( mimeFilters.count() == 0 ) {
          add( dl );
          match = TRUE;
      } else {
          for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) {
        if ( (*it).match(dl->type()) >= 0 ) {
            add(dl);
            match = TRUE;
        }
          }
      }
      if ( !match )
          delete dl;
        } else {
      if ( !reference.find(fi->fileName()) )
          reference.insert(fi->filePath(), (void*)2);
        }
    }
      }
  }
    }
}
 MemberDef* VerilogDocGen::findMemberDef(ClassDef* cd,QCString& key,MemberListType type,int spec,bool def)
 {

    static QCString className;
	static QCString prevName;
    static ClassDef* sClass=0;

	MemberDef  *mem=NULL;

	if(cd==0)
	{       
 	  mem=globalMemDict.find(key.data());
	  if(mem) return mem;
	  return NULL;
	}
	className=cd->name();
	 
  if(prevName != className )
  {
     prevName=className;
	 buildVariableDict(cd);
  }
  

	  if(mem==0)
		  mem=variableDict.find(key.data());
		  
	  if(mem)
	  { 
		 return mem;
	  }
      mem=globalMemDict.find(key.data());
	  if(mem)
		 return mem;
	  	
 return NULL;


}//findMemberDef
MemberDef* VerilogDocGen::findInstMember(QCString & cl,QCString & inst,QCString & key,bool b)
	{
     ClassDef* cdInst=0;
	 ClassDef* cdClass=0;
	 if(!cl.isEmpty())
		cdClass= VhdlDocGen::getClass(cl.data());

	  if(!inst.isEmpty())
		 cdInst= VhdlDocGen::getClass(inst.data());

    if(!buildInst)
		{
         buildVariableDict(cdInst,cdClass);
         buildInst=true;
		}

      if(!b) 
		  return  classPortDict.find(key.data());
	  else
		  return  instPortDict.find(key.data());

 	}//find
示例#8
0
void DbPlugin::loadIndexData (QString &symbol, QDict<Bar> &lookup, QDateTime &startDate, float weight,
                           int barRange, BarData::BarLength barLength)
{
  QFileInfo fi(symbol);
  QString fn = fi.fileName();

  DbPlugin db;
  if (db.open(symbol, chartIndex))
  {
    qDebug("Index::getIndexHistory: cannot open symbol chart");
    return;
  }

  BarData *bar = new BarData(symbol);
  bar->setBarLength(barLength);
  db.setBarRange(barRange);
  db.getHistory(bar, startDate);
  db.close();
  
  int loop;
  for (loop = 0; loop < (int) bar->count(); loop++)
  {
    QDateTime dt;
    bar->getDate(loop, dt);
    QString s = dt.toString("yyyyMMddhhmmss");
    Bar *r = lookup.find(s);
    if (! r)
    {
      r = new Bar;
      r->setDate(dt);
      r->setOpen(bar->getOpen(loop) * weight);
      r->setHigh(bar->getHigh(loop) * weight);
      r->setLow(bar->getLow(loop) * weight);
      r->setClose(bar->getClose(loop) * weight);
      r->setOI(1);
      r->getDateTimeString(FALSE, s);
      lookup.insert(s, r);
    }
    else
    {
      r->setOpen(r->getOpen() + (bar->getOpen(loop) * weight));
      r->setHigh(r->getHigh() + (bar->getHigh(loop) * weight));
      r->setLow(r->getLow() + (bar->getLow(loop) * weight));
      r->setClose(r->getClose() + (bar->getClose(loop) * weight));
      r->setOI((int) r->getOI() + 1);
    }
  }

  delete bar;
}
示例#9
0
SlaveConfigProtocol* SlaveConfigPrivate::readProtocolConfig(const QString &_protocol)
{
   SlaveConfigProtocol *scp = protocol.find(_protocol);
   if (!scp)
   {
      QString filename = KProtocolInfo::config(_protocol);
      scp = new SlaveConfigProtocol;
      scp->configFile = new KConfig(filename, true, false);
      protocol.insert(_protocol, scp);
   }
   // Read global stuff...
   readConfig(scp->configFile, "<default>", &(scp->global));
   return scp;
}
示例#10
0
static void addUnique(KService::List &lst, QDict< KService > &dict, const KService::List &newLst, bool lowPrio)
{
    QValueListConstIterator< KService::Ptr > it = newLst.begin();
    for(; it != newLst.end(); ++it)
    {
        KService *service = static_cast< KService * >(*it);
        if(dict.find(service->desktopEntryPath()))
            continue;
        dict.insert(service->desktopEntryPath(), service);
        lst.append(service);
        if(lowPrio)
            service->setInitialPreference(0);
    }
}
示例#11
0
void CUS::createPlot (QString &d, QDict<PlotLine> &lines, Indicator *output)
{
  if (! d.contains("plot"))
    return;

  QStringList l = QStringList::split("(", d, FALSE);
  if (l.count() != 2)
  {
    qDebug("CUS::createPlot: bad plot format: %s", d.ascii());
    return;
  }

  QString parms = l[1];
  parms.truncate(parms.find(")", -1, TRUE));
  l = QStringList::split(",", parms, FALSE);
  if (l.count() != 4)
  {
    qDebug("CUS::createPlot: missing plot parms: %s",d.ascii());
    return;
  }

  // 1.var name
  l[0] = l[0].stripWhiteSpace();
  PlotLine *pl = lines.find(l[0]);
  if (! pl)
  {
    qDebug("CUS::createPlot: bad plot parm 1: %s",d.ascii());
    return;
  }

  // 2.color
  l[1] = l[1].stripWhiteSpace();
  pl->setColor(l[1]);

  // 3.label
  l[2] = l[2].stripWhiteSpace();
  pl->setLabel(l[2]);

  // 4.linetype
  l[3] = l[3].stripWhiteSpace();
  pl->setType(l[3]);

  PlotLine *tline = new PlotLine;
  tline->copy(pl);
  output->addLine(tline);
}
void loadStylesheet(const char *name, QDict<StyleData>& dict)
{
  QFile file(name);
  if (!file.open(IO_ReadOnly))
  {
    err("Can't open RTF style sheet file %s. Using defaults.\n",name);
    return;
  }
  msg("Loading RTF style sheet %s...\n",name);

  static const QRegExp separator("[ \t]*=[ \t]*");
  uint lineNr=1;
  QTextStream t(&file);
#if QT_VERSION >= 200
  t.setEncoding(QTextStream::Latin1);
#endif

  while (!t.eof())
  {
    QCString s(4096); // string buffer of max line length
    s = t.readLine().stripWhiteSpace();
    if (s.isEmpty() || s.at(0)=='#') continue; // skip blanks & comments
    int sepLength;
    int sepStart = separator.match(s,0,&sepLength);
    if (sepStart<=0) // no valid assignment statement
    {
      warn(name,lineNr,"Assignment of style sheet name expected!\n");
      continue;
    }
    QCString key=s.left(sepStart);
    if (dict[key]==0) // not a valid style sheet name
    {
      warn(name,lineNr,"Invalid style sheet name %s ignored.\n",key.data());
      continue;
    }
    StyleData* styleData = dict.find(key);
    if (styleData == 0)
    {
      warn(name,lineNr,"Unknown style sheet name %s ignored.\n",key.data());
      continue;
    }
    s+=" "; // add command separator
    styleData->setStyle(s.data() + sepStart + sepLength, key.data());
    lineNr++;
  }
}
示例#13
0
void Spread::getHistory (BarData *barData, QDateTime &startDate, QString &fs, QString &ss,
                     int barRange, BarData::BarLength barLength)
{
  // get the first symbol bars
  QString s;
  DbPlugin db;
  if (db.openChart(fs))
  {
    qDebug("DbPlugin::getSpreadHistory: cannot open first symbol chart");
    db.close();
    return;
  }

  BarData *bar = new BarData(fs);
  bar->setBarLength(barLength);
  db.setBarRange(barRange);
  db.getHistory(bar, startDate);
  db.close();

  // get the second symbol bars
  if (db.openChart(ss))
  {
    qDebug("DbPlugin::getSpreadHistory: cannot open second symbol chart");
    db.close();
    delete bar;
    return;
  }

  BarData *bar2 = new BarData(ss);
  bar2->setBarLength(barLength);
  db.setBarRange(barRange);
  db.getHistory(bar2, startDate);
  db.close();

  // create lookup dict for first symbol bars
  QDict<Bar> lookup;
  lookup.setAutoDelete(TRUE);
  int loop;
  for (loop = 0; loop < bar->count(); loop++)
  {
    Bar *r = new Bar;
    QDateTime dt;
    bar->getDate(loop, dt);
    r->setDate(dt);
    r->setClose(bar->getClose(loop));
    r->getDateTimeString(FALSE, s);
    lookup.insert(s, r);
  }

  // match all second symbol bars
  for (loop = bar2->count() - 1; loop > -1; loop--)
  {
    Bar r;
    QDateTime dt;
    bar2->getDate(loop, dt);
    s = dt.toString("yyyyMMddhhmmss");
    Bar *tr = lookup.find(s);
    if (tr)
    {
      double t = tr->getClose() - bar2->getClose(loop);
      r.setDate(dt);
      r.setOpen(t);
      r.setHigh(t);
      r.setLow(t);
      r.setClose(t);
      barData->prepend(r);
    }
  }

  delete bar;
  delete bar2;
}
示例#14
0
/**
 * Add entries to a variable. Will just add the variables to the existing line, removing duplicates
 * Will preserve += constructs and make sure that the variable only has one copy of the value across
 * all += constructs
 * @param fileName
 * @param variables key=value string of entries to add
 * @param add true= add these key,value pairs, false = remove. You can have empty values for an add - the whole line is
 * removed. For adding, we will not add an empty line.
 */
void AutoProjectTool::addRemoveMakefileam(const QString &fileName, QMap<QString, QString> variables,  bool add)
{
	// input file reading
	QFile fin(fileName);
	if (!fin.open(IO_ReadOnly))
	{
		return ;
	}
	QTextStream ins(&fin);

	// output file writing.
	QFile fout(fileName + "#");
	if (!fout.open(IO_WriteOnly))
	{
		fin.close();
		return ;
	}
	QTextStream outs(&fout);

	// variables
	QRegExp re("^(#kdevelop:[ \t]*)?([A-Za-z][@A-Za-z0-9_]*)[ \t]*([:\\+]?=)[ \t]*(.*)$");

	// build key=map of values to add
	// map can be empty.we never add an empty key, but do remove empty keys from the file..
	QDict< QMap<QString, bool> > interest;
	for (QMap<QString, QString>::Iterator it0 = variables.begin(); it0 != variables.end(); ++it0)
	{
		kdDebug(9020) << "key (" << add<<"): " << it0.key() << "="<< it0.data() << endl;

		QMap<QString, bool>* set = new QMap<QString, bool>();
		if (!it0.data().stripWhiteSpace().isEmpty())
		{
			QStringList variableList = QStringList::split(' ', it0.data());

			for (uint i = 0; i < variableList.count(); i++)
			{
				set->insert(variableList[i], true);
			}
		}
		interest.insert(it0.key(), set);
	}

	bool multiLine = false;
	QString lastLhs;
	QStringList lastRhs;
	QMap<QString, QString> seenLhs;
	while (!fin.atEnd())
	{
		QString s = ins.readLine();
		if (re.exactMatch(s))
		{
			QString lhs = re.cap(2);
			QMap<QString, bool>* ourRhs = interest.find(lhs);

			if (!ourRhs)
			{
				// not interested in this line at all
				// write it out as is..
				outs << s << endl;
			}
			else
			{
				// we are interested in this line..
				QString rhs = re.cap(4).stripWhiteSpace();
				if (rhs[ rhs.length() - 1 ] == '\\')
				{
					// save it for when we have the whole line..
					multiLine = true;
					lastLhs = lhs;
					rhs.setLength(rhs.length() - 1);
					lastRhs += QStringList::split(" ", rhs);
				}
				else
				{
					// deal with it now.

					QStringList bits = QStringList::split(" ", rhs);
					if (add)
					{
						// we are adding our interested values to this line and writing it

						// add this line to we we want to add to remove duplicates.
						for (uint index = 0; index < bits.size(); index++)
						{
							QMap<QString, bool>::iterator findEntry = ourRhs->find(bits[index]);
							if (findEntry == ourRhs->end())
							{
								// we haven't seen it, so add it, so we don't add it again later..
								ourRhs->insert(bits[index], true);
							}
							// else we have this value in our 'to add list' , it is either already been
							// added, so we don't want to add it again, or it hasn't been added, in which
							// case we will do so soon. so we can ignore this now..
						}
						// now write the line out if it is not going to be empty.
						QString newLine(lhs);
						if (seenLhs.find(lhs) == seenLhs.end())
						{
							newLine += " = ";
							seenLhs[lhs] = "";
						}
						else
						{
							newLine += " += ";
						}

						int len = newLine.length();
						bool added = false;
						QValueList<QString> keys = ourRhs->keys();
						for (uint count = 0; count < keys.size(); count++)
						{
							// if out entry is true, add it..
							if ((*ourRhs)[keys[count]])
							{
								added = true;
								len += keys[count].length() + 1;
								if (len > 80)
								{
									newLine += "\\\n\t";
									len = 8;
								}
								newLine += keys[count];
								newLine += ' ';
								// set our value so we don't add it again.
								(*ourRhs)[keys[count]] = false;
							}
						}
						// only print it out if there was a value to add..
						if (added)
						{
							newLine.setLength(newLine.length() - 1);
							outs << newLine << endl;
						}
					}
					else
					{
						// we are removing our interested values from this line

						// special case - no values, remove the line..
						if (!ourRhs->empty())
						{
							// check if any of these values are down to remove.
							QString newLine(lhs);
							if (seenLhs.find(lhs) == seenLhs.end())
							{
								newLine += " = ";
								seenLhs[lhs] = "";
							}
							else
							{
								newLine += " += ";
							}

							int len = newLine.length();
							bool added = false;
							for (QStringList::Iterator posIter = bits.begin(); posIter != bits.end();posIter++)
							{
								QMap<QString, bool>::iterator findEntry = ourRhs->find(*posIter);
								if (findEntry == ourRhs->end())
								{
									// we do not want to remove it..
									added = true;
									len += (*posIter).length() + 1;
									if (len > 80)
									{
										newLine += "\\\n\t";
										len = 8;
									}
									newLine += (*posIter);
									newLine += ' ';
								}
								// else we have this value in our 'to remove list', so don't add it.
							}
							// only print it out if there was a value on it..
							if (added)
							{
								newLine.setLength(newLine.length() - 1);
								outs << newLine << endl;
							}
						}
					}//if (add)
				}//if ( rhs[ rhs.length() - 1 ] == '\\'  )
			}//if ( found == interest.end())
		}
		else if (multiLine)
		{
			s = s.stripWhiteSpace();
			// we are only here if were interested in this line..
			if (s[s.length()-1] == '\\')
			{
				s.setLength(s.length() - 1);
				// still more multi line we wait for..
			}
			else
			{
				// end of the multi line..
				multiLine = false;
			}
			lastRhs += QStringList::split(" ", s);

			if (!multiLine)
			{
				// now we have to deal with this multiLine value..
				// ourRhs will always be a value, as we only get multiLine if we're interested in it..
				QMap<QString, bool>* ourRhs = interest.find(lastLhs);

				if (add)
				{
					// we are adding our interested values to this line and writing it

					// add this line to we we want to add to remove duplicates.
					for (uint index = 0; index < lastRhs.size(); index++)
					{
						QMap<QString, bool>::iterator findEntry = ourRhs->find(lastRhs[index]);
						if (findEntry == ourRhs->end())
						{
							// we haven't seen it, so add it, so we don't add it again later..
							ourRhs->insert(lastRhs[index], true);
						}
						// else we have this value in our 'to add list' , it is either already been
						// added, so we don't want to add it again, or it hasn't been added, in which
						// case we will do so soon. so we can ignore this now..
					}
					// now write the line out if it is not going to be empty.
					QString newLine(lastLhs);
					if (seenLhs.find(lastLhs) == seenLhs.end())
					{
						newLine += " = ";
						seenLhs[lastLhs] = "";
					}
					else
					{
						newLine += " += ";
					}

					int len = newLine.length();
					bool added = false;
					QValueList<QString> keys = ourRhs->keys();
					for (uint count = 0; count < keys.size(); count++)
					{
						// if out entry is true, add it..
						if ((*ourRhs)[keys[count]])
						{
							added = true;
							len += keys[count].length() + 1;
							if (len > 80)
							{
								newLine += "\\\n\t";
								len = 8;
							}
							newLine += keys[count];
							newLine += ' ';
							// set our value so we don't add it again.
							(*ourRhs)[keys[count]] = false;
						}
					}
					// only print it out if there was a value to add..
					if (added)
					{
						newLine.setLength(newLine.length() - 1);
						outs << newLine << endl;
					}
				}
				else
				{
					// we are removing our interested values from this line
					// special case - no values, remove the line..
					if (!ourRhs->empty())
					{
						// check if any of these values are down to remove.
						QString newLine(lastLhs);
						if (seenLhs.find(lastLhs) == seenLhs.end())
						{
							newLine += " = ";
							seenLhs[lastLhs] = "";
						}
						else
						{
							newLine += " += ";
						}
						int len = newLine.length();
						bool added = false;
						for (QStringList::Iterator posIter = lastRhs.begin(); posIter != lastRhs.end();posIter++)
						{
							QMap<QString, bool>::iterator findEntry = ourRhs->find(*posIter);
							if (findEntry == ourRhs->end())
							{
								// we do not want to remove it..
								added = true;
								len += (*posIter).length() + 1;
								if (len > 80)
								{
									newLine += "\\\n\t";
									len = 8;
								}
								newLine += (*posIter);
								newLine += ' ';
							}
							// else we have this value in our 'to remove list', so don't add it.
						}
						// only print it out if there was a value on it..
						if (added)
						{
							newLine.setLength(newLine.length() - 1);
							outs << newLine << endl;
						}
					}
				}

				lastLhs.setLength(0);
				lastRhs.clear();
			}
		}
		else
		{
			// can write this line out..
			// not a match, not a multi line,
			outs << s << endl;
		}
	}

	if (add)
	{
		QDictIterator<QMap<QString, bool> > it(interest);
		for (; it.current(); ++it)
		{
			QString lhs = it.currentKey();
			QMap<QString, bool>* ourRhs = it.current();

			QString newLine(lhs);
			if (seenLhs.find(lhs) == seenLhs.end())
			{
				newLine += " = ";
				seenLhs[lastLhs] = "";
			}
			else
			{
				newLine += " += ";
			}
			int len = newLine.length();
			bool added = false;
			QValueList<QString> keys = ourRhs->keys();
			for (uint count = 0; count < keys.size(); count++)
			{
				if ((*ourRhs)[keys[count]])
				{
					added = true;
					len += keys[count].length() + 1;
					if (len > 80)
					{
						newLine += "\\\n\t";
						len = 8;
					}
					newLine += keys[count];
					newLine += ' ';
					// set our value so we don't add it again.
					(*ourRhs)[keys[count]] = false;
				}
			}
			// only print it out if there was a value to add..
			if (added)
			{
				newLine.setLength(newLine.length() - 1);
				outs << newLine << endl;
			}
		}
	}
	interest.setAutoDelete(true);
	interest.clear();

	fin.close();
	fout.close();

	QDir().rename(fileName + "#", fileName);
}
示例#15
0
void DbPlugin::getSpreadHistory (BarData *barData, QDateTime &startDate)
{
  QString s = "FirstSymbol";
  QString fs;
  getData(s, fs);

  QString ss;
  s = "SecondSymbol";
  getData(s, ss);

  // get the first symbol bars
  QFileInfo fi(fs);
  QString fn = fi.fileName();

  DbPlugin db;
  if (db.open(fs, chartIndex))
  {
    qDebug("Spread::getSpreadHistory: cannot open first symbol chart");
    return;
  }

  BarData *bar = new BarData(fs);
  bar->setBarLength(barLength);
  db.setBarRange(barRange);
  db.getHistory(bar, startDate);
  db.close();

  // get the second symbol bars
  QFileInfo fi2(ss);
  fn = fi2.fileName();

  if (db.open(ss, chartIndex))
  {
    qDebug("Spread::getSpreadHistory: cannot open second symbol chart");
    delete bar;
    return;
  }

  BarData *bar2 = new BarData(ss);
  bar2->setBarLength(barLength);
  db.setBarRange(barRange);
  db.getHistory(bar2, startDate);
  db.close();

  // create lookup dict for first symbol bars
  QDict<Bar> lookup;
  lookup.setAutoDelete(TRUE);
  int loop;
  for (loop = 0; loop < bar->count(); loop++)
  {
    Bar *r = new Bar;
    QDateTime dt;
    bar->getDate(loop, dt);
    r->setDate(dt);
    r->setClose(bar->getClose(loop));
    r->getDateTimeString(FALSE, s);
    lookup.insert(s, r);
  }

  // match all second symbol bars
  for (loop = bar2->count() - 1; loop > -1; loop--)
  {
    Bar r;
    QDateTime dt;
    bar2->getDate(loop, dt);
    s = dt.toString("yyyyMMddhhmmss");
    Bar *tr = lookup.find(s);
    if (tr)
    {
      double t = tr->getClose() - bar2->getClose(loop);
      r.setDate(dt);
      r.setOpen(t);
      r.setHigh(t);
      r.setLow(t);
      r.setClose(t);
      barData->prepend(r);
    }
  }

  delete bar;
  delete bar2;
}
示例#16
0
void DbPlugin::getIndexHistory (BarData *barData, QDateTime &startDate)
{
  QString s = "List";
  QString s2;
  getData(s, s2);
  QStringList l = QStringList::split(":", s2, FALSE);
  if (! l.count())
    return;
    
  QDict<Bar> lookup;
  lookup.setAutoDelete(TRUE);
  int loop;
  int count = 0;
  for (loop = 0; loop < (int) l.count(); loop = loop + 2)
  {
    float weight = l[loop + 1].toFloat();
    if (weight == 0)
      weight = 1;

    loadIndexData(l[loop], lookup, startDate, weight, barRange, barLength);
    count++;
  }

  l.clear();
  QDictIterator<Bar> it(lookup);
  for (; it.current(); ++it)
  {
    Bar *r = it.current();
    if (r->getOI() == count)
    {
      r->setOpen(r->getOpen() / count);
      r->setHigh(r->getHigh() / count);
      r->setLow(r->getLow() / count);
      r->setClose(r->getClose() / count);
      
      if (r->getOpen() > r->getHigh())
        r->setHigh(r->getOpen());
      if (r->getOpen() < r->getLow())
        r->setLow(r->getOpen());

      if (r->getClose() > r->getHigh())
        r->setHigh(r->getClose());
      if (r->getClose() < r->getLow())
        r->setLow(r->getClose());

      r->getDateTimeString(FALSE, s);
      l.append(s);
    }
    else
      lookup.remove(it.currentKey());
  }

  l.sort();
  for (loop = l.count() - 1; loop > -1; loop--)
  {
    Bar *r = lookup.find(l[loop]);
    if (r)
    {
      QDateTime dt;
      r->getDate(dt);
      Bar tr;
      tr.setDate(dt);
      tr.setOpen(r->getOpen());
      tr.setHigh(r->getHigh());
      tr.setLow(r->getLow());
      tr.setClose(r->getClose());
      barData->prepend(tr);
    }
  }
}
示例#17
0
Indicator * CUS::calculate ()
{
  Config config;
  QStringList varList;
  QDict<PlotLine> lines;
  lines.setAutoDelete(TRUE);

  checkIncludes();

  Indicator *output = new Indicator;
  output->setDateFlag(dateFlag);
  output->setLogScale(logScale);
  
  int loop;
  for (loop = 0; loop < (int) formulaList.count(); loop++)
  {
    // check if whole line is a comment
    QString s = formulaList[loop].left(2);
    if ( ! s.compare("//"))
      continue;

    if (formulaList[loop].contains(":="))
    {
      QStringList l = QStringList::split(":=", formulaList[loop], FALSE);
      if (l.count() != 2)
      {
        qDebug("CUS::calculate: line %i parm missing", loop);
        return output;
      }
      
      QString var = l[0].stripWhiteSpace();
      if (varList.findIndex(var) != -1)
      {
        qDebug("CUS::calculate: line %i duplicate variable: %s", loop, var.latin1());
        return output;
      }
      varList.append(var);

      QStringList l2 = QStringList::split("(", l[1], FALSE);
      if (l2.count() != 2)
      {
        qDebug("CUS::calculate: line %i bad indicator format", loop);
        return output;
      }
      
      QString plugin = l2[0].stripWhiteSpace();
      QString parms = l2[1];
      parms.truncate(parms.find(")", 0, TRUE));
      parms = parms.stripWhiteSpace();
      while(parms.contains(" "))
        parms = parms.remove(parms.find(" ", 0, TRUE), 1);

      IndicatorPlugin *plug = config.getIndicatorPlugin(plugin);
      if (! plug)
      {
        qDebug("CUS::calculate: %s plugin not loaded", plugin.latin1());
        config.closePlugin(plugin);
        return output;
      }
      plug->setIndicatorInput(data);

      l = QStringList::split(",", parms, FALSE);
      int loop2;
      QPtrList<PlotLine> inList;
      inList.setAutoDelete(FALSE);
      for (loop2 = 0; loop2 < (int) l.count(); loop2++)
      {
        if (varList.findIndex(l[loop2]) != -1)
          inList.append(lines.find(l[loop2]));
        else
        {
          int itype = inputTypeList.findIndex(l[loop2]);
          if (itype != -1)
          {
            PlotLine *in = data->getInput((BarData::InputType) itype);
            if (! in)
            {
              qDebug("CUS::calculate:line%i parm%i: input not found", loop, loop2);
              return output;
            }

            lines.replace(l[loop2], in);
            inList.append(in);
          }
        }
      }

      PlotLine *out = plug->calculateCustom(parms, inList);
      if (! out)
      {
        qDebug("CUS::calculate: line %i: no PlotLine returned: %s", loop, parms.latin1());
        config.closePlugin(plugin);
        return output;
      }

      lines.replace(var, out);
    }

    createPlot(formulaList[loop], lines, output);
  }

  return output;
}
示例#18
0
//====================================
// remove and reorganize section ID...
//------------------------------------
bool SaXStorage::delID ( int id ) {
	// .../
	//! remove a data record and adapt the Identifier strings
	//! to provide consistency
	// ----
	if ((! mData.at (id)) || (mData.at(id)->isEmpty())) {
		return false;
	}
	int step = 1;
	int type = SAX_DESKTOP_TYPE;
	QString ident = *mData.at(id)->find ("Identifier");
	if (ident.contains ("Mouse")) {
		type = SAX_POINTER_TYPE;
		step = 2;
	}
	if (ident.contains ("Keyboard")) {
		type = SAX_KEYBOARD_TYPE;
		step = 2;
	}
	int index = -1;
	QListIterator < QDict<QString> > in (mData);
	for (; in.current(); ++in) {
		index++;
		QDict<QString>* data = in.current();
		QString* ident = data->find ("Identifier");
		if (! ident) {
			continue;
		}
		int curType = SAX_DESKTOP_TYPE;
		if (ident->contains("Mouse")) {
			curType = SAX_POINTER_TYPE;
		}
		if (ident->contains("Keyboard")) {
			curType = SAX_KEYBOARD_TYPE;
		}
		if ((data->isEmpty()) || (index <= id) || (curType != type)) {
			continue;
		}
		QString oIDstr;
		QString nIDstr;
		oIDstr.sprintf ("%d",index);
		nIDstr.sprintf ("%d",index - step);
		QString mouseIDstr    ("Mouse["   + oIDstr +"]");
		QString keyboardIDstr ("Keyboard["+ oIDstr +"]");
		QString deviceIDstr   ("Device["  + oIDstr +"]");
		QString monitorIDstr  ("Monitor[" + oIDstr +"]");
		QString screenIDstr   ("Screen["  + oIDstr +"]");
		QDictIterator<QString> it (*data);
		for (; it.current(); ++it) {
			QString val = *it.current();
			QString key = it.currentKey();
			if (val == mouseIDstr) {
				QString* nMouseIDstr = new QString ("Mouse["+nIDstr+"]");
				data -> replace (key,nMouseIDstr);
			}
			if (val == keyboardIDstr) {
				QString* nKbdIDstr = new QString ("Keyboard["+nIDstr+"]");
				data -> replace (key,nKbdIDstr);
			}
			if (val == deviceIDstr) {
				QString* nDeviceIDstr = new QString ("Device["+nIDstr+"]");
				data -> replace (key,nDeviceIDstr);
			}
			if (val == monitorIDstr) {
				QString* nMonitorIDstr = new QString ("Monitor["+nIDstr+"]");
				data -> replace (key,nMonitorIDstr);
			}
			if (val == screenIDstr) {
				QString* nScreenIDstr = new QString ("Screen["+nIDstr+"]");
				data -> replace (key,nScreenIDstr);
			}
			if ((key == "Screen") && (val == oIDstr)) {
				QString* nScreenIDstr = new QString (nIDstr);
				data -> replace (key,nScreenIDstr);
			}
		}
	}
	mData.remove (id);
	if ((mData.at(id)) && (mData.at(id)->isEmpty())) {
		mData.remove (id);
	}
	return true;
}