Skip to content

Commit e0826f2

Browse files
navrkaldnavrkald
authored andcommitted
Added selection regexp node and visualize its automats.
1 parent 011f543 commit e0826f2

File tree

7 files changed

+45
-5
lines changed

7 files changed

+45
-5
lines changed

RegularConvertor/algorithms/regexptofa.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ RegExpToFA::RegExpToFA(AlgorithmWidget* _algorithm_widget, modes _mode, RegExpWi
8181
connect(this->algorithm_widget,SIGNAL(stopPressed()),this,SLOT(stop()));
8282
connect(this->algorithm_widget,SIGNAL(prewPressed()),this,SLOT(prewStep()));
8383
connect(this->algorithm_widget,SIGNAL(nextPressed()),this,SLOT(nextStep()));
84-
84+
connect(this->re_widget,SIGNAL(itemClicked(QModelIndex)),this,SLOT(selectRegExp(QModelIndex)));
85+
connect(this->center_fa_widget,SIGNAL(FA_changed(FiniteAutomata*))
8586
}
8687

8788

@@ -95,6 +96,30 @@ void RegExpToFA::setRE(RegExp* _re)
9596
//computeSolution();
9697
}
9798

99+
void RegExpToFA::selectRegExp(QModelIndex index)
100+
{
101+
RegExpNode* node = re_widget->treeModel->nodeFromIndex(index);
102+
103+
QList<RegExpNode*> children = node->children;
104+
if(children.count() > 0)
105+
{
106+
left_fa_widget->setFA(new FiniteAutomata(children.at(0)->user_FA));
107+
}
108+
else
109+
{
110+
left_fa_widget->setFA(new FiniteAutomata());
111+
}
112+
if(children.count() > 1)
113+
{
114+
right_fa_widget->setFA(new FiniteAutomata(children.at(1)->user_FA));
115+
}
116+
else
117+
{
118+
right_fa_widget->setFA(new FiniteAutomata());
119+
}
120+
center_fa_widget->setFA(new FiniteAutomata(node->user_FA));
121+
}
122+
98123
void RegExpToFA::computeSolution()
99124
{
100125
while(nodesToProcede.count() != 0)
@@ -171,21 +196,21 @@ void RegExpToFA::nextStep()
171196
qDebug() << "Pocet synu: " << children.count();
172197
if(children.count() > 0)
173198
{
174-
left_fa_widget->setFA(&(children.at(0)->user_FA));
199+
left_fa_widget->setFA(new FiniteAutomata(children.at(0)->user_FA));
175200
}
176201
else
177202
{
178203
left_fa_widget->setFA(new FiniteAutomata());
179204
}
180205
if(children.count() > 1)
181206
{
182-
right_fa_widget->setFA(&(children.at(1)->user_FA));
207+
right_fa_widget->setFA(new FiniteAutomata(children.at(1)->user_FA));
183208
}
184209
else
185210
{
186211
right_fa_widget->setFA(new FiniteAutomata());
187212
}
188-
center_fa_widget->setFA(&(processedNode->user_FA));
213+
center_fa_widget->setFA(new FiniteAutomata(processedNode->user_FA));
189214

190215
//set and update node icon
191216
processedNode->state = RegExpNode::CORRECT;
@@ -197,6 +222,7 @@ void RegExpToFA::nextStep()
197222
else
198223
{
199224
//qDebug() << "Nodes to precesed empty!";
225+
timer->stop();
200226
}
201227

202228

RegularConvertor/algorithms/regexptofa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class RegExpToFA : public Algorithm
2626

2727
public slots:
2828
void setRE(RegExp* _re);
29+
void selectRegExp(QModelIndex index);
2930

3031
void runAlgorithm(int mil_sec);
3132
void nextStep();

RegularConvertor/finite_machine/diagramscene.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ void DiagramScene::setFA(FiniteAutomata* _FA)
368368
this->selectAll();
369369
this->deleteSelected();
370370

371+
delete this->FA;
371372
this->FA = _FA;
372373
addNodes(FA->states);
373374
setStartNode(FA->startState);

RegularConvertor/finite_machine/finiteautomata.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ FiniteAutomata::FiniteAutomata(QString symbol)
1616
init(symbol);
1717
}
1818

19+
FiniteAutomata::FiniteAutomata(const FiniteAutomata& _FA)
20+
{
21+
this->nextId = _FA.nextId;
22+
states = _FA.states;
23+
alphabet = _FA.alphabet;
24+
rules = _FA.rules;
25+
startState = _FA.startState;
26+
finalStates = _FA.finalStates;
27+
}
28+
1929
void FiniteAutomata::init(QString symbol)
2030
{
2131
nextId = 0;

RegularConvertor/finite_machine/finiteautomata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class FiniteAutomata //: public QObject
1212
public:
1313
explicit FiniteAutomata();
1414
FiniteAutomata(QString symbol);
15+
FiniteAutomata(const FiniteAutomata& _FA);
1516
void init(QString symbol);
1617
int nextId;
1718
bool isStateUnique(QString state);

RegularConvertor/reg_exp/regexpwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RegExpWidget::RegExpWidget(QWidget *parent) :
1313
modelChanged();
1414
selectionModel = ui->treeView->selectionModel();
1515
connect(ui->regExpTextEdit, SIGNAL(regExpChanged()), this ,SLOT(modelChanged()));
16-
16+
connect(ui->treeView,SIGNAL(clicked(QModelIndex)),this,SIGNAL(itemClicked(QModelIndex)));
1717
treeView = ui->treeView;
1818
}
1919

RegularConvertor/reg_exp/regexpwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class RegExpWidget : public QWidget
2929
void deselectAll();
3030
signals:
3131
void newRegExp(RegExp* re);
32+
void itemClicked(QModelIndex index);
3233

3334
public slots:
3435
void modelChanged();

0 commit comments

Comments
 (0)