@@ -184,22 +184,6 @@ namespace hal
184184 return mParentModule ->get_pin_group_by_id (grpId);
185185 }
186186
187- void ActionPingroup::addUndoAction (PinActionType::Type tp, int id, const QString& name, int value)
188- {
189- ActionPingroup* undo = nullptr ;
190- if (mUndoAction )
191- {
192- undo = static_cast <ActionPingroup*>(mUndoAction );
193- undo->mPinActions .append (AtomicAction (tp,id,name,value));
194- }
195- else
196- {
197- undo = new ActionPingroup (tp,id,name,value);
198- undo->setObject (object ());
199- }
200- mUndoAction = undo;
201- }
202-
203187
204188 void ActionPingroup::prepareUndoAction ()
205189 {
@@ -238,32 +222,23 @@ namespace hal
238222 if (gr.mDirection != PinDirection::none)
239223 restoreActions.append (AtomicAction (PinActionType::GroupDirChange,gr.mId ," " ,(int )gr.mDirection ));
240224 }
241- if (!restoreActions.isEmpty ())
225+
226+ for (auto it = mTempUndoActions .rbegin (); it != mTempUndoActions .rend (); ++it)
242227 {
243- if (mUndoAction )
244- {
245- ActionPingroup* act = static_cast <ActionPingroup*>(mUndoAction );
246- restoreActions += act->mPinActions ;
247- act->mPinActions = restoreActions;
248- }
249- else
250- {
251- mUndoAction = new ActionPingroup (restoreActions);
252- }
228+ for (const AtomicAction& aa : (*it))
229+ restoreActions.append (aa);
253230 }
254231
255232 for (u32 grpId : mGroupToRemove )
256233 {
257- if (mUndoAction )
258- {
259- ActionPingroup* act = static_cast <ActionPingroup*>(mUndoAction );
260- act->mPinActions .append (AtomicAction (PinActionType::GroupDelete,grpId));
261- }
262- else
263- mUndoAction = new ActionPingroup (PinActionType::GroupDelete,grpId);
234+ restoreActions.append (AtomicAction (PinActionType::GroupDelete,grpId));
264235 }
265236
266- if (mUndoAction ) mUndoAction ->setObject (object ());
237+ if (!restoreActions.isEmpty ())
238+ {
239+ mUndoAction = new ActionPingroup (restoreActions);
240+ mUndoAction ->setObject (object ());
241+ }
267242 }
268243
269244 int ActionPingroup::pinGroupRow (const Module *m, PinGroup<ModulePin>* pgroup)
@@ -283,6 +258,7 @@ namespace hal
283258 mGroupRestore .clear ();
284259 mPinsMoved .clear ();
285260 mGroupToRemove .clear ();
261+ mTempUndoActions .clear ();
286262 if (mObject .type () != UserActionObjectType::Module)
287263 return false ;
288264
@@ -365,38 +341,44 @@ namespace hal
365341 QString name = QString::fromStdString (pgroup->get_name ());
366342 if (!mParentModule ->delete_pin_group (pgroup))
367343 return false ;
368- addUndoAction (PinActionType::GroupCreate,id,name,v);
369- addUndoAction (PinActionType::GroupTypeChange,id," " ,ptype);
370- addUndoAction (PinActionType::GroupDirChange,id," " ,pdir);
344+ mTempUndoActions .append (QList<AtomicAction>({
345+ AtomicAction (PinActionType::GroupCreate,id,name,v),
346+ AtomicAction (PinActionType::GroupTypeChange,id," " ,ptype),
347+ AtomicAction (PinActionType::GroupDirChange,id," " ,pdir)}));
371348 break ;
372349 }
373350 case PinActionType::GroupMoveToRow:
374351 {
375352 int inx = pinGroupRow (mParentModule ,pgroup);
376353 if (inx < 0 ) return false ;
377- addUndoAction (PinActionType::GroupMoveToRow,pgroup->get_id ()," " ,inx);
354+ mTempUndoActions .append (QList<AtomicAction>({
355+ AtomicAction (PinActionType::GroupMoveToRow,pgroup->get_id ()," " ,inx)}));
378356 if (!mParentModule ->move_pin_group (pgroup,aa.mValue ))
379357 return false ;
380358 break ;
381359 }
382360 case PinActionType::GroupRename:
383- addUndoAction (PinActionType::GroupRename,pgroup->get_id (),QString::fromStdString (pgroup->get_name ()));
361+ mTempUndoActions .append (QList<AtomicAction>({
362+ AtomicAction (PinActionType::GroupRename,pgroup->get_id (),QString::fromStdString (pgroup->get_name ()))}));
384363 if (!mParentModule ->set_pin_group_name (pgroup,aa.mName .toStdString ()))
385364 return false ;
386365 break ;
387366 case PinActionType::GroupTypeChange:
388- addUndoAction (PinActionType::GroupTypeChange,pgroup->get_id ()," " ,(int )pgroup->get_type ());
367+ mTempUndoActions .append (QList<AtomicAction>({
368+ AtomicAction (PinActionType::GroupTypeChange,pgroup->get_id ()," " ,(int )pgroup->get_type ())}));
389369 if (!mParentModule ->set_pin_group_type (pgroup, (PinType) aa.mValue ))
390370 return false ;
391371 break ;
392372 case PinActionType::GroupDirChange:
393- addUndoAction (PinActionType::GroupDirChange,pgroup->get_id ()," " ,(int )pgroup->get_direction ());
373+ mTempUndoActions .append (QList<AtomicAction>({
374+ AtomicAction (PinActionType::GroupDirChange,pgroup->get_id ()," " ,(int )pgroup->get_direction ())}));
394375 if (!mParentModule ->set_pin_group_direction (pgroup, (PinDirection) aa.mValue ))
395376 return false ;
396377 break ;
397378 case PinActionType::PinAsignToGroup:
398- addUndoAction (PinActionType::PinAsignToGroup,aa.mId ," " ,pin->get_group ().first ->get_id ());
399- addUndoAction (PinActionType::PinMoveToRow,aa.mId ," " ,ActionPingroup::pinIndex2Row (pin,pin->get_group ().second ));
379+ mTempUndoActions .append (QList<AtomicAction>({
380+ AtomicAction (PinActionType::PinAsignToGroup,aa.mId ," " ,pin->get_group ().first ->get_id ()),
381+ AtomicAction (PinActionType::PinMoveToRow,aa.mId ," " ,ActionPingroup::pinIndex2Row (pin,pin->get_group ().second ))}));
400382 mPinsMoved .insert (aa.mId );
401383 pgroup = getGroup (aa.mValue );
402384 if (!pgroup) return false ;
@@ -408,18 +390,21 @@ namespace hal
408390 // dumpPingroups();
409391 break ;
410392 case PinActionType::PinRename:
411- addUndoAction (PinActionType::PinRename,aa.mId , QString::fromStdString (pin->get_name ()));
393+ mTempUndoActions .append (QList<AtomicAction>({
394+ AtomicAction (PinActionType::PinRename,aa.mId , QString::fromStdString (pin->get_name ()))}));
412395 if (!mParentModule ->set_pin_name (pin, aa.mName .toStdString ()))
413396 return false ;
414397 break ;
415398 case PinActionType::PinTypeChange:
416- addUndoAction (PinActionType::PinTypeChange,aa.mId ," " ,(int )pin->get_type ());
399+ mTempUndoActions .append (QList<AtomicAction>({
400+ AtomicAction (PinActionType::PinTypeChange,aa.mId ," " ,(int )pin->get_type ())}));
417401 if (!mParentModule ->set_pin_type (pin, (PinType) aa.mValue ))
418402 return false ;
419403 break ;
420404 case PinActionType::PinMoveToRow:
421405 if (!mPinsMoved .contains (aa.mId ))
422- addUndoAction (PinActionType::PinMoveToRow,aa.mId ," " ,ActionPingroup::pinIndex2Row (pin,pin->get_group ().second ));
406+ mTempUndoActions .append (QList<AtomicAction>({
407+ AtomicAction (PinActionType::PinMoveToRow,aa.mId ," " ,ActionPingroup::pinIndex2Row (pin,pin->get_group ().second ))}));
423408 pgroup = pin->get_group ().first ;
424409 if (!mParentModule ->move_pin_within_group (pgroup,pin,ActionPingroup::pinRow2Index (pin,aa.mValue )))
425410 {
@@ -505,7 +490,11 @@ namespace hal
505490 bool doNotDelete = false ; // if there is a pin with the same name as the
506491 int vid = -1 ;
507492
508- for (ModulePin* pin : groupToDelete->get_pins ())
493+ std::vector<ModulePin*> orderedPins = groupToDelete->get_pins ();
494+ if (groupToDelete->is_descending ())
495+ std::reverse (orderedPins.begin (), orderedPins.end ());
496+
497+ for (ModulePin* pin : orderedPins)
509498 {
510499 if (pin->get_name () == groupToDelete->get_name ())
511500 doNotDelete = true ;
0 commit comments