-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqtconceptmapcommands.cpp
82 lines (76 loc) · 2.46 KB
/
qtconceptmapcommands.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "qtconceptmapcommands.h"
#include "qtconceptmap.h"
#include "container.h"
#include "qtconceptmapcommandcreatenewnode.h"
#include "qtconceptmapcommandcreatenewedge.h"
#include "qtconceptmapcommandmove.h"
#include "qtconceptmapcommandmoveedge.h"
#include "qtconceptmapcommandmovenode.h"
#include "qtconceptmapcommandselect.h"
#include "qtconceptmapcommandselectedge.h"
#include "qtconceptmapcommandselectnode.h"
#include "qtconceptmapcommandsetconcept.h"
#include "qtconceptmapcommandsetmode.h"
#include "qtconceptmapcommandtogglearrowhead.h"
#include "qtconceptmapcommandtogglearrowtail.h"
#include "qtconceptmapcommandunselect.h"
#include "qtconceptmapcommandunselectall.h"
#include "qtconceptmapcommandunselectedge.h"
#include "qtconceptmapcommandunselectnode.h"
std::string ribi::cmap::GetCommands(const std::vector<std::string>& args)
{
//Extract the --command section
const int sz = args.size();
if (sz < 2) return {};
for (int i=0; i!=sz-1; ++i)
{
if (args[i] == "--command") return args[i+1];
}
return {};
}
/// Works on, for example 'create_node(0, 0, from)', 'create_edge(relation)'
ribi::cmap::Command* ribi::cmap::ParseCommand(QtConceptMap& q, const std::string& s)
{
using ParsingFunction = std::function<Command*(QtConceptMap&, std::string)>;
const std::vector<ParsingFunction> parsing_functions =
{
ParseCommandCreateNewEdge,
ParseCommandCreateNewNode,
//ParseCommandCreateDeleteSelected,
ParseCommandMove,
ParseCommandMoveEdge,
ParseCommandMoveNode,
ParseCommandSelect,
ParseCommandSelectEdge,
ParseCommandSelectNode,
ParseCommandSetConcept,
ParseCommandToggleArrowHead,
ParseCommandToggleArrowTail,
ParseCommandSetMode,
ParseCommandUnselect,
ParseCommandUnselectAll,
ParseCommandUnselectEdge,
ParseCommandUnselectNode
};
for (const auto parsing_function: parsing_functions)
{
if (auto p = parsing_function(q, s)) return p;
}
return nullptr;
}
void ribi::cmap::ProcessCommands(
QtConceptMap& q,
const std::vector<std::string>& args)
{
//Get the commands as one string
const std::string s = GetCommands(args);
if (s.empty()) return;
//Convert strings to Commands, nullptr if it string cannot be parsed to any Command
const std::vector<std::string> text_commands = Container().SeperateString(s, ';');
for (const std::string& text_command: text_commands)
{
Command * const cmd = ParseCommand(q, text_command);
if (!cmd) continue;
q.DoCommand(cmd);
}
}