@@ -33,6 +33,12 @@ FA_widget::FA_widget(QWidget *parent) :
3333
3434 // set init checked to AddNodeBut
3535 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.)" ));
3642
3743 // adjust size of button according text in
3844// MoveNodeBut->setMaximumWidth(MoveNodeBut->fontMetrics().boundingRect(MoveNodeBut->text()).width()+15);
@@ -57,7 +63,8 @@ FA_widget::FA_widget(QWidget *parent) :
5763 // notify changes in formal view
5864 connect (this ->ui ->statesLineEdit ,SIGNAL (editingFinished ()),this ,SLOT (statesEdited ()));
5965 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 ()));
6168
6269 // add items to scene
6370 connect (this ,SIGNAL (addNodes (QSet<QString>)),this ->scene ,SLOT (addNodes (QSet<QString>)));
@@ -111,7 +118,7 @@ void FA_widget::setupValidators()
111118{
112119 QRegExp listOfIdentifiers (" ^(\\ w+(,\\ s*\\ w+)*,?)?$" );
113120 // hint [^,] mean what ever char not ','
114- QRegExp listOfSymbols (" ^\\ S(,\\ s*\\ S)*$" );
121+ QRegExp listOfSymbols (" ^( \\ S(,\\ s*\\ S)*)? $" );
115122 QRegExp emptyRegExp (" ^$" );
116123 statesValidator = new QRegExpValidator (listOfIdentifiers, this );
117124 alphabetValidator = new QRegExpValidator (listOfSymbols, this );
@@ -184,7 +191,9 @@ void FA_widget::statesEdited()
184191 if (ui->statesLineEdit ->text () == " " )
185192 {
186193 emit removeNodes (FA->states );
187- FA->states .clear ();
194+ FA->removeStates (FA->states );
195+ // FA->states.clear();
196+
188197 emit FA_changed (FA);
189198 return ;
190199 }
@@ -194,19 +203,34 @@ void FA_widget::statesEdited()
194203 QSet <QString> setOfStatesLineEdit = unique_list_of_states.toSet ();
195204 QSet <QString> statesToDel = FA->states - setOfStatesLineEdit;
196205 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);
198209 if (!statesToDel.empty ())
199210 {
200- emit FA_changed (FA);
211+ // remove nodes emits in scene FA_changed()
201212 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+
202226 }
203227 if (!statesToAdd.empty ())
204228 {
205229 emit addNodes (statesToAdd);
206230 emit FA_changed (FA);
207231 }
208232 updateStates ();
209- emit FA_changed (FA);
233+ // not needed emit FA_changed(FA)(emit only if there is some changes (add or nemove nodes) );
210234}
211235
212236void FA_widget::endingStatesEdited ()
@@ -220,29 +244,57 @@ void FA_widget::endingStatesEdited()
220244 QSet <QString> endingStatesToAdd = setOfEndigStates - FA->finalStates ;
221245 FA->finalStates = setOfEndigStates;
222246 if (!endingStatesToDel.empty ())
247+ {
223248 emit removeEndingNodes (endingStatesToDel);
249+ // FA changed is emited in node
250+ }
224251 if (!endingStatesToAdd.empty ())
252+ {
225253 emit addEndingNodes (endingStatesToAdd);
226-
227- emit FA_changed (FA);
254+ // FA changed is emited in node
255+ }
228256}
229257
230- void FA_widget::alphaberEdited ()
258+ void FA_widget::alphabetEdited ()
231259{
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 (" , " ));
234266
235267
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+ }
244288
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+ }
246298 // TODO! osetrit kdyz se vyskytuji symboly abecedy v prechodech
247299}
248300
@@ -268,7 +320,8 @@ void FA_widget::updateStates()
268320 QStringList items_string_list = items;
269321 QString awailableStates = " (" + items_string_list.join ( " |" ) + " )" ;
270322 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 (" , " ));
272325}
273326
274327void FA_widget::emitAddEdge (ComputationalRules rule)
@@ -289,6 +342,9 @@ void FA_widget::emitAddEndingNode(QString node)
289342void FA_widget::on_startStateComboBox_activated (const QString &arg1)
290343{
291344 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);
292348 if (arg1 != " " )
293349 {
294350 FA->startState = QString (arg1);
@@ -304,7 +360,7 @@ void FA_widget::on_addRuleToolButton_clicked()
304360{
305361 // updatovani stavu a abecedy (zavolame explicitne protoze "nestrati fokus, tak aby to fungovalo")
306362 statesEdited ();
307- alphaberEdited ();
363+ alphabetEdited ();
308364
309365 if (FA->states .isEmpty ())
310366 {
@@ -349,7 +405,7 @@ void FA_widget::on_removeRuleToolButton_clicked()
349405{
350406 // updatovani stavu a abecedy (zavolame explicitne protoze "nestrati fokus, tak aby to fungovalo")
351407 statesEdited ();
352- alphaberEdited ();
408+ alphabetEdited ();
353409
354410 QList<QListWidgetItem *> items = ui->rulesListWidget ->selectedItems ();
355411
@@ -371,7 +427,7 @@ void FA_widget::on_rulesListWidget_itemDoubleClicked(QListWidgetItem *item)
371427{
372428 // updatovani stavu a abecedy (zavolame explicitne protoze "nestrati fokus, tak aby to fungovalo")
373429 statesEdited ();
374- alphaberEdited ();
430+ alphabetEdited ();
375431
376432 ComputationalRules oldrule (item->text ());
377433
@@ -435,7 +491,7 @@ void FA_widget::on_tabWidget_currentChanged(int index)
435491 ui->endingStatesLineEdit ->setText (endingStates.join (" , " ));
436492
437493 }
438- emit FA_changed (FA);
494+ // not needed emit, we set only old data from FA graphic - emit FA_changed(FA);
439495}
440496
441497// vymaze selected items
0 commit comments