Should I build undo stack in model or its wrapper?

I am building an application (Python/PyQt). The first-order item will be a tree view/model with many helper functions to add new items, move them around in the tree, etc.. Then I will have a main window object that will basically serve as a wrapper for the tree. This main window has a toolbar with buttons for the user to add/remove/move items (these buttons call the helper methods built into the tree object).

It’s just about done, but alas I have decided to add undo/redo functionality using Qt’s undo framework. It is my first time using undo/redo functionality, and I am curious whether there is consensus/experience on whether to implement the undo stack in the main window wrapper, or push the details into the internals of the tree class. I can see going either way.

Initially I put the undo stack functionality into the wrapper, so I could keep my tree simpler, and I was thinking that undo/redo is largely a sort of simple wrapper itself, not something I wanted to include in the functionality of the tree itself.

As I started, though, I realized I seemed to be breaking modularity, and because of the way these undo classes are implemented (they are fairly complicated and get into the internals of the tree model), it was starting to feel like I was making the wrapper concern itself with too many details of how the tree is implemented. This defeats the purpose of a simple wrapper.

So now I’m leaning toward incorporating the undo stack, in particular QUndoCommand classes, into the tree model, which is happy to deal with all these internals. This would likely simplify the wrapper, which is sort of the point. In other words, I’m thinking that I was naive about how complicated it was to add undo/redo functionality. It isn’t simple, but something the model itself really should be working on.

However, I am completely new to this, so am wondering if I am making a silly design error that will haunt me in two years when I try to expand the project. One thing I appreciate now: the way I incorporate undo/redo into this application will be a pain to switch in the future, so I want to do it right the first time.

Note added

Based on a comment, I searched ‘undo design patterns’ and got some potentially relevant links:

  • https://stackoverflow.com/questions/3448943/best-design-pattern-for-undo-feature
  • https://stackoverflow.com/questions/49755/design-pattern-for-undo-engine

If you look at the docs for Qt’s undo framework linked above, it seems to use the command design pattern, so that’s what I’m working with. So reposing my question in that light, should I generate the command objects within the original class, or its wrapper? Is there any obvious flaw in my above reasoning that it is better for modularity to do it in the original class?

Update added in 2020
I implemented the undo/redo functionality in the main class, not its wrapper and this was clearly the right move.

3

It seems that you are not asking how to implement undo, since you’ve already chosen to work with Qt’s Undo Framework, which already has an implementation to hook in to.

If I understand you correctly, you are more interested in where to implement the necessary code. It seems that you have tried implementing it in two places which leads to complexity in either situation (been there before). So in some ways it is an arbitrary choice.

One thing you may not have considered is creating more than one wrapper. If you were to wrap your tree with a wrapper which added the undo functionality and then another wrapper which adds additional functionality your application requires, then you may end up with a better architecture. Kind of in line with the Single Responsibility Principle. Note you may wrap the tree in a different order, depending on your needs.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Should I build undo stack in model or its wrapper?

I am building an application (Python/PyQt). The first-order item will be a tree view/model with many helper functions to add new items, move them around in the tree, etc.. Then I will have a main window object that will basically serve as a wrapper for the tree. This main window has a toolbar with buttons for the user to add/remove/move items (these buttons call the helper methods built into the tree object).

It’s just about done, but alas I have decided to add undo/redo functionality using Qt’s undo framework. It is my first time using undo/redo functionality, and I am curious whether there is consensus/experience on whether to implement the undo stack in the main window wrapper, or push the details into the internals of the tree class. I can see going either way.

Initially I put the undo stack functionality into the wrapper, so I could keep my tree simpler, and I was thinking that undo/redo is largely a sort of simple wrapper itself, not something I wanted to include in the functionality of the tree itself.

As I started, though, I realized I seemed to be breaking modularity, and because of the way these undo classes are implemented (they are fairly complicated and get into the internals of the tree model), it was starting to feel like I was making the wrapper concern itself with too many details of how the tree is implemented. This defeats the purpose of a simple wrapper.

So now I’m leaning toward incorporating the undo stack, in particular QUndoCommand classes, into the tree model, which is happy to deal with all these internals. This would likely simplify the wrapper, which is sort of the point. In other words, I’m thinking that I was naive about how complicated it was to add undo/redo functionality. It isn’t simple, but something the model itself really should be working on.

However, I am completely new to this, so am wondering if I am making a silly design error that will haunt me in two years when I try to expand the project. One thing I appreciate now: the way I incorporate undo/redo into this application will be a pain to switch in the future, so I want to do it right the first time.

Note added

Based on a comment, I searched ‘undo design patterns’ and got some potentially relevant links:

  • https://stackoverflow.com/questions/3448943/best-design-pattern-for-undo-feature
  • https://stackoverflow.com/questions/49755/design-pattern-for-undo-engine

If you look at the docs for Qt’s undo framework linked above, it seems to use the command design pattern, so that’s what I’m working with. So reposing my question in that light, should I generate the command objects within the original class, or its wrapper? Is there any obvious flaw in my above reasoning that it is better for modularity to do it in the original class?

Update added in 2020
I implemented the undo/redo functionality in the main class, not its wrapper and this was clearly the right move.

3

It seems that you are not asking how to implement undo, since you’ve already chosen to work with Qt’s Undo Framework, which already has an implementation to hook in to.

If I understand you correctly, you are more interested in where to implement the necessary code. It seems that you have tried implementing it in two places which leads to complexity in either situation (been there before). So in some ways it is an arbitrary choice.

One thing you may not have considered is creating more than one wrapper. If you were to wrap your tree with a wrapper which added the undo functionality and then another wrapper which adds additional functionality your application requires, then you may end up with a better architecture. Kind of in line with the Single Responsibility Principle. Note you may wrap the tree in a different order, depending on your needs.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Should I build undo stack in model or its wrapper?

I am building an application (Python/PyQt). The first-order item will be a tree view/model with many helper functions to add new items, move them around in the tree, etc.. Then I will have a main window object that will basically serve as a wrapper for the tree. This main window has a toolbar with buttons for the user to add/remove/move items (these buttons call the helper methods built into the tree object).

It’s just about done, but alas I have decided to add undo/redo functionality using Qt’s undo framework. It is my first time using undo/redo functionality, and I am curious whether there is consensus/experience on whether to implement the undo stack in the main window wrapper, or push the details into the internals of the tree class. I can see going either way.

Initially I put the undo stack functionality into the wrapper, so I could keep my tree simpler, and I was thinking that undo/redo is largely a sort of simple wrapper itself, not something I wanted to include in the functionality of the tree itself.

As I started, though, I realized I seemed to be breaking modularity, and because of the way these undo classes are implemented (they are fairly complicated and get into the internals of the tree model), it was starting to feel like I was making the wrapper concern itself with too many details of how the tree is implemented. This defeats the purpose of a simple wrapper.

So now I’m leaning toward incorporating the undo stack, in particular QUndoCommand classes, into the tree model, which is happy to deal with all these internals. This would likely simplify the wrapper, which is sort of the point. In other words, I’m thinking that I was naive about how complicated it was to add undo/redo functionality. It isn’t simple, but something the model itself really should be working on.

However, I am completely new to this, so am wondering if I am making a silly design error that will haunt me in two years when I try to expand the project. One thing I appreciate now: the way I incorporate undo/redo into this application will be a pain to switch in the future, so I want to do it right the first time.

Note added

Based on a comment, I searched ‘undo design patterns’ and got some potentially relevant links:

  • https://stackoverflow.com/questions/3448943/best-design-pattern-for-undo-feature
  • https://stackoverflow.com/questions/49755/design-pattern-for-undo-engine

If you look at the docs for Qt’s undo framework linked above, it seems to use the command design pattern, so that’s what I’m working with. So reposing my question in that light, should I generate the command objects within the original class, or its wrapper? Is there any obvious flaw in my above reasoning that it is better for modularity to do it in the original class?

Update added in 2020
I implemented the undo/redo functionality in the main class, not its wrapper and this was clearly the right move.

3

It seems that you are not asking how to implement undo, since you’ve already chosen to work with Qt’s Undo Framework, which already has an implementation to hook in to.

If I understand you correctly, you are more interested in where to implement the necessary code. It seems that you have tried implementing it in two places which leads to complexity in either situation (been there before). So in some ways it is an arbitrary choice.

One thing you may not have considered is creating more than one wrapper. If you were to wrap your tree with a wrapper which added the undo functionality and then another wrapper which adds additional functionality your application requires, then you may end up with a better architecture. Kind of in line with the Single Responsibility Principle. Note you may wrap the tree in a different order, depending on your needs.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Should I build undo stack in model or its wrapper?

I am building an application (Python/PyQt). The first-order item will be a tree view/model with many helper functions to add new items, move them around in the tree, etc.. Then I will have a main window object that will basically serve as a wrapper for the tree. This main window has a toolbar with buttons for the user to add/remove/move items (these buttons call the helper methods built into the tree object).

It’s just about done, but alas I have decided to add undo/redo functionality using Qt’s undo framework. It is my first time using undo/redo functionality, and I am curious whether there is consensus/experience on whether to implement the undo stack in the main window wrapper, or push the details into the internals of the tree class. I can see going either way.

Initially I put the undo stack functionality into the wrapper, so I could keep my tree simpler, and I was thinking that undo/redo is largely a sort of simple wrapper itself, not something I wanted to include in the functionality of the tree itself.

As I started, though, I realized I seemed to be breaking modularity, and because of the way these undo classes are implemented (they are fairly complicated and get into the internals of the tree model), it was starting to feel like I was making the wrapper concern itself with too many details of how the tree is implemented. This defeats the purpose of a simple wrapper.

So now I’m leaning toward incorporating the undo stack, in particular QUndoCommand classes, into the tree model, which is happy to deal with all these internals. This would likely simplify the wrapper, which is sort of the point. In other words, I’m thinking that I was naive about how complicated it was to add undo/redo functionality. It isn’t simple, but something the model itself really should be working on.

However, I am completely new to this, so am wondering if I am making a silly design error that will haunt me in two years when I try to expand the project. One thing I appreciate now: the way I incorporate undo/redo into this application will be a pain to switch in the future, so I want to do it right the first time.

Note added

Based on a comment, I searched ‘undo design patterns’ and got some potentially relevant links:

  • https://stackoverflow.com/questions/3448943/best-design-pattern-for-undo-feature
  • https://stackoverflow.com/questions/49755/design-pattern-for-undo-engine

If you look at the docs for Qt’s undo framework linked above, it seems to use the command design pattern, so that’s what I’m working with. So reposing my question in that light, should I generate the command objects within the original class, or its wrapper? Is there any obvious flaw in my above reasoning that it is better for modularity to do it in the original class?

Update added in 2020
I implemented the undo/redo functionality in the main class, not its wrapper and this was clearly the right move.

3

It seems that you are not asking how to implement undo, since you’ve already chosen to work with Qt’s Undo Framework, which already has an implementation to hook in to.

If I understand you correctly, you are more interested in where to implement the necessary code. It seems that you have tried implementing it in two places which leads to complexity in either situation (been there before). So in some ways it is an arbitrary choice.

One thing you may not have considered is creating more than one wrapper. If you were to wrap your tree with a wrapper which added the undo functionality and then another wrapper which adds additional functionality your application requires, then you may end up with a better architecture. Kind of in line with the Single Responsibility Principle. Note you may wrap the tree in a different order, depending on your needs.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Should I build undo stack in model or its wrapper?

I am building an application (Python/PyQt). The first-order item will be a tree view/model with many helper functions to add new items, move them around in the tree, etc.. Then I will have a main window object that will basically serve as a wrapper for the tree. This main window has a toolbar with buttons for the user to add/remove/move items (these buttons call the helper methods built into the tree object).

It’s just about done, but alas I have decided to add undo/redo functionality using Qt’s undo framework. It is my first time using undo/redo functionality, and I am curious whether there is consensus/experience on whether to implement the undo stack in the main window wrapper, or push the details into the internals of the tree class. I can see going either way.

Initially I put the undo stack functionality into the wrapper, so I could keep my tree simpler, and I was thinking that undo/redo is largely a sort of simple wrapper itself, not something I wanted to include in the functionality of the tree itself.

As I started, though, I realized I seemed to be breaking modularity, and because of the way these undo classes are implemented (they are fairly complicated and get into the internals of the tree model), it was starting to feel like I was making the wrapper concern itself with too many details of how the tree is implemented. This defeats the purpose of a simple wrapper.

So now I’m leaning toward incorporating the undo stack, in particular QUndoCommand classes, into the tree model, which is happy to deal with all these internals. This would likely simplify the wrapper, which is sort of the point. In other words, I’m thinking that I was naive about how complicated it was to add undo/redo functionality. It isn’t simple, but something the model itself really should be working on.

However, I am completely new to this, so am wondering if I am making a silly design error that will haunt me in two years when I try to expand the project. One thing I appreciate now: the way I incorporate undo/redo into this application will be a pain to switch in the future, so I want to do it right the first time.

Note added

Based on a comment, I searched ‘undo design patterns’ and got some potentially relevant links:

  • https://stackoverflow.com/questions/3448943/best-design-pattern-for-undo-feature
  • https://stackoverflow.com/questions/49755/design-pattern-for-undo-engine

If you look at the docs for Qt’s undo framework linked above, it seems to use the command design pattern, so that’s what I’m working with. So reposing my question in that light, should I generate the command objects within the original class, or its wrapper? Is there any obvious flaw in my above reasoning that it is better for modularity to do it in the original class?

Update added in 2020
I implemented the undo/redo functionality in the main class, not its wrapper and this was clearly the right move.

3

It seems that you are not asking how to implement undo, since you’ve already chosen to work with Qt’s Undo Framework, which already has an implementation to hook in to.

If I understand you correctly, you are more interested in where to implement the necessary code. It seems that you have tried implementing it in two places which leads to complexity in either situation (been there before). So in some ways it is an arbitrary choice.

One thing you may not have considered is creating more than one wrapper. If you were to wrap your tree with a wrapper which added the undo functionality and then another wrapper which adds additional functionality your application requires, then you may end up with a better architecture. Kind of in line with the Single Responsibility Principle. Note you may wrap the tree in a different order, depending on your needs.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật