forked from qt-creator/qt-creator
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:
@@ -50,6 +50,7 @@
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <timelineactions.h>
|
||||
|
||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||
|
||||
@@ -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<Model> pasteModel(DesignDocumentView::pasteToModel());
|
||||
|
||||
if (!pasteModel)
|
||||
|
||||
@@ -33,13 +33,12 @@
|
||||
#include <designdocumentview.h>
|
||||
#include <nodelistproperty.h>
|
||||
#include <nodemetainfo.h>
|
||||
#include <rewritertransaction.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <variantproperty.h>
|
||||
#include <qmldesignerplugin.h>
|
||||
#include <qmlobjectnode.h>
|
||||
#include <qmltimelinekeyframegroup.h>
|
||||
#include <QClipboard>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
@@ -291,30 +290,8 @@ void TimelineActions::pasteKeyframes(AbstractView *timelineView, const QmlTimeli
|
||||
|
||||
bool TimelineActions::clipboardContainsKeyframes()
|
||||
{
|
||||
QScopedPointer<Model> 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
|
||||
|
||||
Reference in New Issue
Block a user