Ejemplo n.º 1
0
void GeorefConfigDialog::load_world_file_cb(void)
{
	const QStringList selection = this->world_file_selector->get_selected_files_full_paths();
	if (0 == selection.size()) {
		return;
	}

	WorldFile wfile;
	const WorldFile::ReadStatus answer = wfile.read_file(selection.at(0));

	switch (answer) {
	case WorldFile::ReadStatus::OpenError:
		Dialog::error(tr("The World file you requested could not be opened for reading."), this);
		break;
	case WorldFile::ReadStatus::ReadError:
		Dialog::error(tr("Unexpected end of file reading World file."), this);
		break;
	case WorldFile::ReadStatus::Success:
		this->set_widget_values(wfile);
		break;
	default:
		qDebug() << SG_PREFIX_E << "Unhandled read status" << (int) answer;
		break;
	}
}
Ejemplo n.º 2
0
/**
   Auto attempt to read the world file associated with the image used for the georef.
   Based on simple file name conventions.
   Only attempted if the preference is on.
*/
static void maybe_read_world_file(FileSelectorWidget * file_selector, void * user_data)
{
	if (!user_data) {
		return;
	}
	GeorefConfigDialog * dialog = (GeorefConfigDialog *) user_data;

	if (!Preferences::get_param_value(PREFERENCES_NAMESPACE_IO "georef_auto_read_world_file").u.val_bool) {
		return;
	}

	const QString file_full_path = file_selector->get_selected_file_full_path();
	if (file_full_path.isEmpty()) {
		return;
	}


	const int len = file_full_path.length();
	const bool upper = file_full_path[len - 1].isUpper();
	WorldFile wfile;


	/* Naming convention 1: .jpg -> .jpgw */
	{
		const QString world_file_full_path = file_full_path + (upper ? "W" : "w");
		qDebug() << SG_PREFIX_I << "Trying to open file with naming convention 1:" << world_file_full_path;

		if (WorldFile::ReadStatus::Success == wfile.read_file(world_file_full_path)) {
			dialog->set_widget_values(wfile);
			qDebug() << SG_PREFIX_I << "Trying to open file with naming convention 1: success";
			return;
		}
	}

	/* Naming convention 2: .jpg -> .jgw */
	{
		if (len > 3) {
			QString world_file_full_path = file_full_path;
			const QChar last_char = file_full_path[len - 1];

			world_file_full_path[len - 2] = last_char;
			world_file_full_path[len - 1] = upper ? 'W' : 'w';
			qDebug() << SG_PREFIX_I << "Trying to open file with naming convention 2:" << world_file_full_path;

			if (WorldFile::ReadStatus::Success == wfile.read_file(world_file_full_path)) {
				dialog->set_widget_values(wfile);
				qDebug() << SG_PREFIX_I << "Trying to open file with naming convention 2: success";
				return;
			}
		}
	}

	/* Naming convention 3: always .wld */
	{
		if (len > 3) {
			QString world_file_full_path = file_full_path;
			world_file_full_path.chop(3);
			if (upper) {
				world_file_full_path.append("WLD");
			} else {
				world_file_full_path.append("wld");
			}
			qDebug() << SG_PREFIX_I << "Trying to open file with naming convention 3:" << world_file_full_path;

			if (WorldFile::ReadStatus::Success == wfile.read_file(world_file_full_path)) {
				dialog->set_widget_values(wfile);
				qDebug() << SG_PREFIX_I << "Trying to open file with naming convention 3: success";
				return;
			}
		}
	}
}