本文整理汇总了C++中MapDocument::map方法的典型用法代码示例。如果您正苦于以下问题:C++ MapDocument::map方法的具体用法?C++ MapDocument::map怎么用?C++ MapDocument::map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MapDocument
的用法示例。
在下文中一共展示了MapDocument::map方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: detachSelectedObjects
void AbstractObjectTool::detachSelectedObjects()
{
MapDocument *currentMapDocument = mapDocument();
QList<MapObject *> templateInstances;
/**
* Stores the unique tilesets used by the templates
* to avoid creating multiple undo commands for the same tileset
*/
QSet<SharedTileset> sharedTilesets;
for (MapObject *object : mapDocument()->selectedObjects()) {
if (object->templateObject()) {
templateInstances.append(object);
if (Tile *tile = object->cell().tile())
sharedTilesets.insert(tile->tileset()->sharedPointer());
}
}
auto changeMapObjectCommand = new DetachObjects(currentMapDocument, templateInstances);
// Add any missing tileset used by the templates to the map map before detaching
for (SharedTileset sharedTileset : sharedTilesets) {
if (!currentMapDocument->map()->tilesets().contains(sharedTileset))
new AddTileset(currentMapDocument, sharedTileset, changeMapObjectCommand);
}
currentMapDocument->undoStack()->push(changeMapObjectCommand);
}
示例2: changeTile
void AbstractObjectTool::changeTile()
{
QList<MapObject*> tileObjects;
MapDocument *currentMapDocument = mapDocument();
for (auto object : currentMapDocument->selectedObjects())
if (object->isTileObject())
tileObjects.append(object);
auto changeMapObjectCommand = new ChangeMapObjectsTile(currentMapDocument, tileObjects, tile());
// Make sure the tileset is part of the document
SharedTileset sharedTileset = tile()->tileset()->sharedPointer();
if (!currentMapDocument->map()->tilesets().contains(sharedTileset))
new AddTileset(currentMapDocument, sharedTileset, changeMapObjectCommand);
currentMapDocument->undoStack()->push(changeMapObjectCommand);
}
示例3: tryFixLink
void BrokenLinksWidget::tryFixLink(const BrokenLink &link)
{
Document *document = mBrokenLinksModel->document();
Preferences *prefs = Preferences::instance();
if (link.type == TilesetImageSource || link.type == TilesetTileImageSource) {
auto tilesetDocument = qobject_cast<TilesetDocument*>(document);
if (!tilesetDocument) {
// We need to open the tileset document in order to be able to make changes to it...
const SharedTileset tileset = link.tileset()->sharedPointer();
DocumentManager::instance()->openTileset(tileset);
return;
}
QString startLocation = QFileInfo(prefs->lastPath(Preferences::ImageFile)).absolutePath();
startLocation += QLatin1Char('/');
startLocation += QFileInfo(link.filePath()).fileName();
QString newFileName = QFileDialog::getOpenFileName(window(),
tr("Locate File"),
startLocation,
Utils::readableImageFormatsFilter());
if (newFileName.isEmpty())
return;
QImageReader reader(newFileName);
QImage image = reader.read();
if (image.isNull()) {
QMessageBox::critical(this, tr("Error Loading Image"), reader.errorString());
return;
}
if (link.type == TilesetImageSource) {
TilesetParameters parameters(*link._tileset);
parameters.imageSource = newFileName;
auto command = new ChangeTilesetParameters(tilesetDocument,
parameters);
tilesetDocument->undoStack()->push(command);
} else {
auto command = new ChangeTileImageSource(tilesetDocument,
link._tile,
newFileName);
tilesetDocument->undoStack()->push(command);
}
prefs->setLastPath(Preferences::ImageFile, newFileName);
} else if (link.type == MapTilesetReference) {
const QString allFilesFilter = tr("All Files (*)");
QString selectedFilter = allFilesFilter;
QString filter = allFilesFilter;
FormatHelper<TilesetFormat> helper(FileFormat::Read, filter);
QString start = prefs->lastPath(Preferences::ExternalTileset);
const QString fileName =
QFileDialog::getOpenFileName(this, tr("Locate External Tileset"),
start,
helper.filter(),
&selectedFilter);
if (fileName.isEmpty())
return;
QString error;
// It could be, that we have already loaded this tileset.
SharedTileset newTileset = TilesetManager::instance()->findTileset(fileName);
if (!newTileset || !newTileset->loaded()) {
newTileset = Tiled::readTileset(fileName, &error);
if (!newTileset) {
QMessageBox::critical(window(), tr("Error Reading Tileset"), error);
return;
}
}
MapDocument *mapDocument = static_cast<MapDocument*>(document);
int index = mapDocument->map()->tilesets().indexOf(link._tileset->sharedPointer());
if (index != -1)
document->undoStack()->push(new ReplaceTileset(mapDocument, index, newTileset));
prefs->setLastPath(Preferences::ExternalTileset,
QFileInfo(fileName).path());
}
}