// 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)); }
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); if (i == len) break; } } break; case Xml::TagEnd: if (xml.s1() == "controller") { return; } default: break; } } }
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; } } }
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()); } 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 = loc.toInt(xml.s2(), &ok); if(!ok) printf("CtrlList::read failed reading _visible string: %s\n", xml.s2().toLatin1().constData()); } else if (tag == "color") { #if QT_VERSION >= 0x040700 ok = _displayColor.isValidColor(xml.s2()); if (!ok) { printf("CtrlList::read failed reading color string: %s\n", xml.s2().toLatin1().constData()); break; } #endif _displayColor.setNamedColor(xml.s2()); } 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; 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; } val = loc.toDouble(vs, &ok); if(!ok) { printf("CtrlList::read failed reading value string: %s\n", vs.toLatin1().constData()); break; } add(frame, val); if(i == len) break; } } break; case Xml::TagEnd: if (xml.s1() == "controller") return; default: break; } } }
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); 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; } // Added by Tim. p3.3.6 //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); if (i == len) break; } } break; case Xml::TagEnd: if (xml.s1() == "controller") { // Added by Tim. p3.3.6 //printf("CtrlList::read _id:%d _curVal:%f\n", _id, _curVal); return; } default: break; } } }