示例#1
0
//------------------------------------------------------------------------
void GMapDialog::appendTrackInfo(QStandardItem *it, const GpxTrack &trk)
{
    QDateTime startTime, stopTime;
    bool first = true;
    int count = 0;
    foreach (const GpxTrackSegment &seg, trk.getTrackSegments()) {
        foreach (const GpxTrackPoint &pt, seg.getTrackPoints()) {
            count++;
            QDateTime t = pt.getDateTime();
            if (!t.isValid())
                continue;
            if (first) {
                startTime = t;
                stopTime = t;
                first = false;
            }
            else {
                if (t < startTime)
                    startTime = t;
                if (t > stopTime)
                    stopTime = t;
            }
        }
    }
    if (startTime.isValid()) {
        it->appendRow(new StandardItem(tr("Start: %1")
                                       .arg(startTime.toString("yyyy-MMM-dd HH:mm:ss"))));
        it->appendRow(new StandardItem(tr("Stop: %1")
                                       .arg(stopTime.toString("yyyy-MMM-dd HH:mm:ss"))));
    }
    it->appendRow(new StandardItem(tr("Points: %1").arg(count)));

    it->appendRow(new StandardItem(formatLength(trk.length())));

}
示例#2
0
bool TrafficNetwork::loadFromFile(const string fileName){
	int nbBands;
	long currentNode,otherNode;
	string roadName;
	double roadLength;
	double roadSpeedLimit;
	int metric;

	json_t *root;
	json_error_t error;

	root = json_load_file(fileName.c_str(), 0, &error);

	if(!root){
		std::cout<<std::endl<<"ERROR: while opening "<<fileName<<" at line "<<error.line<<" - "<<error.text<<std::endl;
		return false;
	}

	if(!json_is_object(root)){
		std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - expected root to be an object"<<std::endl;
		json_decref(root);
		return false;
	}

	json_t *_metric, *_roads, *_nodes;
	_metric = json_object_get(root,"metric");

	if(!json_is_integer(_metric)){
		std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - 'metric' field not present or wrong type"<<std::endl;
		json_decref(root);
		return false;
	}
	metric = json_integer_value(_metric);

	_nodes = json_object_get(root,"nodes");
	if(!json_is_array(_nodes)){
		std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - 'nodes' field not present or not an array"<<std::endl;
		json_decref(root);
		return false;
	}

	size_t n = json_array_size(_nodes);
	nbNodes = n;
	nodes = NodeVec(nbNodes);
	json_t *nodeId,*_node, *nodeType;
	for(size_t i = 0; i < n; i++){
		_node = json_array_get(_nodes,i);
		if(!json_is_object(_node)){
			std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - expected node "<<i<<" to be an object"<<std::endl;
			json_decref(root);
			return false;
		}
		nodeId = json_object_get(_node,"id");
		if(!json_is_integer(nodeId)){
			std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - 'id' field of node "<<i<<" not present or wrong type"<<std::endl;
			json_decref(root);
			return false;
		}
		nodeType = json_object_get(_node,"type");
		if(json_is_integer(nodeType)){
			nodes[i] = new Node(json_integer_value(nodeId),json_integer_value(nodeType));
		}else{
			nodes[i] = new Node(json_integer_value(nodeId));
		}

	}

	_roads = json_object_get(root,"roads");
	if(!json_is_array(_roads)){
		std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - 'roads' field not present or not an array"<<std::endl;
		json_decref(root);
		return false;
	}

	n = json_array_size(_roads);
	json_t *_roadName,*_roadSpeedLimit,*_roadNbBands,*_roadLength,*_road,*startId,*endId;
	for(size_t i = 0; i < n; i++){
		_road = json_array_get(_roads,i);
		if(!json_is_object(_road)){
			std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - expected road "<<i<<" to be an object"<<std::endl;
			json_decref(root);
			return false;
		}

		_roadName = json_object_get(_road,"name");
		if(!json_is_string(_roadName)){
			std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - 'name' field of road "<<i<<" not present or wrong type"<<std::endl;
			json_decref(root);
			return false;
		}
		roadName = json_string_value(_roadName);

		_roadSpeedLimit = json_object_get(_road,"speedLimit");
		if(!json_is_integer(_roadSpeedLimit)){
			std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - 'speedLimit' field of road "<<i<<" not present or wrong type"<<std::endl;
			json_decref(root);
			return false;
		}
		roadSpeedLimit = formatSpeedLimit(json_integer_value(_roadSpeedLimit),metric);

		_roadLength = json_object_get(_road,"length");
		if(!json_is_real(_roadLength)){
			std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - 'length' field of road "<<i<<" not present or wrong type"<<std::endl;
			json_decref(root);
			return false;
		}
		roadLength = formatLength(json_real_value(_roadLength),metric);

		_roadNbBands = json_object_get(_road,"nbBands");
		if(!json_is_integer(_roadNbBands)){
			std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - 'nbBands' field of road "<<i<<" not present or wrong type"<<std::endl;
			json_decref(root);
			return false;
		}
		nbBands = json_integer_value(_roadNbBands);

		startId = json_object_get(_road,"startId");
		if(!json_is_integer(startId)){
			std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - 'startId' field of road "<<i<<" not present or wrong type"<<std::endl;
			json_decref(root);
			return false;
		}
		currentNode = json_integer_value(startId);

		endId = json_object_get(_road,"endId");
		if(!json_is_integer(endId)){
			std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - 'endId' field of road "<<i<<" not present or wrong type"<<std::endl;
			json_decref(root);
			return false;
		}
		otherNode = json_integer_value(endId);
		addRoad(currentNode, otherNode, roadName, roadLength, roadSpeedLimit,nbBands);
	}
	//clean up
	json_array_clear(_nodes);
	json_object_clear(_road);
	json_array_clear(_roads);
	json_object_clear(root);
	json_decref(root);
	return true;
}
示例#3
0
//------------------------------------------------------------------------
void GMapDialog::appendRouteInfo(QStandardItem *it, const GpxRoute &rte)
{
    it->appendRow(new StandardItem(formatLength(rte.length())));
}