xlsxdrawinganchor.cpp 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. // xlsxdrawinganchor.cpp
  2. #include <QtGlobal>
  3. #include <QDebug>
  4. #include <QXmlStreamReader>
  5. #include <QXmlStreamWriter>
  6. #include <QBuffer>
  7. #include <QDir>
  8. #include "xlsxdrawinganchor_p.h"
  9. #include "xlsxdrawing_p.h"
  10. #include "xlsxmediafile_p.h"
  11. #include "xlsxchart.h"
  12. #include "xlsxworkbook.h"
  13. #include "xlsxutility_p.h"
  14. QT_BEGIN_NAMESPACE_XLSX
  15. /*
  16. The vertices that define the position of a graphical object
  17. within the worksheet in pixels.
  18. +------------+------------+
  19. | A | B |
  20. +-----+------------+------------+
  21. | |(x1,y1) | |
  22. | 1 |(A1)._______|______ |
  23. | | | | |
  24. | | | | |
  25. +-----+----| OBJECT |-----+
  26. | | | | |
  27. | 2 | |______________. |
  28. | | | (B2)|
  29. | | | (x2,y2)|
  30. +---- +------------+------------+
  31. Example of an object that covers some of the area from cell A1 to B2.
  32. Based on the width and height of the object we need to calculate 8 vars:
  33. col_start, row_start, col_end, row_end, x1, y1, x2, y2.
  34. We also calculate the absolute x and y position of the top left vertex of
  35. the object. This is required for images.
  36. The width and height of the cells that the object occupies can be
  37. variable and have to be taken into account.
  38. */
  39. //anchor
  40. DrawingAnchor::DrawingAnchor(Drawing *drawing, ObjectType objectType)
  41. :m_drawing(drawing), m_objectType(objectType)
  42. {
  43. m_drawing->anchors.append(this);
  44. m_id = m_drawing->anchors.size();//must be unique in one drawing{x}.xml file.
  45. }
  46. DrawingAnchor::~DrawingAnchor()
  47. {
  48. }
  49. void DrawingAnchor::setObjectPicture(const QImage &img)
  50. {
  51. QByteArray ba;
  52. QBuffer buffer(&ba);
  53. buffer.open(QIODevice::WriteOnly);
  54. img.save(&buffer, "PNG");
  55. m_pictureFile = QSharedPointer<MediaFile>(new MediaFile(ba, QStringLiteral("png"), QStringLiteral("image/png")));
  56. m_drawing->workbook->addMediaFile(m_pictureFile);
  57. m_objectType = Picture;
  58. }
  59. bool DrawingAnchor::getObjectPicture(QImage &img)
  60. {
  61. if ( m_pictureFile == nullptr )
  62. return false;
  63. bool ret = img.loadFromData( m_pictureFile->contents() );
  64. return ret;
  65. }
  66. //{{ liufeijin
  67. void DrawingAnchor::setObjectShape(const QImage &img)
  68. {
  69. QByteArray ba;
  70. QBuffer buffer(&ba);
  71. buffer.open(QIODevice::WriteOnly);
  72. img.save(&buffer, "PNG");
  73. m_pictureFile = QSharedPointer<MediaFile>(new MediaFile(ba, QStringLiteral("png"), QStringLiteral("image/png")));
  74. m_drawing->workbook->addMediaFile(m_pictureFile);
  75. m_objectType = Shape;
  76. }
  77. //}}
  78. void DrawingAnchor::setObjectGraphicFrame(QSharedPointer<Chart> chart)
  79. {
  80. m_chartFile = chart;
  81. m_drawing->workbook->addChartFile(chart);
  82. m_objectType = GraphicFrame;
  83. }
  84. int DrawingAnchor::row()
  85. {
  86. return -1;
  87. }
  88. int DrawingAnchor::col()
  89. {
  90. return -1;
  91. }
  92. QPoint DrawingAnchor::loadXmlPos(QXmlStreamReader &reader)
  93. {
  94. Q_ASSERT(reader.name() == QLatin1String("pos"));
  95. QPoint pos;
  96. QXmlStreamAttributes attrs = reader.attributes();
  97. pos.setX(attrs.value(QLatin1String("x")).toString().toInt());
  98. pos.setY(attrs.value(QLatin1String("y")).toString().toInt());
  99. return pos;
  100. }
  101. QSize DrawingAnchor::loadXmlExt(QXmlStreamReader &reader)
  102. {
  103. Q_ASSERT(reader.name() == QLatin1String("ext"));
  104. QSize size;
  105. QXmlStreamAttributes attrs = reader.attributes();
  106. size.setWidth(attrs.value(QLatin1String("cx")).toString().toInt());
  107. size.setHeight(attrs.value(QLatin1String("cy")).toString().toInt());
  108. return size;
  109. }
  110. XlsxMarker DrawingAnchor::loadXmlMarker(QXmlStreamReader &reader, const QString &node)
  111. {
  112. Q_ASSERT(reader.name() == node);
  113. int col = 0;
  114. int colOffset = 0;
  115. int row = 0;
  116. int rowOffset = 0;
  117. while (!reader.atEnd())
  118. {
  119. reader.readNextStartElement();
  120. if (reader.tokenType() == QXmlStreamReader::StartElement)
  121. {
  122. if (reader.name() == QLatin1String("col"))
  123. {
  124. col = reader.readElementText().toInt();
  125. }
  126. else if (reader.name() == QLatin1String("colOff"))
  127. {
  128. colOffset = reader.readElementText().toInt();
  129. }
  130. else if (reader.name() == QLatin1String("row"))
  131. {
  132. row = reader.readElementText().toInt();
  133. }
  134. else if (reader.name() == QLatin1String("rowOff"))
  135. {
  136. rowOffset = reader.readElementText().toInt();
  137. }
  138. }
  139. else if (reader.tokenType() == QXmlStreamReader::EndElement
  140. && reader.name() == node)
  141. {
  142. break;
  143. }
  144. }
  145. return XlsxMarker(row, col, rowOffset, colOffset);
  146. }
  147. void DrawingAnchor::loadXmlObject(QXmlStreamReader &reader)
  148. {
  149. /*
  150. <xsd:group name="EG_ObjectChoices">
  151. <xsd:sequence>
  152. <xsd:choice minOccurs="1" maxOccurs="1">
  153. <xsd:element name="sp" type="CT_Shape"/>
  154. <xsd:element name="grpSp" type="CT_GroupShape"/>
  155. <xsd:element name="graphicFrame" type="CT_GraphicalObjectFrame"/>
  156. <xsd:element name="cxnSp" type="CT_Connector"/>
  157. <xsd:element name="pic" type="CT_Picture"/>
  158. <xsd:element name="contentPart" type="CT_Rel"/>
  159. </xsd:choice>
  160. </xsd:sequence>
  161. </xsd:group>
  162. */
  163. if (reader.name() == QLatin1String("sp")) // <xsd:element name="sp" type="CT_Shape"/>
  164. {
  165. // Shape
  166. m_objectType = Shape;
  167. //{{ liufeijin
  168. sp_textlink = reader.attributes().value(QLatin1String("textlink")).toString();
  169. sp_macro = reader.attributes().value(QLatin1String("macro")).toString();
  170. //}}
  171. // <xsd:attribute name="macro" type="xsd:string" use="optional"/>
  172. // <xsd:attribute name="textlink" type="xsd:string" use="optional"/>
  173. // <xsd:attribute name="fLocksText" type="xsd:boolean" use="optional" default="true"/>
  174. // <xsd:attribute name="fPublished" type="xsd:boolean" use="optional" default="false"/>
  175. loadXmlObjectShape(reader); // CT_Shape
  176. }
  177. else if (reader.name() == QLatin1String("grpSp")) // <xsd:element name="grpSp" type="CT_GroupShape"/>
  178. {
  179. //Group Shape
  180. m_objectType = GroupShape;
  181. loadXmlObjectGroupShape(reader);
  182. }
  183. else if (reader.name() == QLatin1String("graphicFrame")) // <xsd:element name="graphicFrame" type="CT_GraphicalObjectFrame"/>
  184. {
  185. //Graphic Frame
  186. m_objectType = GraphicFrame;
  187. loadXmlObjectGraphicFrame(reader);
  188. }
  189. else if (reader.name() == QLatin1String("cxnSp")) // <xsd:element name="cxnSp" type="CT_Connector"/>
  190. {
  191. //Connection Shape
  192. m_objectType = ConnectionShape;
  193. // {{ liufeijin
  194. cxnSp_macro = reader.attributes().value(QLatin1String("macro")).toString();
  195. // }}
  196. loadXmlObjectConnectionShape(reader);
  197. }
  198. else if (reader.name() == QLatin1String("pic")) // <xsd:element name="pic" type="CT_Picture"/>
  199. {
  200. // Picture
  201. m_objectType = Picture;
  202. loadXmlObjectPicture(reader);
  203. }
  204. else if (reader.name() == QLatin1String("contentPart")) // <xsd:element name="contentPart" type="CT_Rel"/>
  205. {
  206. // contentPart
  207. /// TODO:
  208. }
  209. }
  210. void DrawingAnchor::loadXmlObjectConnectionShape(QXmlStreamReader &reader)
  211. {
  212. Q_ASSERT(reader.name() == QLatin1String("cxnSp"));
  213. bool hasoffext=false;
  214. while (!reader.atEnd()) {
  215. reader.readNextStartElement();
  216. if (reader.tokenType() == QXmlStreamReader::StartElement) {
  217. if (reader.name() == QLatin1String("cNvPr")){
  218. xsp_cNvPR_name= reader.attributes().value(QLatin1String("name")).toString();
  219. xsp_cNvPR_id= reader.attributes().value(QLatin1String("id")).toString();
  220. }else if(reader.name() == QLatin1String("spPr")){
  221. xbwMode= reader.attributes().value(QLatin1String("bwMode")).toString();
  222. }else if(reader.name() == QLatin1String("xfrm")){
  223. cxnSp_filpV= reader.attributes().value(QLatin1String("flipV")).toString();
  224. }else if (reader.name() == QLatin1String("off")) {
  225. posTA = loadXmlPos(reader);
  226. hasoffext=true;
  227. } else if (reader.name() == QLatin1String("ext")&&hasoffext) {
  228. extTA = loadXmlExt(reader);
  229. hasoffext=false;
  230. }else if(reader.name() == QLatin1String("prstGeom")){
  231. xprstGeom_prst= reader.attributes().value(QLatin1String("prst")).toString().trimmed();
  232. }else if(reader.name() == QLatin1String("ln")){
  233. xIn_algn= reader.attributes().value(QLatin1String("algn")).toString().trimmed();
  234. xIn_cmpd= reader.attributes().value(QLatin1String("cmpd")).toString().trimmed();
  235. xIn_cap= reader.attributes().value(QLatin1String("cap")).toString().trimmed();
  236. xIn_w= reader.attributes().value(QLatin1String("w")).toString().trimmed();
  237. }else if(reader.name() == QLatin1String("headEnd")){
  238. x_headEnd_w= reader.attributes().value(QLatin1String("w")).toString().trimmed();
  239. x_headEnd_len= reader.attributes().value(QLatin1String("len")).toString().trimmed();
  240. x_headEnd_tyep= reader.attributes().value(QLatin1String("type")).toString().trimmed();
  241. }else if(reader.name() == QLatin1String("tailEnd")){
  242. x_tailEnd_w= reader.attributes().value(QLatin1String("w")).toString().trimmed();
  243. x_tailEnd_len= reader.attributes().value(QLatin1String("len")).toString().trimmed();
  244. x_tailEnd_tyep= reader.attributes().value(QLatin1String("type")).toString().trimmed();
  245. }else if(reader.name() == QLatin1String("lnRef")){
  246. Style_inref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
  247. reader.readNextStartElement();
  248. if (reader.tokenType() == QXmlStreamReader::StartElement) {
  249. if(reader.name() == QLatin1String("schemeClr")){
  250. Style_inref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed();
  251. }
  252. }
  253. }else if(reader.name() == QLatin1String("fillRef")){
  254. style_fillref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
  255. reader.readNextStartElement();
  256. if (reader.tokenType() == QXmlStreamReader::StartElement) {
  257. if(reader.name() == QLatin1String("schemeClr")){
  258. style_fillref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed();
  259. }
  260. }
  261. }else if(reader.name() == QLatin1String("effectRef")){
  262. style_effectref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
  263. reader.readNextStartElement();
  264. if (reader.tokenType() == QXmlStreamReader::StartElement) {
  265. if(reader.name() == QLatin1String("schemeClr")){
  266. style_effectref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed();
  267. }
  268. }
  269. }else if(reader.name() == QLatin1String("fontRef")){
  270. style_forntref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
  271. reader.readNextStartElement();
  272. if (reader.tokenType() == QXmlStreamReader::StartElement) {
  273. if(reader.name() == QLatin1String("schemeClr")){
  274. style_forntref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed();
  275. }
  276. }
  277. }
  278. } else if (reader.tokenType() == QXmlStreamReader::EndElement
  279. && reader.name() == QLatin1String("cxnSp")) {
  280. break;
  281. }
  282. }
  283. return;
  284. }
  285. void DrawingAnchor::loadXmlObjectGraphicFrame(QXmlStreamReader &reader)
  286. {
  287. Q_ASSERT(reader.name() == QLatin1String("graphicFrame"));
  288. while (!reader.atEnd()) {
  289. reader.readNextStartElement();
  290. if (reader.tokenType() == QXmlStreamReader::StartElement) {
  291. if (reader.name() == QLatin1String("chart")) {
  292. QString rId = reader.attributes().value(QLatin1String("r:id")).toString();
  293. QString name = m_drawing->relationships()->getRelationshipById(rId).target;
  294. QString str = *( splitPath(m_drawing->filePath()).begin() );
  295. str = str + QLatin1String("/");
  296. str = str + name;
  297. QString path = QDir::cleanPath(str);
  298. bool exist = false;
  299. QList<QSharedPointer<Chart> > cfs = m_drawing->workbook->chartFiles();
  300. for (int i=0; i<cfs.size(); ++i) {
  301. if (cfs[i]->filePath() == path) {
  302. //already exist
  303. exist = true;
  304. m_chartFile = cfs[i];
  305. }
  306. }
  307. if (!exist) {
  308. m_chartFile = QSharedPointer<Chart> (new Chart(m_drawing->sheet, Chart::F_LoadFromExists));
  309. m_chartFile->setFilePath(path);
  310. m_drawing->workbook->addChartFile(m_chartFile);
  311. }
  312. }
  313. } else if (reader.tokenType() == QXmlStreamReader::EndElement
  314. && reader.name() == QLatin1String("graphicFrame")) {
  315. break;
  316. }
  317. }
  318. return;
  319. }
  320. void DrawingAnchor::loadXmlObjectGroupShape(QXmlStreamReader &reader)
  321. {
  322. Q_UNUSED(reader)
  323. }
  324. void DrawingAnchor::loadXmlObjectPicture(QXmlStreamReader &reader)
  325. {
  326. Q_ASSERT(reader.name() == QLatin1String("pic"));
  327. while (!reader.atEnd()) {
  328. reader.readNextStartElement();
  329. if (reader.tokenType() == QXmlStreamReader::StartElement) {
  330. if (reader.name() == QLatin1String("blip")) {
  331. QString rId = reader.attributes().value(QLatin1String("r:embed")).toString();
  332. QString name = m_drawing->relationships()->getRelationshipById(rId).target;
  333. QString str = *( splitPath(m_drawing->filePath()).begin() );
  334. str = str + QLatin1String("/");
  335. str = str + name;
  336. QString path = QDir::cleanPath( str );
  337. bool exist = false;
  338. QList<QSharedPointer<MediaFile> > mfs = m_drawing->workbook->mediaFiles();
  339. for (int i=0; i<mfs.size(); ++i) {
  340. if (mfs[i]->fileName() == path) {
  341. //already exist
  342. exist = true;
  343. m_pictureFile = mfs[i];
  344. }
  345. }
  346. if (!exist) {
  347. m_pictureFile = QSharedPointer<MediaFile> (new MediaFile(path));
  348. m_drawing->workbook->addMediaFile(m_pictureFile, true);
  349. }
  350. }
  351. } else if (reader.tokenType() == QXmlStreamReader::EndElement
  352. && reader.name() == QLatin1String("pic")) {
  353. break;
  354. }
  355. }
  356. return;
  357. }
  358. void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader)
  359. {
  360. /*
  361. <xsd:complexType name="CT_Shape">
  362. <xsd:sequence>
  363. <xsd:element name="nvSpPr" type="CT_ShapeNonVisual" minOccurs="1" maxOccurs="1"/>
  364. <xsd:element name="spPr" type="a:CT_ShapeProperties" minOccurs="1" maxOccurs="1"/>
  365. <xsd:element name="style" type="a:CT_ShapeStyle" minOccurs="0" maxOccurs="1"/>
  366. <xsd:element name="txBody" type="a:CT_TextBody" minOccurs="0" maxOccurs="1"/>
  367. </xsd:sequence>
  368. <xsd:attribute name="macro" type="xsd:string" use="optional"/>
  369. <xsd:attribute name="textlink" type="xsd:string" use="optional"/>
  370. <xsd:attribute name="fLocksText" type="xsd:boolean" use="optional" default="true"/>
  371. <xsd:attribute name="fPublished" type="xsd:boolean" use="optional" default="false"/>
  372. </xsd:complexType>
  373. */
  374. /*
  375. <xsd:complexType name="CT_ShapeNonVisual">
  376. <xsd:sequence>
  377. <xsd:element name="cNvPr" type="a:CT_NonVisualDrawingProps" minOccurs="1" maxOccurs="1"/>
  378. <xsd:element name="cNvSpPr" type="a:CT_NonVisualDrawingShapeProps" minOccurs="1" maxOccurs="1"/>
  379. </xsd:sequence>
  380. </xsd:complexType>
  381. */
  382. Q_ASSERT(reader.name() == QLatin1String("sp"));
  383. bool hasoffext = false;
  384. while (!reader.atEnd())
  385. {
  386. reader.readNextStartElement();
  387. // qDebug() << __FUNCTION__ << reader.name().toString();
  388. if (reader.tokenType() == QXmlStreamReader::StartElement)
  389. {
  390. if (reader.name() == QLatin1String("nvSpPr"))
  391. {
  392. }
  393. else if (reader.name() == QLatin1String("spPr"))
  394. {
  395. }
  396. else if (reader.name() == QLatin1String("style"))
  397. {
  398. }
  399. else if (reader.name() == QLatin1String("txBody"))
  400. {
  401. }
  402. }
  403. else if (reader.tokenType() == QXmlStreamReader::EndElement
  404. && reader.name() == QLatin1String("sp"))
  405. {
  406. break;
  407. }
  408. }
  409. /*
  410. bool hasoffext = false;
  411. while (!reader.atEnd())
  412. {
  413. reader.readNextStartElement();
  414. // qDebug() << __FUNCTION__ << reader.name().toString();
  415. if (reader.tokenType() == QXmlStreamReader::StartElement)
  416. {
  417. if (reader.name() == QLatin1String("blip"))
  418. {
  419. QString rId;
  420. sp_blip_rembed= reader.attributes().value(QLatin1String("r:embed")).toString();
  421. sp_blip_cstate=reader.attributes().value(QLatin1String("cstate")).toString();
  422. rId=sp_blip_rembed;
  423. QString name = m_drawing->relationships()->getRelationshipById(rId).target;
  424. QString path = QDir::cleanPath(splitPath(m_drawing->filePath())[0] + QLatin1String("/") + name);
  425. bool exist = false;
  426. QList<QSharedPointer<MediaFile> > mfs = m_drawing->workbook->mediaFiles();
  427. for (int i=0; i<mfs.size(); ++i)
  428. {
  429. if (mfs[i]->fileName() == path)
  430. {
  431. //already exist
  432. exist = true;
  433. m_pictureFile = mfs[i];
  434. }
  435. }
  436. if (!exist) {
  437. m_pictureFile = QSharedPointer<MediaFile> (new MediaFile(path));
  438. m_drawing->workbook->addMediaFile(m_pictureFile, true);
  439. }
  440. }
  441. else if (reader.name() == QLatin1String("off"))
  442. {
  443. posTA = loadXmlPos(reader);
  444. hasoffext=true;
  445. }
  446. else if (reader.name() == QLatin1String("ext")&&hasoffext)
  447. {
  448. extTA = loadXmlExt(reader);
  449. hasoffext=false;
  450. }
  451. else if(reader.name() == QLatin1String("blipFill"))
  452. {
  453. // dev24 : fixed for old Qt 5
  454. rotWithShapeTA = reader.attributes().value(QLatin1String("rotWithShape")).toString().toInt();
  455. dpiTA = reader.attributes().value(QLatin1String("dpi")).toString().toInt();
  456. // rotWithShapeTA = reader.attributes().value(QLatin1String("rotWithShape")).toInt();
  457. // dpiTA = reader.attributes().value(QLatin1String("dpi")).toInt();
  458. }else if(reader.name() == QLatin1String("cNvPr"))
  459. {
  460. xsp_cNvPR_name= reader.attributes().value(QLatin1String("name")).toString();
  461. xsp_cNvPR_id= reader.attributes().value(QLatin1String("id")).toString();
  462. }
  463. else if(reader.name() == QLatin1String("spPr"))
  464. {
  465. xbwMode= reader.attributes().value(QLatin1String("bwMode")).toString();
  466. }
  467. else if(reader.name() == QLatin1String("prstGeom"))
  468. {
  469. xprstGeom_prst= reader.attributes().value(QLatin1String("prst")).toString();
  470. }
  471. else if(reader.name() == QLatin1String("ln"))
  472. {
  473. xIn_algn= reader.attributes().value(QLatin1String("algn")).toString();
  474. xIn_cmpd= reader.attributes().value(QLatin1String("cmpd")).toString();
  475. xIn_cap= reader.attributes().value(QLatin1String("cap")).toString();
  476. xIn_w= reader.attributes().value(QLatin1String("w")).toString();
  477. }
  478. else if(reader.name() == QLatin1String("headEnd"))
  479. {
  480. x_headEnd_w= reader.attributes().value(QLatin1String("w")).toString();
  481. x_headEnd_len= reader.attributes().value(QLatin1String("len")).toString();
  482. x_headEnd_tyep= reader.attributes().value(QLatin1String("type")).toString();
  483. }
  484. else if(reader.name() == QLatin1String("tailEnd"))
  485. {
  486. x_tailEnd_w= reader.attributes().value(QLatin1String("w")).toString();
  487. x_tailEnd_len= reader.attributes().value(QLatin1String("len")).toString();
  488. x_tailEnd_tyep= reader.attributes().value(QLatin1String("type")).toString();
  489. }
  490. else if(reader.name() == QLatin1String("lnRef"))
  491. {
  492. Style_inref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
  493. reader.readNextStartElement();
  494. if (reader.tokenType() == QXmlStreamReader::StartElement) {
  495. if(reader.name() == QLatin1String("schemeClr")){
  496. Style_inref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed();
  497. }
  498. }
  499. }
  500. else if(reader.name() == QLatin1String("fillRef"))
  501. {
  502. style_fillref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
  503. reader.readNextStartElement();
  504. if (reader.tokenType() == QXmlStreamReader::StartElement)
  505. {
  506. if(reader.name() == QLatin1String("schemeClr"))
  507. {
  508. style_fillref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed();
  509. }
  510. }
  511. }
  512. else if(reader.name() == QLatin1String("effectRef"))
  513. {
  514. style_effectref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
  515. reader.readNextStartElement();
  516. if (reader.tokenType() == QXmlStreamReader::StartElement) {
  517. if(reader.name() == QLatin1String("schemeClr")){
  518. style_effectref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed();
  519. }
  520. }
  521. }
  522. else if(reader.name() == QLatin1String("fontRef"))
  523. {
  524. style_forntref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed();
  525. reader.readNextStartElement();
  526. if (reader.tokenType() == QXmlStreamReader::StartElement) {
  527. if(reader.name() == QLatin1String("schemeClr")){
  528. style_forntref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed();
  529. }
  530. }
  531. }
  532. }
  533. else if (reader.tokenType() == QXmlStreamReader::EndElement
  534. && reader.name() == QLatin1String("sp"))
  535. {
  536. break;
  537. }
  538. }
  539. //*/
  540. return;
  541. }
  542. void DrawingAnchor::saveXmlPos(QXmlStreamWriter &writer, const QPoint &pos) const
  543. {
  544. writer.writeEmptyElement(QStringLiteral("xdr:pos"));
  545. writer.writeAttribute(QStringLiteral("x"), QString::number(pos.x()));
  546. writer.writeAttribute(QStringLiteral("y"), QString::number(pos.y()));
  547. }
  548. void DrawingAnchor::saveXmlExt(QXmlStreamWriter &writer, const QSize &ext) const
  549. {
  550. writer.writeStartElement(QStringLiteral("xdr:ext"));
  551. writer.writeAttribute(QStringLiteral("cx"), QString::number(ext.width()));
  552. writer.writeAttribute(QStringLiteral("cy"), QString::number(ext.height()));
  553. writer.writeEndElement(); //xdr:ext
  554. }
  555. void DrawingAnchor::saveXmlMarker(QXmlStreamWriter &writer, const XlsxMarker &marker, const QString &node) const
  556. {
  557. writer.writeStartElement(node); //xdr:from or xdr:to
  558. writer.writeTextElement(QStringLiteral("xdr:col"), QString::number(marker.col()));
  559. writer.writeTextElement(QStringLiteral("xdr:colOff"), QString::number(marker.colOff()));
  560. writer.writeTextElement(QStringLiteral("xdr:row"), QString::number(marker.row()));
  561. writer.writeTextElement(QStringLiteral("xdr:rowOff"), QString::number(marker.rowOff()));
  562. writer.writeEndElement();
  563. }
  564. void DrawingAnchor::saveXmlObject(QXmlStreamWriter &writer) const
  565. {
  566. if (m_objectType == Picture)
  567. saveXmlObjectPicture(writer);
  568. else if (m_objectType == ConnectionShape)
  569. saveXmlObjectConnectionShape(writer);
  570. else if (m_objectType == GraphicFrame)
  571. saveXmlObjectGraphicFrame(writer);
  572. else if (m_objectType == GroupShape)
  573. saveXmlObjectGroupShape(writer);
  574. else if (m_objectType == Shape)
  575. saveXmlObjectShape(writer);
  576. }
  577. void DrawingAnchor::saveXmlObjectConnectionShape(QXmlStreamWriter &writer) const
  578. {
  579. writer.writeStartElement(QStringLiteral("xdr:cxnSp")); ///?
  580. writer.writeAttribute(QStringLiteral("macro"), cxnSp_macro);
  581. writer.writeStartElement(QStringLiteral("xdr:nvCxnSpPr"));
  582. writer.writeEmptyElement(QStringLiteral("xdr:cNvPr"));
  583. writer.writeAttribute(QStringLiteral("id"), xsp_cNvPR_id);
  584. writer.writeAttribute(QStringLiteral("name"), xsp_cNvPR_name);
  585. writer.writeEmptyElement(QStringLiteral("xdr:cNvCxnSpPr"));
  586. writer.writeEndElement(); //xdr:nvCxnSpPr
  587. writer.writeStartElement(QStringLiteral("xdr:spPr"));
  588. if(!xbwMode.isNull()){
  589. writer.writeAttribute(QStringLiteral("bwMode"), xbwMode);
  590. }
  591. writer.writeStartElement(QStringLiteral("a:xfrm"));
  592. if(!cxnSp_filpV.isEmpty()){
  593. writer.writeAttribute(QStringLiteral("flipV"), cxnSp_filpV);}
  594. writer.writeEmptyElement(QStringLiteral("a:off"));
  595. writer.writeAttribute(QStringLiteral("x"), QString::number(posTA.x()));
  596. writer.writeAttribute(QStringLiteral("y"), QString::number(posTA.y()));
  597. writer.writeEmptyElement(QStringLiteral("a:ext"));
  598. writer.writeAttribute(QStringLiteral("cx"), QString::number(extTA.width()));
  599. writer.writeAttribute(QStringLiteral("cy"), QString::number(extTA.height()));
  600. writer.writeEndElement(); //a:xfrm
  601. writer.writeStartElement(QStringLiteral("a:prstGeom"));
  602. writer.writeAttribute(QStringLiteral("prst"), xprstGeom_prst);
  603. writer.writeEmptyElement(QStringLiteral("a:avLst"));
  604. writer.writeEndElement(); //a:prstGeom
  605. writer.writeStartElement(QStringLiteral("a:ln"));
  606. if(!xIn_w.isEmpty()&&!xIn_cap.isEmpty()){
  607. if(!xIn_w.isEmpty()){
  608. writer.writeAttribute(QStringLiteral("w"), xIn_w);
  609. }
  610. if(!xIn_cap.isEmpty()){
  611. writer.writeAttribute(QStringLiteral("cap"), xIn_cap);
  612. }
  613. if(!xIn_cmpd.isEmpty()){
  614. writer.writeAttribute(QStringLiteral("cmpd"), xIn_cmpd);
  615. }
  616. if(!xIn_algn.isEmpty()){
  617. writer.writeAttribute(QStringLiteral("algn"), xIn_algn);
  618. }
  619. }
  620. if((!x_headEnd_tyep.isEmpty())||(!x_headEnd_w.isEmpty())||(!x_headEnd_len.isEmpty())){
  621. writer.writeEmptyElement(QStringLiteral("a:headEnd"));
  622. if(!x_headEnd_tyep.isEmpty()){
  623. writer.writeAttribute(QStringLiteral("type"),x_headEnd_tyep);
  624. }
  625. if(!x_headEnd_w.isEmpty()){
  626. writer.writeAttribute(QStringLiteral("w"),x_headEnd_w);
  627. }
  628. if(!x_headEnd_len.isEmpty()){
  629. writer.writeAttribute(QStringLiteral("len"),x_headEnd_len);
  630. }
  631. }
  632. if((!x_tailEnd_tyep.isEmpty())||(!x_tailEnd_w.isEmpty())||(!x_tailEnd_len.isEmpty())){
  633. writer.writeEmptyElement(QStringLiteral("a:tailEnd"));
  634. if(!x_tailEnd_tyep.isEmpty()){
  635. writer.writeAttribute(QStringLiteral("type"),x_tailEnd_tyep);}
  636. if(!x_tailEnd_w.isEmpty()){
  637. writer.writeAttribute(QStringLiteral("w"),x_tailEnd_w);}
  638. if(!x_tailEnd_len.isEmpty()){
  639. writer.writeAttribute(QStringLiteral("len"),x_tailEnd_len);}
  640. }
  641. writer.writeEndElement();//a:ln
  642. writer.writeEndElement(); //xdr:spPr
  643. // writer style
  644. writer.writeStartElement(QStringLiteral("xdr:style"));// style
  645. writer.writeStartElement(QStringLiteral("a:lnRef"));//lnRef
  646. writer.writeAttribute(QStringLiteral("idx"),Style_inref_idx);
  647. writer.writeStartElement(QStringLiteral("a:schemeClr"));//val
  648. writer.writeAttribute(QStringLiteral("val"),Style_inref_val);
  649. writer.writeEndElement(); // val
  650. writer.writeEndElement(); // lnRef
  651. writer.writeStartElement(QStringLiteral("a:fillRef"));//fillRef
  652. writer.writeAttribute(QStringLiteral("idx"),style_fillref_idx);
  653. writer.writeStartElement(QStringLiteral("a:schemeClr"));//val
  654. writer.writeAttribute(QStringLiteral("val"),style_fillref_val);
  655. writer.writeEndElement(); // val
  656. writer.writeEndElement(); // fillRef
  657. writer.writeStartElement(QStringLiteral("a:effectRef"));//effectRef
  658. writer.writeAttribute(QStringLiteral("idx"),style_effectref_idx);
  659. writer.writeStartElement(QStringLiteral("a:schemeClr"));//val
  660. writer.writeAttribute(QStringLiteral("val"),style_effectref_val);
  661. writer.writeEndElement(); // val
  662. writer.writeEndElement(); // effectRef
  663. writer.writeStartElement(QStringLiteral("a:fontRef"));//fontRef
  664. writer.writeAttribute(QStringLiteral("idx"),style_forntref_idx);
  665. writer.writeStartElement(QStringLiteral("a:schemeClr"));//val
  666. writer.writeAttribute(QStringLiteral("val"),style_forntref_val);
  667. writer.writeEndElement(); // val
  668. writer.writeEndElement(); // fontRef
  669. writer.writeEndElement(); // style
  670. writer.writeEndElement(); //xdr:sp
  671. }
  672. void DrawingAnchor::saveXmlObjectGraphicFrame(QXmlStreamWriter &writer) const
  673. {
  674. writer.writeStartElement(QStringLiteral("xdr:graphicFrame"));
  675. writer.writeAttribute(QStringLiteral("macro"), QString());
  676. writer.writeStartElement(QStringLiteral("xdr:nvGraphicFramePr"));
  677. writer.writeEmptyElement(QStringLiteral("xdr:cNvPr"));
  678. writer.writeAttribute(QStringLiteral("id"), QString::number(m_id));
  679. writer.writeAttribute(QStringLiteral("name"), QStringLiteral("Chart %1").arg(m_id));
  680. writer.writeEmptyElement(QStringLiteral("xdr:cNvGraphicFramePr"));
  681. writer.writeEndElement();//xdr:nvGraphicFramePr
  682. writer.writeStartElement(QStringLiteral("xdr:xfrm"));
  683. writer.writeEndElement(); //xdr:xfrm
  684. writer.writeStartElement(QStringLiteral("a:graphic"));
  685. writer.writeStartElement(QStringLiteral("a:graphicData"));
  686. writer.writeAttribute(QStringLiteral("uri"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart"));
  687. int idx = m_drawing->workbook->chartFiles().indexOf(m_chartFile);
  688. m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/chart"), QStringLiteral("../charts/chart%1.xml").arg(idx+1));
  689. writer.writeEmptyElement(QStringLiteral("c:chart"));
  690. writer.writeAttribute(QStringLiteral("xmlns:c"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart"));
  691. writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
  692. writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(m_drawing->relationships()->count()));
  693. writer.writeEndElement(); //a:graphicData
  694. writer.writeEndElement(); //a:graphic
  695. writer.writeEndElement(); //xdr:graphicFrame
  696. }
  697. void DrawingAnchor::saveXmlObjectGroupShape(QXmlStreamWriter &writer) const
  698. {
  699. Q_UNUSED(writer)
  700. }
  701. void DrawingAnchor::saveXmlObjectPicture(QXmlStreamWriter &writer) const
  702. {
  703. Q_ASSERT(m_objectType == Picture && !m_pictureFile.isNull());
  704. writer.writeStartElement(QStringLiteral("xdr:pic"));
  705. writer.writeStartElement(QStringLiteral("xdr:nvPicPr"));
  706. writer.writeEmptyElement(QStringLiteral("xdr:cNvPr"));
  707. writer.writeAttribute(QStringLiteral("id"), QString::number(m_id+1)); // liufeijin
  708. writer.writeAttribute(QStringLiteral("name"), QStringLiteral("Picture %1").arg(m_id));
  709. writer.writeStartElement(QStringLiteral("xdr:cNvPicPr"));
  710. writer.writeEmptyElement(QStringLiteral("a:picLocks"));
  711. writer.writeAttribute(QStringLiteral("noChangeAspect"), QStringLiteral("1"));
  712. writer.writeEndElement(); //xdr:cNvPicPr
  713. writer.writeEndElement(); //xdr:nvPicPr
  714. m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/image"), QStringLiteral("../media/image%1.%2")
  715. .arg(m_pictureFile->index()+1)
  716. .arg(m_pictureFile->suffix()));
  717. writer.writeStartElement(QStringLiteral("xdr:blipFill"));
  718. writer.writeEmptyElement(QStringLiteral("a:blip"));
  719. writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
  720. writer.writeAttribute(QStringLiteral("r:embed"), QStringLiteral("rId%1").arg(m_drawing->relationships()->count()));
  721. writer.writeStartElement(QStringLiteral("a:stretch"));
  722. writer.writeEmptyElement(QStringLiteral("a:fillRect"));
  723. writer.writeEndElement(); //a:stretch
  724. writer.writeEndElement();//xdr:blipFill
  725. writer.writeStartElement(QStringLiteral("xdr:spPr"));
  726. writer.writeStartElement(QStringLiteral("a:prstGeom"));
  727. writer.writeAttribute(QStringLiteral("prst"), QStringLiteral("rect"));
  728. writer.writeEmptyElement(QStringLiteral("a:avLst"));
  729. writer.writeEndElement(); //a:prstGeom
  730. writer.writeEndElement(); //xdr:spPr
  731. writer.writeEndElement(); //xdr:pic
  732. }
  733. int DrawingAnchor::getm_id()
  734. {
  735. return (this->m_id);
  736. }
  737. void DrawingAnchor::saveXmlObjectShape(QXmlStreamWriter &writer) const
  738. {
  739. //{{ liufeijin
  740. writer.writeStartElement(QStringLiteral("xdr:sp")); //xdr:sp
  741. writer.writeAttribute(QStringLiteral("macro"), sp_macro);
  742. writer.writeAttribute(QStringLiteral("textlink"),sp_textlink);
  743. writer.writeStartElement(QStringLiteral("xdr:nvSpPr"));//xdr:nvSpPr
  744. writer.writeStartElement(QStringLiteral("xdr:cNvPr"));
  745. writer.writeAttribute(QStringLiteral("id"), xsp_cNvPR_id);
  746. writer.writeAttribute(QStringLiteral("name"), xsp_cNvPR_name);
  747. writer.writeStartElement(QStringLiteral("a:extLst"));
  748. writer.writeEndElement();
  749. writer.writeEndElement();//xdr:cNvPr
  750. writer.writeEmptyElement(QStringLiteral("xdr:cNvSpPr"));
  751. writer.writeEndElement(); //xdr:nvSpPr
  752. writer.writeStartElement(QStringLiteral("xdr:spPr"));
  753. if(!xbwMode.isNull()){
  754. writer.writeAttribute(QStringLiteral("bwMode"), xbwMode);
  755. }
  756. writer.writeStartElement(QStringLiteral("a:xfrm"));
  757. writer.writeEmptyElement(QStringLiteral("a:off"));
  758. writer.writeAttribute(QStringLiteral("x"), QString::number(posTA.x()));
  759. writer.writeAttribute(QStringLiteral("y"), QString::number(posTA.y()));
  760. writer.writeEmptyElement(QStringLiteral("a:ext"));
  761. writer.writeAttribute(QStringLiteral("cx"), QString::number(extTA.width()));
  762. writer.writeAttribute(QStringLiteral("cy"), QString::number(extTA.height()));
  763. writer.writeEndElement(); //a:xfrm
  764. writer.writeStartElement(QStringLiteral("a:prstGeom"));
  765. writer.writeAttribute(QStringLiteral("prst"), xprstGeom_prst);
  766. writer.writeEmptyElement(QStringLiteral("a:avLst"));
  767. writer.writeEndElement(); //a:prstGeom
  768. if(!m_pictureFile.isNull()){
  769. m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/image"), QStringLiteral("../media/image%1.%2").arg(m_pictureFile->index()+1).arg(m_pictureFile->suffix()));
  770. writer.writeStartElement(QStringLiteral("a:blipFill"));
  771. writer.writeAttribute(QStringLiteral("dpi"), QString::number(dpiTA));
  772. writer.writeAttribute(QStringLiteral("rotWithShape"),QString::number(rotWithShapeTA));
  773. writer.writeStartElement(QStringLiteral("a:blip"));
  774. writer.writeAttribute(QStringLiteral("r:embed"), QStringLiteral("rId%1").arg(m_drawing->relationships()->count())); //sp_blip_rembed QStringLiteral("rId%1").arg(m_drawing->relationships()->count()) can't made new pic
  775. writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
  776. if(!sp_blip_cstate.isNull()){
  777. writer.writeAttribute(QStringLiteral("cstate"), sp_blip_cstate);
  778. }
  779. writer.writeEndElement();//a:blip
  780. writer.writeEmptyElement(QStringLiteral("a:srcRect"));
  781. writer.writeStartElement(QStringLiteral("a:stretch"));
  782. writer.writeEmptyElement(QStringLiteral("a:fillRect"));
  783. writer.writeEndElement(); //a:stretch
  784. writer.writeEndElement();//a:blipFill
  785. }
  786. writer.writeStartElement(QStringLiteral("a:ln"));
  787. if(!xIn_w.isEmpty()&&!xIn_cap.isEmpty()){
  788. if(!xIn_w.isEmpty()){
  789. writer.writeAttribute(QStringLiteral("w"), xIn_w);
  790. }
  791. if(!xIn_cap.isEmpty()){
  792. writer.writeAttribute(QStringLiteral("cap"), xIn_cap);
  793. }
  794. if(!xIn_cmpd.isEmpty()){
  795. writer.writeAttribute(QStringLiteral("cmpd"), xIn_cmpd);
  796. }
  797. if(!xIn_algn.isEmpty()){
  798. writer.writeAttribute(QStringLiteral("algn"), xIn_algn);
  799. }
  800. }
  801. if((!x_headEnd_tyep.isEmpty())||(!x_headEnd_w.isEmpty())||(!x_headEnd_len.isEmpty())){
  802. writer.writeEmptyElement(QStringLiteral("a:headEnd"));
  803. if(!x_headEnd_tyep.isEmpty()){
  804. writer.writeAttribute(QStringLiteral("type"),x_headEnd_tyep);
  805. }
  806. if(!x_headEnd_w.isEmpty()){
  807. writer.writeAttribute(QStringLiteral("w"),x_headEnd_w);
  808. }
  809. if(!x_headEnd_len.isEmpty()){
  810. writer.writeAttribute(QStringLiteral("len"),x_headEnd_len);
  811. }
  812. }
  813. if((!x_tailEnd_tyep.isEmpty())||(!x_tailEnd_w.isEmpty())||(!x_tailEnd_len.isEmpty())){
  814. writer.writeEmptyElement(QStringLiteral("a:tailEnd"));
  815. if(!x_tailEnd_tyep.isEmpty()){
  816. writer.writeAttribute(QStringLiteral("type"),x_tailEnd_tyep);}
  817. if(!x_tailEnd_w.isEmpty()){
  818. writer.writeAttribute(QStringLiteral("w"),x_tailEnd_w);}
  819. if(!x_tailEnd_len.isEmpty()){
  820. writer.writeAttribute(QStringLiteral("len"),x_tailEnd_len);}
  821. }
  822. writer.writeEndElement();//a:ln
  823. writer.writeEndElement(); //xdr:spPr
  824. // writer style
  825. writer.writeStartElement(QStringLiteral("xdr:style"));// style
  826. writer.writeStartElement(QStringLiteral("a:lnRef"));//lnRef
  827. writer.writeAttribute(QStringLiteral("idx"),Style_inref_idx);
  828. writer.writeStartElement(QStringLiteral("a:schemeClr"));//val
  829. writer.writeAttribute(QStringLiteral("val"),Style_inref_val);
  830. writer.writeEndElement(); // val
  831. writer.writeEndElement(); // lnRef
  832. writer.writeStartElement(QStringLiteral("a:fillRef"));//fillRef
  833. writer.writeAttribute(QStringLiteral("idx"),style_fillref_idx);
  834. writer.writeStartElement(QStringLiteral("a:schemeClr"));//val
  835. writer.writeAttribute(QStringLiteral("val"),style_fillref_val);
  836. writer.writeEndElement(); // val
  837. writer.writeEndElement(); // fillRef
  838. writer.writeStartElement(QStringLiteral("a:effectRef"));//effectRef
  839. writer.writeAttribute(QStringLiteral("idx"),style_effectref_idx);
  840. writer.writeStartElement(QStringLiteral("a:schemeClr"));//val
  841. writer.writeAttribute(QStringLiteral("val"),style_effectref_val);
  842. writer.writeEndElement(); // val
  843. writer.writeEndElement(); // effectRef
  844. writer.writeStartElement(QStringLiteral("a:fontRef"));//fontRef
  845. writer.writeAttribute(QStringLiteral("idx"),style_forntref_idx);
  846. writer.writeStartElement(QStringLiteral("a:schemeClr"));//val
  847. writer.writeAttribute(QStringLiteral("val"),style_forntref_val);
  848. writer.writeEndElement(); // val
  849. writer.writeEndElement(); // fontRef
  850. writer.writeEndElement(); // style
  851. writer.writeEndElement(); //xdr:sp
  852. //}} liufeijin
  853. }
  854. //absolute anchor
  855. DrawingAbsoluteAnchor::DrawingAbsoluteAnchor(Drawing *drawing, ObjectType objectType)
  856. :DrawingAnchor(drawing, objectType)
  857. {
  858. }
  859. // check point
  860. bool DrawingAbsoluteAnchor::loadFromXml(QXmlStreamReader &reader)
  861. {
  862. Q_ASSERT(reader.name() == QLatin1String("absoluteAnchor"));
  863. while (!reader.atEnd()) {
  864. reader.readNextStartElement();
  865. if (reader.tokenType() == QXmlStreamReader::StartElement) {
  866. if (reader.name() == QLatin1String("pos"))
  867. {
  868. pos = loadXmlPos(reader);
  869. }
  870. else if (reader.name() == QLatin1String("ext"))
  871. {
  872. ext = loadXmlExt(reader);
  873. }
  874. else
  875. {
  876. loadXmlObject(reader);
  877. }
  878. }
  879. else if (reader.tokenType() == QXmlStreamReader::EndElement
  880. && reader.name() == QLatin1String("absoluteAnchor"))
  881. {
  882. break;
  883. }
  884. }
  885. return true;
  886. }
  887. void DrawingAbsoluteAnchor::saveToXml(QXmlStreamWriter &writer) const
  888. {
  889. writer.writeStartElement(QStringLiteral("xdr:absoluteAnchor"));
  890. saveXmlPos(writer, pos);
  891. saveXmlExt(writer, ext);
  892. saveXmlObject(writer);
  893. writer.writeEmptyElement(QStringLiteral("xdr:clientData"));
  894. writer.writeEndElement(); //xdr:absoluteAnchor
  895. }
  896. //one cell anchor
  897. DrawingOneCellAnchor::DrawingOneCellAnchor(Drawing *drawing, ObjectType objectType)
  898. :DrawingAnchor(drawing, objectType)
  899. {
  900. }
  901. int DrawingOneCellAnchor::row()
  902. {
  903. return from.row();
  904. }
  905. int DrawingOneCellAnchor::col()
  906. {
  907. return from.col();
  908. }
  909. // check point
  910. bool DrawingOneCellAnchor::loadFromXml(QXmlStreamReader &reader)
  911. {
  912. Q_ASSERT(reader.name() == QLatin1String("oneCellAnchor"));
  913. while (!reader.atEnd())
  914. {
  915. reader.readNextStartElement();
  916. if (reader.tokenType() == QXmlStreamReader::StartElement)
  917. {
  918. if (reader.name() == QLatin1String("from"))
  919. {
  920. from = loadXmlMarker(reader, QLatin1String("from"));
  921. }
  922. else if (reader.name() == QLatin1String("ext"))
  923. {
  924. ext = loadXmlExt(reader);
  925. }
  926. else
  927. {
  928. loadXmlObject(reader);
  929. }
  930. }
  931. else if (reader.tokenType() == QXmlStreamReader::EndElement
  932. && reader.name() == QLatin1String("oneCellAnchor"))
  933. {
  934. break;
  935. }
  936. }
  937. return true;
  938. }
  939. void DrawingOneCellAnchor::saveToXml(QXmlStreamWriter &writer) const
  940. {
  941. writer.writeStartElement(QStringLiteral("xdr:oneCellAnchor"));
  942. saveXmlMarker(writer, from, QStringLiteral("xdr:from"));
  943. saveXmlExt(writer, ext);
  944. saveXmlObject(writer);
  945. writer.writeEmptyElement(QStringLiteral("xdr:clientData"));
  946. writer.writeEndElement(); //xdr:oneCellAnchor
  947. }
  948. /*
  949. Two cell anchor
  950. This class specifies a two cell anchor placeholder for a group
  951. , a shape, or a drawing element. It moves with
  952. cells and its extents are in EMU units.
  953. */
  954. DrawingTwoCellAnchor::DrawingTwoCellAnchor(Drawing *drawing, ObjectType objectType)
  955. :DrawingAnchor(drawing, objectType)
  956. {
  957. }
  958. int DrawingTwoCellAnchor::row()
  959. {
  960. return from.row();
  961. }
  962. int DrawingTwoCellAnchor::col()
  963. {
  964. return from.col();
  965. }
  966. // check point
  967. bool DrawingTwoCellAnchor::loadFromXml(QXmlStreamReader &reader)
  968. {
  969. Q_ASSERT(reader.name() == QLatin1String("twoCellAnchor"));
  970. /*
  971. <xsd:complexType name="CT_TwoCellAnchor">
  972. <xsd:sequence>
  973. <xsd:element name="from" type="CT_Marker"/>
  974. <xsd:element name="to" type="CT_Marker"/>
  975. <xsd:group ref="EG_ObjectChoices"/>
  976. <xsd:element name="clientData" type="CT_AnchorClientData" minOccurs="1" maxOccurs="1"/>
  977. </xsd:sequence>
  978. <xsd:attribute name="editAs" type="ST_EditAs" use="optional" default="twoCell"/>
  979. </xsd:complexType>
  980. */
  981. //{{ liufeijin
  982. QXmlStreamAttributes attrs = reader.attributes(); // for absolute twocell aadd by liufeijin 20181024
  983. editASName = attrs.value(QLatin1String("editAs")).toString();
  984. //}}
  985. while (!reader.atEnd())
  986. {
  987. reader.readNextStartElement();
  988. if (reader.tokenType() == QXmlStreamReader::StartElement)
  989. {
  990. if (reader.name() == QLatin1String("from"))
  991. {
  992. from = loadXmlMarker(reader, QLatin1String("from"));
  993. }
  994. else if (reader.name() == QLatin1String("to"))
  995. {
  996. to = loadXmlMarker(reader, QLatin1String("to"));
  997. }
  998. else if (reader.name() == QLatin1String("clientData"))
  999. {
  1000. // clientData
  1001. }
  1002. else
  1003. {
  1004. /*
  1005. <xsd:group name="EG_ObjectChoices">
  1006. <xsd:sequence>
  1007. <xsd:choice minOccurs="1" maxOccurs="1">
  1008. <xsd:element name="sp" type="CT_Shape"/>
  1009. <xsd:element name="grpSp" type="CT_GroupShape"/>
  1010. <xsd:element name="graphicFrame" type="CT_GraphicalObjectFrame"/>
  1011. <xsd:element name="cxnSp" type="CT_Connector"/>
  1012. <xsd:element name="pic" type="CT_Picture"/>
  1013. <xsd:element name="contentPart" type="CT_Rel"/>
  1014. </xsd:choice>
  1015. </xsd:sequence>
  1016. </xsd:group>
  1017. */
  1018. loadXmlObject(reader);
  1019. }
  1020. }
  1021. else if (reader.tokenType() == QXmlStreamReader::EndElement
  1022. && reader.name() == QLatin1String("twoCellAnchor"))
  1023. {
  1024. break;
  1025. }
  1026. }
  1027. return true;
  1028. }
  1029. void DrawingTwoCellAnchor::saveToXml(QXmlStreamWriter &writer) const
  1030. {
  1031. writer.writeStartElement(QStringLiteral("xdr:twoCellAnchor"));
  1032. //{{ liufeijin
  1033. // writer.writeAttribute(QStringLiteral("editAs"), QStringLiteral("oneCell"));
  1034. if(!editASName.isNull()){
  1035. writer.writeAttribute(QStringLiteral("editAs"), editASName ); //QStringLiteral("oneCell")
  1036. }
  1037. // }}
  1038. saveXmlMarker(writer, from, QStringLiteral("xdr:from"));
  1039. saveXmlMarker(writer, to, QStringLiteral("xdr:to"));
  1040. saveXmlObject(writer);
  1041. writer.writeEmptyElement(QStringLiteral("xdr:clientData"));
  1042. writer.writeEndElement(); //xdr:twoCellAnchor
  1043. }
  1044. QT_END_NAMESPACE_XLSX