From cf7a0f715ea5f20ee5b3892fbf5ac0c888167566 Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Sat, 21 Apr 2018 13:46:06 +0300 Subject: [PATCH] Command macro for complete drag-editing operations. --- .../opencs/view/render/terraintexturemode.cpp | 38 +++++++++++++------ .../opencs/view/render/terraintexturemode.hpp | 2 +- apps/opencs/view/render/worldspacewidget.cpp | 6 +++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index baaae55be..f7f3b0631 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -196,8 +196,21 @@ void CSVRender::TerrainTextureMode::secondarySelectPressed(const WorldspaceHitRe bool CSVRender::TerrainTextureMode::primaryEditStartDrag (const QPoint& pos) { WorldspaceHitResult hit = getWorldspaceWidget().mousePick (pos, getWorldspaceWidget().getInteractionMask()); + + CSMDoc::Document& document = getWorldspaceWidget().getDocument(); + CSMWorld::IdTable& landTable = dynamic_cast ( + *document.getData().getTableModel (CSMWorld::UniversalId::Type_Land)); + CSMWorld::IdTable& ltexTable = dynamic_cast ( + *document.getData().getTableModel (CSMWorld::UniversalId::Type_LandTextures)); + + mCellId = getWorldspaceWidget().getCellId (hit.worldPos); + + QUndoStack& undoStack = document.getUndoStack(); + undoStack.beginMacro ("Edit texture records"); + undoStack.push (new CSMWorld::TouchLandCommand(landTable, ltexTable, mCellId)); editTerrainTextureGrid(hit); - return false; + + return true; } bool CSVRender::TerrainTextureMode::secondaryEditStartDrag (const QPoint& pos) @@ -215,10 +228,16 @@ bool CSVRender::TerrainTextureMode::secondarySelectStartDrag (const QPoint& pos) return false; } -void CSVRender::TerrainTextureMode::drag (const QPoint& pos, int diffX, int diffY, double speedFactor) { +void CSVRender::TerrainTextureMode::drag (const QPoint& pos, int diffX, int diffY, double speedFactor) +{ + WorldspaceHitResult hit = getWorldspaceWidget().mousePick (pos, getWorldspaceWidget().getInteractionMask()); + editTerrainTextureGrid(hit); } void CSVRender::TerrainTextureMode::dragCompleted(const QPoint& pos) { + CSMDoc::Document& document = getWorldspaceWidget().getDocument(); + QUndoStack& undoStack = document.getUndoStack(); + undoStack.endMacro(); } void CSVRender::TerrainTextureMode::dragAborted() { @@ -266,8 +285,6 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe CSMDoc::Document& document = getWorldspaceWidget().getDocument(); CSMWorld::IdTable& landTable = dynamic_cast ( *document.getData().getTableModel (CSMWorld::UniversalId::Type_Land)); - CSMWorld::IdTable& ltexTable = dynamic_cast ( - *document.getData().getTableModel (CSMWorld::UniversalId::Type_LandTextures)); int textureColumn = landTable.findColumnIndex(CSMWorld::Columns::ColumnId_LandTexturesIndex); @@ -284,7 +301,7 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe CSMWorld::LandTexturesColumn::DataType mPointer = landTable.data(landTable.getModelIndex(mCellId, textureColumn)).value(); CSMWorld::LandTexturesColumn::DataType mNew(mPointer); mNew[yHitInCell*landTextureSize+xHitInCell] = brushInt; - pushEditToCommand(mNew, document, landTable, ltexTable, mCellId); + pushEditToCommand(mNew, document, landTable, mCellId); } if (mBrushShape == 1) @@ -329,7 +346,7 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe } } } - pushEditToCommand(mNew, document, landTable, ltexTable, iteratedCellId); + pushEditToCommand(mNew, document, landTable, iteratedCellId); } } } @@ -386,7 +403,7 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe } } } - pushEditToCommand(mNew, document, landTable, ltexTable, iteratedCellId); + pushEditToCommand(mNew, document, landTable, iteratedCellId); } } } @@ -398,16 +415,15 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe } void CSVRender::TerrainTextureMode::pushEditToCommand(CSMWorld::LandTexturesColumn::DataType& newLandGrid, CSMDoc::Document& document, - CSMWorld::IdTable& landTable, CSMWorld::IdTable& ltexTable, std::string cellId) + CSMWorld::IdTable& landTable, std::string cellId) { QVariant changedLand; changedLand.setValue(newLandGrid); - CSMWorld::CommandMacro macro (document.getUndoStack(), "Edit texture records"); QModelIndex index(landTable.getModelIndex (cellId, landTable.findColumnIndex (CSMWorld::Columns::ColumnId_LandTexturesIndex))); - macro.push (new CSMWorld::TouchLandCommand(landTable, ltexTable, cellId)); - macro.push (new CSMWorld::ModifyCommand(landTable, index, changedLand)); + QUndoStack& undoStack = document.getUndoStack(); + undoStack.push (new CSMWorld::ModifyCommand(landTable, index, changedLand)); } void CSVRender::TerrainTextureMode::dragMoveEvent (QDragMoveEvent *event) { diff --git a/apps/opencs/view/render/terraintexturemode.hpp b/apps/opencs/view/render/terraintexturemode.hpp index 48b9aeb59..d8d27d045 100644 --- a/apps/opencs/view/render/terraintexturemode.hpp +++ b/apps/opencs/view/render/terraintexturemode.hpp @@ -113,7 +113,7 @@ namespace CSVRender void editTerrainTextureGrid (const WorldspaceHitResult& hit); void pushEditToCommand (CSMWorld::LandTexturesColumn::DataType& newLandGrid, CSMDoc::Document& document, - CSMWorld::IdTable& landTable, CSMWorld::IdTable& ltexTable, std::string cellId); + CSMWorld::IdTable& landTable, std::string cellId); private: TextureBrushWindow *textureBrushWindow; diff --git a/apps/opencs/view/render/worldspacewidget.cpp b/apps/opencs/view/render/worldspacewidget.cpp index f3b781080..c8ba16666 100644 --- a/apps/opencs/view/render/worldspacewidget.cpp +++ b/apps/opencs/view/render/worldspacewidget.cpp @@ -651,6 +651,12 @@ void CSVRender::WorldspaceWidget::mouseMoveEvent (QMouseEvent *event) mDragX = event->posF().x(); mDragY = height() - event->posF().y(); #endif + + if (mDragMode == InteractionType_PrimaryEdit) + { + EditMode& editMode = dynamic_cast (*mEditMode->getCurrent()); + editMode.drag (event->pos(), mDragX, mDragY, mDragFactor); // note: terraintexturemode only uses pos + } } } else