本文整理汇总了C++中Tileset::clone方法的典型用法代码示例。如果您正苦于以下问题:C++ Tileset::clone方法的具体用法?C++ Tileset::clone怎么用?C++ Tileset::clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tileset
的用法示例。
在下文中一共展示了Tileset::clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: embedTileset
void TilesetDock::embedTileset()
{
Tileset *tileset = currentTileset();
if (!tileset)
return;
if (!tileset->isExternal())
return;
// To embed a tileset we clone it, since further changes to that tileset
// should not affect the exteral tileset.
SharedTileset embeddedTileset = tileset->clone();
QUndoStack *undoStack = mMapDocument->undoStack();
int mapTilesetIndex = mMapDocument->map()->tilesets().indexOf(tileset->sharedPointer());
// Tileset may not be part of the map yet
if (mapTilesetIndex == -1)
undoStack->push(new AddTileset(mMapDocument, embeddedTileset));
else
undoStack->push(new ReplaceTileset(mMapDocument, mapTilesetIndex, embeddedTileset));
// Make sure the embedded tileset is selected
int embeddedTilesetIndex = mTilesets.indexOf(embeddedTileset);
if (embeddedTilesetIndex != -1)
mTabBar->setCurrentIndex(embeddedTilesetIndex);
}
示例2: exportTileset
void TilesetDock::exportTileset()
{
Tileset *tileset = currentTileset();
if (!tileset)
return;
if (tileset->isExternal())
return;
int mapTilesetIndex = mMapDocument->map()->tilesets().indexOf(tileset->sharedPointer());
if (mapTilesetIndex == -1)
return;
// To export a tileset we clone it, since the tileset could now be used by
// other maps. This ensures undo can take the map back to using an embedded
// tileset, without affecting those other maps.
SharedTileset externalTileset = tileset->clone();
FormatHelper<TilesetFormat> helper(FileFormat::ReadWrite);
Preferences *prefs = Preferences::instance();
QString suggestedFileName = prefs->lastPath(Preferences::ExternalTileset);
suggestedFileName += QLatin1Char('/');
suggestedFileName += externalTileset->name();
const QLatin1String extension(".tsx");
if (!suggestedFileName.endsWith(extension))
suggestedFileName.append(extension);
// todo: remember last used filter
QString selectedFilter = TsxTilesetFormat().nameFilter();
const QString fileName =
QFileDialog::getSaveFileName(this, tr("Export Tileset"),
suggestedFileName,
helper.filter(), &selectedFilter);
if (fileName.isEmpty())
return;
prefs->setLastPath(Preferences::ExternalTileset,
QFileInfo(fileName).path());
TilesetFormat *format = helper.formatByNameFilter(selectedFilter);
if (!format)
return; // can't happen
if (!format->write(*externalTileset, fileName)) {
QString error = format->errorString();
QMessageBox::critical(window(),
tr("Export Tileset"),
tr("Error saving tileset: %1").arg(error));
return;
}
externalTileset->setFileName(fileName);
externalTileset->setFormat(format);
QUndoCommand *command = new ReplaceTileset(mMapDocument,
mapTilesetIndex,
externalTileset);
mMapDocument->undoStack()->push(command);
// Make sure the external tileset is selected
int externalTilesetIndex = mTilesets.indexOf(externalTileset);
if (externalTilesetIndex != -1)
mTabBar->setCurrentIndex(externalTilesetIndex);
}