r22677 by jghali - #15402: accidentally pasting scribus object in story editor pastes bunch of XML in plain text

scribus-commit scribus-commit at lists.scribus.net
Mon Sep 10 16:10:02 UTC 2018


Author: jghali
Date: Mon Sep 10 16:10:02 2018
New Revision: 22677

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22677
Log:
#15402: accidentally pasting scribus object in story editor pastes bunch of XML in plain text

Modified:
    trunk/Scribus/scribus/scmimedata.cpp
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/ui/storyeditor.cpp

Modified: trunk/Scribus/scribus/scmimedata.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22677&path=/trunk/Scribus/scribus/scmimedata.cpp
==============================================================================
--- trunk/Scribus/scribus/scmimedata.cpp	(original)
+++ trunk/Scribus/scribus/scmimedata.cpp	Mon Sep 10 16:10:02 2018
@@ -18,6 +18,12 @@
 #include <QApplication>
 #include <QClipboard>
 #include <QMimeData>
+
+// Define to 1 if you need to debug data contained in ScElemMimeData.
+// This will have the effect of enabling the pasting of stored data
+// in any text editor. Leave defined to 0 otherwise as this may trigger
+// unwanted pasting of text in story editor (#15402). 
+#define DEBUG_SCELEMMIMEDATA 0
 
 const QString ScMimeData::ScribusElemMimeType     = "application/x-scribus-elem";
 const QString ScMimeData::ScribusFragmentMimeType = "application/x-scribus-fragment";
@@ -87,7 +93,7 @@
 
 QString ScMimeData::clipboardKnownDataExt()
 {
-	QString ext = "";
+	QString ext;
 	const QMimeData* mimeData = QApplication::clipboard()->mimeData();
 	if (mimeData)
 	{
@@ -103,7 +109,7 @@
 
 QByteArray ScMimeData::clipboardKnownDataData()
 {
-	QByteArray data = "";
+	QByteArray data;
 	const QMimeData* mimeData = QApplication::clipboard()->mimeData();
 	if (mimeData)
 	{
@@ -141,31 +147,39 @@
 
 ScElemMimeData::ScElemMimeData()
 {
-	m_formats << "application/x-scribus-elem" << "text/plain";
+	m_formats << ScMimeData::ScribusElemMimeType;
+#if DEBUG_SCELEMMIMEDATA
+	m_formats << "text/plain";
+#endif 
 }
 
 bool ScElemMimeData::hasFormat (const QString & mimeType) const
 {
-//	bool hasFmt = false;
 	if (mimeType == ScMimeData::ScribusElemMimeType)
 	{
-		if (!m_scribusElemData.isEmpty())
-		{
-			QString elemtag = "SCRIBUSELEM";
-			return (m_scribusElemData.lastIndexOf(elemtag, 50 + elemtag.length()) >= 0);
-		}
+		if (m_scribusElemData.isEmpty())
+			return false;
+		QString elemtag = "SCRIBUSELEM";
+		return (m_scribusElemData.lastIndexOf(elemtag, 50 + elemtag.length()) >= 0);
 	}
-	else if (mimeType == "text/plain")
-		return true;
+#if DEBUG_SCELEMMIMEDATA
+	if (mimeType == "text/plain")
+		return (!m_scribusElemData.isEmpty());
+#endif
 	return QMimeData::hasFormat(mimeType);
 }
 
 QVariant ScElemMimeData::retrieveData (const QString &mimeType, QVariant::Type type) const
 {
-	QVariant variant;
 	if (mimeType == ScMimeData::ScribusElemMimeType)
-		variant = QVariant(m_scribusElemData);
+	{
+		if (m_scribusElemData.isEmpty())
+			return QVariant();
+		return QVariant(m_scribusElemData);
+	}
+#if DEBUG_SCELEMMIMEDATA
 	if (mimeType == "text/plain")
-		variant = QVariant(m_scribusElemData);
-	return variant;
+		return QVariant(m_scribusElemData);
+#endif
+	return QVariant();
 }

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22677&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Mon Sep 10 16:10:02 2018
@@ -4616,7 +4616,6 @@
 		}
 		ScElemMimeData* mimeData = new ScElemMimeData();
 		mimeData->setScribusElem(BufferS);
-		mimeData->setText(BufferS);
 		QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
 		for (int i=0; i < doc->m_Selection->count(); ++i)
 		{
@@ -4694,7 +4693,6 @@
 			}
 			ScElemMimeData* mimeData = new ScElemMimeData();
 			mimeData->setScribusElem(BufferS);
-			mimeData->setText(BufferS);
 			QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
 		}
 		else

Modified: trunk/Scribus/scribus/ui/storyeditor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22677&path=/trunk/Scribus/scribus/ui/storyeditor.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/storyeditor.cpp	(original)
+++ trunk/Scribus/scribus/ui/storyeditor.cpp	Mon Sep 10 16:10:02 2018
@@ -2147,8 +2147,9 @@
 		Editor->clear();
 		setWindowTitle( tr( "Story Editor" ));
 	}
-	if (!QApplication::clipboard()->text(QClipboard::Clipboard).isNull())
-		seActions["editPaste"]->setEnabled(true);
+
+	QString clipboardText = QApplication::clipboard()->text(QClipboard::Clipboard);
+	seActions["editPaste"]->setEnabled(!clipboardText.isEmpty());
 }
 
 void StoryEditor::setSpellActive(bool ssa)




More information about the scribus-commit mailing list