-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Clipboard methods #5627
Conversation
Starts moving logic that belongs to the Clipboard class to it. For now, that only includes the mimeType getter method (for all available mime types) and string pair decoding helper methods. Updated all files that uses those methods. Removed a '#include "StringPairDrag.h"' line from a file that didn't use it at all (src/tracks/Pattern.cpp). TODO: - Remove the second argument of the Clipboard::decodeKey and Clipboard::decodeValue methods, since they are only applicable for Clipboard::StringPair data. - Change Clipboard::copy and Clipboard::paste to use the QClipboard.
🤖 Hey, I'm @LmmsBot from github.com/lmms/bot and I made downloads for this pull request, click me to make them magically appear! 🎩
Linux
Windows
macOS🤖{"platform_name_to_artifacts": {"Linux": [{"artifact": {"title": {"title": "(AppImage)", "platform_name": "Linux"}, "link": {"link": "https://9363-15778896-gh.circle-artifacts.com/0/lmms-1.2.3-743%2Bg6e013cf-linux-x86_64.AppImage"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/9363?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}], "Windows": [{"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://9364-15778896-gh.circle-artifacts.com/0/lmms-1.2.3-743%2Bg6e013cf02-mingw-win32.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/9364?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://9361-15778896-gh.circle-artifacts.com/0/lmms-1.2.3-743%2Bg6e013cf02-mingw-win64.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/9361?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/5dd7dqku36867wm3/artifacts/build/lmms-1.2.2-msvc2017-win32.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/35570324"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/dq7mmmpimv1gvss6/artifacts/build/lmms-1.2.2-msvc2017-win64.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/35570324"}], "macOS": [{"artifact": {"title": {"title": "", "platform_name": "macOS"}, "link": {"link": "https://9362-15778896-gh.circle-artifacts.com/0/lmms-1.2.3-743%2Bg6e013cf02-mac10.13.dmg"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/9362?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}]}, "commit_sha": "edb06d7b016250775681005368dcba3787a3f168"} |
Removes unnecessary mime type argument to those methods since they are only used on data of StringPair type, so the mime type will always be Clipboard::StringPair.
This commit adds a method to the Clipboard class that takes a key and a value as arguments and copies a string pair to the clipboard, moving the logic of actually copying to the Clipboard class. That simplifies its use on the Track.cpp methods and better distribute the responsabilities between classes. Another change was calling TCOV::copy() from the TCOV::cut() method instead of repeating the code, saving some unnecessary lines.
This commit adds a method to the Clipboard class to copy a generic string to the clipboard, using the given MimeType from our enum. That is used in the PianoRoll to copy notes, saving a few lines on PianoRoll.cpp by moving some of the clipboard logic to the Clipboard class.
Last few commits continue to move clipboard logic to the Clipboard class ( Next step is to figure out how to copy a |
Adds convenience methods to Clipboard.h to retrieve the QMimeData from the clipboard and checking whether a particular MimeType format is present on it. This saves a few lines on other files and reduces code pollution by moving more of the clipboard logic to the Clipboard class.
To keep consistency on the behavior of the TCOV copy and paste operations, we now only use the TCOV::copy() and TCOV::paste() methods for copying both individual and multiple TCOs. The TCO::copy() and TCO::paste() methods are still kept since they are used on the src/track/BBTrack.cpp file. TODO: - Since the TCO::copy() and TCO::paste() are now only used for internal operations that have nothing to do with Userland clipboard operations, I believe there's no need to change them to use the system's clipboard (if they do, cloning a BB Track would clear the clipboard which is a somewhat undesired behavior). However, if they don't use the clipboard they shouldn't be relying on the Clipboard.h class at all, so a small refactor would have to be done to move away from it. I believe renaming would also be interesting since now their behavior resembles more a copyState and pasteState operation.
TCO::cut() is not being used anywhere anymore, so it's removed.
TCO::copy() and TCO::paste() were until now only used to copy a state from a TCO to another one when cloning BBTracks. Being an internal operation there's no need for it to use the Clipboard. Also, the naming can be a little confusing now giving it's new only function. Both methods were merged in a single static one called TrackContentObject::copyStateTo(src, dst), which copies the state of one TCO to another one by using the same logic as before but without the need of the Clipboard class. BBTrack.cpp was updated to use this method instead and TCO::copy() and TCO::paste() were removed. Obsolete members of the Clipboard class were removed as well.
I'm changing this PR from Draft to Ready to review because the goal of the PR was achieved on a preliminary stage, which was refactoring the Clipboard class and clipboard operations so they are more consistent and all use the system's clipboard.
Right now, For Testers: Things worth testing:
|
Child classes are supposed to override |
To be honest, I wasn't sure if calling the base class |
On the method TrackContentObject::copyStateTo the arguments were being casted to JournallingObject pointers unnecessarily, when they could have just be treated as TrackContentObject pointers resulting in the same behavior. This was being done because the original method (Clipboard::copy and Clipboard::getContent) received JournallingObject pointers as arguments, but that was probably done so they would work for other objects besides TCO. Since this new method only treats TCOs there's no need to do such conversion.
It was a quick fix, so I just updated the PR. Now the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are minor formatting issues from copy-pasting. The code looks fine.
If someone can also review this, it will be great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Clipboard.cpp
should be moved from src/core
to src/gui
. I don't know whether this should be done in this PR, or left for the refactoring effort.
💯% agree. |
This commit adds a new method to the Clipboard class, fixes some code style issues and improves the logic of a Track.cpp method. The changes are listed below: - A Clipboard::getString(MimeType) method is created, that returns a QString with the contents of the clipboard for that particular mimetype. PianoRoll.cpp was the only place where getMimeData() was still being used for that, so the code was changed to use this new helper method. - Removed parenthesis from return statements on Clipboard.h - On TrackContentObject::copyStateTo, the conditional for the state copy was moved to surround the whole method, since nothing is supposed to run if the conditional is false. - Removed comment that had a doubt about TCOV->remove(), since the doubt was answered on GitHub. TODO: - AutomatableModelView.cpp also uses the clipboard, but right now it uses Qt methods directly. Maybe change the code to use the Clipboard class for consistency.
Instead of calling Qt clipboard directly, AutomatableModelView.cpp now uses the Clipboard class to copy and paste values.
I merged master and added 2 new commits. First one addresses the requested changes from the reviews listed below:
Second commit was a small change to |
There's a merge conflict due to #5619, but it looks easy to resolve that. |
Merged master and conflict on |
Changes the code to use enum class instead of a regular enum for the MimeType values.
Changed the Clipboard class to use During the process a small bug was found. Steps for reproducing:
After those steps the notes added to the I'm still investigating what is causing it. Before, cloning a BBTrack would trigger calls to |
About the bug mentioned before: Apparently it was already present before my PR, I'm sorry about that. I'll still try to figure out what is causing it, but disregard that bug when reviewing the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. One more thing: how about making Clipboard
a namespace instead of a class, since everything in it is now public and static?
Sure, it could be done! I'd basically have to replace Edit: |
If you run into multiple definitions issue, you can add |
Makes Clipboard a namespace instead of a class and adds "using namespace Clipboard;" statements to methods that required functions from that namespace. The only two methods where the statement wasn't added were StringPairDrag::decodeKey and StringPairDrag::decodeValue because they are both one-liners.
Thanks @PhysSong for the hint about using |
Resolved the conflict introduced by #5661 . Does it look good to go? On the "Files Changed" there appeared some stuff about |
I think you've commited the merge commit before running |
Thanks! I thought I ran it before the |
In that case, ping me when it's ready to merge. |
Fixes conflict introduced by LMMS#5661 ("Fix for Mixer volume percentage labels are off by a factor of 100") on src/gui/AutomatableModelView.cpp. Note: This merge was force-pushed after a hard reset, because there were some issues with submodules being included on the last time I pushed the merge. That new merge is an attempt to fix that.
ed3777f
to
edb06d7
Compare
I think I fixed it. Did a hard reset to revert the merge and did it again. Even running Well, that's just what I think happened. Anyways, the ringbuffer files are out of the "Files Changed" preview now! |
Merge? |
* Moves mimeType from StringPairDrag to Clipboard * Simplifies decodeKey and decodeValue methods * Adds method to copy a string to clipboard * Adds method to copy a string pair to the Clipboard * Adds convenience methods to Clipboard.h to retrieve the QMimeData from the clipboard and checking whether a particular mime type format is present on it * Uses only the TCOV copy/paste methods on the song editor To keep consistency on the behavior of the TCOV copy and paste operations, we now only use the TCOV::copy() and TCOV::paste() methods for copying both individual and multiple TCOs. * Removes obsolete TrackContentObject::cut() and merge copy() and paste() methods to single function TrackContentObject::copyStateTo() * Adds Clipboard::getString method to get data for particular mime type * Makes AutomatableModelView.cpp use the Clipboard class instead of calling Qt clipboard directly
This draft's goal is to refactor some of LMMS's clipboard functionality. Currently the system is a little bit unorganized because it mixes the OS's clipboard (accessed through
QClipboard
) and an internal LMMS'sClipboard
class (only accessible on the current running instance of LMMS). It would be interesting to move completely to the OS's clipboard for the sake of consistency and also possibility of multiple LMMS instances interacting with themselves when it comes to copying and pasting.The first commit is just a little reorganizing of some Clipboard related methods. First, the mime type string used to be obtained on both the Clipboard class and the StringPairDrag class (
Clipboard::mimeType()
andStringPairDrag::mimeType()
). Since it's related to the clipboard, I moved it completely to the Clipboard class, the equivalents of the previous methods now beingClipboard::mimeType( Clipboard::Default )
andClipboard::mimeType( Clipboard::StringPair )
. Any new mime type can be easily added to theClipboard
class. The idea is that the Clipboard class will be a class with helper methods for dealing with the clipboard (not a clipboard itself as it is now). Another change is that StringPairDrag class had methods for decoding a string pair key and value from mime data and from a Drop event. I moved the ones that decode the key and value from mime data to the Clipboard class, since they can and are used outside the context of a Drag&Drop event, and kept the ones that extract the key and value from a Drop event on the StringPairDrag class (which by itself calls theClipboard::decodeKey
andClipboard::decodeValue
respectively).I know the draft is at its very beginning, but being a structural change I think it's worth having it here so changes are discussed before I dive too deep into it. Suggestions can be made and I take a smaller risk of refactoring in a way that is not agreed upon by other Devs.