[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [labplot] src/backend/datasources/projects: [Origin import] better parsing of the legend title.
From:       Alexander Semke <null () kde ! org>
Date:       2018-03-31 19:17:14
Message-ID: E1f2M02-0005Ss-EQ () code ! kde ! org
[Download RAW message or body]

Git commit 279a4d51dbe6b50994203b47b25026d481df2628 by Alexander Semke.
Committed on 31/03/2018 at 19:16.
Pushed by asemke into branch 'master'.

[Origin import] better parsing of the legend title.

M  +25   -6    src/backend/datasources/projects/OriginProjectParser.cpp

https://commits.kde.org/labplot/279a4d51dbe6b50994203b47b25026d481df2628

diff --git a/src/backend/datasources/projects/OriginProjectParser.cpp \
b/src/backend/datasources/projects/OriginProjectParser.cpp index 1f0f863b..2225b134 \
                100644
--- a/src/backend/datasources/projects/OriginProjectParser.cpp
+++ b/src/backend/datasources/projects/OriginProjectParser.cpp
@@ -1077,15 +1077,34 @@ bool OriginProjectParser::loadWorksheet(Worksheet* worksheet, \
bool preview) {  
 			//add legend if available
 			const Origin::TextBox& originLegend = layer.legend;
-			QString legendText = \
                parseOriginText(QString::fromLatin1(originLegend.text.c_str()));
-			DEBUG(" parsed legend text = " << legendText.toStdString());
+			const QString& legendText = QString::fromLatin1(originLegend.text.c_str());
+			DEBUG(" legend text = " << legendText.toStdString());
 			if (!originLegend.text.empty()) {
+				CartesianPlotLegend* legend = new CartesianPlotLegend(plot, i18n("legend"));
+
+				//Origin's legend uses "\l(...)" or "\L(...)" string to format the legend symbol
+				// and "%(...) to format the legend text for each curve
+				//s. a. https://www.originlab.com/doc/Origin-Help/Legend-ManualControl
+				//the text before these formatting tags, if available, is interpreted as the \
legend title +				QString legendTitle;
+
+				//search for the first occurance of the legend symbol substring
+				int index = legendText.indexOf(QLatin1String("\\l("), 0, Qt::CaseInsensitive);
+				if (index != -1)
+					legendTitle = legendText.left(index);
+				else {
+					//check legend text
+					index = legendText.indexOf(QLatin1String("%("));
+					if (index != -1)
+						legendTitle = legendText.left(index);
+				}
 
-				//CartesianPlotLegend* legend = new CartesianPlotLegend(plot, i18n("legend"));
-				QString legendTitle = legendText.left(legendText.indexOf("\\c{1}") - 1);
 				legendTitle = legendTitle.trimmed();
-				DEBUG(" title = " << legendTitle.toStdString());
-				CartesianPlotLegend* legend = new CartesianPlotLegend(plot, legendTitle);
+				if (!legendTitle.isEmpty())
+					legendTitle = parseOriginText(legendTitle);
+
+				DEBUG(" legend title = " << legendTitle.toStdString());
+				legend->title()->setText(legendTitle);
 
 				const Origin::Color& originColor = originLegend.color;
 				if (originColor.type == Origin::Color::None)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic