From a689039d99e61553449255eb195037abc5bc20cf Mon Sep 17 00:00:00 2001 From: IanCaio Date: Wed, 12 Aug 2020 17:26:19 -0300 Subject: [PATCH 01/13] Moves mimeType fully to the Clipboard Class 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. --- include/Clipboard.h | 23 ++++++++++++++-- include/StringPairDrag.h | 8 ------ plugins/Lv2Instrument/Lv2Instrument.cpp | 5 ++-- .../audio_file_processor.cpp | 5 ++-- plugins/patman/patman.cpp | 5 ++-- plugins/vestige/vestige.cpp | 9 ++++--- plugins/zynaddsubfx/ZynAddSubFx.cpp | 5 ++-- src/core/Clipboard.cpp | 14 ++++++++++ src/core/Track.cpp | 16 +++++------ src/gui/StringPairDrag.cpp | 27 +++++-------------- src/gui/editors/PianoRoll.cpp | 4 +-- src/tracks/Pattern.cpp | 1 - 12 files changed, 68 insertions(+), 54 deletions(-) diff --git a/include/Clipboard.h b/include/Clipboard.h index fa4d5c5404e..bd9bdbc87b3 100644 --- a/include/Clipboard.h +++ b/include/Clipboard.h @@ -34,14 +34,33 @@ class JournallingObject; class Clipboard { public: + enum MimeType + { + StringPair, + Default + }; + typedef QMap Map; static void copy( JournallingObject * _object ); static const QDomElement * getContent( const QString & _node_name ); - static const char * mimeType() + // Helper methods for String Pair data + static QString decodeKey( const QMimeData * mimeData, const char * mimeType ); + static QString decodeValue( const QMimeData * mimeData, const char * mimeType ); + + static const char * mimeType( MimeType type ) { - return( "application/x-lmms-clipboard" ); + switch( type ) + { + case Clipboard::StringPair: + return( "application/x-lmms-stringpair" ); + break; + case Clipboard::Default: + default: + return( "application/x-lmms-clipboard" ); + break; + } } diff --git a/include/StringPairDrag.h b/include/StringPairDrag.h index cebc3089a15..969a12eec4e 100644 --- a/include/StringPairDrag.h +++ b/include/StringPairDrag.h @@ -45,16 +45,8 @@ class LMMS_EXPORT StringPairDrag : public QDrag static bool processDragEnterEvent( QDragEnterEvent * _dee, const QString & _allowed_keys ); - static QString decodeMimeKey( const QMimeData * mimeData ); - static QString decodeMimeValue( const QMimeData * mimeData ); static QString decodeKey( QDropEvent * _de ); static QString decodeValue( QDropEvent * _de ); - - static const char * mimeType() - { - return( "application/x-lmms-stringpair" ); - } - } ; diff --git a/plugins/Lv2Instrument/Lv2Instrument.cpp b/plugins/Lv2Instrument/Lv2Instrument.cpp index 974aaf416b4..c57d956a36f 100644 --- a/plugins/Lv2Instrument/Lv2Instrument.cpp +++ b/plugins/Lv2Instrument/Lv2Instrument.cpp @@ -33,6 +33,7 @@ #include "Lv2SubPluginFeatures.h" #include "Mixer.h" #include "StringPairDrag.h" +#include "Clipboard.h" #include "embed.h" #include "plugin_export.h" @@ -240,10 +241,10 @@ void Lv2InsView::dragEnterEvent(QDragEnterEvent *_dee) { void (QDragEnterEvent::*reaction)(void) = &QDragEnterEvent::ignore; - if (_dee->mimeData()->hasFormat(StringPairDrag::mimeType())) + if (_dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ))) { const QString txt = - _dee->mimeData()->data(StringPairDrag::mimeType()); + _dee->mimeData()->data( Clipboard::mimeType( Clipboard::StringPair ) ); if (txt.section(':', 0, 0) == "pluginpresetfile") { reaction = &QDragEnterEvent::acceptProposedAction; } diff --git a/plugins/audio_file_processor/audio_file_processor.cpp b/plugins/audio_file_processor/audio_file_processor.cpp index 51af71f55eb..d5d95dfd85c 100644 --- a/plugins/audio_file_processor/audio_file_processor.cpp +++ b/plugins/audio_file_processor/audio_file_processor.cpp @@ -44,6 +44,7 @@ #include "Song.h" #include "StringPairDrag.h" #include "ToolTip.h" +#include "Clipboard.h" #include "embed.h" #include "plugin_export.h" @@ -568,10 +569,10 @@ AudioFileProcessorView::~AudioFileProcessorView() void AudioFileProcessorView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( StringPairDrag::mimeType() ) ) + if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - StringPairDrag::mimeType() ); + Clipboard::mimeType( Clipboard::StringPair ) ); if( txt.section( ':', 0, 0 ) == QString( "tco_%1" ).arg( Track::SampleTrack ) ) { diff --git a/plugins/patman/patman.cpp b/plugins/patman/patman.cpp index e5170383438..e135f480471 100644 --- a/plugins/patman/patman.cpp +++ b/plugins/patman/patman.cpp @@ -41,6 +41,7 @@ #include "Song.h" #include "StringPairDrag.h" #include "ToolTip.h" +#include "Clipboard.h" #include "embed.h" @@ -580,10 +581,10 @@ void PatmanView::updateFilename( void ) void PatmanView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( StringPairDrag::mimeType() ) ) + if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - StringPairDrag::mimeType() ); + Clipboard::mimeType( Clipboard::StringPair ) ); if( txt.section( ':', 0, 0 ) == "samplefile" ) { _dee->acceptProposedAction(); diff --git a/plugins/vestige/vestige.cpp b/plugins/vestige/vestige.cpp index b17a1684541..fa691cdec57 100644 --- a/plugins/vestige/vestige.cpp +++ b/plugins/vestige/vestige.cpp @@ -58,6 +58,7 @@ #include "StringPairDrag.h" #include "TextFloat.h" #include "ToolTip.h" +#include "Clipboard.h" #include "embed.h" @@ -833,10 +834,10 @@ void VestigeInstrumentView::noteOffAll( void ) void VestigeInstrumentView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( StringPairDrag::mimeType() ) ) + if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - StringPairDrag::mimeType() ); + Clipboard::mimeType( Clipboard::StringPair ) ); if( txt.section( ':', 0, 0 ) == "vstplugin" ) { _dee->acceptProposedAction(); @@ -1175,10 +1176,10 @@ void manageVestigeInstrumentView::syncParameterText() void manageVestigeInstrumentView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( StringPairDrag::mimeType() ) ) + if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - StringPairDrag::mimeType() ); + Clipboard::mimeType( Clipboard::StringPair ) ); if( txt.section( ':', 0, 0 ) == "vstplugin" ) { _dee->acceptProposedAction(); diff --git a/plugins/zynaddsubfx/ZynAddSubFx.cpp b/plugins/zynaddsubfx/ZynAddSubFx.cpp index 429948e7508..32eed8ade2a 100644 --- a/plugins/zynaddsubfx/ZynAddSubFx.cpp +++ b/plugins/zynaddsubfx/ZynAddSubFx.cpp @@ -47,6 +47,7 @@ #include "LocalZynAddSubFx.h" #include "Mixer.h" #include "ControllerConnection.h" +#include "Clipboard.h" #include "embed.h" #include "plugin_export.h" @@ -578,10 +579,10 @@ ZynAddSubFxView::~ZynAddSubFxView() void ZynAddSubFxView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( StringPairDrag::mimeType() ) ) + if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - StringPairDrag::mimeType() ); + Clipboard::mimeType( Clipboard::StringPair ) ); if( txt.section( ':', 0, 0 ) == "pluginpresetfile" ) { _dee->acceptProposedAction(); diff --git a/src/core/Clipboard.cpp b/src/core/Clipboard.cpp index 9b1191cdc0d..7d96ade2e55 100644 --- a/src/core/Clipboard.cpp +++ b/src/core/Clipboard.cpp @@ -24,6 +24,7 @@ #include #include +#include #include "Clipboard.h" #include "JournallingObject.h" @@ -58,3 +59,16 @@ const QDomElement * Clipboard::getContent( const QString & _node_name ) + +QString Clipboard::decodeKey( const QMimeData * mimeData, const char * mimeType ) +{ + return( QString::fromUtf8( mimeData->data( mimeType ) ).section( ':', 0, 0 ) ); +} + + + + +QString Clipboard::decodeValue( const QMimeData * mimeData, const char * mimeType ) +{ + return( QString::fromUtf8( mimeData->data( mimeType ) ).section( ':', 1, -1 ) ); +} diff --git a/src/core/Track.cpp b/src/core/Track.cpp index f79a34a15c9..1b1b35599e1 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -1250,7 +1250,7 @@ void TrackContentObjectView::copy( QVector tcovs ) // Copy it to the clipboard QMimeData *tco_content = new QMimeData; - tco_content->setData( StringPairDrag::mimeType(), finalString.toUtf8() ); + tco_content->setData( Clipboard::mimeType( Clipboard::StringPair ), finalString.toUtf8() ); QApplication::clipboard()->setMimeData( tco_content, QClipboard::Clipboard ); } else @@ -1276,7 +1276,7 @@ void TrackContentObjectView::cut( QVector tcovs ) // Copy it to the clipboard QMimeData *tco_content = new QMimeData; - tco_content->setData( StringPairDrag::mimeType(), finalString.toUtf8() ); + tco_content->setData( Clipboard::mimeType( Clipboard::StringPair ), finalString.toUtf8() ); QApplication::clipboard()->setMimeData( tco_content, QClipboard::Clipboard ); } else @@ -1291,7 +1291,7 @@ void TrackContentObjectView::paste() // clear the QApplication Clipboard during the LMMS Clipboard copy operations (Clipboard::copy does that) // If we have TCO data on the clipboard paste it. If not, do our regular TCO paste. - if( QApplication::clipboard()->mimeData( QClipboard::Clipboard )->hasFormat( StringPairDrag::mimeType() ) ) + if( QApplication::clipboard()->mimeData( QClipboard::Clipboard )->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) { // Paste the selection on the MidiTime of the selected Track const QMimeData *md = QApplication::clipboard()->mimeData( QClipboard::Clipboard ); @@ -1706,8 +1706,8 @@ bool TrackContentWidget::canPasteSelection( MidiTime tcoPos, const QDropEvent* d bool TrackContentWidget::canPasteSelection( MidiTime tcoPos, const QMimeData* md , bool allowSameBar ) { Track * t = getTrack(); - QString type = StringPairDrag::decodeMimeKey( md ); - QString value = StringPairDrag::decodeMimeValue( md ); + QString type = Clipboard::decodeKey( md, Clipboard::mimeType( Clipboard::StringPair ) ); + QString value = Clipboard::decodeValue( md, Clipboard::mimeType( Clipboard::StringPair ) ); // We can only paste into tracks of the same type if( type != ( "tco_" + QString::number( t->type() ) ) || @@ -1797,8 +1797,8 @@ bool TrackContentWidget::pasteSelection( MidiTime tcoPos, const QMimeData * md, return false; } - QString type = StringPairDrag::decodeMimeKey( md ); - QString value = StringPairDrag::decodeMimeValue( md ); + QString type = Clipboard::decodeKey( md, Clipboard::mimeType( Clipboard::StringPair ) ); + QString value = Clipboard::decodeValue( md, Clipboard::mimeType( Clipboard::StringPair ) ); getTrack()->addJournalCheckPoint(); @@ -2000,7 +2000,7 @@ void TrackContentWidget::contextMenuEvent( QContextMenuEvent * cme ) // If we don't have TCO data in the clipboard there's no need to create this menu // since "paste" is the only action at the moment. const QMimeData *md = QApplication::clipboard()->mimeData( QClipboard::Clipboard ); - if( !md->hasFormat( StringPairDrag::mimeType() ) ) + if( !md->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) { return; } diff --git a/src/gui/StringPairDrag.cpp b/src/gui/StringPairDrag.cpp index b2b3b0c4a4e..780b9499aa7 100644 --- a/src/gui/StringPairDrag.cpp +++ b/src/gui/StringPairDrag.cpp @@ -32,6 +32,7 @@ #include "StringPairDrag.h" #include "GuiApplication.h" #include "MainWindow.h" +#include "Clipboard.h" StringPairDrag::StringPairDrag( const QString & _key, const QString & _value, @@ -51,7 +52,7 @@ StringPairDrag::StringPairDrag( const QString & _key, const QString & _value, } QString txt = _key + ":" + _value; QMimeData * m = new QMimeData(); - m->setData( mimeType(), txt.toUtf8() ); + m->setData( Clipboard::mimeType( Clipboard::StringPair ), txt.toUtf8() ); setMimeData( m ); exec( Qt::LinkAction, Qt::LinkAction ); } @@ -75,11 +76,11 @@ StringPairDrag::~StringPairDrag() bool StringPairDrag::processDragEnterEvent( QDragEnterEvent * _dee, const QString & _allowed_keys ) { - if( !_dee->mimeData()->hasFormat( mimeType() ) ) + if( !_dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) { return( false ); } - QString txt = _dee->mimeData()->data( mimeType() ); + QString txt = _dee->mimeData()->data( Clipboard::mimeType( Clipboard::StringPair ) ); if( _allowed_keys.split( ',' ).contains( txt.section( ':', 0, 0 ) ) ) { _dee->acceptProposedAction(); @@ -92,25 +93,9 @@ bool StringPairDrag::processDragEnterEvent( QDragEnterEvent * _dee, -QString StringPairDrag::decodeMimeKey( const QMimeData * mimeData ) -{ - return( QString::fromUtf8( mimeData->data( mimeType() ) ).section( ':', 0, 0 ) ); -} - - - - -QString StringPairDrag::decodeMimeValue( const QMimeData * mimeData ) -{ - return( QString::fromUtf8( mimeData->data( mimeType() ) ).section( ':', 1, -1 ) ); -} - - - - QString StringPairDrag::decodeKey( QDropEvent * _de ) { - return decodeMimeKey( _de->mimeData() ); + return Clipboard::decodeKey( _de->mimeData(), Clipboard::mimeType( Clipboard::StringPair ) ); } @@ -118,5 +103,5 @@ QString StringPairDrag::decodeKey( QDropEvent * _de ) QString StringPairDrag::decodeValue( QDropEvent * _de ) { - return decodeMimeValue( _de->mimeData() ); + return Clipboard::decodeValue( _de->mimeData(), Clipboard::mimeType( Clipboard::StringPair ) ); } diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 3d35c9c5133..986d2732fba 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -3891,7 +3891,7 @@ void PianoRoll::copyToClipboard( const NoteVector & notes ) const } QMimeData * clip_content = new QMimeData; - clip_content->setData( Clipboard::mimeType(), dataFile.toString().toUtf8() ); + clip_content->setData( Clipboard::mimeType( Clipboard::Default ), dataFile.toString().toUtf8() ); QApplication::clipboard()->setMimeData( clip_content, QClipboard::Clipboard ); } @@ -3953,7 +3953,7 @@ void PianoRoll::pasteNotes() QString value = QApplication::clipboard() ->mimeData( QClipboard::Clipboard ) - ->data( Clipboard::mimeType() ); + ->data( Clipboard::mimeType( Clipboard::Default ) ); if( ! value.isEmpty() ) { diff --git a/src/tracks/Pattern.cpp b/src/tracks/Pattern.cpp index 40f11b3cb30..75fa0f33227 100644 --- a/src/tracks/Pattern.cpp +++ b/src/tracks/Pattern.cpp @@ -39,7 +39,6 @@ #include "SampleBuffer.h" #include "AudioSampleRecorder.h" #include "BBTrackContainer.h" -#include "StringPairDrag.h" #include "MainWindow.h" #include From f2785fbf2d3057f5be4d612a3e313b16d8a7e195 Mon Sep 17 00:00:00 2001 From: IanCaio Date: Wed, 12 Aug 2020 18:07:44 -0300 Subject: [PATCH 02/13] Simplifies decodeKey and decodeValue methods 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. --- include/Clipboard.h | 4 ++-- src/core/Clipboard.cpp | 8 ++++---- src/core/Track.cpp | 8 ++++---- src/gui/StringPairDrag.cpp | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/Clipboard.h b/include/Clipboard.h index bd9bdbc87b3..10b8864f347 100644 --- a/include/Clipboard.h +++ b/include/Clipboard.h @@ -46,8 +46,8 @@ class Clipboard static const QDomElement * getContent( const QString & _node_name ); // Helper methods for String Pair data - static QString decodeKey( const QMimeData * mimeData, const char * mimeType ); - static QString decodeValue( const QMimeData * mimeData, const char * mimeType ); + static QString decodeKey( const QMimeData * mimeData ); + static QString decodeValue( const QMimeData * mimeData ); static const char * mimeType( MimeType type ) { diff --git a/src/core/Clipboard.cpp b/src/core/Clipboard.cpp index 7d96ade2e55..46150e2f555 100644 --- a/src/core/Clipboard.cpp +++ b/src/core/Clipboard.cpp @@ -60,15 +60,15 @@ const QDomElement * Clipboard::getContent( const QString & _node_name ) -QString Clipboard::decodeKey( const QMimeData * mimeData, const char * mimeType ) +QString Clipboard::decodeKey( const QMimeData * mimeData ) { - return( QString::fromUtf8( mimeData->data( mimeType ) ).section( ':', 0, 0 ) ); + return( QString::fromUtf8( mimeData->data( mimeType( StringPair ) ) ).section( ':', 0, 0 ) ); } -QString Clipboard::decodeValue( const QMimeData * mimeData, const char * mimeType ) +QString Clipboard::decodeValue( const QMimeData * mimeData ) { - return( QString::fromUtf8( mimeData->data( mimeType ) ).section( ':', 1, -1 ) ); + return( QString::fromUtf8( mimeData->data( mimeType( StringPair ) ) ).section( ':', 1, -1 ) ); } diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 1b1b35599e1..5070daf3bd3 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -1706,8 +1706,8 @@ bool TrackContentWidget::canPasteSelection( MidiTime tcoPos, const QDropEvent* d bool TrackContentWidget::canPasteSelection( MidiTime tcoPos, const QMimeData* md , bool allowSameBar ) { Track * t = getTrack(); - QString type = Clipboard::decodeKey( md, Clipboard::mimeType( Clipboard::StringPair ) ); - QString value = Clipboard::decodeValue( md, Clipboard::mimeType( Clipboard::StringPair ) ); + QString type = Clipboard::decodeKey( md ); + QString value = Clipboard::decodeValue( md ); // We can only paste into tracks of the same type if( type != ( "tco_" + QString::number( t->type() ) ) || @@ -1797,8 +1797,8 @@ bool TrackContentWidget::pasteSelection( MidiTime tcoPos, const QMimeData * md, return false; } - QString type = Clipboard::decodeKey( md, Clipboard::mimeType( Clipboard::StringPair ) ); - QString value = Clipboard::decodeValue( md, Clipboard::mimeType( Clipboard::StringPair ) ); + QString type = Clipboard::decodeKey( md ); + QString value = Clipboard::decodeValue( md ); getTrack()->addJournalCheckPoint(); diff --git a/src/gui/StringPairDrag.cpp b/src/gui/StringPairDrag.cpp index 780b9499aa7..62158264ed0 100644 --- a/src/gui/StringPairDrag.cpp +++ b/src/gui/StringPairDrag.cpp @@ -95,7 +95,7 @@ bool StringPairDrag::processDragEnterEvent( QDragEnterEvent * _dee, QString StringPairDrag::decodeKey( QDropEvent * _de ) { - return Clipboard::decodeKey( _de->mimeData(), Clipboard::mimeType( Clipboard::StringPair ) ); + return Clipboard::decodeKey( _de->mimeData() ); } @@ -103,5 +103,5 @@ QString StringPairDrag::decodeKey( QDropEvent * _de ) QString StringPairDrag::decodeValue( QDropEvent * _de ) { - return Clipboard::decodeValue( _de->mimeData(), Clipboard::mimeType( Clipboard::StringPair ) ); + return Clipboard::decodeValue( _de->mimeData() ); } From 76fb1bf979152b5d2eb0fa32cb39d4652ec5af78 Mon Sep 17 00:00:00 2001 From: IanCaio Date: Sat, 15 Aug 2020 22:23:06 -0300 Subject: [PATCH 03/13] Adds method to copy a stringpair to the Clipboard 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. --- include/Clipboard.h | 1 + src/core/Clipboard.cpp | 12 ++++++++++++ src/core/Track.cpp | 24 ++++++------------------ 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/include/Clipboard.h b/include/Clipboard.h index 10b8864f347..02684292f99 100644 --- a/include/Clipboard.h +++ b/include/Clipboard.h @@ -46,6 +46,7 @@ class Clipboard static const QDomElement * getContent( const QString & _node_name ); // Helper methods for String Pair data + static void copyStringPair( const QString & key, const QString & value ); static QString decodeKey( const QMimeData * mimeData ); static QString decodeValue( const QMimeData * mimeData ); diff --git a/src/core/Clipboard.cpp b/src/core/Clipboard.cpp index 46150e2f555..1ace14f5e99 100644 --- a/src/core/Clipboard.cpp +++ b/src/core/Clipboard.cpp @@ -60,6 +60,18 @@ const QDomElement * Clipboard::getContent( const QString & _node_name ) +void Clipboard::copyStringPair( const QString & key, const QString & value ) +{ + QString finalString = key + ":" + value; + + QMimeData *content = new QMimeData; + content->setData( mimeType( StringPair ), finalString.toUtf8() ); + QApplication::clipboard()->setMimeData( content, QClipboard::Clipboard ); +} + + + + QString Clipboard::decodeKey( const QMimeData * mimeData ) { return( QString::fromUtf8( mimeData->data( mimeType( StringPair ) ) ).section( ':', 0, 0 ) ); diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 5070daf3bd3..c8245b16e0c 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -1245,13 +1245,9 @@ void TrackContentObjectView::copy( QVector tcovs ) // Write the TCOs to a DataFile for copying DataFile dataFile = createTCODataFiles( tcovs ); - // Add the TCO type as a key to the final string - QString finalString = QString( "tco_%1:%2" ).arg( m_tco->getTrack()->type() ).arg( dataFile.toString() ); - - // Copy it to the clipboard - QMimeData *tco_content = new QMimeData; - tco_content->setData( Clipboard::mimeType( Clipboard::StringPair ), finalString.toUtf8() ); - QApplication::clipboard()->setMimeData( tco_content, QClipboard::Clipboard ); + // Copy the TCO type as a key and the TCO data file to the clipboard + Clipboard::copyStringPair( QString( "tco_%1" ).arg( m_tco->getTrack()->type() ), + dataFile.toString() ); } else { @@ -1264,20 +1260,12 @@ void TrackContentObjectView::cut( QVector tcovs ) // Checks if there are other selected TCOs and if so cut them as well if( tcovs.size() > 1 ) { - // Write the TCOs to a DataFile for copying - DataFile dataFile = createTCODataFiles( tcovs ); + // Copy the selected TCOs + copy( tcovs ); - // Now that the dataFile is created we can delete the tracks, since we are cutting + // Now that the TCOs are copied we can delete them, since we are cutting // TODO: Is it safe to call tcov->remove(); on the current TCOV instance? remove( tcovs ); - - // Add the TCO type as a key to the final string - QString finalString = QString( "tco_%1:%2" ).arg( m_tco->getTrack()->type() ).arg( dataFile.toString() ); - - // Copy it to the clipboard - QMimeData *tco_content = new QMimeData; - tco_content->setData( Clipboard::mimeType( Clipboard::StringPair ), finalString.toUtf8() ); - QApplication::clipboard()->setMimeData( tco_content, QClipboard::Clipboard ); } else { From b787b4ffdf3c7cd77b8c7bc5bd0c55422cee2da8 Mon Sep 17 00:00:00 2001 From: IanCaio Date: Sat, 15 Aug 2020 23:08:56 -0300 Subject: [PATCH 04/13] Adds method to copy string to clipboard 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. --- include/Clipboard.h | 2 ++ src/core/Clipboard.cpp | 11 +++++++++++ src/gui/editors/PianoRoll.cpp | 5 +---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/Clipboard.h b/include/Clipboard.h index 02684292f99..6e916d9f846 100644 --- a/include/Clipboard.h +++ b/include/Clipboard.h @@ -45,6 +45,8 @@ class Clipboard static void copy( JournallingObject * _object ); static const QDomElement * getContent( const QString & _node_name ); + static void copyString( const QString & str, MimeType mT ); + // Helper methods for String Pair data static void copyStringPair( const QString & key, const QString & value ); static QString decodeKey( const QMimeData * mimeData ); diff --git a/src/core/Clipboard.cpp b/src/core/Clipboard.cpp index 1ace14f5e99..d5ab1cea6b7 100644 --- a/src/core/Clipboard.cpp +++ b/src/core/Clipboard.cpp @@ -60,6 +60,17 @@ const QDomElement * Clipboard::getContent( const QString & _node_name ) +void Clipboard::copyString( const QString & str, MimeType mT ) +{ + QMimeData *content = new QMimeData; + + content->setData( mimeType( mT ), str.toUtf8() ); + QApplication::clipboard()->setMimeData( content, QClipboard::Clipboard ); +} + + + + void Clipboard::copyStringPair( const QString & key, const QString & value ) { QString finalString = key + ":" + value; diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 986d2732fba..4bef9b728b0 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -3890,10 +3890,7 @@ void PianoRoll::copyToClipboard( const NoteVector & notes ) const clip_note.saveState( dataFile, note_list ); } - QMimeData * clip_content = new QMimeData; - clip_content->setData( Clipboard::mimeType( Clipboard::Default ), dataFile.toString().toUtf8() ); - QApplication::clipboard()->setMimeData( clip_content, - QClipboard::Clipboard ); + Clipboard::copyString( dataFile.toString(), Clipboard::Default ); } From 7fa9b554edd6719ea16a77d3cd4219eee5f0cf75 Mon Sep 17 00:00:00 2001 From: IanCaio Date: Sun, 16 Aug 2020 10:32:43 -0300 Subject: [PATCH 05/13] Adds convenience methods to Clipboard.h 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. --- include/Clipboard.h | 5 +++++ src/core/Clipboard.cpp | 16 ++++++++++++++++ src/core/Track.cpp | 13 +++++-------- src/gui/editors/PianoRoll.cpp | 4 +--- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/include/Clipboard.h b/include/Clipboard.h index 6e916d9f846..5643ccb4782 100644 --- a/include/Clipboard.h +++ b/include/Clipboard.h @@ -45,6 +45,11 @@ class Clipboard static void copy( JournallingObject * _object ); static const QDomElement * getContent( const QString & _node_name ); + // Convenience Methods + static const QMimeData * getMimeData(); + static bool hasFormat( MimeType mT ); + + // Helper methods for String data static void copyString( const QString & str, MimeType mT ); // Helper methods for String Pair data diff --git a/src/core/Clipboard.cpp b/src/core/Clipboard.cpp index d5ab1cea6b7..b31323a4b4e 100644 --- a/src/core/Clipboard.cpp +++ b/src/core/Clipboard.cpp @@ -60,6 +60,22 @@ const QDomElement * Clipboard::getContent( const QString & _node_name ) +const QMimeData * Clipboard::getMimeData() +{ + return QApplication::clipboard()->mimeData( QClipboard::Clipboard ); +} + + + + +bool Clipboard::hasFormat( MimeType mT ) +{ + return getMimeData()->hasFormat( mimeType( mT ) ); +} + + + + void Clipboard::copyString( const QString & str, MimeType mT ) { QMimeData *content = new QMimeData; diff --git a/src/core/Track.cpp b/src/core/Track.cpp index c8245b16e0c..ece7c4bd9f1 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -1279,15 +1279,14 @@ void TrackContentObjectView::paste() // clear the QApplication Clipboard during the LMMS Clipboard copy operations (Clipboard::copy does that) // If we have TCO data on the clipboard paste it. If not, do our regular TCO paste. - if( QApplication::clipboard()->mimeData( QClipboard::Clipboard )->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) + if( Clipboard::hasFormat( Clipboard::StringPair ) ) { // Paste the selection on the MidiTime of the selected Track - const QMimeData *md = QApplication::clipboard()->mimeData( QClipboard::Clipboard ); MidiTime tcoPos = MidiTime( m_tco->startPosition() ); TrackContentWidget *tcw = getTrackView()->getTrackContentWidget(); - if( tcw->pasteSelection( tcoPos, md ) == true ) + if( tcw->pasteSelection( tcoPos, Clipboard::getMimeData() ) == true ) { // If we succeed on the paste we delete the TCO we pasted on remove(); @@ -1987,8 +1986,7 @@ void TrackContentWidget::contextMenuEvent( QContextMenuEvent * cme ) // If we don't have TCO data in the clipboard there's no need to create this menu // since "paste" is the only action at the moment. - const QMimeData *md = QApplication::clipboard()->mimeData( QClipboard::Clipboard ); - if( !md->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) + if( ! Clipboard::hasFormat( Clipboard::StringPair ) ) { return; } @@ -1997,7 +1995,7 @@ void TrackContentWidget::contextMenuEvent( QContextMenuEvent * cme ) QAction *pasteA = contextMenu.addAction( embed::getIconPixmap( "edit_paste" ), tr( "Paste" ), [this, cme](){ contextMenuAction( cme, Paste ); } ); // If we can't paste in the current TCW for some reason, disable the action so the user knows - pasteA->setEnabled( canPasteSelection( getPosition( cme->x() ), md ) ? true : false ); + pasteA->setEnabled( canPasteSelection( getPosition( cme->x() ), Clipboard::getMimeData() ) ? true : false ); contextMenu.exec( QCursor::pos() ); } @@ -2008,10 +2006,9 @@ void TrackContentWidget::contextMenuAction( QContextMenuEvent * cme, ContextMenu { case Paste: // Paste the selection on the MidiTime of the context menu event - const QMimeData *md = QApplication::clipboard()->mimeData( QClipboard::Clipboard ); MidiTime tcoPos = getPosition( cme->x() ); - pasteSelection( tcoPos, md ); + pasteSelection( tcoPos, Clipboard::getMimeData() ); break; } } diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 4bef9b728b0..09534e15c64 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -3948,9 +3948,7 @@ void PianoRoll::pasteNotes() return; } - QString value = QApplication::clipboard() - ->mimeData( QClipboard::Clipboard ) - ->data( Clipboard::mimeType( Clipboard::Default ) ); + QString value = Clipboard::getMimeData()->data( Clipboard::mimeType( Clipboard::Default ) ); if( ! value.isEmpty() ) { From ebc808ef5745657aaec2acb8809a007729d6dd17 Mon Sep 17 00:00:00 2001 From: IanCaio Date: Sun, 16 Aug 2020 10:41:34 -0300 Subject: [PATCH 06/13] Uses only the TCOV copy/paste methods on the SE 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. --- src/core/Track.cpp | 59 +++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/src/core/Track.cpp b/src/core/Track.cpp index ece7c4bd9f1..ff0dd6975db 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -1239,62 +1239,35 @@ void TrackContentObjectView::remove( QVector tcovs ) void TrackContentObjectView::copy( QVector tcovs ) { - // Checks if there are other selected TCOs and if so copy them as well - if( tcovs.size() > 1 ) - { - // Write the TCOs to a DataFile for copying - DataFile dataFile = createTCODataFiles( tcovs ); + // Write the TCOs to a DataFile for copying + DataFile dataFile = createTCODataFiles( tcovs ); - // Copy the TCO type as a key and the TCO data file to the clipboard - Clipboard::copyStringPair( QString( "tco_%1" ).arg( m_tco->getTrack()->type() ), - dataFile.toString() ); - } - else - { - tcovs.at(0)->getTrackContentObject()->copy(); - } + // Copy the TCO type as a key and the TCO data file to the clipboard + Clipboard::copyStringPair( QString( "tco_%1" ).arg( m_tco->getTrack()->type() ), + dataFile.toString() ); } void TrackContentObjectView::cut( QVector tcovs ) { - // Checks if there are other selected TCOs and if so cut them as well - if( tcovs.size() > 1 ) - { - // Copy the selected TCOs - copy( tcovs ); + // Copy the selected TCOs + copy( tcovs ); - // Now that the TCOs are copied we can delete them, since we are cutting - // TODO: Is it safe to call tcov->remove(); on the current TCOV instance? - remove( tcovs ); - } - else - { - tcovs.at(0)->cut(); - } + // Now that the TCOs are copied we can delete them, since we are cutting + // TODO: Is it safe to call tcov->remove(); on the current TCOV instance? + remove( tcovs ); } void TrackContentObjectView::paste() { - // NOTE: Because we give preference to the QApplication clipboard over the LMMS Clipboard class, we need to - // clear the QApplication Clipboard during the LMMS Clipboard copy operations (Clipboard::copy does that) - - // If we have TCO data on the clipboard paste it. If not, do our regular TCO paste. - if( Clipboard::hasFormat( Clipboard::StringPair ) ) - { - // Paste the selection on the MidiTime of the selected Track - MidiTime tcoPos = MidiTime( m_tco->startPosition() ); + // If possible, paste the selection on the MidiTime of the selected Track and remove it + MidiTime tcoPos = MidiTime( m_tco->startPosition() ); - TrackContentWidget *tcw = getTrackView()->getTrackContentWidget(); + TrackContentWidget *tcw = getTrackView()->getTrackContentWidget(); - if( tcw->pasteSelection( tcoPos, Clipboard::getMimeData() ) == true ) - { - // If we succeed on the paste we delete the TCO we pasted on - remove(); - } - } - else + if( tcw->pasteSelection( tcoPos, Clipboard::getMimeData() ) == true ) { - getTrackContentObject()->paste(); + // If we succeed on the paste we delete the TCO we pasted on + remove(); } } From 2a04e5b8c2d3a5de22eca586747a8b7f8ef70f01 Mon Sep 17 00:00:00 2001 From: IanCaio Date: Sun, 16 Aug 2020 11:06:19 -0300 Subject: [PATCH 07/13] Removes obsolete method TCO::cut() is not being used anywhere anymore, so it's removed. --- include/Track.h | 1 - src/core/Track.cpp | 14 -------------- 2 files changed, 15 deletions(-) diff --git a/include/Track.h b/include/Track.h index 9362a838019..efa0e691c97 100644 --- a/include/Track.h +++ b/include/Track.h @@ -266,7 +266,6 @@ class TrackContentObjectView : public selectableObject, public ModelView public slots: virtual bool close(); - void cut(); void remove(); void update() override; diff --git a/src/core/Track.cpp b/src/core/Track.cpp index ff0dd6975db..2506b54159a 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -478,20 +478,6 @@ void TrackContentObjectView::remove() -/*! \brief Cut this trackContentObjectView from its track to the clipboard. - * - * Perform the 'cut' action of the clipboard - copies the track content - * object to the clipboard and then removes it from the track. - */ -void TrackContentObjectView::cut() -{ - m_tco->copy(); - remove(); -} - - - - /*! \brief Updates a trackContentObjectView's length * * If this track content object view has a fixed TCO, then we must From 79e29b965d019cf6757dcc8c77f3217f723210f0 Mon Sep 17 00:00:00 2001 From: IanCaio Date: Sun, 16 Aug 2020 11:49:46 -0300 Subject: [PATCH 08/13] Refactor the TCO::copy and TCO::paste methods 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. --- include/Clipboard.h | 12 ------------ include/Track.h | 5 +++-- src/core/Clipboard.cpp | 30 ------------------------------ src/core/Track.cpp | 33 ++++++++++++++------------------- src/tracks/BBTrack.cpp | 4 ++-- 5 files changed, 19 insertions(+), 65 deletions(-) diff --git a/include/Clipboard.h b/include/Clipboard.h index 5643ccb4782..36d22b49c91 100644 --- a/include/Clipboard.h +++ b/include/Clipboard.h @@ -29,8 +29,6 @@ #include -class JournallingObject; - class Clipboard { public: @@ -40,11 +38,6 @@ class Clipboard Default }; - typedef QMap Map; - - static void copy( JournallingObject * _object ); - static const QDomElement * getContent( const QString & _node_name ); - // Convenience Methods static const QMimeData * getMimeData(); static bool hasFormat( MimeType mT ); @@ -70,11 +63,6 @@ class Clipboard break; } } - - -private: - static Map content; - } ; #endif diff --git a/include/Track.h b/include/Track.h index efa0e691c97..a4930832003 100644 --- a/include/Track.h +++ b/include/Track.h @@ -155,9 +155,10 @@ class LMMS_EXPORT TrackContentObject : public Model, public JournallingObject MidiTime startTimeOffset() const; void setStartTimeOffset( const MidiTime &startTimeOffset ); + // Will copy the state of a TCO to another TCO + static void copyStateTo( TrackContentObject *src, TrackContentObject *dst ); + public slots: - void copy(); - void paste(); void toggleMute(); diff --git a/src/core/Clipboard.cpp b/src/core/Clipboard.cpp index b31323a4b4e..4dd52aecafc 100644 --- a/src/core/Clipboard.cpp +++ b/src/core/Clipboard.cpp @@ -30,36 +30,6 @@ #include "JournallingObject.h" -Clipboard::Map Clipboard::content; - - -void Clipboard::copy( JournallingObject * _obj ) -{ - QDomDocument doc; - QDomElement parent = doc.createElement( "Clipboard" ); - _obj->saveState( doc, parent ); - content[_obj->nodeName()] = parent.firstChild().toElement(); - - // Clear the QApplication clipboard, so we don't have any conflicts when LMMS has to - // decide between the QApplication clipboard and the internal clipboard data - QApplication::clipboard()->clear( QClipboard::Clipboard ); -} - - - - -const QDomElement * Clipboard::getContent( const QString & _node_name ) -{ - if( content.find( _node_name ) != content.end() ) - { - return &content[_node_name]; - } - return NULL; -} - - - - const QMimeData * Clipboard::getMimeData() { return QApplication::clipboard()->mimeData( QClipboard::Clipboard ); diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 2506b54159a..4c632173acb 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -184,32 +184,27 @@ bool TrackContentObject::comparePosition(const TrackContentObject *a, const Trac -/*! \brief Copy this TrackContentObject to the clipboard. +/*! \brief Copies the state of a TrackContentObject to another TrackContentObject * - * Copies this track content object to the clipboard. + * This method copies the state of a TCO to another TCO */ -void TrackContentObject::copy() +void TrackContentObject::copyStateTo( TrackContentObject *src, TrackContentObject *dst ) { - Clipboard::copy( this ); -} - - + JournallingObject * srcObj = dynamic_cast( src ); + JournallingObject * dstObj = dynamic_cast( dst ); + QDomDocument doc; + QDomElement parent = doc.createElement( "StateCopy" ); + srcObj->saveState( doc, parent ); -/*! \brief Pastes this TrackContentObject into a track. - * - * Pastes this track content object into a track. - * - * \param _je The journal entry to undo - */ -void TrackContentObject::paste() -{ - if( Clipboard::getContent( nodeName() ) != NULL ) + // If the node names match we copy the state + if( srcObj->nodeName() == dstObj->nodeName() ) { - const MidiTime pos = startPosition(); - restoreState( *( Clipboard::getContent( nodeName() ) ) ); - movePosition( pos ); + const MidiTime pos = dst->startPosition(); + dst->restoreState( parent.firstChild().toElement() ); + dst->movePosition( pos ); } + AutomationPattern::resolveAllIDs(); GuiApplication::instance()->automationEditor()->m_editor->updateAfterPatternChange(); } diff --git a/src/tracks/BBTrack.cpp b/src/tracks/BBTrack.cpp index a779e2ea49b..0e9facbb0ff 100644 --- a/src/tracks/BBTrack.cpp +++ b/src/tracks/BBTrack.cpp @@ -528,8 +528,8 @@ void BBTrack::loadTrackSpecificSettings( const QDomElement & _this ) for( TrackContainer::TrackList::iterator it = tl.begin(); it != tl.end(); ++it ) { - ( *it )->getTCO( src )->copy(); - ( *it )->getTCO( dst )->paste(); + TrackContentObject::copyStateTo( ( *it )->getTCO( src ), + ( *it )->getTCO( dst ) ); } setName( tr( "Clone of %1" ).arg( _this.parentNode().toElement().attribute( "name" ) ) ); From c7763d08daeaa297d75f75046fffcef50e2c57f4 Mon Sep 17 00:00:00 2001 From: IanCaio Date: Mon, 17 Aug 2020 02:13:06 -0300 Subject: [PATCH 09/13] Avoids unnecessary type casting 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. --- src/core/Track.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 4c632173acb..d732af45275 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -190,15 +190,12 @@ bool TrackContentObject::comparePosition(const TrackContentObject *a, const Trac */ void TrackContentObject::copyStateTo( TrackContentObject *src, TrackContentObject *dst ) { - JournallingObject * srcObj = dynamic_cast( src ); - JournallingObject * dstObj = dynamic_cast( dst ); - QDomDocument doc; QDomElement parent = doc.createElement( "StateCopy" ); - srcObj->saveState( doc, parent ); + src->saveState( doc, parent ); // If the node names match we copy the state - if( srcObj->nodeName() == dstObj->nodeName() ) + if( src->nodeName() == dst->nodeName() ) { const MidiTime pos = dst->startPosition(); dst->restoreState( parent.firstChild().toElement() ); From 4ef9e3a3c4291c4bee8c5fa5555f5a30a3b4d689 Mon Sep 17 00:00:00 2001 From: IanCaio Date: Sat, 12 Sep 2020 01:30:39 -0300 Subject: [PATCH 10/13] Adds getString method to Clipboard class 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. --- include/Clipboard.h | 5 +++-- src/core/Clipboard.cpp | 8 ++++++++ src/core/Track.cpp | 20 +++++++++----------- src/gui/editors/PianoRoll.cpp | 2 +- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/include/Clipboard.h b/include/Clipboard.h index 36d22b49c91..71af017cb17 100644 --- a/include/Clipboard.h +++ b/include/Clipboard.h @@ -44,6 +44,7 @@ class Clipboard // Helper methods for String data static void copyString( const QString & str, MimeType mT ); + static QString getString( MimeType mT ); // Helper methods for String Pair data static void copyStringPair( const QString & key, const QString & value ); @@ -55,11 +56,11 @@ class Clipboard switch( type ) { case Clipboard::StringPair: - return( "application/x-lmms-stringpair" ); + return "application/x-lmms-stringpair"; break; case Clipboard::Default: default: - return( "application/x-lmms-clipboard" ); + return "application/x-lmms-clipboard"; break; } } diff --git a/src/core/Clipboard.cpp b/src/core/Clipboard.cpp index 4dd52aecafc..460ec4b4264 100644 --- a/src/core/Clipboard.cpp +++ b/src/core/Clipboard.cpp @@ -57,6 +57,14 @@ void Clipboard::copyString( const QString & str, MimeType mT ) +QString Clipboard::getString( MimeType mT ) +{ + return QString( getMimeData()->data( mimeType( mT ) ) ); +} + + + + void Clipboard::copyStringPair( const QString & key, const QString & value ) { QString finalString = key + ":" + value; diff --git a/src/core/Track.cpp b/src/core/Track.cpp index d107310d74e..66cfa278740 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -190,20 +190,19 @@ bool TrackContentObject::comparePosition(const TrackContentObject *a, const Trac */ void TrackContentObject::copyStateTo( TrackContentObject *src, TrackContentObject *dst ) { - QDomDocument doc; - QDomElement parent = doc.createElement( "StateCopy" ); - src->saveState( doc, parent ); - // If the node names match we copy the state - if( src->nodeName() == dst->nodeName() ) - { + if( src->nodeName() == dst->nodeName() ){ + QDomDocument doc; + QDomElement parent = doc.createElement( "StateCopy" ); + src->saveState( doc, parent ); + const MidiTime pos = dst->startPosition(); dst->restoreState( parent.firstChild().toElement() ); dst->movePosition( pos ); - } - AutomationPattern::resolveAllIDs(); - GuiApplication::instance()->automationEditor()->m_editor->updateAfterPatternChange(); + AutomationPattern::resolveAllIDs(); + GuiApplication::instance()->automationEditor()->m_editor->updateAfterPatternChange(); + } } @@ -1231,7 +1230,6 @@ void TrackContentObjectView::cut( QVector tcovs ) copy( tcovs ); // Now that the TCOs are copied we can delete them, since we are cutting - // TODO: Is it safe to call tcov->remove(); on the current TCOV instance? remove( tcovs ); } @@ -1242,7 +1240,7 @@ void TrackContentObjectView::paste() TrackContentWidget *tcw = getTrackView()->getTrackContentWidget(); - if( tcw->pasteSelection( tcoPos, Clipboard::getMimeData() ) == true ) + if( tcw->pasteSelection( tcoPos, Clipboard::getMimeData() ) ) { // If we succeed on the paste we delete the TCO we pasted on remove(); diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 8ef2ce44331..f62ef847ff2 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -3948,7 +3948,7 @@ void PianoRoll::pasteNotes() return; } - QString value = Clipboard::getMimeData()->data( Clipboard::mimeType( Clipboard::Default ) ); + QString value = Clipboard::getString( Clipboard::Default ); if( ! value.isEmpty() ) { From 4e05470e80d5c4c017276cbb90a5a828c58f4f01 Mon Sep 17 00:00:00 2001 From: IanCaio Date: Sat, 12 Sep 2020 01:46:24 -0300 Subject: [PATCH 11/13] Changes AutomatableModelView to use Clipboard.h Instead of calling Qt clipboard directly, AutomatableModelView.cpp now uses the Clipboard class to copy and paste values. --- src/gui/AutomatableModelView.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/gui/AutomatableModelView.cpp b/src/gui/AutomatableModelView.cpp index 039c75c9953..75e2544966d 100644 --- a/src/gui/AutomatableModelView.cpp +++ b/src/gui/AutomatableModelView.cpp @@ -23,7 +23,6 @@ */ #include -#include #include #include @@ -35,6 +34,7 @@ #include "GuiApplication.h" #include "MainWindow.h" #include "StringPairDrag.h" +#include "Clipboard.h" #include "AutomationEditor.h" @@ -242,8 +242,7 @@ void AutomatableModelViewSlots::unlinkAllModels() void AutomatableModelViewSlots::copyToClipboard() { - QClipboard* clipboard = QApplication::clipboard(); - clipboard->setText(QString::number(m_amv->value())); + Clipboard::copyString( QString::number(m_amv->value()), Clipboard::Default ); } void AutomatableModelViewSlots::pasteFromClipboard() @@ -259,7 +258,6 @@ void AutomatableModelViewSlots::pasteFromClipboard() /// Attempt to parse a float from the clipboard static float floatFromClipboard(bool* ok) { - const QClipboard* clipboard = QApplication::clipboard(); - return clipboard->text().toFloat(ok); + return Clipboard::getString( Clipboard::Default ).toFloat(ok); } From 53bb73daf0dc0ffbb2a7c29c1c2af27086d8b88f Mon Sep 17 00:00:00 2001 From: IanCaio Date: Tue, 15 Sep 2020 20:22:44 -0300 Subject: [PATCH 12/13] Uses enum class for MimeType Changes the code to use enum class instead of a regular enum for the MimeType values. --- include/Clipboard.h | 6 +++--- plugins/Lv2Instrument/Lv2Instrument.cpp | 4 ++-- plugins/audio_file_processor/audio_file_processor.cpp | 4 ++-- plugins/patman/patman.cpp | 4 ++-- plugins/vestige/vestige.cpp | 8 ++++---- plugins/zynaddsubfx/ZynAddSubFx.cpp | 4 ++-- src/core/Clipboard.cpp | 6 +++--- src/core/Track.cpp | 2 +- src/gui/AutomatableModelView.cpp | 4 ++-- src/gui/StringPairDrag.cpp | 6 +++--- src/gui/editors/PianoRoll.cpp | 4 ++-- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/Clipboard.h b/include/Clipboard.h index 71af017cb17..88707d6c058 100644 --- a/include/Clipboard.h +++ b/include/Clipboard.h @@ -32,7 +32,7 @@ class Clipboard { public: - enum MimeType + enum class MimeType { StringPair, Default @@ -55,10 +55,10 @@ class Clipboard { switch( type ) { - case Clipboard::StringPair: + case Clipboard::MimeType::StringPair: return "application/x-lmms-stringpair"; break; - case Clipboard::Default: + case Clipboard::MimeType::Default: default: return "application/x-lmms-clipboard"; break; diff --git a/plugins/Lv2Instrument/Lv2Instrument.cpp b/plugins/Lv2Instrument/Lv2Instrument.cpp index 5f2d92ad8ad..78a89391839 100644 --- a/plugins/Lv2Instrument/Lv2Instrument.cpp +++ b/plugins/Lv2Instrument/Lv2Instrument.cpp @@ -241,10 +241,10 @@ void Lv2InsView::dragEnterEvent(QDragEnterEvent *_dee) { void (QDragEnterEvent::*reaction)(void) = &QDragEnterEvent::ignore; - if (_dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ))) + if (_dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ))) { const QString txt = - _dee->mimeData()->data( Clipboard::mimeType( Clipboard::StringPair ) ); + _dee->mimeData()->data( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); if (txt.section(':', 0, 0) == "pluginpresetfile") { reaction = &QDragEnterEvent::acceptProposedAction; } diff --git a/plugins/audio_file_processor/audio_file_processor.cpp b/plugins/audio_file_processor/audio_file_processor.cpp index bd69eb50817..51aa8a1424b 100644 --- a/plugins/audio_file_processor/audio_file_processor.cpp +++ b/plugins/audio_file_processor/audio_file_processor.cpp @@ -569,10 +569,10 @@ AudioFileProcessorView::~AudioFileProcessorView() void AudioFileProcessorView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) + if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - Clipboard::mimeType( Clipboard::StringPair ) ); + Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); if( txt.section( ':', 0, 0 ) == QString( "tco_%1" ).arg( Track::SampleTrack ) ) { diff --git a/plugins/patman/patman.cpp b/plugins/patman/patman.cpp index bc33ef058ca..b091c5e14ed 100644 --- a/plugins/patman/patman.cpp +++ b/plugins/patman/patman.cpp @@ -581,10 +581,10 @@ void PatmanView::updateFilename( void ) void PatmanView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) + if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - Clipboard::mimeType( Clipboard::StringPair ) ); + Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); if( txt.section( ':', 0, 0 ) == "samplefile" ) { _dee->acceptProposedAction(); diff --git a/plugins/vestige/vestige.cpp b/plugins/vestige/vestige.cpp index 71e385e51a2..36ad087ec4f 100644 --- a/plugins/vestige/vestige.cpp +++ b/plugins/vestige/vestige.cpp @@ -834,10 +834,10 @@ void VestigeInstrumentView::noteOffAll( void ) void VestigeInstrumentView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) + if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - Clipboard::mimeType( Clipboard::StringPair ) ); + Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); if( txt.section( ':', 0, 0 ) == "vstplugin" ) { _dee->acceptProposedAction(); @@ -1176,10 +1176,10 @@ void manageVestigeInstrumentView::syncParameterText() void manageVestigeInstrumentView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) + if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - Clipboard::mimeType( Clipboard::StringPair ) ); + Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); if( txt.section( ':', 0, 0 ) == "vstplugin" ) { _dee->acceptProposedAction(); diff --git a/plugins/zynaddsubfx/ZynAddSubFx.cpp b/plugins/zynaddsubfx/ZynAddSubFx.cpp index 64db833afd3..0d8956e4faf 100644 --- a/plugins/zynaddsubfx/ZynAddSubFx.cpp +++ b/plugins/zynaddsubfx/ZynAddSubFx.cpp @@ -579,10 +579,10 @@ ZynAddSubFxView::~ZynAddSubFxView() void ZynAddSubFxView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) + if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - Clipboard::mimeType( Clipboard::StringPair ) ); + Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); if( txt.section( ':', 0, 0 ) == "pluginpresetfile" ) { _dee->acceptProposedAction(); diff --git a/src/core/Clipboard.cpp b/src/core/Clipboard.cpp index 460ec4b4264..4429a78bdef 100644 --- a/src/core/Clipboard.cpp +++ b/src/core/Clipboard.cpp @@ -70,7 +70,7 @@ void Clipboard::copyStringPair( const QString & key, const QString & value ) QString finalString = key + ":" + value; QMimeData *content = new QMimeData; - content->setData( mimeType( StringPair ), finalString.toUtf8() ); + content->setData( mimeType( MimeType::StringPair ), finalString.toUtf8() ); QApplication::clipboard()->setMimeData( content, QClipboard::Clipboard ); } @@ -79,7 +79,7 @@ void Clipboard::copyStringPair( const QString & key, const QString & value ) QString Clipboard::decodeKey( const QMimeData * mimeData ) { - return( QString::fromUtf8( mimeData->data( mimeType( StringPair ) ) ).section( ':', 0, 0 ) ); + return( QString::fromUtf8( mimeData->data( mimeType( MimeType::StringPair ) ) ).section( ':', 0, 0 ) ); } @@ -87,5 +87,5 @@ QString Clipboard::decodeKey( const QMimeData * mimeData ) QString Clipboard::decodeValue( const QMimeData * mimeData ) { - return( QString::fromUtf8( mimeData->data( mimeType( StringPair ) ) ).section( ':', 1, -1 ) ); + return( QString::fromUtf8( mimeData->data( mimeType( MimeType::StringPair ) ) ).section( ':', 1, -1 ) ); } diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 66cfa278740..7ed832fb220 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -1935,7 +1935,7 @@ void TrackContentWidget::contextMenuEvent( QContextMenuEvent * cme ) // If we don't have TCO data in the clipboard there's no need to create this menu // since "paste" is the only action at the moment. - if( ! Clipboard::hasFormat( Clipboard::StringPair ) ) + if( ! Clipboard::hasFormat( Clipboard::MimeType::StringPair ) ) { return; } diff --git a/src/gui/AutomatableModelView.cpp b/src/gui/AutomatableModelView.cpp index 75e2544966d..d1c053245de 100644 --- a/src/gui/AutomatableModelView.cpp +++ b/src/gui/AutomatableModelView.cpp @@ -242,7 +242,7 @@ void AutomatableModelViewSlots::unlinkAllModels() void AutomatableModelViewSlots::copyToClipboard() { - Clipboard::copyString( QString::number(m_amv->value()), Clipboard::Default ); + Clipboard::copyString( QString::number(m_amv->value()), Clipboard::MimeType::Default ); } void AutomatableModelViewSlots::pasteFromClipboard() @@ -258,6 +258,6 @@ void AutomatableModelViewSlots::pasteFromClipboard() /// Attempt to parse a float from the clipboard static float floatFromClipboard(bool* ok) { - return Clipboard::getString( Clipboard::Default ).toFloat(ok); + return Clipboard::getString( Clipboard::MimeType::Default ).toFloat(ok); } diff --git a/src/gui/StringPairDrag.cpp b/src/gui/StringPairDrag.cpp index 62158264ed0..bc28a3f9dc9 100644 --- a/src/gui/StringPairDrag.cpp +++ b/src/gui/StringPairDrag.cpp @@ -52,7 +52,7 @@ StringPairDrag::StringPairDrag( const QString & _key, const QString & _value, } QString txt = _key + ":" + _value; QMimeData * m = new QMimeData(); - m->setData( Clipboard::mimeType( Clipboard::StringPair ), txt.toUtf8() ); + m->setData( Clipboard::mimeType( Clipboard::MimeType::StringPair ), txt.toUtf8() ); setMimeData( m ); exec( Qt::LinkAction, Qt::LinkAction ); } @@ -76,11 +76,11 @@ StringPairDrag::~StringPairDrag() bool StringPairDrag::processDragEnterEvent( QDragEnterEvent * _dee, const QString & _allowed_keys ) { - if( !_dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::StringPair ) ) ) + if( !_dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ) ) { return( false ); } - QString txt = _dee->mimeData()->data( Clipboard::mimeType( Clipboard::StringPair ) ); + QString txt = _dee->mimeData()->data( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); if( _allowed_keys.split( ',' ).contains( txt.section( ':', 0, 0 ) ) ) { _dee->acceptProposedAction(); diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 25d9db39f7e..e3d0bd59a63 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -3897,7 +3897,7 @@ void PianoRoll::copyToClipboard( const NoteVector & notes ) const clip_note.saveState( dataFile, note_list ); } - Clipboard::copyString( dataFile.toString(), Clipboard::Default ); + Clipboard::copyString( dataFile.toString(), Clipboard::MimeType::Default ); } @@ -3955,7 +3955,7 @@ void PianoRoll::pasteNotes() return; } - QString value = Clipboard::getString( Clipboard::Default ); + QString value = Clipboard::getString( Clipboard::MimeType::Default ); if( ! value.isEmpty() ) { From f194146ab6967894f64ee2fd9935a30035206d34 Mon Sep 17 00:00:00 2001 From: IanCaio Date: Thu, 17 Sep 2020 09:35:32 -0300 Subject: [PATCH 13/13] Makes Clipboard a namespace instead of a class 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. --- include/Clipboard.h | 23 ++++--- plugins/Lv2Instrument/Lv2Instrument.cpp | 7 +- .../audio_file_processor.cpp | 7 +- plugins/patman/patman.cpp | 7 +- plugins/vestige/vestige.cpp | 14 ++-- plugins/zynaddsubfx/ZynAddSubFx.cpp | 7 +- src/core/Clipboard.cpp | 65 ++++++++++--------- src/core/Track.cpp | 36 +++++++--- src/gui/AutomatableModelView.cpp | 10 ++- src/gui/StringPairDrag.cpp | 12 +++- src/gui/editors/PianoRoll.cpp | 10 ++- 11 files changed, 127 insertions(+), 71 deletions(-) diff --git a/include/Clipboard.h b/include/Clipboard.h index 88707d6c058..a2dced9a6b7 100644 --- a/include/Clipboard.h +++ b/include/Clipboard.h @@ -29,9 +29,8 @@ #include -class Clipboard +namespace Clipboard { -public: enum class MimeType { StringPair, @@ -39,26 +38,26 @@ class Clipboard }; // Convenience Methods - static const QMimeData * getMimeData(); - static bool hasFormat( MimeType mT ); + const QMimeData * getMimeData(); + bool hasFormat( MimeType mT ); // Helper methods for String data - static void copyString( const QString & str, MimeType mT ); - static QString getString( MimeType mT ); + void copyString( const QString & str, MimeType mT ); + QString getString( MimeType mT ); // Helper methods for String Pair data - static void copyStringPair( const QString & key, const QString & value ); - static QString decodeKey( const QMimeData * mimeData ); - static QString decodeValue( const QMimeData * mimeData ); + void copyStringPair( const QString & key, const QString & value ); + QString decodeKey( const QMimeData * mimeData ); + QString decodeValue( const QMimeData * mimeData ); - static const char * mimeType( MimeType type ) + inline const char * mimeType( MimeType type ) { switch( type ) { - case Clipboard::MimeType::StringPair: + case MimeType::StringPair: return "application/x-lmms-stringpair"; break; - case Clipboard::MimeType::Default: + case MimeType::Default: default: return "application/x-lmms-clipboard"; break; diff --git a/plugins/Lv2Instrument/Lv2Instrument.cpp b/plugins/Lv2Instrument/Lv2Instrument.cpp index 78a89391839..1547018ea81 100644 --- a/plugins/Lv2Instrument/Lv2Instrument.cpp +++ b/plugins/Lv2Instrument/Lv2Instrument.cpp @@ -239,12 +239,15 @@ Lv2InsView::Lv2InsView(Lv2Instrument *_instrument, QWidget *_parent) : void Lv2InsView::dragEnterEvent(QDragEnterEvent *_dee) { + // For mimeType() and MimeType enum class + using namespace Clipboard; + void (QDragEnterEvent::*reaction)(void) = &QDragEnterEvent::ignore; - if (_dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ))) + if (_dee->mimeData()->hasFormat( mimeType( MimeType::StringPair ))) { const QString txt = - _dee->mimeData()->data( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); + _dee->mimeData()->data( mimeType( MimeType::StringPair ) ); if (txt.section(':', 0, 0) == "pluginpresetfile") { reaction = &QDragEnterEvent::acceptProposedAction; } diff --git a/plugins/audio_file_processor/audio_file_processor.cpp b/plugins/audio_file_processor/audio_file_processor.cpp index 51aa8a1424b..5f579816e41 100644 --- a/plugins/audio_file_processor/audio_file_processor.cpp +++ b/plugins/audio_file_processor/audio_file_processor.cpp @@ -569,10 +569,13 @@ AudioFileProcessorView::~AudioFileProcessorView() void AudioFileProcessorView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ) ) + // For mimeType() and MimeType enum class + using namespace Clipboard; + + if( _dee->mimeData()->hasFormat( mimeType( MimeType::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); + mimeType( MimeType::StringPair ) ); if( txt.section( ':', 0, 0 ) == QString( "tco_%1" ).arg( Track::SampleTrack ) ) { diff --git a/plugins/patman/patman.cpp b/plugins/patman/patman.cpp index b091c5e14ed..b694ee2a00f 100644 --- a/plugins/patman/patman.cpp +++ b/plugins/patman/patman.cpp @@ -581,10 +581,13 @@ void PatmanView::updateFilename( void ) void PatmanView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ) ) + // For mimeType() and MimeType enum class + using namespace Clipboard; + + if( _dee->mimeData()->hasFormat( mimeType( MimeType::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); + mimeType( MimeType::StringPair ) ); if( txt.section( ':', 0, 0 ) == "samplefile" ) { _dee->acceptProposedAction(); diff --git a/plugins/vestige/vestige.cpp b/plugins/vestige/vestige.cpp index 36ad087ec4f..b2c15859464 100644 --- a/plugins/vestige/vestige.cpp +++ b/plugins/vestige/vestige.cpp @@ -834,10 +834,13 @@ void VestigeInstrumentView::noteOffAll( void ) void VestigeInstrumentView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ) ) + // For mimeType() and MimeType enum class + using namespace Clipboard; + + if( _dee->mimeData()->hasFormat( mimeType( MimeType::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); + mimeType( MimeType::StringPair ) ); if( txt.section( ':', 0, 0 ) == "vstplugin" ) { _dee->acceptProposedAction(); @@ -1176,10 +1179,13 @@ void manageVestigeInstrumentView::syncParameterText() void manageVestigeInstrumentView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ) ) + // For mimeType() and MimeType enum class + using namespace Clipboard; + + if( _dee->mimeData()->hasFormat( mimeType( MimeType::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); + mimeType( MimeType::StringPair ) ); if( txt.section( ':', 0, 0 ) == "vstplugin" ) { _dee->acceptProposedAction(); diff --git a/plugins/zynaddsubfx/ZynAddSubFx.cpp b/plugins/zynaddsubfx/ZynAddSubFx.cpp index 0d8956e4faf..8446d36f65b 100644 --- a/plugins/zynaddsubfx/ZynAddSubFx.cpp +++ b/plugins/zynaddsubfx/ZynAddSubFx.cpp @@ -579,10 +579,13 @@ ZynAddSubFxView::~ZynAddSubFxView() void ZynAddSubFxView::dragEnterEvent( QDragEnterEvent * _dee ) { - if( _dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ) ) + // For mimeType() and MimeType enum class + using namespace Clipboard; + + if( _dee->mimeData()->hasFormat( mimeType( MimeType::StringPair ) ) ) { QString txt = _dee->mimeData()->data( - Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); + mimeType( MimeType::StringPair ) ); if( txt.section( ':', 0, 0 ) == "pluginpresetfile" ) { _dee->acceptProposedAction(); diff --git a/src/core/Clipboard.cpp b/src/core/Clipboard.cpp index 4429a78bdef..9b7cf2e775c 100644 --- a/src/core/Clipboard.cpp +++ b/src/core/Clipboard.cpp @@ -30,62 +30,65 @@ #include "JournallingObject.h" -const QMimeData * Clipboard::getMimeData() +namespace Clipboard { - return QApplication::clipboard()->mimeData( QClipboard::Clipboard ); -} + const QMimeData * getMimeData() + { + return QApplication::clipboard()->mimeData( QClipboard::Clipboard ); + } -bool Clipboard::hasFormat( MimeType mT ) -{ - return getMimeData()->hasFormat( mimeType( mT ) ); -} + bool hasFormat( MimeType mT ) + { + return getMimeData()->hasFormat( mimeType( mT ) ); + } -void Clipboard::copyString( const QString & str, MimeType mT ) -{ - QMimeData *content = new QMimeData; + void copyString( const QString & str, MimeType mT ) + { + QMimeData *content = new QMimeData; - content->setData( mimeType( mT ), str.toUtf8() ); - QApplication::clipboard()->setMimeData( content, QClipboard::Clipboard ); -} + content->setData( mimeType( mT ), str.toUtf8() ); + QApplication::clipboard()->setMimeData( content, QClipboard::Clipboard ); + } -QString Clipboard::getString( MimeType mT ) -{ - return QString( getMimeData()->data( mimeType( mT ) ) ); -} + QString getString( MimeType mT ) + { + return QString( getMimeData()->data( mimeType( mT ) ) ); + } -void Clipboard::copyStringPair( const QString & key, const QString & value ) -{ - QString finalString = key + ":" + value; + void copyStringPair( const QString & key, const QString & value ) + { + QString finalString = key + ":" + value; - QMimeData *content = new QMimeData; - content->setData( mimeType( MimeType::StringPair ), finalString.toUtf8() ); - QApplication::clipboard()->setMimeData( content, QClipboard::Clipboard ); -} + QMimeData *content = new QMimeData; + content->setData( mimeType( MimeType::StringPair ), finalString.toUtf8() ); + QApplication::clipboard()->setMimeData( content, QClipboard::Clipboard ); + } -QString Clipboard::decodeKey( const QMimeData * mimeData ) -{ - return( QString::fromUtf8( mimeData->data( mimeType( MimeType::StringPair ) ) ).section( ':', 0, 0 ) ); -} + QString decodeKey( const QMimeData * mimeData ) + { + return( QString::fromUtf8( mimeData->data( mimeType( MimeType::StringPair ) ) ).section( ':', 0, 0 ) ); + } -QString Clipboard::decodeValue( const QMimeData * mimeData ) -{ - return( QString::fromUtf8( mimeData->data( mimeType( MimeType::StringPair ) ) ).section( ':', 1, -1 ) ); + QString decodeValue( const QMimeData * mimeData ) + { + return( QString::fromUtf8( mimeData->data( mimeType( MimeType::StringPair ) ) ).section( ':', 1, -1 ) ); + } } diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 7ed832fb220..1a62d676cd7 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -1216,11 +1216,14 @@ void TrackContentObjectView::remove( QVector tcovs ) void TrackContentObjectView::copy( QVector tcovs ) { + // For copyStringPair() + using namespace Clipboard; + // Write the TCOs to a DataFile for copying DataFile dataFile = createTCODataFiles( tcovs ); // Copy the TCO type as a key and the TCO data file to the clipboard - Clipboard::copyStringPair( QString( "tco_%1" ).arg( m_tco->getTrack()->type() ), + copyStringPair( QString( "tco_%1" ).arg( m_tco->getTrack()->type() ), dataFile.toString() ); } @@ -1235,12 +1238,15 @@ void TrackContentObjectView::cut( QVector tcovs ) void TrackContentObjectView::paste() { + // For getMimeData() + using namespace Clipboard; + // If possible, paste the selection on the MidiTime of the selected Track and remove it MidiTime tcoPos = MidiTime( m_tco->startPosition() ); TrackContentWidget *tcw = getTrackView()->getTrackContentWidget(); - if( tcw->pasteSelection( tcoPos, Clipboard::getMimeData() ) ) + if( tcw->pasteSelection( tcoPos, getMimeData() ) ) { // If we succeed on the paste we delete the TCO we pasted on remove(); @@ -1641,9 +1647,12 @@ bool TrackContentWidget::canPasteSelection( MidiTime tcoPos, const QDropEvent* d // Overloaded method to make it possible to call this method without a Drag&Drop event bool TrackContentWidget::canPasteSelection( MidiTime tcoPos, const QMimeData* md , bool allowSameBar ) { + // For decodeKey() and decodeValue() + using namespace Clipboard; + Track * t = getTrack(); - QString type = Clipboard::decodeKey( md ); - QString value = Clipboard::decodeValue( md ); + QString type = decodeKey( md ); + QString value = decodeValue( md ); // We can only paste into tracks of the same type if( type != ( "tco_" + QString::number( t->type() ) ) || @@ -1727,14 +1736,17 @@ bool TrackContentWidget::pasteSelection( MidiTime tcoPos, QDropEvent * de ) // Overloaded method so we can call it without a Drag&Drop event bool TrackContentWidget::pasteSelection( MidiTime tcoPos, const QMimeData * md, bool skipSafetyCheck ) { + // For decodeKey() and decodeValue() + using namespace Clipboard; + // When canPasteSelection was already called before, skipSafetyCheck will skip this if( !skipSafetyCheck && canPasteSelection( tcoPos, md ) == false ) { return false; } - QString type = Clipboard::decodeKey( md ); - QString value = Clipboard::decodeValue( md ); + QString type = decodeKey( md ); + QString value = decodeValue( md ); getTrack()->addJournalCheckPoint(); @@ -1928,6 +1940,9 @@ MidiTime TrackContentWidget::endPosition( const MidiTime & posStart ) void TrackContentWidget::contextMenuEvent( QContextMenuEvent * cme ) { + // For hasFormat(), MimeType enum class and getMimeData() + using namespace Clipboard; + if( cme->modifiers() ) { return; @@ -1935,7 +1950,7 @@ void TrackContentWidget::contextMenuEvent( QContextMenuEvent * cme ) // If we don't have TCO data in the clipboard there's no need to create this menu // since "paste" is the only action at the moment. - if( ! Clipboard::hasFormat( Clipboard::MimeType::StringPair ) ) + if( ! hasFormat( MimeType::StringPair ) ) { return; } @@ -1944,20 +1959,23 @@ void TrackContentWidget::contextMenuEvent( QContextMenuEvent * cme ) QAction *pasteA = contextMenu.addAction( embed::getIconPixmap( "edit_paste" ), tr( "Paste" ), [this, cme](){ contextMenuAction( cme, Paste ); } ); // If we can't paste in the current TCW for some reason, disable the action so the user knows - pasteA->setEnabled( canPasteSelection( getPosition( cme->x() ), Clipboard::getMimeData() ) ? true : false ); + pasteA->setEnabled( canPasteSelection( getPosition( cme->x() ), getMimeData() ) ? true : false ); contextMenu.exec( QCursor::pos() ); } void TrackContentWidget::contextMenuAction( QContextMenuEvent * cme, ContextMenuAction action ) { + // For getMimeData() + using namespace Clipboard; + switch( action ) { case Paste: // Paste the selection on the MidiTime of the context menu event MidiTime tcoPos = getPosition( cme->x() ); - pasteSelection( tcoPos, Clipboard::getMimeData() ); + pasteSelection( tcoPos, getMimeData() ); break; } } diff --git a/src/gui/AutomatableModelView.cpp b/src/gui/AutomatableModelView.cpp index d1c053245de..ca8b1a015c2 100644 --- a/src/gui/AutomatableModelView.cpp +++ b/src/gui/AutomatableModelView.cpp @@ -242,7 +242,10 @@ void AutomatableModelViewSlots::unlinkAllModels() void AutomatableModelViewSlots::copyToClipboard() { - Clipboard::copyString( QString::number(m_amv->value()), Clipboard::MimeType::Default ); + // For copyString() and MimeType enum class + using namespace Clipboard; + + copyString( QString::number(m_amv->value()), MimeType::Default ); } void AutomatableModelViewSlots::pasteFromClipboard() @@ -258,6 +261,9 @@ void AutomatableModelViewSlots::pasteFromClipboard() /// Attempt to parse a float from the clipboard static float floatFromClipboard(bool* ok) { - return Clipboard::getString( Clipboard::MimeType::Default ).toFloat(ok); + // For getString() and MimeType enum class + using namespace Clipboard; + + return getString( MimeType::Default ).toFloat(ok); } diff --git a/src/gui/StringPairDrag.cpp b/src/gui/StringPairDrag.cpp index bc28a3f9dc9..b08f4adc5f6 100644 --- a/src/gui/StringPairDrag.cpp +++ b/src/gui/StringPairDrag.cpp @@ -39,6 +39,9 @@ StringPairDrag::StringPairDrag( const QString & _key, const QString & _value, const QPixmap & _icon, QWidget * _w ) : QDrag( _w ) { + // For mimeType() and MimeType enum class + using namespace Clipboard; + if( _icon.isNull() && _w ) { setPixmap( _w->grab().scaled( @@ -52,7 +55,7 @@ StringPairDrag::StringPairDrag( const QString & _key, const QString & _value, } QString txt = _key + ":" + _value; QMimeData * m = new QMimeData(); - m->setData( Clipboard::mimeType( Clipboard::MimeType::StringPair ), txt.toUtf8() ); + m->setData( mimeType( MimeType::StringPair ), txt.toUtf8() ); setMimeData( m ); exec( Qt::LinkAction, Qt::LinkAction ); } @@ -76,11 +79,14 @@ StringPairDrag::~StringPairDrag() bool StringPairDrag::processDragEnterEvent( QDragEnterEvent * _dee, const QString & _allowed_keys ) { - if( !_dee->mimeData()->hasFormat( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ) ) + // For mimeType() and MimeType enum class + using namespace Clipboard; + + if( !_dee->mimeData()->hasFormat( mimeType( MimeType::StringPair ) ) ) { return( false ); } - QString txt = _dee->mimeData()->data( Clipboard::mimeType( Clipboard::MimeType::StringPair ) ); + QString txt = _dee->mimeData()->data( mimeType( MimeType::StringPair ) ); if( _allowed_keys.split( ',' ).contains( txt.section( ':', 0, 0 ) ) ) { _dee->acceptProposedAction(); diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index e3d0bd59a63..adfc419de85 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -3885,6 +3885,9 @@ void PianoRoll::updateYScroll() void PianoRoll::copyToClipboard( const NoteVector & notes ) const { + // For copyString() and MimeType enum class + using namespace Clipboard; + DataFile dataFile( DataFile::ClipboardData ); QDomElement note_list = dataFile.createElement( "note-list" ); dataFile.content().appendChild( note_list ); @@ -3897,7 +3900,7 @@ void PianoRoll::copyToClipboard( const NoteVector & notes ) const clip_note.saveState( dataFile, note_list ); } - Clipboard::copyString( dataFile.toString(), Clipboard::MimeType::Default ); + copyString( dataFile.toString(), MimeType::Default ); } @@ -3950,12 +3953,15 @@ void PianoRoll::cutSelectedNotes() void PianoRoll::pasteNotes() { + // For getString() and MimeType enum class + using namespace Clipboard; + if( ! hasValidPattern() ) { return; } - QString value = Clipboard::getString( Clipboard::MimeType::Default ); + QString value = getString( MimeType::Default ); if( ! value.isEmpty() ) {