TAB BEGIN void MainWindow tab4_read_polinom QRegExp rx 0-9 0-9 0-9 0-9

 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
// ************ TAB 4 BEGIN *******************
void MainWindow::tab4_read_polinom()
{
QRegExp rx("([-+]?)([0-9]*)\\*?([x])?\\^?([0-9])?\\*?([y])?\\^?([0-9])?\\*?([z])?\\^?([0-9])?");
//QRegExp rx("([-+]?)((?:[0-9]*))\\*?([a-z]?)\\^?((?:[0-9]*))");
QString str = ui.lineEdit->text();
QString sym, coef, var, exp;
int pos = 0;
P.clear();
while ( pos < str.length() -1 )
{
rx.indexIn(str,pos);
pos += rx.matchedLength();
sym = rx.cap(1);
int coef = rx.cap(2).toInt(0,0);
int x,y,z;
z=0; y=0; x=0;
if (rx.cap(3)=="x")
{
x = rx.cap(4).toInt(0,0);
}
if (rx.cap(5)=="y")
{
y = rx.cap(6).toInt(0,0);
}
if (rx.cap(7)=="z")
{
z = rx.cap(8).toInt(0,0);
}
if ((coef==0) && ( (x!=0) || (y!=0) || (z!=0) ) )
{
if (coef == 0)
{
coef=1;
}
}
if (sym == "-")
{
P.put(-1*coef,x,y,z);
}
else
{
P.put(coef,x,y,z);
}
}
}
void MainWindow::tab4_simplify()
{
tab4_read_polinom();
P.simplify();
QString s = P.get();
ui.lineEdit->setText(s);
}
void MainWindow::tab4_clear()
{
P.clear();
ui.lineEdit->clear();
}
void MainWindow::tab4_save()
{
tab4_read_polinom();
QString fname = QFileDialog::getSaveFileName(this,"",QString::null,QString::null);
if (fname.length()>0) P.save_to_file(fname.toUtf8().data());
}
void MainWindow::tab4_load()
{
QString fname = QFileDialog::getOpenFileName(this,"",QString::null,QString::null);
if (fname.length()>0)
{
P.read_from_file(fname.toUtf8().data());
QString s = P.get();
ui.lineEdit->setText(s);
}
}
// ************ TAB 4 END *******************