1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-30 05:02:52 +08:00

reading chart axis name

This commit is contained in:
Jay Two 2019-02-26 15:24:03 +09:00
parent ab309ed7de
commit ab371541cd
4 changed files with 313 additions and 239 deletions

View File

@ -70,10 +70,12 @@ public:
public:
bool loadXmlChart(QXmlStreamReader &reader);
bool loadXmlPlotArea(QXmlStreamReader &reader);
protected:
bool loadXmlPlotAreaElement(QXmlStreamReader &reader);
public:
bool loadXmlXxxChart(QXmlStreamReader &reader);
bool loadXmlSer(QXmlStreamReader &reader);
QString loadXmlNumRef(QXmlStreamReader &reader);
bool loadXmlAxis(QXmlStreamReader &reader);
bool loadXmlChartTitle(QXmlStreamReader &reader);
protected:
bool loadXmlChartTitleTx(QXmlStreamReader &reader);
@ -86,11 +88,14 @@ protected:
bool loadXmlAxisSerAx(QXmlStreamReader &reader);
bool loadXmlAxisValAx(QXmlStreamReader &reader);
bool loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Scaling(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title_Overlay(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title_Tx(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title_Tx_Rich(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title_Tx_Rich_P(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title_Tx_Rich_P_T(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title_Tx_Rich_P_pPr(QXmlStreamReader &reader, XlsxAxis* axis);
bool loadXmlAxisEG_AxShared_Title_Tx_Rich_P_R(QXmlStreamReader &reader, XlsxAxis* axis);
public:
void saveXmlChart(QXmlStreamWriter &writer) const;

View File

@ -308,10 +308,6 @@ bool ChartPrivate::loadXmlChart(QXmlStreamReader &reader)
}
// TO DEBUG: loop is not work, when i looping second element.
bool ChartPrivate::loadXmlPlotArea(QXmlStreamReader &reader)
{
Q_ASSERT(reader.name() == QLatin1String("plotArea"));
/*
dchrt_CT_PlotArea =
element layout { dchrt_CT_Layout }?,
@ -339,27 +335,53 @@ bool ChartPrivate::loadXmlPlotArea(QXmlStreamReader &reader)
element spPr { a_CT_ShapeProperties }?,
element extLst { dchrt_CT_ExtensionList }?
*/
bool ChartPrivate::loadXmlPlotArea(QXmlStreamReader &reader)
{
Q_ASSERT(reader.name() == QLatin1String("plotArea"));
// TO DEBUG:
reader.readNext();
while (!reader.atEnd())
{
if (reader.isStartElement())
{
if (!loadXmlPlotAreaElement(reader))
{
qDebug() << "[debug] failed to load plotarea element.";
return false;
}
QXmlStreamReader::TokenType retType = reader.readNext();
reader.readNext();
}
else
{
reader.readNext();
}
}
qDebug() << "[debug] " << reader.name() << retType;
return true;
}
bool ChartPrivate::loadXmlPlotAreaElement(QXmlStreamReader &reader)
{
if (reader.name() == QLatin1String("layout"))
{
//!ToDo
// layout
reader.skipCurrentElement();
}
else if (reader.name().endsWith(QLatin1String("Chart")))
{
// for pieChart, barChart, ... (choose one)
loadXmlXxxChart(reader);
if ( ! loadXmlXxxChart(reader) )
{
qDebug() << "[debug] failed to load chart";
return false;
}
}
else if (reader.name() == QLatin1String("catAx")) // choose one : catAx, dateAx, serAx, valAx
{
@ -375,30 +397,26 @@ bool ChartPrivate::loadXmlPlotArea(QXmlStreamReader &reader)
}
else if (reader.name() == QLatin1String("valAx")) // choose one : catAx, dateAx, serAx, valAx
{
// qDebug() << QTime::currentTime() << reader.name().toString();
loadXmlAxisValAx(reader);
}
else if (reader.name() == QLatin1String("dTable"))
{
//!ToDo
// dTable "CT_DTable"
reader.skipCurrentElement();
}
else if (reader.name() == QLatin1String("spPr"))
{
//!ToDo
// spPr "a:CT_ShapeProperties"
reader.skipCurrentElement();
}
else if (reader.name() == QLatin1String("extLst"))
{
//!ToDo
// extLst "CT_ExtensionList"
}
if ( reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == QLatin1String("plotArea") )
{
break;
}
reader.skipCurrentElement();
}
return true;
@ -907,11 +925,16 @@ void ChartPrivate::saveXmlScatterChart(QXmlStreamWriter &writer) const
if (axisList.isEmpty())
{
const_cast<ChartPrivate*>(this)->axisList.append(QSharedPointer<XlsxAxis>(new XlsxAxis(XlsxAxis::T_Val, XlsxAxis::Bottom, 0, 1, axisNames[XlsxAxis::Bottom] )));
const_cast<ChartPrivate*>(this)->axisList.append(QSharedPointer<XlsxAxis>(new XlsxAxis(XlsxAxis::T_Val, XlsxAxis::Left, 1, 0, axisNames[XlsxAxis::Left] )));
const_cast<ChartPrivate*>(this)->axisList.append(
QSharedPointer<XlsxAxis>(
new XlsxAxis(XlsxAxis::T_Val, XlsxAxis::Bottom, 0, 1, axisNames[XlsxAxis::Bottom] )));
const_cast<ChartPrivate*>(this)->axisList.append(
QSharedPointer<XlsxAxis>(
new XlsxAxis(XlsxAxis::T_Val, XlsxAxis::Left, 1, 0, axisNames[XlsxAxis::Left] )));
}
Q_ASSERT(axisList.size()==2);
int axisListSize = axisList.size();
Q_ASSERT(axisListSize == 2);
for (int i=0; i<axisList.size(); ++i)
{
@ -1002,56 +1025,6 @@ void ChartPrivate::saveXmlSer(QXmlStreamWriter &writer, XlsxSeries *ser, int id)
writer.writeEndElement();//c:ser
}
bool ChartPrivate::loadXmlAxis(QXmlStreamReader &reader)
{
Q_ASSERT(reader.name().endsWith(QLatin1String("Ax")));
QString name = reader.name().toString();
XlsxAxis* axis = new XlsxAxis();
// valAx, catAx, serAx, dateAx (choose one)
if (name == QLatin1String("valAx")) { axis->type = XlsxAxis::T_Val; }
else if (name == QLatin1String("catAx")) { axis->type = XlsxAxis::T_Cat; }
else if (name == QLatin1String("serAx")) { axis->type = XlsxAxis::T_Ser; }
else if (name == QLatin1String("dateAx")) { axis->type = XlsxAxis::T_Date; }
else { axis->type = XlsxAxis::T_None; }
axisList.append( QSharedPointer<XlsxAxis>(axis) );
while ( !reader.atEnd() )
{
reader.readNextStartElement();
if ( reader.tokenType() == QXmlStreamReader::StartElement )
{
if ( reader.name() == QLatin1String("axPos") )
{
QXmlStreamAttributes attrs = reader.attributes();
QStringRef pos = attrs.value(QLatin1String("val"));
if ( pos == QLatin1String("l") ) { axis->axisPos = XlsxAxis::Left; }
else if ( pos == QLatin1String("r") ) { axis->axisPos = XlsxAxis::Right; }
else if ( pos == QLatin1String("b") ) { axis->axisPos = XlsxAxis::Bottom; }
else if ( pos == QLatin1String("t") ) { axis->axisPos = XlsxAxis::Top; }
else { axis->axisPos = XlsxAxis::None; }
}
else if ( reader.name() == QLatin1String("axId") )
{
axis->axisId = reader.attributes().value(QLatin1String("val")).toString().toInt();
}
else if ( reader.name() == QLatin1String("crossAx") )
{
axis->crossAx = reader.attributes().value(QLatin1String("val")).toString().toInt();
}
}
else if ( reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == name )
{
break;
}
}
return true;
}
bool ChartPrivate::loadXmlAxisCatAx(QXmlStreamReader &reader)
{
@ -1129,26 +1102,18 @@ bool ChartPrivate::loadXmlAxisSerAx(QXmlStreamReader &reader)
bool ChartPrivate::loadXmlAxisValAx(QXmlStreamReader &reader)
{
Q_ASSERT(reader.name() == QLatin1String("valAx"));
XlsxAxis* axis = new XlsxAxis();
axis->type = XlsxAxis::T_Val;
axisList.append( QSharedPointer<XlsxAxis>(axis) );
// reader.readNext();
while(!(reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == "valAx"))
{
// load EG_AxShared
if ( ! loadXmlAxisEG_AxShared( reader, axis ) )
{
// qDebug() << "failed to load EG_AxShared";
// return false;
}
reader.readNext();
}
//!TODO: load element
// crossBetween
// majorUnit
@ -1159,11 +1124,6 @@ bool ChartPrivate::loadXmlAxisValAx(QXmlStreamReader &reader)
return true;
}
bool ChartPrivate::loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis* axis)
{
if ( NULL == axis )
return false;
/*
<xsd:group name="EG_AxShared">
<xsd:sequence>
@ -1188,33 +1148,34 @@ bool ChartPrivate::loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis* ax
</xsd:sequence>
</xsd:group>
*/
QString name = reader.name().toString();
if ( name.isEmpty() )
return false;
bool ChartPrivate::loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis* axis)
{
Q_ASSERT( NULL != axis );
Q_ASSERT(reader.name() == QLatin1String("valAx"));
while ( !reader.atEnd() )
{
reader.readNextStartElement();
if ( reader.tokenType() == QXmlStreamReader::StartElement )
{
// qDebug() << "[debug]" << QTime::currentTime() << reader.name().toString();
if ( reader.name() == QLatin1String("axId") )
{
// mandatory element
QString axIdValue = reader.readElementText();
int axId = axIdValue.toInt();
int axId = reader.attributes().value("val").toInt();
axis->axisId = axId;
}
else if ( reader.name() == QLatin1String("scaling") )
{
// mandatory element
QString strOrientation = reader.attributes().value(QLatin1String("orientation")).toString();
// minMax or maxMin
loadXmlAxisEG_AxShared_Scaling(reader, axis);
}
else if ( reader.name() == QLatin1String("delete") )
{
//!TODO
}
else if ( reader.name() == QLatin1String("axPos") )
{
@ -1226,13 +1187,14 @@ bool ChartPrivate::loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis* ax
else if ( axPosVal == "r" ) { axis->axisPos = XlsxAxis::Right; }
else if ( axPosVal == "t" ) { axis->axisPos = XlsxAxis::Top; }
else if ( axPosVal == "b" ) { axis->axisPos = XlsxAxis::Bottom; }
}
else if ( reader.name() == QLatin1String("majorGridlines") )
{
//!TODO
}
else if ( reader.name() == QLatin1String("minorGridlines") )
{
//!TODO
}
else if ( reader.name() == QLatin1String("title") )
{
@ -1240,43 +1202,54 @@ bool ChartPrivate::loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis* ax
if ( !loadXmlAxisEG_AxShared_Title(reader, axis) )
{
qDebug() << "failed to load EG_AxShared title.";
Q_ASSERT(false);
return false;
}
}
else if ( reader.name() == QLatin1String("numFmt") )
{
//!TODO
}
else if ( reader.name() == QLatin1String("majorTickMark") )
{
//!TODO
}
else if ( reader.name() == QLatin1String("minorTickMark") )
{
//!TODO
}
else if ( reader.name() == QLatin1String("tickLblPos") )
{
//!TODO
}
else if ( reader.name() == QLatin1String("spPr") )
{
//!TODO
}
else if ( reader.name() == QLatin1String("txPr") )
{
//!TODO
}
else if ( reader.name() == QLatin1String("crossAx") )
{
// mandatory element
int crossAx = reader.attributes().value(QLatin1String("crossAx")).toInt();
int crossAx = reader.attributes().value(QLatin1String("val")).toInt();
axis->crossAx = crossAx;
}
else if ( reader.name() == QLatin1String("crosses") )
{
//!TODO
}
else if ( reader.name() == QLatin1String("crossesAt") )
{
//!TODO
}
// reader.readNext();
}
else if ( reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == name )
else if ( reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == "valAx" )
{
break;
}
@ -1285,8 +1258,34 @@ bool ChartPrivate::loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis* ax
return true;
}
bool ChartPrivate::loadXmlAxisEG_AxShared_Title(QXmlStreamReader &reader, XlsxAxis* axis)
bool ChartPrivate::loadXmlAxisEG_AxShared_Scaling(QXmlStreamReader &reader, XlsxAxis* axis)
{
Q_ASSERT(reader.name() == QLatin1String("scaling"));
while ( !reader.atEnd() )
{
reader.readNextStartElement();
if ( reader.tokenType() == QXmlStreamReader::StartElement )
{
if ( reader.name() == QLatin1String("orientation") )
{
QString strOrientation = reader.attributes().value(QLatin1String("val")).toString();
int debugLine = 0;
}
else
{
}
}
else if ( reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == "scaling" )
{
break;
}
}
return true;
}
/*
<xsd:complexType name="CT_Title">
<xsd:sequence>
@ -1324,6 +1323,9 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title(QXmlStreamReader &reader, XlsxAx
</xsd:sequence>
</xsd:complexType>
*/
bool ChartPrivate::loadXmlAxisEG_AxShared_Title(QXmlStreamReader &reader, XlsxAxis* axis)
{
Q_ASSERT(reader.name() == QLatin1String("title"));
while ( !reader.atEnd() )
{
@ -1336,6 +1338,8 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title(QXmlStreamReader &reader, XlsxAx
}
else if ( reader.name() == QLatin1String("overlay") )
{
//!TODO: load overlay
loadXmlAxisEG_AxShared_Title_Overlay(reader, axis);
}
else
{
@ -1351,8 +1355,30 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title(QXmlStreamReader &reader, XlsxAx
return true;
}
bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Overlay(QXmlStreamReader &reader, XlsxAxis* axis)
{
Q_ASSERT(reader.name() == QLatin1String("overlay"));
while ( !reader.atEnd() )
{
reader.readNextStartElement();
if ( reader.tokenType() == QXmlStreamReader::StartElement )
{
}
else if ( reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == "overlay" )
{
break;
}
}
return true;
}
bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx(QXmlStreamReader &reader, XlsxAxis* axis)
{
Q_ASSERT(reader.name() == QLatin1String("tx"));
while ( !reader.atEnd() )
{
reader.readNextStartElement();
@ -1378,6 +1404,8 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx(QXmlStreamReader &reader, Xls
bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich(QXmlStreamReader &reader, XlsxAxis* axis)
{
Q_ASSERT(reader.name() == QLatin1String("rich"));
while ( !reader.atEnd() )
{
reader.readNextStartElement();
@ -1403,6 +1431,8 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich(QXmlStreamReader &reader
bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P(QXmlStreamReader &reader, XlsxAxis* axis)
{
Q_ASSERT(reader.name() == QLatin1String("p"));
while ( !reader.atEnd() )
{
reader.readNextStartElement();
@ -1410,10 +1440,15 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P(QXmlStreamReader &read
{
if ( reader.name() == QLatin1String("r") )
{
loadXmlAxisEG_AxShared_Title_Tx_Rich_P_T(reader, axis);
loadXmlAxisEG_AxShared_Title_Tx_Rich_P_R(reader, axis);
}
else if ( reader.name() == QLatin1String("pPr") )
{
loadXmlAxisEG_AxShared_Title_Tx_Rich_P_pPr(reader, axis);
}
else
{
}
}
else if ( reader.tokenType() == QXmlStreamReader::EndElement &&
@ -1426,8 +1461,38 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P(QXmlStreamReader &read
return true;
}
bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P_T(QXmlStreamReader &reader, XlsxAxis* axis)
bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P_pPr(QXmlStreamReader &reader, XlsxAxis* axis)
{
Q_ASSERT(reader.name() == QLatin1String("pPr"));
while ( !reader.atEnd() )
{
reader.readNextStartElement();
if ( reader.tokenType() == QXmlStreamReader::StartElement )
{
if ( reader.name() == QLatin1String("defRPr") )
{
QString strDefRPr = reader.readElementText();
int debugLine = 0;
}
else
{
}
}
else if ( reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == "pPr" )
{
break;
}
}
return true;
}
bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P_R(QXmlStreamReader &reader, XlsxAxis* axis)
{
Q_ASSERT(reader.name() == QLatin1String("r"));
while ( !reader.atEnd() )
{
reader.readNextStartElement();
@ -1444,7 +1509,7 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P_T(QXmlStreamReader &re
}
}
else if ( reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == "t" )
reader.name() == "r" )
{
break;
}

View File

@ -35,29 +35,33 @@ Travis CI | AppVeyor | CodeFactor
## 할 일
<details><summary>CLICK ME</summary>
<p>
- [테스트 할 일](ToTest.md)
- [업그레이드 할 일](ToUpgrade.md)
</p>
</details>
## 컨트리뷰터
- [컨트리뷰터](https://github.com/QtExcel/QXlsx/graphs/contributors) 참조.
## 라이센스와 링크
- QXlsx 는 MIT 라이센스 입니다. [https://github.com/QtExcel/QXlsx](https://github.com/QtExcel/QXlsx)
- QtXlsx 는 MIT 라이센스 입니다. [https://github.com/dbzhang800/QtXlsxWriter](https://github.com/dbzhang800/QtXlsxWriter)
- Qt-Table-Printer 는 BSD 3-Clause 라이센스 입니다. [https://github.com/T0ny0/Qt-Table-Printer](https://github.com/T0ny0/Qt-Table-Printer)
- recurse 는 MIT 라이센스 입니다. [https://github.com/pkoretic/recurse](https://github.com/pkoretic/recurse)
- Qt 는 LGPL v3 라이센스 또는 상업용 라이센스 입니다. [https://www.qt.io/](https://www.qt.io/)
## :email: 문의
- 이슈를 남겨 주세요. [https://github.com/QtExcel/QXlsx/issues](https://github.com/QtExcel/QXlsx/issues)
- 프로젝트 참여에 관심이 있으신 분은 이슈로 연락주세요.
- README.md를 모국어로 번역하려면 저에게 연락하십시오.
- 이슈(issue)를 제기하거나 pull request를 사용하시면 됩니다. (예: README.ko.md)

View File

@ -11,7 +11,7 @@
## How to use
- See [examples](Example.md)
- HelloWorld : Hello world example (the most basic structure)
- [HelloWorld](HelloWorld/) : Hello world example (the most basic structure)
- TestExcel : basic samples based on QtXlsx samples
- HelloAndroid : read xlsx on Android
- Copycat : load xlsx file and display on widget. print xlsx file.
@ -35,24 +35,24 @@ Travis CI | AppVeyor | CodeFactor
## To Do
<details><summary>CLICK ME</summary>
<p>
- [To test](ToTest.md)
- [What to upgrade](ToUpgrade.md).
</p>
</details>
## Contributions
- See [contributors](https://github.com/QtExcel/QXlsx/graphs/contributors).
## License and links
- QXlsx is under MIT license. [https://github.com/QtExcel/QXlsx](https://github.com/QtExcel/QXlsx)
- QtXlsx is under MIT license. [https://github.com/dbzhang800/QtXlsxWriter](https://github.com/dbzhang800/QtXlsxWriter)
- Qt-Table-Printer is under BSD 3-Clause license. [https://github.com/T0ny0/Qt-Table-Printer](https://github.com/T0ny0/Qt-Table-Printer)
- recurse is under MIT license. [https://github.com/pkoretic/recurse](https://github.com/pkoretic/recurse)
- Qt is under LGPL v3 license or Commercial license. [https://www.qt.io/](https://www.qt.io/)
## :email: Contact