Skip to content

Commit 0f9014a

Browse files
committed
revision namespace 'cmd' (commands)
1 parent 4b0fb83 commit 0f9014a

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

src/commands.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
3-
* Copyright (c) 2022-2023 Jochen Meidow, Fraunhofer IOSB
3+
* Copyright (c) 2022-2025 Jochen Meidow, Fraunhofer IOSB
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -23,6 +23,9 @@
2323

2424
#include <QDebug>
2525
#include <QGraphicsItem>
26+
#include <QStringLiteral>
27+
#include <QUndoCommand>
28+
2629
#include <memory>
2730
#include <utility>
2831

@@ -42,7 +45,7 @@ AddStroke::AddStroke( State *curr,
4245
QUndoCommand *parent) : Undo(parent)
4346
{
4447
// qDebug() << Q_FUNC_INFO;
45-
setText( "add stroke" );
48+
setText( QStringLiteral("add stroke") );
4649
current_state_ = curr; // set pointer
4750
prev_state_ = std::move(p);
4851
next_state_ = std::move(n);
@@ -70,7 +73,7 @@ DeleteSelection::DeleteSelection( State *st,
7073
std::unique_ptr<State> & n,
7174
QUndoCommand *parent) : Undo(parent)
7275
{
73-
setText( QString("delete selected item%1")
76+
setText( QStringLiteral("delete selected item%1")
7477
.arg( scene()->selectedItems().size()==1 ? "" : "s") );
7578

7679
current_state_ = st; // pointer
@@ -96,7 +99,7 @@ void DeleteSelection::undo()
9699
TabulaRasa::TabulaRasa( State *st, QUndoCommand *parent ) : Undo(parent)
97100
{
98101
// qDebug() << Q_FUNC_INFO ;
99-
setText( "clear all" );
102+
setText( QStringLiteral("clear all") );
100103
current_state_ = st; // pointer
101104
prev_state_ = std::make_unique<State>(*st); // copy
102105
next_state_ = std::make_unique<State>();

src/commands.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
3-
* Copyright (c) 2022-2023 Jochen Meidow, Fraunhofer IOSB
3+
* Copyright (c) 2022-2025 Jochen Meidow, Fraunhofer IOSB
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -22,12 +22,13 @@
2222
#include <memory>
2323

2424
#include <QGraphicsScene>
25+
#include <QString>
2526
#include <QUndoCommand>
2627

2728
class State;
2829
namespace GUI {
2930
class MainScene;
30-
}
31+
} // namespace GUI
3132

3233

3334
//! Namespace for commands (und/redo)
@@ -42,20 +43,19 @@ class Undo : public QUndoCommand
4243
Undo & operator= (const Undo & other) = delete; //!< Copy assignment operator
4344
Undo & operator= (Undo && other) = delete; //!< Move assignment operator
4445

46+
//! Set pointer to scene
47+
static void setScene ( GUI::MainScene * sc) { s_scene = sc; }
48+
//! Get pointer to scene
49+
static GUI::MainScene * scene() { return s_scene; }
50+
4551
protected:
46-
Undo( QUndoCommand *parent=nullptr); //!< Standard constructor
47-
~Undo() override = default;
52+
explicit Undo( QUndoCommand *parent); //!< Standard constructor
53+
~Undo() = default;
4854

4955
State *current_state_{}; //!< Pointer to current state
5056
std::unique_ptr<State> next_state_; //!< Pointer to next state (redo)
5157
std::unique_ptr<State> prev_state_; //!< Pointer to previous state (undo)
5258

53-
public:
54-
//! Set pointer to scene
55-
static void setScene ( GUI::MainScene * sc) { s_scene = sc; }
56-
//! Get pointer to scene
57-
static GUI::MainScene * scene() { return s_scene; }
58-
5959
private:
6060
static GUI::MainScene *s_scene;
6161
};
@@ -69,7 +69,7 @@ class AddStroke : public Undo
6969
AddStroke( State *curr,
7070
std::unique_ptr<State> & p,
7171
std::unique_ptr<State> & n,
72-
QUndoCommand *parent=nullptr);
72+
QUndoCommand *parent);
7373
AddStroke( const AddStroke &) = delete;
7474
AddStroke( AddStroke &&) = delete;
7575
AddStroke operator= (const AddStroke &) = delete;
@@ -90,8 +90,7 @@ class DeleteSelection : public Undo
9090
DeleteSelection( State *st,
9191
std::unique_ptr<State> &p,
9292
std::unique_ptr<State> &n,
93-
QUndoCommand *parent=nullptr);
94-
93+
QUndoCommand *parent);
9594
private:
9695
void redo() override;
9796
void undo() override;
@@ -103,8 +102,7 @@ class TabulaRasa : public Undo
103102
{
104103
public:
105104
//! Value constructor
106-
TabulaRasa( State *st,
107-
QUndoCommand *parent=nullptr);
105+
TabulaRasa( State *st, QUndoCommand *parent);
108106
private:
109107
void redo() override;
110108
void undo() override;
@@ -119,7 +117,7 @@ class ReplaceStateWithFileContent : public Undo
119117
State *curr,
120118
std::unique_ptr<State> &p,
121119
std::unique_ptr<State> &n,
122-
QUndoCommand *parent=nullptr);
120+
QUndoCommand *parent);
123121
private:
124122
void redo() override;
125123
void undo() override;

src/mainwindow.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,8 @@ void MainWindow::readBinaryFile( const QString & fileName)
815815
fileInfo.fileName(),
816816
&curr_state,
817817
prev_state,
818-
next_state)
818+
next_state,
819+
nullptr)
819820
);
820821

821822
// setWindowModified( false );
@@ -826,7 +827,7 @@ void MainWindow::readBinaryFile( const QString & fileName)
826827
void MainWindow::slotCmdTabulaRasa()
827828
{
828829
m_undoStack->push(
829-
new Cmd::TabulaRasa( &curr_state )
830+
new Cmd::TabulaRasa( &curr_state, nullptr )
830831
);
831832

832833
setWindowModified( true );
@@ -859,7 +860,8 @@ void MainWindow::slotCmdAddStroke( QPainterPath *path)
859860
m_undoStack->push(
860861
new Cmd::AddStroke( &curr_state,
861862
prev_state_,
862-
next_state_)
863+
next_state_,
864+
nullptr)
863865
);
864866
setWindowModified( true );
865867
}
@@ -883,7 +885,7 @@ void MainWindow::slotCmdDeleteSelection()
883885
m_undoStack->push(
884886
new Cmd::DeleteSelection( &curr_state,
885887
prev_state_,
886-
next_state_)
888+
next_state_, nullptr)
887889
);
888890
setWindowModified( true );
889891
}

0 commit comments

Comments
 (0)