From 31a92abfec7015d0fd9993651513c31001dafebb Mon Sep 17 00:00:00 2001 From: Timur Buchkin Date: Wed, 7 Oct 2026 15:26:07 +0300 Subject: [PATCH 01/13] add nix wrapper --- .clang-format | 2 + .envrc | 1 + flake.lock | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 24 +++++++++++ treefmt.nix | 7 ++++ 5 files changed, 148 insertions(+) create mode 100644 .clang-format create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 treefmt.nix diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..84f9c6a --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: Google +IndentWidth: 4 diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..42a6181 --- /dev/null +++ b/flake.lock @@ -0,0 +1,114 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1790898470, + "narHash": "sha256-zTwuwezD0w3hpga6a6P8emidzAZFyWqlNeRBlpWOOl8=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "024633cd702b10285db5cb19b40ad48d2399ba60", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "import-tree": { + "locked": { + "lastModified": 1788467110, + "narHash": "sha256-ljEMTXP/rH0tOvDzc9gzwww6KcHRPRnEHzd9lK48V7s=", + "owner": "vic", + "repo": "import-tree", + "rev": "eb1b52eaecc57f7c136d07ae8a93e724dfecac46", + "type": "github" + }, + "original": { + "owner": "vic", + "repo": "import-tree", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1791254437, + "narHash": "sha256-qMSsgG+9tIdx282dMqGuJAUK3t6F36clM6efd0rXfes=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b25309931cfda5f0b8805f462a29897eeae50168", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-26.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1790477367, + "narHash": "sha256-oujbxmVKDhci2E4EM3KyAbRUgp5/IsCoiA/LfEF7OOk=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "f7cd230690d9fc982d06129f9189b101fddcfa3b", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "import-tree": "import-tree", + "nixpkgs": "nixpkgs", + "systems": "systems", + "treefmt-nix": "treefmt-nix" + } + }, + "systems": { + "locked": { + "lastModified": 1791244623, + "narHash": "sha256-uuanbkFk8a313Zfrxdcz8Us/yQtaxNnKJtX8v0ZPpd8=", + "owner": "nix-systems", + "repo": "default", + "rev": "d36eeed142f88b5a636f2e3856a53c61654cf29b", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1791203292, + "narHash": "sha256-vuzVwvjeucSnwKwMBpyP8r5IzdrMKCHEdwTrRFwUN7I=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "03d8ee1bcbc8f9638907bb79edb9673151d0e22b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..212d914 --- /dev/null +++ b/flake.nix @@ -0,0 +1,24 @@ +{ + description = "Default flake-parts based setup"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05"; + flake-parts.url = "github:hercules-ci/flake-parts"; + import-tree.url = "github:vic/import-tree"; + systems.url = "github:nix-systems/default"; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = inputs: + inputs.flake-parts.lib.mkFlake {inherit inputs;} { + imports = [inputs.treefmt-nix.flakeModule]; + systems = import inputs.systems; + perSystem = {inputs', ...}: { + packages = {}; + treefmt = import ./treefmt.nix; + }; + }; +} diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..470184c --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,7 @@ +{ + projectRootFile = "flake.nix"; + programs.alejandra.enable = true; + + # Other formatting tools + programs.clang-format.enable = true; +} From c2da008d7037a9dc31fe40657de7101d355ee9d1 Mon Sep 17 00:00:00 2001 From: Timur Buchkin Date: Wed, 7 Oct 2026 17:45:15 +0300 Subject: [PATCH 02/13] style fix --- VirtualTuringMachine/VMTAlphabit.cpp | 103 +-- VirtualTuringMachine/VMTAlphabit.h | 22 +- VirtualTuringMachine/VMTJsonSerializer.cpp | 228 +++--- VirtualTuringMachine/VMTJsonSerializer.h | 7 +- VirtualTuringMachine/VMTLine.cpp | 193 ++--- VirtualTuringMachine/VMTLine.h | 49 +- VirtualTuringMachine/VMTSerializer.cpp | 505 ++++++------ VirtualTuringMachine/VMTSerializer.h | 151 ++-- .../VMTTransitionConditions.cpp | 164 ++-- .../VMTTransitionConditions.h | 41 +- VirtualTuringMachine/VMTTransitionImpl.cpp | 759 +++++++++--------- VirtualTuringMachine/VMTTransitionImpl.h | 64 +- VirtualTuringMachine/clickablelabel.cpp | 14 +- VirtualTuringMachine/clickablelabel.h | 20 +- VirtualTuringMachine/configuration.cpp | 176 ++-- VirtualTuringMachine/configuration.h | 19 +- VirtualTuringMachine/diagrambezier.cpp | 28 +- VirtualTuringMachine/diagrambezier.h | 10 +- VirtualTuringMachine/diagramrouting.cpp | 46 +- VirtualTuringMachine/diagramrouting.h | 25 +- VirtualTuringMachine/exercise.cpp | 79 +- VirtualTuringMachine/exercise.h | 30 +- VirtualTuringMachine/flowlayout.cpp | 93 +-- VirtualTuringMachine/flowlayout.h | 24 +- VirtualTuringMachine/formactionhint.cpp | 24 +- VirtualTuringMachine/formactionhint.h | 18 +- VirtualTuringMachine/formalphabit.cpp | 73 +- VirtualTuringMachine/formalphabit.h | 31 +- VirtualTuringMachine/formbase.h | 15 +- VirtualTuringMachine/formcalculator.cpp | 136 ++-- VirtualTuringMachine/formcalculator.h | 27 +- VirtualTuringMachine/formcompilermachine.cpp | 291 ++++--- VirtualTuringMachine/formcompilermachine.h | 39 +- VirtualTuringMachine/formcomplexmachines.cpp | 63 +- VirtualTuringMachine/formcomplexmachines.h | 22 +- VirtualTuringMachine/formdebugermachine.cpp | 186 +++-- VirtualTuringMachine/formdebugermachine.h | 53 +- VirtualTuringMachine/formeditormachine.cpp | 571 +++++++------ VirtualTuringMachine/formeditormachine.h | 57 +- VirtualTuringMachine/formeditorwidget.cpp | 108 ++- VirtualTuringMachine/formeditorwidget.h | 51 +- VirtualTuringMachine/formexercises.cpp | 197 +++-- VirtualTuringMachine/formexercises.h | 23 +- VirtualTuringMachine/formexport4th.cpp | 102 ++- VirtualTuringMachine/formexport4th.h | 33 +- VirtualTuringMachine/formlinewidget.cpp | 190 +++-- VirtualTuringMachine/formlinewidget.h | 47 +- VirtualTuringMachine/formmain.cpp | 159 ++-- VirtualTuringMachine/formmain.h | 29 +- VirtualTuringMachine/formnewmachine.cpp | 171 ++-- VirtualTuringMachine/formnewmachine.h | 24 +- VirtualTuringMachine/formnewproject.cpp | 168 ++-- VirtualTuringMachine/formnewproject.h | 17 +- VirtualTuringMachine/formwarning.cpp | 25 +- VirtualTuringMachine/formwarning.h | 18 +- .../interfaces/IVMDebugEnabler.h | 21 +- VirtualTuringMachine/interfaces/IVMTAction.h | 38 +- .../interfaces/IVMTActionController.h | 11 +- .../interfaces/IVMTAlphabitSource.h | 23 +- .../interfaces/IVMTCalculatorCallback.h | 21 +- .../interfaces/IVMTCompilerCallback.h | 12 +- .../interfaces/IVMTComplexMachineSource.h | 16 +- .../interfaces/IVMTDebugerCallback.h | 18 +- .../interfaces/IVMTEnvironment.h | 33 +- .../interfaces/IVMTLineObserver.h | 18 +- VirtualTuringMachine/interfaces/IVMTMachine.h | 131 +-- .../interfaces/IVMTProjectMachineReplacer.h | 10 +- .../interfaces/IVMTTransition.h | 90 ++- VirtualTuringMachine/interfaces/ivmtdebuger.h | 11 +- .../interfaces/ivmtundoobserver.h | 6 +- VirtualTuringMachine/machineslibrary.cpp | 6 +- VirtualTuringMachine/machineslibrary.h | 10 +- VirtualTuringMachine/machineslibrary_global.h | 6 +- VirtualTuringMachine/main.cpp | 8 +- VirtualTuringMachine/mainwindow.cpp | 294 +++---- VirtualTuringMachine/mainwindow.h | 40 +- VirtualTuringMachine/pathfinder.cpp | 260 +++--- VirtualTuringMachine/pathfinder.h | 33 +- VirtualTuringMachine/screentools.cpp | 53 +- VirtualTuringMachine/screentools.h | 45 +- VirtualTuringMachine/statecontroller.h | 108 ++- VirtualTuringMachine/ui_formactionhint.h | 48 +- VirtualTuringMachine/ui_formalphabit.h | 32 +- VirtualTuringMachine/ui_formcalculator.h | 45 +- VirtualTuringMachine/ui_formcompilermachine.h | 65 +- VirtualTuringMachine/ui_formcomplexmachines.h | 35 +- VirtualTuringMachine/ui_formdebugermachine.h | 99 +-- VirtualTuringMachine/ui_formeditormachine.h | 299 ++++--- VirtualTuringMachine/ui_formeditorwidget.h | 29 +- VirtualTuringMachine/ui_formexercises.h | 83 +- VirtualTuringMachine/ui_formexport4th.h | 224 +++--- VirtualTuringMachine/ui_formlinewidget.h | 32 +- VirtualTuringMachine/ui_formmain.h | 101 +-- VirtualTuringMachine/ui_formnewmachine.h | 102 +-- VirtualTuringMachine/ui_formnewproject.h | 184 +++-- VirtualTuringMachine/ui_formwarning.h | 69 +- VirtualTuringMachine/ui_mainwindow.h | 346 +++++--- VirtualTuringMachine/uicanvas.cpp | 386 +++++---- VirtualTuringMachine/uicanvas.h | 131 +-- VirtualTuringMachine/uistate.h | 35 +- VirtualTuringMachine/uistatecompilermachine.h | 60 +- VirtualTuringMachine/uistatedebugermachine.h | 55 +- VirtualTuringMachine/uistateeditormachine.h | 112 ++- VirtualTuringMachine/uistateexercises.h | 51 +- VirtualTuringMachine/uistateexport4th.h | 45 +- VirtualTuringMachine/uistatemain.h | 32 +- VirtualTuringMachine/uistatenewmachine.h | 45 +- VirtualTuringMachine/uistatenewproject.h | 87 +- VirtualTuringMachine/uistatestub.h | 30 +- .../virtualturingmachine_plugin_import.cpp | 5 +- .../vmtactions/vmtactioncreateandconnect.cpp | 114 +-- .../vmtactions/vmtactioncreateandconnect.h | 39 +- .../vmtactions/vmtactiondelete.cpp | 90 +-- .../vmtactions/vmtactiondelete.h | 30 +- .../vmtactions/vmtactionlink.cpp | 228 +++--- .../vmtactions/vmtactionlink.h | 39 +- .../vmtactions/vmtactionmachine.cpp | 86 +- .../vmtactions/vmtactionmachine.h | 35 +- .../vmtactions/vmtactionpointer.cpp | 430 +++++----- .../vmtactions/vmtactionpointer.h | 79 +- .../vmtactions/vmtactiontranslate.cpp | 88 +- .../vmtactions/vmtactiontranslate.h | 39 +- VirtualTuringMachine/vmtdebuger.cpp | 168 ++-- VirtualTuringMachine/vmtdebuger.h | 33 +- VirtualTuringMachine/vmterror.cpp | 19 +- VirtualTuringMachine/vmterror.h | 16 +- VirtualTuringMachine/vmterrormachine.cpp | 13 +- VirtualTuringMachine/vmterrormachine.h | 15 +- VirtualTuringMachine/vmterrortransition.cpp | 11 +- VirtualTuringMachine/vmterrortransition.h | 16 +- .../vmtexport4th/vmtexport4th.cpp | 557 +++++++------ .../vmtexport4th/vmtexport4th.h | 141 ++-- .../vmtexportplantuml/vmtexportplantuml.cpp | 99 ++- .../vmtexportplantuml/vmtexportplantuml.h | 7 +- VirtualTuringMachine/vmticons.cpp | 206 +++-- VirtualTuringMachine/vmticons.h | 16 +- .../vmtmachines/VMTComplexMachine.cpp | 419 +++++----- .../vmtmachines/VMTComplexMachine.h | 62 +- .../vmtmachines/VMTComplexMachineInner.cpp | 106 ++- .../vmtmachines/VMTComplexMachineInner.h | 39 +- .../vmtmachines/VMTMachineAlpha.cpp | 152 ++-- .../vmtmachines/VMTMachineAlpha.h | 22 +- .../vmtmachines/VMTMachineStub.cpp | 320 ++++---- .../vmtmachines/VMTMachineStub.h | 58 +- .../vmtmachines/vmtmachinecopy.cpp | 281 ++++--- .../vmtmachines/vmtmachinecopy.h | 17 +- .../vmtmachines/vmtmachinefinish.cpp | 54 +- .../vmtmachines/vmtmachinefinish.h | 10 +- .../vmtmachines/vmtmachineleft.cpp | 54 +- .../vmtmachines/vmtmachineleft.h | 11 +- .../vmtmachines/vmtmachineleftword.cpp | 121 +-- .../vmtmachines/vmtmachineleftword.h | 20 +- .../vmtmachines/vmtmachineright.cpp | 55 +- .../vmtmachines/vmtmachineright.h | 11 +- .../vmtmachines/vmtmachinerightword.cpp | 123 +-- .../vmtmachines/vmtmachinerightword.h | 18 +- .../vmtmachines/vmtmachinestart.cpp | 54 +- .../vmtmachines/vmtmachinestart.h | 11 +- VirtualTuringMachine/vmtproject.cpp | 68 +- VirtualTuringMachine/vmtproject.h | 62 +- VirtualTuringMachine/vmttheme.cpp | 559 ++++++------- VirtualTuringMachine/vmttheme.h | 13 +- VirtualTuringMachine/vmtundoelement.cpp | 24 +- VirtualTuringMachine/vmtundoelement.h | 22 +- VirtualTuringMachine/vmtundoelementeditor.cpp | 14 +- VirtualTuringMachine/vmtundoelementeditor.h | 12 +- .../vmtundoelementmachine.cpp | 22 +- VirtualTuringMachine/vmtundoelementmachine.h | 13 +- VirtualTuringMachine/vmtundomanager.cpp | 43 +- VirtualTuringMachine/vmtundomanager.h | 18 +- tests/pathfinder/test_pathfinder.cpp | 278 +++---- .../test_machine_serialization.cpp | 113 ++- 172 files changed, 7901 insertions(+), 7999 deletions(-) mode change 100755 => 100644 VirtualTuringMachine/VMTAlphabit.cpp mode change 100755 => 100644 VirtualTuringMachine/VMTAlphabit.h mode change 100755 => 100644 VirtualTuringMachine/VMTLine.cpp mode change 100755 => 100644 VirtualTuringMachine/VMTLine.h mode change 100755 => 100644 VirtualTuringMachine/VMTSerializer.cpp mode change 100755 => 100644 VirtualTuringMachine/VMTSerializer.h mode change 100755 => 100644 VirtualTuringMachine/VMTTransitionConditions.cpp mode change 100755 => 100644 VirtualTuringMachine/VMTTransitionConditions.h mode change 100755 => 100644 VirtualTuringMachine/VMTTransitionImpl.cpp mode change 100755 => 100644 VirtualTuringMachine/VMTTransitionImpl.h mode change 100755 => 100644 VirtualTuringMachine/clickablelabel.cpp mode change 100755 => 100644 VirtualTuringMachine/clickablelabel.h mode change 100755 => 100644 VirtualTuringMachine/configuration.cpp mode change 100755 => 100644 VirtualTuringMachine/configuration.h mode change 100755 => 100644 VirtualTuringMachine/exercise.cpp mode change 100755 => 100644 VirtualTuringMachine/exercise.h mode change 100755 => 100644 VirtualTuringMachine/flowlayout.cpp mode change 100755 => 100644 VirtualTuringMachine/flowlayout.h mode change 100755 => 100644 VirtualTuringMachine/formactionhint.cpp mode change 100755 => 100644 VirtualTuringMachine/formactionhint.h mode change 100755 => 100644 VirtualTuringMachine/formalphabit.cpp mode change 100755 => 100644 VirtualTuringMachine/formalphabit.h mode change 100755 => 100644 VirtualTuringMachine/formbase.h mode change 100755 => 100644 VirtualTuringMachine/formcalculator.cpp mode change 100755 => 100644 VirtualTuringMachine/formcalculator.h mode change 100755 => 100644 VirtualTuringMachine/formcompilermachine.cpp mode change 100755 => 100644 VirtualTuringMachine/formcompilermachine.h mode change 100755 => 100644 VirtualTuringMachine/formcomplexmachines.cpp mode change 100755 => 100644 VirtualTuringMachine/formcomplexmachines.h mode change 100755 => 100644 VirtualTuringMachine/formdebugermachine.cpp mode change 100755 => 100644 VirtualTuringMachine/formdebugermachine.h mode change 100755 => 100644 VirtualTuringMachine/formeditormachine.cpp mode change 100755 => 100644 VirtualTuringMachine/formeditormachine.h mode change 100755 => 100644 VirtualTuringMachine/formeditorwidget.cpp mode change 100755 => 100644 VirtualTuringMachine/formeditorwidget.h mode change 100755 => 100644 VirtualTuringMachine/formexercises.cpp mode change 100755 => 100644 VirtualTuringMachine/formexercises.h mode change 100755 => 100644 VirtualTuringMachine/formexport4th.cpp mode change 100755 => 100644 VirtualTuringMachine/formexport4th.h mode change 100755 => 100644 VirtualTuringMachine/formlinewidget.cpp mode change 100755 => 100644 VirtualTuringMachine/formlinewidget.h mode change 100755 => 100644 VirtualTuringMachine/formmain.cpp mode change 100755 => 100644 VirtualTuringMachine/formmain.h mode change 100755 => 100644 VirtualTuringMachine/formnewmachine.cpp mode change 100755 => 100644 VirtualTuringMachine/formnewmachine.h mode change 100755 => 100644 VirtualTuringMachine/formnewproject.cpp mode change 100755 => 100644 VirtualTuringMachine/formnewproject.h mode change 100755 => 100644 VirtualTuringMachine/formwarning.cpp mode change 100755 => 100644 VirtualTuringMachine/formwarning.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/IVMDebugEnabler.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/IVMTAction.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/IVMTActionController.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/IVMTAlphabitSource.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/IVMTCalculatorCallback.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/IVMTCompilerCallback.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/IVMTComplexMachineSource.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/IVMTDebugerCallback.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/IVMTEnvironment.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/IVMTLineObserver.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/IVMTMachine.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/IVMTProjectMachineReplacer.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/IVMTTransition.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/ivmtdebuger.h mode change 100755 => 100644 VirtualTuringMachine/interfaces/ivmtundoobserver.h mode change 100755 => 100644 VirtualTuringMachine/machineslibrary.cpp mode change 100755 => 100644 VirtualTuringMachine/machineslibrary.h mode change 100755 => 100644 VirtualTuringMachine/machineslibrary_global.h mode change 100755 => 100644 VirtualTuringMachine/main.cpp mode change 100755 => 100644 VirtualTuringMachine/mainwindow.cpp mode change 100755 => 100644 VirtualTuringMachine/mainwindow.h mode change 100755 => 100644 VirtualTuringMachine/screentools.cpp mode change 100755 => 100644 VirtualTuringMachine/screentools.h mode change 100755 => 100644 VirtualTuringMachine/statecontroller.h mode change 100755 => 100644 VirtualTuringMachine/ui_formactionhint.h mode change 100755 => 100644 VirtualTuringMachine/ui_formalphabit.h mode change 100755 => 100644 VirtualTuringMachine/ui_formcalculator.h mode change 100755 => 100644 VirtualTuringMachine/ui_formcompilermachine.h mode change 100755 => 100644 VirtualTuringMachine/ui_formcomplexmachines.h mode change 100755 => 100644 VirtualTuringMachine/ui_formdebugermachine.h mode change 100755 => 100644 VirtualTuringMachine/ui_formeditormachine.h mode change 100755 => 100644 VirtualTuringMachine/ui_formeditorwidget.h mode change 100755 => 100644 VirtualTuringMachine/ui_formexercises.h mode change 100755 => 100644 VirtualTuringMachine/ui_formexport4th.h mode change 100755 => 100644 VirtualTuringMachine/ui_formlinewidget.h mode change 100755 => 100644 VirtualTuringMachine/ui_formmain.h mode change 100755 => 100644 VirtualTuringMachine/ui_formnewmachine.h mode change 100755 => 100644 VirtualTuringMachine/ui_formnewproject.h mode change 100755 => 100644 VirtualTuringMachine/ui_formwarning.h mode change 100755 => 100644 VirtualTuringMachine/ui_mainwindow.h mode change 100755 => 100644 VirtualTuringMachine/uicanvas.cpp mode change 100755 => 100644 VirtualTuringMachine/uicanvas.h mode change 100755 => 100644 VirtualTuringMachine/uistate.h mode change 100755 => 100644 VirtualTuringMachine/uistatecompilermachine.h mode change 100755 => 100644 VirtualTuringMachine/uistatedebugermachine.h mode change 100755 => 100644 VirtualTuringMachine/uistateeditormachine.h mode change 100755 => 100644 VirtualTuringMachine/uistateexercises.h mode change 100755 => 100644 VirtualTuringMachine/uistateexport4th.h mode change 100755 => 100644 VirtualTuringMachine/uistatemain.h mode change 100755 => 100644 VirtualTuringMachine/uistatenewmachine.h mode change 100755 => 100644 VirtualTuringMachine/uistatenewproject.h mode change 100755 => 100644 VirtualTuringMachine/uistatestub.h mode change 100755 => 100644 VirtualTuringMachine/virtualturingmachine_plugin_import.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtactions/vmtactioncreateandconnect.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtactions/vmtactioncreateandconnect.h mode change 100755 => 100644 VirtualTuringMachine/vmtactions/vmtactiondelete.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtactions/vmtactiondelete.h mode change 100755 => 100644 VirtualTuringMachine/vmtactions/vmtactionlink.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtactions/vmtactionlink.h mode change 100755 => 100644 VirtualTuringMachine/vmtactions/vmtactionmachine.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtactions/vmtactionmachine.h mode change 100755 => 100644 VirtualTuringMachine/vmtactions/vmtactionpointer.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtactions/vmtactionpointer.h mode change 100755 => 100644 VirtualTuringMachine/vmtactions/vmtactiontranslate.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtactions/vmtactiontranslate.h mode change 100755 => 100644 VirtualTuringMachine/vmtdebuger.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtdebuger.h mode change 100755 => 100644 VirtualTuringMachine/vmterror.cpp mode change 100755 => 100644 VirtualTuringMachine/vmterror.h mode change 100755 => 100644 VirtualTuringMachine/vmterrormachine.cpp mode change 100755 => 100644 VirtualTuringMachine/vmterrormachine.h mode change 100755 => 100644 VirtualTuringMachine/vmterrortransition.cpp mode change 100755 => 100644 VirtualTuringMachine/vmterrortransition.h mode change 100755 => 100644 VirtualTuringMachine/vmtexport4th/vmtexport4th.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtexport4th/vmtexport4th.h mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/VMTComplexMachine.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/VMTComplexMachine.h mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.h mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/VMTMachineAlpha.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/VMTMachineAlpha.h mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/VMTMachineStub.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/VMTMachineStub.h mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachinecopy.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachinecopy.h mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachinefinish.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachinefinish.h mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachineleft.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachineleft.h mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachineleftword.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachineleftword.h mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachineright.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachineright.h mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachinerightword.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachinerightword.h mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachinestart.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtmachines/vmtmachinestart.h mode change 100755 => 100644 VirtualTuringMachine/vmtproject.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtproject.h mode change 100755 => 100644 VirtualTuringMachine/vmtundoelement.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtundoelement.h mode change 100755 => 100644 VirtualTuringMachine/vmtundoelementeditor.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtundoelementeditor.h mode change 100755 => 100644 VirtualTuringMachine/vmtundoelementmachine.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtundoelementmachine.h mode change 100755 => 100644 VirtualTuringMachine/vmtundomanager.cpp mode change 100755 => 100644 VirtualTuringMachine/vmtundomanager.h diff --git a/VirtualTuringMachine/VMTAlphabit.cpp b/VirtualTuringMachine/VMTAlphabit.cpp old mode 100755 new mode 100644 index 4d1f208..0ccb725 --- a/VirtualTuringMachine/VMTAlphabit.cpp +++ b/VirtualTuringMachine/VMTAlphabit.cpp @@ -1,94 +1,69 @@ #include "VMTAlphabit.h" + #include -VMTAlphabit::~VMTAlphabit(){ - qDebug() << "VMTAlphabit::~VMTAlphabit"; -} +VMTAlphabit::~VMTAlphabit() { qDebug() << "VMTAlphabit::~VMTAlphabit"; } -VMTAlphabit::VMTAlphabit(){ +VMTAlphabit::VMTAlphabit() {} -} - -bool VMTAlphabit::operator !=(const VMTAlphabit &other){ - if(_signs.length()!=other._signs.length()) return false; - else - { - for(int i=0;i<_signs.length();i++){ - bool found = false; - for(int j=0;(j0) return _signs[0].toLatin1(); - return 0; +char VMTAlphabit::GetLambda() { + if (_signs.size() > 0) return _signs[0].toLatin1(); + return 0; } - -char VMTAlphabit::GetSignAt(int index){ - if(index>=0){ - if(index<_signs.size()) - return _signs[index].toLatin1(); +char VMTAlphabit::GetSignAt(int index) { + if (index >= 0) { + if (index < _signs.size()) return _signs[index].toLatin1(); } - return 0; + return 0; } - -int VMTAlphabit::GetSignsCount(){ - - return _signs.size(); -} +int VMTAlphabit::GetSignsCount() { return _signs.size(); } #include -bool VMTAlphabit::IsEqual(const VMTAlphabit &other){ - - if(_signs.size() != other._signs.size()) return false; +bool VMTAlphabit::IsEqual(const VMTAlphabit& other) { + if (_signs.size() != other._signs.size()) return false; std::set other_set; - for(int i = 0; i < static_cast(other._signs.size()); ++i) other_set.insert(other._signs[i]); + for (int i = 0; i < static_cast(other._signs.size()); ++i) + other_set.insert(other._signs[i]); - for(int i = 0; i < static_cast(_signs.size()); ++i) - if(other_set.find(_signs[i])==other_set.end()) return false; + for (int i = 0; i < static_cast(_signs.size()); ++i) + if (other_set.find(_signs[i]) == other_set.end()) return false; return true; } +bool VMTAlphabit::IsLambda(char sign) { return (sign == GetLambda()); } -bool VMTAlphabit::IsLambda(char sign){ - - return (sign==GetLambda()); -} - - -bool VMTAlphabit::IsSign(char sign){ - for(int i = 0; i < static_cast(_signs.size()); ++i){ - if(_signs[i].toLatin1()==sign) return true; +bool VMTAlphabit::IsSign(char sign) { + for (int i = 0; i < static_cast(_signs.size()); ++i) { + if (_signs[i].toLatin1() == sign) return true; } - return false; + return false; } - - -const QString& VMTAlphabit::ToString(){ - return _signs; -} +const QString& VMTAlphabit::ToString() { return _signs; } diff --git a/VirtualTuringMachine/VMTAlphabit.h b/VirtualTuringMachine/VMTAlphabit.h old mode 100755 new mode 100644 index c2e59ea..9096231 --- a/VirtualTuringMachine/VMTAlphabit.h +++ b/VirtualTuringMachine/VMTAlphabit.h @@ -3,28 +3,26 @@ #include -class VMTAlphabit -{ -private: +class VMTAlphabit { + private: QString _signs; -public: - VMTAlphabit(); + + public: + VMTAlphabit(); VMTAlphabit(const VMTAlphabit& other); void AddSign(char sign); - char GetLambda(); char GetSignAt(int index); int GetSignsCount(); - bool IsEqual(const VMTAlphabit &other); - bool IsLambda(char sign); + bool IsEqual(const VMTAlphabit& other); + bool IsLambda(char sign); bool IsSign(char sign); void ReplaceString(const QString& other); - const QString& ToString(); + const QString& ToString(); - bool operator !=(const VMTAlphabit &other); + bool operator!=(const VMTAlphabit& other); virtual ~VMTAlphabit(); - }; -#endif // !defined(EA_F87A7617_E180_442b_A3D0_541F8C64FC9B__INCLUDED_) +#endif // !defined(EA_F87A7617_E180_442b_A3D0_541F8C64FC9B__INCLUDED_) diff --git a/VirtualTuringMachine/VMTJsonSerializer.cpp b/VirtualTuringMachine/VMTJsonSerializer.cpp index d539e02..a9164f0 100644 --- a/VirtualTuringMachine/VMTJsonSerializer.cpp +++ b/VirtualTuringMachine/VMTJsonSerializer.cpp @@ -1,14 +1,7 @@ #include "VMTJsonSerializer.h" -#include "VMTAlphabit.h" -#include "VMTTransitionImpl.h" -#include "vmtmachines/VMTComplexMachine.h" -#include "vmtmachines/VMTComplexMachineInner.h" -#include "vmtmachines/VMTMachineAlpha.h" -#include "vmtmachines/VMTMachineStub.h" -#include "vmtproject.h" - #include +#include #include #include #include @@ -16,36 +9,48 @@ #include #include #include -#include #include +#include "VMTAlphabit.h" +#include "VMTTransitionImpl.h" +#include "vmtmachines/VMTComplexMachine.h" +#include "vmtmachines/VMTComplexMachineInner.h" +#include "vmtmachines/VMTMachineAlpha.h" +#include "vmtmachines/VMTMachineStub.h" +#include "vmtproject.h" + namespace { const int SCHEMA_VERSION = 1; -QString newId() -{ - return QUuid::createUuid().toString(QUuid::WithoutBraces); -} +QString newId() { return QUuid::createUuid().toString(QUuid::WithoutBraces); } -QString machineTypeToString(IVMTMachine::MachineType type) -{ +QString machineTypeToString(IVMTMachine::MachineType type) { switch (type) { - case IVMTMachine::MT_START: return QStringLiteral("start"); - case IVMTMachine::MT_FINISH: return QStringLiteral("finish"); - case IVMTMachine::MT_LEFT: return QStringLiteral("left"); - case IVMTMachine::MT_RIGHT: return QStringLiteral("right"); - case IVMTMachine::MT_LEFT_WORD: return QStringLiteral("leftWord"); - case IVMTMachine::MT_RIGHT_WORD: return QStringLiteral("rightWord"); - case IVMTMachine::MT_WRITE: return QStringLiteral("write"); - case IVMTMachine::MT_COPY: return QStringLiteral("copy"); - case IVMTMachine::MT_COMPLEX: return QStringLiteral("complex"); - default: return QStringLiteral("start"); + case IVMTMachine::MT_START: + return QStringLiteral("start"); + case IVMTMachine::MT_FINISH: + return QStringLiteral("finish"); + case IVMTMachine::MT_LEFT: + return QStringLiteral("left"); + case IVMTMachine::MT_RIGHT: + return QStringLiteral("right"); + case IVMTMachine::MT_LEFT_WORD: + return QStringLiteral("leftWord"); + case IVMTMachine::MT_RIGHT_WORD: + return QStringLiteral("rightWord"); + case IVMTMachine::MT_WRITE: + return QStringLiteral("write"); + case IVMTMachine::MT_COPY: + return QStringLiteral("copy"); + case IVMTMachine::MT_COMPLEX: + return QStringLiteral("complex"); + default: + return QStringLiteral("start"); } } -IVMTMachine::MachineType machineTypeFromString(const QString& type) -{ +IVMTMachine::MachineType machineTypeFromString(const QString& type) { if (type == QLatin1String("finish")) return IVMTMachine::MT_FINISH; if (type == QLatin1String("left")) return IVMTMachine::MT_LEFT; if (type == QLatin1String("right")) return IVMTMachine::MT_RIGHT; @@ -57,21 +62,19 @@ IVMTMachine::MachineType machineTypeFromString(const QString& type) return IVMTMachine::MT_START; } -QJsonObject pointToJson(const QPoint& p) -{ +QJsonObject pointToJson(const QPoint& p) { QJsonObject o; o.insert(QStringLiteral("x"), p.x()); o.insert(QStringLiteral("y"), p.y()); return o; } -QPoint pointFromJson(const QJsonObject& o) -{ - return QPoint(o.value(QStringLiteral("x")).toInt(), o.value(QStringLiteral("y")).toInt()); +QPoint pointFromJson(const QJsonObject& o) { + return QPoint(o.value(QStringLiteral("x")).toInt(), + o.value(QStringLiteral("y")).toInt()); } -std::vector routingFromJson(const QJsonArray& arr) -{ +std::vector routingFromJson(const QJsonArray& arr) { std::vector points; points.reserve(arr.size()); for (const QJsonValue& pv : arr) { @@ -83,15 +86,14 @@ std::vector routingFromJson(const QJsonArray& arr) void linkTransition(const std::shared_ptr& transition, const std::shared_ptr& start, const std::shared_ptr& finish, - const QJsonObject& transitionJson) -{ + const QJsonObject& transitionJson) { transition->AttachStartMachine(start); transition->AttachFinishMachine(finish); start->AddOutgoingTransition(transition); finish->AddIncomingTransition(transition); - const std::vector route = - routingFromJson(transitionJson.value(QStringLiteral("routingPoints")).toArray()); + const std::vector route = routingFromJson( + transitionJson.value(QStringLiteral("routingPoints")).toArray()); if (route.size() >= 2) { transition->SetCommittedRoutingPolyline(route); } else { @@ -99,16 +101,14 @@ void linkTransition(const std::shared_ptr& transition, } } -std::shared_ptr alphabitFromString(const QString& alphabet) -{ +std::shared_ptr alphabitFromString(const QString& alphabet) { auto a = std::make_shared(); a->ReplaceString(alphabet); return a; } QJsonArray enabledSignsToJson(VMTTransitionConditions& conditions, - const std::shared_ptr& alphabit) -{ + const std::shared_ptr& alphabit) { QJsonArray arr; const QString all = alphabit->ToString(); for (const QChar& ch : all) { @@ -120,9 +120,7 @@ QJsonArray enabledSignsToJson(VMTTransitionConditions& conditions, } void applyEnabledSigns(VMTTransitionConditions& conditions, - const QJsonArray& signs, - IVMTEnvironment* env) -{ + const QJsonArray& signs, IVMTEnvironment* env) { QString alphabit = conditions.GetAlphabit()->ToString(); for (const QChar& ch : alphabit) { conditions.SetEnable(ch.toLatin1(), false, env); @@ -135,10 +133,9 @@ void applyEnabledSigns(VMTTransitionConditions& conditions, } } -QJsonObject machineToJson(IVMTMachine* machine, - const QMap& machineIds, - const QMap, QString>& innerIds) -{ +QJsonObject machineToJson( + IVMTMachine* machine, const QMap& machineIds, + const QMap, QString>& innerIds) { QJsonObject o; o.insert(QStringLiteral("id"), machineIds.value(machine)); o.insert(QStringLiteral("type"), machineTypeToString(machine->GetID())); @@ -161,18 +158,18 @@ QJsonObject machineToJson(IVMTMachine* machine, return o; } -QJsonObject bodyToJson(const QString& bodyId, - const QString& bodyName, - VMTComplexMachineInner* inner, - const std::shared_ptr& projectAlphabit, - QMap& machineIds, - const QMap, QString>& innerIds) -{ +QJsonObject bodyToJson( + const QString& bodyId, const QString& bodyName, + VMTComplexMachineInner* inner, + const std::shared_ptr& projectAlphabit, + QMap& machineIds, + const QMap, QString>& innerIds) { QJsonObject body; body.insert(QStringLiteral("id"), bodyId); body.insert(QStringLiteral("name"), bodyName); body.insert(QStringLiteral("alphabet"), - inner->GetAlphabit() ? inner->GetAlphabit()->ToString() : projectAlphabit->ToString()); + inner->GetAlphabit() ? inner->GetAlphabit()->ToString() + : projectAlphabit->ToString()); QJsonArray machines; for (const auto& m : inner->GetMachineCollection()) { @@ -192,8 +189,10 @@ QJsonObject bodyToJson(const QString& bodyId, QJsonObject tr; tr.insert(QStringLiteral("id"), newId()); - tr.insert(QStringLiteral("startMachineId"), machineIds.value(start.get())); - tr.insert(QStringLiteral("finishMachineId"), machineIds.value(finish.get())); + tr.insert(QStringLiteral("startMachineId"), + machineIds.value(start.get())); + tr.insert(QStringLiteral("finishMachineId"), + machineIds.value(finish.get())); QJsonArray route; for (const QPoint& p : t->GetCommittedRoutingPolyline()) { @@ -212,21 +211,17 @@ QJsonObject bodyToJson(const QString& bodyId, return body; } -} // namespace +} // namespace VMTJsonSerializer::VMTJsonSerializer(const QString& fileName) - : _file_name(fileName) -{ -} + : _file_name(fileName) {} -bool VMTJsonSerializer::isJsonPath(const QString& path) -{ - return path.endsWith(QLatin1String(".json"), Qt::CaseInsensitive) - || path.endsWith(QLatin1String(".vmt.json"), Qt::CaseInsensitive); +bool VMTJsonSerializer::isJsonPath(const QString& path) { + return path.endsWith(QLatin1String(".json"), Qt::CaseInsensitive) || + path.endsWith(QLatin1String(".vmt.json"), Qt::CaseInsensitive); } -bool VMTJsonSerializer::serialize(VMTProject* project) const -{ +bool VMTJsonSerializer::serialize(VMTProject* project) const { if (!project) return false; QMap, QString> innerIds; @@ -236,8 +231,9 @@ bool VMTJsonSerializer::serialize(VMTProject* project) const QMap, QString> innerNames; - const auto registerInner = [&](const std::shared_ptr& inner, - const QString& defaultName) -> QString { + const auto registerInner = + [&](const std::shared_ptr& inner, + const QString& defaultName) -> QString { if (!inner) return QString(); if (!innerIds.contains(inner)) { innerIds.insert(inner, newId()); @@ -246,7 +242,8 @@ bool VMTJsonSerializer::serialize(VMTProject* project) const return innerIds.value(inner); }; - std::function&, const QString&)> + std::function&, + const QString&)> scanInner; scanInner = [&](const std::shared_ptr& inner, const QString& defaultName) { @@ -262,7 +259,8 @@ bool VMTJsonSerializer::serialize(VMTProject* project) const }; QSet exported; - std::function&, const QString&)> + std::function&, + const QString&)> emitBody; emitBody = [&](const std::shared_ptr& inner, const QString& defaultName) { @@ -271,7 +269,8 @@ bool VMTJsonSerializer::serialize(VMTProject* project) const const QString bodyId = innerIds.value(inner); const QString bodyName = innerNames.value(inner, defaultName); bodiesArr.append(bodyToJson(bodyId, bodyName, inner.get(), - project->GetAlphabit(), machineIds, innerIds)); + project->GetAlphabit(), machineIds, + innerIds)); for (const auto& m : inner->GetMachineCollection()) { if (!m || m->GetID() != IVMTMachine::MT_COMPLEX) continue; const auto cm = std::dynamic_pointer_cast(m); @@ -313,8 +312,7 @@ bool VMTJsonSerializer::serialize(VMTProject* project) const return true; } -bool VMTJsonSerializer::deserialize(VMTProject* project) const -{ +bool VMTJsonSerializer::deserialize(VMTProject* project) const { if (!project) return false; QFile file(_file_name); @@ -326,18 +324,23 @@ bool VMTJsonSerializer::deserialize(VMTProject* project) const if (!doc.isObject()) return false; const QJsonObject root = doc.object(); - const QString alphabet = root.value(QStringLiteral("alphabet")).toString(QLatin1String(" 01")); + const QString alphabet = + root.value(QStringLiteral("alphabet")).toString(QLatin1String(" 01")); project->SetAlphabit(alphabitFromString(alphabet)); - project->GetName() = root.value(QStringLiteral("name")).toString(project->GetName()); + project->GetName() = + root.value(QStringLiteral("name")).toString(project->GetName()); QMap> bodiesById; QMap bodyJsonById; - for (const QJsonValue& bv : root.value(QStringLiteral("bodies")).toArray()) { + for (const QJsonValue& bv : + root.value(QStringLiteral("bodies")).toArray()) { const QJsonObject b = bv.toObject(); const QString id = b.value(QStringLiteral("id")).toString(); - const QString bodyName = b.value(QStringLiteral("name")).toString(QStringLiteral("Machine")); - const QString bodyAlphabet = b.value(QStringLiteral("alphabet")).toString(alphabet); + const QString bodyName = + b.value(QStringLiteral("name")).toString(QStringLiteral("Machine")); + const QString bodyAlphabet = + b.value(QStringLiteral("alphabet")).toString(alphabet); auto inner = std::make_shared( bodyName, alphabitFromString(bodyAlphabet)); bodiesById.insert(id, inner); @@ -352,11 +355,13 @@ bool VMTJsonSerializer::deserialize(VMTProject* project) const const QString bodyName = b.value(QStringLiteral("name")).toString(); const std::shared_ptr bodyAlphabit = inner->GetAlphabit(); - auto shell = std::make_shared(bodyName, bodyAlphabit); + auto shell = + std::make_shared(bodyName, bodyAlphabit); shell->SetInnerObject(inner, shell); QMap> idMap; - for (const QJsonValue& mv : b.value(QStringLiteral("machines")).toArray()) { + for (const QJsonValue& mv : + b.value(QStringLiteral("machines")).toArray()) { const QJsonObject mo = mv.toObject(); const QString id = mo.value(QStringLiteral("id")).toString(); const QString type = mo.value(QStringLiteral("type")).toString(); @@ -364,15 +369,18 @@ bool VMTJsonSerializer::deserialize(VMTProject* project) const std::shared_ptr machine; if (mt == IVMTMachine::MT_WRITE) { - const QString sign = mo.value(QStringLiteral("sign")).toString(); - const char ch = sign.isEmpty() - ? bodyAlphabit->GetLambda() - : sign[0].toLatin1(); + const QString sign = + mo.value(QStringLiteral("sign")).toString(); + const char ch = sign.isEmpty() ? bodyAlphabit->GetLambda() + : sign[0].toLatin1(); machine = std::make_shared(ch, shell); } else if (mt == IVMTMachine::MT_COMPLEX) { - const QString cmName = mo.value(QStringLiteral("name")).toString(bodyName); - auto cm = std::make_shared(cmName, bodyAlphabit); - const QString innerId = mo.value(QStringLiteral("innerId")).toString(); + const QString cmName = + mo.value(QStringLiteral("name")).toString(bodyName); + auto cm = + std::make_shared(cmName, bodyAlphabit); + const QString innerId = + mo.value(QStringLiteral("innerId")).toString(); if (bodiesById.contains(innerId)) { cm->SetInnerObject(bodiesById.value(innerId), shell); } @@ -382,18 +390,24 @@ bool VMTJsonSerializer::deserialize(VMTProject* project) const } if (!machine) continue; - machine->Move(pointFromJson(mo.value(QStringLiteral("center")).toObject()), nullptr); - machine->GetSize() = pointFromJson(mo.value(QStringLiteral("size")).toObject()); + machine->Move( + pointFromJson(mo.value(QStringLiteral("center")).toObject()), + nullptr); + machine->GetSize() = + pointFromJson(mo.value(QStringLiteral("size")).toObject()); machine->SetPower(mo.value(QStringLiteral("power")).toInt(1)); shell->AddMachine(machine); idMap.insert(id, machine); } - for (const QJsonValue& tv : b.value(QStringLiteral("transitions")).toArray()) { + for (const QJsonValue& tv : + b.value(QStringLiteral("transitions")).toArray()) { const QJsonObject to = tv.toObject(); - const QString startId = to.value(QStringLiteral("startMachineId")).toString(); - const QString finishId = to.value(QStringLiteral("finishMachineId")).toString(); + const QString startId = + to.value(QStringLiteral("startMachineId")).toString(); + const QString finishId = + to.value(QStringLiteral("finishMachineId")).toString(); if (!idMap.contains(startId) || !idMap.contains(finishId)) continue; const auto startMachine = idMap.value(startId); @@ -401,17 +415,19 @@ bool VMTJsonSerializer::deserialize(VMTProject* project) const auto transition = std::make_shared(shell); linkTransition(transition, startMachine, finishMachine, to); - const QJsonObject cond = to.value(QStringLiteral("conditions")).toObject(); - applyEnabledSigns(transition->GetConditions(), - cond.value(QStringLiteral("enabledSigns")).toArray(), - nullptr); + const QJsonObject cond = + to.value(QStringLiteral("conditions")).toObject(); + applyEnabledSigns( + transition->GetConditions(), + cond.value(QStringLiteral("enabledSigns")).toArray(), nullptr); shell->AddTransition(transition); } } project->GetMachines().clear(); - const QJsonArray rootIds = root.value(QStringLiteral("rootBodyIds")).toArray(); + const QJsonArray rootIds = + root.value(QStringLiteral("rootBodyIds")).toArray(); if (rootIds.isEmpty() && !bodiesById.isEmpty()) { for (auto it = bodiesById.begin(); it != bodiesById.end(); ++it) { auto cm = std::make_shared( @@ -423,11 +439,12 @@ bool VMTJsonSerializer::deserialize(VMTProject* project) const for (const QJsonValue& rv : rootIds) { const QString bodyId = rv.toString(); const QJsonObject b = bodyJsonById.value(bodyId); - const QString name = b.value(QStringLiteral("name")).toString(QStringLiteral("Machine")); + const QString name = b.value(QStringLiteral("name")) + .toString(QStringLiteral("Machine")); auto cm = std::make_shared( - name, - bodiesById.contains(bodyId) ? bodiesById.value(bodyId)->GetAlphabit() - : project->GetAlphabit()); + name, bodiesById.contains(bodyId) + ? bodiesById.value(bodyId)->GetAlphabit() + : project->GetAlphabit()); if (bodiesById.contains(bodyId)) { cm->SetInnerObject(bodiesById.value(bodyId), cm); } @@ -436,7 +453,8 @@ bool VMTJsonSerializer::deserialize(VMTProject* project) const } if (!project->GetMachines().empty()) { - project->GetCurrentMachineName() = project->GetMachines().front()->GetName(); + project->GetCurrentMachineName() = + project->GetMachines().front()->GetName(); } return !project->GetMachines().empty(); diff --git a/VirtualTuringMachine/VMTJsonSerializer.h b/VirtualTuringMachine/VMTJsonSerializer.h index 53a5382..fba5d6b 100644 --- a/VirtualTuringMachine/VMTJsonSerializer.h +++ b/VirtualTuringMachine/VMTJsonSerializer.h @@ -6,11 +6,10 @@ class VMTProject; /** JSON interchange format compatible with vmt-web (.vmt.json). */ -class VMTJsonSerializer -{ +class VMTJsonSerializer { QString _file_name; -public: + public: explicit VMTJsonSerializer(const QString& fileName); bool serialize(VMTProject* project) const; @@ -19,4 +18,4 @@ class VMTJsonSerializer static bool isJsonPath(const QString& path); }; -#endif // VMTJSONSERIALIZER_H +#endif // VMTJSONSERIALIZER_H diff --git a/VirtualTuringMachine/VMTLine.cpp b/VirtualTuringMachine/VMTLine.cpp old mode 100755 new mode 100644 index d50e23e..0c26e8c --- a/VirtualTuringMachine/VMTLine.cpp +++ b/VirtualTuringMachine/VMTLine.cpp @@ -1,159 +1,140 @@ #include "VMTLine.h" -#include - -VMTLine::VMTLine(std::shared_ptr alphabit) : _alphabit(alphabit),_machine(0),_zero(0){ - -} - +#include -void VMTLine::CheckPosition(long index){ - long array_index = (index-_zero)/SHIFT_STEP; - if(index<_zero){ - long new_zero = (index-SHIFT_STEP)/SHIFT_STEP*SHIFT_STEP; - long add = (_zero-new_zero)/SHIFT_STEP; - for(int i=0;iGetLambda(); - _array.insert(_array.begin(),ptr); - } - _zero = new_zero; - - } else - if(array_index>=(long)_array.size()){ - long to_add = array_index-_array.size()+1; - for(int i=0;iGetLambda(); +VMTLine::VMTLine(std::shared_ptr alphabit) + : _alphabit(alphabit), _machine(0), _zero(0) {} + +void VMTLine::CheckPosition(long index) { + long array_index = (index - _zero) / SHIFT_STEP; + if (index < _zero) { + long new_zero = (index - SHIFT_STEP) / SHIFT_STEP * SHIFT_STEP; + long add = (_zero - new_zero) / SHIFT_STEP; + for (int i = 0; i < add; i++) { + char* ptr = new char[SHIFT_STEP]; + for (int j = 0; j < SHIFT_STEP; j++) + ptr[j] = _alphabit->GetLambda(); + _array.insert(_array.begin(), ptr); + } + _zero = new_zero; + + } else if (array_index >= (long)_array.size()) { + long to_add = array_index - _array.size() + 1; + for (int i = 0; i < to_add; i++) { + char* ptr = new char[SHIFT_STEP]; + for (int j = 0; j < SHIFT_STEP; j++) + ptr[j] = _alphabit->GetLambda(); _array.push_back(ptr); } } - -} - -void VMTLine::ChangeAlphabit([[maybe_unused]] std::shared_ptr alphabit){ - } -std::shared_ptr VMTLine::CopyCurrentWord(){ - return std::shared_ptr (); -} +void VMTLine::ChangeAlphabit( + [[maybe_unused]] std::shared_ptr alphabit) {} -std::shared_ptr VMTLine::GetAlphabit(){ - return _alphabit; +std::shared_ptr VMTLine::CopyCurrentWord() { + return std::shared_ptr(); } -long VMTLine::GetMachinePosition(){ +std::shared_ptr VMTLine::GetAlphabit() { return _alphabit; } - return _machine; -} +long VMTLine::GetMachinePosition() { return _machine; } -long VMTLine::GetRightSignPosition(){ - for(ptrdiff_t i = static_cast(_array.size()) - 1; i >= 0; --i){ - for(int j=SHIFT_STEP-1;j>=0;j--){ - if(_array[i][j]!=_alphabit->GetLambda()) - return i*SHIFT_STEP+j+_zero; +long VMTLine::GetRightSignPosition() { + for (ptrdiff_t i = static_cast(_array.size()) - 1; i >= 0; --i) { + for (int j = SHIFT_STEP - 1; j >= 0; j--) { + if (_array[i][j] != _alphabit->GetLambda()) + return i * SHIFT_STEP + j + _zero; } } return -1; } -long VMTLine::GetLeftSignPosition(){ - for(size_t i=0; i< _array.size();i++){ - for(size_t j=0;jGetLambda()) - return i*SHIFT_STEP+j+_zero; - } - } - return -1; +long VMTLine::GetLeftSignPosition() { + for (size_t i = 0; i < _array.size(); i++) { + for (size_t j = 0; j < SHIFT_STEP; j++) { + if (_array[i][j] != _alphabit->GetLambda()) + return i * SHIFT_STEP + j + _zero; + } + } + return -1; } -IVMTLineObserver* VMTLine::GetObserver(){ - return nullptr; -} +IVMTLineObserver* VMTLine::GetObserver() { return nullptr; } -char VMTLine::GetValueAt(long index){ +char VMTLine::GetValueAt(long index) { CheckPosition(index); - long array_index = (index-_zero)/SHIFT_STEP; - long inside_index = (index-_zero)%SHIFT_STEP; + long array_index = (index - _zero) / SHIFT_STEP; + long inside_index = (index - _zero) % SHIFT_STEP; return _array[array_index][inside_index]; } -char VMTLine::GetValueAtMachine(){ - return this->GetValueAt(_machine); -} +char VMTLine::GetValueAtMachine() { return this->GetValueAt(_machine); } -bool VMTLine::IsEqualAlphabit([[maybe_unused]] VMTAlphabit* alphabit){ - return false; +bool VMTLine::IsEqualAlphabit([[maybe_unused]] VMTAlphabit* alphabit) { + return false; } -bool VMTLine::IsMachinePosition(long index){ - return _machine==index; -} +bool VMTLine::IsMachinePosition(long index) { return _machine == index; } -std::shared_ptr VMTLine::SetMachinePosition(long index){ - _machine = index; - return std::shared_ptr (); +std::shared_ptr VMTLine::SetMachinePosition(long index) { + _machine = index; + return std::shared_ptr(); } -void VMTLine::SetObserver([[maybe_unused]] IVMTLineObserver* observer){ - -} +void VMTLine::SetObserver([[maybe_unused]] IVMTLineObserver* observer) {} -std::shared_ptr VMTLine::SetSignAtMachine(char sign){ - return SetValueAt(_machine,sign); +std::shared_ptr VMTLine::SetSignAtMachine(char sign) { + return SetValueAt(_machine, sign); } -std::shared_ptr VMTLine::SetValueAt(long index, char sign){ +std::shared_ptr VMTLine::SetValueAt(long index, char sign) { CheckPosition(index); - long array_index = (index-_zero)/SHIFT_STEP; - long inside_index = (index-_zero)%SHIFT_STEP; + long array_index = (index - _zero) / SHIFT_STEP; + long inside_index = (index - _zero) % SHIFT_STEP; _array[array_index][inside_index] = sign; - return std::shared_ptr (); + return std::shared_ptr(); } -std::shared_ptr VMTLine::ShiftLeft(){ - _machine--; - return std::shared_ptr (); +std::shared_ptr VMTLine::ShiftLeft() { + _machine--; + return std::shared_ptr(); } -std::shared_ptr VMTLine::ShiftLeftWord(){ - do{ - _machine --; - }while(GetValueAtMachine()!=_alphabit->GetLambda()); - return std::shared_ptr (); +std::shared_ptr VMTLine::ShiftLeftWord() { + do { + _machine--; + } while (GetValueAtMachine() != _alphabit->GetLambda()); + return std::shared_ptr(); } -std::shared_ptr VMTLine::ShiftRight(){ - _machine ++; - return std::shared_ptr (); +std::shared_ptr VMTLine::ShiftRight() { + _machine++; + return std::shared_ptr(); } -std::shared_ptr VMTLine::ShiftRightWord(){ - do{ - _machine ++; - }while(GetValueAtMachine()!=_alphabit->GetLambda()); - return std::shared_ptr (); +std::shared_ptr VMTLine::ShiftRightWord() { + do { + _machine++; + } while (GetValueAtMachine() != _alphabit->GetLambda()); + return std::shared_ptr(); } -void VMTLine::Clear(){ - for(size_t i=0;i_array.size();i++) - for(size_t j=0;jGetLambda(); +void VMTLine::Clear() { + for (size_t i = 0; i < this->_array.size(); i++) + for (size_t j = 0; j < SHIFT_STEP; j++) + _array[i][j] = _alphabit->GetLambda(); } -QString VMTLine::ToString(){ - QString result; - for(size_t i=0;i_array.size();i++) - for(size_t j=0;j_array.size(); i++) + for (size_t j = 0; j < SHIFT_STEP; j++) + result.append(QChar(_array[i][j])); - return result; + return result; } - -VMTLine::~VMTLine(){ - -} +VMTLine::~VMTLine() {} diff --git a/VirtualTuringMachine/VMTLine.h b/VirtualTuringMachine/VMTLine.h old mode 100755 new mode 100644 index 02057a0..7037b78 --- a/VirtualTuringMachine/VMTLine.h +++ b/VirtualTuringMachine/VMTLine.h @@ -1,54 +1,51 @@ #if !defined(EA_0A644956_9080_4fc2_B4F8_CA6F597178CE__INCLUDED_) #define EA_0A644956_9080_4fc2_B4F8_CA6F597178CE__INCLUDED_ -#include "interfaces/IVMTLineObserver.h" -#include "VMTAlphabit.h" -#include "vmtundoelement.h" -#include #include +#include +#include "VMTAlphabit.h" +#include "interfaces/IVMTLineObserver.h" +#include "vmtundoelement.h" #define SHIFT_STEP 10 -class VMTLine -{ +class VMTLine { + private: + // IVMTLineObserver* _observer; -private: - //IVMTLineObserver* _observer; - - std::shared_ptr _alphabit; - std::vector _array; + std::shared_ptr _alphabit; + std::vector _array; long _machine; long _zero; void CheckPosition(long index); -public: + public: VMTLine(std::shared_ptr alphabit); void ChangeAlphabit(std::shared_ptr alphabit); std::shared_ptr CopyCurrentWord(); - - std::shared_ptr GetAlphabit(); - long GetMachinePosition(); + std::shared_ptr GetAlphabit(); + long GetMachinePosition(); long GetLeftSignPosition(); long GetRightSignPosition(); IVMTLineObserver* GetObserver(); void Clear(); - char GetValueAt(long index); - char GetValueAtMachine(); + char GetValueAt(long index); + char GetValueAtMachine(); bool IsEqualAlphabit(VMTAlphabit* alphabit); - bool IsMachinePosition(long index); - std::shared_ptr SetMachinePosition(long index); + bool IsMachinePosition(long index); + std::shared_ptr SetMachinePosition(long index); void SetObserver(IVMTLineObserver* observer); - std::shared_ptr SetSignAtMachine(char sign); - std::shared_ptr SetValueAt(long index, char sign); - std::shared_ptr ShiftLeft(); - std::shared_ptr ShiftLeftWord(); - std::shared_ptr ShiftRight(); - std::shared_ptr ShiftRightWord(); + std::shared_ptr SetSignAtMachine(char sign); + std::shared_ptr SetValueAt(long index, char sign); + std::shared_ptr ShiftLeft(); + std::shared_ptr ShiftLeftWord(); + std::shared_ptr ShiftRight(); + std::shared_ptr ShiftRightWord(); QString ToString(); virtual ~VMTLine(); }; -#endif // !defined(EA_0A644956_9080_4fc2_B4F8_CA6F597178CE__INCLUDED_) +#endif // !defined(EA_0A644956_9080_4fc2_B4F8_CA6F597178CE__INCLUDED_) diff --git a/VirtualTuringMachine/VMTSerializer.cpp b/VirtualTuringMachine/VMTSerializer.cpp old mode 100755 new mode 100644 index 06ab596..01c5c83 --- a/VirtualTuringMachine/VMTSerializer.cpp +++ b/VirtualTuringMachine/VMTSerializer.cpp @@ -1,40 +1,39 @@ #include "VMTSerializer.h" -#include "vmtmachines/VMTComplexMachine.h" + +#include + +#include "QDebug" #include "VMTAlphabit.h" -#include "vmtproject.h" #include "VMTTransitionImpl.h" -#include "QDebug" -#include +#include "vmtmachines/VMTComplexMachine.h" +#include "vmtproject.h" -#define TYPE_MACHINE 1 -#define TYPE_TRANSITION 2 +#define TYPE_MACHINE 1 +#define TYPE_TRANSITION 2 namespace { -bool readMachineId(QDataStream& stream, qint64& id) -{ +bool readMachineId(QDataStream& stream, qint64& id) { stream >> id; return stream.status() == QDataStream::Ok; } -} +} // namespace -VMTSerializer::VMTSerializer(QString & name) : _name(name){ -} +VMTSerializer::VMTSerializer(QString& name) : _name(name) {} -void VMTSerializer::FinalizeProject(VMTProject* project) -{ +void VMTSerializer::FinalizeProject(VMTProject* project) { if (!project) { return; } const std::shared_ptr alphabit = project->GetAlphabit(); - for (const std::shared_ptr& machine : project->GetMachines()) { + for (const std::shared_ptr& machine : + project->GetMachines()) { machine->ChangeAlphabit(alphabit); } } -bool VMTSerializer::DeserializeTransition(ReadContext& context, - const std::shared_ptr& machine) -{ +bool VMTSerializer::DeserializeTransition( + ReadContext& context, const std::shared_ptr& machine) { qint64 transitionId = 0; qint64 startMachineId = 0; qint64 finishMachineId = 0; @@ -47,7 +46,8 @@ bool VMTSerializer::DeserializeTransition(ReadContext& context, return false; } - auto transition = std::shared_ptr(new VMTTransitionImpl(machine)); + auto transition = + std::shared_ptr(new VMTTransitionImpl(machine)); transition->Deserialize(context._stream); if (startMachineId != 0) { @@ -56,7 +56,9 @@ bool VMTSerializer::DeserializeTransition(ReadContext& context, transition->AttachStartMachine(startIt->second); startIt->second->AddOutgoingTransition(transition); } else { - qWarning() << "VMTSerializer: transition start machine not found, id=" << startMachineId; + qWarning() + << "VMTSerializer: transition start machine not found, id=" + << startMachineId; } } @@ -66,7 +68,9 @@ bool VMTSerializer::DeserializeTransition(ReadContext& context, transition->AttachFinishMachine(finishIt->second); finishIt->second->AddIncomingTransition(transition); } else { - qWarning() << "VMTSerializer: transition finish machine not found, id=" << finishMachineId; + qWarning() + << "VMTSerializer: transition finish machine not found, id=" + << finishMachineId; } } @@ -75,7 +79,7 @@ bool VMTSerializer::DeserializeTransition(ReadContext& context, return true; } -void VMTSerializer::Deserialize(VMTProject *project){ +void VMTSerializer::Deserialize(VMTProject* project) { project->GetCurrentMachineName() = ""; project->GetMachines().clear(); @@ -83,10 +87,10 @@ void VMTSerializer::Deserialize(VMTProject *project){ qDebug() << _name; - if(context._open){ + if (context._open) { qDebug() << "Start deserialize"; QString signs; - ReadString(context,signs); + ReadString(context, signs); project->GetAlphabit()->ReplaceString(signs); qDebug() << "Alphabit:" << project->GetAlphabit()->ToString(); @@ -95,15 +99,16 @@ void VMTSerializer::Deserialize(VMTProject *project){ qDebug() << "Machine count:" << count; - for(int i=0;i machine = Deserialize(context,1,true); + for (int i = 0; i < count; i++) { + std::shared_ptr machine = + Deserialize(context, 1, true); } - std::map> inner_map; + std::map> inner_map; qDebug() << "Total machines " << context._machines.size(); - for(auto machine: context._complex){ - if(machine){ + for (auto machine : context._complex) { + if (machine) { qDebug() << "add " << machine->GetName(); project->GetMachines().push_back(machine); inner_map[machine->GetName()] = machine->GetInnerObject(); @@ -111,32 +116,33 @@ void VMTSerializer::Deserialize(VMTProject *project){ } qDebug() << "Replace inner machines"; - for(auto &machine: project->GetMachines()){ - ReplaceInnerObject(true,machine,inner_map); + for (auto& machine : project->GetMachines()) { + ReplaceInnerObject(true, machine, inner_map); } qDebug() << "Clear garbrage"; - for(auto &machine: project->GetMachines()) - ClearGarbrageTransitions(machine); + for (auto& machine : project->GetMachines()) + ClearGarbrageTransitions(machine); FinalizeProject(project); - } else qDebug() << "Opps not open!"; + } else + qDebug() << "Opps not open!"; qDebug() << "Finish deserialize"; } -void VMTSerializer::Deserialize(VMTProject *project,QBuffer &buffer){ - //QString current_name= project->GetCurrentMachineName() = ""; +void VMTSerializer::Deserialize(VMTProject* project, QBuffer& buffer) { + // QString current_name= project->GetCurrentMachineName() = ""; project->GetMachines().clear(); ReadContext context(buffer); qDebug() << _name; - if(context._open){ + if (context._open) { qDebug() << "Start deserialize"; QString signs; - ReadString(context,signs); + ReadString(context, signs); project->GetAlphabit()->ReplaceString(signs); qDebug() << "Alphabit:" << project->GetAlphabit()->ToString(); @@ -145,90 +151,101 @@ void VMTSerializer::Deserialize(VMTProject *project,QBuffer &buffer){ qDebug() << "Machine count:" << count; - for(int i=0;i machine = Deserialize(context,1,true); + for (int i = 0; i < count; i++) { + std::shared_ptr machine = + Deserialize(context, 1, true); } - std::map> inner_map; + std::map> inner_map; qDebug() << "Total machines " << context._machines.size(); - for(auto machine: context._complex){ - if(machine){ + for (auto machine : context._complex) { + if (machine) { qDebug() << "add " << machine->GetName(); project->GetMachines().push_back(machine); inner_map[machine->GetName()] = machine->GetInnerObject(); } } - for(auto &machine: project->GetMachines()){ - ReplaceInnerObject(true,machine,inner_map); + for (auto& machine : project->GetMachines()) { + ReplaceInnerObject(true, machine, inner_map); } - for(auto &machine: project->GetMachines()) - ClearGarbrageTransitions(machine); + for (auto& machine : project->GetMachines()) + ClearGarbrageTransitions(machine); FinalizeProject(project); - } else qDebug() << "Opps not open!"; + } else + qDebug() << "Opps not open!"; } -void VMTSerializer::ReplaceInnerObject(bool recursive,std::shared_ptr machine, std::map> inner_map){ +void VMTSerializer::ReplaceInnerObject( + bool recursive, std::shared_ptr machine, + std::map> inner_map) { auto ptr = inner_map.find(machine->GetName()); - if(ptr!=inner_map.end()){ - if(machine->GetInnerObject()!=ptr->second){ + if (ptr != inner_map.end()) { + if (machine->GetInnerObject() != ptr->second) { qDebug() << "Replacer replace:" << machine->GetName(); - machine->SetInnerObject(ptr->second,machine); + machine->SetInnerObject(ptr->second, machine); } else { qDebug() << "Replacer skip:" << machine->GetName(); } - if(recursive) - for(auto &child: machine->GetMachineCollection()){ - std::shared_ptr ptr_child = std::dynamic_pointer_cast(child); - if(ptr_child) - { - qDebug() << "Machine:" << ptr_child->GetName() << " has " << ptr_child->GetMachineCollection().size() << " childs"; - ReplaceInnerObject(false,ptr_child,inner_map); + if (recursive) + for (auto& child : machine->GetMachineCollection()) { + std::shared_ptr ptr_child = + std::dynamic_pointer_cast(child); + if (ptr_child) { + qDebug() << "Machine:" << ptr_child->GetName() << " has " + << ptr_child->GetMachineCollection().size() + << " childs"; + ReplaceInnerObject(false, ptr_child, inner_map); } } - } else qDebug() << "Replacer not found map for " << machine->GetName(); + } else + qDebug() << "Replacer not found map for " << machine->GetName(); } -std::shared_ptr VMTSerializer::Deserialize(ReadContext & context, long inner_id,bool binner){ +std::shared_ptr VMTSerializer::Deserialize( + ReadContext& context, long inner_id, bool binner) { std::shared_ptr machine; - if(context._open) - { + if (context._open) { QString value; - machine = std::shared_ptr(new VMTComplexMachine(value,std::shared_ptr(new VMTAlphabit()))); + machine = std::shared_ptr(new VMTComplexMachine( + value, std::shared_ptr(new VMTAlphabit()))); machine->Deserialize(context._stream); - - ReadString(context,value); machine->SetName(value); + ReadString(context, value); + machine->SetName(value); qDebug() << "Complex machine name:" << machine->GetName(); - ReadString(context,value); machine->GetAlphabit()->ReplaceString(value); - qDebug() << "Complex machine alphabit:" << machine->GetAlphabit()->ToString(); + ReadString(context, value); + machine->GetAlphabit()->ReplaceString(value); + qDebug() << "Complex machine alphabit:" + << machine->GetAlphabit()->ToString(); - if(!binner){ + if (!binner) { qDebug() << "Finding inner machine"; auto ptr = context._inner.find(inner_id); - if(ptr!=context._inner.end()){ - machine->SetInnerObject(ptr->second,machine); + if (ptr != context._inner.end()) { + machine->SetInnerObject(ptr->second, machine); qDebug() << "Found"; - } else qDebug() << "ERROR!!! ID:" << inner_id; + } else + qDebug() << "ERROR!!! ID:" << inner_id; } - if(binner) - { + if (binner) { qDebug() << "Deserialize inner machine"; - context._inner[inner_id]=machine->GetInnerObject(); + context._inner[inner_id] = machine->GetInnerObject(); - bool found= false; - for(auto &complex_machine : context._complex) - if(complex_machine->GetName() == machine->GetName()) found = true; - if(!found) { + bool found = false; + for (auto& complex_machine : context._complex) + if (complex_machine->GetName() == machine->GetName()) + found = true; + if (!found) { context._complex.insert(machine); } @@ -236,76 +253,89 @@ std::shared_ptr VMTSerializer::Deserialize(ReadContext & cont context._stream >> total_components; qDebug() << "Total components:" << total_components; - while(total_components>0){ + while (total_components > 0) { qint32 type_id; context._stream >> type_id; qDebug() << "MACHINE_TYPE:" << type_id; total_components--; - switch(type_id){ - case TYPE_MACHINE: - { - qint64 id; context._stream >> id; - qint32 machine_type; context._stream >> machine_type; - qDebug() << "\n---------------Machine id:" << id << " Type:"<< machine_type; - - if(machine_type==IVMTMachine::MachineType::MT_COMPLEX){ - qDebug() << "\n---------------Machine : complex"; - bool inner_local; context._stream >> inner_local; - qint64 inner_id_local; context._stream >> inner_id_local; - std::shared_ptr stub =Deserialize(context,inner_id_local,inner_local); - stub->SetParent(machine); - auto ptr = context._machines.find(id); - if(ptr!=context._machines.end()){ - qDebug() << "Insert complex old id=" << id; - machine->AddMachine(ptr->second); - } else { - qDebug() << "Insert complex new id=" << id; - context._machines[id]=stub; - machine->AddMachine(stub); - } - - } else { - qDebug() << "Deserialize machine id=" << id; - if(machine_type==0) { - qWarning() << "VMTSerializer: invalid machine type"; - return machine; - } - std::shared_ptr stub = VMTMachineStub::CreateMachineByID((IVMTMachine::MachineType)machine_type,machine); - if(stub) - { - qDebug() << "start deserialize"; - stub->Deserialize(context._stream); - qDebug() << "end deserialize"; + switch (type_id) { + case TYPE_MACHINE: { + qint64 id; + context._stream >> id; + qint32 machine_type; + context._stream >> machine_type; + qDebug() << "\n---------------Machine id:" << id + << " Type:" << machine_type; + + if (machine_type == + IVMTMachine::MachineType::MT_COMPLEX) { + qDebug() << "\n---------------Machine : complex"; + bool inner_local; + context._stream >> inner_local; + qint64 inner_id_local; + context._stream >> inner_id_local; + std::shared_ptr stub = + Deserialize(context, inner_id_local, + inner_local); + stub->SetParent(machine); auto ptr = context._machines.find(id); - if(ptr!=context._machines.end()){ - qDebug() << "Add machine old id=" << id; + if (ptr != context._machines.end()) { + qDebug() << "Insert complex old id=" << id; machine->AddMachine(ptr->second); } else { - qDebug() << "Add machine new id=" << id; - context._machines[id]=stub; + qDebug() << "Insert complex new id=" << id; + context._machines[id] = stub; machine->AddMachine(stub); } + } else { - qWarning() << "VMTSerializer: cannot create machine type" << machine_type; + qDebug() << "Deserialize machine id=" << id; + if (machine_type == 0) { + qWarning() + << "VMTSerializer: invalid machine type"; + return machine; + } + std::shared_ptr stub = + VMTMachineStub::CreateMachineByID( + (IVMTMachine::MachineType)machine_type, + machine); + if (stub) { + qDebug() << "start deserialize"; + stub->Deserialize(context._stream); + qDebug() << "end deserialize"; + auto ptr = context._machines.find(id); + if (ptr != context._machines.end()) { + qDebug() << "Add machine old id=" << id; + machine->AddMachine(ptr->second); + } else { + qDebug() << "Add machine new id=" << id; + context._machines[id] = stub; + machine->AddMachine(stub); + } + } else { + qWarning() << "VMTSerializer: cannot create " + "machine type" + << machine_type; + return machine; + } + } + qDebug() << "\n--------------- End deserialize machine"; + + break; + } + case TYPE_TRANSITION: { + if (!DeserializeTransition(context, machine)) { + qWarning() << "VMTSerializer: failed to " + "deserialize transition"; return machine; } + break; } - qDebug() << "\n--------------- End deserialize machine" ; - - break; - } - case TYPE_TRANSITION: - { - if (!DeserializeTransition(context, machine)) { - qWarning() << "VMTSerializer: failed to deserialize transition"; + default: + qWarning() << "VMTSerializer: unknown component type" + << type_id; return machine; - } - break; - } - default: - qWarning() << "VMTSerializer: unknown component type" << type_id; - return machine; } } } @@ -314,48 +344,46 @@ std::shared_ptr VMTSerializer::Deserialize(ReadContext & cont return machine; } -void VMTSerializer::Serialize(VMTProject *project){ +void VMTSerializer::Serialize(VMTProject* project) { WriteContext context(_name); qDebug() << "context created"; - if(context._open){ - qDebug() << "context opened"; - WriteString(context,project->GetAlphabit()->ToString()); - context._stream << (qint64) project->GetMachines().size(); + if (context._open) { + qDebug() << "context opened"; + WriteString(context, project->GetAlphabit()->ToString()); + context._stream << (qint64)project->GetMachines().size(); - for(auto machine : project->GetMachines()){ - qDebug() << "serialize mschine:" << machine->GetName(); + for (auto machine : project->GetMachines()) { + qDebug() << "serialize mschine:" << machine->GetName(); context._inner[machine->GetInnerObject()] = context._inner_id++; - Serialize(context,machine,true); + Serialize(context, machine, true); } } } -void VMTSerializer::Serialize(VMTProject *project,QBuffer& buffer){ +void VMTSerializer::Serialize(VMTProject* project, QBuffer& buffer) { WriteContext context(buffer); - if(context._open){ - WriteString(context,project->GetAlphabit()->ToString()); - context._stream << (qint64) project->GetMachines().size(); + if (context._open) { + WriteString(context, project->GetAlphabit()->ToString()); + context._stream << (qint64)project->GetMachines().size(); - for(auto machine : project->GetMachines()){ + for (auto machine : project->GetMachines()) { context._inner[machine->GetInnerObject()] = context._inner_id++; - Serialize(context,machine,true); + Serialize(context, machine, true); } } } -void VMTSerializer::ReadString(ReadContext & context, QString& str){ - if(context._open) - { +void VMTSerializer::ReadString(ReadContext& context, QString& str) { + if (context._open) { short int length; context._stream >> length; - if(length>0) - { - char * array = new char[length+1]; - std::memset(array,0,length+1); - context._stream.readRawData(array,length); + if (length > 0) { + char* array = new char[length + 1]; + std::memset(array, 0, length + 1); + context._stream.readRawData(array, length); str = QString::fromUtf8((const char*)array); delete[] array; @@ -363,115 +391,108 @@ void VMTSerializer::ReadString(ReadContext & context, QString& str){ } } -void VMTSerializer::WriteString(WriteContext & context, const QString& str){ - if(context._open) - { - //context._stream << (short int)str.length(); +void VMTSerializer::WriteString(WriteContext& context, const QString& str) { + if (context._open) { + // context._stream << (short int)str.length(); QByteArray array = str.toUtf8(); context._stream << (short int)array.length(); - const char* carray = array.constData(); + const char* carray = array.constData(); for (int i = 0; i < array.length(); i++) { - context._stream << (qint8) (carray[i]); + context._stream << (qint8)(carray[i]); // context._stream << (qint8)array[i];//(str[i]); - } - } } -void VMTSerializer::Serialize(WriteContext & context,std::shared_ptr machine,bool bInner) -{ - if(context._open) - { +void VMTSerializer::Serialize(WriteContext& context, + std::shared_ptr machine, + bool bInner) { + if (context._open) { machine->Serialize(context._stream); - WriteString(context,machine->GetName()); - WriteString(context,machine->GetAlphabit()->ToString()); + WriteString(context, machine->GetName()); + WriteString(context, machine->GetAlphabit()->ToString()); - - - if(!bInner) return; + if (!bInner) return; qDebug() << "Serialize machine structure:" << machine->GetName(); // fill machine hash qint64 total_components = 0; - for(auto &stub : machine->GetMachineCollection()) - { + for (auto& stub : machine->GetMachineCollection()) { auto find = context._machines.find(stub); - if(find==context._machines.end()) - context._machines[stub]=context._machine_id++; + if (find == context._machines.end()) + context._machines[stub] = context._machine_id++; - total_components ++; + total_components++; } // fill transition hash - for(auto &stub : machine->GetTransitionCollection()) - { + for (auto& stub : machine->GetTransitionCollection()) { auto find = context._transitions.find(stub); - if(find==context._transitions.end()) - context._transitions[stub]=context._transition_id++; - total_components ++; + if (find == context._transitions.end()) + context._transitions[stub] = context._transition_id++; + total_components++; } context._stream << (qint64)total_components; - - for(auto stub : machine->GetMachineCollection()) - { - long nID =context._machines[stub]; - context._stream << (qint32) TYPE_MACHINE; - context._stream << (qint64) nID; - context._stream << (qint32) stub->GetID(); - - if (stub->GetID()==IVMTMachine::MachineType::MT_COMPLEX) - { - qDebug() << "----- Serialize complex machine:" << stub->GetName(); - std::shared_ptr ptr = std::dynamic_pointer_cast(stub); - if(ptr) - { - if(context._inner.find(ptr->GetInnerObject())!=context._inner.end()) - { + for (auto stub : machine->GetMachineCollection()) { + long nID = context._machines[stub]; + context._stream << (qint32)TYPE_MACHINE; + context._stream << (qint64)nID; + context._stream << (qint32)stub->GetID(); + + if (stub->GetID() == IVMTMachine::MachineType::MT_COMPLEX) { + qDebug() << "----- Serialize complex machine:" + << stub->GetName(); + std::shared_ptr ptr = + std::dynamic_pointer_cast(stub); + if (ptr) { + if (context._inner.find(ptr->GetInnerObject()) != + context._inner.end()) { context._stream << false; - context._stream << (qint64) context._inner[ptr->GetInnerObject()]; - Serialize(context,ptr,false); - } else - { + context._stream + << (qint64)context._inner[ptr->GetInnerObject()]; + Serialize(context, ptr, false); + } else { context._stream << true; context._stream << (qint64)context._inner_id; - qDebug() << "Add inner:" << context._inner_id << " for:" << ptr->GetName(); - context._inner[ptr->GetInnerObject()] = context._inner_id++; - Serialize(context,ptr,true); + qDebug() << "Add inner:" << context._inner_id + << " for:" << ptr->GetName(); + context._inner[ptr->GetInnerObject()] = + context._inner_id++; + Serialize(context, ptr, true); } - qDebug() << "----- Done serialize complex machine:" << stub->GetName(); + qDebug() << "----- Done serialize complex machine:" + << stub->GetName(); } - } else - { - qDebug() << "----- Serialize simple machine:" << stub->GetName(); + } else { + qDebug() << "----- Serialize simple machine:" + << stub->GetName(); stub->Serialize(context._stream); - qDebug() << "----- Done serialize simple machine:" << stub->GetName(); + qDebug() << "----- Done serialize simple machine:" + << stub->GetName(); } } // save transitions - for(auto stub : machine->GetTransitionCollection()) - { + for (auto stub : machine->GetTransitionCollection()) { long nID = context._transitions[stub]; // save transition type - context._stream << (qint32) TYPE_TRANSITION; - context._stream << (qint64) nID; + context._stream << (qint32)TYPE_TRANSITION; + context._stream << (qint64)nID; - if(auto ptr=stub->GetStartMachine().lock()) - { + if (auto ptr = stub->GetStartMachine().lock()) { context._stream << (qint64)context._machines[ptr]; qDebug() << "Ptr" << (qint64)context._machines[ptr]; - } else context._stream << (qint64)0; - + } else + context._stream << (qint64)0; - if(auto ptr=stub->GetFinishMachine().lock()) - { + if (auto ptr = stub->GetFinishMachine().lock()) { context._stream << (qint64)context._machines[ptr]; qDebug() << "Ptr" << (qint64)context._machines[ptr]; - } else context._stream << (qint64)0; + } else + context._stream << (qint64)0; // save transition internal data stub->Serialize(context._stream); @@ -479,20 +500,22 @@ void VMTSerializer::Serialize(WriteContext & context,std::shared_ptr machine){ - for(std::shared_ptr m: machine->GetMachineCollection()){ - - bool removed = true; +void VMTSerializer::ClearGarbrageTransitions( + std::shared_ptr machine) { + for (std::shared_ptr m : machine->GetMachineCollection()) { + bool removed = true; - while(removed){ + while (removed) { removed = false; - for(const std::weak_ptr& t: m->GetIncomingTransitions()){ + for (const std::weak_ptr& t : + m->GetIncomingTransitions()) { bool found = false; - if(auto tptr = t.lock()){ - for(std::shared_ptr tc: machine->GetTransitionCollection()) if(tc==tptr) found = true; - if(!found) - { + if (auto tptr = t.lock()) { + for (std::shared_ptr tc : + machine->GetTransitionCollection()) + if (tc == tptr) found = true; + if (!found) { m->RemoveIncomingTransition(tptr); qDebug() << "!!!!!!!!!!! Removed garbrage"; removed = true; @@ -502,17 +525,19 @@ void VMTSerializer::ClearGarbrageTransitions(std::shared_ptr } } - removed = true; + removed = true; - while(removed){ + while (removed) { removed = false; - for(const std::weak_ptr &t: m->GetOutgoingTransitions()){ + for (const std::weak_ptr& t : + m->GetOutgoingTransitions()) { bool found = false; - if(auto tptr = t.lock()){ - for(std::shared_ptr &tc: machine->GetTransitionCollection()) if(tc==tptr) found = true; - if(!found) - { + if (auto tptr = t.lock()) { + for (std::shared_ptr& tc : + machine->GetTransitionCollection()) + if (tc == tptr) found = true; + if (!found) { m->RemoveOutgoingTransition(tptr); qDebug() << "!!!!!!!!!!! Removed garbrage"; removed = true; @@ -524,6 +549,4 @@ void VMTSerializer::ClearGarbrageTransitions(std::shared_ptr } } -VMTSerializer::~VMTSerializer(){ - -} +VMTSerializer::~VMTSerializer() {} diff --git a/VirtualTuringMachine/VMTSerializer.h b/VirtualTuringMachine/VMTSerializer.h old mode 100755 new mode 100644 index 0b78ca6..531dfaf --- a/VirtualTuringMachine/VMTSerializer.h +++ b/VirtualTuringMachine/VMTSerializer.h @@ -1,137 +1,134 @@ #if !defined(EA_FBF9ECAB_E1A9_4b4f_A5F3_7B533457B83F__INCLUDED_) #define EA_FBF9ECAB_E1A9_4b4f_A5F3_7B533457B83F__INCLUDED_ - -#include -#include -#include -#include - -#include -#include #include #include #include -#include + #include +#include +#include +#include +#include +#include +#include +#include class VMTProject; struct machine_compare { - bool operator() (const std::shared_ptr &a, const std::shared_ptr &b) const{ + bool operator()(const std::shared_ptr& a, + const std::shared_ptr& b) const { return a->GetName() < b->GetName(); } }; -class VMTSerializer -{ - -public: - - class ReadContext{ - public: +class VMTSerializer { + public: + class ReadContext { + public: QDataStream _stream; - QFile _file; - bool _open; - + QFile _file; + bool _open; - std::map> _machines; - std::set,machine_compare> _complex; - std::map> _transitions; - std::map> _inner; + std::map> _machines; + std::set, machine_compare> _complex; + std::map> _transitions; + std::map> _inner; - ReadContext(QBuffer &buffer){ - _open = true; - buffer.open(QIODevice::ReadOnly); - _stream.setDevice(&buffer); + ReadContext(QBuffer& buffer) { + _open = true; + buffer.open(QIODevice::ReadOnly); + _stream.setDevice(&buffer); } - ReadContext(QString name){ + ReadContext(QString name) { _open = false; _file.setFileName(name); _file.open(QIODevice::ReadOnly); - if(_file.isOpen()){ + if (_file.isOpen()) { _stream.setDevice(&_file); _open = true; - }else { - qWarning() << "VMTSerializer: cannot read file" << name << _file.errorString(); + } else { + qWarning() << "VMTSerializer: cannot read file" << name + << _file.errorString(); } - } - - virtual ~ReadContext(){ - if(_file.isOpen()) _file.close(); + virtual ~ReadContext() { + if (_file.isOpen()) _file.close(); } }; - class WriteContext{ - public: + class WriteContext { + public: long _machine_id; long _inner_id; long _transition_id; QDataStream _stream; - QFile _file; - bool _open; + QFile _file; + bool _open; - WriteContext(QString name){ + WriteContext(QString name) { _open = false; _file.setFileName(name); _file.open(QIODevice::WriteOnly | QIODevice::Truncate); - if(_file.isOpen()){ + if (_file.isOpen()) { _open = true; _stream.setDevice(&_file); } else { - qWarning() << "VMTSerializer: cannot create file" << name << _file.errorString(); + qWarning() << "VMTSerializer: cannot create file" << name + << _file.errorString(); } _machine_id = 1; _inner_id = 1; _transition_id = 1; } - WriteContext(QBuffer &buffer){ - buffer.open(QIODevice::WriteOnly); - _stream.setDevice(&buffer); + WriteContext(QBuffer& buffer) { + buffer.open(QIODevice::WriteOnly); + _stream.setDevice(&buffer); _machine_id = 1; _inner_id = 1; _transition_id = 1; _open = true; } - std::map,long> _machines; - std::map,long> _transitions; - std::map,long> _inner; + std::map, long> _machines; + std::map, long> _transitions; + std::map, long> _inner; - virtual ~WriteContext(){ - if(_file.isOpen()) _file.close(); + virtual ~WriteContext() { + if (_file.isOpen()) _file.close(); } }; - - - - VMTSerializer(QString & name); - - void Deserialize(VMTProject *project); - void Deserialize(VMTProject *project,QBuffer &buffer); - std::shared_ptr Deserialize(ReadContext & context,long inner_id,bool binner); - - void Serialize(VMTProject *project); - void Serialize(VMTProject *project,QBuffer& buffer); - void Serialize(WriteContext & context,std::shared_ptr p_Machine,bool bInner); - - virtual ~VMTSerializer(); - - protected: - QString _name; - void WriteString(WriteContext & context, const QString &str); - void ReadString(ReadContext & context, QString& str); - void ReplaceInnerObject(bool recursive,std::shared_ptr machine,std::map> inner_map); - void ClearGarbrageTransitions(std::shared_ptr machine); - void FinalizeProject(VMTProject* project); - bool DeserializeTransition(ReadContext& context, - const std::shared_ptr& machine); - + VMTSerializer(QString& name); + + void Deserialize(VMTProject* project); + void Deserialize(VMTProject* project, QBuffer& buffer); + std::shared_ptr Deserialize(ReadContext& context, + long inner_id, bool binner); + + void Serialize(VMTProject* project); + void Serialize(VMTProject* project, QBuffer& buffer); + void Serialize(WriteContext& context, + std::shared_ptr p_Machine, bool bInner); + + virtual ~VMTSerializer(); + + protected: + QString _name; + void WriteString(WriteContext& context, const QString& str); + void ReadString(ReadContext& context, QString& str); + void ReplaceInnerObject( + bool recursive, std::shared_ptr machine, + std::map> inner_map); + void ClearGarbrageTransitions(std::shared_ptr machine); + void FinalizeProject(VMTProject* project); + bool DeserializeTransition( + ReadContext& context, + const std::shared_ptr& machine); }; -#endif // !defined(EA_FBF9ECAB_E1A9_4b4f_A5F3_7B533457B83F__INCLUDED_) +#endif // !defined(EA_FBF9ECAB_E1A9_4b4f_A5F3_7B533457B83F__INCLUDED_) diff --git a/VirtualTuringMachine/VMTTransitionConditions.cpp b/VirtualTuringMachine/VMTTransitionConditions.cpp old mode 100755 new mode 100644 index 4aba647..d48a1cf --- a/VirtualTuringMachine/VMTTransitionConditions.cpp +++ b/VirtualTuringMachine/VMTTransitionConditions.cpp @@ -1,141 +1,133 @@ #include "VMTTransitionConditions.h" -#include "vmticons.h" + #include + #include "interfaces/IVMTTransition.h" +#include "vmticons.h" -VMTTransitionConditions::VMTTransitionConditions(IVMTTransition *transition,std::shared_ptr alphabit) : - _alphabit(alphabit), _transition(transition){ - _signs = _alphabit->ToString(); +VMTTransitionConditions::VMTTransitionConditions( + IVMTTransition* transition, std::shared_ptr alphabit) + : _alphabit(alphabit), _transition(transition) { + _signs = _alphabit->ToString(); } -VMTTransitionConditions& VMTTransitionConditions::operator=(const VMTTransitionConditions& other){ - _signs = other._signs; - _transition = other._transition; - _alphabit = other._alphabit; - return *this; +VMTTransitionConditions& VMTTransitionConditions::operator=( + const VMTTransitionConditions& other) { + _signs = other._signs; + _transition = other._transition; + _alphabit = other._alphabit; + return *this; } -QPixmap* VMTTransitionConditions::GetImage(){ +QPixmap* VMTTransitionConditions::GetImage() { static QPixmap image; image = VmtIcons::linkPixmap(); return ℑ } -const QString& VMTTransitionConditions::GetMessage(){ +const QString& VMTTransitionConditions::GetMessage() { static QString msg("Select sign allowed for selected transition"); return msg; } - -VMTTransitionConditions::VMTTransitionConditions(const VMTTransitionConditions& other) : _alphabit(other._alphabit){ - this->_signs = other._signs; +VMTTransitionConditions::VMTTransitionConditions( + const VMTTransitionConditions& other) + : _alphabit(other._alphabit) { + this->_signs = other._signs; this->_transition = other._transition; } - -void VMTTransitionConditions::Update(IVMTEnvironment *environment){ - _transition->Changed(environment); +void VMTTransitionConditions::Update(IVMTEnvironment* environment) { + _transition->Changed(environment); } -void VMTTransitionConditions::Deserialize(QDataStream& stream){ +void VMTTransitionConditions::Deserialize(QDataStream& stream) { short int length; stream >> length; - if(length>0) - { - char * array = new char[length+1]; - memset(array,0,length+1); - stream.readRawData(array,length); + if (length > 0) { + char* array = new char[length + 1]; + memset(array, 0, length + 1); + stream.readRawData(array, length); _signs.resize(length); - for(int i=0;i other){ - - if(IsAllEnabled()) - { - _alphabit = other; - _signs = _alphabit->ToString(); - } else - { - _alphabit = other; - QString new_signs; - for(int i=0;i<_signs.length();i++) - { - if(_alphabit->IsSign(_signs[i].toLatin1())) new_signs += _signs[i]; - } - _signs = new_signs; - qDebug() << "VMTTransitionConditions::ChangeAlphabit:" << _signs; - } - + const char* array = _signs.toStdString().c_str(); + stream.writeRawData(array, _signs.length()); +} + +void VMTTransitionConditions::ChangeAlphabit( + const std::shared_ptr other) { + if (IsAllEnabled()) { + _alphabit = other; + _signs = _alphabit->ToString(); + } else { + _alphabit = other; + QString new_signs; + for (int i = 0; i < _signs.length(); i++) { + if (_alphabit->IsSign(_signs[i].toLatin1())) new_signs += _signs[i]; + } + _signs = new_signs; + qDebug() << "VMTTransitionConditions::ChangeAlphabit:" << _signs; + } } +const QString& VMTTransitionConditions::GetAsString() { return this->_signs; } - -const QString& VMTTransitionConditions::GetAsString(){ - return this->_signs; +QPoint VMTTransitionConditions::GetDimensions( + [[maybe_unused]] IVMTEnvironment* environment, [[maybe_unused]] int size) { + return QPoint(); } -QPoint VMTTransitionConditions::GetDimensions([[maybe_unused]] IVMTEnvironment* environment, [[maybe_unused]] int size){ - return QPoint(); +bool VMTTransitionConditions::IsAllDisabled() { + QString alphabit_string = _alphabit->ToString(); + return alphabit_string.size() != _signs.size(); } -bool VMTTransitionConditions::IsAllDisabled(){ +bool VMTTransitionConditions::IsAllEnabled() { QString alphabit_string = _alphabit->ToString(); - return alphabit_string.size()!=_signs.size(); + return alphabit_string.size() == _signs.size(); } -bool VMTTransitionConditions::IsAllEnabled(){ - QString alphabit_string = _alphabit->ToString(); - return alphabit_string.size()==_signs.size(); +std::shared_ptr VMTTransitionConditions::GetAlphabit() { + return _alphabit; } +bool VMTTransitionConditions::IsSingleChar() { return false; } -std::shared_ptr VMTTransitionConditions::GetAlphabit(){ - return _alphabit; +bool VMTTransitionConditions::IsEnabled(char sign) { + return _signs.indexOf(QChar(sign)) != -1; } -bool VMTTransitionConditions::IsSingleChar(){ - return false; -} - -bool VMTTransitionConditions::IsEnabled(char sign){ - return _signs.indexOf(QChar(sign))!=-1; -} +void VMTTransitionConditions::SetEnable(char sign, bool enable, + IVMTEnvironment* environment) { + if (enable) { + if (_signs.indexOf(QChar(sign)) == -1) _signs.append(QChar(sign)); + } else { + int index = _signs.indexOf(QChar(sign)); -void VMTTransitionConditions::SetEnable(char sign, bool enable,IVMTEnvironment* environment){ - if(enable) { - if(_signs.indexOf(QChar(sign))==-1) - _signs.append(QChar(sign)); - } else - { - int index=_signs.indexOf(QChar(sign)); - - if(index!=-1) _signs.remove(index,1); - } - Update(environment); + if (index != -1) _signs.remove(index, 1); + } + Update(environment); } -void VMTTransitionConditions::SetDisableAllExclude(char sign, IVMTEnvironment* environment) { +void VMTTransitionConditions::SetDisableAllExclude( + char sign, IVMTEnvironment* environment) { QString signsCopy = _signs; - for(int i = 0; i < static_cast(signsCopy.size()); ++i) { - if(signsCopy[i] == QChar(sign)) { + for (int i = 0; i < static_cast(signsCopy.size()); ++i) { + if (signsCopy[i] == QChar(sign)) { continue; } int index = _signs.indexOf(signsCopy[i]); - if(index != -1) { + if (index != -1) { _signs.remove(index, 1); } } Update(environment); } -VMTTransitionConditions::~VMTTransitionConditions(){ - -} +VMTTransitionConditions::~VMTTransitionConditions() {} diff --git a/VirtualTuringMachine/VMTTransitionConditions.h b/VirtualTuringMachine/VMTTransitionConditions.h old mode 100755 new mode 100644 index 4b3517e..d259c91 --- a/VirtualTuringMachine/VMTTransitionConditions.h +++ b/VirtualTuringMachine/VMTTransitionConditions.h @@ -1,49 +1,48 @@ #if !defined(EA_8E22BF93_B3F1_4ef0_B3CD_FE57BE2AC4DD__INCLUDED_) #define EA_8E22BF93_B3F1_4ef0_B3CD_FE57BE2AC4DD__INCLUDED_ - class IVMTEnvironment; -#include "interfaces/IVMTAlphabitSource.h" - -#include -#include #include #include +#include +#include + +#include "interfaces/IVMTAlphabitSource.h" class IVMTTransition; -class VMTTransitionConditions : public IVMTAlphabitSource -{ -protected: - std::shared_ptr _alphabit; - QString _signs; - IVMTTransition *_transition; - void Update(IVMTEnvironment *environment); +class VMTTransitionConditions : public IVMTAlphabitSource { + protected: + std::shared_ptr _alphabit; + QString _signs; + IVMTTransition* _transition; + void Update(IVMTEnvironment* environment); -public: - VMTTransitionConditions(IVMTTransition *transition,std::shared_ptr alphabit); + public: + VMTTransitionConditions(IVMTTransition* transition, + std::shared_ptr alphabit); VMTTransitionConditions(const VMTTransitionConditions& other); VMTTransitionConditions& operator=(const VMTTransitionConditions& other); void Serialize(QDataStream&); void Deserialize(QDataStream&); void ChangeAlphabit(const std::shared_ptr other); const QString& GetAsString(); - QPoint GetDimensions(IVMTEnvironment* environment, int size); - bool IsAllDisabled(); - bool IsAllEnabled(); + QPoint GetDimensions(IVMTEnvironment* environment, int size); + bool IsAllDisabled(); + bool IsAllEnabled(); - //IVMTAlphabitSource + // IVMTAlphabitSource std::shared_ptr GetAlphabit() override; bool IsSingleChar() override; bool IsEnabled(char sign) override; - void SetEnable(char sign, bool enable, IVMTEnvironment* environment) override; + void SetEnable(char sign, bool enable, + IVMTEnvironment* environment) override; void SetDisableAllExclude(char sign, IVMTEnvironment* environment) override; QPixmap* GetImage() override; const QString& GetMessage() override; virtual ~VMTTransitionConditions(); - }; -#endif // !defined(EA_8E22BF93_B3F1_4ef0_B3CD_FE57BE2AC4DD__INCLUDED_) +#endif // !defined(EA_8E22BF93_B3F1_4ef0_B3CD_FE57BE2AC4DD__INCLUDED_) diff --git a/VirtualTuringMachine/VMTTransitionImpl.cpp b/VirtualTuringMachine/VMTTransitionImpl.cpp old mode 100755 new mode 100644 index 4d95f19..31f6806 --- a/VirtualTuringMachine/VMTTransitionImpl.cpp +++ b/VirtualTuringMachine/VMTTransitionImpl.cpp @@ -1,14 +1,16 @@ #include "VMTTransitionImpl.h" -#include "diagrambezier.h" -#include "vmtmachines/VMTComplexMachine.h" + #include #include + +#include "diagrambezier.h" +#include "vmtmachines/VMTComplexMachine.h" #define PRECISION 5 namespace { -void updateTransitionBoundsFromPoints(const std::vector& points, QRect& bounds) -{ +void updateTransitionBoundsFromPoints(const std::vector& points, + QRect& bounds) { if (points.empty()) { return; } @@ -34,21 +36,16 @@ void updateTransitionBoundsFromPoints(const std::vector& points, QRect& } if (points.size() >= 2) { - const QRect curveBounds = DiagramBezier::buildConnectorPath(points).boundingRect().toRect(); + const QRect curveBounds = + DiagramBezier::buildConnectorPath(points).boundingRect().toRect(); bounds = bounds.united(curveBounds); } } -int routingStubLength(int gridStep) -{ - return std::max(gridStep * 2, 20); -} +int routingStubLength(int gridStep) { return std::max(gridStep * 2, 20); } -void buildRubberBandRoute(const QPoint& startOutput, - const QPoint& finishInput, - int stub, - std::vector& points) -{ +void buildRubberBandRoute(const QPoint& startOutput, const QPoint& finishInput, + int stub, std::vector& points) { points.clear(); points.push_back(startOutput); @@ -57,19 +54,19 @@ void buildRubberBandRoute(const QPoint& startOutput, points.push_back(finishInput); current = points.back(); - points.insert(points.begin() + static_cast(points.size() - 1), - QPoint(current.x() - stub, finishInput.y())); + points.insert( + points.begin() + static_cast(points.size() - 1), + QPoint(current.x() - stub, finishInput.y())); } -void finalizeTransitionPoints(std::vector& points) -{ +void finalizeTransitionPoints(std::vector& points) { DiagramBezier::snapPortHeights(points); } -} // namespace +} // namespace -VMTTransitionImpl::VMTTransitionImpl(std::weak_ptr parent) : - _conditions(this, parent.lock()->GetAlphabit()), _parent(parent){ +VMTTransitionImpl::VMTTransitionImpl(std::weak_ptr parent) + : _conditions(this, parent.lock()->GetAlphabit()), _parent(parent) { _fixed = false; _changed = true; _highlighted = false; @@ -77,224 +74,218 @@ VMTTransitionImpl::VMTTransitionImpl(std::weak_ptr parent) : _conditions_segment_number = 2; _conditions_segment = 0.5; _drag_point_number = -1; - _drag_condition = false; + _drag_condition = false; ScreenTools st; _condition_width = st.GetFontSize(); } -void VMTTransitionImpl::SetParent(std::weak_ptr parent){ +void VMTTransitionImpl::SetParent(std::weak_ptr parent) { _parent = parent; } -std::weak_ptr VMTTransitionImpl::GetStartMachine(){ +std::weak_ptr VMTTransitionImpl::GetStartMachine() { return _start_machine; } -std::weak_ptr VMTTransitionImpl::GetFinishMachine(){ +std::weak_ptr VMTTransitionImpl::GetFinishMachine() { return _finish_machine; } -void VMTTransitionImpl::SetConditions(VMTTransitionConditions& other){ +void VMTTransitionImpl::SetConditions(VMTTransitionConditions& other) { this->_conditions = other; } -void VMTTransitionImpl::Serialize(QDataStream& stream){ - stream << true; - stream << (double) _start_point.x(); - stream << (double) _start_point.y(); +void VMTTransitionImpl::Serialize(QDataStream& stream) { + stream << true; + stream << (double)_start_point.x(); + stream << (double)_start_point.y(); - stream << true; - stream << (double) _finish_point.x(); - stream << (double) _finish_point.y(); + stream << true; + stream << (double)_finish_point.x(); + stream << (double)_finish_point.y(); - stream << (double) _conditions_point.x(); - stream << (double) _conditions_point.y(); + stream << (double)_conditions_point.x(); + stream << (double)_conditions_point.y(); - stream << (qint32) _points.size(); + stream << (qint32)_points.size(); - for(auto point: _points){ - stream << (double) point.x(); - stream << (double) point.y(); + for (auto point : _points) { + stream << (double)point.x(); + stream << (double)point.y(); } - stream << (qint32) _conditions_segment_number; - stream << (double) _conditions_segment; - stream << _fixed; + stream << (qint32)_conditions_segment_number; + stream << (double)_conditions_segment; + stream << _fixed; _conditions.Serialize(stream); - } -void VMTTransitionImpl::Deserialize(QDataStream& stream){ +void VMTTransitionImpl::Deserialize(QDataStream& stream) { bool flag; double value; stream >> flag; qDebug() << "flag:" << flag; - if(flag){ - stream >> value; _start_point.setX(value); - qDebug() << "x:" << value; - stream >> value; _start_point.setY(value); - qDebug() << "y:" << value; + if (flag) { + stream >> value; + _start_point.setX(value); + qDebug() << "x:" << value; + stream >> value; + _start_point.setY(value); + qDebug() << "y:" << value; } stream >> flag; qDebug() << "flag:" << flag; - if(flag) - { - - stream >> value; _finish_point.setX(value); - qDebug() << "x:" << value; - stream >> value; _finish_point.setY(value); - qDebug() << "y:" << value; + if (flag) { + stream >> value; + _finish_point.setX(value); + qDebug() << "x:" << value; + stream >> value; + _finish_point.setY(value); + qDebug() << "y:" << value; } - stream >> value; _conditions_point.setX(value); + stream >> value; + _conditions_point.setX(value); qDebug() << "x:" << value; - stream >> value; _conditions_point.setY(value); + stream >> value; + _conditions_point.setY(value); qDebug() << "y:" << value; qint32 size; stream >> size; qDebug() << "size:" << size; - _points.clear(); - for(int i=0;i> value; point.setX(value); - qDebug() << "x:" << value; - stream >> value; point.setY(value); - qDebug() << "y:" << value; - _points.push_back(point); - } - - qint32 value_int; - stream >> value_int;_conditions_segment_number = value_int; - stream >> value;_conditions_segment = value; - - stream >> _fixed; - _conditions.Deserialize(stream); - _changed = false; - finalizeTransitionPoints(_points); - _committedPoints = _points; - updateTransitionBoundsFromPoints(_points, _bounds); - -} - -IVMTAlphabitSource *VMTTransitionImpl::GetAlphabitSource(){ + _points.clear(); + for (int i = 0; i < size; i++) { + QPoint point; + stream >> value; + point.setX(value); + qDebug() << "x:" << value; + stream >> value; + point.setY(value); + qDebug() << "y:" << value; + _points.push_back(point); + } + + qint32 value_int; + stream >> value_int; + _conditions_segment_number = value_int; + stream >> value; + _conditions_segment = value; + + stream >> _fixed; + _conditions.Deserialize(stream); + _changed = false; + finalizeTransitionPoints(_points); + _committedPoints = _points; + updateTransitionBoundsFromPoints(_points, _bounds); +} + +IVMTAlphabitSource* VMTTransitionImpl::GetAlphabitSource() { return &_conditions; } -std::vector VMTTransitionImpl::GetRoutingPolyline() const -{ +std::vector VMTTransitionImpl::GetRoutingPolyline() const { return _points; } -std::vector VMTTransitionImpl::GetCommittedRoutingPolyline() const -{ +std::vector VMTTransitionImpl::GetCommittedRoutingPolyline() const { if (!_committedPoints.empty()) { return _committedPoints; } return _points; } -void VMTTransitionImpl::ChangeAlphabit(std::shared_ptr alphabit){ +void VMTTransitionImpl::ChangeAlphabit(std::shared_ptr alphabit) { _conditions.ChangeAlphabit(alphabit); } -void VMTTransitionImpl::BeginDrag(IVMTEnvironment* environment,const QPoint& point){ - +void VMTTransitionImpl::BeginDrag(IVMTEnvironment* environment, + const QPoint& point) { _drag_point_number = -1; - _drag_condition = false; + _drag_condition = false; - for(size_t i=2;(_drag_point_number==-1)&&(i<_points.size()-2);i++) - { + for (size_t i = 2; (_drag_point_number == -1) && (i < _points.size() - 2); + i++) { QPoint current = _points[i]; - if ((current.x()-PRECISION<=point.x())&& - (current.x()+PRECISION>=point.x())&& - (current.y()-PRECISION<=point.y())&& - (current.y()+PRECISION>=point.y())) - { - _drag_point.rx() = current.x()-point.x(); - _drag_point.ry() = current.y()-point.y(); + if ((current.x() - PRECISION <= point.x()) && + (current.x() + PRECISION >= point.x()) && + (current.y() - PRECISION <= point.y()) && + (current.y() + PRECISION >= point.y())) { + _drag_point.rx() = current.x() - point.x(); + _drag_point.ry() = current.y() - point.y(); _drag_point_number = i; } } - if (_drag_point_number==-1) - { + if (_drag_point_number == -1) { QRect rect = GetConditionRectangle(environment->GetGraphics()); - if (rect.contains(point)) - { - _drag_point.rx() = _conditions_point.x()-point.x(); - _drag_point.ry() = _conditions_point.y()-point.y(); + if (rect.contains(point)) { + _drag_point.rx() = _conditions_point.x() - point.x(); + _drag_point.ry() = _conditions_point.y() - point.y(); _drag_condition = true; } } } -void VMTTransitionImpl::Drag([[maybe_unused]] IVMTEnvironment* environment,const QPoint& point){ - - if (_drag_point_number==-1) - { - if(_drag_condition) - { +void VMTTransitionImpl::Drag([[maybe_unused]] IVMTEnvironment* environment, + const QPoint& point) { + if (_drag_point_number == -1) { + if (_drag_condition) { bool done = false; int iterations = 0; - do - { - iterations ++; + do { + iterations++; QPoint prev = _points[_conditions_segment_number]; - QPoint current = _points[_conditions_segment_number+1]; - - - double a= current.y() - prev.y(); - double b= current.x() - prev.x(); - double dK = (a*(point.y()-prev.y())+b*(point.x()-prev.x()))/(a*a+b*b); - - if ((iterations<2)&&(dK<0)) - { - if (_conditions_segment_number>0) { - - _conditions_segment_number--; + QPoint current = _points[_conditions_segment_number + 1]; + + double a = current.y() - prev.y(); + double b = current.x() - prev.x(); + double dK = + (a * (point.y() - prev.y()) + b * (point.x() - prev.x())) / + (a * a + b * b); + + if ((iterations < 2) && (dK < 0)) { + if (_conditions_segment_number > 0) { + _conditions_segment_number--; + } else { + dK = 0; + done = true; } - else - { - dK=0; + } else if ((iterations < 2) && (dK > 1)) { + if (_conditions_segment_number < + static_cast(_points.size()) - 2) + _conditions_segment_number++; + else { + dK = 1; done = true; } } else - if ((iterations<2)&&(dK>1)) - { - if (_conditions_segment_number(_points.size())-2) _conditions_segment_number++; - else - { - dK=1; - done = true; - } - } else done = true; + done = true; - if(done) - { - if(dK<0) dK=0; - if(dK>1) dK = 1; + if (done) { + if (dK < 0) dK = 0; + if (dK > 1) dK = 1; _conditions_segment = dK; done = true; } - }while(!done); + } while (!done); } - } else - { - if((_drag_point_number>=0)&&(_drag_point_number(_points.size()))) - _points[_drag_point_number] = QPoint(point.x()+_drag_point.x(),point.y()+_drag_point.y()); + } else { + if ((_drag_point_number >= 0) && + (_drag_point_number < static_cast(_points.size()))) + _points[_drag_point_number] = QPoint(point.x() + _drag_point.x(), + point.y() + _drag_point.y()); } refreshPaintBounds(); } -void VMTTransitionImpl::refreshPaintBounds() -{ +void VMTTransitionImpl::refreshPaintBounds() { updateTransitionBoundsFromPoints(_points, _bounds); if (!_conditions.IsAllEnabled()) { @@ -308,29 +299,28 @@ void VMTTransitionImpl::refreshPaintBounds() } QRect conditionRect(_conditions_point.x() - width / 2, - _conditions_point.y() - height / 2, - width, - height); + _conditions_point.y() - height / 2, width, height); _bounds = _bounds.united(conditionRect); } } -void VMTTransitionImpl::EndDrag([[maybe_unused]] IVMTEnvironment* environment,[[maybe_unused]] const QPoint& p_Point){ - _drag_condition = false; - _drag_point_number = false; +void VMTTransitionImpl::EndDrag([[maybe_unused]] IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& p_Point) { + _drag_condition = false; + _drag_point_number = false; } -void VMTTransitionImpl::Changed(IVMTEnvironment* environment){ +void VMTTransitionImpl::Changed(IVMTEnvironment* environment) { _changed = true; Update(environment); } -void VMTTransitionImpl::UpdatePreview(IVMTEnvironment* environment) -{ +void VMTTransitionImpl::UpdatePreview(IVMTEnvironment* environment) { if (!environment) { return; } - const int stub = routingStubLength(static_cast(environment->GetGraphics().GetStep())); + const int stub = routingStubLength( + static_cast(environment->GetGraphics().GetStep())); QPoint startOutput = _start_point; QPoint finishInput = _finish_point; @@ -346,29 +336,26 @@ void VMTTransitionImpl::UpdatePreview(IVMTEnvironment* environment) refreshPaintBounds(); } -const QRect& VMTTransitionImpl::GetBounds(){ - return _bounds; -} -VMTTransitionConditions& VMTTransitionImpl::GetConditions(){ +const QRect& VMTTransitionImpl::GetBounds() { return _bounds; } +VMTTransitionConditions& VMTTransitionImpl::GetConditions() { return _conditions; } -std::weak_ptr VMTTransitionImpl::GetFinish(){ +std::weak_ptr VMTTransitionImpl::GetFinish() { return _finish_machine; } -std::weak_ptr VMTTransitionImpl::GetStart(){ +std::weak_ptr VMTTransitionImpl::GetStart() { return _start_machine; } -bool VMTTransitionImpl::IsError(){ - return this->_error; -} +bool VMTTransitionImpl::IsError() { return this->_error; } struct Event { int x, y1, y2; bool isStart; - Event(int x, int y1, int y2, bool isStart) : x(x), y1(y1), y2(y2), isStart(isStart) {} + Event(int x, int y1, int y2, bool isStart) + : x(x), y1(y1), y2(y2), isStart(isStart) {} bool operator<(const Event& e) const { if (x != e.x) return x < e.x; @@ -376,11 +363,13 @@ struct Event { } }; -bool VMTTransitionImpl::IsIntersectLine([[maybe_unused]] IVMTEnvironment* environment,const QPoint& segmentStart,const QPoint& segmentEnd){ - - - const QPainterPath connectorPath = DiagramBezier::buildConnectorPath(_points); - const std::vector sampled = DiagramBezier::flattenPath(connectorPath, 8.0); +bool VMTTransitionImpl::IsIntersectLine( + [[maybe_unused]] IVMTEnvironment* environment, const QPoint& segmentStart, + const QPoint& segmentEnd) { + const QPainterPath connectorPath = + DiagramBezier::buildConnectorPath(_points); + const std::vector sampled = + DiagramBezier::flattenPath(connectorPath, 8.0); std::vector events; for (size_t i = 0; i + 1 < sampled.size(); ++i) { @@ -404,20 +393,23 @@ bool VMTTransitionImpl::IsIntersectLine([[maybe_unused]] IVMTEnvironment* enviro std::multiset yCoords; for (const Event& event : events) { if (event.isStart) { - if (yCoords.lower_bound(event.y1) != yCoords.upper_bound(event.y2)) { + if (yCoords.lower_bound(event.y1) != + yCoords.upper_bound(event.y2)) { return true; - } - yCoords.insert(event.y1); + } + yCoords.insert(event.y1); } else { - yCoords.erase(yCoords.find(event.y1)); + yCoords.erase(yCoords.find(event.y1)); } } return false; } -bool VMTTransitionImpl::IsInside(IVMTEnvironment* environment,const QPoint& point){ - const QPainterPath connectorPath = DiagramBezier::buildConnectorPath(_points); +bool VMTTransitionImpl::IsInside(IVMTEnvironment* environment, + const QPoint& point) { + const QPainterPath connectorPath = + DiagramBezier::buildConnectorPath(_points); if (DiagramBezier::isPointNearStroke(connectorPath, point, PRECISION)) { return true; } @@ -429,109 +421,106 @@ bool VMTTransitionImpl::IsInside(IVMTEnvironment* environment,const QPoint& poin return false; } -bool VMTTransitionImpl::IsInsideLine(const QPoint& prev, const QPoint& current, const QPoint& point){ +bool VMTTransitionImpl::IsInsideLine(const QPoint& prev, const QPoint& current, + const QPoint& point) { int nBorderWidth = PRECISION; - bool bIntersept = false; + bool bIntersept = false; QPoint p_Tmp1; QPoint p_Tmp2; - p_Tmp1.rx() = current.x()prev.x()?current.x():prev.x(); - p_Tmp1.ry() = current.y()prev.y()?current.y():prev.y(); - - - if((p_Tmp1.x()-nBorderWidth<=point.x())&& - (p_Tmp1.y()-nBorderWidth<=point.y())&& - (p_Tmp2.x()+nBorderWidth>=point.x())&& - (p_Tmp2.y()+nBorderWidth>=point.y())) bIntersept = true; - - if(bIntersept) - { - - if (current.x()!=prev.x()) - { - double dTg = ((double)(current.y()-prev.y()))/((double)(current.x()-prev.x())); + p_Tmp1.rx() = current.x() < prev.x() ? current.x() : prev.x(); + p_Tmp2.rx() = current.x() > prev.x() ? current.x() : prev.x(); + p_Tmp1.ry() = current.y() < prev.y() ? current.y() : prev.y(); + p_Tmp2.ry() = current.y() > prev.y() ? current.y() : prev.y(); + + if ((p_Tmp1.x() - nBorderWidth <= point.x()) && + (p_Tmp1.y() - nBorderWidth <= point.y()) && + (p_Tmp2.x() + nBorderWidth >= point.x()) && + (p_Tmp2.y() + nBorderWidth >= point.y())) + bIntersept = true; + + if (bIntersept) { + if (current.x() != prev.x()) { + double dTg = ((double)(current.y() - prev.y())) / + ((double)(current.x() - prev.x())); double Fi = std::atan(dTg); double dSin = std::sin(Fi); double dCos = std::cos(Fi); - double delta = (((double)point.y())-((double)(point.x()-prev.x()))*dTg -(double)prev.y())/ - (dTg*dSin+dCos); + double delta = + (((double)point.y()) - ((double)(point.x() - prev.x())) * dTg - + (double)prev.y()) / + (dTg * dSin + dCos); - if(std::abs(delta)<=nBorderWidth) - { - double tMax = ((double)(current.x()-prev.x()))/dCos; + if (std::abs(delta) <= nBorderWidth) { + double tMax = ((double)(current.x() - prev.x())) / dCos; - double t = (point.x()+dSin*delta-prev.x())/dCos; - - if((t<=tMax)&&(t>=0)) return true; - if((t>=tMax)&&(t<=0)) return true; + double t = (point.x() + dSin * delta - prev.x()) / dCos; + if ((t <= tMax) && (t >= 0)) return true; + if ((t >= tMax) && (t <= 0)) return true; } - } else return true; - - long dLineLength = ((long)nBorderWidth)*((long)nBorderWidth); - long dLength = ((long)(point.x()-prev.x()))*((long)(point.x()-prev.x())) - +((long)(point.y()-prev.y()))*((long)(point.y()-prev.y())); - if(dLength<=dLineLength) + } else return true; - dLength = ((long)(point.x()-current.x()))*((long)(point.x()-current.x())) - +((long)(point.y()-current.y()))*((long)(point.y()-current.y())); - if(dLength<=dLineLength) - return true; + long dLineLength = ((long)nBorderWidth) * ((long)nBorderWidth); + long dLength = + ((long)(point.x() - prev.x())) * ((long)(point.x() - prev.x())) + + ((long)(point.y() - prev.y())) * ((long)(point.y() - prev.y())); + if (dLength <= dLineLength) return true; + dLength = ((long)(point.x() - current.x())) * + ((long)(point.x() - current.x())) + + ((long)(point.y() - current.y())) * + ((long)(point.y() - current.y())); + if (dLength <= dLineLength) return true; } return false; - } -void VMTTransitionImpl::Paint(UICanvas& canvas, const QRect& rect){ +void VMTTransitionImpl::Paint(UICanvas& canvas, const QRect& rect) { if (!rect.isEmpty() && !_bounds.isEmpty() && !rect.intersects(_bounds)) { return; } - const QPainterPath connectorPath = DiagramBezier::buildConnectorPath(_points); + const QPainterPath connectorPath = + DiagramBezier::buildConnectorPath(_points); if (!connectorPath.isEmpty()) { - canvas.DrawConnectorPath(connectorPath, _highlighted, _error, _highlighted); + canvas.DrawConnectorPath(connectorPath, _highlighted, _error, + _highlighted); if (_points.size() > 1) { canvas.DrawArrowForPath(connectorPath, _highlighted, _error); } } - if(!_conditions.IsAllEnabled()){ - if(_conditions.GetAsString().length()>0){ - QRect rect= GetConditionRectangle(canvas); + if (!_conditions.IsAllEnabled()) { + if (_conditions.GetAsString().length() > 0) { + QRect rect = GetConditionRectangle(canvas); QString text = _conditions.GetAsString(); - canvas.FillRect(rect,this->_highlighted); - //canvas.DrawRectAnimation(_bounds,true); - canvas.DrawText(text,_conditions_point,_condition_width/2,this->_highlighted); + canvas.FillRect(rect, this->_highlighted); + // canvas.DrawRectAnimation(_bounds,true); + canvas.DrawText(text, _conditions_point, _condition_width / 2, + this->_highlighted); - // canvas.DrawText(text,rect); + // canvas.DrawText(text,rect); } else { - QRect rect= GetConditionRectangle(canvas); - canvas.DrawImage(ImageType::CANCEL,rect); + QRect rect = GetConditionRectangle(canvas); + canvas.DrawImage(ImageType::CANCEL, rect); } - } } -void VMTTransitionImpl::RemoveChilds(){ - if(auto ptr=_start_machine.lock()) - ptr->RemoveOutgoingTransition(this); +void VMTTransitionImpl::RemoveChilds() { + if (auto ptr = _start_machine.lock()) ptr->RemoveOutgoingTransition(this); - if(auto ptr=_finish_machine.lock()) - ptr->RemoveIncomingTransition(this); - -} -void VMTTransitionImpl::SetError(bool error){ - this->_error = error; + if (auto ptr = _finish_machine.lock()) ptr->RemoveIncomingTransition(this); } +void VMTTransitionImpl::SetError(bool error) { this->_error = error; } -void VMTTransitionImpl::SetFinish(IVMTEnvironment* environment,std::shared_ptr machine){ - if(auto ptr= _finish_machine.lock()){ +void VMTTransitionImpl::SetFinish(IVMTEnvironment* environment, + std::shared_ptr machine) { + if (auto ptr = _finish_machine.lock()) { ptr->RemoveIncomingTransition(this); } @@ -540,9 +529,9 @@ void VMTTransitionImpl::SetFinish(IVMTEnvironment* environment,std::shared_ptrRemoveIncomingTransition(this); } @@ -551,12 +540,11 @@ void VMTTransitionImpl::SetFinish(IVMTEnvironment* environment,const QPoint& poi Changed(environment); } -void VMTTransitionImpl::SetSelected(bool enable){ - _highlighted = enable; -} +void VMTTransitionImpl::SetSelected(bool enable) { _highlighted = enable; } -void VMTTransitionImpl::SetStart(IVMTEnvironment* environment,std::shared_ptr machine){ - if(auto ptr= _start_machine.lock()){ +void VMTTransitionImpl::SetStart(IVMTEnvironment* environment, + std::shared_ptr machine) { + if (auto ptr = _start_machine.lock()) { ptr->RemoveOutgoingTransition(this); } @@ -565,20 +553,20 @@ void VMTTransitionImpl::SetStart(IVMTEnvironment* environment,std::shared_ptr& machine) -{ +void VMTTransitionImpl::AttachStartMachine( + const std::shared_ptr& machine) { _start_machine = machine; _start_point = QPoint(); } -void VMTTransitionImpl::AttachFinishMachine(const std::shared_ptr& machine) -{ +void VMTTransitionImpl::AttachFinishMachine( + const std::shared_ptr& machine) { _finish_machine = machine; _finish_point = QPoint(); } -void VMTTransitionImpl::SetCommittedRoutingPolyline(const std::vector& points) -{ +void VMTTransitionImpl::SetCommittedRoutingPolyline( + const std::vector& points) { _points = points; finalizeTransitionPoints(_points); _committedPoints = _points; @@ -587,15 +575,15 @@ void VMTTransitionImpl::SetCommittedRoutingPolyline(const std::vector& p _changed = false; } -void VMTTransitionImpl::RebuildRouteFromMachines() -{ +void VMTTransitionImpl::RebuildRouteFromMachines() { const auto start = _start_machine.lock(); const auto finish = _finish_machine.lock(); if (!start || !finish) { return; } const int stub = 40; - buildRubberBandRoute(start->GetOutputPoint(), finish->GetInputPoint(), stub, _points); + buildRubberBandRoute(start->GetOutputPoint(), finish->GetInputPoint(), stub, + _points); finalizeTransitionPoints(_points); _committedPoints = _points; updateTransitionBoundsFromPoints(_points, _bounds); @@ -603,8 +591,9 @@ void VMTTransitionImpl::RebuildRouteFromMachines() _changed = false; } -void VMTTransitionImpl::SetStart(IVMTEnvironment* environment,const QPoint& point){ - if(auto ptr= _start_machine.lock()){ +void VMTTransitionImpl::SetStart(IVMTEnvironment* environment, + const QPoint& point) { + if (auto ptr = _start_machine.lock()) { ptr->RemoveIncomingTransition(this); } @@ -613,34 +602,30 @@ void VMTTransitionImpl::SetStart(IVMTEnvironment* environment,const QPoint& poin Changed(environment); } +VMTTransitionImpl::~VMTTransitionImpl() {} - -VMTTransitionImpl::~VMTTransitionImpl(){ - -} - -void VMTTransitionImpl::CalculateConditionsPoint([[maybe_unused]] bool fixed){ - if(static_cast(_points.size())>_conditions_segment_number+1) - { +void VMTTransitionImpl::CalculateConditionsPoint([[maybe_unused]] bool fixed) { + if (static_cast(_points.size()) > _conditions_segment_number + 1) { QPoint& one = _points[_conditions_segment_number]; - QPoint& two = _points[_conditions_segment_number+1]; + QPoint& two = _points[_conditions_segment_number + 1]; - _conditions_point.rx() = one.x()+(two.x()-one.x())*_conditions_segment; - _conditions_point.ry() = one.y()+(two.y()-one.y())*_conditions_segment; + _conditions_point.rx() = + one.x() + (two.x() - one.x()) * _conditions_segment; + _conditions_point.ry() = + one.y() + (two.y() - one.y()) * _conditions_segment; } - } -#include "pathfinder.h" #include "diagramrouting.h" +#include "pathfinder.h" -void VMTTransitionImpl::Update([[maybe_unused]] IVMTEnvironment* environment){ - if(_changed) - { - if(!environment) { +void VMTTransitionImpl::Update([[maybe_unused]] IVMTEnvironment* environment) { + if (_changed) { + if (!environment) { return; } - const int gridStep = static_cast(environment->GetGraphics().GetStep()); + const int gridStep = + static_cast(environment->GetGraphics().GetStep()); const int routeStub = routingStubLength(gridStep); const int clearanceMargin = gridStep * 2; @@ -665,34 +650,33 @@ void VMTTransitionImpl::Update([[maybe_unused]] IVMTEnvironment* environment){ if (auto ptr = _finish_machine.lock()) { total_bound = total_bound.united(ptr->GetBounds()); } - total_bound = total_bound.marginsAdded(QMargins(kRouteMargin, kRouteMargin, kRouteMargin, kRouteMargin)); + total_bound = total_bound.marginsAdded( + QMargins(kRouteMargin, kRouteMargin, kRouteMargin, kRouteMargin)); std::vector blockedPaths; MachineSpatialIndex spatialIndex(std::max(gridStep * 2, 8)); if (auto parent_ptr = _parent.lock()) { blockedPaths = parent_ptr->blockedPathsFor(this); - spatialIndex.rebuild(parent_ptr->GetMachineCollection(), clearanceMargin); + spatialIndex.rebuild(parent_ptr->GetMachineCollection(), + clearanceMargin); } - path_t path = p.GetPath(_start_point, - _finish_point, - total_bound, - gridStep * 2, - [&](const QPoint& point) { return spatialIndex.contains(point); }, - blockedPaths, - static_cast(gridStep)); - if(!path.empty()){ - _points.clear(); - if(auto ptr = _start_machine.lock()){ + path_t path = p.GetPath( + _start_point, _finish_point, total_bound, gridStep * 2, + [&](const QPoint& point) { return spatialIndex.contains(point); }, + blockedPaths, static_cast(gridStep)); + if (!path.empty()) { + _points.clear(); + if (auto ptr = _start_machine.lock()) { _points.push_back(ptr->GetOutputPoint()); - } else _points.push_back(_start_point); - for(const auto &p: path) _points.push_back(p); - if(auto ptr = _finish_machine.lock()){ + } else + _points.push_back(_start_point); + for (const auto& p : path) _points.push_back(p); + if (auto ptr = _finish_machine.lock()) { _points.push_back(ptr->GetInputPoint()); - } else _points.push_back(_finish_point); - } else - { - if(!_fixed) - { + } else + _points.push_back(_finish_point); + } else { + if (!_fixed) { QPoint startOutput = _start_point; QPoint finishInput = _finish_point; if (auto ptr = _start_machine.lock()) { @@ -701,23 +685,26 @@ void VMTTransitionImpl::Update([[maybe_unused]] IVMTEnvironment* environment){ if (auto ptr = _finish_machine.lock()) { finishInput = ptr->GetInputPoint(); } - buildRubberBandRoute(startOutput, finishInput, routeStub, _points); + buildRubberBandRoute(startOutput, finishInput, routeStub, + _points); UpdateSegment(1, 2); - } else - { - if(auto ptr = _start_machine.lock()){ - _points[0]=ptr->GetOutputPoint(); - } else _points[0]=_start_point; + } else { + if (auto ptr = _start_machine.lock()) { + _points[0] = ptr->GetOutputPoint(); + } else + _points[0] = _start_point; QPoint current = _points[0]; - _points[1]=QPoint(current.rx()+routeStub,current.ry()); + _points[1] = QPoint(current.rx() + routeStub, current.ry()); - if(auto ptr = _finish_machine.lock()){ - _points[_points.size()-1]=ptr->GetInputPoint(); - } else _points[_points.size()-1]=_finish_point; + if (auto ptr = _finish_machine.lock()) { + _points[_points.size() - 1] = ptr->GetInputPoint(); + } else + _points[_points.size() - 1] = _finish_point; - current = _points[_points.size()-1]; - _points[_points.size()-2]=QPoint(current.rx()-routeStub,current.ry()); + current = _points[_points.size() - 1]; + _points[_points.size() - 2] = + QPoint(current.rx() - routeStub, current.ry()); } } @@ -726,127 +713,111 @@ void VMTTransitionImpl::Update([[maybe_unused]] IVMTEnvironment* environment){ refreshPaintBounds(); _changed = false; _committedPoints = _points; - } } -void VMTTransitionImpl::UpdateSegment(int start_position, int end_position){ - QPoint start = _points[start_position]; - QPoint end = _points[end_position]; +void VMTTransitionImpl::UpdateSegment(int start_position, int end_position) { + QPoint start = _points[start_position]; + QPoint end = _points[end_position]; - if (start.rx()GetMachineCollection()) - { + if (auto parent_ptr = _parent.lock()) { + for (auto machine : parent_ptr->GetMachineCollection()) { QRect rect = machine->GetBounds(); - if(start.ry()==end.ry()) - { - if ((rect.top()<=start.ry())&&(rect.top()+rect.height()>=start.ry())) - { - if (end.rx()>start.rx()) - { - if ((start.rx()<=rect.left())&&(end.rx()>=rect.left()+rect.width())) - { + if (start.ry() == end.ry()) { + if ((rect.top() <= start.ry()) && + (rect.top() + rect.height() >= start.ry())) { + if (end.rx() > start.rx()) { + if ((start.rx() <= rect.left()) && + (end.rx() >= rect.left() + rect.width())) { intersect = true; } - } else - { - if ((end.rx()<=rect.left())&&(start.rx()>=rect.left()+rect.width())) - { - intersect = true; + } else { + if ((end.rx() <= rect.left()) && + (start.rx() >= rect.left() + rect.width())) { + intersect = true; } } } - if (intersect) - { - start.setY(start.y()-PRECISION); - end.setY(end.y()-PRECISION); + if (intersect) { + start.setY(start.y() - PRECISION); + end.setY(end.y() - PRECISION); _points[start_position] = start; _points[end_position] = end; } - } else - if(start.rx()==end.rx()) - { - if ((rect.left()<=start.rx())&&(rect.left()+rect.width()>=start.rx())) - { - if (end.ry()>start.ry()) - { - if ((start.ry()<=rect.top()+rect.height())&&(end.ry()>=rect.top())) - { - intersect = true; - } - } else - { - if ((end.ry()<=rect.top()+rect.height())&&(start.ry()>=rect.top())) - { - intersect = true; - } + } else if (start.rx() == end.rx()) { + if ((rect.left() <= start.rx()) && + (rect.left() + rect.width() >= start.rx())) { + if (end.ry() > start.ry()) { + if ((start.ry() <= rect.top() + rect.height()) && + (end.ry() >= rect.top())) { + intersect = true; + } + } else { + if ((end.ry() <= rect.top() + rect.height()) && + (start.ry() >= rect.top())) { + intersect = true; } - } - if (intersect) - { - start.setX(start.x()-PRECISION); - end.setX(end.x()-PRECISION); - _points[start_position] = start; - _points[end_position] = end; } } + if (intersect) { + start.setX(start.x() - PRECISION); + end.setX(end.x() - PRECISION); + _points[start_position] = start; + _points[end_position] = end; + } + } } } - return intersect; } -QRect VMTTransitionImpl::GetConditionRectangle([[maybe_unused]] UICanvas& canvas){ +QRect VMTTransitionImpl::GetConditionRectangle( + [[maybe_unused]] UICanvas& canvas) { CalculateConditionsPoint(false); - QRect rect(_conditions_point.x(),_conditions_point.y(),_condition_width,_condition_width); + QRect rect(_conditions_point.x(), _conditions_point.y(), _condition_width, + _condition_width); QString text = _conditions.GetAsString(); - if(text.length()>0){ - rect.setWidth(_st.GetCellSize().width()*text.length()); + if (text.length() > 0) { + rect.setWidth(_st.GetCellSize().width() * text.length()); rect.setHeight(_st.GetCellSize().height()); -// canvas.CalculateTextSize(text,rect); + // canvas.CalculateTextSize(text,rect); } - rect.moveLeft(rect.left()-rect.width()/2); - rect.moveTop(rect.top()-rect.height()/2); -/* - rect.setTop(rect.top()-rect.height()/2); - rect.setHeight(rect.height()); + rect.moveLeft(rect.left() - rect.width() / 2); + rect.moveTop(rect.top() - rect.height() / 2); + /* + rect.setTop(rect.top()-rect.height()/2); + rect.setHeight(rect.height()); - rect.setLeft(rect.left()-rect.width()/2); - rect.setWidth(rect.width());*/ + rect.setLeft(rect.left()-rect.width()/2); + rect.setWidth(rect.width());*/ return rect; } diff --git a/VirtualTuringMachine/VMTTransitionImpl.h b/VirtualTuringMachine/VMTTransitionImpl.h old mode 100755 new mode 100644 index 6319dca..e522102 --- a/VirtualTuringMachine/VMTTransitionImpl.h +++ b/VirtualTuringMachine/VMTTransitionImpl.h @@ -1,34 +1,33 @@ #if !defined(EA_605C0DDC_936B_4cfe_BE03_26F5FE6A1A08__INCLUDED_) #define EA_605C0DDC_936B_4cfe_BE03_26F5FE6A1A08__INCLUDED_ -#include "VMTTransitionConditions.h" -#include "interfaces/IVMTMachine.h" +#include +#include +#include + #include "VMTSerializer.h" +#include "VMTTransitionConditions.h" #include "interfaces/IVMTMachine.h" #include "interfaces/IVMTTransition.h" -#include "vmtmachines/VMTComplexMachine.h" #include "screentools.h" -#include -#include -#include +#include "vmtmachines/VMTComplexMachine.h" #define PRECISION 5 -class VMTTransitionImpl : public IVMTTransition -{ - -public: +class VMTTransitionImpl : public IVMTTransition { + public: VMTTransitionImpl(std::weak_ptr parent); void Serialize(QDataStream&) override; void Deserialize(QDataStream&) override; - void BeginDrag(IVMTEnvironment* environment,const QPoint& p_Point) override; + void BeginDrag(IVMTEnvironment* environment, + const QPoint& p_Point) override; void ChangeAlphabit(std::shared_ptr alphabit) override; void Changed(IVMTEnvironment* environment) override; void UpdatePreview(IVMTEnvironment* environment) override; - void Drag(IVMTEnvironment* environment,const QPoint& p_Point) override; - void EndDrag(IVMTEnvironment* environment,const QPoint& p_Point) override; + void Drag(IVMTEnvironment* environment, const QPoint& p_Point) override; + void EndDrag(IVMTEnvironment* environment, const QPoint& p_Point) override; const QRect& GetBounds() override; VMTTransitionConditions& GetConditions() override; @@ -38,8 +37,9 @@ class VMTTransitionImpl : public IVMTTransition std::weak_ptr GetStart() override; bool IsError() override; - bool IsInside(IVMTEnvironment* environment,const QPoint& p_Point) override; - bool IsIntersectLine(IVMTEnvironment* environment,const QPoint& start,const QPoint& end) override; + bool IsInside(IVMTEnvironment* environment, const QPoint& p_Point) override; + bool IsIntersectLine(IVMTEnvironment* environment, const QPoint& start, + const QPoint& end) override; void Paint(UICanvas& canvas, const QRect& rect) override; void RemoveChilds() override; @@ -48,12 +48,14 @@ class VMTTransitionImpl : public IVMTTransition std::weak_ptr GetFinishMachine() override; void SetError(bool bError) override; - void SetFinish(IVMTEnvironment* environment,std::shared_ptr machine) override; - void SetFinish(IVMTEnvironment* environment,const QPoint& point) override; + void SetFinish(IVMTEnvironment* environment, + std::shared_ptr machine) override; + void SetFinish(IVMTEnvironment* environment, const QPoint& point) override; void SetSelected(bool enable) override; - void SetStart(IVMTEnvironment* environment,std::shared_ptr machine) override; - void SetStart(IVMTEnvironment* environment,const QPoint& point) override; + void SetStart(IVMTEnvironment* environment, + std::shared_ptr machine) override; + void SetStart(IVMTEnvironment* environment, const QPoint& point) override; void AttachStartMachine(const std::shared_ptr& machine); void AttachFinishMachine(const std::shared_ptr& machine); @@ -63,13 +65,13 @@ class VMTTransitionImpl : public IVMTTransition void RebuildRouteFromMachines(); void SetParent(std::weak_ptr parent) override; - IVMTAlphabitSource *GetAlphabitSource() override; + IVMTAlphabitSource* GetAlphabitSource() override; std::vector GetRoutingPolyline() const override; std::vector GetCommittedRoutingPolyline() const override; ~VMTTransitionImpl() override; -protected: + protected: bool _changed; bool _error; bool _fixed; @@ -83,7 +85,7 @@ class VMTTransitionImpl : public IVMTTransition QPoint _start_point; QPoint _finish_point; - QRect _bounds; + QRect _bounds; std::weak_ptr _start_machine; std::weak_ptr _finish_machine; @@ -92,24 +94,22 @@ class VMTTransitionImpl : public IVMTTransition std::vector _points; std::vector _committedPoints; - - int _conditions_segment_number; - int _drag_point_number; + int _conditions_segment_number; + int _drag_point_number; bool _drag_condition; - size_t _condition_width; - + size_t _condition_width; void CalculateConditionsPoint(bool fixed); void refreshPaintBounds(); bool CheckLineIntersectMachine(int start_position, int end_position); - bool IsInsideLine(const QPoint& prev, const QPoint& current, const QPoint& point); + bool IsInsideLine(const QPoint& prev, const QPoint& current, + const QPoint& point); void Update(IVMTEnvironment* environment); - void UpdateSegment(int start_position, int end_position); + void UpdateSegment(int start_position, int end_position); -private: + private: QRect GetConditionRectangle(UICanvas& canvas); - }; -#endif // !defined(EA_605C0DDC_936B_4cfe_BE03_26F5FE6A1A08__INCLUDED_) +#endif // !defined(EA_605C0DDC_936B_4cfe_BE03_26F5FE6A1A08__INCLUDED_) diff --git a/VirtualTuringMachine/clickablelabel.cpp b/VirtualTuringMachine/clickablelabel.cpp old mode 100755 new mode 100644 index 61f09e4..31598e3 --- a/VirtualTuringMachine/clickablelabel.cpp +++ b/VirtualTuringMachine/clickablelabel.cpp @@ -1,19 +1,15 @@ #include "clickablelabel.h" + #include "QDebug" ClickableLabel::ClickableLabel(const QString& text, QWidget* parent) - : QLabel(parent) -{ + : QLabel(parent) { setText(text); - // connect( this, SIGNAL( clicked() ), this, SLOT( slotClicked() ) ); -} - -ClickableLabel::~ClickableLabel() -{ + // connect( this, SIGNAL( clicked() ), this, SLOT( slotClicked() ) ); } +ClickableLabel::~ClickableLabel() {} -void ClickableLabel::mousePressEvent([[maybe_unused]] QMouseEvent* event) -{ +void ClickableLabel::mousePressEvent([[maybe_unused]] QMouseEvent* event) { emit clicked(); } diff --git a/VirtualTuringMachine/clickablelabel.h b/VirtualTuringMachine/clickablelabel.h old mode 100755 new mode 100644 index 6ca0d08..5423a41 --- a/VirtualTuringMachine/clickablelabel.h +++ b/VirtualTuringMachine/clickablelabel.h @@ -4,16 +4,16 @@ #include #include -class ClickableLabel : public QLabel -{ +class ClickableLabel : public QLabel { Q_OBJECT - public: - explicit ClickableLabel( const QString& text="", QWidget* parent=0 ); - ~ClickableLabel(); - signals: - void clicked(); - protected: - void mousePressEvent(QMouseEvent* event); + public: + explicit ClickableLabel(const QString& text = "", QWidget* parent = 0); + ~ClickableLabel(); + signals: + void clicked(); + + protected: + void mousePressEvent(QMouseEvent* event); }; -#endif // CLICKABLELABEL_H +#endif // CLICKABLELABEL_H diff --git a/VirtualTuringMachine/configuration.cpp b/VirtualTuringMachine/configuration.cpp old mode 100755 new mode 100644 index 68841e8..872b6b8 --- a/VirtualTuringMachine/configuration.cpp +++ b/VirtualTuringMachine/configuration.cpp @@ -1,48 +1,41 @@ #include "configuration.h" + #include #include -#include #include - +#include Configuration Configuration::instance; -Configuration::Configuration() - : _dark_theme(false) -{ -} +Configuration::Configuration() : _dark_theme(false) {} -const std::vector& Configuration::GetRecentProjects(){ +const std::vector& Configuration::GetRecentProjects() { return this->_recent_projects; } -const std::vector>& Configuration::GetExercises(){ +const std::vector>& Configuration::GetExercises() { return _exercises; } -void Configuration::AddRecentProject(QString & name){ +void Configuration::AddRecentProject(QString& name) { bool found = false; - for(auto &n:_recent_projects) - if(n==name) found = true; + for (auto& n : _recent_projects) + if (n == name) found = true; - if(!found) - this->_recent_projects.insert(_recent_projects.begin(),name); + if (!found) this->_recent_projects.insert(_recent_projects.begin(), name); - if(_recent_projects.size()>10) _recent_projects.pop_back(); + if (_recent_projects.size() > 10) _recent_projects.pop_back(); } -const QString& Configuration::GetDefaultLocation(){ - return _default_location; -} +const QString& Configuration::GetDefaultLocation() { return _default_location; } -void Configuration::LoadExercises(){ +void Configuration::LoadExercises() { // QFile file("://config/exercises.xml"); - if(file.open(QFile::ReadOnly | QFile::Text)) - { + if (file.open(QFile::ReadOnly | QFile::Text)) { QXmlStreamReader reader(file.readAll()); std::shared_ptr ex; while (!reader.atEnd() && !reader.hasError()) { @@ -50,63 +43,62 @@ void Configuration::LoadExercises(){ if (token == QXmlStreamReader::StartElement) { if (reader.name() == QString("exercise")) { ex = std::make_shared(); - foreach(const QXmlStreamAttribute &attr, reader.attributes()) { + foreach (const QXmlStreamAttribute& attr, + reader.attributes()) { if (attr.name().toString() == QLatin1String("id")) { ex->SetIndex(attr.value().toInt()); - } else - if (attr.name().toString() == QLatin1String("text_en")) { - ex->SetTextEn(attr.value().toString()); - } else - if (attr.name().toString() == QLatin1String("text_ru")) { - ex->SetTextRu(attr.value().toString()); - } else - if (attr.name().toString() == QLatin1String("completed")) { - ex->SetCompleted(attr.value().toInt()); - } else - if (attr.name().toString() == QLatin1String("alphabit")) { - ex->SetAlphabit(attr.value().toString()); - } + } else if (attr.name().toString() == + QLatin1String("text_en")) { + ex->SetTextEn(attr.value().toString()); + } else if (attr.name().toString() == + QLatin1String("text_ru")) { + ex->SetTextRu(attr.value().toString()); + } else if (attr.name().toString() == + QLatin1String("completed")) { + ex->SetCompleted(attr.value().toInt()); + } else if (attr.name().toString() == + QLatin1String("alphabit")) { + ex->SetAlphabit(attr.value().toString()); + } } _exercises.push_back(ex); - } else - if (reader.name() == QString("test")) { - QString input; - QString output; - - foreach(const QXmlStreamAttribute &attr, reader.attributes()) { - if (attr.name().toString() == QLatin1String("input")) { - input=attr.value().toString(); - } else - if (attr.name().toString() == QLatin1String("output")) { - output = attr.value().toString(); - } + } else if (reader.name() == QString("test")) { + QString input; + QString output; + + foreach (const QXmlStreamAttribute& attr, + reader.attributes()) { + if (attr.name().toString() == QLatin1String("input")) { + input = attr.value().toString(); + } else if (attr.name().toString() == + QLatin1String("output")) { + output = attr.value().toString(); } - std::shared_ptr ex = _exercises.back(); - ex->AddTest(input,output); } - + std::shared_ptr ex = _exercises.back(); + ex->AddTest(input, output); + } } } file.close(); } } -void Configuration::Init(QApplication *app){ +void Configuration::Init(QApplication* app) { LoadExercises(); _app = app; - _default_location = _app->applicationDirPath(); + _default_location = _app->applicationDirPath(); QString filename = _default_location; filename.append("/config.xml"); QFile file(filename); - if(!file.open(QFile::ReadOnly | QFile::Text)) - { + if (!file.open(QFile::ReadOnly | QFile::Text)) { // QMessageBox box; // box.setText(filename); // box.exec(); - //qDebug(qPrintable(QString("Error: Cannot read file %1 %2").arg(filename).arg(file.errorString()))); - } else - { + // qDebug(qPrintable(QString("Error: Cannot read file %1 + // %2").arg(filename).arg(file.errorString()))); + } else { QXmlStreamReader reader(file.readAll()); while (!reader.atEnd() && !reader.hasError()) { QXmlStreamReader::TokenType token = reader.readNext(); @@ -117,71 +109,61 @@ void Configuration::Init(QApplication *app){ name.append(reader.readElementText()); _recent_projects.push_back(name); } else if (reader.name() == QString("darkTheme")) { - _dark_theme = reader.readElementText().trimmed() == QLatin1String("1"); + _dark_theme = reader.readElementText().trimmed() == + QLatin1String("1"); } - } } file.close(); } - } - -void Configuration::Save(){ +void Configuration::Save() { QString filename = _app->applicationDirPath(); filename.append("/config.xml"); QFile file(filename); - if(!file.open(QFile::WriteOnly | QFile::Text)) - { - //qDebug(qPrintable(QString("Error: Cannot write file %1 %2").arg(filename).arg(file.errorString()))); + if (!file.open(QFile::WriteOnly | QFile::Text)) { + // qDebug(qPrintable(QString("Error: Cannot write file %1 + // %2").arg(filename).arg(file.errorString()))); } else { QXmlStreamWriter stream(&file); stream.setAutoFormatting(true); stream.writeStartDocument(); stream.writeStartElement("config"); stream.writeStartElement("projects"); - for(const QString &name: _recent_projects){ - stream.writeTextElement("project",name); + for (const QString& name : _recent_projects) { + stream.writeTextElement("project", name); } stream.writeEndElement(); - stream.writeTextElement("darkTheme", _dark_theme ? QStringLiteral("1") : QStringLiteral("0")); -/* - stream.writeStartElement("exercises"); - for(std::shared_ptr ex:GetExercises()){ - stream.writeStartElement("exercise"); - stream.writeAttribute("id",QString::number(ex->GetIndex())); - stream.writeAttribute("text_en",ex->GetTextEn()); - stream.writeAttribute("text_ru",ex->GetTextRu()); - stream.writeAttribute("completed",QString::number(ex->GetCompleted()?1:0)); - stream.writeAttribute("alphabit",ex->GetAlphabit()); - for(auto p:ex->GetTests()){ - stream.writeStartElement("test"); - stream.writeAttribute("input",p.first); - stream.writeAttribute("output",p.second); - stream.writeEndElement(); - } - stream.writeEndElement(); - } - stream.writeEndElement();*/ + stream.writeTextElement("darkTheme", _dark_theme ? QStringLiteral("1") + : QStringLiteral("0")); + /* + stream.writeStartElement("exercises"); + for(std::shared_ptr ex:GetExercises()){ + stream.writeStartElement("exercise"); + stream.writeAttribute("id",QString::number(ex->GetIndex())); + stream.writeAttribute("text_en",ex->GetTextEn()); + stream.writeAttribute("text_ru",ex->GetTextRu()); + stream.writeAttribute("completed",QString::number(ex->GetCompleted()?1:0)); + stream.writeAttribute("alphabit",ex->GetAlphabit()); + for(auto p:ex->GetTests()){ + stream.writeStartElement("test"); + stream.writeAttribute("input",p.first); + stream.writeAttribute("output",p.second); + stream.writeEndElement(); + } + stream.writeEndElement(); + } + stream.writeEndElement();*/ stream.writeEndElement(); stream.writeEndDocument(); file.close(); } - } -bool Configuration::IsDarkTheme() const -{ - return _dark_theme; -} +bool Configuration::IsDarkTheme() const { return _dark_theme; } -void Configuration::SetDarkTheme(bool enabled) -{ - _dark_theme = enabled; -} +void Configuration::SetDarkTheme(bool enabled) { _dark_theme = enabled; } -Configuration& Configuration::GetInstance(){ - return instance; -} +Configuration& Configuration::GetInstance() { return instance; } diff --git a/VirtualTuringMachine/configuration.h b/VirtualTuringMachine/configuration.h old mode 100755 new mode 100644 index 0f8f809..fcd9db8 --- a/VirtualTuringMachine/configuration.h +++ b/VirtualTuringMachine/configuration.h @@ -1,33 +1,34 @@ #ifndef CONFIGURATION_H #define CONFIGURATION_H #include +#include #include + #include "exercise.h" -#include -class Configuration -{ -private: +class Configuration { + private: static Configuration instance; - QApplication *_app; + QApplication* _app; std::vector _recent_projects; std::vector> _exercises; QString _default_location; bool _dark_theme; void LoadExercises(); -public: + + public: Configuration(); - void Init(QApplication *app); + void Init(QApplication* app); void Save(); const QString& GetDefaultLocation(); const std::vector& GetRecentProjects(); const std::vector>& GetExercises(); - void AddRecentProject(QString & name); + void AddRecentProject(QString& name); bool IsDarkTheme() const; void SetDarkTheme(bool enabled); static Configuration& GetInstance(); }; -#endif // CONFIGURATION_H +#endif // CONFIGURATION_H diff --git a/VirtualTuringMachine/diagrambezier.cpp b/VirtualTuringMachine/diagrambezier.cpp index cdb78ca..d1d0d2b 100644 --- a/VirtualTuringMachine/diagrambezier.cpp +++ b/VirtualTuringMachine/diagrambezier.cpp @@ -1,7 +1,6 @@ #include "diagrambezier.h" #include - #include #include @@ -9,18 +8,15 @@ namespace DiagramBezier { namespace { -QPoint extrapolateStart(const std::vector& points) -{ +QPoint extrapolateStart(const std::vector& points) { return points.front() + (points.front() - points[1]); } -QPoint extrapolateEnd(const std::vector& points) -{ +QPoint extrapolateEnd(const std::vector& points) { return points.back() + (points.back() - points[points.size() - 2]); } -QPoint pointAt(const std::vector& points, int index) -{ +QPoint pointAt(const std::vector& points, int index) { if (index < 0) { return extrapolateStart(points); } @@ -30,10 +26,9 @@ QPoint pointAt(const std::vector& points, int index) return points[static_cast(index)]; } -} // namespace +} // namespace -void snapPortHeights(std::vector& points) -{ +void snapPortHeights(std::vector& points) { if (points.size() < 2) { return; } @@ -52,8 +47,7 @@ void snapPortHeights(std::vector& points) } } -QPainterPath buildConnectorPath(const std::vector& points) -{ +QPainterPath buildConnectorPath(const std::vector& points) { QPainterPath path; if (points.empty()) { return path; @@ -93,8 +87,8 @@ QPainterPath buildConnectorPath(const std::vector& points) return path; } -std::vector flattenPath(const QPainterPath& path, qreal maxSegmentLength) -{ +std::vector flattenPath(const QPainterPath& path, + qreal maxSegmentLength) { std::vector samples; if (path.isEmpty()) { return samples; @@ -118,8 +112,8 @@ std::vector flattenPath(const QPainterPath& path, qreal maxSegmentLength return samples; } -bool isPointNearStroke(const QPainterPath& path, const QPoint& point, qreal tolerance) -{ +bool isPointNearStroke(const QPainterPath& path, const QPoint& point, + qreal tolerance) { if (path.isEmpty()) { return false; } @@ -133,4 +127,4 @@ bool isPointNearStroke(const QPainterPath& path, const QPoint& point, qreal tole return stroke.contains(point); } -} // namespace DiagramBezier +} // namespace DiagramBezier diff --git a/VirtualTuringMachine/diagrambezier.h b/VirtualTuringMachine/diagrambezier.h index df3b7fb..23bf98f 100644 --- a/VirtualTuringMachine/diagrambezier.h +++ b/VirtualTuringMachine/diagrambezier.h @@ -14,10 +14,12 @@ void snapPortHeights(std::vector& points); QPainterPath buildConnectorPath(const std::vector& points); /** Polyline approximation for hit-testing and overlap checks. */ -std::vector flattenPath(const QPainterPath& path, qreal maxSegmentLength = 8.0); +std::vector flattenPath(const QPainterPath& path, + qreal maxSegmentLength = 8.0); -bool isPointNearStroke(const QPainterPath& path, const QPoint& point, qreal tolerance); +bool isPointNearStroke(const QPainterPath& path, const QPoint& point, + qreal tolerance); -} // namespace DiagramBezier +} // namespace DiagramBezier -#endif // DIAGRAMBEZIER_H +#endif // DIAGRAMBEZIER_H diff --git a/VirtualTuringMachine/diagramrouting.cpp b/VirtualTuringMachine/diagramrouting.cpp index 9d8f44a..d62349d 100644 --- a/VirtualTuringMachine/diagramrouting.cpp +++ b/VirtualTuringMachine/diagramrouting.cpp @@ -1,21 +1,17 @@ #include "diagramrouting.h" -#include "interfaces/IVMTTransition.h" - #include -std::int64_t MachineSpatialIndex::cellKey(int x, int y) -{ +#include "interfaces/IVMTTransition.h" + +std::int64_t MachineSpatialIndex::cellKey(int x, int y) { return (static_cast(x) << 32) ^ static_cast(y); } MachineSpatialIndex::MachineSpatialIndex(int cellSize) - : _cellSize(std::max(8, cellSize)) -{ -} + : _cellSize(std::max(8, cellSize)) {} -void MachineSpatialIndex::addRect(const QRect& rect) -{ +void MachineSpatialIndex::addRect(const QRect& rect) { if (rect.isEmpty()) { return; } @@ -32,9 +28,9 @@ void MachineSpatialIndex::addRect(const QRect& rect) } } -void MachineSpatialIndex::rebuild(const std::vector>& machines, - int clearanceMargin) -{ +void MachineSpatialIndex::rebuild( + const std::vector>& machines, + int clearanceMargin) { _cells.clear(); for (const std::shared_ptr& machine : machines) { if (!machine) { @@ -44,15 +40,16 @@ void MachineSpatialIndex::rebuild(const std::vector QRect obstacle = machine->GetBounds(); if (clearanceMargin > 0) { obstacle = obstacle.marginsAdded( - QMargins(clearanceMargin, clearanceMargin, clearanceMargin, clearanceMargin)); + QMargins(clearanceMargin, clearanceMargin, clearanceMargin, + clearanceMargin)); } addRect(obstacle); } } -bool MachineSpatialIndex::contains(const QPoint& point) const -{ - const std::int64_t key = cellKey(point.x() / _cellSize, point.y() / _cellSize); +bool MachineSpatialIndex::contains(const QPoint& point) const { + const std::int64_t key = + cellKey(point.x() / _cellSize, point.y() / _cellSize); const auto it = _cells.find(key); if (it == _cells.end()) { return false; @@ -67,8 +64,8 @@ bool MachineSpatialIndex::contains(const QPoint& point) const return false; } -void DiagramRoutingPass::begin(const std::vector>& transitions) -{ +void DiagramRoutingPass::begin( + const std::vector>& transitions) { _snapshot.clear(); _snapshot.reserve(transitions.size()); @@ -76,23 +73,24 @@ void DiagramRoutingPass::begin(const std::vector if (!transition) { continue; } - const std::vector polyline = transition->GetCommittedRoutingPolyline(); + const std::vector polyline = + transition->GetCommittedRoutingPolyline(); if (polyline.size() >= 2) { - _snapshot.push_back({transition.get(), {polyline.begin(), polyline.end()}}); + _snapshot.push_back( + {transition.get(), {polyline.begin(), polyline.end()}}); } } _active = true; } -void DiagramRoutingPass::end() -{ +void DiagramRoutingPass::end() { _active = false; _snapshot.clear(); } -std::vector DiagramRoutingPass::blockedPathsFor(const IVMTTransition* exclude) const -{ +std::vector DiagramRoutingPass::blockedPathsFor( + const IVMTTransition* exclude) const { std::vector blockedPaths; if (!_active) { return blockedPaths; diff --git a/VirtualTuringMachine/diagramrouting.h b/VirtualTuringMachine/diagramrouting.h index 612ad33..bb32c8d 100644 --- a/VirtualTuringMachine/diagramrouting.h +++ b/VirtualTuringMachine/diagramrouting.h @@ -1,9 +1,6 @@ #ifndef DIAGRAMROUTING_H #define DIAGRAMROUTING_H -#include "interfaces/IVMTMachine.h" -#include "pathfinder.h" - #include #include #include @@ -11,17 +8,20 @@ #include #include +#include "interfaces/IVMTMachine.h" +#include "pathfinder.h" + class IVMTTransition; -class MachineSpatialIndex -{ -public: +class MachineSpatialIndex { + public: explicit MachineSpatialIndex(int cellSize = 64); - void rebuild(const std::vector>& machines, int clearanceMargin = 0); + void rebuild(const std::vector>& machines, + int clearanceMargin = 0); bool contains(const QPoint& point) const; -private: + private: int _cellSize = 64; std::unordered_map> _cells; @@ -29,16 +29,15 @@ class MachineSpatialIndex void addRect(const QRect& rect); }; -class DiagramRoutingPass -{ -public: +class DiagramRoutingPass { + public: void begin(const std::vector>& transitions); void end(); bool active() const { return _active; } std::vector blockedPathsFor(const IVMTTransition* exclude) const; -private: + private: struct SnapshotEntry { const IVMTTransition* transition = nullptr; path_t polyline; @@ -48,4 +47,4 @@ class DiagramRoutingPass std::vector _snapshot; }; -#endif // DIAGRAMROUTING_H +#endif // DIAGRAMROUTING_H diff --git a/VirtualTuringMachine/exercise.cpp b/VirtualTuringMachine/exercise.cpp old mode 100755 new mode 100644 index 4cf3815..b457f0b --- a/VirtualTuringMachine/exercise.cpp +++ b/VirtualTuringMachine/exercise.cpp @@ -1,77 +1,54 @@ #include "exercise.h" +Exercise::Exercise() : _index(0), _completed(false), _alphabit("") {} -Exercise::Exercise() : _index(0),_completed(false),_alphabit("") -{ - -} - -Exercise::Exercise(const Exercise& other){ - _alphabit = other._alphabit; - _completed = other._completed; - _index = other._index; - _tests = other._tests; - _text_en = other._text_en; - _text_ru = other._text_ru; +Exercise::Exercise(const Exercise& other) { + _alphabit = other._alphabit; + _completed = other._completed; + _index = other._index; + _tests = other._tests; + _text_en = other._text_en; + _text_ru = other._text_ru; } -void Exercise::Clear(){ +void Exercise::Clear() { _tests.clear(); _text_ru = ""; _text_en = ""; - _index = 0; + _index = 0; } -const QString & Exercise::GetAlphabit(){ - return _alphabit; -} +const QString& Exercise::GetAlphabit() { return _alphabit; } -void Exercise::SetAlphabit(const QString &alphabit){ - _alphabit = alphabit; -} +void Exercise::SetAlphabit(const QString& alphabit) { _alphabit = alphabit; } -bool Exercise::GetCompleted(){ - return _completed; -} +bool Exercise::GetCompleted() { return _completed; } -void Exercise::SetCompleted(bool completed){ - _completed = completed; -} +void Exercise::SetCompleted(bool completed) { _completed = completed; } -int Exercise::GetIndex(){ - return _index; -} +int Exercise::GetIndex() { return _index; } -const QString & Exercise::GetTextRu(){ - return _text_ru; -} -const QString & Exercise::GetTextEn(){ - return _text_en; -} -const std::vector>& Exercise::GetTests(){ +const QString& Exercise::GetTextRu() { return _text_ru; } +const QString& Exercise::GetTextEn() { return _text_en; } +const std::vector>& Exercise::GetTests() { return _tests; } -void Exercise::SetIndex(int index){ - _index = index; -} +void Exercise::SetIndex(int index) { _index = index; } -void Exercise::SetTextRu(const QString& text){ - _text_ru = text; -} +void Exercise::SetTextRu(const QString& text) { _text_ru = text; } -void Exercise::SetTextEn(const QString& text){ - _text_en = text; -} +void Exercise::SetTextEn(const QString& text) { _text_en = text; } -void Exercise::AddTest(const QString& start,const QString& finish){ - _tests.push_back(std::pair(start,finish)); +void Exercise::AddTest(const QString& start, const QString& finish) { + _tests.push_back(std::pair(start, finish)); } -QDebug operator<<(QDebug os, Exercise& ex){ - os << "Exercise:" << ex.GetIndex() << " ," << ex.GetTextEn() << " ," << ex.GetTextRu() ; - for(const auto &p : ex.GetTests()){ - os << "Test: " << p.first <<" ," << p.second; +QDebug operator<<(QDebug os, Exercise& ex) { + os << "Exercise:" << ex.GetIndex() << " ," << ex.GetTextEn() << " ," + << ex.GetTextRu(); + for (const auto& p : ex.GetTests()) { + os << "Test: " << p.first << " ," << p.second; } return os; diff --git a/VirtualTuringMachine/exercise.h b/VirtualTuringMachine/exercise.h old mode 100755 new mode 100644 index d278414..8b87c11 --- a/VirtualTuringMachine/exercise.h +++ b/VirtualTuringMachine/exercise.h @@ -1,22 +1,22 @@ #ifndef EXERCISE_H #define EXERCISE_H +#include #include +#include #include #include -#include -#include -class Exercise -{ -protected: +class Exercise { + protected: int _index; bool _completed; QString _text_ru; QString _text_en; QString _alphabit; - std::vector> _tests; -public: + std::vector> _tests; + + public: Exercise(); Exercise(const Exercise& other); @@ -24,21 +24,19 @@ class Exercise int GetIndex(); bool GetCompleted(); - const QString & GetAlphabit(); - const QString & GetTextRu(); - const QString & GetTextEn(); - const std::vector>& GetTests(); + const QString& GetAlphabit(); + const QString& GetTextRu(); + const QString& GetTextEn(); + const std::vector>& GetTests(); void SetIndex(int index); void SetCompleted(bool); - void SetAlphabit(const QString &alphabit); + void SetAlphabit(const QString& alphabit); void SetTextRu(const QString& text); void SetTextEn(const QString& text); - void AddTest(const QString& start,const QString& finish); - - + void AddTest(const QString& start, const QString& finish); }; QDebug operator<<(QDebug os, Exercise& ex); -#endif // EXERCISE_H +#endif // EXERCISE_H diff --git a/VirtualTuringMachine/flowlayout.cpp b/VirtualTuringMachine/flowlayout.cpp old mode 100755 new mode 100644 index 76b91dc..c4f8f0a --- a/VirtualTuringMachine/flowlayout.cpp +++ b/VirtualTuringMachine/flowlayout.cpp @@ -38,35 +38,27 @@ ** ****************************************************************************/ -#include - #include "flowlayout.h" -FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing) - : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing) -{ + +#include +FlowLayout::FlowLayout(QWidget* parent, int margin, int hSpacing, int vSpacing) + : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing) { setContentsMargins(margin, margin, margin, margin); } FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing) - : m_hSpace(hSpacing), m_vSpace(vSpacing) -{ + : m_hSpace(hSpacing), m_vSpace(vSpacing) { setContentsMargins(margin, margin, margin, margin); } -FlowLayout::~FlowLayout() -{ - QLayoutItem *item; - while ((item = takeAt(0))) - delete item; +FlowLayout::~FlowLayout() { + QLayoutItem* item; + while ((item = takeAt(0))) delete item; } -void FlowLayout::addItem(QLayoutItem *item) -{ - itemList.append(item); -} +void FlowLayout::addItem(QLayoutItem* item) { itemList.append(item); } -int FlowLayout::horizontalSpacing() const -{ +int FlowLayout::horizontalSpacing() const { if (m_hSpace >= 0) { return m_hSpace; } else { @@ -74,8 +66,7 @@ int FlowLayout::horizontalSpacing() const } } -int FlowLayout::verticalSpacing() const -{ +int FlowLayout::verticalSpacing() const { if (m_vSpace >= 0) { return m_vSpace; } else { @@ -83,57 +74,41 @@ int FlowLayout::verticalSpacing() const } } -int FlowLayout::count() const -{ - return itemList.size(); -} +int FlowLayout::count() const { return itemList.size(); } -QLayoutItem *FlowLayout::itemAt(int index) const -{ +QLayoutItem* FlowLayout::itemAt(int index) const { return itemList.value(index); } -QLayoutItem *FlowLayout::takeAt(int index) -{ +QLayoutItem* FlowLayout::takeAt(int index) { if (index >= 0 && index < itemList.size()) return itemList.takeAt(index); else return 0; } -Qt::Orientations FlowLayout::expandingDirections() const -{ +Qt::Orientations FlowLayout::expandingDirections() const { return Qt::Orientations(); } -bool FlowLayout::hasHeightForWidth() const -{ - return true; -} +bool FlowLayout::hasHeightForWidth() const { return true; } -int FlowLayout::heightForWidth(int width) const -{ +int FlowLayout::heightForWidth(int width) const { int height = doLayout(QRect(0, 0, width, 0), true); return height; } -void FlowLayout::setGeometry(const QRect &rect) -{ +void FlowLayout::setGeometry(const QRect& rect) { QLayout::setGeometry(rect); doLayout(rect, false); } -QSize FlowLayout::sizeHint() const -{ - return minimumSize(); -} +QSize FlowLayout::sizeHint() const { return minimumSize(); } -QSize FlowLayout::minimumSize() const -{ +QSize FlowLayout::minimumSize() const { QSize size; - QLayoutItem *item; - foreach (item, itemList) - size = size.expandedTo(item->minimumSize()); + QLayoutItem* item; + foreach (item, itemList) size = size.expandedTo(item->minimumSize()); int left, top, right, bottom; getContentsMargins(&left, &top, &right, &bottom); @@ -141,8 +116,7 @@ QSize FlowLayout::minimumSize() const return size; } -int FlowLayout::doLayout(const QRect &rect, bool testOnly) const -{ +int FlowLayout::doLayout(const QRect& rect, bool testOnly) const { int left, top, right, bottom; getContentsMargins(&left, &top, &right, &bottom); QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom); @@ -150,13 +124,14 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const int y = effectiveRect.y(); int lineHeight = 0; - QLayoutItem *item; + QLayoutItem* item; foreach (item, itemList) { - QWidget *wid = item->widget(); + QWidget* wid = item->widget(); int spaceX = horizontalSpacing(); if (spaceX == -1) - spaceX = wid->style()->layoutSpacing( - QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal); + spaceX = wid->style()->layoutSpacing(QSizePolicy::PushButton, + QSizePolicy::PushButton, + Qt::Horizontal); int spaceY = verticalSpacing(); if (spaceY == -1) spaceY = wid->style()->layoutSpacing( @@ -169,23 +144,21 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const lineHeight = 0; } - if (!testOnly) - item->setGeometry(QRect(QPoint(x, y), item->sizeHint())); + if (!testOnly) item->setGeometry(QRect(QPoint(x, y), item->sizeHint())); x = nextX; lineHeight = qMax(lineHeight, item->sizeHint().height()); } return y + lineHeight - rect.y() + bottom; } -int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const -{ - QObject *parent = this->parent(); +int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const { + QObject* parent = this->parent(); if (!parent) { return -1; } else if (parent->isWidgetType()) { - QWidget *pw = static_cast(parent); + QWidget* pw = static_cast(parent); return pw->style()->pixelMetric(pm, 0, pw); } else { - return static_cast(parent)->spacing(); + return static_cast(parent)->spacing(); } } diff --git a/VirtualTuringMachine/flowlayout.h b/VirtualTuringMachine/flowlayout.h old mode 100755 new mode 100644 index 6e61ef9..3c2a04b --- a/VirtualTuringMachine/flowlayout.h +++ b/VirtualTuringMachine/flowlayout.h @@ -44,33 +44,33 @@ #include #include #include -class FlowLayout : public QLayout -{ -public: - explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1); +class FlowLayout : public QLayout { + public: + explicit FlowLayout(QWidget* parent, int margin = -1, int hSpacing = -1, + int vSpacing = -1); explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1); ~FlowLayout(); - void addItem(QLayoutItem *item) Q_DECL_OVERRIDE; + void addItem(QLayoutItem* item) Q_DECL_OVERRIDE; int horizontalSpacing() const; int verticalSpacing() const; Qt::Orientations expandingDirections() const Q_DECL_OVERRIDE; bool hasHeightForWidth() const Q_DECL_OVERRIDE; int heightForWidth(int) const Q_DECL_OVERRIDE; int count() const Q_DECL_OVERRIDE; - QLayoutItem *itemAt(int index) const Q_DECL_OVERRIDE; + QLayoutItem* itemAt(int index) const Q_DECL_OVERRIDE; QSize minimumSize() const Q_DECL_OVERRIDE; - void setGeometry(const QRect &rect) Q_DECL_OVERRIDE; + void setGeometry(const QRect& rect) Q_DECL_OVERRIDE; QSize sizeHint() const Q_DECL_OVERRIDE; - QLayoutItem *takeAt(int index) Q_DECL_OVERRIDE; + QLayoutItem* takeAt(int index) Q_DECL_OVERRIDE; -private: - int doLayout(const QRect &rect, bool testOnly) const; + private: + int doLayout(const QRect& rect, bool testOnly) const; int smartSpacing(QStyle::PixelMetric pm) const; - QList itemList; + QList itemList; int m_hSpace; int m_vSpace; }; -#endif // FLOWLAYOUT_H +#endif // FLOWLAYOUT_H diff --git a/VirtualTuringMachine/formactionhint.cpp b/VirtualTuringMachine/formactionhint.cpp old mode 100755 new mode 100644 index e6762a9..d9183e3 --- a/VirtualTuringMachine/formactionhint.cpp +++ b/VirtualTuringMachine/formactionhint.cpp @@ -1,21 +1,19 @@ #include "formactionhint.h" -#include "ui_formactionhint.h" + #include "screentools.h" +#include "ui_formactionhint.h" -FormActionHint::FormActionHint(const QString &txt,QPixmap& img,QWidget *parent) : - QWidget(parent), - ui(new Ui::FormActionHint) -{ +FormActionHint::FormActionHint(const QString& txt, QPixmap& img, + QWidget* parent) + : QWidget(parent), ui(new Ui::FormActionHint) { ui->setupUi(this); - ScreenTools st; + ScreenTools st; - ui->label_text->setText(txt); - ui->label_img->setPixmap(img.scaled(st.GetImageSize(),Qt::KeepAspectRatio, Qt::SmoothTransformation)); - ui->label_img->setText(""); + ui->label_text->setText(txt); + ui->label_img->setPixmap(img.scaled(st.GetImageSize(), Qt::KeepAspectRatio, + Qt::SmoothTransformation)); + ui->label_img->setText(""); } -FormActionHint::~FormActionHint() -{ - delete ui; -} +FormActionHint::~FormActionHint() { delete ui; } diff --git a/VirtualTuringMachine/formactionhint.h b/VirtualTuringMachine/formactionhint.h old mode 100755 new mode 100644 index 10db4d8..b3825fe --- a/VirtualTuringMachine/formactionhint.h +++ b/VirtualTuringMachine/formactionhint.h @@ -1,24 +1,24 @@ #ifndef FORMACTIONHINT_H #define FORMACTIONHINT_H -#include -#include #include +#include +#include namespace Ui { class FormActionHint; } -class FormActionHint : public QWidget -{ +class FormActionHint : public QWidget { Q_OBJECT -public: - explicit FormActionHint(const QString &txt,QPixmap& img,QWidget *parent = 0); + public: + explicit FormActionHint(const QString& txt, QPixmap& img, + QWidget* parent = 0); ~FormActionHint(); -private: - Ui::FormActionHint *ui; + private: + Ui::FormActionHint* ui; }; -#endif // FORMACTIONHINT_H +#endif // FORMACTIONHINT_H diff --git a/VirtualTuringMachine/formalphabit.cpp b/VirtualTuringMachine/formalphabit.cpp old mode 100755 new mode 100644 index 724dd85..8ed51ca --- a/VirtualTuringMachine/formalphabit.cpp +++ b/VirtualTuringMachine/formalphabit.cpp @@ -1,80 +1,77 @@ #include "formalphabit.h" -#include "ui_formalphabit.h" + #include + #include "interfaces/IVMTEnvironment.h" #include "screentools.h" +#include "ui_formalphabit.h" #include "vmttheme.h" -FormAlphabit::FormAlphabit(IVMTAlphabitSource *alphabit_source,IVMTEnvironment *environment,QWidget *parent) : - QWidget(parent), - ui(new Ui::FormAlphabit), - _alphabit_source(alphabit_source), - _environment(environment) -{ +FormAlphabit::FormAlphabit(IVMTAlphabitSource* alphabit_source, + IVMTEnvironment* environment, QWidget* parent) + : QWidget(parent), + ui(new Ui::FormAlphabit), + _alphabit_source(alphabit_source), + _environment(environment) { ui->setupUi(this); VmtTheme::polishWidgetTree(this); -// QButtonGroup *_group = nullptr; -// if(_alphabit_source->IsSingleChar()) -// _group = new QButtonGroup(); + // QButtonGroup *_group = nullptr; + // if(_alphabit_source->IsSingleChar()) + // _group = new QButtonGroup(); - if(!_alphabit_source->GetAlphabit()) qDebug() << "FormAlphabit::FormAlphabit Oppps 2!"; + if (!_alphabit_source->GetAlphabit()) + qDebug() << "FormAlphabit::FormAlphabit Oppps 2!"; QString str = _alphabit_source->GetAlphabit()->ToString(); //_layout.setSpacing(10); ui->frame->setLayout(&_layout); - ui->frame->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); - _layout.setContentsMargins(5,5,5,5); + ui->frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + _layout.setContentsMargins(5, 5, 5, 5); ScreenTools st; const QString style = VmtTheme::alphabetButtonStyle(); const int count = qMin(static_cast(str.size()), 256); - for(int i = 0; i < count; ++i){ - + for (int i = 0; i < count; ++i) { QToolButton* label = &_buttons[i]; - //label->setFlat(true); - label->setProperty("sign",QString(QChar(str[i]))); + // label->setFlat(true); + label->setProperty("sign", QString(QChar(str[i]))); label->setText(QString(QChar(str[i]))); label->setCheckable(true); label->setStyleSheet(style); st.ResizeButton(label); - if(_alphabit_source->IsEnabled(str[i].toLatin1())) + if (_alphabit_source->IsEnabled(str[i].toLatin1())) label->setChecked(true); - else label->setChecked(false); + else + label->setChecked(false); - QObject::connect(label, SIGNAL(clicked()), - this, SLOT(onRefClicked())); + QObject::connect(label, SIGNAL(clicked()), this, SLOT(onRefClicked())); _layout.addWidget(label); - if(_alphabit_source->IsSingleChar()) _group.addButton(label); + if (_alphabit_source->IsSingleChar()) _group.addButton(label); } - } -void FormAlphabit::onRefClicked(){ - QToolButton *button = dynamic_cast (sender()); - if(button) - { +void FormAlphabit::onRefClicked() { + QToolButton* button = dynamic_cast(sender()); + if (button) { QVariant var = button->property("sign"); - QString sign = var.toString(); + QString sign = var.toString(); qDebug() << "Click"; - if(_alphabit_source) - { - if(ctrlPressed) { + if (_alphabit_source) { + if (ctrlPressed) { qDebug() << "Disable all exclude this"; - _alphabit_source->SetDisableAllExclude(sign[0].toLatin1(),_environment); + _alphabit_source->SetDisableAllExclude(sign[0].toLatin1(), + _environment); _environment->Repaint(QRect()); } else { - _alphabit_source->SetEnable(sign[0].toLatin1(),button->isChecked(),_environment); + _alphabit_source->SetEnable(sign[0].toLatin1(), + button->isChecked(), _environment); _environment->Repaint(QRect()); } } } } - -FormAlphabit::~FormAlphabit() -{ - delete ui; -} +FormAlphabit::~FormAlphabit() { delete ui; } diff --git a/VirtualTuringMachine/formalphabit.h b/VirtualTuringMachine/formalphabit.h old mode 100755 new mode 100644 index d79a919..7c05ffd --- a/VirtualTuringMachine/formalphabit.h +++ b/VirtualTuringMachine/formalphabit.h @@ -1,40 +1,41 @@ #ifndef FORMALPHABIT_H #define FORMALPHABIT_H +#include +#include #include -#include "interfaces/IVMTAlphabitSource.h" -#include "isCtrlPressed.h" #include -#include -#include + #include "flowlayout.h" +#include "interfaces/IVMTAlphabitSource.h" +#include "isCtrlPressed.h" class IVMTEnvironment; namespace Ui { class FormAlphabit; } -class FormAlphabit : public QWidget -{ +class FormAlphabit : public QWidget { Q_OBJECT -public: - explicit FormAlphabit(IVMTAlphabitSource *alphabit_source,IVMTEnvironment *environment,QWidget *parent = 0); + public: + explicit FormAlphabit(IVMTAlphabitSource* alphabit_source, + IVMTEnvironment* environment, QWidget* parent = 0); IVMTAlphabitSource* GetAlphabitSource() const { return _alphabit_source; } ~FormAlphabit(); -private: - Ui::FormAlphabit *ui; - IVMTAlphabitSource *_alphabit_source; - IVMTEnvironment *_environment; - //std::vector _buttons; + private: + Ui::FormAlphabit* ui; + IVMTAlphabitSource* _alphabit_source; + IVMTEnvironment* _environment; + // std::vector _buttons; std::vector _names; FlowLayout _layout; QToolButton _buttons[256]; QButtonGroup _group; -private slots: + private slots: void onRefClicked(); }; -#endif // FORMALPHABIT_H +#endif // FORMALPHABIT_H diff --git a/VirtualTuringMachine/formbase.h b/VirtualTuringMachine/formbase.h old mode 100755 new mode 100644 index d28f4fe..52a956e --- a/VirtualTuringMachine/formbase.h +++ b/VirtualTuringMachine/formbase.h @@ -4,13 +4,12 @@ #include "statecontroller.h" #include "uistate.h" -class FormBase{ -protected: - StateController *_controller = nullptr; -public: - void SetController(StateController *c){ - _controller = c; - } +class FormBase { + protected: + StateController* _controller = nullptr; + + public: + void SetController(StateController* c) { _controller = c; } virtual void BeforeChange(std::shared_ptr state_data) = 0; virtual void AfterUndo(std::shared_ptr state_data) = 0; @@ -19,4 +18,4 @@ class FormBase{ virtual ~FormBase() = default; }; -#endif // FORMBASE_H +#endif // FORMBASE_H diff --git a/VirtualTuringMachine/formcalculator.cpp b/VirtualTuringMachine/formcalculator.cpp old mode 100755 new mode 100644 index 21bbe1c..c024632 --- a/VirtualTuringMachine/formcalculator.cpp +++ b/VirtualTuringMachine/formcalculator.cpp @@ -1,93 +1,83 @@ #include "formcalculator.h" -#include "ui_formcalculator.h" + #include "screentools.h" +#include "ui_formcalculator.h" -FormCalculator::FormCalculator(std::shared_ptr machine, IVMTEnvironment * environment, QWidget * parent) : - QWidget(parent), - ui(new Ui::FormCalculator), - _machine(machine), - _environment(environment) { - ui->setupUi(this); +FormCalculator::FormCalculator(std::shared_ptr machine, + IVMTEnvironment* environment, QWidget* parent) + : QWidget(parent), + ui(new Ui::FormCalculator), + _machine(machine), + _environment(environment) { + ui->setupUi(this); - ScreenTools st; + ScreenTools st; - st.ResizeButton(ui->_plus); - st.ResizeButton(ui->_minus); + st.ResizeButton(ui->_plus); + st.ResizeButton(ui->_minus); - QString str; - str = QString::number(machine->GetPower()); - ui->text_power->setText(str); + QString str; + str = QString::number(machine->GetPower()); + ui->text_power->setText(str); } void FormCalculator::Check() { - QString str = ui->text_power->text(); - if (str.length() < 1) { - str = "1"; - ui->text_power->setText(str); - } - else { - - bool ok = true; - for (int i = 0;i < str.length();i++) - if ((str[i] < '0') || (str[i] > '9')) { - str.remove(i, 1); - ok = false; - } - if (!ok) ui->text_power->setText(str); - } - -} - -FormCalculator::~FormCalculator() { - delete ui; -} - - - -void FormCalculator::on_text_power_textChanged(const QString &) { - Check(); - - QString str = ui->text_power->text(); - bool ok; - int power = str.toInt(&ok); - if (ok) { - _machine->SetPower(power); - _machine->Update(_environment); - QRect rect; - if (_environment) _environment->Repaint(rect); - // VMTProject::GetInstance().GetUndoManager()->Remember( - // std::shared_ptr(new VMTUndoElementMachine())); - } + QString str = ui->text_power->text(); + if (str.length() < 1) { + str = "1"; + ui->text_power->setText(str); + } else { + bool ok = true; + for (int i = 0; i < str.length(); i++) + if ((str[i] < '0') || (str[i] > '9')) { + str.remove(i, 1); + ok = false; + } + if (!ok) ui->text_power->setText(str); + } } -void FormCalculator::on_button_plus_clicked() { - - +FormCalculator::~FormCalculator() { delete ui; } + +void FormCalculator::on_text_power_textChanged(const QString&) { + Check(); + + QString str = ui->text_power->text(); + bool ok; + int power = str.toInt(&ok); + if (ok) { + _machine->SetPower(power); + _machine->Update(_environment); + QRect rect; + if (_environment) _environment->Repaint(rect); + // VMTProject::GetInstance().GetUndoManager()->Remember( + // std::shared_ptr(new + // VMTUndoElementMachine())); + } } -void FormCalculator::on_button_minus_clicked() { +void FormCalculator::on_button_plus_clicked() {} - -} +void FormCalculator::on_button_minus_clicked() {} void FormCalculator::on__plus_clicked() { - QString str = ui->text_power->text(); - bool ok; - int power = str.toInt(&ok); - if (ok) { - str = QString::number(power + 1); - ui->text_power->setText(str); - } + QString str = ui->text_power->text(); + bool ok; + int power = str.toInt(&ok); + if (ok) { + str = QString::number(power + 1); + ui->text_power->setText(str); + } } void FormCalculator::on__minus_clicked() { - QString str = ui->text_power->text(); - bool ok; - int power = str.toInt(&ok); - if (ok) { - if (power > 1) { - str = QString::number(power - 1); - ui->text_power->setText(str); - } - } + QString str = ui->text_power->text(); + bool ok; + int power = str.toInt(&ok); + if (ok) { + if (power > 1) { + str = QString::number(power - 1); + ui->text_power->setText(str); + } + } } diff --git a/VirtualTuringMachine/formcalculator.h b/VirtualTuringMachine/formcalculator.h old mode 100755 new mode 100644 index 473cb7c..5af2d25 --- a/VirtualTuringMachine/formcalculator.h +++ b/VirtualTuringMachine/formcalculator.h @@ -1,27 +1,28 @@ #ifndef FORMCALCULATOR_H #define FORMCALCULATOR_H -#include #include -#include "interfaces/IVMTMachine.h" -#include "interfaces/IVMTEnvironment.h" +#include #include +#include "interfaces/IVMTEnvironment.h" +#include "interfaces/IVMTMachine.h" + namespace Ui { class FormCalculator; } -class FormCalculator : public QWidget -{ +class FormCalculator : public QWidget { Q_OBJECT -public: - explicit FormCalculator(std::shared_ptr machine,IVMTEnvironment *environment,QWidget *parent = 0); + public: + explicit FormCalculator(std::shared_ptr machine, + IVMTEnvironment* environment, QWidget* parent = 0); std::shared_ptr machine() const { return _machine; } ~FormCalculator(); -private slots: - void on_text_power_textChanged(const QString &arg1); + private slots: + void on_text_power_textChanged(const QString& arg1); void on_button_plus_clicked(); @@ -31,12 +32,12 @@ private slots: void on__minus_clicked(); -private: - Ui::FormCalculator *ui; + private: + Ui::FormCalculator* ui; std::shared_ptr _machine; - IVMTEnvironment *_environment; + IVMTEnvironment* _environment; void Check(); }; -#endif // FORMCALCULATOR_H +#endif // FORMCALCULATOR_H diff --git a/VirtualTuringMachine/formcompilermachine.cpp b/VirtualTuringMachine/formcompilermachine.cpp old mode 100755 new mode 100644 index ecbf7a7..1b27f3b --- a/VirtualTuringMachine/formcompilermachine.cpp +++ b/VirtualTuringMachine/formcompilermachine.cpp @@ -1,95 +1,98 @@ #include "formcompilermachine.h" + #include "ui_formcompilermachine.h" -#include "vmtproject.h" #include "vmtactions/vmtactiontranslate.h" +#include "vmtproject.h" -FormCompilerMachine::FormCompilerMachine(QWidget *parent) : - QWidget(parent), - ui(new Ui::FormCompilerMachine) -{ +FormCompilerMachine::FormCompilerMachine(QWidget* parent) + : QWidget(parent), ui(new Ui::FormCompilerMachine) { ui->setupUi(this); ui->widget_editor->SetEnvironment(this); } -void FormCompilerMachine::BeforeChange(std::shared_ptr){ +void FormCompilerMachine::BeforeChange(std::shared_ptr) { qDebug() << "Clear errors"; ClearErrors(); } -void FormCompilerMachine::ClearErrors(){ - for(auto cm: VMTProject::GetInstance().GetMachines()){ - for(std::shared_ptr m: cm->GetMachineCollection()){ +void FormCompilerMachine::ClearErrors() { + for (auto cm : VMTProject::GetInstance().GetMachines()) { + for (std::shared_ptr m : cm->GetMachineCollection()) { m->SetError(false); } - for(const std::weak_ptr &t: cm->GetOutgoingTransitions()){ - if(auto t_ptr = t.lock()){ + for (const std::weak_ptr& t : + cm->GetOutgoingTransitions()) { + if (auto t_ptr = t.lock()) { t_ptr->SetError(false); } } } } -void FormCompilerMachine::AfterUndo(std::shared_ptr) { - -} +void FormCompilerMachine::AfterUndo(std::shared_ptr) {} -void FormCompilerMachine::ChangeZoom(int zoom){ +void FormCompilerMachine::ChangeZoom(int zoom) { ui->widget_editor->SetZoom(zoom); } -void FormCompilerMachine::EnableActionHint([[maybe_unused]] const QString &hint,[[maybe_unused]] QPixmap& img) {}; -void FormCompilerMachine::DisableActionHint(){}; -void FormCompilerMachine::DisableAlphabit(){} +void FormCompilerMachine::EnableActionHint([[maybe_unused]] const QString& hint, + [[maybe_unused]] QPixmap& img) {}; +void FormCompilerMachine::DisableActionHint() {}; +void FormCompilerMachine::DisableAlphabit() {} void FormCompilerMachine::DisableCalculator() {} -void FormCompilerMachine::EnableAlphabit([[maybe_unused]] IVMTAlphabitSource*,const QString& ,[[maybe_unused]] QPixmap & ){} -void FormCompilerMachine::EnableCalculator([[maybe_unused]] std::shared_ptr ){} -void FormCompilerMachine::EnableAnimation([[maybe_unused]] bool enable){}; - -UICanvas& FormCompilerMachine::GetGraphics(){ - return ui->widget_editor->GetCanvas(); +void FormCompilerMachine::EnableAlphabit([[maybe_unused]] IVMTAlphabitSource*, + const QString&, + [[maybe_unused]] QPixmap&) {} +void FormCompilerMachine::EnableCalculator( + [[maybe_unused]] std::shared_ptr) {} +void FormCompilerMachine::EnableAnimation([[maybe_unused]] bool enable) {}; + +UICanvas& FormCompilerMachine::GetGraphics() { + return ui->widget_editor->GetCanvas(); } -std::weak_ptr FormCompilerMachine::GetMachine(){ - return std::weak_ptr(ui->widget_editor->GetComplexMachine()); +std::weak_ptr FormCompilerMachine::GetMachine() { + return std::weak_ptr( + ui->widget_editor->GetComplexMachine()); } -void FormCompilerMachine::Repaint([[maybe_unused]] const QRect& rect){ +void FormCompilerMachine::Repaint([[maybe_unused]] const QRect& rect) { ui->widget_editor->update(); } -void FormCompilerMachine::MoveInScreen(QPoint &&shift){ +void FormCompilerMachine::MoveInScreen(QPoint&& shift) { ui->widget_editor->GetCanvas().MoveInScreen(shift); } -void FormCompilerMachine::Move(QPoint &&shift){ +void FormCompilerMachine::Move(QPoint&& shift) { ui->widget_editor->GetCanvas().Move(shift); } -void FormCompilerMachine::SetMachine(std::shared_ptr machine){ +void FormCompilerMachine::SetMachine( + std::shared_ptr machine) { ui->widget_editor->SetComplexMachine(machine); } -void FormCompilerMachine::OnLoaded(){ +void FormCompilerMachine::OnLoaded() { Check(); SetAction(std::shared_ptr(new VMTActionTranslate(this))); } -void FormCompilerMachine::SetAction(std::shared_ptr action){ - if(ui->widget_editor->GetAction()) ui->widget_editor->GetAction()->Cancel(this); - ui->widget_editor->GetAction() = action; - if(ui->widget_editor->GetAction()) ui->widget_editor->GetAction()->Enable(this); +void FormCompilerMachine::SetAction(std::shared_ptr action) { + if (ui->widget_editor->GetAction()) + ui->widget_editor->GetAction()->Cancel(this); + ui->widget_editor->GetAction() = action; + if (ui->widget_editor->GetAction()) + ui->widget_editor->GetAction()->Enable(this); } -bool FormCompilerMachine::HasErrors(){ - return !_errors.empty(); -} +bool FormCompilerMachine::HasErrors() { return !_errors.empty(); } -void FormCompilerMachine::Check(){ - std::vector> to_go; +void FormCompilerMachine::Check() { + std::vector> to_go; - for(auto m: VMTProject::GetInstance().GetMachines()) - to_go.push_back(m); + for (auto m : VMTProject::GetInstance().GetMachines()) to_go.push_back(m); - while(to_go.size()>0){ + while (to_go.size() > 0) { std::shared_ptr complex_machine = to_go.at(0); CheckStart(complex_machine); @@ -100,153 +103,201 @@ void FormCompilerMachine::Check(){ to_go.erase(to_go.begin()); } - for(VMTError* err: _errors){ + for (VMTError* err : _errors) { ui->list_errors->addItem(err->GetMessage()); } - if(_errors.size()>0) { + if (_errors.size() > 0) { ui->list_errors->item(0)->setSelected(true); on_list_errors_currentRowChanged(0); } } +void FormCompilerMachine::CheckStart( + std::shared_ptr complex_machine) { + int count = 0; -void FormCompilerMachine::CheckStart(std::shared_ptr complex_machine){ - int count=0; - - for(std::shared_ptr m: complex_machine->GetMachineCollection()){ - if(m->GetID()==IVMTMachine::MachineType::MT_START){ - count ++; + for (std::shared_ptr m : + complex_machine->GetMachineCollection()) { + if (m->GetID() == IVMTMachine::MachineType::MT_START) { + count++; } } - if(count==0) _errors.push_back(new VMTError(complex_machine,QString("No start machine found in %1").arg(complex_machine->GetName()))); - if(count>1) _errors.push_back(new VMTError(complex_machine,QString("Oney one start machine should be in %1, now=%2").arg(complex_machine->GetName(),QString::number(count)))); + if (count == 0) + _errors.push_back(new VMTError(complex_machine, + QString("No start machine found in %1") + .arg(complex_machine->GetName()))); + if (count > 1) + _errors.push_back(new VMTError( + complex_machine, + QString("Oney one start machine should be in %1, now=%2") + .arg(complex_machine->GetName(), QString::number(count)))); } -void FormCompilerMachine::CheckFinish(std::shared_ptr complex_machine){ - int count=0; +void FormCompilerMachine::CheckFinish( + std::shared_ptr complex_machine) { + int count = 0; - for(std::shared_ptr m: complex_machine->GetMachineCollection()){ - if(m->GetID()==IVMTMachine::MachineType::MT_FINISH){ - count ++; + for (std::shared_ptr m : + complex_machine->GetMachineCollection()) { + if (m->GetID() == IVMTMachine::MachineType::MT_FINISH) { + count++; } } - if(count==0) this->_errors.push_back(new VMTError(complex_machine,QString("No finish machine found in %1").arg(complex_machine->GetName()))); + if (count == 0) + this->_errors.push_back(new VMTError( + complex_machine, QString("No finish machine found in %1") + .arg(complex_machine->GetName()))); } -void FormCompilerMachine::CheckConnection(std::shared_ptr complex_machine){ - for(std::shared_ptr m: complex_machine->GetMachineCollection()){ - if(m->GetID()==IVMTMachine::MachineType::MT_START){ - if(m->GetIncomingTransitions().size()>0) - _errors.push_back(new VMTErrorMachine(complex_machine,QString("No incoming transition allowed for start machine in %1").arg(complex_machine->GetName()),m)); +void FormCompilerMachine::CheckConnection( + std::shared_ptr complex_machine) { + for (std::shared_ptr m : + complex_machine->GetMachineCollection()) { + if (m->GetID() == IVMTMachine::MachineType::MT_START) { + if (m->GetIncomingTransitions().size() > 0) + _errors.push_back(new VMTErrorMachine( + complex_machine, + QString("No incoming transition allowed for start machine " + "in %1") + .arg(complex_machine->GetName()), + m)); } else { - if(m->GetIncomingTransitions().size()==0) - _errors.push_back(new VMTErrorMachine(complex_machine,QString("No incoming transition found for %1 machine in %2").arg(m->GetName(),complex_machine->GetName()),m)); - + if (m->GetIncomingTransitions().size() == 0) + _errors.push_back(new VMTErrorMachine( + complex_machine, + QString("No incoming transition found for %1 machine in %2") + .arg(m->GetName(), complex_machine->GetName()), + m)); } - if(m->GetID()==IVMTMachine::MachineType::MT_FINISH){ - if(m->GetOutgoingTransitions().size()>0) - _errors.push_back(new VMTErrorMachine(complex_machine,QString("No outgoing transition allowed for finish machine in %1").arg(complex_machine->GetName()),m)); + if (m->GetID() == IVMTMachine::MachineType::MT_FINISH) { + if (m->GetOutgoingTransitions().size() > 0) + _errors.push_back(new VMTErrorMachine( + complex_machine, + QString("No outgoing transition allowed for finish machine " + "in %1") + .arg(complex_machine->GetName()), + m)); } else { - if(m->GetOutgoingTransitions().size()==0) - _errors.push_back(new VMTErrorMachine(complex_machine,QString("No outgoing transition found for %1 machine in %2").arg(m->GetName(),complex_machine->GetName()),m)); - + if (m->GetOutgoingTransitions().size() == 0) + _errors.push_back(new VMTErrorMachine( + complex_machine, + QString("No outgoing transition found for %1 machine in %2") + .arg(m->GetName(), complex_machine->GetName()), + m)); } - - } } -void FormCompilerMachine::CheckAllCases(std::shared_ptr complex_machine){ - for(std::shared_ptr m: complex_machine->GetMachineCollection()){ - if(m->GetID()!=IVMTMachine::MachineType::MT_FINISH){ - QString all_str=complex_machine->GetAlphabit()->ToString(); +void FormCompilerMachine::CheckAllCases( + std::shared_ptr complex_machine) { + for (std::shared_ptr m : + complex_machine->GetMachineCollection()) { + if (m->GetID() != IVMTMachine::MachineType::MT_FINISH) { + QString all_str = complex_machine->GetAlphabit()->ToString(); - for(std::weak_ptr t: m->GetOutgoingTransitions()){ - if(auto t_ptr = t.lock()){ + for (std::weak_ptr t : + m->GetOutgoingTransitions()) { + if (auto t_ptr = t.lock()) { QString tr_str = t_ptr->GetConditions().GetAsString(); - for(QChar c:tr_str){ - for(int i=0;i0) - _errors.push_back(new VMTErrorMachine(complex_machine,QString("No outgoing transition from %1 machine in %2 for signs '%3'").arg(m->GetName(),complex_machine->GetName(),all_str),m)); + if (all_str.length() > 0) + _errors.push_back(new VMTErrorMachine( + complex_machine, + QString("No outgoing transition from %1 machine in %2 for " + "signs '%3'") + .arg(m->GetName(), complex_machine->GetName(), all_str), + m)); } } - - } -void FormCompilerMachine::CheckDublicate(std::shared_ptr complex_machine){ - for(std::shared_ptr m: complex_machine->GetMachineCollection()){ - - if(m->GetID()!=IVMTMachine::MachineType::MT_FINISH){ +void FormCompilerMachine::CheckDublicate( + std::shared_ptr complex_machine) { + for (std::shared_ptr m : + complex_machine->GetMachineCollection()) { + if (m->GetID() != IVMTMachine::MachineType::MT_FINISH) { QString all_str; QString dublicate; - for(std::weak_ptr t: m->GetOutgoingTransitions()){ - if(auto t_ptr = t.lock()){ + for (std::weak_ptr t : + m->GetOutgoingTransitions()) { + if (auto t_ptr = t.lock()) { QString tr_str = t_ptr->GetConditions().GetAsString(); - for(QChar c:tr_str){ - if(all_str.indexOf(c)>=0){ + for (QChar c : tr_str) { + if (all_str.indexOf(c) >= 0) { dublicate.append(c); - } else all_str.append(c); + } else + all_str.append(c); } } } - if(dublicate.length()>0) - _errors.push_back(new VMTErrorMachine(complex_machine,QString("More then one outgoing transition from %1 machine in %2 for signs '%3'").arg(m->GetName(),complex_machine->GetName(),dublicate),m)); - + if (dublicate.length() > 0) + _errors.push_back(new VMTErrorMachine( + complex_machine, + QString("More then one outgoing transition from %1 machine " + "in %2 for signs '%3'") + .arg(m->GetName(), complex_machine->GetName(), + dublicate), + m)); } } } -FormCompilerMachine::~FormCompilerMachine() -{ - //ClearErrors(); +FormCompilerMachine::~FormCompilerMachine() { + // ClearErrors(); delete ui; } - - -void FormCompilerMachine::on_list_errors_currentRowChanged(int currentRow) -{ +void FormCompilerMachine::on_list_errors_currentRowChanged(int currentRow) { qDebug() << "FormCompilerMachine::on_list_errors_currentRowChanged"; ClearErrors(); - if(currentRow>=0){ - qDebug() << "FormCompilerMachine::on_list_errors_currentRowChanged::Select"; + if (currentRow >= 0) { + qDebug() + << "FormCompilerMachine::on_list_errors_currentRowChanged::Select"; - VMTError* err= _errors[currentRow]; + VMTError* err = _errors[currentRow]; ui->widget_editor->SetComplexMachine(err->GetMachine()); - qDebug() << "FormCompilerMachine::on_list_errors_currentRowChanged::Deselect"; + qDebug() << "FormCompilerMachine::on_list_errors_currentRowChanged::" + "Deselect"; - if(! ui->widget_editor->GetComplexMachine()) qDebug() << "FormCompilerMachine::on_list_errors_currentRowChanged::No complex machine"; + if (!ui->widget_editor->GetComplexMachine()) + qDebug() << "FormCompilerMachine::on_list_errors_currentRowChanged:" + ":No complex machine"; ui->widget_editor->GetComplexMachine()->DeselectAll(); - qDebug() << "FormCompilerMachine::on_list_errors_currentRowChanged::Highlight"; + qDebug() << "FormCompilerMachine::on_list_errors_currentRowChanged::" + "Highlight"; - if(err->GetErrorMachine()){ + if (err->GetErrorMachine()) { err->GetErrorMachine()->SetError(true); QPoint point = err->GetErrorMachine()->GetCenter(); - ui->widget_editor->GetCanvas().SetCenter(point,ui->widget_editor->size()); - } else - if(err->GetErrorTransition()){ + ui->widget_editor->GetCanvas().SetCenter(point, + ui->widget_editor->size()); + } else if (err->GetErrorTransition()) { err->GetErrorTransition()->SetError(true); QPoint point = err->GetErrorTransition()->GetBounds().center(); - ui->widget_editor->GetCanvas().SetCenter(point,ui->widget_editor->size()); + ui->widget_editor->GetCanvas().SetCenter(point, + ui->widget_editor->size()); } - qDebug() << "FormCompilerMachine::on_list_errors_currentRowChanged::done"; + qDebug() + << "FormCompilerMachine::on_list_errors_currentRowChanged::done"; ui->widget_editor->update(); } } diff --git a/VirtualTuringMachine/formcompilermachine.h b/VirtualTuringMachine/formcompilermachine.h old mode 100755 new mode 100644 index d1906db..76dcf90 --- a/VirtualTuringMachine/formcompilermachine.h +++ b/VirtualTuringMachine/formcompilermachine.h @@ -2,24 +2,26 @@ #define FORMCOMPILERMACHINE_H #include -#include "formbase.h" - #include + +#include "formbase.h" +#include "interfaces/IVMTActionController.h" +#include "interfaces/IVMTEnvironment.h" #include "vmterrormachine.h" #include "vmterrortransition.h" -#include "interfaces/IVMTEnvironment.h" -#include "interfaces/IVMTActionController.h" namespace Ui { class FormCompilerMachine; } -class FormCompilerMachine : public QWidget , public FormBase, public IVMTEnvironment, public IVMTActionController -{ +class FormCompilerMachine : public QWidget, + public FormBase, + public IVMTEnvironment, + public IVMTActionController { Q_OBJECT -public: - explicit FormCompilerMachine(QWidget *parent = 0); + public: + explicit FormCompilerMachine(QWidget* parent = 0); void BeforeChange(std::shared_ptr state_data) override; void AfterUndo(std::shared_ptr state_data) override; void OnLoaded() override; @@ -28,29 +30,30 @@ class FormCompilerMachine : public QWidget , public FormBase, public IVMTEnviron bool HasErrors(); // IVMTEnvironment - void EnableActionHint(const QString &hint,QPixmap& img) override; + void EnableActionHint(const QString& hint, QPixmap& img) override; void DisableActionHint() override; void DisableAlphabit() override; void DisableCalculator() override; - void EnableAlphabit(IVMTAlphabitSource* p_Alphabit,const QString& msg,QPixmap &img) override; + void EnableAlphabit(IVMTAlphabitSource* p_Alphabit, const QString& msg, + QPixmap& img) override; void EnableCalculator(std::shared_ptr machine) override; UICanvas& GetGraphics() override; std::weak_ptr GetMachine() override; void Repaint(const QRect& rect) override; - void MoveInScreen(QPoint &&shift) override; - void Move(QPoint &&shift) override; + void MoveInScreen(QPoint&& shift) override; + void Move(QPoint&& shift) override; void SetMachine(std::shared_ptr machine) override; - //IVMTActionController + // IVMTActionController void SetAction(std::shared_ptr action) override; void EnableAnimation(bool enable) override; ~FormCompilerMachine(); -private slots: + private slots: void on_list_errors_currentRowChanged(int currentRow); -private: - Ui::FormCompilerMachine *ui; + private: + Ui::FormCompilerMachine* ui; std::vector _errors; void ClearErrors(); @@ -60,8 +63,6 @@ private slots: void CheckConnection(std::shared_ptr p_Machine); void CheckAllCases(std::shared_ptr p_Machine); void CheckDublicate(std::shared_ptr p_Machine); - - }; -#endif // FORMCOMPILERMACHINE_H +#endif // FORMCOMPILERMACHINE_H diff --git a/VirtualTuringMachine/formcomplexmachines.cpp b/VirtualTuringMachine/formcomplexmachines.cpp old mode 100755 new mode 100644 index 46cdbdb..d605282 --- a/VirtualTuringMachine/formcomplexmachines.cpp +++ b/VirtualTuringMachine/formcomplexmachines.cpp @@ -1,36 +1,34 @@ #include "formcomplexmachines.h" -#include "ui_formcomplexmachines.h" -#include "vmtproject.h" #include -#include #include +#include + #include "interfaces/IVMTAction.h" #include "interfaces/IVMTActionController.h" -#include "vmtactions/vmtactionmachine.h" #include "interfaces/IVMTMachine.h" +#include "ui_formcomplexmachines.h" +#include "vmtactions/vmtactionmachine.h" +#include "vmtproject.h" -FormComplexMachines::FormComplexMachines(IVMTActionController *controller, QWidget *parent,bool navi) : - QWidget(parent), - ui(new Ui::FormComplexMachines), - _controller(controller), - _navi(navi) -{ - +FormComplexMachines::FormComplexMachines(IVMTActionController* controller, + QWidget* parent, bool navi) + : QWidget(parent), + ui(new Ui::FormComplexMachines), + _controller(controller), + _navi(navi) { ui->setupUi(this); qDebug() << "FormComplexMachines::Begin Ctr"; - QHBoxLayout *layout = new QHBoxLayout; + QHBoxLayout* layout = new QHBoxLayout; ui->_frame->setLayout(layout); - layout->setContentsMargins(0,0,0,0); + layout->setContentsMargins(0, 0, 0, 0); _tools_group = std::shared_ptr(new QButtonGroup(ui->_frame)); - for(auto &m: VMTProject::GetInstance().GetMachines()){ - - - QPushButton *button = new QPushButton(); - QHBoxLayout *pLayout = new QHBoxLayout(); - QLabel *pTextLabel = new QLabel(); + for (auto& m : VMTProject::GetInstance().GetMachines()) { + QPushButton* button = new QPushButton(); + QHBoxLayout* pLayout = new QHBoxLayout(); + QLabel* pTextLabel = new QLabel(); button->setCheckable(true); @@ -39,36 +37,33 @@ FormComplexMachines::FormComplexMachines(IVMTActionController *controller, QWidg pTextLabel->setWordWrap(true); pTextLabel->setTextInteractionFlags(Qt::NoTextInteraction); pTextLabel->setMouseTracking(false); - pTextLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + pTextLabel->setSizePolicy(QSizePolicy::Expanding, + QSizePolicy::Expanding); button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); pLayout->addWidget(pTextLabel); pLayout->setSpacing(0); pLayout->setContentsMargins(5, 0, 5, 0); button->setLayout(pLayout); - button->setProperty("machine",QString(m->GetName())); - QObject::connect(button, SIGNAL(clicked()), - this, SLOT(on_complex_machine_clicked())); + button->setProperty("machine", QString(m->GetName())); + QObject::connect(button, SIGNAL(clicked()), this, + SLOT(on_complex_machine_clicked())); _tools_group->addButton(button); ui->_frame->layout()->addWidget(button); } qDebug() << "FormComplexMachines::End Ctr"; } -void FormComplexMachines::on_complex_machine_clicked(){ - QPushButton *button = dynamic_cast (sender()); - if(button) - { +void FormComplexMachines::on_complex_machine_clicked() { + QPushButton* button = dynamic_cast(sender()); + if (button) { QVariant var = button->property("machine"); QString name = var.toString(); auto machine = VMTProject::GetInstance().GetMachine(name); - if(machine){ - _controller->SetAction(std::shared_ptr(new VMTActionMachine(_controller,machine,_navi))); - + if (machine) { + _controller->SetAction(std::shared_ptr( + new VMTActionMachine(_controller, machine, _navi))); } } } -FormComplexMachines::~FormComplexMachines() -{ - delete ui; -} +FormComplexMachines::~FormComplexMachines() { delete ui; } diff --git a/VirtualTuringMachine/formcomplexmachines.h b/VirtualTuringMachine/formcomplexmachines.h old mode 100755 new mode 100644 index bcb7af6..566c1db --- a/VirtualTuringMachine/formcomplexmachines.h +++ b/VirtualTuringMachine/formcomplexmachines.h @@ -1,34 +1,32 @@ #ifndef FORMCOMPLEXMACHINES_H #define FORMCOMPLEXMACHINES_H -#include #include +#include #include class IVMTActionController; - namespace Ui { class FormComplexMachines; } -class FormComplexMachines : public QWidget -{ +class FormComplexMachines : public QWidget { Q_OBJECT -public: - explicit FormComplexMachines(IVMTActionController *controller, QWidget *parent,bool navi); + public: + explicit FormComplexMachines(IVMTActionController* controller, + QWidget* parent, bool navi); ~FormComplexMachines(); -private slots: + private slots: void on_complex_machine_clicked(); -private: - Ui::FormComplexMachines *ui; + private: + Ui::FormComplexMachines* ui; std::shared_ptr _tools_group; - IVMTActionController *_controller; + IVMTActionController* _controller; bool _navi; - }; -#endif // FORMCOMPLEXMACHINES_H +#endif // FORMCOMPLEXMACHINES_H diff --git a/VirtualTuringMachine/formdebugermachine.cpp b/VirtualTuringMachine/formdebugermachine.cpp old mode 100755 new mode 100644 index 5f87ffe..552929d --- a/VirtualTuringMachine/formdebugermachine.cpp +++ b/VirtualTuringMachine/formdebugermachine.cpp @@ -1,34 +1,34 @@ #include "formdebugermachine.h" -#include "vmticons.h" + +#include "configuration.h" +#include "screentools.h" #include "ui_formdebugermachine.h" -#include "vmtproject.h" #include "vmtactions/vmtactiontranslate.h" -#include "screentools.h" +#include "vmticons.h" +#include "vmtproject.h" #include "vmttheme.h" -#include "configuration.h" - -FormDebugerMachine::FormDebugerMachine(QWidget *parent) : - QWidget(parent), - ui(new Ui::FormDebugerMachine), - _current_test(0), - _debugger(VMTProject::GetInstance().GetAlphabit(),VMTProject::GetInstance().GetCurrentMachine()), - _model(nullptr) -{ +FormDebugerMachine::FormDebugerMachine(QWidget* parent) + : QWidget(parent), + ui(new Ui::FormDebugerMachine), + _current_test(0), + _debugger(VMTProject::GetInstance().GetAlphabit(), + VMTProject::GetInstance().GetCurrentMachine()), + _model(nullptr) { ui->setupUi(this); VmtTheme::polishWidgetTree(this); ui->widget_line->SetLine(_debugger.GetLine()); ui->widget_editor->SetEnvironment(this); - ui->widget_editor->SetComplexMachine( _debugger.GetComplexMachine()); + ui->widget_editor->SetComplexMachine(_debugger.GetComplexMachine()); ui->widget_editor->GetComplexMachine()->DeselectAll(); _stop = false; - if(VMTProject::GetInstance().IsTestMode()){ + if (VMTProject::GetInstance().IsTestMode()) { ui->widget_line->SetTestMode(); _model = createModel(); ui->_test_list->setModel(_model); - }else { + } else { ui->_tests_frame->setVisible(false); } @@ -38,20 +38,19 @@ FormDebugerMachine::FormDebugerMachine(QWidget *parent) : st.ResizeButton(ui->button_left_page); st.ResizeButton(ui->button_right); st.ResizeButton(ui->button_right_page); - } -QStandardItemModel *FormDebugerMachine::createModel() -{ - QStandardItemModel *model = new QStandardItemModel(); - QList listItem; +QStandardItemModel* FormDebugerMachine::createModel() { + QStandardItemModel* model = new QStandardItemModel(); + QList listItem; - if(VMTProject::GetInstance().GetExercise()){ - int i=1; - for([[maybe_unused]] auto &test : VMTProject::GetInstance().GetExercise()->GetTests()){ - QStandardItem *item = new QStandardItem(); + if (VMTProject::GetInstance().GetExercise()) { + int i = 1; + for ([[maybe_unused]] auto& test : + VMTProject::GetInstance().GetExercise()->GetTests()) { + QStandardItem* item = new QStandardItem(); QString text("Test "); - text+= QString::number(i++); + text += QString::number(i++); item->setText(text); listItem << item; } @@ -60,82 +59,83 @@ QStandardItemModel *FormDebugerMachine::createModel() return model; } -void FormDebugerMachine::BeforeChange(std::shared_ptr){ - -} +void FormDebugerMachine::BeforeChange(std::shared_ptr) {} -void FormDebugerMachine::AfterUndo(std::shared_ptr) { - -} +void FormDebugerMachine::AfterUndo(std::shared_ptr) {} -void FormDebugerMachine::ChangeZoom(int zoom){ +void FormDebugerMachine::ChangeZoom(int zoom) { ui->widget_editor->SetZoom(zoom); } -void FormDebugerMachine::EnableActionHint([[maybe_unused]] const QString &hint,[[maybe_unused]] QPixmap& img) {}; -void FormDebugerMachine::DisableActionHint(){}; -void FormDebugerMachine::DisableAlphabit(){} +void FormDebugerMachine::EnableActionHint([[maybe_unused]] const QString& hint, + [[maybe_unused]] QPixmap& img) {}; +void FormDebugerMachine::DisableActionHint() {}; +void FormDebugerMachine::DisableAlphabit() {} void FormDebugerMachine::DisableCalculator() {} -void FormDebugerMachine::EnableAlphabit([[maybe_unused]] IVMTAlphabitSource* ,[[maybe_unused]] const QString& ,QPixmap &){} -void FormDebugerMachine::EnableCalculator([[maybe_unused]] std::shared_ptr ){} -void FormDebugerMachine::EnableAnimation([[maybe_unused]] bool enable){}; +void FormDebugerMachine::EnableAlphabit([[maybe_unused]] IVMTAlphabitSource*, + [[maybe_unused]] const QString&, + QPixmap&) {} +void FormDebugerMachine::EnableCalculator( + [[maybe_unused]] std::shared_ptr) {} +void FormDebugerMachine::EnableAnimation([[maybe_unused]] bool enable) {}; -UICanvas& FormDebugerMachine::GetGraphics(){ - return ui->widget_editor->GetCanvas(); +UICanvas& FormDebugerMachine::GetGraphics() { + return ui->widget_editor->GetCanvas(); } -std::weak_ptr FormDebugerMachine::GetMachine(){ - return std::weak_ptr(ui->widget_editor->GetComplexMachine()); +std::weak_ptr FormDebugerMachine::GetMachine() { + return std::weak_ptr( + ui->widget_editor->GetComplexMachine()); } -void FormDebugerMachine::Repaint([[maybe_unused]] const QRect& rect){ +void FormDebugerMachine::Repaint([[maybe_unused]] const QRect& rect) { ui->widget_editor->update(); } -void FormDebugerMachine::MoveInScreen(QPoint &&shift){ +void FormDebugerMachine::MoveInScreen(QPoint&& shift) { ui->widget_editor->GetCanvas().MoveInScreen(shift); } -void FormDebugerMachine::Move(QPoint &&shift){ +void FormDebugerMachine::Move(QPoint&& shift) { ui->widget_editor->GetCanvas().Move(shift); } -void FormDebugerMachine::SetMachine(std::shared_ptr machine){ +void FormDebugerMachine::SetMachine( + std::shared_ptr machine) { ui->widget_editor->SetComplexMachine(machine); ui->widget_editor->update(); } -void FormDebugerMachine::OnLoaded(){ +void FormDebugerMachine::OnLoaded() { SetAction(std::shared_ptr(new VMTActionTranslate(this))); } -void FormDebugerMachine::SetAction(std::shared_ptr action){ - if(ui->widget_editor->GetAction()) ui->widget_editor->GetAction()->Cancel(this); +void FormDebugerMachine::SetAction(std::shared_ptr action) { + if (ui->widget_editor->GetAction()) + ui->widget_editor->GetAction()->Cancel(this); ui->widget_editor->GetAction() = action; - if(ui->widget_editor->GetAction()) ui->widget_editor->GetAction()->Enable(this); + if (ui->widget_editor->GetAction()) + ui->widget_editor->GetAction()->Enable(this); } -FormDebugerMachine::~FormDebugerMachine() -{ - delete ui; -} +FormDebugerMachine::~FormDebugerMachine() { delete ui; } -void FormDebugerMachine::StartExercise(){ +void FormDebugerMachine::StartExercise() { _debugger.ToStart(this); _stop = false; _current_test = 0; PrepareTest(); - } -void FormDebugerMachine::PrepareTest(){ - if(VMTProject::GetInstance().GetExercise()){ +void FormDebugerMachine::PrepareTest() { + if (VMTProject::GetInstance().GetExercise()) { std::shared_ptr ex = VMTProject::GetInstance().GetExercise(); - if(_current_test(ex->GetTests().size())){ - std::shared_ptr ex = VMTProject::GetInstance().GetExercise(); + if (_current_test < static_cast(ex->GetTests().size())) { + std::shared_ptr ex = + VMTProject::GetInstance().GetExercise(); auto test = ex->GetTests().at(_current_test); - for(QChar &ch: test.first){ + for (QChar& ch : test.first) { _debugger.GetLine()->SetSignAtMachine(ch.toLatin1()); _debugger.GetLine()->ShiftRight(); } @@ -150,29 +150,33 @@ void FormDebugerMachine::PrepareTest(){ } } -void FormDebugerMachine::CheckTest(){ - if(VMTProject::GetInstance().GetExercise()){ +void FormDebugerMachine::CheckTest() { + if (VMTProject::GetInstance().GetExercise()) { std::shared_ptr ex = VMTProject::GetInstance().GetExercise(); - if(_current_test(ex->GetTests().size())){ - std::shared_ptr ex = VMTProject::GetInstance().GetExercise(); + if (_current_test < static_cast(ex->GetTests().size())) { + std::shared_ptr ex = + VMTProject::GetInstance().GetExercise(); auto test = ex->GetTests().at(_current_test); int length = test.second.length(); - for(int i=0;iShiftLeft(); + for (int i = 0; i < length; i++) _debugger.GetLine()->ShiftLeft(); - bool ok=true; - for(QChar &ch: test.second){ - if(_debugger.GetLine()->GetValueAtMachine()!=ch.toLatin1()) ok=false; + bool ok = true; + for (QChar& ch : test.second) { + if (_debugger.GetLine()->GetValueAtMachine() != ch.toLatin1()) + ok = false; _debugger.GetLine()->ShiftRight(); } - if(ok) { - _model->item(_current_test)->setIcon(QIcon(VmtIcons::okPixmap())); + if (ok) { + _model->item(_current_test) + ->setIcon(QIcon(VmtIcons::okPixmap())); _debugger.GetLine()->Clear(); _current_test++; _debugger.ToStart(this); PrepareTest(); - } else { - _model->item(_current_test)->setIcon(QIcon(VmtIcons::cancelPixmap())); + } else { + _model->item(_current_test) + ->setIcon(QIcon(VmtIcons::cancelPixmap())); QMessageBox box; box.setText("Test failed"); @@ -182,7 +186,7 @@ void FormDebugerMachine::CheckTest(){ } } -void FormDebugerMachine::Run(){ +void FormDebugerMachine::Run() { _controller->EnableDebugStep(false); _controller->EnableDebugRun(false); _controller->EnableDebugStop(true); @@ -191,48 +195,38 @@ void FormDebugerMachine::Run(){ RunTimer(); } -void FormDebugerMachine::RunTimer(){ - if((!_debugger.IsFinish())&&(!_stop)){ +void FormDebugerMachine::RunTimer() { + if ((!_debugger.IsFinish()) && (!_stop)) { Step(); - _timer.singleShot(50,this,SLOT(RunTimer())); - } else{ - _stop=false; + _timer.singleShot(50, this, SLOT(RunTimer())); + } else { + _stop = false; _controller->EnableDebugStep(true); _controller->EnableDebugRun(true); _controller->EnableDebugStop(false); //_debugger.ToStart(this); - if(VMTProject::GetInstance().IsTestMode()){ + if (VMTProject::GetInstance().IsTestMode()) { CheckTest(); } } } -void FormDebugerMachine::Stop(){ - _stop = true; -} +void FormDebugerMachine::Stop() { _stop = true; } -void FormDebugerMachine::Step(){ +void FormDebugerMachine::Step() { _debugger.Step(this); ui->widget_line->Repaint(); } -void FormDebugerMachine::on_button_left_page_clicked() -{ +void FormDebugerMachine::on_button_left_page_clicked() { ui->widget_line->LeftPage(); } -void FormDebugerMachine::on_button_left_clicked() -{ - ui->widget_line->Left(); -} +void FormDebugerMachine::on_button_left_clicked() { ui->widget_line->Left(); } -void FormDebugerMachine::on_button_right_clicked() -{ - ui->widget_line->Right(); -} +void FormDebugerMachine::on_button_right_clicked() { ui->widget_line->Right(); } -void FormDebugerMachine::on_button_right_page_clicked() -{ +void FormDebugerMachine::on_button_right_page_clicked() { ui->widget_line->RightPage(); } diff --git a/VirtualTuringMachine/formdebugermachine.h b/VirtualTuringMachine/formdebugermachine.h old mode 100755 new mode 100644 index cfccbb5..b0ee27f --- a/VirtualTuringMachine/formdebugermachine.h +++ b/VirtualTuringMachine/formdebugermachine.h @@ -1,27 +1,29 @@ #ifndef FORMDEBUGERMACHINE_H #define FORMDEBUGERMACHINE_H -#include -#include -#include "formbase.h" -#include "vmtdebuger.h" -#include "interfaces/IVMTEnvironment.h" -#include "interfaces/IVMTActionController.h" - #include #include #include +#include +#include + +#include "formbase.h" +#include "interfaces/IVMTActionController.h" +#include "interfaces/IVMTEnvironment.h" +#include "vmtdebuger.h" namespace Ui { class FormDebugerMachine; } -class FormDebugerMachine : public QWidget , public FormBase, public IVMTEnvironment, public IVMTActionController -{ +class FormDebugerMachine : public QWidget, + public FormBase, + public IVMTEnvironment, + public IVMTActionController { Q_OBJECT -public: - explicit FormDebugerMachine(QWidget *parent = 0); + public: + explicit FormDebugerMachine(QWidget* parent = 0); void BeforeChange(std::shared_ptr state_data) override; void AfterUndo(std::shared_ptr state_data) override; void OnLoaded() override; @@ -32,45 +34,46 @@ class FormDebugerMachine : public QWidget , public FormBase, public IVMTEnvironm void StartExercise(); // IVMTEnvironment - void EnableActionHint(const QString &hint,QPixmap& img) override; + void EnableActionHint(const QString& hint, QPixmap& img) override; void DisableActionHint() override; void DisableAlphabit() override; void DisableCalculator() override; - void EnableAlphabit(IVMTAlphabitSource* p_Alphabit,const QString& msg,QPixmap &img) override; + void EnableAlphabit(IVMTAlphabitSource* p_Alphabit, const QString& msg, + QPixmap& img) override; void EnableCalculator(std::shared_ptr machine) override; UICanvas& GetGraphics() override; std::weak_ptr GetMachine() override; void Repaint(const QRect& rect) override; - void MoveInScreen(QPoint &&shift) override; - void Move(QPoint &&shift) override; + void MoveInScreen(QPoint&& shift) override; + void Move(QPoint&& shift) override; void SetMachine(std::shared_ptr machine) override; void EnableAnimation(bool enable) override; - //IVMTActionController + // IVMTActionController void SetAction(std::shared_ptr action) override; ~FormDebugerMachine(); -public slots: - void RunTimer(); + public slots: + void RunTimer(); -private slots: + private slots: void on_button_left_page_clicked(); void on_button_left_clicked(); void on_button_right_clicked(); void on_button_right_page_clicked(); -private: - Ui::FormDebugerMachine *ui; + + private: + Ui::FormDebugerMachine* ui; bool _stop; QTimer _timer; int _current_test; VMTDebuger _debugger; - QStandardItemModel *_model; - QStandardItemModel *createModel(); + QStandardItemModel* _model; + QStandardItemModel* createModel(); void PrepareTest(); void CheckTest(); - }; -#endif // FORMDEBUGERMACHINE_H +#endif // FORMDEBUGERMACHINE_H diff --git a/VirtualTuringMachine/formeditormachine.cpp b/VirtualTuringMachine/formeditormachine.cpp old mode 100755 new mode 100644 index 7bf5411..6136757 --- a/VirtualTuringMachine/formeditormachine.cpp +++ b/VirtualTuringMachine/formeditormachine.cpp @@ -1,66 +1,65 @@ #include "formeditormachine.h" -#include "vmticons.h" -#include "ui_formeditormachine.h" -#include "uistateeditormachine.h" -#include "vmtproject.h" -#include "vmtactions/vmtactiontranslate.h" -#include "vmtactions/vmtactiondelete.h" -#include "vmtactions/vmtactionpointer.h" -#include "vmtactions/vmtactionmachine.h" -#include "vmtactions/vmtactionlink.h" -#include "vmtactions/vmtactioncreateandconnect.h" -#include "vmtmachines/VMTMachineStub.h" -#include "vmtmachines/VMTComplexMachine.h" -#include "formactionhint.h" -#include "formalphabit.h" +#include #include #include #include #include +#include +#include #include + +#include "formactionhint.h" +#include "formalphabit.h" #include "screentools.h" -#include "vmttheme.h" +#include "ui_formeditormachine.h" +#include "uistateeditormachine.h" +#include "vmtactions/vmtactioncreateandconnect.h" +#include "vmtactions/vmtactiondelete.h" +#include "vmtactions/vmtactionlink.h" +#include "vmtactions/vmtactionmachine.h" +#include "vmtactions/vmtactionpointer.h" +#include "vmtactions/vmtactiontranslate.h" #include "vmtexportplantuml/vmtexportplantuml.h" -#include -#include -#include +#include "vmticons.h" +#include "vmtmachines/VMTComplexMachine.h" +#include "vmtmachines/VMTMachineStub.h" +#include "vmtproject.h" +#include "vmttheme.h" -FormEditorMachine::FormEditorMachine(QWidget *parent) : - QWidget(parent), - ui(new Ui::FormEditorMachine), - _form_alphabit(nullptr), - _form_calculator(nullptr), - _form_complex_machines(nullptr), - _form_action_hint(nullptr) -{ +FormEditorMachine::FormEditorMachine(QWidget* parent) + : QWidget(parent), + ui(new Ui::FormEditorMachine), + _form_alphabit(nullptr), + _form_calculator(nullptr), + _form_complex_machines(nullptr), + _form_action_hint(nullptr) { qDebug() << "FormEditorMachine::Constructor"; ui->setupUi(this); VmtTheme::polishWidgetTree(this); - QString machine_name = VMTProject::GetInstance().GetCurrentMachineName(); ui->widget_editor->SetEnvironment(this); - //* - - - - - ui->widget_editor->SetComplexMachine(VMTProject::GetInstance().GetMachine(machine_name)); + //* + ui->widget_editor->SetComplexMachine( + VMTProject::GetInstance().GetMachine(machine_name)); /*/ - std::shared_ptr left_word = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_COPY,VMTProject::GetInstance().GetMachine(machine_name)); - std::shared_ptr complex_stub = left_word->CreateComplexMachine(this); - std::shared_ptr complex_machine= VMTProject::GetInstance().GetMachine(machine_name); + std::shared_ptr left_word = + VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_COPY,VMTProject::GetInstance().GetMachine(machine_name)); + std::shared_ptr complex_stub = + left_word->CreateComplexMachine(this); std::shared_ptr + complex_machine= VMTProject::GetInstance().GetMachine(machine_name); complex_machine->SetInnerObject(std::dynamic_pointer_cast(complex_stub)->GetInnerObject(),complex_machine); ui->widget_editor->SetComplexMachine(complex_machine); //*/ ui->widget_editor->GetComplexMachine()->DeselectAll(); - _tools_group = std::shared_ptr(new QButtonGroup(ui->tool_frame)); + _tools_group = + std::shared_ptr(new QButtonGroup(ui->tool_frame)); _tools_group->addButton(ui->tool_link); _tools_group->addButton(ui->tool_machine_copy); _tools_group->addButton(ui->tool_machine_finish); @@ -79,7 +78,6 @@ FormEditorMachine::FormEditorMachine(QWidget *parent) : VmtTheme::applyIconToolBar(ui->tool_frame); VmtTheme::applyIconToolBar(ui->frame_navi); - ui->_navi->setCheckable(true); ui->_navi->setChecked(false); @@ -103,34 +101,32 @@ FormEditorMachine::FormEditorMachine(QWidget *parent) : ui->properties_frame->setHidden(true); st.ResizePropertyPanel(ui->properties_frame); - - //ui->properies_splitter->setStretchFactor(0,3); - //ui->properies_splitter->setStretchFactor(1,1); - + // ui->properies_splitter->setStretchFactor(0,3); + // ui->properies_splitter->setStretchFactor(1,1); } - -void FormEditorMachine::Run(){ +void FormEditorMachine::Run() { VMTProject::GetInstance().SetTestMode(false); - _controller->ChangeState( - std::shared_ptr(new UIStateCompilerMachineData())); + _controller->ChangeState(std::shared_ptr( + new UIStateCompilerMachineData())); } -void FormEditorMachine::Exercise(){ +void FormEditorMachine::Exercise() { VMTProject::GetInstance().SetTestMode(true); - _controller->ChangeState( - std::shared_ptr(new UIStateCompilerMachineData())); -} - -void FormEditorMachine::Undo(){ - if(auto ptr = GetMachine().lock()){ - if(VMTProject::GetInstance().GetUndoManager()->Recall(this)) - { - QString machine_name = VMTProject::GetInstance().GetCurrentMachineName(); - ui->widget_editor->SetComplexMachine(VMTProject::GetInstance().GetMachine(machine_name)); - if(ui->widget_editor->GetAction()){ + _controller->ChangeState(std::shared_ptr( + new UIStateCompilerMachineData())); +} + +void FormEditorMachine::Undo() { + if (auto ptr = GetMachine().lock()) { + if (VMTProject::GetInstance().GetUndoManager()->Recall(this)) { + QString machine_name = + VMTProject::GetInstance().GetCurrentMachineName(); + ui->widget_editor->SetComplexMachine( + VMTProject::GetInstance().GetMachine(machine_name)); + if (ui->widget_editor->GetAction()) { ui->widget_editor->GetAction()->Cancel(this); ui->widget_editor->GetAction().reset(); - if( _tools_group->checkedButton()){ + if (_tools_group->checkedButton()) { _tools_group->setExclusive(false); _tools_group->checkedButton()->setChecked(false); _tools_group->setExclusive(true); @@ -139,65 +135,68 @@ void FormEditorMachine::Undo(){ this->Repaint(QRect()); } } - } -void FormEditorMachine::OnKeyPressed(QKeyEvent* event){ - if(event->key() == Qt::Key_Escape){ - this->SetAction(std::shared_ptr(new VMTActionPointer(this,ui->_navi->isChecked()))); - } else if(event->key() == Qt::Key_Space){ - if(!_action_space){ - _action_space = ui->widget_editor->GetAction(); - SetAction(std::shared_ptr(new VMTActionTranslate(this))); - } - } +void FormEditorMachine::OnKeyPressed(QKeyEvent* event) { + if (event->key() == Qt::Key_Escape) { + this->SetAction(std::shared_ptr( + new VMTActionPointer(this, ui->_navi->isChecked()))); + } else if (event->key() == Qt::Key_Space) { + if (!_action_space) { + _action_space = ui->widget_editor->GetAction(); + SetAction( + std::shared_ptr(new VMTActionTranslate(this))); + } + } } -void FormEditorMachine::OnKeyReleased(QKeyEvent* event){ - if(event->key() == Qt::Key_Space){ - if(_action_space){ - SetAction(std::shared_ptr(_action_space)); - _action_space = nullptr; - } - } +void FormEditorMachine::OnKeyReleased(QKeyEvent* event) { + if (event->key() == Qt::Key_Space) { + if (_action_space) { + SetAction(std::shared_ptr(_action_space)); + _action_space = nullptr; + } + } } -void FormEditorMachine::ExportMachine(){ +void FormEditorMachine::ExportMachine() { QFileDialog dlg; dlg.setWindowTitle("Export Turing Machine Image"); dlg.setAcceptMode(QFileDialog::AcceptSave); - //dlg.setLabelText(QFileDialog::LookIn,"OPEN"); + // dlg.setLabelText(QFileDialog::LookIn,"OPEN"); dlg.setFileMode(QFileDialog::AnyFile); dlg.setViewMode(QFileDialog::List); QStringList filters; - filters <<"PNG (*.png)"; - dlg.setOption(QFileDialog::HideNameFilterDetails,false); + filters << "PNG (*.png)"; + dlg.setOption(QFileDialog::HideNameFilterDetails, false); dlg.setNameFilters(filters); dlg.resize(QApplication::primaryScreen()->availableSize()); - if(dlg.exec()==QDialog::Accepted) - { - //QString file = QFileDialog::getSaveFileName(this,"Export to PNG",VMTProject::GetInstance().GetLocation(),QString("png")); - QStringList fileName=dlg.selectedFiles(); - if(fileName.length()>0) - { + if (dlg.exec() == QDialog::Accepted) { + // QString file = QFileDialog::getSaveFileName(this,"Export to + // PNG",VMTProject::GetInstance().GetLocation(),QString("png")); + QStringList fileName = dlg.selectedFiles(); + if (fileName.length() > 0) { QString file = fileName[0]; - if(file.length()>0){ - if(!ui->widget_editor->GetComplexMachine()) qDebug() << "WTF!"; - QRect rect = ui->widget_editor->GetComplexMachine()->GetBoundsWithChilds(); - - - rect.setLeft(rect.left()-20); - rect.setTop(rect.top()-20); - rect.setWidth(rect.width()+40); - rect.setHeight(rect.height()+40); - - QImage image(QSize(rect.width(),rect.height()), QImage::Format_ARGB32); + if (file.length() > 0) { + if (!ui->widget_editor->GetComplexMachine()) qDebug() << "WTF!"; + QRect rect = ui->widget_editor->GetComplexMachine() + ->GetBoundsWithChilds(); + + rect.setLeft(rect.left() - 20); + rect.setTop(rect.top() - 20); + rect.setWidth(rect.width() + 40); + rect.setHeight(rect.height() + 40); + + QImage image(QSize(rect.width(), rect.height()), + QImage::Format_ARGB32); QPainter painter; - painter.begin(&image); // Here is the error. See below - ScreenTools st; + painter.begin(&image); // Here is the error. See below + ScreenTools st; UICanvas canvas(QBrush(VmtTheme::diagramBackground()), - QPen(VmtTheme::diagramGrid(), 1, Qt::DotLine, Qt::RoundCap, Qt::RoundJoin), - QPen(VmtTheme::diagramLine()), st.GetCellSize(), st.GetFontSize()); + QPen(VmtTheme::diagramGrid(), 1, Qt::DotLine, + Qt::RoundCap, Qt::RoundJoin), + QPen(VmtTheme::diagramLine()), st.GetCellSize(), + st.GetFontSize()); canvas.SetPainter(&painter); @@ -207,35 +206,33 @@ void FormEditorMachine::ExportMachine(){ p.setY(-p.y()); canvas.MoveInScreen(p); - - //QRect area = canvas.ToScreen(ui->widget_editor->GetComplexMachine()->GetBoundsWithChilds()); - //rect.setWidth(rect.width()-rect.left()); - //rect.setHeight(rect.height()-rect.top()); + // QRect area = + // canvas.ToScreen(ui->widget_editor->GetComplexMachine()->GetBoundsWithChilds()); + // rect.setWidth(rect.width()-rect.left()); + // rect.setHeight(rect.height()-rect.top()); rect.moveLeft(0); rect.moveTop(0); qDebug() << rect; - ui->widget_editor->Paint(canvas,rect); + ui->widget_editor->Paint(canvas, rect); painter.end(); - if(file.indexOf(".png")!=file.length()-4) file.append(".png"); - QImageWriter imageWriter(file,"png"); + if (file.indexOf(".png") != file.length() - 4) + file.append(".png"); + QImageWriter imageWriter(file, "png"); - - if(!imageWriter.write( image )) - { + if (!imageWriter.write(image)) { QString msg; - msg.append("Error create file: " ); + msg.append("Error create file: "); msg.append(imageWriter.errorString()); - QMessageBox::question( nullptr,"VMT",msg,QMessageBox::Ok,QMessageBox::Ok); + QMessageBox::question(nullptr, "VMT", msg, QMessageBox::Ok, + QMessageBox::Ok); } - } } } } -void FormEditorMachine::ExportPlantUml() -{ +void FormEditorMachine::ExportPlantUml() { auto machine = ui->widget_editor->GetComplexMachine(); if (!machine) { return; @@ -246,7 +243,8 @@ void FormEditorMachine::ExportPlantUml() dlg.setAcceptMode(QFileDialog::AcceptSave); dlg.setFileMode(QFileDialog::AnyFile); dlg.setViewMode(QFileDialog::List); - dlg.setNameFilters(QStringList() << tr("PlantUML (*.puml)") << tr("All files (*)")); + dlg.setNameFilters(QStringList() + << tr("PlantUML (*.puml)") << tr("All files (*)")); dlg.setOption(QFileDialog::HideNameFilterDetails, false); dlg.resize(QApplication::primaryScreen()->availableSize()); @@ -267,60 +265,56 @@ void FormEditorMachine::ExportPlantUml() const QString content = VmtExportPlantUml::exportStateMachine(*machine); QFile file(filePath); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - QMessageBox::warning(this, - tr("VMT"), - tr("Cannot write file: %1").arg(file.errorString())); + QMessageBox::warning( + this, tr("VMT"), + tr("Cannot write file: %1").arg(file.errorString())); return; } if (file.write(content.toUtf8()) < 0) { - QMessageBox::warning(this, - tr("VMT"), - tr("Cannot write file: %1").arg(file.errorString())); + QMessageBox::warning( + this, tr("VMT"), + tr("Cannot write file: %1").arg(file.errorString())); return; } file.close(); } -void FormEditorMachine::BeforeChange(std::shared_ptr state_data){ - UIStateEditorMachineData *data = dynamic_cast(state_data.get()); - if(data){ - //data->_machine = ui->widget_editor->GetComplexMachine(); +void FormEditorMachine::BeforeChange(std::shared_ptr state_data) { + UIStateEditorMachineData* data = + dynamic_cast(state_data.get()); + if (data) { + // data->_machine = ui->widget_editor->GetComplexMachine(); } } void FormEditorMachine::AfterUndo(std::shared_ptr state_data) { - UIStateEditorMachineData *data = dynamic_cast(state_data.get()); - if(data){ - //ui->widget_editor->GetComplexMachine() = data->_machine; + UIStateEditorMachineData* data = + dynamic_cast(state_data.get()); + if (data) { + // ui->widget_editor->GetComplexMachine() = data->_machine; } } -FormEditorMachine::~FormEditorMachine() -{ - delete ui; -} +FormEditorMachine::~FormEditorMachine() { delete ui; } -void FormEditorMachine::ChangeZoom(size_t zoom){ +void FormEditorMachine::ChangeZoom(size_t zoom) { ui->widget_editor->SetZoom(zoom); } -void FormEditorMachine::keyPressEvent (QKeyEvent* event) { - -if (event->key () == Qt::Key_Escape) { - SetAction(std::shared_ptr(new VMTActionPointer(this,ui->_navi->isChecked()))); - ui->tool_pointer->setChecked(true); - } - - +void FormEditorMachine::keyPressEvent(QKeyEvent* event) { + if (event->key() == Qt::Key_Escape) { + SetAction(std::shared_ptr( + new VMTActionPointer(this, ui->_navi->isChecked()))); + ui->tool_pointer->setChecked(true); + } } // IVMTEnvironment -void FormEditorMachine::DisableAlphabit(){ - if(_form_alphabit) - { +void FormEditorMachine::DisableAlphabit() { + if (_form_alphabit) { ui->properties->layout()->removeWidget(_form_alphabit); delete _form_alphabit; _form_alphabit = nullptr; @@ -328,9 +322,8 @@ void FormEditorMachine::DisableAlphabit(){ ui->properties_frame->setHidden(true); } -void FormEditorMachine::DisableCalculator(){ - if(_form_calculator) - { +void FormEditorMachine::DisableCalculator() { + if (_form_calculator) { ui->properties->layout()->removeWidget(_form_calculator); delete _form_calculator; _form_calculator = nullptr; @@ -338,119 +331,115 @@ void FormEditorMachine::DisableCalculator(){ ui->properties_frame->setHidden(true); } - -void FormEditorMachine::EnableAlphabit(IVMTAlphabitSource* alphabit,const QString& msg,QPixmap &img){ +void FormEditorMachine::EnableAlphabit(IVMTAlphabitSource* alphabit, + const QString& msg, QPixmap& img) { ScreenTools st; - if(_form_alphabit) DisableAlphabit(); - if(!ui->properties->layout()) ui->properties->setLayout(new QHBoxLayout()); - ui->properties->layout()->setContentsMargins(0,0,0,0); - ui->properties->layout()->addWidget(_form_alphabit = new FormAlphabit(alphabit,this,ui->properties)); + if (_form_alphabit) DisableAlphabit(); + if (!ui->properties->layout()) ui->properties->setLayout(new QHBoxLayout()); + ui->properties->layout()->setContentsMargins(0, 0, 0, 0); + ui->properties->layout()->addWidget( + _form_alphabit = new FormAlphabit(alphabit, this, ui->properties)); ui->label_title->setText(msg); - ui->label_image->setPixmap(img.scaled(st.GetImageSize(),Qt::KeepAspectRatio, Qt::SmoothTransformation)); + ui->label_image->setPixmap(img.scaled( + st.GetImageSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); ui->label_image->setText(""); ui->properties_frame->setHidden(false); } -void FormEditorMachine::EnableCalculator(std::shared_ptr machine){ +void FormEditorMachine::EnableCalculator(std::shared_ptr machine) { ScreenTools st; - if(_form_calculator) DisableCalculator(); - if(!ui->properties->layout()) ui->properties->setLayout(new QHBoxLayout()); - ui->properties->layout()->setContentsMargins(0,0,0,0); - ui->properties->layout()->addWidget(_form_calculator = new FormCalculator(machine,this,ui->properties)); - //ui->label_image->setPixmap(*GetGraphics().GetImage(machine->GetImageType())); - ui->label_image->setPixmap(GetGraphics().GetImage(machine->GetImageType())->scaled(st.GetImageSize(),Qt::KeepAspectRatio, Qt::SmoothTransformation)); + if (_form_calculator) DisableCalculator(); + if (!ui->properties->layout()) ui->properties->setLayout(new QHBoxLayout()); + ui->properties->layout()->setContentsMargins(0, 0, 0, 0); + ui->properties->layout()->addWidget( + _form_calculator = new FormCalculator(machine, this, ui->properties)); + // ui->label_image->setPixmap(*GetGraphics().GetImage(machine->GetImageType())); + ui->label_image->setPixmap(GetGraphics() + .GetImage(machine->GetImageType()) + ->scaled(st.GetImageSize(), + Qt::KeepAspectRatio, + Qt::SmoothTransformation)); ui->label_title->setText("Select machine power"); ui->properties_frame->setHidden(false); } - - -UICanvas& FormEditorMachine::GetGraphics(){ - return ui->widget_editor->GetCanvas(); +UICanvas& FormEditorMachine::GetGraphics() { + return ui->widget_editor->GetCanvas(); } - - -std::weak_ptr FormEditorMachine::GetMachine(){ - return std::weak_ptr(ui->widget_editor->GetComplexMachine()); +std::weak_ptr FormEditorMachine::GetMachine() { + return std::weak_ptr( + ui->widget_editor->GetComplexMachine()); } -void FormEditorMachine::SetMachine(std::shared_ptr machine){ +void FormEditorMachine::SetMachine(std::shared_ptr machine) { ui->widget_editor->SetComplexMachine(machine); } -void FormEditorMachine::Repaint(const QRect& rect){ +void FormEditorMachine::Repaint(const QRect& rect) { ui->widget_editor->Repaint(rect); } -void FormEditorMachine::RepaintThrottled(const QRect& rect) -{ +void FormEditorMachine::RepaintThrottled(const QRect& rect) { ui->widget_editor->RepaintThrottled(rect); } -bool FormEditorMachine::deferTransitionRouting() const -{ +bool FormEditorMachine::deferTransitionRouting() const { return _deferTransitionRouting; } -void FormEditorMachine::setDeferTransitionRouting(bool defer) -{ +void FormEditorMachine::setDeferTransitionRouting(bool defer) { _deferTransitionRouting = defer; } - -void FormEditorMachine::MoveInScreen(QPoint &&shift){ +void FormEditorMachine::MoveInScreen(QPoint&& shift) { ui->widget_editor->GetCanvas().MoveInScreen(shift); } -void FormEditorMachine::Move(QPoint &&shift){ +void FormEditorMachine::Move(QPoint&& shift) { ui->widget_editor->GetCanvas().Move(shift); } - -void FormEditorMachine::SetAction(std::shared_ptr action){ +void FormEditorMachine::SetAction(std::shared_ptr action) { DisableFormComplexMachines(); - if(ui->widget_editor->GetAction()) ui->widget_editor->GetAction()->Cancel(this); + if (ui->widget_editor->GetAction()) + ui->widget_editor->GetAction()->Cancel(this); ui->widget_editor->GetAction() = action; - if(action){ - if(dynamic_cast(action.get())){ + if (action) { + if (dynamic_cast(action.get())) { ui->tool_link->setChecked(true); - } else - if(dynamic_cast(action.get())){ - ui->tool_pointer->setChecked(true); - } else - if(dynamic_cast(action.get())){ - ui->tool_pointer->setChecked(true); - } - - + } else if (dynamic_cast(action.get())) { + ui->tool_pointer->setChecked(true); + } else if (dynamic_cast(action.get())) { + ui->tool_pointer->setChecked(true); + } } - if(ui->widget_editor->GetAction()) ui->widget_editor->GetAction()->Enable(this); + if (ui->widget_editor->GetAction()) + ui->widget_editor->GetAction()->Enable(this); } -void FormEditorMachine::on_tool_pointer_clicked() -{ - SetAction(std::shared_ptr(new VMTActionPointer(this,ui->_navi->isChecked()))); +void FormEditorMachine::on_tool_pointer_clicked() { + SetAction(std::shared_ptr( + new VMTActionPointer(this, ui->_navi->isChecked()))); } -void FormEditorMachine::on_tool_link_clicked() -{ +void FormEditorMachine::on_tool_link_clicked() { SetAction(std::shared_ptr(new VMTActionLink(this))); } +void FormEditorMachine::on_tool_translate_clicked() { + static std::chrono::high_resolution_clock::time_point last = + std::chrono::high_resolution_clock::now(); + std::chrono::high_resolution_clock::time_point ct = + std::chrono::high_resolution_clock::now(); -void FormEditorMachine::on_tool_translate_clicked() -{ - - static std::chrono::high_resolution_clock::time_point last = std::chrono::high_resolution_clock::now(); - std::chrono::high_resolution_clock::time_point ct = std::chrono::high_resolution_clock::now(); - - if(std::chrono::duration_cast(ct-last).count()>0) - if(std::chrono::duration_cast(ct-last).count()<1000) - { + if (std::chrono::duration_cast(ct - last) + .count() > 0) + if (std::chrono::duration_cast(ct - last) + .count() < 1000) { ui->widget_editor->Center(); } @@ -459,89 +448,88 @@ void FormEditorMachine::on_tool_translate_clicked() SetAction(std::shared_ptr(new VMTActionTranslate(this))); } -void FormEditorMachine::on_tool_trash_clicked() -{ +void FormEditorMachine::on_tool_trash_clicked() { SetAction(std::shared_ptr(new VMTActionDelete(this))); } -void FormEditorMachine::on_tool_machine_start_clicked() -{ - SetAction(std::shared_ptr(new VMTActionMachine(this, - VMTMachineStub::CreateMachineByID( - IVMTMachine::MachineType::MT_START, - this->GetMachine()),ui->_navi->isChecked()))); +void FormEditorMachine::on_tool_machine_start_clicked() { + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_START, + this->GetMachine()), + ui->_navi->isChecked()))); } -void FormEditorMachine::on_tool_machine_lambda_clicked() -{ - SetAction(std::shared_ptr(new VMTActionMachine(this, - VMTMachineStub::CreateMachineByID( - IVMTMachine::MachineType::MT_WRITE, - this->GetMachine()),ui->_navi->isChecked()))); +void FormEditorMachine::on_tool_machine_lambda_clicked() { + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_WRITE, + this->GetMachine()), + ui->_navi->isChecked()))); } -void FormEditorMachine::on_tool_machine_finish_clicked() -{ - SetAction(std::shared_ptr(new VMTActionMachine(this, - VMTMachineStub::CreateMachineByID( - IVMTMachine::MachineType::MT_FINISH, - this->GetMachine()),ui->_navi->isChecked()))); +void FormEditorMachine::on_tool_machine_finish_clicked() { + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_FINISH, + this->GetMachine()), + ui->_navi->isChecked()))); } -void FormEditorMachine::on_tool_machine_left_clicked() -{ - SetAction(std::shared_ptr(new VMTActionMachine(this, - VMTMachineStub::CreateMachineByID( - IVMTMachine::MachineType::MT_LEFT, - this->GetMachine()),ui->_navi->isChecked()))); +void FormEditorMachine::on_tool_machine_left_clicked() { + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_LEFT, + this->GetMachine()), + ui->_navi->isChecked()))); } -void FormEditorMachine::on_tool_machine_right_clicked() -{ - SetAction(std::shared_ptr(new VMTActionMachine(this, - VMTMachineStub::CreateMachineByID( - IVMTMachine::MachineType::MT_RIGHT, - this->GetMachine()),ui->_navi->isChecked()))); +void FormEditorMachine::on_tool_machine_right_clicked() { + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_RIGHT, + this->GetMachine()), + ui->_navi->isChecked()))); } -void FormEditorMachine::on_tool_machine_left_word_clicked() -{ - SetAction(std::shared_ptr(new VMTActionMachine(this, - VMTMachineStub::CreateMachineByID( - IVMTMachine::MachineType::MT_LEFT_WORD, - this->GetMachine()),ui->_navi->isChecked()))); +void FormEditorMachine::on_tool_machine_left_word_clicked() { + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_LEFT_WORD, this->GetMachine()), + ui->_navi->isChecked()))); } -void FormEditorMachine::on_tool_machine_right_word_clicked() -{ - SetAction(std::shared_ptr(new VMTActionMachine(this, - VMTMachineStub::CreateMachineByID( - IVMTMachine::MachineType::MT_RIGHT_WORD, - this->GetMachine()),ui->_navi->isChecked()))); +void FormEditorMachine::on_tool_machine_right_word_clicked() { + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_RIGHT_WORD, this->GetMachine()), + ui->_navi->isChecked()))); } -void FormEditorMachine::on_tool_machine_copy_clicked() -{ - SetAction(std::shared_ptr(new VMTActionMachine(this, - VMTMachineStub::CreateMachineByID( - IVMTMachine::MachineType::MT_COPY, - this->GetMachine()),ui->_navi->isChecked()))); +void FormEditorMachine::on_tool_machine_copy_clicked() { + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_COPY, + this->GetMachine()), + ui->_navi->isChecked()))); } -void FormEditorMachine::EnableActionHint(const QString &hint,QPixmap& img){ +void FormEditorMachine::EnableActionHint(const QString& hint, QPixmap& img) { ScreenTools st; ui->label_title->setText(hint); - ui->label_image->setPixmap(img.scaled(st.GetImageSize(),Qt::KeepAspectRatio, Qt::SmoothTransformation)); + ui->label_image->setPixmap(img.scaled( + st.GetImageSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); ui->label_image->setText(""); ui->properties_frame->setHidden(false); } -void FormEditorMachine::DisableActionHint(){ +void FormEditorMachine::DisableActionHint() { ui->properties_frame->setHidden(true); } -void FormEditorMachine::refreshInterfaceIcons() -{ +void FormEditorMachine::refreshInterfaceIcons() { ui->widget_editor->applyTheme(); ScreenTools st; @@ -550,39 +538,47 @@ void FormEditorMachine::refreshInterfaceIcons() const auto machine = _form_calculator->machine(); if (machine) { ui->label_image->setPixmap( - GetGraphics().GetImage(machine->GetImageType()) - ->scaled(st.GetImageSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + GetGraphics() + .GetImage(machine->GetImageType()) + ->scaled(st.GetImageSize(), Qt::KeepAspectRatio, + Qt::SmoothTransformation)); } } else if (_form_alphabit) { - if (QPixmap* image = _form_alphabit->GetAlphabitSource()->GetImage()) { + if (QPixmap* image = + _form_alphabit->GetAlphabitSource()->GetImage()) { ui->label_image->setPixmap( - image->scaled(st.GetImageSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + image->scaled(st.GetImageSize(), Qt::KeepAspectRatio, + Qt::SmoothTransformation)); } } else if (_form_complex_machines) { const QPixmap img = VmtIcons::machinePixmap(MACHINE_COMPLEX); - ui->label_image->setPixmap( - img.scaled(st.GetImageSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + ui->label_image->setPixmap(img.scaled(st.GetImageSize(), + Qt::KeepAspectRatio, + Qt::SmoothTransformation)); } } } -void FormEditorMachine::EnableFormComplexMachines(){ +void FormEditorMachine::EnableFormComplexMachines() { ScreenTools st; const QPixmap img = VmtIcons::machinePixmap(MACHINE_COMPLEX); - if(_form_complex_machines) DisableFormComplexMachines(); - if(!ui->properties->layout()) ui->properties->setLayout(new QHBoxLayout()); - ui->properties->layout()->addWidget(_form_complex_machines = new FormComplexMachines(this,ui->properties,ui->_navi->isChecked())); - - ui->label_title->setText("Please select sub-machine name and click to diagram"); - ui->label_image->setPixmap(img.scaled(st.GetImageSize(),Qt::KeepAspectRatio, Qt::SmoothTransformation)); + if (_form_complex_machines) DisableFormComplexMachines(); + if (!ui->properties->layout()) ui->properties->setLayout(new QHBoxLayout()); + ui->properties->layout()->addWidget( + _form_complex_machines = new FormComplexMachines( + this, ui->properties, ui->_navi->isChecked())); + + ui->label_title->setText( + "Please select sub-machine name and click to diagram"); + ui->label_image->setPixmap(img.scaled( + st.GetImageSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); ui->label_image->setText(""); ui->properties_frame->setHidden(false); } -void FormEditorMachine::DisableFormComplexMachines(){ - if(_form_complex_machines) - { +void FormEditorMachine::DisableFormComplexMachines() { + if (_form_complex_machines) { ui->properties->layout()->removeWidget(_form_complex_machines); delete _form_complex_machines; _form_complex_machines = nullptr; @@ -590,17 +586,16 @@ void FormEditorMachine::DisableFormComplexMachines(){ ui->properties_frame->setHidden(true); } -void FormEditorMachine::EnableAnimation(bool enable){ +void FormEditorMachine::EnableAnimation(bool enable) { ui->widget_editor->EnableAnimation(enable); } -void FormEditorMachine::on_tool_complex_clicked() -{ +void FormEditorMachine::on_tool_complex_clicked() { SetAction(std::shared_ptr(new VMTActionTranslate(this))); EnableFormComplexMachines(); } -void FormEditorMachine::on__navi_clicked() -{ - SetAction(std::shared_ptr(new VMTActionPointer(this,ui->_navi->isChecked()))); +void FormEditorMachine::on__navi_clicked() { + SetAction(std::shared_ptr( + new VMTActionPointer(this, ui->_navi->isChecked()))); } diff --git a/VirtualTuringMachine/formeditormachine.h b/VirtualTuringMachine/formeditormachine.h old mode 100755 new mode 100644 index 1ddb16c..68aa2b8 --- a/VirtualTuringMachine/formeditormachine.h +++ b/VirtualTuringMachine/formeditormachine.h @@ -1,26 +1,29 @@ #ifndef FORMEDITORMACHINE_H #define FORMEDITORMACHINE_H -#include -#include "formbase.h" -#include "interfaces/IVMTEnvironment.h" -#include "interfaces/IVMTActionController.h" #include +#include + +#include "formactionhint.h" #include "formalphabit.h" +#include "formbase.h" #include "formcalculator.h" #include "formcomplexmachines.h" -#include "formactionhint.h" +#include "interfaces/IVMTActionController.h" +#include "interfaces/IVMTEnvironment.h" namespace Ui { class FormEditorMachine; } -class FormEditorMachine : public QWidget, public FormBase , public IVMTEnvironment , public IVMTActionController -{ +class FormEditorMachine : public QWidget, + public FormBase, + public IVMTEnvironment, + public IVMTActionController { Q_OBJECT -public: - explicit FormEditorMachine(QWidget *parent = 0); + public: + explicit FormEditorMachine(QWidget* parent = 0); void BeforeChange(std::shared_ptr state_data) override; void AfterUndo(std::shared_ptr state_data) override; void ChangeZoom(size_t zoom); @@ -30,7 +33,6 @@ class FormEditorMachine : public QWidget, public FormBase , public IVMTEnvironme void Exercise(); void Run(); - void EnableFormComplexMachines(); void DisableFormComplexMachines(); @@ -39,12 +41,13 @@ class FormEditorMachine : public QWidget, public FormBase , public IVMTEnvironme ~FormEditorMachine(); -// IVMTEnvironment - void EnableActionHint(const QString &hint,QPixmap& img) override; + // IVMTEnvironment + void EnableActionHint(const QString& hint, QPixmap& img) override; void DisableActionHint() override; void DisableAlphabit() override; void DisableCalculator() override; - void EnableAlphabit(IVMTAlphabitSource* p_Alphabit,const QString& msg,QPixmap &img) override; + void EnableAlphabit(IVMTAlphabitSource* p_Alphabit, const QString& msg, + QPixmap& img) override; void EnableCalculator(std::shared_ptr machine) override; UICanvas& GetGraphics() override; std::weak_ptr GetMachine() override; @@ -52,21 +55,20 @@ class FormEditorMachine : public QWidget, public FormBase , public IVMTEnvironme void RepaintThrottled(const QRect& rect) override; bool deferTransitionRouting() const override; void setDeferTransitionRouting(bool defer) override; - void MoveInScreen(QPoint &&shift) override; - void Move(QPoint &&shift) override; + void MoveInScreen(QPoint&& shift) override; + void Move(QPoint&& shift) override; void SetMachine(std::shared_ptr machine) override; void EnableAnimation(bool enable) override; void refreshInterfaceIcons(); - - //IVMTActionController + // IVMTActionController void SetAction(std::shared_ptr action) override; -protected: - void keyPressEvent (QKeyEvent* event) override; + protected: + void keyPressEvent(QKeyEvent* event) override; -private slots: + private slots: void on_tool_pointer_clicked(); void on_tool_link_clicked(); @@ -91,22 +93,19 @@ private slots: void on_tool_machine_copy_clicked(); - - void on_tool_complex_clicked(); void on__navi_clicked(); -private: - Ui::FormEditorMachine *ui; + private: + Ui::FormEditorMachine* ui; std::shared_ptr _tools_group; FormAlphabit* _form_alphabit; - FormCalculator *_form_calculator; - FormComplexMachines *_form_complex_machines; - FormActionHint *_form_action_hint; + FormCalculator* _form_calculator; + FormComplexMachines* _form_complex_machines; + FormActionHint* _form_action_hint; std::shared_ptr _action_space; bool _deferTransitionRouting = false; - }; -#endif // FORMEDITORMACHINE_H +#endif // FORMEDITORMACHINE_H diff --git a/VirtualTuringMachine/formeditorwidget.cpp b/VirtualTuringMachine/formeditorwidget.cpp old mode 100755 new mode 100644 index c8b9ae5..67d015f --- a/VirtualTuringMachine/formeditorwidget.cpp +++ b/VirtualTuringMachine/formeditorwidget.cpp @@ -1,18 +1,21 @@ #include "formeditorwidget.h" -#include "ui_formeditorwidget.h" + #include + #include "screentools.h" +#include "ui_formeditorwidget.h" #include "vmttheme.h" -FormEditorWidget::FormEditorWidget(QWidget *parent) : - QWidget(parent), - ui(new Ui::FormEditorWidget), - _environment(nullptr), - _canvas(QBrush(VmtTheme::diagramBackground()), - QPen(VmtTheme::diagramGrid(), 1, Qt::DotLine, Qt::RoundCap, Qt::RoundJoin), - QPen(VmtTheme::diagramLine(), 1, Qt::DotLine, Qt::RoundCap, Qt::RoundJoin), - QSize(32, 32), 16) -{ +FormEditorWidget::FormEditorWidget(QWidget* parent) + : QWidget(parent), + ui(new Ui::FormEditorWidget), + _environment(nullptr), + _canvas(QBrush(VmtTheme::diagramBackground()), + QPen(VmtTheme::diagramGrid(), 1, Qt::DotLine, Qt::RoundCap, + Qt::RoundJoin), + QPen(VmtTheme::diagramLine(), 1, Qt::DotLine, Qt::RoundCap, + Qt::RoundJoin), + QSize(32, 32), 16) { ui->setupUi(this); VmtTheme::polishWidgetTree(this); applyTheme(); @@ -21,90 +24,85 @@ FormEditorWidget::FormEditorWidget(QWidget *parent) : ScreenTools st; _canvas.SetCellSize(st.GetCellSize()); _canvas.SetFontSize(st.GetFontSize()); - } -void FormEditorWidget::applyTheme() -{ +void FormEditorWidget::applyTheme() { _canvas.applyThemeColors(); setStyleSheet(QStringLiteral("FormEditorWidget { background-color: %1; }") .arg(VmtTheme::colorName(VmtTheme::canvasWorkspace()))); update(); } -void FormEditorWidget::EnableAnimation([[maybe_unused]] bool enable){ -} +void FormEditorWidget::EnableAnimation([[maybe_unused]] bool enable) {} -void FormEditorWidget::SetEnvironment(IVMTEnvironment *environment){ +void FormEditorWidget::SetEnvironment(IVMTEnvironment* environment) { _environment = environment; } -void FormEditorWidget::SetComplexMachine(std::shared_ptr m){ +void FormEditorWidget::SetComplexMachine(std::shared_ptr m) { _machine = m; } -std::shared_ptr FormEditorWidget::GetComplexMachine(){ - return _machine; +std::shared_ptr FormEditorWidget::GetComplexMachine() { + return _machine; } -UICanvas& FormEditorWidget::GetCanvas(){ - return _canvas; -} +UICanvas& FormEditorWidget::GetCanvas() { return _canvas; } -void FormEditorWidget::SetZoom(size_t zoom){ +void FormEditorWidget::SetZoom(size_t zoom) { _canvas.SetZoom(zoom); update(); - } -void FormEditorWidget::animate() -{ +void FormEditorWidget::animate() { _canvas.Animate(); update(); } -void FormEditorWidget::mouseMoveEvent(QMouseEvent * event){ - if(_action) _action->OnMouseMoved(_environment,event->pos(),_canvas.FromScreen(event->pos())); +void FormEditorWidget::mouseMoveEvent(QMouseEvent* event) { + if (_action) + _action->OnMouseMoved(_environment, event->pos(), + _canvas.FromScreen(event->pos())); } -void FormEditorWidget::mousePressEvent(QMouseEvent * event){ - if(_action) _action->OnMousePressed(_environment,event->pos(),_canvas.FromScreen(event->pos())); +void FormEditorWidget::mousePressEvent(QMouseEvent* event) { + if (_action) + _action->OnMousePressed(_environment, event->pos(), + _canvas.FromScreen(event->pos())); } -void FormEditorWidget::mouseReleaseEvent(QMouseEvent * event){ - if(_action) _action->OnMouseReleased(_environment,event->pos(),_canvas.FromScreen(event->pos())); +void FormEditorWidget::mouseReleaseEvent(QMouseEvent* event) { + if (_action) + _action->OnMouseReleased(_environment, event->pos(), + _canvas.FromScreen(event->pos())); } -void FormEditorWidget::mouseDoubleClickEvent(QMouseEvent * ){ - -} +void FormEditorWidget::mouseDoubleClickEvent(QMouseEvent*) {} -void FormEditorWidget::Center(){ +void FormEditorWidget::Center() { QRect rect = _canvas.ToScreen(_machine->GetBoundsWithChilds()); - _canvas.MoveInScreen(QPoint(-rect.topLeft().x(),-rect.topLeft().y())); + _canvas.MoveInScreen(QPoint(-rect.topLeft().x(), -rect.topLeft().y())); this->repaint(); } -void FormEditorWidget::Paint(UICanvas& canvas,const QRect rect){ - canvas.Paint(*canvas.GetPainter(),rect,rect); - if(_machine) _machine->PaintDiagram(canvas,rect); +void FormEditorWidget::Paint(UICanvas& canvas, const QRect rect) { + canvas.Paint(*canvas.GetPainter(), rect, rect); + if (_machine) _machine->PaintDiagram(canvas, rect); } -void FormEditorWidget::Repaint(const QRect &real_rect){ - if(real_rect.isEmpty()){ - update(); +void FormEditorWidget::Repaint(const QRect& real_rect) { + if (real_rect.isEmpty()) { + update(); } else { QRect screen = _canvas.ToScreen(real_rect); const int margin = std::max(12, static_cast(_canvas.GetStep())); screen = screen.marginsAdded(QMargins(margin, margin, margin, margin)); update(screen); } - } -void FormEditorWidget::RepaintThrottled(const QRect &real_rect) -{ +void FormEditorWidget::RepaintThrottled(const QRect& real_rect) { if (!real_rect.isEmpty()) { Repaint(real_rect); return; @@ -118,26 +116,20 @@ void FormEditorWidget::RepaintThrottled(const QRect &real_rect) update(); } -void FormEditorWidget::paintEvent(QPaintEvent *event) -{ +void FormEditorWidget::paintEvent(QPaintEvent* event) { QPainter painter; painter.begin(this); QRect bounds; bounds.setSize(this->size()); - _canvas.Paint(painter,event->rect(),bounds); - if(_machine) _machine->PaintDiagram(_canvas,event->rect()); - if(_action) _action->Paint(_canvas,event->rect()); + _canvas.Paint(painter, event->rect(), bounds); + if (_machine) _machine->PaintDiagram(_canvas, event->rect()); + if (_action) _action->Paint(_canvas, event->rect()); painter.end(); } -std::shared_ptr &FormEditorWidget::GetAction(){ - return _action; -} - - +std::shared_ptr& FormEditorWidget::GetAction() { return _action; } -FormEditorWidget::~FormEditorWidget() -{ +FormEditorWidget::~FormEditorWidget() { this->setMouseTracking(false); this->_action.reset(); this->_machine.reset(); diff --git a/VirtualTuringMachine/formeditorwidget.h b/VirtualTuringMachine/formeditorwidget.h old mode 100755 new mode 100644 index 82cb48d..e067fab --- a/VirtualTuringMachine/formeditorwidget.h +++ b/VirtualTuringMachine/formeditorwidget.h @@ -1,62 +1,61 @@ #ifndef FORMEDITORWIDGET_H #define FORMEDITORWIDGET_H +#include - -#include #include #include #include -#include -#include "vmtmachines/VMTComplexMachine.h" +#include + #include "interfaces/IVMTAction.h" +#include "vmtmachines/VMTComplexMachine.h" class IVMTEnvironment; namespace Ui { class FormEditorWidget; } -class FormEditorWidget : - public QWidget +class FormEditorWidget : public QWidget { Q_OBJECT -public: - explicit FormEditorWidget(QWidget *parent = 0); + public: + explicit FormEditorWidget(QWidget* parent = 0); void SetZoom(size_t zoom); - void SetEnvironment(IVMTEnvironment *environment); + void SetEnvironment(IVMTEnvironment* environment); UICanvas& GetCanvas(); void SetComplexMachine(std::shared_ptr m); std::shared_ptr GetComplexMachine(); - std::shared_ptr &GetAction(); - void Paint(UICanvas& canvas,const QRect rect); - void Repaint(const QRect &real_rect); - void RepaintThrottled(const QRect &real_rect); + std::shared_ptr& GetAction(); + void Paint(UICanvas& canvas, const QRect rect); + void Repaint(const QRect& real_rect); + void RepaintThrottled(const QRect& real_rect); void Center(); void EnableAnimation(bool enable); void applyTheme(); ~FormEditorWidget(); -public slots: + public slots: void animate(); -protected: + protected: QPoint& GetPaintAreaOffset(); - void mouseMoveEvent(QMouseEvent * event) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent * event) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent * event) Q_DECL_OVERRIDE; - void mouseDoubleClickEvent(QMouseEvent * event) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; - -private: - Ui::FormEditorWidget *ui; - IVMTEnvironment *_environment; + void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent* event) Q_DECL_OVERRIDE; + void mouseDoubleClickEvent(QMouseEvent* event) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE; + + private: + Ui::FormEditorWidget* ui; + IVMTEnvironment* _environment; UICanvas _canvas; - std::shared_ptr _action; + std::shared_ptr _action; std::shared_ptr _machine; qint64 _lastThrottledRepaintMs = 0; }; -#endif // FORMEDITORWIDGET_H +#endif // FORMEDITORWIDGET_H diff --git a/VirtualTuringMachine/formexercises.cpp b/VirtualTuringMachine/formexercises.cpp old mode 100755 new mode 100644 index f5bcc19..a1aa7fb --- a/VirtualTuringMachine/formexercises.cpp +++ b/VirtualTuringMachine/formexercises.cpp @@ -1,22 +1,22 @@ #include "formexercises.h" -#include "ui_formexercises.h" -#include "uistateexercises.h" -#include -#include "screentools.h" -#include "vmttheme.h" -#include "configuration.h" -#include "VMTJsonSerializer.h" -#include "uistatenewproject.h" + #include #include -#include #include +#include #include +#include + +#include "VMTJsonSerializer.h" +#include "configuration.h" +#include "screentools.h" +#include "ui_formexercises.h" +#include "uistateexercises.h" +#include "uistatenewproject.h" +#include "vmttheme.h" -FormExercises::FormExercises(QWidget *parent) : - QWidget(parent), - ui(new Ui::FormExercises) -{ +FormExercises::FormExercises(QWidget* parent) + : QWidget(parent), ui(new Ui::FormExercises) { ui->setupUi(this); VmtTheme::polishWidgetTree(this); ScreenTools st; @@ -37,70 +37,67 @@ FormExercises::FormExercises(QWidget *parent) : ui->_list->setSelectionRectVisible(false); connect(ui->_list->selectionModel(), - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - this, SLOT(OnSelectionChanged(QItemSelection))); + SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, + SLOT(OnSelectionChanged(QItemSelection))); } -void FormExercises::OnSelectionChanged(const QItemSelection& selection){ - if(selection.indexes().isEmpty()) { - ui->_text->setHtml("

Please select exercise

"); - ui->_text_ru->setHtml("

ŠŸŠ¾Š¶Š°Š»ŃƒŠ¹ŃŃ‚Š° выберете ŃƒŠæŃ€Š°Š¶Š½ŠµŠ½ŠøŠµ

"); - ui->_ok->setVisible(false); - ui->_open->setVisible(false); - } else { - int index = selection.indexes().first().row(); - int i=0; - - - for(std::shared_ptr ex:Configuration::GetInstance().GetExercises()){ - if(i==index){ - ui->_text->setHtml("

Exercise "+QString::number(ex->GetIndex())+"

"+ex->GetTextEn() + "

"); - ui->_text_ru->setHtml("

Упражнение "+QString::number(ex->GetIndex())+"

"+ex->GetTextRu() + "

"); - ui->_ok->setVisible(true); - ui->_open->setVisible(true); - _exercise = ex; - - } - i++; - } - - - - } +void FormExercises::OnSelectionChanged(const QItemSelection& selection) { + if (selection.indexes().isEmpty()) { + ui->_text->setHtml("

Please select exercise

"); + ui->_text_ru->setHtml("

ŠŸŠ¾Š¶Š°Š»ŃƒŠ¹ŃŃ‚Š° выберете ŃƒŠæŃ€Š°Š¶Š½ŠµŠ½ŠøŠµ

"); + ui->_ok->setVisible(false); + ui->_open->setVisible(false); + } else { + int index = selection.indexes().first().row(); + int i = 0; + + for (std::shared_ptr ex : + Configuration::GetInstance().GetExercises()) { + if (i == index) { + ui->_text->setHtml("

Exercise " + + QString::number(ex->GetIndex()) + + "

" + ex->GetTextEn() + "

"); + ui->_text_ru->setHtml("

Упражнение " + + QString::number(ex->GetIndex()) + + "

" + ex->GetTextRu() + "

"); + ui->_ok->setVisible(true); + ui->_open->setVisible(true); + _exercise = ex; + } + i++; + } + } } +void FormExercises::BeforeChange(std::shared_ptr state_data) { + UIStateExercisesData* data = + dynamic_cast(state_data.get()); + if (data) { + // state_data->SetName(ui->text_project_name->text()); -void FormExercises::BeforeChange(std::shared_ptr state_data){ - - - UIStateExercisesData *data = dynamic_cast(state_data.get()); - if(data){ -// state_data->SetName(ui->text_project_name->text()); - -// Save(); + // Save(); } - - } -QAbstractItemModel *FormExercises::createModel() -{ - QStandardItemModel *model = new QStandardItemModel(); - QList listItem; +QAbstractItemModel* FormExercises::createModel() { + QStandardItemModel* model = new QStandardItemModel(); + QList listItem; - - for(std::shared_ptr ex : Configuration::GetInstance().GetExercises()){ - QStandardItem *item = new QStandardItem(); + for (std::shared_ptr ex : + Configuration::GetInstance().GetExercises()) { + QStandardItem* item = new QStandardItem(); QString name; - if(ex->GetIndex()<10) name = ":/Files/images/exercises/ex_0"; - else name = ":/Files/images/exercises/ex_"; + if (ex->GetIndex() < 10) + name = ":/Files/images/exercises/ex_0"; + else + name = ":/Files/images/exercises/ex_"; name += QString::number(ex->GetIndex()); qDebug() << name; - if(ex->GetCompleted()) name +="_done"; + if (ex->GetCompleted()) name += "_done"; name += ".png"; item->setIcon(QIcon(QPixmap(name))); - QString text = "Exercise "+QString::number(ex->GetIndex()); + QString text = "Exercise " + QString::number(ex->GetIndex()); item->setText(text); item->setEditable(false); item->setDragEnabled(false); @@ -112,37 +109,38 @@ QAbstractItemModel *FormExercises::createModel() } model->appendColumn(listItem); -return model; - + return model; } void FormExercises::AfterUndo(std::shared_ptr state_data) { - UIStateExercisesData *data = dynamic_cast(state_data.get()); - if(data){ - // ui->text_project_name->setText(VMTProject::GetInstance().GetName());//data->name); - // ui->text_project_location->setText(VMTProject::GetInstance().GetLocation());//data->location); - // ui->text_alphabit->setText(VMTProject::GetInstance().GetAlphabit()->ToString());//data->alphabit); - // Check(); + UIStateExercisesData* data = + dynamic_cast(state_data.get()); + if (data) { + // ui->text_project_name->setText(VMTProject::GetInstance().GetName());//data->name); + // ui->text_project_location->setText(VMTProject::GetInstance().GetLocation());//data->location); + // ui->text_alphabit->setText(VMTProject::GetInstance().GetAlphabit()->ToString());//data->alphabit); + // Check(); } } -FormExercises::~FormExercises() -{ - delete ui; -} +FormExercises::~FormExercises() { delete ui; } -void FormExercises::on__ok_clicked() -{ - if( VMTProject::GetInstance().GetUndoManager()) +void FormExercises::on__ok_clicked() { + if (VMTProject::GetInstance().GetUndoManager()) VMTProject::GetInstance().GetUndoManager()->Clear(); - VMTProject::GetInstance().GetName() = "Exercise "+QString::number(_exercise->GetIndex());; - VMTProject::GetInstance().GetLocation() = Configuration::GetInstance().GetDefaultLocation(); - VMTProject::GetInstance().GetAlphabit()->ReplaceString(_exercise->GetAlphabit()); + VMTProject::GetInstance().GetName() = + "Exercise " + QString::number(_exercise->GetIndex()); + ; + VMTProject::GetInstance().GetLocation() = + Configuration::GetInstance().GetDefaultLocation(); + VMTProject::GetInstance().GetAlphabit()->ReplaceString( + _exercise->GetAlphabit()); VMTProject::GetInstance().SetExercise(_exercise); - _controller->ChangeState(std::shared_ptr(new UIStateNewProjectData())); + _controller->ChangeState( + std::shared_ptr(new UIStateNewProjectData())); } -bool FormExercises::OpenProject(QString &file){ +bool FormExercises::OpenProject(QString& file) { if (VMTJsonSerializer::isJsonPath(file)) { VMTJsonSerializer json(file); if (!json.deserialize(&VMTProject::GetInstance())) { @@ -155,42 +153,43 @@ bool FormExercises::OpenProject(QString &file){ VMTProject::GetInstance().GetUndoManager()->Clear(); QFileInfo file_info(file); - VMTProject::GetInstance().GetLocation() = file_info.absoluteDir().absolutePath(); + VMTProject::GetInstance().GetLocation() = + file_info.absoluteDir().absolutePath(); VMTProject::GetInstance().GetName() = file_info.baseName(); return true; } - -void FormExercises::on__open_clicked() -{ +void FormExercises::on__open_clicked() { QFileDialog dlg; dlg.setWindowTitle("Open Virtual Machine Project"); dlg.setAcceptMode(QFileDialog::AcceptOpen); dlg.setFileMode(QFileDialog::ExistingFile); dlg.setViewMode(QFileDialog::List); QStringList filters; - filters <<"Any files (*)" - <<"Turing machine files (*.jdtp)" - <<"JSON projects (*.vmt.json *.json)"; - dlg.setOption(QFileDialog::HideNameFilterDetails,false); + filters << "Any files (*)" + << "Turing machine files (*.jdtp)" + << "JSON projects (*.vmt.json *.json)"; + dlg.setOption(QFileDialog::HideNameFilterDetails, false); dlg.setNameFilters(filters); dlg.resize(QApplication::primaryScreen()->availableSize()); - if(dlg.exec()==QDialog::Accepted) - { - QStringList fileName=dlg.selectedFiles(); + if (dlg.exec() == QDialog::Accepted) { + QStringList fileName = dlg.selectedFiles(); - if(fileName.length()>0){ + if (fileName.length() > 0) { QString file = fileName[0]; - if(file.length()>0){ - if(OpenProject(file)){ - if( VMTProject::GetInstance().GetUndoManager()) + if (file.length() > 0) { + if (OpenProject(file)) { + if (VMTProject::GetInstance().GetUndoManager()) VMTProject::GetInstance().GetUndoManager()->Clear(); - VMTProject::GetInstance().GetAlphabit()->ReplaceString(_exercise->GetAlphabit()); + VMTProject::GetInstance().GetAlphabit()->ReplaceString( + _exercise->GetAlphabit()); VMTProject::GetInstance().SetExercise(_exercise); Configuration::GetInstance().AddRecentProject(file); Configuration::GetInstance().Save(); - _controller->ChangeState(std::shared_ptr(new UIStateNewProjectData())); + _controller->ChangeState( + std::shared_ptr( + new UIStateNewProjectData())); } } } diff --git a/VirtualTuringMachine/formexercises.h b/VirtualTuringMachine/formexercises.h old mode 100755 new mode 100644 index 0f9efc9..1584c65 --- a/VirtualTuringMachine/formexercises.h +++ b/VirtualTuringMachine/formexercises.h @@ -1,38 +1,37 @@ #ifndef FORMEXERCISES_H #define FORMEXERCISES_H -#include #include #include +#include namespace Ui { class FormExercises; } -#include "formbase.h" #include "exercise.h" +#include "formbase.h" -class FormExercises : public QWidget , public FormBase -{ +class FormExercises : public QWidget, public FormBase { Q_OBJECT -public: - explicit FormExercises(QWidget *parent = 0); + public: + explicit FormExercises(QWidget* parent = 0); void BeforeChange(std::shared_ptr state_data) override; void AfterUndo(std::shared_ptr state_data) override; - QAbstractItemModel *createModel(); + QAbstractItemModel* createModel(); ~FormExercises(); -private slots: + private slots: void OnSelectionChanged(const QItemSelection& selection); void on__ok_clicked(); void on__open_clicked(); -private: - Ui::FormExercises *ui; + private: + Ui::FormExercises* ui; std::shared_ptr _exercise; - bool OpenProject(QString &file); + bool OpenProject(QString& file); }; -#endif // FORMEXERCISES_H +#endif // FORMEXERCISES_H diff --git a/VirtualTuringMachine/formexport4th.cpp b/VirtualTuringMachine/formexport4th.cpp old mode 100755 new mode 100644 index ed61414..7185ecd --- a/VirtualTuringMachine/formexport4th.cpp +++ b/VirtualTuringMachine/formexport4th.cpp @@ -1,17 +1,17 @@ #include "formexport4th.h" -#include "ui_formexport4th.h" -#include "vmtproject.h" + #include #include + #include + #include "screentools.h" +#include "ui_formexport4th.h" +#include "vmtproject.h" #include "vmttheme.h" -FormExport4th::FormExport4th(QWidget *parent) : - QWidget(parent), - ui(new Ui::FormExport4th), - _export(nullptr) -{ +FormExport4th::FormExport4th(QWidget* parent) + : QWidget(parent), ui(new Ui::FormExport4th), _export(nullptr) { ui->setupUi(this); VmtTheme::polishWidgetTree(this); ui->_copy->setVisible(false); @@ -25,74 +25,68 @@ FormExport4th::FormExport4th(QWidget *parent) : _information = ""; } -void FormExport4th::BeforeChange([[maybe_unused]] std::shared_ptr state_data){ -} +void FormExport4th::BeforeChange( + [[maybe_unused]] std::shared_ptr state_data) {} -void FormExport4th::AfterUndo([[maybe_unused]] std::shared_ptr state_data) { -} +void FormExport4th::AfterUndo( + [[maybe_unused]] std::shared_ptr state_data) {} -void FormExport4th::OnLoaded(){ - //ui->edit_location->setText(VMTProject::GetInstance().GetLocation()); +void FormExport4th::OnLoaded() { + // ui->edit_location->setText(VMTProject::GetInstance().GetLocation()); qDebug() << VMTProject::GetInstance().GetCurrentMachineName(); - } -FormExport4th::~FormExport4th() -{ +FormExport4th::~FormExport4th() { delete _export; delete ui; } -std::shared_ptr FormExport4th::CreatePlainMachine(){ +std::shared_ptr FormExport4th::CreatePlainMachine() { std::vector> machines; - for(auto m: VMTProject::GetInstance().GetMachines()) + for (auto m : VMTProject::GetInstance().GetMachines()) machines.push_back(m->CreatePlainCopy(nullptr)); - for(auto &m: machines){ - for(auto &im: m->GetMachineCollection()){ - std::shared_ptr mc = std::dynamic_pointer_cast(im); - if(mc){ - for(auto &mr:machines){ - if(mr->GetMachineName()==mc->GetMachineName()){ - mc->ReplaceMachine(mr.get()); - } - } - } + for (auto& m : machines) { + for (auto& im : m->GetMachineCollection()) { + std::shared_ptr mc = + std::dynamic_pointer_cast(im); + if (mc) { + for (auto& mr : machines) { + if (mr->GetMachineName() == mc->GetMachineName()) { + mc->ReplaceMachine(mr.get()); + } + } + } } } std::shared_ptr result; - for(auto &m: machines){ - if(m->GetMachineName()==VMTProject::GetInstance().GetCurrentMachine()->GetMachineName()) + for (auto& m : machines) { + if (m->GetMachineName() == + VMTProject::GetInstance().GetCurrentMachine()->GetMachineName()) result = m; } return result; } -void FormExport4th::on__export_clicked() -{ - if(_export) return; +void FormExport4th::on__export_clicked() { + if (_export) return; ui->_export->setVisible(false); - Clear(); _done = false; - _export = new VMTExport4th(CreatePlainMachine(), - ui->_delimiter->text(), - ui->_left->text(), - ui->_right->text(), - ui->_stop->text(), - ui->_quotes->text()); - _export->Export(this,nullptr); + _export = new VMTExport4th(CreatePlainMachine(), ui->_delimiter->text(), + ui->_left->text(), ui->_right->text(), + ui->_stop->text(), ui->_quotes->text()); + _export->Export(this, nullptr); QTimer::singleShot(200, this, SLOT(OnTimer())); - } -void FormExport4th::OnTimer(){ +void FormExport4th::OnTimer() { qDebug() << "OnTimer"; - if(!_done){ + if (!_done) { QTimer::singleShot(200, this, SLOT(OnTimer())); } else { ui->_text->setText(_output); @@ -101,30 +95,26 @@ void FormExport4th::OnTimer(){ } } -void FormExport4th::Done(){ - _done = true; -} +void FormExport4th::Done() { _done = true; } -void FormExport4th::Clear(){ +void FormExport4th::Clear() { ui->_text->clear(); _output = ""; _information = ""; } -void FormExport4th::AppendText(const QString &text){ - //ui->_text->append(text); +void FormExport4th::AppendText(const QString& text) { + // ui->_text->append(text); _output.append(text); _output.append("\r\n"); - } -void FormExport4th::Information(const QString &text){ - //ui->information->setText(text); +void FormExport4th::Information(const QString& text) { + // ui->information->setText(text); _information.append(text); } -void FormExport4th::on__copy_clicked() -{ - QClipboard *clipboard = QApplication::clipboard(); +void FormExport4th::on__copy_clicked() { + QClipboard* clipboard = QApplication::clipboard(); QString text = ui->_text->toPlainText(); clipboard->setText(text); QMessageBox box; diff --git a/VirtualTuringMachine/formexport4th.h b/VirtualTuringMachine/formexport4th.h old mode 100755 new mode 100644 index e1abe32..e5fce82 --- a/VirtualTuringMachine/formexport4th.h +++ b/VirtualTuringMachine/formexport4th.h @@ -1,22 +1,22 @@ #ifndef FORMEXPORT4TH_H #define FORMEXPORT4TH_H -#include "formbase.h" -#include -#include #include +#include +#include + +#include "formbase.h" #include "vmtexport4th/vmtexport4th.h" namespace Ui { class FormExport4th; } -class FormExport4th : public QWidget , public FormBase, public TextCallback -{ +class FormExport4th : public QWidget, public FormBase, public TextCallback { Q_OBJECT -public: - explicit FormExport4th(QWidget *parent = 0); + public: + explicit FormExport4th(QWidget* parent = 0); ~FormExport4th(); void BeforeChange(std::shared_ptr state_data) override; void AfterUndo(std::shared_ptr state_data) override; @@ -24,26 +24,25 @@ class FormExport4th : public QWidget , public FormBase, public TextCallback void Done() override; void Clear() override; - void AppendText(const QString &text) override; - void Information(const QString &text) override; -public slots: - -private slots: + void AppendText(const QString& text) override; + void Information(const QString& text) override; + public slots: + private slots: void on__export_clicked(); void on__copy_clicked(); void OnTimer(); -private: - Ui::FormExport4th *ui; - VMTExport4th* _export; + private: + Ui::FormExport4th* ui; + VMTExport4th* _export; QString _output; QString _information; - bool _done; + bool _done; std::shared_ptr CreatePlainMachine(); }; -#endif // FORMEXPORT4TH_H +#endif // FORMEXPORT4TH_H diff --git a/VirtualTuringMachine/formlinewidget.cpp b/VirtualTuringMachine/formlinewidget.cpp old mode 100755 new mode 100644 index 9e0096b..e10c76b --- a/VirtualTuringMachine/formlinewidget.cpp +++ b/VirtualTuringMachine/formlinewidget.cpp @@ -1,49 +1,44 @@ #include "formlinewidget.h" -#include "vmttheme.h" + #include "ui_formlinewidget.h" #include "vmtproject.h" +#include "vmttheme.h" - -FormLineWidget::FormLineWidget(QWidget *parent) : - QWidget(parent), - ui(new Ui::FormLineWidget), - _count(0), - _position(0) -{ +FormLineWidget::FormLineWidget(QWidget* parent) + : QWidget(parent), ui(new Ui::FormLineWidget), _count(0), _position(0) { ui->setupUi(this); ui->frame->setLayout(&_layout); - for(int i=0;i<64;i++){ + for (int i = 0; i < 64; i++) { _line_edit[i].setHidden(true); - _line_edit[i].setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding); - _line_edit[i].setProperty("index",i); - QObject::connect(&_line_edit[i], SIGNAL(textChanged(QString)), - this, SLOT(onEditChanged(QString))); + _line_edit[i].setSizePolicy(QSizePolicy::Minimum, + QSizePolicy::Expanding); + _line_edit[i].setProperty("index", i); + QObject::connect(&_line_edit[i], SIGNAL(textChanged(QString)), this, + SLOT(onEditChanged(QString))); _line_edit[i].installEventFilter(this); ui->frame->layout()->addWidget(&_line_edit[i]); } applyTheme(); } -void FormLineWidget::applyTheme() -{ - ui->frame->setStyleSheet(QStringLiteral("QFrame { background-color: %1; border: none; }") - .arg(VmtTheme::colorName(VmtTheme::canvasWorkspace()))); +void FormLineWidget::applyTheme() { + ui->frame->setStyleSheet( + QStringLiteral("QFrame { background-color: %1; border: none; }") + .arg(VmtTheme::colorName(VmtTheme::canvasWorkspace()))); if (_line) { FillLineEdit(); } } -void FormLineWidget::SetTestMode(){ - for(int i=0;i<64;i++){ +void FormLineWidget::SetTestMode() { + for (int i = 0; i < 64; i++) { _line_edit[i].setEnabled(false); } } -void FormLineWidget::SetLine(std::shared_ptr line){ - _line = line; -} +void FormLineWidget::SetLine(std::shared_ptr line) { _line = line; } -void FormLineWidget::Left(){ +void FormLineWidget::Left() { isShiftFromType = false; _position--; @@ -52,16 +47,16 @@ void FormLineWidget::Left(){ isShiftFromType = true; } -void FormLineWidget::LeftPage(){ +void FormLineWidget::LeftPage() { isShiftFromType = false; - _position-=_count; + _position -= _count; FillLineEdit(); isShiftFromType = true; } -void FormLineWidget::Right(){ +void FormLineWidget::Right() { isShiftFromType = false; _position++; @@ -70,116 +65,117 @@ void FormLineWidget::Right(){ isShiftFromType = true; } -void FormLineWidget::RightPage(){ +void FormLineWidget::RightPage() { isShiftFromType = false; - _position+=_count; + _position += _count; FillLineEdit(); isShiftFromType = true; } -void FormLineWidget::Repaint(){ - long right = _position+((long)_count)+1; - if(_line->GetMachinePosition()<_position){ +void FormLineWidget::Repaint() { + long right = _position + ((long)_count) + 1; + if (_line->GetMachinePosition() < _position) { _position = _line->GetMachinePosition(); - } else if(_line->GetMachinePosition()>=right) - { - _position = _line->GetMachinePosition()-_count; + } else if (_line->GetMachinePosition() >= right) { + _position = _line->GetMachinePosition() - _count; } FillLineEdit(); } -void FormLineWidget::FillLineEdit(){ - for(long i=0;i<=(long)_count;i++){ - _line_edit[i].setText(QString(QChar(_line->GetValueAt(_position+i)))); - _line_edit[i].setStyleSheet(VmtTheme::lineEditTapeStyle(_line->IsMachinePosition(_position + i))); - } +void FormLineWidget::FillLineEdit() { + for (long i = 0; i <= (long)_count; i++) { + _line_edit[i].setText(QString(QChar(_line->GetValueAt(_position + i)))); + _line_edit[i].setStyleSheet(VmtTheme::lineEditTapeStyle( + _line->IsMachinePosition(_position + i))); + } } -bool FormLineWidget::eventFilter(QObject* object, QEvent* event){ - if(event->type() == QEvent::MouseButtonRelease) { +bool FormLineWidget::eventFilter(QObject* object, QEvent* event) { + if (event->type() == QEvent::MouseButtonRelease) { int index = -1; - for(int i=0;i<64;i++) - if(&_line_edit[i]==object) index=i; - if(index>0){ - _line->SetMachinePosition(_position+index); - //VMTProject::GetInstance().GetUndoManager()->Remember(_line->SetMachinePosition(_position+index)); - - for(long i=0;i<=(long)_count;i++){ - _line_edit[i].setStyleSheet(VmtTheme::lineEditTapeStyle(_line->IsMachinePosition(_position + i))); + for (int i = 0; i < 64; i++) + if (&_line_edit[i] == object) index = i; + if (index > 0) { + _line->SetMachinePosition(_position + index); + // VMTProject::GetInstance().GetUndoManager()->Remember(_line->SetMachinePosition(_position+index)); + + for (long i = 0; i <= (long)_count; i++) { + _line_edit[i].setStyleSheet(VmtTheme::lineEditTapeStyle( + _line->IsMachinePosition(_position + i))); } } - return false; // lets the event continue to the edit - } + return false; // lets the event continue to the edit + } return false; } -void FormLineWidget::onEditChanged(QString text){ - QLineEdit *line = dynamic_cast (sender()); - if(line){ +void FormLineWidget::onEditChanged(QString text) { + QLineEdit* line = dynamic_cast(sender()); + if (line) { QVariant var = line->property("index"); - int index = var.toInt(); - - if(text.length()>1){ - QString old(QChar(_line->GetValueAt(index+_position))); - if(text.indexOf(old)==0){ + int index = var.toInt(); - if(_line->GetAlphabit()->IsSign(text[1].toLatin1())) + if (text.length() > 1) { + QString old(QChar(_line->GetValueAt(index + _position))); + if (text.indexOf(old) == 0) { + if (_line->GetAlphabit()->IsSign(text[1].toLatin1())) _line_edit[index].setText(QString(text[1])); - else _line_edit[index].setText(QString(QChar(_line->GetValueAt(_position+index)))); // else set old i think + else + _line_edit[index].setText(QString(QChar(_line->GetValueAt( + _position + index)))); // else set old i think } else { - if(_line->GetAlphabit()->IsSign(text[0].toLatin1())) - _line_edit[index].setText(QString(text[0])); - else _line_edit[index].setText(QString(QChar(_line->GetValueAt(_position+index)))); // else set old i think + if (_line->GetAlphabit()->IsSign(text[0].toLatin1())) + _line_edit[index].setText(QString(text[0])); + else + _line_edit[index].setText(QString(QChar(_line->GetValueAt( + _position + index)))); // else set old i think + } + } else if (text.length() == 0) { + if (_line->GetAlphabit()) + _line_edit[index].setText( + QString(QChar(_line->GetAlphabit()->GetLambda()))); + } else { + if (_line->GetAlphabit()->IsSign(text[0].toLatin1())) + _line->SetValueAt(_position + index, text[0].toLatin1()); + // VMTProject::GetInstance().GetUndoManager()->Remember(_line->SetValueAt(_position+index,text[0].toLatin1())); + else + _line_edit[index].setText( + QString(QChar(_line->GetValueAt(_position + index)))); + + std::shared_ptr alphabit = _line->GetAlphabit(); + if (alphabit->IsSign(text[0].toLatin1()) && + !alphabit->IsLambda(text[0].toLatin1()) && isShiftFromType && + _line_edit[index].hasFocus()) { + qDebug() << "shifting right after keyboard input, text = " + << text; + RightShiftActiveLineEdit(index); } - } else - if(text.length()==0) - { - if(_line->GetAlphabit()) - _line_edit[index].setText(QString(QChar(_line->GetAlphabit()->GetLambda()))); - } else{ - if(_line->GetAlphabit()->IsSign(text[0].toLatin1())) - _line->SetValueAt(_position+index,text[0].toLatin1()); - //VMTProject::GetInstance().GetUndoManager()->Remember(_line->SetValueAt(_position+index,text[0].toLatin1())); - else _line_edit[index].setText(QString(QChar(_line->GetValueAt(_position+index)))); - - std::shared_ptr alphabit = _line->GetAlphabit(); - if( - alphabit->IsSign(text[0].toLatin1()) && - !alphabit->IsLambda(text[0].toLatin1()) && - isShiftFromType && - _line_edit[index].hasFocus() - ) { - qDebug() << "shifting right after keyboard input, text = " << text; - RightShiftActiveLineEdit(index); - } } } - } void FormLineWidget::RightShiftActiveLineEdit(int currentIndex) { - _line_edit[currentIndex+1].setFocus(); + _line_edit[currentIndex + 1].setFocus(); _line->ShiftRight(); Repaint(); } -void FormLineWidget::resizeEvent(QResizeEvent * event){ - size_t count = event->size().width()/event->size().height(); +void FormLineWidget::resizeEvent(QResizeEvent* event) { + size_t count = event->size().width() / event->size().height(); - if(count!=_count){ + if (count != _count) { _count = count; - for(long i=0;i<64;i++) - if(i>(long)_count) ui->frame->layout()->itemAt(i)->widget()->setHidden(true); - else ui->frame->layout()->itemAt(i)->widget()->setHidden(false); + for (long i = 0; i < 64; i++) + if (i > (long)_count) + ui->frame->layout()->itemAt(i)->widget()->setHidden(true); + else + ui->frame->layout()->itemAt(i)->widget()->setHidden(false); ui->frame->layout()->update(); } } -FormLineWidget::~FormLineWidget() -{ - delete ui; -} +FormLineWidget::~FormLineWidget() { delete ui; } diff --git a/VirtualTuringMachine/formlinewidget.h b/VirtualTuringMachine/formlinewidget.h old mode 100755 new mode 100644 index f9de794..1e19d19 --- a/VirtualTuringMachine/formlinewidget.h +++ b/VirtualTuringMachine/formlinewidget.h @@ -1,33 +1,31 @@ #ifndef FORMLINEWIDGET_H #define FORMLINEWIDGET_H -#include -#include -#include +#include #include +#include #include -#include -#include -#include +#include +#include #include -#include +#include +#include +#include #include -#include -#include -#include +#include +#include #include namespace Ui { class FormLineWidget; } -class FormLineWidget : public QWidget -{ +class FormLineWidget : public QWidget { Q_OBJECT -public: - explicit FormLineWidget(QWidget *parent = 0); + public: + explicit FormLineWidget(QWidget* parent = 0); void SetLine(std::shared_ptr line); void Repaint(); void Left(); @@ -38,22 +36,23 @@ class FormLineWidget : public QWidget void applyTheme(); bool eventFilter(QObject* object, QEvent* event) override; ~FormLineWidget(); - void resizeEvent(QResizeEvent * event) Q_DECL_OVERRIDE; -private: - Ui::FormLineWidget *ui; - size_t _count; - long _position; - void FillLineEdit(); + void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE; + + private: + Ui::FormLineWidget* ui; + size_t _count; + long _position; + void FillLineEdit(); QLineEdit _line_edit[128]; QHBoxLayout _layout; std::shared_ptr _line; void RightShiftActiveLineEdit(int currentIndex); - bool isShiftFromType = true; // Input from keyboard, not from Right, RightPage, etc. + bool isShiftFromType = + true; // Input from keyboard, not from Right, RightPage, etc. -private slots: + private slots: void onEditChanged(QString text); - }; -#endif // FORMLINEWIDGET_H +#endif // FORMLINEWIDGET_H diff --git a/VirtualTuringMachine/formmain.cpp b/VirtualTuringMachine/formmain.cpp old mode 100755 new mode 100644 index 4755e9c..2dd7ba3 --- a/VirtualTuringMachine/formmain.cpp +++ b/VirtualTuringMachine/formmain.cpp @@ -1,32 +1,31 @@ #include "formmain.h" -#include "ui_formmain.h" + +#include #include +#include #include -#include "configuration.h" -#include "vmtproject.h" -#include #include -#include "screentools.h" -#include "vmttheme.h" -#include "vmticons.h" +#include + #include "VMTJsonSerializer.h" +#include "configuration.h" +#include "screentools.h" +#include "ui_formmain.h" #include "uistateexercises.h" -#include -#include +#include "vmticons.h" +#include "vmtproject.h" +#include "vmttheme.h" -FormMain::FormMain(QWidget *parent) : - QWidget(parent), - ui(new Ui::FormMain) -{ +FormMain::FormMain(QWidget* parent) : QWidget(parent), ui(new Ui::FormMain) { ui->setupUi(this); VmtTheme::polishWidgetTree(this); - for(const QString &name: Configuration::GetInstance().GetRecentProjects()) - addItem(ui->listWidget, - VmtIcons::pick(":/Files/images/toolbars/main/icon_open_black.png", - ":/Files/images/toolbars/main/icon_open.png"), - name, 1); - + for (const QString& name : Configuration::GetInstance().GetRecentProjects()) + addItem( + ui->listWidget, + VmtIcons::pick(":/Files/images/toolbars/main/icon_open_black.png", + ":/Files/images/toolbars/main/icon_open.png"), + name, 1); VMTProject::GetInstance().GetMachines().clear(); @@ -39,64 +38,52 @@ FormMain::FormMain(QWidget *parent) : ui->listWidget->setStyleSheet(VmtTheme::listSurfaceStyle()); VmtTheme::applyIconToolBar(ui->frame); -// QObject::connect(ui->listWidget, SIGNAL(itemClicked(QListWidgetItem *)), -// this, SLOT(onItemClicked(QListWidgetItem *))); + // QObject::connect(ui->listWidget, SIGNAL(itemClicked(QListWidgetItem + // *)), + // this, SLOT(onItemClicked(QListWidgetItem *))); } -void FormMain::BeforeChange(std::shared_ptr){ +void FormMain::BeforeChange(std::shared_ptr) {} -} +void FormMain::AfterUndo(std::shared_ptr) {} -void FormMain::AfterUndo(std::shared_ptr) { - -} - -void FormMain::addItem(QListWidget *listWidget, QString iconPath, QString text,int data) -{ +void FormMain::addItem(QListWidget* listWidget, QString iconPath, QString text, + int data) { QIcon icon(iconPath); - QListWidgetItem *item = new QListWidgetItem(icon, text); + QListWidgetItem* item = new QListWidgetItem(icon, text); QVariant variant(data); item->setData(Qt::UserRole, variant); listWidget->addItem(item); } - #include "uistatenewproject.h" -FormMain::~FormMain() -{ +FormMain::~FormMain() { qDebug() << "Delete FormMain"; delete ui; } -void FormMain::on_button_new_clicked() -{ +void FormMain::on_button_new_clicked() { qDebug() << "Clear undo manager"; - if( VMTProject::GetInstance().GetUndoManager()) + if (VMTProject::GetInstance().GetUndoManager()) VMTProject::GetInstance().GetUndoManager()->Clear(); VMTProject::GetInstance().GetName() = "MyProject"; - VMTProject::GetInstance().GetLocation() = Configuration::GetInstance().GetDefaultLocation(); + VMTProject::GetInstance().GetLocation() = + Configuration::GetInstance().GetDefaultLocation(); QString alphabit(""); VMTProject::GetInstance().GetAlphabit()->ReplaceString(alphabit); qDebug() << "Change state"; - _controller->ChangeState(std::shared_ptr(new UIStateNewProjectData())); + _controller->ChangeState( + std::shared_ptr(new UIStateNewProjectData())); } -void FormMain::on_pushButton_clicked() -{ +void FormMain::on_pushButton_clicked() {} -} - -void FormMain::on_listWidget_itemSelectionChanged() -{ - -} +void FormMain::on_listWidget_itemSelectionChanged() {} -void FormMain::on_pushButton_Recent_clicked() -{ -} +void FormMain::on_pushButton_Recent_clicked() {} -bool FormMain::OpenProject(QString &file){ +bool FormMain::OpenProject(QString& file) { bool ok = false; if (VMTJsonSerializer::isJsonPath(file)) { VMTJsonSerializer json(file); @@ -110,85 +97,81 @@ bool FormMain::OpenProject(QString &file){ VMTProject::GetInstance().GetUndoManager()->Clear(); QFileInfo file_info(file); - VMTProject::GetInstance().GetLocation() = file_info.absoluteDir().absolutePath(); + VMTProject::GetInstance().GetLocation() = + file_info.absoluteDir().absolutePath(); VMTProject::GetInstance().GetName() = file_info.baseName(); return true; } -void FormMain::on_listWidget_doubleClicked(const QModelIndex &index) -{ +void FormMain::on_listWidget_doubleClicked(const QModelIndex& index) { int row = index.row(); - QListWidgetItem *item=ui->listWidget->item(row); - if(item){ + QListWidgetItem* item = ui->listWidget->item(row); + if (item) { QString file = item->text(); - if(OpenProject(file)) - _controller->ChangeState(std::shared_ptr(new UIStateNewProjectData())); + if (OpenProject(file)) + _controller->ChangeState(std::shared_ptr( + new UIStateNewProjectData())); } } -void FormMain::on_listWidget_clicked(const QModelIndex &index) -{ +void FormMain::on_listWidget_clicked(const QModelIndex& index) { int row = index.row(); - QListWidgetItem *item=ui->listWidget->item(row); - if(item){ + QListWidgetItem* item = ui->listWidget->item(row); + if (item) { QString file = item->text(); - if(OpenProject(file)) - _controller->ChangeState(std::shared_ptr(new UIStateNewProjectData())); + if (OpenProject(file)) + _controller->ChangeState(std::shared_ptr( + new UIStateNewProjectData())); } } -void FormMain::on_button_open_clicked() -{ +void FormMain::on_button_open_clicked() { QFileDialog dlg; dlg.setWindowTitle("Open Virtual Machine Project"); dlg.setAcceptMode(QFileDialog::AcceptOpen); dlg.setFileMode(QFileDialog::ExistingFile); dlg.setViewMode(QFileDialog::List); QStringList filters; - filters <<"Any files (*)" - <<"Turing machine files (*.jdtp)" - <<"JSON projects (*.vmt.json *.json)"; - dlg.setOption(QFileDialog::HideNameFilterDetails,false); + filters << "Any files (*)" + << "Turing machine files (*.jdtp)" + << "JSON projects (*.vmt.json *.json)"; + dlg.setOption(QFileDialog::HideNameFilterDetails, false); dlg.setNameFilters(filters); dlg.resize(QApplication::primaryScreen()->availableSize()); - if(dlg.exec()==QDialog::Accepted) - { - QStringList fileName=dlg.selectedFiles(); + if (dlg.exec() == QDialog::Accepted) { + QStringList fileName = dlg.selectedFiles(); - if(fileName.length()>0){ + if (fileName.length() > 0) { QString file = fileName[0]; - if(file.length()>0){ - if(OpenProject(file)){ - if( VMTProject::GetInstance().GetUndoManager()) + if (file.length() > 0) { + if (OpenProject(file)) { + if (VMTProject::GetInstance().GetUndoManager()) VMTProject::GetInstance().GetUndoManager()->Clear(); Configuration::GetInstance().AddRecentProject(file); Configuration::GetInstance().Save(); - _controller->ChangeState(std::shared_ptr(new UIStateNewProjectData())); + _controller->ChangeState( + std::shared_ptr( + new UIStateNewProjectData())); } } } } } -void FormMain::on_toolButton_clicked() -{ - if( VMTProject::GetInstance().GetUndoManager()) +void FormMain::on_toolButton_clicked() { + if (VMTProject::GetInstance().GetUndoManager()) VMTProject::GetInstance().GetUndoManager()->Clear(); VMTProject::GetInstance().GetName() = "MyExercise"; - VMTProject::GetInstance().GetLocation() = Configuration::GetInstance().GetDefaultLocation(); + VMTProject::GetInstance().GetLocation() = + Configuration::GetInstance().GetDefaultLocation(); QString alphabit(""); VMTProject::GetInstance().GetAlphabit()->ReplaceString(alphabit); _controller->ChangeState(std::make_shared()); - } -void FormMain::on_toolButton_2_triggered([[maybe_unused]] QAction *arg1) -{ - -} +void FormMain::on_toolButton_2_triggered([[maybe_unused]] QAction* arg1) {} -void FormMain::on_toolButton_2_clicked() -{ +void FormMain::on_toolButton_2_clicked() { QDesktopServices::openUrl(QUrl("https://mai.ru/")); } diff --git a/VirtualTuringMachine/formmain.h b/VirtualTuringMachine/formmain.h old mode 100755 new mode 100644 index a19b69d..a69fed6 --- a/VirtualTuringMachine/formmain.h +++ b/VirtualTuringMachine/formmain.h @@ -1,8 +1,9 @@ #ifndef FORMMAIN_H #define FORMMAIN_H -#include #include +#include + #include "formbase.h" namespace Ui { @@ -11,31 +12,31 @@ class FormMain; class MainWindow; -class FormMain : public QWidget, public FormBase -{ +class FormMain : public QWidget, public FormBase { Q_OBJECT -public: - explicit FormMain(QWidget *parent = 0); + public: + explicit FormMain(QWidget* parent = 0); void BeforeChange(std::shared_ptr state_data) override; void AfterUndo(std::shared_ptr state_data) override; ~FormMain(); -private: - Ui::FormMain *ui; - void addItem(QListWidget *listWidget, QString iconPath, QString text,int data); - bool OpenProject(QString &file); -private slots: + private: + Ui::FormMain* ui; + void addItem(QListWidget* listWidget, QString iconPath, QString text, + int data); + bool OpenProject(QString& file); + private slots: void on_button_new_clicked(); void on_pushButton_clicked(); void on_listWidget_itemSelectionChanged(); void on_pushButton_Recent_clicked(); - void on_listWidget_doubleClicked(const QModelIndex &index); - void on_listWidget_clicked(const QModelIndex &index); + void on_listWidget_doubleClicked(const QModelIndex& index); + void on_listWidget_clicked(const QModelIndex& index); void on_button_open_clicked(); void on_toolButton_clicked(); - void on_toolButton_2_triggered(QAction *arg1); + void on_toolButton_2_triggered(QAction* arg1); void on_toolButton_2_clicked(); }; -#endif // FORMMAIN_H +#endif // FORMMAIN_H diff --git a/VirtualTuringMachine/formnewmachine.cpp b/VirtualTuringMachine/formnewmachine.cpp old mode 100755 new mode 100644 index 6db7905..b39faf4 --- a/VirtualTuringMachine/formnewmachine.cpp +++ b/VirtualTuringMachine/formnewmachine.cpp @@ -1,16 +1,16 @@ #include "formnewmachine.h" + +#include + +#include "screentools.h" #include "ui_formnewmachine.h" #include "uistateeditormachine.h" #include "uistatenewmachine.h" #include "vmtproject.h" -#include -#include "screentools.h" #include "vmttheme.h" -FormNewMachine::FormNewMachine(QWidget *parent) : - QWidget(parent), - ui(new Ui::FormNewMachine) -{ +FormNewMachine::FormNewMachine(QWidget* parent) + : QWidget(parent), ui(new Ui::FormNewMachine) { ui->setupUi(this); VmtTheme::polishWidgetTree(this); @@ -25,10 +25,10 @@ FormNewMachine::FormNewMachine(QWidget *parent) : ui->list_machines->setStyleSheet(VmtTheme::listSurfaceStyle()); VmtTheme::applyIconToolBar(ui->frame_2); } -void FormNewMachine::FillList(){ +void FormNewMachine::FillList() { QStringList list; - for(auto &m: VMTProject::GetInstance().GetMachines()){ + for (auto& m : VMTProject::GetInstance().GetMachines()) { list << m->GetName(); } _list_model.setStringList(list); @@ -36,121 +36,118 @@ void FormNewMachine::FillList(){ ui->list_machines->setModel(&_list_model); } -FormNewMachine::~FormNewMachine() -{ - delete ui; -} - -void FormNewMachine::BeforeChange(std::shared_ptr state_data){ - - - UIStateNewMachineData *data = dynamic_cast(state_data.get()); - if(data){ -// qDebug() << "Selected machine:" << ui->text_machine_name->text(); - VMTProject::GetInstance().GetCurrentMachineName() = ui->text_machine_name->text(); - - if(!VMTProject::GetInstance().GetMachine(VMTProject::GetInstance().GetCurrentMachineName())) - { - VMTProject::GetInstance().GetMachines().push_back( - std::shared_ptr( - new VMTComplexMachine(VMTProject::GetInstance().GetCurrentMachineName(), - VMTProject::GetInstance().GetAlphabit()))); - // qDebug() << "Machine added:" << VMTProject::GetInstance().GetCurrentMachineName(); - } //else - // qDebug() << "Machine selected:" << VMTProject::GetInstance().GetCurrentMachineName(); - +FormNewMachine::~FormNewMachine() { delete ui; } + +void FormNewMachine::BeforeChange(std::shared_ptr state_data) { + UIStateNewMachineData* data = + dynamic_cast(state_data.get()); + if (data) { + // qDebug() << "Selected machine:" << + // ui->text_machine_name->text(); + VMTProject::GetInstance().GetCurrentMachineName() = + ui->text_machine_name->text(); + + if (!VMTProject::GetInstance().GetMachine( + VMTProject::GetInstance().GetCurrentMachineName())) { + VMTProject::GetInstance().GetMachines().push_back( + std::shared_ptr(new VMTComplexMachine( + VMTProject::GetInstance().GetCurrentMachineName(), + VMTProject::GetInstance().GetAlphabit()))); + // qDebug() << "Machine added:" << + // VMTProject::GetInstance().GetCurrentMachineName(); + } // else + // qDebug() << "Machine selected:" << + // VMTProject::GetInstance().GetCurrentMachineName(); } - - } void FormNewMachine::AfterUndo(std::shared_ptr state_data) { - UIStateNewMachineData *data = dynamic_cast(state_data.get()); - if(data){ - ui->text_machine_name->setText(VMTProject::GetInstance().GetCurrentMachineName()); - Check(); + UIStateNewMachineData* data = + dynamic_cast(state_data.get()); + if (data) { + ui->text_machine_name->setText( + VMTProject::GetInstance().GetCurrentMachineName()); + Check(); } } -void FormNewMachine::OnLoaded(){ - if(VMTProject::GetInstance().GetMachines().size()==0){ - VMTProject::GetInstance().GetCurrentMachineName() =""; +void FormNewMachine::OnLoaded() { + if (VMTProject::GetInstance().GetMachines().size() == 0) { + VMTProject::GetInstance().GetCurrentMachineName() = ""; ui->text_machine_name->setText("Main machine"); - } else - if(VMTProject::GetInstance().GetCurrentMachineName().length()==0){ - if(VMTProject::GetInstance().GetMachines().size()>0){ - VMTProject::GetInstance().GetCurrentMachineName() = VMTProject::GetInstance().GetMachines()[0]->GetName(); - ui->text_machine_name->setText(VMTProject::GetInstance().GetCurrentMachineName()); + } else if (VMTProject::GetInstance().GetCurrentMachineName().length() == + 0) { + if (VMTProject::GetInstance().GetMachines().size() > 0) { + VMTProject::GetInstance().GetCurrentMachineName() = + VMTProject::GetInstance().GetMachines()[0]->GetName(); + ui->text_machine_name->setText( + VMTProject::GetInstance().GetCurrentMachineName()); } else { - VMTProject::GetInstance().GetCurrentMachineName() =""; - + VMTProject::GetInstance().GetCurrentMachineName() = ""; } } else { - ui->text_machine_name->setText(VMTProject::GetInstance().GetCurrentMachineName()); + ui->text_machine_name->setText( + VMTProject::GetInstance().GetCurrentMachineName()); } Check(); - } -void FormNewMachine::on_button_ok_clicked() -{ - this->_controller->ChangeState(std::shared_ptr(new UIStateEditorMachineData())); +void FormNewMachine::on_button_ok_clicked() { + this->_controller->ChangeState(std::shared_ptr( + new UIStateEditorMachineData())); } -void FormNewMachine::Check(){ +void FormNewMachine::Check() { QString name = ui->text_machine_name->text(); - if(name.length()<1){ - //ui->button_ok->setText(QString("Create or select ")); + if (name.length() < 1) { + // ui->button_ok->setText(QString("Create or select ")); ui->button_delete_2->setVisible(false); ui->button_ok_2->setVisible(false); } else { - if(!VMTProject::GetInstance().GetMachine(name)){ - ui->button_ok_2->setVisible(true); - ui->button_delete_2->setVisible(false); + if (!VMTProject::GetInstance().GetMachine(name)) { + ui->button_ok_2->setVisible(true); + ui->button_delete_2->setVisible(false); // ui->button_ok->setText(QString("Create ")); - } - else { + } else { ui->button_ok_2->setVisible(true); ui->button_delete_2->setVisible(true); - // ui->button_ok->setText(QString("Select ")); + // ui->button_ok->setText(QString("Select ")); } } } -void FormNewMachine::on_text_machine_name_textChanged(const QString &) -{ +void FormNewMachine::on_text_machine_name_textChanged(const QString&) { Check(); } -void FormNewMachine::on_list_machines_clicked(const QModelIndex &index) -{ - ui->text_machine_name->setText(index.data(Qt::DisplayRole ).toString()); +void FormNewMachine::on_list_machines_clicked(const QModelIndex& index) { + ui->text_machine_name->setText(index.data(Qt::DisplayRole).toString()); Check(); } -void FormNewMachine::on_button_delete_clicked() -{ - QMessageBox::StandardButton resBtn = QMessageBox::question( this, "VMT", - "This operation will delete selected complex machine. Are you sure?", - QMessageBox::No | QMessageBox::Yes, - QMessageBox::No); +void FormNewMachine::on_button_delete_clicked() { + QMessageBox::StandardButton resBtn = QMessageBox::question( + this, "VMT", + "This operation will delete selected complex machine. Are you sure?", + QMessageBox::No | QMessageBox::Yes, QMessageBox::No); if (resBtn != QMessageBox::Yes) { - } else { QString name(ui->text_machine_name->text()); VMTProject::GetInstance().GetUndoManager()->Clear(); - auto machine= VMTProject::GetInstance().GetMachine(name); + auto machine = VMTProject::GetInstance().GetMachine(name); - if(machine){ + if (machine) { qDebug() << "Erace referencr to machine"; - for(auto cm:VMTProject::GetInstance().GetMachines()){ + for (auto cm : VMTProject::GetInstance().GetMachines()) { qDebug() << "Inside:" << cm->GetName(); cm->RemoveComplexMachine(machine); } qDebug() << "Erace machine from list"; - for(auto iterator = VMTProject::GetInstance().GetMachines().begin();iterator!=VMTProject::GetInstance().GetMachines().end();iterator++){ - if(machine==*iterator) - { + for (auto iterator = + VMTProject::GetInstance().GetMachines().begin(); + iterator != VMTProject::GetInstance().GetMachines().end(); + iterator++) { + if (machine == *iterator) { VMTProject::GetInstance().GetMachines().erase(iterator); ui->text_machine_name->setText(QString("")); machine.reset(); @@ -162,20 +159,12 @@ void FormNewMachine::on_button_delete_clicked() } } } - } -void FormNewMachine::on_text_machine_name_returnPressed() -{ +void FormNewMachine::on_text_machine_name_returnPressed() {} -} - -void FormNewMachine::on_button_ok_2_clicked() -{ - on_button_ok_clicked(); -} +void FormNewMachine::on_button_ok_2_clicked() { on_button_ok_clicked(); } -void FormNewMachine::on_button_delete_2_clicked() -{ - on_button_delete_clicked(); +void FormNewMachine::on_button_delete_2_clicked() { + on_button_delete_clicked(); } diff --git a/VirtualTuringMachine/formnewmachine.h b/VirtualTuringMachine/formnewmachine.h old mode 100755 new mode 100644 index 2aa127e..e448021 --- a/VirtualTuringMachine/formnewmachine.h +++ b/VirtualTuringMachine/formnewmachine.h @@ -1,29 +1,29 @@ #ifndef FORMNEWMACHINE_H #define FORMNEWMACHINE_H -#include "formbase.h" -#include #include +#include + +#include "formbase.h" namespace Ui { class FormNewMachine; } -class FormNewMachine : public QWidget, public FormBase -{ +class FormNewMachine : public QWidget, public FormBase { Q_OBJECT -public: - explicit FormNewMachine(QWidget *parent = 0); + public: + explicit FormNewMachine(QWidget* parent = 0); ~FormNewMachine(); void BeforeChange(std::shared_ptr state_data) override; void AfterUndo(std::shared_ptr state_data) override; void OnLoaded() override; -private slots: + private slots: void on_button_ok_clicked(); - void on_text_machine_name_textChanged(const QString &arg1); + void on_text_machine_name_textChanged(const QString& arg1); - void on_list_machines_clicked(const QModelIndex &index); + void on_list_machines_clicked(const QModelIndex& index); void on_button_delete_clicked(); @@ -33,12 +33,12 @@ private slots: void on_button_delete_2_clicked(); -private: + private: QStringListModel _list_model; - Ui::FormNewMachine *ui; + Ui::FormNewMachine* ui; void FillList(); void Check(); }; -#endif // FORMNEWMACHINE_H +#endif // FORMNEWMACHINE_H diff --git a/VirtualTuringMachine/formnewproject.cpp b/VirtualTuringMachine/formnewproject.cpp old mode 100755 new mode 100644 index 6b218fb..0b6e5b8 --- a/VirtualTuringMachine/formnewproject.cpp +++ b/VirtualTuringMachine/formnewproject.cpp @@ -1,36 +1,37 @@ #include "formnewproject.h" -#include "ui_formnewproject.h" + +#include #include -#include "uistatenewproject.h" -#include "uistatenewmachine.h" -#include #include -#include "vmtproject.h" -#include "screentools.h" -#include "vmttheme.h" -#include "VMTJsonSerializer.h" #include #include -#include #include +#include -FormNewProject::FormNewProject(QWidget *parent) : - QWidget(parent), - ui(new Ui::FormNewProject) -{ +#include "VMTJsonSerializer.h" +#include "screentools.h" +#include "ui_formnewproject.h" +#include "uistatenewmachine.h" +#include "uistatenewproject.h" +#include "vmtproject.h" +#include "vmttheme.h" + +FormNewProject::FormNewProject(QWidget* parent) + : QWidget(parent), ui(new Ui::FormNewProject) { qDebug() << "Form New project construcor"; ui->setupUi(this); VmtTheme::applyThemedWidgets(this); VmtTheme::applyIconToolBar(ui->frame); - //ui->combo_project_type->addItem("Turing machine project"); - //ui->combo_project_type->setCurrentIndex(0); - + // ui->combo_project_type->addItem("Turing machine project"); + // ui->combo_project_type->setCurrentIndex(0); ui->text_project_location->setText(VMTProject::GetInstance().GetLocation()); ui->text_project_name->setText(VMTProject::GetInstance().GetName()); - ui->text_alphabit->setText(VMTProject::GetInstance().GetAlphabit()->ToString());//data->alphabit); + ui->text_alphabit->setText(VMTProject::GetInstance() + .GetAlphabit() + ->ToString()); // data->alphabit); - if(VMTProject::GetInstance().GetExercise()){ + if (VMTProject::GetInstance().GetExercise()) { ui->text_alphabit->setEnabled(false); ui->text_project_name->setEnabled(false); ui->button_z2->setEnabled(false); @@ -55,7 +56,8 @@ FormNewProject::FormNewProject(QWidget *parent) : auto* extras = new QVBoxLayout(); auto* saveJson = new QPushButton(tr("Save as JSON…"), this); saveJson->setStyleSheet(VmtTheme::primaryButtonStyle()); - connect(saveJson, &QPushButton::clicked, this, &FormNewProject::on_save_json_clicked); + connect(saveJson, &QPushButton::clicked, this, + &FormNewProject::on_save_json_clicked); extras->addWidget(saveJson); ui->verticalLayout_2->addLayout(extras); @@ -63,8 +65,7 @@ FormNewProject::FormNewProject(QWidget *parent) : Check(); } -void FormNewProject::on_save_json_clicked() -{ +void FormNewProject::on_save_json_clicked() { Save(); QString path = VMTProject::GetInstance().GetLocation(); path += QLatin1Char('/'); @@ -72,11 +73,9 @@ void FormNewProject::on_save_json_clicked() if (!path.endsWith(QLatin1String(".json"), Qt::CaseInsensitive)) { path += QLatin1String(".vmt.json"); } - path = QFileDialog::getSaveFileName( - this, - tr("Save JSON project"), - path, - tr("JSON projects (*.vmt.json *.json)")); + path = + QFileDialog::getSaveFileName(this, tr("Save JSON project"), path, + tr("JSON projects (*.vmt.json *.json)")); if (path.isEmpty()) return; VMTJsonSerializer json(path); if (json.serialize(&VMTProject::GetInstance())) { @@ -85,130 +84,117 @@ void FormNewProject::on_save_json_clicked() } } -void FormNewProject::Save(){ +void FormNewProject::Save() { VMTProject::GetInstance().GetName() = ui->text_project_name->text(); VMTProject::GetInstance().GetLocation() = ui->text_project_location->text(); - VMTProject::GetInstance().GetAlphabit()->ReplaceString(ui->text_alphabit->toPlainText()); - for(auto m: VMTProject::GetInstance().GetMachines()) m->ChangeAlphabit(VMTProject::GetInstance().GetAlphabit()); - - - + VMTProject::GetInstance().GetAlphabit()->ReplaceString( + ui->text_alphabit->toPlainText()); + for (auto m : VMTProject::GetInstance().GetMachines()) + m->ChangeAlphabit(VMTProject::GetInstance().GetAlphabit()); } -void FormNewProject::BeforeChange(std::shared_ptr state_data){ - - - UIStateNewProjectData *data = dynamic_cast(state_data.get()); - if(data){ +void FormNewProject::BeforeChange(std::shared_ptr state_data) { + UIStateNewProjectData* data = + dynamic_cast(state_data.get()); + if (data) { state_data->SetName(ui->text_project_name->text()); Save(); } - - } void FormNewProject::AfterUndo(std::shared_ptr state_data) { - UIStateNewProjectData *data = dynamic_cast(state_data.get()); - if(data){ - ui->text_project_name->setText(VMTProject::GetInstance().GetName());//data->name); - ui->text_project_location->setText(VMTProject::GetInstance().GetLocation());//data->location); - ui->text_alphabit->setText(VMTProject::GetInstance().GetAlphabit()->ToString());//data->alphabit); + UIStateNewProjectData* data = + dynamic_cast(state_data.get()); + if (data) { + ui->text_project_name->setText( + VMTProject::GetInstance().GetName()); // data->name); + ui->text_project_location->setText( + VMTProject::GetInstance().GetLocation()); // data->location); + ui->text_alphabit->setText(VMTProject::GetInstance() + .GetAlphabit() + ->ToString()); // data->alphabit); Check(); } } -FormNewProject::~FormNewProject(){ - delete ui; -} - - +FormNewProject::~FormNewProject() { delete ui; } -void FormNewProject::on_button_z2_clicked() -{ +void FormNewProject::on_button_z2_clicked() { ui->text_alphabit->setText(" 01"); } -void FormNewProject::on_button_z3_clicked() -{ +void FormNewProject::on_button_z3_clicked() { ui->text_alphabit->setText(" 012"); } -void FormNewProject::on_button_z4_clicked() -{ +void FormNewProject::on_button_z4_clicked() { ui->text_alphabit->setText(" 01234567"); } -void FormNewProject::on_button_z10_clicked() -{ +void FormNewProject::on_button_z10_clicked() { ui->text_alphabit->setText(" 0123456789"); } -void FormNewProject::on_button_z16_clicked() -{ +void FormNewProject::on_button_z16_clicked() { ui->text_alphabit->setText(" 0123456789ABCDEF"); } -void FormNewProject::on_button_z80_clicked() -{ - ui->text_alphabit->setText(" 0123456789-+=_~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()/\\"); +void FormNewProject::on_button_z80_clicked() { + ui->text_alphabit->setText( + " 0123456789-+=_~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@" + "#$%^&*()/\\"); } -void FormNewProject::on_button_project_location_clicked() -{ +void FormNewProject::on_button_project_location_clicked() { QFileDialog dlg; dlg.setWindowTitle("Project place"); dlg.setAcceptMode(QFileDialog::AcceptOpen); - //dlg.setLabelText(QFileDialog::LookIn,"OPEN"); + // dlg.setLabelText(QFileDialog::LookIn,"OPEN"); dlg.setFileMode(QFileDialog::Directory); dlg.setViewMode(QFileDialog::List); dlg.resize(QApplication::primaryScreen()->availableSize()); - if(dlg.exec()==QDialog::Accepted) - { - //QString file = QFileDialog::getSaveFileName(this,"Export to PNG",VMTProject::GetInstance().GetLocation(),QString("png")); - QStringList fileName=dlg.selectedFiles(); + if (dlg.exec() == QDialog::Accepted) { + // QString file = QFileDialog::getSaveFileName(this,"Export to + // PNG",VMTProject::GetInstance().GetLocation(),QString("png")); + QStringList fileName = dlg.selectedFiles(); - //QString file = QFileDialog::getExistingDirectory(); - if(fileName.length()>0){ + // QString file = QFileDialog::getExistingDirectory(); + if (fileName.length() > 0) { QString file = fileName[0]; - if(file.size()>0) - ui->text_project_location->setText(file); + if (file.size() > 0) ui->text_project_location->setText(file); } } - } - - -void FormNewProject::on_text_alphabit_textChanged() -{ +void FormNewProject::on_text_alphabit_textChanged() { QString alphabit = ui->text_alphabit->toPlainText(); std::set alphabit_set; bool changed = false; - for(QChar a: alphabit) alphabit_set.insert(a); - for(int i = 0; i < static_cast(alphabit.size());){ - if(alphabit_set.find(alphabit[i])!=alphabit_set.end()){ + for (QChar a : alphabit) alphabit_set.insert(a); + for (int i = 0; i < static_cast(alphabit.size());) { + if (alphabit_set.find(alphabit[i]) != alphabit_set.end()) { alphabit_set.erase(alphabit[i]); i++; } else { - alphabit.remove(i,1); + alphabit.remove(i, 1); changed = true; } } - if(changed) ui->text_alphabit->setText(alphabit); + if (changed) ui->text_alphabit->setText(alphabit); Check(); - } -void FormNewProject::Check(){ +void FormNewProject::Check() { QString alphabit = ui->text_alphabit->toPlainText(); - if(alphabit.length()<2){ - ui->button_create->setVisible(false);//setDisabled(true); - } else ui->button_create->setVisible(true); + if (alphabit.length() < 2) { + ui->button_create->setVisible(false); // setDisabled(true); + } else + ui->button_create->setVisible(true); } -void FormNewProject::on_button_create_clicked() -{ - this->_controller->ChangeState(std::shared_ptr(new UIStateNewMachineData())); +void FormNewProject::on_button_create_clicked() { + this->_controller->ChangeState( + std::shared_ptr(new UIStateNewMachineData())); } diff --git a/VirtualTuringMachine/formnewproject.h b/VirtualTuringMachine/formnewproject.h old mode 100755 new mode 100644 index 5a7f28d..ef50300 --- a/VirtualTuringMachine/formnewproject.h +++ b/VirtualTuringMachine/formnewproject.h @@ -2,6 +2,7 @@ #define FORMNEWPROJECT_H #include + #include "formbase.h" namespace Ui { @@ -10,18 +11,16 @@ class FormNewProject; class MainWindow; - -class FormNewProject : public QWidget, public FormBase -{ +class FormNewProject : public QWidget, public FormBase { Q_OBJECT -public: - explicit FormNewProject(QWidget *parent = 0); + public: + explicit FormNewProject(QWidget* parent = 0); ~FormNewProject(); void BeforeChange(std::shared_ptr state_data) override; void AfterUndo(std::shared_ptr state_data) override; void Save(); -private slots: + private slots: void on_button_z2_clicked(); void on_button_z3_clicked(); @@ -42,10 +41,10 @@ private slots: void on_save_json_clicked(); -private: - Ui::FormNewProject *ui; + private: + Ui::FormNewProject* ui; void Check(); }; -#endif // FORMNEWPROJECT_H +#endif // FORMNEWPROJECT_H diff --git a/VirtualTuringMachine/formwarning.cpp b/VirtualTuringMachine/formwarning.cpp old mode 100755 new mode 100644 index 880cfbd..0945504 --- a/VirtualTuringMachine/formwarning.cpp +++ b/VirtualTuringMachine/formwarning.cpp @@ -1,27 +1,16 @@ #include "formwarning.h" + #include "ui_formwarning.h" -FormWarning::FormWarning(StateController *controller,QWidget *parent) : - QWidget(parent), - ui(new Ui::FormWarning), - _controller(controller) -{ +FormWarning::FormWarning(StateController* controller, QWidget* parent) + : QWidget(parent), ui(new Ui::FormWarning), _controller(controller) { ui->setupUi(this); } +FormWarning::~FormWarning() { delete ui; } +void FormWarning::on_button_ok_clicked() { _controller->HideWarning(true); } -FormWarning::~FormWarning() -{ - delete ui; -} - -void FormWarning::on_button_ok_clicked() -{ - _controller->HideWarning(true); -} - -void FormWarning::on_button_cancel_clicked() -{ - _controller->HideWarning(false); +void FormWarning::on_button_cancel_clicked() { + _controller->HideWarning(false); } diff --git a/VirtualTuringMachine/formwarning.h b/VirtualTuringMachine/formwarning.h old mode 100755 new mode 100644 index 8f3f135..ed79e19 --- a/VirtualTuringMachine/formwarning.h +++ b/VirtualTuringMachine/formwarning.h @@ -2,28 +2,28 @@ #define FORMWARNING_H #include + #include "statecontroller.h" namespace Ui { class FormWarning; } -class FormWarning : public QWidget -{ +class FormWarning : public QWidget { Q_OBJECT -public: - explicit FormWarning(StateController *controller,QWidget *parent = 0); + public: + explicit FormWarning(StateController* controller, QWidget* parent = 0); ~FormWarning(); -private slots: + private slots: void on_button_ok_clicked(); void on_button_cancel_clicked(); -private: - Ui::FormWarning *ui; - StateController *_controller; + private: + Ui::FormWarning* ui; + StateController* _controller; }; -#endif // FORMWARNING_H +#endif // FORMWARNING_H diff --git a/VirtualTuringMachine/interfaces/IVMDebugEnabler.h b/VirtualTuringMachine/interfaces/IVMDebugEnabler.h old mode 100755 new mode 100644 index 2158ce8..d72dbc7 --- a/VirtualTuringMachine/interfaces/IVMDebugEnabler.h +++ b/VirtualTuringMachine/interfaces/IVMDebugEnabler.h @@ -3,20 +3,13 @@ #include "ivmtdebuger.h" -class IVMDebugEnabler -{ +class IVMDebugEnabler { + public: + IVMDebugEnabler() {} -public: - IVMDebugEnabler() { - - } - - virtual ~IVMDebugEnabler() { - - } - - virtual void DisableDebug() =0; - virtual void EnableDebug(IVMTDebuger* debuger) =0; + virtual ~IVMDebugEnabler() {} + virtual void DisableDebug() = 0; + virtual void EnableDebug(IVMTDebuger* debuger) = 0; }; -#endif // !defined(EA_B29202CE_6D51_4b60_8631_FEBF36244D66__INCLUDED_) +#endif // !defined(EA_B29202CE_6D51_4b60_8631_FEBF36244D66__INCLUDED_) diff --git a/VirtualTuringMachine/interfaces/IVMTAction.h b/VirtualTuringMachine/interfaces/IVMTAction.h old mode 100755 new mode 100644 index 2504093..653855f --- a/VirtualTuringMachine/interfaces/IVMTAction.h +++ b/VirtualTuringMachine/interfaces/IVMTAction.h @@ -2,32 +2,30 @@ #if !defined(EA_ACB08CBC_DDDD_4b91_9DC8_9C9BCA4CF6F1__INCLUDED_) #define EA_ACB08CBC_DDDD_4b91_9DC8_9C9BCA4CF6F1__INCLUDED_ -#include "IVMTAlphabitSource.h" -#include "uicanvas.h" #include #include #include -class IVMTAction -{ -protected: - std::mutex _mutex; -public: - IVMTAction() { - - } - - virtual ~IVMTAction() { +#include "IVMTAlphabitSource.h" +#include "uicanvas.h" - } +class IVMTAction { + protected: + std::mutex _mutex; + public: + IVMTAction() {} - virtual void Cancel(IVMTEnvironment *environment) =0; - virtual void Enable(IVMTEnvironment *environment) =0; - virtual bool OnMouseMoved(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) =0; - virtual bool OnMousePressed(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) =0; - virtual bool OnMouseReleased(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) =0; - virtual void Paint(UICanvas& canvas, const QRect &rect) =0; + virtual ~IVMTAction() {} + virtual void Cancel(IVMTEnvironment* environment) = 0; + virtual void Enable(IVMTEnvironment* environment) = 0; + virtual bool OnMouseMoved(IVMTEnvironment* environment, + const QPoint& screen, const QPoint& real) = 0; + virtual bool OnMousePressed(IVMTEnvironment* environment, + const QPoint& screen, const QPoint& real) = 0; + virtual bool OnMouseReleased(IVMTEnvironment* environment, + const QPoint& screen, const QPoint& real) = 0; + virtual void Paint(UICanvas& canvas, const QRect& rect) = 0; }; -#endif // !defined(EA_ACB08CBC_DDDD_4b91_9DC8_9C9BCA4CF6F1__INCLUDED_) +#endif // !defined(EA_ACB08CBC_DDDD_4b91_9DC8_9C9BCA4CF6F1__INCLUDED_) diff --git a/VirtualTuringMachine/interfaces/IVMTActionController.h b/VirtualTuringMachine/interfaces/IVMTActionController.h old mode 100755 new mode 100644 index a352a39..18fe1a1 --- a/VirtualTuringMachine/interfaces/IVMTActionController.h +++ b/VirtualTuringMachine/interfaces/IVMTActionController.h @@ -3,15 +3,14 @@ #include #include -#include "IVMTAction.h" #include -class IVMTActionController -{ +#include "IVMTAction.h" -public: - virtual void SetAction(std::shared_ptr action) =0; +class IVMTActionController { + public: + virtual void SetAction(std::shared_ptr action) = 0; virtual ~IVMTActionController() = default; }; -#endif // !defined(EA_88586C2F_1B51_464b_A272_C70BB4980D1F__INCLUDED_) +#endif // !defined(EA_88586C2F_1B51_464b_A272_C70BB4980D1F__INCLUDED_) diff --git a/VirtualTuringMachine/interfaces/IVMTAlphabitSource.h b/VirtualTuringMachine/interfaces/IVMTAlphabitSource.h old mode 100755 new mode 100644 index c192a05..74e40fd --- a/VirtualTuringMachine/interfaces/IVMTAlphabitSource.h +++ b/VirtualTuringMachine/interfaces/IVMTAlphabitSource.h @@ -1,25 +1,26 @@ #if !defined(EA_E676FEFF_500A_4f44_9F83_0DB87EFB6E44__INCLUDED_) #define EA_E676FEFF_500A_4f44_9F83_0DB87EFB6E44__INCLUDED_ +#include #include + #include "VMTAlphabit.h" -#include class QPixmap; class IVMTEnvironment; -class IVMTAlphabitSource -{ - -public: - virtual std::shared_ptr GetAlphabit() =0; +class IVMTAlphabitSource { + public: + virtual std::shared_ptr GetAlphabit() = 0; virtual bool IsSingleChar() = 0; - virtual bool IsEnabled(char sign) =0; + virtual bool IsEnabled(char sign) = 0; virtual QPixmap* GetImage() = 0; virtual const QString& GetMessage() = 0; - virtual void SetEnable(char sign, bool enable,IVMTEnvironment* environment) =0; - virtual void SetDisableAllExclude([[maybe_unused]] char sign, - [[maybe_unused]] IVMTEnvironment* environment) {}; + virtual void SetEnable(char sign, bool enable, + IVMTEnvironment* environment) = 0; + virtual void SetDisableAllExclude( + [[maybe_unused]] char sign, + [[maybe_unused]] IVMTEnvironment* environment) {}; virtual ~IVMTAlphabitSource() = default; }; -#endif // !defined(EA_E676FEFF_500A_4f44_9F83_0DB87EFB6E44__INCLUDED_) +#endif // !defined(EA_E676FEFF_500A_4f44_9F83_0DB87EFB6E44__INCLUDED_) diff --git a/VirtualTuringMachine/interfaces/IVMTCalculatorCallback.h b/VirtualTuringMachine/interfaces/IVMTCalculatorCallback.h old mode 100755 new mode 100644 index 68117e6..fb116f9 --- a/VirtualTuringMachine/interfaces/IVMTCalculatorCallback.h +++ b/VirtualTuringMachine/interfaces/IVMTCalculatorCallback.h @@ -1,20 +1,13 @@ #if !defined(EA_6B80DBEC_F1C7_4381_B9D1_3CCD36BEDBEF__INCLUDED_) #define EA_6B80DBEC_F1C7_4381_B9D1_3CCD36BEDBEF__INCLUDED_ -class IVMTCalculatorCallback -{ +class IVMTCalculatorCallback { + public: + IVMTCalculatorCallback() {} -public: - IVMTCalculatorCallback() { - - } - - virtual ~IVMTCalculatorCallback() { - - } - - virtual long GetCalculatorValue() =0; - virtual void SetCalculatorValue(long value) =0; + virtual ~IVMTCalculatorCallback() {} + virtual long GetCalculatorValue() = 0; + virtual void SetCalculatorValue(long value) = 0; }; -#endif // !defined(EA_6B80DBEC_F1C7_4381_B9D1_3CCD36BEDBEF__INCLUDED_) +#endif // !defined(EA_6B80DBEC_F1C7_4381_B9D1_3CCD36BEDBEF__INCLUDED_) diff --git a/VirtualTuringMachine/interfaces/IVMTCompilerCallback.h b/VirtualTuringMachine/interfaces/IVMTCompilerCallback.h old mode 100755 new mode 100644 index a965a30..0812d4c --- a/VirtualTuringMachine/interfaces/IVMTCompilerCallback.h +++ b/VirtualTuringMachine/interfaces/IVMTCompilerCallback.h @@ -1,11 +1,9 @@ #if !defined(EA_9DDAF49E_2963_4518_8DE4_66127756D970__INCLUDED_) #define EA_9DDAF49E_2963_4518_8DE4_66127756D970__INCLUDED_ -class IVMTCompilerCallback -{ - -public: - virtual void OnCompileComplete(bool errors) =0; - virtual ~IVMTCompilerCallback() = default; +class IVMTCompilerCallback { + public: + virtual void OnCompileComplete(bool errors) = 0; + virtual ~IVMTCompilerCallback() = default; }; -#endif // !defined(EA_9DDAF49E_2963_4518_8DE4_66127756D970__INCLUDED_) +#endif // !defined(EA_9DDAF49E_2963_4518_8DE4_66127756D970__INCLUDED_) diff --git a/VirtualTuringMachine/interfaces/IVMTComplexMachineSource.h b/VirtualTuringMachine/interfaces/IVMTComplexMachineSource.h old mode 100755 new mode 100644 index 732a6a4..a8cf5b0 --- a/VirtualTuringMachine/interfaces/IVMTComplexMachineSource.h +++ b/VirtualTuringMachine/interfaces/IVMTComplexMachineSource.h @@ -1,18 +1,16 @@ #if !defined(EA_88018E24_42D5_4480_B5B6_7A9DEF785464__INCLUDED_) #define EA_88018E24_42D5_4480_B5B6_7A9DEF785464__INCLUDED_ +#include "IVMTEnvironment.h" #include "VMTComplexMachine.h" #include "uicanvas.h" -#include "IVMTEnvironment.h" - -class IVMTComplexMachineSource -{ -public: - virtual VMTComplexMachine* GetComplexMachine() =0; - virtual UICanvas* GetDrawContext() =0; - virtual IVMTEnvironment* GetEnvironment() =0; +class IVMTComplexMachineSource { + public: + virtual VMTComplexMachine* GetComplexMachine() = 0; + virtual UICanvas* GetDrawContext() = 0; + virtual IVMTEnvironment* GetEnvironment() = 0; virtual ~IVMTComplexMachineSource() = default; }; -#endif // !defined(EA_88018E24_42D5_4480_B5B6_7A9DEF785464__INCLUDED_) +#endif // !defined(EA_88018E24_42D5_4480_B5B6_7A9DEF785464__INCLUDED_) diff --git a/VirtualTuringMachine/interfaces/IVMTDebugerCallback.h b/VirtualTuringMachine/interfaces/IVMTDebugerCallback.h old mode 100755 new mode 100644 index 6b7d4db..0b99d13 --- a/VirtualTuringMachine/interfaces/IVMTDebugerCallback.h +++ b/VirtualTuringMachine/interfaces/IVMTDebugerCallback.h @@ -3,17 +3,17 @@ #if !defined(EA_10E536BA_6054_438c_B839_CD170B2144CB__INCLUDED_) #define EA_10E536BA_6054_438c_B839_CD170B2144CB__INCLUDED_ -#include "VMTComplexMachine.h" #include "IVMTMachine.h" +#include "VMTComplexMachine.h" -class IVMTDebugerCallback -{ -public: - virtual void AddStack(VMTComplexMachine* machine) =0; - virtual void DebugerFinish() =0; - virtual void DebugerMachineChanged(VMTComplexMachine* complex, IVMTMachine* current) =0; - virtual void RemoveStack(VMTComplexMachine* machine) =0; +class IVMTDebugerCallback { + public: + virtual void AddStack(VMTComplexMachine* machine) = 0; + virtual void DebugerFinish() = 0; + virtual void DebugerMachineChanged(VMTComplexMachine* complex, + IVMTMachine* current) = 0; + virtual void RemoveStack(VMTComplexMachine* machine) = 0; virtual ~IVMTDebugerCallback() = default; }; -#endif // !defined(EA_10E536BA_6054_438c_B839_CD170B2144CB__INCLUDED_) +#endif // !defined(EA_10E536BA_6054_438c_B839_CD170B2144CB__INCLUDED_) diff --git a/VirtualTuringMachine/interfaces/IVMTEnvironment.h b/VirtualTuringMachine/interfaces/IVMTEnvironment.h old mode 100755 new mode 100644 index 6807b3c..806b79b --- a/VirtualTuringMachine/interfaces/IVMTEnvironment.h +++ b/VirtualTuringMachine/interfaces/IVMTEnvironment.h @@ -1,7 +1,6 @@ #if !defined(EA_6C84CC22_6831_40e5_83A8_7296CDE08AAE__INCLUDED_) #define EA_6C84CC22_6831_40e5_83A8_7296CDE08AAE__INCLUDED_ - class IVMTAlphabitSource; class IVMTMachine; class IVMTCalculatorCallback; @@ -11,29 +10,29 @@ class IVMTComplexMachineSource; class VMTComplexMachine; class VMTLine; #include -#include "uicanvas.h" -class IVMTEnvironment -{ +#include "uicanvas.h" -public: - virtual void EnableActionHint(const QString &hint,QPixmap& img) = 0; +class IVMTEnvironment { + public: + virtual void EnableActionHint(const QString& hint, QPixmap& img) = 0; virtual void DisableActionHint() = 0; - virtual void DisableAlphabit() =0; - virtual void DisableCalculator() =0; - virtual void EnableAlphabit(IVMTAlphabitSource* p_Alphabit,const QString& msg,QPixmap &img) =0; - virtual void EnableCalculator(std::shared_ptr machine) =0; - virtual UICanvas& GetGraphics() =0; - virtual std::weak_ptr GetMachine() =0; - virtual void SetMachine(std::shared_ptr machine) =0; - virtual void Repaint(const QRect& rect) =0; + virtual void DisableAlphabit() = 0; + virtual void DisableCalculator() = 0; + virtual void EnableAlphabit(IVMTAlphabitSource* p_Alphabit, + const QString& msg, QPixmap& img) = 0; + virtual void EnableCalculator(std::shared_ptr machine) = 0; + virtual UICanvas& GetGraphics() = 0; + virtual std::weak_ptr GetMachine() = 0; + virtual void SetMachine(std::shared_ptr machine) = 0; + virtual void Repaint(const QRect& rect) = 0; virtual void RepaintThrottled(const QRect& rect) { Repaint(rect); } virtual bool deferTransitionRouting() const { return false; } virtual void setDeferTransitionRouting(bool defer) { (void)defer; } - virtual void MoveInScreen(QPoint &&shift) =0; - virtual void Move(QPoint &&shift) =0; + virtual void MoveInScreen(QPoint&& shift) = 0; + virtual void Move(QPoint&& shift) = 0; virtual void EnableAnimation(bool enable) = 0; virtual ~IVMTEnvironment() = default; }; -#endif // !defined(EA_6C84CC22_6831_40e5_83A8_7296CDE08AAE__INCLUDED_) +#endif // !defined(EA_6C84CC22_6831_40e5_83A8_7296CDE08AAE__INCLUDED_) diff --git a/VirtualTuringMachine/interfaces/IVMTLineObserver.h b/VirtualTuringMachine/interfaces/IVMTLineObserver.h old mode 100755 new mode 100644 index 0ba1f18..91d92bf --- a/VirtualTuringMachine/interfaces/IVMTLineObserver.h +++ b/VirtualTuringMachine/interfaces/IVMTLineObserver.h @@ -1,15 +1,13 @@ #if !defined(EA_7CBC34C2_863E_487a_972A_9FFC94D25030__INCLUDED_) #define EA_7CBC34C2_863E_487a_972A_9FFC94D25030__INCLUDED_ -class IVMTLineObserver -{ +class IVMTLineObserver { + public: + virtual void OnPositionChanged(long position) = 0; + virtual void OnValueChanged(char sign, long position) = 0; + virtual void StartObserve() = 0; + virtual void StopObserve() = 0; -public: - virtual void OnPositionChanged(long position) =0; - virtual void OnValueChanged(char sign, long position) =0; - virtual void StartObserve() =0; - virtual void StopObserve() =0; - - virtual ~IVMTLineObserver() = default; + virtual ~IVMTLineObserver() = default; }; -#endif // !defined(EA_7CBC34C2_863E_487a_972A_9FFC94D25030__INCLUDED_) +#endif // !defined(EA_7CBC34C2_863E_487a_972A_9FFC94D25030__INCLUDED_) diff --git a/VirtualTuringMachine/interfaces/IVMTMachine.h b/VirtualTuringMachine/interfaces/IVMTMachine.h old mode 100755 new mode 100644 index fe79698..1d97e05 --- a/VirtualTuringMachine/interfaces/IVMTMachine.h +++ b/VirtualTuringMachine/interfaces/IVMTMachine.h @@ -5,95 +5,100 @@ class IVMTTransition; class VMTComplexMachine; class UICanvas; -#include -#include +#include #include +#include +#include #include - -#include "vmtundomanager.h" #include "IVMTAlphabitSource.h" #include "IVMTEnvironment.h" #include "VMTLine.h" -#include #include "uicanvas.h" +#include "vmtundomanager.h" -class IVMTMachine -{ -protected: +class IVMTMachine { + protected: ImageType _image_type; -public: + + public: IVMTMachine() = delete; IVMTMachine(ImageType it) : _image_type(it) {}; virtual std::shared_ptr Clone(IVMTEnvironment*) = 0; - virtual ~IVMTMachine() {} + virtual ~IVMTMachine() {} enum MachineType { - MT_LEFT=1, - MT_LEFT_WORD=2, - MT_RIGHT=3, - MT_RIGHT_WORD=4, - MT_WRITE=5, - MT_COPY=6, - MT_START=7, - MT_FINISH=8, - MT_COMPLEX=9, + MT_LEFT = 1, + MT_LEFT_WORD = 2, + MT_RIGHT = 3, + MT_RIGHT_WORD = 4, + MT_WRITE = 5, + MT_COPY = 6, + MT_START = 7, + MT_FINISH = 8, + MT_COMPLEX = 9, NONE }; - virtual std::shared_ptr CreateComplexMachine(IVMTEnvironment*) = 0; + virtual std::shared_ptr CreateComplexMachine( + IVMTEnvironment*) = 0; virtual void Serialize(QDataStream&) = 0; virtual void Deserialize(QDataStream&) = 0; - virtual void AddIncomingTransition(std::weak_ptr transition) =0; - virtual void AddOutgoingTransition(std::weak_ptr transition) =0; + virtual void AddIncomingTransition( + std::weak_ptr transition) = 0; + virtual void AddOutgoingTransition( + std::weak_ptr transition) = 0; - virtual void RemoveIncomingTransition(std::shared_ptr transition) = 0; - virtual void RemoveOutgoingTransition(std::shared_ptr transition) = 0; + virtual void RemoveIncomingTransition( + std::shared_ptr transition) = 0; + virtual void RemoveOutgoingTransition( + std::shared_ptr transition) = 0; - virtual void DoAction(std::shared_ptr line) =0; - virtual const QRect& GetBounds() =0; + virtual void DoAction(std::shared_ptr line) = 0; + virtual const QRect& GetBounds() = 0; virtual QPoint& GetSize() = 0; - virtual const QRect& GetBoundsWithChilds() =0; - virtual const QPoint& GetCenter() =0; - virtual MachineType GetID() =0; - virtual std::weak_ptr GetParent() =0; - virtual ImageType GetImageType() {return _image_type;} - - virtual const std::vector>& GetIncomingTransitions() =0; - virtual const std::vector>& GetOutgoingTransitions() =0; - - virtual const QPoint& GetInputPoint() =0; - virtual const QString& GetMachineName() =0; - virtual const QString& GetName() =0; - virtual const QPoint& GetOutputPoint() =0; + virtual const QRect& GetBoundsWithChilds() = 0; + virtual const QPoint& GetCenter() = 0; + virtual MachineType GetID() = 0; + virtual std::weak_ptr GetParent() = 0; + virtual ImageType GetImageType() { return _image_type; } + + virtual const std::vector>& + GetIncomingTransitions() = 0; + virtual const std::vector>& + GetOutgoingTransitions() = 0; + + virtual const QPoint& GetInputPoint() = 0; + virtual const QString& GetMachineName() = 0; + virtual const QString& GetName() = 0; + virtual const QPoint& GetOutputPoint() = 0; virtual void ChangeAlphabit(std::shared_ptr) {} - virtual IVMTAlphabitSource *GetAlphabitSource() = 0; - - virtual long GetPower() =0; - virtual bool IsAcceptIncoming() =0; - virtual bool IsAcceptOutgoing() =0; - virtual bool IsAlphabit() =0; - virtual bool IsComplex() =0; - virtual bool IsError() =0; - virtual bool IsInside(const QPoint& point) =0; - virtual bool IsPowerCalculator() =0; - virtual bool IsSelected() =0; - - virtual void Move(const QPoint& center,IVMTEnvironment* environment) =0; - virtual void Move(const QPoint&& center,IVMTEnvironment* environment) =0; - virtual void Paint(UICanvas& canvas, const QRect& rect) =0; - virtual void RemoveChilds() =0; - virtual void RemoveIncomingTransition(IVMTTransition* transition) =0; - virtual void RemoveOutgoingTransition(IVMTTransition* transition) =0; + virtual IVMTAlphabitSource* GetAlphabitSource() = 0; + + virtual long GetPower() = 0; + virtual bool IsAcceptIncoming() = 0; + virtual bool IsAcceptOutgoing() = 0; + virtual bool IsAlphabit() = 0; + virtual bool IsComplex() = 0; + virtual bool IsError() = 0; + virtual bool IsInside(const QPoint& point) = 0; + virtual bool IsPowerCalculator() = 0; + virtual bool IsSelected() = 0; + + virtual void Move(const QPoint& center, IVMTEnvironment* environment) = 0; + virtual void Move(const QPoint&& center, IVMTEnvironment* environment) = 0; + virtual void Paint(UICanvas& canvas, const QRect& rect) = 0; + virtual void RemoveChilds() = 0; + virtual void RemoveIncomingTransition(IVMTTransition* transition) = 0; + virtual void RemoveOutgoingTransition(IVMTTransition* transition) = 0; virtual void Update(IVMTEnvironment* environment) = 0; - virtual void SetError(bool error) =0; - virtual void SetParent(std::weak_ptr parent) =0; - virtual void SetPower(long power) =0; - virtual void SetSelected(bool selected) =0; - + virtual void SetError(bool error) = 0; + virtual void SetParent(std::weak_ptr parent) = 0; + virtual void SetPower(long power) = 0; + virtual void SetSelected(bool selected) = 0; }; -#endif // !defined(EA_A202567F_BD4B_438c_AEB5_364C3A649984__INCLUDED_) +#endif // !defined(EA_A202567F_BD4B_438c_AEB5_364C3A649984__INCLUDED_) diff --git a/VirtualTuringMachine/interfaces/IVMTProjectMachineReplacer.h b/VirtualTuringMachine/interfaces/IVMTProjectMachineReplacer.h old mode 100755 new mode 100644 index c53b861..dbf53c4 --- a/VirtualTuringMachine/interfaces/IVMTProjectMachineReplacer.h +++ b/VirtualTuringMachine/interfaces/IVMTProjectMachineReplacer.h @@ -2,12 +2,10 @@ #define EA_2DE1D8E7_CC65_4196_B305_92B0066B2169__INCLUDED_ class VMTComplexMachine; -class IVMTProjectMachineReplacer -{ - -public: - virtual void ReplaceInnerMachine(VMTComplexMachine* machine) =0; +class IVMTProjectMachineReplacer { + public: + virtual void ReplaceInnerMachine(VMTComplexMachine* machine) = 0; virtual ~IVMTProjectMachineReplacer() = default; }; -#endif // !defined(EA_2DE1D8E7_CC65_4196_B305_92B0066B2169__INCLUDED_) +#endif // !defined(EA_2DE1D8E7_CC65_4196_B305_92B0066B2169__INCLUDED_) diff --git a/VirtualTuringMachine/interfaces/IVMTTransition.h b/VirtualTuringMachine/interfaces/IVMTTransition.h old mode 100755 new mode 100644 index d93d900..269808a --- a/VirtualTuringMachine/interfaces/IVMTTransition.h +++ b/VirtualTuringMachine/interfaces/IVMTTransition.h @@ -2,70 +2,78 @@ #if !defined(EA_BF914F26_4A17_4121_9768_093186EA560B__INCLUDED_) #define EA_BF914F26_4A17_4121_9768_093186EA560B__INCLUDED_ - -#include "VMTTransitionConditions.h" #include "IVMTAlphabitSource.h" #include "IVMTMachine.h" - +#include "VMTTransitionConditions.h" class VMTAlphabit; class IVMTMachine; -#include "uicanvas.h" - +#include #include #include -#include #include -class IVMTEnvironment; +#include "uicanvas.h" -class IVMTTransition -{ +class IVMTEnvironment; -public: - virtual void Serialize(QDataStream&) =0; - virtual void Deserialize(QDataStream&) =0; - virtual void BeginDrag(IVMTEnvironment* environment,const QPoint& p_Point) =0; - virtual void ChangeAlphabit(std::shared_ptr alphabit) =0; - virtual void Changed(IVMTEnvironment* environment) =0; - virtual void UpdatePreview(IVMTEnvironment* environment) { (void)environment; } +class IVMTTransition { + public: + virtual void Serialize(QDataStream&) = 0; + virtual void Deserialize(QDataStream&) = 0; + virtual void BeginDrag(IVMTEnvironment* environment, + const QPoint& p_Point) = 0; + virtual void ChangeAlphabit(std::shared_ptr alphabit) = 0; + virtual void Changed(IVMTEnvironment* environment) = 0; + virtual void UpdatePreview(IVMTEnvironment* environment) { + (void)environment; + } - virtual void Drag(IVMTEnvironment* environment,const QPoint& p_Point) =0; - virtual void EndDrag(IVMTEnvironment* environment,const QPoint& p_Point) =0; + virtual void Drag(IVMTEnvironment* environment, const QPoint& p_Point) = 0; + virtual void EndDrag(IVMTEnvironment* environment, + const QPoint& p_Point) = 0; - virtual const QRect& GetBounds() =0; - virtual VMTTransitionConditions& GetConditions() =0; - virtual void SetConditions(VMTTransitionConditions& other) =0; + virtual const QRect& GetBounds() = 0; + virtual VMTTransitionConditions& GetConditions() = 0; + virtual void SetConditions(VMTTransitionConditions& other) = 0; - virtual std::weak_ptr GetFinish() =0; - virtual std::weak_ptr GetStart() =0; + virtual std::weak_ptr GetFinish() = 0; + virtual std::weak_ptr GetStart() = 0; - virtual bool IsError() =0; - virtual bool IsInside(IVMTEnvironment* environment,const QPoint& p_Point) =0; - virtual bool IsIntersectLine(IVMTEnvironment* environment,const QPoint& start,const QPoint& end) =0; + virtual bool IsError() = 0; + virtual bool IsInside(IVMTEnvironment* environment, + const QPoint& p_Point) = 0; + virtual bool IsIntersectLine(IVMTEnvironment* environment, + const QPoint& start, const QPoint& end) = 0; - virtual void Paint(UICanvas& canvas, const QRect& rect) =0; + virtual void Paint(UICanvas& canvas, const QRect& rect) = 0; - virtual void RemoveChilds() =0; + virtual void RemoveChilds() = 0; virtual std::weak_ptr GetStartMachine() = 0; virtual std::weak_ptr GetFinishMachine() = 0; - virtual void SetError(bool bError) =0; - virtual void SetFinish(IVMTEnvironment* environment,std::shared_ptr machine) =0; - virtual void SetFinish(IVMTEnvironment* environment,const QPoint& point) =0; - virtual void SetSelected(bool enable) =0; - virtual void SetStart(IVMTEnvironment* environment,std::shared_ptr machine) =0; - virtual void SetStart(IVMTEnvironment* environment,const QPoint& point) =0; - virtual void SetParent(std::weak_ptr parent) =0; - - virtual IVMTAlphabitSource *GetAlphabitSource() = 0; - - /** Current visible routing polyline (updates during drag preview). */ + virtual void SetError(bool bError) = 0; + virtual void SetFinish(IVMTEnvironment* environment, + std::shared_ptr machine) = 0; + virtual void SetFinish(IVMTEnvironment* environment, + const QPoint& point) = 0; + virtual void SetSelected(bool enable) = 0; + virtual void SetStart(IVMTEnvironment* environment, + std::shared_ptr machine) = 0; + virtual void SetStart(IVMTEnvironment* environment, + const QPoint& point) = 0; + virtual void SetParent(std::weak_ptr parent) = 0; + + virtual IVMTAlphabitSource* GetAlphabitSource() = 0; + + /** Current visible routing polyline (updates during drag preview). */ virtual std::vector GetRoutingPolyline() const { return {}; } /** Last committed route used for batch rerouting snapshots. */ - virtual std::vector GetCommittedRoutingPolyline() const { return GetRoutingPolyline(); } + virtual std::vector GetCommittedRoutingPolyline() const { + return GetRoutingPolyline(); + } virtual ~IVMTTransition() = default; }; -#endif // !defined(EA_BF914F26_4A17_4121_9768_093186EA560B__INCLUDED_) +#endif // !defined(EA_BF914F26_4A17_4121_9768_093186EA560B__INCLUDED_) diff --git a/VirtualTuringMachine/interfaces/ivmtdebuger.h b/VirtualTuringMachine/interfaces/ivmtdebuger.h old mode 100755 new mode 100644 index afc147f..9a4920e --- a/VirtualTuringMachine/interfaces/ivmtdebuger.h +++ b/VirtualTuringMachine/interfaces/ivmtdebuger.h @@ -5,19 +5,18 @@ class IVMTMachine; -class IVMTDebuger : public IVMTCompilerCallback{ - -protected: +class IVMTDebuger : public IVMTCompilerCallback { + protected: virtual IVMTMachine* FindNextMachine() = 0; virtual void Next() = 0; virtual void MainLoop() = 0; -public: + + public: virtual void DoStep() = 0; virtual void DoUndo() = 0; virtual void DoStepOver() = 0; virtual void DoPause() = 0; virtual void DoStop() = 0; - }; -#endif // IVMTDEBUGER_H +#endif // IVMTDEBUGER_H diff --git a/VirtualTuringMachine/interfaces/ivmtundoobserver.h b/VirtualTuringMachine/interfaces/ivmtundoobserver.h old mode 100755 new mode 100644 index a3b944d..c1b1cbe --- a/VirtualTuringMachine/interfaces/ivmtundoobserver.h +++ b/VirtualTuringMachine/interfaces/ivmtundoobserver.h @@ -1,10 +1,10 @@ #ifndef IVMTUNDOOBSERVER_H #define IVMTUNDOOBSERVER_H -class IVMTUndoObserver{ -public: +class IVMTUndoObserver { + public: virtual void EnableUndoButton(bool enable) = 0; virtual ~IVMTUndoObserver() = default; }; -#endif // IVMTUNDOOBSERVER_H +#endif // IVMTUNDOOBSERVER_H diff --git a/VirtualTuringMachine/machineslibrary.cpp b/VirtualTuringMachine/machineslibrary.cpp old mode 100755 new mode 100644 index e5a8f0d..41c29f2 --- a/VirtualTuringMachine/machineslibrary.cpp +++ b/VirtualTuringMachine/machineslibrary.cpp @@ -1,7 +1,3 @@ #include "machineslibrary.h" - -MachinesLibrary::MachinesLibrary() -{ - a = 5; -} +MachinesLibrary::MachinesLibrary() { a = 5; } diff --git a/VirtualTuringMachine/machineslibrary.h b/VirtualTuringMachine/machineslibrary.h old mode 100755 new mode 100644 index de9a4f6..e910211 --- a/VirtualTuringMachine/machineslibrary.h +++ b/VirtualTuringMachine/machineslibrary.h @@ -3,12 +3,10 @@ #include "machineslibrary_global.h" -class MACHINESLIBRARYSHARED_EXPORT MachinesLibrary -{ - -public: - int a; +class MACHINESLIBRARYSHARED_EXPORT MachinesLibrary { + public: + int a; MachinesLibrary(); }; -#endif // MACHINESLIBRARY_H +#endif // MACHINESLIBRARY_H diff --git a/VirtualTuringMachine/machineslibrary_global.h b/VirtualTuringMachine/machineslibrary_global.h old mode 100755 new mode 100644 index e6f9d03..163f56e --- a/VirtualTuringMachine/machineslibrary_global.h +++ b/VirtualTuringMachine/machineslibrary_global.h @@ -4,9 +4,9 @@ #include #if defined(MACHINESLIBRARY_LIBRARY) -# define MACHINESLIBRARYSHARED_EXPORT Q_DECL_EXPORT +#define MACHINESLIBRARYSHARED_EXPORT Q_DECL_EXPORT #else -# define MACHINESLIBRARYSHARED_EXPORT Q_DECL_IMPORT +#define MACHINESLIBRARYSHARED_EXPORT Q_DECL_IMPORT #endif -#endif // MACHINESLIBRARY_GLOBAL_H +#endif // MACHINESLIBRARY_GLOBAL_H diff --git a/VirtualTuringMachine/main.cpp b/VirtualTuringMachine/main.cpp old mode 100755 new mode 100644 index d21cf62..457c16c --- a/VirtualTuringMachine/main.cpp +++ b/VirtualTuringMachine/main.cpp @@ -1,11 +1,11 @@ -#include "mainwindow.h" -#include "vmttheme.h" #include #include + #include "configuration.h" +#include "mainwindow.h" +#include "vmttheme.h" -int main(int argc, char *argv[]) -{ +int main(int argc, char* argv[]) { QApplication a(argc, argv); QApplication::setApplicationName("Virtual Turing Machine"); diff --git a/VirtualTuringMachine/mainwindow.cpp b/VirtualTuringMachine/mainwindow.cpp old mode 100755 new mode 100644 index cc2a4db..8f46399 --- a/VirtualTuringMachine/mainwindow.cpp +++ b/VirtualTuringMachine/mainwindow.cpp @@ -1,43 +1,45 @@ #include "mainwindow.h" -#include "ui_mainwindow.h" -#include + +#include #include #include #include -#include "uistatemain.h" -#include "formwarning.h" +#include +#include + #include "clickablelabel.h" +#include "configuration.h" +#include "formwarning.h" #include "screentools.h" +#include "ui_mainwindow.h" +#include "uistatemain.h" #include "vmttheme.h" -#include "configuration.h" -#include -#include -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow), - _form_warning(nullptr) +MainWindow::MainWindow(QWidget* parent) + : QMainWindow(parent), + ui(new Ui::MainWindow), + _form_warning(nullptr) { ui->setupUi(this); VmtTheme::applyIconToolBar(ui->frame_header); ui->widgetLabel->setStyleSheet(VmtTheme::headerChromeStyle()); - // QPalette pal(palette()); + // QPalette pal(palette()); // set black background - //pal.setColor(QPalette::Background, QColor("#012C40")); - //pal.setColor(QPalette::ButtonText,Qt::white); - //ui->frame_header->setAutoFillBackground(true); - //ui->frame_header->setPalette(pal); - //ui->widgetLabel->setPalette(pal); + // pal.setColor(QPalette::Background, QColor("#012C40")); + // pal.setColor(QPalette::ButtonText,Qt::white); + // ui->frame_header->setAutoFillBackground(true); + // ui->frame_header->setPalette(pal); + // ui->widgetLabel->setPalette(pal); - //ui->frame_header->setStyleSheet("background-color:#01547a;"); + // ui->frame_header->setStyleSheet("background-color:#01547a;"); - QObject::connect(ui->button_back, SIGNAL(clicked()), - this, SLOT(onBackClicked())); + QObject::connect(ui->button_back, SIGNAL(clicked()), this, + SLOT(onBackClicked())); - QHBoxLayout *layout = new QHBoxLayout; + QHBoxLayout* layout = new QHBoxLayout; ui->widget_container->setLayout(layout); ui->widget_container->setStyleSheet(VmtTheme::contentAreaStyle()); @@ -67,13 +69,13 @@ MainWindow::MainWindow(QWidget *parent) : ui->button_theme->setChecked(Configuration::GetInstance().IsDarkTheme()); updateThemeButton(); - connect(ui->button_theme, &QToolButton::toggled, - this, &MainWindow::on_button_theme_toggled); + connect(ui->button_theme, &QToolButton::toggled, this, + &MainWindow::on_button_theme_toggled); - // st.ResizeSlider(ui->slider_zoom); - // st.ResizeFrame(ui->frame_zoom); + // st.ResizeSlider(ui->slider_zoom); + // st.ResizeFrame(ui->frame_zoom); - //st.ResizeLabel(ui->label_2); + // st.ResizeLabel(ui->label_2); this->ChangeState(std::shared_ptr(new UIStateMainData())); VmtTheme::applyThemedWidgets(this); @@ -103,62 +105,56 @@ void MainWindow::EnablePlantUmlExport(bool enable) { ui->button_export_plantuml->setHidden(!enable); } -void MainWindow::EnableRun(bool enable) { - ui->button_run->setHidden(!enable); -} +void MainWindow::EnableRun(bool enable) { ui->button_run->setHidden(!enable); } void MainWindow::EnableConfigure(bool enable) { ui->button_configure->setHidden(!enable); } -void MainWindow::EnableDebugBack(bool enable){ +void MainWindow::EnableDebugBack(bool enable) { ui->button_debug_back->setHidden(!enable); } -void MainWindow::EnableDebugOver(bool enable){ +void MainWindow::EnableDebugOver(bool enable) { ui->button_debug_over->setHidden(!enable); } -void MainWindow::EnableDebugPause(bool enable){ +void MainWindow::EnableDebugPause(bool enable) { ui->button_debug_pause->setHidden(!enable); } -void MainWindow::EnableDebugRun(bool enable){ +void MainWindow::EnableDebugRun(bool enable) { ui->button_debug_run->setHidden(!enable); } -void MainWindow::EnableDebugStep(bool enable){ +void MainWindow::EnableDebugStep(bool enable) { ui->button_debug_step->setHidden(!enable); } -void MainWindow::EnableDebugStop(bool enable){ +void MainWindow::EnableDebugStop(bool enable) { ui->button_debug_stop->setHidden(!enable); } -void MainWindow::EnableOk(bool enable){ - ui->button_ok->setHidden(!enable); -} +void MainWindow::EnableOk(bool enable) { ui->button_ok->setHidden(!enable); } -void MainWindow::EnableCancel(bool enable){ +void MainWindow::EnableCancel(bool enable) { ui->button_cancel->setHidden(!enable); } -void MainWindow::EnableZoom(bool enable){ +void MainWindow::EnableZoom(bool enable) { ui->slider_zoom->setHidden(!enable); ui->frame_zoom->setHidden(!enable); } -void MainWindow::Enable4thExport(bool enable){ +void MainWindow::Enable4thExport(bool enable) { ui->button_4th->setHidden(!enable); } #include -void MainWindow::closeEvent (QCloseEvent *event) -{ - QMessageBox::StandardButton resBtn = QMessageBox::question( this, "VMT", - "This will delete any unsaved project data. Are you sure?", - QMessageBox::No | QMessageBox::Yes, - QMessageBox::No); +void MainWindow::closeEvent(QCloseEvent* event) { + QMessageBox::StandardButton resBtn = QMessageBox::question( + this, "VMT", "This will delete any unsaved project data. Are you sure?", + QMessageBox::No | QMessageBox::Yes, QMessageBox::No); if (resBtn != QMessageBox::Yes) { event->ignore(); } else { @@ -166,115 +162,111 @@ void MainWindow::closeEvent (QCloseEvent *event) } } -void MainWindow::ShowWarning(std::shared_ptr){ - - if(!_form_warning){ - if(GetContainer()->layout()->count()>0) - { - //_form_warning_state = dynamic_cast(GetContainer()->layout()->children().at(0)); +void MainWindow::ShowWarning(std::shared_ptr) { + if (!_form_warning) { + if (GetContainer()->layout()->count() > 0) { + //_form_warning_state = + //dynamic_cast(GetContainer()->layout()->children().at(0)); //_form_warning_state->setHidden(true); - _form_warning = new FormWarning(this,GetContainer()); + _form_warning = new FormWarning(this, GetContainer()); GetContainer()->layout()->addWidget(_form_warning); - GetContainer()->layout()->setContentsMargins(0,0,0,0); + GetContainer()->layout()->setContentsMargins(0, 0, 0, 0); } } } -void MainWindow::keyReleaseEvent(QKeyEvent *event){ - if(event->key() == Qt::Key_Control) { +void MainWindow::keyReleaseEvent(QKeyEvent* event) { + if (event->key() == Qt::Key_Control) { qDebug() << "CTRL released"; ctrlPressed = false; } - if(_state){ + if (_state) { _state->OnKeyReleased(event); } } -void MainWindow::keyPressEvent (QKeyEvent* event) { - if(event->key() == Qt::Key_Control) { +void MainWindow::keyPressEvent(QKeyEvent* event) { + if (event->key() == Qt::Key_Control) { qDebug() << "CTRL pressed"; ctrlPressed = true; } - if (event->key () == Qt::Key_Back) { + if (event->key() == Qt::Key_Back) { onBackClicked(); - event->accept (); - } else - if(_state){ + event->accept(); + } else if (_state) { _state->OnKeyPressed(event); } } -void MainWindow::HideWarning(bool undo){ - if(_form_warning){ +void MainWindow::HideWarning(bool undo) { + if (_form_warning) { GetContainer()->layout()->removeWidget(_form_warning); delete _form_warning; _form_warning = nullptr; //_form_warning_state->setHidden(false); - if(undo) UndoForce(); + if (undo) UndoForce(); } } -void MainWindow::onBackClicked(){ - this->Undo(); -} +void MainWindow::onBackClicked() { this->Undo(); } -void MainWindow::onRefClicked(){ - ClickableLabel *button = dynamic_cast (sender()); - if(button) - { +void MainWindow::onRefClicked() { + ClickableLabel* button = dynamic_cast(sender()); + if (button) { QVariant var = button->property("state"); unsigned int number = var.toUInt(); bool need_continue = true; - while(need_continue&(this->undo.size()>number)) need_continue=this->Undo(); + while (need_continue & (this->undo.size() > number)) + need_continue = this->Undo(); } } -void MainWindow::OnChanged(std::shared_ptr state,std::shared_ptr new_state_data){ - +void MainWindow::OnChanged(std::shared_ptr state, + std::shared_ptr new_state_data) { qDebug() << "MainWindow::OnChanged"; bool find; - do{ + do { find = false; - for(auto i=ui->widgetLabel->children().begin(); - (i!=ui->widgetLabel->children().end())&&(!find);i++){ - QObject *obj = *i; + for (auto i = ui->widgetLabel->children().begin(); + (i != ui->widgetLabel->children().end()) && (!find); i++) { + QObject* obj = *i; - if(dynamic_cast(obj)) { + if (dynamic_cast(obj)) { find = true; - ui->widgetLabel->layout()->removeWidget(dynamic_cast(obj)); + ui->widgetLabel->layout()->removeWidget( + dynamic_cast(obj)); delete obj; obj = nullptr; } - if(dynamic_cast(obj)) { + if (dynamic_cast(obj)) { find = true; - ui->widgetLabel->layout()->removeWidget(dynamic_cast(obj)); + ui->widgetLabel->layout()->removeWidget( + dynamic_cast(obj)); delete obj; } } - }while(find); + } while (find); unsigned int count = 0; - for(auto i: undo){ + for (auto i : undo) { QString name = i->GetName(); - name+="\\"; - ClickableLabel *label = new ClickableLabel(name,ui->widgetLabel); - + name += "\\"; + ClickableLabel* label = new ClickableLabel(name, ui->widgetLabel); QFont font = label->font(); font.setUnderline(true); - //font.setBold(true); - label->setProperty("state",count++); - label->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); + // font.setBold(true); + label->setProperty("state", count++); + label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); label->setStyleSheet(VmtTheme::breadcrumbLinkStyle()); - label->connect(label, SIGNAL(clicked()), - this, SLOT(onRefClicked())); + label->connect(label, SIGNAL(clicked()), this, SLOT(onRefClicked())); label->setFont(font); ui->widgetLabel->layout()->addWidget(label); } - QLabel *label = new QLabel(new_state_data->GetName(),ui->widgetLabel); - label->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Maximum); + QLabel* label = new QLabel(new_state_data->GetName(), ui->widgetLabel); + label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); label->setStyleSheet(VmtTheme::breadcrumbCurrentStyle()); ui->widgetLabel->layout()->addWidget(label); ui->button_back->setHidden(undo.empty()); @@ -282,150 +274,122 @@ void MainWindow::OnChanged(std::shared_ptr state,std::shared_ptrwidget_container; -} +QWidget* MainWindow::GetContainer() { return ui->widget_container; } -MainWindow::~MainWindow() -{ +MainWindow::~MainWindow() { _state.reset(); delete ui; } -void MainWindow::on_button_new_machine_clicked() -{ +void MainWindow::on_button_new_machine_clicked() { QVariant var = ui->button_new_machine->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::on_button_open_machine_clicked() -{ +void MainWindow::on_button_open_machine_clicked() { QVariant var = ui->button_open_machine->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::on_button_save_clicked() -{ +void MainWindow::on_button_save_clicked() { QVariant var = ui->button_save->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::on_button_export_clicked() -{ +void MainWindow::on_button_export_clicked() { QVariant var = ui->button_export->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::on_button_export_plantuml_clicked() -{ +void MainWindow::on_button_export_plantuml_clicked() { QVariant var = ui->button_export_plantuml->property("name"); const QString action = var.toString(); _state->Action(action); } -void MainWindow::on_button_run_clicked() -{ +void MainWindow::on_button_run_clicked() { QVariant var = ui->button_run->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); - } -void MainWindow::on_button_configure_clicked() -{ +void MainWindow::on_button_configure_clicked() { QVariant var = ui->button_configure->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::on_button_ok_clicked() -{ +void MainWindow::on_button_ok_clicked() { QVariant var = ui->button_ok->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::on_button_cancel_clicked() -{ +void MainWindow::on_button_cancel_clicked() { QVariant var = ui->button_cancel->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::on_slider_zoom_sliderMoved(int position) -{ +void MainWindow::on_slider_zoom_sliderMoved(int position) { _state->OnZoomChanged(position); } -int MainWindow::GetZoom(){ - return ui->slider_zoom->sliderPosition(); -} - +int MainWindow::GetZoom() { return ui->slider_zoom->sliderPosition(); } -void MainWindow::on_button_debug_back_clicked() -{ +void MainWindow::on_button_debug_back_clicked() { QVariant var = ui->button_debug_back->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::on_button_debug_step_clicked() -{ +void MainWindow::on_button_debug_step_clicked() { QVariant var = ui->button_debug_step->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::on_slider_zoom_sliderPressed() -{ - +void MainWindow::on_slider_zoom_sliderPressed() { _state->OnZoomChanged(ui->slider_zoom->sliderPosition()); } -void MainWindow::on_button_4th_clicked() -{ +void MainWindow::on_button_4th_clicked() { QVariant var = ui->button_4th->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::on_button_debug_run_clicked() -{ +void MainWindow::on_button_debug_run_clicked() { QVariant var = ui->button_debug_run->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::on_button_debug_pause_clicked() -{ +void MainWindow::on_button_debug_pause_clicked() { QVariant var = ui->button_debug_pause->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::on_button_debug_stop_clicked() -{ +void MainWindow::on_button_debug_stop_clicked() { QVariant var = ui->button_debug_stop->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::on_button_exercise_clicked() -{ +void MainWindow::on_button_exercise_clicked() { QVariant var = ui->button_exercise->property("name"); - QString action = var.toString(); + QString action = var.toString(); _state->Action(action); } -void MainWindow::updateThemeButton() -{ +void MainWindow::updateThemeButton() { const bool dark = VmtTheme::isDarkMode(); ui->button_theme->blockSignals(true); ui->button_theme->setChecked(dark); @@ -436,8 +400,7 @@ void MainWindow::updateThemeButton() : tr("Switch to dark theme")); } -void MainWindow::applyTheme(bool dark) -{ +void MainWindow::applyTheme(bool dark) { if (auto* app = qobject_cast(QApplication::instance())) { VmtTheme::setDarkMode(dark, app); } @@ -448,8 +411,7 @@ void MainWindow::applyTheme(bool dark) updateThemeButton(); } -void MainWindow::on_button_theme_toggled(bool checked) -{ +void MainWindow::on_button_theme_toggled(bool checked) { Configuration::GetInstance().SetDarkTheme(checked); Configuration::GetInstance().Save(); applyTheme(checked); diff --git a/VirtualTuringMachine/mainwindow.h b/VirtualTuringMachine/mainwindow.h old mode 100755 new mode 100644 index 2d78156..aa8e14d --- a/VirtualTuringMachine/mainwindow.h +++ b/VirtualTuringMachine/mainwindow.h @@ -1,28 +1,28 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H +#include +#include #include #include -#include "statecontroller.h" #include "formwarning.h" #include "isCtrlPressed.h" -#include -#include +#include "statecontroller.h" namespace Ui { class MainWindow; } -class MainWindow : public QMainWindow, public StateController -{ +class MainWindow : public QMainWindow, public StateController { Q_OBJECT -public: - explicit MainWindow(QWidget *parent = 0); + public: + explicit MainWindow(QWidget* parent = 0); ~MainWindow(); QWidget* GetContainer() override; - void OnChanged(std::shared_ptr state,std::shared_ptr new_state_data) override; + void OnChanged(std::shared_ptr state, + std::shared_ptr new_state_data) override; void ShowWarning(std::shared_ptr) override; void HideWarning(bool undo) override; void EnableExercise(bool enable) override; @@ -43,19 +43,21 @@ class MainWindow : public QMainWindow, public StateController void EnableCancel(bool enable) override; void EnableZoom(bool enable) override; void Enable4thExport(bool enable) override; - void closeEvent (QCloseEvent *event) override; - int GetZoom() override; + void closeEvent(QCloseEvent* event) override; + int GetZoom() override; void applyTheme(bool dark); void updateThemeButton(); -protected: - void keyPressEvent (QKeyEvent* event) override; - void keyReleaseEvent(QKeyEvent *) override; -private: - Ui::MainWindow *ui; - FormWarning *_form_warning; - QWidget *_form_warning_state; -private slots: + protected: + void keyPressEvent(QKeyEvent* event) override; + void keyReleaseEvent(QKeyEvent*) override; + + private: + Ui::MainWindow* ui; + FormWarning* _form_warning; + QWidget* _form_warning_state; + + private slots: void onBackClicked(); void onRefClicked(); void on_button_new_machine_clicked(); @@ -79,4 +81,4 @@ private slots: void on_button_theme_toggled(bool checked); }; -#endif // MAINWINDOW_H +#endif // MAINWINDOW_H diff --git a/VirtualTuringMachine/pathfinder.cpp b/VirtualTuringMachine/pathfinder.cpp index 2e6adbb..aa5a02e 100644 --- a/VirtualTuringMachine/pathfinder.cpp +++ b/VirtualTuringMachine/pathfinder.cpp @@ -1,7 +1,6 @@ #include "pathfinder.h" #include - #include #include #include @@ -13,14 +12,15 @@ namespace { constexpr int kMargin = 100; constexpr size_t kMaxCellsPerAxis = 128; -int manhattanCells(std::pair a, std::pair b) -{ - return static_cast(std::abs(static_cast(a.first) - static_cast(b.first))) - + static_cast(std::abs(static_cast(a.second) - static_cast(b.second))); +int manhattanCells(std::pair a, std::pair b) { + return static_cast(std::abs(static_cast(a.first) - + static_cast(b.first))) + + static_cast(std::abs(static_cast(a.second) - + static_cast(b.second))); } -bool pointNearSegment(const QPoint& point, const QPoint& a, const QPoint& b, int tolerance) -{ +bool pointNearSegment(const QPoint& point, const QPoint& a, const QPoint& b, + int tolerance) { if (a.x() == b.x()) { if (std::abs(point.x() - a.x()) > tolerance) { return false; @@ -42,8 +42,8 @@ bool pointNearSegment(const QPoint& point, const QPoint& a, const QPoint& b, int return false; } -bool pointNearPolyline(const QPoint& point, const path_t& polyline, int tolerance) -{ +bool pointNearPolyline(const QPoint& point, const path_t& polyline, + int tolerance) { if (polyline.size() < 2) { return false; } @@ -57,15 +57,14 @@ bool pointNearPolyline(const QPoint& point, const path_t& polyline, int toleranc return false; } -bool valueBetween(int value, int a, int b) -{ +bool valueBetween(int value, int a, int b) { const int low = std::min(a, b); const int high = std::max(a, b); return value >= low && value <= high; } -bool segmentClear(const QPoint& from, const QPoint& to, wall_checker_t checker, int sampleStep) -{ +bool segmentClear(const QPoint& from, const QPoint& to, wall_checker_t checker, + int sampleStep) { if (!checker) { return true; } @@ -78,7 +77,8 @@ bool segmentClear(const QPoint& from, const QPoint& to, wall_checker_t checker, if (from.x() == to.x()) { const int delta = to.y() - from.y(); const int stride = delta >= 0 ? step : -step; - for (int y = from.y(); stride > 0 ? y <= to.y() : y >= to.y(); y += stride) { + for (int y = from.y(); stride > 0 ? y <= to.y() : y >= to.y(); + y += stride) { if (checker(QPoint(from.x(), y))) { return false; } @@ -89,7 +89,8 @@ bool segmentClear(const QPoint& from, const QPoint& to, wall_checker_t checker, if (from.y() == to.y()) { const int delta = to.x() - from.x(); const int stride = delta >= 0 ? step : -step; - for (int x = from.x(); stride > 0 ? x <= to.x() : x >= to.x(); x += stride) { + for (int x = from.x(); stride > 0 ? x <= to.x() : x >= to.x(); + x += stride) { if (checker(QPoint(x, from.y()))) { return false; } @@ -100,19 +101,21 @@ bool segmentClear(const QPoint& from, const QPoint& to, wall_checker_t checker, return false; } -bool lPathClear(const QPoint& from, const QPoint& to, wall_checker_t checker, int sampleStep, QPoint* cornerOut) -{ +bool lPathClear(const QPoint& from, const QPoint& to, wall_checker_t checker, + int sampleStep, QPoint* cornerOut) { const QPoint cornerH(to.x(), from.y()); const QPoint cornerV(from.x(), to.y()); - if (segmentClear(from, cornerH, checker, sampleStep) && segmentClear(cornerH, to, checker, sampleStep)) { + if (segmentClear(from, cornerH, checker, sampleStep) && + segmentClear(cornerH, to, checker, sampleStep)) { if (cornerOut) { *cornerOut = cornerH; } return true; } - if (segmentClear(from, cornerV, checker, sampleStep) && segmentClear(cornerV, to, checker, sampleStep)) { + if (segmentClear(from, cornerV, checker, sampleStep) && + segmentClear(cornerV, to, checker, sampleStep)) { if (cornerOut) { *cornerOut = cornerV; } @@ -122,48 +125,55 @@ bool lPathClear(const QPoint& from, const QPoint& to, wall_checker_t checker, in return false; } -void appendUnique(path_t& path, const QPoint& point) -{ +void appendUnique(path_t& path, const QPoint& point) { if (path.empty() || path.back() != point) { path.push_back(point); } } -bool isAxisSpike(const QPoint& a, const QPoint& b, const QPoint& c) -{ +bool isAxisSpike(const QPoint& a, const QPoint& b, const QPoint& c) { if (a.x() == b.x() && b.x() == c.x()) { - return valueBetween(b.y(), a.y(), c.y()) && b.y() != a.y() && b.y() != c.y(); + return valueBetween(b.y(), a.y(), c.y()) && b.y() != a.y() && + b.y() != c.y(); } if (a.y() == b.y() && b.y() == c.y()) { - return valueBetween(b.x(), a.x(), c.x()) && b.x() != a.x() && b.x() != c.x(); + return valueBetween(b.x(), a.x(), c.x()) && b.x() != a.x() && + b.x() != c.x(); } return false; } -} // namespace +} // namespace -Matrix::Matrix(const QPoint& start, const QPoint& finish, const QRect& bounds, size_t grid_size) - : start(start), finish(finish), grid_size(grid_size) -{ - this->bounds = QRect(bounds.x() - kMargin, - bounds.y() - kMargin, - bounds.width() + kMargin * 2, - bounds.height() + kMargin * 2); +Matrix::Matrix(const QPoint& start, const QPoint& finish, const QRect& bounds, + size_t grid_size) + : start(start), finish(finish), grid_size(grid_size) { + this->bounds = + QRect(bounds.x() - kMargin, bounds.y() - kMargin, + bounds.width() + kMargin * 2, bounds.height() + kMargin * 2); this->bounds = this->bounds.united(QRect(start, finish).normalized()); - this->bounds.setBottom((this->bounds.bottom() / static_cast(grid_size)) * static_cast(grid_size) - + static_cast(grid_size) / 2); - this->bounds.setTop((this->bounds.top() / static_cast(grid_size)) * static_cast(grid_size) - + static_cast(grid_size) / 2); + this->bounds.setBottom( + (this->bounds.bottom() / static_cast(grid_size)) * + static_cast(grid_size) + + static_cast(grid_size) / 2); + this->bounds.setTop((this->bounds.top() / static_cast(grid_size)) * + static_cast(grid_size) + + static_cast(grid_size) / 2); - this->bounds.setWidth((this->bounds.width() / static_cast(grid_size)) * static_cast(grid_size)); - this->bounds.setHeight((this->bounds.height() / static_cast(grid_size)) * static_cast(grid_size)); + this->bounds.setWidth((this->bounds.width() / static_cast(grid_size)) * + static_cast(grid_size)); + this->bounds.setHeight( + (this->bounds.height() / static_cast(grid_size)) * + static_cast(grid_size)); size_t effectiveGrid = grid_size > 0 ? grid_size : 1; auto computeAxisCells = [&](int dimension) -> size_t { - size_t cells = static_cast((dimension + static_cast(effectiveGrid) - 1) / static_cast(effectiveGrid)); + size_t cells = static_cast( + (dimension + static_cast(effectiveGrid) - 1) / + static_cast(effectiveGrid)); if (cells < 2) { cells = 2; } @@ -172,13 +182,14 @@ Matrix::Matrix(const QPoint& start, const QPoint& finish, const QRect& bounds, s cells_count_x = computeAxisCells(this->bounds.width()); cells_count_y = computeAxisCells(this->bounds.height()); - while (cells_count_x > kMaxCellsPerAxis || cells_count_y > kMaxCellsPerAxis) { + while (cells_count_x > kMaxCellsPerAxis || + cells_count_y > kMaxCellsPerAxis) { effectiveGrid *= 2; cells_count_x = computeAxisCells(this->bounds.width()); cells_count_y = computeAxisCells(this->bounds.height()); } - cells.assign(cells_count_x * cells_count_y, Cell {}); + cells.assign(cells_count_x * cells_count_y, Cell{}); start_cell = point_to_cell(start); finish_cell = point_to_cell(finish); @@ -186,58 +197,62 @@ Matrix::Matrix(const QPoint& start, const QPoint& finish, const QRect& bounds, s at(finish_cell).wall = false; } -size_t Matrix::index(std::pair cell) const -{ +size_t Matrix::index(std::pair cell) const { return cell.first + cell.second * cells_count_x; } -Cell& Matrix::at(std::pair cell) -{ - return cells[index(cell)]; -} +Cell& Matrix::at(std::pair cell) { return cells[index(cell)]; } -const Cell& Matrix::at(std::pair cell) const -{ +const Cell& Matrix::at(std::pair cell) const { return cells[index(cell)]; } -QPoint Matrix::cell_to_point(std::pair cell) const -{ +QPoint Matrix::cell_to_point(std::pair cell) const { QPoint result(bounds.left(), bounds.top()); - result.rx() += static_cast(cell.first * bounds.width() / static_cast(cells_count_x)); - result.ry() += static_cast(cell.second * bounds.height() / static_cast(cells_count_y)); + result.rx() += static_cast(cell.first * bounds.width() / + static_cast(cells_count_x)); + result.ry() += static_cast(cell.second * bounds.height() / + static_cast(cells_count_y)); return result; } -std::pair Matrix::point_to_cell(const QPoint& point) const -{ +std::pair Matrix::point_to_cell(const QPoint& point) const { if (cells_count_x == 0 || cells_count_y == 0) { return {0, 0}; } - const int cellWidth = std::max(1, bounds.width() / static_cast(cells_count_x)); - const int cellHeight = std::max(1, bounds.height() / static_cast(cells_count_y)); + const int cellWidth = + std::max(1, bounds.width() / static_cast(cells_count_x)); + const int cellHeight = + std::max(1, bounds.height() / static_cast(cells_count_y)); size_t bestI = 0; size_t bestJ = 0; int bestDistance = std::numeric_limits::max(); const size_t guessI = - static_cast(std::clamp((point.x() - bounds.left()) / cellWidth, 0, static_cast(cells_count_x) - 1)); + static_cast(std::clamp((point.x() - bounds.left()) / cellWidth, + 0, static_cast(cells_count_x) - 1)); const size_t guessJ = - static_cast(std::clamp((point.y() - bounds.top()) / cellHeight, 0, static_cast(cells_count_y) - 1)); + static_cast(std::clamp((point.y() - bounds.top()) / cellHeight, + 0, static_cast(cells_count_y) - 1)); for (size_t di = 0; di <= 1; ++di) { for (size_t dj = 0; dj <= 1; ++dj) { - const long i = static_cast(guessI) + static_cast(di) - 1; - const long j = static_cast(guessJ) + static_cast(dj) - 1; - if (i < 0 || j < 0 || i >= static_cast(cells_count_x) || j >= static_cast(cells_count_y)) { + const long i = + static_cast(guessI) + static_cast(di) - 1; + const long j = + static_cast(guessJ) + static_cast(dj) - 1; + if (i < 0 || j < 0 || i >= static_cast(cells_count_x) || + j >= static_cast(cells_count_y)) { continue; } - const std::pair cell {static_cast(i), static_cast(j)}; + const std::pair cell{static_cast(i), + static_cast(j)}; const QPoint center = cell_to_point(cell); - const int distance = std::abs(center.x() - point.x()) + std::abs(center.y() - point.y()); + const int distance = std::abs(center.x() - point.x()) + + std::abs(center.y() - point.y()); if (distance < bestDistance) { bestDistance = distance; bestI = cell.first; @@ -249,11 +264,10 @@ std::pair Matrix::point_to_cell(const QPoint& point) const return {bestI, bestJ}; } -void Matrix::FillWalls(wall_checker_t checker) -{ +void Matrix::FillWalls(wall_checker_t checker) { for (size_t i = 0; i < cells_count_x; ++i) { for (size_t j = 0; j < cells_count_y; ++j) { - const std::pair cell {i, j}; + const std::pair cell{i, j}; if (cell == start_cell || cell == finish_cell) { at(cell).wall = false; continue; @@ -263,28 +277,38 @@ void Matrix::FillWalls(wall_checker_t checker) } } -void Matrix::markBlockedPaths(const std::vector& blockedPaths, int pathCorridor) -{ +void Matrix::markBlockedPaths(const std::vector& blockedPaths, + int pathCorridor) { for (const path_t& blockedPath : blockedPaths) { if (blockedPath.size() < 2) { continue; } - for (size_t segmentIndex = 1; segmentIndex < blockedPath.size(); ++segmentIndex) { + for (size_t segmentIndex = 1; segmentIndex < blockedPath.size(); + ++segmentIndex) { const QPoint& from = blockedPath[segmentIndex - 1]; const QPoint& to = blockedPath[segmentIndex]; - const int steps = std::max(std::abs(to.x() - from.x()), std::abs(to.y() - from.y())); - const int stride = std::max(1, steps / static_cast(std::max(cells_count_x, cells_count_y)) + 1); + const int steps = std::max(std::abs(to.x() - from.x()), + std::abs(to.y() - from.y())); + const int stride = + std::max(1, steps / static_cast(std::max(cells_count_x, + cells_count_y)) + + 1); for (int step = 0; step <= steps; step += stride) { - const double t = steps == 0 ? 0.0 : static_cast(step) / steps; - const QPoint sample(static_cast(from.x() + (to.x() - from.x()) * t), - static_cast(from.y() + (to.y() - from.y()) * t)); - - for (int dx = -pathCorridor; dx <= pathCorridor; dx += pathCorridor / 2 + 1) { - for (int dy = -pathCorridor; dy <= pathCorridor; dy += pathCorridor / 2 + 1) { + const double t = + steps == 0 ? 0.0 : static_cast(step) / steps; + const QPoint sample( + static_cast(from.x() + (to.x() - from.x()) * t), + static_cast(from.y() + (to.y() - from.y()) * t)); + + for (int dx = -pathCorridor; dx <= pathCorridor; + dx += pathCorridor / 2 + 1) { + for (int dy = -pathCorridor; dy <= pathCorridor; + dy += pathCorridor / 2 + 1) { const QPoint probe(sample.x() + dx, sample.y() + dy); - const std::pair cell = point_to_cell(probe); + const std::pair cell = + point_to_cell(probe); if (cell == start_cell || cell == finish_cell) { continue; } @@ -296,8 +320,8 @@ void Matrix::markBlockedPaths(const std::vector& blockedPaths, int pathC } } -bool Matrix::segment_is_clear(std::pair from, std::pair to) const -{ +bool Matrix::segment_is_clear(std::pair from, + std::pair to) const { const int x0 = static_cast(from.first); const int y0 = static_cast(from.second); const int x1 = static_cast(to.first); @@ -313,11 +337,13 @@ bool Matrix::segment_is_clear(std::pair from, std::pair= static_cast(cells_count_x) || y >= static_cast(cells_count_y)) { + if (x < 0 || y < 0 || x >= static_cast(cells_count_x) || + y >= static_cast(cells_count_y)) { return false; } - const std::pair cell {static_cast(x), static_cast(y)}; + const std::pair cell{static_cast(x), + static_cast(y)}; if (cell != from && cell != to && at(cell).wall) { return false; } @@ -343,8 +369,7 @@ bool Matrix::segment_is_clear(std::pair from, std::pair& blockedPaths, - int pathCorridor) const -{ + int pathCorridor) const { if (checker && checker(point)) { return true; } @@ -358,17 +383,15 @@ bool Pathfinder::pointBlocksPath(const QPoint& point, return false; } -path_t Pathfinder::GetPath(const QPoint& start, - const QPoint& finish, - const QRect& bounds, - size_t grid_size, +path_t Pathfinder::GetPath(const QPoint& start, const QPoint& finish, + const QRect& bounds, size_t grid_size, wall_checker_t checker, const std::vector& blockedPaths, - int pathCorridor) -{ + int pathCorridor) { matrix = Matrix(start, finish, bounds, grid_size); - const wall_checker_t combinedChecker = [this, checker, blockedPaths, pathCorridor](const QPoint& point) { + const wall_checker_t combinedChecker = [this, checker, blockedPaths, + pathCorridor](const QPoint& point) { return pointBlocksPath(point, checker, blockedPaths, pathCorridor); }; @@ -386,8 +409,7 @@ path_t Pathfinder::GetPath(const QPoint& start, return optimizeOrthogonalPath(std::move(path), combinedChecker); } -path_t Pathfinder::enforceTerminalDirections(path_t path) const -{ +path_t Pathfinder::enforceTerminalDirections(path_t path) const { if (path.size() < 2) { return path; } @@ -397,7 +419,8 @@ path_t Pathfinder::enforceTerminalDirections(path_t path) const ::appendUnique(result, path.front()); if (path.size() == 1 || path[1].x() <= path.front().x()) { - ::appendUnique(result, QPoint(path.front().x() + stub, path.front().y())); + ::appendUnique(result, + QPoint(path.front().x() + stub, path.front().y())); } for (size_t i = 1; i < path.size(); ++i) { @@ -415,8 +438,8 @@ path_t Pathfinder::enforceTerminalDirections(path_t path) const return result; } -path_t Pathfinder::optimizeOrthogonalPath(path_t path, wall_checker_t checker) const -{ +path_t Pathfinder::optimizeOrthogonalPath(path_t path, + wall_checker_t checker) const { if (path.size() < 3) { return path; } @@ -462,8 +485,7 @@ path_t Pathfinder::optimizeOrthogonalPath(path_t path, wall_checker_t checker) c return path; } -bool Pathfinder::searchPath(path_t& path) -{ +bool Pathfinder::searchPath(path_t& path) { constexpr int kTurnPenalty = 6; const size_t cellCount = matrix.cells_count_x * matrix.cells_count_y; @@ -483,16 +505,20 @@ bool Pathfinder::searchPath(path_t& path) size_t state; }; - auto cmp = [](const Node& lhs, const Node& rhs) { return lhs.fScore > rhs.fScore; }; + auto cmp = [](const Node& lhs, const Node& rhs) { + return lhs.fScore > rhs.fScore; + }; std::priority_queue, decltype(cmp)> open(cmp); - static const std::pair kDirections[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; + static const std::pair kDirections[] = { + {1, 0}, {-1, 0}, {0, 1}, {0, -1}}; std::vector closed(stateCount, false); const size_t startState = stateId(startIndex, 0); gScore[startState] = 0; parent[startState] = -1; - open.push({manhattanCells(matrix.start_cell, matrix.finish_cell), startState}); + open.push( + {manhattanCells(matrix.start_cell, matrix.finish_cell), startState}); while (!open.empty()) { const size_t currentState = open.top().state; @@ -508,7 +534,8 @@ bool Pathfinder::searchPath(path_t& path) if (currentIndex == finishIndex) { path.clear(); - for (int cursor = static_cast(currentState); cursor >= 0; cursor = parent[static_cast(cursor)]) { + for (int cursor = static_cast(currentState); cursor >= 0; + cursor = parent[static_cast(cursor)]) { const size_t cellIndex = static_cast(cursor) / 4; const size_t i = cellIndex % matrix.cells_count_x; const size_t j = cellIndex / matrix.cells_count_x; @@ -523,28 +550,31 @@ bool Pathfinder::searchPath(path_t& path) const size_t currentI = currentIndex % matrix.cells_count_x; const size_t currentJ = currentIndex / matrix.cells_count_x; - const std::pair current {currentI, currentJ}; + const std::pair current{currentI, currentJ}; for (int direction = 0; direction < 4; ++direction) { const auto& delta = kDirections[direction]; const long nextI = static_cast(currentI) + delta.first; const long nextJ = static_cast(currentJ) + delta.second; - if (nextI < 0 || nextJ < 0 || nextI >= static_cast(matrix.cells_count_x) - || nextJ >= static_cast(matrix.cells_count_y)) { + if (nextI < 0 || nextJ < 0 || + nextI >= static_cast(matrix.cells_count_x) || + nextJ >= static_cast(matrix.cells_count_y)) { continue; } - const std::pair next {static_cast(nextI), static_cast(nextJ)}; + const std::pair next{static_cast(nextI), + static_cast(nextJ)}; if (matrix.at(next).wall) { continue; } const size_t nextIndex = matrix.index(next); const size_t nextState = stateId(nextIndex, direction); - const int turnCost = (parent[currentState] >= 0 && currentIndex != startIndex - && incomingDirection != direction) - ? kTurnPenalty - : 0; + const int turnCost = + (parent[currentState] >= 0 && currentIndex != startIndex && + incomingDirection != direction) + ? kTurnPenalty + : 0; const int tentative = gScore[currentState] + 1 + turnCost; if (tentative >= gScore[nextState]) { continue; @@ -552,7 +582,8 @@ bool Pathfinder::searchPath(path_t& path) parent[nextState] = static_cast(currentState); gScore[nextState] = tentative; - const int fScore = tentative + manhattanCells(next, matrix.finish_cell); + const int fScore = + tentative + manhattanCells(next, matrix.finish_cell); open.push({fScore, nextState}); } } @@ -561,8 +592,7 @@ bool Pathfinder::searchPath(path_t& path) return false; } -path_t Pathfinder::simplifyPath(const path_t& gridPath) const -{ +path_t Pathfinder::simplifyPath(const path_t& gridPath) const { if (gridPath.size() <= 2) { return gridPath; } diff --git a/VirtualTuringMachine/pathfinder.h b/VirtualTuringMachine/pathfinder.h index 41ede7c..65ac582 100644 --- a/VirtualTuringMachine/pathfinder.h +++ b/VirtualTuringMachine/pathfinder.h @@ -10,7 +10,7 @@ using wall_checker_t = std::function; using wall_painter_t = std::function; -using path_t = std::vector; +using path_t = std::vector; struct Cell { bool wall = false; @@ -24,12 +24,13 @@ struct Matrix { QPoint finish; size_t grid_size = 0; - std::pair start_cell {0, 0}; - std::pair finish_cell {0, 0}; + std::pair start_cell{0, 0}; + std::pair finish_cell{0, 0}; std::vector cells; Matrix() = default; - Matrix(const QPoint& start, const QPoint& finish, const QRect& bounds, size_t grid_size); + Matrix(const QPoint& start, const QPoint& finish, const QRect& bounds, + size_t grid_size); Cell& at(std::pair cell); const Cell& at(std::pair cell) const; @@ -38,33 +39,31 @@ struct Matrix { std::pair point_to_cell(const QPoint& point) const; void FillWalls(wall_checker_t checker); - void markBlockedPaths(const std::vector& blockedPaths, int pathCorridor); - bool segment_is_clear(std::pair from, std::pair to) const; + void markBlockedPaths(const std::vector& blockedPaths, + int pathCorridor); + bool segment_is_clear(std::pair from, + std::pair to) const; }; -class Pathfinder -{ -public: +class Pathfinder { + public: Pathfinder() = default; - path_t GetPath(const QPoint& start, - const QPoint& finish, - const QRect& bounds, - size_t grid_size, + path_t GetPath(const QPoint& start, const QPoint& finish, + const QRect& bounds, size_t grid_size, wall_checker_t checker, const std::vector& blockedPaths = {}, int pathCorridor = 6); -private: + private: Matrix matrix; bool searchPath(path_t& path); path_t simplifyPath(const path_t& gridPath) const; path_t optimizeOrthogonalPath(path_t path, wall_checker_t checker) const; path_t enforceTerminalDirections(path_t path) const; - bool pointBlocksPath(const QPoint& point, - const wall_checker_t& checker, + bool pointBlocksPath(const QPoint& point, const wall_checker_t& checker, const std::vector& blockedPaths, int pathCorridor) const; }; -#endif // PATHFINDER_H +#endif // PATHFINDER_H diff --git a/VirtualTuringMachine/screentools.cpp b/VirtualTuringMachine/screentools.cpp old mode 100755 new mode 100644 index 636bcf1..0843155 --- a/VirtualTuringMachine/screentools.cpp +++ b/VirtualTuringMachine/screentools.cpp @@ -1,53 +1,45 @@ #include "screentools.h" + #include -#include #include +#include #define MM2INCH 0.0393700787401575 #define INCH2MM 25.4 -ScreenTools::ScreenTools() -{ +ScreenTools::ScreenTools() { mDpi = QApplication::primaryScreen()->physicalDotsPerInch(); - int pxls =cvtMm2Px(6); + int pxls = cvtMm2Px(6); size.setWidth(pxls); size.setHeight(pxls); - pxls =cvtMm2Px(10); + pxls = cvtMm2Px(10); size2.setWidth(pxls); size2.setHeight(pxls); _font_size = cvtMm2Px(3); - pxls =cvtMm2Px(4); + pxls = cvtMm2Px(4); net.setWidth(pxls); net.setHeight(pxls); } -size_t ScreenTools::GetFontSize(){ - return _font_size; -} -const QSize& ScreenTools::GetCellSize(){ - return net; -} +size_t ScreenTools::GetFontSize() { return _font_size; } +const QSize& ScreenTools::GetCellSize() { return net; } -const QSize& ScreenTools::GetBigButtonSize(){ - return size2; -} -int ScreenTools::cvtMm2Px( qreal mm ) -{ - qreal inch = mm*MM2INCH; +const QSize& ScreenTools::GetBigButtonSize() { return size2; } +int ScreenTools::cvtMm2Px(qreal mm) { + qreal inch = mm * MM2INCH; - return cvtInch2Px( inch ); + return cvtInch2Px(inch); } -int ScreenTools::cvtInch2Px( qreal in ) -{ +int ScreenTools::cvtInch2Px(qreal in) { qreal px = in * mDpi; - return (int)(px+0.5); + return (int)(px + 0.5); } -void ScreenTools::ResizeButtonBig(QToolButton *btn){ +void ScreenTools::ResizeButtonBig(QToolButton* btn) { btn->setIconSize(size2); btn->setMaximumHeight(size2.height()); } @@ -58,11 +50,11 @@ void ScreenTools::ResizeLabel(QLabel *label){ // label->setMaximumHeight(size.height()/4); } */ -void ScreenTools::ResizeButton(QToolButton *btn){ +void ScreenTools::ResizeButton(QToolButton* btn) { btn->setIconSize(size); btn->setMaximumHeight(size.height()); } -void ScreenTools::ResizeButton(QPushButton *btn){ +void ScreenTools::ResizeButton(QPushButton* btn) { btn->setIconSize(size); btn->setMaximumHeight(size.height()); } @@ -75,12 +67,9 @@ void ScreenTools::ResizeFrame(QFrame *frame){ frame->setMinimumSize(size); } */ -void ScreenTools::ResizePropertyPanel(QFrame *frame){ - int pxls =cvtMm2Px(6); - frame->setMinimumSize(QSize(pxls,pxls)); +void ScreenTools::ResizePropertyPanel(QFrame* frame) { + int pxls = cvtMm2Px(6); + frame->setMinimumSize(QSize(pxls, pxls)); } -const QSize& ScreenTools::GetImageSize(){ - - return size; -} +const QSize& ScreenTools::GetImageSize() { return size; } diff --git a/VirtualTuringMachine/screentools.h b/VirtualTuringMachine/screentools.h old mode 100755 new mode 100644 index 4405055..a76abff --- a/VirtualTuringMachine/screentools.h +++ b/VirtualTuringMachine/screentools.h @@ -1,41 +1,40 @@ #ifndef SCREENTOOLS_H #define SCREENTOOLS_H -#include -#include -#include #include -#include #include +#include #include +#include +#include +#include #define REF_DPI 196.0f -class ScreenTools : public QObject -{ +class ScreenTools : public QObject { Q_OBJECT private: - qreal mDpi; - QSize size,size2; - QSize net; - size_t _font_size; - int cvtMm2Px( qreal mm ); - int cvtInch2Px( qreal in ); -public: + qreal mDpi; + QSize size, size2; + QSize net; + size_t _font_size; + int cvtMm2Px(qreal mm); + int cvtInch2Px(qreal in); + + public: ScreenTools(); - void ResizeButton(QToolButton *btn); - void ResizeButtonBig(QToolButton *btn); - void ResizeButton(QPushButton *btn); - //void ResizeLabel(QLabel *label); - //void ResizeSlider(QSlider *sld); - //void ResizeFrame(QFrame *frame); - void ResizePropertyPanel(QFrame *frame); + void ResizeButton(QToolButton* btn); + void ResizeButtonBig(QToolButton* btn); + void ResizeButton(QPushButton* btn); + // void ResizeLabel(QLabel *label); + // void ResizeSlider(QSlider *sld); + // void ResizeFrame(QFrame *frame); + void ResizePropertyPanel(QFrame* frame); const QSize& GetImageSize(); const QSize& GetCellSize(); const QSize& GetBigButtonSize(); - size_t GetFontSize(); - + size_t GetFontSize(); }; -#endif // SCREENTOOLS_H +#endif // SCREENTOOLS_H diff --git a/VirtualTuringMachine/statecontroller.h b/VirtualTuringMachine/statecontroller.h old mode 100755 new mode 100644 index 2f72ae5..6999a05 --- a/VirtualTuringMachine/statecontroller.h +++ b/VirtualTuringMachine/statecontroller.h @@ -2,108 +2,104 @@ #define STATECONTROLLER_H #include -#include + +#include #include #include -#include "vmtproject.h" -#include #include +#include + +#include "vmtproject.h" -class StateController{ -protected: +class StateController { + protected: std::vector> undo; - std::shared_ptr _state; + std::shared_ptr _state; std::shared_ptr _state_data; std::deque> _old_states; -public: + + public: virtual QWidget* GetContainer() = 0; - void Update() - { - if(_state) _state->BeforeChange(_state_data); + void Update() { + if (_state) _state->BeforeChange(_state_data); } - void ChangeState(std::shared_ptr new_state_data){ + void ChangeState(std::shared_ptr new_state_data) { qDebug() << "Clear old states"; ClearOldStates(); qDebug() << "Clear observer"; VMTProject::GetInstance().GetUndoManager()->SetObserver(nullptr); qDebug() << "StateController::Before change"; - if(_state) _state->BeforeChange(_state_data); - if(_state_data) - { + if (_state) _state->BeforeChange(_state_data); + if (_state_data) { qDebug() << "StateController::Place undo"; - if(_state_data->IsUndoPlacable()) undo.push_back(_state_data); + if (_state_data->IsUndoPlacable()) undo.push_back(_state_data); } _state_data = new_state_data; VMTProject::GetInstance().SetUIState(_state_data); qDebug() << "StateController::Construct state"; - if(_state_data){ - if(_state) { - _state->RemoveState(); - _old_states.push_back(_state); - } - _state = _state_data->ConstructNewState(this); - qDebug() << "StateController::Call On Change"; - OnChanged(_state,_state_data); + if (_state_data) { + if (_state) { + _state->RemoveState(); + _old_states.push_back(_state); + } + _state = _state_data->ConstructNewState(this); + qDebug() << "StateController::Call On Change"; + OnChanged(_state, _state_data); } qDebug() << "StateController::ChangeState Done"; } - virtual void ClearOldStates(){ - _old_states.clear(); - } + virtual void ClearOldStates() { _old_states.clear(); } - virtual void ShowWarning(std::shared_ptr) =0; - virtual void HideWarning(bool undo) =0; - virtual void OnChanged( std::shared_ptr , std::shared_ptr ){ + virtual void ShowWarning(std::shared_ptr) = 0; + virtual void HideWarning(bool undo) = 0; + virtual void OnChanged(std::shared_ptr, + std::shared_ptr) {} - } - - bool Undo(){ + bool Undo() { bool warning = false; - if(_state_data){ + if (_state_data) { qDebug() << "Clear observer"; VMTProject::GetInstance().GetUndoManager()->SetObserver(nullptr); - if(_state_data->IsNeedWarning()){ + if (_state_data->IsNeedWarning()) { warning = true; - QMessageBox::StandardButton resBtn = QMessageBox::question( nullptr, - "VMT", - "This will delete any unsaved project data. Are you sure?", - QMessageBox::No | QMessageBox::Yes, - QMessageBox::No); + QMessageBox::StandardButton resBtn = QMessageBox::question( + nullptr, "VMT", + "This will delete any unsaved project data. Are you sure?", + QMessageBox::No | QMessageBox::Yes, QMessageBox::No); if (resBtn != QMessageBox::Yes) { return false; - //event->ignore(); + // event->ignore(); } else { - warning = false; - //event->accept(); + warning = false; + // event->accept(); } - //ShowWarning(state_data); - + // ShowWarning(state_data); } } - if(!warning) UndoForce(); + if (!warning) UndoForce(); return true; } - void UndoForce(){ - if(!undo.empty()){ + void UndoForce() { + if (!undo.empty()) { _state_data = undo.back(); undo.pop_back(); - if(_state) _state->BeforeChange(_state_data); - if(_state_data){ - _state = _state_data->ConstructUndoState(this); - if(_state) - _state->AfterUndo(_state_data); - OnChanged(_state,_state_data); + if (_state) _state->BeforeChange(_state_data); + if (_state_data) { + _state = _state_data->ConstructUndoState(this); + if (_state) _state->AfterUndo(_state_data); + OnChanged(_state, _state_data); } - } else QApplication::quit(); + } else + QApplication::quit(); } virtual void EnableExercise(bool enable) = 0; @@ -127,9 +123,9 @@ class StateController{ virtual void EnableCancel(bool enable) = 0; virtual void EnableZoom(bool enable) = 0; - virtual int GetZoom() = 0; + virtual int GetZoom() = 0; virtual ~StateController() = default; }; -#endif // STATECONTROLLER_H +#endif // STATECONTROLLER_H diff --git a/VirtualTuringMachine/ui_formactionhint.h b/VirtualTuringMachine/ui_formactionhint.h old mode 100755 new mode 100644 index bd832b1..24d73d9 --- a/VirtualTuringMachine/ui_formactionhint.h +++ b/VirtualTuringMachine/ui_formactionhint.h @@ -9,8 +9,8 @@ #ifndef UI_FORMACTIONHINT_H #define UI_FORMACTIONHINT_H -#include #include +#include #include #include #include @@ -20,15 +20,13 @@ QT_BEGIN_NAMESPACE -class Ui_FormActionHint -{ -public: - QHBoxLayout *horizontalLayout; - QLabel *label_img; - QLabel *label_text; +class Ui_FormActionHint { + public: + QHBoxLayout* horizontalLayout; + QLabel* label_img; + QLabel* label_text; - void setupUi(QWidget *FormActionHint) - { + void setupUi(QWidget* FormActionHint) { if (FormActionHint->objectName().isEmpty()) FormActionHint->setObjectName(QStringLiteral("FormActionHint")); FormActionHint->resize(400, 46); @@ -40,7 +38,8 @@ class Ui_FormActionHint QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); - sizePolicy.setHeightForWidth(label_img->sizePolicy().hasHeightForWidth()); + sizePolicy.setHeightForWidth( + label_img->sizePolicy().hasHeightForWidth()); label_img->setSizePolicy(sizePolicy); horizontalLayout->addWidget(label_img); @@ -50,30 +49,31 @@ class Ui_FormActionHint QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Preferred); sizePolicy1.setHorizontalStretch(0); sizePolicy1.setVerticalStretch(0); - sizePolicy1.setHeightForWidth(label_text->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + label_text->sizePolicy().hasHeightForWidth()); label_text->setSizePolicy(sizePolicy1); horizontalLayout->addWidget(label_text); - retranslateUi(FormActionHint); QMetaObject::connectSlotsByName(FormActionHint); - } // setupUi - - void retranslateUi(QWidget *FormActionHint) - { - FormActionHint->setWindowTitle(QApplication::translate("FormActionHint", "Form", Q_NULLPTR)); - label_img->setText(QApplication::translate("FormActionHint", "TextLabel", Q_NULLPTR)); - label_text->setText(QApplication::translate("FormActionHint", "TextLabel", Q_NULLPTR)); - } // retranslateUi - + } // setupUi + + void retranslateUi(QWidget* FormActionHint) { + FormActionHint->setWindowTitle( + QApplication::translate("FormActionHint", "Form", Q_NULLPTR)); + label_img->setText( + QApplication::translate("FormActionHint", "TextLabel", Q_NULLPTR)); + label_text->setText( + QApplication::translate("FormActionHint", "TextLabel", Q_NULLPTR)); + } // retranslateUi }; namespace Ui { - class FormActionHint: public Ui_FormActionHint {}; -} // namespace Ui +class FormActionHint : public Ui_FormActionHint {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMACTIONHINT_H +#endif // UI_FORMACTIONHINT_H diff --git a/VirtualTuringMachine/ui_formalphabit.h b/VirtualTuringMachine/ui_formalphabit.h old mode 100755 new mode 100644 index 0ed86ae..b2f205a --- a/VirtualTuringMachine/ui_formalphabit.h +++ b/VirtualTuringMachine/ui_formalphabit.h @@ -9,8 +9,8 @@ #ifndef UI_FORMALPHABIT_H #define UI_FORMALPHABIT_H -#include #include +#include #include #include #include @@ -20,14 +20,12 @@ QT_BEGIN_NAMESPACE -class Ui_FormAlphabit -{ -public: - QHBoxLayout *horizontalLayout; - QFrame *frame; +class Ui_FormAlphabit { + public: + QHBoxLayout* horizontalLayout; + QFrame* frame; - void setupUi(QWidget *FormAlphabit) - { + void setupUi(QWidget* FormAlphabit) { if (FormAlphabit->objectName().isEmpty()) FormAlphabit->setObjectName(QStringLiteral("FormAlphabit")); FormAlphabit->resize(413, 174); @@ -46,23 +44,21 @@ class Ui_FormAlphabit horizontalLayout->addWidget(frame); - retranslateUi(FormAlphabit); QMetaObject::connectSlotsByName(FormAlphabit); - } // setupUi - - void retranslateUi(QWidget *FormAlphabit) - { - FormAlphabit->setWindowTitle(QApplication::translate("FormAlphabit", "Form", Q_NULLPTR)); - } // retranslateUi + } // setupUi + void retranslateUi(QWidget* FormAlphabit) { + FormAlphabit->setWindowTitle( + QApplication::translate("FormAlphabit", "Form", Q_NULLPTR)); + } // retranslateUi }; namespace Ui { - class FormAlphabit: public Ui_FormAlphabit {}; -} // namespace Ui +class FormAlphabit : public Ui_FormAlphabit {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMALPHABIT_H +#endif // UI_FORMALPHABIT_H diff --git a/VirtualTuringMachine/ui_formcalculator.h b/VirtualTuringMachine/ui_formcalculator.h old mode 100755 new mode 100644 index b06370c..5d03701 --- a/VirtualTuringMachine/ui_formcalculator.h +++ b/VirtualTuringMachine/ui_formcalculator.h @@ -9,8 +9,8 @@ #ifndef UI_FORMCALCULATOR_H #define UI_FORMCALCULATOR_H -#include #include +#include #include #include #include @@ -21,23 +21,22 @@ QT_BEGIN_NAMESPACE -class Ui_FormCalculator -{ -public: - QHBoxLayout *horizontalLayout; - QLineEdit *text_power; - QToolButton *_plus; - QToolButton *_minus; +class Ui_FormCalculator { + public: + QHBoxLayout* horizontalLayout; + QLineEdit* text_power; + QToolButton* _plus; + QToolButton* _minus; - void setupUi(QWidget *FormCalculator) - { + void setupUi(QWidget* FormCalculator) { if (FormCalculator->objectName().isEmpty()) FormCalculator->setObjectName(QStringLiteral("FormCalculator")); FormCalculator->resize(618, 26); QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); - sizePolicy.setHeightForWidth(FormCalculator->sizePolicy().hasHeightForWidth()); + sizePolicy.setHeightForWidth( + FormCalculator->sizePolicy().hasHeightForWidth()); FormCalculator->setSizePolicy(sizePolicy); horizontalLayout = new QHBoxLayout(FormCalculator); horizontalLayout->setObjectName(QStringLiteral("horizontalLayout")); @@ -50,7 +49,8 @@ class Ui_FormCalculator _plus = new QToolButton(FormCalculator); _plus->setObjectName(QStringLiteral("_plus")); QIcon icon; - icon.addFile(QStringLiteral(":/Files/images/plus.png"), QSize(), QIcon::Normal, QIcon::Off); + icon.addFile(QStringLiteral(":/Files/images/plus.png"), QSize(), + QIcon::Normal, QIcon::Off); _plus->setIcon(icon); horizontalLayout->addWidget(_plus); @@ -58,30 +58,29 @@ class Ui_FormCalculator _minus = new QToolButton(FormCalculator); _minus->setObjectName(QStringLiteral("_minus")); QIcon icon1; - icon1.addFile(QStringLiteral(":/Files/images/minus.png"), QSize(), QIcon::Normal, QIcon::Off); + icon1.addFile(QStringLiteral(":/Files/images/minus.png"), QSize(), + QIcon::Normal, QIcon::Off); _minus->setIcon(icon1); horizontalLayout->addWidget(_minus); - retranslateUi(FormCalculator); QMetaObject::connectSlotsByName(FormCalculator); - } // setupUi + } // setupUi - void retranslateUi(QWidget *FormCalculator) - { - FormCalculator->setWindowTitle(QApplication::translate("FormCalculator", "Form", Q_NULLPTR)); + void retranslateUi(QWidget* FormCalculator) { + FormCalculator->setWindowTitle( + QApplication::translate("FormCalculator", "Form", Q_NULLPTR)); _plus->setText(QString()); _minus->setText(QString()); - } // retranslateUi - + } // retranslateUi }; namespace Ui { - class FormCalculator: public Ui_FormCalculator {}; -} // namespace Ui +class FormCalculator : public Ui_FormCalculator {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMCALCULATOR_H +#endif // UI_FORMCALCULATOR_H diff --git a/VirtualTuringMachine/ui_formcompilermachine.h b/VirtualTuringMachine/ui_formcompilermachine.h old mode 100755 new mode 100644 index 67e3c41..86da46f --- a/VirtualTuringMachine/ui_formcompilermachine.h +++ b/VirtualTuringMachine/ui_formcompilermachine.h @@ -16,25 +16,25 @@ #include #include #include + #include "formeditorwidget.h" QT_BEGIN_NAMESPACE -class Ui_FormCompilerMachine -{ -public: - QVBoxLayout *verticalLayout; - QSplitter *splitter; - FormEditorWidget *widget_editor; - QToolBox *toolBox; - QWidget *page_2; - QVBoxLayout *verticalLayout_3; - QListWidget *list_errors; - - void setupUi(QWidget *FormCompilerMachine) - { +class Ui_FormCompilerMachine { + public: + QVBoxLayout* verticalLayout; + QSplitter* splitter; + FormEditorWidget* widget_editor; + QToolBox* toolBox; + QWidget* page_2; + QVBoxLayout* verticalLayout_3; + QListWidget* list_errors; + + void setupUi(QWidget* FormCompilerMachine) { if (FormCompilerMachine->objectName().isEmpty()) - FormCompilerMachine->setObjectName(QString::fromUtf8("FormCompilerMachine")); + FormCompilerMachine->setObjectName( + QString::fromUtf8("FormCompilerMachine")); FormCompilerMachine->resize(542, 434); verticalLayout = new QVBoxLayout(FormCompilerMachine); verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); @@ -47,7 +47,8 @@ class Ui_FormCompilerMachine QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(9); - sizePolicy.setHeightForWidth(widget_editor->sizePolicy().hasHeightForWidth()); + sizePolicy.setHeightForWidth( + widget_editor->sizePolicy().hasHeightForWidth()); widget_editor->setSizePolicy(sizePolicy); splitter->addWidget(widget_editor); toolBox = new QToolBox(splitter); @@ -55,7 +56,8 @@ class Ui_FormCompilerMachine QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Expanding); sizePolicy1.setHorizontalStretch(0); sizePolicy1.setVerticalStretch(1); - sizePolicy1.setHeightForWidth(toolBox->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + toolBox->sizePolicy().hasHeightForWidth()); toolBox->setSizePolicy(sizePolicy1); toolBox->setFrameShadow(QFrame::Plain); toolBox->setLineWidth(0); @@ -70,10 +72,12 @@ class Ui_FormCompilerMachine QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Expanding); sizePolicy2.setHorizontalStretch(0); sizePolicy2.setVerticalStretch(0); - sizePolicy2.setHeightForWidth(list_errors->sizePolicy().hasHeightForWidth()); + sizePolicy2.setHeightForWidth( + list_errors->sizePolicy().hasHeightForWidth()); list_errors->setSizePolicy(sizePolicy2); list_errors->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - list_errors->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow); + list_errors->setSizeAdjustPolicy( + QAbstractScrollArea::AdjustToContentsOnFirstShow); verticalLayout_3->addWidget(list_errors); @@ -82,27 +86,26 @@ class Ui_FormCompilerMachine verticalLayout->addWidget(splitter); - retranslateUi(FormCompilerMachine); toolBox->setCurrentIndex(0); - QMetaObject::connectSlotsByName(FormCompilerMachine); - } // setupUi - - void retranslateUi(QWidget *FormCompilerMachine) - { - FormCompilerMachine->setWindowTitle(QCoreApplication::translate("FormCompilerMachine", "Form", nullptr)); - toolBox->setItemText(toolBox->indexOf(page_2), QCoreApplication::translate("FormCompilerMachine", "Messages", nullptr)); - } // retranslateUi - + } // setupUi + + void retranslateUi(QWidget* FormCompilerMachine) { + FormCompilerMachine->setWindowTitle(QCoreApplication::translate( + "FormCompilerMachine", "Form", nullptr)); + toolBox->setItemText(toolBox->indexOf(page_2), + QCoreApplication::translate("FormCompilerMachine", + "Messages", nullptr)); + } // retranslateUi }; namespace Ui { - class FormCompilerMachine: public Ui_FormCompilerMachine {}; -} // namespace Ui +class FormCompilerMachine : public Ui_FormCompilerMachine {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMCOMPILERMACHINE_H +#endif // UI_FORMCOMPILERMACHINE_H diff --git a/VirtualTuringMachine/ui_formcomplexmachines.h b/VirtualTuringMachine/ui_formcomplexmachines.h old mode 100755 new mode 100644 index d51f171..bd6d6cb --- a/VirtualTuringMachine/ui_formcomplexmachines.h +++ b/VirtualTuringMachine/ui_formcomplexmachines.h @@ -9,8 +9,8 @@ #ifndef UI_FORMCOMPLEXMACHINES_H #define UI_FORMCOMPLEXMACHINES_H -#include #include +#include #include #include #include @@ -20,16 +20,15 @@ QT_BEGIN_NAMESPACE -class Ui_FormComplexMachines -{ -public: - QHBoxLayout *horizontalLayout; - QFrame *_frame; +class Ui_FormComplexMachines { + public: + QHBoxLayout* horizontalLayout; + QFrame* _frame; - void setupUi(QWidget *FormComplexMachines) - { + void setupUi(QWidget* FormComplexMachines) { if (FormComplexMachines->objectName().isEmpty()) - FormComplexMachines->setObjectName(QStringLiteral("FormComplexMachines")); + FormComplexMachines->setObjectName( + QStringLiteral("FormComplexMachines")); FormComplexMachines->resize(400, 108); horizontalLayout = new QHBoxLayout(FormComplexMachines); horizontalLayout->setObjectName(QStringLiteral("horizontalLayout")); @@ -42,23 +41,21 @@ class Ui_FormComplexMachines horizontalLayout->addWidget(_frame); - retranslateUi(FormComplexMachines); QMetaObject::connectSlotsByName(FormComplexMachines); - } // setupUi - - void retranslateUi(QWidget *FormComplexMachines) - { - FormComplexMachines->setWindowTitle(QApplication::translate("FormComplexMachines", "Form", Q_NULLPTR)); - } // retranslateUi + } // setupUi + void retranslateUi(QWidget* FormComplexMachines) { + FormComplexMachines->setWindowTitle( + QApplication::translate("FormComplexMachines", "Form", Q_NULLPTR)); + } // retranslateUi }; namespace Ui { - class FormComplexMachines: public Ui_FormComplexMachines {}; -} // namespace Ui +class FormComplexMachines : public Ui_FormComplexMachines {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMCOMPLEXMACHINES_H +#endif // UI_FORMCOMPLEXMACHINES_H diff --git a/VirtualTuringMachine/ui_formdebugermachine.h b/VirtualTuringMachine/ui_formdebugermachine.h old mode 100755 new mode 100644 index de5b215..1c2d413 --- a/VirtualTuringMachine/ui_formdebugermachine.h +++ b/VirtualTuringMachine/ui_formdebugermachine.h @@ -18,33 +18,33 @@ #include #include #include + #include "formeditorwidget.h" #include "formlinewidget.h" QT_BEGIN_NAMESPACE -class Ui_FormDebugerMachine -{ -public: - QVBoxLayout *verticalLayout; - QWidget *widget; - QHBoxLayout *horizontalLayout; - QToolButton *button_left_page; - QToolButton *button_left; - FormLineWidget *widget_line; - QToolButton *button_right; - QToolButton *button_right_page; - QWidget *left_panel; - QHBoxLayout *horizontalLayout_2; - QFrame *_tests_frame; - QVBoxLayout *verticalLayout_2; - QListView *_test_list; - FormEditorWidget *widget_editor; - - void setupUi(QWidget *FormDebugerMachine) - { +class Ui_FormDebugerMachine { + public: + QVBoxLayout* verticalLayout; + QWidget* widget; + QHBoxLayout* horizontalLayout; + QToolButton* button_left_page; + QToolButton* button_left; + FormLineWidget* widget_line; + QToolButton* button_right; + QToolButton* button_right_page; + QWidget* left_panel; + QHBoxLayout* horizontalLayout_2; + QFrame* _tests_frame; + QVBoxLayout* verticalLayout_2; + QListView* _test_list; + FormEditorWidget* widget_editor; + + void setupUi(QWidget* FormDebugerMachine) { if (FormDebugerMachine->objectName().isEmpty()) - FormDebugerMachine->setObjectName(QString::fromUtf8("FormDebugerMachine")); + FormDebugerMachine->setObjectName( + QString::fromUtf8("FormDebugerMachine")); FormDebugerMachine->resize(583, 452); verticalLayout = new QVBoxLayout(FormDebugerMachine); verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); @@ -56,7 +56,8 @@ class Ui_FormDebugerMachine sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(widget->sizePolicy().hasHeightForWidth()); widget->setSizePolicy(sizePolicy); - widget->setStyleSheet(QString::fromUtf8("color:black;background:white")); + widget->setStyleSheet( + QString::fromUtf8("color:black;background:white")); horizontalLayout = new QHBoxLayout(widget); horizontalLayout->setSpacing(0); horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); @@ -65,7 +66,8 @@ class Ui_FormDebugerMachine button_left_page->setObjectName(QString::fromUtf8("button_left_page")); button_left_page->setStyleSheet(QString::fromUtf8("background:white;")); QIcon icon; - icon.addFile(QString::fromUtf8(":/Files/images/left_page.png"), QSize(), QIcon::Normal, QIcon::Off); + icon.addFile(QString::fromUtf8(":/Files/images/left_page.png"), QSize(), + QIcon::Normal, QIcon::Off); button_left_page->setIcon(icon); button_left_page->setIconSize(QSize(32, 32)); button_left_page->setAutoRaise(true); @@ -76,7 +78,8 @@ class Ui_FormDebugerMachine button_left->setObjectName(QString::fromUtf8("button_left")); button_left->setStyleSheet(QString::fromUtf8("background:white;")); QIcon icon1; - icon1.addFile(QString::fromUtf8(":/Files/images/left.png"), QSize(), QIcon::Normal, QIcon::Off); + icon1.addFile(QString::fromUtf8(":/Files/images/left.png"), QSize(), + QIcon::Normal, QIcon::Off); button_left->setIcon(icon1); button_left->setIconSize(QSize(32, 32)); button_left->setAutoRaise(true); @@ -92,7 +95,8 @@ class Ui_FormDebugerMachine button_right->setObjectName(QString::fromUtf8("button_right")); button_right->setStyleSheet(QString::fromUtf8("background:white;")); QIcon icon2; - icon2.addFile(QString::fromUtf8(":/Files/images/right.png"), QSize(), QIcon::Normal, QIcon::Off); + icon2.addFile(QString::fromUtf8(":/Files/images/right.png"), QSize(), + QIcon::Normal, QIcon::Off); button_right->setIcon(icon2); button_right->setIconSize(QSize(32, 32)); button_right->setAutoRaise(true); @@ -100,17 +104,19 @@ class Ui_FormDebugerMachine horizontalLayout->addWidget(button_right); button_right_page = new QToolButton(widget); - button_right_page->setObjectName(QString::fromUtf8("button_right_page")); - button_right_page->setStyleSheet(QString::fromUtf8("background:white;")); + button_right_page->setObjectName( + QString::fromUtf8("button_right_page")); + button_right_page->setStyleSheet( + QString::fromUtf8("background:white;")); QIcon icon3; - icon3.addFile(QString::fromUtf8(":/Files/images/right_page.png"), QSize(), QIcon::Normal, QIcon::Off); + icon3.addFile(QString::fromUtf8(":/Files/images/right_page.png"), + QSize(), QIcon::Normal, QIcon::Off); button_right_page->setIcon(icon3); button_right_page->setIconSize(QSize(32, 32)); button_right_page->setAutoRaise(true); horizontalLayout->addWidget(button_right_page); - verticalLayout->addWidget(widget); left_panel = new QWidget(FormDebugerMachine); @@ -118,16 +124,19 @@ class Ui_FormDebugerMachine QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Preferred); sizePolicy1.setHorizontalStretch(0); sizePolicy1.setVerticalStretch(0); - sizePolicy1.setHeightForWidth(left_panel->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + left_panel->sizePolicy().hasHeightForWidth()); left_panel->setSizePolicy(sizePolicy1); horizontalLayout_2 = new QHBoxLayout(left_panel); - horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2")); + horizontalLayout_2->setObjectName( + QString::fromUtf8("horizontalLayout_2")); _tests_frame = new QFrame(left_panel); _tests_frame->setObjectName(QString::fromUtf8("_tests_frame")); QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Expanding); sizePolicy2.setHorizontalStretch(1); sizePolicy2.setVerticalStretch(0); - sizePolicy2.setHeightForWidth(_tests_frame->sizePolicy().hasHeightForWidth()); + sizePolicy2.setHeightForWidth( + _tests_frame->sizePolicy().hasHeightForWidth()); _tests_frame->setSizePolicy(sizePolicy2); _tests_frame->setFrameShape(QFrame::NoFrame); _tests_frame->setFrameShadow(QFrame::Raised); @@ -136,12 +145,12 @@ class Ui_FormDebugerMachine verticalLayout_2->setContentsMargins(0, 0, 0, 0); _test_list = new QListView(_tests_frame); _test_list->setObjectName(QString::fromUtf8("_test_list")); - sizePolicy1.setHeightForWidth(_test_list->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + _test_list->sizePolicy().hasHeightForWidth()); _test_list->setSizePolicy(sizePolicy1); verticalLayout_2->addWidget(_test_list); - horizontalLayout_2->addWidget(_tests_frame, 0, Qt::AlignLeft); widget_editor = new FormEditorWidget(left_panel); @@ -149,35 +158,33 @@ class Ui_FormDebugerMachine QSizePolicy sizePolicy3(QSizePolicy::Expanding, QSizePolicy::Expanding); sizePolicy3.setHorizontalStretch(9); sizePolicy3.setVerticalStretch(0); - sizePolicy3.setHeightForWidth(widget_editor->sizePolicy().hasHeightForWidth()); + sizePolicy3.setHeightForWidth( + widget_editor->sizePolicy().hasHeightForWidth()); widget_editor->setSizePolicy(sizePolicy3); horizontalLayout_2->addWidget(widget_editor); - verticalLayout->addWidget(left_panel); - retranslateUi(FormDebugerMachine); QMetaObject::connectSlotsByName(FormDebugerMachine); - } // setupUi + } // setupUi - void retranslateUi(QWidget *FormDebugerMachine) - { - FormDebugerMachine->setWindowTitle(QCoreApplication::translate("FormDebugerMachine", "Form", nullptr)); + void retranslateUi(QWidget* FormDebugerMachine) { + FormDebugerMachine->setWindowTitle( + QCoreApplication::translate("FormDebugerMachine", "Form", nullptr)); button_left_page->setText(QString()); button_left->setText(QString()); button_right->setText(QString()); button_right_page->setText(QString()); - } // retranslateUi - + } // retranslateUi }; namespace Ui { - class FormDebugerMachine: public Ui_FormDebugerMachine {}; -} // namespace Ui +class FormDebugerMachine : public Ui_FormDebugerMachine {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMDEBUGERMACHINE_H +#endif // UI_FORMDEBUGERMACHINE_H diff --git a/VirtualTuringMachine/ui_formeditormachine.h b/VirtualTuringMachine/ui_formeditormachine.h old mode 100755 new mode 100644 index e03a715..db7745b --- a/VirtualTuringMachine/ui_formeditormachine.h +++ b/VirtualTuringMachine/ui_formeditormachine.h @@ -21,60 +21,60 @@ #include #include #include + #include "formeditorwidget.h" QT_BEGIN_NAMESPACE -class Ui_FormEditorMachine -{ -public: - QVBoxLayout *verticalLayout_6; - QSplitter *splitter; - QFrame *frame; - QVBoxLayout *verticalLayout_2; - QFrame *tool_frame; - QVBoxLayout *verticalLayout_5; - QFrame *frame_3; - QGridLayout *gridLayout; - QToolButton *tool_pointer; - QToolButton *tool_machine_right; - QToolButton *tool_machine_left_word; - QToolButton *tool_translate; - QToolButton *tool_machine_copy; - QToolButton *tool_machine_lambda; - QToolButton *tool_machine_finish; - QToolButton *tool_trash; - QToolButton *tool_machine_left; - QToolButton *tool_machine_right_word; - QToolButton *tool_machine_start; - QToolButton *tool_link; - QSpacerItem *verticalSpacer; - QFrame *frame_6; - QFrame *frame_7; - QVBoxLayout *verticalLayout_8; - QFrame *frame_navi; - QHBoxLayout *horizontalLayout_2; - QToolButton *tool_complex; - QToolButton *_navi; - QFrame *frame_4; - QVBoxLayout *verticalLayout; - QWidget *widget_5; - QVBoxLayout *verticalLayout_4; - FormEditorWidget *widget_editor; - QFrame *properties_frame; - QVBoxLayout *verticalLayout_3; - QFrame *frame_2; - QVBoxLayout *verticalLayout_7; - QFrame *frame_5; - QHBoxLayout *horizontalLayout; - QLabel *label_image; - QLabel *label_title; - QFrame *properties; - - void setupUi(QWidget *FormEditorMachine) - { +class Ui_FormEditorMachine { + public: + QVBoxLayout* verticalLayout_6; + QSplitter* splitter; + QFrame* frame; + QVBoxLayout* verticalLayout_2; + QFrame* tool_frame; + QVBoxLayout* verticalLayout_5; + QFrame* frame_3; + QGridLayout* gridLayout; + QToolButton* tool_pointer; + QToolButton* tool_machine_right; + QToolButton* tool_machine_left_word; + QToolButton* tool_translate; + QToolButton* tool_machine_copy; + QToolButton* tool_machine_lambda; + QToolButton* tool_machine_finish; + QToolButton* tool_trash; + QToolButton* tool_machine_left; + QToolButton* tool_machine_right_word; + QToolButton* tool_machine_start; + QToolButton* tool_link; + QSpacerItem* verticalSpacer; + QFrame* frame_6; + QFrame* frame_7; + QVBoxLayout* verticalLayout_8; + QFrame* frame_navi; + QHBoxLayout* horizontalLayout_2; + QToolButton* tool_complex; + QToolButton* _navi; + QFrame* frame_4; + QVBoxLayout* verticalLayout; + QWidget* widget_5; + QVBoxLayout* verticalLayout_4; + FormEditorWidget* widget_editor; + QFrame* properties_frame; + QVBoxLayout* verticalLayout_3; + QFrame* frame_2; + QVBoxLayout* verticalLayout_7; + QFrame* frame_5; + QHBoxLayout* horizontalLayout; + QLabel* label_image; + QLabel* label_title; + QFrame* properties; + + void setupUi(QWidget* FormEditorMachine) { if (FormEditorMachine->objectName().isEmpty()) - FormEditorMachine->setObjectName(QString::fromUtf8("FormEditorMachine")); + FormEditorMachine->setObjectName( + QString::fromUtf8("FormEditorMachine")); FormEditorMachine->resize(600, 440); verticalLayout_6 = new QVBoxLayout(FormEditorMachine); verticalLayout_6->setObjectName(QString::fromUtf8("verticalLayout_6")); @@ -84,7 +84,8 @@ class Ui_FormEditorMachine splitter->setOrientation(Qt::Horizontal); frame = new QFrame(splitter); frame->setObjectName(QString::fromUtf8("frame")); - QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding); + QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, + QSizePolicy::Expanding); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(frame->sizePolicy().hasHeightForWidth()); @@ -97,7 +98,8 @@ class Ui_FormEditorMachine verticalLayout_2->setContentsMargins(0, 0, 0, 0); tool_frame = new QFrame(frame); tool_frame->setObjectName(QString::fromUtf8("tool_frame")); - tool_frame->setStyleSheet(QString::fromUtf8("color:white;background:#01547a;")); + tool_frame->setStyleSheet( + QString::fromUtf8("color:white;background:#01547a;")); tool_frame->setFrameShape(QFrame::NoFrame); tool_frame->setFrameShadow(QFrame::Raised); verticalLayout_5 = new QVBoxLayout(tool_frame); @@ -116,11 +118,14 @@ class Ui_FormEditorMachine QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Fixed); sizePolicy1.setHorizontalStretch(0); sizePolicy1.setVerticalStretch(0); - sizePolicy1.setHeightForWidth(tool_pointer->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + tool_pointer->sizePolicy().hasHeightForWidth()); tool_pointer->setSizePolicy(sizePolicy1); tool_pointer->setStyleSheet(QString::fromUtf8("")); QIcon icon; - icon.addFile(QString::fromUtf8(":/Files/images/toolbars/tools/icon_arrow.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon.addFile( + QString::fromUtf8(":/Files/images/toolbars/tools/icon_arrow.gif"), + QSize(), QIcon::Normal, QIcon::Off); tool_pointer->setIcon(icon); tool_pointer->setIconSize(QSize(24, 24)); tool_pointer->setCheckable(true); @@ -132,12 +137,16 @@ class Ui_FormEditorMachine gridLayout->addWidget(tool_pointer, 0, 0, 1, 1); tool_machine_right = new QToolButton(frame_3); - tool_machine_right->setObjectName(QString::fromUtf8("tool_machine_right")); - sizePolicy1.setHeightForWidth(tool_machine_right->sizePolicy().hasHeightForWidth()); + tool_machine_right->setObjectName( + QString::fromUtf8("tool_machine_right")); + sizePolicy1.setHeightForWidth( + tool_machine_right->sizePolicy().hasHeightForWidth()); tool_machine_right->setSizePolicy(sizePolicy1); tool_machine_right->setStyleSheet(QString::fromUtf8("")); QIcon icon1; - icon1.addFile(QString::fromUtf8(":/Files/images/toolbars/tools/icon_r_small.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon1.addFile( + QString::fromUtf8(":/Files/images/toolbars/tools/icon_r_small.gif"), + QSize(), QIcon::Normal, QIcon::Off); tool_machine_right->setIcon(icon1); tool_machine_right->setIconSize(QSize(24, 24)); tool_machine_right->setCheckable(true); @@ -146,12 +155,16 @@ class Ui_FormEditorMachine gridLayout->addWidget(tool_machine_right, 4, 1, 1, 1); tool_machine_left_word = new QToolButton(frame_3); - tool_machine_left_word->setObjectName(QString::fromUtf8("tool_machine_left_word")); - sizePolicy1.setHeightForWidth(tool_machine_left_word->sizePolicy().hasHeightForWidth()); + tool_machine_left_word->setObjectName( + QString::fromUtf8("tool_machine_left_word")); + sizePolicy1.setHeightForWidth( + tool_machine_left_word->sizePolicy().hasHeightForWidth()); tool_machine_left_word->setSizePolicy(sizePolicy1); tool_machine_left_word->setStyleSheet(QString::fromUtf8("")); QIcon icon2; - icon2.addFile(QString::fromUtf8(":/Files/images/toolbars/tools/icon_l_big.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon2.addFile( + QString::fromUtf8(":/Files/images/toolbars/tools/icon_l_big.gif"), + QSize(), QIcon::Normal, QIcon::Off); tool_machine_left_word->setIcon(icon2); tool_machine_left_word->setIconSize(QSize(24, 24)); tool_machine_left_word->setCheckable(true); @@ -161,11 +174,14 @@ class Ui_FormEditorMachine tool_translate = new QToolButton(frame_3); tool_translate->setObjectName(QString::fromUtf8("tool_translate")); - sizePolicy1.setHeightForWidth(tool_translate->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + tool_translate->sizePolicy().hasHeightForWidth()); tool_translate->setSizePolicy(sizePolicy1); tool_translate->setStyleSheet(QString::fromUtf8("")); QIcon icon3; - icon3.addFile(QString::fromUtf8(":/Files/images/toolbars/tools/icon_hand.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon3.addFile( + QString::fromUtf8(":/Files/images/toolbars/tools/icon_hand.gif"), + QSize(), QIcon::Normal, QIcon::Off); tool_translate->setIcon(icon3); tool_translate->setIconSize(QSize(24, 24)); tool_translate->setCheckable(true); @@ -174,12 +190,16 @@ class Ui_FormEditorMachine gridLayout->addWidget(tool_translate, 1, 0, 1, 1); tool_machine_copy = new QToolButton(frame_3); - tool_machine_copy->setObjectName(QString::fromUtf8("tool_machine_copy")); - sizePolicy1.setHeightForWidth(tool_machine_copy->sizePolicy().hasHeightForWidth()); + tool_machine_copy->setObjectName( + QString::fromUtf8("tool_machine_copy")); + sizePolicy1.setHeightForWidth( + tool_machine_copy->sizePolicy().hasHeightForWidth()); tool_machine_copy->setSizePolicy(sizePolicy1); tool_machine_copy->setStyleSheet(QString::fromUtf8("")); QIcon icon4; - icon4.addFile(QString::fromUtf8(":/Files/images/toolbars/tools/icon_k.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon4.addFile( + QString::fromUtf8(":/Files/images/toolbars/tools/icon_k.gif"), + QSize(), QIcon::Normal, QIcon::Off); tool_machine_copy->setIcon(icon4); tool_machine_copy->setIconSize(QSize(24, 24)); tool_machine_copy->setCheckable(true); @@ -188,12 +208,16 @@ class Ui_FormEditorMachine gridLayout->addWidget(tool_machine_copy, 6, 0, 1, 1); tool_machine_lambda = new QToolButton(frame_3); - tool_machine_lambda->setObjectName(QString::fromUtf8("tool_machine_lambda")); - sizePolicy1.setHeightForWidth(tool_machine_lambda->sizePolicy().hasHeightForWidth()); + tool_machine_lambda->setObjectName( + QString::fromUtf8("tool_machine_lambda")); + sizePolicy1.setHeightForWidth( + tool_machine_lambda->sizePolicy().hasHeightForWidth()); tool_machine_lambda->setSizePolicy(sizePolicy1); tool_machine_lambda->setStyleSheet(QString::fromUtf8("")); QIcon icon5; - icon5.addFile(QString::fromUtf8(":/Files/images/toolbars/tools/icon_lambda.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon5.addFile( + QString::fromUtf8(":/Files/images/toolbars/tools/icon_lambda.gif"), + QSize(), QIcon::Normal, QIcon::Off); tool_machine_lambda->setIcon(icon5); tool_machine_lambda->setIconSize(QSize(24, 24)); tool_machine_lambda->setCheckable(true); @@ -202,12 +226,16 @@ class Ui_FormEditorMachine gridLayout->addWidget(tool_machine_lambda, 6, 1, 1, 1); tool_machine_finish = new QToolButton(frame_3); - tool_machine_finish->setObjectName(QString::fromUtf8("tool_machine_finish")); - sizePolicy1.setHeightForWidth(tool_machine_finish->sizePolicy().hasHeightForWidth()); + tool_machine_finish->setObjectName( + QString::fromUtf8("tool_machine_finish")); + sizePolicy1.setHeightForWidth( + tool_machine_finish->sizePolicy().hasHeightForWidth()); tool_machine_finish->setSizePolicy(sizePolicy1); tool_machine_finish->setStyleSheet(QString::fromUtf8("")); QIcon icon6; - icon6.addFile(QString::fromUtf8(":/images/toolbars/tools/icon_finish.png"), QSize(), QIcon::Normal, QIcon::Off); + icon6.addFile( + QString::fromUtf8(":/images/toolbars/tools/icon_finish.png"), + QSize(), QIcon::Normal, QIcon::Off); tool_machine_finish->setIcon(icon6); tool_machine_finish->setIconSize(QSize(24, 24)); tool_machine_finish->setCheckable(true); @@ -217,11 +245,14 @@ class Ui_FormEditorMachine tool_trash = new QToolButton(frame_3); tool_trash->setObjectName(QString::fromUtf8("tool_trash")); - sizePolicy1.setHeightForWidth(tool_trash->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + tool_trash->sizePolicy().hasHeightForWidth()); tool_trash->setSizePolicy(sizePolicy1); tool_trash->setStyleSheet(QString::fromUtf8("")); QIcon icon7; - icon7.addFile(QString::fromUtf8(":/Files/images/toolbars/tools/icon_delete.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon7.addFile( + QString::fromUtf8(":/Files/images/toolbars/tools/icon_delete.gif"), + QSize(), QIcon::Normal, QIcon::Off); tool_trash->setIcon(icon7); tool_trash->setIconSize(QSize(24, 24)); tool_trash->setCheckable(true); @@ -230,12 +261,16 @@ class Ui_FormEditorMachine gridLayout->addWidget(tool_trash, 1, 1, 1, 1); tool_machine_left = new QToolButton(frame_3); - tool_machine_left->setObjectName(QString::fromUtf8("tool_machine_left")); - sizePolicy1.setHeightForWidth(tool_machine_left->sizePolicy().hasHeightForWidth()); + tool_machine_left->setObjectName( + QString::fromUtf8("tool_machine_left")); + sizePolicy1.setHeightForWidth( + tool_machine_left->sizePolicy().hasHeightForWidth()); tool_machine_left->setSizePolicy(sizePolicy1); tool_machine_left->setStyleSheet(QString::fromUtf8("")); QIcon icon8; - icon8.addFile(QString::fromUtf8(":/Files/images/toolbars/tools/icon_l_small.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon8.addFile( + QString::fromUtf8(":/Files/images/toolbars/tools/icon_l_small.gif"), + QSize(), QIcon::Normal, QIcon::Off); tool_machine_left->setIcon(icon8); tool_machine_left->setIconSize(QSize(24, 24)); tool_machine_left->setCheckable(true); @@ -244,12 +279,16 @@ class Ui_FormEditorMachine gridLayout->addWidget(tool_machine_left, 4, 0, 1, 1); tool_machine_right_word = new QToolButton(frame_3); - tool_machine_right_word->setObjectName(QString::fromUtf8("tool_machine_right_word")); - sizePolicy1.setHeightForWidth(tool_machine_right_word->sizePolicy().hasHeightForWidth()); + tool_machine_right_word->setObjectName( + QString::fromUtf8("tool_machine_right_word")); + sizePolicy1.setHeightForWidth( + tool_machine_right_word->sizePolicy().hasHeightForWidth()); tool_machine_right_word->setSizePolicy(sizePolicy1); tool_machine_right_word->setStyleSheet(QString::fromUtf8("")); QIcon icon9; - icon9.addFile(QString::fromUtf8(":/Files/images/toolbars/tools/icon_r_big.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon9.addFile( + QString::fromUtf8(":/Files/images/toolbars/tools/icon_r_big.gif"), + QSize(), QIcon::Normal, QIcon::Off); tool_machine_right_word->setIcon(icon9); tool_machine_right_word->setIconSize(QSize(24, 24)); tool_machine_right_word->setCheckable(true); @@ -258,12 +297,16 @@ class Ui_FormEditorMachine gridLayout->addWidget(tool_machine_right_word, 5, 1, 1, 1); tool_machine_start = new QToolButton(frame_3); - tool_machine_start->setObjectName(QString::fromUtf8("tool_machine_start")); - sizePolicy1.setHeightForWidth(tool_machine_start->sizePolicy().hasHeightForWidth()); + tool_machine_start->setObjectName( + QString::fromUtf8("tool_machine_start")); + sizePolicy1.setHeightForWidth( + tool_machine_start->sizePolicy().hasHeightForWidth()); tool_machine_start->setSizePolicy(sizePolicy1); tool_machine_start->setStyleSheet(QString::fromUtf8("")); QIcon icon10; - icon10.addFile(QString::fromUtf8(":/images/toolbars/tools/icon_start.png"), QSize(), QIcon::Normal, QIcon::Off); + icon10.addFile( + QString::fromUtf8(":/images/toolbars/tools/icon_start.png"), + QSize(), QIcon::Normal, QIcon::Off); tool_machine_start->setIcon(icon10); tool_machine_start->setIconSize(QSize(24, 24)); tool_machine_start->setCheckable(true); @@ -273,11 +316,14 @@ class Ui_FormEditorMachine tool_link = new QToolButton(frame_3); tool_link->setObjectName(QString::fromUtf8("tool_link")); - sizePolicy1.setHeightForWidth(tool_link->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + tool_link->sizePolicy().hasHeightForWidth()); tool_link->setSizePolicy(sizePolicy1); tool_link->setStyleSheet(QString::fromUtf8("")); QIcon icon11; - icon11.addFile(QString::fromUtf8(":/Files/images/toolbars/tools/icon_link.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon11.addFile( + QString::fromUtf8(":/Files/images/toolbars/tools/icon_link.gif"), + QSize(), QIcon::Normal, QIcon::Off); tool_link->setIcon(icon11); tool_link->setIconSize(QSize(24, 24)); tool_link->setCheckable(true); @@ -285,11 +331,11 @@ class Ui_FormEditorMachine gridLayout->addWidget(tool_link, 0, 1, 1, 1); - verticalSpacer = new QSpacerItem(12, 12, QSizePolicy::Minimum, QSizePolicy::Expanding); + verticalSpacer = new QSpacerItem(12, 12, QSizePolicy::Minimum, + QSizePolicy::Expanding); gridLayout->addItem(verticalSpacer, 2, 0, 1, 1); - verticalLayout_5->addWidget(frame_3); frame_6 = new QFrame(tool_frame); @@ -297,7 +343,8 @@ class Ui_FormEditorMachine QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Expanding); sizePolicy2.setHorizontalStretch(0); sizePolicy2.setVerticalStretch(0); - sizePolicy2.setHeightForWidth(frame_6->sizePolicy().hasHeightForWidth()); + sizePolicy2.setHeightForWidth( + frame_6->sizePolicy().hasHeightForWidth()); frame_6->setSizePolicy(sizePolicy2); frame_6->setFrameShape(QFrame::NoFrame); frame_6->setFrameShadow(QFrame::Raised); @@ -309,7 +356,8 @@ class Ui_FormEditorMachine QSizePolicy sizePolicy3(QSizePolicy::Expanding, QSizePolicy::Preferred); sizePolicy3.setHorizontalStretch(0); sizePolicy3.setVerticalStretch(0); - sizePolicy3.setHeightForWidth(frame_7->sizePolicy().hasHeightForWidth()); + sizePolicy3.setHeightForWidth( + frame_7->sizePolicy().hasHeightForWidth()); frame_7->setSizePolicy(sizePolicy3); frame_7->setFrameShape(QFrame::NoFrame); frame_7->setFrameShadow(QFrame::Raised); @@ -321,21 +369,26 @@ class Ui_FormEditorMachine QSizePolicy sizePolicy4(QSizePolicy::Expanding, QSizePolicy::Minimum); sizePolicy4.setHorizontalStretch(0); sizePolicy4.setVerticalStretch(0); - sizePolicy4.setHeightForWidth(frame_navi->sizePolicy().hasHeightForWidth()); + sizePolicy4.setHeightForWidth( + frame_navi->sizePolicy().hasHeightForWidth()); frame_navi->setSizePolicy(sizePolicy4); frame_navi->setMinimumSize(QSize(0, 0)); frame_navi->setFrameShape(QFrame::NoFrame); frame_navi->setFrameShadow(QFrame::Raised); horizontalLayout_2 = new QHBoxLayout(frame_navi); - horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2")); + horizontalLayout_2->setObjectName( + QString::fromUtf8("horizontalLayout_2")); horizontalLayout_2->setContentsMargins(4, 4, 4, 4); tool_complex = new QToolButton(frame_navi); tool_complex->setObjectName(QString::fromUtf8("tool_complex")); - sizePolicy1.setHeightForWidth(tool_complex->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + tool_complex->sizePolicy().hasHeightForWidth()); tool_complex->setSizePolicy(sizePolicy1); tool_complex->setStyleSheet(QString::fromUtf8("")); QIcon icon12; - icon12.addFile(QString::fromUtf8(":/Files/images/toolbars/tools/icon_complex.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon12.addFile( + QString::fromUtf8(":/Files/images/toolbars/tools/icon_complex.gif"), + QSize(), QIcon::Normal, QIcon::Off); tool_complex->setIcon(icon12); tool_complex->setIconSize(QSize(24, 24)); tool_complex->setCheckable(false); @@ -348,19 +401,17 @@ class Ui_FormEditorMachine sizePolicy1.setHeightForWidth(_navi->sizePolicy().hasHeightForWidth()); _navi->setSizePolicy(sizePolicy1); QIcon icon13; - icon13.addFile(QString::fromUtf8(":/Files/images/nav.png"), QSize(), QIcon::Normal, QIcon::Off); + icon13.addFile(QString::fromUtf8(":/Files/images/nav.png"), QSize(), + QIcon::Normal, QIcon::Off); _navi->setIcon(icon13); _navi->setIconSize(QSize(24, 24)); horizontalLayout_2->addWidget(_navi); - verticalLayout_8->addWidget(frame_navi); - verticalLayout_5->addWidget(frame_7); - verticalLayout_2->addWidget(tool_frame); splitter->addWidget(frame); @@ -369,7 +420,8 @@ class Ui_FormEditorMachine QSizePolicy sizePolicy5(QSizePolicy::Expanding, QSizePolicy::Expanding); sizePolicy5.setHorizontalStretch(9); sizePolicy5.setVerticalStretch(0); - sizePolicy5.setHeightForWidth(frame_4->sizePolicy().hasHeightForWidth()); + sizePolicy5.setHeightForWidth( + frame_4->sizePolicy().hasHeightForWidth()); frame_4->setSizePolicy(sizePolicy5); frame_4->setFrameShape(QFrame::NoFrame); frame_4->setFrameShadow(QFrame::Plain); @@ -381,25 +433,27 @@ class Ui_FormEditorMachine QSizePolicy sizePolicy6(QSizePolicy::Expanding, QSizePolicy::Expanding); sizePolicy6.setHorizontalStretch(0); sizePolicy6.setVerticalStretch(9); - sizePolicy6.setHeightForWidth(widget_5->sizePolicy().hasHeightForWidth()); + sizePolicy6.setHeightForWidth( + widget_5->sizePolicy().hasHeightForWidth()); widget_5->setSizePolicy(sizePolicy6); verticalLayout_4 = new QVBoxLayout(widget_5); verticalLayout_4->setObjectName(QString::fromUtf8("verticalLayout_4")); verticalLayout_4->setContentsMargins(0, 0, 0, 0); widget_editor = new FormEditorWidget(widget_5); widget_editor->setObjectName(QString::fromUtf8("widget_editor")); - sizePolicy2.setHeightForWidth(widget_editor->sizePolicy().hasHeightForWidth()); + sizePolicy2.setHeightForWidth( + widget_editor->sizePolicy().hasHeightForWidth()); widget_editor->setSizePolicy(sizePolicy2); widget_editor->setMinimumSize(QSize(128, 128)); verticalLayout_4->addWidget(widget_editor); - verticalLayout->addWidget(widget_5); properties_frame = new QFrame(frame_4); properties_frame->setObjectName(QString::fromUtf8("properties_frame")); - sizePolicy4.setHeightForWidth(properties_frame->sizePolicy().hasHeightForWidth()); + sizePolicy4.setHeightForWidth( + properties_frame->sizePolicy().hasHeightForWidth()); properties_frame->setSizePolicy(sizePolicy4); properties_frame->setMinimumSize(QSize(0, 0)); properties_frame->setFrameShape(QFrame::NoFrame); @@ -409,7 +463,8 @@ class Ui_FormEditorMachine verticalLayout_3->setContentsMargins(0, 0, 0, 0); frame_2 = new QFrame(properties_frame); frame_2->setObjectName(QString::fromUtf8("frame_2")); - sizePolicy4.setHeightForWidth(frame_2->sizePolicy().hasHeightForWidth()); + sizePolicy4.setHeightForWidth( + frame_2->sizePolicy().hasHeightForWidth()); frame_2->setSizePolicy(sizePolicy4); frame_2->setFrameShape(QFrame::NoFrame); frame_2->setFrameShadow(QFrame::Raised); @@ -421,10 +476,12 @@ class Ui_FormEditorMachine verticalLayout_7->setContentsMargins(0, 0, 0, 12); frame_5 = new QFrame(frame_2); frame_5->setObjectName(QString::fromUtf8("frame_5")); - sizePolicy4.setHeightForWidth(frame_5->sizePolicy().hasHeightForWidth()); + sizePolicy4.setHeightForWidth( + frame_5->sizePolicy().hasHeightForWidth()); frame_5->setSizePolicy(sizePolicy4); frame_5->setAutoFillBackground(false); - frame_5->setStyleSheet(QString::fromUtf8("color:white;background:#0095da")); + frame_5->setStyleSheet( + QString::fromUtf8("color:white;background:#0095da")); frame_5->setFrameShape(QFrame::VLine); frame_5->setFrameShadow(QFrame::Raised); frame_5->setLineWidth(0); @@ -436,7 +493,8 @@ class Ui_FormEditorMachine QSizePolicy sizePolicy7(QSizePolicy::Preferred, QSizePolicy::Preferred); sizePolicy7.setHorizontalStretch(0); sizePolicy7.setVerticalStretch(0); - sizePolicy7.setHeightForWidth(label_image->sizePolicy().hasHeightForWidth()); + sizePolicy7.setHeightForWidth( + label_image->sizePolicy().hasHeightForWidth()); label_image->setSizePolicy(sizePolicy7); QFont font; font.setPointSize(10); @@ -446,13 +504,13 @@ class Ui_FormEditorMachine label_title = new QLabel(frame_5); label_title->setObjectName(QString::fromUtf8("label_title")); - sizePolicy3.setHeightForWidth(label_title->sizePolicy().hasHeightForWidth()); + sizePolicy3.setHeightForWidth( + label_title->sizePolicy().hasHeightForWidth()); label_title->setSizePolicy(sizePolicy3); label_title->setFont(font); horizontalLayout->addWidget(label_title); - verticalLayout_7->addWidget(frame_5); properties = new QFrame(frame_2); @@ -460,7 +518,8 @@ class Ui_FormEditorMachine QSizePolicy sizePolicy8(QSizePolicy::Expanding, QSizePolicy::Maximum); sizePolicy8.setHorizontalStretch(0); sizePolicy8.setVerticalStretch(0); - sizePolicy8.setHeightForWidth(properties->sizePolicy().hasHeightForWidth()); + sizePolicy8.setHeightForWidth( + properties->sizePolicy().hasHeightForWidth()); properties->setSizePolicy(sizePolicy8); properties->setFrameShape(QFrame::NoFrame); properties->setFrameShadow(QFrame::Raised); @@ -468,25 +527,22 @@ class Ui_FormEditorMachine verticalLayout_7->addWidget(properties); - verticalLayout_3->addWidget(frame_2); - verticalLayout->addWidget(properties_frame); splitter->addWidget(frame_4); verticalLayout_6->addWidget(splitter); - retranslateUi(FormEditorMachine); QMetaObject::connectSlotsByName(FormEditorMachine); - } // setupUi + } // setupUi - void retranslateUi(QWidget *FormEditorMachine) - { - FormEditorMachine->setWindowTitle(QCoreApplication::translate("FormEditorMachine", "Form", nullptr)); + void retranslateUi(QWidget* FormEditorMachine) { + FormEditorMachine->setWindowTitle( + QCoreApplication::translate("FormEditorMachine", "Form", nullptr)); tool_pointer->setText(QString()); tool_machine_right->setText(QString()); tool_machine_left_word->setText(QString()); @@ -501,16 +557,17 @@ class Ui_FormEditorMachine tool_link->setText(QString()); tool_complex->setText(QString()); _navi->setText(QString()); - label_image->setText(QCoreApplication::translate("FormEditorMachine", "TextLabel", nullptr)); - label_title->setText(QCoreApplication::translate("FormEditorMachine", "TextLabel", nullptr)); - } // retranslateUi - + label_image->setText(QCoreApplication::translate("FormEditorMachine", + "TextLabel", nullptr)); + label_title->setText(QCoreApplication::translate("FormEditorMachine", + "TextLabel", nullptr)); + } // retranslateUi }; namespace Ui { - class FormEditorMachine: public Ui_FormEditorMachine {}; -} // namespace Ui +class FormEditorMachine : public Ui_FormEditorMachine {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMEDITORMACHINE_H +#endif // UI_FORMEDITORMACHINE_H diff --git a/VirtualTuringMachine/ui_formeditorwidget.h b/VirtualTuringMachine/ui_formeditorwidget.h old mode 100755 new mode 100644 index 0f37975..39fe669 --- a/VirtualTuringMachine/ui_formeditorwidget.h +++ b/VirtualTuringMachine/ui_formeditorwidget.h @@ -15,32 +15,29 @@ QT_BEGIN_NAMESPACE -class Ui_FormEditorWidget -{ -public: - - void setupUi(QWidget *FormEditorWidget) - { +class Ui_FormEditorWidget { + public: + void setupUi(QWidget* FormEditorWidget) { if (FormEditorWidget->objectName().isEmpty()) - FormEditorWidget->setObjectName(QString::fromUtf8("FormEditorWidget")); + FormEditorWidget->setObjectName( + QString::fromUtf8("FormEditorWidget")); FormEditorWidget->resize(400, 300); retranslateUi(FormEditorWidget); QMetaObject::connectSlotsByName(FormEditorWidget); - } // setupUi - - void retranslateUi(QWidget *FormEditorWidget) - { - FormEditorWidget->setWindowTitle(QCoreApplication::translate("FormEditorWidget", "Form", nullptr)); - } // retranslateUi + } // setupUi + void retranslateUi(QWidget* FormEditorWidget) { + FormEditorWidget->setWindowTitle( + QCoreApplication::translate("FormEditorWidget", "Form", nullptr)); + } // retranslateUi }; namespace Ui { - class FormEditorWidget: public Ui_FormEditorWidget {}; -} // namespace Ui +class FormEditorWidget : public Ui_FormEditorWidget {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMEDITORWIDGET_H +#endif // UI_FORMEDITORWIDGET_H diff --git a/VirtualTuringMachine/ui_formexercises.h b/VirtualTuringMachine/ui_formexercises.h old mode 100755 new mode 100644 index dcf1b5a..7e07126 --- a/VirtualTuringMachine/ui_formexercises.h +++ b/VirtualTuringMachine/ui_formexercises.h @@ -23,30 +23,28 @@ QT_BEGIN_NAMESPACE -class Ui_FormExercises -{ -public: - QHBoxLayout *horizontalLayout; - QFrame *frame; - QVBoxLayout *verticalLayout; - QToolButton *_ok; - QToolButton *_open; - QFrame *frame_3; - QFrame *frame_4; - QVBoxLayout *verticalLayout_3; - QListView *_list; - QFrame *frame_2; - QVBoxLayout *verticalLayout_2; - QTabWidget *tabWidget; - QWidget *en; - QVBoxLayout *verticalLayout_4; - QTextEdit *_text; - QWidget *ru; - QVBoxLayout *verticalLayout_5; - QTextEdit *_text_ru; - - void setupUi(QWidget *FormExercises) - { +class Ui_FormExercises { + public: + QHBoxLayout* horizontalLayout; + QFrame* frame; + QVBoxLayout* verticalLayout; + QToolButton* _ok; + QToolButton* _open; + QFrame* frame_3; + QFrame* frame_4; + QVBoxLayout* verticalLayout_3; + QListView* _list; + QFrame* frame_2; + QVBoxLayout* verticalLayout_2; + QTabWidget* tabWidget; + QWidget* en; + QVBoxLayout* verticalLayout_4; + QTextEdit* _text; + QWidget* ru; + QVBoxLayout* verticalLayout_5; + QTextEdit* _text_ru; + + void setupUi(QWidget* FormExercises) { if (FormExercises->objectName().isEmpty()) FormExercises->setObjectName(QString::fromUtf8("FormExercises")); FormExercises->resize(478, 300); @@ -74,7 +72,8 @@ class Ui_FormExercises sizePolicy1.setHeightForWidth(_ok->sizePolicy().hasHeightForWidth()); _ok->setSizePolicy(sizePolicy1); QIcon icon; - icon.addFile(QString::fromUtf8(":/Files/images/ok.png"), QSize(), QIcon::Normal, QIcon::Off); + icon.addFile(QString::fromUtf8(":/Files/images/ok.png"), QSize(), + QIcon::Normal, QIcon::Off); _ok->setIcon(icon); _ok->setIconSize(QSize(32, 32)); @@ -83,7 +82,9 @@ class Ui_FormExercises _open = new QToolButton(frame); _open->setObjectName(QString::fromUtf8("_open")); QIcon icon1; - icon1.addFile(QString::fromUtf8(":/Files/images/toolbars/main/icon_open.png"), QSize(), QIcon::Normal, QIcon::Off); + icon1.addFile( + QString::fromUtf8(":/Files/images/toolbars/main/icon_open.png"), + QSize(), QIcon::Normal, QIcon::Off); _open->setIcon(icon1); _open->setIconSize(QSize(32, 32)); @@ -96,7 +97,6 @@ class Ui_FormExercises verticalLayout->addWidget(frame_3); - horizontalLayout->addWidget(frame); frame_4 = new QFrame(FormExercises); @@ -120,7 +120,6 @@ class Ui_FormExercises verticalLayout_3->addWidget(_list); - horizontalLayout->addWidget(frame_4); frame_2 = new QFrame(FormExercises); @@ -160,33 +159,33 @@ class Ui_FormExercises verticalLayout_2->addWidget(tabWidget); - horizontalLayout->addWidget(frame_2); - retranslateUi(FormExercises); tabWidget->setCurrentIndex(0); - QMetaObject::connectSlotsByName(FormExercises); - } // setupUi + } // setupUi - void retranslateUi(QWidget *FormExercises) - { - FormExercises->setWindowTitle(QCoreApplication::translate("FormExercises", "Form", nullptr)); + void retranslateUi(QWidget* FormExercises) { + FormExercises->setWindowTitle( + QCoreApplication::translate("FormExercises", "Form", nullptr)); _ok->setText(QString()); _open->setText(QString()); - tabWidget->setTabText(tabWidget->indexOf(en), QCoreApplication::translate("FormExercises", "En", nullptr)); - tabWidget->setTabText(tabWidget->indexOf(ru), QCoreApplication::translate("FormExercises", "Ru", nullptr)); - } // retranslateUi - + tabWidget->setTabText( + tabWidget->indexOf(en), + QCoreApplication::translate("FormExercises", "En", nullptr)); + tabWidget->setTabText( + tabWidget->indexOf(ru), + QCoreApplication::translate("FormExercises", "Ru", nullptr)); + } // retranslateUi }; namespace Ui { - class FormExercises: public Ui_FormExercises {}; -} // namespace Ui +class FormExercises : public Ui_FormExercises {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMEXERCISES_H +#endif // UI_FORMEXERCISES_H diff --git a/VirtualTuringMachine/ui_formexport4th.h b/VirtualTuringMachine/ui_formexport4th.h old mode 100755 new mode 100644 index 01dfd25..61e03b4 --- a/VirtualTuringMachine/ui_formexport4th.h +++ b/VirtualTuringMachine/ui_formexport4th.h @@ -23,56 +23,55 @@ QT_BEGIN_NAMESPACE -class Ui_FormExport4th -{ -public: - QHBoxLayout *horizontalLayout; - QFrame *frame_4; - QVBoxLayout *verticalLayout_5; - QToolButton *_export; - QToolButton *_copy; - QFrame *frame_5; - QFrame *frame; - QVBoxLayout *verticalLayout; - QFrame *frame_2; - QVBoxLayout *verticalLayout_3; - QFrame *frame_6; - QHBoxLayout *horizontalLayout_3; - QTextEdit *_text; - QFrame *frame_7; - QVBoxLayout *verticalLayout_4; - QFrame *frame_10; - QHBoxLayout *horizontalLayout_5; - QLabel *label_2; - QLineEdit *_delimiter; - QFrame *frame_11; - QHBoxLayout *horizontalLayout_6; - QLabel *label_3; - QLineEdit *_left; - QFrame *frame_12; - QHBoxLayout *horizontalLayout_7; - QLabel *label_4; - QLineEdit *_right; - QFrame *frame_13; - QHBoxLayout *horizontalLayout_8; - QLabel *label_5; - QLineEdit *_stop; - QFrame *frame_14; - QHBoxLayout *horizontalLayout_9; - QLabel *label_6; - QLineEdit *_quotes; - QFrame *frame_15; - QFrame *frame_3; - QVBoxLayout *verticalLayout_2; - QLabel *information; - - void setupUi(QWidget *FormExport4th) - { +class Ui_FormExport4th { + public: + QHBoxLayout* horizontalLayout; + QFrame* frame_4; + QVBoxLayout* verticalLayout_5; + QToolButton* _export; + QToolButton* _copy; + QFrame* frame_5; + QFrame* frame; + QVBoxLayout* verticalLayout; + QFrame* frame_2; + QVBoxLayout* verticalLayout_3; + QFrame* frame_6; + QHBoxLayout* horizontalLayout_3; + QTextEdit* _text; + QFrame* frame_7; + QVBoxLayout* verticalLayout_4; + QFrame* frame_10; + QHBoxLayout* horizontalLayout_5; + QLabel* label_2; + QLineEdit* _delimiter; + QFrame* frame_11; + QHBoxLayout* horizontalLayout_6; + QLabel* label_3; + QLineEdit* _left; + QFrame* frame_12; + QHBoxLayout* horizontalLayout_7; + QLabel* label_4; + QLineEdit* _right; + QFrame* frame_13; + QHBoxLayout* horizontalLayout_8; + QLabel* label_5; + QLineEdit* _stop; + QFrame* frame_14; + QHBoxLayout* horizontalLayout_9; + QLabel* label_6; + QLineEdit* _quotes; + QFrame* frame_15; + QFrame* frame_3; + QVBoxLayout* verticalLayout_2; + QLabel* information; + + void setupUi(QWidget* FormExport4th) { if (FormExport4th->objectName().isEmpty()) FormExport4th->setObjectName(QString::fromUtf8("FormExport4th")); FormExport4th->resize(683, 439); - FormExport4th->setStyleSheet(QString::fromUtf8("background:white;\n" -"color:black")); + FormExport4th->setStyleSheet( + QString::fromUtf8("background:white;\n" + "color:black")); horizontalLayout = new QHBoxLayout(FormExport4th); horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); horizontalLayout->setContentsMargins(0, 0, 0, 0); @@ -87,7 +86,8 @@ class Ui_FormExport4th _export->setObjectName(QString::fromUtf8("_export")); _export->setStyleSheet(QString::fromUtf8("")); QIcon icon; - icon.addFile(QString::fromUtf8(":/Files/images/export.png"), QSize(), QIcon::Normal, QIcon::Off); + icon.addFile(QString::fromUtf8(":/Files/images/export.png"), QSize(), + QIcon::Normal, QIcon::Off); _export->setIcon(icon); _export->setIconSize(QSize(32, 32)); @@ -97,7 +97,8 @@ class Ui_FormExport4th _copy->setObjectName(QString::fromUtf8("_copy")); _copy->setStyleSheet(QString::fromUtf8("")); QIcon icon1; - icon1.addFile(QString::fromUtf8(":/Files/images/copy.png"), QSize(), QIcon::Normal, QIcon::Off); + icon1.addFile(QString::fromUtf8(":/Files/images/copy.png"), QSize(), + QIcon::Normal, QIcon::Off); _copy->setIcon(icon1); _copy->setIconSize(QSize(32, 32)); @@ -110,7 +111,6 @@ class Ui_FormExport4th verticalLayout_5->addWidget(frame_5); - horizontalLayout->addWidget(frame_4); frame = new QFrame(FormExport4th); @@ -137,7 +137,8 @@ class Ui_FormExport4th frame_6->setFrameShape(QFrame::NoFrame); frame_6->setFrameShadow(QFrame::Raised); horizontalLayout_3 = new QHBoxLayout(frame_6); - horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3")); + horizontalLayout_3->setObjectName( + QString::fromUtf8("horizontalLayout_3")); horizontalLayout_3->setContentsMargins(0, 0, 0, 0); _text = new QTextEdit(frame_6); _text->setObjectName(QString::fromUtf8("_text")); @@ -149,7 +150,8 @@ class Ui_FormExport4th QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Preferred); sizePolicy1.setHorizontalStretch(0); sizePolicy1.setVerticalStretch(0); - sizePolicy1.setHeightForWidth(frame_7->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + frame_7->sizePolicy().hasHeightForWidth()); frame_7->setSizePolicy(sizePolicy1); frame_7->setMinimumSize(QSize(300, 0)); frame_7->setFrameShape(QFrame::NoFrame); @@ -162,11 +164,13 @@ class Ui_FormExport4th frame_10->setFrameShape(QFrame::NoFrame); frame_10->setFrameShadow(QFrame::Raised); horizontalLayout_5 = new QHBoxLayout(frame_10); - horizontalLayout_5->setObjectName(QString::fromUtf8("horizontalLayout_5")); + horizontalLayout_5->setObjectName( + QString::fromUtf8("horizontalLayout_5")); horizontalLayout_5->setContentsMargins(0, 0, 0, 0); label_2 = new QLabel(frame_10); label_2->setObjectName(QString::fromUtf8("label_2")); - sizePolicy1.setHeightForWidth(label_2->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + label_2->sizePolicy().hasHeightForWidth()); label_2->setSizePolicy(sizePolicy1); horizontalLayout_5->addWidget(label_2); @@ -176,12 +180,12 @@ class Ui_FormExport4th QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Fixed); sizePolicy2.setHorizontalStretch(0); sizePolicy2.setVerticalStretch(0); - sizePolicy2.setHeightForWidth(_delimiter->sizePolicy().hasHeightForWidth()); + sizePolicy2.setHeightForWidth( + _delimiter->sizePolicy().hasHeightForWidth()); _delimiter->setSizePolicy(sizePolicy2); horizontalLayout_5->addWidget(_delimiter); - verticalLayout_4->addWidget(frame_10); frame_11 = new QFrame(frame_7); @@ -189,11 +193,13 @@ class Ui_FormExport4th frame_11->setFrameShape(QFrame::NoFrame); frame_11->setFrameShadow(QFrame::Raised); horizontalLayout_6 = new QHBoxLayout(frame_11); - horizontalLayout_6->setObjectName(QString::fromUtf8("horizontalLayout_6")); + horizontalLayout_6->setObjectName( + QString::fromUtf8("horizontalLayout_6")); horizontalLayout_6->setContentsMargins(0, 0, 0, 0); label_3 = new QLabel(frame_11); label_3->setObjectName(QString::fromUtf8("label_3")); - sizePolicy1.setHeightForWidth(label_3->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + label_3->sizePolicy().hasHeightForWidth()); label_3->setSizePolicy(sizePolicy1); horizontalLayout_6->addWidget(label_3); @@ -205,7 +211,6 @@ class Ui_FormExport4th horizontalLayout_6->addWidget(_left); - verticalLayout_4->addWidget(frame_11); frame_12 = new QFrame(frame_7); @@ -213,11 +218,13 @@ class Ui_FormExport4th frame_12->setFrameShape(QFrame::NoFrame); frame_12->setFrameShadow(QFrame::Raised); horizontalLayout_7 = new QHBoxLayout(frame_12); - horizontalLayout_7->setObjectName(QString::fromUtf8("horizontalLayout_7")); + horizontalLayout_7->setObjectName( + QString::fromUtf8("horizontalLayout_7")); horizontalLayout_7->setContentsMargins(0, 0, 0, 0); label_4 = new QLabel(frame_12); label_4->setObjectName(QString::fromUtf8("label_4")); - sizePolicy1.setHeightForWidth(label_4->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + label_4->sizePolicy().hasHeightForWidth()); label_4->setSizePolicy(sizePolicy1); horizontalLayout_7->addWidget(label_4); @@ -229,7 +236,6 @@ class Ui_FormExport4th horizontalLayout_7->addWidget(_right); - verticalLayout_4->addWidget(frame_12); frame_13 = new QFrame(frame_7); @@ -237,11 +243,13 @@ class Ui_FormExport4th frame_13->setFrameShape(QFrame::NoFrame); frame_13->setFrameShadow(QFrame::Raised); horizontalLayout_8 = new QHBoxLayout(frame_13); - horizontalLayout_8->setObjectName(QString::fromUtf8("horizontalLayout_8")); + horizontalLayout_8->setObjectName( + QString::fromUtf8("horizontalLayout_8")); horizontalLayout_8->setContentsMargins(0, 0, 0, 0); label_5 = new QLabel(frame_13); label_5->setObjectName(QString::fromUtf8("label_5")); - sizePolicy1.setHeightForWidth(label_5->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + label_5->sizePolicy().hasHeightForWidth()); label_5->setSizePolicy(sizePolicy1); horizontalLayout_8->addWidget(label_5); @@ -253,7 +261,6 @@ class Ui_FormExport4th horizontalLayout_8->addWidget(_stop); - verticalLayout_4->addWidget(frame_13); frame_14 = new QFrame(frame_7); @@ -261,23 +268,25 @@ class Ui_FormExport4th frame_14->setFrameShape(QFrame::NoFrame); frame_14->setFrameShadow(QFrame::Raised); horizontalLayout_9 = new QHBoxLayout(frame_14); - horizontalLayout_9->setObjectName(QString::fromUtf8("horizontalLayout_9")); + horizontalLayout_9->setObjectName( + QString::fromUtf8("horizontalLayout_9")); horizontalLayout_9->setContentsMargins(0, 0, 0, 0); label_6 = new QLabel(frame_14); label_6->setObjectName(QString::fromUtf8("label_6")); - sizePolicy1.setHeightForWidth(label_6->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + label_6->sizePolicy().hasHeightForWidth()); label_6->setSizePolicy(sizePolicy1); horizontalLayout_9->addWidget(label_6); _quotes = new QLineEdit(frame_14); _quotes->setObjectName(QString::fromUtf8("_quotes")); - sizePolicy2.setHeightForWidth(_quotes->sizePolicy().hasHeightForWidth()); + sizePolicy2.setHeightForWidth( + _quotes->sizePolicy().hasHeightForWidth()); _quotes->setSizePolicy(sizePolicy2); horizontalLayout_9->addWidget(_quotes); - verticalLayout_4->addWidget(frame_14); frame_15 = new QFrame(frame_7); @@ -285,20 +294,18 @@ class Ui_FormExport4th QSizePolicy sizePolicy3(QSizePolicy::Expanding, QSizePolicy::Expanding); sizePolicy3.setHorizontalStretch(0); sizePolicy3.setVerticalStretch(0); - sizePolicy3.setHeightForWidth(frame_15->sizePolicy().hasHeightForWidth()); + sizePolicy3.setHeightForWidth( + frame_15->sizePolicy().hasHeightForWidth()); frame_15->setSizePolicy(sizePolicy3); frame_15->setFrameShape(QFrame::NoFrame); frame_15->setFrameShadow(QFrame::Raised); verticalLayout_4->addWidget(frame_15); - horizontalLayout_3->addWidget(frame_7); - verticalLayout_3->addWidget(frame_6); - verticalLayout->addWidget(frame_2); frame_3 = new QFrame(frame); @@ -315,57 +322,72 @@ class Ui_FormExport4th QSizePolicy sizePolicy4(QSizePolicy::Preferred, QSizePolicy::Preferred); sizePolicy4.setHorizontalStretch(0); sizePolicy4.setVerticalStretch(0); - sizePolicy4.setHeightForWidth(information->sizePolicy().hasHeightForWidth()); + sizePolicy4.setHeightForWidth( + information->sizePolicy().hasHeightForWidth()); information->setSizePolicy(sizePolicy4); QFont font; font.setItalic(true); information->setFont(font); information->setTextFormat(Qt::AutoText); information->setScaledContents(false); - information->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop); + information->setAlignment(Qt::AlignLeading | Qt::AlignLeft | + Qt::AlignTop); verticalLayout_2->addWidget(information); - verticalLayout->addWidget(frame_3); - horizontalLayout->addWidget(frame); - retranslateUi(FormExport4th); QMetaObject::connectSlotsByName(FormExport4th); - } // setupUi + } // setupUi - void retranslateUi(QWidget *FormExport4th) - { - FormExport4th->setWindowTitle(QCoreApplication::translate("FormExport4th", "Form", nullptr)); + void retranslateUi(QWidget* FormExport4th) { + FormExport4th->setWindowTitle( + QCoreApplication::translate("FormExport4th", "Form", nullptr)); _export->setText(QString()); _copy->setText(QString()); - label_2->setText(QCoreApplication::translate("FormExport4th", "Inline delimiter", nullptr)); - _delimiter->setText(QCoreApplication::translate("FormExport4th", ",", nullptr)); - label_3->setText(QCoreApplication::translate("FormExport4th", "Left", nullptr)); - _left->setText(QCoreApplication::translate("FormExport4th", "<", nullptr)); - label_4->setText(QCoreApplication::translate("FormExport4th", "Right", nullptr)); - _right->setText(QCoreApplication::translate("FormExport4th", ">", nullptr)); - label_5->setText(QCoreApplication::translate("FormExport4th", "Stop", nullptr)); - _stop->setText(QCoreApplication::translate("FormExport4th", "#", nullptr)); - label_6->setText(QCoreApplication::translate("FormExport4th", "Write quotes", nullptr)); + label_2->setText(QCoreApplication::translate( + "FormExport4th", "Inline delimiter", nullptr)); + _delimiter->setText( + QCoreApplication::translate("FormExport4th", ",", nullptr)); + label_3->setText( + QCoreApplication::translate("FormExport4th", "Left", nullptr)); + _left->setText( + QCoreApplication::translate("FormExport4th", "<", nullptr)); + label_4->setText( + QCoreApplication::translate("FormExport4th", "Right", nullptr)); + _right->setText( + QCoreApplication::translate("FormExport4th", ">", nullptr)); + label_5->setText( + QCoreApplication::translate("FormExport4th", "Stop", nullptr)); + _stop->setText( + QCoreApplication::translate("FormExport4th", "#", nullptr)); + label_6->setText(QCoreApplication::translate("FormExport4th", + "Write quotes", nullptr)); _quotes->setText(QString()); - information->setText(QCoreApplication::translate("FormExport4th", "\n" -"\n" -"


", nullptr)); - } // retranslateUi - + information->setText(QCoreApplication::translate( + "FormExport4th", + "\n" + "\n" + "


", + nullptr)); + } // retranslateUi }; namespace Ui { - class FormExport4th: public Ui_FormExport4th {}; -} // namespace Ui +class FormExport4th : public Ui_FormExport4th {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMEXPORT4TH_H +#endif // UI_FORMEXPORT4TH_H diff --git a/VirtualTuringMachine/ui_formlinewidget.h b/VirtualTuringMachine/ui_formlinewidget.h old mode 100755 new mode 100644 index add1522..a5ec92b --- a/VirtualTuringMachine/ui_formlinewidget.h +++ b/VirtualTuringMachine/ui_formlinewidget.h @@ -17,14 +17,12 @@ QT_BEGIN_NAMESPACE -class Ui_FormLineWidget -{ -public: - QHBoxLayout *horizontalLayout; - QFrame *frame; - - void setupUi(QWidget *FormLineWidget) - { +class Ui_FormLineWidget { + public: + QHBoxLayout* horizontalLayout; + QFrame* frame; + + void setupUi(QWidget* FormLineWidget) { if (FormLineWidget->objectName().isEmpty()) FormLineWidget->setObjectName(QString::fromUtf8("FormLineWidget")); FormLineWidget->resize(1023, 88); @@ -39,23 +37,21 @@ class Ui_FormLineWidget horizontalLayout->addWidget(frame); - retranslateUi(FormLineWidget); QMetaObject::connectSlotsByName(FormLineWidget); - } // setupUi - - void retranslateUi(QWidget *FormLineWidget) - { - FormLineWidget->setWindowTitle(QCoreApplication::translate("FormLineWidget", "Form", nullptr)); - } // retranslateUi + } // setupUi + void retranslateUi(QWidget* FormLineWidget) { + FormLineWidget->setWindowTitle( + QCoreApplication::translate("FormLineWidget", "Form", nullptr)); + } // retranslateUi }; namespace Ui { - class FormLineWidget: public Ui_FormLineWidget {}; -} // namespace Ui +class FormLineWidget : public Ui_FormLineWidget {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMLINEWIDGET_H +#endif // UI_FORMLINEWIDGET_H diff --git a/VirtualTuringMachine/ui_formmain.h b/VirtualTuringMachine/ui_formmain.h old mode 100755 new mode 100644 index 5cf71d7..d5b0f14 --- a/VirtualTuringMachine/ui_formmain.h +++ b/VirtualTuringMachine/ui_formmain.h @@ -23,27 +23,25 @@ QT_BEGIN_NAMESPACE -class Ui_FormMain -{ -public: - QVBoxLayout *verticalLayout; - QScrollArea *scrollArea; - QWidget *scrollAreaWidgetContents; - QHBoxLayout *horizontalLayout; - QFrame *frame; - QVBoxLayout *verticalLayout_2; - QToolButton *button_new; - QToolButton *button_open; - QToolButton *toolButton; - QFrame *frame_3; - QToolButton *toolButton_2; - QFrame *frame_2; - QVBoxLayout *verticalLayout_3; - QLabel *label; - QListWidget *listWidget; - - void setupUi(QWidget *FormMain) - { +class Ui_FormMain { + public: + QVBoxLayout* verticalLayout; + QScrollArea* scrollArea; + QWidget* scrollAreaWidgetContents; + QHBoxLayout* horizontalLayout; + QFrame* frame; + QVBoxLayout* verticalLayout_2; + QToolButton* button_new; + QToolButton* button_open; + QToolButton* toolButton; + QFrame* frame_3; + QToolButton* toolButton_2; + QFrame* frame_2; + QVBoxLayout* verticalLayout_3; + QLabel* label; + QListWidget* listWidget; + + void setupUi(QWidget* FormMain) { if (FormMain->objectName().isEmpty()) FormMain->setObjectName(QString::fromUtf8("FormMain")); FormMain->resize(755, 462); @@ -64,9 +62,11 @@ class Ui_FormMain scrollArea->setMinimumSize(QSize(500, 0)); scrollArea->setFrameShape(QFrame::NoFrame); scrollArea->setWidgetResizable(true); - scrollArea->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop); + scrollArea->setAlignment(Qt::AlignLeading | Qt::AlignLeft | + Qt::AlignTop); scrollAreaWidgetContents = new QWidget(); - scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents")); + scrollAreaWidgetContents->setObjectName( + QString::fromUtf8("scrollAreaWidgetContents")); scrollAreaWidgetContents->setGeometry(QRect(0, 0, 755, 462)); scrollAreaWidgetContents->setAutoFillBackground(true); horizontalLayout = new QHBoxLayout(scrollAreaWidgetContents); @@ -94,11 +94,14 @@ class Ui_FormMain QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Fixed); sizePolicy1.setHorizontalStretch(0); sizePolicy1.setVerticalStretch(0); - sizePolicy1.setHeightForWidth(button_new->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + button_new->sizePolicy().hasHeightForWidth()); button_new->setSizePolicy(sizePolicy1); button_new->setStyleSheet(QString::fromUtf8("background:#01547a")); QIcon icon; - icon.addFile(QString::fromUtf8(":/Files/images/toolbars/main/icon_new.png"), QSize(), QIcon::Normal, QIcon::Off); + icon.addFile( + QString::fromUtf8(":/Files/images/toolbars/main/icon_new.png"), + QSize(), QIcon::Normal, QIcon::Off); button_new->setIcon(icon); button_new->setIconSize(QSize(32, 32)); @@ -106,11 +109,14 @@ class Ui_FormMain button_open = new QToolButton(frame); button_open->setObjectName(QString::fromUtf8("button_open")); - sizePolicy1.setHeightForWidth(button_open->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + button_open->sizePolicy().hasHeightForWidth()); button_open->setSizePolicy(sizePolicy1); button_open->setStyleSheet(QString::fromUtf8("background:#01547a")); QIcon icon1; - icon1.addFile(QString::fromUtf8(":/Files/images/toolbars/main/icon_open.png"), QSize(), QIcon::Normal, QIcon::Off); + icon1.addFile( + QString::fromUtf8(":/Files/images/toolbars/main/icon_open.png"), + QSize(), QIcon::Normal, QIcon::Off); button_open->setIcon(icon1); button_open->setIconSize(QSize(32, 32)); @@ -118,11 +124,13 @@ class Ui_FormMain toolButton = new QToolButton(frame); toolButton->setObjectName(QString::fromUtf8("toolButton")); - sizePolicy1.setHeightForWidth(toolButton->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + toolButton->sizePolicy().hasHeightForWidth()); toolButton->setSizePolicy(sizePolicy1); toolButton->setStyleSheet(QString::fromUtf8("background:#01547a")); QIcon icon2; - icon2.addFile(QString::fromUtf8(":/Files/images/exercise.png"), QSize(), QIcon::Normal, QIcon::Off); + icon2.addFile(QString::fromUtf8(":/Files/images/exercise.png"), QSize(), + QIcon::Normal, QIcon::Off); toolButton->setIcon(icon2); toolButton->setIconSize(QSize(32, 32)); @@ -133,7 +141,8 @@ class Ui_FormMain QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Expanding); sizePolicy2.setHorizontalStretch(0); sizePolicy2.setVerticalStretch(0); - sizePolicy2.setHeightForWidth(frame_3->sizePolicy().hasHeightForWidth()); + sizePolicy2.setHeightForWidth( + frame_3->sizePolicy().hasHeightForWidth()); frame_3->setSizePolicy(sizePolicy2); frame_3->setLineWidth(0); @@ -144,22 +153,24 @@ class Ui_FormMain QSizePolicy sizePolicy3(QSizePolicy::Fixed, QSizePolicy::Fixed); sizePolicy3.setHorizontalStretch(0); sizePolicy3.setVerticalStretch(0); - sizePolicy3.setHeightForWidth(toolButton_2->sizePolicy().hasHeightForWidth()); + sizePolicy3.setHeightForWidth( + toolButton_2->sizePolicy().hasHeightForWidth()); toolButton_2->setSizePolicy(sizePolicy3); toolButton_2->setStyleSheet(QString::fromUtf8("background:#01547a")); QIcon icon3; - icon3.addFile(QString::fromUtf8(":/Files/images/emblema_mai.png"), QSize(), QIcon::Normal, QIcon::Off); + icon3.addFile(QString::fromUtf8(":/Files/images/emblema_mai.png"), + QSize(), QIcon::Normal, QIcon::Off); toolButton_2->setIcon(icon3); toolButton_2->setIconSize(QSize(64, 64)); verticalLayout_2->addWidget(toolButton_2); - horizontalLayout->addWidget(frame); frame_2 = new QFrame(scrollAreaWidgetContents); frame_2->setObjectName(QString::fromUtf8("frame_2")); - sizePolicy2.setHeightForWidth(frame_2->sizePolicy().hasHeightForWidth()); + sizePolicy2.setHeightForWidth( + frame_2->sizePolicy().hasHeightForWidth()); frame_2->setSizePolicy(sizePolicy2); frame_2->setFrameShape(QFrame::NoFrame); frame_2->setFrameShadow(QFrame::Raised); @@ -186,35 +197,33 @@ class Ui_FormMain verticalLayout_3->addWidget(listWidget); - horizontalLayout->addWidget(frame_2); scrollArea->setWidget(scrollAreaWidgetContents); verticalLayout->addWidget(scrollArea); - retranslateUi(FormMain); QMetaObject::connectSlotsByName(FormMain); - } // setupUi + } // setupUi - void retranslateUi(QWidget *FormMain) - { - FormMain->setWindowTitle(QCoreApplication::translate("FormMain", "Form", nullptr)); + void retranslateUi(QWidget* FormMain) { + FormMain->setWindowTitle( + QCoreApplication::translate("FormMain", "Form", nullptr)); button_new->setText(QString()); button_open->setText(QString()); toolButton->setText(QString()); toolButton_2->setText(QString()); - label->setText(QCoreApplication::translate("FormMain", "Recent projects", nullptr)); - } // retranslateUi - + label->setText(QCoreApplication::translate("FormMain", + "Recent projects", nullptr)); + } // retranslateUi }; namespace Ui { - class FormMain: public Ui_FormMain {}; -} // namespace Ui +class FormMain : public Ui_FormMain {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMMAIN_H +#endif // UI_FORMMAIN_H diff --git a/VirtualTuringMachine/ui_formnewmachine.h b/VirtualTuringMachine/ui_formnewmachine.h old mode 100755 new mode 100644 index 9e3f159..560dcc7 --- a/VirtualTuringMachine/ui_formnewmachine.h +++ b/VirtualTuringMachine/ui_formnewmachine.h @@ -23,32 +23,31 @@ QT_BEGIN_NAMESPACE -class Ui_FormNewMachine -{ -public: - QHBoxLayout *horizontalLayout; - QFrame *frame_2; - QVBoxLayout *verticalLayout_2; - QToolButton *button_ok_2; - QToolButton *button_delete_2; - QFrame *frame_6; - QVBoxLayout *verticalLayout; - QLabel *label; - QLineEdit *text_machine_name; - QFrame *frame; - QVBoxLayout *verticalLayout_3; - QLabel *label_2; - QFrame *frame_4; - QHBoxLayout *horizontalLayout_2; - QListView *list_machines; - - void setupUi(QWidget *FormNewMachine) - { +class Ui_FormNewMachine { + public: + QHBoxLayout* horizontalLayout; + QFrame* frame_2; + QVBoxLayout* verticalLayout_2; + QToolButton* button_ok_2; + QToolButton* button_delete_2; + QFrame* frame_6; + QVBoxLayout* verticalLayout; + QLabel* label; + QLineEdit* text_machine_name; + QFrame* frame; + QVBoxLayout* verticalLayout_3; + QLabel* label_2; + QFrame* frame_4; + QHBoxLayout* horizontalLayout_2; + QListView* list_machines; + + void setupUi(QWidget* FormNewMachine) { if (FormNewMachine->objectName().isEmpty()) FormNewMachine->setObjectName(QString::fromUtf8("FormNewMachine")); FormNewMachine->resize(610, 515); - FormNewMachine->setStyleSheet(QString::fromUtf8("background:white;\n" -"color:black")); + FormNewMachine->setStyleSheet( + QString::fromUtf8("background:white;\n" + "color:black")); horizontalLayout = new QHBoxLayout(FormNewMachine); horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); horizontalLayout->setContentsMargins(0, 0, 0, 0); @@ -65,12 +64,14 @@ class Ui_FormNewMachine QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); - sizePolicy.setHeightForWidth(button_ok_2->sizePolicy().hasHeightForWidth()); + sizePolicy.setHeightForWidth( + button_ok_2->sizePolicy().hasHeightForWidth()); button_ok_2->setSizePolicy(sizePolicy); button_ok_2->setAutoFillBackground(false); button_ok_2->setStyleSheet(QString::fromUtf8("")); QIcon icon; - icon.addFile(QString::fromUtf8(":/Files/images/ok.png"), QSize(), QIcon::Normal, QIcon::Off); + icon.addFile(QString::fromUtf8(":/Files/images/ok.png"), QSize(), + QIcon::Normal, QIcon::Off); button_ok_2->setIcon(icon); button_ok_2->setIconSize(QSize(32, 32)); @@ -78,12 +79,14 @@ class Ui_FormNewMachine button_delete_2 = new QToolButton(frame_2); button_delete_2->setObjectName(QString::fromUtf8("button_delete_2")); - sizePolicy.setHeightForWidth(button_delete_2->sizePolicy().hasHeightForWidth()); + sizePolicy.setHeightForWidth( + button_delete_2->sizePolicy().hasHeightForWidth()); button_delete_2->setSizePolicy(sizePolicy); button_delete_2->setAutoFillBackground(false); button_delete_2->setStyleSheet(QString::fromUtf8("")); QIcon icon1; - icon1.addFile(QString::fromUtf8(":/Files/images/toolbars/main/bin.png"), QSize(), QIcon::Normal, QIcon::Off); + icon1.addFile(QString::fromUtf8(":/Files/images/toolbars/main/bin.png"), + QSize(), QIcon::Normal, QIcon::Off); button_delete_2->setIcon(icon1); button_delete_2->setIconSize(QSize(32, 32)); @@ -94,14 +97,14 @@ class Ui_FormNewMachine QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Expanding); sizePolicy1.setHorizontalStretch(0); sizePolicy1.setVerticalStretch(0); - sizePolicy1.setHeightForWidth(frame_6->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + frame_6->sizePolicy().hasHeightForWidth()); frame_6->setSizePolicy(sizePolicy1); frame_6->setFrameShape(QFrame::NoFrame); frame_6->setFrameShadow(QFrame::Raised); verticalLayout_2->addWidget(frame_6); - horizontalLayout->addWidget(frame_2); verticalLayout = new QVBoxLayout(); @@ -121,18 +124,21 @@ class Ui_FormNewMachine verticalLayout->addWidget(label); text_machine_name = new QLineEdit(FormNewMachine); - text_machine_name->setObjectName(QString::fromUtf8("text_machine_name")); + text_machine_name->setObjectName( + QString::fromUtf8("text_machine_name")); QSizePolicy sizePolicy3(QSizePolicy::Expanding, QSizePolicy::Maximum); sizePolicy3.setHorizontalStretch(0); sizePolicy3.setVerticalStretch(0); - sizePolicy3.setHeightForWidth(text_machine_name->sizePolicy().hasHeightForWidth()); + sizePolicy3.setHeightForWidth( + text_machine_name->sizePolicy().hasHeightForWidth()); text_machine_name->setSizePolicy(sizePolicy3); verticalLayout->addWidget(text_machine_name); frame = new QFrame(FormNewMachine); frame->setObjectName(QString::fromUtf8("frame")); - QSizePolicy sizePolicy4(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding); + QSizePolicy sizePolicy4(QSizePolicy::Expanding, + QSizePolicy::MinimumExpanding); sizePolicy4.setHorizontalStretch(0); sizePolicy4.setVerticalStretch(0); sizePolicy4.setHeightForWidth(frame->sizePolicy().hasHeightForWidth()); @@ -156,46 +162,44 @@ class Ui_FormNewMachine frame_4->setFrameShape(QFrame::NoFrame); frame_4->setFrameShadow(QFrame::Raised); horizontalLayout_2 = new QHBoxLayout(frame_4); - horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2")); + horizontalLayout_2->setObjectName( + QString::fromUtf8("horizontalLayout_2")); horizontalLayout_2->setContentsMargins(0, 0, 0, 0); list_machines = new QListView(frame_4); list_machines->setObjectName(QString::fromUtf8("list_machines")); horizontalLayout_2->addWidget(list_machines); - verticalLayout_3->addWidget(frame_4); - verticalLayout->addWidget(frame); - horizontalLayout->addLayout(verticalLayout); - retranslateUi(FormNewMachine); QMetaObject::connectSlotsByName(FormNewMachine); - } // setupUi + } // setupUi - void retranslateUi(QWidget *FormNewMachine) - { - FormNewMachine->setWindowTitle(QCoreApplication::translate("FormNewMachine", "Form", nullptr)); + void retranslateUi(QWidget* FormNewMachine) { + FormNewMachine->setWindowTitle( + QCoreApplication::translate("FormNewMachine", "Form", nullptr)); button_ok_2->setText(QString()); #if QT_CONFIG(shortcut) button_ok_2->setShortcut(QString()); -#endif // QT_CONFIG(shortcut) +#endif // QT_CONFIG(shortcut) button_delete_2->setText(QString()); - label->setText(QCoreApplication::translate("FormNewMachine", "Machine Name", nullptr)); - label_2->setText(QCoreApplication::translate("FormNewMachine", "Existing project machines", nullptr)); - } // retranslateUi - + label->setText(QCoreApplication::translate("FormNewMachine", + "Machine Name", nullptr)); + label_2->setText(QCoreApplication::translate( + "FormNewMachine", "Existing project machines", nullptr)); + } // retranslateUi }; namespace Ui { - class FormNewMachine: public Ui_FormNewMachine {}; -} // namespace Ui +class FormNewMachine : public Ui_FormNewMachine {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMNEWMACHINE_H +#endif // UI_FORMNEWMACHINE_H diff --git a/VirtualTuringMachine/ui_formnewproject.h b/VirtualTuringMachine/ui_formnewproject.h old mode 100755 new mode 100644 index e31cf7b..825dd5f --- a/VirtualTuringMachine/ui_formnewproject.h +++ b/VirtualTuringMachine/ui_formnewproject.h @@ -24,40 +24,38 @@ QT_BEGIN_NAMESPACE -class Ui_FormNewProject -{ -public: - QHBoxLayout *horizontalLayout; - QScrollArea *scrollArea; - QWidget *scrollAreaWidgetContents; - QHBoxLayout *horizontalLayout_2; - QFrame *frame; - QVBoxLayout *verticalLayout; - QToolButton *button_create; - QFrame *frame_2; - QFrame *frame_5; - QVBoxLayout *verticalLayout_2; - QLabel *label; - QLineEdit *text_project_name; - QLabel *label_3; - QFrame *frame_3; - QHBoxLayout *horizontalLayout_3; - QLineEdit *text_project_location; - QToolButton *button_project_location; - QLabel *label_4; - QWidget *widget_4; - QHBoxLayout *horizontalLayout_6; - QToolButton *button_z2; - QToolButton *button_z3; - QToolButton *button_z4; - QToolButton *button_z10; - QToolButton *button_z16; - QToolButton *button_z80; - QWidget *widget_6; - QTextEdit *text_alphabit; - - void setupUi(QWidget *FormNewProject) - { +class Ui_FormNewProject { + public: + QHBoxLayout* horizontalLayout; + QScrollArea* scrollArea; + QWidget* scrollAreaWidgetContents; + QHBoxLayout* horizontalLayout_2; + QFrame* frame; + QVBoxLayout* verticalLayout; + QToolButton* button_create; + QFrame* frame_2; + QFrame* frame_5; + QVBoxLayout* verticalLayout_2; + QLabel* label; + QLineEdit* text_project_name; + QLabel* label_3; + QFrame* frame_3; + QHBoxLayout* horizontalLayout_3; + QLineEdit* text_project_location; + QToolButton* button_project_location; + QLabel* label_4; + QWidget* widget_4; + QHBoxLayout* horizontalLayout_6; + QToolButton* button_z2; + QToolButton* button_z3; + QToolButton* button_z4; + QToolButton* button_z10; + QToolButton* button_z16; + QToolButton* button_z80; + QWidget* widget_6; + QTextEdit* text_alphabit; + + void setupUi(QWidget* FormNewProject) { if (FormNewProject->objectName().isEmpty()) FormNewProject->setObjectName(QString::fromUtf8("FormNewProject")); FormNewProject->resize(549, 571); @@ -73,10 +71,12 @@ class Ui_FormNewProject scrollArea->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); scrollArea->setWidgetResizable(true); scrollAreaWidgetContents = new QWidget(); - scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents")); + scrollAreaWidgetContents->setObjectName( + QString::fromUtf8("scrollAreaWidgetContents")); scrollAreaWidgetContents->setGeometry(QRect(0, 0, 549, 571)); horizontalLayout_2 = new QHBoxLayout(scrollAreaWidgetContents); - horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2")); + horizontalLayout_2->setObjectName( + QString::fromUtf8("horizontalLayout_2")); horizontalLayout_2->setContentsMargins(0, 0, 0, 0); frame = new QFrame(scrollAreaWidgetContents); frame->setObjectName(QString::fromUtf8("frame")); @@ -95,11 +95,13 @@ class Ui_FormNewProject QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Preferred); sizePolicy1.setHorizontalStretch(0); sizePolicy1.setVerticalStretch(0); - sizePolicy1.setHeightForWidth(button_create->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + button_create->sizePolicy().hasHeightForWidth()); button_create->setSizePolicy(sizePolicy1); button_create->setStyleSheet(QString::fromUtf8("")); QIcon icon; - icon.addFile(QString::fromUtf8(":/Files/images/ok.png"), QSize(), QIcon::Normal, QIcon::Off); + icon.addFile(QString::fromUtf8(":/Files/images/ok.png"), QSize(), + QIcon::Normal, QIcon::Off); button_create->setIcon(icon); button_create->setIconSize(QSize(32, 32)); button_create->setAutoRaise(true); @@ -111,14 +113,14 @@ class Ui_FormNewProject QSizePolicy sizePolicy2(QSizePolicy::Preferred, QSizePolicy::Expanding); sizePolicy2.setHorizontalStretch(0); sizePolicy2.setVerticalStretch(0); - sizePolicy2.setHeightForWidth(frame_2->sizePolicy().hasHeightForWidth()); + sizePolicy2.setHeightForWidth( + frame_2->sizePolicy().hasHeightForWidth()); frame_2->setSizePolicy(sizePolicy2); frame_2->setFrameShape(QFrame::NoFrame); frame_2->setFrameShadow(QFrame::Raised); verticalLayout->addWidget(frame_2); - horizontalLayout_2->addWidget(frame); frame_5 = new QFrame(scrollAreaWidgetContents); @@ -126,7 +128,8 @@ class Ui_FormNewProject QSizePolicy sizePolicy3(QSizePolicy::Expanding, QSizePolicy::Expanding); sizePolicy3.setHorizontalStretch(0); sizePolicy3.setVerticalStretch(0); - sizePolicy3.setHeightForWidth(frame_5->sizePolicy().hasHeightForWidth()); + sizePolicy3.setHeightForWidth( + frame_5->sizePolicy().hasHeightForWidth()); frame_5->setSizePolicy(sizePolicy3); frame_5->setFrameShape(QFrame::NoFrame); frame_5->setFrameShadow(QFrame::Raised); @@ -146,11 +149,13 @@ class Ui_FormNewProject verticalLayout_2->addWidget(label); text_project_name = new QLineEdit(frame_5); - text_project_name->setObjectName(QString::fromUtf8("text_project_name")); + text_project_name->setObjectName( + QString::fromUtf8("text_project_name")); QSizePolicy sizePolicy5(QSizePolicy::Expanding, QSizePolicy::Maximum); sizePolicy5.setHorizontalStretch(0); sizePolicy5.setVerticalStretch(0); - sizePolicy5.setHeightForWidth(text_project_name->sizePolicy().hasHeightForWidth()); + sizePolicy5.setHeightForWidth( + text_project_name->sizePolicy().hasHeightForWidth()); text_project_name->setSizePolicy(sizePolicy5); verticalLayout_2->addWidget(text_project_name); @@ -160,7 +165,8 @@ class Ui_FormNewProject QSizePolicy sizePolicy6(QSizePolicy::Preferred, QSizePolicy::Maximum); sizePolicy6.setHorizontalStretch(0); sizePolicy6.setVerticalStretch(0); - sizePolicy6.setHeightForWidth(label_3->sizePolicy().hasHeightForWidth()); + sizePolicy6.setHeightForWidth( + label_3->sizePolicy().hasHeightForWidth()); label_3->setSizePolicy(sizePolicy6); label_3->setFont(font); @@ -171,24 +177,27 @@ class Ui_FormNewProject frame_3->setFrameShape(QFrame::NoFrame); frame_3->setFrameShadow(QFrame::Raised); horizontalLayout_3 = new QHBoxLayout(frame_3); - horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3")); + horizontalLayout_3->setObjectName( + QString::fromUtf8("horizontalLayout_3")); horizontalLayout_3->setContentsMargins(0, 0, 0, 0); text_project_location = new QLineEdit(frame_3); - text_project_location->setObjectName(QString::fromUtf8("text_project_location")); + text_project_location->setObjectName( + QString::fromUtf8("text_project_location")); horizontalLayout_3->addWidget(text_project_location); button_project_location = new QToolButton(frame_3); - button_project_location->setObjectName(QString::fromUtf8("button_project_location")); + button_project_location->setObjectName( + QString::fromUtf8("button_project_location")); QSizePolicy sizePolicy7(QSizePolicy::Fixed, QSizePolicy::Maximum); sizePolicy7.setHorizontalStretch(0); sizePolicy7.setVerticalStretch(0); - sizePolicy7.setHeightForWidth(button_project_location->sizePolicy().hasHeightForWidth()); + sizePolicy7.setHeightForWidth( + button_project_location->sizePolicy().hasHeightForWidth()); button_project_location->setSizePolicy(sizePolicy7); horizontalLayout_3->addWidget(button_project_location); - verticalLayout_2->addWidget(frame_3); label_4 = new QLabel(frame_5); @@ -200,18 +209,21 @@ class Ui_FormNewProject widget_4 = new QWidget(frame_5); widget_4->setObjectName(QString::fromUtf8("widget_4")); widget_4->setEnabled(true); - sizePolicy6.setHeightForWidth(widget_4->sizePolicy().hasHeightForWidth()); + sizePolicy6.setHeightForWidth( + widget_4->sizePolicy().hasHeightForWidth()); widget_4->setSizePolicy(sizePolicy6); widget_4->setLayoutDirection(Qt::LeftToRight); widget_4->setStyleSheet(QString::fromUtf8("")); horizontalLayout_6 = new QHBoxLayout(widget_4); - horizontalLayout_6->setObjectName(QString::fromUtf8("horizontalLayout_6")); + horizontalLayout_6->setObjectName( + QString::fromUtf8("horizontalLayout_6")); horizontalLayout_6->setContentsMargins(0, 0, 0, 0); button_z2 = new QToolButton(widget_4); button_z2->setObjectName(QString::fromUtf8("button_z2")); button_z2->setStyleSheet(QString::fromUtf8("background:white")); QIcon icon1; - icon1.addFile(QString::fromUtf8(":/Files/images/alphabet/z2.png"), QSize(), QIcon::Normal, QIcon::Off); + icon1.addFile(QString::fromUtf8(":/Files/images/alphabet/z2.png"), + QSize(), QIcon::Normal, QIcon::Off); button_z2->setIcon(icon1); button_z2->setIconSize(QSize(32, 32)); @@ -221,7 +233,8 @@ class Ui_FormNewProject button_z3->setObjectName(QString::fromUtf8("button_z3")); button_z3->setStyleSheet(QString::fromUtf8("background:white")); QIcon icon2; - icon2.addFile(QString::fromUtf8(":/Files/images/alphabet/z3.png"), QSize(), QIcon::Normal, QIcon::Off); + icon2.addFile(QString::fromUtf8(":/Files/images/alphabet/z3.png"), + QSize(), QIcon::Normal, QIcon::Off); button_z3->setIcon(icon2); button_z3->setIconSize(QSize(32, 32)); @@ -231,7 +244,8 @@ class Ui_FormNewProject button_z4->setObjectName(QString::fromUtf8("button_z4")); button_z4->setStyleSheet(QString::fromUtf8("background:white")); QIcon icon3; - icon3.addFile(QString::fromUtf8(":/Files/images/alphabet/z8.png"), QSize(), QIcon::Normal, QIcon::Off); + icon3.addFile(QString::fromUtf8(":/Files/images/alphabet/z8.png"), + QSize(), QIcon::Normal, QIcon::Off); button_z4->setIcon(icon3); button_z4->setIconSize(QSize(32, 32)); @@ -241,7 +255,8 @@ class Ui_FormNewProject button_z10->setObjectName(QString::fromUtf8("button_z10")); button_z10->setStyleSheet(QString::fromUtf8("background:white")); QIcon icon4; - icon4.addFile(QString::fromUtf8(":/Files/images/alphabet/z10.png"), QSize(), QIcon::Normal, QIcon::Off); + icon4.addFile(QString::fromUtf8(":/Files/images/alphabet/z10.png"), + QSize(), QIcon::Normal, QIcon::Off); button_z10->setIcon(icon4); button_z10->setIconSize(QSize(32, 32)); @@ -251,7 +266,8 @@ class Ui_FormNewProject button_z16->setObjectName(QString::fromUtf8("button_z16")); button_z16->setStyleSheet(QString::fromUtf8("background:white")); QIcon icon5; - icon5.addFile(QString::fromUtf8(":/Files/images/alphabet/z16.png"), QSize(), QIcon::Normal, QIcon::Off); + icon5.addFile(QString::fromUtf8(":/Files/images/alphabet/z16.png"), + QSize(), QIcon::Normal, QIcon::Off); button_z16->setIcon(icon5); button_z16->setIconSize(QSize(32, 32)); @@ -261,7 +277,8 @@ class Ui_FormNewProject button_z80->setObjectName(QString::fromUtf8("button_z80")); button_z80->setStyleSheet(QString::fromUtf8("background:white")); QIcon icon6; - icon6.addFile(QString::fromUtf8(":/Files/images/alphabet/z80.png"), QSize(), QIcon::Normal, QIcon::Off); + icon6.addFile(QString::fromUtf8(":/Files/images/alphabet/z80.png"), + QSize(), QIcon::Normal, QIcon::Off); button_z80->setIcon(icon6); button_z80->setIconSize(QSize(32, 32)); @@ -272,12 +289,12 @@ class Ui_FormNewProject QSizePolicy sizePolicy8(QSizePolicy::Expanding, QSizePolicy::Preferred); sizePolicy8.setHorizontalStretch(0); sizePolicy8.setVerticalStretch(0); - sizePolicy8.setHeightForWidth(widget_6->sizePolicy().hasHeightForWidth()); + sizePolicy8.setHeightForWidth( + widget_6->sizePolicy().hasHeightForWidth()); widget_6->setSizePolicy(sizePolicy8); horizontalLayout_6->addWidget(widget_6); - verticalLayout_2->addWidget(widget_4); text_alphabit = new QTextEdit(frame_5); @@ -286,41 +303,48 @@ class Ui_FormNewProject verticalLayout_2->addWidget(text_alphabit); - horizontalLayout_2->addWidget(frame_5); scrollArea->setWidget(scrollAreaWidgetContents); horizontalLayout->addWidget(scrollArea); - retranslateUi(FormNewProject); QMetaObject::connectSlotsByName(FormNewProject); - } // setupUi + } // setupUi - void retranslateUi(QWidget *FormNewProject) - { - FormNewProject->setWindowTitle(QCoreApplication::translate("FormNewProject", "Form", nullptr)); + void retranslateUi(QWidget* FormNewProject) { + FormNewProject->setWindowTitle( + QCoreApplication::translate("FormNewProject", "Form", nullptr)); button_create->setText(QString()); - label->setText(QCoreApplication::translate("FormNewProject", "Project Name", nullptr)); - label_3->setText(QCoreApplication::translate("FormNewProject", "Location", nullptr)); - button_project_location->setText(QCoreApplication::translate("FormNewProject", "...", nullptr)); - label_4->setText(QCoreApplication::translate("FormNewProject", "Alphabet", nullptr)); - button_z2->setText(QCoreApplication::translate("FormNewProject", "...", nullptr)); - button_z3->setText(QCoreApplication::translate("FormNewProject", "...", nullptr)); - button_z4->setText(QCoreApplication::translate("FormNewProject", "...", nullptr)); - button_z10->setText(QCoreApplication::translate("FormNewProject", "...", nullptr)); - button_z16->setText(QCoreApplication::translate("FormNewProject", "...", nullptr)); - button_z80->setText(QCoreApplication::translate("FormNewProject", "...", nullptr)); - } // retranslateUi - + label->setText(QCoreApplication::translate("FormNewProject", + "Project Name", nullptr)); + label_3->setText( + QCoreApplication::translate("FormNewProject", "Location", nullptr)); + button_project_location->setText( + QCoreApplication::translate("FormNewProject", "...", nullptr)); + label_4->setText( + QCoreApplication::translate("FormNewProject", "Alphabet", nullptr)); + button_z2->setText( + QCoreApplication::translate("FormNewProject", "...", nullptr)); + button_z3->setText( + QCoreApplication::translate("FormNewProject", "...", nullptr)); + button_z4->setText( + QCoreApplication::translate("FormNewProject", "...", nullptr)); + button_z10->setText( + QCoreApplication::translate("FormNewProject", "...", nullptr)); + button_z16->setText( + QCoreApplication::translate("FormNewProject", "...", nullptr)); + button_z80->setText( + QCoreApplication::translate("FormNewProject", "...", nullptr)); + } // retranslateUi }; namespace Ui { - class FormNewProject: public Ui_FormNewProject {}; -} // namespace Ui +class FormNewProject : public Ui_FormNewProject {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMNEWPROJECT_H +#endif // UI_FORMNEWPROJECT_H diff --git a/VirtualTuringMachine/ui_formwarning.h b/VirtualTuringMachine/ui_formwarning.h old mode 100755 new mode 100644 index d7c0b65..588e1bc --- a/VirtualTuringMachine/ui_formwarning.h +++ b/VirtualTuringMachine/ui_formwarning.h @@ -21,21 +21,19 @@ QT_BEGIN_NAMESPACE -class Ui_FormWarning -{ -public: - QVBoxLayout *verticalLayout; - QFrame *frame; - QHBoxLayout *horizontalLayout_2; - QLabel *label_2; - QLabel *label; - QFrame *frame_2; - QHBoxLayout *horizontalLayout; - QPushButton *button_ok; - QPushButton *button_cancel; - - void setupUi(QWidget *FormWarning) - { +class Ui_FormWarning { + public: + QVBoxLayout* verticalLayout; + QFrame* frame; + QHBoxLayout* horizontalLayout_2; + QLabel* label_2; + QLabel* label; + QFrame* frame_2; + QHBoxLayout* horizontalLayout; + QPushButton* button_ok; + QPushButton* button_cancel; + + void setupUi(QWidget* FormWarning) { if (FormWarning->objectName().isEmpty()) FormWarning->setObjectName(QString::fromUtf8("FormWarning")); FormWarning->resize(400, 300); @@ -46,10 +44,12 @@ class Ui_FormWarning frame->setFrameShape(QFrame::NoFrame); frame->setFrameShadow(QFrame::Plain); horizontalLayout_2 = new QHBoxLayout(frame); - horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2")); + horizontalLayout_2->setObjectName( + QString::fromUtf8("horizontalLayout_2")); label_2 = new QLabel(frame); label_2->setObjectName(QString::fromUtf8("label_2")); - label_2->setPixmap(QPixmap(QString::fromUtf8(":/Files/images/warning.png"))); + label_2->setPixmap( + QPixmap(QString::fromUtf8(":/Files/images/warning.png"))); horizontalLayout_2->addWidget(label_2); @@ -63,7 +63,6 @@ class Ui_FormWarning horizontalLayout_2->addWidget(label); - verticalLayout->addWidget(frame); frame_2 = new QFrame(FormWarning); @@ -75,7 +74,8 @@ class Ui_FormWarning button_ok = new QPushButton(frame_2); button_ok->setObjectName(QString::fromUtf8("button_ok")); QIcon icon; - icon.addFile(QString::fromUtf8(":/Files/images/ok.png"), QSize(), QIcon::Normal, QIcon::Off); + icon.addFile(QString::fromUtf8(":/Files/images/ok.png"), QSize(), + QIcon::Normal, QIcon::Off); button_ok->setIcon(icon); horizontalLayout->addWidget(button_ok); @@ -83,35 +83,36 @@ class Ui_FormWarning button_cancel = new QPushButton(frame_2); button_cancel->setObjectName(QString::fromUtf8("button_cancel")); QIcon icon1; - icon1.addFile(QString::fromUtf8(":/Files/images/cancel.png"), QSize(), QIcon::Normal, QIcon::Off); + icon1.addFile(QString::fromUtf8(":/Files/images/cancel.png"), QSize(), + QIcon::Normal, QIcon::Off); button_cancel->setIcon(icon1); horizontalLayout->addWidget(button_cancel); - verticalLayout->addWidget(frame_2); - retranslateUi(FormWarning); QMetaObject::connectSlotsByName(FormWarning); - } // setupUi + } // setupUi - void retranslateUi(QWidget *FormWarning) - { - FormWarning->setWindowTitle(QCoreApplication::translate("FormWarning", "Form", nullptr)); + void retranslateUi(QWidget* FormWarning) { + FormWarning->setWindowTitle( + QCoreApplication::translate("FormWarning", "Form", nullptr)); label_2->setText(QString()); - label->setText(QCoreApplication::translate("FormWarning", "Are you sure?", nullptr)); - button_ok->setText(QCoreApplication::translate("FormWarning", "Ok", nullptr)); - button_cancel->setText(QCoreApplication::translate("FormWarning", "Cancel", nullptr)); - } // retranslateUi - + label->setText(QCoreApplication::translate("FormWarning", + "Are you sure?", nullptr)); + button_ok->setText( + QCoreApplication::translate("FormWarning", "Ok", nullptr)); + button_cancel->setText( + QCoreApplication::translate("FormWarning", "Cancel", nullptr)); + } // retranslateUi }; namespace Ui { - class FormWarning: public Ui_FormWarning {}; -} // namespace Ui +class FormWarning : public Ui_FormWarning {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_FORMWARNING_H +#endif // UI_FORMWARNING_H diff --git a/VirtualTuringMachine/ui_mainwindow.h b/VirtualTuringMachine/ui_mainwindow.h old mode 100755 new mode 100644 index e809a92..490c08d --- a/VirtualTuringMachine/ui_mainwindow.h +++ b/VirtualTuringMachine/ui_mainwindow.h @@ -23,52 +23,51 @@ QT_BEGIN_NAMESPACE -class Ui_MainWindow -{ -public: - QWidget *centralWidget; - QVBoxLayout *verticalLayout; - QFrame *frame_header; - QHBoxLayout *horizontalLayout_2; - QToolButton *button_back; - QToolButton *button_debug_back; - QWidget *widgetLabel; - QHBoxLayout *horizontalLayout; - QLabel *label; - QToolButton *button_ok; - QToolButton *button_cancel; - QToolButton *button_4th; - QToolButton *button_exercise; - QToolButton *button_new_machine; - QToolButton *button_open_machine; - QToolButton *button_save; - QToolButton *button_export; - QToolButton *button_export_plantuml; - QToolButton *button_run; - QToolButton *button_configure; - QToolButton *button_theme; - QToolButton *button_debug_run; - QToolButton *button_debug_pause; - QToolButton *button_debug_stop; - QToolButton *button_debug_over; - QToolButton *button_debug_step; - QFrame *frame; - QHBoxLayout *horizontalLayout_3; - QWidget *widget_container; - QFrame *frame_zoom; - QVBoxLayout *verticalLayout_2; - QSlider *slider_zoom; - QLabel *label_2; - - void setupUi(QMainWindow *MainWindow) - { +class Ui_MainWindow { + public: + QWidget* centralWidget; + QVBoxLayout* verticalLayout; + QFrame* frame_header; + QHBoxLayout* horizontalLayout_2; + QToolButton* button_back; + QToolButton* button_debug_back; + QWidget* widgetLabel; + QHBoxLayout* horizontalLayout; + QLabel* label; + QToolButton* button_ok; + QToolButton* button_cancel; + QToolButton* button_4th; + QToolButton* button_exercise; + QToolButton* button_new_machine; + QToolButton* button_open_machine; + QToolButton* button_save; + QToolButton* button_export; + QToolButton* button_export_plantuml; + QToolButton* button_run; + QToolButton* button_configure; + QToolButton* button_theme; + QToolButton* button_debug_run; + QToolButton* button_debug_pause; + QToolButton* button_debug_stop; + QToolButton* button_debug_over; + QToolButton* button_debug_step; + QFrame* frame; + QHBoxLayout* horizontalLayout_3; + QWidget* widget_container; + QFrame* frame_zoom; + QVBoxLayout* verticalLayout_2; + QSlider* slider_zoom; + QLabel* label_2; + + void setupUi(QMainWindow* MainWindow) { if (MainWindow->objectName().isEmpty()) MainWindow->setObjectName(QString::fromUtf8("MainWindow")); MainWindow->resize(816, 426); QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); - sizePolicy.setHeightForWidth(MainWindow->sizePolicy().hasHeightForWidth()); + sizePolicy.setHeightForWidth( + MainWindow->sizePolicy().hasHeightForWidth()); MainWindow->setSizePolicy(sizePolicy); MainWindow->setBaseSize(QSize(800, 600)); MainWindow->setStyleSheet(QString::fromUtf8("")); @@ -78,7 +77,8 @@ class Ui_MainWindow QSizePolicy sizePolicy1(QSizePolicy::Ignored, QSizePolicy::Ignored); sizePolicy1.setHorizontalStretch(0); sizePolicy1.setVerticalStretch(0); - sizePolicy1.setHeightForWidth(centralWidget->sizePolicy().hasHeightForWidth()); + sizePolicy1.setHeightForWidth( + centralWidget->sizePolicy().hasHeightForWidth()); centralWidget->setSizePolicy(sizePolicy1); centralWidget->setStyleSheet(QString::fromUtf8("background:#012C40")); verticalLayout = new QVBoxLayout(centralWidget); @@ -91,7 +91,8 @@ class Ui_MainWindow QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Maximum); sizePolicy2.setHorizontalStretch(0); sizePolicy2.setVerticalStretch(0); - sizePolicy2.setHeightForWidth(frame_header->sizePolicy().hasHeightForWidth()); + sizePolicy2.setHeightForWidth( + frame_header->sizePolicy().hasHeightForWidth()); frame_header->setSizePolicy(sizePolicy2); frame_header->setAutoFillBackground(false); frame_header->setStyleSheet(QString::fromUtf8("")); @@ -100,19 +101,22 @@ class Ui_MainWindow horizontalLayout_2 = new QHBoxLayout(frame_header); horizontalLayout_2->setSpacing(-1); horizontalLayout_2->setContentsMargins(11, 11, 11, 11); - horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2")); + horizontalLayout_2->setObjectName( + QString::fromUtf8("horizontalLayout_2")); horizontalLayout_2->setContentsMargins(4, 4, 4, 4); button_back = new QToolButton(frame_header); button_back->setObjectName(QString::fromUtf8("button_back")); QSizePolicy sizePolicy3(QSizePolicy::Maximum, QSizePolicy::Maximum); sizePolicy3.setHorizontalStretch(0); sizePolicy3.setVerticalStretch(0); - sizePolicy3.setHeightForWidth(button_back->sizePolicy().hasHeightForWidth()); + sizePolicy3.setHeightForWidth( + button_back->sizePolicy().hasHeightForWidth()); button_back->setSizePolicy(sizePolicy3); button_back->setAutoFillBackground(false); button_back->setStyleSheet(QString::fromUtf8("background:#012C40")); QIcon icon; - icon.addFile(QString::fromUtf8(":/Files/images/toolbars/main/undo.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon.addFile(QString::fromUtf8(":/Files/images/toolbars/main/undo.gif"), + QSize(), QIcon::Normal, QIcon::Off); button_back->setIcon(icon); button_back->setIconSize(QSize(24, 24)); button_back->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -121,10 +125,13 @@ class Ui_MainWindow horizontalLayout_2->addWidget(button_back); button_debug_back = new QToolButton(frame_header); - button_debug_back->setObjectName(QString::fromUtf8("button_debug_back")); - button_debug_back->setStyleSheet(QString::fromUtf8("background:#012C40")); + button_debug_back->setObjectName( + QString::fromUtf8("button_debug_back")); + button_debug_back->setStyleSheet( + QString::fromUtf8("background:#012C40")); QIcon icon1; - icon1.addFile(QString::fromUtf8(":/images/toolbars/debug/undo.png"), QSize(), QIcon::Normal, QIcon::Off); + icon1.addFile(QString::fromUtf8(":/images/toolbars/debug/undo.png"), + QSize(), QIcon::Normal, QIcon::Off); button_debug_back->setIcon(icon1); button_debug_back->setIconSize(QSize(24, 24)); button_debug_back->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -137,7 +144,8 @@ class Ui_MainWindow QSizePolicy sizePolicy4(QSizePolicy::Expanding, QSizePolicy::Preferred); sizePolicy4.setHorizontalStretch(0); sizePolicy4.setVerticalStretch(0); - sizePolicy4.setHeightForWidth(widgetLabel->sizePolicy().hasHeightForWidth()); + sizePolicy4.setHeightForWidth( + widgetLabel->sizePolicy().hasHeightForWidth()); widgetLabel->setSizePolicy(sizePolicy4); horizontalLayout = new QHBoxLayout(widgetLabel); horizontalLayout->setSpacing(6); @@ -147,18 +155,19 @@ class Ui_MainWindow label = new QLabel(widgetLabel); label->setObjectName(QString::fromUtf8("label")); label->setAutoFillBackground(false); - label->setStyleSheet(QString::fromUtf8("background:transparent;color:white")); + label->setStyleSheet( + QString::fromUtf8("background:transparent;color:white")); horizontalLayout->addWidget(label); - horizontalLayout_2->addWidget(widgetLabel); button_ok = new QToolButton(frame_header); button_ok->setObjectName(QString::fromUtf8("button_ok")); button_ok->setStyleSheet(QString::fromUtf8("background:#012C40")); QIcon icon2; - icon2.addFile(QString::fromUtf8(":/Files/images/ok.png"), QSize(), QIcon::Normal, QIcon::Off); + icon2.addFile(QString::fromUtf8(":/Files/images/ok.png"), QSize(), + QIcon::Normal, QIcon::Off); button_ok->setIcon(icon2); button_ok->setIconSize(QSize(24, 24)); button_ok->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -169,7 +178,8 @@ class Ui_MainWindow button_cancel->setObjectName(QString::fromUtf8("button_cancel")); button_cancel->setStyleSheet(QString::fromUtf8("background:#012C40")); QIcon icon3; - icon3.addFile(QString::fromUtf8(":/Files/images/cancel.png"), QSize(), QIcon::Normal, QIcon::Off); + icon3.addFile(QString::fromUtf8(":/Files/images/cancel.png"), QSize(), + QIcon::Normal, QIcon::Off); button_cancel->setIcon(icon3); button_cancel->setIconSize(QSize(24, 24)); button_cancel->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -180,7 +190,8 @@ class Ui_MainWindow button_4th->setObjectName(QString::fromUtf8("button_4th")); button_4th->setStyleSheet(QString::fromUtf8("background:#012C40")); QIcon icon4; - icon4.addFile(QString::fromUtf8(":/Files/images/toolbars/tools/e4.png"), QSize(), QIcon::Normal, QIcon::Off); + icon4.addFile(QString::fromUtf8(":/Files/images/toolbars/tools/e4.png"), + QSize(), QIcon::Normal, QIcon::Off); button_4th->setIcon(icon4); button_4th->setIconSize(QSize(24, 24)); button_4th->setAutoRaise(true); @@ -192,7 +203,8 @@ class Ui_MainWindow button_exercise->setAutoFillBackground(false); button_exercise->setStyleSheet(QString::fromUtf8("background:#012C40")); QIcon icon5; - icon5.addFile(QString::fromUtf8(":/Files/images/exercise.png"), QSize(), QIcon::Normal, QIcon::Off); + icon5.addFile(QString::fromUtf8(":/Files/images/exercise.png"), QSize(), + QIcon::Normal, QIcon::Off); button_exercise->setIcon(icon5); button_exercise->setIconSize(QSize(24, 24)); button_exercise->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -201,11 +213,15 @@ class Ui_MainWindow horizontalLayout_2->addWidget(button_exercise); button_new_machine = new QToolButton(frame_header); - button_new_machine->setObjectName(QString::fromUtf8("button_new_machine")); + button_new_machine->setObjectName( + QString::fromUtf8("button_new_machine")); button_new_machine->setAutoFillBackground(false); - button_new_machine->setStyleSheet(QString::fromUtf8("background:#012C40")); + button_new_machine->setStyleSheet( + QString::fromUtf8("background:#012C40")); QIcon icon6; - icon6.addFile(QString::fromUtf8(":/Files/images/toolbars/main/icon_new_machine.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon6.addFile(QString::fromUtf8( + ":/Files/images/toolbars/main/icon_new_machine.gif"), + QSize(), QIcon::Normal, QIcon::Off); button_new_machine->setIcon(icon6); button_new_machine->setIconSize(QSize(24, 24)); button_new_machine->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -214,11 +230,15 @@ class Ui_MainWindow horizontalLayout_2->addWidget(button_new_machine); button_open_machine = new QToolButton(frame_header); - button_open_machine->setObjectName(QString::fromUtf8("button_open_machine")); + button_open_machine->setObjectName( + QString::fromUtf8("button_open_machine")); button_open_machine->setAutoFillBackground(false); - button_open_machine->setStyleSheet(QString::fromUtf8("background:#012C40")); + button_open_machine->setStyleSheet( + QString::fromUtf8("background:#012C40")); QIcon icon7; - icon7.addFile(QString::fromUtf8(":/Files/images/toolbars/main/icon_open.png"), QSize(), QIcon::Normal, QIcon::Off); + icon7.addFile( + QString::fromUtf8(":/Files/images/toolbars/main/icon_open.png"), + QSize(), QIcon::Normal, QIcon::Off); button_open_machine->setIcon(icon7); button_open_machine->setIconSize(QSize(24, 24)); button_open_machine->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -231,7 +251,9 @@ class Ui_MainWindow button_save->setAutoFillBackground(false); button_save->setStyleSheet(QString::fromUtf8("background:#012C40")); QIcon icon8; - icon8.addFile(QString::fromUtf8(":/Files/images/toolbars/main/icon_save.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon8.addFile( + QString::fromUtf8(":/Files/images/toolbars/main/icon_save.gif"), + QSize(), QIcon::Normal, QIcon::Off); button_save->setIcon(icon8); button_save->setIconSize(QSize(24, 24)); button_save->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -244,7 +266,9 @@ class Ui_MainWindow button_export->setAutoFillBackground(false); button_export->setStyleSheet(QString::fromUtf8("background:#012C40")); QIcon icon9; - icon9.addFile(QString::fromUtf8(":/Files/images/toolbars/main/icon_export.png"), QSize(), QIcon::Normal, QIcon::Off); + icon9.addFile( + QString::fromUtf8(":/Files/images/toolbars/main/icon_export.png"), + QSize(), QIcon::Normal, QIcon::Off); button_export->setIcon(icon9); button_export->setIconSize(QSize(24, 24)); button_export->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -253,10 +277,12 @@ class Ui_MainWindow horizontalLayout_2->addWidget(button_export); button_export_plantuml = new QToolButton(frame_header); - button_export_plantuml->setObjectName(QString::fromUtf8("button_export_plantuml")); + button_export_plantuml->setObjectName( + QString::fromUtf8("button_export_plantuml")); button_export_plantuml->setIcon(icon9); button_export_plantuml->setIconSize(QSize(24, 24)); - button_export_plantuml->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + button_export_plantuml->setToolButtonStyle( + Qt::ToolButtonTextBesideIcon); button_export_plantuml->setAutoRaise(true); horizontalLayout_2->addWidget(button_export_plantuml); @@ -266,7 +292,9 @@ class Ui_MainWindow button_run->setAutoFillBackground(false); button_run->setStyleSheet(QString::fromUtf8("background:#012C40")); QIcon icon10; - icon10.addFile(QString::fromUtf8(":/Files/images/toolbars/main/icon_run.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon10.addFile( + QString::fromUtf8(":/Files/images/toolbars/main/icon_run.gif"), + QSize(), QIcon::Normal, QIcon::Off); button_run->setIcon(icon10); button_run->setIconSize(QSize(24, 24)); button_run->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -277,9 +305,12 @@ class Ui_MainWindow button_configure = new QToolButton(frame_header); button_configure->setObjectName(QString::fromUtf8("button_configure")); button_configure->setAutoFillBackground(false); - button_configure->setStyleSheet(QString::fromUtf8("background:#012C40")); + button_configure->setStyleSheet( + QString::fromUtf8("background:#012C40")); QIcon icon11; - icon11.addFile(QString::fromUtf8(":/Files/images/toolbars/main/icon_configure.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon11.addFile(QString::fromUtf8( + ":/Files/images/toolbars/main/icon_configure.gif"), + QSize(), QIcon::Normal, QIcon::Off); button_configure->setIcon(icon11); button_configure->setIconSize(QSize(24, 24)); button_configure->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -298,9 +329,12 @@ class Ui_MainWindow button_debug_run = new QToolButton(frame_header); button_debug_run->setObjectName(QString::fromUtf8("button_debug_run")); - button_debug_run->setStyleSheet(QString::fromUtf8("background:#012C40")); + button_debug_run->setStyleSheet( + QString::fromUtf8("background:#012C40")); QIcon icon12; - icon12.addFile(QString::fromUtf8(":/Files/images/toolbars/debug/run.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon12.addFile( + QString::fromUtf8(":/Files/images/toolbars/debug/run.gif"), QSize(), + QIcon::Normal, QIcon::Off); button_debug_run->setIcon(icon12); button_debug_run->setIconSize(QSize(24, 24)); button_debug_run->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -308,10 +342,14 @@ class Ui_MainWindow horizontalLayout_2->addWidget(button_debug_run); button_debug_pause = new QToolButton(frame_header); - button_debug_pause->setObjectName(QString::fromUtf8("button_debug_pause")); - button_debug_pause->setStyleSheet(QString::fromUtf8("background:#012C40")); + button_debug_pause->setObjectName( + QString::fromUtf8("button_debug_pause")); + button_debug_pause->setStyleSheet( + QString::fromUtf8("background:#012C40")); QIcon icon13; - icon13.addFile(QString::fromUtf8(":/Files/images/toolbars/debug/pause.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon13.addFile( + QString::fromUtf8(":/Files/images/toolbars/debug/pause.gif"), + QSize(), QIcon::Normal, QIcon::Off); button_debug_pause->setIcon(icon13); button_debug_pause->setIconSize(QSize(24, 24)); button_debug_pause->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -319,10 +357,14 @@ class Ui_MainWindow horizontalLayout_2->addWidget(button_debug_pause); button_debug_stop = new QToolButton(frame_header); - button_debug_stop->setObjectName(QString::fromUtf8("button_debug_stop")); - button_debug_stop->setStyleSheet(QString::fromUtf8("background:#012C40")); + button_debug_stop->setObjectName( + QString::fromUtf8("button_debug_stop")); + button_debug_stop->setStyleSheet( + QString::fromUtf8("background:#012C40")); QIcon icon14; - icon14.addFile(QString::fromUtf8(":/Files/images/toolbars/debug/stop.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon14.addFile( + QString::fromUtf8(":/Files/images/toolbars/debug/stop.gif"), + QSize(), QIcon::Normal, QIcon::Off); button_debug_stop->setIcon(icon14); button_debug_stop->setIconSize(QSize(24, 24)); button_debug_stop->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -330,10 +372,14 @@ class Ui_MainWindow horizontalLayout_2->addWidget(button_debug_stop); button_debug_over = new QToolButton(frame_header); - button_debug_over->setObjectName(QString::fromUtf8("button_debug_over")); - button_debug_over->setStyleSheet(QString::fromUtf8("background:#012C40")); + button_debug_over->setObjectName( + QString::fromUtf8("button_debug_over")); + button_debug_over->setStyleSheet( + QString::fromUtf8("background:#012C40")); QIcon icon15; - icon15.addFile(QString::fromUtf8(":/Files/images/toolbars/debug/step_over.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon15.addFile( + QString::fromUtf8(":/Files/images/toolbars/debug/step_over.gif"), + QSize(), QIcon::Normal, QIcon::Off); button_debug_over->setIcon(icon15); button_debug_over->setIconSize(QSize(24, 24)); button_debug_over->setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -341,17 +387,20 @@ class Ui_MainWindow horizontalLayout_2->addWidget(button_debug_over); button_debug_step = new QToolButton(frame_header); - button_debug_step->setObjectName(QString::fromUtf8("button_debug_step")); - button_debug_step->setStyleSheet(QString::fromUtf8("background:#012C40")); + button_debug_step->setObjectName( + QString::fromUtf8("button_debug_step")); + button_debug_step->setStyleSheet( + QString::fromUtf8("background:#012C40")); QIcon icon16; - icon16.addFile(QString::fromUtf8(":/Files/images/toolbars/debug/step.gif"), QSize(), QIcon::Normal, QIcon::Off); + icon16.addFile( + QString::fromUtf8(":/Files/images/toolbars/debug/step.gif"), + QSize(), QIcon::Normal, QIcon::Off); button_debug_step->setIcon(icon16); button_debug_step->setIconSize(QSize(24, 24)); button_debug_step->setToolButtonStyle(Qt::ToolButtonIconOnly); horizontalLayout_2->addWidget(button_debug_step); - verticalLayout->addWidget(frame_header); frame = new QFrame(centralWidget); @@ -367,11 +416,13 @@ class Ui_MainWindow horizontalLayout_3 = new QHBoxLayout(frame); horizontalLayout_3->setSpacing(6); horizontalLayout_3->setContentsMargins(11, 11, 11, 11); - horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3")); + horizontalLayout_3->setObjectName( + QString::fromUtf8("horizontalLayout_3")); horizontalLayout_3->setContentsMargins(0, 0, 0, 0); widget_container = new QWidget(frame); widget_container->setObjectName(QString::fromUtf8("widget_container")); - sizePolicy5.setHeightForWidth(widget_container->sizePolicy().hasHeightForWidth()); + sizePolicy5.setHeightForWidth( + widget_container->sizePolicy().hasHeightForWidth()); widget_container->setSizePolicy(sizePolicy5); widget_container->setMaximumSize(QSize(16777215, 16777215)); widget_container->setAutoFillBackground(false); @@ -384,7 +435,8 @@ class Ui_MainWindow QSizePolicy sizePolicy6(QSizePolicy::Minimum, QSizePolicy::Expanding); sizePolicy6.setHorizontalStretch(0); sizePolicy6.setVerticalStretch(0); - sizePolicy6.setHeightForWidth(frame_zoom->sizePolicy().hasHeightForWidth()); + sizePolicy6.setHeightForWidth( + frame_zoom->sizePolicy().hasHeightForWidth()); frame_zoom->setSizePolicy(sizePolicy6); frame_zoom->setMinimumSize(QSize(0, 0)); frame_zoom->setMaximumSize(QSize(16777215, 16777215)); @@ -397,7 +449,8 @@ class Ui_MainWindow verticalLayout_2->setContentsMargins(12, 12, 12, 12); slider_zoom = new QSlider(frame_zoom); slider_zoom->setObjectName(QString::fromUtf8("slider_zoom")); - sizePolicy6.setHeightForWidth(slider_zoom->sizePolicy().hasHeightForWidth()); + sizePolicy6.setHeightForWidth( + slider_zoom->sizePolicy().hasHeightForWidth()); slider_zoom->setSizePolicy(sizePolicy6); slider_zoom->setMinimumSize(QSize(0, 0)); slider_zoom->setMaximumSize(QSize(16, 16777215)); @@ -416,21 +469,21 @@ class Ui_MainWindow QSizePolicy sizePolicy7(QSizePolicy::Minimum, QSizePolicy::Minimum); sizePolicy7.setHorizontalStretch(0); sizePolicy7.setVerticalStretch(0); - sizePolicy7.setHeightForWidth(label_2->sizePolicy().hasHeightForWidth()); + sizePolicy7.setHeightForWidth( + label_2->sizePolicy().hasHeightForWidth()); label_2->setSizePolicy(sizePolicy7); label_2->setMinimumSize(QSize(0, 0)); label_2->setMaximumSize(QSize(16, 16)); label_2->setText(QString::fromUtf8("")); - label_2->setPixmap(QPixmap(QString::fromUtf8(":/Files/images/zoom.png"))); + label_2->setPixmap( + QPixmap(QString::fromUtf8(":/Files/images/zoom.png"))); label_2->setScaledContents(true); label_2->setAlignment(Qt::AlignCenter); verticalLayout_2->addWidget(label_2); - horizontalLayout_3->addWidget(frame_zoom); - verticalLayout->addWidget(frame); MainWindow->setCentralWidget(centralWidget); @@ -438,63 +491,104 @@ class Ui_MainWindow retranslateUi(MainWindow); QMetaObject::connectSlotsByName(MainWindow); - } // setupUi + } // setupUi - void retranslateUi(QMainWindow *MainWindow) - { - MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "Virtual Turing Machine", nullptr)); + void retranslateUi(QMainWindow* MainWindow) { + MainWindow->setWindowTitle(QCoreApplication::translate( + "MainWindow", "Virtual Turing Machine", nullptr)); button_back->setText(QString()); button_debug_back->setText(QString()); - button_debug_back->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_back", nullptr))); - label->setText(QCoreApplication::translate("MainWindow", "TextLabel", nullptr)); - button_ok->setText(QCoreApplication::translate("MainWindow", "OK", nullptr)); - button_ok->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_ok", nullptr))); + button_debug_back->setProperty( + "name", QVariant(QCoreApplication::translate( + "MainWindow", "button_back", nullptr))); + label->setText( + QCoreApplication::translate("MainWindow", "TextLabel", nullptr)); + button_ok->setText( + QCoreApplication::translate("MainWindow", "OK", nullptr)); + button_ok->setProperty("name", + QVariant(QCoreApplication::translate( + "MainWindow", "button_ok", nullptr))); button_cancel->setText(QString()); - button_cancel->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_cancel", nullptr))); + button_cancel->setProperty( + "name", QVariant(QCoreApplication::translate( + "MainWindow", "button_cancel", nullptr))); button_4th->setText(QString()); - button_4th->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_4th", nullptr))); + button_4th->setProperty("name", + QVariant(QCoreApplication::translate( + "MainWindow", "button_4th", nullptr))); button_exercise->setText(QString()); - button_exercise->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_exercise", nullptr))); + button_exercise->setProperty( + "name", QVariant(QCoreApplication::translate( + "MainWindow", "button_exercise", nullptr))); button_new_machine->setText(QString()); - button_new_machine->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_new_machine", nullptr))); + button_new_machine->setProperty( + "name", QVariant(QCoreApplication::translate( + "MainWindow", "button_new_machine", nullptr))); button_open_machine->setText(QString()); - button_open_machine->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_open_machine", nullptr))); + button_open_machine->setProperty( + "name", QVariant(QCoreApplication::translate( + "MainWindow", "button_open_machine", nullptr))); button_save->setText(QString()); - button_save->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_save", nullptr))); + button_save->setProperty("name", + QVariant(QCoreApplication::translate( + "MainWindow", "button_save", nullptr))); button_export->setText(QString()); - button_export->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_export", nullptr))); + button_export->setProperty( + "name", QVariant(QCoreApplication::translate( + "MainWindow", "button_export", nullptr))); #if QT_CONFIG(tooltip) - button_export_plantuml->setToolTip(QCoreApplication::translate("MainWindow", "Export diagram to PlantUML (.puml)", nullptr)); -#endif // QT_CONFIG(tooltip) - button_export_plantuml->setText(QCoreApplication::translate("MainWindow", "PUML", nullptr)); - button_export_plantuml->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_export_plantuml", nullptr))); + button_export_plantuml->setToolTip(QCoreApplication::translate( + "MainWindow", "Export diagram to PlantUML (.puml)", nullptr)); +#endif // QT_CONFIG(tooltip) + button_export_plantuml->setText( + QCoreApplication::translate("MainWindow", "PUML", nullptr)); + button_export_plantuml->setProperty( + "name", QVariant(QCoreApplication::translate( + "MainWindow", "button_export_plantuml", nullptr))); button_run->setText(QString()); - button_run->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_run", nullptr))); + button_run->setProperty("name", + QVariant(QCoreApplication::translate( + "MainWindow", "button_run", nullptr))); button_configure->setText(QString()); - button_configure->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_configure", nullptr))); + button_configure->setProperty( + "name", QVariant(QCoreApplication::translate( + "MainWindow", "button_configure", nullptr))); #if QT_CONFIG(tooltip) - button_theme->setToolTip(QCoreApplication::translate("MainWindow", "Dark theme", nullptr)); -#endif // QT_CONFIG(tooltip) - button_theme->setText(QCoreApplication::translate("MainWindow", "\360\237\214\231", nullptr)); - button_theme->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_theme", nullptr))); + button_theme->setToolTip( + QCoreApplication::translate("MainWindow", "Dark theme", nullptr)); +#endif // QT_CONFIG(tooltip) + button_theme->setText(QCoreApplication::translate( + "MainWindow", "\360\237\214\231", nullptr)); + button_theme->setProperty("name", + QVariant(QCoreApplication::translate( + "MainWindow", "button_theme", nullptr))); button_debug_run->setText(QString()); - button_debug_run->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_debug_run", nullptr))); + button_debug_run->setProperty( + "name", QVariant(QCoreApplication::translate( + "MainWindow", "button_debug_run", nullptr))); button_debug_pause->setText(QString()); - button_debug_pause->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_debug_pause", nullptr))); + button_debug_pause->setProperty( + "name", QVariant(QCoreApplication::translate( + "MainWindow", "button_debug_pause", nullptr))); button_debug_stop->setText(QString()); - button_debug_stop->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_debug_stop", nullptr))); + button_debug_stop->setProperty( + "name", QVariant(QCoreApplication::translate( + "MainWindow", "button_debug_stop", nullptr))); button_debug_over->setText(QString()); - button_debug_over->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_debug_over", nullptr))); + button_debug_over->setProperty( + "name", QVariant(QCoreApplication::translate( + "MainWindow", "button_debug_over", nullptr))); button_debug_step->setText(QString()); - button_debug_step->setProperty("name", QVariant(QCoreApplication::translate("MainWindow", "button_debug_step", nullptr))); - } // retranslateUi - + button_debug_step->setProperty( + "name", QVariant(QCoreApplication::translate( + "MainWindow", "button_debug_step", nullptr))); + } // retranslateUi }; namespace Ui { - class MainWindow: public Ui_MainWindow {}; -} // namespace Ui +class MainWindow : public Ui_MainWindow {}; +} // namespace Ui QT_END_NAMESPACE -#endif // UI_MAINWINDOW_H +#endif // UI_MAINWINDOW_H diff --git a/VirtualTuringMachine/uicanvas.cpp b/VirtualTuringMachine/uicanvas.cpp old mode 100755 new mode 100644 index dfefa53..9096f8f --- a/VirtualTuringMachine/uicanvas.cpp +++ b/VirtualTuringMachine/uicanvas.cpp @@ -1,32 +1,31 @@ #include "uicanvas.h" -#include "vmticons.h" -#include "vmttheme.h" #include - #include -//#define STEP 20 -//#define FONT_SIZE 18 - - -UICanvas::UICanvas(QBrush background,QPen net,[[maybe_unused]] QPen foreground,QSize size,size_t font_size): - _brush_background(background), - _pen_net(net), - _pen_foreground(QPen(VmtTheme::diagramLine())), - _pen_selected(QPen(VmtTheme::primary(), 2)), - _pen_error(QPen(VmtTheme::error(), 3)), - _painter(nullptr), - _fill_normal(QBrush(VmtTheme::machineFill())), - _fill_selected(VmtTheme::machineFillSelected()), - _animation(0) -{ +#include "vmticons.h" +#include "vmttheme.h" + +// #define STEP 20 +// #define FONT_SIZE 18 + +UICanvas::UICanvas(QBrush background, QPen net, + [[maybe_unused]] QPen foreground, QSize size, + size_t font_size) + : _brush_background(background), + _pen_net(net), + _pen_foreground(QPen(VmtTheme::diagramLine())), + _pen_selected(QPen(VmtTheme::primary(), 2)), + _pen_error(QPen(VmtTheme::error(), 3)), + _painter(nullptr), + _fill_normal(QBrush(VmtTheme::machineFill())), + _fill_selected(VmtTheme::machineFillSelected()), + _animation(0) { _font_size = font_size; _net = size; _font = QFont("Courier New", 12, QFont::Bold); - - for(int i=0;i<10;i++){ + for (int i = 0; i < 10; i++) { QVector dashes; _animation_pen[i].setWidth(1); _animation_pen[i].setDashOffset(i); @@ -36,21 +35,17 @@ UICanvas::UICanvas(QBrush background,QPen net,[[maybe_unused]] QPen foreground,Q _animation_pen[i].setStyle(Qt::CustomDashLine); _animation_pen[i].setDashPattern(dashes); - } applyThemeColors(); } -void UICanvas::reloadMachineIcons() -{ - VmtIcons::loadMachineIcons(_images); -} +void UICanvas::reloadMachineIcons() { VmtIcons::loadMachineIcons(_images); } -void UICanvas::applyThemeColors() -{ +void UICanvas::applyThemeColors() { _brush_background = QBrush(VmtTheme::diagramBackground()); - _pen_net = QPen(VmtTheme::diagramGrid(), 1, Qt::DotLine, Qt::RoundCap, Qt::RoundJoin); + _pen_net = QPen(VmtTheme::diagramGrid(), 1, Qt::DotLine, Qt::RoundCap, + Qt::RoundJoin); _pen_foreground = QPen(VmtTheme::diagramLine()); _pen_selected = QPen(VmtTheme::primary(), 2); _pen_error = QPen(VmtTheme::error(), 3); @@ -62,150 +57,130 @@ void UICanvas::applyThemeColors() reloadMachineIcons(); } -void UICanvas::SetFontSize(size_t font_size){ - _font_size = font_size; -} -void UICanvas::SetCellSize(QSize size){ - _net = size; -} -size_t UICanvas::GetStep(){ - return _net.width(); -} - -QPainter *UICanvas::GetPainter(){ - return _painter; -} +void UICanvas::SetFontSize(size_t font_size) { _font_size = font_size; } +void UICanvas::SetCellSize(QSize size) { _net = size; } +size_t UICanvas::GetStep() { return _net.width(); } -void UICanvas::SetPainter(QPainter *painter){ - _painter = painter; -} +QPainter* UICanvas::GetPainter() { return _painter; } +void UICanvas::SetPainter(QPainter* painter) { _painter = painter; } - -void UICanvas::SnapToGris(QPoint &point){ - point.rx() = (point.x()/GetStep())*GetStep()+GetStep()/2; - point.ry() = (point.y()/GetStep())*GetStep()+GetStep()/2; -} - -void UICanvas::Animate(){ - _animation = (_animation+1)%10; +void UICanvas::SnapToGris(QPoint& point) { + point.rx() = (point.x() / GetStep()) * GetStep() + GetStep() / 2; + point.ry() = (point.y() / GetStep()) * GetStep() + GetStep() / 2; } +void UICanvas::Animate() { _animation = (_animation + 1) % 10; } - -double UICanvas::GetFactor(){ - size_t factor = (_state._zoom*100)/100; - return (double)factor/100.0; +double UICanvas::GetFactor() { + size_t factor = (_state._zoom * 100) / 100; + return (double)factor / 100.0; } -void UICanvas::SetCenter(QPoint point,QSize screen_size){ +void UICanvas::SetCenter(QPoint point, QSize screen_size) { double factor = GetFactor(); - _state._center.setX(-point.x()+screen_size.width()/(2*factor)); - _state._center.setY(-point.y()+screen_size.height()/(2*factor)); + _state._center.setX(-point.x() + screen_size.width() / (2 * factor)); + _state._center.setY(-point.y() + screen_size.height() / (2 * factor)); } -QPoint& UICanvas::GetCenter(){ - return _state._center; -} +QPoint& UICanvas::GetCenter() { return _state._center; } -QRect UICanvas::ToScreen(const QRect& rect){ +QRect UICanvas::ToScreen(const QRect& rect) { QRect result; double factor = GetFactor(); - result.setLeft((rect.left()+_state._center.x())*factor); - result.setTop((rect.top()+_state._center.y())*factor); - result.setWidth(rect.width()*factor); - result.setHeight(rect.height()*factor); + result.setLeft((rect.left() + _state._center.x()) * factor); + result.setTop((rect.top() + _state._center.y()) * factor); + result.setWidth(rect.width() * factor); + result.setHeight(rect.height() * factor); return result; } -QPoint UICanvas::ToScreen(QPoint point){ +QPoint UICanvas::ToScreen(QPoint point) { double factor = GetFactor(); - return QPoint((point.rx()+_state._center.rx())*factor, - (point.ry()+_state._center.ry())*factor); + return QPoint((point.rx() + _state._center.rx()) * factor, + (point.ry() + _state._center.ry()) * factor); } -QPoint UICanvas::FromScreen(QPoint &shift){ +QPoint UICanvas::FromScreen(QPoint& shift) { double factor = GetFactor(); - return QPoint(shift.rx()/factor-_state._center.rx(),shift.ry()/factor-_state._center.ry()); + return QPoint(shift.rx() / factor - _state._center.rx(), + shift.ry() / factor - _state._center.ry()); } -QPoint UICanvas::FromScreen(QPoint &&shift){ +QPoint UICanvas::FromScreen(QPoint&& shift) { double factor = GetFactor(); - return QPoint(shift.rx()/factor-_state._center.rx(),shift.ry()/factor-_state._center.ry()); + return QPoint(shift.rx() / factor - _state._center.rx(), + shift.ry() / factor - _state._center.ry()); } -QRect UICanvas::FromScreen(const QRect& rect){ +QRect UICanvas::FromScreen(const QRect& rect) { QRect result; double factor = GetFactor(); - result.setLeft(rect.left()/factor-_state._center.x()); - result.setTop(rect.top()/factor-_state._center.y()); - result.setWidth(rect.width()/factor); - result.setHeight(rect.height()/factor); + result.setLeft(rect.left() / factor - _state._center.x()); + result.setTop(rect.top() / factor - _state._center.y()); + result.setWidth(rect.width() / factor); + result.setHeight(rect.height() / factor); return result; } - -void UICanvas::MoveInScreen(QPoint &shift){ +void UICanvas::MoveInScreen(QPoint& shift) { double factor = GetFactor(); - _state._center += QPoint(shift.rx()/factor,shift.ry()/factor); + _state._center += QPoint(shift.rx() / factor, shift.ry() / factor); } -void UICanvas::MoveInScreen(QPoint &&shift){ +void UICanvas::MoveInScreen(QPoint&& shift) { double factor = GetFactor(); - _state._center += QPoint(shift.rx()/factor,shift.ry()/factor); + _state._center += QPoint(shift.rx() / factor, shift.ry() / factor); } -void UICanvas::SetInScreen(QPoint &¢er){ +void UICanvas::SetInScreen(QPoint&& center) { double factor = GetFactor(); - _state._center = QPoint(center.rx()/factor,center.ry()/factor); + _state._center = QPoint(center.rx() / factor, center.ry() / factor); } -void UICanvas::Move(QPoint &shift){ - _state._center += shift; -} -void UICanvas::Move(QPoint &&shift){ - _state._center += shift; -} +void UICanvas::Move(QPoint& shift) { _state._center += shift; } +void UICanvas::Move(QPoint&& shift) { _state._center += shift; } +size_t UICanvas::GetZoom() const { return _state._zoom; } -size_t UICanvas::GetZoom() const{ - return _state._zoom; +void UICanvas::SetZoom(size_t zoom) { + if (zoom > 0) _state._zoom = zoom; } -void UICanvas::SetZoom(size_t zoom){ - if(zoom>0) _state._zoom = zoom; -} - -void UICanvas::Paint(QPainter &painter,const QRect &rect,const QRect &bounds){ +void UICanvas::Paint(QPainter& painter, const QRect& rect, + const QRect& bounds) { std::lock_guard guard(_mutex); _painter = &painter; - PaintBackground(rect,bounds); + PaintBackground(rect, bounds); } -void UICanvas::PaintBackground(const QRect &rect,const QRect &bounds){ - if(_painter!=nullptr){ +void UICanvas::PaintBackground(const QRect& rect, const QRect& bounds) { + if (_painter != nullptr) { _painter->fillRect(rect, _brush_background); _painter->setPen(_pen_net); double factor = GetFactor(); - double step = _net.width()*factor; - - int x_count = (_state._center.x()*factor)/step; - int y_count = (_state._center.y()*factor)/step; + double step = _net.width() * factor; - QPoint offset(_state._center.x()*factor - x_count*step,_state._center.y()*factor - y_count*step); + int x_count = (_state._center.x() * factor) / step; + int y_count = (_state._center.y() * factor) / step; + QPoint offset(_state._center.x() * factor - x_count * step, + _state._center.y() * factor - y_count * step); - for(double i=0;i=rect.left())&&((i+offset.x())<=rect.right())) - _painter->drawLine(QLineF(i+offset.x(),0,i+offset.x(),bounds.height())); + for (double i = 0; i < bounds.width(); i += step) + if (((i + offset.x()) >= rect.left()) && + ((i + offset.x()) <= rect.right())) + _painter->drawLine( + QLineF(i + offset.x(), 0, i + offset.x(), bounds.height())); - for(double i=0;i=rect.top())&&((i+offset.y())<=rect.bottom())) - _painter->drawLine(QLineF(0,i+offset.y(),bounds.width(),i+offset.y())); + for (double i = 0; i < bounds.height(); i += step) + if (((i + offset.y()) >= rect.top()) && + ((i + offset.y()) <= rect.bottom())) + _painter->drawLine( + QLineF(0, i + offset.y(), bounds.width(), i + offset.y())); } - } -void UICanvas::CalculateTextSize(const QString& text,QRect &rect){ +void UICanvas::CalculateTextSize(const QString& text, QRect& rect) { /* double factor = GetFactor(); _font.setPointSizeF(_font_size*factor); @@ -223,141 +198,142 @@ void UICanvas::CalculateTextSize(const QString& text,QRect &rect){ rect.setWidth(fm.horizontalAdvance(text)); rect.setHeight(fm.height()); //*/ - } -void UICanvas::DrawButton(const QRect &rect){ +void UICanvas::DrawButton(const QRect& rect) { std::lock_guard guard(_mutex); const QBrush fill_brush(VmtTheme::machineFill()); const QPen fill_pen(VmtTheme::diagramNodeBorder()); -// static QPen pen_white(QColor(255,255,255)); -// static QPen pen_blue(QColor(1,84,122)); -// static QBrush fill_blue(QColor(1,84,122)); + // static QPen pen_white(QColor(255,255,255)); + // static QPen pen_blue(QColor(1,84,122)); + // static QBrush fill_blue(QColor(1,84,122)); double factor = GetFactor(); - QRect to_draw((_state._center.rx()+rect.left())*factor, - (_state._center.ry()+rect.top())*factor, - rect.width()*factor,rect.height()*factor); + QRect to_draw((_state._center.rx() + rect.left()) * factor, + (_state._center.ry() + rect.top()) * factor, + rect.width() * factor, rect.height() * factor); _painter->setPen(fill_pen); - _painter->fillRect(to_draw,fill_brush); + _painter->fillRect(to_draw, fill_brush); //_painter->setBrush(fill_blue); //_painter->drawRect(to_draw); //_painter->setPen(pen_blue); //_painter->drawEllipse(QRect(to_draw.right()-to_draw.height()/4,to_draw.top()+1,to_draw.height()/2,to_draw.height()-2)); //_painter->fillRect(QRect(to_draw.left(),to_draw.top(),3,to_draw.height()),fill_blue); - } -void UICanvas::FillRect(const QRect &rect, bool selected){ +void UICanvas::FillRect(const QRect& rect, bool selected) { std::lock_guard guard(_mutex); double factor = GetFactor(); - QRect to_draw((_state._center.rx()+rect.left())*factor, - (_state._center.ry()+rect.top())*factor, - rect.width()*factor,rect.height()*factor); - if(!selected) _painter->fillRect(to_draw,_fill_normal); - else _painter->fillRect(to_draw,_fill_selected); + QRect to_draw((_state._center.rx() + rect.left()) * factor, + (_state._center.ry() + rect.top()) * factor, + rect.width() * factor, rect.height() * factor); + if (!selected) + _painter->fillRect(to_draw, _fill_normal); + else + _painter->fillRect(to_draw, _fill_selected); } -QPixmap* UICanvas::GetImage(ImageType image_type){ +QPixmap* UICanvas::GetImage(ImageType image_type) { return _images[image_type]; } -void UICanvas::DrawImageScreen(ImageType image_type, const QRect &rect){ +void UICanvas::DrawImageScreen(ImageType image_type, const QRect& rect) { std::lock_guard guard(_mutex); - _painter->drawPixmap(rect.left(), - rect.top(), - rect.width(), - rect.height(), *_images[image_type]); + _painter->drawPixmap(rect.left(), rect.top(), rect.width(), rect.height(), + *_images[image_type]); } -void UICanvas::DrawImage(ImageType image_type, const QRect &rect){ +void UICanvas::DrawImage(ImageType image_type, const QRect& rect) { std::lock_guard guard(_mutex); double factor = GetFactor(); - _painter->drawPixmap((_state._center.rx()+rect.left())*factor, - (_state._center.ry()+rect.top())*factor, - rect.width()*factor, - rect.height()*factor, *_images[image_type]); + _painter->drawPixmap((_state._center.rx() + rect.left()) * factor, + (_state._center.ry() + rect.top()) * factor, + rect.width() * factor, rect.height() * factor, + *_images[image_type]); } -void UICanvas::DrawArrow([[maybe_unused]] const QPoint &start,const QPoint &end, [[maybe_unused]] bool selected,bool error){ +void UICanvas::DrawArrow([[maybe_unused]] const QPoint& start, + const QPoint& end, [[maybe_unused]] bool selected, + bool error) { std::lock_guard guard(_mutex); double factor = GetFactor(); - if(error) { + if (error) { _painter->setPen(_pen_error); - } else if(selected) { + } else if (selected) { _painter->setPen(_pen_selected); } else { _painter->setPen(_pen_foreground); } - QLine line1((_state._center.x()+end.x()-10)*factor, - (_state._center.y()+end.y()-10)*factor, - (_state._center.x()+end.x())*factor, - (_state._center.y()+end.y())*factor); + QLine line1((_state._center.x() + end.x() - 10) * factor, + (_state._center.y() + end.y() - 10) * factor, + (_state._center.x() + end.x()) * factor, + (_state._center.y() + end.y()) * factor); _painter->drawLine(line1); - QLine line2((_state._center.x()+end.x()-10)*factor, - (_state._center.y()+end.y()+10)*factor, - (_state._center.x()+end.x())*factor, - (_state._center.y()+end.y())*factor); + QLine line2((_state._center.x() + end.x() - 10) * factor, + (_state._center.y() + end.y() + 10) * factor, + (_state._center.x() + end.x()) * factor, + (_state._center.y() + end.y()) * factor); _painter->drawLine(line2); } -void UICanvas::DrawLine(const QPoint &start,const QPoint &end, bool selected,bool error){ +void UICanvas::DrawLine(const QPoint& start, const QPoint& end, bool selected, + bool error) { std::lock_guard guard(_mutex); double factor = GetFactor(); - if(error) { + if (error) { _painter->setPen(_pen_error); - } else if(selected) { + } else if (selected) { _painter->setPen(_pen_selected); } else { _painter->setPen(_pen_foreground); } - QLine line((_state._center.x()+start.x())*factor, - (_state._center.y()+start.y())*factor, - (_state._center.x()+end.x())*factor, - (_state._center.y()+end.y())*factor); + QLine line((_state._center.x() + start.x()) * factor, + (_state._center.y() + start.y()) * factor, + (_state._center.x() + end.x()) * factor, + (_state._center.y() + end.y()) * factor); _painter->drawLine(line); } -void UICanvas::DrawLineAnimation(const QPoint &start,const QPoint &end,[[maybe_unused]] bool selected){ +void UICanvas::DrawLineAnimation(const QPoint& start, const QPoint& end, + [[maybe_unused]] bool selected) { std::lock_guard guard(_mutex); double factor = GetFactor(); _painter->setPen(_animation_pen[_animation]); - - QLine line((_state._center.x()+start.x())*factor, - (_state._center.y()+start.y())*factor, - (_state._center.x()+end.x())*factor, - (_state._center.y()+end.y())*factor); + QLine line((_state._center.x() + start.x()) * factor, + (_state._center.y() + start.y()) * factor, + (_state._center.x() + end.x()) * factor, + (_state._center.y() + end.y()) * factor); _painter->drawLine(line); } namespace { -QTransform diagramToScreenTransform(const UICanvasState& state, double factor) -{ +QTransform diagramToScreenTransform(const UICanvasState& state, double factor) { QTransform transform; transform.scale(factor, factor); transform.translate(state._center.x(), state._center.y()); return transform; } -} // namespace +} // namespace -void UICanvas::DrawConnectorPath(const QPainterPath& diagramPath, bool selected, bool error, bool animated) -{ +void UICanvas::DrawConnectorPath(const QPainterPath& diagramPath, bool selected, + bool error, bool animated) { if (diagramPath.isEmpty()) { return; } std::lock_guard guard(_mutex); const double factor = GetFactor(); - const QPainterPath screenPath = diagramToScreenTransform(_state, factor).map(diagramPath); + const QPainterPath screenPath = + diagramToScreenTransform(_state, factor).map(diagramPath); _painter->setRenderHint(QPainter::Antialiasing, true); @@ -374,8 +350,8 @@ void UICanvas::DrawConnectorPath(const QPainterPath& diagramPath, bool selected, _painter->strokePath(screenPath, _painter->pen()); } -void UICanvas::DrawArrowForPath(const QPainterPath& diagramPath, bool selected, bool error) -{ +void UICanvas::DrawArrowForPath(const QPainterPath& diagramPath, bool selected, + bool error) { if (diagramPath.isEmpty()) { return; } @@ -413,58 +389,59 @@ void UICanvas::DrawArrowForPath(const QPainterPath& diagramPath, bool selected, _painter->drawLine(QLineF(back - normal * headWidth, tip)); } -void UICanvas::DrawRectAnimation(const QRect & rect,bool selected){ +void UICanvas::DrawRectAnimation(const QRect& rect, bool selected) { std::lock_guard guard(_mutex); double factor = GetFactor(); _painter->setPen(_animation_pen[_animation]); - QRect to_draw((_state._center.rx()+rect.left())*factor, - (_state._center.ry()+rect.top())*factor, - rect.width()*factor,rect.height()*factor); - if(selected) _painter->fillRect(to_draw,this->_fill_selected); + QRect to_draw((_state._center.rx() + rect.left()) * factor, + (_state._center.ry() + rect.top()) * factor, + rect.width() * factor, rect.height() * factor); + if (selected) _painter->fillRect(to_draw, this->_fill_selected); _painter->drawRect(to_draw); } -void UICanvas::DrawRectScreen(const QRect & rect){ +void UICanvas::DrawRectScreen(const QRect& rect) { std::lock_guard guard(_mutex); _painter->setPen(_pen_selected); _painter->drawRect(rect); } -void UICanvas::DrawRect(const QRect & rect,bool selected,bool error){ +void UICanvas::DrawRect(const QRect& rect, bool selected, bool error) { std::lock_guard guard(_mutex); double factor = GetFactor(); - - QRect to_draw((_state._center.rx()+rect.left())*factor, - (_state._center.ry()+rect.top())*factor, - rect.width()*factor,rect.height()*factor); - if(error) { + QRect to_draw((_state._center.rx() + rect.left()) * factor, + (_state._center.ry() + rect.top()) * factor, + rect.width() * factor, rect.height() * factor); + if (error) { _painter->setPen(_pen_error); - } else if(selected) { + } else if (selected) { _painter->setPen(_pen_selected); } else { _painter->setPen(_pen_foreground); } - if(selected) { + if (selected) { _painter->fillRect(to_draw, _fill_selected); } _painter->drawRect(to_draw); } -void UICanvas::DrawText(const QString& text,const QPoint center,size_t size,bool selected){ +void UICanvas::DrawText(const QString& text, const QPoint center, size_t size, + bool selected) { std::lock_guard guard(_mutex); double factor = GetFactor(); - if(selected) _painter->setPen(_pen_selected); - else _painter->setPen(_pen_foreground); + if (selected) + _painter->setPen(_pen_selected); + else + _painter->setPen(_pen_foreground); - float _heightToFitIn = size*factor; - float oldFontSize=_font.pointSizeF(); + float _heightToFitIn = size * factor; + float oldFontSize = _font.pointSizeF(); float newFontSize; // Loop - for (int i=0 ; i<3 ; i++) - { + for (int i = 0; i < 3; i++) { float oldHeight = _painter->fontMetrics().boundingRect('D').height(); newFontSize = (_heightToFitIn / oldHeight) * oldFontSize; _font.setPointSizeF(newFontSize); @@ -476,9 +453,10 @@ void UICanvas::DrawText(const QString& text,const QPoint center,size_t size,bool _painter->setFont(_font); QRect fontRect = _painter->fontMetrics().boundingRect(text); - QPoint point((_state._center.rx()+center.x())*factor-fontRect.width()/2, - (_state._center.ry()+center.y())*factor+fontRect.height()/3); - _painter->drawText(point,text); + QPoint point( + (_state._center.rx() + center.x()) * factor - fontRect.width() / 2, + (_state._center.ry() + center.y()) * factor + fontRect.height() / 3); + _painter->drawText(point, text); } /* void UICanvas::DrawText(const QString& text,const QRect &bounds,bool selected){ @@ -506,16 +484,12 @@ void UICanvas::DrawText(const QString& text,const QRect &bounds,bool selected){ QRect fontRect = _painter->fontMetrics().boundingRect(text); - QPoint point((_state._center.rx()+bounds.left()+bounds.width()/2-fontRect.width()/2)*factor, + QPoint +point((_state._center.rx()+bounds.left()+bounds.width()/2-fontRect.width()/2)*factor, (_state._center.ry()+bounds.bottom()-bounds.height()/2+fontRect.height()/2)*factor); _painter->drawText(point,text); }*/ -const UICanvasState& UICanvas::GetState(){ - return _state; -} - -void UICanvas::SetState(const UICanvasState& other){ - _state = other; -} +const UICanvasState& UICanvas::GetState() { return _state; } +void UICanvas::SetState(const UICanvasState& other) { _state = other; } diff --git a/VirtualTuringMachine/uicanvas.h b/VirtualTuringMachine/uicanvas.h old mode 100755 new mode 100644 index 136eff0..ec2c055 --- a/VirtualTuringMachine/uicanvas.h +++ b/VirtualTuringMachine/uicanvas.h @@ -1,17 +1,15 @@ #ifndef UICANVAS_H #define UICANVAS_H +#include #include #include -#include -#include #include -#include - +#include #include #include -enum ImageType{ +enum ImageType { MACHINE_LAMBDA = 0, MACHINE_START = 1, MACHINE_FINISH = 2, @@ -20,48 +18,46 @@ enum ImageType{ MACHINE_LEFT_WORD = 5, MACHINE_RIGHT_WORD = 6, MACHINE_COPY = 7, - CANCEL=8, - MACHINE_COMPLEX=9, - LINK=10, - NAVIGATION_CIRCLE=11 + CANCEL = 8, + MACHINE_COMPLEX = 9, + LINK = 10, + NAVIGATION_CIRCLE = 11 }; -class UICanvasState{ - public: +class UICanvasState { + public: QPoint _center; size_t _zoom; UICanvasState() { - _center = QPoint(0,0); - _zoom = 100; + _center = QPoint(0, 0); + _zoom = 100; } - UICanvasState &operator= (const UICanvasState &other){ + UICanvasState& operator=(const UICanvasState& other) { _center = other._center; _zoom = other._zoom; return *this; } }; -class UICanvas -{ -protected: +class UICanvas { + protected: QBrush _brush_background; - QPen _pen_net; - QPen _pen_foreground; - QPen _pen_selected; - QPen _pen_error; + QPen _pen_net; + QPen _pen_foreground; + QPen _pen_selected; + QPen _pen_error; UICanvasState _state; - QPainter *_painter; - QFont _font; + QPainter* _painter; + QFont _font; QBrush _fill_normal; QBrush _fill_selected; - double GetFactor(); - void PaintBackground(const QRect &rect,const QRect &bounds); + void PaintBackground(const QRect& rect, const QRect& bounds); QPen _animation_pen[10]; int _animation; @@ -73,56 +69,65 @@ class UICanvas void reloadMachineIcons(); -public: + public: size_t GetStep(); void SetFontSize(size_t font_size); void SetCellSize(QSize size); - UICanvas(QBrush background,QPen net,QPen foreground,QSize size,size_t font_size); + UICanvas(QBrush background, QPen net, QPen foreground, QSize size, + size_t font_size); /** Sync pens/brushes and machine icons from current VmtTheme. */ void applyThemeColors(); const UICanvasState& GetState(); void SetState(const UICanvasState& other); - QPainter *GetPainter(); - void Animate(); - QPoint &GetCenter(); - void SnapToGris(QPoint &point); - void SetPainter(QPainter *painter); + QPainter* GetPainter(); + void Animate(); + QPoint& GetCenter(); + void SnapToGris(QPoint& point); + void SetPainter(QPainter* painter); QPixmap* GetImage(ImageType type); - size_t GetZoom() const; - void SetZoom(size_t zoom); - QPoint FromScreen(QPoint &shift); - QPoint FromScreen(QPoint &&shift); - QRect FromScreen(const QRect& rect); + size_t GetZoom() const; + void SetZoom(size_t zoom); + QPoint FromScreen(QPoint& shift); + QPoint FromScreen(QPoint&& shift); + QRect FromScreen(const QRect& rect); QPoint ToScreen(QPoint point); - QRect ToScreen(const QRect& rect); - void SetInScreen(QPoint &&); - void MoveInScreen(QPoint &shift); - void MoveInScreen(QPoint &&shift); - void Move(QPoint &shift); - void Move(QPoint &&shift); - void SetCenter(QPoint point,QSize screen_size); - void Paint(QPainter &painter, const QRect &rect,const QRect &bounds); - - void CalculateTextSize(const QString& text,QRect &rect); - void FillRect(const QRect &rect, bool selected=false); - void DrawButton(const QRect &rect); - void DrawImageScreen(ImageType image_type, const QRect &rect); - void DrawImage(ImageType image_type, const QRect &rect); - - void DrawLine(const QPoint &start,const QPoint &end, bool selected=false,bool error=false); - void DrawArrow(const QPoint &start,const QPoint &end, bool selected=false,bool error=false); - void DrawLineAnimation(const QPoint &start,const QPoint &end, bool selected=false); - void DrawConnectorPath(const QPainterPath& diagramPath, bool selected=false, bool error=false, bool animated=false); - void DrawArrowForPath(const QPainterPath& diagramPath, bool selected=false, bool error=false); - void DrawRect(const QRect & rect,bool selected=false,bool error=false); - void DrawRectScreen(const QRect & rect); - void DrawRectAnimation(const QRect & rect,bool selected=false); - //void DrawText(const QString& text,const QRect &bounds,bool selected=false); - void DrawText(const QString& text,const QPoint center,size_t size,bool selected = false); + QRect ToScreen(const QRect& rect); + void SetInScreen(QPoint&&); + void MoveInScreen(QPoint& shift); + void MoveInScreen(QPoint&& shift); + void Move(QPoint& shift); + void Move(QPoint&& shift); + void SetCenter(QPoint point, QSize screen_size); + void Paint(QPainter& painter, const QRect& rect, const QRect& bounds); + + void CalculateTextSize(const QString& text, QRect& rect); + void FillRect(const QRect& rect, bool selected = false); + void DrawButton(const QRect& rect); + void DrawImageScreen(ImageType image_type, const QRect& rect); + void DrawImage(ImageType image_type, const QRect& rect); + + void DrawLine(const QPoint& start, const QPoint& end, bool selected = false, + bool error = false); + void DrawArrow(const QPoint& start, const QPoint& end, + bool selected = false, bool error = false); + void DrawLineAnimation(const QPoint& start, const QPoint& end, + bool selected = false); + void DrawConnectorPath(const QPainterPath& diagramPath, + bool selected = false, bool error = false, + bool animated = false); + void DrawArrowForPath(const QPainterPath& diagramPath, + bool selected = false, bool error = false); + void DrawRect(const QRect& rect, bool selected = false, bool error = false); + void DrawRectScreen(const QRect& rect); + void DrawRectAnimation(const QRect& rect, bool selected = false); + // void DrawText(const QString& text,const QRect &bounds,bool + // selected=false); + void DrawText(const QString& text, const QPoint center, size_t size, + bool selected = false); }; -#endif // UICANVAS_H +#endif // UICANVAS_H diff --git a/VirtualTuringMachine/uistate.h b/VirtualTuringMachine/uistate.h old mode 100755 new mode 100644 index 863731f..06ecda3 --- a/VirtualTuringMachine/uistate.h +++ b/VirtualTuringMachine/uistate.h @@ -1,24 +1,21 @@ #ifndef UISTATE_H #define UISTATE_H -#include #include +#include #include class StateController; class UIStateData; -class UIState -{ -protected: - StateController *parent; - UIState(StateController* p) : parent(p) { - } - -public: +class UIState { + protected: + StateController* parent; + UIState(StateController* p) : parent(p) {} + public: virtual void BeforeChange(std::shared_ptr state_data) = 0; virtual void AfterUndo(std::shared_ptr state_data) = 0; - virtual void OnLoaded(std::shared_ptr) {}; + virtual void OnLoaded(std::shared_ptr){}; virtual void Action(const QString& name) = 0; virtual void OnZoomChanged(int) {} virtual void OnKeyPressed([[maybe_unused]] QKeyEvent* event) {}; @@ -27,15 +24,17 @@ class UIState virtual ~UIState() = default; }; -class UIStateData{ -public: +class UIStateData { + public: virtual ~UIStateData() = default; - virtual bool IsUndoPlacable() { return true;} - virtual bool IsNeedWarning() { return false;} - virtual std::shared_ptr ConstructNewState(StateController * controller) = 0; - virtual std::shared_ptr ConstructUndoState(StateController * controller) = 0; + virtual bool IsUndoPlacable() { return true; } + virtual bool IsNeedWarning() { return false; } + virtual std::shared_ptr ConstructNewState( + StateController* controller) = 0; + virtual std::shared_ptr ConstructUndoState( + StateController* controller) = 0; virtual QString GetName() = 0; - virtual void SetName(QString) {}; + virtual void SetName(QString){}; }; -#endif // UISTATE_H +#endif // UISTATE_H diff --git a/VirtualTuringMachine/uistatecompilermachine.h b/VirtualTuringMachine/uistatecompilermachine.h old mode 100755 new mode 100644 index ba6f495..14d5475 --- a/VirtualTuringMachine/uistatecompilermachine.h +++ b/VirtualTuringMachine/uistatecompilermachine.h @@ -1,17 +1,16 @@ #ifndef UISTATECOMPILERMACHINE_H #define UISTATECOMPILERMACHINE_H -#include "uistatestub.h" #include "formcompilermachine.h" #include "uistatedebugermachine.h" +#include "uistatestub.h" class UIStateCompilerMachineData; -class UIStateCompilerMachine : public UIStateStub -{ -protected: - UIStateCompilerMachine(StateController* parent): UIStateStub(parent) - { +class UIStateCompilerMachine : public UIStateStub { + protected: + UIStateCompilerMachine(StateController* parent) + : UIStateStub(parent) { qDebug() << "UIStateCompilerMachine::ctr"; parent->EnableExercise(false); parent->EnableNewMachine(false); @@ -37,44 +36,39 @@ class UIStateCompilerMachine : public UIStateStub form.ChangeZoom(parent->GetZoom()); qDebug() << "UIStateCompilerMachine::ctr done"; - - } - - void OnLoaded(std::shared_ptr ) override{ - if(!form.HasErrors()) - parent->ChangeState(std::shared_ptr(new UIStateDebugerMachineData())); - } - void OnZoomChanged(int zoom) override { - form.ChangeZoom(zoom); + void OnLoaded(std::shared_ptr) override { + if (!form.HasErrors()) + parent->ChangeState(std::shared_ptr( + new UIStateDebugerMachineData())); } + void OnZoomChanged(int zoom) override { form.ChangeZoom(zoom); } - void Action(const QString& name) override{ - if(name == QString("button_run")) - parent->ChangeState(std::shared_ptr(new UIStateDebugerMachineData())); - - + void Action(const QString& name) override { + if (name == QString("button_run")) + parent->ChangeState(std::shared_ptr( + new UIStateDebugerMachineData())); } friend UIStateCompilerMachineData; }; -class UIStateCompilerMachineData : public UIStateData{ -public: - bool IsUndoPlacable() override { - return false; - } - std::shared_ptr ConstructNewState(StateController * controller) override{ +class UIStateCompilerMachineData : public UIStateData { + public: + bool IsUndoPlacable() override { return false; } + std::shared_ptr ConstructNewState( + StateController* controller) override { qDebug() << "UIStateCompilerMachineData::ConstructNewState"; - return std::shared_ptr(new UIStateCompilerMachine(controller)); - } - std::shared_ptr ConstructUndoState(StateController * controller) override{ - return std::shared_ptr(new UIStateCompilerMachine(controller)); + return std::shared_ptr( + new UIStateCompilerMachine(controller)); } - QString GetName() override{ - return QString("Compiler"); + std::shared_ptr ConstructUndoState( + StateController* controller) override { + return std::shared_ptr( + new UIStateCompilerMachine(controller)); } + QString GetName() override { return QString("Compiler"); } }; -#endif // UISTATECOMPILERMACHINE_H +#endif // UISTATECOMPILERMACHINE_H diff --git a/VirtualTuringMachine/uistatedebugermachine.h b/VirtualTuringMachine/uistatedebugermachine.h old mode 100755 new mode 100644 index 018cd67..3c552f4 --- a/VirtualTuringMachine/uistatedebugermachine.h +++ b/VirtualTuringMachine/uistatedebugermachine.h @@ -1,16 +1,14 @@ #ifndef UISTATEDEBUGERMACHINE_H #define UISTATEDEBUGERMACHINE_H -#include "uistatestub.h" #include "formdebugermachine.h" +#include "uistatestub.h" class UIStateDebugerMachineData; -class UIStateDebugerMachine : public UIStateStub -{ -protected: - UIStateDebugerMachine(StateController* parent): UIStateStub(parent) - { - +class UIStateDebugerMachine : public UIStateStub { + protected: + UIStateDebugerMachine(StateController* parent) + : UIStateStub(parent) { parent->EnableNewMachine(false); parent->EnableOpenMachine(false); parent->EnableSave(false); @@ -23,7 +21,7 @@ class UIStateDebugerMachine : public UIStateStub parent->EnableDebugBack(false); parent->EnableDebugOver(false); parent->EnableDebugPause(false); - if(VMTProject::GetInstance().IsTestMode()){ + if (VMTProject::GetInstance().IsTestMode()) { parent->EnableExercise(true); parent->EnableDebugRun(false); parent->EnableDebugStep(false); @@ -41,35 +39,30 @@ class UIStateDebugerMachine : public UIStateStub form.ChangeZoom(parent->GetZoom()); } - void OnZoomChanged(int zoom) override { - form.ChangeZoom(zoom); - } - + void OnZoomChanged(int zoom) override { form.ChangeZoom(zoom); } - void Action(const QString& name) override{ - if(name == QString("button_debug_step")) - form.Step(); - if(name == QString("button_debug_run")) - form.Run(); - if(name == QString("button_debug_stop")) - form.Stop(); - if(name == QString("button_exercise")) - form.StartExercise(); + void Action(const QString& name) override { + if (name == QString("button_debug_step")) form.Step(); + if (name == QString("button_debug_run")) form.Run(); + if (name == QString("button_debug_stop")) form.Stop(); + if (name == QString("button_exercise")) form.StartExercise(); } friend UIStateDebugerMachineData; }; -class UIStateDebugerMachineData : public UIStateData{ -public: - std::shared_ptr ConstructNewState(StateController * controller) override{ - return std::shared_ptr(new UIStateDebugerMachine(controller)); - } - std::shared_ptr ConstructUndoState(StateController * controller) override{ - return std::shared_ptr(new UIStateDebugerMachine(controller)); +class UIStateDebugerMachineData : public UIStateData { + public: + std::shared_ptr ConstructNewState( + StateController* controller) override { + return std::shared_ptr( + new UIStateDebugerMachine(controller)); } - QString GetName() override{ - return QString("Debuger"); + std::shared_ptr ConstructUndoState( + StateController* controller) override { + return std::shared_ptr( + new UIStateDebugerMachine(controller)); } + QString GetName() override { return QString("Debuger"); } }; -#endif // UISTATEDEBUGERMACHINE_H +#endif // UISTATEDEBUGERMACHINE_H diff --git a/VirtualTuringMachine/uistateeditormachine.h b/VirtualTuringMachine/uistateeditormachine.h old mode 100755 new mode 100644 index bcd621e..b505c26 --- a/VirtualTuringMachine/uistateeditormachine.h +++ b/VirtualTuringMachine/uistateeditormachine.h @@ -1,23 +1,25 @@ #ifndef UISTATEEDITORMACHINE_H #define UISTATEEDITORMACHINE_H -#include "uistatestub.h" -#include "formmain.h" #include "formeditormachine.h" +#include "formmain.h" +#include "interfaces/ivmtundoobserver.h" #include "uistatecompilermachine.h" #include "uistateexport4th.h" +#include "uistatestub.h" #include "vmtproject.h" -#include "interfaces/ivmtundoobserver.h" class UIStateEditorMachineData; -class UIStateEditorMachine : public UIStateStub , public IVMTUndoObserver -{ -protected: - UIStateEditorMachine(StateController* parent): UIStateStub(parent) - { +class UIStateEditorMachine : public UIStateStub, + public IVMTUndoObserver { + protected: + UIStateEditorMachine(StateController* parent) + : UIStateStub(parent) { VMTProject::GetInstance().SetTestMode(false); - if(VMTProject::GetInstance().GetExercise()) parent->EnableExercise(true); - else parent->EnableExercise(false); + if (VMTProject::GetInstance().GetExercise()) + parent->EnableExercise(true); + else + parent->EnableExercise(false); parent->EnableNewMachine(false); parent->EnableOpenMachine(false); @@ -28,8 +30,10 @@ class UIStateEditorMachine : public UIStateStub , public IVMT parent->EnableConfigure(false); parent->Enable4thExport(true); - if(VMTProject::GetInstance().GetUndoManager()->IsEnable()) parent->EnableDebugBack(true); - else parent->EnableDebugBack(false); + if (VMTProject::GetInstance().GetUndoManager()->IsEnable()) + parent->EnableDebugBack(true); + else + parent->EnableDebugBack(false); VMTProject::GetInstance().GetUndoManager()->SetObserver(this); parent->EnableDebugOver(false); parent->EnableDebugPause(false); @@ -44,71 +48,57 @@ class UIStateEditorMachine : public UIStateStub , public IVMT form.ChangeZoom(parent->GetZoom()); } - void OnKeyPressed(QKeyEvent* event) override{ - form.OnKeyPressed(event); - } + void OnKeyPressed(QKeyEvent* event) override { form.OnKeyPressed(event); } - void OnKeyReleased(QKeyEvent* event) override{ - form.OnKeyReleased(event); - } - void EnableUndoButton(bool enable) override{ + void OnKeyReleased(QKeyEvent* event) override { form.OnKeyReleased(event); } + void EnableUndoButton(bool enable) override { parent->EnableDebugBack(enable); } - void OnZoomChanged(int zoom) override { - form.ChangeZoom(zoom); - } + void OnZoomChanged(int zoom) override { form.ChangeZoom(zoom); } - void Action(const QString& name) override{ - if(name == QString("button_run")) - { - form.Run(); - } else - if(name == QString("button_exercise")) - { - form.Exercise(); - } else - if(name == QString("button_export")) - { - form.ExportMachine(); - } else - if(name == QString("button_export_plantuml")) - { - form.ExportPlantUml(); - } else - if(name == QString("button_back")) - { - form.Undo(); - }else - if(name == QString("button_4th")) - { - this->parent->ChangeState( - std::shared_ptr(new UIStateExport4thData())); - } + void Action(const QString& name) override { + if (name == QString("button_run")) { + form.Run(); + } else if (name == QString("button_exercise")) { + form.Exercise(); + } else if (name == QString("button_export")) { + form.ExportMachine(); + } else if (name == QString("button_export_plantuml")) { + form.ExportPlantUml(); + } else if (name == QString("button_back")) { + form.Undo(); + } else if (name == QString("button_4th")) { + this->parent->ChangeState(std::shared_ptr( + new UIStateExport4thData())); + } } friend UIStateEditorMachineData; }; -#include "vmtmachines/VMTComplexMachine.h" #include -class UIStateEditorMachineData : public UIStateData{ -public: - //std::shared_ptr _machine; +#include "vmtmachines/VMTComplexMachine.h" - bool IsNeedWarning() override { - return false; - } +class UIStateEditorMachineData : public UIStateData { + public: + // std::shared_ptr _machine; + + bool IsNeedWarning() override { return false; } - std::shared_ptr ConstructNewState(StateController * controller) override{ - return std::shared_ptr(new UIStateEditorMachine(controller)); + std::shared_ptr ConstructNewState( + StateController* controller) override { + return std::shared_ptr( + new UIStateEditorMachine(controller)); } - std::shared_ptr ConstructUndoState(StateController * controller) override{ - return std::shared_ptr(new UIStateEditorMachine(controller)); + std::shared_ptr ConstructUndoState( + StateController* controller) override { + return std::shared_ptr( + new UIStateEditorMachine(controller)); } - QString GetName() override{ + QString GetName() override { return VMTProject::GetInstance().GetCurrentMachineName(); } }; -#endif // UISTATEEDITORMACHINE_H +#endif // UISTATEEDITORMACHINE_H diff --git a/VirtualTuringMachine/uistateexercises.h b/VirtualTuringMachine/uistateexercises.h old mode 100755 new mode 100644 index 99c8a94..56dd980 --- a/VirtualTuringMachine/uistateexercises.h +++ b/VirtualTuringMachine/uistateexercises.h @@ -1,22 +1,20 @@ #ifndef UISTATEEXERCISES_H #define UISTATEEXERCISES_H -#include "uistatestub.h" +#include +#include + +#include "configuration.h" #include "formexercises.h" #include "uistateeditormachine.h" -#include "configuration.h" -#include -#include +#include "uistatestub.h" class StateController; class UIStateExercisesData; -class UIStateExercises : public UIStateStub -{ -public: - - - UIStateExercises(StateController* parent): UIStateStub(parent) - { +class UIStateExercises : public UIStateStub { + public: + UIStateExercises(StateController* parent) + : UIStateStub(parent) { parent->EnableExercise(false); parent->EnableNewMachine(false); parent->EnableOpenMachine(false); @@ -40,35 +38,28 @@ class UIStateExercises : public UIStateStub parent->EnableZoom(false); } - void Action([[maybe_unused]] const QString& name) override{ - - } + void Action([[maybe_unused]] const QString& name) override {} friend UIStateExercisesData; }; -class UIStateExercisesData : public UIStateData{ - -public: - std::shared_ptr ConstructNewState(StateController * controller) override{ +class UIStateExercisesData : public UIStateData { + public: + std::shared_ptr ConstructNewState( + StateController* controller) override { return std::make_shared(controller); } - std::shared_ptr ConstructUndoState(StateController * controller) override{ + std::shared_ptr ConstructUndoState( + StateController* controller) override { return std::make_shared(controller); } - bool IsNeedWarning() override { - return false; - } + bool IsNeedWarning() override { return false; } - QString GetName() override{ - return name; - } + QString GetName() override { return name; } - void SetName(QString name) override{ - this->name = name; - } + void SetName(QString name) override { this->name = name; } - QString name="Exercises"; + QString name = "Exercises"; }; -#endif // UISTATEEXERCISES_H +#endif // UISTATEEXERCISES_H diff --git a/VirtualTuringMachine/uistateexport4th.h b/VirtualTuringMachine/uistateexport4th.h old mode 100755 new mode 100644 index a2d47e9..0da80ea --- a/VirtualTuringMachine/uistateexport4th.h +++ b/VirtualTuringMachine/uistateexport4th.h @@ -1,19 +1,16 @@ #ifndef UISTATEEXPORT4TH_H #define UISTATEEXPORT4TH_H -#include "uistatestub.h" #include "formexport4th.h" +#include "uistatestub.h" class StateController; class UIStateExport4thData; -class UIStateExport4th : public UIStateStub -{ -protected: - - - UIStateExport4th(StateController* parent): UIStateStub(parent) - { +class UIStateExport4th : public UIStateStub { + protected: + UIStateExport4th(StateController* parent) + : UIStateStub(parent) { parent->EnableExercise(false); parent->EnableNewMachine(false); parent->EnableOpenMachine(false); @@ -37,28 +34,26 @@ class UIStateExport4th : public UIStateStub parent->EnableZoom(false); } - void Action(const QString& name) override{ - if(name == QString("button_ok")){ - - } - + void Action(const QString& name) override { + if (name == QString("button_ok")) { + } } friend UIStateExport4thData; }; -class UIStateExport4thData : public UIStateData{ - -public: - std::shared_ptr ConstructNewState(StateController * controller) override{ - return std::shared_ptr(new UIStateExport4th(controller)); +class UIStateExport4thData : public UIStateData { + public: + std::shared_ptr ConstructNewState( + StateController* controller) override { + return std::shared_ptr( + new UIStateExport4th(controller)); } - std::shared_ptr ConstructUndoState(StateController * controller) override{ - return std::shared_ptr(new UIStateExport4th(controller)); + std::shared_ptr ConstructUndoState( + StateController* controller) override { + return std::shared_ptr( + new UIStateExport4th(controller)); } - QString GetName() override{ - return "Export 4th"; - } - + QString GetName() override { return "Export 4th"; } }; -#endif // UISTATEEXPORT4TH_H +#endif // UISTATEEXPORT4TH_H diff --git a/VirtualTuringMachine/uistatemain.h b/VirtualTuringMachine/uistatemain.h old mode 100755 new mode 100644 index 1f4d626..f5169b3 --- a/VirtualTuringMachine/uistatemain.h +++ b/VirtualTuringMachine/uistatemain.h @@ -1,14 +1,12 @@ #ifndef UISTATEMAIN_H #define UISTATEMAIN_H -#include "uistatestub.h" #include "formmain.h" +#include "uistatestub.h" class UIStateMainData; -class UIStateMain : public UIStateStub -{ -protected: - UIStateMain(StateController* parent): UIStateStub(parent) - { +class UIStateMain : public UIStateStub { + protected: + UIStateMain(StateController* parent) : UIStateStub(parent) { parent->EnableExercise(false); parent->EnableNewMachine(false); parent->EnableOpenMachine(false); @@ -32,23 +30,21 @@ class UIStateMain : public UIStateStub parent->EnableZoom(false); } - void Action(const QString& ) override{ + void Action(const QString&) override {} - } - -friend UIStateMainData; + friend UIStateMainData; }; -class UIStateMainData : public UIStateData{ -public: - std::shared_ptr ConstructNewState(StateController * controller) override{ +class UIStateMainData : public UIStateData { + public: + std::shared_ptr ConstructNewState( + StateController* controller) override { return std::shared_ptr(new UIStateMain(controller)); } - std::shared_ptr ConstructUndoState(StateController * controller) override{ + std::shared_ptr ConstructUndoState( + StateController* controller) override { return std::shared_ptr(new UIStateMain(controller)); } - QString GetName() override{ - return QString("VTM"); - } + QString GetName() override { return QString("VTM"); } }; -#endif // UISTATEMAIN_H +#endif // UISTATEMAIN_H diff --git a/VirtualTuringMachine/uistatenewmachine.h b/VirtualTuringMachine/uistatenewmachine.h old mode 100755 new mode 100644 index 437d136..2759f06 --- a/VirtualTuringMachine/uistatenewmachine.h +++ b/VirtualTuringMachine/uistatenewmachine.h @@ -1,19 +1,16 @@ #ifndef UISTATENEWMACHINE_H #define UISTATENEWMACHINE_H -#include "uistatestub.h" #include "formnewmachine.h" +#include "uistatestub.h" class StateController; class UIStateNewMachineData; -class UIStateNewMachine : public UIStateStub -{ -protected: - - - UIStateNewMachine(StateController* parent): UIStateStub(parent) - { +class UIStateNewMachine : public UIStateStub { + protected: + UIStateNewMachine(StateController* parent) + : UIStateStub(parent) { parent->EnableExercise(false); parent->EnableNewMachine(false); parent->EnableOpenMachine(false); @@ -37,29 +34,27 @@ class UIStateNewMachine : public UIStateStub parent->EnableZoom(false); } - void Action(const QString& name) override{ - if(name == QString("button_ok")){ - - } - + void Action(const QString& name) override { + if (name == QString("button_ok")) { + } } friend UIStateNewMachineData; }; -class UIStateNewMachineData : public UIStateData{ - -public: - std::shared_ptr ConstructNewState(StateController * controller) override{ - return std::shared_ptr(new UIStateNewMachine(controller)); +class UIStateNewMachineData : public UIStateData { + public: + std::shared_ptr ConstructNewState( + StateController* controller) override { + return std::shared_ptr( + new UIStateNewMachine(controller)); } - std::shared_ptr ConstructUndoState(StateController * controller) override{ - return std::shared_ptr(new UIStateNewMachine(controller)); + std::shared_ptr ConstructUndoState( + StateController* controller) override { + return std::shared_ptr( + new UIStateNewMachine(controller)); } - QString GetName() override{ - return "Machines"; - } - + QString GetName() override { return "Machines"; } }; -#endif // UISTATENEWMACHINE_H +#endif // UISTATENEWMACHINE_H diff --git a/VirtualTuringMachine/uistatenewproject.h b/VirtualTuringMachine/uistatenewproject.h old mode 100755 new mode 100644 index e8aa85f..34fa997 --- a/VirtualTuringMachine/uistatenewproject.h +++ b/VirtualTuringMachine/uistatenewproject.h @@ -1,20 +1,18 @@ #ifndef UISTATENEWPROJECT_H #define UISTATENEWPROJECT_H -#include "uistatestub.h" +#include + +#include "configuration.h" #include "formnewproject.h" #include "uistateeditormachine.h" -#include "configuration.h" -#include +#include "uistatestub.h" class StateController; class UIStateNewProjectData; -class UIStateNewProject : public UIStateStub -{ -protected: - - - UIStateNewProject(StateController* parent): UIStateStub(parent) - { +class UIStateNewProject : public UIStateStub { + protected: + UIStateNewProject(StateController* parent) + : UIStateStub(parent) { parent->EnableExercise(false); parent->EnableNewMachine(false); parent->EnableOpenMachine(false); @@ -38,58 +36,53 @@ class UIStateNewProject : public UIStateStub parent->EnableZoom(false); } - void Action(const QString& name) override{ - parent->Update(); - if(name == QString("button_save")){ - QString name; - GetProjectFileName(name); - VMTSerializer serializer(name); - serializer.Serialize(&VMTProject::GetInstance()); - - Configuration::GetInstance().AddRecentProject(name); - Configuration::GetInstance().Save(); - QMessageBox box; - box.setText("Project saved"); - box.exec(); - - } - + void Action(const QString& name) override { + parent->Update(); + if (name == QString("button_save")) { + QString name; + GetProjectFileName(name); + VMTSerializer serializer(name); + serializer.Serialize(&VMTProject::GetInstance()); + + Configuration::GetInstance().AddRecentProject(name); + Configuration::GetInstance().Save(); + QMessageBox box; + box.setText("Project saved"); + box.exec(); + } } friend UIStateNewProjectData; -public: - static void GetProjectFileName(QString &name){ + public: + static void GetProjectFileName(QString& name) { name = VMTProject::GetInstance().GetLocation(); name += "/"; name += VMTProject::GetInstance().GetName(); - if(!name.endsWith(".jdtp", Qt::CaseInsensitive)) name += ".jdtp"; + if (!name.endsWith(".jdtp", Qt::CaseInsensitive)) name += ".jdtp"; } }; -class UIStateNewProjectData : public UIStateData{ - -public: - std::shared_ptr ConstructNewState(StateController * controller) override{ - return std::shared_ptr(new UIStateNewProject(controller)); +class UIStateNewProjectData : public UIStateData { + public: + std::shared_ptr ConstructNewState( + StateController* controller) override { + return std::shared_ptr( + new UIStateNewProject(controller)); } - std::shared_ptr ConstructUndoState(StateController * controller) override{ - return std::shared_ptr(new UIStateNewProject(controller)); + std::shared_ptr ConstructUndoState( + StateController* controller) override { + return std::shared_ptr( + new UIStateNewProject(controller)); } - bool IsNeedWarning() override { - return true; - } + bool IsNeedWarning() override { return true; } - QString GetName() override{ - return name; - } + QString GetName() override { return name; } - void SetName(QString name) override{ - this->name = name; - } + void SetName(QString name) override { this->name = name; } - QString name="New machine"; + QString name = "New machine"; }; -#endif // UISTATENEWPROJECT_H +#endif // UISTATENEWPROJECT_H diff --git a/VirtualTuringMachine/uistatestub.h b/VirtualTuringMachine/uistatestub.h old mode 100755 new mode 100644 index 92ec25d..932eb73 --- a/VirtualTuringMachine/uistatestub.h +++ b/VirtualTuringMachine/uistatestub.h @@ -1,20 +1,24 @@ #ifndef UISTATESTUB_H #define UISTATESTUB_H -#include "uistate.h" +#include +#include + #include "mainwindow.h" #include "statecontroller.h" -#include -#include +#include "uistate.h" + +template +class UIStateStub : public UIState { + protected: + T form; -template class UIStateStub : public UIState{ -protected: - T form; -public: - UIStateStub(StateController* parent) : UIState(parent),form(parent->GetContainer()){ + public: + UIStateStub(StateController* parent) + : UIState(parent), form(parent->GetContainer()) { qDebug() << "UIStateStub::ctr"; parent->GetContainer()->layout()->addWidget(&form); - parent->GetContainer()->layout()->setContentsMargins(0,0,0,0); + parent->GetContainer()->layout()->setContentsMargins(0, 0, 0, 0); qDebug() << "UIStateStub::SetController"; form.SetController(parent); qDebug() << "UIStateStub::OnLoaded"; @@ -22,12 +26,12 @@ template class UIStateStub : public UIState{ qDebug() << "UIStateStub::ctr done"; } - void BeforeChange(std::shared_ptr state_data) override{ - form.BeforeChange(state_data); + void BeforeChange(std::shared_ptr state_data) override { + form.BeforeChange(state_data); } void AfterUndo(std::shared_ptr state_data) override { - form.AfterUndo(state_data); + form.AfterUndo(state_data); } void RemoveState() override { @@ -40,4 +44,4 @@ template class UIStateStub : public UIState{ ~UIStateStub() override = default; }; -#endif // UISTATESTUB_H +#endif // UISTATESTUB_H diff --git a/VirtualTuringMachine/virtualturingmachine_plugin_import.cpp b/VirtualTuringMachine/virtualturingmachine_plugin_import.cpp old mode 100755 new mode 100644 index 6b23c46..b2b8e60 --- a/VirtualTuringMachine/virtualturingmachine_plugin_import.cpp +++ b/VirtualTuringMachine/virtualturingmachine_plugin_import.cpp @@ -1,7 +1,6 @@ // // This file is autogenerated by qmake. It imports static plugin classes for -// // static plugins specified using QTPLUGIN and QT_PLUGIN_CLASS. variables. -// #include -// Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin) +// // static plugins specified using QTPLUGIN and QT_PLUGIN_CLASS. +// variables. #include Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin) // Q_IMPORT_PLUGIN(QGifPlugin) // Q_IMPORT_PLUGIN(QICNSPlugin) // Q_IMPORT_PLUGIN(QICOPlugin) diff --git a/VirtualTuringMachine/vmtactions/vmtactioncreateandconnect.cpp b/VirtualTuringMachine/vmtactions/vmtactioncreateandconnect.cpp old mode 100755 new mode 100644 index 01a761c..a1ee0db --- a/VirtualTuringMachine/vmtactions/vmtactioncreateandconnect.cpp +++ b/VirtualTuringMachine/vmtactions/vmtactioncreateandconnect.cpp @@ -1,95 +1,103 @@ #include "vmtactioncreateandconnect.h" -#include "VMTTransitionImpl.h" - -VMTActionCreateAndConnect::VMTActionCreateAndConnect(IVMTActionController *controller, - std::shared_ptr machine_start, - std::shared_ptr machine) : - _controller(controller),_machine_start(machine_start),_machine(machine) -{ -} +#include "VMTTransitionImpl.h" -void VMTActionCreateAndConnect::Cancel(IVMTEnvironment *environment){ - // environment->EnableAnimation(false); - if(_machine->IsAlphabit()) +VMTActionCreateAndConnect::VMTActionCreateAndConnect( + IVMTActionController* controller, + std::shared_ptr machine_start, + std::shared_ptr machine) + : _controller(controller), + _machine_start(machine_start), + _machine(machine) {} + +void VMTActionCreateAndConnect::Cancel(IVMTEnvironment* environment) { + // environment->EnableAnimation(false); + if (_machine->IsAlphabit()) environment->DisableAlphabit(); - else environment->DisableActionHint(); + else + environment->DisableActionHint(); - if(_transition) { + if (_transition) { _transition->RemoveChilds(); } - - if(_machine_start) _machine_start->SetSelected(false); - if(_machine) _machine->SetSelected(false); - + if (_machine_start) _machine_start->SetSelected(false); + if (_machine) _machine->SetSelected(false); environment->Repaint(QRect()); - } -void VMTActionCreateAndConnect::Enable(IVMTEnvironment *environment){ - if(!environment) return; +void VMTActionCreateAndConnect::Enable(IVMTEnvironment* environment) { + if (!environment) return; - _transition = std::shared_ptr(new VMTTransitionImpl(environment->GetMachine())); + _transition = std::shared_ptr( + new VMTTransitionImpl(environment->GetMachine())); - _transition->SetStart(environment,_machine_start); - _transition->SetFinish(environment,_machine); - _machine_start->AddOutgoingTransition(std::weak_ptr(_transition)); + _transition->SetStart(environment, _machine_start); + _transition->SetFinish(environment, _machine); + _machine_start->AddOutgoingTransition( + std::weak_ptr(_transition)); _machine->AddIncomingTransition(std::weak_ptr(_transition)); - _machine->Move(_machine_start->GetCenter(),environment); + _machine->Move(_machine_start->GetCenter(), environment); _machine->Update(environment); - // _machine->Update(environment) + // _machine->Update(environment) - if(_machine->IsAlphabit()) - environment->EnableAlphabit(_machine->GetAlphabitSource(),"Select sign for \"Write\" machine",*environment->GetGraphics().GetImage(_machine->GetImageType())); + if (_machine->IsAlphabit()) + environment->EnableAlphabit( + _machine->GetAlphabitSource(), "Select sign for \"Write\" machine", + *environment->GetGraphics().GetImage(_machine->GetImageType())); else { QString str = "Click on the editor field to add \""; str.append(_machine->GetName()); str.append("\" machine to diagram."); - environment->EnableActionHint(str,*environment->GetGraphics().GetImage(_machine->GetImageType())); + environment->EnableActionHint(str, *environment->GetGraphics().GetImage( + _machine->GetImageType())); } - // environment->EnableAnimation(true); + // environment->EnableAnimation(true); } -bool VMTActionCreateAndConnect::OnMouseMoved(IVMTEnvironment* environment,[[maybe_unused]] const QPoint &screen,const QPoint &real){ - if(!environment) return false; +bool VMTActionCreateAndConnect::OnMouseMoved( + IVMTEnvironment* environment, [[maybe_unused]] const QPoint& screen, + const QPoint& real) { + if (!environment) return false; QRect old_bounds = _transition->GetBounds(); old_bounds = old_bounds.united(_machine->GetBounds()); old_bounds = old_bounds.united(_machine_start->GetBounds()); - _machine->Move(real,environment); + _machine->Move(real, environment); _machine->Update(environment); old_bounds = old_bounds.united(_machine->GetBounds()); old_bounds = old_bounds.united(_machine_start->GetBounds()); old_bounds = old_bounds.united(_transition->GetBounds()); - old_bounds.setWidth(old_bounds.width()+32); - old_bounds.setHeight(old_bounds.height()+32); - old_bounds.moveLeft(old_bounds.left()-16); - old_bounds.moveTop(old_bounds.top()-16); + old_bounds.setWidth(old_bounds.width() + 32); + old_bounds.setHeight(old_bounds.height() + 32); + old_bounds.moveLeft(old_bounds.left() - 16); + old_bounds.moveTop(old_bounds.top() - 16); environment->Repaint(old_bounds); return true; } +#include "vmtactionpointer.h" +#include "vmtmachines/VMTComplexMachine.h" #include "vmtproject.h" #include "vmtundoelementmachine.h" -#include "vmtmachines/VMTComplexMachine.h" -#include "vmtactionpointer.h" -bool VMTActionCreateAndConnect::OnMousePressed(IVMTEnvironment* environment,[[maybe_unused]] const QPoint &screen,const QPoint &real){ - - if(auto complex_machine = environment->GetMachine().lock()){ +bool VMTActionCreateAndConnect::OnMousePressed( + IVMTEnvironment* environment, [[maybe_unused]] const QPoint& screen, + const QPoint& real) { + if (auto complex_machine = environment->GetMachine().lock()) { VMTProject::GetInstance().GetUndoManager()->Remember( - std::shared_ptr(new VMTUndoElementMachine())); + std::shared_ptr( + new VMTUndoElementMachine())); QPoint center = real; environment->GetGraphics().SnapToGris(center); - _machine->Move(center,environment); + _machine->Move(center, environment); complex_machine->AddMachine(_machine); complex_machine->AddTransition(_transition); @@ -97,20 +105,20 @@ bool VMTActionCreateAndConnect::OnMousePressed(IVMTEnvironment* environment,[[ma environment->Repaint(QRect()); _transition = nullptr; - _controller->SetAction(std::shared_ptr(new VMTActionPointer(_controller,_machine,true))); - + _controller->SetAction(std::shared_ptr( + new VMTActionPointer(_controller, _machine, true))); } return true; } -bool VMTActionCreateAndConnect::OnMouseReleased([[maybe_unused]] IVMTEnvironment* environment,[[maybe_unused]] const QPoint &screen,[[maybe_unused]] const QPoint &real){ - +bool VMTActionCreateAndConnect::OnMouseReleased( + [[maybe_unused]] IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& screen, + [[maybe_unused]] const QPoint& real) { return true; } -void VMTActionCreateAndConnect::Paint(UICanvas& canvas, const QRect &rect){ - if(_transition) - _transition->Paint(canvas,rect); - if(_machine) - _machine->Paint(canvas,rect); +void VMTActionCreateAndConnect::Paint(UICanvas& canvas, const QRect& rect) { + if (_transition) _transition->Paint(canvas, rect); + if (_machine) _machine->Paint(canvas, rect); } diff --git a/VirtualTuringMachine/vmtactions/vmtactioncreateandconnect.h b/VirtualTuringMachine/vmtactions/vmtactioncreateandconnect.h old mode 100755 new mode 100644 index 113b6ab..c0b39ff --- a/VirtualTuringMachine/vmtactions/vmtactioncreateandconnect.h +++ b/VirtualTuringMachine/vmtactions/vmtactioncreateandconnect.h @@ -1,34 +1,35 @@ #ifndef VMTACTIONCREATEANDCONNECT_H #define VMTACTIONCREATEANDCONNECT_H +#include #include "interfaces/IVMTAction.h" -#include "interfaces/IVMTMachine.h" -#include "interfaces/IVMTEnvironment.h" #include "interfaces/IVMTActionController.h" +#include "interfaces/IVMTEnvironment.h" +#include "interfaces/IVMTMachine.h" #include "interfaces/IVMTTransition.h" - -#include -class VMTActionCreateAndConnect : public IVMTAction -{ -protected: - IVMTActionController *_controller; +class VMTActionCreateAndConnect : public IVMTAction { + protected: + IVMTActionController* _controller; std::shared_ptr _transition; std::shared_ptr _machine_start; std::shared_ptr _machine; - -public: - VMTActionCreateAndConnect(IVMTActionController *controller,std::shared_ptr machine_start,std::shared_ptr machine); - void Cancel(IVMTEnvironment *environment) override; - void Enable(IVMTEnvironment *environment) override; - bool OnMouseMoved(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - bool OnMousePressed(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - bool OnMouseReleased(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - void Paint(UICanvas& canvas, const QRect &rect) override; + public: + VMTActionCreateAndConnect(IVMTActionController* controller, + std::shared_ptr machine_start, + std::shared_ptr machine); + void Cancel(IVMTEnvironment* environment) override; + void Enable(IVMTEnvironment* environment) override; + bool OnMouseMoved(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + bool OnMousePressed(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + bool OnMouseReleased(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + void Paint(UICanvas& canvas, const QRect& rect) override; }; - -#endif // VMTACTIONCREATEANDCONNECT_H +#endif // VMTACTIONCREATEANDCONNECT_H diff --git a/VirtualTuringMachine/vmtactions/vmtactiondelete.cpp b/VirtualTuringMachine/vmtactions/vmtactiondelete.cpp old mode 100755 new mode 100644 index 708bcf1..434f5a2 --- a/VirtualTuringMachine/vmtactions/vmtactiondelete.cpp +++ b/VirtualTuringMachine/vmtactions/vmtactiondelete.cpp @@ -1,62 +1,61 @@ #include "vmtactiondelete.h" -#include "vmticons.h" + +#include #include "interfaces/IVMTMachine.h" +#include "vmticons.h" #include "vmtmachines/VMTComplexMachine.h" -#include #include "vmtproject.h" -#include "vmtundomanager.h" #include "vmtundoelementmachine.h" +#include "vmtundomanager.h" -VMTActionDelete::VMTActionDelete(IVMTActionController *controller) : - _controller(controller) -{ - -} -void VMTActionDelete::Cancel(IVMTEnvironment *environment){ +VMTActionDelete::VMTActionDelete(IVMTActionController* controller) + : _controller(controller) {} +void VMTActionDelete::Cancel(IVMTEnvironment* environment) { std::lock_guard lock(_mutex); environment->EnableAnimation(false); - if(auto ptr = _machine.lock()){ + if (auto ptr = _machine.lock()) { ptr->SetSelected(false); environment->Repaint(ptr->GetBounds()); } environment->DisableActionHint(); - } -void VMTActionDelete::Enable(IVMTEnvironment *environment){ +void VMTActionDelete::Enable(IVMTEnvironment* environment) { std::lock_guard lock(_mutex); QPixmap img = VmtIcons::deletePixmap(); - environment->EnableActionHint("Click on machine or link to delete it from diagram.",img); + environment->EnableActionHint( + "Click on machine or link to delete it from diagram.", img); environment->EnableAnimation(true); } -bool VMTActionDelete::OnMouseMoved(IVMTEnvironment* environment,[[maybe_unused]] const QPoint &screen,const QPoint &real){ +bool VMTActionDelete::OnMouseMoved(IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& screen, + const QPoint& real) { std::lock_guard lock(_mutex); - if(!environment) return false; + if (!environment) return false; - if(auto ptr = _machine.lock()){ + if (auto ptr = _machine.lock()) { ptr->SetSelected(false); environment->Repaint(ptr->GetBounds()); } - if(auto ptr = _transition.lock()){ + if (auto ptr = _transition.lock()) { ptr->SetSelected(false); environment->Repaint(ptr->GetBounds()); } - if(auto complex_machine = environment->GetMachine().lock()){ - - _machine = complex_machine->FindMachine(environment,real); - if(auto ptr = _machine.lock()){ + if (auto complex_machine = environment->GetMachine().lock()) { + _machine = complex_machine->FindMachine(environment, real); + if (auto ptr = _machine.lock()) { ptr->SetSelected(true); environment->Repaint(ptr->GetBounds()); - } else{ - _transition = complex_machine->FindTransition(environment,real); - if(auto ptr = _transition.lock()){ + } else { + _transition = complex_machine->FindTransition(environment, real); + if (auto ptr = _transition.lock()) { ptr->SetSelected(true); environment->Repaint(ptr->GetBounds()); } @@ -65,31 +64,34 @@ bool VMTActionDelete::OnMouseMoved(IVMTEnvironment* environment,[[maybe_unused]] return true; } -bool VMTActionDelete::OnMousePressed(IVMTEnvironment* environment,[[maybe_unused]] const QPoint &screen,const QPoint &real){ +bool VMTActionDelete::OnMousePressed(IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& screen, + const QPoint& real) { std::lock_guard lock(_mutex); - if(!environment) return false; - - if(auto complex_machine = environment->GetMachine().lock()){ + if (!environment) return false; - _machine = complex_machine->FindMachine(environment,real); - if(auto ptr = _machine.lock()){ + if (auto complex_machine = environment->GetMachine().lock()) { + _machine = complex_machine->FindMachine(environment, real); + if (auto ptr = _machine.lock()) { VMTProject::GetInstance().GetUndoManager()->Remember( - std::shared_ptr(new VMTUndoElementMachine())); + std::shared_ptr( + new VMTUndoElementMachine())); complex_machine->RemoveMachine(ptr); environment->Repaint(QRect()); } else { - _transition = complex_machine->FindTransition(environment,real); - if(auto ptr = _transition.lock()){ + _transition = complex_machine->FindTransition(environment, real); + if (auto ptr = _transition.lock()) { VMTProject::GetInstance().GetUndoManager()->Remember( - std::shared_ptr(new VMTUndoElementMachine())); + std::shared_ptr( + new VMTUndoElementMachine())); complex_machine->RemoveTransition(ptr); - if(auto ptr_start=ptr->GetStartMachine().lock()){ + if (auto ptr_start = ptr->GetStartMachine().lock()) { ptr_start->RemoveOutgoingTransition(ptr); } - if(auto ptr_finish=ptr->GetFinishMachine().lock()){ + if (auto ptr_finish = ptr->GetFinishMachine().lock()) { ptr_finish->RemoveIncomingTransition(ptr); } @@ -101,18 +103,14 @@ bool VMTActionDelete::OnMousePressed(IVMTEnvironment* environment,[[maybe_unused return true; } -bool VMTActionDelete::OnMouseReleased([[maybe_unused]] IVMTEnvironment* environment,[[maybe_unused]] const QPoint &screen,[[maybe_unused]] const QPoint &real){ +bool VMTActionDelete::OnMouseReleased( + [[maybe_unused]] IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& screen, + [[maybe_unused]] const QPoint& real) { std::lock_guard lock(_mutex); - if(!environment) return false; - + if (!environment) return false; return false; } -void VMTActionDelete::Paint(UICanvas& , const QRect &){ - -} - - - - +void VMTActionDelete::Paint(UICanvas&, const QRect&) {} diff --git a/VirtualTuringMachine/vmtactions/vmtactiondelete.h b/VirtualTuringMachine/vmtactions/vmtactiondelete.h old mode 100755 new mode 100644 index faf8fc2..f87679f --- a/VirtualTuringMachine/vmtactions/vmtactiondelete.h +++ b/VirtualTuringMachine/vmtactions/vmtactiondelete.h @@ -2,26 +2,28 @@ #define VMTACTIONDELETE_H #include "interfaces/IVMTAction.h" -#include "interfaces/IVMTEnvironment.h" #include "interfaces/IVMTActionController.h" #include "interfaces/IVMTAlphabitSource.h" +#include "interfaces/IVMTEnvironment.h" #include "interfaces/IVMTTransition.h" -class VMTActionDelete: public IVMTAction -{ -protected: - IVMTActionController *_controller; +class VMTActionDelete : public IVMTAction { + protected: + IVMTActionController* _controller; std::weak_ptr _machine; std::weak_ptr _transition; -public: - VMTActionDelete(IVMTActionController *controller); - void Cancel(IVMTEnvironment *environment) override; - void Enable(IVMTEnvironment *environment) override; - bool OnMouseMoved(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - bool OnMousePressed(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - bool OnMouseReleased(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - void Paint(UICanvas& canvas, const QRect &rect) override; + public: + VMTActionDelete(IVMTActionController* controller); + void Cancel(IVMTEnvironment* environment) override; + void Enable(IVMTEnvironment* environment) override; + bool OnMouseMoved(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + bool OnMousePressed(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + bool OnMouseReleased(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + void Paint(UICanvas& canvas, const QRect& rect) override; }; -#endif // VMTACTIONDELETE_H +#endif // VMTACTIONDELETE_H diff --git a/VirtualTuringMachine/vmtactions/vmtactionlink.cpp b/VirtualTuringMachine/vmtactions/vmtactionlink.cpp old mode 100755 new mode 100644 index 19847f0..7bf7156 --- a/VirtualTuringMachine/vmtactions/vmtactionlink.cpp +++ b/VirtualTuringMachine/vmtactions/vmtactionlink.cpp @@ -1,162 +1,172 @@ #include "vmtactionlink.h" + +#include + +#include "VMTTransitionImpl.h" #include "interfaces/IVMTMachine.h" +#include "vmticons.h" #include "vmtmachines/VMTComplexMachine.h" -#include "VMTTransitionImpl.h" -#include "vmtundomanager.h" -#include "vmtundoelementmachine.h" #include "vmtproject.h" -#include "vmticons.h" -#include - -VMTActionLink::VMTActionLink(IVMTActionController *controller) : - _controller(controller) -{ - _current_machine = std::weak_ptr(); +#include "vmtundoelementmachine.h" +#include "vmtundomanager.h" +VMTActionLink::VMTActionLink(IVMTActionController* controller) + : _controller(controller) { + _current_machine = std::weak_ptr(); } -VMTActionLink::VMTActionLink(IVMTActionController *controller,std::shared_ptr machine) : _controller(controller) -{ - _current_machine = std::weak_ptr(); - _machine_parameter = machine; - +VMTActionLink::VMTActionLink(IVMTActionController* controller, + std::shared_ptr machine) + : _controller(controller) { + _current_machine = std::weak_ptr(); + _machine_parameter = machine; } -void VMTActionLink::RecreateTransition(IVMTEnvironment *environment){ - _transition = std::shared_ptr(new VMTTransitionImpl(environment->GetMachine())); +void VMTActionLink::RecreateTransition(IVMTEnvironment* environment) { + _transition = std::shared_ptr( + new VMTTransitionImpl(environment->GetMachine())); _machine_start = nullptr; - _machine_end = nullptr; + _machine_end = nullptr; QPixmap img = VmtIcons::linkPixmap(); - environment->EnableAlphabit(_transition->GetAlphabitSource(),QString("Select first machine in transition."),img); + environment->EnableAlphabit(_transition->GetAlphabitSource(), + QString("Select first machine in transition."), + img); } -void VMTActionLink::Cancel(IVMTEnvironment *environment){ +void VMTActionLink::Cancel(IVMTEnvironment* environment) { std::lock_guard lock(_mutex); environment->EnableAnimation(false); - if(_transition) { + if (_transition) { _transition->RemoveChilds(); } environment->DisableAlphabit(); - if(auto ptr = _current_machine.lock()){ + if (auto ptr = _current_machine.lock()) { ptr->SetSelected(false); } - if(_machine_start) _machine_start->SetSelected(false); - if(_machine_end) _machine_end->SetSelected(false); + if (_machine_start) _machine_start->SetSelected(false); + if (_machine_end) _machine_end->SetSelected(false); - _transition = nullptr; + _transition = nullptr; _machine_start = nullptr; - _machine_end = nullptr; - _current_machine = std::weak_ptr(); + _machine_end = nullptr; + _current_machine = std::weak_ptr(); QRect _action_rect; environment->Repaint(_action_rect); - } -void VMTActionLink::Enable(IVMTEnvironment *environment){ - if(environment){ - RecreateTransition(environment); - if(_machine_parameter) - { - if(_machine_parameter->IsAcceptOutgoing()){ - _machine_start = _machine_parameter; - _transition->SetStart(environment,_machine_start); - _transition->SetFinish(environment,_machine_start->GetCenter()); - _transition->SetSelected(true); - _machine_start->SetSelected(true); - QPixmap img = VmtIcons::linkPixmap(); - environment->EnableAlphabit(_transition->GetAlphabitSource(), - QString("Select last machine in transition."),img); - } - _machine_parameter = nullptr; - } - environment->EnableAnimation(true); - } +void VMTActionLink::Enable(IVMTEnvironment* environment) { + if (environment) { + RecreateTransition(environment); + if (_machine_parameter) { + if (_machine_parameter->IsAcceptOutgoing()) { + _machine_start = _machine_parameter; + _transition->SetStart(environment, _machine_start); + _transition->SetFinish(environment, + _machine_start->GetCenter()); + _transition->SetSelected(true); + _machine_start->SetSelected(true); + QPixmap img = VmtIcons::linkPixmap(); + environment->EnableAlphabit( + _transition->GetAlphabitSource(), + QString("Select last machine in transition."), img); + } + _machine_parameter = nullptr; + } + environment->EnableAnimation(true); + } } -bool VMTActionLink::OnMouseMoved(IVMTEnvironment* environment,[[maybe_unused]] const QPoint &screen,const QPoint &real){ +bool VMTActionLink::OnMouseMoved(IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& screen, + const QPoint& real) { std::lock_guard lock(_mutex); - if(!environment) return false; + if (!environment) return false; - if(auto ptr = _current_machine.lock()){ - if(ptr!=_machine_start) ptr->SetSelected(false); + if (auto ptr = _current_machine.lock()) { + if (ptr != _machine_start) ptr->SetSelected(false); QRect _bounds = ptr->GetBounds(); _bounds = _bounds.united(_transition->GetBounds()); - _bounds.setLeft(_bounds.left()-5); - _bounds.setTop(_bounds.top()-5); - _bounds.setWidth(_bounds.width()+10); - _bounds.setHeight(_bounds.height()+10); + _bounds.setLeft(_bounds.left() - 5); + _bounds.setTop(_bounds.top() - 5); + _bounds.setWidth(_bounds.width() + 10); + _bounds.setHeight(_bounds.height() + 10); environment->Repaint(_bounds); } - if(auto complex_machine = environment->GetMachine().lock()){ - _current_machine =complex_machine->FindMachine(environment,real); - if(auto ptr = _current_machine.lock()){ + if (auto complex_machine = environment->GetMachine().lock()) { + _current_machine = complex_machine->FindMachine(environment, real); + if (auto ptr = _current_machine.lock()) { ptr->SetSelected(true); QRect _bounds = ptr->GetBounds(); _bounds = _bounds.united(_transition->GetBounds()); - _bounds.setLeft(_bounds.left()-5); - _bounds.setTop(_bounds.top()-5); - _bounds.setWidth(_bounds.width()+10); - _bounds.setHeight(_bounds.height()+10); + _bounds.setLeft(_bounds.left() - 5); + _bounds.setTop(_bounds.top() - 5); + _bounds.setWidth(_bounds.width() + 10); + _bounds.setHeight(_bounds.height() + 10); environment->Repaint(_bounds); } } - if(_machine_start==nullptr){ - - }else{ - if(_transition){ + if (_machine_start == nullptr) { + } else { + if (_transition) { QRect _bounds = _transition->GetBounds(); - _transition->SetFinish(environment,real); + _transition->SetFinish(environment, real); _bounds = _bounds.united(_transition->GetBounds()); - _bounds.setLeft(_bounds.left()-5); - _bounds.setTop(_bounds.top()-5); - _bounds.setWidth(_bounds.width()+10); - _bounds.setHeight(_bounds.height()+10); - environment->Repaint(_bounds); + _bounds.setLeft(_bounds.left() - 5); + _bounds.setTop(_bounds.top() - 5); + _bounds.setWidth(_bounds.width() + 10); + _bounds.setHeight(_bounds.height() + 10); + environment->Repaint(_bounds); } } return true; } -bool VMTActionLink::OnMousePressed(IVMTEnvironment* environment,[[maybe_unused]]const QPoint &screen,const QPoint &real){ +bool VMTActionLink::OnMousePressed(IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& screen, + const QPoint& real) { std::lock_guard lock(_mutex); - if(!environment) return false; + if (!environment) return false; QRect action_rect; - if(auto complex_machine = environment->GetMachine().lock()){ - if(auto ptr = complex_machine->FindMachine(environment,real).lock()){ - if(_machine_start==nullptr){ - if(ptr->IsAcceptOutgoing()){ - _machine_start = ptr; - _transition->SetStart(environment,ptr); - _transition->SetFinish(environment,real); - _transition->SetSelected(true); - _machine_start->SetSelected(true); - QPixmap img = VmtIcons::linkPixmap(); - environment->EnableAlphabit(_transition->GetAlphabitSource(),QString("Select last machine in transition."),img); + if (auto complex_machine = environment->GetMachine().lock()) { + if (auto ptr = complex_machine->FindMachine(environment, real).lock()) { + if (_machine_start == nullptr) { + if (ptr->IsAcceptOutgoing()) { + _machine_start = ptr; + _transition->SetStart(environment, ptr); + _transition->SetFinish(environment, real); + _transition->SetSelected(true); + _machine_start->SetSelected(true); + QPixmap img = VmtIcons::linkPixmap(); + environment->EnableAlphabit( + _transition->GetAlphabitSource(), + QString("Select last machine in transition."), img); } - } else { - if(_machine_end==nullptr){ - _machine_end = ptr; - _transition->SetFinish(environment,ptr); - _machine_start->AddOutgoingTransition(std::weak_ptr(_transition)); - _machine_end->AddIncomingTransition(std::weak_ptr(_transition)); - VMTProject::GetInstance().GetUndoManager()->Remember( - std::shared_ptr(new VMTUndoElementMachine())); - complex_machine->AddTransition(_transition); - _transition->SetSelected(false); - if(_machine_start) _machine_start->SetSelected(false); - if(_machine_end) _machine_end->SetSelected(false); - - RecreateTransition(environment); - } - - } + } else { + if (_machine_end == nullptr) { + _machine_end = ptr; + _transition->SetFinish(environment, ptr); + _machine_start->AddOutgoingTransition( + std::weak_ptr(_transition)); + _machine_end->AddIncomingTransition( + std::weak_ptr(_transition)); + VMTProject::GetInstance().GetUndoManager()->Remember( + std::shared_ptr( + new VMTUndoElementMachine())); + complex_machine->AddTransition(_transition); + _transition->SetSelected(false); + if (_machine_start) _machine_start->SetSelected(false); + if (_machine_end) _machine_end->SetSelected(false); + + RecreateTransition(environment); + } + } environment->Repaint(action_rect); } @@ -164,18 +174,18 @@ bool VMTActionLink::OnMousePressed(IVMTEnvironment* environment,[[maybe_unused]] return true; } -bool VMTActionLink::OnMouseReleased(IVMTEnvironment* environment,[[maybe_unused]]const QPoint &screen,[[maybe_unused]]const QPoint &real){ - if(!environment) return false; +bool VMTActionLink::OnMouseReleased(IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& screen, + [[maybe_unused]] const QPoint& real) { + if (!environment) return false; return false; } -void VMTActionLink::Paint(UICanvas& canvas, const QRect &rect){ +void VMTActionLink::Paint(UICanvas& canvas, const QRect& rect) { std::lock_guard lock(_mutex); - if(_machine_start!=nullptr){ - if(_transition) - _transition->Paint(canvas,rect); + if (_machine_start != nullptr) { + if (_transition) _transition->Paint(canvas, rect); canvas.DrawRectAnimation(_machine_start->GetBounds()); } } - diff --git a/VirtualTuringMachine/vmtactions/vmtactionlink.h b/VirtualTuringMachine/vmtactions/vmtactionlink.h old mode 100755 new mode 100644 index 98fd5e3..922d74b --- a/VirtualTuringMachine/vmtactions/vmtactionlink.h +++ b/VirtualTuringMachine/vmtactions/vmtactionlink.h @@ -1,16 +1,16 @@ #ifndef VMTACTIONLINK_H #define VMTACTIONLINK_H +#include + #include "interfaces/IVMTAction.h" -#include "interfaces/IVMTEnvironment.h" #include "interfaces/IVMTActionController.h" +#include "interfaces/IVMTEnvironment.h" #include "interfaces/IVMTTransition.h" -#include -class VMTActionLink: public IVMTAction -{ -protected: - IVMTActionController *_controller; +class VMTActionLink : public IVMTAction { + protected: + IVMTActionController* _controller; std::shared_ptr _machine_start; std::shared_ptr _machine_end; @@ -19,15 +19,20 @@ class VMTActionLink: public IVMTAction std::weak_ptr _current_machine; std::shared_ptr _machine_parameter; - void RecreateTransition(IVMTEnvironment *environment); -public: - VMTActionLink(IVMTActionController *controller); - VMTActionLink(IVMTActionController *controller,std::shared_ptr machine); - void Cancel(IVMTEnvironment *environment) override; - void Enable(IVMTEnvironment *environment) override; - bool OnMouseMoved(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - bool OnMousePressed(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - bool OnMouseReleased(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - void Paint(UICanvas& canvas, const QRect &rect) override; + void RecreateTransition(IVMTEnvironment* environment); + + public: + VMTActionLink(IVMTActionController* controller); + VMTActionLink(IVMTActionController* controller, + std::shared_ptr machine); + void Cancel(IVMTEnvironment* environment) override; + void Enable(IVMTEnvironment* environment) override; + bool OnMouseMoved(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + bool OnMousePressed(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + bool OnMouseReleased(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + void Paint(UICanvas& canvas, const QRect& rect) override; }; -#endif // VMTACTIONLINK_H +#endif // VMTACTIONLINK_H diff --git a/VirtualTuringMachine/vmtactions/vmtactionmachine.cpp b/VirtualTuringMachine/vmtactions/vmtactionmachine.cpp old mode 100755 new mode 100644 index 9206f30..a13aa96 --- a/VirtualTuringMachine/vmtactions/vmtactionmachine.cpp +++ b/VirtualTuringMachine/vmtactions/vmtactionmachine.cpp @@ -1,68 +1,80 @@ #include "vmtactionmachine.h" + +#include + #include "interfaces/IVMTMachine.h" +#include "vmtactionpointer.h" #include "vmtmachines/VMTComplexMachine.h" #include "vmtproject.h" -#include "vmtundomanager.h" #include "vmtundoelementmachine.h" -#include "vmtactionpointer.h" -#include - -VMTActionMachine::VMTActionMachine(IVMTActionController *controller,std::shared_ptr machine,bool navi) : - _controller(controller), _machine(machine),_navi(navi) -{ +#include "vmtundomanager.h" -} -void VMTActionMachine::Cancel(IVMTEnvironment *environment){ - if(!environment) return; - if(_machine->IsAlphabit()) - environment->DisableAlphabit(); - else environment->DisableActionHint(); +VMTActionMachine::VMTActionMachine(IVMTActionController* controller, + std::shared_ptr machine, + bool navi) + : _controller(controller), _machine(machine), _navi(navi) {} +void VMTActionMachine::Cancel(IVMTEnvironment* environment) { + if (!environment) return; + if (_machine->IsAlphabit()) + environment->DisableAlphabit(); + else + environment->DisableActionHint(); } -void VMTActionMachine::Enable(IVMTEnvironment *environment){ - if(!environment) return; - if(_machine->IsAlphabit()) - environment->EnableAlphabit(_machine->GetAlphabitSource(),"Select sign for \"Write\" machine",*environment->GetGraphics().GetImage(_machine->GetImageType())); - else { - QString str = "Click on the editor field to add \""; - str.append(_machine->GetName()); - str.append("\" machine to diagram."); - environment->EnableActionHint(str,*environment->GetGraphics().GetImage(_machine->GetImageType())); - } +void VMTActionMachine::Enable(IVMTEnvironment* environment) { + if (!environment) return; + if (_machine->IsAlphabit()) + environment->EnableAlphabit( + _machine->GetAlphabitSource(), "Select sign for \"Write\" machine", + *environment->GetGraphics().GetImage(_machine->GetImageType())); + else { + QString str = "Click on the editor field to add \""; + str.append(_machine->GetName()); + str.append("\" machine to diagram."); + environment->EnableActionHint(str, *environment->GetGraphics().GetImage( + _machine->GetImageType())); + } } -bool VMTActionMachine::OnMouseMoved(IVMTEnvironment* environment,[[maybe_unused]]const QPoint &screen,[[maybe_unused]]const QPoint &real){ - if(!environment) return false; +bool VMTActionMachine::OnMouseMoved(IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& screen, + [[maybe_unused]] const QPoint& real) { + if (!environment) return false; return true; } -bool VMTActionMachine::OnMousePressed(IVMTEnvironment* environment,[[maybe_unused]]const QPoint &screen,[[maybe_unused]]const QPoint &real){ - if(!environment) return false; +bool VMTActionMachine::OnMousePressed(IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& screen, + [[maybe_unused]] const QPoint& real) { + if (!environment) return false; - if(auto complex_machine = environment->GetMachine().lock()){ + if (auto complex_machine = environment->GetMachine().lock()) { VMTProject::GetInstance().GetUndoManager()->Remember( - std::shared_ptr(new VMTUndoElementMachine())); + std::shared_ptr( + new VMTUndoElementMachine())); std::shared_ptr machine_add = _machine->Clone(environment); QPoint center = real; environment->GetGraphics().SnapToGris(center); - machine_add->Move(center,environment); + machine_add->Move(center, environment); complex_machine->AddMachine(machine_add); machine_add->Update(environment); environment->Repaint(machine_add->GetBounds()); - if(_navi) - _controller->SetAction(std::shared_ptr(new VMTActionPointer(_controller,machine_add,_navi))); + if (_navi) + _controller->SetAction(std::shared_ptr( + new VMTActionPointer(_controller, machine_add, _navi))); } return true; } -bool VMTActionMachine::OnMouseReleased(IVMTEnvironment* environment,[[maybe_unused]]const QPoint &screen,[[maybe_unused]]const QPoint &real){ - if(!environment) return false; +bool VMTActionMachine::OnMouseReleased(IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& screen, + [[maybe_unused]] const QPoint& real) { + if (!environment) return false; return true; } -void VMTActionMachine::Paint([[maybe_unused]]UICanvas& canvas, [[maybe_unused]]const QRect &rect){ - -} +void VMTActionMachine::Paint([[maybe_unused]] UICanvas& canvas, + [[maybe_unused]] const QRect& rect) {} diff --git a/VirtualTuringMachine/vmtactions/vmtactionmachine.h b/VirtualTuringMachine/vmtactions/vmtactionmachine.h old mode 100755 new mode 100644 index fa0c965..bdbe8db --- a/VirtualTuringMachine/vmtactions/vmtactionmachine.h +++ b/VirtualTuringMachine/vmtactions/vmtactionmachine.h @@ -1,28 +1,31 @@ #ifndef VMACTIONMACHINE_H #define VMACTIONMACHINE_H +#include #include "interfaces/IVMTAction.h" -#include "interfaces/IVMTEnvironment.h" #include "interfaces/IVMTActionController.h" +#include "interfaces/IVMTEnvironment.h" -#include - -class VMTActionMachine : public IVMTAction -{ -protected: - IVMTActionController *_controller; +class VMTActionMachine : public IVMTAction { + protected: + IVMTActionController* _controller; std::shared_ptr _machine; bool _navi; -public: - VMTActionMachine(IVMTActionController *controller,std::shared_ptr machine,bool navi); - void Cancel(IVMTEnvironment *environment) override; - void Enable(IVMTEnvironment *environment) override; - bool OnMouseMoved(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - bool OnMousePressed(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - bool OnMouseReleased(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - void Paint(UICanvas& canvas, const QRect &rect) override; + + public: + VMTActionMachine(IVMTActionController* controller, + std::shared_ptr machine, bool navi); + void Cancel(IVMTEnvironment* environment) override; + void Enable(IVMTEnvironment* environment) override; + bool OnMouseMoved(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + bool OnMousePressed(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + bool OnMouseReleased(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + void Paint(UICanvas& canvas, const QRect& rect) override; }; -#endif // VMACTIONMACHINE_H +#endif // VMACTIONMACHINE_H diff --git a/VirtualTuringMachine/vmtactions/vmtactionpointer.cpp b/VirtualTuringMachine/vmtactions/vmtactionpointer.cpp old mode 100755 new mode 100644 index f199c84..cd0e7d5 --- a/VirtualTuringMachine/vmtactions/vmtactionpointer.cpp +++ b/VirtualTuringMachine/vmtactions/vmtactionpointer.cpp @@ -1,26 +1,27 @@ #include "vmtactionpointer.h" + +#include + +#include "diagrambezier.h" #include "interfaces/IVMTMachine.h" +#include "screentools.h" +#include "vmtactioncreateandconnect.h" +#include "vmtactionlink.h" #include "vmtmachines/VMTComplexMachine.h" -#include #include "vmtproject.h" #include "vmtundoelementmachine.h" -#include "vmtactioncreateandconnect.h" -#include "vmtactionlink.h" -#include "screentools.h" -#include "diagrambezier.h" namespace { -QRect expandedRepaintBounds(const QRect& rect, int margin) -{ +QRect expandedRepaintBounds(const QRect& rect, int margin) { if (rect.isEmpty()) { return rect; } return rect.marginsAdded(QMargins(margin, margin, margin, margin)); } -QRect transitionRepaintBounds(const std::shared_ptr& transition, int margin) -{ +QRect transitionRepaintBounds(const std::shared_ptr& transition, + int margin) { if (!transition) { return QRect(); } @@ -31,7 +32,9 @@ QRect transitionRepaintBounds(const std::shared_ptr& transition, bounds = bounds.united(QRect(point, QSize(1, 1))); } if (polyline.size() >= 2) { - bounds = bounds.united(DiagramBezier::buildConnectorPath(polyline).boundingRect().toRect()); + bounds = bounds.united(DiagramBezier::buildConnectorPath(polyline) + .boundingRect() + .toRect()); } const int strokeMargin = std::max(margin, 16); @@ -40,54 +43,66 @@ QRect transitionRepaintBounds(const std::shared_ptr& transition, void unionMachineAndLinks(QRect& rect, const std::shared_ptr& machine, - int margin) -{ + int margin) { if (!machine) { return; } rect = expandedRepaintBounds(rect.united(machine->GetBounds()), margin); - for (const std::weak_ptr& link : machine->GetIncomingTransitions()) { + for (const std::weak_ptr& link : + machine->GetIncomingTransitions()) { if (auto transition = link.lock()) { rect = rect.united(transitionRepaintBounds(transition, margin)); } } - for (const std::weak_ptr& link : machine->GetOutgoingTransitions()) { + for (const std::weak_ptr& link : + machine->GetOutgoingTransitions()) { if (auto transition = link.lock()) { rect = rect.united(transitionRepaintBounds(transition, margin)); } } } -} // namespace +} // namespace -VMTActionPointer::VMTActionPointer(IVMTActionController *controller, bool navi) : - _controller(controller), _action_rect(0,0,0,0), _mouse(0,0), _shift(0,0), _is_shift(false), _navi(navi), _drag_dirty_rect() -{ +VMTActionPointer::VMTActionPointer(IVMTActionController* controller, bool navi) + : _controller(controller), + _action_rect(0, 0, 0, 0), + _mouse(0, 0), + _shift(0, 0), + _is_shift(false), + _navi(navi), + _drag_dirty_rect() { _machine = std::weak_ptr(); ScreenTools st; _control_size = st.GetBigButtonSize(); } -VMTActionPointer::VMTActionPointer(IVMTActionController *controller,std::shared_ptr select,bool navi): - _controller(controller), _action_rect(0,0,0,0), _mouse(0,0), _shift(0,0), _is_shift(false), _navi(navi), _drag_dirty_rect() -{ +VMTActionPointer::VMTActionPointer(IVMTActionController* controller, + std::shared_ptr select, + bool navi) + : _controller(controller), + _action_rect(0, 0, 0, 0), + _mouse(0, 0), + _shift(0, 0), + _is_shift(false), + _navi(navi), + _drag_dirty_rect() { _machine = select; ScreenTools st; _control_size = st.GetBigButtonSize(); } -void VMTActionPointer::Cancel(IVMTEnvironment *environment){ - +void VMTActionPointer::Cancel(IVMTEnvironment* environment) { environment->EnableAnimation(false); - if(auto ptr = _machine.lock()){ + if (auto ptr = _machine.lock()) { ptr->SetSelected(false); environment->Repaint(_action_rect); } - if(auto ptr = _transition.lock()){ + if (auto ptr = _transition.lock()) { ptr->SetSelected(false); environment->Repaint(_action_rect); } @@ -98,19 +113,18 @@ void VMTActionPointer::Cancel(IVMTEnvironment *environment){ environment->DisableAlphabit(); environment->DisableCalculator(); - } -void VMTActionPointer::Enable(IVMTEnvironment *environment){ - if(environment) environment->EnableAnimation(true); - if(auto ptr=_machine.lock()) - { - Select(_machine,environment); +void VMTActionPointer::Enable(IVMTEnvironment* environment) { + if (environment) environment->EnableAnimation(true); + if (auto ptr = _machine.lock()) { + Select(_machine, environment); environment->Repaint(QRect()); } } -void VMTActionPointer::GetMachineRect(std::shared_ptr machine,QRect &rect){ +void VMTActionPointer::GetMachineRect(std::shared_ptr machine, + QRect& rect) { rect = QRect(); if (!machine) { return; @@ -119,43 +133,46 @@ void VMTActionPointer::GetMachineRect(std::shared_ptr machine,QRect unionMachineAndLinks(rect, machine, margin); } -bool VMTActionPointer::OnMouseMoved(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real){ - if(!environment) return false; +bool VMTActionPointer::OnMouseMoved(IVMTEnvironment* environment, + const QPoint& screen, const QPoint& real) { + if (!environment) return false; _screen_mouse = screen; bool repaint = false; - if(_is_shift) - { - const int repaintMargin = static_cast(environment->GetGraphics().GetStep()) * 4; + if (_is_shift) { + const int repaintMargin = + static_cast(environment->GetGraphics().GetStep()) * 4; - if(auto ptr = _machine.lock()){ - _shift = real-_mouse; + if (auto ptr = _machine.lock()) { + _shift = real - _mouse; QRect before_rect; unionMachineAndLinks(before_rect, ptr, repaintMargin); - ptr->Move(_shift,environment); + ptr->Move(_shift, environment); QRect after_rect; unionMachineAndLinks(after_rect, ptr, repaintMargin); GetActionRect(ptr, _action_rect, environment); _action_rect = _action_rect.united(after_rect).united(before_rect); - _drag_dirty_rect = _drag_dirty_rect.united(before_rect).united(after_rect).united(_action_rect); + _drag_dirty_rect = _drag_dirty_rect.united(before_rect) + .united(after_rect) + .united(_action_rect); FillControls(environment); repaint = true; - } else - if(auto ptr = _transition.lock()){ - _shift = real-_mouse; - const QRect before_rect = transitionRepaintBounds(ptr, repaintMargin); - ptr->Drag(environment,real); - _action_rect = transitionRepaintBounds(ptr, repaintMargin).united(before_rect); - repaint = true; - - } + } else if (auto ptr = _transition.lock()) { + _shift = real - _mouse; + const QRect before_rect = + transitionRepaintBounds(ptr, repaintMargin); + ptr->Drag(environment, real); + _action_rect = + transitionRepaintBounds(ptr, repaintMargin).united(before_rect); + repaint = true; + } } - if(repaint){ + if (repaint) { if (_machine.lock()) { environment->Repaint(_drag_dirty_rect); } else { @@ -166,23 +183,24 @@ bool VMTActionPointer::OnMouseMoved(IVMTEnvironment* environment,const QPoint &s return true; } - -bool VMTActionPointer::CheckControlClick(IVMTEnvironment *environment,const QPoint& real){ - for(VMTActionPointerControl ctrl : _controls){ - if((ctrl._bounds.left()<=real.x())&& - (ctrl._bounds.right()>=real.x())&& - (ctrl._bounds.top()<=real.y())&& - (ctrl._bounds.bottom()>=real.y())) - { - - if(auto ptr = _machine.lock()){ - if(auto complex_machine = environment->GetMachine().lock()){ - if(ctrl._machine_type!=IVMTMachine::MachineType::NONE) - _controller->SetAction(std::shared_ptr(new VMTActionCreateAndConnect(_controller,ptr, - VMTMachineStub::CreateMachineByID( - ctrl._machine_type, - complex_machine)))); - else _controller->SetAction(std::shared_ptr(new VMTActionLink(_controller,ptr))); +bool VMTActionPointer::CheckControlClick(IVMTEnvironment* environment, + const QPoint& real) { + for (VMTActionPointerControl ctrl : _controls) { + if ((ctrl._bounds.left() <= real.x()) && + (ctrl._bounds.right() >= real.x()) && + (ctrl._bounds.top() <= real.y()) && + (ctrl._bounds.bottom() >= real.y())) { + if (auto ptr = _machine.lock()) { + if (auto complex_machine = environment->GetMachine().lock()) { + if (ctrl._machine_type != IVMTMachine::MachineType::NONE) + _controller->SetAction(std::shared_ptr( + new VMTActionCreateAndConnect( + _controller, ptr, + VMTMachineStub::CreateMachineByID( + ctrl._machine_type, complex_machine)))); + else + _controller->SetAction(std::shared_ptr( + new VMTActionLink(_controller, ptr))); } } @@ -193,67 +211,72 @@ bool VMTActionPointer::CheckControlClick(IVMTEnvironment *environment,const QPoi return false; } -void VMTActionPointer::Select([[maybe_unused]] std::weak_ptr machine,IVMTEnvironment *environment){ - if(auto ptr = _machine.lock()){ +void VMTActionPointer::Select( + [[maybe_unused]] std::weak_ptr machine, + IVMTEnvironment* environment) { + if (auto ptr = _machine.lock()) { VMTProject::GetInstance().GetUndoManager()->Remember( - std::shared_ptr(new VMTUndoElementMachine())); + std::shared_ptr( + new VMTUndoElementMachine())); ptr->SetSelected(true); - if(ptr->IsAlphabit()) - if(ptr->GetAlphabitSource()) - environment->EnableAlphabit(ptr->GetAlphabitSource(),"Select sign for \"Write\" machine",*environment->GetGraphics().GetImage(ptr->GetImageType())); + if (ptr->IsAlphabit()) + if (ptr->GetAlphabitSource()) + environment->EnableAlphabit( + ptr->GetAlphabitSource(), + "Select sign for \"Write\" machine", + *environment->GetGraphics().GetImage(ptr->GetImageType())); - if(ptr->IsPowerCalculator()) - environment->EnableCalculator(ptr); + if (ptr->IsPowerCalculator()) environment->EnableCalculator(ptr); FillControls(environment); - } - } -void VMTActionPointer::GetActionRect(std::shared_ptr machine,QRect& rect,IVMTEnvironment *environment){ - - GetMachineRect(machine,rect); - if(_navi){ - QRect rect_navi; - QPoint screen_center = environment->GetGraphics().ToScreen(machine->GetCenter()); - rect_navi.setLeft(screen_center.x()-_control_size.width()*2); - rect_navi.setTop(screen_center.y()-_control_size.height()*2); - rect_navi.setWidth(_control_size.width()*4); - rect_navi.setHeight(_control_size.height()*4); - rect_navi = environment->GetGraphics().FromScreen(rect_navi); - rect = rect_navi.united(rect); - } else { - rect.setLeft(rect.left()-_control_size.width()); - rect.setTop(rect.top()-_control_size.height()); - rect.setWidth(rect.width()+2*_control_size.width()); - rect.setHeight(rect.height()+2*_control_size.height()); - } +void VMTActionPointer::GetActionRect(std::shared_ptr machine, + QRect& rect, + IVMTEnvironment* environment) { + GetMachineRect(machine, rect); + if (_navi) { + QRect rect_navi; + QPoint screen_center = + environment->GetGraphics().ToScreen(machine->GetCenter()); + rect_navi.setLeft(screen_center.x() - _control_size.width() * 2); + rect_navi.setTop(screen_center.y() - _control_size.height() * 2); + rect_navi.setWidth(_control_size.width() * 4); + rect_navi.setHeight(_control_size.height() * 4); + rect_navi = environment->GetGraphics().FromScreen(rect_navi); + rect = rect_navi.united(rect); + } else { + rect.setLeft(rect.left() - _control_size.width()); + rect.setTop(rect.top() - _control_size.height()); + rect.setWidth(rect.width() + 2 * _control_size.width()); + rect.setHeight(rect.height() + 2 * _control_size.height()); + } } -bool VMTActionPointer::OnMousePressed(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real){ - if(!environment) return false; +bool VMTActionPointer::OnMousePressed(IVMTEnvironment* environment, + const QPoint& screen, + const QPoint& real) { + if (!environment) return false; bool repaint = false; _screen_mouse = screen; _action_rect.setWidth(0); _action_rect.setHeight(0); + if (CheckControlClick(environment, screen)) return true; - if(CheckControlClick(environment,screen)) return true; - - if(auto ptr = _machine.lock()){ + if (auto ptr = _machine.lock()) { ptr->SetSelected(false); environment->DisableAlphabit(); environment->DisableCalculator(); - GetActionRect(ptr,_action_rect,environment); + GetActionRect(ptr, _action_rect, environment); _machine = std::weak_ptr(); repaint = true; - } - if(auto ptr_trans = _transition.lock()){ + if (auto ptr_trans = _transition.lock()) { ptr_trans->SetSelected(false); environment->DisableAlphabit(); environment->DisableCalculator(); @@ -261,75 +284,74 @@ bool VMTActionPointer::OnMousePressed(IVMTEnvironment* environment,const QPoint repaint = true; } - if(auto complex_machine = environment->GetMachine().lock()){ - - - - _machine = complex_machine->FindMachine(environment,real); - if(auto ptr=_machine.lock()){ - Select(_machine,environment); + if (auto complex_machine = environment->GetMachine().lock()) { + _machine = complex_machine->FindMachine(environment, real); + if (auto ptr = _machine.lock()) { + Select(_machine, environment); _is_shift = true; _drag_dirty_rect = QRect(); environment->setDeferTransitionRouting(true); - _mouse=real-ptr->GetCenter(); - _shift = QPoint(0,0); - QRect old_rect=_action_rect; - GetActionRect(ptr,_action_rect,environment); + _mouse = real - ptr->GetCenter(); + _shift = QPoint(0, 0); + QRect old_rect = _action_rect; + GetActionRect(ptr, _action_rect, environment); if (!old_rect.isEmpty()) { _action_rect = _action_rect.united(old_rect); } _drag_dirty_rect = _action_rect; repaint = true; - } - - if(_machine.use_count()==0){ + if (_machine.use_count() == 0) { _controls.clear(); - _transition = complex_machine->FindTransition(environment,real); - if(auto ptr_trans = _transition.lock()){ + _transition = complex_machine->FindTransition(environment, real); + if (auto ptr_trans = _transition.lock()) { VMTProject::GetInstance().GetUndoManager()->Remember( - std::shared_ptr(new VMTUndoElementMachine())); + std::shared_ptr( + new VMTUndoElementMachine())); ptr_trans->SetSelected(true); - if(ptr_trans->GetAlphabitSource()) - environment->EnableAlphabit(ptr_trans->GetAlphabitSource(),ptr_trans->GetAlphabitSource()->GetMessage(),*ptr_trans->GetAlphabitSource()->GetImage()); + if (ptr_trans->GetAlphabitSource()) + environment->EnableAlphabit( + ptr_trans->GetAlphabitSource(), + ptr_trans->GetAlphabitSource()->GetMessage(), + *ptr_trans->GetAlphabitSource()->GetImage()); _action_rect = ptr_trans->GetBounds(); _is_shift = true; - _shift = QPoint(0,0); - ptr_trans->BeginDrag(environment,real); + _shift = QPoint(0, 0); + ptr_trans->BeginDrag(environment, real); repaint = true; } } } - - - if(repaint){ + if (repaint) { environment->Repaint(_action_rect); } return true; } -bool VMTActionPointer::OnMouseReleased(IVMTEnvironment* environment,[[maybe_unused]] const QPoint &screen,const QPoint &real){ - if(!environment) return false; +bool VMTActionPointer::OnMouseReleased(IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& screen, + const QPoint& real) { + if (!environment) return false; bool repaint = false; - if(_is_shift) - if(auto ptr = _machine.lock()){ + if (_is_shift) + if (auto ptr = _machine.lock()) { QRect old_rect; - GetMachineRect(ptr,old_rect); + GetMachineRect(ptr, old_rect); environment->setDeferTransitionRouting(false); QPoint center = ptr->GetCenter(); environment->GetGraphics().SnapToGris(center); ptr->Move(center, environment); - GetActionRect(ptr,_action_rect,environment); + GetActionRect(ptr, _action_rect, environment); _action_rect = _action_rect.united(old_rect); FillControls(environment); repaint = true; @@ -337,16 +359,18 @@ bool VMTActionPointer::OnMouseReleased(IVMTEnvironment* environment,[[maybe_unus if (auto ptr = _transition.lock()) { _shift = real - _mouse; - const int repaintMargin = static_cast(environment->GetGraphics().GetStep()) * 4; + const int repaintMargin = + static_cast(environment->GetGraphics().GetStep()) * 4; const QRect before_rect = transitionRepaintBounds(ptr, repaintMargin); ptr->EndDrag(environment, real); - _action_rect = transitionRepaintBounds(ptr, repaintMargin).united(before_rect); + _action_rect = + transitionRepaintBounds(ptr, repaintMargin).united(before_rect); repaint = true; } _is_shift = false; environment->setDeferTransitionRouting(false); - if(repaint){ + if (repaint) { if (_machine.lock()) { environment->Repaint(_drag_dirty_rect.united(_action_rect)); } else { @@ -357,71 +381,79 @@ bool VMTActionPointer::OnMouseReleased(IVMTEnvironment* environment,[[maybe_unus return false; } -void VMTActionPointer::FillControls(IVMTEnvironment *environment){ - if(_navi) - if(environment) - if(auto ptr = _machine.lock()){ - if(ptr->GetID() == IVMTMachine::MachineType::MT_FINISH) return; - _controls.clear(); - - QRect m_bounds = environment->GetGraphics().ToScreen(ptr->GetBounds()); - QRect bounds,rect; - rect.setLeft(m_bounds.center().x()-_control_size.width()/2); - rect.setTop(m_bounds.center().y()-_control_size.width()/2); - rect.setWidth(_control_size.width()); - rect.setHeight(_control_size.height()); - - bounds = rect; - - - - bounds.moveLeft(rect.right()); - bounds.moveTop(rect.top()-bounds.height()); - _controls.push_back(VMTActionPointerControl(bounds,ImageType::LINK,IVMTMachine::MachineType::NONE)); - - bounds.moveTop(rect.top()); - _controls.push_back(VMTActionPointerControl(bounds,ImageType::MACHINE_RIGHT,IVMTMachine::MachineType::MT_RIGHT)); - - bounds.moveTop(rect.top()+bounds.height()); - _controls.push_back(VMTActionPointerControl(bounds,ImageType::MACHINE_RIGHT_WORD,IVMTMachine::MachineType::MT_RIGHT_WORD)); - - bounds.moveLeft(rect.right()-bounds.width()); - _controls.push_back(VMTActionPointerControl(bounds,ImageType::MACHINE_FINISH,IVMTMachine::MachineType::MT_FINISH)); - - bounds.moveLeft(rect.right()-2*bounds.width()); - _controls.push_back(VMTActionPointerControl(bounds,ImageType::MACHINE_LEFT_WORD,IVMTMachine::MachineType::MT_LEFT_WORD)); - - bounds.moveTop(rect.top()); - _controls.push_back(VMTActionPointerControl(bounds,ImageType::MACHINE_LEFT,IVMTMachine::MachineType::MT_LEFT)); - - bounds.moveTop(rect.top()-bounds.height()); - _controls.push_back(VMTActionPointerControl(bounds,ImageType::MACHINE_COPY,IVMTMachine::MachineType::MT_COPY)); - - bounds.moveLeft(rect.left()); - _controls.push_back(VMTActionPointerControl(bounds,ImageType::MACHINE_LAMBDA,IVMTMachine::MachineType::MT_WRITE)); - } +void VMTActionPointer::FillControls(IVMTEnvironment* environment) { + if (_navi) + if (environment) + if (auto ptr = _machine.lock()) { + if (ptr->GetID() == IVMTMachine::MachineType::MT_FINISH) return; + _controls.clear(); + + QRect m_bounds = + environment->GetGraphics().ToScreen(ptr->GetBounds()); + QRect bounds, rect; + rect.setLeft(m_bounds.center().x() - _control_size.width() / 2); + rect.setTop(m_bounds.center().y() - _control_size.width() / 2); + rect.setWidth(_control_size.width()); + rect.setHeight(_control_size.height()); + + bounds = rect; + + bounds.moveLeft(rect.right()); + bounds.moveTop(rect.top() - bounds.height()); + _controls.push_back(VMTActionPointerControl( + bounds, ImageType::LINK, IVMTMachine::MachineType::NONE)); + + bounds.moveTop(rect.top()); + _controls.push_back(VMTActionPointerControl( + bounds, ImageType::MACHINE_RIGHT, + IVMTMachine::MachineType::MT_RIGHT)); + + bounds.moveTop(rect.top() + bounds.height()); + _controls.push_back(VMTActionPointerControl( + bounds, ImageType::MACHINE_RIGHT_WORD, + IVMTMachine::MachineType::MT_RIGHT_WORD)); + + bounds.moveLeft(rect.right() - bounds.width()); + _controls.push_back(VMTActionPointerControl( + bounds, ImageType::MACHINE_FINISH, + IVMTMachine::MachineType::MT_FINISH)); + + bounds.moveLeft(rect.right() - 2 * bounds.width()); + _controls.push_back(VMTActionPointerControl( + bounds, ImageType::MACHINE_LEFT_WORD, + IVMTMachine::MachineType::MT_LEFT_WORD)); + + bounds.moveTop(rect.top()); + _controls.push_back( + VMTActionPointerControl(bounds, ImageType::MACHINE_LEFT, + IVMTMachine::MachineType::MT_LEFT)); + + bounds.moveTop(rect.top() - bounds.height()); + _controls.push_back( + VMTActionPointerControl(bounds, ImageType::MACHINE_COPY, + IVMTMachine::MachineType::MT_COPY)); + + bounds.moveLeft(rect.left()); + _controls.push_back(VMTActionPointerControl( + bounds, ImageType::MACHINE_LAMBDA, + IVMTMachine::MachineType::MT_WRITE)); + } } -void VMTActionPointer::Paint(UICanvas& canvas, [[maybe_unused]] const QRect &rect){ +void VMTActionPointer::Paint(UICanvas& canvas, + [[maybe_unused]] const QRect& rect) { std::lock_guard lock(_mutex); - - - if(auto ptr = _machine.lock()){ - if(!_controls.empty()){ - QRect rect; - QRect m_bounds = canvas.ToScreen(ptr->GetBounds()); - rect.setLeft(m_bounds.center().x()-_control_size.width()*3/2); - rect.setTop(m_bounds.center().y()-_control_size.height()*3/2); - rect.setWidth(_control_size.width()*3); - rect.setHeight(_control_size.height()*3); - canvas.DrawImageScreen(ImageType::NAVIGATION_CIRCLE,rect); - } else canvas.DrawRectAnimation(ptr->GetBounds()); - - + if (auto ptr = _machine.lock()) { + if (!_controls.empty()) { + QRect rect; + QRect m_bounds = canvas.ToScreen(ptr->GetBounds()); + rect.setLeft(m_bounds.center().x() - _control_size.width() * 3 / 2); + rect.setTop(m_bounds.center().y() - _control_size.height() * 3 / 2); + rect.setWidth(_control_size.width() * 3); + rect.setHeight(_control_size.height() * 3); + canvas.DrawImageScreen(ImageType::NAVIGATION_CIRCLE, rect); + } else + canvas.DrawRectAnimation(ptr->GetBounds()); } } - - - - diff --git a/VirtualTuringMachine/vmtactions/vmtactionpointer.h b/VirtualTuringMachine/vmtactions/vmtactionpointer.h old mode 100755 new mode 100644 index 8f1c029..ea0c0c7 --- a/VirtualTuringMachine/vmtactions/vmtactionpointer.h +++ b/VirtualTuringMachine/vmtactions/vmtactionpointer.h @@ -1,57 +1,62 @@ #ifndef VMTACTIONPOINTER_H #define VMTACTIONPOINTER_H +#include +#include +#include #include "interfaces/IVMTAction.h" -#include "interfaces/IVMTEnvironment.h" #include "interfaces/IVMTActionController.h" #include "interfaces/IVMTAlphabitSource.h" +#include "interfaces/IVMTEnvironment.h" #include "interfaces/IVMTTransition.h" -#include -#include -#include - -struct VMTActionPointerControl{ - QRect _bounds; +struct VMTActionPointerControl { + QRect _bounds; ImageType _image; - std::function _handler; + std::function _handler; IVMTMachine::MachineType _machine_type; - VMTActionPointerControl(QRect bounds,ImageType image,IVMTMachine::MachineType machine_type) : - _bounds(bounds),_image(image),_machine_type(machine_type){} + VMTActionPointerControl(QRect bounds, ImageType image, + IVMTMachine::MachineType machine_type) + : _bounds(bounds), _image(image), _machine_type(machine_type) {} }; -class VMTActionPointer : public IVMTAction -{ -protected: +class VMTActionPointer : public IVMTAction { + protected: std::vector _controls; - IVMTActionController *_controller; - VMTAlphabit _alphabit_dummy; + IVMTActionController* _controller; + VMTAlphabit _alphabit_dummy; - QRect _action_rect; - QPoint _mouse,_shift,_screen_mouse; - QSize _control_size; - bool _is_shift; - bool _navi; - QRect _drag_dirty_rect; + QRect _action_rect; + QPoint _mouse, _shift, _screen_mouse; + QSize _control_size; + bool _is_shift; + bool _navi; + QRect _drag_dirty_rect; std::weak_ptr _machine; std::weak_ptr _transition; - void GetMachineRect(std::shared_ptr machine,QRect &rect); - void FillControls(IVMTEnvironment *environment); - bool CheckControlClick(IVMTEnvironment *environment,const QPoint& real); - void Select(std::weak_ptr machine,IVMTEnvironment *environment); - void GetActionRect(std::shared_ptr machine,QRect& rect,IVMTEnvironment *environment); -public: - VMTActionPointer(IVMTActionController *controller,bool navi); - VMTActionPointer(IVMTActionController *controller,std::shared_ptr select,bool navi); - void Cancel(IVMTEnvironment *environment) override; - void Enable(IVMTEnvironment *environment) override; - bool OnMouseMoved(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - bool OnMousePressed(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - bool OnMouseReleased(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - void Paint(UICanvas& canvas, const QRect &rect) override; - + void GetMachineRect(std::shared_ptr machine, QRect& rect); + void FillControls(IVMTEnvironment* environment); + bool CheckControlClick(IVMTEnvironment* environment, const QPoint& real); + void Select(std::weak_ptr machine, + IVMTEnvironment* environment); + void GetActionRect(std::shared_ptr machine, QRect& rect, + IVMTEnvironment* environment); + + public: + VMTActionPointer(IVMTActionController* controller, bool navi); + VMTActionPointer(IVMTActionController* controller, + std::shared_ptr select, bool navi); + void Cancel(IVMTEnvironment* environment) override; + void Enable(IVMTEnvironment* environment) override; + bool OnMouseMoved(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + bool OnMousePressed(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + bool OnMouseReleased(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + void Paint(UICanvas& canvas, const QRect& rect) override; }; -#endif // VMTACTIONPOINTER_H +#endif // VMTACTIONPOINTER_H diff --git a/VirtualTuringMachine/vmtactions/vmtactiontranslate.cpp b/VirtualTuringMachine/vmtactions/vmtactiontranslate.cpp old mode 100755 new mode 100644 index effd495..102862c --- a/VirtualTuringMachine/vmtactions/vmtactiontranslate.cpp +++ b/VirtualTuringMachine/vmtactions/vmtactiontranslate.cpp @@ -1,57 +1,69 @@ #include "vmtactiontranslate.h" -#include "vmticons.h" -VMTActionTranslate::VMTActionTranslate(IVMTActionController *controller) : - _controller(controller), _position(0,0), _mouse(0,0), _shift(0,0), _is_shift(false) -{ +#include "vmticons.h" -} -void VMTActionTranslate::Cancel(IVMTEnvironment *environment){ - environment->DisableActionHint(); +VMTActionTranslate::VMTActionTranslate(IVMTActionController* controller) + : _controller(controller), + _position(0, 0), + _mouse(0, 0), + _shift(0, 0), + _is_shift(false) {} +void VMTActionTranslate::Cancel(IVMTEnvironment* environment) { + environment->DisableActionHint(); } -void VMTActionTranslate::Enable(IVMTEnvironment *environment){ +void VMTActionTranslate::Enable(IVMTEnvironment* environment) { QPixmap img = VmtIcons::handPixmap(); - environment->EnableActionHint("Drag editor field in any direction. Double click on the Hand icon - center the editor field.",img); + environment->EnableActionHint( + "Drag editor field in any direction. Double click on the Hand icon - " + "center the editor field.", + img); } -bool VMTActionTranslate::OnMouseMoved(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real){ - static QRect empty_rect; - _position = real; +bool VMTActionTranslate::OnMouseMoved(IVMTEnvironment* environment, + const QPoint& screen, + const QPoint& real) { + static QRect empty_rect; + _position = real; - if(_is_shift){ - environment->MoveInScreen(QPoint(-_shift)); - _shift = screen-_mouse; - environment->MoveInScreen(QPoint(_shift)); - environment->RepaintThrottled(empty_rect); - } + if (_is_shift) { + environment->MoveInScreen(QPoint(-_shift)); + _shift = screen - _mouse; + environment->MoveInScreen(QPoint(_shift)); + environment->RepaintThrottled(empty_rect); + } - return true; + return true; } -#include "vmtundoelementeditor.h" #include "vmtproject.h" +#include "vmtundoelementeditor.h" -bool VMTActionTranslate::OnMousePressed([[maybe_unused]] IVMTEnvironment* environment,[[maybe_unused]] const QPoint &screen,[[maybe_unused]] const QPoint &real){ - _is_shift = true; - _mouse=screen; - _shift = QPoint(0,0); - VMTProject::GetInstance().GetUndoManager()->Remember( - std::shared_ptr(new VMTUndoElementEditor(environment))); - return true; +bool VMTActionTranslate::OnMousePressed( + [[maybe_unused]] IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& screen, + [[maybe_unused]] const QPoint& real) { + _is_shift = true; + _mouse = screen; + _shift = QPoint(0, 0); + VMTProject::GetInstance().GetUndoManager()->Remember( + std::shared_ptr( + new VMTUndoElementEditor(environment))); + return true; } -bool VMTActionTranslate::OnMouseReleased(IVMTEnvironment* environment,[[maybe_unused]] const QPoint &screen,[[maybe_unused]]const QPoint &real){ - _is_shift = false; - if (environment) { - static const QRect empty_rect; - environment->Repaint(empty_rect); - } - return true; +bool VMTActionTranslate::OnMouseReleased(IVMTEnvironment* environment, + [[maybe_unused]] const QPoint& screen, + [[maybe_unused]] const QPoint& real) { + _is_shift = false; + if (environment) { + static const QRect empty_rect; + environment->Repaint(empty_rect); + } + return true; } -void VMTActionTranslate::Paint(UICanvas& , const QRect &){ - - //QRect action_rect(_position.rx(),_position.ry(),10,10); - //canvas.DrawRect(action_rect); +void VMTActionTranslate::Paint(UICanvas&, const QRect&) { + // QRect action_rect(_position.rx(),_position.ry(),10,10); + // canvas.DrawRect(action_rect); } diff --git a/VirtualTuringMachine/vmtactions/vmtactiontranslate.h b/VirtualTuringMachine/vmtactions/vmtactiontranslate.h old mode 100755 new mode 100644 index 00b29f7..0d59bd7 --- a/VirtualTuringMachine/vmtactions/vmtactiontranslate.h +++ b/VirtualTuringMachine/vmtactions/vmtactiontranslate.h @@ -1,29 +1,30 @@ #ifndef VMTACTIONTRANSLATE_H #define VMTACTIONTRANSLATE_H +#include + #include "interfaces/IVMTAction.h" -#include "interfaces/IVMTEnvironment.h" #include "interfaces/IVMTActionController.h" - -#include -class VMTActionTranslate : public IVMTAction -{ -protected: - IVMTActionController *_controller; +#include "interfaces/IVMTEnvironment.h" +class VMTActionTranslate : public IVMTAction { + protected: + IVMTActionController* _controller; QPoint _position; - QPoint _mouse,_shift; - bool _is_shift; - + QPoint _mouse, _shift; + bool _is_shift; -public: - VMTActionTranslate(IVMTActionController *controller); - void Cancel(IVMTEnvironment *environment) override; - void Enable(IVMTEnvironment *environment) override; - bool OnMouseMoved(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - bool OnMousePressed(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - bool OnMouseReleased(IVMTEnvironment* environment,const QPoint &screen,const QPoint &real) override; - void Paint(UICanvas& canvas, const QRect &rect) override; + public: + VMTActionTranslate(IVMTActionController* controller); + void Cancel(IVMTEnvironment* environment) override; + void Enable(IVMTEnvironment* environment) override; + bool OnMouseMoved(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + bool OnMousePressed(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + bool OnMouseReleased(IVMTEnvironment* environment, const QPoint& screen, + const QPoint& real) override; + void Paint(UICanvas& canvas, const QRect& rect) override; }; -#endif // VMTACTIONTRANSLATE_H +#endif // VMTACTIONTRANSLATE_H diff --git a/VirtualTuringMachine/vmtdebuger.cpp b/VirtualTuringMachine/vmtdebuger.cpp old mode 100755 new mode 100644 index 60bc5e7..099551d --- a/VirtualTuringMachine/vmtdebuger.cpp +++ b/VirtualTuringMachine/vmtdebuger.cpp @@ -1,65 +1,68 @@ #include "vmtdebuger.h" + #include -VMTDebuger::VMTDebuger(std::shared_ptr alphabit,std::shared_ptr complex_machine) : - _line(std::shared_ptr(new VMTLine(alphabit))), _complex_machine(complex_machine) +VMTDebuger::VMTDebuger(std::shared_ptr alphabit, + std::shared_ptr complex_machine) + : _line(std::shared_ptr(new VMTLine(alphabit))), + _complex_machine(complex_machine) { _state.complex_machine = _complex_machine; - for(std::shared_ptr ptr: _complex_machine->GetMachineCollection()) - if(ptr->GetID() == IVMTMachine::MachineType::MT_START){ + for (std::shared_ptr ptr : + _complex_machine->GetMachineCollection()) + if (ptr->GetID() == IVMTMachine::MachineType::MT_START) { _state.machine = ptr; break; } _state.machine->SetSelected(true); } -std::shared_ptr VMTDebuger::GetLine(){ - return _line; -} +std::shared_ptr VMTDebuger::GetLine() { return _line; } -std::shared_ptr VMTDebuger::GetComplexMachine(){ +std::shared_ptr VMTDebuger::GetComplexMachine() { return _complex_machine; } -void VMTDebuger::ToStart(IVMTEnvironment *environment){ - if(_state.machine) - if(_state.complex_machine){ +void VMTDebuger::ToStart(IVMTEnvironment* environment) { + if (_state.machine) + if (_state.complex_machine) { _state.machine->SetSelected(false); } - _state.complex_machine = _complex_machine; - for(std::shared_ptr ptr: _complex_machine->GetMachineCollection()) - if(ptr->GetID() == IVMTMachine::MachineType::MT_START){ + for (std::shared_ptr ptr : + _complex_machine->GetMachineCollection()) + if (ptr->GetID() == IVMTMachine::MachineType::MT_START) { _state.machine = ptr; break; } _state.machine->SetSelected(true); environment->SetMachine(_state.complex_machine); - } -bool VMTDebuger::IsFinish(){ - if(_stack.empty()) - if(_state.machine) - if(_state.complex_machine) - if(_state.machine->GetID()==IVMTMachine::MachineType::MT_FINISH){ +bool VMTDebuger::IsFinish() { + if (_stack.empty()) + if (_state.machine) + if (_state.complex_machine) + if (_state.machine->GetID() == + IVMTMachine::MachineType::MT_FINISH) { return true; } return false; } -VMTDebuger::State VMTDebuger::FindNextMachine(){ +VMTDebuger::State VMTDebuger::FindNextMachine() { char sign = _line->GetValueAtMachine(); VMTDebuger::State result; result.complex_machine = _state.complex_machine; result.machine = _state.machine; - for(const std::weak_ptr &ptr: _state.machine->GetOutgoingTransitions()){ - if(auto t = ptr.lock()) - if(t->GetConditions().IsEnabled(sign)){ + for (const std::weak_ptr& ptr : + _state.machine->GetOutgoingTransitions()) { + if (auto t = ptr.lock()) + if (t->GetConditions().IsEnabled(sign)) { result.machine = t->GetFinishMachine().lock(); break; } @@ -68,69 +71,76 @@ VMTDebuger::State VMTDebuger::FindNextMachine(){ return result; } -void VMTDebuger::Step(IVMTEnvironment *environment){ - if(_state.machine) - if(_state.complex_machine){ +void VMTDebuger::Step(IVMTEnvironment* environment) { + if (_state.machine) + if (_state.complex_machine) { _state.machine->SetSelected(false); - switch(_state.machine->GetID()){ - case IVMTMachine::MachineType::MT_COMPLEX:{ - long power= _state.machine->GetPower(); - _stack.push(_state); - _state.complex_machine = std::dynamic_pointer_cast(_state.machine); - environment->SetMachine(_state.complex_machine); - for(std::shared_ptr ptr: _state.complex_machine->GetMachineCollection()) - if(ptr->GetID() == IVMTMachine::MachineType::MT_START){ - _state.machine = ptr; - break; - } - for(int i=0;iGetPower(); - auto old_machine = _state.machine; - _stack.push(_state); - _state.complex_machine = std::dynamic_pointer_cast(_state.machine->CreateComplexMachine(environment));//std::dynamic_pointer_cast(_state.machine); - environment->SetMachine(_state.complex_machine); - for(std::shared_ptr ptr: _state.complex_machine->GetMachineCollection()) - if(ptr->GetID() == IVMTMachine::MachineType::MT_START){ - _state.machine = ptr; - break; - } - - for(int i=0;i ptr: _complex_machine->GetMachineCollection()) - if(ptr->GetID() == IVMTMachine::MachineType::MT_START){ + switch (_state.machine->GetID()) { + case IVMTMachine::MachineType::MT_COMPLEX: { + long power = _state.machine->GetPower(); + _stack.push(_state); + _state.complex_machine = + std::dynamic_pointer_cast( + _state.machine); + environment->SetMachine(_state.complex_machine); + for (std::shared_ptr ptr : + _state.complex_machine->GetMachineCollection()) + if (ptr->GetID() == + IVMTMachine::MachineType::MT_START) { _state.machine = ptr; break; } - } else { - _state = _stack.top(); - _stack.pop(); - _state = FindNextMachine(); + for (int i = 0; i < power - 1; i++) _stack.push(_state); + break; + } + case IVMTMachine::MachineType::MT_RIGHT_WORD: + case IVMTMachine::MachineType::MT_LEFT_WORD: + case IVMTMachine::MachineType::MT_COPY: { + long power = _state.machine->GetPower(); + auto old_machine = _state.machine; + _stack.push(_state); + _state.complex_machine = std::dynamic_pointer_cast< + VMTComplexMachine>(_state.machine->CreateComplexMachine( + environment)); // std::dynamic_pointer_cast(_state.machine); environment->SetMachine(_state.complex_machine); + for (std::shared_ptr ptr : + _state.complex_machine->GetMachineCollection()) + if (ptr->GetID() == + IVMTMachine::MachineType::MT_START) { + _state.machine = ptr; + break; + } + for (int i = 0; i < power - 1; i++) _stack.push(_state); + break; } - break; - default: - for(long i = 0; i < _state.machine->GetPower(); ++i) - _state.machine->DoAction(_line); - _state = FindNextMachine(); - break; + + case IVMTMachine::MachineType::MT_START: + _state = FindNextMachine(); + break; + case IVMTMachine::MachineType::MT_FINISH: + if (_stack.empty()) { + _state.complex_machine = _complex_machine; + for (std::shared_ptr ptr : + _complex_machine->GetMachineCollection()) + if (ptr->GetID() == + IVMTMachine::MachineType::MT_START) { + _state.machine = ptr; + break; + } + } else { + _state = _stack.top(); + _stack.pop(); + _state = FindNextMachine(); + environment->SetMachine(_state.complex_machine); + } + break; + default: + for (long i = 0; i < _state.machine->GetPower(); ++i) + _state.machine->DoAction(_line); + _state = FindNextMachine(); + break; } _state.machine->SetSelected(true); environment->Repaint(QRect()); diff --git a/VirtualTuringMachine/vmtdebuger.h b/VirtualTuringMachine/vmtdebuger.h old mode 100755 new mode 100644 index 4068677..c25cb2c --- a/VirtualTuringMachine/vmtdebuger.h +++ b/VirtualTuringMachine/vmtdebuger.h @@ -1,39 +1,38 @@ #ifndef VMTDEBUGER_H #define VMTDEBUGER_H -#include "VMTLine.h" -#include "VMTAlphabit.h" -#include "vmtmachines/VMTComplexMachine.h" - #include #include -class VMTDebuger -{ -protected: - std::shared_ptr _line; +#include "VMTAlphabit.h" +#include "VMTLine.h" +#include "vmtmachines/VMTComplexMachine.h" + +class VMTDebuger { + protected: + std::shared_ptr _line; std::shared_ptr _complex_machine; - class State{ + class State { public: std::shared_ptr complex_machine; std::shared_ptr machine; }; std::stack _stack; - State _state; + State _state; VMTDebuger::State FindNextMachine(); + public: + VMTDebuger(std::shared_ptr alphabit, + std::shared_ptr complex_machine); -public: - VMTDebuger(std::shared_ptr alphabit,std::shared_ptr complex_machine); - - std::shared_ptr GetLine(); + std::shared_ptr GetLine(); std::shared_ptr GetComplexMachine(); - void ToStart(IVMTEnvironment *environment); + void ToStart(IVMTEnvironment* environment); bool IsFinish(); - void Step(IVMTEnvironment *environment); + void Step(IVMTEnvironment* environment); }; -#endif // VMTDEBUGER_H +#endif // VMTDEBUGER_H diff --git a/VirtualTuringMachine/vmterror.cpp b/VirtualTuringMachine/vmterror.cpp old mode 100755 new mode 100644 index f1da9a5..73bb3cd --- a/VirtualTuringMachine/vmterror.cpp +++ b/VirtualTuringMachine/vmterror.cpp @@ -1,24 +1,19 @@ #include "vmterror.h" -VMTError::VMTError(std::shared_ptr complex_machine,QString message) : - _complex_machine(complex_machine),_message(message) -{ +VMTError::VMTError(std::shared_ptr complex_machine, + QString message) + : _complex_machine(complex_machine), _message(message) {} -} - -const QString& VMTError::GetMessage(){ - return _message; -} +const QString& VMTError::GetMessage() { return _message; } -std::shared_ptr VMTError::GetMachine(){ +std::shared_ptr VMTError::GetMachine() { return _complex_machine; - } -std::shared_ptr VMTError::GetErrorMachine(){ +std::shared_ptr VMTError::GetErrorMachine() { return std::shared_ptr(); } -std::shared_ptr VMTError::GetErrorTransition(){ +std::shared_ptr VMTError::GetErrorTransition() { return std::shared_ptr(); } diff --git a/VirtualTuringMachine/vmterror.h b/VirtualTuringMachine/vmterror.h old mode 100755 new mode 100644 index c01ac5b..39e8511 --- a/VirtualTuringMachine/vmterror.h +++ b/VirtualTuringMachine/vmterror.h @@ -1,17 +1,19 @@ #ifndef VMTERROR_H #define VMTERROR_H -#include #include + +#include #include -class VMTError -{ -protected: +class VMTError { + protected: std::shared_ptr _complex_machine; QString _message; -public: - VMTError(std::shared_ptr complex_machine,QString message); + + public: + VMTError(std::shared_ptr complex_machine, + QString message); const QString& GetMessage(); std::shared_ptr GetMachine(); virtual std::shared_ptr GetErrorMachine(); @@ -19,4 +21,4 @@ class VMTError virtual ~VMTError() = default; }; -#endif // VMTERROR_H +#endif // VMTERROR_H diff --git a/VirtualTuringMachine/vmterrormachine.cpp b/VirtualTuringMachine/vmterrormachine.cpp old mode 100755 new mode 100644 index 8110bf1..b3459cf --- a/VirtualTuringMachine/vmterrormachine.cpp +++ b/VirtualTuringMachine/vmterrormachine.cpp @@ -1,13 +1,10 @@ #include "vmterrormachine.h" -VMTErrorMachine::VMTErrorMachine(std::shared_ptr complex_machine, - QString message,std::shared_ptr machine) : - VMTError(complex_machine,message), _machine(machine) -{ +VMTErrorMachine::VMTErrorMachine( + std::shared_ptr complex_machine, QString message, + std::shared_ptr machine) + : VMTError(complex_machine, message), _machine(machine) {} -} - -std::shared_ptr VMTErrorMachine::GetErrorMachine(){ +std::shared_ptr VMTErrorMachine::GetErrorMachine() { return _machine; } - diff --git a/VirtualTuringMachine/vmterrormachine.h b/VirtualTuringMachine/vmterrormachine.h old mode 100755 new mode 100644 index 2bebc3c..9d03da9 --- a/VirtualTuringMachine/vmterrormachine.h +++ b/VirtualTuringMachine/vmterrormachine.h @@ -1,15 +1,16 @@ #ifndef VMTERRORMACHINE_H #define VMTERRORMACHINE_H -#include "vmterror.h" #include "interfaces/IVMTMachine.h" -class VMTErrorMachine : public VMTError -{ -protected: +#include "vmterror.h" +class VMTErrorMachine : public VMTError { + protected: std::shared_ptr _machine; -public: - VMTErrorMachine(std::shared_ptr _complex_machine,QString _message,std::shared_ptr machine); + + public: + VMTErrorMachine(std::shared_ptr _complex_machine, + QString _message, std::shared_ptr machine); std::shared_ptr GetErrorMachine() override; }; -#endif // VMTERRORMACHINE_H +#endif // VMTERRORMACHINE_H diff --git a/VirtualTuringMachine/vmterrortransition.cpp b/VirtualTuringMachine/vmterrortransition.cpp old mode 100755 new mode 100644 index f118b16..4fe3509 --- a/VirtualTuringMachine/vmterrortransition.cpp +++ b/VirtualTuringMachine/vmterrortransition.cpp @@ -1,11 +1,10 @@ #include "vmterrortransition.h" -VMTErrorTransition::VMTErrorTransition(std::shared_ptr complex_machine,QString message,std::shared_ptr transition) : - VMTError(complex_machine,message), _transition(transition) -{ +VMTErrorTransition::VMTErrorTransition( + std::shared_ptr complex_machine, QString message, + std::shared_ptr transition) + : VMTError(complex_machine, message), _transition(transition) {} -} - -std::shared_ptr VMTErrorTransition::GetErrorTransition(){ +std::shared_ptr VMTErrorTransition::GetErrorTransition() { return _transition; } diff --git a/VirtualTuringMachine/vmterrortransition.h b/VirtualTuringMachine/vmterrortransition.h old mode 100755 new mode 100644 index 4bad681..4e0fab0 --- a/VirtualTuringMachine/vmterrortransition.h +++ b/VirtualTuringMachine/vmterrortransition.h @@ -1,16 +1,18 @@ #ifndef VMTERRORTRANSITION_H #define VMTERRORTRANSITION_H -#include "vmterror.h" #include "interfaces/IVMTTransition.h" +#include "vmterror.h" -class VMTErrorTransition : public VMTError -{ -protected: +class VMTErrorTransition : public VMTError { + protected: std::shared_ptr _transition; -public: - VMTErrorTransition(std::shared_ptr complex_machine,QString message,std::shared_ptr transition); + + public: + VMTErrorTransition(std::shared_ptr complex_machine, + QString message, + std::shared_ptr transition); std::shared_ptr GetErrorTransition() override; }; -#endif // VMTERRORTRANSITION_H +#endif // VMTERRORTRANSITION_H diff --git a/VirtualTuringMachine/vmtexport4th/vmtexport4th.cpp b/VirtualTuringMachine/vmtexport4th/vmtexport4th.cpp old mode 100755 new mode 100644 index b955af7..4f503d3 --- a/VirtualTuringMachine/vmtexport4th/vmtexport4th.cpp +++ b/VirtualTuringMachine/vmtexport4th/vmtexport4th.cpp @@ -1,183 +1,184 @@ #include "vmtexport4th.h" -#include "vmtmachines/VMTComplexMachine.h" #include -#include -#include #include #include - +#include #include +#include + +#include "vmtmachines/VMTComplexMachine.h" namespace std { template -std::string to_string(T value) -{ - std::ostringstream os ; - os << value ; - return os.str() ; +std::string to_string(T value) { + std::ostringstream os; + os << value; + return os.str(); } -} +} // namespace std #include "vmtmachines/VMTMachineAlpha.h" VMTExport4th::VMTExport4th(std::shared_ptr machine, - QString delimiter, QString left, QString right, QString stop, QString quotes) : - _progress(0), - _machine(machine), - _delimiter(delimiter), - _left(left), - _right(right), - _stop(stop), - _quotes(quotes), - _error(false), - _machine_count(0), - _callback(nullptr){ -} - -bool VMTExport4th::IsError(){ + QString delimiter, QString left, QString right, + QString stop, QString quotes) + : _progress(0), + _machine(machine), + _delimiter(delimiter), + _left(left), + _right(right), + _stop(stop), + _quotes(quotes), + _error(false), + _machine_count(0), + _callback(nullptr) {} + +bool VMTExport4th::IsError() { std::lock_guard lock(_mtx); return _error; } -const QString VMTExport4th::GetErrorMessage(){ +const QString VMTExport4th::GetErrorMessage() { std::lock_guard lock(_mtx); return _error_message; } -const QString VMTExport4th::GetInformation(){ +const QString VMTExport4th::GetInformation() { std::lock_guard lock(_mtx); return _information; } -size_t VMTExport4th::GetMachineCount(){ +size_t VMTExport4th::GetMachineCount() { std::lock_guard lock(_mtx); return _machine_count; } -void VMTExport4th::Export(TextCallback *callback,IVMTEnvironment *environment){ - if(IsRuning()) return; - _callback = callback; - _can_run = true; - _progress = 0; - _error = false; - _error_message = ""; - _information = ""; - _machine_count = 0; - - _thread = std::shared_ptr(new std::thread(std::ref(*this),environment)); - +void VMTExport4th::Export(TextCallback* callback, + IVMTEnvironment* environment) { + if (IsRuning()) return; + _callback = callback; + _can_run = true; + _progress = 0; + _error = false; + _error_message = ""; + _information = ""; + _machine_count = 0; + + _thread = std::shared_ptr( + new std::thread(std::ref(*this), environment)); } -size_t VMTExport4th::GetProgress(){ +size_t VMTExport4th::GetProgress() { std::lock_guard lock(_mtx); return _progress; } -bool VMTExport4th::IsRuning(){ +bool VMTExport4th::IsRuning() { std::lock_guard lock(_mtx); - if(_thread) return true; + if (_thread) return true; return false; } -void VMTExport4th::Stop(){ +void VMTExport4th::Stop() { { std::lock_guard lock(_mtx); _can_run = false; } - while(IsRuning()){ + while (IsRuning()) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); } - } -void VMTExport4th::AddInformation(QString && str){ +void VMTExport4th::AddInformation(QString&& str) { std::lock_guard lock(_mtx); _information += str; - if(_callback) _callback->Information(_information); + if (_callback) _callback->Information(_information); } template -void MachineFunction(std::shared_ptr complex, FUNCTION_COMPLEX fc,FUNCTION_SIMPLE fs){ - for(auto m : complex->GetMachineCollection()){ - if(m->GetID() == IVMTMachine::MachineType::MT_COMPLEX) { - if(!fc(complex,std::dynamic_pointer_cast(m))) return; - MachineFunction(std::dynamic_pointer_cast(m),fc,fs); - } else if(!fs(complex,m)) return; +void MachineFunction(std::shared_ptr complex, + FUNCTION_COMPLEX fc, FUNCTION_SIMPLE fs) { + for (auto m : complex->GetMachineCollection()) { + if (m->GetID() == IVMTMachine::MachineType::MT_COMPLEX) { + if (!fc(complex, std::dynamic_pointer_cast(m))) + return; + MachineFunction( + std::dynamic_pointer_cast(m), fc, fs); + } else if (!fs(complex, m)) + return; } } - - -QString VMTExport4th::FormatString(size_t state,QChar c,Command cmd,size_t state2){ +QString VMTExport4th::FormatString(size_t state, QChar c, Command cmd, + size_t state2) { QString cmd_sz; - switch(cmd){ - case left: cmd_sz = _left;break; - case right: cmd_sz= _right;break; - case stop: cmd_sz = _stop;break; + switch (cmd) { + case left: + cmd_sz = _left; + break; + case right: + cmd_sz = _right; + break; + case stop: + cmd_sz = _stop; + break; } - return QString("%1%2%3%4%5%6%7%8%9").arg( - QString::number(state), - _delimiter, - _quotes, - c, - _quotes, - _delimiter, - cmd_sz, - _delimiter, - QString::number(state2)); + return QString("%1%2%3%4%5%6%7%8%9") + .arg(QString::number(state), _delimiter, _quotes, c, _quotes, + _delimiter, cmd_sz, _delimiter, QString::number(state2)); } -QString VMTExport4th::FormatString(size_t state,QChar c,QString write,size_t state2){ - return QString("%1%2%3%4%5%6%7").arg( - QString::number(state), - _delimiter, - _quotes+c+_quotes, - _delimiter, - _quotes+write+_quotes, - _delimiter, - QString::number(state2)); +QString VMTExport4th::FormatString(size_t state, QChar c, QString write, + size_t state2) { + return QString("%1%2%3%4%5%6%7") + .arg(QString::number(state), _delimiter, _quotes + c + _quotes, + _delimiter, _quotes + write + _quotes, _delimiter, + QString::number(state2)); } - - -void VMTExport4th::operator ()(IVMTEnvironment *environment){ - if(!_callback) return; +void VMTExport4th::operator()(IVMTEnvironment* environment) { + if (!_callback) return; { AddInformation("Checking for recursive calls ... \r\n"); std::set stack; stack.insert(_machine->GetName()); - MachineFunction(_machine, - [&](std::shared_ptr complex,std::shared_ptr m)->bool{ - if(stack.count(m->GetName())) { - _error = true; - _error_message = QString("Recursive machine call to %1 detected in %2").arg(m->GetName(),complex->GetName()); - return false; - } else return true; - }, - [&]([[maybe_unused]] std::shared_ptr complex, - [[maybe_unused]] std::shared_ptr m) -> bool { return true; }); + MachineFunction( + _machine, + [&](std::shared_ptr complex, + std::shared_ptr m) -> bool { + if (stack.count(m->GetName())) { + _error = true; + _error_message = + QString("Recursive machine call to %1 detected in %2") + .arg(m->GetName(), complex->GetName()); + return false; + } else + return true; + }, + [&]([[maybe_unused]] std::shared_ptr complex, + [[maybe_unused]] std::shared_ptr m) -> bool { + return true; + }); } - if(!_error) { - std::map state_index; - std::deque call_stack; - size_t index=0; + if (!_error) { + std::map state_index; + std::deque call_stack; + size_t index = 0; std::string prefix; - MapState(index,prefix,call_stack,_machine,state_index,environment); - ProcessComplex(0,prefix,call_stack,_machine,state_index,environment); - - - + MapState(index, prefix, call_stack, _machine, state_index, environment); + ProcessComplex(0, prefix, call_stack, _machine, state_index, + environment); AddInformation("Export complete \r\n"); _callback->Done(); - } else{ + } else { AddInformation("Export doesn't support recursive calls \r\n"); } @@ -189,15 +190,17 @@ void VMTExport4th::operator ()(IVMTEnvironment *environment){ } } -std::string VMTExport4th::GetFullName(std::string prefix,std::shared_ptr machine){ +std::string VMTExport4th::GetFullName(std::string prefix, + std::shared_ptr machine) { std::string result = prefix; - result +=":"; + result += ":"; result += std::to_string((unsigned long long)machine.get()); return result; } /* -std::string VMTExport4th::GetFullName(std::deque &call_stack,std::shared_ptr machine,size_t power){ - std::string result =""; +std::string VMTExport4th::GetFullName(std::deque +&call_stack,std::shared_ptr machine,size_t power){ std::string +result =""; for(std::string s:call_stack) result+=s+":"; @@ -209,195 +212,227 @@ std::string VMTExport4th::GetFullName(std::deque &call_stack,std::s return result; }*/ -void VMTExport4th::MapState(size_t& index,std::string prefix,std::deque &call_stack,std::shared_ptr complex,std::map& state_index,IVMTEnvironment *environment){ +void VMTExport4th::MapState(size_t& index, std::string prefix, + std::deque& call_stack, + std::shared_ptr complex, + std::map& state_index, + IVMTEnvironment* environment) { call_stack.push_back(std::to_string((unsigned long long)complex.get())); - std::string new_prefix = GetFullName(prefix,complex); - for(auto m: complex->GetMachineCollection()){ - std::string full_name = GetFullName(new_prefix,m); - state_index[full_name]=index++; - qDebug() << (index-1) << " = " << full_name.c_str(); - if(auto current_complex=std::dynamic_pointer_cast(m)){ - MapState(index,new_prefix,call_stack,current_complex,state_index,environment); - } else { - switch(m->GetID()){ + std::string new_prefix = GetFullName(prefix, complex); + for (auto m : complex->GetMachineCollection()) { + std::string full_name = GetFullName(new_prefix, m); + state_index[full_name] = index++; + qDebug() << (index - 1) << " = " << full_name.c_str(); + if (auto current_complex = + std::dynamic_pointer_cast(m)) { + MapState(index, new_prefix, call_stack, current_complex, + state_index, environment); + } else { + switch (m->GetID()) { case IVMTMachine::MachineType::MT_RIGHT_WORD: case IVMTMachine::MachineType::MT_LEFT_WORD: - case IVMTMachine::MachineType::MT_COPY:{ + case IVMTMachine::MachineType::MT_COPY: { std::shared_ptr current_complex = - std::dynamic_pointer_cast(m->CreateComplexMachine(environment)); - MapState(index,new_prefix,call_stack,current_complex,state_index,environment); + std::dynamic_pointer_cast( + m->CreateComplexMachine(environment)); + MapState(index, new_prefix, call_stack, current_complex, + state_index, environment); break; } - } } - - + } } call_stack.pop_back(); } -void VMTExport4th::ProcessComplex(size_t parent_index, - std::string prefix, - std::deque &call_stack, - std::shared_ptr complex, - std::map& state_index, - IVMTEnvironment *environment){ - std::set> machine_set; +void VMTExport4th::ProcessComplex(size_t parent_index, std::string prefix, + std::deque& call_stack, + std::shared_ptr complex, + std::map& state_index, + IVMTEnvironment* environment) { + std::set> machine_set; std::shared_ptr start_machine = nullptr; - std::string full_name = GetFullName(prefix,complex); + std::string full_name = GetFullName(prefix, complex); - for(auto m: complex->GetMachineCollection()) - if(m->GetID()==IVMTMachine::MachineType::MT_START) start_machine = m; + for (auto m : complex->GetMachineCollection()) + if (m->GetID() == IVMTMachine::MachineType::MT_START) start_machine = m; - - if(start_machine){ + if (start_machine) { call_stack.push_back(std::to_string((unsigned long long)complex.get())); - qDebug() << "Begin complex machine:" << complex->GetMachineName()+" ,"+QString(std::to_string((unsigned long long)complex.get()).c_str()); - Process(parent_index,full_name,call_stack,start_machine,state_index,machine_set,environment); - - if(call_stack.size()==1){ + qDebug() << "Begin complex machine:" + << complex->GetMachineName() + " ," + + QString( + std::to_string((unsigned long long)complex.get()) + .c_str()); + Process(parent_index, full_name, call_stack, start_machine, state_index, + machine_set, environment); + + if (call_stack.size() == 1) { std::shared_ptr end_machine = nullptr; - for(auto m: complex->GetMachineCollection()) - if(m->GetID()==IVMTMachine::MachineType::MT_FINISH) - { - end_machine = m; - QString str = complex->GetAlphabit()->ToString(); - size_t index_start = state_index[GetFullName(full_name,end_machine)];//GetFullName(call_stack,end_machine)]; - - for(QChar c:str) - _callback->AppendText(FormatString(index_start,c,c,index_start)); - } + for (auto m : complex->GetMachineCollection()) + if (m->GetID() == IVMTMachine::MachineType::MT_FINISH) { + end_machine = m; + QString str = complex->GetAlphabit()->ToString(); + size_t index_start = state_index[GetFullName( + full_name, + end_machine)]; // GetFullName(call_stack,end_machine)]; + + for (QChar c : str) + _callback->AppendText( + FormatString(index_start, c, c, index_start)); + } } call_stack.pop_back(); qDebug() << "End complex machine:" << complex->GetMachineName(); } } -void VMTExport4th::Process(size_t parent_index, - std::string prefix, - std::deque &call_stack, - std::shared_ptr current, - std::map& state_index, - std::set> &machine_set, - IVMTEnvironment *environment){ - +void VMTExport4th::Process(size_t parent_index, std::string prefix, + std::deque& call_stack, + std::shared_ptr current, + std::map& state_index, + std::set>& machine_set, + IVMTEnvironment* environment) { machine_set.insert(current); - std::string full_name = GetFullName(prefix,current); + std::string full_name = GetFullName(prefix, current); size_t index = state_index[full_name]; - qDebug() << "Process: Index: "<< index <<" , full_name:"<< full_name.c_str(); + qDebug() << "Process: Index: " << index + << " , full_name:" << full_name.c_str(); - for(auto l : current->GetIncomingTransitions()) - if(std::shared_ptr lptr = l.lock()){ + for (auto l : current->GetIncomingTransitions()) + if (std::shared_ptr lptr = l.lock()) { auto mptr = lptr->GetStartMachine().lock(); - std::string incoming_name = GetFullName(prefix,mptr); // whate power??? + std::string incoming_name = + GetFullName(prefix, mptr); // whate power??? size_t index_start = state_index[incoming_name]; - switch(mptr->GetID()){ - case IVMTMachine::MachineType::MT_START: - if(parent_index){ - qDebug() << "Replace index: " << index_start << " to parent:" << parent_index; - index_start = parent_index; - } - break; - // if left machine is complex - then change index to finish machine of complex - case IVMTMachine::MachineType::MT_COMPLEX: - case IVMTMachine::MachineType::MT_LEFT_WORD: - case IVMTMachine::MachineType::MT_RIGHT_WORD: - case IVMTMachine::MachineType::MT_COPY: - std::shared_ptr left_complex = std::dynamic_pointer_cast(mptr); - if(!left_complex) left_complex = std::dynamic_pointer_cast(mptr->CreateComplexMachine(environment)); - if(left_complex){ - std::shared_ptr finish_machine = nullptr; - for(auto m: left_complex->GetMachineCollection()) - if(m->GetID()==IVMTMachine::MachineType::MT_FINISH) finish_machine = m; - - call_stack.push_back(std::to_string((unsigned long long)left_complex.get())); - std::string complex_name = GetFullName(prefix,left_complex); - size_t finish_index = state_index[GetFullName(complex_name,finish_machine)]; // add complex machine!!!! - call_stack.pop_back(); - qDebug() << "Replace index: " << index_start << " to parent:" << finish_index; - index_start = finish_index; - } - break; + switch (mptr->GetID()) { + case IVMTMachine::MachineType::MT_START: + if (parent_index) { + qDebug() << "Replace index: " << index_start + << " to parent:" << parent_index; + index_start = parent_index; + } + break; + // if left machine is complex - then change index to finish + // machine of complex + case IVMTMachine::MachineType::MT_COMPLEX: + case IVMTMachine::MachineType::MT_LEFT_WORD: + case IVMTMachine::MachineType::MT_RIGHT_WORD: + case IVMTMachine::MachineType::MT_COPY: + std::shared_ptr left_complex = + std::dynamic_pointer_cast(mptr); + if (!left_complex) + left_complex = + std::dynamic_pointer_cast( + mptr->CreateComplexMachine(environment)); + if (left_complex) { + std::shared_ptr finish_machine = nullptr; + for (auto m : left_complex->GetMachineCollection()) + if (m->GetID() == + IVMTMachine::MachineType::MT_FINISH) + finish_machine = m; + + call_stack.push_back(std::to_string( + (unsigned long long)left_complex.get())); + std::string complex_name = + GetFullName(prefix, left_complex); + size_t finish_index = state_index[GetFullName( + complex_name, + finish_machine)]; // add complex machine!!!! + call_stack.pop_back(); + qDebug() << "Replace index: " << index_start + << " to parent:" << finish_index; + index_start = finish_index; + } + break; } - QString condition = lptr->GetConditions().GetAsString(); - qDebug() << "start machine:" << index_start << " end machine:" << index << " [" <GetID()){ - case IVMTMachine::MachineType::MT_LEFT: - for(auto c: condition) - _callback->AppendText(FormatString(index_start,c,Command::left,index)); - break; - case IVMTMachine::MachineType::MT_RIGHT: - for(auto c: condition) - _callback->AppendText(FormatString(index_start,c,Command::right,index)); - break; - case IVMTMachine::MachineType::MT_LEFT_WORD: - case IVMTMachine::MachineType::MT_RIGHT_WORD: - case IVMTMachine::MachineType::MT_COPY: - case IVMTMachine::MachineType::MT_COMPLEX: - { - for(auto c: condition) - _callback->AppendText(FormatString(index_start,c,c,index)); - break; - } - case IVMTMachine::MachineType::MT_WRITE:{ - std::shared_ptr ma = std::dynamic_pointer_cast(current); - - if(!ma) { - _error = true; - _error_message = "Error: Pointer cast error"; - AddInformation(QString("Error: Pointer cast error\r\n")); + qDebug() << "start machine:" << index_start + << " end machine:" << index << " [" << condition << "] " + << (lptr.get()); + + switch (current->GetID()) { + case IVMTMachine::MachineType::MT_LEFT: + for (auto c : condition) + _callback->AppendText( + FormatString(index_start, c, Command::left, index)); + break; + case IVMTMachine::MachineType::MT_RIGHT: + for (auto c : condition) + _callback->AppendText(FormatString( + index_start, c, Command::right, index)); + break; + case IVMTMachine::MachineType::MT_LEFT_WORD: + case IVMTMachine::MachineType::MT_RIGHT_WORD: + case IVMTMachine::MachineType::MT_COPY: + case IVMTMachine::MachineType::MT_COMPLEX: { + for (auto c : condition) + _callback->AppendText( + FormatString(index_start, c, c, index)); + break; } + case IVMTMachine::MachineType::MT_WRITE: { + std::shared_ptr ma = + std::dynamic_pointer_cast(current); + + if (!ma) { + _error = true; + _error_message = "Error: Pointer cast error"; + AddInformation( + QString("Error: Pointer cast error\r\n")); + } + for (auto c : condition) + _callback->AppendText( + FormatString(index_start, c, ma->GetSign(), index)); - for(auto c: condition) - _callback->AppendText(FormatString(index_start,c,ma->GetSign(),index)); - - break; - } - case IVMTMachine::MachineType::MT_START:{ - QString str = current->GetParent().lock()->GetAlphabit()->ToString(); - for(QChar c:str) - _callback->AppendText(FormatString(index_start,c,c,index)); - break; - } - case IVMTMachine::MachineType::MT_FINISH: - if(parent_index){ - for(auto c: condition) - _callback->AppendText(FormatString(index_start,c,c,index)); - } else - for(auto c: condition) - _callback->AppendText(FormatString(index_start,c,Command::stop,index)); - break; + break; + } + case IVMTMachine::MachineType::MT_START: { + QString str = + current->GetParent().lock()->GetAlphabit()->ToString(); + for (QChar c : str) + _callback->AppendText( + FormatString(index_start, c, c, index)); + break; + } + case IVMTMachine::MachineType::MT_FINISH: + if (parent_index) { + for (auto c : condition) + _callback->AppendText( + FormatString(index_start, c, c, index)); + } else + for (auto c : condition) + _callback->AppendText(FormatString( + index_start, c, Command::stop, index)); + break; } } - // check for complex - //* - std::shared_ptr current_complex = std::dynamic_pointer_cast(current); - if(!current_complex) current_complex = std::dynamic_pointer_cast(current->CreateComplexMachine(environment)); - if(current_complex){ - ProcessComplex(index,prefix,call_stack,current_complex,state_index,environment); - } - //*/ - - // check for outgoing connection - for(std::weak_ptr link:current->GetOutgoingTransitions()){ - std::shared_ptr link_ptr = link.lock(); - std::shared_ptr m = link_ptr->GetFinishMachine().lock(); - if(!machine_set.count(m)) - Process(parent_index,prefix,call_stack,link_ptr->GetFinishMachine().lock(),state_index,machine_set,environment); - } - - - -} - - -VMTExport4th::~VMTExport4th(){ - Stop(); + // check for complex + //* + std::shared_ptr current_complex = + std::dynamic_pointer_cast(current); + if (!current_complex) + current_complex = std::dynamic_pointer_cast( + current->CreateComplexMachine(environment)); + if (current_complex) { + ProcessComplex(index, prefix, call_stack, current_complex, state_index, + environment); + } + //*/ + + // check for outgoing connection + for (std::weak_ptr link : + current->GetOutgoingTransitions()) { + std::shared_ptr link_ptr = link.lock(); + std::shared_ptr m = link_ptr->GetFinishMachine().lock(); + if (!machine_set.count(m)) + Process(parent_index, prefix, call_stack, + link_ptr->GetFinishMachine().lock(), state_index, + machine_set, environment); + } } - +VMTExport4th::~VMTExport4th() { Stop(); } diff --git a/VirtualTuringMachine/vmtexport4th/vmtexport4th.h b/VirtualTuringMachine/vmtexport4th/vmtexport4th.h old mode 100755 new mode 100644 index 4a0e560..1c47566 --- a/VirtualTuringMachine/vmtexport4th/vmtexport4th.h +++ b/VirtualTuringMachine/vmtexport4th/vmtexport4th.h @@ -1,41 +1,39 @@ #ifndef VMTEXPORT4TH_H #define VMTEXPORT4TH_H -#include -#include -#include -#include +#include +#include #include +#include #include +#include +#include +#include #include -#include +#include #include -#include -#include + #include "interfaces/IVMTEnvironment.h" class VMTComplexMachine; class IVMTMachine; -class TextCallback{ -public: +class TextCallback { + public: virtual ~TextCallback() = default; virtual void Done() = 0; virtual void Clear() = 0; - virtual void AppendText(const QString &text) = 0; - virtual void Information(const QString &text) = 0; + virtual void AppendText(const QString& text) = 0; + virtual void Information(const QString& text) = 0; }; -class VMTExport4th -{ -protected: - enum Command{ - left,right,stop - }; +class VMTExport4th { + protected: + enum Command { left, right, stop }; std::mutex _mtx; - size_t _progress; - bool _can_run; - std::shared_ptr _thread; + size_t _progress; + bool _can_run; + std::shared_ptr _thread; std::shared_ptr _machine; QString _delimiter; @@ -44,59 +42,56 @@ class VMTExport4th QString _stop; QString _quotes; - bool _error; - QString _error_message; - QString _information; - QString _output; - size_t _machine_count; - - TextCallback *_callback; - - void AddInformation(QString && str); - QString FormatString(size_t state,QChar c,Command cmd,size_t state2); - QString FormatString(size_t state,QChar c,QString write,size_t state2); - - void MapState(size_t& index, - std::string prefix, - std::deque &call_stack, - std::shared_ptr complex, - std::map& state_index, - IVMTEnvironment *environment); - - // std::string GetFullName(std::deque &call_stack,std::shared_ptr machine,size_t power); - std::string GetFullName(std::string prefix,std::shared_ptr machine); - void Process(size_t parent_index, - std::string prefix, - std::deque &call_stack, - std::shared_ptr current, - std::map& state_index, - std::set> &machine_set, - IVMTEnvironment *environment); - - void ProcessComplex(size_t parent_index, - std::string prefix, - std::deque &call_stack, - std::shared_ptr complex, - std::map& state_index, - IVMTEnvironment *environment); - - -public: - VMTExport4th(std::shared_ptr machine, - QString delimiter, QString left, QString right, QString stop, QString quotes); - void Export(TextCallback *_callback,IVMTEnvironment *environment); - size_t GetProgress(); - bool IsRuning(); - void Stop(); - - - bool IsError(); - const QString GetErrorMessage(); - const QString GetInformation(); - size_t GetMachineCount(); - - void operator()(IVMTEnvironment *environment); + bool _error; + QString _error_message; + QString _information; + QString _output; + size_t _machine_count; + + TextCallback* _callback; + + void AddInformation(QString&& str); + QString FormatString(size_t state, QChar c, Command cmd, size_t state2); + QString FormatString(size_t state, QChar c, QString write, size_t state2); + + void MapState(size_t& index, std::string prefix, + std::deque& call_stack, + std::shared_ptr complex, + std::map& state_index, + IVMTEnvironment* environment); + + // std::string GetFullName(std::deque + // &call_stack,std::shared_ptr machine,size_t power); + std::string GetFullName(std::string prefix, + std::shared_ptr machine); + void Process(size_t parent_index, std::string prefix, + std::deque& call_stack, + std::shared_ptr current, + std::map& state_index, + std::set>& machine_set, + IVMTEnvironment* environment); + + void ProcessComplex(size_t parent_index, std::string prefix, + std::deque& call_stack, + std::shared_ptr complex, + std::map& state_index, + IVMTEnvironment* environment); + + public: + VMTExport4th(std::shared_ptr machine, QString delimiter, + QString left, QString right, QString stop, QString quotes); + void Export(TextCallback* _callback, IVMTEnvironment* environment); + size_t GetProgress(); + bool IsRuning(); + void Stop(); + + bool IsError(); + const QString GetErrorMessage(); + const QString GetInformation(); + size_t GetMachineCount(); + + void operator()(IVMTEnvironment* environment); virtual ~VMTExport4th(); }; -#endif // VMTEXPORT4TH_H +#endif // VMTEXPORT4TH_H diff --git a/VirtualTuringMachine/vmtexportplantuml/vmtexportplantuml.cpp b/VirtualTuringMachine/vmtexportplantuml/vmtexportplantuml.cpp index 281a98a..78068b9 100644 --- a/VirtualTuringMachine/vmtexportplantuml/vmtexportplantuml.cpp +++ b/VirtualTuringMachine/vmtexportplantuml/vmtexportplantuml.cpp @@ -1,18 +1,17 @@ #include "vmtexportplantuml.h" +#include +#include + #include "VMTTransitionConditions.h" #include "interfaces/IVMTTransition.h" #include "vmtmachines/VMTComplexMachine.h" #include "vmtmachines/VMTComplexMachineInner.h" #include "vmtmachines/VMTMachineAlpha.h" -#include -#include - namespace { -QString escapePlantumlLabel(const QString& label) -{ +QString escapePlantumlLabel(const QString& label) { QString escaped = label; escaped.replace(QLatin1String("\\"), QLatin1String("\\\\")); escaped.replace(QLatin1String("\""), QLatin1String("\\\"")); @@ -21,8 +20,7 @@ QString escapePlantumlLabel(const QString& label) return escaped; } -QString makeUniqueAlias(const QString& base, QHash& usage) -{ +QString makeUniqueAlias(const QString& base, QHash& usage) { QString alias = base; if (alias.isEmpty()) { alias = QStringLiteral("state"); @@ -38,8 +36,7 @@ QString makeUniqueAlias(const QString& base, QHash& usage) return alias; } -QString sanitizeAliasBase(const QString& raw) -{ +QString sanitizeAliasBase(const QString& raw) { QString alias; alias.reserve(raw.size()); for (const QChar ch : raw) { @@ -59,25 +56,25 @@ QString sanitizeAliasBase(const QString& raw) return alias; } -QString machineDisplayName(const std::shared_ptr& machine) -{ +QString machineDisplayName(const std::shared_ptr& machine) { if (!machine) { return QStringLiteral("unknown"); } switch (machine->GetID()) { - case IVMTMachine::MachineType::MT_START: - return QStringLiteral("start"); - case IVMTMachine::MachineType::MT_FINISH: - return QStringLiteral("finish"); - case IVMTMachine::MachineType::MT_WRITE: { - if (auto alpha = std::dynamic_pointer_cast(machine)) { - return QStringLiteral("Ī»(%1)").arg(alpha->GetSign()); + case IVMTMachine::MachineType::MT_START: + return QStringLiteral("start"); + case IVMTMachine::MachineType::MT_FINISH: + return QStringLiteral("finish"); + case IVMTMachine::MachineType::MT_WRITE: { + if (auto alpha = + std::dynamic_pointer_cast(machine)) { + return QStringLiteral("Ī»(%1)").arg(alpha->GetSign()); + } + return QStringLiteral("write"); } - return QStringLiteral("write"); - } - default: - break; + default: + break; } const QString name = machine->GetName(); @@ -87,16 +84,11 @@ QString machineDisplayName(const std::shared_ptr& machine) return QStringLiteral("machine"); } -class PlantUmlBuilder -{ -public: - explicit PlantUmlBuilder(QTextStream& out) - : _out(out) - { - } +class PlantUmlBuilder { + public: + explicit PlantUmlBuilder(QTextStream& out) : _out(out) {} - void exportComplexMachine(VMTComplexMachine& machine) - { + void exportComplexMachine(VMTComplexMachine& machine) { _out << "@startuml\n"; _out << "!theme plain\n"; _out << "hide empty description\n"; @@ -114,50 +106,57 @@ class PlantUmlBuilder _out << "@enduml\n"; } -private: - void exportScope(VMTComplexMachineInner& scope, const QString& indent) - { + private: + void exportScope(VMTComplexMachineInner& scope, const QString& indent) { QHash aliasUsage; QHash machineAliases; - for (const std::shared_ptr& machine : scope.GetMachineCollection()) { + for (const std::shared_ptr& machine : + scope.GetMachineCollection()) { if (!machine) { continue; } - if (machine->GetID() == IVMTMachine::MachineType::MT_START - || machine->GetID() == IVMTMachine::MachineType::MT_FINISH) { + if (machine->GetID() == IVMTMachine::MachineType::MT_START || + machine->GetID() == IVMTMachine::MachineType::MT_FINISH) { continue; } if (machine->GetID() == IVMTMachine::MachineType::MT_COMPLEX) { - auto complex = std::dynamic_pointer_cast(machine); + auto complex = + std::dynamic_pointer_cast(machine); if (!complex) { continue; } const QString display = machineDisplayName(machine); - const QString alias = makeUniqueAlias(sanitizeAliasBase(display), aliasUsage); + const QString alias = + makeUniqueAlias(sanitizeAliasBase(display), aliasUsage); machineAliases.insert(machine.get(), alias); - _out << indent << "state \"" << escapePlantumlLabel(display) << "\" as " << alias << " {\n"; + _out << indent << "state \"" << escapePlantumlLabel(display) + << "\" as " << alias << " {\n"; if (complex->GetInnerObject()) { - exportScope(*complex->GetInnerObject(), indent + QStringLiteral(" ")); + exportScope(*complex->GetInnerObject(), + indent + QStringLiteral(" ")); } _out << indent << "}\n"; continue; } const QString display = machineDisplayName(machine); - const QString alias = makeUniqueAlias(sanitizeAliasBase(display), aliasUsage); + const QString alias = + makeUniqueAlias(sanitizeAliasBase(display), aliasUsage); machineAliases.insert(machine.get(), alias); - _out << indent << "state \"" << escapePlantumlLabel(display) << "\" as " << alias << "\n"; + _out << indent << "state \"" << escapePlantumlLabel(display) + << "\" as " << alias << "\n"; } if (!scope.GetTransitionCollection().empty()) { _out << "\n"; } - for (const std::shared_ptr& transition : scope.GetTransitionCollection()) { + for (const std::shared_ptr& transition : + scope.GetTransitionCollection()) { if (!transition) { continue; } @@ -192,14 +191,13 @@ class PlantUmlBuilder } QString stateRef(const std::shared_ptr& machine, - const QHash& aliases) const - { + const QHash& aliases) const { if (!machine) { return QString(); } - if (machine->GetID() == IVMTMachine::MachineType::MT_START - || machine->GetID() == IVMTMachine::MachineType::MT_FINISH) { + if (machine->GetID() == IVMTMachine::MachineType::MT_START || + machine->GetID() == IVMTMachine::MachineType::MT_FINISH) { return QStringLiteral("[*]"); } @@ -209,10 +207,9 @@ class PlantUmlBuilder QTextStream& _out; }; -} // namespace +} // namespace -QString VmtExportPlantUml::exportStateMachine(VMTComplexMachine& machine) -{ +QString VmtExportPlantUml::exportStateMachine(VMTComplexMachine& machine) { QString result; QTextStream stream(&result); PlantUmlBuilder builder(stream); diff --git a/VirtualTuringMachine/vmtexportplantuml/vmtexportplantuml.h b/VirtualTuringMachine/vmtexportplantuml/vmtexportplantuml.h index 57c87ad..c362a6b 100644 --- a/VirtualTuringMachine/vmtexportplantuml/vmtexportplantuml.h +++ b/VirtualTuringMachine/vmtexportplantuml/vmtexportplantuml.h @@ -5,10 +5,9 @@ class VMTComplexMachine; -class VmtExportPlantUml -{ -public: +class VmtExportPlantUml { + public: static QString exportStateMachine(VMTComplexMachine& machine); }; -#endif // VMTEXPORTPLANTUML_H +#endif // VMTEXPORTPLANTUML_H diff --git a/VirtualTuringMachine/vmticons.cpp b/VirtualTuringMachine/vmticons.cpp index 743d0c7..368d182 100644 --- a/VirtualTuringMachine/vmticons.cpp +++ b/VirtualTuringMachine/vmticons.cpp @@ -1,47 +1,56 @@ #include "vmticons.h" -#include "formeditormachine.h" -#include "vmttheme.h" - #include #include #include #include #include #include - #include +#include "formeditormachine.h" +#include "vmttheme.h" + namespace { -QString pathOrEmpty(const char* path) -{ +QString pathOrEmpty(const char* path) { return path ? QString::fromUtf8(path) : QString(); } -const QHash& editorToolChromePaths() -{ +const QHash& editorToolChromePaths() { static const QHash map = { - {QStringLiteral("tool_pointer"), ":/Files/images/toolbars/tools/icon_arrow.gif"}, - {QStringLiteral("tool_link"), ":/Files/images/toolbars/tools/icon_link.gif"}, - {QStringLiteral("tool_translate"), ":/Files/images/toolbars/tools/icon_hand.gif"}, - {QStringLiteral("tool_trash"), ":/Files/images/toolbars/tools/icon_delete.gif"}, - {QStringLiteral("tool_machine_start"), ":/images/toolbars/tools/icon_start.png"}, - {QStringLiteral("tool_machine_finish"), ":/images/toolbars/tools/icon_finish.png"}, - {QStringLiteral("tool_machine_left"), ":/Files/images/toolbars/tools/icon_l_small.gif"}, - {QStringLiteral("tool_machine_right"), ":/Files/images/toolbars/tools/icon_r_small.gif"}, - {QStringLiteral("tool_machine_left_word"), ":/Files/images/toolbars/tools/icon_l_big.gif"}, - {QStringLiteral("tool_machine_right_word"), ":/Files/images/toolbars/tools/icon_r_big.gif"}, - {QStringLiteral("tool_machine_lambda"), ":/Files/images/toolbars/tools/icon_lambda.gif"}, - {QStringLiteral("tool_machine_copy"), ":/Files/images/toolbars/tools/icon_k.gif"}, - {QStringLiteral("tool_complex"), ":/Files/images/toolbars/tools/icon_complex.gif"}, + {QStringLiteral("tool_pointer"), + ":/Files/images/toolbars/tools/icon_arrow.gif"}, + {QStringLiteral("tool_link"), + ":/Files/images/toolbars/tools/icon_link.gif"}, + {QStringLiteral("tool_translate"), + ":/Files/images/toolbars/tools/icon_hand.gif"}, + {QStringLiteral("tool_trash"), + ":/Files/images/toolbars/tools/icon_delete.gif"}, + {QStringLiteral("tool_machine_start"), + ":/images/toolbars/tools/icon_start.png"}, + {QStringLiteral("tool_machine_finish"), + ":/images/toolbars/tools/icon_finish.png"}, + {QStringLiteral("tool_machine_left"), + ":/Files/images/toolbars/tools/icon_l_small.gif"}, + {QStringLiteral("tool_machine_right"), + ":/Files/images/toolbars/tools/icon_r_small.gif"}, + {QStringLiteral("tool_machine_left_word"), + ":/Files/images/toolbars/tools/icon_l_big.gif"}, + {QStringLiteral("tool_machine_right_word"), + ":/Files/images/toolbars/tools/icon_r_big.gif"}, + {QStringLiteral("tool_machine_lambda"), + ":/Files/images/toolbars/tools/icon_lambda.gif"}, + {QStringLiteral("tool_machine_copy"), + ":/Files/images/toolbars/tools/icon_k.gif"}, + {QStringLiteral("tool_complex"), + ":/Files/images/toolbars/tools/icon_complex.gif"}, {QStringLiteral("_navi"), ":/Files/images/nav.png"}, }; return map; } -void refreshEditorToolbars(QWidget* root) -{ +void refreshEditorToolbars(QWidget* root) { for (QFrame* frame : root->findChildren()) { if (frame->objectName() != QLatin1String("tool_frame")) { continue; @@ -55,83 +64,77 @@ void refreshEditorToolbars(QWidget* root) } } -} // namespace +} // namespace -QString VmtIcons::pick(const char* lightSurfacePath, const char* darkSurfacePath) -{ - return VmtTheme::isDarkMode() ? pathOrEmpty(darkSurfacePath) : pathOrEmpty(lightSurfacePath); +QString VmtIcons::pick(const char* lightSurfacePath, + const char* darkSurfacePath) { + return VmtTheme::isDarkMode() ? pathOrEmpty(darkSurfacePath) + : pathOrEmpty(lightSurfacePath); } -QIcon VmtIcons::iconForSurface(const char* lightSurfacePath, const char* darkSurfacePath) -{ +QIcon VmtIcons::iconForSurface(const char* lightSurfacePath, + const char* darkSurfacePath) { return QIcon(pick(lightSurfacePath, darkSurfacePath)); } -QPixmap VmtIcons::pixmapForSurface(const char* lightSurfacePath, const char* darkSurfacePath) -{ +QPixmap VmtIcons::pixmapForSurface(const char* lightSurfacePath, + const char* darkSurfacePath) { return QPixmap(pick(lightSurfacePath, darkSurfacePath)); } -QString VmtIcons::toolbarChromePath(const char* path) -{ +QString VmtIcons::toolbarChromePath(const char* path) { return pathOrEmpty(path); } -QString VmtIcons::machinePath(ImageType type) -{ +QString VmtIcons::machinePath(ImageType type) { switch (type) { - case MACHINE_LAMBDA: - return pick(":/Files/images/toolbars/tools/icon_lambda_black.gif", - ":/Files/images/toolbars/tools/icon_lambda.gif"); - case MACHINE_START: - return pick(":/Files/images/toolbars/tools/icon_start_black.png", - ":/images/toolbars/tools/icon_start.png"); - case MACHINE_FINISH: - return pick(":/Files/images/toolbars/tools/icon_finish_black.png", - ":/images/toolbars/tools/icon_finish.png"); - case MACHINE_LEFT: - return pick(":/Files/images/toolbars/tools/icon_l_small_black.gif", - ":/Files/images/toolbars/tools/icon_l_small.gif"); - case MACHINE_RIGHT: - return pick(":/Files/images/toolbars/tools/icon_r_small_black.gif", - ":/Files/images/toolbars/tools/icon_r_small.gif"); - case MACHINE_LEFT_WORD: - return pick(":/Files/images/toolbars/tools/icon_l_big_black.gif", - ":/Files/images/toolbars/tools/icon_l_big.gif"); - case MACHINE_RIGHT_WORD: - return pick(":/Files/images/toolbars/tools/icon_r_big_black.gif", - ":/Files/images/toolbars/tools/icon_r_big.gif"); - case MACHINE_COPY: - return pick(":/Files/images/toolbars/tools/icon_k_black.gif", - ":/Files/images/toolbars/tools/icon_k.gif"); - case CANCEL: - return QStringLiteral(":/Files/images/cancel.png"); - case MACHINE_COMPLEX: - return pick(":/Files/images/machine_complex.gif", - ":/Files/images/toolbars/tools/icon_complex.gif"); - case LINK: - return pick(":/Files/images/toolbars/tools/icon_link_black.png", - ":/Files/images/toolbars/tools/icon_link.gif"); - case NAVIGATION_CIRCLE: - return QStringLiteral(":/Files/images/circle.png"); - default: - return QString(); + case MACHINE_LAMBDA: + return pick(":/Files/images/toolbars/tools/icon_lambda_black.gif", + ":/Files/images/toolbars/tools/icon_lambda.gif"); + case MACHINE_START: + return pick(":/Files/images/toolbars/tools/icon_start_black.png", + ":/images/toolbars/tools/icon_start.png"); + case MACHINE_FINISH: + return pick(":/Files/images/toolbars/tools/icon_finish_black.png", + ":/images/toolbars/tools/icon_finish.png"); + case MACHINE_LEFT: + return pick(":/Files/images/toolbars/tools/icon_l_small_black.gif", + ":/Files/images/toolbars/tools/icon_l_small.gif"); + case MACHINE_RIGHT: + return pick(":/Files/images/toolbars/tools/icon_r_small_black.gif", + ":/Files/images/toolbars/tools/icon_r_small.gif"); + case MACHINE_LEFT_WORD: + return pick(":/Files/images/toolbars/tools/icon_l_big_black.gif", + ":/Files/images/toolbars/tools/icon_l_big.gif"); + case MACHINE_RIGHT_WORD: + return pick(":/Files/images/toolbars/tools/icon_r_big_black.gif", + ":/Files/images/toolbars/tools/icon_r_big.gif"); + case MACHINE_COPY: + return pick(":/Files/images/toolbars/tools/icon_k_black.gif", + ":/Files/images/toolbars/tools/icon_k.gif"); + case CANCEL: + return QStringLiteral(":/Files/images/cancel.png"); + case MACHINE_COMPLEX: + return pick(":/Files/images/machine_complex.gif", + ":/Files/images/toolbars/tools/icon_complex.gif"); + case LINK: + return pick(":/Files/images/toolbars/tools/icon_link_black.png", + ":/Files/images/toolbars/tools/icon_link.gif"); + case NAVIGATION_CIRCLE: + return QStringLiteral(":/Files/images/circle.png"); + default: + return QString(); } } -QPixmap VmtIcons::machinePixmap(ImageType type) -{ +QPixmap VmtIcons::machinePixmap(ImageType type) { const QString path = machinePath(type); return path.isEmpty() ? QPixmap() : QPixmap(path); } -QIcon VmtIcons::machineIcon(ImageType type) -{ - return QIcon(machinePath(type)); -} +QIcon VmtIcons::machineIcon(ImageType type) { return QIcon(machinePath(type)); } -QString VmtIcons::editorToolPath(const QString& objectName) -{ +QString VmtIcons::editorToolPath(const QString& objectName) { const auto& map = editorToolChromePaths(); const auto it = map.find(objectName); if (it == map.end()) { @@ -140,58 +143,51 @@ QString VmtIcons::editorToolPath(const QString& objectName) return toolbarChromePath(it.value()); } -QPixmap VmtIcons::linkPixmap() -{ +QPixmap VmtIcons::linkPixmap() { return pixmapForSurface(":/Files/images/toolbars/tools/icon_link_black.png", - ":/Files/images/toolbars/tools/icon_link.gif"); + ":/Files/images/toolbars/tools/icon_link.gif"); } -QPixmap VmtIcons::deletePixmap() -{ - return pixmapForSurface(":/Files/images/toolbars/tools/icon_delete_black.png", - ":/Files/images/toolbars/tools/icon_delete.gif"); +QPixmap VmtIcons::deletePixmap() { + return pixmapForSurface( + ":/Files/images/toolbars/tools/icon_delete_black.png", + ":/Files/images/toolbars/tools/icon_delete.gif"); } -QPixmap VmtIcons::handPixmap() -{ +QPixmap VmtIcons::handPixmap() { return pixmapForSurface(":/Files/images/toolbars/tools/icon_hand_black.png", - ":/Files/images/toolbars/tools/icon_hand.gif"); + ":/Files/images/toolbars/tools/icon_hand.gif"); } -QPixmap VmtIcons::lambdaPixmap() -{ - return machinePixmap(MACHINE_LAMBDA); -} +QPixmap VmtIcons::lambdaPixmap() { return machinePixmap(MACHINE_LAMBDA); } -QPixmap VmtIcons::cancelPixmap() -{ +QPixmap VmtIcons::cancelPixmap() { return QPixmap(QStringLiteral(":/Files/images/cancel.png")); } -QPixmap VmtIcons::okPixmap() -{ - return pixmapForSurface(":/Files/images/ok_black.png", ":/Files/images/ok.png"); +QPixmap VmtIcons::okPixmap() { + return pixmapForSurface(":/Files/images/ok_black.png", + ":/Files/images/ok.png"); } -void VmtIcons::loadMachineIcons(std::vector& out) -{ +void VmtIcons::loadMachineIcons(std::vector& out) { for (QPixmap* pixmap : out) { delete pixmap; } out.clear(); const ImageType types[] = { - MACHINE_LAMBDA, MACHINE_START, MACHINE_FINISH, MACHINE_LEFT, MACHINE_RIGHT, - MACHINE_LEFT_WORD, MACHINE_RIGHT_WORD, MACHINE_COPY, CANCEL, MACHINE_COMPLEX, - LINK, NAVIGATION_CIRCLE, + MACHINE_LAMBDA, MACHINE_START, MACHINE_FINISH, + MACHINE_LEFT, MACHINE_RIGHT, MACHINE_LEFT_WORD, + MACHINE_RIGHT_WORD, MACHINE_COPY, CANCEL, + MACHINE_COMPLEX, LINK, NAVIGATION_CIRCLE, }; for (ImageType type : types) { out.push_back(new QPixmap(machinePath(type))); } } -void VmtIcons::refreshInterfaceIcons(QWidget* root) -{ +void VmtIcons::refreshInterfaceIcons(QWidget* root) { if (!root) { return; } diff --git a/VirtualTuringMachine/vmticons.h b/VirtualTuringMachine/vmticons.h index 95a726c..c548615 100644 --- a/VirtualTuringMachine/vmticons.h +++ b/VirtualTuringMachine/vmticons.h @@ -10,14 +10,16 @@ class QPixmap; class QWidget; /** Theme-aware icon paths (pairs for light / dark surfaces). */ -class VmtIcons -{ -public: +class VmtIcons { + public: /** Dark glyph on light UI; light glyph on dark UI (canvas, panels). */ - static QString pick(const char* lightSurfacePath, const char* darkSurfacePath); + static QString pick(const char* lightSurfacePath, + const char* darkSurfacePath); - static QIcon iconForSurface(const char* lightSurfacePath, const char* darkSurfacePath); - static QPixmap pixmapForSurface(const char* lightSurfacePath, const char* darkSurfacePath); + static QIcon iconForSurface(const char* lightSurfacePath, + const char* darkSurfacePath); + static QPixmap pixmapForSurface(const char* lightSurfacePath, + const char* darkSurfacePath); /** Colored icons for dark toolbar chrome (#012C40 / #01547a). */ static QString toolbarChromePath(const char* path); @@ -39,4 +41,4 @@ class VmtIcons static void refreshInterfaceIcons(QWidget* root); }; -#endif // VMTICONS_H +#endif // VMTICONS_H diff --git a/VirtualTuringMachine/vmtmachines/VMTComplexMachine.cpp b/VirtualTuringMachine/vmtmachines/VMTComplexMachine.cpp old mode 100755 new mode 100644 index fef5367..6c2c488 --- a/VirtualTuringMachine/vmtmachines/VMTComplexMachine.cpp +++ b/VirtualTuringMachine/vmtmachines/VMTComplexMachine.cpp @@ -1,53 +1,60 @@ #include "VMTComplexMachine.h" + #include -#include "vmtundoelementmachine.h" -#include "uicanvas.h" -#include "VMTTransitionImpl.h" #include -VMTComplexMachine::VMTComplexMachine(const QString& name, std::shared_ptr alphabit) : - VMTMachineStub(name,std::weak_ptr(),IVMTMachine::MachineType::MT_COMPLEX, ImageType::MACHINE_COMPLEX){ - _inner = std::shared_ptr(new VMTComplexMachineInner(alphabit)); +#include "VMTTransitionImpl.h" +#include "uicanvas.h" +#include "vmtundoelementmachine.h" + +VMTComplexMachine::VMTComplexMachine(const QString& name, + std::shared_ptr alphabit) + : VMTMachineStub(name, std::weak_ptr(), + IVMTMachine::MachineType::MT_COMPLEX, + ImageType::MACHINE_COMPLEX) { + _inner = std::shared_ptr( + new VMTComplexMachineInner(alphabit)); SetName(name); } -void VMTComplexMachine::DeselectAll(){ - for(std::shared_ptr m: this->GetMachineCollection()) +void VMTComplexMachine::DeselectAll() { + for (std::shared_ptr m : this->GetMachineCollection()) m->SetSelected(false); } -const QString VMTComplexMachine::GetNickName(){ - return _nick_name; -} +const QString VMTComplexMachine::GetNickName() { return _nick_name; } -void VMTComplexMachine::Update(IVMTEnvironment* environment){ - if(environment){ - QRect bounds; - _size = QPoint(VMTMachineStub::_st.GetCellSize().width()*GetNickName().size(),VMTMachineStub::_st.GetCellSize().height()); - // environment->GetGraphics().CalculateTextSize(GetNickName(),bounds); - //_size.rx() = bounds.width(); - //_size.ry() = bounds.height(); - _internal_bounds.setWidth(bounds.width()); - _internal_bounds.setHeight(bounds.height()); +void VMTComplexMachine::Update(IVMTEnvironment* environment) { + if (environment) { + QRect bounds; + _size = QPoint( + VMTMachineStub::_st.GetCellSize().width() * GetNickName().size(), + VMTMachineStub::_st.GetCellSize().height()); + // environment->GetGraphics().CalculateTextSize(GetNickName(),bounds); + //_size.rx() = bounds.width(); + //_size.ry() = bounds.height(); + _internal_bounds.setWidth(bounds.width()); + _internal_bounds.setHeight(bounds.height()); } - VMTMachineStub::Update(environment); + VMTMachineStub::Update(environment); - //if(environment) - // environment->Repaint(QRect()); + // if(environment) + // environment->Repaint(QRect()); } - -std::shared_ptr VMTComplexMachine::CreatePlainCopy(IVMTEnvironment* environment){ - - std::map,std::shared_ptr> mapping_first; - std::map,std::shared_ptr> mapping_last; +std::shared_ptr VMTComplexMachine::CreatePlainCopy( + IVMTEnvironment* environment) { + std::map, std::shared_ptr> + mapping_first; + std::map, std::shared_ptr> + mapping_last; std::shared_ptr result = - std::shared_ptr(new VMTComplexMachine(this->GetName(), - this->GetAlphabit())); - for(std::shared_ptr m: this->GetMachineCollection()){ + std::shared_ptr( + new VMTComplexMachine(this->GetName(), this->GetAlphabit())); + for (std::shared_ptr m : this->GetMachineCollection()) { std::shared_ptr m_copy = m->Clone(environment); result->AddMachine(m_copy); @@ -57,20 +64,22 @@ std::shared_ptr VMTComplexMachine::CreatePlainCopy(IVMTEnviro std::shared_ptr prev = m_copy; const long power = m_copy->GetPower(); - if(power > 1){ + if (power > 1) { m_copy->SetPower(1); QPoint center = m_copy->GetCenter(); - for(long i = 1; i < power; ++i){ - std::shared_ptr m_copy_k = m_copy->Clone(environment); - center.setY(center.y()+100); - m_copy_k->Move(center,environment); + for (long i = 1; i < power; ++i) { + std::shared_ptr m_copy_k = + m_copy->Clone(environment); + center.setY(center.y() + 100); + m_copy_k->Move(center, environment); result->AddMachine(m_copy_k); m_copy_k->Update(environment); - std::shared_ptr transition = std::make_shared(result); + std::shared_ptr transition = + std::make_shared(result); - transition->SetStart(environment,prev); - transition->SetFinish(environment,m_copy_k); + transition->SetStart(environment, prev); + transition->SetFinish(environment, m_copy_k); prev->AddOutgoingTransition(transition); m_copy_k->AddIncomingTransition(transition); @@ -83,23 +92,25 @@ std::shared_ptr VMTComplexMachine::CreatePlainCopy(IVMTEnviro } } - for(std::shared_ptr t: this->GetTransitionCollection()){ - std::shared_ptr t_new = std::make_shared(result); + for (std::shared_ptr t : this->GetTransitionCollection()) { + std::shared_ptr t_new = + std::make_shared(result); std::shared_ptr new_start; std::shared_ptr new_finish; - if(t->GetStartMachine().lock()){ + if (t->GetStartMachine().lock()) { std::shared_ptr m_start = t->GetStartMachine().lock(); new_start = mapping_last[m_start]; } - if(t->GetFinishMachine().lock()){ - std::shared_ptr m_finish = t->GetFinishMachine().lock(); + if (t->GetFinishMachine().lock()) { + std::shared_ptr m_finish = + t->GetFinishMachine().lock(); new_finish = mapping_first[m_finish]; } - t_new->SetStart(environment,new_start); - t_new->SetFinish(environment,new_finish); + t_new->SetStart(environment, new_start); + t_new->SetFinish(environment, new_finish); new_start->AddOutgoingTransition(t_new); new_finish->AddIncomingTransition(t_new); @@ -110,126 +121,137 @@ std::shared_ptr VMTComplexMachine::CreatePlainCopy(IVMTEnviro } return result; - } -std::shared_ptr VMTComplexMachine::Clone([[maybe_unused]] IVMTEnvironment* environment){ +std::shared_ptr VMTComplexMachine::Clone( + [[maybe_unused]] IVMTEnvironment* environment) { qDebug() << "VMTComplexMachine::Clone() Begin"; - std::shared_ptr result = - std::shared_ptr(new VMTComplexMachine(this->GetName(), - this->GetAlphabit())); - result->ReplaceMachine(this); - std::dynamic_pointer_cast(result)->_center = _center; - std::dynamic_pointer_cast(result)->_bounds = _bounds; - std::dynamic_pointer_cast(result)->_size = _size; - std::dynamic_pointer_cast(result)->_power = _power; - - return result; -} -VMTComplexMachine::VMTComplexMachine(const VMTComplexMachine &other) : -VMTMachineStub(other._name,other._parent,IVMTMachine::MachineType::MT_COMPLEX,ImageType::MACHINE_COMPLEX){ + std::shared_ptr result = + std::shared_ptr( + new VMTComplexMachine(this->GetName(), this->GetAlphabit())); + result->ReplaceMachine(this); + std::dynamic_pointer_cast(result)->_center = _center; + std::dynamic_pointer_cast(result)->_bounds = _bounds; + std::dynamic_pointer_cast(result)->_size = _size; + std::dynamic_pointer_cast(result)->_power = _power; + return result; } - -void VMTComplexMachine::CheckBounds(const QPoint &p,bool first){ - if(first){ - _bounds.moveLeft(p.x()); - _bounds.moveTop(p.y()); - } else { - if((_bounds.left()>p.x())) {_bounds.setLeft(p.x());} - if((_bounds.top()>p.y())) {_bounds.setTop(p.y());} +VMTComplexMachine::VMTComplexMachine(const VMTComplexMachine& other) + : VMTMachineStub(other._name, other._parent, + IVMTMachine::MachineType::MT_COMPLEX, + ImageType::MACHINE_COMPLEX) {} + +void VMTComplexMachine::CheckBounds(const QPoint& p, bool first) { + if (first) { + _bounds.moveLeft(p.x()); + _bounds.moveTop(p.y()); + } else { + if ((_bounds.left() > p.x())) { + _bounds.setLeft(p.x()); } + if ((_bounds.top() > p.y())) { + _bounds.setTop(p.y()); + } + } - if((_bounds.left()+_bounds.width()) m: _inner->GetMachineCollection()){ - CheckBounds(m->GetBounds().topLeft(),first); first=false; - CheckBounds(m->GetBounds().bottomRight(),first); - } + for (std::shared_ptr m : _inner->GetMachineCollection()) { + CheckBounds(m->GetBounds().topLeft(), first); + first = false; + CheckBounds(m->GetBounds().bottomRight(), first); + } - for(std::shared_ptr t: _inner->GetTransitionCollection()){ - CheckBounds(t->GetBounds().topLeft(),first); - CheckBounds(t->GetBounds().bottomRight(),first); - } + for (std::shared_ptr t : + _inner->GetTransitionCollection()) { + CheckBounds(t->GetBounds().topLeft(), first); + CheckBounds(t->GetBounds().bottomRight(), first); + } - return _bounds; + return _bounds; } -std::vector>& VMTComplexMachine::GetMachineCollection(){ +std::vector>& +VMTComplexMachine::GetMachineCollection() { return _inner->GetMachineCollection(); } -std::vector>& VMTComplexMachine::GetTransitionCollection(){ - return _inner->GetTransitionCollection(); +std::vector>& +VMTComplexMachine::GetTransitionCollection() { + return _inner->GetTransitionCollection(); } -void VMTComplexMachine::AddMachine(std::shared_ptr machine){ - if(_inner) - _inner->GetMachineCollection().push_back(machine); +void VMTComplexMachine::AddMachine(std::shared_ptr machine) { + if (_inner) _inner->GetMachineCollection().push_back(machine); } -void VMTComplexMachine::AddTransition(std::shared_ptr transition){ - if(_inner) - _inner->GetTransitionCollection().push_back(transition); - +void VMTComplexMachine::AddTransition( + std::shared_ptr transition) { + if (_inner) _inner->GetTransitionCollection().push_back(transition); } #include "VMTTransitionImpl.h" -std::shared_ptr VMTComplexMachine::ConnectMachines(std::shared_ptr first,std::shared_ptr second,IVMTEnvironment *environment,std::shared_ptr parent){ - - std::shared_ptr tr = std::shared_ptr(new VMTTransitionImpl(parent)); +std::shared_ptr VMTComplexMachine::ConnectMachines( + std::shared_ptr first, std::shared_ptr second, + IVMTEnvironment* environment, std::shared_ptr parent) { + std::shared_ptr tr = + std::shared_ptr(new VMTTransitionImpl(parent)); first->AddOutgoingTransition(tr); second->AddIncomingTransition(tr); - tr->SetStart(environment,first); - tr->SetFinish(environment,second); + tr->SetStart(environment, first); + tr->SetFinish(environment, second); parent->AddTransition(tr); return tr; } -void VMTComplexMachine::ChangeAlphabit(std::shared_ptr other){ - if(_inner) - _inner->ChangeAlphabit(other); +void VMTComplexMachine::ChangeAlphabit(std::shared_ptr other) { + if (_inner) _inner->ChangeAlphabit(other); } -std::weak_ptr VMTComplexMachine::FindMachine([[maybe_unused]] IVMTEnvironment* environment,const QPoint& point){ - - for(std::shared_ptr m : _inner->GetMachineCollection()) - { - if(m->IsInside(point)) return std::weak_ptr(m); +std::weak_ptr VMTComplexMachine::FindMachine( + [[maybe_unused]] IVMTEnvironment* environment, const QPoint& point) { + for (std::shared_ptr m : _inner->GetMachineCollection()) { + if (m->IsInside(point)) return std::weak_ptr(m); } - return std::weak_ptr(); + return std::weak_ptr(); } -std::weak_ptr VMTComplexMachine::FindTransition(IVMTEnvironment* environment,const QPoint& point){ - for(std::shared_ptr m : _inner->GetTransitionCollection()) - { - if(m->IsInside(environment,point)) return std::weak_ptr(m); +std::weak_ptr VMTComplexMachine::FindTransition( + IVMTEnvironment* environment, const QPoint& point) { + for (std::shared_ptr m : + _inner->GetTransitionCollection()) { + if (m->IsInside(environment, point)) + return std::weak_ptr(m); } - return std::weak_ptr(); + return std::weak_ptr(); } -std::shared_ptr VMTComplexMachine::GetAlphabit(){ - return _inner->GetAlphabit(); +std::shared_ptr VMTComplexMachine::GetAlphabit() { + return _inner->GetAlphabit(); } -void VMTComplexMachine::SetInnerObject(std::shared_ptr other,std::shared_ptr current){ - _inner = other; +void VMTComplexMachine::SetInnerObject( + std::shared_ptr other, + std::shared_ptr current) { + _inner = other; - for(auto m: GetMachineCollection()) m->SetParent(current); - for(auto t: GetTransitionCollection()) t->SetParent(current); + for (auto m : GetMachineCollection()) m->SetParent(current); + for (auto t : GetTransitionCollection()) t->SetParent(current); } -std::shared_ptr VMTComplexMachine::GetInnerObject(){ - - return _inner; +std::shared_ptr VMTComplexMachine::GetInnerObject() { + return _inner; } /* @@ -245,65 +267,62 @@ std::vector VMTComplexMachine::GetTransitions(){ return std::vector(); } */ -bool VMTComplexMachine::IsComplex(){ - return true; -} +bool VMTComplexMachine::IsComplex() { return true; } -void VMTComplexMachine::UpdateChilds(IVMTEnvironment* environment){ - - for(std::shared_ptr m: _inner->GetMachineCollection()){ +void VMTComplexMachine::UpdateChilds(IVMTEnvironment* environment) { + for (std::shared_ptr m : _inner->GetMachineCollection()) { m->Update(environment); } } -void VMTComplexMachine::Paint(UICanvas& canvas, const QRect& rect){ - VMTMachineStub::Paint(canvas,rect); - canvas.DrawText(GetNickName(),_internal_bounds.center(),_internal_bounds.height(),false); - //canvas.DrawText(GetNickName(),_internal_bounds,this->IsSelected()); +void VMTComplexMachine::Paint(UICanvas& canvas, const QRect& rect) { + VMTMachineStub::Paint(canvas, rect); + canvas.DrawText(GetNickName(), _internal_bounds.center(), + _internal_bounds.height(), false); + // canvas.DrawText(GetNickName(),_internal_bounds,this->IsSelected()); } -void VMTComplexMachine::PaintDiagram(UICanvas& canvas, const QRect& rect){ - if(_inner){ - _inner->PaintDiagramm(canvas,rect,true); +void VMTComplexMachine::PaintDiagram(UICanvas& canvas, const QRect& rect) { + if (_inner) { + _inner->PaintDiagramm(canvas, rect, true); } } -void VMTComplexMachine::beginRoutingPass() -{ +void VMTComplexMachine::beginRoutingPass() { if (_inner) { _inner->beginRoutingPass(); } } -void VMTComplexMachine::endRoutingPass() -{ +void VMTComplexMachine::endRoutingPass() { if (_inner) { _inner->endRoutingPass(); } } -std::vector VMTComplexMachine::blockedPathsFor(const IVMTTransition* exclude) const -{ +std::vector VMTComplexMachine::blockedPathsFor( + const IVMTTransition* exclude) const { if (_inner) { return _inner->blockedPathsFor(exclude); } return {}; } -void VMTComplexMachine::recalculateRoutingForMachine(const std::shared_ptr& machine, - IVMTEnvironment* environment) -{ +void VMTComplexMachine::recalculateRoutingForMachine( + const std::shared_ptr& machine, IVMTEnvironment* environment) { if (!machine || !environment || !_inner) { return; } std::vector> affected; - for (const std::weak_ptr& transition : machine->GetIncomingTransitions()) { + for (const std::weak_ptr& transition : + machine->GetIncomingTransitions()) { if (auto ptr = transition.lock()) { affected.push_back(ptr); } } - for (const std::weak_ptr& transition : machine->GetOutgoingTransitions()) { + for (const std::weak_ptr& transition : + machine->GetOutgoingTransitions()) { if (auto ptr = transition.lock()) { affected.push_back(ptr); } @@ -320,14 +339,16 @@ void VMTComplexMachine::recalculateRoutingForMachine(const std::shared_ptr machine){ +void VMTComplexMachine::RemoveComplexMachine( + std::shared_ptr machine) { bool found = false; - do{ + do { found = false; - for(auto m: _inner->GetMachineCollection()){ - std::shared_ptr cm = std::dynamic_pointer_cast(m); - if(cm){ - if(cm->_inner==machine->_inner){ + for (auto m : _inner->GetMachineCollection()) { + std::shared_ptr cm = + std::dynamic_pointer_cast(m); + if (cm) { + if (cm->_inner == machine->_inner) { qDebug() << "VMTComplexMachine::RemoveComplexMachine"; RemoveMachine(m); found = true; @@ -335,88 +356,80 @@ void VMTComplexMachine::RemoveComplexMachine(std::shared_ptr } } } - }while(found); + } while (found); } #include -void VMTComplexMachine::RemoveMachine(std::shared_ptr machine){ - - - - - +void VMTComplexMachine::RemoveMachine(std::shared_ptr machine) { std::vector> trans_to_del; qDebug() << "Found transition to delete"; - for(std::shared_ptr t:_inner->GetTransitionCollection()) - { - bool added=false; - if(auto ptr = t->GetStart().lock()) - { - if(ptr==machine) { + for (std::shared_ptr t : + _inner->GetTransitionCollection()) { + bool added = false; + if (auto ptr = t->GetStart().lock()) { + if (ptr == machine) { trans_to_del.push_back(t); added = true; } } - if(!added) - if(auto ptr = t->GetFinish().lock()) - { - if(ptr==machine) trans_to_del.push_back(t); - } + if (!added) + if (auto ptr = t->GetFinish().lock()) { + if (ptr == machine) trans_to_del.push_back(t); + } } - for(std::shared_ptr t:trans_to_del){ + for (std::shared_ptr t : trans_to_del) { _inner->GetTransitionCollection().erase( - std::remove(_inner->GetTransitionCollection().begin(),_inner->GetTransitionCollection().end(),t), - _inner->GetTransitionCollection().end()); - if(auto ptr_start=t->GetStartMachine().lock()){ + std::remove(_inner->GetTransitionCollection().begin(), + _inner->GetTransitionCollection().end(), t), + _inner->GetTransitionCollection().end()); + if (auto ptr_start = t->GetStartMachine().lock()) { ptr_start->RemoveOutgoingTransition(t); } - if(auto ptr_finish=t->GetFinishMachine().lock()){ + if (auto ptr_finish = t->GetFinishMachine().lock()) { ptr_finish->RemoveIncomingTransition(t); } - } _inner->GetMachineCollection().erase( - std::remove(_inner->GetMachineCollection().begin(),_inner->GetMachineCollection().end(),machine), - _inner->GetMachineCollection().end()); - + std::remove(_inner->GetMachineCollection().begin(), + _inner->GetMachineCollection().end(), machine), + _inner->GetMachineCollection().end()); } -void VMTComplexMachine::RemoveTransition(std::shared_ptr transition){ +void VMTComplexMachine::RemoveTransition( + std::shared_ptr transition) { _inner->GetTransitionCollection().erase( - std::remove(_inner->GetTransitionCollection().begin(),_inner->GetTransitionCollection().end(),transition), - _inner->GetTransitionCollection().end()); + std::remove(_inner->GetTransitionCollection().begin(), + _inner->GetTransitionCollection().end(), transition), + _inner->GetTransitionCollection().end()); } - -void VMTComplexMachine::ReplaceMachine(VMTComplexMachine* machine){ - if(machine){ - this->_inner = machine->_inner; - } +void VMTComplexMachine::ReplaceMachine(VMTComplexMachine* machine) { + if (machine) { + this->_inner = machine->_inner; + } } -//void VMTComplexMachine::SetInner(VMTComplexMachine* src, VMTComplexMachine* parent){ -//} - -//void VMTComplexMachine::SetInnerObject(VMTComplexMachineInner* inner){ -//} +// void VMTComplexMachine::SetInner(VMTComplexMachine* src, VMTComplexMachine* +// parent){ +// } -void VMTComplexMachine::SetName(const QString& name){ - this->_name = name; - QStringList list = name.split(" "); - this->_nick_name = ""; - for(QString s : list) { - this->_nick_name.append(s[0].toUpper()); - } - this->_nick_name += QString::number(_name.size()); +// void VMTComplexMachine::SetInnerObject(VMTComplexMachineInner* inner){ +// } +void VMTComplexMachine::SetName(const QString& name) { + this->_name = name; + QStringList list = name.split(" "); + this->_nick_name = ""; + for (QString s : list) { + this->_nick_name.append(s[0].toUpper()); + } + this->_nick_name += QString::number(_name.size()); } - - -VMTComplexMachine::~VMTComplexMachine(){ - //qDebug() << "Delete complex machine"; +VMTComplexMachine::~VMTComplexMachine() { + // qDebug() << "Delete complex machine"; } diff --git a/VirtualTuringMachine/vmtmachines/VMTComplexMachine.h b/VirtualTuringMachine/vmtmachines/VMTComplexMachine.h old mode 100755 new mode 100644 index 84500e7..43978e9 --- a/VirtualTuringMachine/vmtmachines/VMTComplexMachine.h +++ b/VirtualTuringMachine/vmtmachines/VMTComplexMachine.h @@ -1,55 +1,60 @@ #if !defined(EA_B62B4E89_40FD_4575_97A8_8AF48A7036B8__INCLUDED_) #define EA_B62B4E89_40FD_4575_97A8_8AF48A7036B8__INCLUDED_ - - -#include -#include #include #include #include +#include +#include -//#include "IVMTMachine.h" -//#include "IVMTTransition.h" -//#include "IVMTEnvironment.h" -//#include "VMTAlphabit.h" -#include "VMTMachineStub.h" +// #include "IVMTMachine.h" +// #include "IVMTTransition.h" +// #include "IVMTEnvironment.h" +// #include "VMTAlphabit.h" #include "VMTComplexMachineInner.h" +#include "VMTMachineStub.h" #include "pathfinder.h" class VMTUndoElementMachine; class IVMTTransition; -class VMTComplexMachine : public VMTMachineStub -{ -protected: +class VMTComplexMachine : public VMTMachineStub { + protected: std::shared_ptr _inner; - static QPoint calculateDimension(const QString name, IVMTEnvironment* environment); - void CheckBounds(const QPoint &p,bool first); + static QPoint calculateDimension(const QString name, + IVMTEnvironment* environment); + void CheckBounds(const QPoint& p, bool first); QString _nick_name; -public: - VMTComplexMachine(const QString& name, std::shared_ptr alphabit); - VMTComplexMachine(const VMTComplexMachine &other); + public: + VMTComplexMachine(const QString& name, + std::shared_ptr alphabit); + VMTComplexMachine(const VMTComplexMachine& other); void DeselectAll(); void Update(IVMTEnvironment* environment) override; void UpdateChilds(IVMTEnvironment* environment); std::shared_ptr Clone(IVMTEnvironment* environment) override; - std::shared_ptr CreatePlainCopy(IVMTEnvironment* environment); + std::shared_ptr CreatePlainCopy( + IVMTEnvironment* environment); void AddMachine(std::shared_ptr machine); void AddTransition(std::shared_ptr transition); - - static std::shared_ptr ConnectMachines(std::shared_ptr first,std::shared_ptr second,IVMTEnvironment *environment,std::shared_ptr parent); + static std::shared_ptr ConnectMachines( + std::shared_ptr first, std::shared_ptr second, + IVMTEnvironment* environment, + std::shared_ptr parent); void ChangeAlphabit(std::shared_ptr alphabit) override; - std::weak_ptr FindMachine(IVMTEnvironment* environment,const QPoint& point); - std::weak_ptr FindTransition(IVMTEnvironment* environment,const QPoint& p_Point); - std::shared_ptr GetAlphabit(); + std::weak_ptr FindMachine(IVMTEnvironment* environment, + const QPoint& point); + std::weak_ptr FindTransition(IVMTEnvironment* environment, + const QPoint& p_Point); + std::shared_ptr GetAlphabit(); - void SetInnerObject(std::shared_ptr other,std::shared_ptr current); + void SetInnerObject(std::shared_ptr other, + std::shared_ptr current); std::shared_ptr GetInnerObject(); const QRect& GetBoundsWithChilds() override; std::vector GetMachines(); @@ -64,7 +69,9 @@ class VMTComplexMachine : public VMTMachineStub void beginRoutingPass(); void endRoutingPass(); std::vector blockedPathsFor(const IVMTTransition* exclude) const; - void recalculateRoutingForMachine(const std::shared_ptr& machine, IVMTEnvironment* environment); + void recalculateRoutingForMachine( + const std::shared_ptr& machine, + IVMTEnvironment* environment); void RemoveComplexMachine(std::shared_ptr machine); void RemoveMachine(std::shared_ptr machine); @@ -73,9 +80,6 @@ class VMTComplexMachine : public VMTMachineStub void SetName(const QString& name); const QString GetNickName(); - - virtual ~VMTComplexMachine(); - }; -#endif // !defined(EA_B62B4E89_40FD_4575_97A8_8AF48A7036B8__INCLUDED_) +#endif // !defined(EA_B62B4E89_40FD_4575_97A8_8AF48A7036B8__INCLUDED_) diff --git a/VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.cpp b/VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.cpp old mode 100755 new mode 100644 index 704a338..5f35a2e --- a/VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.cpp +++ b/VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.cpp @@ -1,84 +1,81 @@ -#include #include "VMTComplexMachineInner.h" +#include -VMTComplexMachineInner::~VMTComplexMachineInner(){ - //qDebug() << "Complex machine deleted"; -} - -VMTComplexMachineInner::VMTComplexMachineInner(QString name, std::shared_ptr alphabit) : - _name(name), _alphabit(alphabit) { +VMTComplexMachineInner::~VMTComplexMachineInner() { + // qDebug() << "Complex machine deleted"; } -VMTComplexMachineInner::VMTComplexMachineInner( std::shared_ptr alphabit) ://, IVMTEnvironment* environment): - _alphabit(alphabit){ -} +VMTComplexMachineInner::VMTComplexMachineInner( + QString name, std::shared_ptr alphabit) + : _name(name), _alphabit(alphabit) {} -void VMTComplexMachineInner::ChangeAlphabit(const std::shared_ptr other){ +VMTComplexMachineInner::VMTComplexMachineInner( + std::shared_ptr alphabit) + : //, IVMTEnvironment* environment): + _alphabit(alphabit) {} - if(_alphabit!=other){ - _alphabit = other; - qDebug() << "VMTComplexMachineInner::ChangeAlphabit"; +void VMTComplexMachineInner::ChangeAlphabit( + const std::shared_ptr other) { + if (_alphabit != other) { + _alphabit = other; + qDebug() << "VMTComplexMachineInner::ChangeAlphabit"; - for(std::shared_ptr m : _machines ){ - m->ChangeAlphabit(_alphabit); - } - for(std::shared_ptr t : _transitions ){ - t->ChangeAlphabit(_alphabit); - } + for (std::shared_ptr m : _machines) { + m->ChangeAlphabit(_alphabit); + } + for (std::shared_ptr t : _transitions) { + t->ChangeAlphabit(_alphabit); + } } - } -QRect VMTComplexMachineInner::GetDiagramBounds(){ - return QRect(0,0,0,0); -} +QRect VMTComplexMachineInner::GetDiagramBounds() { return QRect(0, 0, 0, 0); } -std::shared_ptr VMTComplexMachineInner::GetAlphabit(){ - return _alphabit; +std::shared_ptr VMTComplexMachineInner::GetAlphabit() { + return _alphabit; } -std::vector>& VMTComplexMachineInner::GetMachineCollection(){ - return _machines; +std::vector>& +VMTComplexMachineInner::GetMachineCollection() { + return _machines; } -std::vector>& VMTComplexMachineInner::GetTransitionCollection(){ - return _transitions; +std::vector>& +VMTComplexMachineInner::GetTransitionCollection() { + return _transitions; } -void VMTComplexMachineInner::PaintDiagramm(UICanvas &canvas, QRect rect, [[maybe_unused]] bool all){ - for(std::shared_ptr m : _machines ){ - if (!rect.isEmpty() && !rect.intersects(m->GetBounds())) { - continue; - } - m->Paint(canvas,rect); - } - for(std::shared_ptr t : _transitions ){ - const QRect& transitionBounds = t->GetBounds(); - if (!rect.isEmpty() && !transitionBounds.isEmpty() && !rect.intersects(transitionBounds)) { - continue; - } - t->Paint(canvas,rect); - } +void VMTComplexMachineInner::PaintDiagramm(UICanvas& canvas, QRect rect, + [[maybe_unused]] bool all) { + for (std::shared_ptr m : _machines) { + if (!rect.isEmpty() && !rect.intersects(m->GetBounds())) { + continue; + } + m->Paint(canvas, rect); + } + for (std::shared_ptr t : _transitions) { + const QRect& transitionBounds = t->GetBounds(); + if (!rect.isEmpty() && !transitionBounds.isEmpty() && + !rect.intersects(transitionBounds)) { + continue; + } + t->Paint(canvas, rect); + } } -void VMTComplexMachineInner::beginRoutingPass() -{ +void VMTComplexMachineInner::beginRoutingPass() { _routingPass.begin(_transitions); } -void VMTComplexMachineInner::endRoutingPass() -{ - _routingPass.end(); -} +void VMTComplexMachineInner::endRoutingPass() { _routingPass.end(); } -bool VMTComplexMachineInner::isRoutingPassActive() const -{ +bool VMTComplexMachineInner::isRoutingPassActive() const { return _routingPass.active(); } -std::vector VMTComplexMachineInner::blockedPathsFor(const IVMTTransition* exclude) const -{ +std::vector VMTComplexMachineInner::blockedPathsFor( + const IVMTTransition* exclude) const { if (_routingPass.active()) { return _routingPass.blockedPathsFor(exclude); } @@ -96,4 +93,3 @@ std::vector VMTComplexMachineInner::blockedPathsFor(const IVMTTransition } return blockedPaths; } - diff --git a/VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.h b/VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.h old mode 100755 new mode 100644 index 866b646..bd1f255 --- a/VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.h +++ b/VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.h @@ -1,36 +1,36 @@ #ifndef VMTCOMPLEXMACHINEINNER_H #define VMTCOMPLEXMACHINEINNER_H - -#include -#include #include -#include +#include +#include #include +#include #include "VMTAlphabit.h" +#include "diagramrouting.h" #include "interfaces/IVMTEnvironment.h" #include "interfaces/IVMTTransition.h" -#include "diagramrouting.h" -class VMTComplexMachineInner -{ - -public: +class VMTComplexMachineInner { + public: VMTComplexMachineInner(); virtual ~VMTComplexMachineInner(); - VMTComplexMachineInner(QString name, std::shared_ptr alphabit);//, IVMTEnvironment* environment); - VMTComplexMachineInner( std::shared_ptr alphabit);//, IVMTEnvironment* environment); - //void SetEnvironment(IVMTEnvironment* environment); + VMTComplexMachineInner(QString name, + std::shared_ptr + alphabit); //, IVMTEnvironment* environment); + VMTComplexMachineInner(std::shared_ptr + alphabit); //, IVMTEnvironment* environment); + // void SetEnvironment(IVMTEnvironment* environment); void ChangeAlphabit(const std::shared_ptr other); - //std::vector FindComplexMachineByName(QString name); - //std::vector GetComplexMachines(); + // std::vector FindComplexMachineByName(QString name); + // std::vector GetComplexMachines(); QRect GetDiagramBounds(); std::shared_ptr GetAlphabit(); - //IVMTEnvironment* GetEnvironment(); + // IVMTEnvironment* GetEnvironment(); std::vector>& GetMachineCollection(); std::vector>& GetTransitionCollection(); void PaintDiagramm(UICanvas& canvas, QRect rect, bool all); @@ -40,13 +40,12 @@ class VMTComplexMachineInner bool isRoutingPassActive() const; std::vector blockedPathsFor(const IVMTTransition* exclude) const; -private: + private: QString _name; - std::shared_ptr _alphabit; - //IVMTEnvironment *_environment; + std::shared_ptr _alphabit; + // IVMTEnvironment *_environment; std::vector> _machines; std::vector> _transitions; DiagramRoutingPass _routingPass; - }; -#endif // !defined(EA_701AC423_8239_46bb_B6A5_2B97167167A9__INCLUDED_) +#endif // !defined(EA_701AC423_8239_46bb_B6A5_2B97167167A9__INCLUDED_) diff --git a/VirtualTuringMachine/vmtmachines/VMTMachineAlpha.cpp b/VirtualTuringMachine/vmtmachines/VMTMachineAlpha.cpp old mode 100755 new mode 100644 index e66ed29..322f746 --- a/VirtualTuringMachine/vmtmachines/VMTMachineAlpha.cpp +++ b/VirtualTuringMachine/vmtmachines/VMTMachineAlpha.cpp @@ -1,33 +1,39 @@ #include "VMTMachineAlpha.h" -#include "vmticons.h" -#include "uicanvas.h" -#include "VMTComplexMachine.h" -#include + #include +#include -VMTMachineAlpha::VMTMachineAlpha(char sign,std::weak_ptr parent) : - VMTMachineStub(QString("lambda"), parent, IVMTMachine::MachineType::MT_WRITE,ImageType::MACHINE_LAMBDA){ - _sign = sign; - _size = QPoint(VMTMachineStub::_st.GetCellSize().width(),VMTMachineStub::_st.GetCellSize().height()); +#include "VMTComplexMachine.h" +#include "uicanvas.h" +#include "vmticons.h" +VMTMachineAlpha::VMTMachineAlpha(char sign, + std::weak_ptr parent) + : VMTMachineStub(QString("lambda"), parent, + IVMTMachine::MachineType::MT_WRITE, + ImageType::MACHINE_LAMBDA) { + _sign = sign; + _size = QPoint(VMTMachineStub::_st.GetCellSize().width(), + VMTMachineStub::_st.GetCellSize().height()); } -void VMTMachineAlpha::Serialize(QDataStream& stream){ - +void VMTMachineAlpha::Serialize(QDataStream& stream) { VMTMachineStub::Serialize(stream); stream << QChar(_sign); } -void VMTMachineAlpha::Deserialize(QDataStream& stream){ +void VMTMachineAlpha::Deserialize(QDataStream& stream) { VMTMachineStub::Deserialize(stream); - QChar value; stream >> value; + QChar value; + stream >> value; _sign = value.toLatin1(); } -std::shared_ptr VMTMachineAlpha::Clone(IVMTEnvironment*){ - std::shared_ptr result = std::shared_ptr(new VMTMachineAlpha(_sign,_parent)); +std::shared_ptr VMTMachineAlpha::Clone(IVMTEnvironment*) { + std::shared_ptr result = + std::shared_ptr(new VMTMachineAlpha(_sign, _parent)); std::dynamic_pointer_cast(result)->_center = _center; std::dynamic_pointer_cast(result)->_bounds = _bounds; @@ -37,111 +43,93 @@ std::shared_ptr VMTMachineAlpha::Clone(IVMTEnvironment*){ return result; } -void VMTMachineAlpha::ChangeAlphabit(std::shared_ptr alphabit){ - if(!alphabit->IsSign(_sign)) - _sign = alphabit->GetLambda(); +void VMTMachineAlpha::ChangeAlphabit(std::shared_ptr alphabit) { + if (!alphabit->IsSign(_sign)) _sign = alphabit->GetLambda(); } - -void VMTMachineAlpha::DoAction(std::shared_ptr line){ - line->SetSignAtMachine(_sign); +void VMTMachineAlpha::DoAction(std::shared_ptr line) { + line->SetSignAtMachine(_sign); } -bool VMTMachineAlpha::IsPowerCalculator(){ - return false; -} +bool VMTMachineAlpha::IsPowerCalculator() { return false; } -bool VMTMachineAlpha::IsAlphabit(){ - return true; -} +bool VMTMachineAlpha::IsAlphabit() { return true; } -void VMTMachineAlpha::Update(IVMTEnvironment* environment){ - /*if(environment){ - QString str; - str.append(QChar(_sign)); - if(auto ptr = environment->GetMachine().lock()){ - if (ptr->GetAlphabit()->IsLambda(_sign)) { - _size.rx() = 32; - _size.ry() = 32; - _internal_bounds.setWidth(32); - _internal_bounds.setHeight(32); +void VMTMachineAlpha::Update(IVMTEnvironment* environment) { + /*if(environment){ + QString str; + str.append(QChar(_sign)); + if(auto ptr = environment->GetMachine().lock()){ + if (ptr->GetAlphabit()->IsLambda(_sign)) { + _size.rx() = 32; + _size.ry() = 32; + _internal_bounds.setWidth(32); + _internal_bounds.setHeight(32); - } - else { - QRect bounds; - environment->GetGraphics().CalculateTextSize(str, bounds); - _size.rx() = bounds.width(); - _size.ry() = bounds.height(); - _internal_bounds.setWidth(bounds.width()); - _internal_bounds.setHeight(bounds.height()); - } - } - }*/ + } + else { + QRect bounds; + environment->GetGraphics().CalculateTextSize(str, bounds); + _size.rx() = bounds.width(); + _size.ry() = bounds.height(); + _internal_bounds.setWidth(bounds.width()); + _internal_bounds.setHeight(bounds.height()); + } + } + }*/ VMTMachineStub::Update(environment); } -void VMTMachineAlpha::Paint(UICanvas& canvas, const QRect& rect){ - VMTMachineStub::Paint(canvas,rect); +void VMTMachineAlpha::Paint(UICanvas& canvas, const QRect& rect) { + VMTMachineStub::Paint(canvas, rect); QString str; str.append(QChar(_sign)); - if(auto ptr = _parent.lock()){ - if (ptr->GetAlphabit()->IsLambda(_sign)) { + if (auto ptr = _parent.lock()) { + if (ptr->GetAlphabit()->IsLambda(_sign)) { canvas.DrawImage(ImageType::MACHINE_LAMBDA, _internal_bounds); - } - else { - canvas.DrawText(str,_center,_size.y(), this->IsSelected()); - } + } else { + canvas.DrawText(str, _center, _size.y(), this->IsSelected()); + } } - } -QPixmap* VMTMachineAlpha::GetImage(){ +QPixmap* VMTMachineAlpha::GetImage() { static QPixmap image; image = VmtIcons::lambdaPixmap(); return ℑ } -const QString& VMTMachineAlpha::GetMessage(){ +const QString& VMTMachineAlpha::GetMessage() { static QString msg("Select sign for machine:"); return msg; } -IVMTAlphabitSource *VMTMachineAlpha::GetAlphabitSource(){ - return this; -} - -std::shared_ptr VMTMachineAlpha::GetAlphabit(){ +IVMTAlphabitSource* VMTMachineAlpha::GetAlphabitSource() { return this; } - if(auto parent_ptr = _parent.lock()) - return parent_ptr->GetAlphabit(); +std::shared_ptr VMTMachineAlpha::GetAlphabit() { + if (auto parent_ptr = _parent.lock()) return parent_ptr->GetAlphabit(); qDebug() << "VMTMachineAlpha::GetAlphabit - No alphabit!"; - return std::shared_ptr(); + return std::shared_ptr(); } -bool VMTMachineAlpha::IsSingleChar(){ - return true; -} +bool VMTMachineAlpha::IsSingleChar() { return true; } -bool VMTMachineAlpha::IsEnabled(char sign){ - return _sign==sign; -} +bool VMTMachineAlpha::IsEnabled(char sign) { return _sign == sign; } -void VMTMachineAlpha::SetEnable(char sign, bool enable,IVMTEnvironment* environment){ - if(enable) _sign=sign; +void VMTMachineAlpha::SetEnable(char sign, bool enable, + IVMTEnvironment* environment) { + if (enable) _sign = sign; - if(auto parent = _parent.lock()){ - if(environment) - parent->Update(environment); + if (auto parent = _parent.lock()) { + if (environment) parent->Update(environment); } } -QString VMTMachineAlpha::GetSign(){ - return QString(_sign); -} +QString VMTMachineAlpha::GetSign() { return QString(_sign); } -VMTMachineAlpha::~VMTMachineAlpha(){ - //qDebug() << "Delete alpha"; +VMTMachineAlpha::~VMTMachineAlpha() { + // qDebug() << "Delete alpha"; } diff --git a/VirtualTuringMachine/vmtmachines/VMTMachineAlpha.h b/VirtualTuringMachine/vmtmachines/VMTMachineAlpha.h old mode 100755 new mode 100644 index 1383456..550a5c6 --- a/VirtualTuringMachine/vmtmachines/VMTMachineAlpha.h +++ b/VirtualTuringMachine/vmtmachines/VMTMachineAlpha.h @@ -6,17 +6,14 @@ #include "VMTMachineStub.h" #include "interfaces/IVMTAlphabitSource.h" -class VMTMachineAlpha : public VMTMachineStub , public IVMTAlphabitSource -{ - -public: - VMTMachineAlpha(char sign,std::weak_ptr parent); +class VMTMachineAlpha : public VMTMachineStub, public IVMTAlphabitSource { + public: + VMTMachineAlpha(char sign, std::weak_ptr parent); void Serialize(QDataStream&) override; void Deserialize(QDataStream&) override; std::shared_ptr Clone(IVMTEnvironment*) override; - void DoAction(std::shared_ptr line) override; bool IsPowerCalculator() override; bool IsAlphabit() override; @@ -26,19 +23,20 @@ class VMTMachineAlpha : public VMTMachineStub , public IVMTAlphabitSource void Paint(UICanvas& canvas, const QRect& rect) override; virtual ~VMTMachineAlpha(); - IVMTAlphabitSource *GetAlphabitSource() override; + IVMTAlphabitSource* GetAlphabitSource() override; void Update(IVMTEnvironment* environment) override; - //IVMTAlphabitSource + // IVMTAlphabitSource std::shared_ptr GetAlphabit() override; bool IsSingleChar() override; bool IsEnabled(char sign) override; - void SetEnable(char sign, bool enable,IVMTEnvironment* environment) override; + void SetEnable(char sign, bool enable, + IVMTEnvironment* environment) override; QPixmap* GetImage() override; QString GetSign(); const QString& GetMessage() override; -protected: - char _sign; + protected: + char _sign; }; -#endif // !defined(EA_0735A521_1ACC_4b60_B911_F969C5F9DA47__INCLUDED_) +#endif // !defined(EA_0735A521_1ACC_4b60_B911_F969C5F9DA47__INCLUDED_) diff --git a/VirtualTuringMachine/vmtmachines/VMTMachineStub.cpp b/VirtualTuringMachine/vmtmachines/VMTMachineStub.cpp old mode 100755 new mode 100644 index acda214..6cc04c7 --- a/VirtualTuringMachine/vmtmachines/VMTMachineStub.cpp +++ b/VirtualTuringMachine/vmtmachines/VMTMachineStub.cpp @@ -1,11 +1,11 @@ #include "VMTMachineStub.h" -#include "uicanvas.h" -#include "VMTComplexMachine.h" -#include "VMTAlphabit.h" - +#include +#include "VMTAlphabit.h" +#include "VMTComplexMachine.h" #include "VMTMachineAlpha.h" +#include "uicanvas.h" #include "vmtmachinecopy.h" #include "vmtmachinefinish.h" #include "vmtmachineleft.h" @@ -13,51 +13,52 @@ #include "vmtmachineright.h" #include "vmtmachinerightword.h" #include "vmtmachinestart.h" -#include - - -std::shared_ptr VMTMachineStub::CreateMachineByID(MachineType id, - std::weak_ptr parent){ - - if(auto parent_ptr = parent.lock()){ - switch(id){ - case MachineType::MT_WRITE: - return std::shared_ptr(new VMTMachineAlpha(parent_ptr->GetAlphabit()->GetLambda(),parent)); - case MachineType::MT_START: - return std::shared_ptr(new VMTMachineStart(parent)); - case MachineType::MT_FINISH: - return std::shared_ptr(new VMTMachineFinish(parent)); - case MachineType::MT_LEFT: - return std::shared_ptr(new VMTMachineLeft(parent)); - case MachineType::MT_LEFT_WORD: - return std::shared_ptr(new VMTMachineLeftWord(parent)); - case MachineType::MT_RIGHT: - return std::shared_ptr(new VMTMachineRight(parent)); - case MachineType::MT_RIGHT_WORD: - return std::shared_ptr(new VMTMachineRightWord(parent)); - case MachineType::MT_COPY: - return std::shared_ptr(new VMTMachineCopy(parent)); - default: - return std::shared_ptr(); +std::shared_ptr VMTMachineStub::CreateMachineByID( + MachineType id, std::weak_ptr parent) { + if (auto parent_ptr = parent.lock()) { + switch (id) { + case MachineType::MT_WRITE: + return std::shared_ptr(new VMTMachineAlpha( + parent_ptr->GetAlphabit()->GetLambda(), parent)); + case MachineType::MT_START: + return std::shared_ptr( + new VMTMachineStart(parent)); + case MachineType::MT_FINISH: + return std::shared_ptr( + new VMTMachineFinish(parent)); + case MachineType::MT_LEFT: + return std::shared_ptr(new VMTMachineLeft(parent)); + case MachineType::MT_LEFT_WORD: + return std::shared_ptr( + new VMTMachineLeftWord(parent)); + case MachineType::MT_RIGHT: + return std::shared_ptr( + new VMTMachineRight(parent)); + case MachineType::MT_RIGHT_WORD: + return std::shared_ptr( + new VMTMachineRightWord(parent)); + case MachineType::MT_COPY: + return std::shared_ptr(new VMTMachineCopy(parent)); + default: + return std::shared_ptr(); } - - } return std::shared_ptr(); } -std::shared_ptr VMTMachineStub::CreateComplexMachine(IVMTEnvironment*){ - return std::shared_ptr(); +std::shared_ptr VMTMachineStub::CreateComplexMachine( + IVMTEnvironment*) { + return std::shared_ptr(); } namespace { const qint32 kMachineFormatV2Marker = -1; } -void VMTMachineStub::applyLayoutFromState(IVMTEnvironment* environment, bool notifyTransitions) -{ +void VMTMachineStub::applyLayoutFromState(IVMTEnvironment* environment, + bool notifyTransitions) { _input_point = _center; _output_point = _center; _internal_bounds.setLeft(_center.x() - _size.x() / 2); @@ -85,15 +86,16 @@ void VMTMachineStub::applyLayoutFromState(IVMTEnvironment* environment, bool not if (notifyTransitions && environment) { const bool deferRouting = environment->deferTransitionRouting(); - auto notifyTransition = [&](const std::weak_ptr& transition) { - if (auto ptr = transition.lock()) { - if (deferRouting) { - ptr->UpdatePreview(environment); - } else { - ptr->Changed(environment); + auto notifyTransition = + [&](const std::weak_ptr& transition) { + if (auto ptr = transition.lock()) { + if (deferRouting) { + ptr->UpdatePreview(environment); + } else { + ptr->Changed(environment); + } } - } - }; + }; if (deferRouting) { for (auto transition : _incoming) { @@ -126,8 +128,7 @@ void VMTMachineStub::applyLayoutFromState(IVMTEnvironment* environment, bool not } } -void VMTMachineStub::restoreLayoutFromLegacyBounds() -{ +void VMTMachineStub::restoreLayoutFromLegacyBounds() { _internal_bounds.setLeft(_bounds.left() + 5); _internal_bounds.setTop(_bounds.top() + 5); _internal_bounds.setWidth(qMax(0, _bounds.width() - 10)); @@ -141,7 +142,7 @@ void VMTMachineStub::restoreLayoutFromLegacyBounds() _output_point.ry() = portY; } -void VMTMachineStub::Serialize(QDataStream& stream){ +void VMTMachineStub::Serialize(QDataStream& stream) { stream << kMachineFormatV2Marker; stream << (qint32)_center.x(); stream << (qint32)_center.y(); @@ -150,7 +151,7 @@ void VMTMachineStub::Serialize(QDataStream& stream){ stream << (qint64)_power; } -void VMTMachineStub::Deserialize(QDataStream& stream){ +void VMTMachineStub::Deserialize(QDataStream& stream) { qint32 marker = 0; stream >> marker; @@ -184,7 +185,10 @@ void VMTMachineStub::Deserialize(QDataStream& stream){ restoreLayoutFromLegacyBounds(); } -VMTMachineStub::VMTMachineStub(const QString name, std::weak_ptr parent, MachineType id,ImageType it) : IVMTMachine(it){ +VMTMachineStub::VMTMachineStub(const QString name, + std::weak_ptr parent, + MachineType id, ImageType it) + : IVMTMachine(it) { this->_error = false; this->_selected = false; this->_power = 1; @@ -193,26 +197,28 @@ VMTMachineStub::VMTMachineStub(const QString name, std::weak_ptr transition){ +void VMTMachineStub::AddIncomingTransition( + std::weak_ptr transition) { _incoming.push_back(transition); } -void VMTMachineStub::AddOutgoingTransition(std::weak_ptr transition){ +void VMTMachineStub::AddOutgoingTransition( + std::weak_ptr transition) { _outgoing.push_back(transition); } -void VMTMachineStub::RemoveIncomingTransition(std::shared_ptr transition){ - +void VMTMachineStub::RemoveIncomingTransition( + std::shared_ptr transition) { bool found = true; - while(found){ + while (found) { found = false; - for(std::vector>::iterator it= _incoming.begin();(it!=_incoming.end())&&!found;++it){ - if(std::shared_ptr ptr=it->lock()){ - if(ptr == transition) { + for (std::vector>::iterator it = + _incoming.begin(); + (it != _incoming.end()) && !found; ++it) { + if (std::shared_ptr ptr = it->lock()) { + if (ptr == transition) { _incoming.erase(it); qDebug() << "Removed"; found = true; @@ -222,14 +228,17 @@ void VMTMachineStub::RemoveIncomingTransition(std::shared_ptr tr } } -void VMTMachineStub::RemoveOutgoingTransition(std::shared_ptr transition){ +void VMTMachineStub::RemoveOutgoingTransition( + std::shared_ptr transition) { bool found = true; qDebug() << "Remove outgoing"; - while(found){ + while (found) { found = false; - for(std::vector>::iterator it= _outgoing.begin();(it!=_outgoing.end())&&!found;++it){ - if(std::shared_ptr ptr=it->lock()){ - if(ptr == transition) { + for (std::vector>::iterator it = + _outgoing.begin(); + (it != _outgoing.end()) && !found; ++it) { + if (std::shared_ptr ptr = it->lock()) { + if (ptr == transition) { qDebug() << "Erase"; _outgoing.erase(it); qDebug() << "Removed"; @@ -241,142 +250,110 @@ void VMTMachineStub::RemoveOutgoingTransition(std::shared_ptr tr qDebug() << "Done"; } -void VMTMachineStub::DoAction([[maybe_unused]] std::shared_ptr line){ - -} +void VMTMachineStub::DoAction([[maybe_unused]] std::shared_ptr line) {} -QPoint& VMTMachineStub::GetSize(){ - return _size; -} +QPoint& VMTMachineStub::GetSize() { return _size; } -const QRect& VMTMachineStub::GetBounds(){ - return _bounds; -} +const QRect& VMTMachineStub::GetBounds() { return _bounds; } -const QRect& VMTMachineStub::GetBoundsWithChilds(){ +const QRect& VMTMachineStub::GetBoundsWithChilds() { return this->_bounds_with_childs; } -const QPoint& VMTMachineStub::GetCenter(){ - _center = QPoint((_bounds.left()+_bounds.right())/2, - (_bounds.top()+_bounds.bottom())/2); +const QPoint& VMTMachineStub::GetCenter() { + _center = QPoint((_bounds.left() + _bounds.right()) / 2, + (_bounds.top() + _bounds.bottom()) / 2); return _center; } -IVMTMachine::MachineType VMTMachineStub::GetID() { - return this->_id; -} +IVMTMachine::MachineType VMTMachineStub::GetID() { return this->_id; } -std::weak_ptr VMTMachineStub::GetParent(){ +std::weak_ptr VMTMachineStub::GetParent() { return this->_parent; } -const std::vector>& VMTMachineStub::GetIncomingTransitions(){ +const std::vector>& +VMTMachineStub::GetIncomingTransitions() { return this->_incoming; } -const std::vector>& VMTMachineStub::GetOutgoingTransitions(){ +const std::vector>& +VMTMachineStub::GetOutgoingTransitions() { return this->_outgoing; } -const QPoint& VMTMachineStub::GetInputPoint(){ - return this->_input_point; -} +const QPoint& VMTMachineStub::GetInputPoint() { return this->_input_point; } -const QString& VMTMachineStub::GetMachineName(){ - return this->_name; -} +const QString& VMTMachineStub::GetMachineName() { return this->_name; } -const QString& VMTMachineStub::GetName(){ - return this->_name; -} - -const QPoint& VMTMachineStub::GetOutputPoint(){ - return this->_output_point; -} +const QString& VMTMachineStub::GetName() { return this->_name; } +const QPoint& VMTMachineStub::GetOutputPoint() { return this->_output_point; } -long VMTMachineStub::GetPower(){ - return this->_power; -} +long VMTMachineStub::GetPower() { return this->_power; } -bool VMTMachineStub::IsAcceptIncoming(){ - return false; -} +bool VMTMachineStub::IsAcceptIncoming() { return false; } -bool VMTMachineStub::IsAcceptOutgoing(){ - return true; -} +bool VMTMachineStub::IsAcceptOutgoing() { return true; } -bool VMTMachineStub::IsAlphabit(){ - return false; -} +bool VMTMachineStub::IsAlphabit() { return false; } -bool VMTMachineStub::IsComplex(){ - return false; -} +bool VMTMachineStub::IsComplex() { return false; } -bool VMTMachineStub::IsError(){ - return this->_error; -} +bool VMTMachineStub::IsError() { return this->_error; } -bool VMTMachineStub::IsInside(const QPoint& point){ - return (this->_bounds.top()<=point.y())&&(this->_bounds.bottom()>=point.y())&& - (this->_bounds.left()<=point.x())&&(this->_bounds.right()>=point.x()); +bool VMTMachineStub::IsInside(const QPoint& point) { + return (this->_bounds.top() <= point.y()) && + (this->_bounds.bottom() >= point.y()) && + (this->_bounds.left() <= point.x()) && + (this->_bounds.right() >= point.x()); } -bool VMTMachineStub::IsPowerCalculator(){ - return true; -} +bool VMTMachineStub::IsPowerCalculator() { return true; } -bool VMTMachineStub::IsSelected(){ - return this->_selected; -} +bool VMTMachineStub::IsSelected() { return this->_selected; } -void VMTMachineStub::Move(const QPoint& center,IVMTEnvironment* environment){ +void VMTMachineStub::Move(const QPoint& center, IVMTEnvironment* environment) { _center = center; Update(environment); } - -void VMTMachineStub::Update(IVMTEnvironment* environment){ +void VMTMachineStub::Update(IVMTEnvironment* environment) { applyLayoutFromState(environment, true); } -void VMTMachineStub::Move(const QPoint&& center,IVMTEnvironment* environment){ +void VMTMachineStub::Move(const QPoint&& center, IVMTEnvironment* environment) { _center = center; Update(environment); } -void VMTMachineStub::Paint(UICanvas& canvas, const QRect& rect){ +void VMTMachineStub::Paint(UICanvas& canvas, const QRect& rect) { if (!rect.isEmpty() && !rect.intersects(_bounds)) { return; } - if(this->_selected||this->_error) - { - if(_selected) { - canvas.DrawRectAnimation(_bounds,_selected); - } else canvas.DrawRect(_bounds,_selected,_error); - } else{ - //canvas.DrawButton(_bounds); + if (this->_selected || this->_error) { + if (_selected) { + canvas.DrawRectAnimation(_bounds, _selected); + } else + canvas.DrawRect(_bounds, _selected, _error); + } else { + // canvas.DrawButton(_bounds); } - if(_power>1){ - QString str = QString::number(_power); - QRect rect = _internal_bounds; - rect.setLeft(rect.left()+rect.width()); - rect.setWidth(rect.height()/2); - rect.setHeight(rect.height()/2); - //canvas.DrawText(str, rect, false); - - canvas.DrawText(str,rect.center(),rect.height(),false); + if (_power > 1) { + QString str = QString::number(_power); + QRect rect = _internal_bounds; + rect.setLeft(rect.left() + rect.width()); + rect.setWidth(rect.height() / 2); + rect.setHeight(rect.height() / 2); + // canvas.DrawText(str, rect, false); + + canvas.DrawText(str, rect.center(), rect.height(), false); } - - } -void VMTMachineStub::RemoveChilds(){ +void VMTMachineStub::RemoveChilds() { _incoming.clear(); _outgoing.clear(); } @@ -384,50 +361,41 @@ void VMTMachineStub::RemoveChilds(){ //* void VMTMachineStub::RemoveIncomingTransition(IVMTTransition* transition) { for (auto it = _incoming.begin(); it != _incoming.end();) { - if(auto ptr = it->lock()) - { + if (auto ptr = it->lock()) { IVMTTransition* current = ptr.get(); - if (current == transition) _incoming.erase(it); - else it++; - } else it++; + if (current == transition) + _incoming.erase(it); + else + it++; + } else + it++; }; } - -void VMTMachineStub::RemoveOutgoingTransition(IVMTTransition* transition){ - qDebug() << "Remove outgoing??"; +void VMTMachineStub::RemoveOutgoingTransition(IVMTTransition* transition) { + qDebug() << "Remove outgoing??"; for (auto it = _outgoing.begin(); it != _outgoing.end();) { - if(auto ptr = it->lock()) - { + if (auto ptr = it->lock()) { IVMTTransition* current = ptr.get(); if (current == transition) { qDebug() << "Erase:" << ptr.use_count(); _outgoing.erase(it); - } - else it++; - } else it++; + } else + it++; + } else + it++; }; - - } //*/ -void VMTMachineStub::SetError(bool error){ - this->_error = error; -} +void VMTMachineStub::SetError(bool error) { this->_error = error; } -void VMTMachineStub::SetParent(std::weak_ptr parent){ +void VMTMachineStub::SetParent(std::weak_ptr parent) { this->_parent = parent; } -void VMTMachineStub::SetPower(long power){ - this->_power = power; -} - -void VMTMachineStub::SetSelected(bool selected){ - this->_selected =selected; -} +void VMTMachineStub::SetPower(long power) { this->_power = power; } -VMTMachineStub::~VMTMachineStub(){ +void VMTMachineStub::SetSelected(bool selected) { this->_selected = selected; } -} +VMTMachineStub::~VMTMachineStub() {} diff --git a/VirtualTuringMachine/vmtmachines/VMTMachineStub.h b/VirtualTuringMachine/vmtmachines/VMTMachineStub.h old mode 100755 new mode 100644 index d440b14..81cfc98 --- a/VirtualTuringMachine/vmtmachines/VMTMachineStub.h +++ b/VirtualTuringMachine/vmtmachines/VMTMachineStub.h @@ -1,19 +1,16 @@ #if !defined(EA_978A931C_4910_4dd8_9125_0E050BC6179C__INCLUDED_) #define EA_978A931C_4910_4dd8_9125_0E050BC6179C__INCLUDED_ - +#include "../screentools.h" #include "VMTLine.h" #include "interfaces/IVMTEnvironment.h" #include "interfaces/IVMTMachine.h" #include "interfaces/IVMTTransition.h" -#include "../screentools.h" - class VMTComplexMachine; -class VMTMachineStub : public IVMTMachine -{ -protected: +class VMTMachineStub : public IVMTMachine { + protected: QRect _internal_bounds; QRect _bounds; QRect _bounds_with_childs; @@ -31,34 +28,38 @@ class VMTMachineStub : public IVMTMachine QString _name; std::weak_ptr _parent; - std::vector> _incoming; std::vector> _outgoing; ScreenTools _st; - void applyLayoutFromState(IVMTEnvironment* environment, bool notifyTransitions); + void applyLayoutFromState(IVMTEnvironment* environment, + bool notifyTransitions); void restoreLayoutFromLegacyBounds(); -public: - - static std::shared_ptr CreateMachineByID(MachineType id, std::weak_ptr parent); + public: + static std::shared_ptr CreateMachineByID( + MachineType id, std::weak_ptr parent); - VMTMachineStub(const QString name,std::weak_ptr parent, IVMTMachine::MachineType id,ImageType it); + VMTMachineStub(const QString name, std::weak_ptr parent, + IVMTMachine::MachineType id, ImageType it); - std::shared_ptr CreateComplexMachine(IVMTEnvironment*) override; + std::shared_ptr CreateComplexMachine( + IVMTEnvironment*) override; void Serialize(QDataStream&) override; void Deserialize(QDataStream&) override; - void Update(IVMTEnvironment* environment) override; + void Update(IVMTEnvironment* environment) override; + void AddIncomingTransition( + std::weak_ptr transition) override; + void AddOutgoingTransition( + std::weak_ptr transition) override; - void AddIncomingTransition(std::weak_ptr transition) override; - void AddOutgoingTransition(std::weak_ptr transition) override; - - void RemoveIncomingTransition(std::shared_ptr transition) override; - void RemoveOutgoingTransition(std::shared_ptr transition) override; - + void RemoveIncomingTransition( + std::shared_ptr transition) override; + void RemoveOutgoingTransition( + std::shared_ptr transition) override; void DoAction(std::shared_ptr line) override; QPoint& GetSize() override; @@ -68,15 +69,17 @@ class VMTMachineStub : public IVMTMachine MachineType GetID() override; std::weak_ptr GetParent() override; - const std::vector>& GetIncomingTransitions() override; - const std::vector>& GetOutgoingTransitions() override; + const std::vector>& GetIncomingTransitions() + override; + const std::vector>& GetOutgoingTransitions() + override; const QPoint& GetInputPoint() override; const QString& GetMachineName() override; const QString& GetName() override; const QPoint& GetOutputPoint() override; - IVMTAlphabitSource *GetAlphabitSource() override; + IVMTAlphabitSource* GetAlphabitSource() override; long GetPower() override; bool IsAcceptIncoming() override; @@ -88,8 +91,8 @@ class VMTMachineStub : public IVMTMachine bool IsPowerCalculator() override; bool IsSelected() override; - void Move(const QPoint& center,IVMTEnvironment* environment) override; - void Move(const QPoint&& center,IVMTEnvironment* environment) override; + void Move(const QPoint& center, IVMTEnvironment* environment) override; + void Move(const QPoint&& center, IVMTEnvironment* environment) override; void Paint(UICanvas& canvas, const QRect& rect) override; void RemoveChilds() override; void RemoveIncomingTransition(IVMTTransition* transition) override; @@ -101,8 +104,5 @@ class VMTMachineStub : public IVMTMachine void SetSelected(bool selected) override; virtual ~VMTMachineStub(); - - - }; -#endif // !defined(EA_978A931C_4910_4dd8_9125_0E050BC6179C__INCLUDED_) +#endif // !defined(EA_978A931C_4910_4dd8_9125_0E050BC6179C__INCLUDED_) diff --git a/VirtualTuringMachine/vmtmachines/vmtmachinecopy.cpp b/VirtualTuringMachine/vmtmachines/vmtmachinecopy.cpp old mode 100755 new mode 100644 index dfaeed0..b2de908 --- a/VirtualTuringMachine/vmtmachines/vmtmachinecopy.cpp +++ b/VirtualTuringMachine/vmtmachines/vmtmachinecopy.cpp @@ -1,24 +1,28 @@ #include "vmtmachinecopy.h" + #include -#include "uicanvas.h" -#include "VMTComplexMachine.h" -VMTMachineCopy::VMTMachineCopy(std::weak_ptr parent) : - VMTMachineStub(QString("copy"), parent, IVMTMachine::MachineType::MT_COPY,ImageType::MACHINE_COPY){ - _size = QPoint(VMTMachineStub::_st.GetCellSize().width(),VMTMachineStub::_st.GetCellSize().height()); +#include "VMTComplexMachine.h" +#include "uicanvas.h" +VMTMachineCopy::VMTMachineCopy(std::weak_ptr parent) + : VMTMachineStub(QString("copy"), parent, IVMTMachine::MachineType::MT_COPY, + ImageType::MACHINE_COPY) { + _size = QPoint(VMTMachineStub::_st.GetCellSize().width(), + VMTMachineStub::_st.GetCellSize().height()); } -void VMTMachineCopy::Serialize(QDataStream& stream){ +void VMTMachineCopy::Serialize(QDataStream& stream) { VMTMachineStub::Serialize(stream); } -void VMTMachineCopy::Deserialize(QDataStream& stream){ +void VMTMachineCopy::Deserialize(QDataStream& stream) { VMTMachineStub::Deserialize(stream); } -std::shared_ptr VMTMachineCopy::Clone(IVMTEnvironment*){ - std::shared_ptr result = std::shared_ptr(new VMTMachineCopy(_parent)); +std::shared_ptr VMTMachineCopy::Clone(IVMTEnvironment*) { + std::shared_ptr result = + std::shared_ptr(new VMTMachineCopy(_parent)); std::dynamic_pointer_cast(result)->_center = _center; std::dynamic_pointer_cast(result)->_bounds = _bounds; @@ -28,153 +32,188 @@ std::shared_ptr VMTMachineCopy::Clone(IVMTEnvironment*){ return result; } -std::shared_ptr VMTMachineCopy::CreateComplexMachine(IVMTEnvironment* environment){ - - if(_complex) return _complex; - - std::shared_ptr alphabit = std::shared_ptr (new VMTAlphabit(*this->GetParent().lock()->GetAlphabit())); - std::shared_ptr result = std::make_shared(QString("Copy"),alphabit); - - auto connect_space = [&](std::shared_ptr a,std::shared_ptr b){ - std::shared_ptr line = result->ConnectMachines(a,b,environment,result); - for(int i=0;iGetAlphabit()->GetSignsCount();i++) - if(result->GetAlphabit()->GetSignAt(i)!=result->GetAlphabit()->GetLambda()) - line->GetConditions().SetEnable(result->GetAlphabit()->GetSignAt(i),false,environment); +std::shared_ptr VMTMachineCopy::CreateComplexMachine( + IVMTEnvironment* environment) { + if (_complex) return _complex; + + std::shared_ptr alphabit = std::shared_ptr( + new VMTAlphabit(*this->GetParent().lock()->GetAlphabit())); + std::shared_ptr result = + std::make_shared(QString("Copy"), alphabit); + + auto connect_space = [&](std::shared_ptr a, + std::shared_ptr b) { + std::shared_ptr line = + result->ConnectMachines(a, b, environment, result); + for (int i = 0; i < result->GetAlphabit()->GetSignsCount(); i++) + if (result->GetAlphabit()->GetSignAt(i) != + result->GetAlphabit()->GetLambda()) + line->GetConditions().SetEnable( + result->GetAlphabit()->GetSignAt(i), false, environment); }; - auto connect_char = [&](std::shared_ptr a,std::shared_ptr b,char c){ - std::shared_ptr line = result->ConnectMachines(a,b,environment,result); - for(int i=0;iGetAlphabit()->GetSignsCount();i++) - if(result->GetAlphabit()->GetSignAt(i)!=c) - line->GetConditions().SetEnable(result->GetAlphabit()->GetSignAt(i),false,environment); + auto connect_char = [&](std::shared_ptr a, + std::shared_ptr b, char c) { + std::shared_ptr line = + result->ConnectMachines(a, b, environment, result); + for (int i = 0; i < result->GetAlphabit()->GetSignsCount(); i++) + if (result->GetAlphabit()->GetSignAt(i) != c) + line->GetConditions().SetEnable( + result->GetAlphabit()->GetSignAt(i), false, environment); }; - auto connect_non_space = [&](std::shared_ptr a,std::shared_ptr b){ - std::shared_ptr line = result->ConnectMachines(a,b,environment,result); - line->GetConditions().SetEnable(result->GetAlphabit()->GetLambda(),false,environment); + auto connect_non_space = [&](std::shared_ptr a, + std::shared_ptr b) { + std::shared_ptr line = + result->ConnectMachines(a, b, environment, result); + line->GetConditions().SetEnable(result->GetAlphabit()->GetLambda(), + false, environment); }; - auto connect = [&](std::shared_ptr a,std::shared_ptr b){ - std::shared_ptr line = result->ConnectMachines(a,b,environment,result); + auto connect = [&](std::shared_ptr a, + std::shared_ptr b) { + std::shared_ptr line = + result->ConnectMachines(a, b, environment, result); }; - - - std::shared_ptr start = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_START,result); result->AddMachine(start); - std::shared_ptr left = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_LEFT,result); result->AddMachine(left); - std::shared_ptr right_1 = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_RIGHT,result); result->AddMachine(right_1); - - std::shared_ptr right_2 = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_RIGHT,result); result->AddMachine(right_2); - std::shared_ptr finish = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_FINISH,result); result->AddMachine(finish); - + std::shared_ptr start = VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_START, result); + result->AddMachine(start); + std::shared_ptr left = VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_LEFT, result); + result->AddMachine(left); + std::shared_ptr right_1 = VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_RIGHT, result); + result->AddMachine(right_1); + + std::shared_ptr right_2 = VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_RIGHT, result); + result->AddMachine(right_2); + std::shared_ptr finish = VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_FINISH, result); + result->AddMachine(finish); const int STEP = 200; - start->Move(QPoint(STEP,100),environment); - left->Move(QPoint(2*STEP,100),environment); - right_1->Move(QPoint(3*STEP,100),environment); - right_2->Move(QPoint(4*STEP,0),environment); - finish->Move(QPoint(5*STEP,0),environment); - - - - connect(start,left); - connect_non_space(left,left); - connect_space(left,right_1); - connect_space(right_1,right_2); - connect_non_space(right_2,right_2); - connect_space(right_2,finish); - + start->Move(QPoint(STEP, 100), environment); + left->Move(QPoint(2 * STEP, 100), environment); + right_1->Move(QPoint(3 * STEP, 100), environment); + right_2->Move(QPoint(4 * STEP, 0), environment); + finish->Move(QPoint(5 * STEP, 0), environment); + + connect(start, left); + connect_non_space(left, left); + connect_space(left, right_1); + connect_space(right_1, right_2); + connect_non_space(right_2, right_2); + connect_space(right_2, finish); int i = STEP; QString astr = alphabit->ToString(); - for(int j = 0; j < astr.length(); ++j){ + for (int j = 0; j < astr.length(); ++j) { QChar c = astr.at(j); - if(!alphabit->IsLambda(c.toLatin1())){ - std::shared_ptr lambda_2 = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_WRITE,result); result->AddMachine(lambda_2); - std::shared_ptr right_3 = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_RIGHT,result); result->AddMachine(right_3); - std::shared_ptr right_4 = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_RIGHT,result); result->AddMachine(right_4); - std::shared_ptr lambda_3 = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_WRITE,result); result->AddMachine(lambda_3); - std::shared_ptr left_1 = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_LEFT,result); result->AddMachine(left_1); - std::shared_ptr left_2 = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_LEFT,result); result->AddMachine(left_2); - std::shared_ptr lambda_4 = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_WRITE,result); result->AddMachine(lambda_4); - - std::dynamic_pointer_cast(lambda_3)->SetEnable(c.toLatin1(),true,nullptr); - std::dynamic_pointer_cast(lambda_4)->SetEnable(c.toLatin1(),true,nullptr); - lambda_2->Move(QPoint(4*STEP,i),environment); - right_3->Move(QPoint(5*STEP,i),environment); - right_4->Move(QPoint(6*STEP,i),environment); - lambda_3->Move(QPoint(7*STEP,i),environment); - left_1->Move(QPoint(8*STEP,i),environment); - left_2->Move(QPoint(9*STEP,i),environment); - lambda_4->Move(QPoint(10*STEP,i),environment); - - connect_char(right_1,lambda_2,c.toLatin1()); - connect(lambda_2,right_3); - connect_non_space(right_3,right_3); - connect_space(right_3,right_4); - connect_non_space(right_4,right_4); - connect_space(right_4,lambda_3); - connect(lambda_3,left_1); - connect_non_space(left_1,left_1); - connect_space(left_1,left_2); - connect_non_space(left_2,left_2); - connect_space(left_2,lambda_4); - connect(lambda_4,right_1); - - i+=STEP; + if (!alphabit->IsLambda(c.toLatin1())) { + std::shared_ptr lambda_2 = + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_WRITE, result); + result->AddMachine(lambda_2); + std::shared_ptr right_3 = + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_RIGHT, result); + result->AddMachine(right_3); + std::shared_ptr right_4 = + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_RIGHT, result); + result->AddMachine(right_4); + std::shared_ptr lambda_3 = + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_WRITE, result); + result->AddMachine(lambda_3); + std::shared_ptr left_1 = + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_LEFT, result); + result->AddMachine(left_1); + std::shared_ptr left_2 = + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_LEFT, result); + result->AddMachine(left_2); + std::shared_ptr lambda_4 = + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_WRITE, result); + result->AddMachine(lambda_4); + + std::dynamic_pointer_cast(lambda_3)->SetEnable( + c.toLatin1(), true, nullptr); + std::dynamic_pointer_cast(lambda_4)->SetEnable( + c.toLatin1(), true, nullptr); + lambda_2->Move(QPoint(4 * STEP, i), environment); + right_3->Move(QPoint(5 * STEP, i), environment); + right_4->Move(QPoint(6 * STEP, i), environment); + lambda_3->Move(QPoint(7 * STEP, i), environment); + left_1->Move(QPoint(8 * STEP, i), environment); + left_2->Move(QPoint(9 * STEP, i), environment); + lambda_4->Move(QPoint(10 * STEP, i), environment); + + connect_char(right_1, lambda_2, c.toLatin1()); + connect(lambda_2, right_3); + connect_non_space(right_3, right_3); + connect_space(right_3, right_4); + connect_non_space(right_4, right_4); + connect_space(right_4, lambda_3); + connect(lambda_3, left_1); + connect_non_space(left_1, left_1); + connect_space(left_1, left_2); + connect_non_space(left_2, left_2); + connect_space(left_2, lambda_4); + connect(lambda_4, right_1); + + i += STEP; } } + /* + result->ConnectMachines(start,left,environment,result); -/* - result->ConnectMachines(start,left,environment,result); - - - std::shared_ptr left_left = result->ConnectMachines(left,left,environment,result); - left_left->GetConditions().SetEnable(result->GetAlphabit()->GetLambda(),false,environment); + std::shared_ptr left_left = + result->ConnectMachines(left,left,environment,result); + left_left->GetConditions().SetEnable(result->GetAlphabit()->GetLambda(),false,environment); - std::shared_ptr left_finish = result->ConnectMachines(left,finish,environment,result); - for(int i=0;iGetAlphabit()->GetSignsCount();i++) - if(result->GetAlphabit()->GetSignAt(i)!=result->GetAlphabit()->GetLambda()) - left_finish->GetConditions().SetEnable(result->GetAlphabit()->GetSignAt(i),false,environment); -*/ + std::shared_ptr left_finish = + result->ConnectMachines(left,finish,environment,result); for(int + i=0;iGetAlphabit()->GetSignsCount();i++) + if(result->GetAlphabit()->GetSignAt(i)!=result->GetAlphabit()->GetLambda()) + left_finish->GetConditions().SetEnable(result->GetAlphabit()->GetSignAt(i),false,environment); + */ _complex = result; return result; } -void VMTMachineCopy::DoAction(std::shared_ptr line){ +void VMTMachineCopy::DoAction(std::shared_ptr line) { line->ShiftLeft(); QString reverse_word; - if(std::shared_ptr ptr = _parent.lock()){ - while(line->GetValueAtMachine()!=ptr->GetAlphabit()->GetLambda()){ + if (std::shared_ptr ptr = _parent.lock()) { + while (line->GetValueAtMachine() != ptr->GetAlphabit()->GetLambda()) { reverse_word.append(QChar(line->GetValueAtMachine())); line->ShiftLeft(); } } - long position = line->GetRightSignPosition()+2; - for(int i=0;iSetValueAt(position+i,reverse_word[reverse_word.length()-i-1].toLatin1()); + long position = line->GetRightSignPosition() + 2; + for (int i = 0; i < reverse_word.length(); i++) { + line->SetValueAt( + position + i, + reverse_word[reverse_word.length() - i - 1].toLatin1()); } - line->SetMachinePosition(position+reverse_word.length()); - -} - -bool VMTMachineCopy::IsPowerCalculator(){ - return true; + line->SetMachinePosition(position + reverse_word.length()); } -bool VMTMachineCopy::IsAlphabit(){ - return false; -} +bool VMTMachineCopy::IsPowerCalculator() { return true; } -void VMTMachineCopy::Paint(UICanvas& canvas, const QRect& rect){ - VMTMachineStub::Paint(canvas,rect); - canvas.DrawImage(ImageType::MACHINE_COPY,_internal_bounds); +bool VMTMachineCopy::IsAlphabit() { return false; } +void VMTMachineCopy::Paint(UICanvas& canvas, const QRect& rect) { + VMTMachineStub::Paint(canvas, rect); + canvas.DrawImage(ImageType::MACHINE_COPY, _internal_bounds); } -VMTMachineCopy::~VMTMachineCopy(){ - -} +VMTMachineCopy::~VMTMachineCopy() {} diff --git a/VirtualTuringMachine/vmtmachines/vmtmachinecopy.h b/VirtualTuringMachine/vmtmachines/vmtmachinecopy.h old mode 100755 new mode 100644 index a906258..c57515c --- a/VirtualTuringMachine/vmtmachines/vmtmachinecopy.h +++ b/VirtualTuringMachine/vmtmachines/vmtmachinecopy.h @@ -1,31 +1,30 @@ #ifndef VMTMACHINECOPY_H #define VMTMACHINECOPY_H +#include "VMTComplexMachine.h" #include "VMTLine.h" #include "VMTMachineStub.h" -#include "VMTComplexMachine.h" -class VMTMachineCopy : public VMTMachineStub -{ -protected: +class VMTMachineCopy : public VMTMachineStub { + protected: std::shared_ptr _complex; -public: + + public: VMTMachineCopy(std::weak_ptr parent); void Serialize(QDataStream&) override; void Deserialize(QDataStream&) override; std::shared_ptr Clone(IVMTEnvironment*) override; - std::shared_ptr CreateComplexMachine(IVMTEnvironment* environment) override; + std::shared_ptr CreateComplexMachine( + IVMTEnvironment* environment) override; void DoAction(std::shared_ptr line) override; bool IsPowerCalculator() override; bool IsAlphabit() override; - void Paint(UICanvas& canvas, const QRect& rect) override; virtual ~VMTMachineCopy(); - }; -#endif // VMTMACHINECOPY_H +#endif // VMTMACHINECOPY_H diff --git a/VirtualTuringMachine/vmtmachines/vmtmachinefinish.cpp b/VirtualTuringMachine/vmtmachines/vmtmachinefinish.cpp old mode 100755 new mode 100644 index 0f3090a..a47ba31 --- a/VirtualTuringMachine/vmtmachines/vmtmachinefinish.cpp +++ b/VirtualTuringMachine/vmtmachines/vmtmachinefinish.cpp @@ -1,50 +1,48 @@ #include "vmtmachinefinish.h" + #include -#include "uicanvas.h" + #include "VMTComplexMachine.h" +#include "uicanvas.h" -VMTMachineFinish::VMTMachineFinish(std::weak_ptr parent) : - VMTMachineStub(QString("finish"), parent, IVMTMachine::MachineType::MT_FINISH,ImageType::MACHINE_FINISH){ - _size = QPoint(VMTMachineStub::_st.GetCellSize().width(),VMTMachineStub::_st.GetCellSize().height()); +VMTMachineFinish::VMTMachineFinish(std::weak_ptr parent) + : VMTMachineStub(QString("finish"), parent, + IVMTMachine::MachineType::MT_FINISH, + ImageType::MACHINE_FINISH) { + _size = QPoint(VMTMachineStub::_st.GetCellSize().width(), + VMTMachineStub::_st.GetCellSize().height()); } -void VMTMachineFinish::Serialize(QDataStream& stream){ +void VMTMachineFinish::Serialize(QDataStream& stream) { VMTMachineStub::Serialize(stream); } -void VMTMachineFinish::Deserialize(QDataStream& stream){ +void VMTMachineFinish::Deserialize(QDataStream& stream) { VMTMachineStub::Deserialize(stream); } -std::shared_ptr VMTMachineFinish::Clone(IVMTEnvironment*){ - std::shared_ptr result = std::shared_ptr(new VMTMachineFinish(_parent)); +std::shared_ptr VMTMachineFinish::Clone(IVMTEnvironment*) { + std::shared_ptr result = + std::shared_ptr(new VMTMachineFinish(_parent)); - std::dynamic_pointer_cast(result)->_center = _center; - std::dynamic_pointer_cast(result)->_bounds = _bounds; - std::dynamic_pointer_cast(result)->_size = _size; - std::dynamic_pointer_cast(result)->_power = _power; + std::dynamic_pointer_cast(result)->_center = _center; + std::dynamic_pointer_cast(result)->_bounds = _bounds; + std::dynamic_pointer_cast(result)->_size = _size; + std::dynamic_pointer_cast(result)->_power = _power; - return result; + return result; } -void VMTMachineFinish::DoAction(std::shared_ptr ){ - -} +void VMTMachineFinish::DoAction(std::shared_ptr) {} -bool VMTMachineFinish::IsPowerCalculator(){ - return false; -} +bool VMTMachineFinish::IsPowerCalculator() { return false; } -bool VMTMachineFinish::IsAlphabit(){ - return false; -} +bool VMTMachineFinish::IsAlphabit() { return false; } -void VMTMachineFinish::Paint(UICanvas& canvas, const QRect& rect){ - VMTMachineStub::Paint(canvas,rect); +void VMTMachineFinish::Paint(UICanvas& canvas, const QRect& rect) { + VMTMachineStub::Paint(canvas, rect); - canvas.DrawImage(ImageType::MACHINE_FINISH,_internal_bounds); + canvas.DrawImage(ImageType::MACHINE_FINISH, _internal_bounds); } -VMTMachineFinish::~VMTMachineFinish(){ - -} +VMTMachineFinish::~VMTMachineFinish() {} diff --git a/VirtualTuringMachine/vmtmachines/vmtmachinefinish.h b/VirtualTuringMachine/vmtmachines/vmtmachinefinish.h old mode 100755 new mode 100644 index 9c7e76d..0bac675 --- a/VirtualTuringMachine/vmtmachines/vmtmachinefinish.h +++ b/VirtualTuringMachine/vmtmachines/vmtmachinefinish.h @@ -4,24 +4,20 @@ #include "VMTLine.h" #include "VMTMachineStub.h" -class VMTMachineFinish : public VMTMachineStub -{ -public: +class VMTMachineFinish : public VMTMachineStub { + public: VMTMachineFinish(std::weak_ptr parent); void Serialize(QDataStream&) override; void Deserialize(QDataStream&) override; std::shared_ptr Clone(IVMTEnvironment*) override; - void DoAction(std::shared_ptr line) override; bool IsPowerCalculator() override; bool IsAlphabit() override; - void Paint(UICanvas& canvas, const QRect& rect) override; virtual ~VMTMachineFinish(); - }; -#endif // VMTMACHINEFINISH_H +#endif // VMTMACHINEFINISH_H diff --git a/VirtualTuringMachine/vmtmachines/vmtmachineleft.cpp b/VirtualTuringMachine/vmtmachines/vmtmachineleft.cpp old mode 100755 new mode 100644 index 0910062..e4a4498 --- a/VirtualTuringMachine/vmtmachines/vmtmachineleft.cpp +++ b/VirtualTuringMachine/vmtmachines/vmtmachineleft.cpp @@ -1,51 +1,49 @@ #include "vmtmachineleft.h" + #include -#include "uicanvas.h" + #include "VMTComplexMachine.h" +#include "uicanvas.h" -VMTMachineLeft::VMTMachineLeft(std::weak_ptr parent) : - VMTMachineStub(QString("left"), parent, IVMTMachine::MachineType::MT_LEFT,ImageType::MACHINE_LEFT){ - _size = QPoint(VMTMachineStub::_st.GetCellSize().width(),VMTMachineStub::_st.GetCellSize().height()); +VMTMachineLeft::VMTMachineLeft(std::weak_ptr parent) + : VMTMachineStub(QString("left"), parent, IVMTMachine::MachineType::MT_LEFT, + ImageType::MACHINE_LEFT) { + _size = QPoint(VMTMachineStub::_st.GetCellSize().width(), + VMTMachineStub::_st.GetCellSize().height()); } -void VMTMachineLeft::Serialize(QDataStream& stream){ +void VMTMachineLeft::Serialize(QDataStream& stream) { VMTMachineStub::Serialize(stream); } -void VMTMachineLeft::Deserialize(QDataStream& stream){ +void VMTMachineLeft::Deserialize(QDataStream& stream) { VMTMachineStub::Deserialize(stream); } -std::shared_ptr VMTMachineLeft::Clone(IVMTEnvironment*){ - std::shared_ptr result = std::shared_ptr(new VMTMachineLeft(_parent)); +std::shared_ptr VMTMachineLeft::Clone(IVMTEnvironment*) { + std::shared_ptr result = + std::shared_ptr(new VMTMachineLeft(_parent)); - std::dynamic_pointer_cast(result)->_center = _center; - std::dynamic_pointer_cast(result)->_bounds = _bounds; - std::dynamic_pointer_cast(result)->_size = _size; - std::dynamic_pointer_cast(result)->_power = _power; + std::dynamic_pointer_cast(result)->_center = _center; + std::dynamic_pointer_cast(result)->_bounds = _bounds; + std::dynamic_pointer_cast(result)->_size = _size; + std::dynamic_pointer_cast(result)->_power = _power; - return result; + return result; } -void VMTMachineLeft::DoAction(std::shared_ptr line){ - line->ShiftLeft(); +void VMTMachineLeft::DoAction(std::shared_ptr line) { + line->ShiftLeft(); } -bool VMTMachineLeft::IsPowerCalculator(){ - return true; -} +bool VMTMachineLeft::IsPowerCalculator() { return true; } -bool VMTMachineLeft::IsAlphabit(){ - return false; -} - -void VMTMachineLeft::Paint(UICanvas& canvas, const QRect& rect){ - VMTMachineStub::Paint(canvas,rect); - - canvas.DrawImage(ImageType::MACHINE_LEFT,_internal_bounds); -} +bool VMTMachineLeft::IsAlphabit() { return false; } -VMTMachineLeft::~VMTMachineLeft(){ +void VMTMachineLeft::Paint(UICanvas& canvas, const QRect& rect) { + VMTMachineStub::Paint(canvas, rect); + canvas.DrawImage(ImageType::MACHINE_LEFT, _internal_bounds); } +VMTMachineLeft::~VMTMachineLeft() {} diff --git a/VirtualTuringMachine/vmtmachines/vmtmachineleft.h b/VirtualTuringMachine/vmtmachines/vmtmachineleft.h old mode 100755 new mode 100644 index 7fae817..aaa18d2 --- a/VirtualTuringMachine/vmtmachines/vmtmachineleft.h +++ b/VirtualTuringMachine/vmtmachines/vmtmachineleft.h @@ -1,28 +1,23 @@ #ifndef VMTMACHINELEFT_H #define VMTMACHINELEFT_H - #include "VMTLine.h" #include "VMTMachineStub.h" -class VMTMachineLeft : public VMTMachineStub -{ -public: +class VMTMachineLeft : public VMTMachineStub { + public: VMTMachineLeft(std::weak_ptr parent); void Serialize(QDataStream&) override; void Deserialize(QDataStream&) override; std::shared_ptr Clone(IVMTEnvironment*) override; - void DoAction(std::shared_ptr line) override; bool IsPowerCalculator() override; bool IsAlphabit() override; - void Paint(UICanvas& canvas, const QRect& rect) override; virtual ~VMTMachineLeft(); - }; -#endif // VMTMACHINELEFT_H +#endif // VMTMACHINELEFT_H diff --git a/VirtualTuringMachine/vmtmachines/vmtmachineleftword.cpp b/VirtualTuringMachine/vmtmachines/vmtmachineleftword.cpp old mode 100755 new mode 100644 index 33cce85..cd928ac --- a/VirtualTuringMachine/vmtmachines/vmtmachineleftword.cpp +++ b/VirtualTuringMachine/vmtmachines/vmtmachineleftword.cpp @@ -1,81 +1,92 @@ #include "vmtmachineleftword.h" + #include -#include "uicanvas.h" + #include "VMTComplexMachine.h" #include "VMTTransitionImpl.h" +#include "uicanvas.h" -VMTMachineLeftWord::VMTMachineLeftWord(std::weak_ptr parent) : - VMTMachineStub(QString("left word"), parent, IVMTMachine::MachineType::MT_LEFT_WORD,ImageType::MACHINE_LEFT_WORD){ - _size = QPoint(VMTMachineStub::_st.GetCellSize().width(),VMTMachineStub::_st.GetCellSize().height()); +VMTMachineLeftWord::VMTMachineLeftWord(std::weak_ptr parent) + : VMTMachineStub(QString("left word"), parent, + IVMTMachine::MachineType::MT_LEFT_WORD, + ImageType::MACHINE_LEFT_WORD) { + _size = QPoint(VMTMachineStub::_st.GetCellSize().width(), + VMTMachineStub::_st.GetCellSize().height()); } -void VMTMachineLeftWord::Serialize(QDataStream& stream){ +void VMTMachineLeftWord::Serialize(QDataStream& stream) { VMTMachineStub::Serialize(stream); } -void VMTMachineLeftWord::Deserialize(QDataStream& stream){ +void VMTMachineLeftWord::Deserialize(QDataStream& stream) { VMTMachineStub::Deserialize(stream); } -std::shared_ptr VMTMachineLeftWord::Clone(IVMTEnvironment*){ - std::shared_ptr result = std::shared_ptr(new VMTMachineLeftWord(_parent)); +std::shared_ptr VMTMachineLeftWord::Clone(IVMTEnvironment*) { + std::shared_ptr result = + std::shared_ptr(new VMTMachineLeftWord(_parent)); - std::dynamic_pointer_cast(result)->_center = _center; - std::dynamic_pointer_cast(result)->_bounds = _bounds; - std::dynamic_pointer_cast(result)->_size = _size; - std::dynamic_pointer_cast(result)->_power = _power; + std::dynamic_pointer_cast(result)->_center = _center; + std::dynamic_pointer_cast(result)->_bounds = _bounds; + std::dynamic_pointer_cast(result)->_size = _size; + std::dynamic_pointer_cast(result)->_power = _power; - return result; + return result; } -std::shared_ptr VMTMachineLeftWord::CreateComplexMachine(IVMTEnvironment* environment){ - - if(_complex) return _complex; - std::shared_ptr result = std::make_shared(QString("Left Word"),this->GetParent().lock()->GetAlphabit()); - - std::shared_ptr start = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_START,result); result->AddMachine(start); - std::shared_ptr left = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_LEFT,result); result->AddMachine(left); - std::shared_ptr finish = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_FINISH,result); result->AddMachine(finish); - - const int STEP=200; - start->Move(QPoint(STEP,STEP),environment); - left->Move(QPoint(3*STEP,STEP),environment); - finish->Move(QPoint(5*STEP,STEP),environment); - - result->ConnectMachines(start,left,environment,result); - - - std::shared_ptr left_left = result->ConnectMachines(left,left,environment,result); - left_left->GetConditions().SetEnable(result->GetAlphabit()->GetLambda(),false,environment); - - std::shared_ptr left_finish = result->ConnectMachines(left,finish,environment,result); - for(int i=0;iGetAlphabit()->GetSignsCount();i++) - if(result->GetAlphabit()->GetSignAt(i)!=result->GetAlphabit()->GetLambda()) - left_finish->GetConditions().SetEnable(result->GetAlphabit()->GetSignAt(i),false,environment); - - _complex= result; - return result; -} - -void VMTMachineLeftWord::DoAction(std::shared_ptr line){ - line->ShiftLeftWord(); -} - -bool VMTMachineLeftWord::IsPowerCalculator(){ - return true; +std::shared_ptr VMTMachineLeftWord::CreateComplexMachine( + IVMTEnvironment* environment) { + if (_complex) return _complex; + std::shared_ptr result = + std::make_shared( + QString("Left Word"), this->GetParent().lock()->GetAlphabit()); + + std::shared_ptr start = VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_START, result); + result->AddMachine(start); + std::shared_ptr left = VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_LEFT, result); + result->AddMachine(left); + std::shared_ptr finish = VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_FINISH, result); + result->AddMachine(finish); + + const int STEP = 200; + start->Move(QPoint(STEP, STEP), environment); + left->Move(QPoint(3 * STEP, STEP), environment); + finish->Move(QPoint(5 * STEP, STEP), environment); + + result->ConnectMachines(start, left, environment, result); + + std::shared_ptr left_left = + result->ConnectMachines(left, left, environment, result); + left_left->GetConditions().SetEnable(result->GetAlphabit()->GetLambda(), + false, environment); + + std::shared_ptr left_finish = + result->ConnectMachines(left, finish, environment, result); + for (int i = 0; i < result->GetAlphabit()->GetSignsCount(); i++) + if (result->GetAlphabit()->GetSignAt(i) != + result->GetAlphabit()->GetLambda()) + left_finish->GetConditions().SetEnable( + result->GetAlphabit()->GetSignAt(i), false, environment); + + _complex = result; + return result; } -bool VMTMachineLeftWord::IsAlphabit(){ - return false; +void VMTMachineLeftWord::DoAction(std::shared_ptr line) { + line->ShiftLeftWord(); } -void VMTMachineLeftWord::Paint(UICanvas& canvas, const QRect& rect){ - VMTMachineStub::Paint(canvas,rect); +bool VMTMachineLeftWord::IsPowerCalculator() { return true; } - canvas.DrawImage(ImageType::MACHINE_LEFT_WORD,_internal_bounds); -} +bool VMTMachineLeftWord::IsAlphabit() { return false; } -VMTMachineLeftWord::~VMTMachineLeftWord(){ +void VMTMachineLeftWord::Paint(UICanvas& canvas, const QRect& rect) { + VMTMachineStub::Paint(canvas, rect); + canvas.DrawImage(ImageType::MACHINE_LEFT_WORD, _internal_bounds); } +VMTMachineLeftWord::~VMTMachineLeftWord() {} diff --git a/VirtualTuringMachine/vmtmachines/vmtmachineleftword.h b/VirtualTuringMachine/vmtmachines/vmtmachineleftword.h old mode 100755 new mode 100644 index 31e5078..dcf3135 --- a/VirtualTuringMachine/vmtmachines/vmtmachineleftword.h +++ b/VirtualTuringMachine/vmtmachines/vmtmachineleftword.h @@ -1,34 +1,30 @@ #ifndef VMTMACHINELEFTWORD_H #define VMTMACHINELEFTWORD_H - +#include "VMTComplexMachine.h" #include "VMTLine.h" #include "VMTMachineStub.h" -#include "VMTComplexMachine.h" -class VMTMachineLeftWord : public VMTMachineStub -{ -protected: +class VMTMachineLeftWord : public VMTMachineStub { + protected: std::shared_ptr _complex; -public: + + public: VMTMachineLeftWord(std::weak_ptr parent); - std::shared_ptr CreateComplexMachine(IVMTEnvironment*) override; + std::shared_ptr CreateComplexMachine( + IVMTEnvironment*) override; void Serialize(QDataStream&) override; void Deserialize(QDataStream&) override; std::shared_ptr Clone(IVMTEnvironment*) override; - void DoAction(std::shared_ptr line) override; bool IsPowerCalculator() override; bool IsAlphabit() override; - void Paint(UICanvas& canvas, const QRect& rect) override; virtual ~VMTMachineLeftWord(); - }; - -#endif // VMTMACHINELEFTWORD_H +#endif // VMTMACHINELEFTWORD_H diff --git a/VirtualTuringMachine/vmtmachines/vmtmachineright.cpp b/VirtualTuringMachine/vmtmachines/vmtmachineright.cpp old mode 100755 new mode 100644 index 679e374..5ca037b --- a/VirtualTuringMachine/vmtmachines/vmtmachineright.cpp +++ b/VirtualTuringMachine/vmtmachines/vmtmachineright.cpp @@ -1,51 +1,50 @@ #include "vmtmachineright.h" + #include -#include "uicanvas.h" + #include "VMTComplexMachine.h" +#include "uicanvas.h" -VMTMachineRight::VMTMachineRight(std::weak_ptr parent) : - VMTMachineStub(QString("right"), parent, IVMTMachine::MachineType::MT_RIGHT,ImageType::MACHINE_RIGHT){ - _size = QPoint(VMTMachineStub::_st.GetCellSize().width(),VMTMachineStub::_st.GetCellSize().height()); +VMTMachineRight::VMTMachineRight(std::weak_ptr parent) + : VMTMachineStub(QString("right"), parent, + IVMTMachine::MachineType::MT_RIGHT, + ImageType::MACHINE_RIGHT) { + _size = QPoint(VMTMachineStub::_st.GetCellSize().width(), + VMTMachineStub::_st.GetCellSize().height()); } -void VMTMachineRight::Serialize(QDataStream& stream){ +void VMTMachineRight::Serialize(QDataStream& stream) { VMTMachineStub::Serialize(stream); } -void VMTMachineRight::Deserialize(QDataStream& stream){ +void VMTMachineRight::Deserialize(QDataStream& stream) { VMTMachineStub::Deserialize(stream); } -std::shared_ptr VMTMachineRight::Clone(IVMTEnvironment*){ - std::shared_ptr result = std::shared_ptr(new VMTMachineRight(_parent)); +std::shared_ptr VMTMachineRight::Clone(IVMTEnvironment*) { + std::shared_ptr result = + std::shared_ptr(new VMTMachineRight(_parent)); - std::dynamic_pointer_cast(result)->_center = _center; - std::dynamic_pointer_cast(result)->_bounds = _bounds; - std::dynamic_pointer_cast(result)->_size = _size; - std::dynamic_pointer_cast(result)->_power = _power; + std::dynamic_pointer_cast(result)->_center = _center; + std::dynamic_pointer_cast(result)->_bounds = _bounds; + std::dynamic_pointer_cast(result)->_size = _size; + std::dynamic_pointer_cast(result)->_power = _power; - return result; + return result; } -void VMTMachineRight::DoAction(std::shared_ptr line){ - line->ShiftRight(); +void VMTMachineRight::DoAction(std::shared_ptr line) { + line->ShiftRight(); } -bool VMTMachineRight::IsPowerCalculator(){ - return true; -} +bool VMTMachineRight::IsPowerCalculator() { return true; } -bool VMTMachineRight::IsAlphabit(){ - return false; -} - -void VMTMachineRight::Paint(UICanvas& canvas, const QRect& rect){ - VMTMachineStub::Paint(canvas,rect); - - canvas.DrawImage(ImageType::MACHINE_RIGHT,_internal_bounds); -} +bool VMTMachineRight::IsAlphabit() { return false; } -VMTMachineRight::~VMTMachineRight(){ +void VMTMachineRight::Paint(UICanvas& canvas, const QRect& rect) { + VMTMachineStub::Paint(canvas, rect); + canvas.DrawImage(ImageType::MACHINE_RIGHT, _internal_bounds); } +VMTMachineRight::~VMTMachineRight() {} diff --git a/VirtualTuringMachine/vmtmachines/vmtmachineright.h b/VirtualTuringMachine/vmtmachines/vmtmachineright.h old mode 100755 new mode 100644 index eb063a8..5552e08 --- a/VirtualTuringMachine/vmtmachines/vmtmachineright.h +++ b/VirtualTuringMachine/vmtmachines/vmtmachineright.h @@ -1,28 +1,23 @@ #ifndef VMTMACHINERIGHT_H #define VMTMACHINERIGHT_H - #include "VMTLine.h" #include "VMTMachineStub.h" -class VMTMachineRight : public VMTMachineStub -{ -public: +class VMTMachineRight : public VMTMachineStub { + public: VMTMachineRight(std::weak_ptr parent); void Serialize(QDataStream&) override; void Deserialize(QDataStream&) override; std::shared_ptr Clone(IVMTEnvironment*) override; - void DoAction(std::shared_ptr line) override; bool IsPowerCalculator() override; bool IsAlphabit() override; - void Paint(UICanvas& canvas, const QRect& rect) override; virtual ~VMTMachineRight(); - }; -#endif // VMTMACHINERIGHT_H +#endif // VMTMACHINERIGHT_H diff --git a/VirtualTuringMachine/vmtmachines/vmtmachinerightword.cpp b/VirtualTuringMachine/vmtmachines/vmtmachinerightword.cpp old mode 100755 new mode 100644 index 63c00f0..eaa0f72 --- a/VirtualTuringMachine/vmtmachines/vmtmachinerightword.cpp +++ b/VirtualTuringMachine/vmtmachines/vmtmachinerightword.cpp @@ -1,79 +1,92 @@ #include "vmtmachinerightword.h" + #include -#include "uicanvas.h" + #include "VMTComplexMachine.h" +#include "uicanvas.h" -VMTMachineRightWord::VMTMachineRightWord(std::weak_ptr parent) : - VMTMachineStub(QString("right word"), parent, IVMTMachine::MachineType::MT_RIGHT_WORD,ImageType::MACHINE_RIGHT_WORD){ - _size = QPoint(VMTMachineStub::_st.GetCellSize().width(),VMTMachineStub::_st.GetCellSize().height()); +VMTMachineRightWord::VMTMachineRightWord( + std::weak_ptr parent) + : VMTMachineStub(QString("right word"), parent, + IVMTMachine::MachineType::MT_RIGHT_WORD, + ImageType::MACHINE_RIGHT_WORD) { + _size = QPoint(VMTMachineStub::_st.GetCellSize().width(), + VMTMachineStub::_st.GetCellSize().height()); } -void VMTMachineRightWord::Serialize(QDataStream& stream){ +void VMTMachineRightWord::Serialize(QDataStream& stream) { VMTMachineStub::Serialize(stream); } -void VMTMachineRightWord::Deserialize(QDataStream& stream){ +void VMTMachineRightWord::Deserialize(QDataStream& stream) { VMTMachineStub::Deserialize(stream); } -std::shared_ptr VMTMachineRightWord::Clone(IVMTEnvironment*){ - std::shared_ptr result = std::shared_ptr(new VMTMachineRightWord(_parent)); +std::shared_ptr VMTMachineRightWord::Clone(IVMTEnvironment*) { + std::shared_ptr result = + std::shared_ptr(new VMTMachineRightWord(_parent)); - std::dynamic_pointer_cast(result)->_center = _center; - std::dynamic_pointer_cast(result)->_bounds = _bounds; - std::dynamic_pointer_cast(result)->_size = _size; - std::dynamic_pointer_cast(result)->_power = _power; + std::dynamic_pointer_cast(result)->_center = _center; + std::dynamic_pointer_cast(result)->_bounds = _bounds; + std::dynamic_pointer_cast(result)->_size = _size; + std::dynamic_pointer_cast(result)->_power = _power; - return result; + return result; } -std::shared_ptr VMTMachineRightWord::CreateComplexMachine(IVMTEnvironment* environment){ - if(_complex) return _complex; - - std::shared_ptr result = std::make_shared(QString("Right Word"),this->GetParent().lock()->GetAlphabit()); - - std::shared_ptr start = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_START,result); result->AddMachine(start); - std::shared_ptr left = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_RIGHT,result); result->AddMachine(left); - std::shared_ptr finish = VMTMachineStub::CreateMachineByID(IVMTMachine::MachineType::MT_FINISH,result); result->AddMachine(finish); - - const int STEP = 200; - - start->Move(QPoint(STEP,STEP),environment); - left->Move(QPoint(3*STEP,STEP),environment); - finish->Move(QPoint(5*STEP,STEP),environment); - - result->ConnectMachines(start,left,environment,result); - - - std::shared_ptr left_left = result->ConnectMachines(left,left,environment,result); - left_left->GetConditions().SetEnable(result->GetAlphabit()->GetLambda(),false,environment); - - std::shared_ptr left_finish = result->ConnectMachines(left,finish,environment,result); - for(int i=0;iGetAlphabit()->GetSignsCount();i++) - if(result->GetAlphabit()->GetSignAt(i)!=result->GetAlphabit()->GetLambda()) - left_finish->GetConditions().SetEnable(result->GetAlphabit()->GetSignAt(i),false,environment); - _complex = result; - return result; -} - -void VMTMachineRightWord::DoAction(std::shared_ptr line){ - line->ShiftRightWord(); -} - -bool VMTMachineRightWord::IsPowerCalculator(){ - return true; +std::shared_ptr VMTMachineRightWord::CreateComplexMachine( + IVMTEnvironment* environment) { + if (_complex) return _complex; + + std::shared_ptr result = + std::make_shared( + QString("Right Word"), this->GetParent().lock()->GetAlphabit()); + + std::shared_ptr start = VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_START, result); + result->AddMachine(start); + std::shared_ptr left = VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_RIGHT, result); + result->AddMachine(left); + std::shared_ptr finish = VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_FINISH, result); + result->AddMachine(finish); + + const int STEP = 200; + + start->Move(QPoint(STEP, STEP), environment); + left->Move(QPoint(3 * STEP, STEP), environment); + finish->Move(QPoint(5 * STEP, STEP), environment); + + result->ConnectMachines(start, left, environment, result); + + std::shared_ptr left_left = + result->ConnectMachines(left, left, environment, result); + left_left->GetConditions().SetEnable(result->GetAlphabit()->GetLambda(), + false, environment); + + std::shared_ptr left_finish = + result->ConnectMachines(left, finish, environment, result); + for (int i = 0; i < result->GetAlphabit()->GetSignsCount(); i++) + if (result->GetAlphabit()->GetSignAt(i) != + result->GetAlphabit()->GetLambda()) + left_finish->GetConditions().SetEnable( + result->GetAlphabit()->GetSignAt(i), false, environment); + _complex = result; + return result; } -bool VMTMachineRightWord::IsAlphabit(){ - return false; +void VMTMachineRightWord::DoAction(std::shared_ptr line) { + line->ShiftRightWord(); } -void VMTMachineRightWord::Paint(UICanvas& canvas, const QRect& rect){ - VMTMachineStub::Paint(canvas,rect); - canvas.DrawImage(ImageType::MACHINE_RIGHT_WORD,_internal_bounds); -} +bool VMTMachineRightWord::IsPowerCalculator() { return true; } -VMTMachineRightWord::~VMTMachineRightWord(){ +bool VMTMachineRightWord::IsAlphabit() { return false; } +void VMTMachineRightWord::Paint(UICanvas& canvas, const QRect& rect) { + VMTMachineStub::Paint(canvas, rect); + canvas.DrawImage(ImageType::MACHINE_RIGHT_WORD, _internal_bounds); } +VMTMachineRightWord::~VMTMachineRightWord() {} diff --git a/VirtualTuringMachine/vmtmachines/vmtmachinerightword.h b/VirtualTuringMachine/vmtmachines/vmtmachinerightword.h old mode 100755 new mode 100644 index 38b1775..f9c1968 --- a/VirtualTuringMachine/vmtmachines/vmtmachinerightword.h +++ b/VirtualTuringMachine/vmtmachines/vmtmachinerightword.h @@ -1,32 +1,30 @@ #ifndef VMTMACHINERIGHTWORD_H #define VMTMACHINERIGHTWORD_H - +#include "VMTComplexMachine.h" #include "VMTLine.h" #include "VMTMachineStub.h" -#include "VMTComplexMachine.h" -class VMTMachineRightWord : public VMTMachineStub -{ -protected: +class VMTMachineRightWord : public VMTMachineStub { + protected: std::shared_ptr _complex; -public: + + public: VMTMachineRightWord(std::weak_ptr parent); void Serialize(QDataStream&) override; void Deserialize(QDataStream&) override; std::shared_ptr Clone(IVMTEnvironment*) override; - std::shared_ptr CreateComplexMachine(IVMTEnvironment* environment) override; + std::shared_ptr CreateComplexMachine( + IVMTEnvironment* environment) override; void DoAction(std::shared_ptr line) override; bool IsPowerCalculator() override; bool IsAlphabit() override; - void Paint(UICanvas& canvas, const QRect& rect) override; virtual ~VMTMachineRightWord(); - }; -#endif // VMTMACHINERIGHTWORD_H +#endif // VMTMACHINERIGHTWORD_H diff --git a/VirtualTuringMachine/vmtmachines/vmtmachinestart.cpp b/VirtualTuringMachine/vmtmachines/vmtmachinestart.cpp old mode 100755 new mode 100644 index 791e04d..534c585 --- a/VirtualTuringMachine/vmtmachines/vmtmachinestart.cpp +++ b/VirtualTuringMachine/vmtmachines/vmtmachinestart.cpp @@ -1,49 +1,47 @@ #include "vmtmachinestart.h" + #include -#include "uicanvas.h" + #include "VMTComplexMachine.h" +#include "uicanvas.h" -VMTMachineStart::VMTMachineStart(std::weak_ptr parent) : - VMTMachineStub(QString("start"), parent, IVMTMachine::MachineType::MT_START,ImageType::MACHINE_START){ - _size = QPoint(VMTMachineStub::_st.GetCellSize().width(),VMTMachineStub::_st.GetCellSize().height()); +VMTMachineStart::VMTMachineStart(std::weak_ptr parent) + : VMTMachineStub(QString("start"), parent, + IVMTMachine::MachineType::MT_START, + ImageType::MACHINE_START) { + _size = QPoint(VMTMachineStub::_st.GetCellSize().width(), + VMTMachineStub::_st.GetCellSize().height()); } -void VMTMachineStart::Serialize(QDataStream& stream){ +void VMTMachineStart::Serialize(QDataStream& stream) { VMTMachineStub::Serialize(stream); } -void VMTMachineStart::Deserialize(QDataStream& stream){ +void VMTMachineStart::Deserialize(QDataStream& stream) { VMTMachineStub::Deserialize(stream); } -std::shared_ptr VMTMachineStart::Clone(IVMTEnvironment*){ - std::shared_ptr result = std::shared_ptr(new VMTMachineStart(_parent)); +std::shared_ptr VMTMachineStart::Clone(IVMTEnvironment*) { + std::shared_ptr result = + std::shared_ptr(new VMTMachineStart(_parent)); - std::dynamic_pointer_cast(result)->_center = _center; - std::dynamic_pointer_cast(result)->_bounds = _bounds; - std::dynamic_pointer_cast(result)->_size = _size; - std::dynamic_pointer_cast(result)->_power = _power; + std::dynamic_pointer_cast(result)->_center = _center; + std::dynamic_pointer_cast(result)->_bounds = _bounds; + std::dynamic_pointer_cast(result)->_size = _size; + std::dynamic_pointer_cast(result)->_power = _power; - return result; + return result; } -void VMTMachineStart::DoAction(std::shared_ptr ){ - -} +void VMTMachineStart::DoAction(std::shared_ptr) {} -bool VMTMachineStart::IsPowerCalculator(){ - return false; -} +bool VMTMachineStart::IsPowerCalculator() { return false; } -bool VMTMachineStart::IsAlphabit(){ - return false; -} +bool VMTMachineStart::IsAlphabit() { return false; } -void VMTMachineStart::Paint(UICanvas& canvas, const QRect& rect){ - VMTMachineStub::Paint(canvas,rect); - canvas.DrawImage(ImageType::MACHINE_START,_internal_bounds); +void VMTMachineStart::Paint(UICanvas& canvas, const QRect& rect) { + VMTMachineStub::Paint(canvas, rect); + canvas.DrawImage(ImageType::MACHINE_START, _internal_bounds); } -VMTMachineStart::~VMTMachineStart(){ - -} +VMTMachineStart::~VMTMachineStart() {} diff --git a/VirtualTuringMachine/vmtmachines/vmtmachinestart.h b/VirtualTuringMachine/vmtmachines/vmtmachinestart.h old mode 100755 new mode 100644 index 6d33c1e..f7de6fb --- a/VirtualTuringMachine/vmtmachines/vmtmachinestart.h +++ b/VirtualTuringMachine/vmtmachines/vmtmachinestart.h @@ -1,28 +1,23 @@ #ifndef VMTMACHINESTART_H #define VMTMACHINESTART_H - #include "VMTLine.h" #include "VMTMachineStub.h" -class VMTMachineStart : public VMTMachineStub -{ -public: +class VMTMachineStart : public VMTMachineStub { + public: VMTMachineStart(std::weak_ptr parent); void Serialize(QDataStream&) override; void Deserialize(QDataStream&) override; std::shared_ptr Clone(IVMTEnvironment*) override; - void DoAction(std::shared_ptr line) override; bool IsPowerCalculator() override; bool IsAlphabit() override; - void Paint(UICanvas& canvas, const QRect& rect) override; virtual ~VMTMachineStart(); - }; -#endif // VMTMACHINESTART_H +#endif // VMTMACHINESTART_H diff --git a/VirtualTuringMachine/vmtproject.cpp b/VirtualTuringMachine/vmtproject.cpp old mode 100755 new mode 100644 index 563edf8..abeae91 --- a/VirtualTuringMachine/vmtproject.cpp +++ b/VirtualTuringMachine/vmtproject.cpp @@ -2,79 +2,55 @@ VMTProject VMTProject::_instance; -VMTProject & VMTProject::GetInstance(){ - return _instance; -} +VMTProject& VMTProject::GetInstance() { return _instance; } -VMTProject::VMTProject() : _test_mode(false), _exercise(nullptr) -{ +VMTProject::VMTProject() : _test_mode(false), _exercise(nullptr) { _alphabit = std::shared_ptr(new VMTAlphabit()); - _undo = std::shared_ptr(new VMTUndoManager()); + _undo = std::shared_ptr(new VMTUndoManager()); } -bool VMTProject::IsTestMode(){ - return _test_mode; -} -void VMTProject::SetTestMode(bool test){ - _test_mode = test; -} -std::shared_ptr VMTProject::GetExercise(){ - return _exercise; -} +bool VMTProject::IsTestMode() { return _test_mode; } +void VMTProject::SetTestMode(bool test) { _test_mode = test; } +std::shared_ptr VMTProject::GetExercise() { return _exercise; } -void VMTProject::SetExercise(std::shared_ptr ex){ - _exercise = ex; -} +void VMTProject::SetExercise(std::shared_ptr ex) { _exercise = ex; } -void VMTProject::SetUIState(std::shared_ptr state){ +void VMTProject::SetUIState(std::shared_ptr state) { _ui_state = state; } -std::weak_ptr VMTProject::GetUIState(){ - return _ui_state; -} +std::weak_ptr VMTProject::GetUIState() { return _ui_state; } -void VMTProject::SetAlphabit(std::shared_ptr alphabit){ +void VMTProject::SetAlphabit(std::shared_ptr alphabit) { _alphabit = alphabit; } -QString & VMTProject::GetCurrentMachineName(){ - return _current_machine_name; -} +QString& VMTProject::GetCurrentMachineName() { return _current_machine_name; } -std::shared_ptr VMTProject::GetCurrentMachine(){ - for(auto machine: _machines){ - if(_current_machine_name == machine->GetName()) return machine; +std::shared_ptr VMTProject::GetCurrentMachine() { + for (auto machine : _machines) { + if (_current_machine_name == machine->GetName()) return machine; } return std::shared_ptr(); } -std::shared_ptr VMTProject::GetMachine(QString& name){ - - for(auto machine: _machines){ - if(name == machine->GetName()) return machine; +std::shared_ptr VMTProject::GetMachine(QString& name) { + for (auto machine : _machines) { + if (name == machine->GetName()) return machine; } return std::shared_ptr(); } -std::vector> & VMTProject::GetMachines(){ +std::vector>& VMTProject::GetMachines() { return _machines; } -std::shared_ptr VMTProject::GetUndoManager(){ - return _undo; -} +std::shared_ptr VMTProject::GetUndoManager() { return _undo; } -std::shared_ptr VMTProject::GetAlphabit(){ - return _alphabit; -} +std::shared_ptr VMTProject::GetAlphabit() { return _alphabit; } -QString & VMTProject::GetName(){ - return _name; -} +QString& VMTProject::GetName() { return _name; } -QString & VMTProject::GetLocation(){ - return _location; -} +QString& VMTProject::GetLocation() { return _location; } diff --git a/VirtualTuringMachine/vmtproject.h b/VirtualTuringMachine/vmtproject.h old mode 100755 new mode 100644 index 4e6c66e..bec60e9 --- a/VirtualTuringMachine/vmtproject.h +++ b/VirtualTuringMachine/vmtproject.h @@ -1,54 +1,54 @@ #ifndef VMTPROJECT_H #define VMTPROJECT_H -#include "VMTAlphabit.h" -#include "vmtproject.h" -#include "exercise.h" +#include +#include + +#include #include #include -#include -#include -#include + +#include "VMTAlphabit.h" +#include "exercise.h" +#include "vmtproject.h" class UIStateData; -class VMTProject -{ -protected: +class VMTProject { + protected: static VMTProject _instance; - - QString _name; - QString _location; - QString _current_machine_name; + QString _name; + QString _location; + QString _current_machine_name; std::weak_ptr _ui_state; - bool _test_mode; + bool _test_mode; - std::shared_ptr _alphabit; - std::shared_ptr _undo; - std::shared_ptr _exercise; + std::shared_ptr _alphabit; + std::shared_ptr _undo; + std::shared_ptr _exercise; std::vector> _machines; VMTProject(); -public: - static VMTProject & GetInstance(); + public: + static VMTProject& GetInstance(); - bool IsTestMode(); - QString & GetName(); - QString & GetLocation(); - QString & GetCurrentMachineName(); + bool IsTestMode(); + QString& GetName(); + QString& GetLocation(); + QString& GetCurrentMachineName(); void SetTestMode(bool); void SetAlphabit(std::shared_ptr alphabit); void SetExercise(std::shared_ptr); void SetUIState(std::shared_ptr state); - std::shared_ptr GetAlphabit(); - std::shared_ptr GetExercise(); - std::shared_ptr GetUndoManager(); - std::shared_ptr GetMachine(QString& name); - std::shared_ptr GetCurrentMachine(); - std::weak_ptr GetUIState(); - std::vector> & GetMachines(); + std::shared_ptr GetAlphabit(); + std::shared_ptr GetExercise(); + std::shared_ptr GetUndoManager(); + std::shared_ptr GetMachine(QString& name); + std::shared_ptr GetCurrentMachine(); + std::weak_ptr GetUIState(); + std::vector>& GetMachines(); }; -#endif // VMTPROJECT_H +#endif // VMTPROJECT_H diff --git a/VirtualTuringMachine/vmttheme.cpp b/VirtualTuringMachine/vmttheme.cpp index b45feee..783ee1f 100644 --- a/VirtualTuringMachine/vmttheme.cpp +++ b/VirtualTuringMachine/vmttheme.cpp @@ -1,9 +1,5 @@ #include "vmttheme.h" -#include "formeditorwidget.h" -#include "formlinewidget.h" -#include "vmticons.h" - #include #include #include @@ -14,40 +10,43 @@ #include #include +#include "formeditorwidget.h" +#include "formlinewidget.h" +#include "vmticons.h" + namespace { -QColor gPrimary(25, 118, 210); // #1976D2 -QColor gPrimaryDark(1, 44, 64); // #012C40 toolbar chrome -QColor gPrimaryLight(227, 242, 253); // #E3F2FD +QColor gPrimary(25, 118, 210); // #1976D2 +QColor gPrimaryDark(1, 44, 64); // #012C40 toolbar chrome +QColor gPrimaryLight(227, 242, 253); // #E3F2FD QColor gOnPrimary(255, 255, 255); -QColor gBackground(245, 245, 245); // #F5F5F5 app bg +QColor gBackground(245, 245, 245); // #F5F5F5 app bg QColor gSurface(255, 255, 255); QColor gOnSurface(33, 33, 33); // #212121 QColor gOnSurfaceSecondary(97, 97, 97); // #616161 -QColor gDivider(189, 189, 189); // #BDBDBD +QColor gDivider(189, 189, 189); // #BDBDBD QColor gSelectionBackground(187, 222, 251); QColor gOnSelection(21, 101, 192); -QColor gError(211, 47, 47); // #D32F2F +QColor gError(211, 47, 47); // #D32F2F QColor gOnError(255, 255, 255); -QColor gCanvasWorkspace(236, 239, 241); // #ECEFF1 editor wrap +QColor gCanvasWorkspace(236, 239, 241); // #ECEFF1 editor wrap QColor gDiagramBackground(250, 250, 250); // #FAFAFA stage QColor gDiagramGrid(224, 224, 224); // #E0E0E0 QColor gDiagramLine(33, 33, 33); // #212121 QColor gDiagramLineSelected(25, 118, 210); QColor gMachineFill(255, 255, 255); -QColor gMachineFillSelected(187, 222, 251); // #BBDEFB +QColor gMachineFillSelected(187, 222, 251); // #BBDEFB QColor gDiagramNodeFillSelected(187, 222, 251); QColor gDiagramNodeBorder(33, 33, 33); QColor gDiagramNodeBorderSelected(25, 118, 210); bool gDarkMode = false; -void applyLightPalette() -{ +void applyLightPalette() { gPrimary = QColor(25, 118, 210); gPrimaryDark = QColor(1, 44, 64); gPrimaryLight = QColor(227, 242, 253); @@ -73,8 +72,7 @@ void applyLightPalette() gDiagramNodeBorderSelected = QColor(25, 118, 210); } -void applyDarkPalette() -{ +void applyDarkPalette() { gPrimary = QColor(66, 165, 245); gPrimaryDark = QColor(1, 44, 64); gPrimaryLight = QColor(38, 50, 56); @@ -100,33 +98,34 @@ void applyDarkPalette() gDiagramNodeBorderSelected = QColor(66, 165, 245); } -bool isLegacyStyleSheet(const QString& styleSheet) -{ - return styleSheet.contains("#012C40", Qt::CaseInsensitive) - || styleSheet.contains("#01547a", Qt::CaseInsensitive) - || styleSheet.contains("rgb(232,143,12)", Qt::CaseInsensitive) - || styleSheet.contains("rgb(232, 143, 12)", Qt::CaseInsensitive) - || styleSheet.contains("background-color:gray", Qt::CaseInsensitive) - || styleSheet.contains("color:darkgray", Qt::CaseInsensitive) - || styleSheet.contains("rgb(80, 80, 80)", Qt::CaseInsensitive); +bool isLegacyStyleSheet(const QString& styleSheet) { + return styleSheet.contains("#012C40", Qt::CaseInsensitive) || + styleSheet.contains("#01547a", Qt::CaseInsensitive) || + styleSheet.contains("rgb(232,143,12)", Qt::CaseInsensitive) || + styleSheet.contains("rgb(232, 143, 12)", Qt::CaseInsensitive) || + styleSheet.contains("background-color:gray", Qt::CaseInsensitive) || + styleSheet.contains("color:darkgray", Qt::CaseInsensitive) || + styleSheet.contains("rgb(80, 80, 80)", Qt::CaseInsensitive); } -bool shouldClearWidgetStyle(const QString& styleSheet) -{ +bool shouldClearWidgetStyle(const QString& styleSheet) { if (styleSheet.isEmpty()) { return false; } if (isLegacyStyleSheet(styleSheet)) { return true; } - return styleSheet.contains(QStringLiteral("background:white"), Qt::CaseInsensitive) - || styleSheet.contains(QStringLiteral("background-color:white"), Qt::CaseInsensitive) - || styleSheet.contains(QStringLiteral("background-color: white"), Qt::CaseInsensitive) - || styleSheet.contains(QStringLiteral("background: white"), Qt::CaseInsensitive); + return styleSheet.contains(QStringLiteral("background:white"), + Qt::CaseInsensitive) || + styleSheet.contains(QStringLiteral("background-color:white"), + Qt::CaseInsensitive) || + styleSheet.contains(QStringLiteral("background-color: white"), + Qt::CaseInsensitive) || + styleSheet.contains(QStringLiteral("background: white"), + Qt::CaseInsensitive); } -void applyThemedWidget(QWidget* widget) -{ +void applyThemedWidget(QWidget* widget) { if (!widget) { return; } @@ -139,7 +138,8 @@ void applyThemedWidget(QWidget* widget) lineEdit->setStyleSheet(VmtTheme::inputStyle()); } else if (auto* textEdit = qobject_cast(widget)) { const QString name = textEdit->objectName(); - if (name == QLatin1String("_text") || name == QLatin1String("_text_ru")) { + if (name == QLatin1String("_text") || + name == QLatin1String("_text_ru")) { textEdit->setStyleSheet(VmtTheme::accentPanelStyle()); } else { textEdit->setStyleSheet(VmtTheme::inputStyle()); @@ -155,9 +155,10 @@ void applyThemedWidget(QWidget* widget) } else if (auto* tool = qobject_cast(widget)) { if (tool->objectName().startsWith(QLatin1String("button_z"))) { tool->setStyleSheet(VmtTheme::surfaceToolButtonStyle()); - } else if (widget->parentWidget() - && QLatin1String(widget->parentWidget()->metaObject()->className()) - == QLatin1String("FormAlphabit")) { + } else if (widget->parentWidget() && + QLatin1String( + widget->parentWidget()->metaObject()->className()) == + QLatin1String("FormAlphabit")) { tool->setStyleSheet(VmtTheme::alphabetButtonStyle()); } } @@ -169,8 +170,7 @@ void applyThemedWidget(QWidget* widget) } } -void polishWidgetTreeImpl(QWidget* root) -{ +void polishWidgetTreeImpl(QWidget* root) { if (!root) { return; } @@ -186,7 +186,7 @@ void polishWidgetTreeImpl(QWidget* root) } } -} // namespace +} // namespace const QColor& VmtTheme::primary() { return gPrimary; } const QColor& VmtTheme::primaryDark() { return gPrimaryDark; } @@ -212,17 +212,19 @@ const QColor& VmtTheme::diagramLine() { return gDiagramLine; } const QColor& VmtTheme::diagramLineSelected() { return gDiagramLineSelected; } const QColor& VmtTheme::machineFill() { return gMachineFill; } const QColor& VmtTheme::machineFillSelected() { return gMachineFillSelected; } -const QColor& VmtTheme::diagramNodeFillSelected() { return gDiagramNodeFillSelected; } +const QColor& VmtTheme::diagramNodeFillSelected() { + return gDiagramNodeFillSelected; +} const QColor& VmtTheme::diagramNodeBorder() { return gDiagramNodeBorder; } -const QColor& VmtTheme::diagramNodeBorderSelected() { return gDiagramNodeBorderSelected; } +const QColor& VmtTheme::diagramNodeBorderSelected() { + return gDiagramNodeBorderSelected; +} -QString VmtTheme::colorName(const QColor& color) -{ +QString VmtTheme::colorName(const QColor& color) { return color.name(QColor::HexRgb); } -QString VmtTheme::applicationStyleSheet() -{ +QString VmtTheme::applicationStyleSheet() { const QString primary = colorName(gPrimary); const QString primaryDark = colorName(gPrimaryDark); const QString onPrimary = colorName(gOnPrimary); @@ -236,232 +238,210 @@ QString VmtTheme::applicationStyleSheet() const QString error = colorName(gError); return QString( - "QWidget {" - " background-color: %1;" - " color: %2;" - "}" - "QMainWindow, QDialog {" - " background-color: %1;" - "}" - "QFrame, QGroupBox {" - " background-color: %3;" - " color: %2;" - " border: none;" - "}" - "QLabel {" - " background-color: transparent;" - " color: %2;" - "}" - "QLineEdit, QTextEdit, QPlainTextEdit, QSpinBox, QComboBox {" - " background-color: %3;" - " color: %2;" - " border: 1px solid %4;" - " border-radius: 4px;" - " padding: 4px;" - " selection-background-color: %5;" - " selection-color: %6;" - "}" - "QListWidget, QListView, QTreeView, QTableView {" - " background-color: %3;" - " color: %2;" - " border: 1px solid %4;" - " selection-background-color: %5;" - " selection-color: %6;" - "}" - "QPushButton {" - " background-color: %3;" - " color: %2;" - " border: 1px solid %4;" - " border-radius: 4px;" - " padding: 6px 12px;" - "}" - "QPushButton:hover {" - " background-color: %5;" - " color: %6;" - "}" - "QPushButton:pressed {" - " background-color: %7;" - " color: %8;" - "}" - "QSlider::groove:horizontal {" - " background: %4;" - " height: 4px;" - " border-radius: 2px;" - "}" - "QSlider::handle:horizontal {" - " background: %7;" - " width: 14px;" - " margin: -5px 0;" - " border-radius: 7px;" - "}" - "QScrollBar:vertical {" - " background: %1;" - " width: 10px;" - "}" - "QScrollBar::handle:vertical {" - " background: %4;" - " border-radius: 5px;" - " min-height: 24px;" - "}" - ) - .arg(background, onSurface, surface, divider, selectionBg, onSelection, primaryDark, onPrimary); + "QWidget {" + " background-color: %1;" + " color: %2;" + "}" + "QMainWindow, QDialog {" + " background-color: %1;" + "}" + "QFrame, QGroupBox {" + " background-color: %3;" + " color: %2;" + " border: none;" + "}" + "QLabel {" + " background-color: transparent;" + " color: %2;" + "}" + "QLineEdit, QTextEdit, QPlainTextEdit, QSpinBox, QComboBox {" + " background-color: %3;" + " color: %2;" + " border: 1px solid %4;" + " border-radius: 4px;" + " padding: 4px;" + " selection-background-color: %5;" + " selection-color: %6;" + "}" + "QListWidget, QListView, QTreeView, QTableView {" + " background-color: %3;" + " color: %2;" + " border: 1px solid %4;" + " selection-background-color: %5;" + " selection-color: %6;" + "}" + "QPushButton {" + " background-color: %3;" + " color: %2;" + " border: 1px solid %4;" + " border-radius: 4px;" + " padding: 6px 12px;" + "}" + "QPushButton:hover {" + " background-color: %5;" + " color: %6;" + "}" + "QPushButton:pressed {" + " background-color: %7;" + " color: %8;" + "}" + "QSlider::groove:horizontal {" + " background: %4;" + " height: 4px;" + " border-radius: 2px;" + "}" + "QSlider::handle:horizontal {" + " background: %7;" + " width: 14px;" + " margin: -5px 0;" + " border-radius: 7px;" + "}" + "QScrollBar:vertical {" + " background: %1;" + " width: 10px;" + "}" + "QScrollBar::handle:vertical {" + " background: %4;" + " border-radius: 5px;" + " min-height: 24px;" + "}") + .arg(background, onSurface, surface, divider, selectionBg, onSelection, + primaryDark, onPrimary); } -QString VmtTheme::headerChromeStyle() -{ +QString VmtTheme::headerChromeStyle() { return QString("QWidget { background-color: %1; color: %2; }") .arg(colorName(gPrimaryDark), colorName(gOnPrimary)); } -QString VmtTheme::contentAreaStyle() -{ +QString VmtTheme::contentAreaStyle() { return QString("QWidget { background-color: %1; color: %2; }") .arg(colorName(gBackground), colorName(gOnSurface)); } -QString VmtTheme::breadcrumbLinkStyle() -{ +QString VmtTheme::breadcrumbLinkStyle() { return QString( - "QLabel { color: #BBDEFB; background: transparent; text-decoration: underline; }"); + "QLabel { color: #BBDEFB; background: transparent; text-decoration: " + "underline; }"); } -QString VmtTheme::breadcrumbCurrentStyle() -{ - return QString("QLabel { color: %1; background: transparent; font-weight: bold; }") +QString VmtTheme::breadcrumbCurrentStyle() { + return QString( + "QLabel { color: %1; background: transparent; font-weight: " + "bold; }") .arg(colorName(gOnPrimary)); } -QString VmtTheme::toolButtonStyle() -{ +QString VmtTheme::toolButtonStyle() { return QString( - "QToolButton { background-color: transparent; color: %1; border: none; border-radius: 4px; }" - "QToolButton:hover { background-color: %2; color: %3; }" - "QToolButton:checked { background-color: %4; color: %5; }") - .arg(colorName(gOnSurface), - colorName(gSelectionBackground), - colorName(gOnSelection), - colorName(gPrimaryDark), + "QToolButton { background-color: transparent; color: %1; " + "border: none; border-radius: 4px; }" + "QToolButton:hover { background-color: %2; color: %3; }" + "QToolButton:checked { background-color: %4; color: %5; }") + .arg(colorName(gOnSurface), colorName(gSelectionBackground), + colorName(gOnSelection), colorName(gPrimaryDark), colorName(gOnPrimary)); } -QString VmtTheme::iconToolButtonStyle() -{ +QString VmtTheme::iconToolButtonStyle() { return QString( - "QToolButton {" - " background-color: transparent;" - " border: none;" - " border-radius: 4px;" - " padding: 4px;" - "}" - "QToolButton:hover {" - " background-color: %1;" - "}" - "QToolButton:pressed {" - " background-color: %2;" - "}" - "QToolButton:checked {" - " background-color: %1;" - " border: 1px solid %3;" - "}" - "QToolButton:disabled {" - " background-color: transparent;" - " opacity: 0.45;" - "}") - .arg(colorName(gPrimary), - colorName(gPrimaryDark), + "QToolButton {" + " background-color: transparent;" + " border: none;" + " border-radius: 4px;" + " padding: 4px;" + "}" + "QToolButton:hover {" + " background-color: %1;" + "}" + "QToolButton:pressed {" + " background-color: %2;" + "}" + "QToolButton:checked {" + " background-color: %1;" + " border: 1px solid %3;" + "}" + "QToolButton:disabled {" + " background-color: transparent;" + " opacity: 0.45;" + "}") + .arg(colorName(gPrimary), colorName(gPrimaryDark), colorName(gOnPrimary)); } -QString VmtTheme::toolbarToolButtonStyle() -{ - return iconToolButtonStyle(); -} +QString VmtTheme::toolbarToolButtonStyle() { return iconToolButtonStyle(); } -QString VmtTheme::inputStyle() -{ +QString VmtTheme::inputStyle() { return QString( - "QLineEdit, QTextEdit, QPlainTextEdit, QSpinBox, QComboBox {" - " background-color: %1;" - " color: %2;" - " border: 1px solid %3;" - " border-radius: 4px;" - " padding: 4px;" - " selection-background-color: %4;" - " selection-color: %5;" - "}") - .arg(colorName(gSurface), - colorName(gOnSurface), - colorName(gDivider), - colorName(gSelectionBackground), - colorName(gOnSelection)); + "QLineEdit, QTextEdit, QPlainTextEdit, QSpinBox, QComboBox {" + " background-color: %1;" + " color: %2;" + " border: 1px solid %3;" + " border-radius: 4px;" + " padding: 4px;" + " selection-background-color: %4;" + " selection-color: %5;" + "}") + .arg(colorName(gSurface), colorName(gOnSurface), colorName(gDivider), + colorName(gSelectionBackground), colorName(gOnSelection)); } -QString VmtTheme::surfaceToolButtonStyle() -{ +QString VmtTheme::surfaceToolButtonStyle() { return QString( - "QToolButton {" - " background-color: %1;" - " border: 1px solid %2;" - " border-radius: 4px;" - "}") + "QToolButton {" + " background-color: %1;" + " border: 1px solid %2;" + " border-radius: 4px;" + "}") .arg(colorName(gSurface), colorName(gDivider)); } -QString VmtTheme::alphabetButtonStyle() -{ +QString VmtTheme::alphabetButtonStyle() { return QString( - "QToolButton {" - " background-color: %1;" - " color: %2;" - " border: 1px solid %3;" - " border-radius: 4px;" - " font-size: 18px;" - " font-weight: bold;" - "}" - "QToolButton:hover {" - " background-color: %4;" - " color: %5;" - "}" - "QToolButton:checked {" - " background-color: %6;" - " color: %7;" - " border: 1px solid %6;" - "}") - .arg(colorName(gSurface), - colorName(gOnSurface), - colorName(gDivider), - colorName(gSelectionBackground), - colorName(gOnSelection), - colorName(gPrimaryDark), - colorName(gOnPrimary)); + "QToolButton {" + " background-color: %1;" + " color: %2;" + " border: 1px solid %3;" + " border-radius: 4px;" + " font-size: 18px;" + " font-weight: bold;" + "}" + "QToolButton:hover {" + " background-color: %4;" + " color: %5;" + "}" + "QToolButton:checked {" + " background-color: %6;" + " color: %7;" + " border: 1px solid %6;" + "}") + .arg(colorName(gSurface), colorName(gOnSurface), colorName(gDivider), + colorName(gSelectionBackground), colorName(gOnSelection), + colorName(gPrimaryDark), colorName(gOnPrimary)); } -QString VmtTheme::primaryButtonStyle() -{ +QString VmtTheme::primaryButtonStyle() { return QString( - "QPushButton {" - " background-color: %1;" - " color: %2;" - " border: none;" - " border-radius: 4px;" - " padding: 6px 12px;" - "}" - "QPushButton:hover {" - " background-color: %3;" - " color: %2;" - "}" - "QPushButton:pressed {" - " background-color: %4;" - " color: %2;" - "}") - .arg(colorName(gPrimary), - colorName(gOnPrimary), - colorName(gPrimaryDark), - colorName(gPrimaryDark)); + "QPushButton {" + " background-color: %1;" + " color: %2;" + " border: none;" + " border-radius: 4px;" + " padding: 6px 12px;" + "}" + "QPushButton:hover {" + " background-color: %3;" + " color: %2;" + "}" + "QPushButton:pressed {" + " background-color: %4;" + " color: %2;" + "}") + .arg(colorName(gPrimary), colorName(gOnPrimary), + colorName(gPrimaryDark), colorName(gPrimaryDark)); } -void VmtTheme::applyIconToolBar(QWidget* toolbarRoot) -{ +void VmtTheme::applyIconToolBar(QWidget* toolbarRoot) { if (!toolbarRoot) { return; } @@ -474,18 +454,14 @@ void VmtTheme::applyIconToolBar(QWidget* toolbarRoot) } } -void VmtTheme::applyIconToolBarsInTree(QWidget* root) -{ +void VmtTheme::applyIconToolBarsInTree(QWidget* root) { if (!root) { return; } static const QStringList toolbarFrameNames = { - QStringLiteral("frame_header"), - QStringLiteral("frame"), - QStringLiteral("tool_frame"), - QStringLiteral("frame_navi"), - QStringLiteral("frame_2"), - QStringLiteral("frame_4"), + QStringLiteral("frame_header"), QStringLiteral("frame"), + QStringLiteral("tool_frame"), QStringLiteral("frame_navi"), + QStringLiteral("frame_2"), QStringLiteral("frame_4"), }; for (QWidget* widget : root->findChildren()) { if (toolbarFrameNames.contains(widget->objectName())) { @@ -494,75 +470,62 @@ void VmtTheme::applyIconToolBarsInTree(QWidget* root) } } -QString VmtTheme::accentPanelStyle() -{ +QString VmtTheme::accentPanelStyle() { return QString( - "QTextEdit, QTextBrowser {" - " background-color: %1;" - " color: %2;" - " border: 1px solid %3;" - " border-radius: 4px;" - "}") - .arg(colorName(gPrimaryLight), - colorName(gOnSelection), + "QTextEdit, QTextBrowser {" + " background-color: %1;" + " color: %2;" + " border: 1px solid %3;" + " border-radius: 4px;" + "}") + .arg(colorName(gPrimaryLight), colorName(gOnSelection), colorName(gPrimary)); } -QString VmtTheme::lineEditTapeStyle(bool machineHead) -{ +QString VmtTheme::lineEditTapeStyle(bool machineHead) { if (machineHead) { return QString( - "QLineEdit {" - " background-color: %1;" - " color: %2;" - " selection-background-color: %2;" - " selection-color: %1;" - " border: 1px solid %1;" - " font-weight: bold;" - "}") + "QLineEdit {" + " background-color: %1;" + " color: %2;" + " selection-background-color: %2;" + " selection-color: %1;" + " border: 1px solid %1;" + " font-weight: bold;" + "}") .arg(colorName(gPrimaryDark), colorName(gOnPrimary)); } return QString( - "QLineEdit {" - " background-color: %1;" - " color: %2;" - " border: 1px solid %3;" - " selection-background-color: %4;" - " selection-color: %5;" - "}") - .arg(colorName(gSurface), - colorName(gOnSurface), - colorName(gDivider), - colorName(gSelectionBackground), - colorName(gOnSelection)); + "QLineEdit {" + " background-color: %1;" + " color: %2;" + " border: 1px solid %3;" + " selection-background-color: %4;" + " selection-color: %5;" + "}") + .arg(colorName(gSurface), colorName(gOnSurface), colorName(gDivider), + colorName(gSelectionBackground), colorName(gOnSelection)); } -QString VmtTheme::panelSurfaceStyle() -{ +QString VmtTheme::panelSurfaceStyle() { return QString("QWidget { background-color: %1; color: %2; }") .arg(colorName(gSurface), colorName(gOnSurface)); } -QString VmtTheme::listSurfaceStyle() -{ +QString VmtTheme::listSurfaceStyle() { return QString( - "QListWidget { background-color: %1; color: %2; border: 1px solid %3; }" - "QListWidget::item:selected { background-color: %4; color: %5; }") - .arg(colorName(gSurface), - colorName(gOnSurface), - colorName(gDivider), - colorName(gPrimaryDark), - colorName(gOnPrimary)); + "QListWidget { background-color: %1; color: %2; border: 1px " + "solid %3; }" + "QListWidget::item:selected { background-color: %4; color: %5; " + "}") + .arg(colorName(gSurface), colorName(gOnSurface), colorName(gDivider), + colorName(gPrimaryDark), colorName(gOnPrimary)); } -bool VmtTheme::isDarkMode() -{ - return gDarkMode; -} +bool VmtTheme::isDarkMode() { return gDarkMode; } -void VmtTheme::setDarkMode(bool dark, QApplication* app) -{ +void VmtTheme::setDarkMode(bool dark, QApplication* app) { gDarkMode = dark; if (dark) { applyDarkPalette(); @@ -574,21 +537,16 @@ void VmtTheme::setDarkMode(bool dark, QApplication* app) } } -void VmtTheme::applyApplication(QApplication* app) -{ +void VmtTheme::applyApplication(QApplication* app) { if (!app) { return; } app->setStyleSheet(applicationStyleSheet()); } -void VmtTheme::polishWidgetTree(QWidget* root) -{ - polishWidgetTreeImpl(root); -} +void VmtTheme::polishWidgetTree(QWidget* root) { polishWidgetTreeImpl(root); } -void VmtTheme::applyThemedWidgets(QWidget* root) -{ +void VmtTheme::applyThemedWidgets(QWidget* root) { if (!root) { return; } @@ -600,8 +558,7 @@ void VmtTheme::applyThemedWidgets(QWidget* root) } } -void VmtTheme::refreshDiagramViews(QWidget* root) -{ +void VmtTheme::refreshDiagramViews(QWidget* root) { if (!root) { return; } diff --git a/VirtualTuringMachine/vmttheme.h b/VirtualTuringMachine/vmttheme.h index 68a418e..2cf72de 100644 --- a/VirtualTuringMachine/vmttheme.h +++ b/VirtualTuringMachine/vmttheme.h @@ -8,9 +8,8 @@ class QApplication; class QWidget; /** Material Design 2 palette and styles for VTM. */ -class VmtTheme -{ -public: +class VmtTheme { + public: // --- Material palette (Blue primary) --- static const QColor& primary(); static const QColor& primaryDark(); @@ -47,9 +46,11 @@ class VmtTheme static void refreshDiagramViews(QWidget* root); static void applyApplication(QApplication* app); static void polishWidgetTree(QWidget* root); - /** Clear hard-coded UI colors and apply themed inputs, lists, canvas, tape. */ + /** Clear hard-coded UI colors and apply themed inputs, lists, canvas, tape. + */ static void applyThemedWidgets(QWidget* root); - /** Dark chrome + button styles for toolbars that use white/light pixmap icons. */ + /** Dark chrome + button styles for toolbars that use white/light pixmap + * icons. */ static void applyIconToolBar(QWidget* toolbarRoot); /** Re-apply toolbar chrome on all known toolbar frames under root. */ static void applyIconToolBarsInTree(QWidget* root); @@ -74,4 +75,4 @@ class VmtTheme static QString colorName(const QColor& color); }; -#endif // VMTTHEME_H +#endif // VMTTHEME_H diff --git a/VirtualTuringMachine/vmtundoelement.cpp b/VirtualTuringMachine/vmtundoelement.cpp old mode 100755 new mode 100644 index f4e4fc8..2788961 --- a/VirtualTuringMachine/vmtundoelement.cpp +++ b/VirtualTuringMachine/vmtundoelement.cpp @@ -1,27 +1,19 @@ #include "vmtundoelement.h" -VMTUndoElement::VMTUndoElement() -{ +VMTUndoElement::VMTUndoElement() {} -} - -void VMTUndoElement::SetUIState(std::weak_ptr ptr){ +void VMTUndoElement::SetUIState(std::weak_ptr ptr) { _ui_state = ptr; } -std::weak_ptr VMTUndoElement::GetUIState(){ - return _ui_state; -} +std::weak_ptr VMTUndoElement::GetUIState() { return _ui_state; } -void VMTUndoElement::SetCurrentMachineName(QString current_machine_name){ - _current_machine_name = current_machine_name; +void VMTUndoElement::SetCurrentMachineName(QString current_machine_name) { + _current_machine_name = current_machine_name; } -const QString& VMTUndoElement::GetCurrentMachineName(){ - return _current_machine_name; +const QString& VMTUndoElement::GetCurrentMachineName() { + return _current_machine_name; } -VMTUndoElement::~VMTUndoElement() -{ - -} +VMTUndoElement::~VMTUndoElement() {} diff --git a/VirtualTuringMachine/vmtundoelement.h b/VirtualTuringMachine/vmtundoelement.h old mode 100755 new mode 100644 index a967b0a..9fef076 --- a/VirtualTuringMachine/vmtundoelement.h +++ b/VirtualTuringMachine/vmtundoelement.h @@ -1,27 +1,27 @@ #ifndef VMTUNDOELEMENT_H #define VMTUNDOELEMENT_H -#include #include +#include class VMTLine; class VMTComplexMachine; class UIStateData; class IVMTEnvironment; -class VMTUndoElement -{ -protected: +class VMTUndoElement { + protected: std::weak_ptr _ui_state; - QString _current_machine_name; -public: + QString _current_machine_name; + + public: VMTUndoElement(); - void SetUIState(std::weak_ptr ptr); - std::weak_ptr GetUIState(); - void SetCurrentMachineName(QString current_machine_name); - const QString& GetCurrentMachineName(); + void SetUIState(std::weak_ptr ptr); + std::weak_ptr GetUIState(); + void SetCurrentMachineName(QString current_machine_name); + const QString& GetCurrentMachineName(); virtual void Undo(IVMTEnvironment*) = 0; virtual ~VMTUndoElement(); }; -#endif // VMTUNDOELEMENT_H +#endif // VMTUNDOELEMENT_H diff --git a/VirtualTuringMachine/vmtundoelementeditor.cpp b/VirtualTuringMachine/vmtundoelementeditor.cpp old mode 100755 new mode 100644 index 1427511..49aeef4 --- a/VirtualTuringMachine/vmtundoelementeditor.cpp +++ b/VirtualTuringMachine/vmtundoelementeditor.cpp @@ -1,14 +1,14 @@ #include "vmtundoelementeditor.h" + #include + #include "interfaces/IVMTEnvironment.h" -VMTUndoElementEditor::VMTUndoElementEditor(IVMTEnvironment* environment) -{ - _state = environment->GetGraphics().GetState(); +VMTUndoElementEditor::VMTUndoElementEditor(IVMTEnvironment* environment) { + _state = environment->GetGraphics().GetState(); } -void VMTUndoElementEditor::Undo(IVMTEnvironment* environment){ - environment->GetGraphics().SetState(_state); - environment->Repaint(QRect()); +void VMTUndoElementEditor::Undo(IVMTEnvironment* environment) { + environment->GetGraphics().SetState(_state); + environment->Repaint(QRect()); } - diff --git a/VirtualTuringMachine/vmtundoelementeditor.h b/VirtualTuringMachine/vmtundoelementeditor.h old mode 100755 new mode 100644 index 1c9c325..119a304 --- a/VirtualTuringMachine/vmtundoelementeditor.h +++ b/VirtualTuringMachine/vmtundoelementeditor.h @@ -1,16 +1,16 @@ #ifndef VMTUNDOELEMENTEDITOR_H #define VMTUNDOELEMENTEDITOR_H -#include "vmtundoelement.h" #include "uicanvas.h" +#include "vmtundoelement.h" -class VMTUndoElementEditor : public VMTUndoElement -{ -protected: +class VMTUndoElementEditor : public VMTUndoElement { + protected: UICanvasState _state; -public: + + public: VMTUndoElementEditor(IVMTEnvironment*); void Undo(IVMTEnvironment*) override; }; -#endif // VMTUNDOELEMENTEDITOR_H +#endif // VMTUNDOELEMENTEDITOR_H diff --git a/VirtualTuringMachine/vmtundoelementmachine.cpp b/VirtualTuringMachine/vmtundoelementmachine.cpp old mode 100755 new mode 100644 index 445e273..ca58e41 --- a/VirtualTuringMachine/vmtundoelementmachine.cpp +++ b/VirtualTuringMachine/vmtundoelementmachine.cpp @@ -1,20 +1,20 @@ #include "vmtundoelementmachine.h" + #include + #include "VMTSerializer.h" #include "vmtproject.h" -VMTUndoElementMachine::VMTUndoElementMachine() -{ - QBuffer buffer(&_array); - VMTSerializer serializer(VMTProject::GetInstance().GetName()); - serializer.Serialize(&VMTProject::GetInstance(),buffer); +VMTUndoElementMachine::VMTUndoElementMachine() { + QBuffer buffer(&_array); + VMTSerializer serializer(VMTProject::GetInstance().GetName()); + serializer.Serialize(&VMTProject::GetInstance(), buffer); } -void VMTUndoElementMachine::Undo(IVMTEnvironment*){ - QBuffer buffer(&_array); - VMTSerializer serializer(VMTProject::GetInstance().GetName()); - serializer.Deserialize(&VMTProject::GetInstance(),buffer); +void VMTUndoElementMachine::Undo(IVMTEnvironment*) { + QBuffer buffer(&_array); + VMTSerializer serializer(VMTProject::GetInstance().GetName()); + serializer.Deserialize(&VMTProject::GetInstance(), buffer); } -VMTUndoElementMachine::~VMTUndoElementMachine(){ -} +VMTUndoElementMachine::~VMTUndoElementMachine() {} diff --git a/VirtualTuringMachine/vmtundoelementmachine.h b/VirtualTuringMachine/vmtundoelementmachine.h old mode 100755 new mode 100644 index cd437ac..fc70376 --- a/VirtualTuringMachine/vmtundoelementmachine.h +++ b/VirtualTuringMachine/vmtundoelementmachine.h @@ -1,18 +1,19 @@ #ifndef VMTUNDOELEMENTMACHINE_H #define VMTUNDOELEMENTMACHINE_H -#include "vmtundoelement.h" #include #include -class VMTUndoElementMachine : public VMTUndoElement -{ -protected: +#include "vmtundoelement.h" + +class VMTUndoElementMachine : public VMTUndoElement { + protected: QByteArray _array; -public: + + public: VMTUndoElementMachine(); void Undo(IVMTEnvironment*) override; virtual ~VMTUndoElementMachine(); }; -#endif // VMTUNDOELEMENTMACHINE_H +#endif // VMTUNDOELEMENTMACHINE_H diff --git a/VirtualTuringMachine/vmtundomanager.cpp b/VirtualTuringMachine/vmtundomanager.cpp old mode 100755 new mode 100644 index 82cb380..22f3e00 --- a/VirtualTuringMachine/vmtundomanager.cpp +++ b/VirtualTuringMachine/vmtundomanager.cpp @@ -1,46 +1,43 @@ #include "vmtundomanager.h" + #include "interfaces/IVMTEnvironment.h" #include "vmtproject.h" -VMTUndoManager::VMTUndoManager() : _observer(nullptr) -{ - -} +VMTUndoManager::VMTUndoManager() : _observer(nullptr) {} -void VMTUndoManager::SetObserver(IVMTUndoObserver * observer){ - _observer = observer; +void VMTUndoManager::SetObserver(IVMTUndoObserver* observer) { + _observer = observer; } -bool VMTUndoManager::IsEnable(){ - return !_stack.empty(); -} +bool VMTUndoManager::IsEnable() { return !_stack.empty(); } -void VMTUndoManager::Remember(std::shared_ptr element){ - if(element) { - element->SetCurrentMachineName(VMTProject::GetInstance().GetCurrentMachineName()); +void VMTUndoManager::Remember(std::shared_ptr element) { + if (element) { + element->SetCurrentMachineName( + VMTProject::GetInstance().GetCurrentMachineName()); element->SetUIState(VMTProject::GetInstance().GetUIState()); _stack.push(element); qDebug() << "Remember"; - if(_observer) _observer->EnableUndoButton(IsEnable()); + if (_observer) _observer->EnableUndoButton(IsEnable()); } } -bool VMTUndoManager::Recall(IVMTEnvironment *environment){ - - if(!_stack.empty()){ +bool VMTUndoManager::Recall(IVMTEnvironment* environment) { + if (!_stack.empty()) { std::shared_ptr element = _stack.top(); _stack.pop(); element->Undo(environment); - VMTProject::GetInstance().GetCurrentMachineName() = element->GetCurrentMachineName(); - if(_observer) _observer->EnableUndoButton(IsEnable()); + VMTProject::GetInstance().GetCurrentMachineName() = + element->GetCurrentMachineName(); + if (_observer) _observer->EnableUndoButton(IsEnable()); return true; - } else return false; - + } else + return false; } -void VMTUndoManager::Clear(){ - while(!_stack.empty()) _stack.pop(); +void VMTUndoManager::Clear() { + while (!_stack.empty()) _stack.pop(); qDebug() << "Observer!!!"; - if(_observer) _observer->EnableUndoButton(IsEnable()); + if (_observer) _observer->EnableUndoButton(IsEnable()); } diff --git a/VirtualTuringMachine/vmtundomanager.h b/VirtualTuringMachine/vmtundomanager.h old mode 100755 new mode 100644 index ccc6a30..56df435 --- a/VirtualTuringMachine/vmtundomanager.h +++ b/VirtualTuringMachine/vmtundomanager.h @@ -6,21 +6,21 @@ class VMTComplexMachine; class VMTLine; class IVMTEnvironment; -#include "vmtundoelement.h" #include "interfaces/ivmtundoobserver.h" +#include "vmtundoelement.h" -class VMTUndoManager -{ -protected: +class VMTUndoManager { + protected: std::stack> _stack; - IVMTUndoObserver *_observer; -public: + IVMTUndoObserver* _observer; + + public: VMTUndoManager(); - void SetObserver(IVMTUndoObserver * observer); + void SetObserver(IVMTUndoObserver* observer); void Remember(std::shared_ptr element); - bool Recall(IVMTEnvironment *environment); + bool Recall(IVMTEnvironment* environment); void Clear(); bool IsEnable(); }; -#endif // VMTUNDOMANAGER_H +#endif // VMTUNDOMANAGER_H diff --git a/tests/pathfinder/test_pathfinder.cpp b/tests/pathfinder/test_pathfinder.cpp index b0780f0..22dd9a0 100644 --- a/tests/pathfinder/test_pathfinder.cpp +++ b/tests/pathfinder/test_pathfinder.cpp @@ -1,7 +1,6 @@ -#include -#include #include - +#include +#include #include #include #include @@ -10,13 +9,12 @@ namespace { -constexpr size_t kGridStep = 40; // как GetStep()*2 в реГакторе (step=20) +constexpr size_t kGridStep = 40; // как GetStep()*2 в реГакторе (step=20) struct DiagramLayout { std::vector nodes; - QRect totalBounds(int margin = 100) const - { + QRect totalBounds(int margin = 100) const { if (nodes.empty()) { return QRect(); } @@ -29,13 +27,12 @@ struct DiagramLayout { } }; -QRect makeNode(int centerX, int centerY, int halfSize = 15) -{ - return QRect(centerX - halfSize, centerY - halfSize, halfSize * 2, halfSize * 2); +QRect makeNode(int centerX, int centerY, int halfSize = 15) { + return QRect(centerX - halfSize, centerY - halfSize, halfSize * 2, + halfSize * 2); } -DiagramLayout chainLayout(int nodeCount, int spacing = 120, int centerY = 100) -{ +DiagramLayout chainLayout(int nodeCount, int spacing = 120, int centerY = 100) { DiagramLayout layout; layout.nodes.reserve(static_cast(nodeCount)); for (int i = 0; i < nodeCount; ++i) { @@ -44,51 +41,44 @@ DiagramLayout chainLayout(int nodeCount, int spacing = 120, int centerY = 100) return layout; } -DiagramLayout gridLayout(int columns, int rows, int spacingX = 120, int spacingY = 100) -{ +DiagramLayout gridLayout(int columns, int rows, int spacingX = 120, + int spacingY = 100) { DiagramLayout layout; for (int row = 0; row < rows; ++row) { for (int col = 0; col < columns; ++col) { - layout.nodes.push_back(makeNode(100 + col * spacingX, 80 + row * spacingY)); + layout.nodes.push_back( + makeNode(100 + col * spacingX, 80 + row * spacingY)); } } return layout; } -QPoint outputPoint(const QRect& node) -{ +QPoint outputPoint(const QRect& node) { return QPoint(node.right(), node.center().y()); } -QPoint inputPoint(const QRect& node) -{ +QPoint inputPoint(const QRect& node) { return QPoint(node.left(), node.center().y()); } -QPoint routeStartPoint(const QPoint& output) -{ +QPoint routeStartPoint(const QPoint& output) { QPoint result = output; result.rx() += static_cast(kGridStep / 2); return result; } -QPoint routeFinishPoint(const QPoint& input) -{ +QPoint routeFinishPoint(const QPoint& input) { QPoint result = input; result.rx() -= static_cast(kGridStep / 2); return result; } -int chebyshev(const QPoint& a, const QPoint& b) -{ +int chebyshev(const QPoint& a, const QPoint& b) { return std::max(std::abs(a.x() - b.x()), std::abs(a.y() - b.y())); } -bool pointNearSegment(const QPoint& point, - const QPoint& a, - const QPoint& b, - int tolerance = 3) -{ +bool pointNearSegment(const QPoint& point, const QPoint& a, const QPoint& b, + int tolerance = 3) { if (a.x() == b.x()) { if (std::abs(point.x() - a.x()) > tolerance) { return false; @@ -107,11 +97,12 @@ bool pointNearSegment(const QPoint& point, return point.x() >= minX - tolerance && point.x() <= maxX + tolerance; } - return chebyshev(point, a) + chebyshev(point, b) <= chebyshev(a, b) + tolerance; + return chebyshev(point, a) + chebyshev(point, b) <= + chebyshev(a, b) + tolerance; } -bool pathContainsPoint(const path_t& path, const QPoint& point, int tolerance = 3) -{ +bool pathContainsPoint(const path_t& path, const QPoint& point, + int tolerance = 3) { if (path.empty()) { return false; } @@ -131,12 +122,8 @@ bool pathContainsPoint(const path_t& path, const QPoint& point, int tolerance = return false; } -bool segmentsOverlap(const QPoint& a1, - const QPoint& a2, - const QPoint& b1, - const QPoint& b2, - int tolerance = 2) -{ +bool segmentsOverlap(const QPoint& a1, const QPoint& a2, const QPoint& b1, + const QPoint& b2, int tolerance = 2) { const bool aHorizontal = a1.y() == a2.y(); const bool bHorizontal = b1.y() == b2.y(); @@ -176,12 +163,12 @@ bool segmentsOverlap(const QPoint& a1, const int vMin = std::min(v1.y(), v2.y()); const int vMax = std::max(v1.y(), v2.y()); - return v1.x() >= hMin - tolerance && v1.x() <= hMax + tolerance && h1.y() >= vMin - tolerance - && h1.y() <= vMax + tolerance; + return v1.x() >= hMin - tolerance && v1.x() <= hMax + tolerance && + h1.y() >= vMin - tolerance && h1.y() <= vMax + tolerance; } -bool pathsShareOnlyEndpoints(const path_t& left, const path_t& right, int tolerance = 4) -{ +bool pathsShareOnlyEndpoints(const path_t& left, const path_t& right, + int tolerance = 4) { if (left.empty() || right.empty()) { return false; } @@ -193,17 +180,20 @@ bool pathsShareOnlyEndpoints(const path_t& left, const path_t& right, int tolera for (size_t i = 1; i < left.size(); ++i) { for (size_t j = 1; j < right.size(); ++j) { - if (!segmentsOverlap(left[i - 1], left[i], right[j - 1], right[j], tolerance)) { + if (!segmentsOverlap(left[i - 1], left[i], right[j - 1], right[j], + tolerance)) { continue; } const bool touchesSharedEndpoint = - chebyshev(left[i - 1], rightStart) <= tolerance - || chebyshev(left[i - 1], rightEnd) <= tolerance - || chebyshev(left[i], rightStart) <= tolerance || chebyshev(left[i], rightEnd) <= tolerance - || chebyshev(right[j - 1], leftStart) <= tolerance - || chebyshev(right[j - 1], leftEnd) <= tolerance - || chebyshev(right[j], leftStart) <= tolerance || chebyshev(right[j], leftEnd) <= tolerance; + chebyshev(left[i - 1], rightStart) <= tolerance || + chebyshev(left[i - 1], rightEnd) <= tolerance || + chebyshev(left[i], rightStart) <= tolerance || + chebyshev(left[i], rightEnd) <= tolerance || + chebyshev(right[j - 1], leftStart) <= tolerance || + chebyshev(right[j - 1], leftEnd) <= tolerance || + chebyshev(right[j], leftStart) <= tolerance || + chebyshev(right[j], leftEnd) <= tolerance; if (!touchesSharedEndpoint) { return false; @@ -214,8 +204,7 @@ bool pathsShareOnlyEndpoints(const path_t& left, const path_t& right, int tolera return true; } -bool pathsCrossEachOther(const std::vector& paths) -{ +bool pathsCrossEachOther(const std::vector& paths) { for (size_t i = 0; i < paths.size(); ++i) { for (size_t j = i + 1; j < paths.size(); ++j) { if (!pathsShareOnlyEndpoints(paths[i], paths[j])) { @@ -226,8 +215,8 @@ bool pathsCrossEachOther(const std::vector& paths) return false; } -bool pointInsideNodes(const QPoint& point, const std::vector& nodes, int shrink = 1) -{ +bool pointInsideNodes(const QPoint& point, const std::vector& nodes, + int shrink = 1) { for (const QRect& node : nodes) { QRect inner = node; inner.adjust(shrink, shrink, -shrink, -shrink); @@ -239,10 +228,8 @@ bool pointInsideNodes(const QPoint& point, const std::vector& nodes, int } bool pathAvoidsIntermediateNodes(const path_t& path, - const std::vector& nodes, - size_t fromIndex, - size_t toIndex) -{ + const std::vector& nodes, + size_t fromIndex, size_t toIndex) { if (path.size() < 2) { return true; } @@ -250,12 +237,14 @@ bool pathAvoidsIntermediateNodes(const path_t& path, for (size_t i = 1; i < path.size(); ++i) { const QPoint& from = path[i - 1]; const QPoint& to = path[i]; - const int steps = std::max(1, chebyshev(from, to) / static_cast(kGridStep / 2)); + const int steps = + std::max(1, chebyshev(from, to) / static_cast(kGridStep / 2)); for (int step = 0; step <= steps; ++step) { const double t = static_cast(step) / steps; - const QPoint sample(static_cast(from.x() + (to.x() - from.x()) * t), - static_cast(from.y() + (to.y() - from.y()) * t)); + const QPoint sample( + static_cast(from.x() + (to.x() - from.x()) * t), + static_cast(from.y() + (to.y() - from.y()) * t)); for (size_t nodeIndex = 0; nodeIndex < nodes.size(); ++nodeIndex) { if (nodeIndex == fromIndex || nodeIndex == toIndex) { @@ -274,16 +263,14 @@ bool pathAvoidsIntermediateNodes(const path_t& path, return true; } -wall_checker_t makeNodeWallChecker(const DiagramLayout& layout) -{ - return [&layout](const QPoint& point) { return pointInsideNodes(point, layout.nodes); }; +wall_checker_t makeNodeWallChecker(const DiagramLayout& layout) { + return [&layout](const QPoint& point) { + return pointInsideNodes(point, layout.nodes); + }; } -path_t assembleFullPath(const DiagramLayout& layout, - size_t fromIndex, - size_t toIndex, - const path_t& routedMiddle) -{ +path_t assembleFullPath(const DiagramLayout& layout, size_t fromIndex, + size_t toIndex, const path_t& routedMiddle) { path_t full; full.push_back(outputPoint(layout.nodes[fromIndex])); for (const QPoint& point : routedMiddle) { @@ -300,21 +287,15 @@ path_t assembleFullPath(const DiagramLayout& layout, path_t buildTransitionPath(const DiagramLayout& layout, const std::vector& existingPaths, - size_t fromIndex, - size_t toIndex) -{ + size_t fromIndex, size_t toIndex) { Pathfinder pathfinder; const QPoint start = routeStartPoint(outputPoint(layout.nodes[fromIndex])); const QPoint finish = routeFinishPoint(inputPoint(layout.nodes[toIndex])); const QRect bounds = layout.totalBounds(); - const path_t routedMiddle = pathfinder.GetPath(start, - finish, - bounds, - kGridStep, - makeNodeWallChecker(layout), - existingPaths, - static_cast(kGridStep / 2)); + const path_t routedMiddle = pathfinder.GetPath( + start, finish, bounds, kGridStep, makeNodeWallChecker(layout), + existingPaths, static_cast(kGridStep / 2)); return assembleFullPath(layout, fromIndex, toIndex, routedMiddle); } @@ -325,8 +306,8 @@ struct TransitionPath { path_t points; }; -std::vector collectPoints(const std::vector& transitions) -{ +std::vector collectPoints( + const std::vector& transitions) { std::vector paths; paths.reserve(transitions.size()); for (const TransitionPath& transition : transitions) { @@ -335,8 +316,7 @@ std::vector collectPoints(const std::vector& transitions return paths; } -std::vector buildChainPaths(const DiagramLayout& layout) -{ +std::vector buildChainPaths(const DiagramLayout& layout) { std::vector paths; if (layout.nodes.size() < 2) { return paths; @@ -354,44 +334,44 @@ std::vector buildChainPaths(const DiagramLayout& layout) return paths; } -std::vector buildExplicitPaths(const DiagramLayout& layout, - const std::vector>& edges) -{ +std::vector buildExplicitPaths( + const DiagramLayout& layout, + const std::vector>& edges) { std::vector paths; for (const auto& edge : edges) { TransitionPath transition; transition.fromIndex = edge.first; transition.toIndex = edge.second; - transition.points = - buildTransitionPath(layout, collectPoints(paths), edge.first, edge.second); + transition.points = buildTransitionPath(layout, collectPoints(paths), + edge.first, edge.second); paths.push_back(std::move(transition)); } return paths; } -bool allPathsNonEmpty(const std::vector& paths) -{ - return std::all_of(paths.begin(), paths.end(), [](const TransitionPath& transition) { - return !transition.points.empty(); - }); +bool allPathsNonEmpty(const std::vector& paths) { + return std::all_of(paths.begin(), paths.end(), + [](const TransitionPath& transition) { + return !transition.points.empty(); + }); } bool allPathsAvoidIntermediateNodes(const std::vector& paths, - const std::vector& nodes) -{ - return std::all_of(paths.begin(), paths.end(), [&](const TransitionPath& transition) { - return pathAvoidsIntermediateNodes(transition.points, nodes, transition.fromIndex, transition.toIndex); - }); + const std::vector& nodes) { + return std::all_of( + paths.begin(), paths.end(), [&](const TransitionPath& transition) { + return pathAvoidsIntermediateNodes(transition.points, nodes, + transition.fromIndex, + transition.toIndex); + }); } -bool allPathsSeparated(const std::vector& paths) -{ +bool allPathsSeparated(const std::vector& paths) { const std::vector points = collectPoints(paths); return !pathsCrossEachOther(points); } -int countBends(const path_t& path) -{ +int countBends(const path_t& path) { if (path.size() < 3) { return 0; } @@ -410,8 +390,7 @@ int countBends(const path_t& path) return bends; } -bool hasAxisSpike(const path_t& path) -{ +bool hasAxisSpike(const path_t& path) { for (size_t i = 1; i + 1 < path.size(); ++i) { const QPoint& a = path[i - 1]; const QPoint& b = path[i]; @@ -420,7 +399,8 @@ bool hasAxisSpike(const path_t& path) if (a.x() == b.x() && b.x() == c.x()) { const int low = std::min(a.y(), c.y()); const int high = std::max(a.y(), c.y()); - if (b.y() > low && b.y() < high && b.y() != a.y() && b.y() != c.y()) { + if (b.y() > low && b.y() < high && b.y() != a.y() && + b.y() != c.y()) { return true; } } @@ -428,7 +408,8 @@ bool hasAxisSpike(const path_t& path) if (a.y() == b.y() && b.y() == c.y()) { const int low = std::min(a.x(), c.x()); const int high = std::max(a.x(), c.x()); - if (b.x() > low && b.x() < high && b.x() != a.x() && b.x() != c.x()) { + if (b.x() > low && b.x() < high && b.x() != a.x() && + b.x() != c.x()) { return true; } } @@ -437,8 +418,7 @@ bool hasAxisSpike(const path_t& path) return false; } -bool terminalSegmentsAreMonotonic(const path_t& path) -{ +bool terminalSegmentsAreMonotonic(const path_t& path) { if (path.size() < 3) { return true; } @@ -469,13 +449,12 @@ bool terminalSegmentsAreMonotonic(const path_t& path) return true; } -} // namespace +} // namespace -class PathfinderDiagramTest : public QObject -{ +class PathfinderDiagramTest : public QObject { Q_OBJECT -private slots: + private slots: void singleTransition_avoidsMiddleNode(); void chainTransitions_avoidNodes_data(); void chainTransitions_avoidNodes(); @@ -486,8 +465,7 @@ private slots: void routedPaths_minimizeBendsWithoutSpikes(); }; -void PathfinderDiagramTest::singleTransition_avoidsMiddleNode() -{ +void PathfinderDiagramTest::singleTransition_avoidsMiddleNode() { DiagramLayout layout; layout.nodes = {makeNode(100, 100), makeNode(220, 100), makeNode(340, 100)}; @@ -496,8 +474,7 @@ void PathfinderDiagramTest::singleTransition_avoidsMiddleNode() QVERIFY(pathAvoidsIntermediateNodes(path, layout.nodes, 0, 2)); } -void PathfinderDiagramTest::chainTransitions_avoidNodes_data() -{ +void PathfinderDiagramTest::chainTransitions_avoidNodes_data() { QTest::addColumn("nodeCount"); QTest::newRow("3_nodes") << 3; @@ -506,8 +483,7 @@ void PathfinderDiagramTest::chainTransitions_avoidNodes_data() QTest::newRow("7_nodes") << 7; } -void PathfinderDiagramTest::chainTransitions_avoidNodes() -{ +void PathfinderDiagramTest::chainTransitions_avoidNodes() { QFETCH(int, nodeCount); const DiagramLayout layout = chainLayout(nodeCount); @@ -519,8 +495,7 @@ void PathfinderDiagramTest::chainTransitions_avoidNodes() QVERIFY(allPathsSeparated(paths)); } -void PathfinderDiagramTest::parallelRowTransitions_doNotIntersect() -{ +void PathfinderDiagramTest::parallelRowTransitions_doNotIntersect() { const DiagramLayout layout = gridLayout(4, 1, 120, 100); const std::vector paths = buildExplicitPaths(layout, {{0, 1}, {1, 2}, {2, 3}}); @@ -531,17 +506,16 @@ void PathfinderDiagramTest::parallelRowTransitions_doNotIntersect() QVERIFY(allPathsSeparated(paths)); } -void PathfinderDiagramTest::denseDiagram_multiplePathsRemainSeparated() -{ +void PathfinderDiagramTest::denseDiagram_multiplePathsRemainSeparated() { const DiagramLayout layout = gridLayout(3, 2, 120, 100); - const std::vector paths = buildExplicitPaths(layout, - { - {0, 1}, - {1, 2}, - {3, 4}, - {4, 5}, - {2, 5}, - }); + const std::vector paths = + buildExplicitPaths(layout, { + {0, 1}, + {1, 2}, + {3, 4}, + {4, 5}, + {2, 5}, + }); QCOMPARE(static_cast(paths.size()), 5); QVERIFY(allPathsNonEmpty(paths)); @@ -549,8 +523,7 @@ void PathfinderDiagramTest::denseDiagram_multiplePathsRemainSeparated() QVERIFY(allPathsSeparated(paths)); } -void PathfinderDiagramTest::blockedRoute_returnsEmptyPath() -{ +void PathfinderDiagramTest::blockedRoute_returnsEmptyPath() { DiagramLayout layout; layout.nodes = { makeNode(100, 100), @@ -560,11 +533,11 @@ void PathfinderDiagramTest::blockedRoute_returnsEmptyPath() }; const path_t path = buildTransitionPath(layout, {}, 0, 2); - QVERIFY(path.empty() || pathAvoidsIntermediateNodes(path, layout.nodes, 0, 2)); + QVERIFY(path.empty() || + pathAvoidsIntermediateNodes(path, layout.nodes, 0, 2)); } -void PathfinderDiagramTest::terminalRouting_exitsRightAndEntersLeft() -{ +void PathfinderDiagramTest::terminalRouting_exitsRightAndEntersLeft() { const DiagramLayout layout = chainLayout(4); const std::vector paths = buildChainPaths(layout); QVERIFY(allPathsNonEmpty(paths)); @@ -577,35 +550,38 @@ void PathfinderDiagramTest::terminalRouting_exitsRightAndEntersLeft() QCOMPARE(path.back(), inputPoint(layout.nodes[transition.toIndex])); QVERIFY2(path[1].x() > path[0].x(), - qPrintable(QStringLiteral("first segment must go right from output"))); + qPrintable(QStringLiteral( + "first segment must go right from output"))); QVERIFY2(path[path.size() - 2].x() < path.back().x(), - qPrintable(QStringLiteral("last segment must approach input from left"))); + qPrintable(QStringLiteral( + "last segment must approach input from left"))); } } -void PathfinderDiagramTest::routedPaths_minimizeBendsWithoutSpikes() -{ +void PathfinderDiagramTest::routedPaths_minimizeBendsWithoutSpikes() { const DiagramLayout layout = gridLayout(4, 2, 120, 100); - const std::vector paths = buildExplicitPaths(layout, - { - {0, 1}, - {1, 2}, - {2, 3}, - {3, 4}, - {4, 5}, - {6, 7}, - {2, 5}, - }); + const std::vector paths = + buildExplicitPaths(layout, { + {0, 1}, + {1, 2}, + {2, 3}, + {3, 4}, + {4, 5}, + {6, 7}, + {2, 5}, + }); QVERIFY(allPathsNonEmpty(paths)); for (const TransitionPath& transition : paths) { const path_t& path = transition.points; - QVERIFY2(!hasAxisSpike(path), qPrintable(QStringLiteral("path has redundant axis spike"))); + QVERIFY2(!hasAxisSpike(path), + qPrintable(QStringLiteral("path has redundant axis spike"))); QVERIFY2(terminalSegmentsAreMonotonic(path), qPrintable(QStringLiteral("path oscillates near terminals"))); - QVERIFY2(countBends(path) <= 6, - qPrintable(QString("too many bends (%1)").arg(countBends(path)))); + QVERIFY2( + countBends(path) <= 6, + qPrintable(QString("too many bends (%1)").arg(countBends(path)))); } } diff --git a/tests/serialization/test_machine_serialization.cpp b/tests/serialization/test_machine_serialization.cpp index 2bcd6ad..30fd2cc 100644 --- a/tests/serialization/test_machine_serialization.cpp +++ b/tests/serialization/test_machine_serialization.cpp @@ -1,64 +1,58 @@ -#include #include -#include #include - +#include +#include #include #include #include -#include "vmtproject.h" #include "VMTSerializer.h" -#include "vmtmachines/VMTComplexMachine.h" -#include "vmtmachines/VMTMachineStub.h" +#include "interfaces/IVMTEnvironment.h" #include "interfaces/IVMTMachine.h" #include "interfaces/IVMTTransition.h" -#include "interfaces/IVMTEnvironment.h" #include "uicanvas.h" +#include "vmtmachines/VMTComplexMachine.h" +#include "vmtmachines/VMTMachineStub.h" +#include "vmtproject.h" namespace { -class TestEnvironment : public IVMTEnvironment -{ -public: +class TestEnvironment : public IVMTEnvironment { + public: explicit TestEnvironment(const std::shared_ptr& machine) - : _machine(machine) - , _canvas(QBrush(Qt::white), - QPen(Qt::gray), - QPen(Qt::black), - QSize(20, 20), - 12) - {} + : _machine(machine), + _canvas(QBrush(Qt::white), QPen(Qt::gray), QPen(Qt::black), + QSize(20, 20), 12) {} void EnableActionHint(const QString&, QPixmap&) override {} void DisableActionHint() override {} void DisableAlphabit() override {} void DisableCalculator() override {} - void EnableAlphabit(IVMTAlphabitSource*, const QString&, QPixmap&) override {} + void EnableAlphabit(IVMTAlphabitSource*, const QString&, + QPixmap&) override {} void EnableCalculator(std::shared_ptr) override {} UICanvas& GetGraphics() override { return _canvas; } std::weak_ptr GetMachine() override { return _machine; } - void SetMachine(std::shared_ptr machine) override { _machine = machine; } + void SetMachine(std::shared_ptr machine) override { + _machine = machine; + } void Repaint(const QRect&) override {} void MoveInScreen(QPoint&&) override {} void Move(QPoint&&) override {} void EnableAnimation(bool) override {} -private: + private: std::shared_ptr _machine; UICanvas _canvas; }; - struct NodeSnapshot { int type = 0; QRect bounds; long power = 1; - bool operator<(const NodeSnapshot& other) const - { - if (type != other.type) - return type < other.type; + bool operator<(const NodeSnapshot& other) const { + if (type != other.type) return type < other.type; if (bounds.x() != other.bounds.x()) return bounds.x() < other.bounds.x(); if (bounds.y() != other.bounds.y()) @@ -75,10 +69,8 @@ struct TransitionSnapshot { int startType = 0; int finishType = 0; - bool operator<(const TransitionSnapshot& other) const - { - if (startType != other.startType) - return startType < other.startType; + bool operator<(const TransitionSnapshot& other) const { + if (startType != other.startType) return startType < other.startType; return finishType < other.finishType; } }; @@ -89,8 +81,7 @@ struct DiagramSnapshot { std::vector transitions; }; -void resetProject() -{ +void resetProject() { VMTProject& project = VMTProject::GetInstance(); project.GetMachines().clear(); project.GetCurrentMachineName().clear(); @@ -100,18 +91,18 @@ void resetProject() project.GetUndoManager()->Clear(); } -void placeNode(const std::shared_ptr& node, int x, int y) -{ +void placeNode(const std::shared_ptr& node, int x, int y) { node->Move(QPoint(x, y), nullptr); node->Update(nullptr); } -DiagramSnapshot captureDiagram(const std::shared_ptr& machine) -{ +DiagramSnapshot captureDiagram( + const std::shared_ptr& machine) { DiagramSnapshot snapshot; snapshot.name = machine->GetName(); - for (const std::shared_ptr& node : machine->GetMachineCollection()) { + for (const std::shared_ptr& node : + machine->GetMachineCollection()) { NodeSnapshot nodeSnapshot; nodeSnapshot.type = static_cast(node->GetID()); nodeSnapshot.bounds = node->GetBounds(); @@ -134,19 +125,21 @@ DiagramSnapshot captureDiagram(const std::shared_ptr& machine return snapshot; } -std::shared_ptr buildSampleDiagram() -{ +std::shared_ptr buildSampleDiagram() { auto machine = std::make_shared( QStringLiteral("Main machine"), VMTProject::GetInstance().GetAlphabit()); - auto start = VMTMachineStub::CreateMachineByID(IVMTMachine::MT_START, machine); - auto left = VMTMachineStub::CreateMachineByID(IVMTMachine::MT_LEFT, machine); - auto right = VMTMachineStub::CreateMachineByID(IVMTMachine::MT_RIGHT, machine); - auto finish = VMTMachineStub::CreateMachineByID(IVMTMachine::MT_FINISH, machine); + auto start = + VMTMachineStub::CreateMachineByID(IVMTMachine::MT_START, machine); + auto left = + VMTMachineStub::CreateMachineByID(IVMTMachine::MT_LEFT, machine); + auto right = + VMTMachineStub::CreateMachineByID(IVMTMachine::MT_RIGHT, machine); + auto finish = + VMTMachineStub::CreateMachineByID(IVMTMachine::MT_FINISH, machine); - if (!start || !left || !right || !finish) - return {}; + if (!start || !left || !right || !finish) return {}; placeNode(start, 100, 100); placeNode(left, 220, 100); @@ -167,41 +160,31 @@ std::shared_ptr buildSampleDiagram() return machine; } -QString saveProjectToTempFile(QTemporaryDir& tempDir) -{ +QString saveProjectToTempFile(QTemporaryDir& tempDir) { QString path = tempDir.filePath(QStringLiteral("diagram.jdtp")); VMTSerializer serializer(path); serializer.Serialize(&VMTProject::GetInstance()); return path; } -void loadProjectFromFile(QString path) -{ +void loadProjectFromFile(QString path) { VMTProject& project = VMTProject::GetInstance(); project.GetMachines().clear(); VMTSerializer serializer(path); serializer.Deserialize(&project); } -} // namespace +} // namespace -class MachineSerializationTest : public QObject -{ +class MachineSerializationTest : public QObject { Q_OBJECT -private slots: - void initTestCase() - { - resetProject(); - } + private slots: + void initTestCase() { resetProject(); } - void cleanup() - { - resetProject(); - } + void cleanup() { resetProject(); } - void roundTrip_preservesDiagramNodesAndTransitions() - { + void roundTrip_preservesDiagramNodesAndTransitions() { resetProject(); const std::shared_ptr machine = buildSampleDiagram(); @@ -233,8 +216,10 @@ private slots: } for (size_t i = 0; i < original.transitions.size(); ++i) { - QCOMPARE(loaded.transitions[i].startType, original.transitions[i].startType); - QCOMPARE(loaded.transitions[i].finishType, original.transitions[i].finishType); + QCOMPARE(loaded.transitions[i].startType, + original.transitions[i].startType); + QCOMPARE(loaded.transitions[i].finishType, + original.transitions[i].finishType); } } }; From 848f41b93814434c6eccc0fcd773ba7eb8921d62 Mon Sep 17 00:00:00 2001 From: Timur Buchkin Date: Wed, 7 Oct 2026 23:10:46 +0300 Subject: [PATCH 03/13] add vtm headless version --- .envrc | 1 - .gitignore | 3 + VirtualTuringMachine/CMakeLists.txt | 26 ++-- VirtualTuringMachine/headless_main.cpp | 183 +++++++++++++++++++++++++ VirtualTuringMachine/main.cpp | 1 + default.nix | 31 +++++ flake.nix | 12 +- tests/CMakeLists.txt | 6 +- 8 files changed, 242 insertions(+), 21 deletions(-) delete mode 100644 .envrc create mode 100644 VirtualTuringMachine/headless_main.cpp create mode 100644 default.nix diff --git a/.envrc b/.envrc deleted file mode 100644 index 3550a30..0000000 --- a/.envrc +++ /dev/null @@ -1 +0,0 @@ -use flake diff --git a/.gitignore b/.gitignore index fac35a2..8403c1b 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* pnpm-debug.log* +.cache/ +compile_commands.json +result diff --git a/VirtualTuringMachine/CMakeLists.txt b/VirtualTuringMachine/CMakeLists.txt index 1e580b5..a4234b1 100644 --- a/VirtualTuringMachine/CMakeLists.txt +++ b/VirtualTuringMachine/CMakeLists.txt @@ -10,7 +10,7 @@ if(APPLE AND NOT CMAKE_PREFIX_PATH) "/opt/homebrew/opt/qt@5" "/usr/local/opt/qt@5") foreach(_qt_path IN LISTS _qt5_mac_candidates) - if(EXISTS "${_qt_path}/lib/cmake/Qt5/Qt5Config.cmake") + if(EXISTS "${_qt_path}/lib/cmake/Qt6/Qt6Config.cmake") list(APPEND CMAKE_PREFIX_PATH "${_qt_path}") break() endif() @@ -22,11 +22,10 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core Gui Widgets) -find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets) +find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) if(APPLE) - get_target_property(_qt_core_location Qt5::Core LOCATION) + get_target_property(_qt_core_location Qt6::Core LOCATION) if(_qt_core_location) get_filename_component(_qt_lib_dir "${_qt_core_location}" DIRECTORY) execute_process( @@ -54,7 +53,7 @@ file( GLOB_RECURSE VTM_SOURCES LIST_DIRECTORIES FALSE *.cpp) -list(FILTER VTM_SOURCES EXCLUDE REGEX "/main\\.cpp$") +list(FILTER VTM_SOURCES EXCLUDE REGEX "/(main|headless_main)\\.cpp$") add_library(vtm_core STATIC ${VTM_SOURCES} resources.qrc) target_include_directories(vtm_core PUBLIC ${ADDITIONAL_DIRS}) @@ -67,18 +66,12 @@ if(MSVC) target_compile_options(vtm_core PRIVATE /utf-8) endif() -if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) - qt_add_executable(${PROJECT_NAME} main.cpp MANUAL_FINALIZATION) -else() - if(ANDROID) - add_library(${PROJECT_NAME} SHARED main.cpp) - else() - add_executable(${PROJECT_NAME} main.cpp isCtrlPressed.h) - endif() -endif() - +qt_add_executable(${PROJECT_NAME} main.cpp MANUAL_FINALIZATION) target_link_libraries(${PROJECT_NAME} PRIVATE vtm_core) +add_executable(${PROJECT_NAME}-headless headless_main.cpp) +target_link_libraries(${PROJECT_NAME}-headless PRIVATE vtm_core) + if(MSVC) target_compile_options(${PROJECT_NAME} PRIVATE /utf-8) endif() @@ -96,3 +89,6 @@ endif() if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(${PROJECT_NAME}) endif() + +install(TARGETS ${PROJECT_NAME} vtm_core) +install(TARGETS ${PROJECT_NAME}-headless) diff --git a/VirtualTuringMachine/headless_main.cpp b/VirtualTuringMachine/headless_main.cpp new file mode 100644 index 0000000..9101f99 --- /dev/null +++ b/VirtualTuringMachine/headless_main.cpp @@ -0,0 +1,183 @@ +#include +#include +#include +#include + +#include "VMTJsonSerializer.h" +#include "VMTSerializer.h" +#include "vmtdebuger.h" +#include "vmtproject.h" + +namespace { +class HeadlessEnvironment final : public IVMTEnvironment { + public: + void EnableActionHint(const QString&, QPixmap&) override {} + void DisableActionHint() override {} + void DisableAlphabit() override {} + void DisableCalculator() override {} + void EnableAlphabit(IVMTAlphabitSource*, const QString&, QPixmap&) override {} + void EnableCalculator(std::shared_ptr) override {} + UICanvas& GetGraphics() override { return _canvas; } + std::weak_ptr GetMachine() override { return _machine; } + void SetMachine(std::shared_ptr machine) override { + _machine = machine; + } + void Repaint(const QRect&) override {} + void MoveInScreen(QPoint&&) override {} + void Move(QPoint&&) override {} + void EnableAnimation(bool) override {} + + private: + UICanvas _canvas{QBrush(), QPen(), QPen(), QSize(1, 1), 1}; + std::weak_ptr _machine; +}; + +QString outputWord(const std::shared_ptr& line) { + const long left = line->GetLeftSignPosition(); + const long right = line->GetRightSignPosition(); + if (left < 0 || right < left) return QString(); + + QString result; + result.reserve(static_cast(right - left + 1)); + for (long position = left; position <= right; ++position) { + result.append(QChar(line->GetValueAt(position))); + } + return result; +} + +bool run(const QString& path, const QString& machineName, + const QString& input, int maxSteps, QString& output, QString& error) { + VMTProject& project = VMTProject::GetInstance(); + bool loaded = false; + if (VMTJsonSerializer::isJsonPath(path)) { + loaded = VMTJsonSerializer(path).deserialize(&project); + } else { + QString mutablePath = path; + VMTSerializer serializer(mutablePath); + serializer.Deserialize(&project); + loaded = !project.GetMachines().empty(); + } + if (!loaded) { + error = QStringLiteral("cannot load diagram: ") + path; + return false; + } + + QString selected = machineName; + std::shared_ptr machine; + if (selected.isEmpty()) { + machine = project.GetCurrentMachine(); + } else { + machine = project.GetMachine(selected); + } + if (!machine) { + error = QStringLiteral("machine not found: ") + + (selected.isEmpty() ? QStringLiteral("") : selected); + return false; + } + bool hasStart = false; + for (const auto& component : machine->GetMachineCollection()) { + if (component->GetID() == IVMTMachine::MT_START) { + hasStart = true; + break; + } + } + if (!hasStart) { + error = QStringLiteral("machine has no start state: ") + machine->GetName(); + return false; + } + + VMTDebuger debugger(project.GetAlphabit(), machine); + for (long position = 0; position < input.size(); ++position) { + debugger.GetLine()->SetValueAt(position + 1, input[position].toLatin1()); + QTextStream(stderr) << "Input: " << input[position].toLatin1() << "; code: " << int(input[position.toLatin1()]) << Qt::endl; + } + debugger.GetLine()->SetMachinePosition(input.size() + 1); + + HeadlessEnvironment environment; + debugger.ToStart(&environment); + int steps = 0; + while (!debugger.IsFinish() && steps < maxSteps) { + debugger.Step(&environment); + + QTextStream(stderr) << debugger.GetLine()->GetMachinePosition() << " | " << debugger.GetLine()->ToString() << Qt::endl; + if(debugger.GetLine()->GetMachinePosition() < 0) { + error = QStringLiteral("Machine working cell out of left line border (< 0). Which is forbidden"); + return false; + } + ++steps; + } + if (!debugger.IsFinish()) { + error = QStringLiteral("maximum step count exceeded: ") + + QString::number(maxSteps); + return false; + } + output = outputWord(debugger.GetLine()); + return true; +} +} // namespace + +int main(int argc, char* argv[]) { + if (!qEnvironmentVariableIsSet("QT_QPA_PLATFORM")) { + qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("offscreen")); + } + QGuiApplication app(argc, argv); + app.setApplicationName(QStringLiteral("VTM-headless")); + app.setApplicationVersion(QStringLiteral("1.0.2")); + + QCommandLineParser parser; + parser.setApplicationDescription( + QStringLiteral("Execute a Virtual Turing Machine diagram.")); + parser.addHelpOption(); + parser.addVersionOption(); + QCommandLineOption diagramOption({QStringLiteral("d"), QStringLiteral("diagram")}, + QStringLiteral( + "Diagram file (.vmt or .vmt.json)."), + QStringLiteral("file")); + QCommandLineOption machineOption({QStringLiteral("m"), QStringLiteral("machine")}, + QStringLiteral( + "Machine name (defaults to the first one)."), + QStringLiteral("name")); + QCommandLineOption inputOption({QStringLiteral("i"), QStringLiteral("input")}, + QStringLiteral("Input tape word (may be repeated)."), + QStringLiteral("word")); + QCommandLineOption maxStepsOption(QStringLiteral("max-steps"), + QStringLiteral("Maximum execution steps."), + QStringLiteral("count"), + QStringLiteral("1000000")); + parser.addOption(diagramOption); + parser.addOption(machineOption); + parser.addOption(inputOption); + parser.addOption(maxStepsOption); + parser.addPositionalArgument(QStringLiteral("word"), + QStringLiteral("Input tape word.")); + parser.process(app); + const QString path = parser.value(diagramOption); + if (path.isEmpty()) { + QTextStream(stderr) << "A diagram file is required (--diagram)." << Qt::endl; + return 2; + } + bool ok = false; + const int maxSteps = parser.value(maxStepsOption).toInt(&ok); + if (!ok || maxSteps <= 0) { + QTextStream(stderr) << "--max-steps must be a positive integer." << Qt::endl; + return 2; + } + + QStringList inputs = parser.values(inputOption); + inputs.append(parser.positionalArguments()); + if (inputs.isEmpty()) inputs.append(QString()); + + QTextStream out(stdout); + QTextStream err(stderr); + for (const QString& input : inputs) { + QString result; + QString error; + if (!run(path, parser.value(machineOption), input, maxSteps, result, + error)) { + err << error << Qt::endl; + return 1; + } + out << result << Qt::endl; + } + return 0; +} diff --git a/VirtualTuringMachine/main.cpp b/VirtualTuringMachine/main.cpp index 457c16c..475dd23 100644 --- a/VirtualTuringMachine/main.cpp +++ b/VirtualTuringMachine/main.cpp @@ -10,6 +10,7 @@ int main(int argc, char* argv[]) { QApplication::setApplicationName("Virtual Turing Machine"); QApplication::setOrganizationDomain("mai.ru"); + Q_INIT_RESOURCE(resources); Configuration::GetInstance().Init(&a); if (Configuration::GetInstance().IsDarkTheme()) { diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..1a4c113 --- /dev/null +++ b/default.nix @@ -0,0 +1,31 @@ +{ + stdenv, + lib, + cmake, + qtbase, + qttools, + qtsvg, + qtimageformats, + wrapQtAppsHook, +}: let + fs = lib.fileset; + sources = fs.toSource { + root = ./.; + fileset = fs.difference ./. (fs.maybeMissing ./result); + }; +in + stdenv.mkDerivation { + pname = "VTM"; + version = "v1.0.2"; + src = sources; + buildInputs = [ + qtbase + ]; + nativeBuildInputs = [ + cmake + qttools + wrapQtAppsHook + qtsvg + qtimageformats + ]; + } diff --git a/flake.nix b/flake.nix index 212d914..6db3a18 100644 --- a/flake.nix +++ b/flake.nix @@ -16,8 +16,16 @@ inputs.flake-parts.lib.mkFlake {inherit inputs;} { imports = [inputs.treefmt-nix.flakeModule]; systems = import inputs.systems; - perSystem = {inputs', ...}: { - packages = {}; + perSystem = { + pkgs, + self', + ... + }: let + in { + packages = { + VTM = pkgs.qt6.callPackage ./default.nix {}; + default = self'.packages.VTM; + }; treefmt = import ./treefmt.nix; }; }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c12403c..a99e1f1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,18 +1,18 @@ set(CMAKE_AUTOMOC ON) -find_package(Qt5 REQUIRED COMPONENTS Test) +find_package(Qt6 REQUIRED COMPONENTS Test) add_executable(test_machine_serialization serialization/test_machine_serialization.cpp) target_link_libraries(test_machine_serialization - PRIVATE vtm_core Qt5::Test) + PRIVATE vtm_core Qt6::Test) add_test(NAME test_machine_serialization COMMAND test_machine_serialization) add_executable(test_pathfinder pathfinder/test_pathfinder.cpp) -target_link_libraries(test_pathfinder PRIVATE vtm_core Qt5::Test) +target_link_libraries(test_pathfinder PRIVATE vtm_core Qt6::Test) add_test(NAME test_pathfinder COMMAND test_pathfinder) From 448184f4b77a3411179e2f7affe7afb6465f75ca Mon Sep 17 00:00:00 2001 From: Timur Buchkin Date: Wed, 7 Oct 2026 23:47:19 +0300 Subject: [PATCH 04/13] fix config path --- VirtualTuringMachine/configuration.cpp | 25 ++++++++++++++++++------- VirtualTuringMachine/headless_main.cpp | 1 - default.nix | 2 ++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/VirtualTuringMachine/configuration.cpp b/VirtualTuringMachine/configuration.cpp index 872b6b8..6b83dea 100644 --- a/VirtualTuringMachine/configuration.cpp +++ b/VirtualTuringMachine/configuration.cpp @@ -1,12 +1,27 @@ #include "configuration.h" #include +#include #include +#include #include #include Configuration Configuration::instance; +namespace { +QString configurationFilePath() { + QString directory = + QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); + if (directory.isEmpty()) { + directory = QDir::homePath(); + } + QDir().mkpath(directory); + qDebug() << "Config path: " << QDir(directory).filePath(QStringLiteral("config.xml")) << '\n'; + return QDir(directory).filePath(QStringLiteral("config.xml")); +} +} // namespace + Configuration::Configuration() : _dark_theme(false) {} const std::vector& Configuration::GetRecentProjects() { @@ -87,10 +102,8 @@ void Configuration::LoadExercises() { void Configuration::Init(QApplication* app) { LoadExercises(); _app = app; - _default_location = _app->applicationDirPath(); - QString filename = _default_location; - filename.append("/config.xml"); - QFile file(filename); + _default_location = QDir::homePath(); + QFile file(configurationFilePath()); if (!file.open(QFile::ReadOnly | QFile::Text)) { // QMessageBox box; @@ -119,9 +132,7 @@ void Configuration::Init(QApplication* app) { } void Configuration::Save() { - QString filename = _app->applicationDirPath(); - filename.append("/config.xml"); - QFile file(filename); + QFile file(configurationFilePath()); if (!file.open(QFile::WriteOnly | QFile::Text)) { // qDebug(qPrintable(QString("Error: Cannot write file %1 diff --git a/VirtualTuringMachine/headless_main.cpp b/VirtualTuringMachine/headless_main.cpp index 9101f99..7d317ae 100644 --- a/VirtualTuringMachine/headless_main.cpp +++ b/VirtualTuringMachine/headless_main.cpp @@ -89,7 +89,6 @@ bool run(const QString& path, const QString& machineName, VMTDebuger debugger(project.GetAlphabit(), machine); for (long position = 0; position < input.size(); ++position) { debugger.GetLine()->SetValueAt(position + 1, input[position].toLatin1()); - QTextStream(stderr) << "Input: " << input[position].toLatin1() << "; code: " << int(input[position.toLatin1()]) << Qt::endl; } debugger.GetLine()->SetMachinePosition(input.size() + 1); diff --git a/default.nix b/default.nix index 1a4c113..debc799 100644 --- a/default.nix +++ b/default.nix @@ -28,4 +28,6 @@ in qtsvg qtimageformats ]; + + meta.mainProgram = "VTM"; } From b88695e3a03d89f0116542cd05e9582ab918ccc5 Mon Sep 17 00:00:00 2001 From: Timur Buchkin Date: Wed, 14 Oct 2026 13:47:17 +0300 Subject: [PATCH 05/13] add devenv --- .envrc | 1 + .gitignore | 4 + VirtualTuringMachine/configuration.cpp | 3 +- VirtualTuringMachine/headless_main.cpp | 64 ++--- VirtualTuringMachine/isCtrlPressed.h | 2 +- VirtualTuringMachine/mainwindow.cpp | 2 +- devenv/default.nix | 13 ++ devenv/git-hooks.nix | 12 + devenv/packages.nix | 11 + devenv/tasks.nix | 30 +++ devenv/tests.nix | 9 + flake.lock | 310 ++++++++++++++++++++++++- flake.nix | 17 ++ 13 files changed, 445 insertions(+), 33 deletions(-) create mode 100644 .envrc create mode 100644 devenv/default.nix create mode 100644 devenv/git-hooks.nix create mode 100644 devenv/packages.nix create mode 100644 devenv/tasks.nix create mode 100644 devenv/tests.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..a41f435 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . --no-pure-eval diff --git a/.gitignore b/.gitignore index 8403c1b..cf8eaed 100644 --- a/.gitignore +++ b/.gitignore @@ -74,3 +74,7 @@ pnpm-debug.log* .cache/ compile_commands.json result +result +.pre-commit-config.yaml +.devenv +.direnv diff --git a/VirtualTuringMachine/configuration.cpp b/VirtualTuringMachine/configuration.cpp index 6b83dea..4fe34d2 100644 --- a/VirtualTuringMachine/configuration.cpp +++ b/VirtualTuringMachine/configuration.cpp @@ -17,7 +17,8 @@ QString configurationFilePath() { directory = QDir::homePath(); } QDir().mkpath(directory); - qDebug() << "Config path: " << QDir(directory).filePath(QStringLiteral("config.xml")) << '\n'; + qDebug() << "Config path: " + << QDir(directory).filePath(QStringLiteral("config.xml")) << '\n'; return QDir(directory).filePath(QStringLiteral("config.xml")); } } // namespace diff --git a/VirtualTuringMachine/headless_main.cpp b/VirtualTuringMachine/headless_main.cpp index 7d317ae..d6be433 100644 --- a/VirtualTuringMachine/headless_main.cpp +++ b/VirtualTuringMachine/headless_main.cpp @@ -1,6 +1,6 @@ +#include #include #include -#include #include #include "VMTJsonSerializer.h" @@ -15,7 +15,8 @@ class HeadlessEnvironment final : public IVMTEnvironment { void DisableActionHint() override {} void DisableAlphabit() override {} void DisableCalculator() override {} - void EnableAlphabit(IVMTAlphabitSource*, const QString&, QPixmap&) override {} + void EnableAlphabit(IVMTAlphabitSource*, const QString&, + QPixmap&) override {} void EnableCalculator(std::shared_ptr) override {} UICanvas& GetGraphics() override { return _canvas; } std::weak_ptr GetMachine() override { return _machine; } @@ -45,8 +46,8 @@ QString outputWord(const std::shared_ptr& line) { return result; } -bool run(const QString& path, const QString& machineName, - const QString& input, int maxSteps, QString& output, QString& error) { +bool run(const QString& path, const QString& machineName, const QString& input, + int maxSteps, QString& output, QString& error) { VMTProject& project = VMTProject::GetInstance(); bool loaded = false; if (VMTJsonSerializer::isJsonPath(path)) { @@ -82,13 +83,15 @@ bool run(const QString& path, const QString& machineName, } } if (!hasStart) { - error = QStringLiteral("machine has no start state: ") + machine->GetName(); + error = + QStringLiteral("machine has no start state: ") + machine->GetName(); return false; } VMTDebuger debugger(project.GetAlphabit(), machine); for (long position = 0; position < input.size(); ++position) { - debugger.GetLine()->SetValueAt(position + 1, input[position].toLatin1()); + debugger.GetLine()->SetValueAt(position + 1, + input[position].toLatin1()); } debugger.GetLine()->SetMachinePosition(input.size() + 1); @@ -98,11 +101,14 @@ bool run(const QString& path, const QString& machineName, while (!debugger.IsFinish() && steps < maxSteps) { debugger.Step(&environment); - QTextStream(stderr) << debugger.GetLine()->GetMachinePosition() << " | " << debugger.GetLine()->ToString() << Qt::endl; - if(debugger.GetLine()->GetMachinePosition() < 0) { - error = QStringLiteral("Machine working cell out of left line border (< 0). Which is forbidden"); + QTextStream(stderr) << debugger.GetLine()->GetMachinePosition() << " | " + << debugger.GetLine()->ToString() << Qt::endl; + if (debugger.GetLine()->GetMachinePosition() < 0) { + error = QStringLiteral( + "Machine working cell out of left line border (< 0). Which is " + "forbidden"); return false; - } + } ++steps; } if (!debugger.IsFinish()) { @@ -128,37 +134,39 @@ int main(int argc, char* argv[]) { QStringLiteral("Execute a Virtual Turing Machine diagram.")); parser.addHelpOption(); parser.addVersionOption(); - QCommandLineOption diagramOption({QStringLiteral("d"), QStringLiteral("diagram")}, - QStringLiteral( - "Diagram file (.vmt or .vmt.json)."), - QStringLiteral("file")); - QCommandLineOption machineOption({QStringLiteral("m"), QStringLiteral("machine")}, - QStringLiteral( - "Machine name (defaults to the first one)."), - QStringLiteral("name")); - QCommandLineOption inputOption({QStringLiteral("i"), QStringLiteral("input")}, - QStringLiteral("Input tape word (may be repeated)."), - QStringLiteral("word")); - QCommandLineOption maxStepsOption(QStringLiteral("max-steps"), - QStringLiteral("Maximum execution steps."), - QStringLiteral("count"), - QStringLiteral("1000000")); + QCommandLineOption diagramOption( + {QStringLiteral("d"), QStringLiteral("diagram")}, + QStringLiteral("Diagram file (.vmt or .vmt.json)."), + QStringLiteral("file")); + QCommandLineOption machineOption( + {QStringLiteral("m"), QStringLiteral("machine")}, + QStringLiteral("Machine name (defaults to the first one)."), + QStringLiteral("name")); + QCommandLineOption inputOption( + {QStringLiteral("i"), QStringLiteral("input")}, + QStringLiteral("Input tape word (may be repeated)."), + QStringLiteral("word")); + QCommandLineOption maxStepsOption( + QStringLiteral("max-steps"), QStringLiteral("Maximum execution steps."), + QStringLiteral("count"), QStringLiteral("1000000")); parser.addOption(diagramOption); parser.addOption(machineOption); parser.addOption(inputOption); parser.addOption(maxStepsOption); parser.addPositionalArgument(QStringLiteral("word"), - QStringLiteral("Input tape word.")); + QStringLiteral("Input tape word.")); parser.process(app); const QString path = parser.value(diagramOption); if (path.isEmpty()) { - QTextStream(stderr) << "A diagram file is required (--diagram)." << Qt::endl; + QTextStream(stderr) + << "A diagram file is required (--diagram)." << Qt::endl; return 2; } bool ok = false; const int maxSteps = parser.value(maxStepsOption).toInt(&ok); if (!ok || maxSteps <= 0) { - QTextStream(stderr) << "--max-steps must be a positive integer." << Qt::endl; + QTextStream(stderr) + << "--max-steps must be a positive integer." << Qt::endl; return 2; } diff --git a/VirtualTuringMachine/isCtrlPressed.h b/VirtualTuringMachine/isCtrlPressed.h index 57ab8cb..6395395 100644 --- a/VirtualTuringMachine/isCtrlPressed.h +++ b/VirtualTuringMachine/isCtrlPressed.h @@ -1,4 +1,4 @@ #ifndef ISCTRLPRESSED_H #define ISCTRLPRESSED_H inline bool ctrlPressed = false; -#endif // ISCTRLPRESSED_H +#endif // ISCTRLPRESSED_H diff --git a/VirtualTuringMachine/mainwindow.cpp b/VirtualTuringMachine/mainwindow.cpp index 8f46399..3e95d86 100644 --- a/VirtualTuringMachine/mainwindow.cpp +++ b/VirtualTuringMachine/mainwindow.cpp @@ -166,7 +166,7 @@ void MainWindow::ShowWarning(std::shared_ptr) { if (!_form_warning) { if (GetContainer()->layout()->count() > 0) { //_form_warning_state = - //dynamic_cast(GetContainer()->layout()->children().at(0)); + // dynamic_cast(GetContainer()->layout()->children().at(0)); //_form_warning_state->setHidden(true); _form_warning = new FormWarning(this, GetContainer()); GetContainer()->layout()->addWidget(_form_warning); diff --git a/devenv/default.nix b/devenv/default.nix new file mode 100644 index 0000000..c2235ff --- /dev/null +++ b/devenv/default.nix @@ -0,0 +1,13 @@ +{ + env = { + GREET = "devenv"; + }; + + enterShell = + /* + bash + */ + '' + echo "Hello VTM developer"; + ''; +} diff --git a/devenv/git-hooks.nix b/devenv/git-hooks.nix new file mode 100644 index 0000000..1b06cd0 --- /dev/null +++ b/devenv/git-hooks.nix @@ -0,0 +1,12 @@ +{ + git-hooks.hooks = { + alejandra = { + enable = true; + files = "\\.(nix)$"; + }; + clang-format = { + enable = true; + files = "\\.(h|hpp|cpp|c)$"; + }; + }; +} diff --git a/devenv/packages.nix b/devenv/packages.nix new file mode 100644 index 0000000..ce43844 --- /dev/null +++ b/devenv/packages.nix @@ -0,0 +1,11 @@ +{pkgs, ...}: { + packages = with pkgs; + with pkgs.qt6; [ + qtbase + cmake + qttools + wrapQtAppsHook + qtsvg + qtimageformats + ]; +} diff --git a/devenv/tasks.nix b/devenv/tasks.nix new file mode 100644 index 0000000..1a6a7d3 --- /dev/null +++ b/devenv/tasks.nix @@ -0,0 +1,30 @@ +{ + tasks = { + "vtm:build" = { + exec = '' + mkdir -p build + cd build + cmake -S .. -DCMAKE_BUILD_TYPE=Debug + make + ''; + }; + + "vtm:gen_cc" = { + exec = '' + mkdir -p build + cd build + cmake -S .. -DCMAKE_EXPORT_COMPILE_COMMANDS=1 + cp compile_commands.json ../ + ''; + }; + + "vtm:release" = { + exec = '' + mkdir -p build + cd build + cmake -S .. + make + ''; + }; + }; +} diff --git a/devenv/tests.nix b/devenv/tests.nix new file mode 100644 index 0000000..876556c --- /dev/null +++ b/devenv/tests.nix @@ -0,0 +1,9 @@ +{ + enterTest = '' + echo "Running tests" + + # Some commands that runs tests + + echo "Testing done" + ''; +} diff --git a/flake.lock b/flake.lock index 42a6181..03f9aa4 100644 --- a/flake.lock +++ b/flake.lock @@ -1,6 +1,138 @@ { "nodes": { + "cachix": { + "inputs": { + "devenv": [ + "devenv" + ], + "flake-compat": [ + "devenv", + "flake-compat" + ], + "git-hooks": [ + "devenv", + "git-hooks" + ], + "nixpkgs": [ + "devenv", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1788181969, + "narHash": "sha256-OUB6hPlFBB9FRdZgZXSye4lDOg+fbrqKe8ePv2IM7NY=", + "owner": "cachix", + "repo": "cachix", + "rev": "98093e8eea6c1635ef1337a576fa76f3e8bd4f39", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "latest", + "repo": "cachix", + "type": "github" + } + }, + "crate2nix": { + "flake": false, + "locked": { + "lastModified": 1772186516, + "narHash": "sha256-8s28pzmQ6TOIUzznwFibtW1CMieMUl1rYJIxoQYor58=", + "owner": "rossng", + "repo": "crate2nix", + "rev": "ba5dd398e31ee422fbe021767eb83b0650303a6e", + "type": "github" + }, + "original": { + "owner": "rossng", + "repo": "crate2nix", + "rev": "ba5dd398e31ee422fbe021767eb83b0650303a6e", + "type": "github" + } + }, + "devenv": { + "inputs": { + "cachix": "cachix", + "crate2nix": "crate2nix", + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "ghostty": "ghostty", + "git-hooks": "git-hooks", + "nix": "nix", + "nixd": "nixd", + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1791917453, + "narHash": "sha256-BuVZNLxDPisddnzyzUpfzkJaCuKVDAKSG/Gkmrj3NA8=", + "owner": "cachix", + "repo": "devenv", + "rev": "30ef5a2458f270574726efe3574e5eb7e731f647", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "devenv", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1788306937, + "narHash": "sha256-lbrI1UYVpFgKSsyrU9oeF7FHfnu8nLD9ja0ou9f2rxk=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "f16b25b8c3d2809b87925d0b76652d7821a75c68", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_2": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" }, @@ -18,6 +150,69 @@ "type": "github" } }, + "ghostty": { + "flake": false, + "locked": { + "lastModified": 1786026742, + "narHash": "sha256-tRtgTg/i3w1nFdRHU2IGekfJN8EyP+HARW4MtoUZyqk=", + "owner": "ghostty-org", + "repo": "ghostty", + "rev": "22d13172cde98a0a4dda05d3d6a3fcb0dd8ed018", + "type": "github" + }, + "original": { + "owner": "ghostty-org", + "repo": "ghostty", + "rev": "22d13172cde98a0a4dda05d3d6a3fcb0dd8ed018", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": [ + "devenv", + "flake-compat" + ], + "nixpkgs": [ + "devenv", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1788267358, + "narHash": "sha256-nt+lUqYVpc9Y6JeMd2WmXzCDojasdadKo0mWcluvY2Y=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "27555e2624241fb116b49095df4caaee85a25691", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "git-hooks_2": { + "inputs": { + "flake-compat": "flake-compat_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1791909798, + "narHash": "sha256-VAhpCOmrun/KXimYfR8NM88bciKCui7CqHHhThSzgag=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "1ba1dbfe28738c9a71c266be6efa5b89e75491a9", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, "import-tree": { "locked": { "lastModified": 1788467110, @@ -33,6 +228,72 @@ "type": "github" } }, + "nix": { + "inputs": { + "flake-compat": [ + "devenv", + "flake-compat" + ], + "flake-parts": [ + "devenv", + "flake-parts" + ], + "git-hooks-nix": [ + "devenv", + "git-hooks" + ], + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "nixpkgs-23-11": [ + "devenv" + ], + "nixpkgs-regression": [ + "devenv" + ] + }, + "locked": { + "lastModified": 1790176416, + "narHash": "sha256-acP7QvsB+dHghUeL9AwSSZ3qS//skpqjv484aveg1EQ=", + "owner": "cachix", + "repo": "nix", + "rev": "bd10d7f563420c6034b9d1dc75c4168fc01e5afc", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "devenv-2.35", + "repo": "nix", + "type": "github" + } + }, + "nixd": { + "inputs": { + "flake-parts": [ + "devenv", + "flake-parts" + ], + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1788165251, + "narHash": "sha256-ITHt6eU6DuwQqlNV1/wehvKYPE6J8sZIlv75CpDjcHI=", + "owner": "nix-community", + "repo": "nixd", + "rev": "e2ca72c353cfbc3d63e942fe9aeae4ec497863bf", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixd", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1791254437, @@ -66,11 +327,34 @@ }, "root": { "inputs": { - "flake-parts": "flake-parts", + "devenv": "devenv", + "flake-parts": "flake-parts_2", + "git-hooks": "git-hooks_2", "import-tree": "import-tree", "nixpkgs": "nixpkgs", "systems": "systems", - "treefmt-nix": "treefmt-nix" + "treefmt-nix": "treefmt-nix_2" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "devenv", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1788332415, + "narHash": "sha256-BTFrmyh0oaVDsvA9NNw0YpbbeppTwU0t70iVx672Ew8=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "860d7c835ab91bfc8972b67092f5f2db8e9390a0", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" } }, "systems": { @@ -89,6 +373,28 @@ } }, "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "devenv", + "nixd", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1786901030, + "narHash": "sha256-WSFCsDSE5ffgD2MqzkM2CYjeFiKhRF/dJUN8uedb6YE=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "27b3b12a8e6375f28ebe122f07d230ca5459bbfa", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, + "treefmt-nix_2": { "inputs": { "nixpkgs": [ "nixpkgs" diff --git a/flake.nix b/flake.nix index 6db3a18..bb47a9b 100644 --- a/flake.nix +++ b/flake.nix @@ -10,6 +10,15 @@ url = "github:numtide/treefmt-nix"; inputs.nixpkgs.follows = "nixpkgs"; }; + + devenv = { + url = "github:cachix/devenv"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + git-hooks = { + url = "github:cachix/git-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = inputs: @@ -26,6 +35,14 @@ VTM = pkgs.qt6.callPackage ./default.nix {}; default = self'.packages.VTM; }; + devShells = { + default = inputs.devenv.lib.mkShell { + inherit inputs pkgs; + modules = [ + (import inputs.import-tree ./devenv) + ]; + }; + }; treefmt = import ./treefmt.nix; }; }; From f797907539f11a0805313714fab4601d723d27dd Mon Sep 17 00:00:00 2001 From: Timur Buchkin Date: Wed, 14 Oct 2026 17:29:42 +0300 Subject: [PATCH 06/13] remove buggy draw optimization, add spaces as lambdas rendering --- .gitignore | 2 ++ VirtualTuringMachine/CMakeLists.txt | 5 +++++ VirtualTuringMachine/VMTTransitionImpl.cpp | 8 +++----- VirtualTuringMachine/formalphabit.cpp | 9 ++------- VirtualTuringMachine/utils/ui.cpp | 18 ++++++++++++++++++ VirtualTuringMachine/utils/ui.h | 19 +++++++++++++++++++ .../vmtmachines/VMTComplexMachineInner.cpp | 7 ------- .../vmtmachines/VMTMachineStub.cpp | 7 ------- devenv/tasks.nix | 4 ++-- 9 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 VirtualTuringMachine/utils/ui.cpp create mode 100644 VirtualTuringMachine/utils/ui.h diff --git a/.gitignore b/.gitignore index cf8eaed..9b5e32d 100644 --- a/.gitignore +++ b/.gitignore @@ -78,3 +78,5 @@ result .pre-commit-config.yaml .devenv .direnv +.gdb_history +.qtcreator diff --git a/VirtualTuringMachine/CMakeLists.txt b/VirtualTuringMachine/CMakeLists.txt index a4234b1..9feba61 100644 --- a/VirtualTuringMachine/CMakeLists.txt +++ b/VirtualTuringMachine/CMakeLists.txt @@ -1,5 +1,10 @@ cmake_minimum_required(VERSION 3.16) +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + # Prevent optimizations for begger debugger UX + add_compile_options(-O0) +endif() + if(NOT CMAKE_PREFIX_PATH AND DEFINED ENV{QTDIR}) list(APPEND CMAKE_PREFIX_PATH "$ENV{QTDIR}") endif() diff --git a/VirtualTuringMachine/VMTTransitionImpl.cpp b/VirtualTuringMachine/VMTTransitionImpl.cpp index 31f6806..0a7bcb6 100644 --- a/VirtualTuringMachine/VMTTransitionImpl.cpp +++ b/VirtualTuringMachine/VMTTransitionImpl.cpp @@ -4,7 +4,9 @@ #include #include "diagrambezier.h" +#include "utils/ui.h" #include "vmtmachines/VMTComplexMachine.h" + #define PRECISION 5 namespace { @@ -481,10 +483,6 @@ bool VMTTransitionImpl::IsInsideLine(const QPoint& prev, const QPoint& current, } void VMTTransitionImpl::Paint(UICanvas& canvas, const QRect& rect) { - if (!rect.isEmpty() && !_bounds.isEmpty() && !rect.intersects(_bounds)) { - return; - } - const QPainterPath connectorPath = DiagramBezier::buildConnectorPath(_points); if (!connectorPath.isEmpty()) { @@ -498,7 +496,7 @@ void VMTTransitionImpl::Paint(UICanvas& canvas, const QRect& rect) { if (!_conditions.IsAllEnabled()) { if (_conditions.GetAsString().length() > 0) { QRect rect = GetConditionRectangle(canvas); - QString text = _conditions.GetAsString(); + QString text = utils::ui::escapeString(_conditions.GetAsString()); canvas.FillRect(rect, this->_highlighted); // canvas.DrawRectAnimation(_bounds,true); canvas.DrawText(text, _conditions_point, _condition_width / 2, diff --git a/VirtualTuringMachine/formalphabit.cpp b/VirtualTuringMachine/formalphabit.cpp index 8ed51ca..bf6c731 100644 --- a/VirtualTuringMachine/formalphabit.cpp +++ b/VirtualTuringMachine/formalphabit.cpp @@ -5,6 +5,7 @@ #include "interfaces/IVMTEnvironment.h" #include "screentools.h" #include "ui_formalphabit.h" +#include "utils/ui.h" #include "vmttheme.h" FormAlphabit::FormAlphabit(IVMTAlphabitSource* alphabit_source, @@ -16,14 +17,9 @@ FormAlphabit::FormAlphabit(IVMTAlphabitSource* alphabit_source, ui->setupUi(this); VmtTheme::polishWidgetTree(this); - // QButtonGroup *_group = nullptr; - // if(_alphabit_source->IsSingleChar()) - // _group = new QButtonGroup(); - if (!_alphabit_source->GetAlphabit()) qDebug() << "FormAlphabit::FormAlphabit Oppps 2!"; QString str = _alphabit_source->GetAlphabit()->ToString(); - //_layout.setSpacing(10); ui->frame->setLayout(&_layout); ui->frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); @@ -35,9 +31,8 @@ FormAlphabit::FormAlphabit(IVMTAlphabitSource* alphabit_source, const int count = qMin(static_cast(str.size()), 256); for (int i = 0; i < count; ++i) { QToolButton* label = &_buttons[i]; - // label->setFlat(true); label->setProperty("sign", QString(QChar(str[i]))); - label->setText(QString(QChar(str[i]))); + label->setText(QString(utils::ui::escapeChar(str[i]))); label->setCheckable(true); label->setStyleSheet(style); diff --git a/VirtualTuringMachine/utils/ui.cpp b/VirtualTuringMachine/utils/ui.cpp new file mode 100644 index 0000000..9b2a0a7 --- /dev/null +++ b/VirtualTuringMachine/utils/ui.cpp @@ -0,0 +1,18 @@ +#include "ui.h" + +namespace utils::ui { +QChar escapeChar(QChar c) { + if (c == QChar(' ')) { + return QChar(L'Ī»'); + } + return c; +} +QString escapeString(const QString& s) { + QString result; + result.reserve(s.size()); + for (QChar c : s) { + result.push_back(escapeChar(c)); + } + return result; +} +} // namespace utils::ui diff --git a/VirtualTuringMachine/utils/ui.h b/VirtualTuringMachine/utils/ui.h new file mode 100644 index 0000000..840920c --- /dev/null +++ b/VirtualTuringMachine/utils/ui.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +namespace utils::ui { + +/** + * @brief Change some chars to pretty render view + + * For example: ' ' -> 'Ī»' + */ +QChar escapeChar(QChar c); + +/** + * @brief Map escapeChar to all chars in string + */ +QString escapeString(const QString& s); +} // namespace utils::ui diff --git a/VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.cpp b/VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.cpp index 5f35a2e..30a686d 100644 --- a/VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.cpp +++ b/VirtualTuringMachine/vmtmachines/VMTComplexMachineInner.cpp @@ -49,17 +49,10 @@ VMTComplexMachineInner::GetTransitionCollection() { void VMTComplexMachineInner::PaintDiagramm(UICanvas& canvas, QRect rect, [[maybe_unused]] bool all) { for (std::shared_ptr m : _machines) { - if (!rect.isEmpty() && !rect.intersects(m->GetBounds())) { - continue; - } m->Paint(canvas, rect); } for (std::shared_ptr t : _transitions) { const QRect& transitionBounds = t->GetBounds(); - if (!rect.isEmpty() && !transitionBounds.isEmpty() && - !rect.intersects(transitionBounds)) { - continue; - } t->Paint(canvas, rect); } } diff --git a/VirtualTuringMachine/vmtmachines/VMTMachineStub.cpp b/VirtualTuringMachine/vmtmachines/VMTMachineStub.cpp index 6cc04c7..be07837 100644 --- a/VirtualTuringMachine/vmtmachines/VMTMachineStub.cpp +++ b/VirtualTuringMachine/vmtmachines/VMTMachineStub.cpp @@ -328,17 +328,11 @@ void VMTMachineStub::Move(const QPoint&& center, IVMTEnvironment* environment) { } void VMTMachineStub::Paint(UICanvas& canvas, const QRect& rect) { - if (!rect.isEmpty() && !rect.intersects(_bounds)) { - return; - } - if (this->_selected || this->_error) { if (_selected) { canvas.DrawRectAnimation(_bounds, _selected); } else canvas.DrawRect(_bounds, _selected, _error); - } else { - // canvas.DrawButton(_bounds); } if (_power > 1) { @@ -347,7 +341,6 @@ void VMTMachineStub::Paint(UICanvas& canvas, const QRect& rect) { rect.setLeft(rect.left() + rect.width()); rect.setWidth(rect.height() / 2); rect.setHeight(rect.height() / 2); - // canvas.DrawText(str, rect, false); canvas.DrawText(str, rect.center(), rect.height(), false); } diff --git a/devenv/tasks.nix b/devenv/tasks.nix index 1a6a7d3..7ce8e6d 100644 --- a/devenv/tasks.nix +++ b/devenv/tasks.nix @@ -5,7 +5,7 @@ mkdir -p build cd build cmake -S .. -DCMAKE_BUILD_TYPE=Debug - make + make -j$(nproc) ''; }; @@ -23,7 +23,7 @@ mkdir -p build cd build cmake -S .. - make + make -j$(nproc) ''; }; }; From 3e1a2bca44000c35b813f2469a81e675b722c9e3 Mon Sep 17 00:00:00 2001 From: Timur Buchkin Date: Wed, 14 Oct 2026 19:03:30 +0300 Subject: [PATCH 07/13] drop legacy .jdtp format support --- VirtualTuringMachine/VMTJsonSerializer.cpp | 73 ++- VirtualTuringMachine/VMTJsonSerializer.h | 4 + VirtualTuringMachine/VMTSerializer.cpp | 552 ------------------ VirtualTuringMachine/VMTSerializer.h | 134 ----- VirtualTuringMachine/VMTTransitionImpl.h | 1 - VirtualTuringMachine/formexercises.cpp | 4 +- VirtualTuringMachine/formmain.cpp | 6 +- VirtualTuringMachine/formnewproject.cpp | 29 - VirtualTuringMachine/formnewproject.h | 2 - VirtualTuringMachine/headless_main.cpp | 6 +- VirtualTuringMachine/uistatenewproject.h | 7 +- VirtualTuringMachine/vmtproject.h | 2 - .../vmtundoelementmachine.cpp | 13 +- devenv/packages.nix | 1 + .../test_machine_serialization.cpp | 12 +- 15 files changed, 82 insertions(+), 764 deletions(-) delete mode 100644 VirtualTuringMachine/VMTSerializer.cpp delete mode 100644 VirtualTuringMachine/VMTSerializer.h diff --git a/VirtualTuringMachine/VMTJsonSerializer.cpp b/VirtualTuringMachine/VMTJsonSerializer.cpp index a9164f0..761c019 100644 --- a/VirtualTuringMachine/VMTJsonSerializer.cpp +++ b/VirtualTuringMachine/VMTJsonSerializer.cpp @@ -1,5 +1,9 @@ #include "VMTJsonSerializer.h" +#include +#include +#include + #include #include #include @@ -10,6 +14,8 @@ #include #include #include +#include +#include #include "VMTAlphabit.h" #include "VMTTransitionImpl.h" @@ -221,8 +227,10 @@ bool VMTJsonSerializer::isJsonPath(const QString& path) { path.endsWith(QLatin1String(".vmt.json"), Qt::CaseInsensitive); } -bool VMTJsonSerializer::serialize(VMTProject* project) const { - if (!project) return false; +namespace { +std::optional PackProjectToJson(VMTProject* project, + bool pretty = true) { + if (!project) return std::nullopt; QMap, QString> innerIds; QMap machineIds; @@ -303,24 +311,16 @@ bool VMTJsonSerializer::serialize(VMTProject* project) const { root.insert(QStringLiteral("createdAt"), now); root.insert(QStringLiteral("updatedAt"), now); - QFile file(_file_name); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - qWarning() << "VMTJsonSerializer: cannot write" << _file_name; - return false; - } - file.write(QJsonDocument(root).toJson(QJsonDocument::Indented)); - return true; + QJsonDocument::JsonFormat format = + pretty ? QJsonDocument::Indented : QJsonDocument::Compact; + return QJsonDocument(root).toJson(format); } -bool VMTJsonSerializer::deserialize(VMTProject* project) const { - if (!project) return false; - - QFile file(_file_name); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qWarning() << "VMTJsonSerializer: cannot read" << _file_name; +bool UnpackProjectFromJson(VMTProject* project, const QByteArray& bytes) { + if (!project) { return false; } - const QJsonDocument doc = QJsonDocument::fromJson(file.readAll()); + const QJsonDocument doc = QJsonDocument::fromJson(bytes); if (!doc.isObject()) return false; const QJsonObject root = doc.object(); @@ -459,3 +459,44 @@ bool VMTJsonSerializer::deserialize(VMTProject* project) const { return !project->GetMachines().empty(); } + +} // namespace + +bool VMTJsonSerializer::serialize(VMTProject* project) const { + auto packed_project = PackProjectToJson(project, /*pretty=*/true); + if (!packed_project) { + return false; + } + + QFile file(_file_name); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + qWarning() << "VMTJsonSerializer: cannot write" << _file_name; + return false; + } + file.write(*packed_project); + return true; +} + +QByteArray VMTJsonSerializer::serializeInMemory(VMTProject* project) { + auto packed_project = PackProjectToJson(project, /*pretty=*/false); + if (!packed_project) { + throw std::logic_error("Failed pack project to bytes array"); + } + return *packed_project; +} + +bool VMTJsonSerializer::deserializeFromMemory(VMTProject* project, + QByteArray serialized_project) { + return UnpackProjectFromJson(project, serialized_project); +} + +bool VMTJsonSerializer::deserialize(VMTProject* project) const { + if (!project) return false; + + QFile file(_file_name); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning() << "VMTJsonSerializer: cannot read" << _file_name; + return false; + } + return UnpackProjectFromJson(project, file.readAll()); +} diff --git a/VirtualTuringMachine/VMTJsonSerializer.h b/VirtualTuringMachine/VMTJsonSerializer.h index fba5d6b..a2def80 100644 --- a/VirtualTuringMachine/VMTJsonSerializer.h +++ b/VirtualTuringMachine/VMTJsonSerializer.h @@ -15,6 +15,10 @@ class VMTJsonSerializer { bool serialize(VMTProject* project) const; bool deserialize(VMTProject* project) const; + static QByteArray serializeInMemory(VMTProject* project); + static bool deserializeFromMemory(VMTProject* project, + QByteArray serialized_project); + static bool isJsonPath(const QString& path); }; diff --git a/VirtualTuringMachine/VMTSerializer.cpp b/VirtualTuringMachine/VMTSerializer.cpp deleted file mode 100644 index 01c5c83..0000000 --- a/VirtualTuringMachine/VMTSerializer.cpp +++ /dev/null @@ -1,552 +0,0 @@ -#include "VMTSerializer.h" - -#include - -#include "QDebug" -#include "VMTAlphabit.h" -#include "VMTTransitionImpl.h" -#include "vmtmachines/VMTComplexMachine.h" -#include "vmtproject.h" - -#define TYPE_MACHINE 1 -#define TYPE_TRANSITION 2 - -namespace { -bool readMachineId(QDataStream& stream, qint64& id) { - stream >> id; - return stream.status() == QDataStream::Ok; -} -} // namespace - -VMTSerializer::VMTSerializer(QString& name) : _name(name) {} - -void VMTSerializer::FinalizeProject(VMTProject* project) { - if (!project) { - return; - } - - const std::shared_ptr alphabit = project->GetAlphabit(); - for (const std::shared_ptr& machine : - project->GetMachines()) { - machine->ChangeAlphabit(alphabit); - } -} - -bool VMTSerializer::DeserializeTransition( - ReadContext& context, const std::shared_ptr& machine) { - qint64 transitionId = 0; - qint64 startMachineId = 0; - qint64 finishMachineId = 0; - - context._stream >> transitionId; - if (!readMachineId(context._stream, startMachineId)) { - return false; - } - if (!readMachineId(context._stream, finishMachineId)) { - return false; - } - - auto transition = - std::shared_ptr(new VMTTransitionImpl(machine)); - transition->Deserialize(context._stream); - - if (startMachineId != 0) { - const auto startIt = context._machines.find(startMachineId); - if (startIt != context._machines.end()) { - transition->AttachStartMachine(startIt->second); - startIt->second->AddOutgoingTransition(transition); - } else { - qWarning() - << "VMTSerializer: transition start machine not found, id=" - << startMachineId; - } - } - - if (finishMachineId != 0) { - const auto finishIt = context._machines.find(finishMachineId); - if (finishIt != context._machines.end()) { - transition->AttachFinishMachine(finishIt->second); - finishIt->second->AddIncomingTransition(transition); - } else { - qWarning() - << "VMTSerializer: transition finish machine not found, id=" - << finishMachineId; - } - } - - context._transitions[transitionId] = transition; - machine->AddTransition(transition); - return true; -} - -void VMTSerializer::Deserialize(VMTProject* project) { - project->GetCurrentMachineName() = ""; - project->GetMachines().clear(); - - ReadContext context(_name); - - qDebug() << _name; - - if (context._open) { - qDebug() << "Start deserialize"; - QString signs; - ReadString(context, signs); - project->GetAlphabit()->ReplaceString(signs); - - qDebug() << "Alphabit:" << project->GetAlphabit()->ToString(); - qint64 count; - context._stream >> count; - - qDebug() << "Machine count:" << count; - - for (int i = 0; i < count; i++) { - std::shared_ptr machine = - Deserialize(context, 1, true); - } - - std::map> inner_map; - - qDebug() << "Total machines " << context._machines.size(); - for (auto machine : context._complex) { - if (machine) { - qDebug() << "add " << machine->GetName(); - project->GetMachines().push_back(machine); - inner_map[machine->GetName()] = machine->GetInnerObject(); - } - } - - qDebug() << "Replace inner machines"; - for (auto& machine : project->GetMachines()) { - ReplaceInnerObject(true, machine, inner_map); - } - - qDebug() << "Clear garbrage"; - for (auto& machine : project->GetMachines()) - ClearGarbrageTransitions(machine); - - FinalizeProject(project); - - } else - qDebug() << "Opps not open!"; - qDebug() << "Finish deserialize"; -} - -void VMTSerializer::Deserialize(VMTProject* project, QBuffer& buffer) { - // QString current_name= project->GetCurrentMachineName() = ""; - project->GetMachines().clear(); - - ReadContext context(buffer); - - qDebug() << _name; - - if (context._open) { - qDebug() << "Start deserialize"; - QString signs; - ReadString(context, signs); - project->GetAlphabit()->ReplaceString(signs); - - qDebug() << "Alphabit:" << project->GetAlphabit()->ToString(); - qint64 count; - context._stream >> count; - - qDebug() << "Machine count:" << count; - - for (int i = 0; i < count; i++) { - std::shared_ptr machine = - Deserialize(context, 1, true); - } - - std::map> inner_map; - - qDebug() << "Total machines " << context._machines.size(); - for (auto machine : context._complex) { - if (machine) { - qDebug() << "add " << machine->GetName(); - project->GetMachines().push_back(machine); - inner_map[machine->GetName()] = machine->GetInnerObject(); - } - } - - for (auto& machine : project->GetMachines()) { - ReplaceInnerObject(true, machine, inner_map); - } - - for (auto& machine : project->GetMachines()) - ClearGarbrageTransitions(machine); - - FinalizeProject(project); - - } else - qDebug() << "Opps not open!"; -} - -void VMTSerializer::ReplaceInnerObject( - bool recursive, std::shared_ptr machine, - std::map> inner_map) { - auto ptr = inner_map.find(machine->GetName()); - if (ptr != inner_map.end()) { - if (machine->GetInnerObject() != ptr->second) { - qDebug() << "Replacer replace:" << machine->GetName(); - machine->SetInnerObject(ptr->second, machine); - - } else { - qDebug() << "Replacer skip:" << machine->GetName(); - } - - if (recursive) - for (auto& child : machine->GetMachineCollection()) { - std::shared_ptr ptr_child = - std::dynamic_pointer_cast(child); - if (ptr_child) { - qDebug() << "Machine:" << ptr_child->GetName() << " has " - << ptr_child->GetMachineCollection().size() - << " childs"; - ReplaceInnerObject(false, ptr_child, inner_map); - } - } - - } else - qDebug() << "Replacer not found map for " << machine->GetName(); -} - -std::shared_ptr VMTSerializer::Deserialize( - ReadContext& context, long inner_id, bool binner) { - std::shared_ptr machine; - if (context._open) { - QString value; - machine = std::shared_ptr(new VMTComplexMachine( - value, std::shared_ptr(new VMTAlphabit()))); - machine->Deserialize(context._stream); - - ReadString(context, value); - machine->SetName(value); - qDebug() << "Complex machine name:" << machine->GetName(); - ReadString(context, value); - machine->GetAlphabit()->ReplaceString(value); - qDebug() << "Complex machine alphabit:" - << machine->GetAlphabit()->ToString(); - - if (!binner) { - qDebug() << "Finding inner machine"; - auto ptr = context._inner.find(inner_id); - if (ptr != context._inner.end()) { - machine->SetInnerObject(ptr->second, machine); - qDebug() << "Found"; - - } else - qDebug() << "ERROR!!! ID:" << inner_id; - } - - if (binner) { - qDebug() << "Deserialize inner machine"; - context._inner[inner_id] = machine->GetInnerObject(); - - bool found = false; - for (auto& complex_machine : context._complex) - if (complex_machine->GetName() == machine->GetName()) - found = true; - if (!found) { - context._complex.insert(machine); - } - - qint64 total_components; - context._stream >> total_components; - qDebug() << "Total components:" << total_components; - - while (total_components > 0) { - qint32 type_id; - context._stream >> type_id; - qDebug() << "MACHINE_TYPE:" << type_id; - total_components--; - - switch (type_id) { - case TYPE_MACHINE: { - qint64 id; - context._stream >> id; - qint32 machine_type; - context._stream >> machine_type; - qDebug() << "\n---------------Machine id:" << id - << " Type:" << machine_type; - - if (machine_type == - IVMTMachine::MachineType::MT_COMPLEX) { - qDebug() << "\n---------------Machine : complex"; - bool inner_local; - context._stream >> inner_local; - qint64 inner_id_local; - context._stream >> inner_id_local; - std::shared_ptr stub = - Deserialize(context, inner_id_local, - inner_local); - stub->SetParent(machine); - auto ptr = context._machines.find(id); - if (ptr != context._machines.end()) { - qDebug() << "Insert complex old id=" << id; - machine->AddMachine(ptr->second); - } else { - qDebug() << "Insert complex new id=" << id; - context._machines[id] = stub; - machine->AddMachine(stub); - } - - } else { - qDebug() << "Deserialize machine id=" << id; - if (machine_type == 0) { - qWarning() - << "VMTSerializer: invalid machine type"; - return machine; - } - std::shared_ptr stub = - VMTMachineStub::CreateMachineByID( - (IVMTMachine::MachineType)machine_type, - machine); - if (stub) { - qDebug() << "start deserialize"; - stub->Deserialize(context._stream); - qDebug() << "end deserialize"; - auto ptr = context._machines.find(id); - if (ptr != context._machines.end()) { - qDebug() << "Add machine old id=" << id; - machine->AddMachine(ptr->second); - } else { - qDebug() << "Add machine new id=" << id; - context._machines[id] = stub; - machine->AddMachine(stub); - } - } else { - qWarning() << "VMTSerializer: cannot create " - "machine type" - << machine_type; - return machine; - } - } - qDebug() << "\n--------------- End deserialize machine"; - - break; - } - case TYPE_TRANSITION: { - if (!DeserializeTransition(context, machine)) { - qWarning() << "VMTSerializer: failed to " - "deserialize transition"; - return machine; - } - break; - } - default: - qWarning() << "VMTSerializer: unknown component type" - << type_id; - return machine; - } - } - } - } - - return machine; -} - -void VMTSerializer::Serialize(VMTProject* project) { - WriteContext context(_name); - - qDebug() << "context created"; - if (context._open) { - qDebug() << "context opened"; - WriteString(context, project->GetAlphabit()->ToString()); - context._stream << (qint64)project->GetMachines().size(); - - for (auto machine : project->GetMachines()) { - qDebug() << "serialize mschine:" << machine->GetName(); - context._inner[machine->GetInnerObject()] = context._inner_id++; - Serialize(context, machine, true); - } - } -} - -void VMTSerializer::Serialize(VMTProject* project, QBuffer& buffer) { - WriteContext context(buffer); - - if (context._open) { - WriteString(context, project->GetAlphabit()->ToString()); - context._stream << (qint64)project->GetMachines().size(); - - for (auto machine : project->GetMachines()) { - context._inner[machine->GetInnerObject()] = context._inner_id++; - Serialize(context, machine, true); - } - } -} - -void VMTSerializer::ReadString(ReadContext& context, QString& str) { - if (context._open) { - short int length; - context._stream >> length; - - if (length > 0) { - char* array = new char[length + 1]; - std::memset(array, 0, length + 1); - context._stream.readRawData(array, length); - - str = QString::fromUtf8((const char*)array); - delete[] array; - } - } -} - -void VMTSerializer::WriteString(WriteContext& context, const QString& str) { - if (context._open) { - // context._stream << (short int)str.length(); - QByteArray array = str.toUtf8(); - context._stream << (short int)array.length(); - const char* carray = array.constData(); - for (int i = 0; i < array.length(); i++) { - context._stream << (qint8)(carray[i]); - // context._stream << (qint8)array[i];//(str[i]); - } - } -} - -void VMTSerializer::Serialize(WriteContext& context, - std::shared_ptr machine, - bool bInner) { - if (context._open) { - machine->Serialize(context._stream); - - WriteString(context, machine->GetName()); - WriteString(context, machine->GetAlphabit()->ToString()); - - if (!bInner) return; - - qDebug() << "Serialize machine structure:" << machine->GetName(); - // fill machine hash - qint64 total_components = 0; - for (auto& stub : machine->GetMachineCollection()) { - auto find = context._machines.find(stub); - if (find == context._machines.end()) - context._machines[stub] = context._machine_id++; - - total_components++; - } - // fill transition hash - - for (auto& stub : machine->GetTransitionCollection()) { - auto find = context._transitions.find(stub); - if (find == context._transitions.end()) - context._transitions[stub] = context._transition_id++; - total_components++; - } - context._stream << (qint64)total_components; - - for (auto stub : machine->GetMachineCollection()) { - long nID = context._machines[stub]; - context._stream << (qint32)TYPE_MACHINE; - context._stream << (qint64)nID; - context._stream << (qint32)stub->GetID(); - - if (stub->GetID() == IVMTMachine::MachineType::MT_COMPLEX) { - qDebug() << "----- Serialize complex machine:" - << stub->GetName(); - std::shared_ptr ptr = - std::dynamic_pointer_cast(stub); - if (ptr) { - if (context._inner.find(ptr->GetInnerObject()) != - context._inner.end()) { - context._stream << false; - context._stream - << (qint64)context._inner[ptr->GetInnerObject()]; - Serialize(context, ptr, false); - } else { - context._stream << true; - context._stream << (qint64)context._inner_id; - qDebug() << "Add inner:" << context._inner_id - << " for:" << ptr->GetName(); - context._inner[ptr->GetInnerObject()] = - context._inner_id++; - Serialize(context, ptr, true); - } - qDebug() << "----- Done serialize complex machine:" - << stub->GetName(); - } - } else { - qDebug() << "----- Serialize simple machine:" - << stub->GetName(); - stub->Serialize(context._stream); - qDebug() << "----- Done serialize simple machine:" - << stub->GetName(); - } - } - - // save transitions - for (auto stub : machine->GetTransitionCollection()) { - long nID = context._transitions[stub]; - - // save transition type - context._stream << (qint32)TYPE_TRANSITION; - context._stream << (qint64)nID; - - if (auto ptr = stub->GetStartMachine().lock()) { - context._stream << (qint64)context._machines[ptr]; - qDebug() << "Ptr" << (qint64)context._machines[ptr]; - } else - context._stream << (qint64)0; - - if (auto ptr = stub->GetFinishMachine().lock()) { - context._stream << (qint64)context._machines[ptr]; - qDebug() << "Ptr" << (qint64)context._machines[ptr]; - } else - context._stream << (qint64)0; - - // save transition internal data - stub->Serialize(context._stream); - } - } -} - -void VMTSerializer::ClearGarbrageTransitions( - std::shared_ptr machine) { - for (std::shared_ptr m : machine->GetMachineCollection()) { - bool removed = true; - - while (removed) { - removed = false; - for (const std::weak_ptr& t : - m->GetIncomingTransitions()) { - bool found = false; - - if (auto tptr = t.lock()) { - for (std::shared_ptr tc : - machine->GetTransitionCollection()) - if (tc == tptr) found = true; - if (!found) { - m->RemoveIncomingTransition(tptr); - qDebug() << "!!!!!!!!!!! Removed garbrage"; - removed = true; - break; - } - } - } - } - - removed = true; - - while (removed) { - removed = false; - for (const std::weak_ptr& t : - m->GetOutgoingTransitions()) { - bool found = false; - - if (auto tptr = t.lock()) { - for (std::shared_ptr& tc : - machine->GetTransitionCollection()) - if (tc == tptr) found = true; - if (!found) { - m->RemoveOutgoingTransition(tptr); - qDebug() << "!!!!!!!!!!! Removed garbrage"; - removed = true; - break; - } - } - } - } - } -} - -VMTSerializer::~VMTSerializer() {} diff --git a/VirtualTuringMachine/VMTSerializer.h b/VirtualTuringMachine/VMTSerializer.h deleted file mode 100644 index 531dfaf..0000000 --- a/VirtualTuringMachine/VMTSerializer.h +++ /dev/null @@ -1,134 +0,0 @@ -#if !defined(EA_FBF9ECAB_E1A9_4b4f_A5F3_7B533457B83F__INCLUDED_) -#define EA_FBF9ECAB_E1A9_4b4f_A5F3_7B533457B83F__INCLUDED_ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -class VMTProject; - -struct machine_compare { - bool operator()(const std::shared_ptr& a, - const std::shared_ptr& b) const { - return a->GetName() < b->GetName(); - } -}; - -class VMTSerializer { - public: - class ReadContext { - public: - QDataStream _stream; - QFile _file; - bool _open; - - std::map> _machines; - std::set, machine_compare> _complex; - std::map> _transitions; - std::map> _inner; - - ReadContext(QBuffer& buffer) { - _open = true; - buffer.open(QIODevice::ReadOnly); - _stream.setDevice(&buffer); - } - - ReadContext(QString name) { - _open = false; - _file.setFileName(name); - _file.open(QIODevice::ReadOnly); - if (_file.isOpen()) { - _stream.setDevice(&_file); - _open = true; - } else { - qWarning() << "VMTSerializer: cannot read file" << name - << _file.errorString(); - } - } - - virtual ~ReadContext() { - if (_file.isOpen()) _file.close(); - } - }; - - class WriteContext { - public: - long _machine_id; - long _inner_id; - long _transition_id; - - QDataStream _stream; - QFile _file; - bool _open; - - WriteContext(QString name) { - _open = false; - _file.setFileName(name); - _file.open(QIODevice::WriteOnly | QIODevice::Truncate); - if (_file.isOpen()) { - _open = true; - _stream.setDevice(&_file); - } else { - qWarning() << "VMTSerializer: cannot create file" << name - << _file.errorString(); - } - _machine_id = 1; - _inner_id = 1; - _transition_id = 1; - } - - WriteContext(QBuffer& buffer) { - buffer.open(QIODevice::WriteOnly); - _stream.setDevice(&buffer); - _machine_id = 1; - _inner_id = 1; - _transition_id = 1; - _open = true; - } - - std::map, long> _machines; - std::map, long> _transitions; - std::map, long> _inner; - - virtual ~WriteContext() { - if (_file.isOpen()) _file.close(); - } - }; - - VMTSerializer(QString& name); - - void Deserialize(VMTProject* project); - void Deserialize(VMTProject* project, QBuffer& buffer); - std::shared_ptr Deserialize(ReadContext& context, - long inner_id, bool binner); - - void Serialize(VMTProject* project); - void Serialize(VMTProject* project, QBuffer& buffer); - void Serialize(WriteContext& context, - std::shared_ptr p_Machine, bool bInner); - - virtual ~VMTSerializer(); - - protected: - QString _name; - void WriteString(WriteContext& context, const QString& str); - void ReadString(ReadContext& context, QString& str); - void ReplaceInnerObject( - bool recursive, std::shared_ptr machine, - std::map> inner_map); - void ClearGarbrageTransitions(std::shared_ptr machine); - void FinalizeProject(VMTProject* project); - bool DeserializeTransition( - ReadContext& context, - const std::shared_ptr& machine); -}; -#endif // !defined(EA_FBF9ECAB_E1A9_4b4f_A5F3_7B533457B83F__INCLUDED_) diff --git a/VirtualTuringMachine/VMTTransitionImpl.h b/VirtualTuringMachine/VMTTransitionImpl.h index e522102..5dc05a2 100644 --- a/VirtualTuringMachine/VMTTransitionImpl.h +++ b/VirtualTuringMachine/VMTTransitionImpl.h @@ -5,7 +5,6 @@ #include #include -#include "VMTSerializer.h" #include "VMTTransitionConditions.h" #include "interfaces/IVMTMachine.h" #include "interfaces/IVMTTransition.h" diff --git a/VirtualTuringMachine/formexercises.cpp b/VirtualTuringMachine/formexercises.cpp index a1aa7fb..9811760 100644 --- a/VirtualTuringMachine/formexercises.cpp +++ b/VirtualTuringMachine/formexercises.cpp @@ -147,8 +147,7 @@ bool FormExercises::OpenProject(QString& file) { return false; } } else { - VMTSerializer serializer(file); - serializer.Deserialize(&VMTProject::GetInstance()); + throw std::logic_error("Legacy .jdtp format support was dropped"); } VMTProject::GetInstance().GetUndoManager()->Clear(); @@ -168,7 +167,6 @@ void FormExercises::on__open_clicked() { dlg.setViewMode(QFileDialog::List); QStringList filters; filters << "Any files (*)" - << "Turing machine files (*.jdtp)" << "JSON projects (*.vmt.json *.json)"; dlg.setOption(QFileDialog::HideNameFilterDetails, false); dlg.setNameFilters(filters); diff --git a/VirtualTuringMachine/formmain.cpp b/VirtualTuringMachine/formmain.cpp index 2dd7ba3..b55d0ea 100644 --- a/VirtualTuringMachine/formmain.cpp +++ b/VirtualTuringMachine/formmain.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "VMTJsonSerializer.h" #include "configuration.h" @@ -89,9 +90,7 @@ bool FormMain::OpenProject(QString& file) { VMTJsonSerializer json(file); ok = json.deserialize(&VMTProject::GetInstance()); } else { - VMTSerializer serializer(file); - serializer.Deserialize(&VMTProject::GetInstance()); - ok = true; + throw std::logic_error("Legacy .jdtp format support was dropped"); } if (!ok) return false; VMTProject::GetInstance().GetUndoManager()->Clear(); @@ -134,7 +133,6 @@ void FormMain::on_button_open_clicked() { dlg.setViewMode(QFileDialog::List); QStringList filters; filters << "Any files (*)" - << "Turing machine files (*.jdtp)" << "JSON projects (*.vmt.json *.json)"; dlg.setOption(QFileDialog::HideNameFilterDetails, false); dlg.setNameFilters(filters); diff --git a/VirtualTuringMachine/formnewproject.cpp b/VirtualTuringMachine/formnewproject.cpp index 0b6e5b8..128e663 100644 --- a/VirtualTuringMachine/formnewproject.cpp +++ b/VirtualTuringMachine/formnewproject.cpp @@ -52,38 +52,9 @@ FormNewProject::FormNewProject(QWidget* parent) st.ResizeButtonBig(ui->button_z80); st.ResizeButtonBig(ui->button_create); - - auto* extras = new QVBoxLayout(); - auto* saveJson = new QPushButton(tr("Save as JSON…"), this); - saveJson->setStyleSheet(VmtTheme::primaryButtonStyle()); - connect(saveJson, &QPushButton::clicked, this, - &FormNewProject::on_save_json_clicked); - extras->addWidget(saveJson); - - ui->verticalLayout_2->addLayout(extras); - Check(); } -void FormNewProject::on_save_json_clicked() { - Save(); - QString path = VMTProject::GetInstance().GetLocation(); - path += QLatin1Char('/'); - path += VMTProject::GetInstance().GetName(); - if (!path.endsWith(QLatin1String(".json"), Qt::CaseInsensitive)) { - path += QLatin1String(".vmt.json"); - } - path = - QFileDialog::getSaveFileName(this, tr("Save JSON project"), path, - tr("JSON projects (*.vmt.json *.json)")); - if (path.isEmpty()) return; - VMTJsonSerializer json(path); - if (json.serialize(&VMTProject::GetInstance())) { - Configuration::GetInstance().AddRecentProject(path); - Configuration::GetInstance().Save(); - } -} - void FormNewProject::Save() { VMTProject::GetInstance().GetName() = ui->text_project_name->text(); VMTProject::GetInstance().GetLocation() = ui->text_project_location->text(); diff --git a/VirtualTuringMachine/formnewproject.h b/VirtualTuringMachine/formnewproject.h index ef50300..3c09311 100644 --- a/VirtualTuringMachine/formnewproject.h +++ b/VirtualTuringMachine/formnewproject.h @@ -39,8 +39,6 @@ class FormNewProject : public QWidget, public FormBase { void on_button_create_clicked(); - void on_save_json_clicked(); - private: Ui::FormNewProject* ui; diff --git a/VirtualTuringMachine/headless_main.cpp b/VirtualTuringMachine/headless_main.cpp index d6be433..c489767 100644 --- a/VirtualTuringMachine/headless_main.cpp +++ b/VirtualTuringMachine/headless_main.cpp @@ -4,7 +4,6 @@ #include #include "VMTJsonSerializer.h" -#include "VMTSerializer.h" #include "vmtdebuger.h" #include "vmtproject.h" @@ -53,10 +52,7 @@ bool run(const QString& path, const QString& machineName, const QString& input, if (VMTJsonSerializer::isJsonPath(path)) { loaded = VMTJsonSerializer(path).deserialize(&project); } else { - QString mutablePath = path; - VMTSerializer serializer(mutablePath); - serializer.Deserialize(&project); - loaded = !project.GetMachines().empty(); + throw std::logic_error("Legacy .jdtp format support was dropped"); } if (!loaded) { error = QStringLiteral("cannot load diagram: ") + path; diff --git a/VirtualTuringMachine/uistatenewproject.h b/VirtualTuringMachine/uistatenewproject.h index 34fa997..4659764 100644 --- a/VirtualTuringMachine/uistatenewproject.h +++ b/VirtualTuringMachine/uistatenewproject.h @@ -2,6 +2,7 @@ #define UISTATENEWPROJECT_H #include +#include "VMTJsonSerializer.h" #include "configuration.h" #include "formnewproject.h" #include "uistateeditormachine.h" @@ -41,8 +42,8 @@ class UIStateNewProject : public UIStateStub { if (name == QString("button_save")) { QString name; GetProjectFileName(name); - VMTSerializer serializer(name); - serializer.Serialize(&VMTProject::GetInstance()); + VMTJsonSerializer serializer(name); + serializer.serialize(&VMTProject::GetInstance()); Configuration::GetInstance().AddRecentProject(name); Configuration::GetInstance().Save(); @@ -59,7 +60,7 @@ class UIStateNewProject : public UIStateStub { name = VMTProject::GetInstance().GetLocation(); name += "/"; name += VMTProject::GetInstance().GetName(); - if (!name.endsWith(".jdtp", Qt::CaseInsensitive)) name += ".jdtp"; + name += ".vmt.json"; } }; diff --git a/VirtualTuringMachine/vmtproject.h b/VirtualTuringMachine/vmtproject.h index bec60e9..6afed58 100644 --- a/VirtualTuringMachine/vmtproject.h +++ b/VirtualTuringMachine/vmtproject.h @@ -1,7 +1,6 @@ #ifndef VMTPROJECT_H #define VMTPROJECT_H -#include #include #include @@ -10,7 +9,6 @@ #include "VMTAlphabit.h" #include "exercise.h" -#include "vmtproject.h" class UIStateData; class VMTProject { diff --git a/VirtualTuringMachine/vmtundoelementmachine.cpp b/VirtualTuringMachine/vmtundoelementmachine.cpp index ca58e41..10ff4c7 100644 --- a/VirtualTuringMachine/vmtundoelementmachine.cpp +++ b/VirtualTuringMachine/vmtundoelementmachine.cpp @@ -1,20 +1,19 @@ #include "vmtundoelementmachine.h" +#include + #include -#include "VMTSerializer.h" +#include "VMTJsonSerializer.h" #include "vmtproject.h" VMTUndoElementMachine::VMTUndoElementMachine() { - QBuffer buffer(&_array); - VMTSerializer serializer(VMTProject::GetInstance().GetName()); - serializer.Serialize(&VMTProject::GetInstance(), buffer); + _array = VMTJsonSerializer::serializeInMemory(&VMTProject::GetInstance()); } void VMTUndoElementMachine::Undo(IVMTEnvironment*) { - QBuffer buffer(&_array); - VMTSerializer serializer(VMTProject::GetInstance().GetName()); - serializer.Deserialize(&VMTProject::GetInstance(), buffer); + VMTJsonSerializer::deserializeFromMemory(&VMTProject::GetInstance(), + _array); } VMTUndoElementMachine::~VMTUndoElementMachine() {} diff --git a/devenv/packages.nix b/devenv/packages.nix index ce43844..66e6772 100644 --- a/devenv/packages.nix +++ b/devenv/packages.nix @@ -7,5 +7,6 @@ wrapQtAppsHook qtsvg qtimageformats + qtcreator ]; } diff --git a/tests/serialization/test_machine_serialization.cpp b/tests/serialization/test_machine_serialization.cpp index 30fd2cc..c57b4ab 100644 --- a/tests/serialization/test_machine_serialization.cpp +++ b/tests/serialization/test_machine_serialization.cpp @@ -6,7 +6,7 @@ #include #include -#include "VMTSerializer.h" +#include "VMTJsonSerializer.h" #include "interfaces/IVMTEnvironment.h" #include "interfaces/IVMTMachine.h" #include "interfaces/IVMTTransition.h" @@ -161,17 +161,17 @@ std::shared_ptr buildSampleDiagram() { } QString saveProjectToTempFile(QTemporaryDir& tempDir) { - QString path = tempDir.filePath(QStringLiteral("diagram.jdtp")); - VMTSerializer serializer(path); - serializer.Serialize(&VMTProject::GetInstance()); + QString path = tempDir.filePath(QStringLiteral("diagram.vmt.json")); + VMTJsonSerializer serializer(path); + serializer.serialize(&VMTProject::GetInstance()); return path; } void loadProjectFromFile(QString path) { VMTProject& project = VMTProject::GetInstance(); project.GetMachines().clear(); - VMTSerializer serializer(path); - serializer.Deserialize(&project); + VMTJsonSerializer serializer(path); + serializer.deserialize(&project); } } // namespace From 442b322c35ea49c3055f48c3016ff7a2ff153e65 Mon Sep 17 00:00:00 2001 From: Timur Buchkin Date: Wed, 14 Oct 2026 19:39:52 +0300 Subject: [PATCH 08/13] fix division by zero error --- VirtualTuringMachine/VMTTransitionImpl.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/VirtualTuringMachine/VMTTransitionImpl.cpp b/VirtualTuringMachine/VMTTransitionImpl.cpp index 0a7bcb6..288f7d3 100644 --- a/VirtualTuringMachine/VMTTransitionImpl.cpp +++ b/VirtualTuringMachine/VMTTransitionImpl.cpp @@ -246,6 +246,9 @@ void VMTTransitionImpl::Drag([[maybe_unused]] IVMTEnvironment* environment, double a = current.y() - prev.y(); double b = current.x() - prev.x(); + if (a * a + b * b == 0) { + a = b = 0.1; + } double dK = (a * (point.y() - prev.y()) + b * (point.x() - prev.x())) / (a * a + b * b); From 96e429ad9ae0ad98ff7784715b0a471653436f81 Mon Sep 17 00:00:00 2001 From: Timur Buchkin Date: Wed, 14 Oct 2026 20:10:31 +0300 Subject: [PATCH 09/13] remove unused code --- VirtualTuringMachine/formeditormachine.cpp | 10 ++-------- VirtualTuringMachine/formeditormachine.h | 3 --- VirtualTuringMachine/screentools.h | 3 --- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/VirtualTuringMachine/formeditormachine.cpp b/VirtualTuringMachine/formeditormachine.cpp index 6136757..c04ded8 100644 --- a/VirtualTuringMachine/formeditormachine.cpp +++ b/VirtualTuringMachine/formeditormachine.cpp @@ -1,5 +1,7 @@ #include "formeditormachine.h" +#include + #include #include #include @@ -303,14 +305,6 @@ void FormEditorMachine::ChangeZoom(size_t zoom) { ui->widget_editor->SetZoom(zoom); } -void FormEditorMachine::keyPressEvent(QKeyEvent* event) { - if (event->key() == Qt::Key_Escape) { - SetAction(std::shared_ptr( - new VMTActionPointer(this, ui->_navi->isChecked()))); - ui->tool_pointer->setChecked(true); - } -} - // IVMTEnvironment void FormEditorMachine::DisableAlphabit() { diff --git a/VirtualTuringMachine/formeditormachine.h b/VirtualTuringMachine/formeditormachine.h index 68aa2b8..333abbe 100644 --- a/VirtualTuringMachine/formeditormachine.h +++ b/VirtualTuringMachine/formeditormachine.h @@ -65,9 +65,6 @@ class FormEditorMachine : public QWidget, void SetAction(std::shared_ptr action) override; - protected: - void keyPressEvent(QKeyEvent* event) override; - private slots: void on_tool_pointer_clicked(); diff --git a/VirtualTuringMachine/screentools.h b/VirtualTuringMachine/screentools.h index a76abff..d3817fb 100644 --- a/VirtualTuringMachine/screentools.h +++ b/VirtualTuringMachine/screentools.h @@ -27,9 +27,6 @@ class ScreenTools : public QObject { void ResizeButton(QToolButton* btn); void ResizeButtonBig(QToolButton* btn); void ResizeButton(QPushButton* btn); - // void ResizeLabel(QLabel *label); - // void ResizeSlider(QSlider *sld); - // void ResizeFrame(QFrame *frame); void ResizePropertyPanel(QFrame* frame); const QSize& GetImageSize(); const QSize& GetCellSize(); From 7b63486f635847da265c98468c6658085db125bf Mon Sep 17 00:00:00 2001 From: Timur Buchkin Date: Wed, 14 Oct 2026 21:41:16 +0300 Subject: [PATCH 10/13] add hotkeys to toolbar navigation --- VirtualTuringMachine/formeditormachine.cpp | 95 +++++++++++++++++++--- VirtualTuringMachine/formeditormachine.h | 1 - VirtualTuringMachine/mainwindow.cpp | 8 ++ 3 files changed, 92 insertions(+), 12 deletions(-) diff --git a/VirtualTuringMachine/formeditormachine.cpp b/VirtualTuringMachine/formeditormachine.cpp index c04ded8..11c952c 100644 --- a/VirtualTuringMachine/formeditormachine.cpp +++ b/VirtualTuringMachine/formeditormachine.cpp @@ -143,21 +143,94 @@ void FormEditorMachine::OnKeyPressed(QKeyEvent* event) { if (event->key() == Qt::Key_Escape) { this->SetAction(std::shared_ptr( new VMTActionPointer(this, ui->_navi->isChecked()))); - } else if (event->key() == Qt::Key_Space) { - if (!_action_space) { - _action_space = ui->widget_editor->GetAction(); - SetAction( - std::shared_ptr(new VMTActionTranslate(this))); - } } } void FormEditorMachine::OnKeyReleased(QKeyEvent* event) { - if (event->key() == Qt::Key_Space) { - if (_action_space) { - SetAction(std::shared_ptr(_action_space)); - _action_space = nullptr; - } + switch (event->key()) { + case Qt::Key_Escape: + case Qt::Key_1: + SetAction(std::shared_ptr( + new VMTActionPointer(this, ui->_navi->isChecked()))); + return ui->tool_pointer->setChecked(true); + case Qt::Key_2: + SetAction( + std::shared_ptr(new VMTActionTranslate(this))); + return ui->tool_translate->setChecked(true); + case Qt::Key_3: + SetAction(std::shared_ptr(new VMTActionLink(this))); + return ui->tool_link->setChecked(true); + case Qt::Key_4: + SetAction(std::shared_ptr(new VMTActionDelete(this))); + return ui->tool_trash->setChecked(true); + case Qt::Key_Y: + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_START, this->GetMachine()), + ui->_navi->isChecked()))); + return ui->tool_machine_start->setChecked(true); + case Qt::Key_U: + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_LEFT, this->GetMachine()), + ui->_navi->isChecked()))); + return ui->tool_machine_left->setChecked(true); + case Qt::Key_I: + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_LEFT_WORD, this->GetMachine()), + ui->_navi->isChecked()))); + return ui->tool_machine_left_word->setChecked(true); + case Qt::Key_O: + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_COPY, this->GetMachine()), + ui->_navi->isChecked()))); + return ui->tool_machine_copy->setChecked(true); + case Qt::Key_H: + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_FINISH, this->GetMachine()), + ui->_navi->isChecked()))); + return ui->tool_machine_finish->setChecked(true); + case Qt::Key_J: + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_RIGHT, this->GetMachine()), + ui->_navi->isChecked()))); + return ui->tool_machine_right->setChecked(true); + case Qt::Key_K: + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_RIGHT_WORD, + this->GetMachine()), + ui->_navi->isChecked()))); + return ui->tool_machine_right_word->setChecked(true); + case Qt::Key_L: + SetAction(std::shared_ptr(new VMTActionMachine( + this, + VMTMachineStub::CreateMachineByID( + IVMTMachine::MachineType::MT_WRITE, this->GetMachine()), + ui->_navi->isChecked()))); + return ui->tool_machine_lambda->setChecked(true); + case Qt::Key_V: + SetAction( + std::shared_ptr(new VMTActionTranslate(this))); + return EnableFormComplexMachines(); + case Qt::Key_B: + ui->_navi->setChecked(!ui->_navi->isChecked()); + if (ui->_navi->isChecked()) { + SetAction(std::shared_ptr( + new VMTActionPointer(this, ui->_navi->isChecked()))); + } + return; } } diff --git a/VirtualTuringMachine/formeditormachine.h b/VirtualTuringMachine/formeditormachine.h index 333abbe..4fab239 100644 --- a/VirtualTuringMachine/formeditormachine.h +++ b/VirtualTuringMachine/formeditormachine.h @@ -101,7 +101,6 @@ class FormEditorMachine : public QWidget, FormCalculator* _form_calculator; FormComplexMachines* _form_complex_machines; FormActionHint* _form_action_hint; - std::shared_ptr _action_space; bool _deferTransitionRouting = false; }; diff --git a/VirtualTuringMachine/mainwindow.cpp b/VirtualTuringMachine/mainwindow.cpp index 3e95d86..fb3c95d 100644 --- a/VirtualTuringMachine/mainwindow.cpp +++ b/VirtualTuringMachine/mainwindow.cpp @@ -1,5 +1,8 @@ #include "mainwindow.h" +#include +#include + #include #include #include @@ -180,6 +183,11 @@ void MainWindow::keyReleaseEvent(QKeyEvent* event) { qDebug() << "CTRL released"; ctrlPressed = false; } + if (event->key() == Qt::Key_Space) { + qDebug() << "TODO(Tias): inspect how space traverse to undo manager " + "and clear it\n"; + return; + } if (_state) { _state->OnKeyReleased(event); } From b91f24071241ecf1e2c178d1c1f378c70f2ad3ff Mon Sep 17 00:00:00 2001 From: Timur Buchkin Date: Wed, 14 Oct 2026 21:42:28 +0300 Subject: [PATCH 11/13] fix recursive serialization bug --- VirtualTuringMachine/VMTJsonSerializer.cpp | 62 +++++++++++----------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/VirtualTuringMachine/VMTJsonSerializer.cpp b/VirtualTuringMachine/VMTJsonSerializer.cpp index 761c019..05fb26e 100644 --- a/VirtualTuringMachine/VMTJsonSerializer.cpp +++ b/VirtualTuringMachine/VMTJsonSerializer.cpp @@ -241,52 +241,50 @@ std::optional PackProjectToJson(VMTProject* project, const auto registerInner = [&](const std::shared_ptr& inner, - const QString& defaultName) -> QString { - if (!inner) return QString(); + const QString& defaultName) -> bool { + if (!inner) return false; if (!innerIds.contains(inner)) { innerIds.insert(inner, newId()); innerNames.insert(inner, defaultName); + return true; } - return innerIds.value(inner); + return false; }; std::function&, const QString&)> - scanInner; - scanInner = [&](const std::shared_ptr& inner, - const QString& defaultName) { - if (!inner) return; - registerInner(inner, defaultName); - for (const auto& m : inner->GetMachineCollection()) { - if (!m || m->GetID() != IVMTMachine::MT_COMPLEX) continue; - const auto cm = std::dynamic_pointer_cast(m); - if (cm && cm->GetInnerObject()) { - scanInner(cm->GetInnerObject(), cm->GetName()); + scanInner = [&](const std::shared_ptr& inner, + const QString& defaultName) { + if (!inner || !registerInner(inner, defaultName)) return; + for (const auto& m : inner->GetMachineCollection()) { + if (!m || m->GetID() != IVMTMachine::MT_COMPLEX) continue; + const auto cm = std::dynamic_pointer_cast(m); + if (cm && cm->GetInnerObject()) { + scanInner(cm->GetInnerObject(), cm->GetName()); + } } - } - }; + }; QSet exported; std::function&, const QString&)> - emitBody; - emitBody = [&](const std::shared_ptr& inner, - const QString& defaultName) { - if (!inner || exported.contains(inner.get())) return; - exported.insert(inner.get()); - const QString bodyId = innerIds.value(inner); - const QString bodyName = innerNames.value(inner, defaultName); - bodiesArr.append(bodyToJson(bodyId, bodyName, inner.get(), - project->GetAlphabit(), machineIds, - innerIds)); - for (const auto& m : inner->GetMachineCollection()) { - if (!m || m->GetID() != IVMTMachine::MT_COMPLEX) continue; - const auto cm = std::dynamic_pointer_cast(m); - if (cm && cm->GetInnerObject()) { - emitBody(cm->GetInnerObject(), cm->GetName()); + emitBody = [&](const std::shared_ptr& inner, + const QString& defaultName) { + if (!inner || exported.contains(inner.get())) return; + exported.insert(inner.get()); + const QString bodyId = innerIds.value(inner); + const QString bodyName = innerNames.value(inner, defaultName); + bodiesArr.append(bodyToJson(bodyId, bodyName, inner.get(), + project->GetAlphabit(), machineIds, + innerIds)); + for (const auto& m : inner->GetMachineCollection()) { + if (!m || m->GetID() != IVMTMachine::MT_COMPLEX) continue; + const auto cm = std::dynamic_pointer_cast(m); + if (cm && cm->GetInnerObject()) { + emitBody(cm->GetInnerObject(), cm->GetName()); + } } - } - }; + }; for (const auto& top : project->GetMachines()) { if (!top) continue; From 37289265ccc944b3da323ee0ead14f8a62446412 Mon Sep 17 00:00:00 2001 From: Timur Buchkin Date: Wed, 14 Oct 2026 22:10:10 +0300 Subject: [PATCH 12/13] work on ui function to auto serialize --- VirtualTuringMachine/mainwindow.cpp | 21 +++++++++++++++------ VirtualTuringMachine/statecontroller.h | 15 +++++++++++++++ VirtualTuringMachine/utils/ui.h | 7 +++++++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/VirtualTuringMachine/mainwindow.cpp b/VirtualTuringMachine/mainwindow.cpp index fb3c95d..ac40bd0 100644 --- a/VirtualTuringMachine/mainwindow.cpp +++ b/VirtualTuringMachine/mainwindow.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -10,12 +11,15 @@ #include #include +#include "VMTJsonSerializer.h" #include "clickablelabel.h" #include "configuration.h" #include "formwarning.h" #include "screentools.h" #include "ui_mainwindow.h" #include "uistatemain.h" +#include "uistatenewproject.h" +#include "vmtproject.h" #include "vmttheme.h" MainWindow::MainWindow(QWidget* parent) @@ -155,13 +159,18 @@ void MainWindow::Enable4thExport(bool enable) { #include void MainWindow::closeEvent(QCloseEvent* event) { - QMessageBox::StandardButton resBtn = QMessageBox::question( - this, "VMT", "This will delete any unsaved project data. Are you sure?", - QMessageBox::No | QMessageBox::Yes, QMessageBox::No); - if (resBtn != QMessageBox::Yes) { - event->ignore(); - } else { + QString file_path; + UIStateNewProject::GetProjectFileName(file_path); + VMTJsonSerializer serializer{file_path}; + auto& project = VMTProject::GetInstance(); + if (!project.GetMachines().empty() && serializer.serialize(&project)) { event->accept(); + Configuration::GetInstance().AddRecentProject(file_path); + Configuration::GetInstance().Save(); + QMessageBox box; + box.setText("Project saved"); + box.exec(); + return; } } diff --git a/VirtualTuringMachine/statecontroller.h b/VirtualTuringMachine/statecontroller.h index 6999a05..af359cd 100644 --- a/VirtualTuringMachine/statecontroller.h +++ b/VirtualTuringMachine/statecontroller.h @@ -9,6 +9,8 @@ #include #include +#include "VMTJsonSerializer.h" +#include "uistatenewproject.h" #include "vmtproject.h" class StateController { @@ -67,6 +69,19 @@ class StateController { VMTProject::GetInstance().GetUndoManager()->SetObserver(nullptr); if (_state_data->IsNeedWarning()) { warning = true; + QString file_path; + UIStateNewProject::GetProjectFileName(file_path); + VMTJsonSerializer serializer{file_path}; + auto& project = VMTProject::GetInstance(); + if (!project.GetMachines().empty() && + serializer.serialize(&project)) { + Configuration::GetInstance().AddRecentProject(file_path); + Configuration::GetInstance().Save(); + QMessageBox box; + box.setText("Project saved"); + box.exec(); + warning = false; + } QMessageBox::StandardButton resBtn = QMessageBox::question( nullptr, "VMT", diff --git a/VirtualTuringMachine/utils/ui.h b/VirtualTuringMachine/utils/ui.h index 840920c..0652127 100644 --- a/VirtualTuringMachine/utils/ui.h +++ b/VirtualTuringMachine/utils/ui.h @@ -16,4 +16,11 @@ QChar escapeChar(QChar c); * @brief Map escapeChar to all chars in string */ QString escapeString(const QString& s); + +/** + * @brief Serialize project if needed + * + * @return true if serialized happened, false otherwise, + */ +bool SerializeWithPromptIfNeeded(); } // namespace utils::ui From 8e4d55a19fbe606be64f5296df64dfa8c9896c2e Mon Sep 17 00:00:00 2001 From: Timur Buchkin Date: Wed, 14 Oct 2026 23:38:54 +0300 Subject: [PATCH 13/13] auto save project on exit --- VirtualTuringMachine/mainwindow.cpp | 20 +++--------------- VirtualTuringMachine/statecontroller.h | 29 ++------------------------ VirtualTuringMachine/utils/ui.cpp | 18 ++++++++++++++++ 3 files changed, 23 insertions(+), 44 deletions(-) diff --git a/VirtualTuringMachine/mainwindow.cpp b/VirtualTuringMachine/mainwindow.cpp index ac40bd0..4a0dfe6 100644 --- a/VirtualTuringMachine/mainwindow.cpp +++ b/VirtualTuringMachine/mainwindow.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -11,15 +10,13 @@ #include #include -#include "VMTJsonSerializer.h" #include "clickablelabel.h" #include "configuration.h" #include "formwarning.h" #include "screentools.h" #include "ui_mainwindow.h" #include "uistatemain.h" -#include "uistatenewproject.h" -#include "vmtproject.h" +#include "utils/ui.h" #include "vmttheme.h" MainWindow::MainWindow(QWidget* parent) @@ -159,19 +156,8 @@ void MainWindow::Enable4thExport(bool enable) { #include void MainWindow::closeEvent(QCloseEvent* event) { - QString file_path; - UIStateNewProject::GetProjectFileName(file_path); - VMTJsonSerializer serializer{file_path}; - auto& project = VMTProject::GetInstance(); - if (!project.GetMachines().empty() && serializer.serialize(&project)) { - event->accept(); - Configuration::GetInstance().AddRecentProject(file_path); - Configuration::GetInstance().Save(); - QMessageBox box; - box.setText("Project saved"); - box.exec(); - return; - } + utils::ui::SerializeWithPromptIfNeeded(); + event->accept(); } void MainWindow::ShowWarning(std::shared_ptr) { diff --git a/VirtualTuringMachine/statecontroller.h b/VirtualTuringMachine/statecontroller.h index af359cd..b295f17 100644 --- a/VirtualTuringMachine/statecontroller.h +++ b/VirtualTuringMachine/statecontroller.h @@ -9,8 +9,7 @@ #include #include -#include "VMTJsonSerializer.h" -#include "uistatenewproject.h" +#include "utils/ui.h" #include "vmtproject.h" class StateController { @@ -69,33 +68,9 @@ class StateController { VMTProject::GetInstance().GetUndoManager()->SetObserver(nullptr); if (_state_data->IsNeedWarning()) { warning = true; - QString file_path; - UIStateNewProject::GetProjectFileName(file_path); - VMTJsonSerializer serializer{file_path}; - auto& project = VMTProject::GetInstance(); - if (!project.GetMachines().empty() && - serializer.serialize(&project)) { - Configuration::GetInstance().AddRecentProject(file_path); - Configuration::GetInstance().Save(); - QMessageBox box; - box.setText("Project saved"); - box.exec(); + if (utils::ui::SerializeWithPromptIfNeeded()) { warning = false; } - - QMessageBox::StandardButton resBtn = QMessageBox::question( - nullptr, "VMT", - "This will delete any unsaved project data. Are you sure?", - QMessageBox::No | QMessageBox::Yes, QMessageBox::No); - if (resBtn != QMessageBox::Yes) { - return false; - // event->ignore(); - } else { - warning = false; - // event->accept(); - } - - // ShowWarning(state_data); } } diff --git a/VirtualTuringMachine/utils/ui.cpp b/VirtualTuringMachine/utils/ui.cpp index 9b2a0a7..ae0fa13 100644 --- a/VirtualTuringMachine/utils/ui.cpp +++ b/VirtualTuringMachine/utils/ui.cpp @@ -1,5 +1,8 @@ #include "ui.h" +#include "VMTJsonSerializer.h" +#include "uistatenewproject.h" + namespace utils::ui { QChar escapeChar(QChar c) { if (c == QChar(' ')) { @@ -15,4 +18,19 @@ QString escapeString(const QString& s) { } return result; } +bool SerializeWithPromptIfNeeded() { + QString file_path; + UIStateNewProject::GetProjectFileName(file_path); + VMTJsonSerializer serializer{file_path}; + auto& project = VMTProject::GetInstance(); + if (!project.GetMachines().empty() && serializer.serialize(&project)) { + Configuration::GetInstance().AddRecentProject(file_path); + Configuration::GetInstance().Save(); + QMessageBox box; + box.setText("Project saved"); + box.exec(); + return true; + } + return false; +} } // namespace utils::ui