2007-08-07 17:09:41 +02:00
|
|
|
/* This file is part of Mapnik (c++ mapping toolkit)
|
2011-10-23 16:09:12 +02:00
|
|
|
*
|
2021-01-05 15:39:07 +01:00
|
|
|
* Copyright (C) 2021 Artem Pavlenko
|
2007-08-07 17:09:41 +02:00
|
|
|
*
|
|
|
|
* Mapnik is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2016-01-26 10:54:42 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-08-07 17:09:41 +02:00
|
|
|
*/
|
|
|
|
|
2009-06-30 18:23:50 +02:00
|
|
|
// qt
|
2013-09-20 03:30:28 +02:00
|
|
|
#include <QApplication>
|
2007-08-07 17:09:41 +02:00
|
|
|
#include <QStringList>
|
2010-06-18 12:53:57 +02:00
|
|
|
#include <QSettings>
|
2007-08-07 17:09:41 +02:00
|
|
|
#include <mapnik/datasource_cache.hpp>
|
|
|
|
#include <mapnik/font_engine_freetype.hpp>
|
|
|
|
#include "mainwindow.hpp"
|
2013-06-03 04:28:24 +02:00
|
|
|
|
2022-01-26 23:34:08 +01:00
|
|
|
int main(int argc, char** argv)
|
2010-06-18 12:53:57 +02:00
|
|
|
{
|
|
|
|
using mapnik::datasource_cache;
|
2010-07-16 01:08:02 +02:00
|
|
|
using mapnik::freetype_engine;
|
2012-07-31 19:45:38 +02:00
|
|
|
try
|
2010-06-18 12:53:57 +02:00
|
|
|
{
|
2022-01-26 23:34:08 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
2018-02-20 11:43:55 +01:00
|
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
2022-01-26 23:34:08 +01:00
|
|
|
#endif
|
2012-07-31 19:45:38 +02:00
|
|
|
QCoreApplication::setOrganizationName("Mapnik");
|
|
|
|
QCoreApplication::setOrganizationDomain("mapnik.org");
|
|
|
|
QCoreApplication::setApplicationName("Viewer");
|
2022-01-26 23:34:08 +01:00
|
|
|
QSettings settings("viewer.ini", QSettings::IniFormat);
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2012-07-31 19:45:38 +02:00
|
|
|
// register input plug-ins
|
2022-01-26 23:34:08 +01:00
|
|
|
QString plugins_dir = settings.value("mapnik/plugins_dir", QVariant("/usr/local/lib/mapnik/input/")).toString();
|
2012-09-07 17:23:03 +02:00
|
|
|
datasource_cache::instance().register_datasources(plugins_dir.toStdString());
|
2012-07-31 19:45:38 +02:00
|
|
|
// register fonts
|
|
|
|
int count = settings.beginReadArray("mapnik/fonts");
|
2022-01-26 23:34:08 +01:00
|
|
|
for (int index = 0; index < count; ++index)
|
2012-07-31 19:45:38 +02:00
|
|
|
{
|
|
|
|
settings.setArrayIndex(index);
|
|
|
|
QString font_dir = settings.value("dir").toString();
|
|
|
|
freetype_engine::register_fonts(font_dir.toStdString());
|
|
|
|
}
|
|
|
|
settings.endArray();
|
|
|
|
|
2022-01-26 23:34:08 +01:00
|
|
|
QApplication app(argc, argv);
|
2012-07-31 19:45:38 +02:00
|
|
|
MainWindow window;
|
|
|
|
window.show();
|
2022-01-26 23:34:08 +01:00
|
|
|
if (argc > 1)
|
|
|
|
window.open(argv[1]);
|
2012-07-31 19:45:38 +02:00
|
|
|
if (argc >= 3)
|
|
|
|
{
|
|
|
|
QStringList list = QString(argv[2]).split(",");
|
2022-01-26 23:34:08 +01:00
|
|
|
if (list.size() == 4)
|
2012-07-31 19:45:38 +02:00
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
double x0 = list[0].toDouble(&ok);
|
|
|
|
double y0 = list[1].toDouble(&ok);
|
|
|
|
double x1 = list[2].toDouble(&ok);
|
|
|
|
double y1 = list[3].toDouble(&ok);
|
2022-01-26 23:34:08 +01:00
|
|
|
if (ok)
|
|
|
|
window.set_default_extent(x0, y0, x1, y1);
|
2012-07-31 19:45:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
std::shared_ptr<mapnik::Map> map = window.get_map();
|
2022-01-26 23:34:08 +01:00
|
|
|
if (map)
|
|
|
|
map->zoom_all();
|
2012-07-31 19:45:38 +02:00
|
|
|
}
|
|
|
|
if (argc == 4)
|
2010-06-15 14:27:26 +02:00
|
|
|
{
|
|
|
|
bool ok;
|
2012-07-31 19:45:38 +02:00
|
|
|
double scaling_factor = QString(argv[3]).toDouble(&ok);
|
2022-01-26 23:34:08 +01:00
|
|
|
if (ok)
|
|
|
|
window.set_scaling_factor(scaling_factor);
|
2010-06-15 14:27:26 +02:00
|
|
|
}
|
2012-07-31 19:45:38 +02:00
|
|
|
return app.exec();
|
2022-11-10 16:57:38 +01:00
|
|
|
}
|
|
|
|
catch (std::exception const& ex)
|
2010-06-17 10:26:08 +02:00
|
|
|
{
|
2012-07-31 19:45:38 +02:00
|
|
|
std::cerr << "Could not start viewer: '" << ex.what() << "'\n";
|
|
|
|
return 1;
|
2010-06-17 10:26:08 +02:00
|
|
|
}
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|