예제 #1
0
int main ()
{
    QHash<int, int> myQHash;
    QHash<int, int> :: const_iterator it;

    myQHash[1] = 500;
    myQHash[2] = 300;
    myQHash[3] = 100;

    it = myQHash.cbegin();
    assert(it.key() != 1);
    assert(it.value() != 500);
    it++;
    assert(it.key() != 2);
    assert(it.value() != 300);
    it++;
    assert(it.key() != 3);
    assert(it.value() != 100);

    // show content:
    for ( it=myQHash.cbegin() ; it != myQHash.cend(); it++ )
        cout << it.key() << " => " << it.value() << endl;

    return 0;
}
void FormGenBagModel::setCompareOperator(const Compare &comparison)
{
    emit layoutAboutToBeChanged(QList<QPersistentModelIndex>(), QAbstractItemModel::VerticalSortHint);

    QHash<int, int> persistentRows;
    {
        auto tmp = persistentIndexList();
        for( const auto &idx: tmp )
            persistentRows.insert(idx.row(), -1);
    }

    mItems.setCompareOperatorGetReorderMap(comparison, &persistentRows);

    {
        QModelIndexList oldList, newList;
        oldList.reserve(persistentRows.size());
        newList.reserve(persistentRows.size());
        for( auto it = persistentRows.cbegin(); it != persistentRows.cend(); ++it ) {
            //changePersistentIndex(index(it.key()), index(it.value()));
            oldList.append(index(it.key()));
            newList.append(index(it.value()));
        }
        changePersistentIndexList(oldList, newList);
    }

    emit layoutChanged(QList<QPersistentModelIndex>(), QAbstractItemModel::VerticalSortHint);
}
예제 #3
0
파일: main.cpp 프로젝트: haugerbr/zeal
void unregisterProtocolHandlers(const QHash<QString, QString> &protocols)
{
    const QString regPath = QStringLiteral("HKEY_CURRENT_USER\\Software\\Classes");
    QScopedPointer<QSettings> reg(new QSettings(regPath, QSettings::NativeFormat));

    for (auto it = protocols.cbegin(); it != protocols.cend(); ++it)
        reg->remove(it.key());
}
예제 #4
0
파일: main.cpp 프로젝트: haugerbr/zeal
void registerProtocolHandlers(const QHash<QString, QString> &protocols, bool force = false)
{
    const QString regPath = QStringLiteral("HKEY_CURRENT_USER\\Software\\Classes");
    QScopedPointer<QSettings> reg(new QSettings(regPath, QSettings::NativeFormat));

    const QStringList groups = reg->childGroups();
    for (auto it = protocols.cbegin(); it != protocols.cend(); ++it) {
        if (force || !groups.contains(it.key()))
            registerProtocolHandler(it.key(), it.value());
    }
}
예제 #5
0
// This function counts how many unique 2x2 16BPP pixel blocks there are in the image.
// If there are <= maxCodes, it puts the unique blocks in 'codebook' and 'indexedImages'
// will contain images that index the 'codebook' vector, resulting in quick "lossless"
// compression, if possible.
// It will keep counting blocks even if the block count exceeds maxCodes for the sole
// purpose of reporting it back to the user.
// Returns number of unique 2x2 16BPP pixel blocks in all images.
static int encodeLossless(const ImageContainer& images, int pixelFormat, QVector<QImage>& indexedImages, QVector<quint64>& codebook, int maxCodes) {
	QHash<quint64, int> uniqueQuads; // Quad <=> index

	for (int i=0; i<images.imageCount(); i++) {
		const QImage& img = images.getByIndex(i);

		// Ignore images smaller than this
		if (img.width() < MIN_MIPMAP_VQ || img.height() < MIN_MIPMAP_VQ)
			continue;

		QImage indexedImage(img.width() / 2, img.height() / 2, QImage::Format_Indexed8);
		indexedImage.setColorCount(256);

		for (int y=0; y<img.height(); y+=2) {
			for (int x=0; x<img.width(); x+=2) {
				QRgb tl = img.pixel(x + 0, y + 0);
				QRgb tr = img.pixel(x + 1, y + 0);
				QRgb bl = img.pixel(x + 0, y + 1);
				QRgb br = img.pixel(x + 1, y + 1);
				quint64 quad = packQuad(tl, tr, bl, br, pixelFormat);

				if (!uniqueQuads.contains(quad))
					uniqueQuads.insert(quad, uniqueQuads.size());

				if (uniqueQuads.size() <= maxCodes)
					indexedImage.setPixel(x / 2, y / 2, uniqueQuads.value(quad));
			}
		}

		// Only add the image if we haven't hit the code limit
		if (uniqueQuads.size() <= maxCodes) {
			indexedImages.push_back(indexedImage);
		}
	}

	if (uniqueQuads.size() <= maxCodes) {
		// This texture can be losslessly compressed.
		// Copy the unique quads over to the codebook.
		// indexedImages is already done.
		codebook.resize(uniqueQuads.size());
		for (auto it = uniqueQuads.cbegin(); it != uniqueQuads.cend(); ++it)
			codebook[it.value()] = it.key();
	} else {
		// This texture needs lossy compression
		indexedImages.clear();
	}

	return uniqueQuads.size();
}
예제 #6
0
void LibraryController::requestSearch(const QHash<QString, QStringList> &query, const QStringList &uris, bool exact)
{
    Q_D(LibraryController);

    QJsonObject params;

    QJsonObject joQuery;
    for(auto it = query.cbegin(); it != query.cend(); ++it)
        joQuery.insert(it.key(), QJsonArray::fromStringList(it.value()));
    params["query"] = joQuery;

    if(uris.size() == 1)
        params["uri"] = uris.first();
    else if(uris.size() > 1)
        params["uris"] = QJsonArray::fromStringList(uris);

    params["exact"] = exact;

    send_message(std::bind(&LibraryControllerPrivate::onSearch, d, std::placeholders::_1), "search", params);
}
예제 #7
0
OsmAnd::MapStyleRule::MapStyleRule(MapStyle* owner_, const QHash< QString, QString >& attributes)
    : _d(new MapStyleRule_P(this))
    , owner(owner_)
{
    _d->_valueDefinitionsRefs.reserve(attributes.size());
    _d->_values.reserve(attributes.size());
    
    for(auto itAttribute = attributes.cbegin(); itAttribute != attributes.cend(); ++itAttribute)
    {
        const auto& key = itAttribute.key();
        const auto& value = itAttribute.value();

        std::shared_ptr<const MapStyleValueDefinition> valueDef;
        bool ok = owner->resolveValueDefinition(key, valueDef);
        assert(ok);

        _d->_valueDefinitionsRefs.push_back(valueDef);
        MapStyleValue parsedValue;
        switch (valueDef->dataType)
        {
        case MapStyleValueDataType::Boolean:
            parsedValue.asSimple.asInt = (value == QLatin1String("true")) ? 1 : 0;
            break;
        case MapStyleValueDataType::Integer:
            {
                if(valueDef->isComplex)
                {
                    parsedValue.isComplex = true;
                    if(!value.contains(':'))
                    {
                        parsedValue.asComplex.asInt.dip = Utilities::parseArbitraryInt(value, -1);
                        parsedValue.asComplex.asInt.px = 0.0;
                    }
                    else
                    {
                        // 'dip:px' format
                        const auto& complexValue = value.split(':', QString::KeepEmptyParts);

                        parsedValue.asComplex.asInt.dip = Utilities::parseArbitraryInt(complexValue[0], 0);
                        parsedValue.asComplex.asInt.px = Utilities::parseArbitraryInt(complexValue[1], 0);
                    }
                }
                else
                {
                    assert(!value.contains(':'));
                    parsedValue.asSimple.asInt = Utilities::parseArbitraryInt(value, -1);
                }
            }
            break;
        case MapStyleValueDataType::Float:
            {
                if(valueDef->isComplex)
                {
                    parsedValue.isComplex = true;
                    if(!value.contains(':'))
                    {
                        parsedValue.asComplex.asFloat.dip = Utilities::parseArbitraryFloat(value, -1.0f);
                        parsedValue.asComplex.asFloat.px = 0.0f;
                    }
                    else
                    {
                        // 'dip:px' format
                        const auto& complexValue = value.split(':', QString::KeepEmptyParts);

                        parsedValue.asComplex.asFloat.dip = Utilities::parseArbitraryFloat(complexValue[0], 0);
                        parsedValue.asComplex.asFloat.px = Utilities::parseArbitraryFloat(complexValue[1], 0);
                    }
                }
                else
                {
                    assert(!value.contains(':'));
                    parsedValue.asSimple.asFloat = Utilities::parseArbitraryFloat(value, -1.0f);
                }
            }
            break;
        case MapStyleValueDataType::String:
            parsedValue.asSimple.asUInt = owner->_d->lookupStringId(value);
            break;
        case MapStyleValueDataType::Color:
            {
                assert(value[0] == '#');
                parsedValue.asSimple.asUInt = value.mid(1).toUInt(nullptr, 16);
                if(value.size() <= 7)
                    parsedValue.asSimple.asUInt |= 0xFF000000;
            }
            break;
        }
        
        _d->_values.insert(key, parsedValue);
    }
}
예제 #8
0
void dump(std::ostream &output, const OsmAnd::Verifier::Configuration& cfg)
#endif
{
    OsmAnd::ObfsCollection obfsCollection;
    for(const auto& obfsDir : cfg.obfDirs)
        obfsCollection.addDirectory(obfsDir);
    for(const auto& obfFile : cfg.obfFiles)
        obfsCollection.addFile(obfFile);
    const auto dataInterface = obfsCollection.obtainDataInterface();

    const auto obfFiles = obfsCollection.getObfFiles();
    output << "Will work with these files:" << std::endl;
    for(const auto& obfFile : obfFiles)
        output << "\t" << qPrintable(obfFile->filePath) << std::endl;

    if(cfg.action == OsmAnd::Verifier::Configuration::Action::UniqueMapObjectIds)
    {
        const OsmAnd::AreaI entireWorld(0, 0, std::numeric_limits<int32_t>::max(), std::numeric_limits<int32_t>::max());

        unsigned int lastReportedCount = 0;
        unsigned int totalDuplicatesCount = 0;

        for(int zoomLevel = OsmAnd::MinZoomLevel; zoomLevel <= OsmAnd::MaxZoomLevel; zoomLevel++)
        {
            output << "Processing " << zoomLevel << " zoom level..." << std::endl;

            QList< std::shared_ptr<const OsmAnd::Model::MapObject> > duplicateMapObjects;
            QHash<uint64_t, unsigned int> mapObjectIds;
            const auto idsCollector = [&mapObjectIds, &lastReportedCount, &output, &totalDuplicatesCount](
                const std::shared_ptr<const OsmAnd::ObfMapSectionInfo>& section,
                const uint64_t mapObjectId,
                const OsmAnd::AreaI& bbox,
                const OsmAnd::ZoomLevel firstZoomLevel,
                const OsmAnd::ZoomLevel lasttZoomLevel) -> bool
            {
                const auto itId = mapObjectIds.find(mapObjectId);
                if(itId != mapObjectIds.end())
                {
                    // Increment duplicates counter
                    itId.value()++;
                    totalDuplicatesCount++;

                    return true;
                }

                // Insert new entry
                mapObjectIds.insert(mapObjectId, 0);

                if(mapObjectIds.size() - lastReportedCount == 10000)
                {
                    output << "\t... processed 10k map objects, found " << totalDuplicatesCount << " duplicate(s) so far ... " << std::endl;
                    lastReportedCount = mapObjectIds.size();
                }

                return false;
            };

            dataInterface->loadMapObjects(&duplicateMapObjects, nullptr, entireWorld, static_cast<OsmAnd::ZoomLevel>(zoomLevel), nullptr, idsCollector, nullptr);

            output << "\tProcessed " << mapObjectIds.size() << " map objects.";
            if(!mapObjectIds.isEmpty())
                output << " Found " << totalDuplicatesCount << " duplicate(s) :";
            output << std::endl;
            for(auto itEntry = mapObjectIds.cbegin(); itEntry != mapObjectIds.cend(); ++itEntry)
            {
                const auto mapObjectId = itEntry.key();
                const auto duplicatesCount = itEntry.value();
                if(duplicatesCount == 0)
                    continue;

                output << "\tMapObject ";
                if(static_cast<int64_t>(mapObjectId) < 0)
                {
                    int64_t originalId = -static_cast<int64_t>(static_cast<uint64_t>(-static_cast<int64_t>(mapObjectId)) & 0xFFFFFFFF);
                    output << originalId;
                }
                else
                {
                    output << mapObjectId;
                }
                output << " has " << duplicatesCount << " duplicate(s)." << std::endl;
            }
        }

        output << "Totally " << totalDuplicatesCount << " duplicate(s) across all zoom levels" << std::endl;
    }
}