bool QLandmarkFileHandlerLmx::readCoordinates(QLandmark &landmark) { /* <xsd:complexType name="coordinatesType"> <xsd:sequence> <xsd:element name="latitude"> <xsd:simpleType> <xsd:restriction base="xsd:double"> <xsd:minInclusive value="-90"/> <xsd:maxInclusive value="90"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="longitude"> <xsd:simpleType> <xsd:restriction base="xsd:double"> <xsd:minInclusive value="-180"/> <xsd:maxExclusive value="180"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="altitude" type="xsd:float" minOccurs="0" /> <xsd:element name="horizontalAccuracy" minOccurs="0"> <xsd:simpleType> <xsd:restriction base="xsd:float"> <xsd:minInclusive value="0"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="verticalAccuracy" minOccurs="0"> <xsd:simpleType> <xsd:restriction base="xsd:float"> <xsd:minInclusive value="0"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="timeStamp" type="xsd:dateTime" minOccurs="0" /> </xsd:sequence> </xsd:complexType> */ Q_ASSERT(m_reader->isStartElement() && (m_reader->name() == "coordinates")); if (!m_reader->readNextStartElement()) { m_reader->raiseError("The element \"coordinates\" did not have the required child element \"latitude\"."); return false; } if (m_reader->name() == "latitude") { bool ok = false; QString s = m_reader->readElementText(); if ((s == "INF") || (s == "-INF") || (s == "NaN")) { m_reader->raiseError(QString("The element \"latitude\" expected a value convertable to type double (value was \"%1\").").arg(s)); return false; } double lat = s.toDouble(&ok); if (!ok) { m_reader->raiseError(QString("The element \"latitude\" expected a value convertable to type double (value was \"%1\").").arg(s)); return false; } if (lat < -90.0 || 90.0 < lat) { m_reader->raiseError(QString("The element \"latitude\" fell outside of the bounds -90.0 <= latitude <= 90.0 (value was \"%1\").").arg(s)); return false; } QGeoCoordinate coord = landmark.coordinate(); coord.setLatitude(lat); landmark.setCoordinate(coord); if (!m_reader->readNextStartElement()) { m_reader->raiseError("The element \"coordinates\" did not have the required child element \"longitude\"."); return false; } } else { m_reader->raiseError("The element \"coordinates\" did not have the required child element \"latitude\"."); return false; } if (m_reader->name() == "longitude") { bool ok = false; QString s = m_reader->readElementText(); if ((s == "INF") || (s == "-INF") || (s == "NaN")) { m_reader->raiseError(QString("The element \"longitude\" expected a value convertable to type double (value was \"%1\").").arg(s)); return false; } double lon = s.toDouble(&ok); if (!ok) { m_reader->raiseError(QString("The element \"longitude\" expected a value convertable to type double (value was \"%1\").").arg(s)); return false; } if (lon < -180.0 || 180.0 <= lon) { m_reader->raiseError(QString("The element \"longitude\" fell outside of the bounds -180.0 <= longitude < 180.0 (value was \"%1\").").arg(s)); return false; } QGeoCoordinate coord = landmark.coordinate(); coord.setLongitude(lon); landmark.setCoordinate(coord); if (!m_reader->readNextStartElement()) return true; } else { m_reader->raiseError("The element \"coordinates\" did not have the required child element \"longitude\"."); return false; } if (m_reader->name() == "altitude") { bool ok = false; QString s = m_reader->readElementText(); if ((s == "INF") || (s == "-INF") || (s == "NaN")) { m_reader->raiseError(QString("The element \"altitude\" expected a value convertable to type double (value was \"%1\").").arg(s)); return false; } double alt = s.toDouble(&ok); if (!ok) { m_reader->raiseError(QString("The element \"altitude\" expected a value convertable to type float (value was \"%1\").").arg(s)); return false; } QGeoCoordinate coord = landmark.coordinate(); coord.setAltitude(alt); landmark.setCoordinate(coord); if (!m_reader->readNextStartElement()) return true; } QList<QString> names; names << "horizontalAccuracy"; names << "verticalAccuracy"; names << "timeStamp"; for (int i = 0; i < names.size(); ++i) { // Not used outside of schema compliance check if (m_reader->name() == names.at(i)) { m_reader->skipCurrentElement(); if (!m_reader->readNextStartElement()) return true; } } m_reader->raiseError(QString("The element \"coordinate\" did not expect a child element named \"%1\" at this point (unknown child element or child element out of order).").arg(m_reader->name().toString())); return false; }
void PropertyModel::addProperty(PropertyID propID, EPropertyType propType, const QString& propName, const QVariant& value, const QString& uiHint) { if(!_propIdMap.contains(propID)) { Property* prop; switch(propType) { case EPropertyType::Boolean: prop = new BooleanProperty(propName, value.toBool()); break; case EPropertyType::Integer: prop = new IntegerProperty(propName, value.toInt()); break; case EPropertyType::Double: prop = new DoubleProperty(propName, value.toDouble()); break; case EPropertyType::Enum: prop = new EnumProperty(propName, value.value<Enum>()); break; case EPropertyType::Matrix: prop = new MatrixProperty(propName, value.value<Matrix3x3>()); break; case EPropertyType::Filepath: prop = new FilePathProperty(propName, value.value<Filepath>()); break; case EPropertyType::String: prop = new StringProperty(propName, value.toString()); break; default: /// TODO: throw ?? return; } if(!uiHint.isEmpty()) { PropertyHintList uiHintsLists; QRegExp re(QString("([^= ]*):{1}([^,]*),?")); re.setMinimal(false); int pos = 0; while((pos = re.indexIn(uiHint, pos)) != -1) { uiHintsLists.append(qMakePair(re.cap(1), re.cap(2).trimmed())); pos += re.matchedLength(); } if(!uiHintsLists.isEmpty()) prop->setUiHints(uiHintsLists); } prop->setPropertyID(propID); _propIdMap.insert(propID, prop); _currentGroup->appendChild(prop); } else { /// TODO: throw ?? } }
void PropertyModel::addPropertyGroup(const QString& groupName) { _currentGroup = new Property(groupName, QString(), EPropertyType::String, nullptr); _root->appendChild(_currentGroup); }
QString BitcoinUnits::formatWithUnit(int unit, qint64 amount, bool plussign) { return format(unit, amount, plussign) + QString(" ") + name(unit); }
QNetworkReplyFileImpl::QNetworkReplyFileImpl(QObject *parent, const QNetworkRequest &req, const QNetworkAccessManager::Operation op) : QNetworkReply(*new QNetworkReplyFileImplPrivate(), parent) { setRequest(req); setUrl(req.url()); setOperation(op); setFinished(true); QNetworkReply::open(QIODevice::ReadOnly); QNetworkReplyFileImplPrivate *d = (QNetworkReplyFileImplPrivate*) d_func(); QUrl url = req.url(); if (url.host() == QLatin1String("localhost")) url.setHost(QString()); #if !defined(Q_OS_WIN) // do not allow UNC paths on Unix if (!url.host().isEmpty()) { // we handle only local files QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Request for opening non-local file %1").arg(url.toString()); setError(QNetworkReply::ProtocolInvalidOperationError, msg); QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ProtocolInvalidOperationError)); QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); return; } #endif if (url.path().isEmpty()) url.setPath(QLatin1String("/")); setUrl(url); QString fileName = url.toLocalFile(); if (fileName.isEmpty()) { if (url.scheme() == QLatin1String("qrc")) { fileName = QLatin1Char(':') + url.path(); } else { #if defined(Q_OS_ANDROID) if (url.scheme() == QLatin1String("assets")) fileName = QLatin1String("assets:") + url.path(); else #endif fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery); } } QFileInfo fi(fileName); if (fi.isDir()) { QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Cannot open %1: Path is a directory").arg(url.toString()); setError(QNetworkReply::ContentOperationNotPermittedError, msg); QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentOperationNotPermittedError)); QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); return; } d->realFile.setFileName(fileName); bool opened = d->realFile.open(QIODevice::ReadOnly | QIODevice::Unbuffered); // could we open the file? if (!opened) { QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2") .arg(d->realFile.fileName(), d->realFile.errorString()); if (d->realFile.exists()) { setError(QNetworkReply::ContentAccessDenied, msg); QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentAccessDenied)); } else { setError(QNetworkReply::ContentNotFoundError, msg); QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentNotFoundError)); } QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); return; } setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified()); d->realFileSize = fi.size(); setHeader(QNetworkRequest::ContentLengthHeader, d->realFileSize); QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection, Q_ARG(qint64, d->realFileSize), Q_ARG(qint64, d->realFileSize)); QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); }
QString dateTimeStr(const QDateTime &date) { return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + date.toString("hh:mm"); }
void faxDecoder::setup_faxDecoder (QSettings *s) { QString h; int k; faxLowPass = new LowPassFIR (FILTER_DEFAULT, deviation + 50, theRate); faxAverager = new average (20); myDemodulator = new faxDemodulator (FAX_FM, theRate, deviation); /* * restore some of the settings */ s -> beginGroup ("faxDecoder"); h = s -> value ("fax_iocSetter", "576"). toString (); k = iocSetter -> findText (h); if (k != -1) iocSetter -> setCurrentIndex (k); // // OK, we know now faxParams *myfaxParameters = getFaxParams (iocSetter -> currentText ()); lpmSetter -> setValue (myfaxParameters -> lpm); lpm = myfaxParameters -> lpm;; samplesperLine = theRate * 60 / lpm; fax_IOC = myfaxParameters -> IOC; numberofColums = M_PI * fax_IOC; faxColor = myfaxParameters -> color ? FAX_COLOR: FAX_BLACKWHITE; carrier = FAX_IF; // default phaseInvers = false; lastRow = 100; // will change theImage = new faxImage (numberofColums, lastRow); rawData. resize (1024 * 1024); // pointNeeded = false; faxState = APTSTART; aptCount = 0; apt_upCrossings = 0; whiteSide = false; pixelValue = 0; pixelSamples = 0; currentSampleIndex = 0; set_savingRequested (false); set_autoContinue (false); nameGenerator = new faxFilenames (0); // startSetter -> setValue (myfaxParameters -> aptStart); stopSetter -> setValue (myfaxParameters -> aptStop); fax_setstartFreq (startSetter -> value ()); fax_setstopFreq (stopSetter -> value ()); fax_setCarrier (carrierSetter -> value ()); fax_setDeviation (deviationSetter -> value ()); setDetectorMarker (carrier); showState -> setText (QString ("APTSTART")); theImage -> clear (); fax_displayImage (theImage -> getImage ()); // // connect (colorSetter, SIGNAL (activated (const QString &)), this, SLOT (fax_setColor (const QString &))); connect (skipSetter, SIGNAL (clicked (void)), this, SLOT (fax_setSkip (void))); connect (iocSetter, SIGNAL (activated (const QString &)), this, SLOT (fax_setIOC (const QString &))); connect (modeSetter, SIGNAL (activated (const QString &)), this, SLOT (fax_setMode (const QString &))); connect (startSetter, SIGNAL (valueChanged (int)), this, SLOT (fax_setstartFreq (int))); connect (stopSetter, SIGNAL (valueChanged (int)), this, SLOT (fax_setstopFreq (int))); connect (carrierSetter, SIGNAL (valueChanged (int)), this, SLOT (fax_setCarrier (int))); connect (deviationSetter, SIGNAL (valueChanged (int)), this, SLOT (fax_setDeviation (int))); connect (lpmSetter, SIGNAL (valueChanged (int)), this, SLOT (fax_setLPM (int))); connect (phaseSetter, SIGNAL (activated (const QString &)), this, SLOT (fax_setPhase (const QString &))); connect (resetButton, SIGNAL (clicked (void)), this, SLOT (reset (void))); connect (saveButton, SIGNAL (clicked (void)), this, SLOT (fax_setsavingonDone (void))); connect (faxContainer, SIGNAL (fax_Clicked (int, int)), this, SLOT (fax_setClicked (int, int))); connect (autoContinueButton, SIGNAL (clicked (void)), this, SLOT (fax_setautoContinue (void))); h = s -> value ("fax_modeSetter", "FM"). toString (); k = modeSetter -> findText (h); if (k != -1) modeSetter -> setCurrentIndex (k); h = s -> value ("fax_phaseSetter", "phase"). toString (); k = phaseSetter -> findText (h); if (k != -1) phaseSetter -> setCurrentIndex (k); k = s -> value ("fax_deviationSetter", 400). toInt (); deviationSetter -> setValue (k); s -> endGroup (); }
/* * fax_setSkip is called through a signal * from the GUI */ void faxDecoder::fax_setSkip (void) { double pos; set_autoContinue (false); switch (faxState) { case APTSTART: faxState = FAX_PHASING; lpm = 120; lpmSum = 0; currPhaseLength = 0; phaseLines = 0; whiteLength = 0; whiteSide = currentValue >= 128 ? true : false; showState -> setText (QString ("Phasing")); currentSampleIndex = 0; theImage -> clear (); break; case FAX_PHASING: faxState = FAX_IMAGING; lpm = 120; pos = fmod ((double)currentSampleIndex, (double)theRate * 60 / lpm); pos /= theRate * 60.0 / lpm; currentColumn = (int) pos * numberofColums; pixelValue = 0; pixelSamples = 0; lastRow = 100; showState -> setText (QString ("Imaging")); break; case FAX_IMAGING: faxState = FAX_DONE; rawData. resize (currentSampleIndex); showState -> setText (QString ("Done")); fax_displayImage (theImage -> getImage (), 0, faxColor == FAX_COLOR ? lastRow / 3 : lastRow); if (savingRequested) { fax_saveFile (theImage -> getImage (), autoContinue); set_savingRequested (false); } break; default: // cannot happen case FAX_DONE: // reset everything faxState = APTSTART; aptCount = 0; apt_upCrossings = 0; whiteSide = false; pixelValue = 0; pixelSamples = 0; currentSampleIndex = 0; theImage -> clear (); rawData. resize (1024 * 1024); fax_displayImage (theImage -> getImage (), 0, faxColor == FAX_COLOR ? lastRow / 3 : lastRow); showState -> setText (QString ("APTSTART")); set_savingRequested (false); break; } }
void faxDecoder::doDecode (DSPCOMPLEX z) { int16_t sampleValue; // // for the sound: outputSample (real (z), imag (z)); // // When we are in autoContinue mode, we just wait at least for // 30 seconds after detecting the FAX_DONE before resetting if (faxState == FAX_DONE) { if (autoContinue && delayCounter ++ > theRate * 30) { reset (); // will a.o set the state delayCounter = 0; } else return; } z = z * localOscillator -> nextValue (carrier); z = faxLowPass -> Pass (z); sampleValue = myDemodulator -> demodulate (z); if (phaseInvers) sampleValue = 256 - sampleValue; if (faxColor == FAX_BLACKWHITE) sampleValue = isWhite (sampleValue) ? 255 : 0; fax_oldz = z; currentValue = sampleValue; // We count the number of times the decoded values // goes up from black to white. If in a period of half a second // (i.e. we had theRate / 2 samples), the number // of upCrossings is aptStartFreq / 2, we have a start // if the number is aptStopFreq and we are // not DONE or APT_START then we finish the transmission if (we_are_Black && realWhite (sampleValue)) { whiteSide = true; apt_upCrossings ++; } else if (whiteSide && realBlack (sampleValue)) whiteSide = false; // if we have samples for about half a second of samples, // check the frequency // to see whether we are ready for phasing or for exit if (++aptCount >= theRate / 2) { int16_t freq = 2 * apt_upCrossings; aptFreq -> display (freq); aptCount = 0; apt_upCrossings = 0; if ((faxState == APTSTART) && inRange (freq, aptStartFreq)) { faxState = FAX_PHASING; // carrier -= freq - aptStartFreq; initPhasing (); return; } if (((faxState & (FAX_PHASING | FAX_IMAGING)) != 0) && inRange (freq, aptStopFreq)) { rawData. resize (currentSampleIndex); faxState = FAX_DONE; showState -> setText (QString ("Done")); fax_displayImage (theImage -> getImage (), 0, faxColor == FAX_COLOR ? lastRow / 3 : lastRow); if (savingRequested || autoContinue) { fax_saveFile (theImage -> getImage (), autoContinue); set_savingRequested (false); } return; } // // otherwise: fall through } if (faxState == FAX_PHASING) addtoPhasing (sampleValue); if ((faxState == FAX_PHASING) || (faxState == FAX_IMAGING)) if (lpm > 0) // just a precaution addtoImage (sampleValue); }
bool QLandmarkFileHandlerLmx::readAddressInfo(QLandmark &landmark) { /* <xsd:complexType name="addressInfoType"> <xsd:all> <xsd:element name="country" type="xsd:string" minOccurs="0" /> <xsd:element name="countryCode" minOccurs="0"> <xsd:simpleType> <xsd:restriction base="xsd:token"> <xsd:length value="2"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="state" type="xsd:string" minOccurs="0" /> <xsd:element name="county" type="xsd:string" minOccurs="0" /> <xsd:element name="city" type="xsd:string" minOccurs="0" /> <xsd:element name="district" type="xsd:string" minOccurs="0" /> <xsd:element name="postalCode" type="xsd:string" minOccurs="0" /> <xsd:element name="crossing1" type="xsd:string" minOccurs="0" /> <xsd:element name="crossing2" type="xsd:string" minOccurs="0" /> <xsd:element name="street" type="xsd:string" minOccurs="0" /> <xsd:element name="buildingName" type="xsd:string" minOccurs="0" /> <xsd:element name="buildingZone" type="xsd:string" minOccurs="0" /> <xsd:element name="buildingFloor" type="xsd:string" minOccurs="0" /> <xsd:element name="buildingRoom" type="xsd:string" minOccurs="0" /> <xsd:element name="extension" type="xsd:string" minOccurs="0" /> <xsd:element name="phoneNumber" type="xsd:string" minOccurs="0" /> </xsd:all> </xsd:complexType> */ Q_ASSERT(m_reader->isStartElement() && (m_reader->name() == "addressInfo")); QHash<QString, int> counts; counts["country"] = 0; counts["countryCode"] = 0; counts["state"] = 0; counts["county"] = 0; counts["city"] = 0; counts["district"] = 0; counts["postalCode"] = 0; counts["crossing1"] = 0; counts["crossing2"] = 0; counts["street"] = 0; counts["buildingName"] = 0; counts["buildingZone"] = 0; counts["buildingFloor"] = 0; counts["buildingRoom"] = 0; counts["extension"] = 0; counts["phoneNumber"] = 0; QGeoAddress address; while (m_reader->readNextStartElement()) { QString name = m_reader->name().toString(); if (counts.keys().contains(name)) { if (counts.value(name) == 1) { m_reader->raiseError(QString("The element \"addressInfo\" did not expect more then one occurrence of the child element named \"%1\".").arg(m_reader->name().toString())); return false; } counts[name] = 1; if (name == "county") { address.setCounty(m_reader->readElementText()); } else if (name == "country") { address.setCountry(m_reader->readElementText()); } else if (name == "state") { address.setState(m_reader->readElementText()); } else if (name == "city") { address.setCity(m_reader->readElementText()); } else if (name == "district") { address.setDistrict(m_reader->readElementText()); } else if (name == "postalCode") { address.setPostcode(m_reader->readElementText()); } else if (name == "street") { QString street = m_reader->readElementText(); address.setStreet(street); } else if (name == "phoneNumber") { landmark.setPhoneNumber(m_reader->readElementText()); } else { m_reader->skipCurrentElement(); } } else { m_reader->raiseError(QString("The element \"addressInfo\" did not expect a child element named \"%1\".").arg(m_reader->name().toString())); return false; } } landmark.setAddress(address); return true; }
bool QLandmarkFileHandlerLmx::readLandmark(QLandmark &landmark) { /* <xsd:complexType name="landmarkType"> <xsd:sequence> <xsd:element name="name" type="xsd:string" minOccurs="0" /> <xsd:element name="description" type="xsd:string" minOccurs="0" /> <xsd:element name="coordinates" type="coordinatesType" minOccurs="0" /> <xsd:element name="coverageRadius" minOccurs="0"> <xsd:simpleType> <xsd:restriction base="xsd:float"> <xsd:minInclusive value="0"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="addressInfo" type="addressInfoType" minOccurs="0" /> <xsd:element name="mediaLink" type="mediaLinkType" minOccurs="0" maxOccurs="unbounded" /> <xsd:element name="category" type="categoryType" minOccurs="0" maxOccurs="unbounded" /> </xsd:sequence> </xsd:complexType> */ if(m_cancel && (*m_cancel) == true) { m_errorCode = QLandmarkManager::CancelError; m_error = "Import of lmx file was canceled"; return false; } Q_ASSERT(m_reader->isStartElement() && (m_reader->name() == "landmark")); m_landmarkCategoryNames.append(QStringList()); if (!m_reader->readNextStartElement()) return true; if (m_reader->name() == "name") { landmark.setName(m_reader->readElementText()); if (!m_reader->readNextStartElement()) return true; } if (m_reader->name() == "description") { landmark.setDescription(m_reader->readElementText()); if (!m_reader->readNextStartElement()) return true; } if (m_reader->name() == "coordinates") { if (!readCoordinates(landmark)) return false; if (!m_reader->readNextStartElement()) return true; } if (m_reader->name() == "coverageRadius") { bool ok = false; QString s = m_reader->readElementText(); if ((s == "INF") || (s == "-INF") || (s == "NaN")) { m_reader->raiseError(QString("The element \"coverageRadius\" expected a value convertable to type real (value was \"%1\").").arg(s)); return false; } qreal rad = (qreal)(s.toDouble(&ok)); if (!ok) { m_reader->raiseError(QString("The element \"coverageRadius\" expected a value convertable to type real (value was \"%1\").").arg(s)); return false; } if (rad < 0.0) { m_reader->raiseError(QString("The element \"coverageRadius\" is expected to have a non-negative value (value was \"%1\").").arg(s)); return false; } landmark.setRadius(rad); if (!m_reader->readNextStartElement()) return true; } if (m_reader->name() == "addressInfo") { if (!readAddressInfo(landmark)) return false; if (!m_reader->readNextStartElement()) return true; } // TODO need to document the fact that only the first link is read // and the others are ignored bool mediaLinkRead = false; while (m_reader->name() == "mediaLink") { if (!mediaLinkRead) { mediaLinkRead = true; if (!readMediaLink(landmark)) return false; } if (!m_reader->readNextStartElement()) return true; } QStringList categoryNames; while (m_reader->name() == "category") { QString name; if (!readCategory(name)) return false; categoryNames << name; if (!m_reader->readNextStartElement()) { m_landmarkCategoryNames.last() = categoryNames; return true; } } m_reader->raiseError(QString("The element \"landmark\" did not expect a child element named \"%1\" at this point (unknown child element or child element out of order).").arg(m_reader->name().toString())); return false; }