summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2022-07-19 18:24:27 +0200
committerJarek Kobus <jaroslaw.kobus@qt.io>2022-07-19 20:17:20 +0000
commit7f4363e51aadce3ac27a66ffe2db662eb30650e3 (patch)
tree189f8f5dea5c66be0cb80cc60d70870d3c646cdd /src
parent52e649cf53d7e11183fc3e92a52158352acf1531 (diff)
downloadqt-creator-7f4363e51aadce3ac27a66ffe2db662eb30650e3.tar.gz
VcsBaseEditorWidget: Get rid of DiffChunkAction struct
Change-Id: Ia35a8ef6b836709f7e058cfe33bf902f015e89b9 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/vcsbase/vcsbaseeditor.cpp45
-rw-r--r--src/plugins/vcsbase/vcsbaseeditor.h2
2 files changed, 15 insertions, 32 deletions
diff --git a/src/plugins/vcsbase/vcsbaseeditor.cpp b/src/plugins/vcsbase/vcsbaseeditor.cpp
index 21d46e99a5..92d2f967fa 100644
--- a/src/plugins/vcsbase/vcsbaseeditor.cpp
+++ b/src/plugins/vcsbase/vcsbaseeditor.cpp
@@ -128,24 +128,8 @@ QByteArray DiffChunk::asPatch(const QString &workingDirectory) const
return rc;
}
-namespace Internal {
-
-// Data to be passed to apply/revert diff chunk actions.
-class DiffChunkAction
-{
-public:
- DiffChunkAction(const DiffChunk &dc = DiffChunk(), bool revertIn = false) :
- chunk(dc), revert(revertIn) {}
-
- DiffChunk chunk;
- bool revert;
-};
-
-} // namespace Internal
} // namespace VcsBase
-Q_DECLARE_METATYPE(VcsBase::Internal::DiffChunkAction)
-
namespace VcsBase {
/*!
@@ -1015,12 +999,14 @@ void VcsBaseEditorWidget::contextMenuEvent(QContextMenuEvent *e)
// the user has "Open With" and choose the right diff editor so that
// fileNameFromDiffSpecification() works.
QAction *applyAction = menu->addAction(tr("Apply Chunk..."));
- applyAction->setData(QVariant::fromValue(Internal::DiffChunkAction(chunk, false)));
- connect(applyAction, &QAction::triggered, this, &VcsBaseEditorWidget::slotApplyDiffChunk);
+ connect(applyAction, &QAction::triggered, this, [this, chunk] {
+ slotApplyDiffChunk(chunk, false);
+ });
// Revert a chunk from a VCS diff, which might be linked to reloading the diff.
QAction *revertAction = menu->addAction(tr("Revert Chunk..."));
- revertAction->setData(QVariant::fromValue(Internal::DiffChunkAction(chunk, true)));
- connect(revertAction, &QAction::triggered, this, &VcsBaseEditorWidget::slotApplyDiffChunk);
+ connect(revertAction, &QAction::triggered, this, [this, chunk] {
+ slotApplyDiffChunk(chunk, true);
+ });
// Custom diff actions
addDiffActions(menu, chunk);
break;
@@ -1624,22 +1610,19 @@ bool VcsBaseEditorWidget::hasDiff() const
}
}
-void VcsBaseEditorWidget::slotApplyDiffChunk()
+void VcsBaseEditorWidget::slotApplyDiffChunk(const DiffChunk &chunk, bool revert)
{
- const QAction *a = qobject_cast<QAction *>(sender());
- QTC_ASSERT(a, return);
- const Internal::DiffChunkAction chunkAction = qvariant_cast<Internal::DiffChunkAction>(a->data());
- const QString title = chunkAction.revert ? tr("Revert Chunk") : tr("Apply Chunk");
- const QString question = chunkAction.revert ?
- tr("Would you like to revert the chunk?") : tr("Would you like to apply the chunk?");
+ const QString title = revert ? tr("Revert Chunk") : tr("Apply Chunk");
+ const QString question = revert ? tr("Would you like to revert the chunk?")
+ : tr("Would you like to apply the chunk?");
if (QMessageBox::No == QMessageBox::question(this, title, question, QMessageBox::Yes|QMessageBox::No))
return;
- if (applyDiffChunk(chunkAction.chunk, chunkAction.revert)) {
- if (chunkAction.revert)
- emit diffChunkReverted(chunkAction.chunk);
+ if (applyDiffChunk(chunk, revert)) {
+ if (revert)
+ emit diffChunkReverted(chunk);
else
- emit diffChunkApplied(chunkAction.chunk);
+ emit diffChunkApplied(chunk);
}
}
diff --git a/src/plugins/vcsbase/vcsbaseeditor.h b/src/plugins/vcsbase/vcsbaseeditor.h
index 99dc64a0ac..51f6f57208 100644
--- a/src/plugins/vcsbase/vcsbaseeditor.h
+++ b/src/plugins/vcsbase/vcsbaseeditor.h
@@ -274,7 +274,7 @@ private:
void slotJumpToEntry(int);
void slotCursorPositionChanged() override;
void slotAnnotateRevision(const QString &change);
- void slotApplyDiffChunk();
+ void slotApplyDiffChunk(const DiffChunk &chunk, bool revert);
void slotPaste();
void showProgressIndicator();
void hideProgressIndicator();