Ejemplo n.º 1
0
void FoursquareModel::parseFile( const QByteArray& file )
{
    QScriptValue data;
    QScriptEngine engine;
    // Qt requires parentheses around JSON
    data = engine.evaluate( '(' + QString::fromUtf8( file ) + ')' );
    data = data.property("response");
    
    // Parse if any result exists
    if ( data.property( "venues" ).isArray() ) {
        QScriptValueIterator iterator( data.property( "venues" ) );
        // Add items to the list
        QList<AbstractDataPluginItem*> items;
        do {
            iterator.next();
            QString id = iterator.value().property( "id" ).toString();
            QString name = iterator.value().property( "name" ).toString();
            QString category = iterator.value().property( "categories" ).property( 0 ).property( "name" ).toString();
            QString address = iterator.value().property( "location" ).property( "address" ).toString();
            QString city = iterator.value().property( "location" ).property( "city" ).toString();
            QString country = iterator.value().property( "location" ).property( "country" ).toString();
            double latitude = iterator.value().property( "location" ).property( "lat" ).toString().toDouble();
            double longitude = iterator.value().property( "location" ).property( "lng" ).toString().toDouble();
            int usersCount = iterator.value().property( "stats" ).property( "usersCount" ).toInteger();
            
            QScriptValue categoryIcon = iterator.value().property( "categories" ).property( 0 ).property( "icon" );
            QString iconUrl;
            QString largeIconUrl;
            if ( categoryIcon.isValid() ) {
                iconUrl = categoryIcon.property( "prefix" ).toString()
                        + "32" // That's the icon size hardcoded
                        + categoryIcon.property( "name" ).toString();
                        
                largeIconUrl = categoryIcon.property( "prefix" ).toString()
                        + "64" // Larger icon
                        + categoryIcon.property( "name" ).toString();
            }

            if( !itemExists( id ) ) {
                GeoDataCoordinates coordinates( longitude, latitude, 0.0, GeoDataCoordinates::Degree );
                FoursquareItem *item = new FoursquareItem( this );
                item->setId( id );
                item->setCoordinate( coordinates );
                item->setTarget( "earth" );
                item->setName( name );
                item->setCategory( category );
                item->setAddress( address );
                item->setCity( city );
                item->setCountry( country );
                item->setUsersCount( usersCount );
                item->setCategoryIconUrl( iconUrl );
                item->setCategoryLargeIconUrl( largeIconUrl );
                
                items << item;
            }
        }
        while ( iterator.hasNext() );
        addItemsToList( items );
    }
}
Ejemplo n.º 2
0
void ReachableList::calculateNewList()
{
  // qDebug( "ReachableList::calculateNewList() is called" );

  // calculateNewList is also called from calculator, so on check has to be
  // executed
  if ( !isOn() )
    {
      return;
    }

  // QTime t; // timer for performance measurement
  // t.start();

  setInitValues();
  clearLists();  // clear all lists

  // Now add items of different type to the list
  addItemsToList(MapContents::AirfieldList);
  addItemsToList(MapContents::GliderfieldList);
  addItemsToList(MapContents::OutLandingList);
  addItemsToList(MapContents::WaypointList);
  modeAltitude = false;
  //qDebug("Number of potential reachable sites: %d", count() );

  // sort list according to distances
  qSort(begin(), end() );
  removeDoubles();
  // qDebug("Number of potential reachable sites (after pruning): %d", count() );

  // Remove all elements over the maximum. That are the far away elements.
  int nr = getMaxNrOfSites();

  while ( nr < size() )
    {
      removeFirst();
    }

  // qDebug("Limited Number of potential reachable sites: %d", count() );
  calculateDataInList();
  //qDebug("Time for full calculation: %d msec", t.restart() );
}
Ejemplo n.º 3
0
void OpenCachingComModel::parseFile( const QByteArray& file )
{
    QScriptEngine engine;

    // Qt requires parentheses around json code
    QScriptValue data = engine.evaluate( '(' + QString::fromUtf8( file ) + ')' );
    QVariantList caches = data.toVariant().toList();

//     qDebug()<<"parsing "<<caches.size()<<" items";
    QList<AbstractDataPluginItem*> items;
    while (!caches.isEmpty())
    {
        QVariantMap map = caches.takeFirst().toMap();
        if ( !findItem( map["oxcode"].toString() ) )
        {
            items << new OpenCachingComItem( map, this );
        }
    }
    addItemsToList(items);
}
Ejemplo n.º 4
0
void EarthquakeModel::parseFile( const QByteArray& file )
{
    QJsonDocument jsonDoc = QJsonDocument::fromJson(file);
    QJsonValue earthquakesValue = jsonDoc.object().value(QStringLiteral("earthquakes"));

    // Parse if any result exists
    if (earthquakesValue.isArray()) {
        // Add items to the list
        QList<AbstractDataPluginItem*> items;

        QJsonArray earthquakeArray = earthquakesValue.toArray();
        for (int earthquakeIndex = 0; earthquakeIndex < earthquakeArray.size(); ++earthquakeIndex) {
            QJsonObject levelObject = earthquakeArray[earthquakeIndex].toObject();

            // Converting earthquake's properties from JSON to appropriate types
            const QString eqid = levelObject.value(QStringLiteral("eqid")).toString(); // Earthquake's ID
            const double longitude = levelObject.value(QStringLiteral("lng")).toDouble();
            const double latitude = levelObject.value(QStringLiteral("lat")).toDouble();
            const double magnitude = levelObject.value(QStringLiteral("magnitude")).toDouble();
            const QString dateString = levelObject.value(QStringLiteral("datetime")).toString();
            const QDateTime date = QDateTime::fromString(dateString, QStringLiteral("yyyy-MM-dd hh:mm:ss"));
            const double depth = levelObject.value(QStringLiteral("depth")).toDouble();

            if( date <= m_endDate && date >= m_startDate && magnitude >= m_minMagnitude ) {
                if( !itemExists( eqid ) ) {
                    // If it does not exists, create it
                    GeoDataCoordinates coordinates( longitude, latitude, 0.0, GeoDataCoordinates::Degree );
                    EarthquakeItem *item = new EarthquakeItem( this );
                    item->setId( eqid );
                    item->setCoordinate( coordinates );
                    item->setMagnitude( magnitude );
                    item->setDateTime( date );
                    item->setDepth( depth );
                    items << item;
                }
            }
        }

        addItemsToList( items );
    }
}