@@ -33,6 +33,12 @@ FA_widget::FA_widget(QWidget *parent) :
33
33
34
34
// set init checked to AddNodeBut
35
35
AddNodeBut->setChecked (true );
36
+ // MoveNodeBut->setChecked(true);
37
+
38
+ MoveNodeBut->setToolTip (tr (" If this button is activated, you can select and move with items in scene." ));
39
+ AddNodeBut->setToolTip (tr (" If this button is activated, left mouse click into screene creates new node." ));
40
+ AddArrowBut->setToolTip (tr (" If this button is activated, you can create transition between nodes. <br>(Click on from item, hold mouse left button and release on arrow target.)" ));
41
+ DeleteNodeBut->setToolTip (tr (" Click on this button deletes all selected items. <br>(You can select multiple items when holding control button.)" ));
36
42
37
43
// adjust size of button according text in
38
44
// MoveNodeBut->setMaximumWidth(MoveNodeBut->fontMetrics().boundingRect(MoveNodeBut->text()).width()+15);
@@ -57,7 +63,8 @@ FA_widget::FA_widget(QWidget *parent) :
57
63
// notify changes in formal view
58
64
connect (this ->ui ->statesLineEdit ,SIGNAL (editingFinished ()),this ,SLOT (statesEdited ()));
59
65
connect (this ->ui ->endingStatesLineEdit ,SIGNAL (editingFinished ()),this ,SLOT (endingStatesEdited ()));
60
- connect (this ->ui ->alphabetLineEdit ,SIGNAL (editingFinished ()),this ,SLOT (alphaberEdited ()));
66
+ connect (this ->ui ->alphabetLineEdit ,SIGNAL (editingFinished ()),this ,SLOT (alphabetEdited ()));
67
+ connect (this ->ui ->alphabetLineEdit ,SIGNAL (textEdited (QString)),this ,SLOT (alphabetEdited ()));
61
68
62
69
// add items to scene
63
70
connect (this ,SIGNAL (addNodes (QSet<QString>)),this ->scene ,SLOT (addNodes (QSet<QString>)));
@@ -111,7 +118,7 @@ void FA_widget::setupValidators()
111
118
{
112
119
QRegExp listOfIdentifiers (" ^(\\ w+(,\\ s*\\ w+)*,?)?$" );
113
120
// hint [^,] mean what ever char not ','
114
- QRegExp listOfSymbols (" ^\\ S(,\\ s*\\ S)*$" );
121
+ QRegExp listOfSymbols (" ^( \\ S(,\\ s*\\ S)*)? $" );
115
122
QRegExp emptyRegExp (" ^$" );
116
123
statesValidator = new QRegExpValidator (listOfIdentifiers, this );
117
124
alphabetValidator = new QRegExpValidator (listOfSymbols, this );
@@ -184,7 +191,9 @@ void FA_widget::statesEdited()
184
191
if (ui->statesLineEdit ->text () == " " )
185
192
{
186
193
emit removeNodes (FA->states );
187
- FA->states .clear ();
194
+ FA->removeStates (FA->states );
195
+ // FA->states.clear();
196
+
188
197
emit FA_changed (FA);
189
198
return ;
190
199
}
@@ -194,19 +203,34 @@ void FA_widget::statesEdited()
194
203
QSet <QString> setOfStatesLineEdit = unique_list_of_states.toSet ();
195
204
QSet <QString> statesToDel = FA->states - setOfStatesLineEdit;
196
205
QSet <QString> statesToAdd = setOfStatesLineEdit - FA->states ;
197
- FA->states =setOfStatesLineEdit;
206
+ FA->removeStates (statesToDel);
207
+ foreach (QString state_to_add, statesToAdd)
208
+ FA->addState (state_to_add);
198
209
if (!statesToDel.empty ())
199
210
{
200
- emit FA_changed (FA);
211
+ // remove nodes emits in scene FA_changed()
201
212
emit removeNodes (statesToDel);
213
+
214
+ // this block of code removes rules in formal view that consist of
215
+ foreach (QString state_to_del,statesToDel)
216
+ {
217
+ QList<QListWidgetItem *> items_to_dell = ui->rulesListWidget ->findItems (state_to_del+" " ,Qt::MatchStartsWith);
218
+ items_to_dell.append (ui->rulesListWidget ->findItems (" " +state_to_del,Qt::MatchEndsWith));
219
+ foreach (QListWidgetItem* item,items_to_dell.toSet ())
220
+ {
221
+ ui->rulesListWidget ->takeItem (ui->rulesListWidget ->row (item));
222
+ delete item;
223
+ }
224
+ }
225
+
202
226
}
203
227
if (!statesToAdd.empty ())
204
228
{
205
229
emit addNodes (statesToAdd);
206
230
emit FA_changed (FA);
207
231
}
208
232
updateStates ();
209
- emit FA_changed (FA);
233
+ // not needed emit FA_changed(FA)(emit only if there is some changes (add or nemove nodes) );
210
234
}
211
235
212
236
void FA_widget::endingStatesEdited ()
@@ -220,29 +244,57 @@ void FA_widget::endingStatesEdited()
220
244
QSet <QString> endingStatesToAdd = setOfEndigStates - FA->finalStates ;
221
245
FA->finalStates = setOfEndigStates;
222
246
if (!endingStatesToDel.empty ())
247
+ {
223
248
emit removeEndingNodes (endingStatesToDel);
249
+ // FA changed is emited in node
250
+ }
224
251
if (!endingStatesToAdd.empty ())
252
+ {
225
253
emit addEndingNodes (endingStatesToAdd);
226
-
227
- emit FA_changed (FA);
254
+ // FA changed is emited in node
255
+ }
228
256
}
229
257
230
- void FA_widget::alphaberEdited ()
258
+ void FA_widget::alphabetEdited ()
231
259
{
232
- QStringList SortedUniqueList = getSortedUniqueList (ui->alphabetLineEdit ->text ());
233
- ui->alphabetLineEdit ->setText (SortedUniqueList.join (" , " ));
260
+ QString text = ui->alphabetLineEdit ->text ();
261
+ int pos = 0 ;
262
+ if (alphabetValidator->validate (text, pos) == QValidator::Acceptable)
263
+ {
264
+ QStringList SortedUniqueList = getSortedUniqueList (ui->alphabetLineEdit ->text ());
265
+ ui->alphabetLineEdit ->setText (SortedUniqueList.join (" , " ));
234
266
235
267
236
- QSet <QString> setOfAlphabet = SortedUniqueList.toSet ();
237
- QSet <QString> symbolsToDel = FA->alphabet - setOfAlphabet;
238
- QSet <QString> symbolsToAdd = setOfAlphabet - FA->alphabet ;
239
- FA->alphabet = SortedUniqueList.toSet ();
240
- if (!symbolsToDel.empty ())
241
- emit removeSymbols (symbolsToDel);
242
- if (!symbolsToAdd.empty ())
243
- emit addSymbols (symbolsToAdd);
268
+ QSet <QString> setOfAlphabet = SortedUniqueList.toSet ();
269
+ QSet <QString> symbolsToDel = FA->alphabet - setOfAlphabet;
270
+ QSet <QString> symbolsToAdd = setOfAlphabet - FA->alphabet ;
271
+ if (!symbolsToDel.empty ())
272
+ {
273
+ foreach (QString symbol, symbolsToDel)
274
+ {
275
+ // This block of code removes rules from formal view where delete symbols appears
276
+ // QList<QListWidgetItem *> items_to_dell = ui->rulesListWidget->findItems(" "+symbol+" ->",Qt::MatchContains);
277
+ QList<QListWidgetItem *> items_to_dell = ui->rulesListWidget ->findItems (" ^\\ S+ " +symbol+" -> \\ S+$" ,Qt::MatchRegExp);
278
+ foreach (QListWidgetItem* item,items_to_dell.toSet ())
279
+ {
280
+ ui->rulesListWidget ->takeItem (ui->rulesListWidget ->row (item));
281
+ delete item;
282
+ }
283
+ emit removeEdges (FA->findRule_Symbol (symbol).toSet ());
284
+ FA->removeSymbol (symbol);
285
+ }
286
+ emit FA_changed (FA);
287
+ }
244
288
245
- emit FA_changed (FA);
289
+ if (!symbolsToAdd.empty ())
290
+ {
291
+ foreach (QString symbol, symbolsToAdd)
292
+ {
293
+ FA->addSymbol (symbol);
294
+ }
295
+ emit FA_changed (FA);
296
+ }
297
+ }
246
298
// TODO! osetrit kdyz se vyskytuji symboly abecedy v prechodech
247
299
}
248
300
@@ -268,7 +320,8 @@ void FA_widget::updateStates()
268
320
QStringList items_string_list = items;
269
321
QString awailableStates = " (" + items_string_list.join ( " |" ) + " )" ;
270
322
endingStatesValidator->setRegExp (QRegExp (" ^" + awailableStates + " +(,\\ s*" + awailableStates + " )*,?$" )); // RegExp: ^\\w+(,\\s*\\w+)*,?$
271
- // TODO! osetrit kdyz se smaze uzel ktery se vyskytuje v prechodech
323
+ QStringList endingStates = FA->finalStates .toList ();
324
+ ui->endingStatesLineEdit ->setText (endingStates.join (" , " ));
272
325
}
273
326
274
327
void FA_widget::emitAddEdge (ComputationalRules rule)
@@ -289,6 +342,9 @@ void FA_widget::emitAddEndingNode(QString node)
289
342
void FA_widget::on_startStateComboBox_activated (const QString &arg1)
290
343
{
291
344
statesEdited (); // zavolame explicitne protoze "strati fokus, tak aby to fungovalo"
345
+ // because prew function erase selected item in gui
346
+ int index = ui->startStateComboBox ->findText (arg1);
347
+ ui->startStateComboBox ->setCurrentIndex (index);
292
348
if (arg1 != " " )
293
349
{
294
350
FA->startState = QString (arg1);
@@ -304,7 +360,7 @@ void FA_widget::on_addRuleToolButton_clicked()
304
360
{
305
361
// updatovani stavu a abecedy (zavolame explicitne protoze "nestrati fokus, tak aby to fungovalo")
306
362
statesEdited ();
307
- alphaberEdited ();
363
+ alphabetEdited ();
308
364
309
365
if (FA->states .isEmpty ())
310
366
{
@@ -349,7 +405,7 @@ void FA_widget::on_removeRuleToolButton_clicked()
349
405
{
350
406
// updatovani stavu a abecedy (zavolame explicitne protoze "nestrati fokus, tak aby to fungovalo")
351
407
statesEdited ();
352
- alphaberEdited ();
408
+ alphabetEdited ();
353
409
354
410
QList<QListWidgetItem *> items = ui->rulesListWidget ->selectedItems ();
355
411
@@ -371,7 +427,7 @@ void FA_widget::on_rulesListWidget_itemDoubleClicked(QListWidgetItem *item)
371
427
{
372
428
// updatovani stavu a abecedy (zavolame explicitne protoze "nestrati fokus, tak aby to fungovalo")
373
429
statesEdited ();
374
- alphaberEdited ();
430
+ alphabetEdited ();
375
431
376
432
ComputationalRules oldrule (item->text ());
377
433
@@ -435,7 +491,7 @@ void FA_widget::on_tabWidget_currentChanged(int index)
435
491
ui->endingStatesLineEdit ->setText (endingStates.join (" , " ));
436
492
437
493
}
438
- emit FA_changed (FA);
494
+ // not needed emit, we set only old data from FA graphic - emit FA_changed(FA);
439
495
}
440
496
441
497
// vymaze selected items
0 commit comments