void MapTest::initTestCase() { Q_INIT_RESOURCE(resources); doStaticInitializations(); // Static map initializations Map map; }
void FileFormatTest::initTestCase() { // Needed to load current developer preferences, if possible QCoreApplication::setOrganizationName("OpenOrienteering.org"); QCoreApplication::setApplicationName("Mapper"); doStaticInitializations(); map_filenames << "COPY_OF_test_map.omap" << "COPY_OF_spotcolor_overprint.xmap"; for (int i = 0; i < map_filenames.size(); ++i) { QString filename = MapperResource::locate(MapperResource::TEST_DATA, map_filenames[i]); QVERIFY2(!filename.isEmpty(), QString("Unable to locate %1").arg(map_filenames[i]).toLocal8Bit()); map_filenames[i] = filename; } }
void FileFormatTest::initTestCase() { QCoreApplication::setOrganizationName("OpenOrienteering.org"); QCoreApplication::setApplicationName("FileFormatTest"); Settings::getInstance().setSetting(Settings::General_NewOcd8Implementation, true); doStaticInitializations(); if (!FileFormats.findFormat("OCAD78")) FileFormats.registerFormat(new OCAD8FileFormat()); map_filenames << "COPY_OF_issue-513-coords-outside-printable.xmap" << "COPY_OF_issue-513-coords-outside-qint32.omap" << "COPY_OF_spotcolor_overprint.xmap" << "COPY_OF_test_map.omap"; for (auto&& filename : map_filenames) { QString path = MapperResource::locate(MapperResource::TEST_DATA, filename); QVERIFY2(!path.isEmpty(), QString("Unable to locate %1").arg(filename).toLocal8Bit()); filename = path; } }
void ToolsTest::initTestCase() { Q_INIT_RESOURCE(resources); doStaticInitializations(); }
int main(int argc, char** argv) { #ifdef Q_OS_ANDROID // Android native style is activated later. qputenv("QT_USE_ANDROID_NATIVE_STYLE", "0"); #endif #if MAPPER_USE_QTSINGLEAPPLICATION // Create single-instance application. // Use "oo-mapper" instead of the executable as identifier, in case we launch from different paths. QtSingleApplication qapp("oo-mapper", argc, argv); if (qapp.isRunning()) { // Send a message to activate the running app, and optionally open a file qapp.sendMessage((argc > 1) ? argv[1] : ""); return 0; } #else QApplication qapp(argc, argv); #endif // Load resources #ifdef MAPPER_USE_QT_CONF_QRC Q_INIT_RESOURCE(qt); #endif Q_INIT_RESOURCE(resources); Q_INIT_RESOURCE(licensing); // QSettings on OS X benefits from using an internet domain here. QCoreApplication::setOrganizationName("OpenOrienteering.org"); QCoreApplication::setApplicationName("Mapper"); // Set settings defaults Settings& settings = Settings::getInstance(); settings.applySettings(); #ifdef WIN32 // Load plugins on Windows qapp.addLibraryPath(QCoreApplication::applicationDirPath() + "/plugins"); #endif // Localization TranslationUtil::setBaseName(QString("OpenOrienteering")); QLocale::Language lang = (QLocale::Language)settings.getSetting(Settings::General_Language).toInt(); QString translation_file = settings.getSetting(Settings::General_TranslationFile).toString(); TranslationUtil translation(lang, translation_file); QLocale::setDefault(translation.getLocale()); #if defined(Mapper_DEBUG_TRANSLATIONS) if (!translation.getAppTranslator().isEmpty()) { // Debug translation only if there is a Mapper translation, i.e. not for English. qapp.installTranslator(new RecordingTranslator()); } #endif qapp.installTranslator(&translation.getQtTranslator()); qapp.installTranslator(&translation.getAppTranslator()); // Initialize static things like the file format registry. doStaticInitializations(); QStyle* base_style = nullptr; #if defined(Q_OS_ANDROID) base_style = QStyleFactory::create("android"); #elif !defined(Q_OS_WIN) && !defined(Q_OS_OSX) if (QGuiApplication::platformName() == QLatin1String("xcb")) { // Use the modern 'fusion' style instead of the // default "windows" style on X11. base_style = QStyleFactory::create("fusion"); } #endif QApplication::setStyle(new MapperProxyStyle(base_style)); #if !defined(Q_OS_OSX) QApplication::setPalette(QApplication::style()->standardPalette()); #endif // Create first main window MainWindow first_window(true); first_window.setAttribute(Qt::WA_DeleteOnClose, false); first_window.setController(new HomeScreenController()); bool no_files_given = true; #ifdef Q_OS_ANDROID QAndroidJniObject activity = QtAndroid::androidActivity(); QAndroidJniObject intent = activity.callObjectMethod("getIntent", "()Landroid/content/Intent;"); const QString action = intent.callObjectMethod<jstring>("getAction").toString(); static const QString action_edit = QAndroidJniObject::getStaticObjectField<jstring>("android/content/Intent", "ACTION_EDIT").toString(); static const QString action_view = QAndroidJniObject::getStaticObjectField<jstring>("android/content/Intent", "ACTION_VIEW").toString(); if (action == action_edit || action == action_view) { const QString data_string = intent.callObjectMethod<jstring>("getDataString").toString(); const QString local_file = QUrl(data_string).toLocalFile(); first_window.setHomeScreenDisabled(true); first_window.setCentralWidget(new QLabel(MainWindow::tr("Loading %1...").arg(local_file))); first_window.setVisible(true); first_window.raise(); // Empircal tested: We need to process the loop twice. QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); if (!first_window.openPath(local_file)) return -1; return qapp.exec(); } #else // Open given files later, i.e. after the initial home screen has been // displayed. In this way, error messages for missing files will show on // top of a regular main window (home screen or other file). // Treat all program parameters as files to be opened QStringList args(qapp.arguments()); args.removeFirst(); // the program name for (auto&& arg : args) { if (arg[0] != '-') { first_window.openPathLater(arg); no_files_given = false; } } #endif // Optionally open most recently used file on startup if (no_files_given && settings.getSettingCached(Settings::General_OpenMRUFile).toBool()) { QStringList files(settings.getSettingCached(Settings::General_RecentFilesList).toStringList()); if (!files.isEmpty()) first_window.openPathLater(files[0]); } #if MAPPER_USE_QTSINGLEAPPLICATION // If we need to respond to a second app launch, do so, but also accept a file open request. qapp.setActivationWindow(&first_window); QObject::connect(&qapp, SIGNAL(messageReceived(const QString&)), &first_window, SLOT(openPath(const QString &))); #endif // Let application run first_window.setVisible(true); first_window.raise(); return qapp.exec(); }