Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

R1853 Copy/Paste and Undo/Redo

2 posters

Go down  Message [Page 1 of 1]

1R1853 Copy/Paste and Undo/Redo Empty R1853 Copy/Paste and Undo/Redo Mon Sep 04, 2023 10:40 am

royqh1979



I'm trying to implement coping items by ctrl+drag/drop. It's a feature that most vector drawing programs had.

I found some issues:

- Items copied by copy/paste can't be undo.
- Undo/redo system is not working well. Sometimes items redued can't be undo again. Repeated undo/redo may cause crash.

I'm trying to refactor undo/redo system now.

2R1853 Copy/Paste and Undo/Redo Empty Re: R1853 Copy/Paste and Undo/Redo Mon Sep 04, 2023 1:46 pm

arcachofo

arcachofo

Yes, the Undo/Redo system still need some work.
Maybe even a complete redesign. If you have some idea please let me know.

3R1853 Copy/Paste and Undo/Redo Empty Re: R1853 Copy/Paste and Undo/Redo Mon Sep 04, 2023 2:28 pm

royqh1979



arcachofo wrote:Yes, the Undo/Redo system still need some work.
Maybe even a complete redesign. If you have some idea please let me know.

What I've done now:

- Undo/Redo : merge circleState's remove/create queue.

Now restateStore() first handle remove queue, then create queue.

So if there's batch change : create / remove / create / remove, it only can be handled as create/create/remove/remove

I use one queue to save states. States are retrieved backward from the queue when undo, forward when redo.

- Clean up undo/redo index

Undo/Redo indexes are only updated if undostatck/redostatck is pop/pushed.

- Prevent prop change from breaking batch works
I added a counter flag  m_batchProcess  , and two methods beginBatchProcess()/endBatchProcess().

If m_batchProcess is greater than 0, addCompState won't saveState();

- change addCompState()'s default state to stateAdd | stateSave
    - clear stats in saveState()


addCompState shouldn't clear state, if no explicitly specified.

- changes in paste()/removeItems to handel undo/redo

- ctrl+drag/drop to copy


There's still something need to be done to handle nodes.
Attachments
R1853 Copy/Paste and Undo/Redo Attachmentdrag-demo1.zip
You don't have permission to download attachments.
(9 Kb) Downloaded 1 times

4R1853 Copy/Paste and Undo/Redo Empty Re: R1853 Copy/Paste and Undo/Redo Mon Sep 04, 2023 4:02 pm

royqh1979



Unsolved issues:

- removeItems

When a component is removed, how to know the connectors that auto removed with it.

- Node

Node is auto generated when connect to line. And auto removed the connector is removed. With its removal, other connectors connected to it are also removed.

When undo copy, how to handle it.

5R1853 Copy/Paste and Undo/Redo Empty Re: R1853 Copy/Paste and Undo/Redo Mon Sep 04, 2023 4:05 pm

royqh1979



royqh1979 wrote:Unsolved issues:

- removeItems

When a component is removed, how to know the connectors that auto removed with it.

- Node

Node is auto generated when connect to line. And auto removed the connector is removed. With its removal, other connectors connected to it are also removed. This might cause a deleted connector obj to be delete again (and crash).

When undo copy, how to handle it. Maybe smartpointer?

6R1853 Copy/Paste and Undo/Redo Empty Re: R1853 Copy/Paste and Undo/Redo Mon Sep 04, 2023 4:26 pm

arcachofo

arcachofo

I'm looking at your changes now.
I think we should go step by step. First changes in Undo/Redo, and then Copy by drag.
Indeed we should discuss this Copy by drag feature.

7R1853 Copy/Paste and Undo/Redo Empty Re: R1853 Copy/Paste and Undo/Redo Mon Sep 04, 2023 6:43 pm

royqh1979



All basiclly done. More test needed.

The patch are not qDebug cleaned.

- Undo/Redo for remove selections. (removeItems)

All connector/compnont string is saved in a map before remove.
After remove is done, check which ones are removed and use the saved string to generate undo data.

- Undo/Redo for copy/paste.

Undo for copy/paste needs batch remove. All comp remove are done through removeConnector/removeComp/removeNode methods, just we can control how comps are removed.

If a obj to be removed is not in the cache(already removed), dont remove again.

The type for cache containers m_conList/nodeList/compList are changed from QList to QSet to speed up search.

obj are not deleted immediated, but saved to a temp list, in case its info are needed in the middle of batch operation. Objs in the temp list are deleted after saveState();

- Copy by ctrl+drag/drop and Undo support.


The code for copy by ctrl+drag/drop is in circuitview's mouseMoveEvent/mousePressEvent/dragEnterEvent/dragMoveEvent/dragLeaveEvent/dropEvent.

Attachments
R1853 Copy/Paste and Undo/Redo Attachmentdrag-test1.zip
You don't have permission to download attachments.
(12 Kb) Downloaded 1 times

8R1853 Copy/Paste and Undo/Redo Empty Re: R1853 Copy/Paste and Undo/Redo Tue Sep 05, 2023 12:16 am

arcachofo

arcachofo

Patch applied at Rev 1859.

Your work in the Undo/Redo system is beyond excellent.
I was procastinating on this because by brain hurts just by thinking about working on it.
So I'm eternally grateful.

I did some changes in the "copy by drag" feature:
- Changed it to Ctrl+Shift because only Ctrl was interfering with other features.
- Simplified it a little bit (still some issue to solve).

9R1853 Copy/Paste and Undo/Redo Empty Re: R1853 Copy/Paste and Undo/Redo Tue Sep 05, 2023 2:30 am

royqh1979



arcachofo wrote:Patch applied at Rev 1859.

Your work in the Undo/Redo system is beyond excellent.
I was procastinating on this because by brain hurts just by thinking about working on it.
So I'm eternally grateful.

I made some changes for the "copy by drag" feature:
- Changed it to Ctrl+Shift because only Ctrl was interfering with other features.
- Simplified it a little bit (still some issue to solve).

Thanks.

In the attached patch (for Revision 1859):
- An extra param "undo" is added to circuit::paste(), to control save undo info or not.
- use drag/drop mechnism to handle shift+ctrl+drag operatoion, so it can be cancelled by pressing ESC.
- use the same mechnism as circuit::removeItems(), to get the copied items.
- use copy()/paste() to copy items in the drag&drop copy. But undo info are only added in the circuitView::dropEvent(), which is called after drop is done.
- minor fix: create new component by drag from left pane are not undoable.
- minor fix: prevent drag copy from starting if linking is in process.

And for the modify key, maybe we could list all the mouse operations that uses Ctrl, and check if we could keep compatible with them?
Attachments
R1853 Copy/Paste and Undo/Redo Attachmentdrag-1859-2.zip
You don't have permission to download attachments.
(4 Kb) Downloaded 1 times

10R1853 Copy/Paste and Undo/Redo Empty Re: R1853 Copy/Paste and Undo/Redo Tue Sep 05, 2023 1:33 pm

royqh1979



Patch against the last patch "drag-1859-2.diff"
 - Undo support for component property change.
Attachments
R1853 Copy/Paste and Undo/Redo Attachmentundoprop.zip
You don't have permission to download attachments.
(3 Kb) Downloaded 1 times

11R1853 Copy/Paste and Undo/Redo Empty Re: R1853 Copy/Paste and Undo/Redo Tue Sep 05, 2023 3:44 pm

royqh1979



Patch for R1859.

Fixes:
- new component (created by drag from the left pane) are not undoable. (circuitView::dragEnterEvent())

Issues:
- move the code to save undo info to pasted contents into circuit::paste(). And use the same logic as removeItems() to scan for all new compoments created in the paste.
- In drag&drop, (circuitView::mouseMoveEvent) make sure the copied ones are not exactly overlapped with the origin ones. Since drag&drop is implemented by copy/paste and move ( two undo steps), this may cause users forget to undo the copy/paste step.
Attachments
R1853 Copy/Paste and Undo/Redo Attachmentdrag-1859-3.zip
You don't have permission to download attachments.
(2 Kb) Downloaded 1 times

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum