当前位置: 首页>>代码示例>>C++>>正文


C++ QUndoStack类代码示例

本文整理汇总了C++中QUndoStack的典型用法代码示例。如果您正苦于以下问题:C++ QUndoStack类的具体用法?C++ QUndoStack怎么用?C++ QUndoStack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QUndoStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: toggleOtherLayers

void LayerModel::toggleOtherLayers(int layerIndex)
{
    if (mMap->layerCount() <= 1) // No other layers
        return;

    bool visibility = true;
    for (int i = 0; i < mMap->layerCount(); i++) {
        if (i == layerIndex)
            continue;

        Layer *layer = mMap->layerAt(i);
        if (layer->isVisible()) {
            visibility = false;
            break;
        }
    }

    QUndoStack *undoStack = mMapDocument->undoStack();
    if (visibility)
        undoStack->beginMacro(tr("Show Other Layers"));
    else
        undoStack->beginMacro(tr("Hide Other Layers"));

    for (int i = 0; i < mMap->layerCount(); i++) {
        if (i == layerIndex)
            continue;

        if (visibility != mMap->layerAt(i)->isVisible())
            undoStack->push(new SetLayerVisible(mMapDocument, i, visibility));
    }

    undoStack->endMacro();
}
开发者ID:jaman1020,项目名称:tiled,代码行数:33,代码来源:layermodel.cpp

示例2: ChangeProperties

void PropertiesDock::pasteProperties()
{
    auto clipboardManager = ClipboardManager::instance();

    Properties pastedProperties = clipboardManager->properties();
    if (pastedProperties.isEmpty())
        return;

    const QList<Object *> objects = mDocument->currentObjects();
    if (objects.isEmpty())
        return;

    QList<QUndoCommand*> commands;

    for (Object *object : objects) {
        Properties properties = object->properties();
        properties.merge(pastedProperties);

        if (object->properties() != properties) {
            commands.append(new ChangeProperties(mDocument, QString(), object,
                                                 properties));
        }
    }

    if (!commands.isEmpty()) {
        QUndoStack *undoStack = mDocument->undoStack();
        undoStack->beginMacro(tr("Paste Property/Properties", nullptr,
                                 pastedProperties.size()));

        for (QUndoCommand *command : commands)
            undoStack->push(command);

        undoStack->endMacro();
    }
}
开发者ID:ihuangx,项目名称:tiled,代码行数:35,代码来源:propertiesdock.cpp

示例3: applyImageLayerValue

void PropertyBrowser::applyImageLayerValue(PropertyId id, const QVariant &val)
{
    ImageLayer *imageLayer = static_cast<ImageLayer*>(mObject);
    QUndoStack *undoStack = mMapDocument->undoStack();

    switch (id) {
    case ImageSourceProperty: {
        const QString imageSource = val.toString();
        const QColor &color = imageLayer->transparentColor();
        undoStack->push(new ChangeImageLayerProperties(mMapDocument,
                                                       imageLayer,
                                                       color,
                                                       imageSource));
        break;
    }
    case ColorProperty: {
        QColor color = val.value<QColor>();
        if (color == Qt::gray)
            color = QColor();

        const QString &imageSource = imageLayer->imageSource();
        undoStack->push(new ChangeImageLayerProperties(mMapDocument,
                                                       imageLayer,
                                                       color,
                                                       imageSource));
        break;
    }
    default:
        break;
    }
}
开发者ID:josephbleau,项目名称:tiled,代码行数:31,代码来源:propertybrowser.cpp

示例4: formWindow

void ButtonTaskMenu::createGroup()
{
    QDesignerFormWindowInterface *fw = formWindow();
    const ButtonList bl = buttonList(fw->cursor());
    // Do we need to remove the buttons from an existing group?
    QUndoCommand *removeCmd = 0;
    if (bl.front()->group()) {
        removeCmd = createRemoveButtonsCommand(fw, bl);
        if (!removeCmd)
            return;
    }
    // Add cmd
    CreateButtonGroupCommand *addCmd = new CreateButtonGroupCommand(fw);
    if (!addCmd->init(bl)) {
        qWarning("** WARNING Failed to initialize CreateButtonGroupCommand!");
        delete addCmd;
        return;
    }
    // Need a macro [even if we only have the add command] since the command might trigger additional commands
    QUndoStack *history = fw->commandHistory();
    history->beginMacro(addCmd->text());
    if (removeCmd)
        history->push(removeCmd);
    history->push(addCmd);
    history->endMacro();
}
开发者ID:phen89,项目名称:rtqt,代码行数:26,代码来源:button_taskmenu.cpp

示例5: delete_

void MapDocumentActionHandler::delete_()
{
    if (!mMapDocument)
        return;

    Layer *currentLayer = mMapDocument->currentLayer();
    if (!currentLayer)
        return;

    TileLayer *tileLayer = dynamic_cast<TileLayer*>(currentLayer);
    const QRegion &selectedArea = mMapDocument->selectedArea();
    const QList<MapObject*> &selectedObjects = mMapDocument->selectedObjects();

    QUndoStack *undoStack = mMapDocument->undoStack();
    undoStack->beginMacro(tr("Delete"));

    if (tileLayer && !selectedArea.isEmpty()) {
        undoStack->push(new EraseTiles(mMapDocument, tileLayer, selectedArea));
    } else if (!selectedObjects.isEmpty()) {
        foreach (MapObject *mapObject, selectedObjects)
            undoStack->push(new RemoveMapObject(mMapDocument, mapObject));
    }

    selectNone();
    undoStack->endMacro();
}
开发者ID:Y-way,项目名称:tiled,代码行数:26,代码来源:mapdocumentactionhandler.cpp

示例6: groupIndexesByObject

void EditPolygonTool::splitSegments()
{
    if (mSelectedHandles.size() < 2)
        return;

    const PointIndexesByObject p = groupIndexesByObject(mSelectedHandles);
    QMapIterator<MapObject*, RangeSet<int> > i(p);

    QUndoStack *undoStack = mapDocument()->undoStack();
    bool macroStarted = false;

    while (i.hasNext()) {
        MapObject *object = i.next().key();
        const RangeSet<int> &indexRanges = i.value();

        const bool closed = object->shape() == MapObject::Polygon;
        QPolygonF oldPolygon = object->polygon();
        QPolygonF newPolygon = splitPolygonSegments(oldPolygon, indexRanges,
                                                    closed);

        if (newPolygon.size() > oldPolygon.size()) {
            if (!macroStarted) {
                undoStack->beginMacro(tr("Split Segments"));
                macroStarted = true;
            }

            undoStack->push(new ChangePolygon(mapDocument(), object,
                                              newPolygon,
                                              oldPolygon));
        }
    }

    if (macroStarted)
        undoStack->endMacro();
}
开发者ID:Shorttail,项目名称:tiled,代码行数:35,代码来源:editpolygontool.cpp

示例7: initializeActions

void SCgMainWindow::initializeActions()
{
    QUndoStack* undoStack = mScene->undoStack();

    QAction* actionRedo = undoStack->createRedoAction(mScene);
    actionRedo->setShortcut(QKeySequence::Redo);
//    actionRedo->setShortcutContext(Qt::WidgetShortcut);

    QAction* actionUndo = undoStack->createUndoAction(mScene);
    actionUndo->setShortcut(QKeySequence::Undo);
//    actionUndo->setShortcutContext(Qt::WidgetShortcut);

    QAction* actionDelete = new QAction("Delete", mScene);
    actionDelete->setShortcut(QKeySequence::Delete);
    connect(actionDelete, SIGNAL(triggered()), mInputHandler, SLOT(deleteSelected()));
    actionDelete->setShortcutContext(Qt::WidgetShortcut);

    QAction* actionDeleteJustContour = new QAction("Delete just contour", mScene);
    actionDeleteJustContour->setShortcut( QKeySequence(tr("Backspace")) );
    connect(actionDeleteJustContour, SIGNAL(triggered()), mInputHandler, SLOT(deleteJustContour()));
    actionDeleteJustContour->setShortcutContext(Qt::WidgetShortcut);

    mView->addAction(actionDeleteJustContour);
    mView->addAction(actionDelete);
    mView->addAction(actionRedo);
    mView->addAction(actionUndo);
}
开发者ID:asvitenkov,项目名称:sui,代码行数:27,代码来源:scgmainwindow.cpp

示例8: accept

void ImageLayerPropertiesDialog::accept()
{
    QUndoStack *undoStack = mMapDocument->undoStack();

    const QColor newColor = mColorButton->color() != Qt::gray
        ? mColorButton->color()
        : QColor();

    const QString newPath = mImage->text();
    const bool localChanges = newColor != mImageLayer->transparentColor() ||
            newPath != mImageLayer->imageSource();

    if (localChanges) {
        undoStack->beginMacro(QCoreApplication::translate(
            "Undo Commands",
            "Change Image Layer Properties"));

        undoStack->push(new ChangeImageLayerProperties(
                            mMapDocument,
                            mImageLayer,
                            newColor,
                            newPath));
    }

    PropertiesDialog::accept();

    if (localChanges)
        undoStack->endMacro();
}
开发者ID:277473242,项目名称:tiled,代码行数:29,代码来源:imagelayerpropertiesdialog.cpp

示例9: eraseRegionObjectGroup

void eraseRegionObjectGroup(MapDocument *mapDocument,
                            ObjectGroup *layer,
                            const QRegion &where)
{
    QUndoStack *undo = mapDocument->undoStack();

    const auto objects = layer->objects();
    for (MapObject *obj : objects) {
        // TODO: we are checking bounds, which is only correct for rectangles and
        // tile objects. polygons and polylines are not covered correctly by this
        // erase method (we are in fact deleting too many objects)
        // TODO2: toAlignedRect may even break rects.

        // Convert the boundary of the object into tile space
        const QRectF objBounds = obj->boundsUseTile();
        QPointF tl = mapDocument->renderer()->pixelToTileCoords(objBounds.topLeft());
        QPointF tr = mapDocument->renderer()->pixelToTileCoords(objBounds.topRight());
        QPointF br = mapDocument->renderer()->pixelToTileCoords(objBounds.bottomRight());
        QPointF bl = mapDocument->renderer()->pixelToTileCoords(objBounds.bottomLeft());

        QRectF objInTileSpace;
        objInTileSpace.setTopLeft(tl);
        objInTileSpace.setTopRight(tr);
        objInTileSpace.setBottomRight(br);
        objInTileSpace.setBottomLeft(bl);

        const QRect objAlignedRect = objInTileSpace.toAlignedRect();
        if (where.intersects(objAlignedRect))
            undo->push(new RemoveMapObject(mapDocument, obj));
    }
}
开发者ID:Bertram25,项目名称:tiled,代码行数:31,代码来源:automappingutils.cpp

示例10: currentTileset

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);
}
开发者ID:Shorttail,项目名称:tiled,代码行数:27,代码来源:tilesetdock.cpp

示例11: removeProperties

void PropertiesDock::removeProperties()
{
    Object *object = mDocument->currentObject();
    if (!object)
        return;

    const QList<QtBrowserItem*> items = mPropertyBrowser->selectedItems();
    if (items.isEmpty() || !mPropertyBrowser->allCustomPropertyItems(items))
        return;

    QStringList propertyNames;
    for (QtBrowserItem *item : items)
        propertyNames.append(item->property()->propertyName());

    QUndoStack *undoStack = mDocument->undoStack();
    undoStack->beginMacro(tr("Remove Property/Properties", nullptr,
                             propertyNames.size()));

    for (const QString &name : propertyNames) {
        undoStack->push(new RemoveProperty(mDocument,
                                           mDocument->currentObjects(),
                                           name));
    }

    undoStack->endMacro();
}
开发者ID:ihuangx,项目名称:tiled,代码行数:26,代码来源:propertiesdock.cpp

示例12: accept

void MapPropertiesDialog::accept()
{
    int format = mLayerDataCombo->currentIndex();
    if (format == -1) {
        // this shouldn't happen!
        format = 0;
    }

    Map::LayerDataFormat newLayerDataFormat = static_cast<Map::LayerDataFormat>(format - 1);

    QUndoStack *undoStack = mMapDocument->undoStack();

    QColor newColor = mColorButton->color();
    if (newColor == Qt::darkGray)
        newColor = QColor();

    const Map *map = mMapDocument->map();
    bool localChanges = newColor != map->backgroundColor() ||
            newLayerDataFormat != map->layerDataFormat();

    if (localChanges) {
        undoStack->beginMacro(QCoreApplication::translate(
            "Undo Commands",
            "Change Map Properties"));

        undoStack->push(new ChangeMapProperties(mMapDocument,
                                                newColor,
                                                newLayerDataFormat));
    }

    PropertiesDialog::accept();

    if (localChanges)
        undoStack->endMacro();
}
开发者ID:277473242,项目名称:tiled,代码行数:35,代码来源:mappropertiesdialog.cpp

示例13: swapTiles

void TilesetDock::swapTiles(Tile *tileA, Tile *tileB)
{
    if (!mMapDocument)
        return;

    QUndoStack *undoStack = mMapDocument->undoStack();
    undoStack->push(new SwapTiles(mMapDocument, tileA, tileB));
}
开发者ID:Shorttail,项目名称:tiled,代码行数:8,代码来源:tilesetdock.cpp

示例14: scene

  void ReactionArrowTool::mousePressEvent(QGraphicsSceneMouseEvent *event)
  {
    QPointF downPos = event->buttonDownScenePos(event->button());
    QUndoStack *stack = scene()->stack();

    ReactionArrow *arrow = new ReactionArrow;
    stack->push(new AddItem(arrow, scene()));
    arrow->setPos(downPos);
  }
开发者ID:timvdm,项目名称:Molsketch,代码行数:9,代码来源:reactionarrowtool.cpp

示例15: initialize

void RedoOperation::initialize(IServiceLocator *serviceLocator)
{
    QUndoStackAdapter* adapter = serviceLocator->locate<QUndoStackAdapter>();
    QUndoStack *stack = adapter->wrappedStack();

    m_action = stack->createRedoAction(this);
    setEnabled(m_action->isEnabled());

    connect(m_action, &QAction::changed, this, &RedoOperation::onActionChanged);
}
开发者ID:yudjin87,项目名称:tour_du_monde,代码行数:10,代码来源:RedoOperation.cpp


注:本文中的QUndoStack类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。