示例#1
0
void LogDock::saveLogToFile()
{
    if ( !lastProbe ) return;
    saveLog->setEnabled(false);
    saveLog->setDown(true);
    QString _fileName;
    if ( autoSaveLog->isChecked() ) {
        _fileName = getTemplateFilename();
    } else {
        _fileName = QFileDialog::getSaveFileName(
                this,
                "Save Log To",
                QString("~/%1")
                    .arg(getTemplateFilename()));
    };
    if ( !_fileName.isEmpty() ) {
        QFile file;
        file.setFileName(_fileName);
        file.open(QIODevice::WriteOnly);
        QByteArray text = Log->toPlainText().toLocal8Bit();
        int written = file.write(text.data());
        file.close();
        QString msg;
        if ( written==text.size() ) {
            Log->clear();
            emit overflow(false);
            msg.append(QString("Save Log to %1 done.")
                       .arg(_fileName));
            lastProbe = true;
        } else {
            msg.append(QString("Save Log to %1 failed.")
                       .arg(_fileName));
            lastProbe = false;
        };
        QString time = QTime::currentTime().toString();
        QString currMsg = QString(
        "<b>%1:</b><br><font color='green'><b>ACTION</b></font>: %3")
                .arg(time).arg(msg);
        appendMsgToLog(currMsg);
    };
    saveLog->setDown(false);
    saveLog->setEnabled(true);
}
示例#2
0
文件: template.cpp 项目: kshji/mapper
void Template::saveTemplateConfiguration(QXmlStreamWriter& xml, bool open)
{
	xml.writeStartElement("template");
	xml.writeAttribute("open", open ? "true" : "false");
	xml.writeAttribute("name", getTemplateFilename());
	xml.writeAttribute("path", getTemplatePath());
	xml.writeAttribute("relpath", getTemplateRelativePath());
	if (is_georeferenced)
		xml.writeAttribute("georef", "true");
	else
	{
		xml.writeAttribute("group", QString::number(template_group));
		
		xml.writeStartElement("transformations");
		if (adjusted)
			xml.writeAttribute("adjusted", "true");
		if (adjustment_dirty)
			xml.writeAttribute("adjustment_dirty", "true");
		int num_passpoints = (int)passpoints.size();
		xml.writeAttribute("passpoints", QString::number(num_passpoints));
		
		transform.save(xml, "active");
		other_transform.save(xml, "other");
		
		for (int i = 0; i < num_passpoints; ++i)
			passpoints[i].save(xml);
		
		map_to_template.save(xml, "map_to_template");
		template_to_map.save(xml, "template_to_map");
		template_to_map_other.save(xml, "template_to_map_other");
		
		xml.writeEndElement(/*transformations*/);
	}
	
	saveTypeSpecificTemplateConfiguration(xml);
	
	if (open && hasUnsavedChanges())
	{
		// Save the template itself (e.g. image, gpx file, etc.)
		saveTemplateFile();
		setHasUnsavedChanges(false); // TODO: Error handling?
	}
	xml.writeEndElement(/*template*/);
}
示例#3
0
文件: template.cpp 项目: kshji/mapper
bool Template::tryToFindAndReloadTemplateFile(QString map_directory, bool* out_loaded_from_map_dir)
{
	if (!map_directory.isEmpty() && !map_directory.endsWith('/'))
		map_directory.append('/');
	if (out_loaded_from_map_dir)
		*out_loaded_from_map_dir = false;
	
	const QString old_absolute_path = getTemplatePath();
	
	// First try relative path (if this information is available)
	if (!getTemplateRelativePath().isEmpty() && !map_directory.isEmpty())
	{
		setTemplatePath(map_directory + getTemplateRelativePath());
		loadTemplateFile(false);
		if (getTemplateState() == Template::Loaded)
			return true;
	}
	
	// Then try absolute path
	loadTemplateFile(false);
	if (getTemplateState() == Template::Loaded)
		return true;
	
	// Then try the template filename in the map's directory
	if (!map_directory.isEmpty())
	{
		setTemplatePath(map_directory + getTemplateFilename());
		loadTemplateFile(false);
		if (getTemplateState() == Template::Loaded)
		{
			if (out_loaded_from_map_dir)
				*out_loaded_from_map_dir = true;
			return true;
		}
	}
	
	setTemplatePath(old_absolute_path);
	return false;
}
示例#4
0
bool TemplateImage::postLoadConfiguration(QWidget* dialog_parent, bool& out_center_in_view)
{
	Q_UNUSED(out_center_in_view);
	
	if (getTemplateFilename().endsWith(".gif", Qt::CaseInsensitive))
		QMessageBox::warning(dialog_parent, tr("Warning"), tr("Loading a GIF image template.\nSaving GIF files is not supported. This means that drawings on this template won't be saved!\nIf you do not intend to draw on this template however, that is no problem."));
	
	TemplateImageOpenDialog open_dialog(this, dialog_parent);
	open_dialog.setWindowModality(Qt::WindowModal);
	while (true)
	{
		if (open_dialog.exec() == QDialog::Rejected)
			return false;
		
		if (open_dialog.isGeorefRadioChecked() && !map->getGeoreferencing().isValid())
		{
			// Make sure that the map is georeferenced;
			// use the center coordinates of the image as initial reference point.
			calculateGeoreferencing();
			QPointF template_coords_center = georef->toProjectedCoords(MapCoordF(0.5 * (image.width() - 1), 0.5 * (image.height() - 1)));
			bool template_coords_probably_geographic =
				template_coords_center.x() >= -90 && template_coords_center.x() <= 90 &&
				template_coords_center.y() >= -90 && template_coords_center.y() <= 90;
			
			Georeferencing initial_georef(map->getGeoreferencing());
			if (template_coords_probably_geographic)
				initial_georef.setGeographicRefPoint(LatLon(template_coords_center.y(), template_coords_center.x()));
			else
				initial_georef.setProjectedRefPoint(template_coords_center);
			initial_georef.setState(Georeferencing::ScaleOnly);
			
			GeoreferencingDialog dialog(dialog_parent, map, &initial_georef, false);
			if (template_coords_probably_geographic)
				dialog.setKeepGeographicRefCoords();
			else
				dialog.setKeepProjectedRefCoords();
			if (dialog.exec() == QDialog::Rejected)
				continue;
		}
		
		if (open_dialog.isGeorefRadioChecked() && available_georef == Georeferencing_WorldFile)
		{
			// Let user select the coordinate reference system, as this is not specified in world files
			SelectCRSDialog dialog(map, dialog_parent, true, false, true, tr("Select the coordinate reference system of the coordinates in the world file"));
			if (dialog.exec() == QDialog::Rejected)
				continue;
			temp_crs_spec = dialog.getCRSSpec();
		}
		
		break;
	}
	
	is_georeferenced = open_dialog.isGeorefRadioChecked();	
	if (is_georeferenced)
		calculateGeoreferencing();
	else
	{
		transform.template_scale_x = open_dialog.getMpp() * 1000.0 / map->getScaleDenominator();
		transform.template_scale_y = transform.template_scale_x;
		
		//transform.template_x = main_view->getPositionX();
		//transform.template_y = main_view->getPositionY();
		
		updateTransformationMatrices();
	}
	
	return true;
}