コード例 #1
0
AbstractInterface::AbstractInterface(const QString &busName,
        const QString &path, const QLatin1String &interface,
        const QDBusConnection &dbusConnection, QObject *parent)
    : QDBusAbstractInterface(busName, path, interface.latin1(), dbusConnection, parent),
      mPriv(new Private)
{
}
コード例 #2
0
AbstractInterface::AbstractInterface(DBusProxy *parent, const QLatin1String &interface)
    : QDBusAbstractInterface(parent->busName(), parent->objectPath(),
            interface.latin1(), parent->dbusConnection(), parent),
      mPriv(new Private)
{
    connect(parent, SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)),
            this, SLOT(invalidate(Tp::DBusProxy*,QString,QString)));
}
コード例 #3
0
void CMakeCbpParser::parseBuildTargetOption()
{
    if (attributes().hasAttribute(QLatin1String("output"))) {
        m_buildTarget.executable = attributes().value(QLatin1String("output")).toString();
        CMakeTool *tool = CMakeKitInformation::cmakeTool(m_kit);
        if (tool)
            m_buildTarget.executable = tool->mapAllPaths(m_kit, m_buildTarget.executable);
    } else if (attributes().hasAttribute(QLatin1String("type"))) {
        const QStringRef value = attributes().value(QLatin1String("type"));
        if (value == QLatin1String("2") || value == QLatin1String("3"))
            m_buildTarget.targetType = TargetType(value.toInt());
    } else if (attributes().hasAttribute(QLatin1String("working_dir"))) {
        m_buildTarget.workingDirectory = attributes().value(QLatin1String("working_dir")).toString();

        QFile cmakeSourceInfoFile(m_buildTarget.workingDirectory
                                  + QStringLiteral("/CMakeFiles/CMakeDirectoryInformation.cmake"));
        if (cmakeSourceInfoFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
            QTextStream stream(&cmakeSourceInfoFile);
            const QLatin1String searchSource("SET(CMAKE_RELATIVE_PATH_TOP_SOURCE \"");
            while (!stream.atEnd()) {
                const QString lineTopSource = stream.readLine().trimmed();
                if (lineTopSource.startsWith(searchSource)) {
                    m_buildTarget.sourceDirectory = lineTopSource.mid(searchSource.size());
                    m_buildTarget.sourceDirectory.chop(2); // cut off ")
                    break;
                }
            }
        }

        if (m_buildTarget.sourceDirectory.isEmpty()) {
            QDir dir(m_buildDirectory);
            const QString relative = dir.relativeFilePath(m_buildTarget.workingDirectory);
            m_buildTarget.sourceDirectory
                    = FileName::fromString(m_sourceDirectory).appendPath(relative).toString();
        }
    }
    while (!atEnd()) {
        readNext();
        if (isEndElement())
            return;
        else if (isStartElement())
            parseUnknownElement();
    }
}
コード例 #4
0
ファイル: stillimage.cpp プロジェクト: aportale/qtorials
AVSValue __cdecl StillImage::CreateElements(AVSValue args, void* user_data, IScriptEnvironment* env)
{
    Q_UNUSED(user_data)
    const PClip background = args[0].AsClip();
    const VideoInfo backgroundVI = background->GetVideoInfo();
    const AVSValue &elementValues = args[1];
    QStringList elements;
    for (int i = 0; i < elementValues.ArraySize(); ++i) {
        const QLatin1String element(elementValues[i].AsString());
        if (Filters::elementAvailable(element))
            env->ThrowError("QtAviSynthElements: Invalid element '%s'.", element.latin1());
        elements.append(element);
    }
    QImage image(backgroundVI.width, backgroundVI.height, QImage::Format_ARGB32);
    image.fill(Tools::transparentColor);
    QPainter p(&image);
    Filters::paintElements(&p, elements, image.rect());
    const PClip elementsClip = new StillImage(backgroundVI, image, env);
    return new RgbOverlay(background, elementsClip, env);
}
コード例 #5
0
bool parseIntOption(const QString &parameter,const QLatin1String &option,
                    IntType minimumValue, IntType maximumValue, IntType *target)
{
    const int valueLength = parameter.size() - option.size() - 1;
    if (valueLength < 1 || !parameter.startsWith(option) || parameter.at(option.size()) != QLatin1Char('='))
        return false;
    bool ok;
    const QStringRef valueRef = parameter.rightRef(valueLength);
    const int value = valueRef.toInt(&ok);
    if (ok) {
        if (value >= minimumValue && value <= maximumValue)
            *target = static_cast<IntType>(value);
        else {
            qWarning() << "Value" << value << "for option" << option << "out of range"
                << minimumValue << ".." << maximumValue;
        }
    } else {
        qWarning() << "Invalid value" << valueRef << "for option" << option;
    }
    return true;
}
コード例 #6
0
Telegram::Peer Telegram::Peer::fromString(const QString &string)
{
    // Possible schemes: user1234, chat1234, channel1234
    if (string.length() < 5) {
        return Peer();
    }
    bool ok = true;
    switch (string.at(0).toLatin1()) {
    case 'u': // user
        if (string.startsWith(c_userPrefix)) {
            uint userId = string.midRef(c_userPrefix.size()).toUInt(&ok);
            if (ok) {
                return Peer::fromUserId(userId);
            }
        }
        break;
    case 'c': // chat or channel
        if (string.at(3).toLatin1() == 't') {
            if (string.startsWith(c_chatPrefix)) {
                uint chatId = string.midRef(c_chatPrefix.size()).toUInt(&ok);
                if (ok) {
                    return Peer::fromChatId(chatId);
                }
            }
        } else {
            if (string.startsWith(c_channelPrefix)) {
                uint channelId = string.midRef(c_channelPrefix.size()).toUInt(&ok);
                if (ok) {
                    return Peer::fromChannelId(channelId);
                }
            }
        }
        break;
    default:
        break;
    }
    return Peer();
}
コード例 #7
0
ファイル: proitems.cpp プロジェクト: anchowee/QtCreator
bool ProString::operator==(const QLatin1String &other) const
{
    const ushort *uc = (ushort *)m_string.constData() + m_offset;
    const ushort *e = uc + m_length;
    const uchar *c = (uchar *)other.latin1();

    if (!c)
        return isEmpty();

    while (*c) {
        if (uc == e || *uc != *c)
            return false;
        ++uc;
        ++c;
    }
    return (uc == e);
}
コード例 #8
0
bool checkQml(QLatin1String qml)
{
#ifdef Q_OS_SAILFISH // this check segfaults within libqt5qml on sailfish
    return true;
#endif
    QQmlEngine engine;
    QQmlComponent component(&engine);
    component.setData(qml.latin1(), QUrl());
//    QScopedPointer<QQuickItem> item = qobject_cast<QQuickItem *>(component.create());
    QScopedPointer<QQuickItem> item(qobject_cast<QQuickItem *>(component.create()));

    if (item) {
        // Components plugin seems to be available
        qDebug() << "YAY " << qml;
        return true;
    }
    else {
        // Something is wrong, at least output errors
        qDebug() << "FAIL " << component.errors();
    }
    return false;
}
コード例 #9
0
bool MStyleSheetAttribute::writeAttribute(MUniqueStringCache::Index filename,
        MStyle *style,
        const QMetaProperty &property,
        M::Orientation orientation) const
{
    // first check if the attribute is cached orientation independent, if not found
    // check for the given orientation
    QVariant cachedVariant = variantCache[M::Landscape + 1][value][property.userType()];
    if (cachedVariant.isValid()) {
        return property.write(style, cachedVariant);
    } else {
        cachedVariant = variantCache[orientation][value][property.userType()];
        if (cachedVariant.isValid()) {
            style->setOrientationDependent(true);
            return property.write(style, cachedVariant);
        }
    }

    bool conversionOK = false;
    // most types are the same in landscape and portrait
    CacheOrientationFlags cacheOrientation = CacheOrientationFlags(PortraitFlag | LandscapeFlag);

    QLatin1String vs = MStyleSheetParser::stringCacheWithoutReverseLookup()->indexToString(value);
    QByteArray valueString = QByteArray::fromRawData(vs.latin1(), strlen(vs.latin1()));

    const int attributeType = property.userType();
    if (attributeType == QMetaType::Bool) {
        bool result = booleanFromString(valueString, &conversionOK);
        if (conversionOK) {
            return fillProperty(property, style, cacheOrientation, result);
        }
    } else if (attributeType == QMetaType::Int) {
        int integer = attributeToInt(valueString, &conversionOK);
        if (conversionOK) {
            return fillProperty(property, style, cacheOrientation, integer);
        }
    } else if (attributeType == QMetaType::QColor) {
        if(valueString == "none")
            return fillProperty(property, style, cacheOrientation, QColor());

        QColor color = colorFromString(valueString, &conversionOK);
        if (conversionOK) {
            return fillProperty(property, style, cacheOrientation, color);
        }
    } else if (attributeType == QMetaType::QReal) {
        qreal real = attributeToFloat(valueString, &conversionOK);
        if (conversionOK) {
            return fillProperty(property, style, cacheOrientation, real);
        }
    } else if (attributeType == qMetaTypeId<const QPixmap*>()) {
        if(valueString == "none")
            return fillProperty(property, style, cacheOrientation, qVariantFromValue((const QPixmap *) NULL));

        //"image: image_id;"
        //"image: image_id 64px 64px;"
        //"image: "image id";"
        //"image: "image id" 64px 64px;"

        QList<QByteArray> list;
        if (valueString.startsWith('\"')) {
            //parse name inside quotes
            int idx = valueString.indexOf('\"', 1);
            if (idx != -1) {
                //get quoted image_id
                QByteArray imageid = valueString.mid(1, idx - 1);

                //split rest of the parameters
                QByteArray values = valueString.mid(idx + 1).trimmed();
                list = values.split(' ');
                list.removeAll("");

                //insert image_id as first parameter
                list.insert(0, imageid);
            }
        } else {
            //no quotes, just split the parameters
            list = valueString.split(' ');
            list.removeAll("");
        }

        //only image_id
        if (list.size() == 1) {
            const QPixmap *pixmap = MTheme::pixmap(list.at(0));
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(pixmap), false);
        }
        //image_id + width + height
        else if (list.size() == 3) {
            int width = attributeToInt(list.at(1), &conversionOK, WidthAttribute, orientation, &cacheOrientation);
            int height = attributeToInt(list.at(2), &conversionOK, HeightAttribute, orientation, &cacheOrientation);
            const QPixmap *pixmap = MTheme::pixmap(list.at(0), QSize(width, height));
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(pixmap), false);
        }
        //no parameters
        else if (list.size() == 0) {
            //init null pixmap which is ok if someone does not want to use it
            return fillProperty(property, style, cacheOrientation, qVariantFromValue((const QPixmap *) NULL));
        }
    } else if (attributeType == qMetaTypeId<const MScalableImage*>() || attributeType == qMetaTypeId<MBackgroundTiles>()) {
        //"background: image_id left right top bottom;"
        //"background: image_id;"
        //"background: "image id" left right top bottom;"
        //"background: "image id";"

        QList<QByteArray> list;
        if (valueString.startsWith('\"')) {
            //parse name inside quotes
            int idx = valueString.indexOf('\"', 1);
            if (idx != -1) {
                //get quoted image_id
                QByteArray imageid = valueString.mid(1, idx - 1);

                //split rest of the parameters
                QByteArray values = valueString.mid(idx + 1).trimmed();
                list = values.split(' ');
                list.removeAll("");
                //insert image_id as first parameter
                list.insert(0, imageid);
            }
        } else {
            //no quotes, just split the parameters
            list = valueString.split(' ');
            list.removeAll("");
        }

        //no parameters
        if (valueString.isEmpty() || valueString == "none") {
            //init null image which is ok if someone does not want to use it
            if(attributeType == qMetaTypeId<const MScalableImage*>())
                return fillProperty(property, style, cacheOrientation, qVariantFromValue((const MScalableImage *) NULL));
            else
                return fillProperty(property, style, cacheOrientation, QVariant::fromValue(MBackgroundTiles()), false);
        }
        //only image_id
        else if (list.size() == 1) {
            if(attributeType == qMetaTypeId<const MScalableImage*>()) {
                const MScalableImage *image = MTheme::scalableImage(list.at(0), 0, 0, 0, 0);
                return fillProperty(property, style, cacheOrientation, qVariantFromValue(image), false);
            } else {
                return fillProperty(property, style, cacheOrientation, QVariant::fromValue(MBackgroundTiles(list.at(0), 0,0,0,0)), false);
            }
        }
        //image_id + border width paramaters
        else if (list.size() == 5) {
            //image_id and the border parameters
            if(attributeType == qMetaTypeId<const MScalableImage*>()) {
                const MScalableImage *image = MTheme::scalableImage(list.at(0),
                                                attributeToInt(list.at(1), &conversionOK),
                                                attributeToInt(list.at(2), &conversionOK),
                                                attributeToInt(list.at(3), &conversionOK),
                                                attributeToInt(list.at(4), &conversionOK));
                return fillProperty(property, style, cacheOrientation, qVariantFromValue(image), false);
            } else {
                return fillProperty(property, style, cacheOrientation, QVariant::fromValue(MBackgroundTiles(list.at(0),
                                                                attributeToInt(list.at(1), &conversionOK),
                                                                attributeToInt(list.at(2), &conversionOK),
                                                                attributeToInt(list.at(3), &conversionOK),
                                                                attributeToInt(list.at(4), &conversionOK))), false);
            }
        }
    } else if (attributeType == QMetaType::QSize || attributeType == QMetaType::QSizeF) {
        //size: 25px 25px;

        //just split into pieces and create QSize or QSizeF depending on the attributeType
        QList<QByteArray> list = valueString.split(' ');
        list.removeAll("");
        if (list.size() == 2) {
            if (attributeType == QMetaType::QSize) {
                int width = attributeToInt(list.at(0), &conversionOK, WidthAttribute, orientation, &cacheOrientation);
                int height = attributeToInt(list.at(1), &conversionOK, HeightAttribute, orientation, &cacheOrientation);
                return fillProperty(property, style, cacheOrientation, QSize(width, height));
            } else {
                qreal width = attributeToFloat(list.at(0), &conversionOK, WidthAttribute, orientation, &cacheOrientation);
                qreal height = attributeToFloat(list.at(1), &conversionOK, HeightAttribute, orientation, &cacheOrientation);
                return fillProperty(property, style, cacheOrientation, QSizeF(width, height));
            }
        }
    } else if (attributeType == QMetaType::QPoint || attributeType == QMetaType::QPointF) {
        //"point: 256px 123px;

        //just split into pieces and create QPoint or QPointF depending on the attributeType
        QList<QByteArray> list = valueString.split(' ');
        list.removeAll("");
        if (list.size() == 2) {
            if (attributeType == QMetaType::QPoint) {
                int x = attributeToInt(list.at(0), &conversionOK, WidthAttribute, orientation, &cacheOrientation);
                int y = attributeToInt(list.at(1), &conversionOK, HeightAttribute, orientation, &cacheOrientation);
                return fillProperty(property, style, cacheOrientation, QPoint(x, y));
            } else {
                qreal x = attributeToFloat(list.at(0), &conversionOK, WidthAttribute, orientation, &cacheOrientation);
                qreal y = attributeToFloat(list.at(1), &conversionOK, HeightAttribute, orientation, &cacheOrientation);
                return fillProperty(property, style, cacheOrientation, QPointF(x, y));
            }
        }
    } else if (attributeType == QMetaType::QFont) {
        QFont font = fontFromString(valueString, &conversionOK);
        if (conversionOK) {
            return fillProperty(property, style, cacheOrientation, font);
        }
    } else if (attributeType == QMetaType::QString) {
        if (valueString.length() >= 2) {
            if ((valueString.at(0) == 0x22) && (valueString.at(valueString.length()-1) == 0x22)) {
                return fillProperty(property, style, cacheOrientation, QString(valueString.mid(1, valueString.length() - 2)));
            }
        } else if (valueString.length() == 0) {
            return fillProperty(property, style, cacheOrientation, QString());
        }
    } else if (attributeType == QMetaType::QChar) {
        if (valueString.length() == 3) {
            if ((valueString.at(0) == '\'') && (valueString.at(2) == '\'')) {
                return fillProperty(property, style, cacheOrientation, static_cast<QChar>(valueString.at(1)));
            }
        }
    } else if (attributeType == qMetaTypeId<Qt::Alignment>()) {
        if (DataTypeConverter.ALIGNMENTS.contains(valueString)) {
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.ALIGNMENTS[valueString]));
        }
    } else if (attributeType == qMetaTypeId<Qt::Orientation>()) {
        if (DataTypeConverter.ORIENTATIONS.contains(valueString)) {
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.ORIENTATIONS[valueString]));
        }
    } else if (attributeType == qMetaTypeId<QTextCharFormat::UnderlineStyle>()) {
        if (DataTypeConverter.UNDERLINESTYLES.contains(valueString)) {
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.UNDERLINESTYLES[valueString]));
        }
    } else if (attributeType == qMetaTypeId<Qt::PenStyle>()) {
        if (DataTypeConverter.PENSTYLES.contains(valueString)) {
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.PENSTYLES[valueString]));
        }
    } else if (attributeType == qMetaTypeId<Qt::Axis>()) {
        if (DataTypeConverter.AXES.contains(valueString)) {
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.AXES[valueString]));
        }
    } else if (attributeType == qMetaTypeId<MFeedback>()) {
        MFeedback feedback(valueString);
        return fillProperty(property, style, cacheOrientation, qVariantFromValue(feedback));
    } else if (attributeType == QMetaType::QEasingCurve) {
        QEasingCurve curve;
        // curve type
        QList<QByteArray> list = valueString.split(',');
        if (list.size() > 0) {
            if (DataTypeConverter.EASINGCURVETYPES.contains(list.at(0))) {
                int type = DataTypeConverter.EASINGCURVETYPES[list.at(0)];
                if (type < FirstCustomType)
                    curve.setType(static_cast<QEasingCurve::Type>(type));
                else if (type == OvershotBezier)
                    curve = MOvershotBezierEasingCurve();
                // curve amplitude
                if (list.size() > 1) {
                    curve.setAmplitude((qreal) list.at(1).toDouble());
                    // curve overshoot
                    if (list.size() > 2) {
                        curve.setOvershoot((qreal) list.at(2).toDouble());
                        // curve period
                        if (list.size() > 3) {
                            curve.setPeriod((qreal) list.at(3).toDouble());
                        }
                    }
                }
                return fillProperty(property, style, cacheOrientation, qVariantFromValue(curve));
            }
        }
    } else if (attributeType == qMetaTypeId<QTextOption::WrapMode>()) {
        if (DataTypeConverter.WRAPMODES.contains(valueString)) {
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.WRAPMODES[valueString]));
        }
    }

    MStyleSheetParser::outputParseError(MStyleSheetParser::stringCacheWithReverseLookup()->indexToString(filename), "Not a valid attribute(" + QLatin1String(property.typeName()) + "): " + MStyleSheetParser::stringCacheWithoutReverseLookup()->indexToString(name) + " : " + valueString, MStyleSheetParser::getLineNum(MStyleSheetParser::stringCacheWithReverseLookup()->indexToString(filename), position));
    return false;
}
コード例 #10
0
 bool latreffunc(const QLatin1String& lat) {return qstrcmp(lat.latin1(), "alphabet soup") == 0;}
コード例 #11
0
 bool latfunc(QLatin1String lat) {return qstrcmp(lat.latin1(), "alphabet soup") == 0;}
コード例 #12
0
bool OsmAnd::WorldRegions_P::loadWorldRegions(
    QHash< QString, std::shared_ptr<const WorldRegion> >& outRegions,
    const IQueryController* const controller) const
{
    const std::shared_ptr<QIODevice> ocbfFile(new QFile(owner->ocbfFileName));
    if (!ocbfFile->open(QIODevice::ReadOnly))
        return false;

    const std::shared_ptr<ObfReader> ocbfReader(new ObfReader(ocbfFile));
    const auto& obfInfo = ocbfReader->obtainInfo();
    if (!obfInfo)
    {
        ocbfFile->close();

        return false;
    }

    for(const auto& mapSection : constOf(obfInfo->mapSections))
    {
        // Check if request is aborted
        if (controller && controller->isAborted())
        {
            ocbfFile->close();

            return false;
        }

        bool idsCaptured = false;
        uint32_t nameId = std::numeric_limits<uint32_t>::max();
        uint32_t idId = std::numeric_limits<uint32_t>::max();
        uint32_t downloadNameId = std::numeric_limits<uint32_t>::max();
        uint32_t regionPrefixId = std::numeric_limits<uint32_t>::max();
        uint32_t regionSuffixId = std::numeric_limits<uint32_t>::max();
        const QLatin1String localizedNameTagPrefix("name:");
        const auto localizedNameTagPrefixLen = localizedNameTagPrefix.size();
        const auto worldRegionsCollector =
            [&outRegions, &idsCaptured, &nameId, &idId, &downloadNameId, &regionPrefixId, &regionSuffixId, localizedNameTagPrefix, localizedNameTagPrefixLen]
            (const std::shared_ptr<const OsmAnd::Model::BinaryMapObject>& worldRegionMapObject) -> bool
            {
                const auto& rules = worldRegionMapObject->section->encodingDecodingRules;
                if (!idsCaptured)
                {
                    nameId = rules->name_encodingRuleId;

                    QHash< QString, QHash<QString, uint32_t> >::const_iterator citRule;
                    if ((citRule = rules->encodingRuleIds.constFind(QLatin1String("key_name"))) != rules->encodingRuleIds.cend())
                        idId = citRule->constBegin().value();
                    if ((citRule = rules->encodingRuleIds.constFind(QLatin1String("download_name"))) != rules->encodingRuleIds.cend())
                        downloadNameId = citRule->constBegin().value();
                    if ((citRule = rules->encodingRuleIds.constFind(QLatin1String("region_prefix"))) != rules->encodingRuleIds.cend())
                        regionPrefixId = citRule->constBegin().value();
                    if ((citRule = rules->encodingRuleIds.constFind(QLatin1String("region_suffix"))) != rules->encodingRuleIds.cend())
                        regionSuffixId = citRule->constBegin().value();

                    idsCaptured = true;
                }

                QString name;
                QString id;
                QString downloadName;
                QString regionPrefix;
                QString regionSuffix;
                QHash<QString, QString> localizedNames;
                for(const auto& localizedNameEntry : rangeOf(constOf(worldRegionMapObject->names)))
                {
                    const auto ruleId = localizedNameEntry.key();
                    if (ruleId == idId)
                    {
                        id = localizedNameEntry.value().toLower();
                        continue;
                    }
                    else if (ruleId == nameId)
                    {
                        name = localizedNameEntry.value();
                        continue;
                    }
                    else if (ruleId == downloadNameId)
                    {
                        downloadName = localizedNameEntry.value().toLower();
                        continue;
                    }
                    else if (ruleId == regionPrefixId)
                    {
                        regionPrefix = localizedNameEntry.value().toLower();
                        continue;
                    }
                    else if (ruleId == regionSuffixId)
                    {
                        regionSuffix = localizedNameEntry.value().toLower();
                        continue;
                    }

                    const auto& nameTag = rules->decodingRules[localizedNameEntry.key()].tag;
                    if (!nameTag.startsWith(localizedNameTagPrefix))
                        continue;
                    const auto languageId = nameTag.mid(localizedNameTagPrefixLen).toLower();
                    localizedNames.insert(languageId, localizedNameEntry.value());
                }

                QString parentId = regionSuffix;
                if (!regionPrefix.isEmpty())
                {
                    if (!parentId.isEmpty())
                        parentId.prepend(regionPrefix + QLatin1String("_"));
                    else
                        parentId = regionPrefix;
                }

                // Build up full id
                if (!regionPrefix.isEmpty())
                    id.prepend(regionPrefix + QLatin1String("_"));
                if (!regionSuffix.isEmpty())
                    id.append(QLatin1String("_") + regionSuffix);

                std::shared_ptr<const WorldRegion> newRegion(new WorldRegion(id, downloadName, name, localizedNames, parentId));

                outRegions.insert(id, qMove(newRegion));

                return false;
            };

        // Read objects from each map section
        OsmAnd::ObfMapSectionReader::loadMapObjects(
            ocbfReader,
            mapSection,
            mapSection->levels.first()->minZoom,
            nullptr, // Query entire world
            nullptr, // No need for map objects to be stored
            nullptr, // Foundation is not needed
            nullptr, // No filtering by ID
            worldRegionsCollector,
            controller);
    }

    ocbfFile->close();
    return true;
}
コード例 #13
0
QString bytesToUtf8(QLatin1String bytes) {
	return QString::fromUtf8(bytes.data(), bytes.size());
}
コード例 #14
0
static bool appendBsonValue(bson_t *bson, const QString &key, const QVariant &value)
{
    const QLatin1String oidkey("_id");
    bool ok = true;
    int type = value.type();

    // _id
    if (key == oidkey) {
        QByteArray oidVal = value.toByteArray();
        if (oidVal.length() == 24) {
            // ObjectId
            bson_oid_t oid;
            bson_oid_init_from_string(&oid, oidVal.data());
            BSON_APPEND_OID(bson, oidkey.latin1(), &oid);
        } else {
            int id = value.toInt(&ok);
            if (ok) {
                BSON_APPEND_INT32(bson, oidkey.latin1(), id);
            } else {
                BSON_APPEND_UTF8(bson, oidkey.latin1(), value.toString().toUtf8().data());
            }
        }
        return true;
    }

    switch (type) {
    case QVariant::Int:
        BSON_APPEND_INT32(bson, qPrintable(key), value.toInt(&ok));
        break;

    case QVariant::String:
        BSON_APPEND_UTF8(bson, qPrintable(key), value.toString().toUtf8().data());
        break;

    case QVariant::LongLong:
        BSON_APPEND_INT64(bson, qPrintable(key), value.toLongLong(&ok));
        break;

    case QVariant::Map:
        BSON_APPEND_DOCUMENT(bson, qPrintable(key), (const bson_t *)TBson::toBson(value.toMap()).constData());
        break;

    case QVariant::Double:
        BSON_APPEND_DOUBLE(bson, qPrintable(key), value.toDouble(&ok));
        break;

    case QVariant::Bool:
        BSON_APPEND_BOOL(bson, qPrintable(key), value.toBool());
        break;

    case QVariant::DateTime: {
#if QT_VERSION >= 0x040700
        BSON_APPEND_DATE_TIME(bson, qPrintable(key), value.toDateTime().toMSecsSinceEpoch());
#else
        QDateTime utcDate = value.toDateTime().toUTC();
        qint64 ms = utcDate.time().msec();
        qint64 tm = utcDate.toTime_t() * 1000LL;
        if (ms > 0) {
          tm += ms;
        }
        BSON_APPEND_DATE_TIME(bson, qPrintable(key), tm);
#endif
        break; }

    case QVariant::ByteArray: {
        QByteArray ba = value.toByteArray();
        BSON_APPEND_BINARY(bson, qPrintable(key), BSON_SUBTYPE_BINARY, (uint8_t *)ba.constData(), ba.length());
        break; }

    case QVariant::List:  // FALL THROUGH
    case QVariant::StringList: {
        bson_t child;
        BSON_APPEND_ARRAY_BEGIN(bson, qPrintable(key), &child);

        int i = 0;
        for (auto &var : value.toList()) {
            appendBsonValue(&child, QString::number(i++), var);
        }
        bson_append_array_end(bson, &child);
        break; }

    case QVariant::Invalid:
        BSON_APPEND_UNDEFINED(bson, qPrintable(key));
        break;

    default:
        tError("toBson() failed to convert  name:%s  type:%d", qPrintable(key), type);
        ok = false;
        break;
    }
    return ok;
}