Skip to content

Commit 101ef3f

Browse files
navrkaldnavrkald
authored andcommitted
Many changes, need to rewrite this comment.
* repaired minimalization algorithm * re -> fa is broken dont now why. Unit tests failing on this conversion... Need to investigate.
1 parent e0826f2 commit 101ef3f

39 files changed

+996
-250
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/build-RegularConvertorUnitTests-Desktop_Qt_5_0_2_GCC_64bit-Debug/
77
/build-RegularConvertor-Desktop_qt52-Debug/
88
/build-RegularConvertorUnitTests-Desktop_qt52-Debug/
9+
/build-RegularConvertorUnitTests-Desktop_Qt_5_2_1_GCC_64bit_qt_521-Debug/
910

1011
# User build settings #
1112
#######################
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
#include "algorithm.h"
22

33
Algorithm::Algorithm()
4+
: actInstructionBackroundColor(Qt::yellow), normalInstructionBackroundColor(Qt::white)
45
{
56
}
7+
8+
void Algorithm::initBreakpoints(int _num)
9+
{
10+
breakpoints.resize(_num);
11+
foreach(bool breakpoint,breakpoints)
12+
{
13+
breakpoint = false;
14+
}
15+
}
16+
17+
int Algorithm::setActInstruction()
18+
{
19+
clearActInstruction();
20+
QModelIndex index = this->index(actInstruction,0,QModelIndex());
21+
setData(index,QBrush(actInstructionBackroundColor),Qt::BackgroundRole);
22+
}
23+
24+
int Algorithm::clearActInstruction()
25+
{
26+
for(int i = 0; i<instruction_count; i++)
27+
{
28+
QModelIndex index = this->index(i,0,QModelIndex());
29+
setData(index,QBrush(normalInstructionBackroundColor),Qt::BackgroundRole);
30+
}
31+
}

RegularConvertor/algorithms/algorithm.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,26 @@ class Algorithm : public QStandardItemModel
1111
Algorithm();
1212
//TODO add bool if brakepoint is set for some step
1313
QVector <QString> instructions;
14+
QVector <bool> breakpoints;
1415
enum modes {CHECK_MODE, PLAY_MODE, STEP_MODE};
1516

16-
static const int HasBrakepoint_Role = Qt::UserRole;
17-
static const int Brakepoint_Role = Qt::UserRole +1 ;
17+
static const int HasBreakpoint_Role = Qt::UserRole;
18+
static const int Breakpoint_Role = Qt::UserRole +1 ;
1819

20+
virtual void initInstructions() = 0;
21+
void initBreakpoints(int _num);
22+
23+
24+
QColor actInstructionBackroundColor;
25+
QColor normalInstructionBackroundColor;
26+
27+
int instruction_count;
28+
int actInstruction;
29+
int prewInstruction;
30+
int setActInstruction();
31+
int clearActInstruction();
32+
//signals:
33+
// instructionChanged(int _instruction);
1934
// struct steps
2035
// {
2136
// QString formal_text;

RegularConvertor/algorithms/algorithmwidget.cpp

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
#include "algorithmwidget.h"
22
#include "ui_algorithmwidget.h"
33

4-
AlgorithmWidget::AlgorithmWidget(QWidget *parent) :
5-
QWidget(parent),
4+
AlgorithmWidget::AlgorithmWidget(Algorithm::modes _mode, QWidget *parent) :
5+
QWidget(parent), mode(_mode),
66
ui(new Ui::AlgorithmWidget)
77
{
88
ui->setupUi(this);
9+
10+
showSolution = false;
11+
912
connect(this->ui->nextButton,SIGNAL(clicked()),this,SIGNAL(nextPressed()));
1013
connect(this->ui->prewButton,SIGNAL(clicked()),this,SIGNAL(prewPressed()));
1114
connect(this->ui->playButton,SIGNAL(clicked()),this,SLOT(emitPlay()));
1215
connect(this->ui->stopButton,SIGNAL(clicked()),this,SIGNAL(stopPressed()));
16+
connect(this->ui->checkButton,SIGNAL(clicked()),this,SIGNAL(checkSolutionPressed()));
17+
setWidgets(mode);
1318
}
1419

1520
AlgorithmWidget::~AlgorithmWidget()
@@ -22,7 +27,78 @@ AlgorithmView *AlgorithmWidget::getAlgorithmView()
2227
return ui->treeView;
2328
}
2429

30+
31+
32+
void AlgorithmWidget::hideWidgets(QList<QWidget *> widgets)
33+
{
34+
foreach(QWidget* w,widgets)
35+
w->hide();
36+
}
37+
38+
void AlgorithmWidget::showWidgets(QList<QWidget *> widgets)
39+
{
40+
foreach(QWidget* w,widgets)
41+
w->show();
42+
}
43+
44+
void AlgorithmWidget::setWidgets(Algorithm::modes mode)
45+
{
46+
switch (mode) {
47+
case Algorithm::CHECK_MODE:
48+
showWidgets(QList<QWidget*>() << ui->checkButton << ui->showButton);
49+
showSpacer(ui->checkSpacer);
50+
hideWidgets(QList<QWidget*>()
51+
<< ui->prewButton << ui->nextButton << ui->playButton << ui->stopButton << ui->spinBox << ui->delay_label
52+
<< ui->prew_stepButton << ui->next_stepButton );
53+
hideSpacer(ui->stepSpacer);
54+
break;
55+
case Algorithm::PLAY_MODE:
56+
showWidgets(QList<QWidget*>() << ui->prewButton << ui->nextButton << ui->playButton << ui->stopButton << ui->spinBox << ui->delay_label);
57+
hideWidgets(QList<QWidget*>()
58+
<< ui->checkButton << ui->showButton
59+
<< ui->prew_stepButton << ui->next_stepButton );
60+
hideSpacer(ui->stepSpacer);
61+
hideSpacer(ui->checkSpacer);
62+
break;
63+
case Algorithm::STEP_MODE:
64+
showWidgets(QList<QWidget*>()<< ui->prew_stepButton << ui->next_stepButton);
65+
hideWidgets(QList<QWidget*>()
66+
<< ui->checkButton << ui->showButton
67+
<< ui->prewButton << ui->nextButton << ui->playButton << ui->stopButton << ui->spinBox << ui->delay_label);
68+
showSpacer(ui->stepSpacer);
69+
hideSpacer(ui->checkSpacer);
70+
break;
71+
default:
72+
break;
73+
}
74+
}
75+
76+
void AlgorithmWidget::hideSpacer(QSpacerItem *s)
77+
{
78+
s->changeSize(0,0, QSizePolicy::Fixed, QSizePolicy::Fixed);
79+
}
80+
81+
void AlgorithmWidget::showSpacer(QSpacerItem *s)
82+
{
83+
s->changeSize(1,1, QSizePolicy::Expanding, QSizePolicy::Fixed);
84+
}
85+
2586
void AlgorithmWidget::emitPlay()
2687
{
2788
emit playPressed(this->ui->spinBox->value());
2889
}
90+
91+
void AlgorithmWidget::on_showButton_clicked()
92+
{
93+
showSolution=!showSolution;
94+
if(showSolution)
95+
{
96+
ui->showButton->setText("Show solution.");
97+
emit showCorrectSolutionPressed();
98+
}
99+
else
100+
{
101+
ui->showButton->setText("Back.");
102+
emit showUserSolutionPressed();
103+
}
104+
}

RegularConvertor/algorithms/algorithmwidget.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <QWidget>
55
#include "algorithmview.h"
6+
#include "algorithm.h"
7+
#include <QSpacerItem>
68

79
namespace Ui {
810
class AlgorithmWidget;
@@ -13,17 +15,36 @@ class AlgorithmWidget : public QWidget
1315
Q_OBJECT
1416

1517
public:
16-
explicit AlgorithmWidget(QWidget *parent = 0);
18+
explicit AlgorithmWidget(Algorithm::modes _mode, QWidget *parent = 0);
1719
~AlgorithmWidget();
1820
AlgorithmView* getAlgorithmView();
21+
Algorithm::modes mode;
22+
23+
void hideWidgets(QList<QWidget*> widgets);
24+
void showWidgets(QList<QWidget*> widgets);
25+
26+
void hideSpacer(QSpacerItem * s);
27+
void showSpacer(QSpacerItem * s);
28+
29+
bool showSolution;
30+
1931
signals:
2032
void nextPressed();
2133
void prewPressed();
2234
void playPressed(int mil_sec);
2335
void stopPressed();
36+
void checkSolutionPressed();
37+
void showCorrectSolutionPressed();
38+
void showUserSolutionPressed();
39+
2440

2541
public slots:
2642
void emitPlay();
43+
void setWidgets(Algorithm::modes mode);
44+
45+
46+
private slots:
47+
void on_showButton_clicked();
2748

2849
private:
2950
Ui::AlgorithmWidget *ui;

0 commit comments

Comments
 (0)