-
Notifications
You must be signed in to change notification settings - Fork 7
/
command.cpp
123 lines (111 loc) · 2.68 KB
/
command.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "command.h"
#include <QDebug>
Command::Command (const QString &n, SelectionType st)
{
name=n;
selectionType=st;
}
QString Command::getName()
{
return name;
}
QString Command::getDescription()
{
QString s;
s=QString("%1\n").arg(name);
s+=QString(" Selection: %1\n").arg(getSelectionTypeName());
//s+=QString(" Parameters: %1\n").arg(parCount() );
for (int i=0;i<parCount();i++)
{
s+=QString(" Parameter %1:\n").arg(i);
s+=QString(" Comment: %1\n").arg(getParComment(i));
s+=QString(" Type: %1\n").arg(getParTypeName(i));
s+=QString(" Optional: ");
isParOptional(i) ? s+="yes\n" :s+="No\n";
}
return s;
}
QString Command::getDescriptionLaTeX()
{
QString s;
s=QString("\\item %1\\\\\n").arg(name);
s+="\\begin{tabular}{rl}\n";
s+=QString(" Selection: & %1\\\\\n").arg(getSelectionTypeName());
for (int i=0;i<parCount();i++)
{
s+=QString(" Parameter: & %1:\\\\\n").arg(i);
s+=QString(" Comment: & %1\\\\\n").arg(getParComment(i));
s+=QString(" Type: & %1\\\\\n").arg(getParTypeName(i));
s+=QString(" Optional: & ");
isParOptional(i) ? s+="yes\\\\\n" :s+="No\\\\\n";
}
s+="\\end{tabular}\n";
return s;
}
void Command::addPar (ParameterType t, bool opt, const QString &c)
{
parTypes.append (t);
parOpts.append (opt);
parComments.append (c);
}
int Command::parCount()
{
return parTypes.count();
}
Command::ParameterType Command::getParType (int n)
{
if (n>=0 && n<parTypes.count() )
{
return parTypes.at(n);
}
qDebug()<<"Command::getParType n out of range";
return Undefined;
}
QString Command::getParTypeName (int n)
{
switch (getParType(n))
{
case String: return "String";
case Int: return "Int";
case Double: return "Double";
case Color: return "Color";
case Bool: return "Bool";
default: return "Undefined";
}
}
Command::SelectionType Command::getSelectionType ()
{
return selectionType;
}
QString Command::getSelectionTypeName ()
{
switch (getSelectionType())
{
case Any: return "Any";
case TreeItem: return "TreeItem";
case Branch: return "Branch";
case BranchLike: return "BranchLike";
case Image: return "Image";
case BranchOrImage: return "BranchOrImage";
case XLink: return "XLink";
default: return "Undefined";
}
}
bool Command::isParOptional (int n)
{
if (n>=0 && n<parTypes.count() )
{
return parOpts.at(n);
}
qDebug()<<"Command::isParOpt n out of range";
return false;
}
QString Command::getParComment(int n)
{
if (n>=0 && n<parTypes.count() )
{
return parComments.at(n);
}
qDebug()<<"Command::getParComment n out of range";
return QString();
}