Skip to content

Commit 8aaa5fd

Browse files
author
navrkald
committed
Second conversion Remove epsilon FINISHED!!!
* Some functionality moved from RegExpToFA to class of Algorithm. * Add to this conversion functionality of show correct solution and bact to user solution. * Finished EpsilonCloserWidget and it autonomous - check correct epsilon closer automaticaly. * Fully finished RemoveEpsilon and add also 2 examples. * Send sichnal about FA changed also from class Arrow. * Add assign operator to ComputationalRules - without this asighn wasnt always correct. * Repair of "random" generate of nodes in scene - seed for generating nodes is set only once. * When removing last rule with some symbol also remove this symbol in class FiniteAutomata. * Finished notification about changing FA throw many classes. * Cleaned and refactor MainWindow. * Repaired bug when trying qsetToQstring(QSet<QString> set) with empty set in set_of_sets.cpp.
1 parent 9c73647 commit 8aaa5fd

27 files changed

+865
-193
lines changed

RegularConvertor/algorithms/algorithm.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Algorithm::Algorithm(QObject* parent)
44
: QStandardItemModel(parent), actInstructionBackroundColor(Qt::yellow), normalInstructionBackroundColor(Qt::white)
55
{
6+
play_timer = new QTimer();
7+
check_step_timer = new QTimer();
68
}
79

810
void Algorithm::initBreakpoints(int _num)
@@ -17,7 +19,15 @@ void Algorithm::initBreakpoints(int _num)
1719
int Algorithm::setActInstruction()
1820
{
1921
clearActInstruction();
20-
QModelIndex index = this->index(actInstruction,0,QModelIndex());
22+
QModelIndex index;
23+
if(actInstruction != last_instruction)
24+
{
25+
index = this->index(actInstruction,0,QModelIndex());
26+
}
27+
else
28+
{
29+
index = this->index(prewInstruction,0,QModelIndex());
30+
}
2131
setData(index,QBrush(actInstructionBackroundColor),Qt::BackgroundRole);
2232
}
2333

@@ -35,3 +45,13 @@ void Algorithm::getData(QModelIndex _index)
3545
{
3646
breakpoints[_index.row()] = data(_index, Algorithm::Breakpoint_Role).toBool();
3747
}
48+
49+
void Algorithm::runAlgorithm(int mil_sec)
50+
{
51+
play_timer->start(mil_sec);
52+
}
53+
54+
void Algorithm::stop()
55+
{
56+
play_timer->stop();
57+
}

RegularConvertor/algorithms/algorithm.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
#include <QVector>
44
#include <QString>
55
#include <qstandarditemmodel.h>
6+
#include <QTimer>
67

78
#define INDENT "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"
9+
#define CHECK_STEP_TIMEOUT 1000
810

911
class Algorithm : public QStandardItemModel
1012
{
@@ -18,29 +20,30 @@ class Algorithm : public QStandardItemModel
1820

1921
static const int HasBreakpoint_Role = Qt::UserRole;
2022
static const int Breakpoint_Role = Qt::UserRole +1 ;
23+
static const int last_instruction = -1 ;
2124

2225
virtual void initInstructions() = 0;
26+
virtual void removeFuture() = 0;
2327
void initBreakpoints(int _num);
2428

2529

2630
QColor actInstructionBackroundColor;
2731
QColor normalInstructionBackroundColor;
2832

33+
int num;
2934
int instruction_count;
3035
int actInstruction;
3136
int prewInstruction;
37+
int actPos;
3238
int setActInstruction();
3339
int clearActInstruction();
3440
public slots:
3541
void getData(QModelIndex _index);
36-
//signals:
37-
// instructionChanged(int _instruction);
38-
// struct steps
39-
// {
40-
// QString formal_text;
41-
// QString informal_text;
42-
// int pos;
43-
// };
42+
void runAlgorithm(int mil_sec);
43+
void stop();
44+
protected:
45+
QTimer *play_timer;
46+
QTimer *check_step_timer;
4447
};
4548

4649
#endif // ALGORITHM_H

RegularConvertor/algorithms/algorithmwidget.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,44 @@ void AlgorithmWidget::setWidgets(Algorithm::modes mode)
7373
}
7474
}
7575

76+
void AlgorithmWidget::disableNext()
77+
{
78+
ui->nextButton->setEnabled(false);
79+
}
80+
81+
void AlgorithmWidget::enableNext()
82+
{
83+
ui->nextButton->setEnabled(true);
84+
}
85+
86+
void AlgorithmWidget::enablePrev()
87+
{
88+
ui->prewButton->setEnabled(true);
89+
}
90+
91+
void AlgorithmWidget::disablePrev()
92+
{
93+
ui->prewButton->setEnabled(false);
94+
}
95+
7696
void AlgorithmWidget::hideSpacer(QSpacerItem *s)
7797
{
7898
s->changeSize(0,0, QSizePolicy::Fixed, QSizePolicy::Fixed);
7999
}
80100

81101
void AlgorithmWidget::showSpacer(QSpacerItem *s)
82102
{
83-
s->changeSize(1,1, QSizePolicy::Expanding, QSizePolicy::Fixed);
103+
s->changeSize(1,1, QSizePolicy::Expanding, QSizePolicy::Fixed);
104+
}
105+
106+
void AlgorithmWidget::enableShowButton()
107+
{
108+
ui->showButton->setEnabled(true);
109+
}
110+
111+
void AlgorithmWidget::disableShowButton()
112+
{
113+
ui->showButton->setEnabled(false);
84114
}
85115

86116
void AlgorithmWidget::emitPlay()
@@ -94,11 +124,11 @@ void AlgorithmWidget::on_showButton_clicked()
94124
if(showSolution)
95125
{
96126
ui->showButton->setText("Show solution");
97-
emit showCorrectSolutionPressed();
127+
emit showUserSolutionPressed();
98128
}
99129
else
100130
{
101131
ui->showButton->setText("Back");
102-
emit showUserSolutionPressed();
132+
emit showCorrectSolutionPressed();
103133
}
104134
}

RegularConvertor/algorithms/algorithmwidget.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class AlgorithmWidget : public QWidget
2525

2626
void hideSpacer(QSpacerItem * s);
2727
void showSpacer(QSpacerItem * s);
28+
void enableShowButton();
29+
void disableShowButton();
2830

2931
bool showSolution;
3032

@@ -41,6 +43,11 @@ class AlgorithmWidget : public QWidget
4143
public slots:
4244
void emitPlay();
4345
void setWidgets(Algorithm::modes mode);
46+
void disableNext();
47+
void enableNext();
48+
void disablePrev();
49+
void enablePrev();
50+
4451

4552

4653
private slots:
Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
11
#include "algorithms/epsiloncloserwidget.h"
22

3-
EpsilonCloserWidget::EpsilonCloserWidget(QString _state, QList<QString> _epsilon_closer_list, QWidget *parent):
4-
QWidget(parent), state(_state), epsilon_closer_list(_epsilon_closer_list)
3+
EpsilonCloserWidget::EpsilonCloserWidget(QString _state, QList<QString> _user_epsilon_closer_list, QList<QString> _correct_epsilon_closer_list, QWidget *parent):
4+
QWidget(parent), state(_state), user_epsilon_closer_list(_user_epsilon_closer_list), correct_epsilon_closer_list(_correct_epsilon_closer_list)
55
{
6-
QLabel* label1 = new QLabel("ɜ-uzávěr(" + state + ") = {",this);
7-
QLabel* label2 = new QLabel("}", this);
8-
QTextEdit* text_edit = new QTextEdit(state,this);
9-
//unknown_icon.addFile(":/algorithms/algorithms/pictures/unknown.png");
10-
correct_icon.addFile(":/algorithms/algorithms/pictures/ok.png");
11-
wrong_icon.addFile(":/algorithms/algorithms/pictures/wrong.png");
12-
icon = unknown_icon;
6+
label1 = new QLabel("ɜ-uzávěr(<b>" + state + "</b>) = {",this);
7+
label2 = new QLabel("}", this);
8+
line_edit = new QLineEdit(user_epsilon_closer_list.join(", "),this);
9+
line_edit->show();
10+
unknown = QPixmap(":/algorithms/algorithms/pictures/unknown.png");
11+
correct = QPixmap(":/algorithms/algorithms/pictures/ok.png");
12+
wrong = QPixmap(":/algorithms/algorithms/pictures/wrong.png");
1313
layout = new QHBoxLayout(this);
1414
layout->addWidget(label1);
15-
layout->addWidget(text_edit);
15+
layout->addWidget(line_edit);
1616
layout->addWidget(label2);
17-
QPixmap* map = new QPixmap(":/algorithms/algorithms/pictures/unknown.png");
18-
QLabel* label = new QLabel(this);
19-
label->setPixmap(*map);
20-
layout->addWidget(label);
21-
//layout->add;
17+
label3 = new QLabel(this);
18+
label3->setPixmap(unknown.scaledToHeight(iconHeight));
19+
layout->addWidget(label3);
20+
21+
connect(line_edit,SIGNAL(textEdited(QString)),this,SLOT(statesEdited(QString)));
22+
}
23+
24+
void EpsilonCloserWidget::setCorrectness(bool correct)
25+
{
26+
if(correct)
27+
{
28+
label3->setPixmap(this->correct.scaledToHeight(iconHeight));
29+
}
30+
else
31+
{
32+
label3->setPixmap(this->wrong.scaledToHeight(iconHeight));
33+
}
2234
}
2335

24-
void EpsilonCloserWidget::setIsCorrect(bool correct)
36+
void EpsilonCloserWidget::setCompleter(MultiSelectCompleter *_completer)
2537
{
38+
completer = _completer;
39+
line_edit->setCompleter(completer);
40+
}
2641

42+
void EpsilonCloserWidget::statesEdited(QString s)
43+
{
44+
user_epsilon_closer_list = FA_widget::getSortedUniqueList(s);
45+
if(user_epsilon_closer_list.empty())
46+
label3->setPixmap(unknown.scaledToHeight(iconHeight));
47+
else
48+
setCorrectness(user_epsilon_closer_list == correct_epsilon_closer_list);
2749
}

RegularConvertor/algorithms/epsiloncloserwidget.h

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,43 @@
33

44
#include <QWidget>
55
#include <QtWidgets>
6+
#include <set/set_of_sets.h>
7+
#include "finite_machine/multiselectcompleter.h"
8+
#include "finite_machine/fa_widget.h"
9+
610
class EpsilonCloserWidget : public QWidget
711
{
812
Q_OBJECT
913
public:
10-
explicit EpsilonCloserWidget(QString _state, QList<QString> _epsilon_closer_list, QWidget *parent = 0);
11-
void setIsCorrect(bool correct);
14+
explicit EpsilonCloserWidget(QString _state, QList<QString> _user_epsilon_closer_list, QList<QString> _correct_epsilon_closer_list, QWidget *parent = 0);
15+
1216
QString state;
13-
QList<QString> epsilon_closer_list;
17+
QStringList user_epsilon_closer_list;
18+
QStringList correct_epsilon_closer_list;
1419
QLabel* label1;
1520
QLabel* label2;
16-
QTextEdit* text_edit;
17-
QIcon icon;
18-
QIcon unknown_icon;
19-
QIcon correct_icon;
20-
QIcon wrong_icon;
21+
QLabel* label3;
22+
QLineEdit* line_edit;
23+
QPixmap unknown;
24+
QPixmap correct;
25+
QPixmap wrong;
2126
QHBoxLayout* layout;
27+
const static int iconHeight = 20;
28+
MultiSelectCompleter* completer;
29+
QStringList states;
30+
31+
// Setters
32+
void setCompleter(MultiSelectCompleter* _completer);
33+
void setCorrectness(bool correct);
34+
35+
// Getters
36+
inline QList<QString> getCloser(){return user_epsilon_closer_list;}
37+
inline QString getState(){return state;}
38+
2239
signals:
2340

2441
public slots:
25-
42+
void statesEdited(QString s);
2643
};
2744

2845
#endif // EPSILONCLOSERWIDGET_H

RegularConvertor/algorithms/regexptofa.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,25 @@ RegExpToFA::RegExpToFA(AlgorithmWidget* _algorithm_widget, modes _mode, RegExpWi
7171
break;
7272
}
7373
}
74-
75-
76-
77-
play_timer = new QTimer();
78-
check_step_timer = new QTimer();
7974
setMode(mode, re);
80-
//
81-
// Connect timers.
82-
//
83-
connect(play_timer, SIGNAL(timeout()), this, SLOT(nextStep()));
84-
connect(check_step_timer, SIGNAL(timeout()), this, SLOT(checkSolution()));
85-
8675

8776
//
8877
// Connect algorithm buttons.
8978
//
9079
connect(this->algorithm_widget,SIGNAL(playPressed(int)),this,SLOT(runAlgorithm(int)));
9180
connect(this->algorithm_widget,SIGNAL(stopPressed()),this,SLOT(stop()));
92-
connect(this->algorithm_widget,SIGNAL(prewPressed()),this,SLOT(prewStep()));
81+
connect(this->algorithm_widget,SIGNAL(prewPressed()),this,SLOT(prevStep()));
9382
connect(this->algorithm_widget,SIGNAL(nextPressed()),this,SLOT(nextStep()));
9483
connect(this->algorithm_widget, SIGNAL(checkSolutionPressed()), this, SLOT(checkSolution()));
9584
connect(this->algorithm_widget, SIGNAL(showCorrectSolutionPressed()), this, SLOT(showCorrectSolution()));
9685
connect(this->algorithm_widget, SIGNAL(showUserSolutionPressed()), this, SLOT(showUserSolution()));
9786

87+
//
88+
// Connect timers.
89+
//
90+
connect(play_timer, SIGNAL(timeout()), this, SLOT(nextStep()));
91+
connect(check_step_timer, SIGNAL(timeout()), this, SLOT(checkSolution()));
92+
9893
//
9994
// Connect regexp widget
10095
//
@@ -103,6 +98,9 @@ RegExpToFA::RegExpToFA(AlgorithmWidget* _algorithm_widget, modes _mode, RegExpWi
10398

10499
re_widget->setRegExp(_re);
105100
re_widget->modelChanged();
101+
102+
// because not implemented
103+
algorithm_widget->disableShowButton();
106104
}
107105

108106
void RegExpToFA::setMode(modes _mode, RegExp* _re)
@@ -283,10 +281,10 @@ void RegExpToFA::computeSolution()
283281
}
284282
}
285283

286-
void RegExpToFA::runAlgorithm(int mil_sec)
287-
{
288-
play_timer->start(mil_sec);
289-
}
284+
//void RegExpToFA::runAlgorithm(int mil_sec)
285+
//{
286+
// play_timer->start(mil_sec);
287+
//}
290288

291289
void RegExpToFA::nextStep()
292290
{
@@ -388,7 +386,7 @@ void RegExpToFA::nextStep()
388386
}
389387
}
390388

391-
void RegExpToFA::prewStep()
389+
void RegExpToFA::prevStep()
392390
{
393391
if (actPos > 0)
394392
{
@@ -413,10 +411,10 @@ void RegExpToFA::removeFuture()
413411
}
414412

415413

416-
void RegExpToFA::stop()
417-
{
418-
play_timer->stop();
419-
}
414+
//void RegExpToFA::stop()
415+
//{
416+
// play_timer->stop();
417+
//}
420418

421419
//void RegExpToFA::getData(QModelIndex _index)
422420
//{

0 commit comments

Comments
 (0)