本文整理汇总了C++中MapDocument::undoStack方法的典型用法代码示例。如果您正苦于以下问题:C++ MapDocument::undoStack方法的具体用法?C++ MapDocument::undoStack怎么用?C++ MapDocument::undoStack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MapDocument
的用法示例。
在下文中一共展示了MapDocument::undoStack方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: contextMenuEvent
/**
* Shows the context menu for map objects. The menu allows you to duplicate and
* remove the map object, or do edit its properties.
*/
void MapObjectItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
if (!mIsEditable)
return;
QMenu menu;
QIcon dupIcon(QLatin1String(":images/16x16/stock-duplicate-16.png"));
QIcon delIcon(QLatin1String(":images/16x16/edit-delete.png"));
QIcon propIcon(QLatin1String(":images/16x16/document-properties.png"));
QAction *dupAction = menu.addAction(dupIcon, tr("&Duplicate"));
QAction *removeAction = menu.addAction(delIcon, tr("&Remove"));
menu.addSeparator();
QAction *propertiesAction = menu.addAction(propIcon, tr("&Properties..."));
Utils::setThemeIcon(removeAction, "edit-delete");
Utils::setThemeIcon(propertiesAction, "document-properties");
QAction *selectedAction = menu.exec(event->screenPos());
if (selectedAction == dupAction) {
MapDocument *doc = mMapDocument;
doc->undoStack()->push(new AddMapObject(doc,
mObject->objectGroup(),
mObject->clone()));
}
else if (selectedAction == removeAction) {
MapDocument *doc = mMapDocument;
doc->undoStack()->push(new RemoveMapObject(doc, mObject));
}
else if (selectedAction == propertiesAction) {
ObjectPropertiesDialog propertiesDialog(mMapDocument, mObject,
event->widget());
propertiesDialog.exec();
}
}
示例2: mousePressed
void SelectSameTileTool::mousePressed(QGraphicsSceneMouseEvent *event)
{
if (event->button() != Qt::LeftButton)
return;
const Qt::KeyboardModifiers modifiers = event->modifiers();
MapDocument *document = mapDocument();
QRegion selection = document->selectedArea();
if (modifiers == Qt::ShiftModifier)
selection += mSelectedRegion;
else if (modifiers == Qt::ControlModifier)
selection -= mSelectedRegion;
else if (modifiers == (Qt::ControlModifier | Qt::ShiftModifier))
selection &= mSelectedRegion;
else
selection = mSelectedRegion;
if (selection != document->selectedArea()) {
QUndoCommand *cmd = new ChangeSelectedArea(document, selection);
document->undoStack()->push(cmd);
}
}
示例3: mouseReleased
void TileSelectionTool::mouseReleased(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
mSelecting = false;
MapDocument *document = mapDocument();
QRegion selection = document->selectedArea();
const QRect area = selectedArea();
switch (mSelectionMode) {
case Replace: selection = area; break;
case Add: selection += area; break;
case Subtract: selection -= area; break;
case Intersect: selection &= area; break;
}
if (selection != document->selectedArea()) {
QUndoCommand *cmd = new ChangeSelectedArea(document, selection);
document->undoStack()->push(cmd);
}
brushItem()->setTileRegion(QRegion());
updateStatusInfo();
}
}
示例4: 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);
}
示例5: mouseReleaseEvent
void ResizeHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Handle::mouseReleaseEvent(event);
// If we resized the object, create an undo command
MapObject *obj = mMapObjectItem->mapObject();
if (event->button() == Qt::LeftButton && mOldSize != obj->size()) {
MapDocument *document = mMapObjectItem->mapDocument();
QUndoCommand *cmd = new ResizeMapObject(document, obj, mOldSize);
document->undoStack()->push(cmd);
}
}
示例6: mouseReleaseEvent
void MapObjectItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseReleaseEvent(event);
// If we got moved, create an undo command
if (event->button() == Qt::LeftButton
&& mOldObjectPos != mObject->position()) {
MapDocument *document = mMapDocument;
QUndoCommand *cmd = new MoveMapObject(document, mObject, mOldObjectPos);
document->undoStack()->push(cmd);
}
}
示例7: 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);
}
示例8: currentIndexChanged
void DocumentManager::currentIndexChanged()
{
if (mSceneWithTool) {
mSceneWithTool->disableSelectedTool();
mSceneWithTool = 0;
}
MapDocument *mapDocument = currentDocument();
if (mapDocument)
mUndoGroup->setActiveStack(mapDocument->undoStack());
emit currentDocumentChanged(mapDocument);
if (MapScene *mapScene = currentMapScene()) {
mapScene->setSelectedTool(mSelectedTool);
mapScene->enableSelectedTool();
mSceneWithTool = mapScene;
}
}
示例9: setTile
void TileCollisionDock::setTile(Tile *tile)
{
if (mTile == tile)
return;
mTile = tile;
mMapScene->disableSelectedTool();
MapDocument *previousDocument = mDummyMapDocument;
mMapView->setEnabled(tile);
if (tile) {
Map::Orientation orientation = Map::Orthogonal;
QSize tileSize = tile->size();
if (tile->tileset()->orientation() == Tileset::Isometric) {
orientation = Map::Isometric;
tileSize = tile->tileset()->gridSize();
}
Map *map = new Map(orientation, 1, 1, tileSize.width(), tileSize.height());
map->addTileset(tile->sharedTileset());
TileLayer *tileLayer = new TileLayer(QString(), 0, 0, 1, 1);
tileLayer->setCell(0, 0, Cell(tile));
map->addLayer(tileLayer);
ObjectGroup *objectGroup;
if (tile->objectGroup())
objectGroup = tile->objectGroup()->clone();
else
objectGroup = new ObjectGroup;
objectGroup->setDrawOrder(ObjectGroup::IndexOrder);
map->setNextObjectId(objectGroup->highestObjectId() + 1);
map->addLayer(objectGroup);
mDummyMapDocument = new MapDocument(map);
mDummyMapDocument->setCurrentLayer(objectGroup);
mMapScene->setMapDocument(mDummyMapDocument);
mToolManager->setMapDocument(mDummyMapDocument);
mMapScene->enableSelectedTool();
connect(mDummyMapDocument->undoStack(), &QUndoStack::indexChanged,
this, &TileCollisionDock::applyChanges);
connect(mDummyMapDocument, &MapDocument::selectedObjectsChanged,
this, &TileCollisionDock::selectedObjectsChanged);
} else {
mDummyMapDocument = nullptr;
mMapScene->setMapDocument(nullptr);
mToolManager->setMapDocument(nullptr);
}
emit dummyMapDocumentChanged(mDummyMapDocument);
setHasSelectedObjects(false);
if (previousDocument) {
// Explicitly disconnect early from this signal, since it can get fired
// from the QUndoStack destructor.
disconnect(previousDocument->undoStack(), &QUndoStack::indexChanged,
this, &TileCollisionDock::applyChanges);
delete previousDocument;
}
}