From 91ad88205a231d88c0af6678af6dc5377b0d98d0 Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Sat, 7 Nov 2020 22:18:57 +0200 Subject: [PATCH] Optimize checking keyframes in clipboard Old implementation is expensive (~200ms) and this method is called frequently. Also prevent pasting keyframes in the FormEditor. Change-Id: Id083b553231893be31c7aab1d0da1809529316c8 Reviewed-by: Miikka Heikkinen Reviewed-by: Thomas Hartmann --- .../components/integration/designdocument.cpp | 4 +++ .../timelineeditor/timelineactions.cpp | 29 ++----------------- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/plugins/qmldesigner/components/integration/designdocument.cpp b/src/plugins/qmldesigner/components/integration/designdocument.cpp index 2b567a8e690..7f83f652e75 100644 --- a/src/plugins/qmldesigner/components/integration/designdocument.cpp +++ b/src/plugins/qmldesigner/components/integration/designdocument.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include @@ -473,6 +474,9 @@ static void scatterItem(const ModelNode &pastedNode, const ModelNode &targetNode void DesignDocument::paste() { + if (TimelineActions::clipboardContainsKeyframes()) // pasting keyframes is handled in TimelineView + return; + QScopedPointer pasteModel(DesignDocumentView::pasteToModel()); if (!pasteModel) diff --git a/src/plugins/qmldesigner/components/timelineeditor/timelineactions.cpp b/src/plugins/qmldesigner/components/timelineeditor/timelineactions.cpp index c9271e490c9..74a543ae9d8 100644 --- a/src/plugins/qmldesigner/components/timelineeditor/timelineactions.cpp +++ b/src/plugins/qmldesigner/components/timelineeditor/timelineactions.cpp @@ -33,13 +33,12 @@ #include #include #include -#include #include #include #include -#include #include #include +#include namespace QmlDesigner { @@ -291,30 +290,8 @@ void TimelineActions::pasteKeyframes(AbstractView *timelineView, const QmlTimeli bool TimelineActions::clipboardContainsKeyframes() { - QScopedPointer pasteModel(DesignDocumentView::pasteToModel()); - - if (!pasteModel) - return false; - - DesignDocumentView view; - pasteModel->attachView(&view); - - if (!view.rootModelNode().isValid()) - return false; - - ModelNode rootNode = view.rootModelNode(); - - if (!rootNode.hasAnySubModelNodes()) - return false; - - //Sanity check - if (!QmlTimelineKeyframeGroup::checkKeyframesType(rootNode)) { - for (const ModelNode &node : rootNode.directSubModelNodes()) - if (!QmlTimelineKeyframeGroup::checkKeyframesType(node)) - return false; - } - - return true; + QRegularExpression rxp("\\bKeyframe\\s*{.*}", QRegularExpression::DotMatchesEverythingOption); + return rxp.match(QApplication::clipboard()->text()).hasMatch(); } } // namespace QmlDesigner