From 3fede6cb547b783377e833c9b269d4cecfe47e61 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 6 Sep 2019 20:27:33 +0200 Subject: Cleanup QtWidgets (tools) examples Cleanup QtWidgets tools examples: - use member-init (clang-tidy) - fix includes/don't include QtWidgets globally - include own header first - use nullptr (clang-tidy) - avoid c-style casts - use QVector instead QList - use QItemDelegate instead QStyledItemDelegate Change-Id: Ibe9440cdf711e5cc2138c054864edebe1fc95731 Reviewed-by: Paul Wicking --- examples/widgets/tools/undoframework/commands.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'examples/widgets/tools/undoframework/commands.cpp') diff --git a/examples/widgets/tools/undoframework/commands.cpp b/examples/widgets/tools/undoframework/commands.cpp index c3e7383de15..077d7eccaa5 100644 --- a/examples/widgets/tools/undoframework/commands.cpp +++ b/examples/widgets/tools/undoframework/commands.cpp @@ -48,19 +48,17 @@ ** ****************************************************************************/ -#include - #include "commands.h" #include "diagramitem.h" +#include + //! [0] MoveCommand::MoveCommand(DiagramItem *diagramItem, const QPointF &oldPos, - QUndoCommand *parent) - : QUndoCommand(parent) + QUndoCommand *parent) + : QUndoCommand(parent), myDiagramItem(diagramItem) + , myOldPos(oldPos), newPos(diagramItem->pos()) { - myDiagramItem = diagramItem; - newPos = diagramItem->pos(); - myOldPos = oldPos; } //! [0] @@ -71,7 +69,7 @@ bool MoveCommand::mergeWith(const QUndoCommand *command) DiagramItem *item = moveCommand->myDiagramItem; if (myDiagramItem != item) - return false; + return false; newPos = item->pos(); setText(QObject::tr("Move %1") @@ -102,9 +100,8 @@ void MoveCommand::redo() //! [4] DeleteCommand::DeleteCommand(QGraphicsScene *scene, QUndoCommand *parent) - : QUndoCommand(parent) + : QUndoCommand(parent), myGraphicsScene(scene) { - myGraphicsScene = scene; QList list = myGraphicsScene->selectedItems(); list.first()->setSelected(false); myDiagramItem = static_cast(list.first()); @@ -131,11 +128,10 @@ void DeleteCommand::redo() //! [7] AddCommand::AddCommand(DiagramItem::DiagramType addType, QGraphicsScene *scene, QUndoCommand *parent) - : QUndoCommand(parent) + : QUndoCommand(parent), myGraphicsScene(scene) { static int itemCount = 0; - myGraphicsScene = scene; myDiagramItem = new DiagramItem(addType); initialPosition = QPointF((itemCount * 15) % int(scene->width()), (itemCount * 15) % int(scene->height())); -- cgit v1.2.3