bool MainWindow::openFile(const QString &fileName, MapReaderInterface *mapReader) { if (fileName.isEmpty()) return false; // Select existing document if this file is already open int documentIndex = mDocumentManager->findDocument(fileName); if (documentIndex != -1) { mDocumentManager->switchToDocument(documentIndex); return true; } TmxMapReader tmxMapReader; const PluginManager *pm = PluginManager::instance(); if (!mapReader && !tmxMapReader.supportsFile(fileName)) { // Try to find a plugin that implements support for this format QList<MapReaderInterface*> readers = pm->interfaces<MapReaderInterface>(); foreach (MapReaderInterface *reader, readers) { if (reader->supportsFile(fileName)) { mapReader = reader; break; } } }
bool MainWindow::openFile(const QString &fileName, MapReaderInterface *mapReader) { if (fileName.isEmpty()) return false; // Select existing document if this file is already open int documentIndex = mDocumentManager->findDocument(fileName); if (documentIndex != -1) { mDocumentManager->switchToDocument(documentIndex); return true; } TmxMapReader tmxMapReader; if (!mapReader && !tmxMapReader.supportsFile(fileName)) { // Try to find a plugin that implements support for this format const PluginManager *pm = PluginManager::instance(); QList<MapReaderInterface*> readers = pm->interfaces<MapReaderInterface>(); foreach (MapReaderInterface *reader, readers) { if (reader->supportsFile(fileName)) { mapReader = reader; break; } } } if (!mapReader) mapReader = &tmxMapReader; Map *map = mapReader->read(fileName); if (!map) { QMessageBox::critical(this, tr("Error Opening Map"), mapReader->errorString()); return false; } addMapDocument(new MapDocument(map, fileName)); setRecentFile(fileName); return true; }
MapDocument *MapDocument::load(const QString &fileName, MapReaderInterface *mapReader, QString *error) { TmxMapReader tmxMapReader; const PluginManager *pm = PluginManager::instance(); if (!mapReader && !tmxMapReader.supportsFile(fileName)) { // Try to find a plugin that implements support for this format QList<MapReaderInterface*> readers = pm->interfaces<MapReaderInterface>(); foreach (MapReaderInterface *reader, readers) { if (reader->supportsFile(fileName)) { mapReader = reader; break; } } }