diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..f7b1523 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,18 @@ +Checks: > + readability-qt6-parent-child-check, + cppcoreguidelines*, + performance*, + readability-identifier-naming, + modernize-use-list-initialization, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-special-member-functions, + -performance-enum-size, + -cppcoreguidelines-non-private-member-variables-in-classes + +HeaderFilterRegex: '.*' + +CheckOptions: + - key: modernize-use-list-initialization.StrictMode + value: 'true' diff --git a/flake.lock b/flake.lock index e39a79d..1aa1f32 100644 --- a/flake.lock +++ b/flake.lock @@ -1,71 +1,103 @@ { - "nodes" : { - "flake-compat" : { - "flake" : false, - "locked" : { - "lastModified" : 1747046372, - "narHash" : "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=", - "owner" : "edolstra", - "repo" : "flake-compat", - "rev" : "9100a0f413b0c601e0533d1d94ffd501ce2e7885", - "type" : "github" - }, - "original" : {"owner" : "edolstra", "repo" : "flake-compat", "type" : "github"} - }, - "git-hooks" : { - "inputs" : { - "flake-compat" : "flake-compat", - "gitignore" : "gitignore", - "nixpkgs" : ["nixpkgs"] - }, - "locked" : { - "lastModified" : 1763032142, - "narHash" : "sha256-M+2QBQoC0lzkCdUQRXylR2RkcT6BCRfW3KDs+c/IGLw=", - "owner" : "cachix", - "repo" : "git-hooks.nix", - "rev" : "84255025dee4c8701a99fbff65ac3c9095952f99", - "type" : "github" - }, - "original" : {"owner" : "cachix", "repo" : "git-hooks.nix", "type" : "github"} - }, - "gitignore" : { - "inputs" : {"nixpkgs" : [ "git-hooks", "nixpkgs" ]}, - "locked" : { - "lastModified" : 1709087332, - "narHash" : "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", - "owner" : "hercules-ci", - "repo" : "gitignore.nix", - "rev" : "637db329424fd7e46cf4185293b9cc8c88c95394", - "type" : "github" - }, - "original" : {"owner" : "hercules-ci", "repo" : "gitignore.nix", "type" : "github"} - }, - "nixpkgs" : { - "locked" : { - "lastModified" : 1763049705, - "narHash" : "sha256-A5LS0AJZ1yDPTa2fHxufZN++n8MCmtgrJDtxFxrH4S8=", - "owner" : "NixOS", - "repo" : "nixpkgs", - "rev" : "3acb677ea67d4c6218f33de0db0955f116b7588c", - "type" : "github" - }, - "original" : - {"owner" : "NixOS", "ref" : "nixos-25.05", "repo" : "nixpkgs", "type" : "github"} - }, - "root" : - {"inputs" : {"git-hooks" : "git-hooks", "nixpkgs" : "nixpkgs", "systems" : "systems"}}, - "systems" : { - "locked" : { - "lastModified" : 1681028828, - "narHash" : "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner" : "nix-systems", - "repo" : "default", - "rev" : "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type" : "github" - }, - "original" : {"owner" : "nix-systems", "repo" : "default", "type" : "github"} - } + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1761588595, + "narHash": "sha256-XKUZz9zewJNUj46b4AJdiRZJAvSZ0Dqj2BNfXvFlJC4=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "f387cd2afec9419c8ee37694406ca490c3f34ee5", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } }, - "root" : "root", - "version" : 7 + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1763988335, + "narHash": "sha256-QlcnByMc8KBjpU37rbq5iP7Cp97HvjRP0ucfdh+M4Qc=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "50b9238891e388c9fdc6a5c49e49c42533a1b5ce", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1764560356, + "narHash": "sha256-M5aFEFPppI4UhdOxwdmceJ9bDJC4T6C6CzCK1E2FZyo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6c8f0cca84510cc79e09ea99a299c9bc17d03cb6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-25.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 } diff --git a/flake.nix b/flake.nix index 5122bce..5144466 100644 --- a/flake.nix +++ b/flake.nix @@ -40,6 +40,8 @@ qt6.qtbase qtcreator + python3 + llvmPackages_latest.clang-tools cmake bear entr diff --git a/src/canvas/canvas.cpp b/src/canvas/canvas.cpp index 42d419c..ae5e5c0 100644 --- a/src/canvas/canvas.cpp +++ b/src/canvas/canvas.cpp @@ -23,9 +23,9 @@ #include // PUBLIC -Canvas::Canvas(QWidget *parent) : QWidget{parent} { +Canvas::Canvas(QWidget *parent) : QWidget{parent}, m_maxSize(m_sizeHint) { m_sizeHint = screen()->size() * m_scale; - m_maxSize = m_sizeHint; + m_canvas = new QPixmap(m_sizeHint); m_overlay = new QPixmap(m_sizeHint); diff --git a/src/canvas/canvas.hpp b/src/canvas/canvas.hpp index caf6d4c..c99e7dc 100644 --- a/src/canvas/canvas.hpp +++ b/src/canvas/canvas.hpp @@ -26,7 +26,7 @@ class Canvas : public QWidget { public: explicit Canvas(QWidget *parent = nullptr); - ~Canvas(); + ~Canvas() override; QPixmap *const canvas() const; QPixmap *const overlay() const; diff --git a/src/command/command.hpp b/src/command/command.hpp index 03d3fcb..9691a47 100644 --- a/src/command/command.hpp +++ b/src/command/command.hpp @@ -22,6 +22,7 @@ class ApplicationContext; class Command { public: + virtual ~Command() = default; virtual void execute(ApplicationContext *context) = 0; virtual void undo(ApplicationContext *context) = 0; }; diff --git a/src/command/commandhistory.cpp b/src/command/commandhistory.cpp index c418c4b..0fafeeb 100644 --- a/src/command/commandhistory.cpp +++ b/src/command/commandhistory.cpp @@ -58,7 +58,7 @@ void CommandHistory::redo() { m_redoStack->pop_front(); } -void CommandHistory::insert(std::shared_ptr command) { +void CommandHistory::insert(const std::shared_ptr& command) { while (!m_redoStack->empty()) { m_redoStack->pop_front(); } diff --git a/src/command/commandhistory.hpp b/src/command/commandhistory.hpp index 62bf3e3..d5ab0bd 100644 --- a/src/command/commandhistory.hpp +++ b/src/command/commandhistory.hpp @@ -31,7 +31,7 @@ class CommandHistory { void undo(); void redo(); - void insert(std::shared_ptr command); + void insert(const std::shared_ptr& command); static constexpr int maxCommands{100}; // arbitrary diff --git a/src/command/deselectcommand.cpp b/src/command/deselectcommand.cpp index acf4bcb..cda5b30 100644 --- a/src/command/deselectcommand.cpp +++ b/src/command/deselectcommand.cpp @@ -18,6 +18,8 @@ #include "deselectcommand.hpp" +#include + #include "../context/applicationcontext.hpp" #include "../context/coordinatetransformer.hpp" #include "../context/selectioncontext.hpp" @@ -25,16 +27,13 @@ #include "../item/item.hpp" #include "../data-structures/cachegrid.hpp" -DeselectCommand::DeselectCommand(QVector> items) : ItemCommand{items} {} - -DeselectCommand::~DeselectCommand() { -} +DeselectCommand::DeselectCommand(QVector> items) : ItemCommand{std::move(items)} {} void DeselectCommand::execute(ApplicationContext *context) { auto &selectedItems{context->selectionContext().selectedItems()}; QRectF dirtyRegion{}; - for (const auto item : m_items) { + for (const auto& item : m_items) { dirtyRegion |= item->boundingBox(); selectedItems.erase(item); } @@ -46,7 +45,7 @@ void DeselectCommand::undo(ApplicationContext *context) { auto &selectedItems{context->selectionContext().selectedItems()}; QRectF dirtyRegion{}; - for (const auto item : m_items) { + for (const auto& item : m_items) { dirtyRegion |= item->boundingBox(); selectedItems.insert(item); } diff --git a/src/command/deselectcommand.hpp b/src/command/deselectcommand.hpp index 661c116..0b7af26 100644 --- a/src/command/deselectcommand.hpp +++ b/src/command/deselectcommand.hpp @@ -25,7 +25,6 @@ class ApplicationContext; class DeselectCommand : public ItemCommand { public: DeselectCommand(QVector> items); - ~DeselectCommand(); void execute(ApplicationContext *context) override; void undo(ApplicationContext *context) override; diff --git a/src/command/groupcommand.cpp b/src/command/groupcommand.cpp index 3882dc6..0c560ab 100644 --- a/src/command/groupcommand.cpp +++ b/src/command/groupcommand.cpp @@ -18,6 +18,8 @@ #include "groupcommand.hpp" +#include + #include "commandhistory.hpp" #include "selectcommand.hpp" #include "deselectcommand.hpp" @@ -29,21 +31,18 @@ #include "../data-structures/quadtree.hpp" #include "../item/group.hpp" -GroupCommand::GroupCommand(QVector> items) : ItemCommand{items} { +GroupCommand::GroupCommand(QVector> items) : ItemCommand{std::move(items)} { m_group = std::make_shared(); // sort according to z order ApplicationContext::instance()->spatialContext().quadtree().reorder(m_items); } -GroupCommand::~GroupCommand() { -} - void GroupCommand::execute(ApplicationContext *context) { auto &quadtree{context->spatialContext().quadtree()}; auto &selectedItems{context->selectionContext().selectedItems()}; - for (const auto item : m_items) { + for (const auto& item : m_items) { quadtree.deleteItem(item, false); } @@ -63,7 +62,7 @@ void GroupCommand::undo(ApplicationContext *context) { quadtree.deleteItem(m_group); selectedItems.clear(); - for (const auto item : m_items) { + for (const auto& item : m_items) { selectedItems.insert(item); quadtree.insertItem(item, false); } diff --git a/src/command/groupcommand.hpp b/src/command/groupcommand.hpp index 69ccb2c..8d6fda3 100644 --- a/src/command/groupcommand.hpp +++ b/src/command/groupcommand.hpp @@ -26,7 +26,6 @@ class GroupItem; class GroupCommand : public ItemCommand { public: GroupCommand(QVector> items); - ~GroupCommand(); void execute(ApplicationContext *context) override; void undo(ApplicationContext *context) override; diff --git a/src/command/insertitemcommand.cpp b/src/command/insertitemcommand.cpp index e755274..b01b088 100644 --- a/src/command/insertitemcommand.cpp +++ b/src/command/insertitemcommand.cpp @@ -18,6 +18,8 @@ #include "insertitemcommand.hpp" +#include + #include "../context/applicationcontext.hpp" #include "../context/coordinatetransformer.hpp" #include "../context/selectioncontext.hpp" @@ -25,10 +27,7 @@ #include "../data-structures/cachegrid.hpp" #include "../data-structures/quadtree.hpp" -InsertItemCommand::InsertItemCommand(QVector> items) : ItemCommand{items} { -} - -InsertItemCommand::~InsertItemCommand() { +InsertItemCommand::InsertItemCommand(QVector> items) : ItemCommand{std::move(items)} { } void InsertItemCommand::execute(ApplicationContext *context) { diff --git a/src/command/insertitemcommand.hpp b/src/command/insertitemcommand.hpp index 87a3fb7..d854fa4 100644 --- a/src/command/insertitemcommand.hpp +++ b/src/command/insertitemcommand.hpp @@ -24,7 +24,6 @@ class ApplicationContext; class InsertItemCommand : public ItemCommand { public: InsertItemCommand(QVector> items); - ~InsertItemCommand(); void execute(ApplicationContext *context) override; void undo(ApplicationContext *context) override; diff --git a/src/command/itemcommand.cpp b/src/command/itemcommand.cpp index d3dcafc..94b5ea6 100644 --- a/src/command/itemcommand.cpp +++ b/src/command/itemcommand.cpp @@ -19,8 +19,9 @@ #include "itemcommand.hpp" #include +#include -ItemCommand::ItemCommand(QVector> items) : m_items{items} { +ItemCommand::ItemCommand(QVector> items) : m_items{std::move(items)} { } ItemCommand::~ItemCommand() { diff --git a/src/command/itemcommand.hpp b/src/command/itemcommand.hpp index 025b474..bb0d56d 100644 --- a/src/command/itemcommand.hpp +++ b/src/command/itemcommand.hpp @@ -28,7 +28,7 @@ class Item; class ItemCommand : public Command { public: ItemCommand(QVector> items); - ~ItemCommand(); + ~ItemCommand() override; protected: QVector> m_items; diff --git a/src/command/moveitemcommand.cpp b/src/command/moveitemcommand.cpp index d75105f..6b3b6b6 100644 --- a/src/command/moveitemcommand.cpp +++ b/src/command/moveitemcommand.cpp @@ -18,16 +18,16 @@ #include "moveitemcommand.hpp" -#include "../common/constants.hpp" +#include + #include "../context/applicationcontext.hpp" #include "../context/coordinatetransformer.hpp" #include "../context/spatialcontext.hpp" #include "../data-structures/cachegrid.hpp" -#include "../data-structures/quadtree.hpp" #include "../item/item.hpp" MoveItemCommand::MoveItemCommand(QVector> items, QPointF delta) - : ItemCommand{items}, + : ItemCommand{std::move(items)}, m_delta{delta} { } @@ -37,8 +37,6 @@ void MoveItemCommand::execute(ApplicationContext *context) { auto &cacheGrid{context->spatialContext().cacheGrid()}; for (auto &item : m_items) { - QRect dirtyRegion{transformer.worldToGrid(item->boundingBox()).toRect()}; - cacheGrid.markDirty(transformer.worldToGrid(item->boundingBox()).toRect()); item->translate(m_delta); cacheGrid.markDirty(transformer.worldToGrid(item->boundingBox()).toRect()); @@ -51,8 +49,6 @@ void MoveItemCommand::undo(ApplicationContext *context) { auto &cacheGrid{context->spatialContext().cacheGrid()}; for (auto &item : m_items) { - QRect dirtyRegion{transformer.worldToGrid(item->boundingBox()).toRect()}; - cacheGrid.markDirty(transformer.worldToGrid(item->boundingBox()).toRect()); item->translate(-m_delta); cacheGrid.markDirty(transformer.worldToGrid(item->boundingBox()).toRect()); diff --git a/src/command/removeitemcommand.cpp b/src/command/removeitemcommand.cpp index 94f638f..4446bb6 100644 --- a/src/command/removeitemcommand.cpp +++ b/src/command/removeitemcommand.cpp @@ -18,6 +18,8 @@ #include "removeitemcommand.hpp" +#include + #include "../common/constants.hpp" #include "../context/applicationcontext.hpp" #include "../context/coordinatetransformer.hpp" @@ -27,10 +29,7 @@ #include "../data-structures/quadtree.hpp" #include "../item/item.hpp" -RemoveItemCommand::RemoveItemCommand(QVector> items) : ItemCommand{items} { -} - -RemoveItemCommand::~RemoveItemCommand() { +RemoveItemCommand::RemoveItemCommand(QVector> items) : ItemCommand{std::move(items)} { } void RemoveItemCommand::execute(ApplicationContext *context) { diff --git a/src/command/removeitemcommand.hpp b/src/command/removeitemcommand.hpp index 3b7729d..c9dd6b6 100644 --- a/src/command/removeitemcommand.hpp +++ b/src/command/removeitemcommand.hpp @@ -24,7 +24,6 @@ class ApplicationContext; class RemoveItemCommand : public ItemCommand { public: RemoveItemCommand(QVector> items); - ~RemoveItemCommand(); void execute(ApplicationContext *context) override; void undo(ApplicationContext *context) override; diff --git a/src/command/selectcommand.cpp b/src/command/selectcommand.cpp index 03bac74..419eeb6 100644 --- a/src/command/selectcommand.cpp +++ b/src/command/selectcommand.cpp @@ -18,6 +18,8 @@ #include "selectcommand.hpp" +#include + #include "../context/applicationcontext.hpp" #include "../context/coordinatetransformer.hpp" #include "../context/selectioncontext.hpp" @@ -25,16 +27,13 @@ #include "../item/item.hpp" #include "../data-structures/cachegrid.hpp" -SelectCommand::SelectCommand(QVector> items) : ItemCommand{items} {} - -SelectCommand::~SelectCommand() { -} +SelectCommand::SelectCommand(QVector> items) : ItemCommand{std::move(items)} {} void SelectCommand::execute(ApplicationContext *context) { auto &selectedItems{context->selectionContext().selectedItems()}; QRectF dirtyRegion{}; - for (const auto item : m_items) { + for (const auto& item : m_items) { dirtyRegion |= item->boundingBox(); selectedItems.insert(item); } @@ -46,7 +45,7 @@ void SelectCommand::undo(ApplicationContext *context) { auto &selectedItems{context->selectionContext().selectedItems()}; QRectF dirtyRegion{}; - for (const auto item : m_items) { + for (const auto& item : m_items) { dirtyRegion |= item->boundingBox(); selectedItems.erase(item); } diff --git a/src/command/selectcommand.hpp b/src/command/selectcommand.hpp index 9669198..9a92701 100644 --- a/src/command/selectcommand.hpp +++ b/src/command/selectcommand.hpp @@ -25,7 +25,6 @@ class ApplicationContext; class SelectCommand : public ItemCommand { public: SelectCommand(QVector> items); - ~SelectCommand(); void execute(ApplicationContext *context) override; void undo(ApplicationContext *context) override; diff --git a/src/command/ungroupcommand.cpp b/src/command/ungroupcommand.cpp index 890cbc9..b444786 100644 --- a/src/command/ungroupcommand.cpp +++ b/src/command/ungroupcommand.cpp @@ -27,17 +27,14 @@ #include "../item/group.hpp" #include -UngroupCommand::UngroupCommand(QVector> items) : ItemCommand{items} { - for (const auto item : items) { +UngroupCommand::UngroupCommand(const QVector>& items) : ItemCommand{items} { + for (const auto& item : items) { if (item->type() == Item::Group) { m_groups.push_back(std::dynamic_pointer_cast(item)); } } } -UngroupCommand::~UngroupCommand() { -} - void UngroupCommand::execute(ApplicationContext *context) { auto &quadtree{context->spatialContext().quadtree()}; auto &selectedItems{context->selectionContext().selectedItems()}; @@ -47,13 +44,13 @@ void UngroupCommand::execute(ApplicationContext *context) { int count = 0; QRectF dirtyRegion{}; - for (const auto group : m_groups) { + for (const auto& group : m_groups) { quadtree.deleteItem(group); dirtyRegion |= group->boundingBox(); auto subItems{group->unGroup()}; - for (const auto subItem : subItems) { + for (const auto& subItem : subItems) { quadtree.insertItem(subItem, false); selectedItems.insert(subItem); } @@ -69,13 +66,13 @@ void UngroupCommand::undo(ApplicationContext *context) { selectedItems.clear(); QRectF dirtyRegion{}; - for (const auto group : m_groups) { + for (const auto& group : m_groups) { quadtree.insertItem(group); selectedItems.insert(group); dirtyRegion |= group->boundingBox(); auto subItems{group->unGroup()}; - for (const auto subItem : subItems) { + for (const auto& subItem : subItems) { quadtree.deleteItem(subItem, false); } } diff --git a/src/command/ungroupcommand.hpp b/src/command/ungroupcommand.hpp index 4dc2b5b..de3f174 100644 --- a/src/command/ungroupcommand.hpp +++ b/src/command/ungroupcommand.hpp @@ -25,8 +25,7 @@ class GroupItem; class UngroupCommand : public ItemCommand { public: - UngroupCommand(QVector> items); - ~UngroupCommand(); + UngroupCommand(const QVector>& items); void execute(ApplicationContext *context) override; void undo(ApplicationContext *context) override; diff --git a/src/command/updatepropertycommand.cpp b/src/command/updatepropertycommand.cpp index 0eb8167..b622a38 100644 --- a/src/command/updatepropertycommand.cpp +++ b/src/command/updatepropertycommand.cpp @@ -19,6 +19,7 @@ #include "updatepropertycommand.hpp" #include +#include #include "../context/applicationcontext.hpp" #include "../context/coordinatetransformer.hpp" @@ -29,8 +30,8 @@ UpdatePropertyCommand::UpdatePropertyCommand(QVector> items, Property newProperty) - : ItemCommand{items}, - m_newProperty{newProperty} { + : ItemCommand{std::move(items)}, + m_newProperty{std::move(newProperty)} { } void UpdatePropertyCommand::execute(ApplicationContext *context) { diff --git a/src/common/constants.hpp b/src/common/constants.hpp index ca61147..806ad16 100644 --- a/src/common/constants.hpp +++ b/src/common/constants.hpp @@ -45,6 +45,8 @@ inline constexpr QColor darkForegroundColor{211, 211, 211}; inline constexpr int maxItemOpacity{255}; inline constexpr int eraseItemOpacity{50}; +inline constexpr int boundingBoxPadding{10}; // in pixels + inline constexpr int translationDelta{1}; // in pixels inline constexpr int shiftTranslationDelta{10}; // in pixels, when holding shift diff --git a/src/common/renderitems.cpp b/src/common/renderitems.cpp index e3eb889..41fb8a5 100644 --- a/src/common/renderitems.cpp +++ b/src/common/renderitems.cpp @@ -49,7 +49,7 @@ void Common::renderCanvas(ApplicationContext *context) { QPainter &canvasPainter{context->renderingContext().canvasPainter()}; - for (auto cell : visibleCells) { + for (const auto& cell : visibleCells) { // canvasPainter.save(); // QPen pen; pen.setColor(Qt::white); canvasPainter.setPen(pen); // canvasPainter.drawRect(transformer.gridToView(cell->rect())); @@ -62,7 +62,7 @@ void Common::renderCanvas(ApplicationContext *context) { QVector> intersectingItems{ context->spatialContext().quadtree().queryItems( transformer.gridToWorld(cell->rect()), - [](auto a, auto b) { return true; })}; + [](const auto& a, auto b) { return true; })}; if (intersectingItems.empty()) continue; @@ -74,7 +74,7 @@ void Common::renderCanvas(ApplicationContext *context) { cell->painter().resetTransform(); cell->painter().scale(zoomFactor, zoomFactor); - for (auto intersectingItem : intersectingItems) { + for (const auto& intersectingItem : intersectingItems) { intersectingItem->draw(cell->painter(), topLeftPoint); } } @@ -96,7 +96,7 @@ void Common::renderCanvas(ApplicationContext *context) { canvasPainter.setPen(pen); - for (auto item : selectedItems) { + for (const auto& item : selectedItems) { QRectF curBox{transformer.worldToView(item->boundingBox()).normalized()}; canvasPainter.drawRect(curBox); selectionBox |= curBox; diff --git a/src/common/utils/compression.cpp b/src/common/utils/compression.cpp index 0fc0e5b..b0c4dc8 100644 --- a/src/common/utils/compression.cpp +++ b/src/common/utils/compression.cpp @@ -27,6 +27,7 @@ #include #include +#include #include namespace Common::Utils::Compression { @@ -34,7 +35,7 @@ QByteArray compressData(const QByteArray &data) { std::ostringstream stream{std::ios::binary}; kanzi::CompressedOutputStream cStream{stream, 1, "HUFFMAN", "LZX"}; - cStream.write(data.constData(), static_cast(data.size())); + cStream.write(data.constData(), static_cast(data.size())); cStream.close(); std::string result = stream.str(); diff --git a/src/components/actionbar.cpp b/src/components/actionbar.cpp index 95d9959..4604163 100644 --- a/src/components/actionbar.cpp +++ b/src/components/actionbar.cpp @@ -19,12 +19,13 @@ #include "actionbar.hpp" #include +#include #include "../context/applicationcontext.hpp" #include "../context/uicontext.hpp" -ActionBar::ActionBar(QWidget *parent) : QFrame{parent} { - m_layout = new QHBoxLayout{this}; +ActionBar::ActionBar(QWidget *parent) : QFrame{parent}, m_layout(new QHBoxLayout{this}) { + m_layout->setSpacing(10); this->setLayout(m_layout); this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); @@ -48,8 +49,8 @@ void ActionBar::addButton(const QString &tooltip, IconManager::Icon icon, int id QPushButton &ActionBar::button(int id) { if (!m_map.contains(id)) { - throw std::logic_error( - QString::asprintf("Button with id %d was not found.", id).toStdString()); + throw std::logic_error(std::format("Button with id {} was not found.", id)); } + return *m_map[id]; } diff --git a/src/components/propertybar.cpp b/src/components/propertybar.cpp index a62eba4..8fb8a7e 100644 --- a/src/components/propertybar.cpp +++ b/src/components/propertybar.cpp @@ -30,13 +30,13 @@ #include "../tools/tool.hpp" #include "toolbar.hpp" -PropertyBar::PropertyBar(QWidget *parent) : QFrame{parent} { +PropertyBar::PropertyBar(QWidget *parent) : QFrame{parent}, m_layout(new QVBoxLayout{this}) { this->setFrameStyle(QFrame::StyledPanel | QFrame::Plain); this->setAutoFillBackground(true); this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); this->setProperty("class", "drawlyFrame drawyPropertyBar"); - m_layout = new QVBoxLayout{this}; + setLayout(m_layout); } @@ -52,7 +52,7 @@ void PropertyBar::updateToolProperties() { // PUBLIC SLOTS void PropertyBar::updateProperties(Tool &tool) { // remove existing widgets - QLayoutItem *curItem; + QLayoutItem *curItem = nullptr; while ((curItem = m_layout->takeAt(0)) != nullptr) { QWidget *widget = curItem->widget(); if (widget) { diff --git a/src/components/toolbar.cpp b/src/components/toolbar.cpp index a255870..b7f0dbf 100644 --- a/src/components/toolbar.cpp +++ b/src/components/toolbar.cpp @@ -22,9 +22,9 @@ #include "../context/uicontext.hpp" #include "../iconmanager/iconmanager.hpp" -ToolBar::ToolBar(QWidget *parent) : QFrame{parent} { - m_group = new QButtonGroup(this); - m_layout = new QHBoxLayout(this); +ToolBar::ToolBar(QWidget *parent) : QFrame{parent}, m_group(new QButtonGroup(this)), m_layout(new QHBoxLayout(this)) { + + this->setLayout(m_layout); this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); this->setFrameShape(QFrame::StyledPanel); @@ -35,11 +35,7 @@ ToolBar::ToolBar(QWidget *parent) : QFrame{parent} { QObject::connect(m_group, &QButtonGroup::idClicked, this, &ToolBar::onToolChanged); } -ToolBar::~ToolBar() { - for (auto &idToolPair : m_tools) { - delete idToolPair.second; - } -} +ToolBar::~ToolBar() {} Tool &ToolBar::curTool() const { int curID{m_group->checkedId()}; @@ -50,8 +46,8 @@ Tool &ToolBar::curTool() const { return *m_tools.at(curID); } -QVector ToolBar::tools() const { - QVector result; +QVector> ToolBar::tools() const { + QVector> result; for (auto &idToolPair : m_tools) { result.push_back(idToolPair.second); } @@ -59,7 +55,7 @@ QVector ToolBar::tools() const { return result; } -void ToolBar::addTool(Tool *tool, Tool::Type type) { +void ToolBar::addTool(const std::shared_ptr& tool, Tool::Type type) { if (tool == nullptr) return; diff --git a/src/components/toolbar.hpp b/src/components/toolbar.hpp index 2711f62..5df4b60 100644 --- a/src/components/toolbar.hpp +++ b/src/components/toolbar.hpp @@ -29,11 +29,11 @@ class ToolBar : public QFrame { Q_OBJECT public: explicit ToolBar(QWidget *parent = nullptr); - ~ToolBar(); + ~ToolBar() override; Tool &curTool() const; - void addTool(Tool *tool, Tool::Type type); - QVector tools() const; + void addTool(const std::shared_ptr& tool, Tool::Type type); + QVector> tools() const; Tool &tool(Tool::Type type) const; void changeTool(Tool::Type type); @@ -44,7 +44,7 @@ class ToolBar : public QFrame { private: QButtonGroup *m_group{}; QHBoxLayout *m_layout{}; - std::unordered_map m_tools{}; + std::unordered_map> m_tools{}; void createButtons() const; private slots: diff --git a/src/context/applicationcontext.cpp b/src/context/applicationcontext.cpp index d655972..7b8da1e 100644 --- a/src/context/applicationcontext.cpp +++ b/src/context/applicationcontext.cpp @@ -26,11 +26,11 @@ ApplicationContext *ApplicationContext::m_instance = nullptr; -ApplicationContext::ApplicationContext(QWidget *parent) : QObject{parent}, m_parentWidget{parent} { - m_selectionContext = new SelectionContext(this); - m_renderingContext = new RenderingContext(this); - m_uiContext = new UIContext(this); - m_spatialContext = new SpatialContext(this); +ApplicationContext::ApplicationContext(QWidget *parent) : QObject{parent}, m_parentWidget{parent}, m_renderingContext(new RenderingContext(this)), m_selectionContext(new SelectionContext(this)), m_spatialContext(new SpatialContext(this)), m_uiContext(new UIContext(this)) { + + + + } ApplicationContext::~ApplicationContext() { diff --git a/src/context/applicationcontext.hpp b/src/context/applicationcontext.hpp index b72481b..3ec99a9 100644 --- a/src/context/applicationcontext.hpp +++ b/src/context/applicationcontext.hpp @@ -30,7 +30,7 @@ class SelectionContext; */ class ApplicationContext : public QObject { public: - ~ApplicationContext(); + ~ApplicationContext() override; static ApplicationContext *instance(QWidget *parent = nullptr) { if (!m_instance) { diff --git a/src/context/coordinatetransformer.hpp b/src/context/coordinatetransformer.hpp index efc1d16..205fd94 100644 --- a/src/context/coordinatetransformer.hpp +++ b/src/context/coordinatetransformer.hpp @@ -30,8 +30,8 @@ class RenderingContext; * 3. View (the viewport) */ class CoordinateTransformer { private: - SpatialContext *m_spatialContext; - RenderingContext *m_renderingContext; + SpatialContext *m_spatialContext{}; + RenderingContext *m_renderingContext{}; ApplicationContext *m_applicationContext; public: diff --git a/src/context/renderingcontext.cpp b/src/context/renderingcontext.cpp index 46e4d66..9b3bd4a 100644 --- a/src/context/renderingcontext.cpp +++ b/src/context/renderingcontext.cpp @@ -146,7 +146,7 @@ void RenderingContext::setZoomFactor(qreal newValue) { const int RenderingContext::fps() const { QScreen *screen{m_canvas->screen()}; if (screen) { - return screen->refreshRate(); + return static_cast(screen->refreshRate()); } return 60; diff --git a/src/context/renderingcontext.hpp b/src/context/renderingcontext.hpp index 268aace..c0fd175 100644 --- a/src/context/renderingcontext.hpp +++ b/src/context/renderingcontext.hpp @@ -29,7 +29,7 @@ class RenderingContext : public QObject { public: RenderingContext(ApplicationContext *context); - ~RenderingContext(); + ~RenderingContext() override; void setRenderingContext(); diff --git a/src/context/selectioncontext.cpp b/src/context/selectioncontext.cpp index 9066d15..d6eba55 100644 --- a/src/context/selectioncontext.cpp +++ b/src/context/selectioncontext.cpp @@ -43,14 +43,14 @@ std::unordered_set> &SelectionContext::selectedItems() { QRectF SelectionContext::selectionBox() const { QRectF selectionBox; - for (auto item : m_selectedItems) { + for (const auto& item : m_selectedItems) { selectionBox |= item->boundingBox(); } return selectionBox; } // PUBLIC SLOTS -void SelectionContext::updatePropertyOfSelectedItems(Property property) { +void SelectionContext::updatePropertyOfSelectedItems(const Property& property) { QVector> items{m_selectedItems.begin(), m_selectedItems.end()}; auto &commandHistory{m_applicationContext->spatialContext().commandHistory()}; diff --git a/src/context/selectioncontext.hpp b/src/context/selectioncontext.hpp index 45dc409..b0601ff 100644 --- a/src/context/selectioncontext.hpp +++ b/src/context/selectioncontext.hpp @@ -28,7 +28,7 @@ class ApplicationContext; class SelectionContext : public QObject { public: SelectionContext(ApplicationContext *context); - ~SelectionContext(); + ~SelectionContext() override; std::unordered_set> &selectedItems(); QRectF selectionBox() const; @@ -36,7 +36,7 @@ class SelectionContext : public QObject { void reset(); public slots: - void updatePropertyOfSelectedItems(Property property); + void updatePropertyOfSelectedItems(const Property& property); private: std::unordered_set> m_selectedItems{}; diff --git a/src/context/spatialcontext.hpp b/src/context/spatialcontext.hpp index f6c8621..afdf504 100644 --- a/src/context/spatialcontext.hpp +++ b/src/context/spatialcontext.hpp @@ -29,7 +29,7 @@ class Canvas; class SpatialContext : public QObject { public: SpatialContext(ApplicationContext *context); - ~SpatialContext(); + ~SpatialContext() override; void setSpatialContext(); diff --git a/src/context/uicontext.cpp b/src/context/uicontext.cpp index db0296b..3b5a83e 100644 --- a/src/context/uicontext.cpp +++ b/src/context/uicontext.cpp @@ -72,15 +72,15 @@ void UIContext::setUIContext() { m_event = new Event(); - m_toolBar->addTool(new SelectionTool(), Tool::Selection); - m_toolBar->addTool(new FreeformTool(), Tool::Freeform); - m_toolBar->addTool(new RectangleTool(), Tool::Rectangle); - m_toolBar->addTool(new EllipseTool(), Tool::Ellipse); - m_toolBar->addTool(new ArrowTool(), Tool::Arrow); - m_toolBar->addTool(new LineTool(), Tool::Line); - m_toolBar->addTool(new EraserTool(), Tool::Eraser); - m_toolBar->addTool(new TextTool(), Tool::Text); - m_toolBar->addTool(new MoveTool(), Tool::Move); + m_toolBar->addTool(std::make_shared(), Tool::Selection); + m_toolBar->addTool(std::make_shared(), Tool::Freeform); + m_toolBar->addTool(std::make_shared(), Tool::Rectangle); + m_toolBar->addTool(std::make_shared(), Tool::Ellipse); + m_toolBar->addTool(std::make_shared(), Tool::Arrow); + m_toolBar->addTool(std::make_shared(), Tool::Line); + m_toolBar->addTool(std::make_shared(), Tool::Eraser); + m_toolBar->addTool(std::make_shared(), Tool::Text); + m_toolBar->addTool(std::make_shared(), Tool::Move); // TODO: Define their functions somewhere else m_actionBar->addButton("Save to File", IconManager::ACTION_SAVE, 6); diff --git a/src/context/uicontext.hpp b/src/context/uicontext.hpp index 3ce8369..998e2a5 100644 --- a/src/context/uicontext.hpp +++ b/src/context/uicontext.hpp @@ -33,7 +33,7 @@ class IconManager; class UIContext : public QObject { public: UIContext(ApplicationContext *context); - ~UIContext(); + ~UIContext() override; void setUIContext(); diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index 50f2106..6388926 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -32,8 +32,8 @@ #include "../event/event.hpp" #include "../tools/tool.hpp" -Controller::Controller(QObject *parent) : QObject{parent} { - m_context = ApplicationContext::instance(dynamic_cast(parent)); +Controller::Controller(QObject *parent) : QObject{parent}, m_context(ApplicationContext::instance(dynamic_cast(parent))) { + m_context->setContexts(); } diff --git a/src/controller/controller.hpp b/src/controller/controller.hpp index 511314e..89e3ee5 100644 --- a/src/controller/controller.hpp +++ b/src/controller/controller.hpp @@ -30,7 +30,7 @@ class Controller : public QObject { public: Controller(QObject *parent = nullptr); - ~Controller(); + ~Controller() override; public slots: void mousePressed(QMouseEvent *event); diff --git a/src/data-structures/cachegrid.cpp b/src/data-structures/cachegrid.cpp index b0996e4..3d56c16 100644 --- a/src/data-structures/cachegrid.cpp +++ b/src/data-structures/cachegrid.cpp @@ -23,7 +23,7 @@ int CacheCell::counter = 0; -CacheCell::CacheCell(const QPoint &point) : m_point{point} { +CacheCell::CacheCell(const QPoint &point) : m_point{point}, m_dirty(true) { m_image = std::make_unique(CacheCell::cellSize()); m_image->fill(Qt::transparent); @@ -33,7 +33,7 @@ CacheCell::CacheCell(const QPoint &point) : m_point{point} { m_painter->setClipRegion(m_image->rect()); CacheCell::counter++; - m_dirty = true; + } CacheCell::~CacheCell() { @@ -104,7 +104,7 @@ QVector> CacheGrid::queryCells(const QRect &rect) { void CacheGrid::markDirty(const QRect &rect) { QVector> dirtyCells{queryCells(rect)}; - for (std::shared_ptr cell : dirtyCells) { + for (const std::shared_ptr& cell : dirtyCells) { cell->setDirty(true); } } @@ -156,7 +156,7 @@ void CacheGrid::setSize(int newSize) { } void CacheGrid::markAllDirty() { - for (auto cell : m_grid) { + for (const auto& cell : m_grid) { cell->setDirty(true); } } diff --git a/src/data-structures/orderedlist.cpp b/src/data-structures/orderedlist.cpp index 4c56f4f..86e341b 100644 --- a/src/data-structures/orderedlist.cpp +++ b/src/data-structures/orderedlist.cpp @@ -25,7 +25,7 @@ OrderedList::~OrderedList() { qDebug() << "Object deleted: OrderedList"; } -bool OrderedList::hasItem(ItemPtr item) const { +bool OrderedList::hasItem(const ItemPtr& item) const { if (m_itemIterMap.find(item) == m_itemIterMap.end()) { return false; } @@ -35,7 +35,7 @@ bool OrderedList::hasItem(ItemPtr item) const { return true; } -void OrderedList::insert(ItemPtr item) { +void OrderedList::insert(const ItemPtr& item) { // item already exists if (hasItem(item)) { return; @@ -52,7 +52,7 @@ void OrderedList::insert(ItemPtr item) { m_itemIterMap[item] = std::prev(m_itemList.end()); } -void OrderedList::remove(ItemPtr item) { +void OrderedList::remove(const ItemPtr& item) { // item already deleted if (!hasItem(item)) { return; @@ -64,7 +64,7 @@ void OrderedList::remove(ItemPtr item) { m_zIndex.erase(item); } -void OrderedList::bringForward(ItemPtr item) { +void OrderedList::bringForward(const ItemPtr& item) { if (!hasItem(item)) { throw std::runtime_error("Item was not found in the iterator map"); } @@ -85,7 +85,7 @@ void OrderedList::bringForward(ItemPtr item) { m_zIndex[*nextIterator] = val; } -void OrderedList::sendBackward(ItemPtr item) { +void OrderedList::sendBackward(const ItemPtr& item) { if (!hasItem(item)) { throw std::runtime_error("Item was not found in the iterator map"); } @@ -106,7 +106,7 @@ void OrderedList::sendBackward(ItemPtr item) { m_zIndex[*prevIterator] = val; }; -void OrderedList::sendToBack(ItemPtr item) { +void OrderedList::sendToBack(const ItemPtr& item) { if (!hasItem(item)) { throw std::runtime_error("Item was not found in the iterator map"); } @@ -121,7 +121,7 @@ void OrderedList::sendToBack(ItemPtr item) { m_zIndex[item] = m_zIndex[*firstIterator] - 1; } -void OrderedList::bringToFront(ItemPtr item) { +void OrderedList::bringToFront(const ItemPtr& item) { if (!hasItem(item)) { throw std::runtime_error("Item was not found in the iterator map"); } @@ -136,7 +136,7 @@ void OrderedList::bringToFront(ItemPtr item) { m_zIndex[item] = m_zIndex[*lastIterator] + 1; } -int OrderedList::zIndex(ItemPtr item) const { +int OrderedList::zIndex(const ItemPtr& item) const { if (!hasItem(item)) { throw std::runtime_error("Item not found in zIndex map"); } diff --git a/src/data-structures/orderedlist.hpp b/src/data-structures/orderedlist.hpp index c745996..804162c 100644 --- a/src/data-structures/orderedlist.hpp +++ b/src/data-structures/orderedlist.hpp @@ -36,14 +36,14 @@ class OrderedList { public: ~OrderedList(); - void insert(ItemPtr item); - void remove(ItemPtr item); + void insert(const ItemPtr& item); + void remove(const ItemPtr& item); - void bringForward(ItemPtr item); - void sendBackward(ItemPtr item); - void sendToBack(ItemPtr item); - void bringToFront(ItemPtr item); - bool hasItem(ItemPtr item) const; + void bringForward(const ItemPtr& item); + void sendBackward(const ItemPtr& item); + void sendToBack(const ItemPtr& item); + void bringToFront(const ItemPtr& item); + bool hasItem(const ItemPtr& item) const; - int zIndex(ItemPtr item) const; + int zIndex(const ItemPtr& item) const; }; diff --git a/src/data-structures/quadtree.cpp b/src/data-structures/quadtree.cpp index d2baa1d..c780beb 100644 --- a/src/data-structures/quadtree.cpp +++ b/src/data-structures/quadtree.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "../item/item.hpp" #include "orderedlist.hpp" @@ -33,8 +34,8 @@ QuadTree::QuadTree(QRectF region, int capacity) : m_boundingBox{region}, m_capac QuadTree::QuadTree(QRectF region, int capacity, std::shared_ptr orderedList) : m_boundingBox{region}, - m_capacity{capacity} { - m_orderedList = orderedList; + m_capacity{capacity}, m_orderedList(std::move(orderedList)) { + } QuadTree::~QuadTree() { @@ -58,7 +59,7 @@ void QuadTree::subdivide() { m_bottomLeft = std::make_unique(bottomLeftRect, m_capacity, m_orderedList); } -void QuadTree::insertItem(std::shared_ptr item, bool updateOrder) { +void QuadTree::insertItem(const std::shared_ptr& item, bool updateOrder) { expand(item->boundingBox().topLeft()); expand(item->boundingBox().topRight()); expand(item->boundingBox().bottomRight()); @@ -66,7 +67,7 @@ void QuadTree::insertItem(std::shared_ptr item, bool updateOrder) { insert(item, updateOrder); } -bool QuadTree::insert(std::shared_ptr item, bool updateOrder) { +bool QuadTree::insert(const std::shared_ptr& item, bool updateOrder) { if (!m_boundingBox.intersects(item->boundingBox())) { return false; } @@ -97,7 +98,7 @@ bool QuadTree::insert(std::shared_ptr item, bool updateOrder) { return inserted; } -void QuadTree::deleteItem(std::shared_ptr const item, bool updateOrder) { +void QuadTree::deleteItem(std::shared_ptr const& item, bool updateOrder) { if (!m_boundingBox.intersects(item->boundingBox())) { return; } @@ -138,7 +139,7 @@ void QuadTree::reorder(QVector& items) const { }); } -void QuadTree::updateItem(std::shared_ptr item, const QRectF &oldBoundingBox) { +void QuadTree::updateItem(const std::shared_ptr& item, const QRectF &oldBoundingBox) { expand(item->boundingBox().topLeft()); expand(item->boundingBox().topRight()); expand(item->boundingBox().bottomRight()); @@ -147,7 +148,7 @@ void QuadTree::updateItem(std::shared_ptr item, const QRectF &oldBoundingB update(item, oldBoundingBox, false); } -void QuadTree::update(std::shared_ptr item, const QRectF &oldBoundingBox, bool inserted) { +void QuadTree::update(const std::shared_ptr& item, const QRectF &oldBoundingBox, bool inserted) { if (!m_boundingBox.intersects(oldBoundingBox) && !m_boundingBox.intersects(item->boundingBox())) { return; diff --git a/src/data-structures/quadtree.hpp b/src/data-structures/quadtree.hpp index 6a41ab3..3feabb9 100644 --- a/src/data-structures/quadtree.hpp +++ b/src/data-structures/quadtree.hpp @@ -59,9 +59,9 @@ class QuadTree { ~QuadTree(); int size() const; - void insertItem(ItemPtr item, bool updateOrder = true); - void deleteItem(ItemPtr item, bool updateOrder = true); - void updateItem(ItemPtr item, const QRectF &oldBoundingBox); + void insertItem(const ItemPtr& item, bool updateOrder = true); + void deleteItem(const ItemPtr& item, bool updateOrder = true); + void updateItem(const ItemPtr& item, const QRectF &oldBoundingBox); void deleteItems(const QRectF &boundingBox); void reorder(QVector& items) const; @@ -79,8 +79,8 @@ class QuadTree { const QRectF &boundingBox() const; private: - bool insert(ItemPtr item, bool updateOrder); - void update(ItemPtr item, const QRectF &oldBoundingBox, bool inserted); + bool insert(const ItemPtr& item, bool updateOrder); + void update(const ItemPtr& item, const QRectF &oldBoundingBox, bool inserted); template void query(const Shape &shape, diff --git a/src/data-structures/quadtree.ipp b/src/data-structures/quadtree.ipp index e3edb87..7e26064 100644 --- a/src/data-structures/quadtree.ipp +++ b/src/data-structures/quadtree.ipp @@ -25,7 +25,7 @@ template QVector> QuadTree::queryItems(const Shape &shape) const { - return queryItems(shape, [](std::shared_ptr item, const Shape &shape) { + return queryItems(shape, [](const std::shared_ptr& item, const Shape &shape) { return item->intersects(shape); }); } diff --git a/src/event/event.cpp b/src/event/event.cpp index 7e862b6..62d1494 100644 --- a/src/event/event.cpp +++ b/src/event/event.cpp @@ -18,7 +18,7 @@ #include "event.hpp" -Event::Event() { +Event::Event() { } void Event::setPos(const QPoint &point, qreal const scale) { diff --git a/src/event/event.hpp b/src/event/event.hpp index d198cd8..c3bfaca 100644 --- a/src/event/event.hpp +++ b/src/event/event.hpp @@ -40,10 +40,10 @@ class Event { void setModifiers(Qt::KeyboardModifiers modifiers); private: - Qt::MouseButton m_button; + Qt::MouseButton m_button{Qt::NoButton}; QPoint m_pos; qreal m_pressure{1.0}; QString m_text; - int m_key; + int m_key{}; Qt::KeyboardModifiers m_modifiers; }; diff --git a/src/item/arrow.cpp b/src/item/arrow.cpp index 7f9296d..229f9f8 100644 --- a/src/item/arrow.cpp +++ b/src/item/arrow.cpp @@ -43,9 +43,9 @@ void ArrowItem::calcArrowPoints() { int maxArrowSize{static_cast(m_maxArrowSize)}; int arrowSize{std::min(maxArrowSize, static_cast(arrowLength * 0.5))}; - m_arrowP1 = QPoint(x2 - arrowSize * std::cos(angle - (M_PI / 180) * 30), + m_arrowP1 = QPointF(x2 - arrowSize * std::cos(angle - (M_PI / 180) * 30), y2 - arrowSize * std::sin(angle - (M_PI / 180) * 30)); - m_arrowP2 = QPoint(x2 - arrowSize * std::cos(angle + (M_PI / 180) * 30), + m_arrowP2 = QPointF(x2 - arrowSize * std::cos(angle + (M_PI / 180) * 30), y2 - arrowSize * std::sin(angle + (M_PI / 180) * 30)); } diff --git a/src/item/ellipse.cpp b/src/item/ellipse.cpp index 29dba7a..3632408 100644 --- a/src/item/ellipse.cpp +++ b/src/item/ellipse.cpp @@ -26,12 +26,12 @@ void EllipseItem::m_draw(QPainter &painter, const QPointF &offset) const { } bool EllipseItem::onEllipse(QLineF line) const { - int sw{m_boundingBoxPadding + property(Property::StrokeWidth).value()}; - double X{m_boundingBox.x() + sw}, Y{m_boundingBox.y() + sw}; - double W{m_boundingBox.width() - 2 * sw}, H{m_boundingBox.height() - 2 * sw}; + int sw{boundingBoxPadding() + property(Property::StrokeWidth).value()}; + double bX{m_boundingBox.x() + sw}, bY{m_boundingBox.y() + sw}; + double bW{m_boundingBox.width() - 2 * sw}, bH{m_boundingBox.height() - 2 * sw}; - double h{X + W / 2}, k{Y + H / 2}; - double a{W / 2}, b{H / 2}; + double h{bX + bW / 2}, k{bY + bH / 2}; + double a{bW / 2}, b{bH / 2}; double x1{line.x1()}, y1{line.y1()}; double x2{line.x2()}, y2{line.y2()}; @@ -42,17 +42,17 @@ bool EllipseItem::onEllipse(QLineF line) const { double ps{p * p}; double qs{q * q}; - double A{ps * bs + qs * as}; - double B{2 * (x1 * p * bs - p * h * bs + y1 * q * as - q * k * as)}; - double C{static_cast(x1) * x1 * bs + bs * h * h - 2 * x1 * h * bs + - static_cast(y1) * y1 * as + as * k * k - 2 * y1 * k * as - as * bs}; + double firstTerm{ps * bs + qs * as}; + double secondTerm{2 * (x1 * p * bs - p * h * bs + y1 * q * as - q * k * as)}; + double thirdTerm{x1 * x1 * bs + bs * h * h - 2 * x1 * h * bs + + y1 * y1 * as + as * k * k - 2 * y1 * k * as - as * bs}; - double discriminant{B * B - 4 * A * C}; + double discriminant{secondTerm * secondTerm - 4 * firstTerm * thirdTerm}; if (discriminant < 0) return false; - double t1{(-B + sqrt(discriminant)) / (2.0 * A)}; - double t2{(-B - sqrt(discriminant)) / (2.0 * A)}; + double t1{(-secondTerm + sqrt(discriminant)) / (2.0 * firstTerm)}; + double t2{(-secondTerm - sqrt(discriminant)) / (2.0 * firstTerm)}; return (t1 >= 0.0 && t1 <= 1.0) || (t2 >= 0.0 && t2 <= 1.0); } diff --git a/src/item/ellipse.hpp b/src/item/ellipse.hpp index c6ea5ea..a0dd88d 100644 --- a/src/item/ellipse.hpp +++ b/src/item/ellipse.hpp @@ -23,7 +23,7 @@ class EllipseItem : public PolygonItem { public: EllipseItem(); - virtual ~EllipseItem() = default; + ~EllipseItem() override = default; bool intersects(const QRectF &rect) override; bool intersects(const QLineF &rect) override; diff --git a/src/item/factory/arrowfactory.hpp b/src/item/factory/arrowfactory.hpp index 41c35e1..952d2e3 100644 --- a/src/item/factory/arrowfactory.hpp +++ b/src/item/factory/arrowfactory.hpp @@ -23,5 +23,6 @@ class ArrowFactory : public ItemFactory { public: ArrowFactory(); + ~ArrowFactory() override = default; std::shared_ptr create() const override; }; diff --git a/src/item/factory/ellipsefactory.hpp b/src/item/factory/ellipsefactory.hpp index ce3a210..635dc95 100644 --- a/src/item/factory/ellipsefactory.hpp +++ b/src/item/factory/ellipsefactory.hpp @@ -23,5 +23,6 @@ class EllipseFactory : public ItemFactory { public: EllipseFactory(); + ~EllipseFactory() override = default; std::shared_ptr create() const override; }; diff --git a/src/item/factory/freeformfactory.hpp b/src/item/factory/freeformfactory.hpp index e3c1691..37ebdc4 100644 --- a/src/item/factory/freeformfactory.hpp +++ b/src/item/factory/freeformfactory.hpp @@ -23,5 +23,6 @@ class FreeformFactory : public ItemFactory { public: FreeformFactory(); + ~FreeformFactory() override = default; std::shared_ptr create() const override; }; diff --git a/src/item/factory/itemfactory.hpp b/src/item/factory/itemfactory.hpp index 66ab2e0..4eb17e3 100644 --- a/src/item/factory/itemfactory.hpp +++ b/src/item/factory/itemfactory.hpp @@ -24,5 +24,6 @@ class Item; class ItemFactory { public: ItemFactory(); + virtual ~ItemFactory() = default; virtual std::shared_ptr create() const = 0; }; diff --git a/src/item/factory/linefactory.hpp b/src/item/factory/linefactory.hpp index a9c9247..6f13963 100644 --- a/src/item/factory/linefactory.hpp +++ b/src/item/factory/linefactory.hpp @@ -23,5 +23,6 @@ class LineFactory : public ItemFactory { public: LineFactory(); + ~LineFactory() override = default; std::shared_ptr create() const override; }; diff --git a/src/item/factory/rectanglefactory.hpp b/src/item/factory/rectanglefactory.hpp index 6449274..92b864f 100644 --- a/src/item/factory/rectanglefactory.hpp +++ b/src/item/factory/rectanglefactory.hpp @@ -25,5 +25,6 @@ class Item; class RectangleFactory : public ItemFactory { public: RectangleFactory(); + ~RectangleFactory() override = default; std::shared_ptr create() const override; }; diff --git a/src/item/factory/textfactory.hpp b/src/item/factory/textfactory.hpp index 94defe4..2a5d094 100644 --- a/src/item/factory/textfactory.hpp +++ b/src/item/factory/textfactory.hpp @@ -23,5 +23,6 @@ class TextFactory : public ItemFactory { public: TextFactory(); + ~TextFactory() override = default; std::shared_ptr create() const override; }; diff --git a/src/item/freeform.cpp b/src/item/freeform.cpp index 04f40b6..c56bc4c 100644 --- a/src/item/freeform.cpp +++ b/src/item/freeform.cpp @@ -126,7 +126,7 @@ QPointF FreeformItem::optimizePoint(const QPointF &newPoint) { m_currentWindow.pop_front(); } - return m_currentWindowSum / m_currentWindow.size(); + return m_currentWindowSum / static_cast(m_currentWindow.size()); } void FreeformItem::quickDraw(QPainter &painter, const QPointF &offset) const { @@ -191,7 +191,7 @@ void FreeformItem::m_draw(QPainter &painter, const QPointF &offset) const { } } -int FreeformItem::size() const { +qsizetype FreeformItem::size() const { return m_points.size(); } @@ -218,7 +218,6 @@ QVector> FreeformItem::split() const { // create a copy std::shared_ptr newItem{std::make_shared()}; newItem->m_properties = m_properties; - newItem->m_boundingBoxPadding = m_boundingBoxPadding; items.push_back(newItem); } diff --git a/src/item/freeform.hpp b/src/item/freeform.hpp index 76fd998..abef06c 100644 --- a/src/item/freeform.hpp +++ b/src/item/freeform.hpp @@ -26,7 +26,7 @@ class FreeformItem : public Item, public std::enable_shared_from_this { public: FreeformItem(); - ~FreeformItem() = default; + ~FreeformItem() override = default; FreeformItem(const FreeformItem &freeform); static int minPointDistance(); @@ -40,7 +40,7 @@ class FreeformItem : public Item, public std::enable_shared_from_this> split() const; - int size() const; + qsizetype size() const; int maxSize() const; virtual void addPoint(const QPointF &point, const qreal pressure, bool optimize = true); diff --git a/src/item/group.cpp b/src/item/group.cpp index 3e3fd1e..bee0b9d 100644 --- a/src/item/group.cpp +++ b/src/item/group.cpp @@ -2,18 +2,18 @@ #include void GroupItem::draw(QPainter &painter, const QPointF &offset) { - for (auto item : m_items) { + for (const auto& item : m_items) { item->draw(painter, offset); } } void GroupItem::erase(QPainter &painter, const QPointF &offset) const { - for (auto item : m_items) { + for (const auto& item : m_items) { item->erase(painter, offset); } } void GroupItem::translate(const QPointF &amount) { - for (auto item : m_items) { + for (const auto& item : m_items) { item->translate(amount); } } @@ -23,7 +23,7 @@ void GroupItem::group(const QVector>& items) { } bool GroupItem::intersects(const QRectF &rect) { - for (auto item : m_items) { + for (const auto& item : m_items) { if (item->intersects(rect)) { return true; } @@ -33,7 +33,7 @@ bool GroupItem::intersects(const QRectF &rect) { }; bool GroupItem::intersects(const QLineF &line) { - for (auto item : m_items) { + for (const auto& item : m_items) { if (item->intersects(line)) { return true; } @@ -50,7 +50,7 @@ QVector> GroupItem::unGroup() { const QRectF GroupItem::boundingBox() const { QRectF result{}; - for (auto item : m_items) { + for (const auto& item : m_items) { result |= item->boundingBox(); } @@ -62,7 +62,7 @@ Item::Type GroupItem::type() const { } void GroupItem::setProperty(const Property::Type propertyType, Property newObj) { - for (auto item : m_items) { + for (const auto& item : m_items) { item->setProperty(propertyType, newObj); } }; @@ -73,7 +73,7 @@ const Property GroupItem::property(const Property::Type propertyType) const { } Property property{}; - for (auto item : m_items) { + for (const auto& item : m_items) { try { if (property.type() != Property::Null) { if (property.variant() != item->property(propertyType).variant()) { @@ -93,7 +93,7 @@ const Property GroupItem::property(const Property::Type propertyType) const { const QVector GroupItem::properties() const { QVector result{}; - for (auto item : m_items) { + for (const auto& item : m_items) { result += item->properties(); } @@ -102,7 +102,7 @@ const QVector GroupItem::properties() const { const QVector GroupItem::propertyTypes() const { std::unordered_set types; - for (auto item : m_items) { + for (const auto& item : m_items) { auto &itemPropertyTypes{item->propertyTypes()}; types.insert(itemPropertyTypes.begin(), itemPropertyTypes.end()); } diff --git a/src/item/item.cpp b/src/item/item.cpp index f19a20d..6cce232 100644 --- a/src/item/item.cpp +++ b/src/item/item.cpp @@ -18,7 +18,9 @@ #include "item.hpp" -#include +#include + +#include "../common/constants.hpp" // PUBLIC Item::Item() { @@ -29,14 +31,10 @@ Item::~Item() { } const QRectF Item::boundingBox() const { - int mg{m_boundingBoxPadding}; + int mg{boundingBoxPadding()}; return m_boundingBox.adjusted(-mg, -mg, mg, mg); } -void Item::setBoundingBoxPadding(int padding) { - m_boundingBoxPadding = padding; -} - const Property Item::property(const Property::Type propertyType) const { if (m_properties.find(propertyType) == m_properties.end()) { throw std::logic_error("Item does not support this property."); @@ -67,7 +65,7 @@ const QVector Item::properties() const { void Item::setProperty(const Property::Type propertyType, Property newObj) { if (m_properties.find(propertyType) != m_properties.end()) { - m_properties[propertyType] = newObj; + m_properties[propertyType] = std::move(newObj); } updateAfterProperty(); @@ -77,5 +75,5 @@ void Item::updateAfterProperty() {} void Item::erase(QPainter &painter, const QPointF &offset) const {} int Item::boundingBoxPadding() const { - return m_boundingBoxPadding; + return Common::boundingBoxPadding; } diff --git a/src/item/item.hpp b/src/item/item.hpp index 9e60d5d..13b71ca 100644 --- a/src/item/item.hpp +++ b/src/item/item.hpp @@ -38,10 +38,8 @@ class Item { virtual const QRectF boundingBox() const; - void setBoundingBoxPadding(int padding); int boundingBoxPadding() const; - virtual void setProperty(const Property::Type propertyType, Property newObj); virtual const Property property(const Property::Type propertyType) const; virtual const QVector properties() const; @@ -55,7 +53,6 @@ class Item { protected: QRectF m_boundingBox{}; - int m_boundingBoxPadding{}; std::unordered_map m_properties{}; virtual void m_draw(QPainter &painter, const QPointF &offset) const = 0; diff --git a/src/item/text.cpp b/src/item/text.cpp index e3fc21f..eb31232 100644 --- a/src/item/text.cpp +++ b/src/item/text.cpp @@ -33,16 +33,16 @@ * TODO: This file needs some refactoring as well, feel free to open a PR */ -TextItem::TextItem() { +TextItem::TextItem() : m_selectionStart(INVALID), m_selectionEnd(INVALID), m_text("") { m_properties[Property::StrokeColor] = Property{QColor(Qt::white), Property::StrokeColor}; m_properties[Property::Opacity] = Property{255, Property::Opacity}; m_properties[Property::FontSize] = Property{18, Property::FontSize}; - m_selectionStart = INVALID; - m_selectionEnd = INVALID; - m_caretIndex = 0; - m_text = ""; - m_mode = NORMAL; + + + + + } TextItem::~TextItem() { @@ -222,7 +222,7 @@ qsizetype TextItem::getIndexFromX(double xPos, int lineNumber) const { qsizetype low{0}, high{m_text.size()}, index{0}; while (low <= high) { - double mid{low + (high - low) / 2.0}; + qsizetype mid{low + (high - low) / 2}; const double prefixWidth{ metrics.boundingRect(m_boundingBox, getTextFlags(), line.left(mid)).width()}; @@ -304,7 +304,7 @@ void TextItem::updateBoundingBox() { m_boundingBox.setHeight(size.height()); } -void TextItem::deleteSubStr(int start, int end) { +void TextItem::deleteSubStr(qsizetype start, qsizetype end) { if (start < 0 || start >= m_text.size() || end < 0 || end >= m_text.size()) return; @@ -394,7 +394,7 @@ std::pair TextItem::getLineRange(qsizetype position) const } qsizetype TextItem::getPrevBreak(qsizetype position) const { - auto isBreak = [&](int pos) { + auto isBreak = [&](qsizetype pos) { for (auto &sep : Common::wordSeparators) { if (m_text[pos] == sep) return true; diff --git a/src/item/text.hpp b/src/item/text.hpp index ec4898d..2b09cb4 100644 --- a/src/item/text.hpp +++ b/src/item/text.hpp @@ -26,7 +26,7 @@ class TextItem : public Item { public: TextItem(); - ~TextItem(); + ~TextItem() override; bool intersects(const QRectF &rect) override; bool intersects(const QLineF &rect) override; @@ -58,7 +58,7 @@ class TextItem : public Item { const QString &text() const; void insertText(const QString &text); - void deleteSubStr(int start, int end); + void deleteSubStr(qsizetype start, qsizetype end); void deleteSelection(); bool hasSelection() const; @@ -94,5 +94,5 @@ class TextItem : public Item { qsizetype m_selectionStart{}; qsizetype m_selectionEnd{}; qsizetype m_caretPosInLine{}; - Mode m_mode; + Mode m_mode{NORMAL}; }; diff --git a/src/keybindings/action.cpp b/src/keybindings/action.cpp index 8a5b807..71ac4a5 100644 --- a/src/keybindings/action.cpp +++ b/src/keybindings/action.cpp @@ -18,9 +18,11 @@ #include "action.hpp" +#include + Action::Action(QString name, QString description, std::function callable, QObject *parent) - : m_name{name}, - m_description{description}, + : m_name{std::move(name)}, + m_description{std::move(description)}, m_callable{std::move(callable)}, QObject{parent} { } diff --git a/src/keybindings/actionmanager.cpp b/src/keybindings/actionmanager.cpp index 75b2bc8..929a86c 100644 --- a/src/keybindings/actionmanager.cpp +++ b/src/keybindings/actionmanager.cpp @@ -42,6 +42,7 @@ ActionManager::ActionManager(ApplicationContext *context) : m_context{context}, QObject(context) { KeybindManager &keybindManager{m_context->uiContext().keybindManager()}; + // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks) Action *undoAction{new Action{"Undo", "Undo last action", [&]() { this->undo(); }, context}}; Action *redoAction{ @@ -51,16 +52,6 @@ ActionManager::ActionManager(ApplicationContext *context) : m_context{context}, Action *zoomOutAction{new Action{"Zoom Out", "Zoom out", [&]() { this->zoomOut(); }, context}}; - Action *increaseThicknessAction{new Action{"Increase Thickness", - "Increase brush thickness", - [&]() { this->increaseThickness(); }, - context}}; - - Action *decreaseThicknessAction{new Action{"Decrease Thickness", - "Decrease brush thickness", - [&]() { this->decreaseThickness(); }, - context}}; - Action *freeformToolAction{new Action{"Freeform Tool", "Switch to freeform drawing tool", [&]() { this->switchToFreeformTool(); }, @@ -280,11 +271,3 @@ void ActionManager::loadFromFile() { Loader loader{}; loader.loadFromFile(m_context); } - -void ActionManager::increaseThickness() { - // TODO: implement -} - -void ActionManager::decreaseThickness() { - // TODO: implement -} diff --git a/src/keybindings/actionmanager.hpp b/src/keybindings/actionmanager.hpp index 3e6646a..a873dcf 100644 --- a/src/keybindings/actionmanager.hpp +++ b/src/keybindings/actionmanager.hpp @@ -30,8 +30,6 @@ class ActionManager : public QObject { void zoomOut(); void undo(); void redo(); - void increaseThickness(); - void decreaseThickness(); void switchToFreeformTool(); void switchToEraserTool(); void switchToSelectionTool(); diff --git a/src/properties/property.hpp b/src/properties/property.hpp index 3f9ef37..d9f5882 100644 --- a/src/properties/property.hpp +++ b/src/properties/property.hpp @@ -19,6 +19,7 @@ #pragma once #include +#include class Property { public: @@ -27,9 +28,9 @@ class Property { enum Type { StrokeWidth, StrokeColor, Opacity, FontSize, EraserSize, Actions, Null}; template - Property(T value, Type type) { - m_value = value; - m_type = type; + Property(T value, Type type) : m_value(std::move(value)), m_type(type) { + + } template diff --git a/src/properties/widgets/strokecolorwidget.cpp b/src/properties/widgets/strokecolorwidget.cpp index a3e0112..a1c035d 100644 --- a/src/properties/widgets/strokecolorwidget.cpp +++ b/src/properties/widgets/strokecolorwidget.cpp @@ -25,14 +25,14 @@ #include "../property.hpp" -// TODO: Use a better widget and a better way to return colors instead of button id -StrokeColorWidget::StrokeColorWidget(QWidget *parent) : PropertyWidget{parent} { +// TODO: Use a better widget +StrokeColorWidget::StrokeColorWidget(QWidget *parent) : PropertyWidget{parent}, m_group(new QButtonGroup{m_widget}) { m_widget = new QWidget{parent}; QHBoxLayout *layout{new QHBoxLayout{m_widget}}; layout->setContentsMargins(0, 0, 0, 0); - m_group = new QButtonGroup{m_widget}; + m_widget->setLayout(layout); QVector colors{QColor{255, 255, 255}, @@ -45,9 +45,10 @@ StrokeColorWidget::StrokeColorWidget(QWidget *parent) : PropertyWidget{parent} { QPushButton *btn{new QPushButton{"", m_widget}}; btn->setCheckable(true); btn->setStyleSheet("background-color: " + color.name()); + btn->setProperty("color-value", color); layout->addWidget(btn); - m_group->addButton(btn, color.rgba()); + m_group->addButton(btn); } layout->setSpacing(0); @@ -63,6 +64,5 @@ QString StrokeColorWidget::name() const { }; const Property StrokeColorWidget::value() const { - return Property{QColor::fromRgba(static_cast(m_group->checkedId())), - Property::StrokeColor}; + return Property{m_group->checkedButton()->property("color-value"), Property::StrokeColor}; }; diff --git a/src/serializer/loader.cpp b/src/serializer/loader.cpp index 5f1a833..514e6b8 100644 --- a/src/serializer/loader.cpp +++ b/src/serializer/loader.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include "../common/constants.hpp" @@ -94,7 +93,7 @@ void Loader::loadFromFile(ApplicationContext *context) { QuadTree &quadtree{context->spatialContext().quadtree()}; QJsonArray itemsArray = array(value(docObj, "items")); - for (const QJsonValue &v : itemsArray) { + for (const QJsonValueRef &v : itemsArray) { QJsonObject itemObj = object(v); std::shared_ptr item = createItem(itemObj); quadtree.insertItem(item); @@ -176,13 +175,11 @@ std::shared_ptr Loader::createItem(const QJsonObject &obj) { } QJsonArray properties = array(value(obj, "properties")); - for (const QJsonValue &propertyValue : properties) { + for (const QJsonValueRef &propertyValue : properties) { Property prop{createProperty(object(propertyValue))}; item->setProperty(prop.type(), prop); } - item->setBoundingBoxPadding(value(obj, "bounding_box_padding").toInt()); - return item; } diff --git a/src/serializer/serializer.cpp b/src/serializer/serializer.cpp index e5e3379..f82bfb1 100644 --- a/src/serializer/serializer.cpp +++ b/src/serializer/serializer.cpp @@ -56,7 +56,7 @@ void Serializer::serialize(ApplicationContext *context) { m_object["zoom_factor"] = zoomFactor; } -QJsonObject Serializer::toJson(std::shared_ptr item) { +QJsonObject Serializer::toJson(const std::shared_ptr& item) { QJsonObject obj{}; obj["type"] = QJsonValue(static_cast(item->type())); diff --git a/src/serializer/serializer.hpp b/src/serializer/serializer.hpp index 89ab6c2..6e5b6eb 100644 --- a/src/serializer/serializer.hpp +++ b/src/serializer/serializer.hpp @@ -35,7 +35,7 @@ class Serializer { private: static QJsonObject toJson(const QRectF &rect); static QJsonObject toJson(const QPointF &point); - static QJsonObject toJson(std::shared_ptr item); + static QJsonObject toJson(const std::shared_ptr& item); static QJsonObject toJson(const Property &property); template diff --git a/src/tools/erasertool.cpp b/src/tools/erasertool.cpp index 6b080a4..ad89a8c 100644 --- a/src/tools/erasertool.cpp +++ b/src/tools/erasertool.cpp @@ -80,7 +80,7 @@ void EraserTool::mouseMoved(ApplicationContext *context) { QVector> toBeErased{ spatialContext.quadtree().queryItems(worldEraserRect)}; - for (std::shared_ptr item : toBeErased) { + for (const std::shared_ptr& item : toBeErased) { if (m_toBeErased.count(item) > 0) continue; @@ -120,7 +120,7 @@ void EraserTool::mouseReleased(ApplicationContext *context) { CommandHistory &commandHistory{spatialContext.commandHistory()}; QVector> erasedItems; - for (std::shared_ptr item : m_toBeErased) { + for (const std::shared_ptr& item : m_toBeErased) { if (selectionContext.selectedItems().count(item) > 0) { selectionContext.selectedItems().erase(item); } diff --git a/src/tools/freeformtool.cpp b/src/tools/freeformtool.cpp index bcd4a69..3f55d4c 100644 --- a/src/tools/freeformtool.cpp +++ b/src/tools/freeformtool.cpp @@ -75,8 +75,6 @@ void FreeformTool::mousePressed(ApplicationContext *context) { curItem->setProperty(Property::StrokeColor, uiContext.propertyManager().value(Property::StrokeColor)); - curItem->setBoundingBoxPadding(10 * renderingContext.canvas().scale()); - m_lastPoint = uiContext.event().pos(); curItem->addPoint(transformer.viewToWorld(m_lastPoint), uiContext.event().pressure()); diff --git a/src/tools/movetool.hpp b/src/tools/movetool.hpp index 047a803..cd6d171 100644 --- a/src/tools/movetool.hpp +++ b/src/tools/movetool.hpp @@ -26,7 +26,7 @@ class Item; class MoveTool : public Tool { public: MoveTool(); - ~MoveTool() = default; + ~MoveTool() override = default; void mousePressed(ApplicationContext *context) override; void mouseMoved(ApplicationContext *context) override; diff --git a/src/tools/polygondrawingtool.cpp b/src/tools/polygondrawingtool.cpp index 2650b91..ec520c2 100644 --- a/src/tools/polygondrawingtool.cpp +++ b/src/tools/polygondrawingtool.cpp @@ -55,7 +55,6 @@ void PolygonDrawingTool::mousePressed(ApplicationContext *context) { curItem->setProperty(Property::StrokeColor, uiContext.propertyManager().value(Property::StrokeColor)); - curItem->setBoundingBoxPadding(10 * renderingContext.canvas().scale()); curItem->setStart(transformer.viewToWorld(uiContext.event().pos())); qreal zoom{renderingContext.zoomFactor()}; diff --git a/src/tools/selectiontool/selectiontool.hpp b/src/tools/selectiontool/selectiontool.hpp index 4ed58df..84328af 100644 --- a/src/tools/selectiontool/selectiontool.hpp +++ b/src/tools/selectiontool/selectiontool.hpp @@ -24,7 +24,7 @@ class SelectionToolState; class SelectionTool : public Tool { public: SelectionTool(); - ~SelectionTool() = default; + ~SelectionTool() override = default; QString tooltip() const override; IconManager::Icon icon() const override; diff --git a/src/tools/selectiontool/selectiontoolmovestate.cpp b/src/tools/selectiontool/selectiontoolmovestate.cpp index 5340292..ff0d15c 100644 --- a/src/tools/selectiontool/selectiontoolmovestate.cpp +++ b/src/tools/selectiontool/selectiontoolmovestate.cpp @@ -69,7 +69,7 @@ void SelectionToolMoveState::mouseMoved(ApplicationContext *context) { QPointF worldLastPos{transformer.viewToWorld(m_lastPos)}; QPointF delta{worldCurPos - worldLastPos}; - for (auto item : selectedItems) { + for (const auto& item : selectedItems) { QRectF oldBoundingBox{item->boundingBox()}; spatialContext.cacheGrid().markDirty(transformer.worldToGrid(item->boundingBox()).toRect()); diff --git a/src/tools/selectiontool/selectiontoolselectstate.cpp b/src/tools/selectiontool/selectiontoolselectstate.cpp index e52f073..d128ee2 100644 --- a/src/tools/selectiontool/selectiontoolselectstate.cpp +++ b/src/tools/selectiontool/selectiontoolselectstate.cpp @@ -47,7 +47,7 @@ bool SelectionToolSelectState::mousePressed(ApplicationContext *context) { QVector> intersectingItems{ spatialContext.quadtree().queryItems(transformer.viewToWorld(m_lastPos), - [](std::shared_ptr item, auto &pos) { + [](const std::shared_ptr& item, auto &pos) { return item->boundingBox().contains(pos); })}; @@ -108,7 +108,7 @@ void SelectionToolSelectState::mouseMoved(ApplicationContext *context) { QVector> intersectingItems{ spatialContext.quadtree().queryItems(worldSelectionBox, - [](std::shared_ptr item, const QRectF &rect) { + [](const std::shared_ptr& item, const QRectF &rect) { return rect.contains(item->boundingBox()); })}; @@ -139,7 +139,7 @@ bool SelectionToolSelectState::mouseReleased(ApplicationContext *context) { if (!selectedItems.empty()) { QVector> items{}; - for (const auto item : selectedItems) { + for (const auto& item : selectedItems) { items.push_back(item); } diff --git a/src/tools/selectiontool/selectiontoolstate.hpp b/src/tools/selectiontool/selectiontoolstate.hpp index 7dda396..995dd41 100644 --- a/src/tools/selectiontool/selectiontoolstate.hpp +++ b/src/tools/selectiontool/selectiontoolstate.hpp @@ -22,6 +22,8 @@ class ApplicationContext; class SelectionToolState { public: + virtual ~SelectionToolState() = default; + // The bool return value indicates whether to lock the state or not virtual bool mousePressed(ApplicationContext *context) = 0; virtual void mouseMoved(ApplicationContext *context) = 0; diff --git a/src/tools/texttool.cpp b/src/tools/texttool.cpp index a0dc5b5..fad22f8 100644 --- a/src/tools/texttool.cpp +++ b/src/tools/texttool.cpp @@ -64,14 +64,13 @@ void TextTool::mousePressed(ApplicationContext *context) { QPointF worldPos{transformer.viewToWorld(uiContext.event().pos())}; QVector> intersectingItems{ - quadTree.queryItems(worldPos, [](std::shared_ptr item, const QPointF &point) { + quadTree.queryItems(worldPos, [](const std::shared_ptr& item, const QPointF &point) { return item->type() == Item::Text && item->boundingBox().contains(point); })}; if (intersectingItems.empty()) { if (m_curItem == nullptr) { m_curItem = std::dynamic_pointer_cast(m_itemFactory->create()); - m_curItem->setBoundingBoxPadding(10 * renderingContext.canvas().scale()); m_curItem->setProperty(Property::StrokeColor, uiContext.propertyManager().value(Property::StrokeColor)); @@ -129,7 +128,7 @@ void TextTool::mouseMoved(ApplicationContext *context) { QPointF worldPos{transformer.viewToWorld(uiContext.event().pos())}; QVector> intersectingItems{ - quadTree.queryItems(worldPos, [](std::shared_ptr item, const QPointF &point) { + quadTree.queryItems(worldPos, [](const std::shared_ptr& item, const QPointF &point) { return item->type() == Item::Text && item->boundingBox().contains(point); })}; diff --git a/src/window/boardlayout.cpp b/src/window/boardlayout.cpp index 8bb6ff5..a8a556c 100644 --- a/src/window/boardlayout.cpp +++ b/src/window/boardlayout.cpp @@ -53,7 +53,7 @@ QLayoutItem *BoardLayout::itemAt(int index) const { QLayoutItem *BoardLayout::takeAt(int index) { try { QLayoutItem *item{*m_widgets.at(index)}; - *m_widgets[index] = nullptr; + *(m_widgets.at(index)) = nullptr; return item; } catch (std::out_of_range) { return nullptr; diff --git a/src/window/boardlayout.hpp b/src/window/boardlayout.hpp index 60bf895..ecfc3ef 100644 --- a/src/window/boardlayout.hpp +++ b/src/window/boardlayout.hpp @@ -24,7 +24,7 @@ class BoardLayout : public QLayout { Q_OBJECT public: BoardLayout(QWidget *parent = nullptr); - ~BoardLayout(); + ~BoardLayout() override; void addItem(QLayoutItem *item) override; QLayoutItem *itemAt(int index) const override; diff --git a/src/window/window.hpp b/src/window/window.hpp index 7506047..0927548 100644 --- a/src/window/window.hpp +++ b/src/window/window.hpp @@ -25,7 +25,7 @@ class MainWindow : public QWidget { public: MainWindow(QWidget *parent = nullptr); - ~MainWindow(); + ~MainWindow() override; private: bool m_config_useSystemStyles{true};