MCPcopy Create free account
hub / github.com/KDE/labplot / paste

Method paste

src/backend/core/AbstractAspect.cpp:780–841  ·  view source on GitHub ↗

! * in case the clipboard containts a LabPlot's specific copy&paste content, * this function deserializes the XML string and adds the created aspect as * a child to the current aspect ("paste"). */

Source from the content-addressed store, hash-verified

778 * a child to the current aspect ("paste").
779 */
780void AbstractAspect::paste(bool duplicate, int index) {
781 const QClipboard* clipboard = QApplication::clipboard();
782 const QMimeData* mimeData = clipboard->mimeData();
783 if (!mimeData->hasText())
784 return;
785
786 const QString& xml = clipboard->text();
787 if (!xml.startsWith(QLatin1String("<?xml version=\"1.0\"?><!DOCTYPE LabPlotCopyPasteXML>")))
788 return;
789
790 WAIT_CURSOR;
791 AbstractAspect* aspect = nullptr;
792 XmlStreamReader reader(xml);
793 while (!reader.atEnd()) {
794 reader.readNext();
795
796 if (!reader.isStartElement())
797 continue;
798
799 if (reader.name() == QLatin1String("type")) {
800 auto attribs = reader.attributes();
801 auto type = static_cast<AspectType>(attribs.value(QLatin1String("value")).toInt());
802 if (type != AspectType::AbstractAspect)
803 aspect = AspectFactory::createAspect(type, this);
804 } else {
805 if (aspect) {
806 aspect->setPasted(true);
807 aspect->setIsLoading(true);
808 aspect->load(&reader, false);
809 break;
810 }
811 }
812 }
813
814 if (aspect) {
815 if (!duplicate)
816 beginMacro(i18n("%1: pasted '%2'", name(), aspect->name()));
817 else {
818 beginMacro(i18n("%1: duplicated '%2'", name(), aspect->name()));
819 aspect->setName(i18n("Copy of '%1'", aspect->name()));
820 }
821
822 if (aspect->type() != AspectType::CartesianPlotLegend) {
823 setPasted(true);
824 insertChild(aspect, index);
825 setPasted(false);
826 } else {
827 // special handling for the legend since only one single
828 // legend object is allowed per plot
829 auto* plot = static_cast<CartesianPlot*>(this);
830 auto* legend = static_cast<CartesianPlotLegend*>(aspect);
831 plot->addLegend(legend);
832 }
833
834 project()->restorePointers(aspect);
835 aspect->setIsLoading(false); // set back to false before calling retransformElements()
836 project()->retransformElements(aspect);
837 aspect->setPasted(false);

Callers 9

keyPressEventMethod · 0.80
keyPressEventMethod · 0.80
duplicateMethod · 0.80
axisLineMethod · 0.80
TestCopyPastePlotMethod · 0.80
copyPasteMethod · 0.80

Calls 12

atEndMethod · 0.80
setPastedMethod · 0.80
setIsLoadingMethod · 0.80
addLegendMethod · 0.80
retransformElementsMethod · 0.80
textMethod · 0.45
nameMethod · 0.45
valueMethod · 0.45
loadMethod · 0.45
setNameMethod · 0.45
typeMethod · 0.45
restorePointersMethod · 0.45

Tested by

no test coverage detected