-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqtconceptmapcommandselect.cpp
119 lines (109 loc) · 2.68 KB
/
qtconceptmapcommandselect.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
#include "qtconceptmapcommandselect.h"
#include <cassert>
#include <boost/algorithm/string/trim.hpp>
#include <gsl/gsl_assert>
#include <QDebug>
#include "count_vertices_with_selectedness.h"
#include "container.h"
#include "conceptmap.h"
#include "conceptmaphelper.h"
#include "conceptmapnode.h"
#include "qtconceptmap.h"
#include "qtconceptmapqtedge.h"
#include "qtconceptmapqtnode.h"
#include "qtconceptmaphelper.h"
#include "qtconceptmapcommandselectedge.h"
#include "qtconceptmapcommandselectnode.h"
ribi::cmap::CommandSelect::CommandSelect(
QtConceptMap& qtconceptmap,
QGraphicsItem& item
)
: Command(qtconceptmap),
m_cmd{nullptr}
{
try
{
if (QtEdge* const qtedge = qgraphicsitem_cast<QtEdge*>(&item))
{
m_cmd = new CommandSelectEdge(qtconceptmap, qtedge, this);
}
else if (QtNode* const qtnode = qgraphicsitem_cast<QtNode*>(&item))
{
if (QtEdge * const qtedge2 = FindQtEdge(qtnode, GetQtConceptMap()))
{
m_cmd = new CommandSelectEdge(qtconceptmap, qtedge2, this);
}
else
{
m_cmd = new CommandSelectNode(qtconceptmap, qtnode, this);
}
}
}
catch (const std::exception& e)
{
throw e;
}
if (!m_cmd)
{
throw std::invalid_argument("item is not a QtEdge nor QtNode");
}
//QCommands have a text
{
assert(m_cmd);
this->setText(m_cmd->text());
}
}
ribi::cmap::CommandSelect::~CommandSelect() noexcept
{
}
ribi::cmap::CommandSelect * ribi::cmap::ParseCommandSelect(
QtConceptMap& qtconceptmap, std::string s)
{
//"select(my text)"
boost::algorithm::trim(s);
const std::string str_begin = "select(";
if (s.substr(0, str_begin.size()) != str_begin) return nullptr;
if (s.back() != ')') return nullptr;
//"my text"
const std::string t = s.substr(str_begin.size(), s.size() - str_begin.size() - 1);
assert(t[0] != '(');
assert(t.back() != ')');
for (QGraphicsItem * const item: qtconceptmap.items())
{
if (QtEdge * const qtedge = qgraphicsitem_cast<QtEdge*>(item))
{
if (GetText(*qtedge) == t)
{
return new CommandSelect(qtconceptmap, *qtedge);
}
}
if (QtNode * const qtnode = qgraphicsitem_cast<QtNode*>(item))
{
if (QtEdge * const qtedge2 = FindQtEdge(qtnode, qtconceptmap))
{
if (GetText(*qtedge2) == t)
{
return new CommandSelect(qtconceptmap, *qtedge2);
}
}
else
{
if (GetText(*qtnode) == t)
{
return new CommandSelect(qtconceptmap, *qtnode);
}
}
}
}
return nullptr;
}
void ribi::cmap::CommandSelect::Redo()
{
assert(m_cmd);
m_cmd->redo();
}
void ribi::cmap::CommandSelect::Undo()
{
assert(m_cmd);
m_cmd->undo();
}