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 <miikka.heikkinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Mahmoud Badri
2020-11-07 22:18:57 +02:00
parent 6514e1b866
commit 91ad88205a
2 changed files with 7 additions and 26 deletions

View File

@@ -50,6 +50,7 @@
#include <coreplugin/idocument.h> #include <coreplugin/idocument.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <timelineactions.h>
#include <qmljs/qmljsmodelmanagerinterface.h> #include <qmljs/qmljsmodelmanagerinterface.h>
@@ -473,6 +474,9 @@ static void scatterItem(const ModelNode &pastedNode, const ModelNode &targetNode
void DesignDocument::paste() void DesignDocument::paste()
{ {
if (TimelineActions::clipboardContainsKeyframes()) // pasting keyframes is handled in TimelineView
return;
QScopedPointer<Model> pasteModel(DesignDocumentView::pasteToModel()); QScopedPointer<Model> pasteModel(DesignDocumentView::pasteToModel());
if (!pasteModel) if (!pasteModel)

View File

@@ -33,13 +33,12 @@
#include <designdocumentview.h> #include <designdocumentview.h>
#include <nodelistproperty.h> #include <nodelistproperty.h>
#include <nodemetainfo.h> #include <nodemetainfo.h>
#include <rewritertransaction.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <variantproperty.h> #include <variantproperty.h>
#include <qmldesignerplugin.h>
#include <qmlobjectnode.h> #include <qmlobjectnode.h>
#include <qmltimelinekeyframegroup.h> #include <qmltimelinekeyframegroup.h>
#include <QClipboard>
namespace QmlDesigner { namespace QmlDesigner {
@@ -291,30 +290,8 @@ void TimelineActions::pasteKeyframes(AbstractView *timelineView, const QmlTimeli
bool TimelineActions::clipboardContainsKeyframes() bool TimelineActions::clipboardContainsKeyframes()
{ {
QScopedPointer<Model> pasteModel(DesignDocumentView::pasteToModel()); QRegularExpression rxp("\\bKeyframe\\s*{.*}", QRegularExpression::DotMatchesEverythingOption);
return rxp.match(QApplication::clipboard()->text()).hasMatch();
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;
} }
} // namespace QmlDesigner } // namespace QmlDesigner