当前位置: 首页>>代码示例>>C++>>正文


C++ QLocale::toInt方法代码示例

本文整理汇总了C++中QLocale::toInt方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocale::toInt方法的具体用法?C++ QLocale::toInt怎么用?C++ QLocale::toInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QLocale的用法示例。


在下文中一共展示了QLocale::toInt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: paintMaleFemale

// QLocale is needed because the data is stored as _strings_ with
// locale-specific separators, e.g., 8.392.419 or 8,392,419.
void CensusVisualizerView::paintMaleFemale(QPainter *painter,
        int row, const QRect &rect)
{
    QRect rectangle(rect);
    QLocale locale;
    int males = locale.toInt(visualizer->model()->data(
            visualizer->model()->index(row, Males)).toString());
    int females = locale.toInt(visualizer->model()->data(
            visualizer->model()->index(row, Females)).toString());
    qreal total = males + females;
    int offset = qRound(
            ((1 - (total / visualizer->maximumPopulation())) / 2) *
             rectangle.width());

    painter->fillRect(rectangle,
            (row == visualizer->selectedRow() &&
             (visualizer->selectedColumn() == Females ||
              visualizer->selectedColumn() == Males))
            ? palette().highlight() : palette().base());

    visualizer->paintItemBorder(painter, palette(), rectangle);
    rectangle.setLeft(rectangle.left() + offset);
    rectangle.setRight(rectangle.right() - offset);
    int rectY = rectangle.center().y();
    painter->fillRect(rectangle.adjusted(0, 1, 0, -1),
            maleFemaleGradient(rectangle.left(), rectY,
                    rectangle.right(), rectY, males / total));
}
开发者ID:JustFFunny,项目名称:WorkSpace,代码行数:30,代码来源:censusvisualizerview.cpp

示例2: read

void CtrlList::read(Xml& xml)
{
    QLocale loc = QLocale::c();
    bool ok;
    for (;;)
    {
        Xml::Token token = xml.parse();
        const QString& tag = xml.s1();
        switch (token)
        {
            case Xml::Error:
            case Xml::End:
                return;
            case Xml::Attribut:
                if (tag == "id")
                {
                    _id = loc.toInt(xml.s2(), &ok);
                    if (!ok)
                    {
                        printf("CtrlList::read failed reading _id string: %s\n", xml.s2().toLatin1().constData());
                        initColor(0); //Set the default color if we have an error
                    }
                    else {
                        initColor(_id);
                    }
                }
                else if (tag == "cur")
                {
                    _curVal = loc.toDouble(xml.s2(), &ok);
                    if (!ok)
                        printf("CtrlList::read failed reading _curVal string: %s\n", xml.s2().toLatin1().constData());
                }
                else if(tag == "visible")
                {
                    _visible = (bool)xml.s2().toInt();
                }
                else if(tag == "color")
                {
                    ;//xml.skip(tag);
                }
                else
                    printf("unknown tag %s\n", tag.toLatin1().constData());
                break;
            case Xml::Text:
            {
                int len = tag.length();
                int frame;
                double val;

                int i = 0;
                for (;;)
                {
                    while (i < len && (tag[i] == ',' || tag[i] == ' ' || tag[i] == '\n'))
                        ++i;
                    if (i == len)
                        break;

                    QString fs;
                    while (i < len && tag[i] != ' ')
                    {
                        fs.append(tag[i]);
                        ++i;
                    }
                    if (i == len)
                        break;

                    // Works OK, but only because if current locale fails it falls back on 'C' locale.
                    // So, let's skip the fallback and force use of 'C' locale.
                    frame = loc.toInt(fs, &ok);
                    if (!ok)
                    {
                        printf("CtrlList::read failed reading frame string: %s\n", fs.toLatin1().constData());
                        break;
                    }

                    while (i < len && (tag[i] == ' ' || tag[i] == '\n'))
                        ++i;
                    if (i == len)
                        break;

                    QString vs;
                    while (i < len && tag[i] != ' ' && tag[i] != ',')
                    {
                        vs.append(tag[i]);
                        ++i;
                    }

                    // Works OK, but only because if current locale fails it falls back on 'C' locale.
                    // So, let's skip the fallback and force use of 'C' locale.
                    //val = vs.toDouble(&ok);
                    val = loc.toDouble(vs, &ok);
                    if (!ok)
                    {
                        printf("CtrlList::read failed reading value string: %s\n", vs.toLatin1().constData());
                        break;
                    }

                    //printf("CtrlList::read i:%d len:%d fs:%s frame %d: vs:%s val %f \n", i, len, fs.toLatin1().constData(), frame, vs.toLatin1().constData(), val);

                    add(frame, val);
//.........这里部分代码省略.........
开发者ID:ViktorNova,项目名称:los,代码行数:101,代码来源:ctrl.cpp

示例3: read

void MidiAudioCtrlMap::read(Xml& xml)
      {
      int port = -1, chan = -1, midi_ctrl = -1;
      MidiAudioCtrlStruct macs(-1);
      
      QLocale loc = QLocale::c();
      bool ok;
      int errcount = 0;
      for (;;) {
            Xml::Token token = xml.parse();
            const QString& tag = xml.s1();
            switch (token) {
                  case Xml::Error:
                  case Xml::End:
                        return;
                  case Xml::Attribut:
                        if (tag == "port")
                        {
                              port = loc.toInt(xml.s2(), &ok);
                              if(!ok)
                              { 
                                ++errcount;
                                printf("MidiAudioCtrlPortMap::read failed reading port string: %s\n", xml.s2().toLatin1().constData());
                              }
                        }
                        else if (tag == "ch")
                        {
                              chan = loc.toInt(xml.s2(), &ok);
                              if(!ok)
                              {
                                ++errcount;
                                printf("MidiAudioCtrlPortMap::read failed reading ch string: %s\n", xml.s2().toLatin1().constData());
                              }
                        }        
                        else if (tag == "mctrl")
                        {
                              midi_ctrl = loc.toInt(xml.s2(), &ok);
                              if(!ok)
                              {
                                ++errcount;
                                printf("MidiAudioCtrlPortMap::read failed reading mctrl string: %s\n", xml.s2().toLatin1().constData());
                              } 
                        }
                        else if (tag == "actrl")
                        {
                              macs.setAudioCtrlId(loc.toInt(xml.s2(), &ok));
                              if(!ok)
                              {
                                ++errcount;
                                printf("MidiAudioCtrlPortMap::read failed reading actrl string: %s\n", xml.s2().toLatin1().constData());
                              }
                        }
                        else
                              printf("unknown tag %s\n", tag.toLatin1().constData());
                        break;
                  case Xml::TagStart:
                        // TODO
                        //if (tag == "???") {  
                        //      }
                        //else
                              xml.unknown("midiMapper");
                        break;
                  case Xml::TagEnd:
                        if (xml.s1() == "midiMapper")
                        {
                              if(errcount == 0 && port != -1 && chan != -1 && midi_ctrl != -1 && macs.audioCtrlId() != -1)
                                  add_ctrl_struct(port, chan, midi_ctrl, macs);
                              return;
                        }
                  default:
                        break;
                  }
            }
      }
开发者ID:UIKit0,项目名称:lmuse,代码行数:74,代码来源:ctrl.cpp

示例4: read

void CtrlList::read(Xml& xml)
{
	QLocale loc = QLocale::c();
	bool ok;
	for (;;)
	{
		Xml::Token token = xml.parse();
		const QString& tag = xml.s1();
		switch (token)
		{
			case Xml::Error:
			case Xml::End:
				return;
			case Xml::Attribut:
				if (tag == "id")
				{
					//_id = xml.s2().toInt();
					_id = loc.toInt(xml.s2(), &ok);
					if (!ok)
					{
						printf("CtrlList::read failed reading _id string: %s\n", xml.s2().toLatin1().constData());
						initColor(0); //Set the default color if we have an error
					}
					else {
						initColor(_id);
					}
				}
				else if (tag == "cur")
				{
					//_curVal = xml.s2().toDouble();
					_curVal = loc.toDouble(xml.s2(), &ok);
					if (!ok)
						printf("CtrlList::read failed reading _curVal string: %s\n", xml.s2().toLatin1().constData());
				}
				else if(tag == "visible")
				{
					_visible = (bool)xml.s2().toInt();
				}
				else if(tag == "color")
				{
					;//xml.skip(tag);
				}
				else
					printf("unknown tag %s\n", tag.toLatin1().constData());
				break;
			case Xml::Text:
			{
				// Changed by Tim. Users in some locales reported corrupt reading,
				//  because of the way floating point is represented (2,3456 not 2.3456).
				/*
				QByteArray ba = tag.toLatin1();
				const char* s = ba;.constData();
				int frame;
				double val;

				for (;;) {
					  char* endp;
					  while (*s == ' ' || *s == '\n')
							++s;
					  if (*s == 0)
							break;
					  frame = strtol(s, &endp, 10);
					  s     = endp;
					  while (*s == ' ' || *s == '\n')
							++s;
					  val = strtod(s, &endp);
					  add(frame, val);
					  s = endp;
					  ++s;
					  }
				 */

				// Added by Tim. p3.3.6
				//printf("CtrlList::read tag:%s\n", tag.toLatin1().constData());

				int len = tag.length();
				int frame;
				double val;

				int i = 0;
				for (;;)
				{
					while (i < len && (tag[i] == ',' || tag[i] == ' ' || tag[i] == '\n'))
						++i;
					if (i == len)
						break;

					QString fs;
					while (i < len && tag[i] != ' ')
					{
						fs.append(tag[i]);
						++i;
					}
					if (i == len)
						break;

					// Works OK, but only because if current locale fails it falls back on 'C' locale.
					// So, let's skip the fallback and force use of 'C' locale.
					//frame = fs.toInt(&ok);
					frame = loc.toInt(fs, &ok);
//.........这里部分代码省略.........
开发者ID:faesong,项目名称:oom,代码行数:101,代码来源:ctrl.cpp


注:本文中的QLocale::toInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。