diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..8343aa31 --- /dev/null +++ b/.clang-format @@ -0,0 +1,93 @@ +# .clang-format for Cutelyst projects 2023-04-18 +# Tries to be close to Qt coding style +# but meh for ASql lambdas which LambdaBodyIndentation ins't enough +--- +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: 'false' +AlignConsecutiveAssignments: 'true' +AlignConsecutiveDeclarations: 'false' +AllowShortEnumsOnASingleLine: 'true' +AlignEscapedNewlines: DontAlign +AlignOperands: 'true' +AlignTrailingComments: 'true' +AllowAllArgumentsOnNextLine: 'true' +AllowAllParametersOfDeclarationOnNextLine: 'false' +AllowShortBlocksOnASingleLine: 'false' +AllowShortCaseLabelsOnASingleLine: 'false' +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: Inline +AllowShortLoopsOnASingleLine: 'false' +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: 'false' +AlwaysBreakTemplateDeclarations: 'Yes' +BinPackArguments: 'false' +BinPackParameters: 'false' +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: 'true' + AfterClass: 'true' + AfterEnum: 'false' + AfterFunction: true + SplitEmptyFunction: 'true' + SplitEmptyRecord: 'true' + SplitEmptyNamespace: 'true' +BreakBeforeTernaryOperators: 'true' +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeComma +BreakStringLiterals: 'true' +CompactNamespaces: 'false' +ConstructorInitializerAllOnOneLineOrOnePerLine: 'false' +ConstructorInitializerIndentWidth: '4' +ContinuationIndentWidth: '4' +ColumnLimit: 100 +Cpp11BracedListStyle: 'true' +FixNamespaceComments: 'true' +ForEachMacros: + - forever # avoids { wrapped to next line + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeCategories: + - Regex: '^ +#include + #include -#include -#include +#include #include -#include - -#include +#include +#include +#include using namespace std; -#include "xlsxdocument.h" -#include "xlsxchartsheet.h" #include "xlsxcellrange.h" #include "xlsxchart.h" +#include "xlsxchartsheet.h" +#include "xlsxdocument.h" #include "xlsxrichstring.h" #include "xlsxworkbook.h" using namespace QXlsx; @@ -22,12 +22,11 @@ extern int test(QVector params); int main(int argc, char *argv[]) { - QCoreApplication app(argc, argv); + QCoreApplication app(argc, argv); - QVector testParams; - int ret = test(testParams); + QVector testParams; + int ret = test(testParams); // qDebug() << "test return value : " << ret; - return 0; + return 0; } - diff --git a/DateTime/test.cpp b/DateTime/test.cpp index 950b249d..950aede7 100644 --- a/DateTime/test.cpp +++ b/DateTime/test.cpp @@ -1,34 +1,34 @@ // test.cpp -#include +#include + #include -#include -#include -#include -#include +#include #include - -#include +#include +#include +#include +#include using namespace std; -#include "xlsxdocument.h" -#include "xlsxchartsheet.h" #include "xlsxcellrange.h" #include "xlsxchart.h" +#include "xlsxchartsheet.h" +#include "xlsxdocument.h" #include "xlsxrichstring.h" #include "xlsxworkbook.h" -int test( QVector params ); -int test1( QVector params ); -int test2( QVector params ); +int test(QVector params); +int test1(QVector params); +int test2(QVector params); -int test( QVector params ) +int test(QVector params) { // return test1( params ); - return test2( params ); + return test2(params); } -int test1( QVector params ) +int test1(QVector params) { qDebug() << "[debug] current path : " << QDir::currentPath(); @@ -36,33 +36,33 @@ int test1( QVector params ) Document doc; - doc.write( "A1", QVariant(QDateTime::currentDateTimeUtc()) ); - doc.write( "A2", QVariant(double(10.5)) ); - doc.write( "A3", QVariant(QDate(2019, 10, 9)) ); - doc.write( "A4", QVariant(QTime(10, 9, 5)) ); - doc.write( "A5", QVariant((int) 40000) ); + doc.write("A1", QVariant(QDateTime::currentDateTimeUtc())); + doc.write("A2", QVariant(double(10.5))); + doc.write("A3", QVariant(QDate(2019, 10, 9))); + doc.write("A4", QVariant(QTime(10, 9, 5))); + doc.write("A5", QVariant((int) 40000)); qDebug() << "doc.read()"; - qDebug() << doc.read( 1, 1 ).type() << doc.read( 1, 1 ); - qDebug() << doc.read( 2, 1 ).type() << doc.read( 2, 1 ); - qDebug() << doc.read( 3, 1 ).type() << doc.read( 3, 1 ); - qDebug() << doc.read( 4, 1 ).type() << doc.read( 4, 1 ); - qDebug() << doc.read( 5, 1 ).type() << doc.read( 5, 1 ); + qDebug() << doc.read(1, 1).type() << doc.read(1, 1); + qDebug() << doc.read(2, 1).type() << doc.read(2, 1); + qDebug() << doc.read(3, 1).type() << doc.read(3, 1); + qDebug() << doc.read(4, 1).type() << doc.read(4, 1); + qDebug() << doc.read(5, 1).type() << doc.read(5, 1); qDebug() << "\n"; qDebug() << "doc.cellAt()->value()"; - qDebug() << doc.cellAt( 1, 1 )->value().type() << doc.cellAt( 1, 1 )->value(); - qDebug() << doc.cellAt( 2, 1 )->value().type() << doc.cellAt( 2, 1 )->value(); - qDebug() << doc.cellAt( 3, 1 )->value().type() << doc.cellAt( 3, 1 )->value(); - qDebug() << doc.cellAt( 4, 1 )->value().type() << doc.cellAt( 4, 1 )->value(); - qDebug() << doc.cellAt( 5, 1 )->value().type() << doc.cellAt( 5, 1 )->value(); + qDebug() << doc.cellAt(1, 1)->value().type() << doc.cellAt(1, 1)->value(); + qDebug() << doc.cellAt(2, 1)->value().type() << doc.cellAt(2, 1)->value(); + qDebug() << doc.cellAt(3, 1)->value().type() << doc.cellAt(3, 1)->value(); + qDebug() << doc.cellAt(4, 1)->value().type() << doc.cellAt(4, 1)->value(); + qDebug() << doc.cellAt(5, 1)->value().type() << doc.cellAt(5, 1)->value(); doc.saveAs("datetime.xlsx"); return 0; } -int test2( QVector params ) +int test2(QVector params) { qDebug() << "[debug] current path : " << QDir::currentPath(); @@ -72,26 +72,26 @@ int test2( QVector params ) Document doc; - doc.write( "A1", QVariant(QDateTime::currentDateTimeUtc()) ); - doc.write( "A2", QVariant(double(10.5)) ); - doc.write( "A3", QVariant(QDate(2019, 10, 9)) ); - doc.write( "A4", QVariant(QTime(10, 9, 5)) ); - doc.write( "A5", QVariant((int) 40000) ); + doc.write("A1", QVariant(QDateTime::currentDateTimeUtc())); + doc.write("A2", QVariant(double(10.5))); + doc.write("A3", QVariant(QDate(2019, 10, 9))); + doc.write("A4", QVariant(QTime(10, 9, 5))); + doc.write("A5", QVariant((int) 40000)); qDebug() << "doc.read()"; - qDebug() << doc.read( 1, 1 ).type() << doc.read( 1, 1 ); - qDebug() << doc.read( 2, 1 ).type() << doc.read( 2, 1 ); - qDebug() << doc.read( 3, 1 ).type() << doc.read( 3, 1 ); - qDebug() << doc.read( 4, 1 ).type() << doc.read( 4, 1 ); - qDebug() << doc.read( 5, 1 ).type() << doc.read( 5, 1 ); + qDebug() << doc.read(1, 1).type() << doc.read(1, 1); + qDebug() << doc.read(2, 1).type() << doc.read(2, 1); + qDebug() << doc.read(3, 1).type() << doc.read(3, 1); + qDebug() << doc.read(4, 1).type() << doc.read(4, 1); + qDebug() << doc.read(5, 1).type() << doc.read(5, 1); qDebug() << "\n"; qDebug() << "doc.cellAt()->value()"; - qDebug() << doc.cellAt( 1, 1 )->value().type() << doc.cellAt( 1, 1 )->value(); - qDebug() << doc.cellAt( 2, 1 )->value().type() << doc.cellAt( 2, 1 )->value(); - qDebug() << doc.cellAt( 3, 1 )->value().type() << doc.cellAt( 3, 1 )->value(); - qDebug() << doc.cellAt( 4, 1 )->value().type() << doc.cellAt( 4, 1 )->value(); - qDebug() << doc.cellAt( 5, 1 )->value().type() << doc.cellAt( 5, 1 )->value(); + qDebug() << doc.cellAt(1, 1)->value().type() << doc.cellAt(1, 1)->value(); + qDebug() << doc.cellAt(2, 1)->value().type() << doc.cellAt(2, 1)->value(); + qDebug() << doc.cellAt(3, 1)->value().type() << doc.cellAt(3, 1)->value(); + qDebug() << doc.cellAt(4, 1)->value().type() << doc.cellAt(4, 1)->value(); + qDebug() << doc.cellAt(5, 1)->value().type() << doc.cellAt(5, 1)->value(); qDebug() << "\n"; doc.saveAs("datetime.xlsx"); @@ -99,81 +99,78 @@ int test2( QVector params ) qDebug() << "\n\ndoc2\n"; Document doc2("datetime.xlsx"); - if ( !doc2.load() ) - { - qWarning() << "failed to load datetime.xlsx" ; + if (!doc2.load()) { + qWarning() << "failed to load datetime.xlsx"; return (-1); } qDebug() << "\n\n"; - doc2.write( "A6", QVariant(QDateTime::currentDateTimeUtc()) ); - doc2.write( "A7", QVariant(double(10.5)) ); - doc2.write( "A8", QVariant(QDate(2019, 10, 9)) ); - doc2.write( "A9", QVariant(QTime(10, 9, 5)) ); - doc2.write( "A10", QVariant((int) 40000) ); + doc2.write("A6", QVariant(QDateTime::currentDateTimeUtc())); + doc2.write("A7", QVariant(double(10.5))); + doc2.write("A8", QVariant(QDate(2019, 10, 9))); + doc2.write("A9", QVariant(QTime(10, 9, 5))); + doc2.write("A10", QVariant((int) 40000)); qDebug() << "doc2.read()"; - qDebug() << doc2.read( 1, 1 ).type() << doc2.read( 1, 1 ); - qDebug() << doc2.read( 2, 1 ).type() << doc2.read( 2, 1 ); - qDebug() << doc2.read( 3, 1 ).type() << doc2.read( 3, 1 ); - qDebug() << doc2.read( 4, 1 ).type() << doc2.read( 4, 1 ); - qDebug() << doc2.read( 5, 1 ).type() << doc2.read( 5, 1 ); - qDebug() << doc2.read( 6, 1 ).type() << doc2.read( 6, 1 ); - qDebug() << doc2.read( 7, 1 ).type() << doc2.read( 7, 1 ); - qDebug() << doc2.read( 8, 1 ).type() << doc2.read( 8, 1 ); - qDebug() << doc2.read( 9, 1 ).type() << doc2.read( 9, 1 ); - qDebug() << doc2.read(10, 1 ).type() << doc2.read(10, 1 ); + qDebug() << doc2.read(1, 1).type() << doc2.read(1, 1); + qDebug() << doc2.read(2, 1).type() << doc2.read(2, 1); + qDebug() << doc2.read(3, 1).type() << doc2.read(3, 1); + qDebug() << doc2.read(4, 1).type() << doc2.read(4, 1); + qDebug() << doc2.read(5, 1).type() << doc2.read(5, 1); + qDebug() << doc2.read(6, 1).type() << doc2.read(6, 1); + qDebug() << doc2.read(7, 1).type() << doc2.read(7, 1); + qDebug() << doc2.read(8, 1).type() << doc2.read(8, 1); + qDebug() << doc2.read(9, 1).type() << doc2.read(9, 1); + qDebug() << doc2.read(10, 1).type() << doc2.read(10, 1); qDebug() << "\n"; qDebug() << "doc2.cellAt()->value()"; - qDebug() << doc2.cellAt( 1, 1 )->value().type() << doc2.cellAt( 1, 1 )->value(); - qDebug() << doc2.cellAt( 2, 1 )->value().type() << doc2.cellAt( 2, 1 )->value(); - qDebug() << doc2.cellAt( 3, 1 )->value().type() << doc2.cellAt( 3, 1 )->value(); - qDebug() << doc2.cellAt( 4, 1 )->value().type() << doc2.cellAt( 4, 1 )->value(); - qDebug() << doc2.cellAt( 5, 1 )->value().type() << doc2.cellAt( 5, 1 )->value(); - qDebug() << doc2.cellAt( 6, 1 )->value().type() << doc2.cellAt( 6, 1 )->value(); - qDebug() << doc2.cellAt( 7, 1 )->value().type() << doc2.cellAt( 7, 1 )->value(); - qDebug() << doc2.cellAt( 8, 1 )->value().type() << doc2.cellAt( 8, 1 )->value(); - qDebug() << doc2.cellAt( 9, 1 )->value().type() << doc2.cellAt( 9, 1 )->value(); - qDebug() << doc2.cellAt(10, 1 )->value().type() << doc2.cellAt(10, 1 )->value(); + qDebug() << doc2.cellAt(1, 1)->value().type() << doc2.cellAt(1, 1)->value(); + qDebug() << doc2.cellAt(2, 1)->value().type() << doc2.cellAt(2, 1)->value(); + qDebug() << doc2.cellAt(3, 1)->value().type() << doc2.cellAt(3, 1)->value(); + qDebug() << doc2.cellAt(4, 1)->value().type() << doc2.cellAt(4, 1)->value(); + qDebug() << doc2.cellAt(5, 1)->value().type() << doc2.cellAt(5, 1)->value(); + qDebug() << doc2.cellAt(6, 1)->value().type() << doc2.cellAt(6, 1)->value(); + qDebug() << doc2.cellAt(7, 1)->value().type() << doc2.cellAt(7, 1)->value(); + qDebug() << doc2.cellAt(8, 1)->value().type() << doc2.cellAt(8, 1)->value(); + qDebug() << doc2.cellAt(9, 1)->value().type() << doc2.cellAt(9, 1)->value(); + qDebug() << doc2.cellAt(10, 1)->value().type() << doc2.cellAt(10, 1)->value(); doc2.saveAs("datetime2.xlsx"); qDebug() << "\n\ndoc3\n"; Document doc3("datetime2.xlsx"); - if ( !doc3.load() ) - { - qWarning() << "failed to load datetime2.xlsx" ; + if (!doc3.load()) { + qWarning() << "failed to load datetime2.xlsx"; return (-1); } qDebug() << "\n\n"; qDebug() << "doc3.read()"; - qDebug() << doc3.read( 1, 1 ).type() << doc3.read( 1, 1 ); - qDebug() << doc3.read( 2, 1 ).type() << doc3.read( 2, 1 ); - qDebug() << doc3.read( 3, 1 ).type() << doc3.read( 3, 1 ); - qDebug() << doc3.read( 4, 1 ).type() << doc3.read( 4, 1 ); - qDebug() << doc3.read( 5, 1 ).type() << doc3.read( 5, 1 ); - qDebug() << doc3.read( 6, 1 ).type() << doc3.read( 6, 1 ); - qDebug() << doc3.read( 7, 1 ).type() << doc3.read( 7, 1 ); - qDebug() << doc3.read( 8, 1 ).type() << doc3.read( 8, 1 ); - qDebug() << doc3.read( 9, 1 ).type() << doc3.read( 9, 1 ); - qDebug() << doc3.read(10, 1 ).type() << doc3.read(10, 1 ); + qDebug() << doc3.read(1, 1).type() << doc3.read(1, 1); + qDebug() << doc3.read(2, 1).type() << doc3.read(2, 1); + qDebug() << doc3.read(3, 1).type() << doc3.read(3, 1); + qDebug() << doc3.read(4, 1).type() << doc3.read(4, 1); + qDebug() << doc3.read(5, 1).type() << doc3.read(5, 1); + qDebug() << doc3.read(6, 1).type() << doc3.read(6, 1); + qDebug() << doc3.read(7, 1).type() << doc3.read(7, 1); + qDebug() << doc3.read(8, 1).type() << doc3.read(8, 1); + qDebug() << doc3.read(9, 1).type() << doc3.read(9, 1); + qDebug() << doc3.read(10, 1).type() << doc3.read(10, 1); qDebug() << "\n"; qDebug() << "doc3.cellAt()->value()"; - qDebug() << doc3.cellAt( 1, 1 )->value().type() << doc3.cellAt( 1, 1 )->value(); - qDebug() << doc3.cellAt( 2, 1 )->value().type() << doc3.cellAt( 2, 1 )->value(); - qDebug() << doc3.cellAt( 3, 1 )->value().type() << doc3.cellAt( 3, 1 )->value(); - qDebug() << doc3.cellAt( 4, 1 )->value().type() << doc3.cellAt( 4, 1 )->value(); - qDebug() << doc3.cellAt( 5, 1 )->value().type() << doc3.cellAt( 5, 1 )->value(); - qDebug() << doc3.cellAt( 6, 1 )->value().type() << doc3.cellAt( 6, 1 )->value(); - qDebug() << doc3.cellAt( 7, 1 )->value().type() << doc3.cellAt( 7, 1 )->value(); - qDebug() << doc3.cellAt( 8, 1 )->value().type() << doc3.cellAt( 8, 1 )->value(); - qDebug() << doc3.cellAt( 9, 1 )->value().type() << doc3.cellAt( 9, 1 )->value(); - qDebug() << doc3.cellAt(10, 1 )->value().type() << doc3.cellAt(10, 1 )->value(); + qDebug() << doc3.cellAt(1, 1)->value().type() << doc3.cellAt(1, 1)->value(); + qDebug() << doc3.cellAt(2, 1)->value().type() << doc3.cellAt(2, 1)->value(); + qDebug() << doc3.cellAt(3, 1)->value().type() << doc3.cellAt(3, 1)->value(); + qDebug() << doc3.cellAt(4, 1)->value().type() << doc3.cellAt(4, 1)->value(); + qDebug() << doc3.cellAt(5, 1)->value().type() << doc3.cellAt(5, 1)->value(); + qDebug() << doc3.cellAt(6, 1)->value().type() << doc3.cellAt(6, 1)->value(); + qDebug() << doc3.cellAt(7, 1)->value().type() << doc3.cellAt(7, 1)->value(); + qDebug() << doc3.cellAt(8, 1)->value().type() << doc3.cellAt(8, 1)->value(); + qDebug() << doc3.cellAt(9, 1)->value().type() << doc3.cellAt(9, 1)->value(); + qDebug() << doc3.cellAt(10, 1)->value().type() << doc3.cellAt(10, 1)->value(); doc2.saveAs("datetime2.xlsx"); return 0; } - diff --git a/HelloAndroid/DynArray2D.h b/HelloAndroid/DynArray2D.h index c0d2a3d7..f05f623f 100644 --- a/HelloAndroid/DynArray2D.h +++ b/HelloAndroid/DynArray2D.h @@ -2,39 +2,33 @@ #ifndef DYNARRAY2D_H #define DYNARRAY2D_H -// Code from https://www.qtcentre.org/threads/31440-two-dimensional-array-size-determined-dynamically -// Some code is fixed by j2doll +// Code from +// https://www.qtcentre.org/threads/31440-two-dimensional-array-size-determined-dynamically Some +// code is fixed by j2doll -template class DynArray2D +template +class DynArray2D { public: DynArray2D(int n, int m) { - _n = n; - _array = new T*[n]; - for(int i = 0; i < n; i++) - { + _n = n; + _array = new T *[n]; + for (int i = 0; i < n; i++) { _array[i] = new T[m]; } } - void setValue(int n, int m, T v) - { - _array[n][m] = v; - } + void setValue(int n, int m, T v) { _array[n][m] = v; } - T getValue(int n, int m) - { - return _array[n][m]; - } + T getValue(int n, int m) { return _array[n][m]; } ~DynArray2D() { - for (int i = 0 ; i < _n ; i++) - { - delete [] _array[i]; + for (int i = 0; i < _n; i++) { + delete[] _array[i]; } - delete [] _array; + delete[] _array; } protected: @@ -42,5 +36,4 @@ template class DynArray2D int _n; }; - #endif // DYNARRAY2D_H diff --git a/HelloAndroid/XlsxTableModel.cpp b/HelloAndroid/XlsxTableModel.cpp index 696acbbc..bfb7a909 100644 --- a/HelloAndroid/XlsxTableModel.cpp +++ b/HelloAndroid/XlsxTableModel.cpp @@ -6,27 +6,25 @@ #include "XlsxTableModel.h" -#include -#include - #include +#include +#include XlsxTableModel::XlsxTableModel(const QList &colTitle, QList data, QObject *parent) : QAbstractTableModel(parent) { - // [1] set name of column + // [1] set name of column - m_colNames = colTitle; - m_roleCount = m_colNames.size(); + m_colNames = colTitle; + m_roleCount = m_colNames.size(); - // [2] set data + // [2] set data - for (int dc = 0; dc < data.size() ; dc++ ) - { - VLIST vList = data.at(dc); - m_the_data.append( vList ); - } + for (int dc = 0; dc < data.size(); dc++) { + VLIST vList = data.at(dc); + m_the_data.append(vList); + } } void XlsxTableModel::testData() @@ -42,9 +40,9 @@ void XlsxTableModel::testData() // set name of column - m_colNames.append( QString( "COL1" ) ); - m_colNames.append( QString( "COL2" ) ); - m_colNames.append( QString( "COL3" ) ); + m_colNames.append(QString("COL1")); + m_colNames.append(QString("COL2")); + m_colNames.append(QString("COL3")); m_roleCount = m_colNames.size(); @@ -54,51 +52,49 @@ void XlsxTableModel::testData() list1.append(QVariant("Alpha")); list1.append(QVariant(10)); list1.append(QVariant(100.0)); - m_the_data.append( list1 ); + m_the_data.append(list1); VLIST list2; list2.append(QVariant("Beta")); list2.append(QVariant(20)); list2.append(QVariant(200.0)); - m_the_data.append( list2 ); + m_the_data.append(list2); VLIST list3; list3.append(QVariant("Gamma")); list3.append(QVariant(30)); list3.append(QVariant(300.0)); - m_the_data.append( list3 ); + m_the_data.append(list3); VLIST list4; list4.append(QVariant("Delta")); list4.append(QVariant(40)); list4.append(QVariant(400.0)); - m_the_data.append( list4 ); - + m_the_data.append(list4); } -int XlsxTableModel::rowCount(const QModelIndex& parent) const +int XlsxTableModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent) return m_the_data.size(); } -int XlsxTableModel::columnCount(const QModelIndex& parent) const +int XlsxTableModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent) return m_roleCount; } -QVariant XlsxTableModel::data(const QModelIndex& index, int role) const +QVariant XlsxTableModel::data(const QModelIndex &index, int role) const { // current column & row int col = index.column(); int row = index.row(); // check boudaries - if ( col < 0 || columnCount() <= col || - row < 0 || rowCount() <= row ) - { - qDebug() << "[Warning]" << " col=" << col << ", row=" << row; + if (col < 0 || columnCount() <= col || row < 0 || rowCount() <= row) { + qDebug() << "[Warning]" + << " col=" << col << ", row=" << row; return QVariant(); } @@ -107,32 +103,28 @@ QVariant XlsxTableModel::data(const QModelIndex& index, int role) const QVariant ret; int cmpRole; - for (int ic = 0; ic < m_the_data.size() ; ic++) - { - if ( row == ic ) - { + for (int ic = 0; ic < m_the_data.size(); ic++) { + if (row == ic) { QList vList = m_the_data.at(ic); - for (int jc = 0; jc < vList.size() ; jc++ ) - { - int plusOneRole = (int)(Qt::UserRole); - plusOneRole = plusOneRole + 1; - cmpRole = plusOneRole + jc; - if ( role == cmpRole ) - { + for (int jc = 0; jc < vList.size(); jc++) { + int plusOneRole = (int) (Qt::UserRole); + plusOneRole = plusOneRole + 1; + cmpRole = plusOneRole + jc; + if (role == cmpRole) { QVariant var = vList.at(jc); - if ( ! var.isValid() ) var.setValue( QString("") ) ; - if ( var.isNull() ) var.setValue( QString("") ) ; + if (!var.isValid()) + var.setValue(QString("")); + if (var.isNull()) + var.setValue(QString("")); ret = var; } } } } - qDebug() - << "data: " - << " col=" << col << ", row=" << row - << ", role=" << role << ", cmpRole=" << cmpRole - << ", value=" << ret.toString(); + qDebug() << "data: " + << " col=" << col << ", row=" << row << ", role=" << role << ", cmpRole=" << cmpRole + << ", value=" << ret.toString(); return ret; } @@ -141,11 +133,10 @@ QHash XlsxTableModel::roleNames() const { QHash roles; - for ( int ic = 0 ; ic < m_roleCount ; ic++) - { + for (int ic = 0; ic < m_roleCount; ic++) { QString strRole = m_colNames.at(ic); - int roleNo = (Qt::UserRole+1) + ic; - roles.insert( roleNo, strRole.toLatin1() ); + int roleNo = (Qt::UserRole + 1) + ic; + roles.insert(roleNo, strRole.toLatin1()); } return roles; @@ -157,16 +148,12 @@ QStringList XlsxTableModel::customRoleNames() QMap res; QHashIterator i(roleNames()); - while ( i.hasNext() ) - { + while (i.hasNext()) { i.next(); - if ( i.key() > Qt::UserRole ) - { - res[ i.key() ] = i.value(); + if (i.key() > Qt::UserRole) { + res[i.key()] = i.value(); } } return res.values(); } - - diff --git a/HelloAndroid/XlsxTableModel.h b/HelloAndroid/XlsxTableModel.h index d6fe9063..3257dd7f 100644 --- a/HelloAndroid/XlsxTableModel.h +++ b/HelloAndroid/XlsxTableModel.h @@ -7,19 +7,19 @@ #ifndef XLSX_MODEL_H #define XLSX_MODEL_H -#include +#include +#include +#include + +#include +#include +#include #include #include #include -#include -#include -#include #include -#include - -#include -#include -#include +#include +#include typedef QList VLIST; @@ -29,13 +29,14 @@ class XlsxTableModel : public QAbstractTableModel // method that is called by QML script Q_PROPERTY(QStringList customRoleNames READ customRoleNames CONSTANT) -public: QStringList customRoleNames(); +public: + QStringList customRoleNames(); public: // constrcutor XlsxTableModel(const QList &colTitle, QList data, QObject *parent = NULL); public: // virtual function of parent object - int rowCount(const QModelIndex & parent = QModelIndex()) const Q_DECL_OVERRIDE; + int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; QHash roleNames() const Q_DECL_OVERRIDE; @@ -44,10 +45,9 @@ public: QStringList customRoleNames(); void testData(); // test function. protected: - QList m_the_data; // table cell data + QList m_the_data; // table cell data QList m_colNames; // column name - quint32 m_roleCount; // role count (same as column count) - + quint32 m_roleCount; // role count (same as column count) }; #endif diff --git a/HelloAndroid/main.cpp b/HelloAndroid/main.cpp index 76ee426f..1a3c516b 100644 --- a/HelloAndroid/main.cpp +++ b/HelloAndroid/main.cpp @@ -4,116 +4,107 @@ // main.cpp -#include -#include -#include -#include -#include -#include +#include "xlsxcellrange.h" +#include "xlsxchart.h" +#include "xlsxchartsheet.h" +#include "xlsxdocument.h" +#include "xlsxrichstring.h" +#include "xlsxworkbook.h" -#include +#include +#include +#include #include +#include +#include #include #include - -#include -#include - -#include "xlsxdocument.h" -#include "xlsxchartsheet.h" -#include "xlsxcellrange.h" -#include "xlsxchart.h" -#include "xlsxrichstring.h" -#include "xlsxworkbook.h" +#include +#include +#include +#include using namespace QXlsx; -#include "XlsxTableModel.h" #include "DynArray2D.h" +#include "XlsxTableModel.h" std::string convertFromNumberToExcelColumn(int n); int main(int argc, char *argv[]) { - QCoreApplication::setAttribute( Qt::AA_EnableHighDpiScaling ); + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; - QQmlContext* ctxt = engine.rootContext(); + QQmlContext *ctxt = engine.rootContext(); - QXlsx::Document xlsx( ":/test.xlsx" ); // load xlsx - if (!xlsx.load()) - { + QXlsx::Document xlsx(":/test.xlsx"); // load xlsx + if (!xlsx.load()) { qDebug() << "[ERROR] Failed to load xlsx"; return (-1); } - QList colTitle; // list of column title + QList colTitle; // list of column title QVector vcl; // vector of cell(s) location - Worksheet* wsheet = (Worksheet*) xlsx.workbook()->activeSheet(); - if ( NULL == wsheet ) - { + Worksheet *wsheet = (Worksheet *) xlsx.workbook()->activeSheet(); + if (NULL == wsheet) { qDebug() << "[ERROR] Failed to get active sheet"; return (-2); } int rowMax = -1; int colMax = -1; - vcl = wsheet->getFullCells( &rowMax, &colMax ); + vcl = wsheet->getFullCells(&rowMax, &colMax); - Q_ASSERT( (-1) != rowMax ); // To CHECK - Q_ASSERT( (-1) != colMax ); + Q_ASSERT((-1) != rowMax); // To CHECK + Q_ASSERT((-1) != colMax); - for (int ic = 0 ; ic < colMax ; ic++) - { + for (int ic = 0; ic < colMax; ic++) { std::string strCol = convertFromNumberToExcelColumn(ic + 1); - QString colName = QString::fromStdString( strCol ); - colTitle.append( colName ); + QString colName = QString::fromStdString(strCol); + colTitle.append(colName); } // make cell matrix that has (colMax x rowMax) size. - DynArray2D< std::string > dynIntArray(colMax, rowMax); + DynArray2D dynIntArray(colMax, rowMax); - for ( int icl = 0; icl < vcl.size(); ++icl ) - { - CellLocation cl = vcl.at(icl); // cell location + for (int icl = 0; icl < vcl.size(); ++icl) { + CellLocation cl = vcl.at(icl); // cell location - // NOTICE: First cell of tableWidget is 0. - // But first cell of Qxlsx document is 1. - int row = cl.row - 1; - int col = cl.col - 1; + // NOTICE: First cell of tableWidget is 0. + // But first cell of Qxlsx document is 1. + int row = cl.row - 1; + int col = cl.col - 1; - auto ptrCell = cl.cell; // cell pointer + auto ptrCell = cl.cell; // cell pointer - // value of cell - QVariant var = ptrCell->value(); - QString str = var.toString(); + // value of cell + QVariant var = ptrCell->value(); + QString str = var.toString(); - // set string value to (col, row) - dynIntArray.setValue( col, row, str.toStdString() ); + // set string value to (col, row) + dynIntArray.setValue(col, row, str.toStdString()); } QList xlsxData; - for (int ir = 0; ir < rowMax; ir++ ) - { + for (int ir = 0; ir < rowMax; ir++) { VLIST vl; - for (int ic = 0; ic < colMax; ic++) - { - std::string value = dynIntArray.getValue( ic, ir ); - vl.append( QString::fromStdString(value) ); + for (int ic = 0; ic < colMax; ic++) { + std::string value = dynIntArray.getValue(ic, ir); + vl.append(QString::fromStdString(value)); } xlsxData.append(vl); } // set model for tableview XlsxTableModel xlsxTableModel(colTitle, xlsxData); - ctxt->setContextProperty( "xlsxModel", &xlsxTableModel ); + ctxt->setContextProperty("xlsxModel", &xlsxTableModel); - engine.load( QUrl(QStringLiteral("qrc:/main.qml")) ); // load QML - if ( engine.rootObjects().isEmpty() ) - { + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); // load QML + if (engine.rootObjects().isEmpty()) { qDebug() << "Failed to load qml"; return (-1); } @@ -130,29 +121,26 @@ std::string convertFromNumberToExcelColumn(int n) std::string stdString; char str[1000]; // To store result (Excel column name) - int i = 0; // To store current index in str which is result + int i = 0; // To store current index in str which is result - while ( n > 0 ) - { + while (n > 0) { // Find remainder int rem = n % 26; // If remainder is 0, then a 'Z' must be there in output - if ( rem == 0 ) - { + if (rem == 0) { str[i++] = 'Z'; - n = (n/26) - 1; - } - else // If remainder is non-zero + n = (n / 26) - 1; + } else // If remainder is non-zero { - str[i++] = (rem-1) + 'A'; - n = n / 26; + str[i++] = (rem - 1) + 'A'; + n = n / 26; } } str[i] = '\0'; // Reverse the string and print result - std::reverse( str, str + strlen(str) ); + std::reverse(str, str + strlen(str)); stdString = str; return stdString; diff --git a/HelloWorld/main.cpp b/HelloWorld/main.cpp index c719e19c..3438b69e 100644 --- a/HelloWorld/main.cpp +++ b/HelloWorld/main.cpp @@ -2,21 +2,21 @@ // QXlsx // MIT License // https://github.com/j2doll/QXlsx // -#include +#include + #include -#include -#include -#include #include - -#include +#include +#include +#include +#include using namespace std; // [0] include QXlsx headers -#include "xlsxdocument.h" -#include "xlsxchartsheet.h" #include "xlsxcellrange.h" #include "xlsxchart.h" +#include "xlsxchartsheet.h" +#include "xlsxdocument.h" #include "xlsxrichstring.h" #include "xlsxworkbook.h" using namespace QXlsx; @@ -30,18 +30,17 @@ int main(int argc, char *argv[]) QXlsx::Document xlsxW; - int row = 1; int col = 1; // + int row = 1; + int col = 1; // // xlsxW.write("A1", "Hello Qt!"); // write "Hello Qt!" to cell(A,1). it's shared string. QVariant writeValue = QString("Hello Qt!"); xlsxW.write(row, col, writeValue); - if ( xlsxW.saveAs("Test.xlsx") ) // save the document as 'Test.xlsx' + if (xlsxW.saveAs("Test.xlsx")) // save the document as 'Test.xlsx' { qDebug() << "[debug] success to write xlsx file"; - } - else - { + } else { qDebug() << "[debug][error] failed to write xlsx file"; exit(-1); } @@ -51,25 +50,21 @@ int main(int argc, char *argv[]) //-------------------------------------- // [2] Reading excel file(*.xlsx) - Document xlsxR("Test.xlsx"); - if ( xlsxR.load() ) // load excel file + Document xlsxR("Test.xlsx"); + if (xlsxR.load()) // load excel file { qDebug() << "[debug] success to load xlsx file."; - Cell* cell = xlsxR.cellAt(row, col); // get cell pointer. - if ( cell != NULL ) - { - QVariant var = cell->readValue(); // read cell value (number(double), QDateTime, QString ...) + Cell *cell = xlsxR.cellAt(row, col); // get cell pointer. + if (cell != NULL) { + QVariant var = + cell->readValue(); // read cell value (number(double), QDateTime, QString ...) qDebug() << "[debug] cell(1,1) is " << var; // Display value. It is 'Hello Qt!'. - } - else - { + } else { qDebug() << "[debug][error] cell(1,1) is not set."; exit(-2); } - } - else - { + } else { qDebug() << "[debug][error] failed to load xlsx file."; } diff --git a/IssueTest/main.cpp b/IssueTest/main.cpp index a302d500..fe1e1876 100644 --- a/IssueTest/main.cpp +++ b/IssueTest/main.cpp @@ -1,19 +1,19 @@ // main.cpp -#include +#include + #include -#include -#include +#include #include -#include - -#include +#include +#include +#include using namespace std; -#include "xlsxdocument.h" -#include "xlsxchartsheet.h" #include "xlsxcellrange.h" #include "xlsxchart.h" +#include "xlsxchartsheet.h" +#include "xlsxdocument.h" #include "xlsxrichstring.h" #include "xlsxworkbook.h" using namespace QXlsx; @@ -22,12 +22,11 @@ extern int test(QVector params); int main(int argc, char *argv[]) { - QCoreApplication app(argc, argv); + QCoreApplication app(argc, argv); - QVector testParams; - int ret = test(testParams); + QVector testParams; + int ret = test(testParams); // qDebug() << "test return value : " << ret; - return 0; + return 0; } - diff --git a/IssueTest/test.cpp b/IssueTest/test.cpp index dbaa7626..c92f7b3d 100644 --- a/IssueTest/test.cpp +++ b/IssueTest/test.cpp @@ -1,28 +1,28 @@ // test.cpp -#include +#include + +#include #include -#include -#include -#include -#include +#include #include -#include #include -#include #include - -#include +#include +#include +#include +#include +#include using namespace std; -#include "xlsxdocument.h" -#include "xlsxchartsheet.h" #include "xlsxcellrange.h" #include "xlsxchart.h" +#include "xlsxchartsheet.h" +#include "xlsxdocument.h" #include "xlsxrichstring.h" #include "xlsxworkbook.h" -int test162( QVector params ) +int test162(QVector params) { using namespace QXlsx; @@ -31,22 +31,17 @@ int test162( QVector params ) xlsx.saveAs("image1.xlsx"); Document xlsx2("image1.xlsx"); - qDebug() << "xlsx2" ; + qDebug() << "xlsx2"; qDebug() << " image count : " << xlsx.getImageCount(); xlsx2.saveAs("image2.xlsx"); return 0; } -int test( QVector params ) +int test(QVector params) { qDebug() << "[debug] current path : " << QDir::currentPath(); // return test162( params ); - - return 0; } - - - diff --git a/Pump/colorprintf.h b/Pump/colorprintf.h index c02ef2e9..e0040915 100644 --- a/Pump/colorprintf.h +++ b/Pump/colorprintf.h @@ -30,11 +30,11 @@ extern "C" { #endif -#include #include +#include #ifdef _WIN32 -#include +# include #endif /* @@ -49,75 +49,76 @@ extern "C" { * 4 -> magenta * 5 -> cyan */ -int colorprintf(int color, const char *format, ...) { - int fcolor = -1, retval = -99; - va_list args; +int colorprintf(int color, const char *format, ...) +{ + int fcolor = -1, retval = -99; + va_list args; #ifdef _WIN32 - if (color == 0) { - fcolor = FOREGROUND_RED; - } else if (color == 1) { - fcolor = FOREGROUND_GREEN; - } else if (color == 2) { - fcolor = FOREGROUND_RED | FOREGROUND_GREEN; - } else if (color == 3) { - fcolor = FOREGROUND_BLUE; - } else if (color == 4) { - fcolor = FOREGROUND_RED | FOREGROUND_BLUE; - } else if (color == 5) { - fcolor = FOREGROUND_GREEN | FOREGROUND_BLUE; - } - CONSOLE_SCREEN_BUFFER_INFO csbiInfo; - WORD wOldColorAttrs; - HANDLE hStdout; - if (fcolor != -1) { - hStdout = GetStdHandle(STD_OUTPUT_HANDLE); - if ((hStdout == NULL) || (hStdout == INVALID_HANDLE_VALUE)) { - return -99; - } - if (GetConsoleScreenBufferInfo(hStdout, &csbiInfo) == 0) { - return -99; - } - wOldColorAttrs = csbiInfo.wAttributes; - if (SetConsoleTextAttribute(hStdout, fcolor | FOREGROUND_INTENSITY) == 0) { - return -99; - } - } + if (color == 0) { + fcolor = FOREGROUND_RED; + } else if (color == 1) { + fcolor = FOREGROUND_GREEN; + } else if (color == 2) { + fcolor = FOREGROUND_RED | FOREGROUND_GREEN; + } else if (color == 3) { + fcolor = FOREGROUND_BLUE; + } else if (color == 4) { + fcolor = FOREGROUND_RED | FOREGROUND_BLUE; + } else if (color == 5) { + fcolor = FOREGROUND_GREEN | FOREGROUND_BLUE; + } + CONSOLE_SCREEN_BUFFER_INFO csbiInfo; + WORD wOldColorAttrs; + HANDLE hStdout; + if (fcolor != -1) { + hStdout = GetStdHandle(STD_OUTPUT_HANDLE); + if ((hStdout == NULL) || (hStdout == INVALID_HANDLE_VALUE)) { + return -99; + } + if (GetConsoleScreenBufferInfo(hStdout, &csbiInfo) == 0) { + return -99; + } + wOldColorAttrs = csbiInfo.wAttributes; + if (SetConsoleTextAttribute(hStdout, fcolor | FOREGROUND_INTENSITY) == 0) { + return -99; + } + } #else - if (color == 0) { - fcolor = 1; - } else if (color == 1) { - fcolor = 2; - } else if (color == 2) { - fcolor = 3; - } else if (color == 3) { - fcolor = 4; - } else if (color == 4) { - fcolor = 5; - } else if (color == 5) { - fcolor = 6; - } - if (fcolor != -1 && printf("\033[1;3%dm", fcolor) < 0) { - return -99; - } + if (color == 0) { + fcolor = 1; + } else if (color == 1) { + fcolor = 2; + } else if (color == 2) { + fcolor = 3; + } else if (color == 3) { + fcolor = 4; + } else if (color == 4) { + fcolor = 5; + } else if (color == 5) { + fcolor = 6; + } + if (fcolor != -1 && printf("\033[1;3%dm", fcolor) < 0) { + return -99; + } #endif - va_start(args, format); - if (!args) { - return -99; - } - retval = vprintf(format, args); - va_end(args); - if (fcolor != -1) { + va_start(args, format); + if (!args) { + return -99; + } + retval = vprintf(format, args); + va_end(args); + if (fcolor != -1) { #ifdef _WIN32 - if (SetConsoleTextAttribute(hStdout, wOldColorAttrs) == 0) { - return -99; - } + if (SetConsoleTextAttribute(hStdout, wOldColorAttrs) == 0) { + return -99; + } #else - if (printf("\033[0m") < 0) { - return -99; - } + if (printf("\033[0m") < 0) { + return -99; + } #endif - } - return retval; + } + return retval; } #ifdef __cplusplus diff --git a/Pump/main.cpp b/Pump/main.cpp index 88e1e7b3..dc243bad 100644 --- a/Pump/main.cpp +++ b/Pump/main.cpp @@ -1,19 +1,19 @@ // main.cpp -#include +#include + #include -#include -#include +#include #include -#include - -#include +#include +#include +#include using namespace std; -#include "xlsxdocument.h" -#include "xlsxchartsheet.h" #include "xlsxcellrange.h" #include "xlsxchart.h" +#include "xlsxchartsheet.h" +#include "xlsxdocument.h" #include "xlsxrichstring.h" #include "xlsxworkbook.h" using namespace QXlsx; @@ -22,11 +22,10 @@ extern int test(QVector params); int main(int argc, char *argv[]) { - QCoreApplication app(argc, argv); + QCoreApplication app(argc, argv); - QVector testParams; - int ret = test(testParams); + QVector testParams; + int ret = test(testParams); - return 0; + return 0; } - diff --git a/Pump/test.cpp b/Pump/test.cpp index 12364b9d..52206cd5 100644 --- a/Pump/test.cpp +++ b/Pump/test.cpp @@ -1,28 +1,28 @@ // test.cpp -#include +#include +#include +#include +#include + +#include #include -#include -#include -#include -#include +#include +#include #include #include -#include -#include -#include #include - -#include -#include -#include -#include +#include +#include +#include +#include +#include using namespace std; -#include "xlsxdocument.h" -#include "xlsxchartsheet.h" #include "xlsxcellrange.h" #include "xlsxchart.h" +#include "xlsxchartsheet.h" +#include "xlsxdocument.h" #include "xlsxrichstring.h" #include "xlsxworkbook.h" @@ -30,21 +30,19 @@ using namespace std; // #include "colorprintf.h" // https://github.com/VittGam/colorprintf #endif -int test( QVector params ); +int test(QVector params); -int test( QVector params ) +int test(QVector params) { qDebug() << "[debug] current path : " << QDir::currentPath(); QFile fileNames(":/xlsx_files/dir2.txt"); - if ( !fileNames.open(QIODevice::ReadOnly | QIODevice::Text) ) - { + if (!fileNames.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "[debug] failed to load dir2.txt"; return (-1); } - while (!fileNames.atEnd()) - { + while (!fileNames.atEnd()) { QByteArray line = fileNames.readLine(); QString strArg(line); @@ -56,19 +54,13 @@ int test( QVector params ) { using namespace QXlsx; Document output2(currentFilename); - if ( output2.load() ) - { - if ( output2.saveAs( strArg3 ) ) - { + if (output2.load()) { + if (output2.saveAs(strArg3)) { qDebug() << "[debug] xlsx is saved. " << strArg3; - } - else - { + } else { qCritical() << "[debug] failed to save. " << strArg3; } - } - else - { + } else { qCritical() << "[debug] failed to load. " << strArg3; } } @@ -76,4 +68,3 @@ int test( QVector params ) return 0; } - diff --git a/QXlsx/header/xlsxabstractooxmlfile.h b/QXlsx/header/xlsxabstractooxmlfile.h index 8355b0b9..5de9db11 100644 --- a/QXlsx/header/xlsxabstractooxmlfile.h +++ b/QXlsx/header/xlsxabstractooxmlfile.h @@ -15,17 +15,13 @@ class QXLSX_EXPORT AbstractOOXmlFile Q_DECLARE_PRIVATE(AbstractOOXmlFile) public: - enum CreateFlag - { - F_NewFromScratch, - F_LoadFromExists - }; + enum CreateFlag { F_NewFromScratch, F_LoadFromExists }; public: virtual ~AbstractOOXmlFile(); virtual void saveToXmlFile(QIODevice *device) const = 0; - virtual bool loadFromXmlFile(QIODevice *device) = 0; + virtual bool loadFromXmlFile(QIODevice *device) = 0; virtual QByteArray saveToXmlData() const; virtual bool loadFromXmlData(const QByteArray &data); diff --git a/QXlsx/header/xlsxabstractooxmlfile_p.h b/QXlsx/header/xlsxabstractooxmlfile_p.h index 30fea98b..027e8a5d 100644 --- a/QXlsx/header/xlsxabstractooxmlfile_p.h +++ b/QXlsx/header/xlsxabstractooxmlfile_p.h @@ -3,9 +3,8 @@ #ifndef XLSXOOXMLFILE_P_H #define XLSXOOXMLFILE_P_H -#include "xlsxglobal.h" - #include "xlsxabstractooxmlfile.h" +#include "xlsxglobal.h" #include "xlsxrelationships_p.h" QT_BEGIN_NAMESPACE_XLSX @@ -15,11 +14,11 @@ class AbstractOOXmlFilePrivate Q_DECLARE_PUBLIC(AbstractOOXmlFile) public: - AbstractOOXmlFilePrivate(AbstractOOXmlFile* q, AbstractOOXmlFile::CreateFlag flag); + AbstractOOXmlFilePrivate(AbstractOOXmlFile *q, AbstractOOXmlFile::CreateFlag flag); virtual ~AbstractOOXmlFilePrivate(); public: - QString filePathInPackage; //such as "xl/worksheets/sheet1.xml" + QString filePathInPackage; // such as "xl/worksheets/sheet1.xml" Relationships *relationships; AbstractOOXmlFile::CreateFlag flag; diff --git a/QXlsx/header/xlsxabstractsheet.h b/QXlsx/header/xlsxabstractsheet.h index 8104740c..674a267a 100644 --- a/QXlsx/header/xlsxabstractsheet.h +++ b/QXlsx/header/xlsxabstractsheet.h @@ -3,8 +3,8 @@ #ifndef XLSXABSTRACTSHEET_H #define XLSXABSTRACTSHEET_H -#include "xlsxglobal.h" #include "xlsxabstractooxmlfile.h" +#include "xlsxglobal.h" QT_BEGIN_NAMESPACE_XLSX @@ -22,7 +22,7 @@ class QXLSX_EXPORT AbstractSheet : public AbstractOOXmlFile public: // NOTE: If all Qt compiler supports C++1x, recommend to use a 'class enum'. enum SheetType { ST_WorkSheet, ST_ChartSheet, ST_DialogSheet, ST_MacroSheet }; - enum SheetState { SS_Visible,SS_Hidden, SS_VeryHidden }; + enum SheetState { SS_Visible, SS_Hidden, SS_VeryHidden }; public: QString sheetName() const; diff --git a/QXlsx/header/xlsxabstractsheet_p.h b/QXlsx/header/xlsxabstractsheet_p.h index b95a0581..6b5568fa 100644 --- a/QXlsx/header/xlsxabstractsheet_p.h +++ b/QXlsx/header/xlsxabstractsheet_p.h @@ -3,15 +3,14 @@ #ifndef XLSXABSTRACTSHEET_P_H #define XLSXABSTRACTSHEET_P_H -#include +#include "xlsxabstractooxmlfile_p.h" +#include "xlsxabstractsheet.h" +#include "xlsxdrawing_p.h" +#include "xlsxglobal.h" #include -#include "xlsxglobal.h" - -#include "xlsxabstractsheet.h" -#include "xlsxabstractooxmlfile_p.h" -#include "xlsxdrawing_p.h" +#include QT_BEGIN_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxcell.h b/QXlsx/header/xlsxcell.h index 619d41ff..aa47ce1e 100644 --- a/QXlsx/header/xlsxcell.h +++ b/QXlsx/header/xlsxcell.h @@ -3,18 +3,18 @@ #ifndef QXLSX_XLSXCELL_H #define QXLSX_XLSXCELL_H +#include "xlsxformat.h" +#include "xlsxglobal.h" + #include -#include -#include -#include -#include #include #include +#include +#include #include - -#include "xlsxglobal.h" -#include "xlsxformat.h" +#include +#include QT_BEGIN_NAMESPACE_XLSX @@ -26,7 +26,7 @@ class WorksheetPrivate; class QXLSX_EXPORT Cell { - Q_DECLARE_PRIVATE(Cell) + Q_DECLARE_PRIVATE(Cell) private: friend class Worksheet; @@ -43,38 +43,37 @@ class QXLSX_EXPORT Cell SharedStringType, StringType, CustomType, // custom or un-defined cell type - }; + }; public: Cell(const QVariant &data = QVariant(), - CellType type = NumberType, - const Format &format = Format(), - Worksheet *parent = nullptr, - qint32 styleIndex = (-1) ); - Cell(const Cell * const cell); + CellType type = NumberType, + const Format &format = Format(), + Worksheet *parent = nullptr, + qint32 styleIndex = (-1)); + Cell(const Cell *const cell); ~Cell(); public: - CellPrivate * const d_ptr; // See D-pointer and Q-pointer of Qt, for more information. + CellPrivate *const d_ptr; // See D-pointer and Q-pointer of Qt, for more information. public: - CellType cellType() const; - QVariant value() const; - QVariant readValue() const; - Format format() const; - - bool hasFormula() const; - CellFormula formula() const; - - bool isDateTime() const; - QVariant dateTime() const; // QDateTime, QDate, QTime + CellType cellType() const; + QVariant value() const; + QVariant readValue() const; + Format format() const; - bool isRichString() const; + bool hasFormula() const; + CellFormula formula() const; + + bool isDateTime() const; + QVariant dateTime() const; // QDateTime, QDate, QTime - qint32 styleNumber() const; + bool isRichString() const; - static bool isDateType(CellType cellType, const Format &format); + qint32 styleNumber() const; + static bool isDateType(CellType cellType, const Format &format); }; QT_END_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxcell_p.h b/QXlsx/header/xlsxcell_p.h index 0abcc428..d7d71c20 100644 --- a/QXlsx/header/xlsxcell_p.h +++ b/QXlsx/header/xlsxcell_p.h @@ -3,15 +3,15 @@ #ifndef XLSXCELL_P_H #define XLSXCELL_P_H -#include -#include -#include - -#include "xlsxglobal.h" #include "xlsxcell.h" +#include "xlsxcellformula.h" #include "xlsxcellrange.h" +#include "xlsxglobal.h" #include "xlsxrichstring.h" -#include "xlsxcellformula.h" + +#include +#include +#include QT_BEGIN_NAMESPACE_XLSX @@ -20,10 +20,12 @@ class CellPrivate Q_DECLARE_PUBLIC(Cell) public: CellPrivate(Cell *p); - CellPrivate(const CellPrivate * const cp); + CellPrivate(const CellPrivate *const cp); + public: Worksheet *parent; Cell *q_ptr; + public: Cell::CellType cellType; QVariant value; diff --git a/QXlsx/header/xlsxcellformula.h b/QXlsx/header/xlsxcellformula.h index f0f4de41..4b96c9ae 100644 --- a/QXlsx/header/xlsxcellformula.h +++ b/QXlsx/header/xlsxcellformula.h @@ -24,14 +24,14 @@ class QXLSX_EXPORT CellFormula public: CellFormula(); - CellFormula(const char *formula, FormulaType type=NormalType); - CellFormula(const QString &formula, FormulaType type=NormalType); + CellFormula(const char *formula, FormulaType type = NormalType); + CellFormula(const QString &formula, FormulaType type = NormalType); CellFormula(const QString &formula, const CellRange &ref, FormulaType type); CellFormula(const CellFormula &other); ~CellFormula(); public: - CellFormula &operator =(const CellFormula &other); + CellFormula &operator=(const CellFormula &other); bool isValid() const; FormulaType formulaType() const; @@ -39,11 +39,12 @@ class QXLSX_EXPORT CellFormula CellRange reference() const; int sharedIndex() const; - bool operator == (const CellFormula &formula) const; - bool operator != (const CellFormula &formula) const; + bool operator==(const CellFormula &formula) const; + bool operator!=(const CellFormula &formula) const; bool saveToXml(QXmlStreamWriter &writer) const; bool loadFromXml(QXmlStreamReader &reader); + private: friend class Worksheet; friend class WorksheetPrivate; diff --git a/QXlsx/header/xlsxcellformula_p.h b/QXlsx/header/xlsxcellformula_p.h index 4390089c..6e8c8fca 100644 --- a/QXlsx/header/xlsxcellformula_p.h +++ b/QXlsx/header/xlsxcellformula_p.h @@ -3,9 +3,9 @@ #ifndef XLSXCELLFORMULA_P_H #define XLSXCELLFORMULA_P_H -#include "xlsxglobal.h" #include "xlsxcellformula.h" #include "xlsxcellrange.h" +#include "xlsxglobal.h" #include #include @@ -15,15 +15,17 @@ QT_BEGIN_NAMESPACE_XLSX class CellFormulaPrivate : public QSharedData { public: - CellFormulaPrivate(const QString &formula, const CellRange &reference, CellFormula::FormulaType type); + CellFormulaPrivate(const QString &formula, + const CellRange &reference, + CellFormula::FormulaType type); CellFormulaPrivate(const CellFormulaPrivate &other); ~CellFormulaPrivate(); - QString formula; //formula contents + QString formula; // formula contents CellFormula::FormulaType type; CellRange reference; - bool ca; //Calculate Cell - int si; //Shared group index + bool ca; // Calculate Cell + int si; // Shared group index }; QT_END_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxcelllocation.h b/QXlsx/header/xlsxcelllocation.h index ccb5cdba..8a5d54ff 100644 --- a/QXlsx/header/xlsxcelllocation.h +++ b/QXlsx/header/xlsxcelllocation.h @@ -3,16 +3,16 @@ #ifndef CELL_LOCATION_H #define CELL_LOCATION_H -#include -#include -#include -#include -#include -#include +#include "xlsxglobal.h" #include -#include "xlsxglobal.h" +#include +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxcellrange.h b/QXlsx/header/xlsxcellrange.h index 719317ca..1e37d40a 100644 --- a/QXlsx/header/xlsxcellrange.h +++ b/QXlsx/header/xlsxcellrange.h @@ -3,11 +3,11 @@ #ifndef QXLSX_XLSXCELLRANGE_H #define QXLSX_XLSXCELLRANGE_H -#include -#include - -#include "xlsxglobal.h" #include "xlsxcellreference.h" +#include "xlsxglobal.h" + +#include +#include QT_BEGIN_NAMESPACE_XLSX @@ -23,7 +23,7 @@ class QXLSX_EXPORT CellRange CellRange(const CellRange &other); ~CellRange(); - QString toString(bool row_abs=false, bool col_abs=false) const; + QString toString(bool row_abs = false, bool col_abs = false) const; bool isValid() const; inline void setFirstRow(int row) { top = row; } inline void setLastRow(int row) { bottom = row; } @@ -40,23 +40,24 @@ class QXLSX_EXPORT CellRange inline CellReference bottomLeft() const { return CellReference(bottom, left); } inline CellReference bottomRight() const { return CellReference(bottom, right); } - inline void operator =(const CellRange &other) + inline void operator=(const CellRange &other) { - top = other.top; + top = other.top; bottom = other.bottom; - left = other.left; - right = other.right; + left = other.left; + right = other.right; } - inline bool operator ==(const CellRange &other) const + inline bool operator==(const CellRange &other) const { - return top==other.top && bottom==other.bottom - && left == other.left && right == other.right; + return top == other.top && bottom == other.bottom && left == other.left && + right == other.right; } - inline bool operator !=(const CellRange &other) const + inline bool operator!=(const CellRange &other) const { - return top!=other.top || bottom!=other.bottom - || left != other.left || right != other.right; + return top != other.top || bottom != other.bottom || left != other.left || + right != other.right; } + private: void init(const QString &range); diff --git a/QXlsx/header/xlsxcellreference.h b/QXlsx/header/xlsxcellreference.h index c20abdc2..e2402708 100644 --- a/QXlsx/header/xlsxcellreference.h +++ b/QXlsx/header/xlsxcellreference.h @@ -3,10 +3,10 @@ #ifndef QXLSX_XLSXCELLREFERENCE_H #define QXLSX_XLSXCELLREFERENCE_H -#include - #include "xlsxglobal.h" +#include + QT_BEGIN_NAMESPACE_XLSX class QXLSX_EXPORT CellReference @@ -19,7 +19,7 @@ class QXLSX_EXPORT CellReference CellReference(const CellReference &other); ~CellReference(); - QString toString(bool row_abs=false, bool col_abs=false) const; + QString toString(bool row_abs = false, bool col_abs = false) const; static CellReference fromString(const QString &cell); bool isValid() const; inline void setRow(int row) { _row = row; } @@ -27,14 +27,15 @@ class QXLSX_EXPORT CellReference inline int row() const { return _row; } inline int column() const { return _column; } - inline bool operator ==(const CellReference &other) const + inline bool operator==(const CellReference &other) const { - return _row==other._row && _column==other._column; + return _row == other._row && _column == other._column; } - inline bool operator !=(const CellReference &other) const + inline bool operator!=(const CellReference &other) const { - return _row!=other._row || _column!=other._column; + return _row != other._row || _column != other._column; } + private: void init(const QString &cell); int _row, _column; diff --git a/QXlsx/header/xlsxchart.h b/QXlsx/header/xlsxchart.h index b724e791..4b178d79 100644 --- a/QXlsx/header/xlsxchart.h +++ b/QXlsx/header/xlsxchart.h @@ -3,11 +3,11 @@ #ifndef QXLSX_CHART_H #define QXLSX_CHART_H -#include +#include "xlsxabstractooxmlfile.h" + #include #include - -#include "xlsxabstractooxmlfile.h" +#include QT_BEGIN_NAMESPACE_XLSX @@ -21,33 +21,52 @@ class QXLSX_EXPORT Chart : public AbstractOOXmlFile { Q_DECLARE_PRIVATE(Chart) public: - enum ChartType { // 16 type of chart (ECMA 376) + enum ChartType { // 16 type of chart (ECMA 376) CT_NoStatementChart = 0, // Zero is internally used for unknown types - CT_AreaChart, CT_Area3DChart, CT_LineChart, - CT_Line3DChart, CT_StockChart, CT_RadarChart, - CT_ScatterChart, CT_PieChart, CT_Pie3DChart, - CT_DoughnutChart, CT_BarChart, CT_Bar3DChart, - CT_OfPieChart, CT_SurfaceChart, CT_Surface3DChart, + CT_AreaChart, + CT_Area3DChart, + CT_LineChart, + CT_Line3DChart, + CT_StockChart, + CT_RadarChart, + CT_ScatterChart, + CT_PieChart, + CT_Pie3DChart, + CT_DoughnutChart, + CT_BarChart, + CT_Bar3DChart, + CT_OfPieChart, + CT_SurfaceChart, + CT_Surface3DChart, CT_BubbleChart, }; - enum ChartAxisPos { None = (-1), Left = 0, Right, Top, Bottom }; + enum ChartAxisPos { None = (-1), Left = 0, Right, Top, Bottom }; + private: friend class AbstractSheet; friend class Worksheet; friend class Chartsheet; friend class DrawingAnchor; + private: Chart(AbstractSheet *parent, CreateFlag flag); + public: ~Chart(); + public: - void addSeries(const CellRange &range, AbstractSheet *sheet = NULL, bool headerH = false, bool headerV = false, bool swapHeaders = false); + void addSeries(const CellRange &range, + AbstractSheet *sheet = NULL, + bool headerH = false, + bool headerV = false, + bool swapHeaders = false); void setChartType(ChartType type); void setChartStyle(int id); void setAxisTitle(Chart::ChartAxisPos pos, QString axisTitle); void setChartTitle(QString strchartTitle); void setChartLegend(Chart::ChartAxisPos legendPos, bool overlap = false); void setGridlinesEnable(bool majorGridlinesEnable = false, bool minorGridlinesEnable = false); + public: bool loadFromXmlFile(QIODevice *device) override; void saveToXmlFile(QIODevice *device) const override; diff --git a/QXlsx/header/xlsxchart_p.h b/QXlsx/header/xlsxchart_p.h index 1d5de8cb..0cb7eea7 100644 --- a/QXlsx/header/xlsxchart_p.h +++ b/QXlsx/header/xlsxchart_p.h @@ -3,30 +3,30 @@ #ifndef QXLSX_CHART_P_H #define QXLSX_CHART_P_H +#include "xlsxabstractooxmlfile_p.h" +#include "xlsxchart.h" + +#include + +#include +#include #include #include #include -#include -#include #include #include -#include - -#include "xlsxabstractooxmlfile_p.h" -#include "xlsxchart.h" - QT_BEGIN_NAMESPACE_XLSX class XlsxSeries { public: - //At present, we care about number cell ranges only! + // At present, we care about number cell ranges only! QString numberDataSource_numRef; // yval, val - QString axDataSource_numRef; // xval, cat + QString axDataSource_numRef; // xval, cat QString headerH_numRef; QString headerV_numRef; - bool swapHeader = false; + bool swapHeader = false; }; class XlsxAxis @@ -34,23 +34,19 @@ class XlsxAxis public: enum Type { T_None = (-1), T_Cat, T_Val, T_Date, T_Ser }; enum AxisPos { None = (-1), Left, Right, Top, Bottom }; + public: - XlsxAxis(){} + XlsxAxis() {} - XlsxAxis( Type t, - XlsxAxis::AxisPos p, - int id, - int crossId, - QString axisTitle = QString()) + XlsxAxis(Type t, XlsxAxis::AxisPos p, int id, int crossId, QString axisTitle = QString()) { - type = t; + type = t; axisPos = p; - axisId = id; + axisId = id; crossAx = crossId; - if ( !axisTitle.isEmpty() ) - { - axisNames[ p ] = axisTitle; + if (!axisTitle.isEmpty()) { + axisNames[p] = axisTitle; } } @@ -59,7 +55,7 @@ class XlsxAxis XlsxAxis::AxisPos axisPos; int axisId; int crossAx; - QMap< XlsxAxis::AxisPos, QString > axisNames; + QMap axisNames; }; class ChartPrivate : public AbstractOOXmlFilePrivate @@ -73,8 +69,10 @@ class ChartPrivate : public AbstractOOXmlFilePrivate public: bool loadXmlChart(QXmlStreamReader &reader); bool loadXmlPlotArea(QXmlStreamReader &reader); + protected: bool loadXmlPlotAreaElement(QXmlStreamReader &reader); + public: bool loadXmlXxxChart(QXmlStreamReader &reader); bool loadXmlSer(QXmlStreamReader &reader); @@ -82,25 +80,27 @@ class ChartPrivate : public AbstractOOXmlFilePrivate QString loadXmlStrRef(QXmlStreamReader &reader); bool loadXmlChartTitle(QXmlStreamReader &reader); bool loadXmlChartLegend(QXmlStreamReader &reader); + protected: bool loadXmlChartTitleTx(QXmlStreamReader &reader); bool loadXmlChartTitleTxRich(QXmlStreamReader &reader); bool loadXmlChartTitleTxRichP(QXmlStreamReader &reader); bool loadXmlChartTitleTxRichP_R(QXmlStreamReader &reader); + protected: bool loadXmlAxisCatAx(QXmlStreamReader &reader); bool loadXmlAxisDateAx(QXmlStreamReader &reader); 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_pPr(QXmlStreamReader &reader, XlsxAxis* axis); - bool loadXmlAxisEG_AxShared_Title_Tx_Rich_P_R(QXmlStreamReader &reader, XlsxAxis* axis); + 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_pPr(QXmlStreamReader &reader, XlsxAxis *axis); + bool loadXmlAxisEG_AxShared_Title_Tx_Rich_P_R(QXmlStreamReader &reader, XlsxAxis *axis); QString readSubTree(QXmlStreamReader &reader); @@ -118,29 +118,29 @@ class ChartPrivate : public AbstractOOXmlFilePrivate void saveXmlChartLegend(QXmlStreamWriter &writer) const; protected: - void saveXmlAxisCatAx(QXmlStreamWriter &writer, XlsxAxis* axis) const; - void saveXmlAxisDateAx(QXmlStreamWriter &writer, XlsxAxis* axis) const; - void saveXmlAxisSerAx(QXmlStreamWriter &writer, XlsxAxis* axis) const; - void saveXmlAxisValAx(QXmlStreamWriter &writer, XlsxAxis* axis) const; + void saveXmlAxisCatAx(QXmlStreamWriter &writer, XlsxAxis *axis) const; + void saveXmlAxisDateAx(QXmlStreamWriter &writer, XlsxAxis *axis) const; + void saveXmlAxisSerAx(QXmlStreamWriter &writer, XlsxAxis *axis) const; + void saveXmlAxisValAx(QXmlStreamWriter &writer, XlsxAxis *axis) const; - void saveXmlAxisEG_AxShared(QXmlStreamWriter &writer, XlsxAxis* axis) const; - void saveXmlAxisEG_AxShared_Title(QXmlStreamWriter &writer, XlsxAxis* axis) const; - QString GetAxisPosString( XlsxAxis::AxisPos axisPos ) const; - QString GetAxisName(XlsxAxis* ptrXlsxAxis) const; + void saveXmlAxisEG_AxShared(QXmlStreamWriter &writer, XlsxAxis *axis) const; + void saveXmlAxisEG_AxShared_Title(QXmlStreamWriter &writer, XlsxAxis *axis) const; + QString GetAxisPosString(XlsxAxis::AxisPos axisPos) const; + QString GetAxisName(XlsxAxis *ptrXlsxAxis) const; public: Chart::ChartType chartType; - QList< std::shared_ptr > seriesList; - QList< std::shared_ptr > axisList; - QMap< XlsxAxis::AxisPos, QString > axisNames; + QList> seriesList; + QList> axisList; + QMap axisNames; QString chartTitle; - AbstractSheet* sheet; + AbstractSheet *sheet; Chart::ChartAxisPos legendPos; bool legendOverlay; bool majorGridlinesEnabled; bool minorGridlinesEnabled; - QString layout; // only for storing a readed file + QString layout; // only for storing a readed file }; QT_END_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxchartsheet.h b/QXlsx/header/xlsxchartsheet.h index e654af1a..889cac68 100644 --- a/QXlsx/header/xlsxchartsheet.h +++ b/QXlsx/header/xlsxchartsheet.h @@ -3,11 +3,11 @@ #ifndef XLSXCHARTSHEET_H #define XLSXCHARTSHEET_H -#include -#include - #include "xlsxabstractsheet.h" +#include +#include + QT_BEGIN_NAMESPACE_XLSX class Workbook; diff --git a/QXlsx/header/xlsxchartsheet_p.h b/QXlsx/header/xlsxchartsheet_p.h index 21ade912..406807e3 100644 --- a/QXlsx/header/xlsxchartsheet_p.h +++ b/QXlsx/header/xlsxchartsheet_p.h @@ -3,11 +3,11 @@ #ifndef XLSXCHARTSHEET_P_H #define XLSXCHARTSHEET_P_H -#include - -#include "xlsxglobal.h" -#include "xlsxchartsheet.h" #include "xlsxabstractsheet_p.h" +#include "xlsxchartsheet.h" +#include "xlsxglobal.h" + +#include QT_BEGIN_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxcolor_p.h b/QXlsx/header/xlsxcolor_p.h index 4fafacf2..9528fa94 100644 --- a/QXlsx/header/xlsxcolor_p.h +++ b/QXlsx/header/xlsxcolor_p.h @@ -3,13 +3,13 @@ #ifndef QXLSX_XLSXCOLOR_P_H #define QXLSX_XLSXCOLOR_P_H -#include -#include +#include "xlsxglobal.h" + #include -#include +#include #include - -#include "xlsxglobal.h" +#include +#include QT_BEGIN_NAMESPACE_XLSX @@ -19,8 +19,8 @@ class XlsxColor { public: explicit XlsxColor(const QColor &color = QColor()); - explicit XlsxColor(const QString &theme, const QString &tint=QString()); - explicit XlsxColor (int index); + explicit XlsxColor(const QString &theme, const QString &tint = QString()); + explicit XlsxColor(int index); bool isThemeColor() const; bool isIndexedColor() const; @@ -36,7 +36,7 @@ class XlsxColor static QColor fromARGBString(const QString &c); static QString toARGBString(const QColor &c); - bool saveToXml(QXmlStreamWriter &writer, const QString &node=QString()) const; + bool saveToXml(QXmlStreamWriter &writer, const QString &node = QString()) const; bool loadFromXml(QXmlStreamReader &reader); private: @@ -44,12 +44,12 @@ class XlsxColor }; #if !defined(QT_NO_DATASTREAM) - QDataStream &operator<<(QDataStream &, const XlsxColor &); - QDataStream &operator>>(QDataStream &, XlsxColor &); +QDataStream &operator<<(QDataStream &, const XlsxColor &); +QDataStream &operator>>(QDataStream &, XlsxColor &); #endif #ifndef QT_NO_DEBUG_STREAM - QDebug operator<<(QDebug dbg, const XlsxColor &c); +QDebug operator<<(QDebug dbg, const XlsxColor &c); #endif QT_END_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxconditionalformatting.h b/QXlsx/header/xlsxconditionalformatting.h index 117f74ae..4ddfdf0b 100644 --- a/QXlsx/header/xlsxconditionalformatting.h +++ b/QXlsx/header/xlsxconditionalformatting.h @@ -3,17 +3,17 @@ #ifndef QXLSX_XLSXCONDITIONALFORMATTING_H #define QXLSX_XLSXCONDITIONALFORMATTING_H -#include -#include -#include +#include "xlsxcellrange.h" +#include "xlsxcellreference.h" +#include "xlsxglobal.h" + #include +#include +#include +#include #include #include -#include - -#include "xlsxglobal.h" -#include "xlsxcellrange.h" -#include "xlsxcellreference.h" +#include class ConditionalFormattingTest; @@ -70,15 +70,7 @@ class QXLSX_EXPORT ConditionalFormatting Highlight_Expression }; - enum ValueObjectType - { - VOT_Formula, - VOT_Max, - VOT_Min, - VOT_Num, - VOT_Percent, - VOT_Percentile - }; + enum ValueObjectType { VOT_Formula, VOT_Max, VOT_Min, VOT_Num, VOT_Percent, VOT_Percentile }; public: ConditionalFormatting(); @@ -86,13 +78,32 @@ class QXLSX_EXPORT ConditionalFormatting ~ConditionalFormatting(); public: - bool addHighlightCellsRule(HighlightRuleType type, const Format &format, bool stopIfTrue=false); - bool addHighlightCellsRule(HighlightRuleType type, const QString &formula1, const Format &format, bool stopIfTrue=false); - bool addHighlightCellsRule(HighlightRuleType type, const QString &formula1, const QString &formula2, const Format &format, bool stopIfTrue=false); - bool addDataBarRule(const QColor &color, bool showData=true, bool stopIfTrue=false); - bool addDataBarRule(const QColor &color, ValueObjectType type1, const QString &val1, ValueObjectType type2, const QString &val2, bool showData=true, bool stopIfTrue=false); - bool add2ColorScaleRule(const QColor &minColor, const QColor &maxColor, bool stopIfTrue=false); - bool add3ColorScaleRule(const QColor &minColor, const QColor &midColor, const QColor &maxColor, bool stopIfTrue=false); + bool addHighlightCellsRule(HighlightRuleType type, + const Format &format, + bool stopIfTrue = false); + bool addHighlightCellsRule(HighlightRuleType type, + const QString &formula1, + const Format &format, + bool stopIfTrue = false); + bool addHighlightCellsRule(HighlightRuleType type, + const QString &formula1, + const QString &formula2, + const Format &format, + bool stopIfTrue = false); + bool addDataBarRule(const QColor &color, bool showData = true, bool stopIfTrue = false); + bool addDataBarRule(const QColor &color, + ValueObjectType type1, + const QString &val1, + ValueObjectType type2, + const QString &val2, + bool showData = true, + bool stopIfTrue = false); + bool + add2ColorScaleRule(const QColor &minColor, const QColor &maxColor, bool stopIfTrue = false); + bool add3ColorScaleRule(const QColor &minColor, + const QColor &midColor, + const QColor &maxColor, + bool stopIfTrue = false); QList ranges() const; @@ -101,7 +112,7 @@ class QXLSX_EXPORT ConditionalFormatting void addRange(int firstRow, int firstCol, int lastRow, int lastCol); void addRange(const CellRange &range); - //needed by QSharedDataPointer!! + // needed by QSharedDataPointer!! ConditionalFormatting &operator=(const ConditionalFormatting &other); private: @@ -110,7 +121,7 @@ class QXLSX_EXPORT ConditionalFormatting private: bool saveToXml(QXmlStreamWriter &writer) const; - bool loadFromXml(QXmlStreamReader &reader, Styles* styles = NULL); + bool loadFromXml(QXmlStreamReader &reader, Styles *styles = NULL); QSharedDataPointer d; }; diff --git a/QXlsx/header/xlsxconditionalformatting_p.h b/QXlsx/header/xlsxconditionalformatting_p.h index 455af598..262e5f32 100644 --- a/QXlsx/header/xlsxconditionalformatting_p.h +++ b/QXlsx/header/xlsxconditionalformatting_p.h @@ -3,14 +3,14 @@ #ifndef XLSXCONDITIONALFORMATTING_P_H #define XLSXCONDITIONALFORMATTING_P_H -#include -#include +#include "xlsxcolor_p.h" +#include "xlsxconditionalformatting.h" +#include "xlsxformat.h" #include -#include "xlsxconditionalformatting.h" -#include "xlsxformat.h" -#include "xlsxcolor_p.h" +#include +#include QT_BEGIN_NAMESPACE_XLSX @@ -18,12 +18,14 @@ class XlsxCfVoData { public: XlsxCfVoData() - :gte(true) + : gte(true) { } - XlsxCfVoData(ConditionalFormatting::ValueObjectType type, const QString &value, bool gte=true) - :type(type), value(value), gte(gte) + XlsxCfVoData(ConditionalFormatting::ValueObjectType type, const QString &value, bool gte = true) + : type(type) + , value(value) + , gte(gte) { } @@ -38,7 +40,7 @@ class XlsxCfRuleData enum Attribute { A_type, A_dxfId, - //A_priority, + // A_priority, A_stopIfTrue, A_aboveAverage, A_percent, @@ -68,8 +70,9 @@ class XlsxCfRuleData }; XlsxCfRuleData() - :priority(1) - {} + : priority(1) + { + } int priority; Format dxfFormat; @@ -83,13 +86,13 @@ class ConditionalFormattingPrivate : public QSharedData ConditionalFormattingPrivate(const ConditionalFormattingPrivate &other); ~ConditionalFormattingPrivate(); - void writeCfVo(QXmlStreamWriter &writer, const XlsxCfVoData& cfvo) const; - bool readCfVo(QXmlStreamReader &reader, XlsxCfVoData& cfvo); + void writeCfVo(QXmlStreamWriter &writer, const XlsxCfVoData &cfvo) const; + bool readCfVo(QXmlStreamReader &reader, XlsxCfVoData &cfvo); bool readCfRule(QXmlStreamReader &reader, XlsxCfRuleData *cfRule, Styles *styles); bool readCfDataBar(QXmlStreamReader &reader, XlsxCfRuleData *cfRule); bool readCfColorScale(QXmlStreamReader &reader, XlsxCfRuleData *cfRule); - QList >cfRules; + QList> cfRules; QList ranges; }; diff --git a/QXlsx/header/xlsxcontenttypes_p.h b/QXlsx/header/xlsxcontenttypes_p.h index 43c73f0d..35cead6a 100644 --- a/QXlsx/header/xlsxcontenttypes_p.h +++ b/QXlsx/header/xlsxcontenttypes_p.h @@ -3,13 +3,13 @@ #ifndef XLSXCONTENTTYPES_H #define XLSXCONTENTTYPES_H -#include +#include "xlsxabstractooxmlfile.h" + +#include +#include #include #include -#include -#include - -#include "xlsxabstractooxmlfile.h" +#include QT_BEGIN_NAMESPACE_XLSX @@ -21,7 +21,7 @@ class ContentTypes : public AbstractOOXmlFile void addDefault(const QString &key, const QString &value); void addOverride(const QString &key, const QString &value); - //Convenient funcation for addOverride() + // Convenient funcation for addOverride() void addDocPropCore(); void addDocPropApp(); void addStyles(); @@ -43,6 +43,7 @@ class ContentTypes : public AbstractOOXmlFile void saveToXmlFile(QIODevice *device) const override; bool loadFromXmlFile(QIODevice *device) override; + private: QMap m_defaults; QMap m_overrides; diff --git a/QXlsx/header/xlsxdatavalidation.h b/QXlsx/header/xlsxdatavalidation.h index ad8a1d61..aea3bea8 100644 --- a/QXlsx/header/xlsxdatavalidation.h +++ b/QXlsx/header/xlsxdatavalidation.h @@ -3,14 +3,14 @@ #ifndef QXLSX_XLSXDATAVALIDATION_H #define QXLSX_XLSXDATAVALIDATION_H -#include +#include "xlsxglobal.h" + +#include #include #include -#include #include #include - -#include "xlsxglobal.h" +#include class QXmlStreamReader; class QXmlStreamWriter; @@ -25,20 +25,9 @@ class DataValidationPrivate; class QXLSX_EXPORT DataValidation { public: - enum ValidationType - { - None, - Whole, - Decimal, - List, - Date, - Time, - TextLength, - Custom - }; + enum ValidationType { None, Whole, Decimal, List, Date, Time, TextLength, Custom }; - enum ValidationOperator - { + enum ValidationOperator { Between, NotBetween, Equal, @@ -49,16 +38,14 @@ class QXLSX_EXPORT DataValidation GreaterThanOrEqual }; - enum ErrorStyle - { - Stop, - Warning, - Information - }; + enum ErrorStyle { Stop, Warning, Information }; DataValidation(); - DataValidation(ValidationType type, ValidationOperator op=Between, const QString &formula1=QString() - , const QString &formula2=QString(), bool allowBlank=false); + DataValidation(ValidationType type, + ValidationOperator op = Between, + const QString &formula1 = QString(), + const QString &formula2 = QString(), + bool allowBlank = false); DataValidation(const DataValidation &other); ~DataValidation(); @@ -81,8 +68,8 @@ class QXLSX_EXPORT DataValidation void setErrorStyle(ErrorStyle es); void setFormula1(const QString &formula); void setFormula2(const QString &formula); - void setErrorMessage(const QString &error, const QString &title=QString()); - void setPromptMessage(const QString &prompt, const QString &title=QString()); + void setErrorMessage(const QString &error, const QString &title = QString()); + void setPromptMessage(const QString &prompt, const QString &title = QString()); void setAllowBlank(bool enable); void setPromptMessageVisible(bool visible); void setErrorMessageVisible(bool visible); @@ -96,6 +83,7 @@ class QXLSX_EXPORT DataValidation bool saveToXml(QXmlStreamWriter &writer) const; static DataValidation loadFromXml(QXmlStreamReader &reader); + private: QSharedDataPointer d; }; diff --git a/QXlsx/header/xlsxdatavalidation_p.h b/QXlsx/header/xlsxdatavalidation_p.h index 727a182b..ebb407c4 100644 --- a/QXlsx/header/xlsxdatavalidation_p.h +++ b/QXlsx/header/xlsxdatavalidation_p.h @@ -3,18 +3,22 @@ #ifndef XLSXDATAVALIDATION_P_H #define XLSXDATAVALIDATION_P_H -#include -#include - #include "xlsxdatavalidation.h" +#include +#include + QT_BEGIN_NAMESPACE_XLSX -class DataValidationPrivate : public QSharedData +class DataValidationPrivate : public QSharedData { public: DataValidationPrivate(); - DataValidationPrivate(DataValidation::ValidationType type, DataValidation::ValidationOperator op, const QString &formula1, const QString &formula2, bool allowBlank); + DataValidationPrivate(DataValidation::ValidationType type, + DataValidation::ValidationOperator op, + const QString &formula1, + const QString &formula2, + bool allowBlank); DataValidationPrivate(const DataValidationPrivate &other); ~DataValidationPrivate(); diff --git a/QXlsx/header/xlsxdatetype.h b/QXlsx/header/xlsxdatetype.h index 366d99a6..cf09f4c6 100644 --- a/QXlsx/header/xlsxdatetype.h +++ b/QXlsx/header/xlsxdatetype.h @@ -3,15 +3,15 @@ #ifndef QXLSX_XLSXDATETYPE_H #define QXLSX_XLSXDATETYPE_H -#include +#include "xlsxglobal.h" + +#include +#include #include #include #include -#include -#include #include - -#include "xlsxglobal.h" +#include QT_BEGIN_NAMESPACE_XLSX @@ -19,30 +19,30 @@ class QXLSX_EXPORT DateType { public: DateType(); -/* - DateType(bool is1904 = false); - DateType(double d, bool is1904 = false); - DateType(QDateTime qdt, bool is1904 = false); - DateType(QDate qd, bool is1904 = false); - DateType(QTime qt, bool is1904 = false); -public: - enum currentDateType { DateAndTimeType, OnlyDateType, OnlyTimeType }; -public: - currentDateType getType(); - bool getValue(QDateTime* pQdt); - bool getValue(QDate* pQd); - bool getValue(QTime* pQt); - bool getValue(double* pD); - -protected: - -protected: - bool isSet; - double dValue; - bool is1904Type; - currentDateType dType; -*/ + /* + DateType(bool is1904 = false); + DateType(double d, bool is1904 = false); + DateType(QDateTime qdt, bool is1904 = false); + DateType(QDate qd, bool is1904 = false); + DateType(QTime qt, bool is1904 = false); + public: + enum currentDateType { DateAndTimeType, OnlyDateType, OnlyTimeType }; + public: + currentDateType getType(); + bool getValue(QDateTime* pQdt); + bool getValue(QDate* pQd); + bool getValue(QTime* pQt); + bool getValue(double* pD); + + protected: + + protected: + bool isSet; + double dValue; + bool is1904Type; + currentDateType dType; + */ }; QT_END_NAMESPACE_XLSX -#endif +#endif diff --git a/QXlsx/header/xlsxdocpropsapp_p.h b/QXlsx/header/xlsxdocpropsapp_p.h index 32b95fa7..e326a02c 100644 --- a/QXlsx/header/xlsxdocpropsapp_p.h +++ b/QXlsx/header/xlsxdocpropsapp_p.h @@ -3,22 +3,22 @@ #ifndef XLSXDOCPROPSAPP_H #define XLSXDOCPROPSAPP_H +#include "xlsxabstractooxmlfile.h" +#include "xlsxglobal.h" + #include -#include #include - -#include "xlsxglobal.h" -#include "xlsxabstractooxmlfile.h" +#include class QIODevice; QT_BEGIN_NAMESPACE_XLSX -class DocPropsApp : public AbstractOOXmlFile +class DocPropsApp : public AbstractOOXmlFile { public: DocPropsApp(CreateFlag flag); - + void addPartTitle(const QString &title); void addHeadingPair(const QString &name, int value); @@ -31,7 +31,7 @@ class DocPropsApp : public AbstractOOXmlFile private: QStringList m_titlesOfPartsList; - QList > m_headingPairsList; + QList> m_headingPairsList; QMap m_properties; }; diff --git a/QXlsx/header/xlsxdocpropscore_p.h b/QXlsx/header/xlsxdocpropscore_p.h index 3aaace6e..9dd827b7 100644 --- a/QXlsx/header/xlsxdocpropscore_p.h +++ b/QXlsx/header/xlsxdocpropscore_p.h @@ -3,8 +3,8 @@ #ifndef XLSXDOCPROPSCORE_H #define XLSXDOCPROPSCORE_H -#include "xlsxglobal.h" #include "xlsxabstractooxmlfile.h" +#include "xlsxglobal.h" #include #include @@ -21,7 +21,7 @@ class DocPropsCore : public AbstractOOXmlFile bool setProperty(const QString &name, const QString &value); QString property(const QString &name) const; QStringList propertyNames() const; - + void saveToXmlFile(QIODevice *device) const override; bool loadFromXmlFile(QIODevice *device) override; diff --git a/QXlsx/header/xlsxdocument.h b/QXlsx/header/xlsxdocument.h index 5d3455f2..85ad3477 100644 --- a/QXlsx/header/xlsxdocument.h +++ b/QXlsx/header/xlsxdocument.h @@ -3,16 +3,16 @@ #ifndef QXLSX_XLSXDOCUMENT_H #define QXLSX_XLSXDOCUMENT_H -#include -#include -#include -#include -#include - -#include "xlsxglobal.h" #include "xlsxformat.h" +#include "xlsxglobal.h" #include "xlsxworksheet.h" +#include +#include +#include +#include +#include + QT_BEGIN_NAMESPACE_XLSX class Workbook; @@ -26,102 +26,105 @@ class DocumentPrivate; class QXLSX_EXPORT Document : public QObject { - Q_OBJECT + Q_OBJECT Q_DECLARE_PRIVATE(Document) // D-Pointer. Qt classes have a Q_DECLARE_PRIVATE // macro in the public class. The macro reads: qglobal.h public: - explicit Document(QObject *parent = nullptr); - Document(const QString& xlsxName, QObject* parent = nullptr); - Document(QIODevice* device, QObject* parent = nullptr); - ~Document(); - - bool write(const CellReference &cell, const QVariant &value, const Format &format=Format()); - bool write(int row, int col, const QVariant &value, const Format &format=Format()); - - QVariant read(const CellReference &cell) const; - QVariant read(int row, int col) const; - + explicit Document(QObject *parent = nullptr); + Document(const QString &xlsxName, QObject *parent = nullptr); + Document(QIODevice *device, QObject *parent = nullptr); + ~Document(); + + bool write(const CellReference &cell, const QVariant &value, const Format &format = Format()); + bool write(int row, int col, const QVariant &value, const Format &format = Format()); + + QVariant read(const CellReference &cell) const; + QVariant read(int row, int col) const; + int insertImage(int row, int col, const QImage &image); - bool getImage(int imageIndex, QImage& img); - bool getImage(int row, int col, QImage& img); + bool getImage(int imageIndex, QImage &img); + bool getImage(int row, int col, QImage &img); uint getImageCount(); - - Chart *insertChart(int row, int col, const QSize &size); - - bool mergeCells(const CellRange &range, const Format &format=Format()); - bool unmergeCells(const CellRange &range); - - bool setColumnWidth(const CellRange &range, double width); - bool setColumnFormat(const CellRange &range, const Format &format); - bool setColumnHidden(const CellRange &range, bool hidden); - bool setColumnWidth(int column, double width); - bool setColumnFormat(int column, const Format &format); - bool setColumnHidden(int column, bool hidden); - bool setColumnWidth(int colFirst, int colLast, double width); - bool setColumnFormat(int colFirst, int colLast, const Format &format); - bool setColumnHidden(int colFirst, int colLast, bool hidden); - - double columnWidth(int column); - Format columnFormat(int column); - bool isColumnHidden(int column); - - bool setRowHeight(int row, double height); - bool setRowFormat(int row, const Format &format); - bool setRowHidden(int row, bool hidden); - bool setRowHeight(int rowFirst, int rowLast, double height); - bool setRowFormat(int rowFirst, int rowLast, const Format &format); - bool setRowHidden(int rowFirst, int rowLast, bool hidden); - - double rowHeight(int row); - Format rowFormat(int row); - bool isRowHidden(int row); - - bool groupRows(int rowFirst, int rowLast, bool collapsed = true); - bool groupColumns(int colFirst, int colLast, bool collapsed = true); - - bool addDataValidation(const DataValidation &validation); - bool addConditionalFormatting(const ConditionalFormatting &cf); - - Cell *cellAt(const CellReference &cell) const; - Cell *cellAt(int row, int col) const; - - bool defineName(const QString &name, const QString &formula, - const QString &comment=QString(), const QString &scope=QString()); - - CellRange dimension() const; - - QString documentProperty(const QString &name) const; - void setDocumentProperty(const QString &name, const QString &property); - QStringList documentPropertyNames() const; - - QStringList sheetNames() const; - bool addSheet(const QString &name = QString(), + + Chart *insertChart(int row, int col, const QSize &size); + + bool mergeCells(const CellRange &range, const Format &format = Format()); + bool unmergeCells(const CellRange &range); + + bool setColumnWidth(const CellRange &range, double width); + bool setColumnFormat(const CellRange &range, const Format &format); + bool setColumnHidden(const CellRange &range, bool hidden); + bool setColumnWidth(int column, double width); + bool setColumnFormat(int column, const Format &format); + bool setColumnHidden(int column, bool hidden); + bool setColumnWidth(int colFirst, int colLast, double width); + bool setColumnFormat(int colFirst, int colLast, const Format &format); + bool setColumnHidden(int colFirst, int colLast, bool hidden); + + double columnWidth(int column); + Format columnFormat(int column); + bool isColumnHidden(int column); + + bool setRowHeight(int row, double height); + bool setRowFormat(int row, const Format &format); + bool setRowHidden(int row, bool hidden); + bool setRowHeight(int rowFirst, int rowLast, double height); + bool setRowFormat(int rowFirst, int rowLast, const Format &format); + bool setRowHidden(int rowFirst, int rowLast, bool hidden); + + double rowHeight(int row); + Format rowFormat(int row); + bool isRowHidden(int row); + + bool groupRows(int rowFirst, int rowLast, bool collapsed = true); + bool groupColumns(int colFirst, int colLast, bool collapsed = true); + + bool addDataValidation(const DataValidation &validation); + bool addConditionalFormatting(const ConditionalFormatting &cf); + + Cell *cellAt(const CellReference &cell) const; + Cell *cellAt(int row, int col) const; + + bool defineName(const QString &name, + const QString &formula, + const QString &comment = QString(), + const QString &scope = QString()); + + CellRange dimension() const; + + QString documentProperty(const QString &name) const; + void setDocumentProperty(const QString &name, const QString &property); + QStringList documentPropertyNames() const; + + QStringList sheetNames() const; + bool addSheet(const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); - bool insertSheet(int index, const QString &name = QString(), + bool insertSheet(int index, + const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); - bool selectSheet(const QString &name); - bool selectSheet(int index); - bool renameSheet(const QString &oldName, const QString &newName); - bool copySheet(const QString &srcName, const QString &distName = QString()); - bool moveSheet(const QString &srcName, int distIndex); - bool deleteSheet(const QString &name); + bool selectSheet(const QString &name); + bool selectSheet(int index); + bool renameSheet(const QString &oldName, const QString &newName); + bool copySheet(const QString &srcName, const QString &distName = QString()); + bool moveSheet(const QString &srcName, int distIndex); + bool deleteSheet(const QString &name); - Workbook *workbook() const; - AbstractSheet *sheet(const QString &sheetName) const; - AbstractSheet *currentSheet() const; - Worksheet *currentWorksheet() const; + Workbook *workbook() const; + AbstractSheet *sheet(const QString &sheetName) const; + AbstractSheet *currentSheet() const; + Worksheet *currentWorksheet() const; - bool save() const; - bool saveAs(const QString &xlsXname) const; - bool saveAs(QIODevice *device) const; + bool save() const; + bool saveAs(const QString &xlsXname) const; + bool saveAs(QIODevice *device) const; - // copy style from one xlsx file to other - static bool copyStyle(const QString &from, const QString &to); + // copy style from one xlsx file to other + static bool copyStyle(const QString &from, const QString &to); - bool isLoadPackage() const; - bool load() const; // equals to isLoadPackage() + bool isLoadPackage() const; + bool load() const; // equals to isLoadPackage() - bool changeimage(int filenoinmidea,QString newfile); // add by liufeijin20181025 + bool changeimage(int filenoinmidea, QString newfile); // add by liufeijin20181025 bool autosizeColumnWidth(const CellRange &range); bool autosizeColumnWidth(int column); @@ -129,13 +132,12 @@ class QXLSX_EXPORT Document : public QObject bool autosizeColumnWidth(void); private: - QMap getMaximalColumnWidth(int firstRow=1, int lastRow=INT_MAX); - + QMap getMaximalColumnWidth(int firstRow = 1, int lastRow = INT_MAX); private: Q_DISABLE_COPY(Document) // Disables the use of copy constructors and // assignment operators for the given Class. - DocumentPrivate* const d_ptr; + DocumentPrivate *const d_ptr; }; QT_END_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxdocument_p.h b/QXlsx/header/xlsxdocument_p.h index b15bdfa6..978df5eb 100644 --- a/QXlsx/header/xlsxdocument_p.h +++ b/QXlsx/header/xlsxdocument_p.h @@ -3,13 +3,13 @@ #ifndef XLSXDOCUMENT_P_H #define XLSXDOCUMENT_P_H -#include -#include - -#include "xlsxglobal.h" +#include "xlsxcontenttypes_p.h" #include "xlsxdocument.h" +#include "xlsxglobal.h" #include "xlsxworkbook.h" -#include "xlsxcontenttypes_p.h" + +#include +#include QT_BEGIN_NAMESPACE_XLSX @@ -23,17 +23,17 @@ class DocumentPrivate bool loadPackage(QIODevice *device); bool savePackage(QIODevice *device) const; - // copy style from one xlsx file to other - static bool copyStyle(const QString &from, const QString &to); + // copy style from one xlsx file to other + static bool copyStyle(const QString &from, const QString &to); Document *q_ptr; - const QString defaultPackageName; //default name when package name not specified - QString packageName; //name of the .xlsx file + const QString defaultPackageName; // default name when package name not specified + QString packageName; // name of the .xlsx file - QMap documentProperties; //core, app and custom properties + QMap documentProperties; // core, app and custom properties QSharedPointer workbook; std::shared_ptr contentTypes; - bool isLoad; + bool isLoad; }; QT_END_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxdrawing_p.h b/QXlsx/header/xlsxdrawing_p.h index 80793cc2..75b6b1d7 100644 --- a/QXlsx/header/xlsxdrawing_p.h +++ b/QXlsx/header/xlsxdrawing_p.h @@ -3,12 +3,12 @@ #ifndef QXLSX_DRAWING_H #define QXLSX_DRAWING_H -#include +#include "xlsxabstractooxmlfile.h" +#include "xlsxrelationships_p.h" + #include #include - -#include "xlsxrelationships_p.h" -#include "xlsxabstractooxmlfile.h" +#include class QIODevice; class QXmlStreamWriter; diff --git a/QXlsx/header/xlsxdrawinganchor_p.h b/QXlsx/header/xlsxdrawinganchor_p.h index 0c8c641e..c6e7743d 100644 --- a/QXlsx/header/xlsxdrawinganchor_p.h +++ b/QXlsx/header/xlsxdrawinganchor_p.h @@ -3,37 +3,36 @@ #ifndef QXLSX_XLSXDRAWINGANCHOR_P_H #define QXLSX_XLSXDRAWINGANCHOR_P_H +#include "xlsxglobal.h" + +#include + #include +#include #include #include -#include #include #include -#include - -#include "xlsxglobal.h" - QT_BEGIN_NAMESPACE_XLSX class Drawing; class MediaFile; class Chart; -//Helper class -struct XlsxMarker -{ - XlsxMarker(){} +// Helper class +struct XlsxMarker { + XlsxMarker() {} XlsxMarker(int row, int column, int rowOffset, int colOffset) - :cell(QPoint(row, column)), offset(rowOffset, colOffset) + : cell(QPoint(row, column)) + , offset(rowOffset, colOffset) { - } - int row() const {return cell.x();} - int col() const {return cell.y();} - int rowOff() const {return offset.width();} - int colOff() const {return offset.height();} + int row() const { return cell.x(); } + int col() const { return cell.y(); } + int rowOff() const { return offset.width(); } + int colOff() const { return offset.height(); } QPoint cell; QSize offset; @@ -42,24 +41,17 @@ struct XlsxMarker class DrawingAnchor { public: - enum ObjectType { - GraphicFrame, - Shape, - GroupShape, - ConnectionShape, - Picture, - Unknown - }; + enum ObjectType { GraphicFrame, Shape, GroupShape, ConnectionShape, Picture, Unknown }; DrawingAnchor(Drawing *drawing, ObjectType objectType); virtual ~DrawingAnchor(); void setObjectPicture(const QImage &img); bool getObjectPicture(QImage &img); - + void setObjectGraphicFrame(QSharedPointer chart); - virtual bool loadFromXml(QXmlStreamReader &reader) = 0; + virtual bool loadFromXml(QXmlStreamReader &reader) = 0; virtual void saveToXml(QXmlStreamWriter &writer) const = 0; virtual int row() const; @@ -78,7 +70,9 @@ class DrawingAnchor void saveXmlPos(QXmlStreamWriter &writer, const QPoint &pos) const; void saveXmlExt(QXmlStreamWriter &writer, const QSize &ext) const; - void saveXmlMarker(QXmlStreamWriter &writer, const XlsxMarker &marker, const QString &node) const; + void saveXmlMarker(QXmlStreamWriter &writer, + const XlsxMarker &marker, + const QString &node) const; void saveXmlObject(QXmlStreamWriter &writer) const; void saveXmlObjectShape(QXmlStreamWriter &writer) const; void saveXmlObjectGroupShape(QXmlStreamWriter &writer) const; @@ -92,40 +86,40 @@ class DrawingAnchor QSharedPointer m_chartFile; int m_id; + public: int getm_id(); protected: + // liufeij {{ + void setObjectShape(const QImage &img); // liufeij - // liufeij {{ - void setObjectShape(const QImage &img); // liufeij - - QString editASName; + QString editASName; // below only for twocellanchor shape - QPoint posTA; // for shape liufeij 20181024 - QSize extTA; // for shape liufeij 20181024 - int rotWithShapeTA; //// for shape liufeij 20181024 - int dpiTA; //// for shape liufeij 20181024 - QString sp_textlink,sp_macro,sp_blip_cstate,sp_blip_rembed; - - // BELOW only for cxnSp shape - QString cxnSp_filpV,cxnSp_macro; - // belwo for cxnsp and sp - QString xsp_cNvPR_name,xsp_cNvPR_id; //x measns shape and cxnSp together using - QString xbwMode; // same as above - QString xIn_algn,xIn_cmpd,xIn_cap,xIn_w; //cxnSp only need xIn_w - QString xprstGeom_prst; - QString x_headEnd_w,x_headEnd_len,x_headEnd_tyep; - QString x_tailEnd_w,x_tailEnd_len,x_tailEnd_tyep; - QString Style_inref_idx,style_fillref_idx,style_effectref_idx,style_forntref_idx; - QString Style_inref_val,style_fillref_val,style_effectref_val,style_forntref_val; - // liufeij }} + QPoint posTA; // for shape liufeij 20181024 + QSize extTA; // for shape liufeij 20181024 + int rotWithShapeTA; //// for shape liufeij 20181024 + int dpiTA; //// for shape liufeij 20181024 + QString sp_textlink, sp_macro, sp_blip_cstate, sp_blip_rembed; + + // BELOW only for cxnSp shape + QString cxnSp_filpV, cxnSp_macro; + // belwo for cxnsp and sp + QString xsp_cNvPR_name, xsp_cNvPR_id; // x measns shape and cxnSp together using + QString xbwMode; // same as above + QString xIn_algn, xIn_cmpd, xIn_cap, xIn_w; // cxnSp only need xIn_w + QString xprstGeom_prst; + QString x_headEnd_w, x_headEnd_len, x_headEnd_tyep; + QString x_tailEnd_w, x_tailEnd_len, x_tailEnd_tyep; + QString Style_inref_idx, style_fillref_idx, style_effectref_idx, style_forntref_idx; + QString Style_inref_val, style_fillref_val, style_effectref_val, style_forntref_val; + // liufeij }} }; class DrawingAbsoluteAnchor : public DrawingAnchor { public: - DrawingAbsoluteAnchor(Drawing *drawing, ObjectType objectType=Unknown); + DrawingAbsoluteAnchor(Drawing *drawing, ObjectType objectType = Unknown); QPoint pos; QSize ext; @@ -137,7 +131,7 @@ class DrawingAbsoluteAnchor : public DrawingAnchor class DrawingOneCellAnchor : public DrawingAnchor { public: - DrawingOneCellAnchor(Drawing *drawing, ObjectType objectType=Unknown); + DrawingOneCellAnchor(Drawing *drawing, ObjectType objectType = Unknown); XlsxMarker from; QSize ext; @@ -152,7 +146,7 @@ class DrawingOneCellAnchor : public DrawingAnchor class DrawingTwoCellAnchor : public DrawingAnchor { public: - DrawingTwoCellAnchor(Drawing *drawing, ObjectType objectType=Unknown); + DrawingTwoCellAnchor(Drawing *drawing, ObjectType objectType = Unknown); XlsxMarker from; XlsxMarker to; diff --git a/QXlsx/header/xlsxformat.h b/QXlsx/header/xlsxformat.h index 8a69e155..5644e5fc 100644 --- a/QXlsx/header/xlsxformat.h +++ b/QXlsx/header/xlsxformat.h @@ -3,15 +3,15 @@ #ifndef QXLSX_FORMAT_H #define QXLSX_FORMAT_H -#include -#include +#include "xlsxglobal.h" + #include -#include +#include #include +#include +#include #include -#include "xlsxglobal.h" - class FormatTest; QT_BEGIN_NAMESPACE_XLSX @@ -27,15 +27,9 @@ class FormatPrivate; class QXLSX_EXPORT Format { public: - enum FontScript - { - FontScriptNormal, - FontScriptSuper, - FontScriptSub - }; + enum FontScript { FontScriptNormal, FontScriptSuper, FontScriptSub }; - enum FontUnderline - { + enum FontUnderline { FontUnderlineNone, FontUnderlineSingle, FontUnderlineDouble, @@ -43,8 +37,7 @@ class QXLSX_EXPORT Format FontUnderlineDoubleAccounting }; - enum HorizontalAlignment - { + enum HorizontalAlignment { AlignHGeneral, AlignLeft, AlignHCenter, @@ -55,8 +48,7 @@ class QXLSX_EXPORT Format AlignHDistributed }; - enum VerticalAlignment - { + enum VerticalAlignment { AlignTop, AlignVCenter, AlignBottom, @@ -64,8 +56,7 @@ class QXLSX_EXPORT Format AlignVDistributed }; - enum BorderStyle - { + enum BorderStyle { BorderNone, BorderThin, BorderMedium, @@ -82,16 +73,14 @@ class QXLSX_EXPORT Format BorderSlantDashDot }; - enum DiagonalBorderType - { + enum DiagonalBorderType { DiagonalBorderNone, DiagonalBorderDown, DiagonalBorderUp, DiagnoalBorderBoth }; - enum FillPattern - { + enum FillPattern { PatternNone, PatternSolid, PatternMediumGray, @@ -200,16 +189,19 @@ class QXLSX_EXPORT Format bool isValid() const; bool isEmpty() const; - bool operator == (const Format &format) const; - bool operator != (const Format &format) const; + bool operator==(const Format &format) const; + bool operator!=(const Format &format) const; - QVariant property(int propertyId, const QVariant &defaultValue=QVariant()) const; - void setProperty(int propertyId, const QVariant &value, const QVariant &clearValue=QVariant(), bool detach=true); + QVariant property(int propertyId, const QVariant &defaultValue = QVariant()) const; + void setProperty(int propertyId, + const QVariant &value, + const QVariant &clearValue = QVariant(), + bool detach = true); void clearProperty(int propertyId); bool hasProperty(int propertyId) const; - bool boolProperty(int propertyId, bool defaultValue=false) const; - int intProperty(int propertyId, int defaultValue=0) const; + bool boolProperty(int propertyId, bool defaultValue = false) const; + int intProperty(int propertyId, int defaultValue = 0) const; double doubleProperty(int propertyId, double defaultValue = 0.0) const; QString stringProperty(int propertyId, const QString &defaultValue = QString()) const; QColor colorProperty(int propertyId, const QColor &defaultValue = QColor()) const; @@ -243,10 +235,11 @@ class QXLSX_EXPORT Format void setFillIndex(int index); void setXfIndex(int index); void setDxfIndex(int index); + private: friend class Styles; friend class ::FormatTest; - friend QDebug operator<<(QDebug, const Format &f); + friend QDebug operator<<(QDebug, const Format &f); int theme() const; @@ -254,7 +247,7 @@ class QXLSX_EXPORT Format }; #ifndef QT_NO_DEBUG_STREAM - QDebug operator<<(QDebug dbg, const Format &f); +QDebug operator<<(QDebug dbg, const Format &f); #endif QT_END_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxformat_p.h b/QXlsx/header/xlsxformat_p.h index 0f3240d9..87d2aa6b 100644 --- a/QXlsx/header/xlsxformat_p.h +++ b/QXlsx/header/xlsxformat_p.h @@ -2,37 +2,36 @@ #ifndef XLSXFORMAT_P_H #define XLSXFORMAT_P_H -#include -#include +#include "xlsxformat.h" + #include #include - -#include "xlsxformat.h" +#include +#include QT_BEGIN_NAMESPACE_XLSX class FormatPrivate : public QSharedData { public: - enum FormatType - { - FT_Invalid = 0, - FT_NumFmt = 0x01, - FT_Font = 0x02, - FT_Alignment = 0x04, - FT_Border = 0x08, - FT_Fill = 0x10, + enum FormatType { + FT_Invalid = 0, + FT_NumFmt = 0x01, + FT_Font = 0x02, + FT_Alignment = 0x04, + FT_Border = 0x08, + FT_Fill = 0x10, FT_Protection = 0x20 }; enum Property { P_STARTID, - //numFmt + // numFmt P_NumFmt_Id, P_NumFmt_FormatCode, - //font + // font P_Font_STARTID, P_Font_Size = P_Font_STARTID, P_Font_Italic, @@ -51,7 +50,7 @@ class FormatPrivate : public QSharedData P_Font_Extend, P_Font_ENDID, - //border + // border P_Border_STARTID, P_Border_LeftStyle = P_Border_STARTID, P_Border_RightStyle, @@ -66,14 +65,14 @@ class FormatPrivate : public QSharedData P_Border_DiagonalType, P_Border_ENDID, - //fill + // fill P_Fill_STARTID, P_Fill_Pattern = P_Fill_STARTID, P_Fill_BgColor, P_Fill_FgColor, P_Fill_ENDID, - //alignment + // alignment P_Alignment_STARTID, P_Alignment_AlignH = P_Alignment_STARTID, P_Alignment_AlignV, @@ -83,7 +82,7 @@ class FormatPrivate : public QSharedData P_Alignment_ShinkToFit, P_Alignment_ENDID, - //protection + // protection P_Protection_Locked, P_Protection_Hidden, @@ -94,7 +93,7 @@ class FormatPrivate : public QSharedData FormatPrivate(const FormatPrivate &other); ~FormatPrivate(); - bool dirty; //The key re-generation is need. + bool dirty; // The key re-generation is need. QByteArray formatKey; bool font_dirty; @@ -124,7 +123,6 @@ class FormatPrivate : public QSharedData QMap properties; }; - QT_END_NAMESPACE_XLSX #endif diff --git a/QXlsx/header/xlsxglobal.h b/QXlsx/header/xlsxglobal.h index a176309f..ef92e022 100644 --- a/QXlsx/header/xlsxglobal.h +++ b/QXlsx/header/xlsxglobal.h @@ -4,25 +4,25 @@ #define XLSXGLOBAL_H #include -#include #include +#include -#include +#include +#include #include #include -#include -#include -#include #include +#include +#include #if defined(QXlsx_SHAREDLIB) -#if defined(QXlsx_EXPORTS) -# define QXLSX_EXPORT Q_DECL_EXPORT -#else -# define QXLSX_EXPORT Q_DECL_IMPORT -#endif +# if defined(QXlsx_EXPORTS) +# define QXLSX_EXPORT Q_DECL_EXPORT +# else +# define QXLSX_EXPORT Q_DECL_IMPORT +# endif #else -# define QXLSX_EXPORT +# define QXLSX_EXPORT #endif #define QT_BEGIN_NAMESPACE_XLSX namespace QXlsx { diff --git a/QXlsx/header/xlsxmediafile_p.h b/QXlsx/header/xlsxmediafile_p.h index 1c18578c..30b9adbc 100644 --- a/QXlsx/header/xlsxmediafile_p.h +++ b/QXlsx/header/xlsxmediafile_p.h @@ -5,8 +5,8 @@ #include "xlsxglobal.h" -#include #include +#include QT_BEGIN_NAMESPACE_XLSX @@ -14,10 +14,10 @@ class MediaFile { public: MediaFile(const QString &fileName); - MediaFile(const QByteArray &bytes, const QString &suffix, const QString &mimeType=QString()); + MediaFile(const QByteArray &bytes, const QString &suffix, const QString &mimeType = QString()); public: - void set(const QByteArray &bytes, const QString &suffix, const QString &mimeType=QString()); + void set(const QByteArray &bytes, const QString &suffix, const QString &mimeType = QString()); QString suffix() const; QString mimeType() const; QByteArray contents() const; diff --git a/QXlsx/header/xlsxrelationships_p.h b/QXlsx/header/xlsxrelationships_p.h index f7259cfa..5595687d 100644 --- a/QXlsx/header/xlsxrelationships_p.h +++ b/QXlsx/header/xlsxrelationships_p.h @@ -38,21 +38,20 @@ #include "xlsxglobal.h" +#include #include #include -#include QT_BEGIN_NAMESPACE_XLSX -struct XlsxRelationship -{ +struct XlsxRelationship { QString id; QString type; QString target; QString targetMode; }; -class Relationships +class Relationships { public: Relationships(); @@ -65,7 +64,9 @@ class Relationships void addDocumentRelationship(const QString &relativeType, const QString &target); void addPackageRelationship(const QString &relativeType, const QString &target); void addMsPackageRelationship(const QString &relativeType, const QString &target); - void addWorksheetRelationship(const QString &relativeType, const QString &target, const QString &targetMode=QString()); + void addWorksheetRelationship(const QString &relativeType, + const QString &target, + const QString &targetMode = QString()); void saveToXmlFile(QIODevice *device) const; QByteArray saveToXmlData() const; @@ -79,7 +80,9 @@ class Relationships private: QList relationships(const QString &type) const; - void addRelationship(const QString &type, const QString &target, const QString &targetMode=QString()); + void addRelationship(const QString &type, + const QString &target, + const QString &targetMode = QString()); QList m_relationships; }; diff --git a/QXlsx/header/xlsxrichstring.h b/QXlsx/header/xlsxrichstring.h index 41a28db0..0eda23c0 100644 --- a/QXlsx/header/xlsxrichstring.h +++ b/QXlsx/header/xlsxrichstring.h @@ -25,23 +25,24 @@ #ifndef XLSXRICHSTRING_H #define XLSXRICHSTRING_H -#include "xlsxglobal.h" #include "xlsxformat.h" -#include -#include +#include "xlsxglobal.h" + #include +#include +#include QT_BEGIN_NAMESPACE_XLSX class RichStringPrivate; class RichString; // qHash is a friend, but we can't use default arguments for friends (§8.3.6.4) - uint qHash(const RichString &rs, uint seed = 0) Q_DECL_NOTHROW; +uint qHash(const RichString &rs, uint seed = 0) Q_DECL_NOTHROW; class QXLSX_EXPORT RichString { public: RichString(); - explicit RichString(const QString& text); + explicit RichString(const QString &text); RichString(const RichString &other); ~RichString(); @@ -60,26 +61,27 @@ class QXLSX_EXPORT RichString operator QVariant() const; RichString &operator=(const RichString &other); + private: - friend uint qHash(const RichString &rs, uint seed) Q_DECL_NOTHROW; - friend bool operator==(const RichString &rs1, const RichString &rs2); - friend bool operator!=(const RichString &rs1, const RichString &rs2); - friend bool operator<(const RichString &rs1, const RichString &rs2); - friend QDebug operator<<(QDebug dbg, const RichString &rs); + friend uint qHash(const RichString &rs, uint seed) Q_DECL_NOTHROW; + friend bool operator==(const RichString &rs1, const RichString &rs2); + friend bool operator!=(const RichString &rs1, const RichString &rs2); + friend bool operator<(const RichString &rs1, const RichString &rs2); + friend QDebug operator<<(QDebug dbg, const RichString &rs); QSharedDataPointer d; }; - bool operator==(const RichString &rs1, const RichString &rs2); - bool operator!=(const RichString &rs1, const RichString &rs2); - bool operator<(const RichString &rs1, const RichString &rs2); - bool operator==(const RichString &rs1, const QString &rs2); - bool operator==(const QString &rs1, const RichString &rs2); - bool operator!=(const RichString &rs1, const QString &rs2); - bool operator!=(const QString &rs1, const RichString &rs2); +bool operator==(const RichString &rs1, const RichString &rs2); +bool operator!=(const RichString &rs1, const RichString &rs2); +bool operator<(const RichString &rs1, const RichString &rs2); +bool operator==(const RichString &rs1, const QString &rs2); +bool operator==(const QString &rs1, const RichString &rs2); +bool operator!=(const RichString &rs1, const QString &rs2); +bool operator!=(const QString &rs1, const RichString &rs2); #ifndef QT_NO_DEBUG_STREAM - QDebug operator<<(QDebug dbg, const RichString &rs); +QDebug operator<<(QDebug dbg, const RichString &rs); #endif QT_END_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxsharedstrings_p.h b/QXlsx/header/xlsxsharedstrings_p.h index c0b32503..75d563df 100644 --- a/QXlsx/header/xlsxsharedstrings_p.h +++ b/QXlsx/header/xlsxsharedstrings_p.h @@ -36,23 +36,24 @@ // We mean it. // +#include "xlsxabstractooxmlfile.h" +#include "xlsxglobal.h" +#include "xlsxrichstring.h" + #include -#include #include +#include #include #include -#include "xlsxglobal.h" -#include "xlsxrichstring.h" -#include "xlsxabstractooxmlfile.h" - QT_BEGIN_NAMESPACE_XLSX class XlsxSharedStringInfo { public: - XlsxSharedStringInfo(int index=0, int count = 1) : - index(index), count(count) + XlsxSharedStringInfo(int index = 0, int count = 1) + : index(index) + , count(count) { } @@ -60,13 +61,13 @@ class XlsxSharedStringInfo int count; }; -class SharedStrings : public AbstractOOXmlFile +class SharedStrings : public AbstractOOXmlFile { public: SharedStrings(CreateFlag flag); int count() const; bool isEmpty() const; - + int addSharedString(const QString &string); int addSharedString(const RichString &string); void removeSharedString(const QString &string); @@ -82,13 +83,13 @@ class SharedStrings : public AbstractOOXmlFile bool loadFromXmlFile(QIODevice *device) override; private: - void readString(QXmlStreamReader &reader); // - void readRichStringPart(QXmlStreamReader &reader, RichString &rich); // + void readString(QXmlStreamReader &reader); // + void readRichStringPart(QXmlStreamReader &reader, RichString &rich); // void readPlainStringPart(QXmlStreamReader &reader, RichString &rich); // Format readRichStringPart_rPr(QXmlStreamReader &reader); void writeRichStringPart_rPr(QXmlStreamWriter &writer, const Format &format) const; - QHash m_stringTable; //for fast lookup + QHash m_stringTable; // for fast lookup QList m_stringList; int m_stringCount; }; diff --git a/QXlsx/header/xlsxsimpleooxmlfile_p.h b/QXlsx/header/xlsxsimpleooxmlfile_p.h index ba026c99..cb8c26e7 100644 --- a/QXlsx/header/xlsxsimpleooxmlfile_p.h +++ b/QXlsx/header/xlsxsimpleooxmlfile_p.h @@ -37,8 +37,8 @@ // #include "xlsxabstractooxmlfile.h" -#include #include +#include QT_BEGIN_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxstyles_p.h b/QXlsx/header/xlsxstyles_p.h index 380afd20..77c68abb 100644 --- a/QXlsx/header/xlsxstyles_p.h +++ b/QXlsx/header/xlsxstyles_p.h @@ -36,30 +36,32 @@ // We mean it. // -#include #include +#include #include #include +#include #include #include -#include #include -#include +#include // class StylesTest; -#include "xlsxglobal.h" -#include "xlsxformat.h" #include "xlsxabstractooxmlfile.h" +#include "xlsxformat.h" +#include "xlsxglobal.h" QT_BEGIN_NAMESPACE_XLSX class Format; class XlsxColor; -struct XlsxFormatNumberData -{ - XlsxFormatNumberData() : formatIndex(0) {} +struct XlsxFormatNumberData { + XlsxFormatNumberData() + : formatIndex(0) + { + } int formatIndex; QString formatString; @@ -70,9 +72,9 @@ class Styles : public AbstractOOXmlFile public: Styles(CreateFlag flag); ~Styles(); - void addXfFormat(const Format &format, bool force=false); + void addXfFormat(const Format &format, bool force = false); Format xfFormat(int idx) const; - void addDxfFormat(const Format &format, bool force=false); + void addDxfFormat(const Format &format, bool force = false); Format dxfFormat(int idx) const; void saveToXmlFile(QIODevice *device) const override; @@ -93,7 +95,10 @@ class Styles : public AbstractOOXmlFile void writeFill(QXmlStreamWriter &writer, const Format &fill, bool isDxf = false) const; void writeBorders(QXmlStreamWriter &writer) const; void writeBorder(QXmlStreamWriter &writer, const Format &border, bool isDxf = false) const; - void writeSubBorder(QXmlStreamWriter &writer, const QString &type, int style, const XlsxColor &color) const; + void writeSubBorder(QXmlStreamWriter &writer, + const QString &type, + int style, + const XlsxColor &color) const; void writeCellXfs(QXmlStreamWriter &writer) const; void writeDxfs(QXmlStreamWriter &writer) const; void writeDxf(QXmlStreamWriter &writer, const Format &format) const; @@ -106,7 +111,10 @@ class Styles : public AbstractOOXmlFile bool readFill(QXmlStreamReader &reader, Format &format); bool readBorders(QXmlStreamReader &reader); bool readBorder(QXmlStreamReader &reader, Format &format); - bool readSubBorder(QXmlStreamReader &reader, const QString &name, Format::BorderStyle &style, XlsxColor &color); + bool readSubBorder(QXmlStreamReader &reader, + const QString &name, + Format::BorderStyle &style, + XlsxColor &color); bool readCellXfs(QXmlStreamReader &reader); bool readDxfs(QXmlStreamReader &reader); bool readDxf(QXmlStreamReader &reader); @@ -116,8 +124,8 @@ class Styles : public AbstractOOXmlFile bool readCellStyleXfs(QXmlStreamReader &reader); QHash m_builtinNumFmtsHash; - QMap > m_customNumFmtIdMap; - QHash > m_customNumFmtsHash; + QMap> m_customNumFmtIdMap; + QHash> m_customNumFmtsHash; int m_nextCustomNumFmtId; QList m_fontsList; QList m_fillsList; diff --git a/QXlsx/header/xlsxtheme_p.h b/QXlsx/header/xlsxtheme_p.h index a9a783be..94d16e8f 100644 --- a/QXlsx/header/xlsxtheme_p.h +++ b/QXlsx/header/xlsxtheme_p.h @@ -3,12 +3,12 @@ #ifndef XLSXTHEME_H #define XLSXTHEME_H -#include -#include -#include - #include "xlsxabstractooxmlfile.h" +#include +#include +#include + QT_BEGIN_NAMESPACE_XLSX class Theme : public AbstractOOXmlFile diff --git a/QXlsx/header/xlsxutility_p.h b/QXlsx/header/xlsxutility_p.h index 0c8e68f6..e7423e79 100644 --- a/QXlsx/header/xlsxutility_p.h +++ b/QXlsx/header/xlsxutility_p.h @@ -3,31 +3,30 @@ #ifndef XLSXUTILITY_H #define XLSXUTILITY_H -#include +#include "xlsxglobal.h" + +#include +#include +#include #include -#include #include #include #include -#include -#include -#include #include #include - -#include "xlsxglobal.h" +#include QT_BEGIN_NAMESPACE_XLSX class CellReference; -bool parseXsdBoolean(const QString &value, bool defaultValue=false); +bool parseXsdBoolean(const QString &value, bool defaultValue = false); QStringList splitPath(const QString &path); QString getRelFilePath(const QString &filePath); -double datetimeToNumber(const QDateTime &dt, bool is1904=false); -QVariant datetimeFromNumber(double num, bool is1904=false); +double datetimeToNumber(const QDateTime &dt, bool is1904 = false); +QVariant datetimeFromNumber(double num, bool is1904 = false); double timeToNumber(const QTime &t); QString createSafeSheetName(const QString &nameProposal); @@ -36,7 +35,9 @@ QString unescapeSheetName(const QString &sheetName); bool isSpaceReserveNeeded(const QString &string); -QString convertSharedFormula(const QString &rootFormula, const CellReference &rootCell, const CellReference &cell); +QString convertSharedFormula(const QString &rootFormula, + const CellReference &rootCell, + const CellReference &cell); QT_END_NAMESPACE_XLSX #endif // XLSXUTILITY_H diff --git a/QXlsx/header/xlsxworkbook.h b/QXlsx/header/xlsxworkbook.h index 536ad5f5..2e3e796a 100644 --- a/QXlsx/header/xlsxworkbook.h +++ b/QXlsx/header/xlsxworkbook.h @@ -3,17 +3,17 @@ #ifndef XLSXWORKBOOK_H #define XLSXWORKBOOK_H -#include -#include -#include -#include -#include +#include "xlsxabstractooxmlfile.h" +#include "xlsxabstractsheet.h" +#include "xlsxglobal.h" #include -#include "xlsxglobal.h" -#include "xlsxabstractooxmlfile.h" -#include "xlsxabstractsheet.h" +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE_XLSX @@ -39,34 +39,40 @@ class QXLSX_EXPORT Workbook : public AbstractOOXmlFile int sheetCount() const; AbstractSheet *sheet(int index) const; - AbstractSheet *addSheet(const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); - AbstractSheet *insertSheet(int index, const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); + AbstractSheet *addSheet(const QString &name = QString(), + AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); + AbstractSheet *insertSheet(int index, + const QString &name = QString(), + AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); bool renameSheet(int index, const QString &name); bool deleteSheet(int index); - bool copySheet(int index, const QString &newName=QString()); + bool copySheet(int index, const QString &newName = QString()); bool moveSheet(int srcIndex, int distIndex); AbstractSheet *activeSheet() const; bool setActiveSheet(int index); -// void addChart(); - bool defineName(const QString &name, const QString &formula, const QString &comment=QString(), const QString &scope=QString()); + // void addChart(); + bool defineName(const QString &name, + const QString &formula, + const QString &comment = QString(), + const QString &scope = QString()); bool isDate1904() const; void setDate1904(bool date1904); bool isStringsToNumbersEnabled() const; - void setStringsToNumbersEnabled(bool enable=true); + void setStringsToNumbersEnabled(bool enable = true); bool isStringsToHyperlinksEnabled() const; - void setStringsToHyperlinksEnabled(bool enable=true); + void setStringsToHyperlinksEnabled(bool enable = true); bool isHtmlToRichStringEnabled() const; - void setHtmlToRichStringEnabled(bool enable=true); + void setHtmlToRichStringEnabled(bool enable = true); QString defaultDateFormat() const; void setDefaultDateFormat(const QString &format); - //internal used member - void addMediaFile(std::shared_ptr media, bool force=false); - QList > mediaFiles() const; + // internal used member + void addMediaFile(std::shared_ptr media, bool force = false); + QList> mediaFiles() const; void addChartFile(QSharedPointer chartFile); - QList > chartFiles() const; + QList> chartFiles() const; private: friend class Worksheet; @@ -85,9 +91,11 @@ class QXLSX_EXPORT Workbook : public AbstractOOXmlFile Theme *theme(); QList images(); QList drawings(); - QList > getSheetsByTypes(AbstractSheet::SheetType type) const; + QList> getSheetsByTypes(AbstractSheet::SheetType type) const; QStringList worksheetNames() const; - AbstractSheet *addSheet(const QString &name, int sheetId, AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); + AbstractSheet *addSheet(const QString &name, + int sheetId, + AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); }; QT_END_NAMESPACE_XLSX diff --git a/QXlsx/header/xlsxworkbook_p.h b/QXlsx/header/xlsxworkbook_p.h index 7124f30a..86847018 100644 --- a/QXlsx/header/xlsxworkbook_p.h +++ b/QXlsx/header/xlsxworkbook_p.h @@ -3,32 +3,37 @@ #ifndef XLSXWORKBOOK_P_H #define XLSXWORKBOOK_P_H -#include -#include -#include - -#include "xlsxworkbook.h" #include "xlsxabstractooxmlfile_p.h" -#include "xlsxtheme_p.h" -#include "xlsxsimpleooxmlfile_p.h" #include "xlsxrelationships_p.h" +#include "xlsxsimpleooxmlfile_p.h" +#include "xlsxtheme_p.h" +#include "xlsxworkbook.h" + +#include +#include +#include QT_BEGIN_NAMESPACE_XLSX -struct XlsxDefineNameData -{ +struct XlsxDefineNameData { XlsxDefineNameData() - :sheetId(-1) - {} - XlsxDefineNameData(const QString &name, const QString &formula, const QString &comment, int sheetId=-1) - :name(name), formula(formula), comment(comment), sheetId(sheetId) + : sheetId(-1) + { + } + XlsxDefineNameData(const QString &name, + const QString &formula, + const QString &comment, + int sheetId = -1) + : name(name) + , formula(formula) + , comment(comment) + , sheetId(sheetId) { - } QString name; QString formula; QString comment; - //using internal sheetId, instead of the localSheetId(order in the workbook) + // using internal sheetId, instead of the localSheetId(order in the workbook) int sheetId; }; @@ -39,13 +44,13 @@ class WorkbookPrivate : public AbstractOOXmlFilePrivate WorkbookPrivate(Workbook *q, Workbook::CreateFlag flag); QSharedPointer sharedStrings; - QList > sheets; - QList > externalLinks; + QList> sheets; + QList> externalLinks; QStringList sheetNames; QSharedPointer styles; QSharedPointer theme; - QList > mediaFiles; - QList > chartFiles; + QList> mediaFiles; + QList> chartFiles; QList definedNamesList; bool strings_to_numbers_enabled; @@ -63,7 +68,7 @@ class WorkbookPrivate : public AbstractOOXmlFilePrivate int firstsheet; int table_count; - //Used to generate new sheet name and id + // Used to generate new sheet name and id int last_worksheet_index; int last_chartsheet_index; int last_sheet_id; diff --git a/QXlsx/header/xlsxworksheet.h b/QXlsx/header/xlsxworksheet.h index 75a08fcb..7c9232a8 100644 --- a/QXlsx/header/xlsxworksheet.h +++ b/QXlsx/header/xlsxworksheet.h @@ -3,22 +3,22 @@ #ifndef XLSXWORKSHEET_H #define XLSXWORKSHEET_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "xlsxabstractsheet.h" #include "xlsxcell.h" +#include "xlsxcelllocation.h" #include "xlsxcellrange.h" #include "xlsxcellreference.h" -#include "xlsxcelllocation.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include class WorksheetTest; @@ -51,44 +51,78 @@ class QXLSX_EXPORT Worksheet : public AbstractSheet ~Worksheet(); public: - bool write(const CellReference &row_column, const QVariant &value, const Format &format=Format()); - bool write(int row, int column, const QVariant &value, const Format &format=Format()); + bool write(const CellReference &row_column, + const QVariant &value, + const Format &format = Format()); + bool write(int row, int column, const QVariant &value, const Format &format = Format()); QVariant read(const CellReference &row_column) const; QVariant read(int row, int column) const; - bool writeString(const CellReference &row_column, const QString &value, const Format &format=Format()); - bool writeString(int row, int column, const QString &value, const Format &format=Format()); - bool writeString(const CellReference &row_column, const RichString &value, const Format &format=Format()); - bool writeString(int row, int column, const RichString &value, const Format &format=Format()); - - bool writeInlineString(const CellReference &row_column, const QString &value, const Format &format=Format()); - bool writeInlineString(int row, int column, const QString &value, const Format &format=Format()); - - bool writeNumeric(const CellReference &row_column, double value, const Format &format=Format()); - bool writeNumeric(int row, int column, double value, const Format &format=Format()); - - bool writeFormula(const CellReference &row_column, const CellFormula &formula, const Format &format=Format(), double result=0); - bool writeFormula(int row, int column, const CellFormula &formula, const Format &format=Format(), double result=0); - - bool writeBlank(const CellReference &row_column, const Format &format=Format()); - bool writeBlank(int row, int column, const Format &format=Format()); - - bool writeBool(const CellReference &row_column, bool value, const Format &format=Format()); - bool writeBool(int row, int column, bool value, const Format &format=Format()); - - bool writeDateTime(const CellReference &row_column, const QDateTime& dt, const Format &format=Format()); - bool writeDateTime(int row, int column, const QDateTime& dt, const Format &format=Format()); + bool writeString(const CellReference &row_column, + const QString &value, + const Format &format = Format()); + bool writeString(int row, int column, const QString &value, const Format &format = Format()); + bool writeString(const CellReference &row_column, + const RichString &value, + const Format &format = Format()); + bool writeString(int row, int column, const RichString &value, const Format &format = Format()); + + bool writeInlineString(const CellReference &row_column, + const QString &value, + const Format &format = Format()); + bool writeInlineString(int row, + int column, + const QString &value, + const Format &format = Format()); + + bool writeNumeric(const CellReference &row_column, + double value, + const Format &format = Format()); + bool writeNumeric(int row, int column, double value, const Format &format = Format()); + + bool writeFormula(const CellReference &row_column, + const CellFormula &formula, + const Format &format = Format(), + double result = 0); + bool writeFormula(int row, + int column, + const CellFormula &formula, + const Format &format = Format(), + double result = 0); + + bool writeBlank(const CellReference &row_column, const Format &format = Format()); + bool writeBlank(int row, int column, const Format &format = Format()); + + bool writeBool(const CellReference &row_column, bool value, const Format &format = Format()); + bool writeBool(int row, int column, bool value, const Format &format = Format()); + + bool writeDateTime(const CellReference &row_column, + const QDateTime &dt, + const Format &format = Format()); + bool writeDateTime(int row, int column, const QDateTime &dt, const Format &format = Format()); // dev67 - bool writeDate(const CellReference &row_column, const QDate& dt, const Format &format=Format()); - bool writeDate(int row, int column, const QDate& dt, const Format &format=Format()); - - bool writeTime(const CellReference &row_column, const QTime& t, const Format &format=Format()); - bool writeTime(int row, int column, const QTime& t, const Format &format=Format()); - - bool writeHyperlink(const CellReference &row_column, const QUrl &url, const Format &format=Format(), const QString &display=QString(), const QString &tip=QString()); - bool writeHyperlink(int row, int column, const QUrl &url, const Format &format=Format(), const QString &display=QString(), const QString &tip=QString()); + bool writeDate(const CellReference &row_column, + const QDate &dt, + const Format &format = Format()); + bool writeDate(int row, int column, const QDate &dt, const Format &format = Format()); + + bool + writeTime(const CellReference &row_column, const QTime &t, const Format &format = Format()); + bool writeTime(int row, int column, const QTime &t, const Format &format = Format()); + + bool writeHyperlink(const CellReference &row_column, + const QUrl &url, + const Format &format = Format(), + const QString &display = QString(), + const QString &tip = QString()); + bool writeHyperlink(int row, + int column, + const QUrl &url, + const Format &format = Format(), + const QString &display = QString(), + const QString &tip = QString()); bool addDataValidation(const DataValidation &validation); bool addConditionalFormatting(const ConditionalFormatting &cf); @@ -97,19 +131,19 @@ class QXLSX_EXPORT Worksheet : public AbstractSheet Cell *cellAt(int row, int column) const; int insertImage(int row, int column, const QImage &image); - bool getImage(int imageIndex, QImage& img); - bool getImage(int row, int column, QImage& img); + bool getImage(int imageIndex, QImage &img); + bool getImage(int row, int column, QImage &img); uint getImageCount(); Chart *insertChart(int row, int column, const QSize &size); - bool mergeCells(const CellRange &range, const Format &format=Format()); + bool mergeCells(const CellRange &range, const Format &format = Format()); bool unmergeCells(const CellRange &range); QList mergedCells() const; - bool setColumnWidth(const CellRange& range, double width); - bool setColumnFormat(const CellRange& range, const Format &format); - bool setColumnHidden(const CellRange& range, bool hidden); + bool setColumnWidth(const CellRange &range, double width); + bool setColumnFormat(const CellRange &range, const Format &format); + bool setColumnHidden(const CellRange &range, bool hidden); bool setColumnWidth(int colFirst, int colLast, double width); bool setColumnFormat(int colFirst, int colLast, const Format &format); bool setColumnHidden(int colFirst, int colLast, bool hidden); @@ -118,9 +152,9 @@ class QXLSX_EXPORT Worksheet : public AbstractSheet Format columnFormat(int column); bool isColumnHidden(int column); - bool setRowHeight(int rowFirst,int rowLast, double height); - bool setRowFormat(int rowFirst,int rowLast, const Format &format); - bool setRowHidden(int rowFirst,int rowLast, bool hidden); + bool setRowHeight(int rowFirst, int rowLast, double height); + bool setRowFormat(int rowFirst, int rowLast, const Format &format); + bool setRowHidden(int rowFirst, int rowLast, bool hidden); double rowHeight(int row); Format rowFormat(int row); @@ -151,9 +185,9 @@ class QXLSX_EXPORT Worksheet : public AbstractSheet void setOutlineSymbolsVisible(bool visible); bool isWhiteSpaceVisible() const; void setWhiteSpaceVisible(bool visible); - bool setStartPage(int spagen); //add by liufeijin20181028 + bool setStartPage(int spagen); // add by liufeijin20181028 - QVector getFullCells(int* maxRow, int* maxCol); + QVector getFullCells(int *maxRow, int *maxCol); private: void saveToXmlFile(QIODevice *device) const override; diff --git a/QXlsx/header/xlsxworksheet_p.h b/QXlsx/header/xlsxworksheet_p.h index 1fdd5520..b7210b71 100644 --- a/QXlsx/header/xlsxworksheet_p.h +++ b/QXlsx/header/xlsxworksheet_p.h @@ -3,76 +3,78 @@ #ifndef XLSXWORKSHEET_P_H #define XLSXWORKSHEET_P_H -#include -#include -#include -#include -#include -#include - -#include - -#include "xlsxworksheet.h" #include "xlsxabstractsheet_p.h" #include "xlsxcell.h" -#include "xlsxdatavalidation.h" -#include "xlsxconditionalformatting.h" #include "xlsxcellformula.h" +#include "xlsxconditionalformatting.h" +#include "xlsxdatavalidation.h" +#include "xlsxworksheet.h" + +#include +#include +#include +#include +#include +#include +#include class QXmlStreamWriter; class QXmlStreamReader; QT_BEGIN_NAMESPACE_XLSX -const int XLSX_ROW_MAX = 1048576; +const int XLSX_ROW_MAX = 1048576; const int XLSX_COLUMN_MAX = 16384; const int XLSX_STRING_MAX = 32767; class SharedStrings; -struct XlsxHyperlinkData -{ - enum LinkType - { - External, - Internal - }; - - XlsxHyperlinkData(LinkType linkType=External, const QString &target=QString(), const QString &location=QString() - , const QString &display=QString(), const QString &tip=QString()) - :linkType(linkType), target(target), location(location), display(display), tooltip(tip) +struct XlsxHyperlinkData { + enum LinkType { External, Internal }; + + XlsxHyperlinkData(LinkType linkType = External, + const QString &target = QString(), + const QString &location = QString(), + const QString &display = QString(), + const QString &tip = QString()) + : linkType(linkType) + , target(target) + , location(location) + , display(display) + , tooltip(tip) { - } LinkType linkType; - QString target; //For External link + QString target; // For External link QString location; QString display; QString tooltip; }; // ECMA-376 Part1 18.3.1.81 -struct XlsxSheetFormatProps -{ - XlsxSheetFormatProps(int baseColWidth = 8, - bool customHeight = false, - double defaultColWidth = 8.430f, // https://learn.microsoft.com/en-us/office/troubleshoot/excel/determine-column-widths - double defaultRowHeight = 15, - quint8 outlineLevelCol = 0, - quint8 outlineLevelRow = 0, - bool thickBottom = false, - bool thickTop = false, - bool zeroHeight = false) : - baseColWidth(baseColWidth), - customHeight(customHeight), - defaultColWidth(defaultColWidth), - defaultRowHeight(defaultRowHeight), - outlineLevelCol(outlineLevelCol), - outlineLevelRow(outlineLevelRow), - thickBottom(thickBottom), - thickTop(thickTop), - zeroHeight(zeroHeight) { +struct XlsxSheetFormatProps { + XlsxSheetFormatProps( + int baseColWidth = 8, + bool customHeight = false, + double defaultColWidth = + 8.430f, // https://learn.microsoft.com/en-us/office/troubleshoot/excel/determine-column-widths + double defaultRowHeight = 15, + quint8 outlineLevelCol = 0, + quint8 outlineLevelRow = 0, + bool thickBottom = false, + bool thickTop = false, + bool zeroHeight = false) + : baseColWidth(baseColWidth) + , customHeight(customHeight) + , defaultColWidth(defaultColWidth) + , defaultRowHeight(defaultRowHeight) + , outlineLevelCol(outlineLevelCol) + , outlineLevelRow(outlineLevelRow) + , thickBottom(thickBottom) + , thickTop(thickTop) + , zeroHeight(zeroHeight) + { } int baseColWidth; @@ -86,13 +88,15 @@ struct XlsxSheetFormatProps bool zeroHeight; }; -struct XlsxRowInfo -{ - XlsxRowInfo(double height=0, const Format &format=Format(), bool hidden=false) : - customHeight(false), height(height), format(format), hidden(hidden), outlineLevel(0) - , collapsed(false) +struct XlsxRowInfo { + XlsxRowInfo(double height = 0, const Format &format = Format(), bool hidden = false) + : customHeight(false) + , height(height) + , format(format) + , hidden(hidden) + , outlineLevel(0) + , collapsed(false) { - } bool customHeight; @@ -103,25 +107,23 @@ struct XlsxRowInfo bool collapsed; }; -struct XlsxColumnInfo -{ - XlsxColumnInfo( int firstColumn, // = 0, - int lastColumn, // = 1, - bool isSetWidth, - double width = 0, - const Format &format = Format(), - bool hidden = false) - : width(width), - format(format), - firstColumn(firstColumn), - lastColumn(lastColumn), - outlineLevel(0), - isSetWidth(isSetWidth), - customWidth(false), - hidden(hidden), - collapsed(false) +struct XlsxColumnInfo { + XlsxColumnInfo(int firstColumn, // = 0, + int lastColumn, // = 1, + bool isSetWidth, + double width = 0, + const Format &format = Format(), + bool hidden = false) + : width(width) + , format(format) + , firstColumn(firstColumn) + , lastColumn(lastColumn) + , outlineLevel(0) + , isSetWidth(isSetWidth) + , customWidth(false) + , hidden(hidden) + , collapsed(false) { - } double width; @@ -144,7 +146,7 @@ class WorksheetPrivate : public AbstractSheetPrivate ~WorksheetPrivate(); public: - int checkDimensions(int row, int col, bool ignore_row=false, bool ignore_col=false); + int checkDimensions(int row, int col, bool ignore_row = false, bool ignore_col = false); Format cellFormat(int row, int col) const; QString generateDimensionString() const; void calculateSpans() const; @@ -152,7 +154,10 @@ class WorksheetPrivate : public AbstractSheetPrivate void validateDimension(); void saveXmlSheetData(QXmlStreamWriter &writer) const; - void saveXmlCellData(QXmlStreamWriter &writer, int row, int col, std::shared_ptr cell) const; + void saveXmlCellData(QXmlStreamWriter &writer, + int row, + int col, + std::shared_ptr cell) const; void saveXmlMergeCells(QXmlStreamWriter &writer) const; void saveXmlHyperlinks(QXmlStreamWriter &writer) const; void saveXmlDrawings(QXmlStreamWriter &writer) const; @@ -169,22 +174,22 @@ class WorksheetPrivate : public AbstractSheetPrivate void loadXmlSheetViews(QXmlStreamReader &reader); void loadXmlHyperlinks(QXmlStreamReader &reader); - QList > getRowInfoList(int rowFirst, int rowLast); - QList > getColumnInfoList(int colFirst, int colLast); + QList> getRowInfoList(int rowFirst, int rowLast); + QList> getColumnInfoList(int colFirst, int colLast); QList getColumnIndexes(int colFirst, int colLast); bool isColumnRangeValid(int colFirst, int colLast); SharedStrings *sharedStrings() const; public: - QMap > > cellTable; + QMap>> cellTable; - QMap > comments; - QMap > > urlTable; + QMap> comments; + QMap>> urlTable; QList merges; - QMap > rowsInfo; - QMap > colsInfo; - QMap > colsInfoHelper; + QMap> rowsInfo; + QMap> colsInfo; + QMap> colsInfoHelper; QList dataValidationsList; QList conditionalFormattingList; @@ -226,7 +231,7 @@ class WorksheetPrivate : public AbstractSheetPrivate // header footer, liufeijin QString MoodFooter; QString ModdHeader; - QString MoodalignWithMargins; // add align 20190619 + QString MoodalignWithMargins; // add align 20190619 XlsxSheetFormatProps sheetFormatProps; @@ -244,7 +249,6 @@ class WorksheetPrivate : public AbstractSheetPrivate QRegularExpression urlPattern; private: - static double calculateColWidth(int characters); }; diff --git a/QXlsx/header/xlsxzipreader_p.h b/QXlsx/header/xlsxzipreader_p.h index 0a18cbc9..e2c965f6 100644 --- a/QXlsx/header/xlsxzipreader_p.h +++ b/QXlsx/header/xlsxzipreader_p.h @@ -3,19 +3,18 @@ #ifndef QXLSX_XLSXZIPREADER_P_H #define QXLSX_XLSXZIPREADER_P_H -#include -#include -#include - #include "xlsxglobal.h" +#include +#include +#include #include class QZipReader; QT_BEGIN_NAMESPACE_XLSX -class ZipReader +class ZipReader { public: explicit ZipReader(const QString &fileName); diff --git a/QXlsx/header/xlsxzipwriter_p.h b/QXlsx/header/xlsxzipwriter_p.h index 52ae63cb..799e77c6 100644 --- a/QXlsx/header/xlsxzipwriter_p.h +++ b/QXlsx/header/xlsxzipwriter_p.h @@ -3,12 +3,12 @@ #ifndef QXLSX_ZIPWRITER_H #define QXLSX_ZIPWRITER_H -#include -#include -#include - #include "xlsxglobal.h" +#include +#include +#include + class QZipWriter; QT_BEGIN_NAMESPACE_XLSX diff --git a/QXlsx/source/xlsxabstractooxmlfile.cpp b/QXlsx/source/xlsxabstractooxmlfile.cpp index e94a721a..47025926 100644 --- a/QXlsx/source/xlsxabstractooxmlfile.cpp +++ b/QXlsx/source/xlsxabstractooxmlfile.cpp @@ -1,24 +1,28 @@ // xlsxabstractooxmlfile.cpp -#include -#include -#include - #include "xlsxabstractooxmlfile.h" + #include "xlsxabstractooxmlfile_p.h" +#include +#include +#include + QT_BEGIN_NAMESPACE_XLSX -AbstractOOXmlFilePrivate::AbstractOOXmlFilePrivate(AbstractOOXmlFile *q, AbstractOOXmlFile::CreateFlag flag=AbstractOOXmlFile::F_NewFromScratch) - : relationships(new Relationships), flag(flag), q_ptr(q) +AbstractOOXmlFilePrivate::AbstractOOXmlFilePrivate( + AbstractOOXmlFile *q, + AbstractOOXmlFile::CreateFlag flag = AbstractOOXmlFile::F_NewFromScratch) + : relationships(new Relationships) + , flag(flag) + , q_ptr(q) { - } AbstractOOXmlFilePrivate::~AbstractOOXmlFilePrivate() { if (relationships) { - delete relationships; + delete relationships; } } @@ -31,14 +35,13 @@ AbstractOOXmlFilePrivate::~AbstractOOXmlFilePrivate() */ AbstractOOXmlFile::AbstractOOXmlFile(CreateFlag flag) - :d_ptr(new AbstractOOXmlFilePrivate(this, flag)) + : d_ptr(new AbstractOOXmlFilePrivate(this, flag)) { } AbstractOOXmlFile::AbstractOOXmlFile(AbstractOOXmlFilePrivate *d) - :d_ptr(d) + : d_ptr(d) { - } AbstractOOXmlFile::~AbstractOOXmlFile() @@ -83,7 +86,6 @@ QString AbstractOOXmlFile::filePath() const return d->filePathInPackage; } - /*! * \internal */ @@ -93,5 +95,4 @@ Relationships *AbstractOOXmlFile::relationships() const return d->relationships; } - QT_END_NAMESPACE_XLSX diff --git a/QXlsx/source/xlsxabstractsheet.cpp b/QXlsx/source/xlsxabstractsheet.cpp index 88f4db4c..69a4f5e8 100644 --- a/QXlsx/source/xlsxabstractsheet.cpp +++ b/QXlsx/source/xlsxabstractsheet.cpp @@ -1,23 +1,22 @@ // xlsxabstractsheet.cpp -#include - #include "xlsxabstractsheet.h" + #include "xlsxabstractsheet_p.h" #include "xlsxworkbook.h" +#include + QT_BEGIN_NAMESPACE_XLSX AbstractSheetPrivate::AbstractSheetPrivate(AbstractSheet *p, AbstractSheet::CreateFlag flag) : AbstractOOXmlFilePrivate(p, flag) { - type = AbstractSheet::ST_WorkSheet; + type = AbstractSheet::ST_WorkSheet; sheetState = AbstractSheet::SS_Visible; } -AbstractSheetPrivate::~AbstractSheetPrivate() -{ -} +AbstractSheetPrivate::~AbstractSheetPrivate() {} /*! \class AbstractSheet @@ -52,15 +51,17 @@ AbstractSheetPrivate::~AbstractSheetPrivate() /*! * \internal */ -AbstractSheet::AbstractSheet(const QString &name, int id, Workbook *workbook, AbstractSheetPrivate *d) : - AbstractOOXmlFile(d) -{ - d_func()->name = name; - d_func()->id = id; +AbstractSheet::AbstractSheet(const QString &name, + int id, + Workbook *workbook, + AbstractSheetPrivate *d) + : AbstractOOXmlFile(d) +{ + d_func()->name = name; + d_func()->id = id; d_func()->workbook = workbook; } - /*! * Returns the name of the sheet. */ diff --git a/QXlsx/source/xlsxcell.cpp b/QXlsx/source/xlsxcell.cpp index f3fe4b61..7a0e49bc 100644 --- a/QXlsx/source/xlsxcell.cpp +++ b/QXlsx/source/xlsxcell.cpp @@ -1,30 +1,30 @@ // xlsxcell.cpp -#include - -#include -#include -#include -#include -#include - #include "xlsxcell.h" + #include "xlsxcell_p.h" #include "xlsxformat.h" #include "xlsxformat_p.h" #include "xlsxutility_p.h" -#include "xlsxworksheet.h" #include "xlsxworkbook.h" +#include "xlsxworksheet.h" + +#include + +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE_XLSX -CellPrivate::CellPrivate(Cell *p) : - q_ptr(p) +CellPrivate::CellPrivate(Cell *p) + : q_ptr(p) { - } -CellPrivate::CellPrivate(const CellPrivate * const cp) +CellPrivate::CellPrivate(const CellPrivate *const cp) : parent(cp->parent) , cellType(cp->cellType) , value(cp->value) @@ -33,7 +33,6 @@ CellPrivate::CellPrivate(const CellPrivate * const cp) , richString(cp->richString) , styleNumber(cp->styleNumber) { - } /*! @@ -58,27 +57,27 @@ CellPrivate::CellPrivate(const CellPrivate * const cp) * Created by Worksheet only. */ // qint32 styleIndex = (-1) -Cell::Cell(const QVariant &data, - CellType type, - const Format &format, - Worksheet *parent, - qint32 styleIndex ) : - d_ptr(new CellPrivate(this)) +Cell::Cell(const QVariant &data, + CellType type, + const Format &format, + Worksheet *parent, + qint32 styleIndex) + : d_ptr(new CellPrivate(this)) { - d_ptr->value = data; - d_ptr->cellType = type; - d_ptr->format = format; - d_ptr->parent = parent; - d_ptr->styleNumber = styleIndex; + d_ptr->value = data; + d_ptr->cellType = type; + d_ptr->format = format; + d_ptr->parent = parent; + d_ptr->styleNumber = styleIndex; } /*! * \internal */ -Cell::Cell(const Cell * const cell): - d_ptr(new CellPrivate(cell->d_ptr)) +Cell::Cell(const Cell *const cell) + : d_ptr(new CellPrivate(cell->d_ptr)) { - d_ptr->q_ptr = this; + d_ptr->q_ptr = this; } /*! @@ -86,8 +85,8 @@ Cell::Cell(const Cell * const cell): */ Cell::~Cell() { - if ( NULL != d_ptr ) - delete d_ptr; + if (NULL != d_ptr) + delete d_ptr; } /*! @@ -95,9 +94,9 @@ Cell::~Cell() */ Cell::CellType Cell::cellType() const { - Q_D(const Cell); + Q_D(const Cell); - return d->cellType; + return d->cellType; } /*! @@ -105,72 +104,56 @@ Cell::CellType Cell::cellType() const */ QVariant Cell::value() const { - Q_D(const Cell); + Q_D(const Cell); - return d->value; + return d->value; } /*! -* Return the data content of this Cell for reading -*/ + * Return the data content of this Cell for reading + */ QVariant Cell::readValue() const { - Q_D(const Cell); + Q_D(const Cell); - QVariant ret; // return value - ret = d->value; + QVariant ret; // return value + ret = d->value; - Format fmt = this->format(); + Format fmt = this->format(); - if (isDateTime()) - { + if (isDateTime()) { QVariant vDT = dateTime(); - if ( vDT.isNull() ) - { + if (vDT.isNull()) { return QVariant(); } - // https://github.com/QtExcel/QXlsx/issues/171 - // https://www.qt.io/blog/whats-new-in-qmetatype-qvariant - #if QT_VERSION >= 0x060000 // Qt 6.0 or over - if ( vDT.metaType().id() == QMetaType::QDateTime ) - { - ret = vDT; - } - else if ( vDT.metaType().id() == QMetaType::QDate ) - { - ret = vDT; - } - else if ( vDT.metaType().id() == QMetaType::QTime ) - { - ret = vDT; - } - else - { - return QVariant(); - } - #else - if ( vDT.type() == QVariant::DateTime ) - { - ret = vDT; - } - else if ( vDT.type() == QVariant::Date ) - { - ret = vDT; - } - else if ( vDT.type() == QVariant::Time ) - { - ret = vDT; - } - else - { - return QVariant(); - } - #endif +// https://github.com/QtExcel/QXlsx/issues/171 +// https://www.qt.io/blog/whats-new-in-qmetatype-qvariant +#if QT_VERSION >= 0x060000 // Qt 6.0 or over + if (vDT.metaType().id() == QMetaType::QDateTime) { + ret = vDT; + } else if (vDT.metaType().id() == QMetaType::QDate) { + ret = vDT; + } else if (vDT.metaType().id() == QMetaType::QTime) { + ret = vDT; + } else { + return QVariant(); + } +#else + if (vDT.type() == QVariant::DateTime) { + ret = vDT; + } else if (vDT.type() == QVariant::Date) { + ret = vDT; + } else if (vDT.type() == QVariant::Time) { + ret = vDT; + } else { + return QVariant(); + } +#endif // QDateTime dt = dateTime(); // ret = dt; - + // QString strFormat = fmt.numberFormat(); // if (!strFormat.isEmpty()) // { @@ -185,9 +168,9 @@ QVariant Cell::readValue() const // if (styleNo == 11) // { - // QTime timeValue = dt.time(); // only time. (HH:mm:ss) - // ret = timeValue; - // return ret; + // QTime timeValue = dt.time(); // only time. (HH:mm:ss) + // ret = timeValue; + // return ret; // } // if (styleNo == 12) @@ -196,42 +179,41 @@ QVariant Cell::readValue() const // if (styleNo == 13) // (HH:mm:ss) // { - // double dValue = d->value.toDouble(); - // int day = int(dValue); // unit is day. - // double deciamlPointValue1 = dValue - double(day); + // double dValue = d->value.toDouble(); + // int day = int(dValue); // unit is day. + // double deciamlPointValue1 = dValue - double(day); + + // double dHour = deciamlPointValue1 * (double(1.0) / double(24.0)); + // int hour = int(dHour); - // double dHour = deciamlPointValue1 * (double(1.0) / double(24.0)); - // int hour = int(dHour); + // double deciamlPointValue2 = deciamlPointValue1 - (double(hour) * (double(1.0) / + // double(24.0))); double dMin = deciamlPointValue2 * (double(1.0) / double(60.0)); int min + // = int(dMin); - // double deciamlPointValue2 = deciamlPointValue1 - (double(hour) * (double(1.0) / double(24.0))); - // double dMin = deciamlPointValue2 * (double(1.0) / double(60.0)); - // int min = int(dMin); + // double deciamlPointValue3 = deciamlPointValue2 - (double(min) * (double(1.0) / + // double(60.0))); double dSec = deciamlPointValue3 * (double(1.0) / double(60.0)); int sec + // = int(dSec); - // double deciamlPointValue3 = deciamlPointValue2 - (double(min) * (double(1.0) / double(60.0))); - // double dSec = deciamlPointValue3 * (double(1.0) / double(60.0)); - // int sec = int(dSec); - - // int totalHour = hour + (day * 24); + // int totalHour = hour + (day * 24); - // QString strTime; - // strTime = QString("%1:%2:%3").arg(totalHour).arg(min).arg(sec); - // ret = strTime; + // QString strTime; + // strTime = QString("%1:%2:%3").arg(totalHour).arg(min).arg(sec); + // ret = strTime; - // return ret; + // return ret; // } // return ret; // */ - } + } - if (hasFormula()) - { - QString formulaString = this->formula().formulaText(); - ret = formulaString; - return ret; // return formula string - } + if (hasFormula()) { + QString formulaString = this->formula().formulaText(); + ret = formulaString; + return ret; // return formula string + } - return ret; + return ret; } /*! @@ -239,9 +221,9 @@ QVariant Cell::readValue() const */ Format Cell::format() const { - Q_D(const Cell); + Q_D(const Cell); - return d->format; + return d->format; } /*! @@ -249,9 +231,9 @@ Format Cell::format() const */ bool Cell::hasFormula() const { - Q_D(const Cell); + Q_D(const Cell); - return d->formula.isValid(); + return d->formula.isValid(); } /*! @@ -259,9 +241,9 @@ bool Cell::hasFormula() const */ CellFormula Cell::formula() const { - Q_D(const Cell); + Q_D(const Cell); - return d->formula; + return d->formula; } /*! @@ -269,28 +251,22 @@ CellFormula Cell::formula() const */ bool Cell::isDateTime() const { - Q_D(const Cell); + Q_D(const Cell); - Cell::CellType cellType = d->cellType; - double dValue = d->value.toDouble(); // number -// QString strValue = d->value.toString().toUtf8(); - bool isValidFormat = d->format.isValid(); + Cell::CellType cellType = d->cellType; + double dValue = d->value.toDouble(); // number + // QString strValue = d->value.toString().toUtf8(); + bool isValidFormat = d->format.isValid(); bool isDateTimeFormat = d->format.isDateTimeFormat(); // datetime format // dev67 - if ( cellType == NumberType || - cellType == DateType || - cellType == CustomType ) - { - if ( dValue >= 0 && - isValidFormat && - isDateTimeFormat ) - { + if (cellType == NumberType || cellType == DateType || cellType == CustomType) { + if (dValue >= 0 && isValidFormat && isDateTimeFormat) { return true; } } - return false; + return false; } /*! @@ -299,29 +275,28 @@ bool Cell::isDateTime() const /* QDateTime Cell::dateTime() const { - Q_D(const Cell); + Q_D(const Cell); - if (!isDateTime()) - return QDateTime(); + if (!isDateTime()) + return QDateTime(); - return datetimeFromNumber(d->value.toDouble(), d->parent->workbook()->isDate1904()); + return datetimeFromNumber(d->value.toDouble(), d->parent->workbook()->isDate1904()); } */ QVariant Cell::dateTime() const { Q_D(const Cell); - if (!isDateTime()) - { + if (!isDateTime()) { return QVariant(); } // dev57 QVariant ret; - double dValue = d->value.toDouble(); + double dValue = d->value.toDouble(); bool isDate1904 = d->parent->workbook()->isDate1904(); - ret = datetimeFromNumber(dValue, isDate1904); + ret = datetimeFromNumber(dValue, isDate1904); return ret; } @@ -330,35 +305,30 @@ QVariant Cell::dateTime() const */ bool Cell::isRichString() const { - Q_D(const Cell); + Q_D(const Cell); - if ( d->cellType != SharedStringType && - d->cellType != InlineStringType && - d->cellType != StringType ) - { - return false; + if (d->cellType != SharedStringType && d->cellType != InlineStringType && + d->cellType != StringType) { + return false; } - return d->richString.isRichString(); + return d->richString.isRichString(); } -qint32 Cell::styleNumber() const +qint32 Cell::styleNumber() const { - Q_D(const Cell); + Q_D(const Cell); - qint32 ret = d->styleNumber; - return ret; + qint32 ret = d->styleNumber; + return ret; } bool Cell::isDateType(CellType cellType, const Format &format) { - if ( cellType == NumberType || - cellType == DateType || - cellType == CustomType ) - { + if (cellType == NumberType || cellType == DateType || cellType == CustomType) { return format.isValid() && format.isDateTimeFormat(); } - return false; + return false; } QT_END_NAMESPACE_XLSX diff --git a/QXlsx/source/xlsxcellformula.cpp b/QXlsx/source/xlsxcellformula.cpp index 4b1e2b59..5ac5c9bb 100644 --- a/QXlsx/source/xlsxcellformula.cpp +++ b/QXlsx/source/xlsxcellformula.cpp @@ -1,40 +1,46 @@ // xlsxcellformula.cpp -#include +#include "xlsxcellformula.h" + +#include "xlsxcellformula_p.h" +#include "xlsxutility_p.h" + +#include #include #include #include #include -#include - -#include "xlsxcellformula.h" -#include "xlsxcellformula_p.h" -#include "xlsxutility_p.h" +#include QT_BEGIN_NAMESPACE_XLSX -CellFormulaPrivate::CellFormulaPrivate(const QString &formula_, const CellRange &ref_, CellFormula::FormulaType type_) - :formula(formula_), type(type_), reference(ref_), ca(false), si(0) +CellFormulaPrivate::CellFormulaPrivate(const QString &formula_, + const CellRange &ref_, + CellFormula::FormulaType type_) + : formula(formula_) + , type(type_) + , reference(ref_) + , ca(false) + , si(0) { - //Remove the formula '=' sign if exists + // Remove the formula '=' sign if exists if (formula.startsWith(QLatin1String("="))) - formula.remove(0,1); + formula.remove(0, 1); else if (formula.startsWith(QLatin1String("{=")) && formula.endsWith(QLatin1String("}"))) - formula = formula.mid(2, formula.length()-3); + formula = formula.mid(2, formula.length() - 3); } CellFormulaPrivate::CellFormulaPrivate(const CellFormulaPrivate &other) : QSharedData(other) - , formula(other.formula), type(other.type), reference(other.reference) - , ca(other.ca), si(other.si) + , formula(other.formula) + , type(other.type) + , reference(other.reference) + , ca(other.ca) + , si(other.si) { - } -CellFormulaPrivate::~CellFormulaPrivate() -{ - -} +CellFormulaPrivate::~CellFormulaPrivate() {} /*! \class CellFormula @@ -56,41 +62,38 @@ CellFormulaPrivate::~CellFormulaPrivate() */ CellFormula::CellFormula() { - //The d pointer is initialized with a null pointer + // The d pointer is initialized with a null pointer } /*! * Creates a new formula with the given \a formula and \a type. */ CellFormula::CellFormula(const char *formula, FormulaType type) - :d(new CellFormulaPrivate(QString::fromLatin1(formula), CellRange(), type)) + : d(new CellFormulaPrivate(QString::fromLatin1(formula), CellRange(), type)) { - } /*! * Creates a new formula with the given \a formula and \a type. */ CellFormula::CellFormula(const QString &formula, FormulaType type) - :d(new CellFormulaPrivate(formula, CellRange(), type)) + : d(new CellFormulaPrivate(formula, CellRange(), type)) { - } /*! * Creates a new formula with the given \a formula, \a ref and \a type. */ CellFormula::CellFormula(const QString &formula, const CellRange &ref, FormulaType type) - :d(new CellFormulaPrivate(formula, ref, type)) + : d(new CellFormulaPrivate(formula, ref, type)) { - } /*! Creates a new formula with the same attributes as the \a other formula. */ CellFormula::CellFormula(const CellFormula &other) - :d(other.d) + : d(other.d) { } @@ -98,7 +101,7 @@ CellFormula::CellFormula(const CellFormula &other) Assigns the \a other formula to this formula, and returns a reference to this formula. */ -CellFormula &CellFormula::operator =(const CellFormula &other) +CellFormula &CellFormula::operator=(const CellFormula &other) { d = other.d; return *this; @@ -107,10 +110,7 @@ CellFormula &CellFormula::operator =(const CellFormula &other) /*! * Destroys this formula. */ -CellFormula::~CellFormula() -{ - -} +CellFormula::~CellFormula() {} /*! * Returns the type of the formula. @@ -187,7 +187,7 @@ int CellFormula::sharedIndex() const * * The possible values for this attribute are defined by the W3C XML Schema * boolean datatype. -*/ + */ /* del2 (Input 2 Deleted) // not-impplmented attribute * @@ -257,8 +257,7 @@ bool CellFormula::saveToXml(QXmlStreamWriter &writer) const // shared (Shared Formula) QString t; - switch (d->type) - { + switch (d->type) { case CellFormula::ArrayType: t = QStringLiteral("array"); break; @@ -282,8 +281,7 @@ bool CellFormula::saveToXml(QXmlStreamWriter &writer) const // character node of this element. writer.writeStartElement(QStringLiteral("f")); - if (!t.isEmpty()) - { + if (!t.isEmpty()) { writer.writeAttribute(QStringLiteral("t"), t); // write type(t) } @@ -297,12 +295,9 @@ bool CellFormula::saveToXml(QXmlStreamWriter &writer) const // The possible values for this attribute are defined by the ST_Ref // simple type (§18.18.62). - if ( d->type == CellFormula::SharedType || - d->type == CellFormula::ArrayType || - d->type == CellFormula::DataTableType ) - { - if (d->reference.isValid()) - { + if (d->type == CellFormula::SharedType || d->type == CellFormula::ArrayType || + d->type == CellFormula::DataTableType) { + if (d->reference.isValid()) { writer.writeAttribute(QStringLiteral("ref"), d->reference.toString()); } } @@ -320,8 +315,7 @@ bool CellFormula::saveToXml(QXmlStreamWriter &writer) const // An instance of a datatype that is defined as ·boolean· can have the // following legal literals {true, false, 1, 0}. - if (d->ca) - { + if (d->ca) { writer.writeAttribute(QStringLiteral("ca"), QStringLiteral("1")); } @@ -337,14 +331,12 @@ bool CellFormula::saveToXml(QXmlStreamWriter &writer) const // what the formula expression should be based on the cell's relative // location to the master formula cell. - if (d->type == CellFormula::SharedType) - { + if (d->type == CellFormula::SharedType) { int si = d->si; writer.writeAttribute(QStringLiteral("si"), QString::number(si)); } - if (!d->formula.isEmpty()) - { + if (!d->formula.isEmpty()) { QString strFormula = d->formula; writer.writeCharacters(strFormula); // write formula } @@ -365,23 +357,19 @@ bool CellFormula::loadFromXml(QXmlStreamReader &reader) d = new CellFormulaPrivate(QString(), CellRange(), NormalType); QXmlStreamAttributes attributes = reader.attributes(); - QString typeString = attributes.value(QLatin1String("t")).toString(); + QString typeString = attributes.value(QLatin1String("t")).toString(); // branch: shared-formula // if (typeString == QLatin1String("array")) { d->type = ArrayType; - } - else if (typeString == QLatin1String("shared")) { + } else if (typeString == QLatin1String("shared")) { d->type = SharedType; - } - else if (typeString == QLatin1String("normal")) { + } else if (typeString == QLatin1String("normal")) { d->type = NormalType; - } - else if (typeString == QLatin1String("dataTable")) { + } else if (typeString == QLatin1String("dataTable")) { d->type = DataTableType; - } - else { + } else { /* // undefined type // qDebug() << "Undefined type" << typeString; @@ -399,14 +387,11 @@ bool CellFormula::loadFromXml(QXmlStreamReader &reader) // ref (Range of Cells) // Range of cells which the formula applies to. // Only required for shared formula, array formula or data table. - if ( d->type == CellFormula::SharedType || - d->type == CellFormula::ArrayType || - d->type == CellFormula::DataTableType ) - { - if (attributes.hasAttribute(QLatin1String("ref"))) - { + if (d->type == CellFormula::SharedType || d->type == CellFormula::ArrayType || + d->type == CellFormula::DataTableType) { + if (attributes.hasAttribute(QLatin1String("ref"))) { QString refString = attributes.value(QLatin1String("ref")).toString(); - d->reference = CellRange(refString); + d->reference = CellRange(refString); } } @@ -416,13 +401,11 @@ bool CellFormula::loadFromXml(QXmlStreamReader &reader) // Optional attribute to optimize load performance by sharing formulas. // When a formula is a shared formula (t value is shared) then this value // indicates the group to which this particular cell's formula belongs. - if ( d->type == CellFormula::SharedType ) - { + if (d->type == CellFormula::SharedType) { QString ca = attributes.value(QLatin1String("si")).toString(); - d->ca = parseXsdBoolean(ca, false); + d->ca = parseXsdBoolean(ca, false); - if (attributes.hasAttribute(QLatin1String("si"))) - { + if (attributes.hasAttribute(QLatin1String("si"))) { d->si = attributes.value(QLatin1String("si")).toInt(); } } @@ -435,19 +418,17 @@ bool CellFormula::loadFromXml(QXmlStreamReader &reader) /*! * \internal */ -bool CellFormula::operator ==(const CellFormula &formula) const +bool CellFormula::operator==(const CellFormula &formula) const { - return d->formula == formula.d->formula && d->type == formula.d->type - && d->si ==formula.d->si; + return d->formula == formula.d->formula && d->type == formula.d->type && d->si == formula.d->si; } /*! * \internal */ -bool CellFormula::operator !=(const CellFormula &formula) const +bool CellFormula::operator!=(const CellFormula &formula) const { - return d->formula != formula.d->formula || d->type != formula.d->type - || d->si !=formula.d->si; + return d->formula != formula.d->formula || d->type != formula.d->type || d->si != formula.d->si; } QT_END_NAMESPACE_XLSX diff --git a/QXlsx/source/xlsxcelllocation.cpp b/QXlsx/source/xlsxcelllocation.cpp index c6342fdc..543c7347 100644 --- a/QXlsx/source/xlsxcelllocation.cpp +++ b/QXlsx/source/xlsxcelllocation.cpp @@ -1,14 +1,15 @@ // xlsxcelllocation.cpp -#include +#include "xlsxcelllocation.h" + +#include "xlsxcell.h" +#include "xlsxglobal.h" + +#include #include #include #include -#include - -#include "xlsxglobal.h" -#include "xlsxcell.h" -#include "xlsxcelllocation.h" +#include QT_BEGIN_NAMESPACE_XLSX diff --git a/QXlsx/source/xlsxcellrange.cpp b/QXlsx/source/xlsxcellrange.cpp index 5f544838..63e7b581 100644 --- a/QXlsx/source/xlsxcellrange.cpp +++ b/QXlsx/source/xlsxcellrange.cpp @@ -1,13 +1,14 @@ // xlsxcellrange.cpp -#include -#include -#include -#include - #include "xlsxcellrange.h" + #include "xlsxcellreference.h" +#include +#include +#include +#include + QT_BEGIN_NAMESPACE_XLSX /*! @@ -24,7 +25,10 @@ QT_BEGIN_NAMESPACE_XLSX whose rowCount() and columnCount() are 0. */ CellRange::CellRange() - : top(-1), left(-1), bottom(-2), right(-2) + : top(-1) + , left(-1) + , bottom(-2) + , right(-2) { } @@ -35,13 +39,18 @@ CellRange::CellRange() \sa topRow(), leftColumn(), bottomRow(), rightColumn() */ CellRange::CellRange(int top, int left, int bottom, int right) - : top(top), left(left), bottom(bottom), right(right) + : top(top) + , left(left) + , bottom(bottom) + , right(right) { } CellRange::CellRange(const CellReference &topLeft, const CellReference &bottomRight) - : top(topLeft.row()), left(topLeft.column()) - , bottom(bottomRight.row()), right(bottomRight.column()) + : top(topLeft.row()) + , left(topLeft.column()) + , bottom(bottomRight.row()) + , right(bottomRight.column()) { } @@ -69,16 +78,16 @@ void CellRange::init(const QString &range) if (rs.size() == 2) { CellReference start(rs[0]); CellReference end(rs[1]); - top = start.row(); - left = start.column(); + top = start.row(); + left = start.column(); bottom = end.row(); - right = end.column(); + right = end.column(); } else { CellReference p(rs[0]); - top = p.row(); - left = p.column(); + top = p.row(); + left = p.column(); bottom = p.row(); - right = p.column(); + right = p.column(); } } @@ -87,16 +96,17 @@ void CellRange::init(const QString &range) other range. */ CellRange::CellRange(const CellRange &other) - : top(other.top), left(other.left), bottom(other.bottom), right(other.right) + : top(other.top) + , left(other.left) + , bottom(other.bottom) + , right(other.right) { } /*! Destroys the range. */ -CellRange::~CellRange() -{ -} +CellRange::~CellRange() {} /*! Convert the range to string notation, such as "A1:B5". @@ -107,7 +117,7 @@ QString CellRange::toString(bool row_abs, bool col_abs) const return QString(); if (left == right && top == bottom) { - //Single cell + // Single cell return CellReference(top, left).toString(row_abs, col_abs); } diff --git a/QXlsx/source/xlsxcellreference.cpp b/QXlsx/source/xlsxcellreference.cpp index dc28b724..173b2f53 100644 --- a/QXlsx/source/xlsxcellreference.cpp +++ b/QXlsx/source/xlsxcellreference.cpp @@ -1,10 +1,10 @@ // xlsxcellreference.cpp #include "xlsxcellreference.h" -#include -#include +#include #include +#include QT_BEGIN_NAMESPACE_XLSX @@ -12,12 +12,16 @@ namespace { int intPow(int x, int p) { - if (p == 0) return 1; - if (p == 1) return x; - - int tmp = intPow(x, p/2); - if (p%2 == 0) return tmp * tmp; - else return x * tmp * tmp; + if (p == 0) + return 1; + if (p == 1) + return x; + + int tmp = intPow(x, p / 2); + if (p % 2 == 0) + return tmp * tmp; + else + return x * tmp * tmp; } QString col_to_name(int col_num) @@ -32,7 +36,7 @@ QString col_to_name(int col_num) remainder = col_num % 26; if (remainder == 0) remainder = 26; - col_str.prepend(QChar('A'+remainder-1)); + col_str.prepend(QChar('A' + remainder - 1)); col_num = (col_num - 1) / 26; } it = col_cache.insert(col_num, col_str); @@ -43,16 +47,16 @@ QString col_to_name(int col_num) int col_from_name(const QString &col_str) { - int col = 0; + int col = 0; int expn = 0; - for (int i=col_str.size()-1; i>-1; --i) { + for (int i = col_str.size() - 1; i > -1; --i) { col += (col_str[i].unicode() - 'A' + 1) * intPow(26, expn); expn++; } return col; } -} //namespace +} // namespace /*! \class CellReference @@ -66,7 +70,8 @@ int col_from_name(const QString &col_str) Constructs an invalid Cell Reference */ CellReference::CellReference() - : _row(-1), _column(-1) + : _row(-1) + , _column(-1) { } @@ -74,7 +79,8 @@ CellReference::CellReference() Constructs the Reference from the given \a row, and \a column. */ CellReference::CellReference(int row, int column) - : _row(row), _column(column) + : _row(row) + , _column(column) { } @@ -103,8 +109,8 @@ void CellReference::init(const QString &cell_str) if (match.hasMatch()) { const QString col_str = match.captured(1); const QString row_str = match.captured(2); - _row = row_str.toInt(); - _column = col_from_name(col_str); + _row = row_str.toInt(); + _column = col_from_name(col_str); } } @@ -113,16 +119,15 @@ void CellReference::init(const QString &cell_str) other Reference. */ CellReference::CellReference(const CellReference &other) - : _row(other._row), _column(other._column) + : _row(other._row) + , _column(other._column) { } /*! Destroys the Reference. */ -CellReference::~CellReference() -{ -} +CellReference::~CellReference() {} /*! Convert the Reference to string notation, such as "A1" or "$A$1". diff --git a/QXlsx/source/xlsxchart.cpp b/QXlsx/source/xlsxchart.cpp index c0a0015b..914dfc78 100644 --- a/QXlsx/source/xlsxchart.cpp +++ b/QXlsx/source/xlsxchart.cpp @@ -1,30 +1,26 @@ // xlsxchart.cpp -#include -#include +#include "xlsxcellrange.h" +#include "xlsxchart_p.h" +#include "xlsxutility_p.h" +#include "xlsxworksheet.h" + +#include #include +#include #include #include -#include - -#include "xlsxchart_p.h" -#include "xlsxworksheet.h" -#include "xlsxcellrange.h" -#include "xlsxutility_p.h" +#include QT_BEGIN_NAMESPACE_XLSX ChartPrivate::ChartPrivate(Chart *q, Chart::CreateFlag flag) - : AbstractOOXmlFilePrivate(q, flag), chartType(static_cast(0)) + : AbstractOOXmlFilePrivate(q, flag) + , chartType(static_cast(0)) { - } -ChartPrivate::~ChartPrivate() -{ -} - - +ChartPrivate::~ChartPrivate() {} /*! * \internal @@ -37,8 +33,8 @@ Chart::Chart(AbstractSheet *parent, CreateFlag flag) d_func()->sheet = parent; // d->legendPos = Chart::ChartAxisPos::None; - d->legendPos = Chart::None; - d->legendOverlay = false; + d->legendPos = Chart::None; + d->legendOverlay = false; d->majorGridlinesEnabled = false; d->minorGridlinesEnabled = false; } @@ -46,14 +42,16 @@ Chart::Chart(AbstractSheet *parent, CreateFlag flag) /*! * Destroys the chart. */ -Chart::~Chart() -{ -} +Chart::~Chart() {} /*! * Add the data series which is in the range \a range of the \a sheet. */ -void Chart::addSeries(const CellRange &range, AbstractSheet *sheet, bool headerH, bool headerV, bool swapHeaders) +void Chart::addSeries(const CellRange &range, + AbstractSheet *sheet, + bool headerH, + bool headerV, + bool swapHeaders) { Q_D(Chart); @@ -65,61 +63,54 @@ void Chart::addSeries(const CellRange &range, AbstractSheet *sheet, bool headerH return; QString sheetName = sheet ? sheet->sheetName() : d->sheet->sheetName(); - //In case sheetName contains space or ' + // In case sheetName contains space or ' sheetName = escapeSheetName(sheetName); - if (range.columnCount() == 1 || range.rowCount() == 1) - { + if (range.columnCount() == 1 || range.rowCount() == 1) { auto series = std::make_shared(); - series->numberDataSource_numRef = sheetName + QLatin1String("!") + range.toString(true, true); + series->numberDataSource_numRef = + sheetName + QLatin1String("!") + range.toString(true, true); d->seriesList.append(series); - } - else if ((range.columnCount() < range.rowCount()) || swapHeaders ) - { - //Column based series - int firstDataRow = range.firstRow(); + } else if ((range.columnCount() < range.rowCount()) || swapHeaders) { + // Column based series + int firstDataRow = range.firstRow(); int firstDataColumn = range.firstColumn(); QString axDataSouruce_numRef; - if (d->chartType == CT_ScatterChart || d->chartType == CT_BubbleChart) - { + if (d->chartType == CT_ScatterChart || d->chartType == CT_BubbleChart) { firstDataColumn += 1; - CellRange subRange(range.firstRow(), range.firstColumn(), range.lastRow(), range.firstColumn()); + CellRange subRange( + range.firstRow(), range.firstColumn(), range.lastRow(), range.firstColumn()); axDataSouruce_numRef = sheetName + QLatin1String("!") + subRange.toString(true, true); } - if( headerH ) - { + if (headerH) { firstDataRow += 1; } - if( headerV ) - { + if (headerV) { firstDataColumn += 1; } - for (int col=firstDataColumn; col<=range.lastColumn(); ++col) - { + for (int col = firstDataColumn; col <= range.lastColumn(); ++col) { CellRange subRange(firstDataRow, col, range.lastRow(), col); - auto series = std::make_shared(); + auto series = std::make_shared(); series->axDataSource_numRef = axDataSouruce_numRef; - series->numberDataSource_numRef = sheetName + QLatin1String("!") + subRange.toString(true, true); + series->numberDataSource_numRef = + sheetName + QLatin1String("!") + subRange.toString(true, true); - if( headerH ) - { + if (headerH) { CellRange subRange(range.firstRow(), col, range.firstRow(), col); - series->headerH_numRef = sheetName + QLatin1String("!") + subRange.toString(true, true); - } - else - { + series->headerH_numRef = + sheetName + QLatin1String("!") + subRange.toString(true, true); + } else { series->headerH_numRef = QString(); } - if( headerV ) - { - CellRange subRange(firstDataRow, range.firstColumn(), range.lastRow(), range.firstColumn()); - series->headerV_numRef = sheetName + QLatin1String("!") + subRange.toString(true, true); - } - else - { + if (headerV) { + CellRange subRange( + firstDataRow, range.firstColumn(), range.lastRow(), range.firstColumn()); + series->headerV_numRef = + sheetName + QLatin1String("!") + subRange.toString(true, true); + } else { series->headerV_numRef = QString(); } series->swapHeader = swapHeaders; @@ -127,54 +118,47 @@ void Chart::addSeries(const CellRange &range, AbstractSheet *sheet, bool headerH d->seriesList.append(series); } - } - else - { - //Row based series - int firstDataRow = range.firstRow(); + } else { + // Row based series + int firstDataRow = range.firstRow(); int firstDataColumn = range.firstColumn(); QString axDataSouruce_numRef; - if (d->chartType == CT_ScatterChart || d->chartType == CT_BubbleChart) - { + if (d->chartType == CT_ScatterChart || d->chartType == CT_BubbleChart) { firstDataRow += 1; - CellRange subRange(range.firstRow(), range.firstColumn(), range.firstRow(), range.lastColumn()); + CellRange subRange( + range.firstRow(), range.firstColumn(), range.firstRow(), range.lastColumn()); axDataSouruce_numRef = sheetName + QLatin1String("!") + subRange.toString(true, true); } - if( headerH ) - { + if (headerH) { firstDataRow += 1; } - if( headerV ) - { + if (headerV) { firstDataColumn += 1; } - for (int row=firstDataRow; row<=range.lastRow(); ++row) - { + for (int row = firstDataRow; row <= range.lastRow(); ++row) { CellRange subRange(row, firstDataColumn, row, range.lastColumn()); - auto series = std::make_shared(); + auto series = std::make_shared(); series->axDataSource_numRef = axDataSouruce_numRef; - series->numberDataSource_numRef = sheetName + QLatin1String("!") + subRange.toString(true, true); - - if( headerH ) - { - CellRange subRange(range.firstRow(), firstDataColumn, range.firstRow(), range.lastColumn()); - series->headerH_numRef = sheetName + QLatin1String("!") + subRange.toString(true, true); - } - else - { + series->numberDataSource_numRef = + sheetName + QLatin1String("!") + subRange.toString(true, true); + + if (headerH) { + CellRange subRange( + range.firstRow(), firstDataColumn, range.firstRow(), range.lastColumn()); + series->headerH_numRef = + sheetName + QLatin1String("!") + subRange.toString(true, true); + } else { series->headerH_numRef = QString(); } - if( headerV ) - { + if (headerV) { CellRange subRange(row, range.firstColumn(), row, range.firstColumn()); - series->headerV_numRef = sheetName + QLatin1String("!") + subRange.toString(true, true); - } - else - { + series->headerV_numRef = + sheetName + QLatin1String("!") + subRange.toString(true, true); + } else { series->headerV_numRef = QString(); } series->swapHeader = swapHeaders; @@ -201,34 +185,26 @@ void Chart::setChartType(ChartType type) void Chart::setChartStyle(int id) { Q_UNUSED(id) - //!Todo + //! Todo } void Chart::setAxisTitle(Chart::ChartAxisPos pos, QString axisTitle) { Q_D(Chart); - if ( axisTitle.isEmpty() ) + if (axisTitle.isEmpty()) return; // dev24 : fixed for old compiler - if ( pos == Chart::Left ) - { - d->axisNames[ XlsxAxis::Left ] = axisTitle; - } - else if ( pos == Chart::Top ) - { - d->axisNames[ XlsxAxis::Top ] = axisTitle; - } - else if ( pos == Chart::Right ) - { - d->axisNames[ XlsxAxis::Right ] = axisTitle; + if (pos == Chart::Left) { + d->axisNames[XlsxAxis::Left] = axisTitle; + } else if (pos == Chart::Top) { + d->axisNames[XlsxAxis::Top] = axisTitle; + } else if (pos == Chart::Right) { + d->axisNames[XlsxAxis::Right] = axisTitle; + } else if (pos == Chart::Bottom) { + d->axisNames[XlsxAxis::Bottom] = axisTitle; } - else if ( pos == Chart::Bottom ) - { - d->axisNames[ XlsxAxis::Bottom ] = axisTitle; - } - } // dev25 @@ -239,16 +215,14 @@ void Chart::setChartTitle(QString strchartTitle) d->chartTitle = strchartTitle; } - void Chart::setChartLegend(Chart::ChartAxisPos legendPos, bool overlay) { Q_D(Chart); - d->legendPos = legendPos; + d->legendPos = legendPos; d->legendOverlay = overlay; } - void Chart::setGridlinesEnable(bool majorGridlinesEnable, bool minorGridlinesEnable) { Q_D(Chart); @@ -257,7 +231,6 @@ void Chart::setGridlinesEnable(bool majorGridlinesEnable, bool minorGridlinesEna d->minorGridlinesEnabled = minorGridlinesEnable; } - /*! * \internal */ @@ -303,19 +276,20 @@ void Chart::saveToXmlFile(QIODevice *device) const QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart")); writer.writeAttribute(QStringLiteral("xmlns:a"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/main")); - writer.writeAttribute(QStringLiteral("xmlns:r"), - QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); + writer.writeAttribute( + QStringLiteral("xmlns:r"), + QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); /* - * chart is the root element for the chart. If the chart is a 3D chart, - * then a view3D element is contained, which specifies the 3D view. - * It then has a plot area, which defines a layout and contains an element - * that corresponds to, and defines, the type of chart. - */ + * chart is the root element for the chart. If the chart is a 3D chart, + * then a view3D element is contained, which specifies the 3D view. + * It then has a plot area, which defines a layout and contains an element + * that corresponds to, and defines, the type of chart. + */ d->saveXmlChart(writer); - writer.writeEndElement();// c:chartSpace + writer.writeEndElement(); // c:chartSpace writer.writeEndDocument(); } @@ -327,15 +301,11 @@ bool Chart::loadFromXmlFile(QIODevice *device) Q_D(Chart); QXmlStreamReader reader(device); - while (!reader.atEnd()) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if (reader.tokenType() == QXmlStreamReader::StartElement) - { - if (reader.name() == QLatin1String("chart")) - { - if (!d->loadXmlChart(reader)) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("chart")) { + if (!d->loadXmlChart(reader)) { return false; } } @@ -345,47 +315,36 @@ bool Chart::loadFromXmlFile(QIODevice *device) return true; } - bool ChartPrivate::loadXmlChart(QXmlStreamReader &reader) { Q_ASSERT(reader.name() == QLatin1String("chart")); -// qDebug() << "-------------- loadXmlChart"; + // qDebug() << "-------------- loadXmlChart"; - while (!reader.atEnd()) - { + while (!reader.atEnd()) { reader.readNextStartElement(); -// qDebug() << "-------------1- " << reader.name(); + // qDebug() << "-------------1- " << reader.name(); - if (reader.tokenType() == QXmlStreamReader::StartElement) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { - if (reader.name() == QLatin1String("plotArea")) - { - if (!loadXmlPlotArea(reader)) - { + if (reader.name() == QLatin1String("plotArea")) { + if (!loadXmlPlotArea(reader)) { return false; } - } - else if (reader.name() == QLatin1String("title")) - { - //!Todo + } else if (reader.name() == QLatin1String("title")) { + //! Todo - if ( loadXmlChartTitle(reader) ) - { + if (loadXmlChartTitle(reader)) { } - } -// else if (reader.name() == QLatin1String("legend")) -// { -// loadXmlChartLegend(reader); -// qDebug() << "-------------- loadXmlChartLegend"; -// } - } - else if (reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == QLatin1String("chart") ) - { + // else if (reader.name() == QLatin1String("legend")) + // { + // loadXmlChartLegend(reader); + // qDebug() << "-------------- loadXmlChartLegend"; + // } + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("chart")) { break; } } @@ -428,27 +387,21 @@ bool ChartPrivate::loadXmlPlotArea(QXmlStreamReader &reader) reader.readNext(); - while (!reader.atEnd()) - { -// qDebug() << "-------------2- " << reader.name(); + while (!reader.atEnd()) { + // qDebug() << "-------------2- " << reader.name(); - if (reader.isStartElement()) - { - if (!loadXmlPlotAreaElement(reader)) - { + if (reader.isStartElement()) { + if (!loadXmlPlotAreaElement(reader)) { qDebug() << "[debug] failed to load plotarea element."; return false; - } - else if (reader.name() == QLatin1String("legend")) // Why here? + } else if (reader.name() == QLatin1String("legend")) // Why here? { loadXmlChartLegend(reader); -// qDebug() << "-------------- loadXmlChartLegend"; + // qDebug() << "-------------- loadXmlChartLegend"; } reader.readNext(); - } - else - { + } else { reader.readNext(); } } @@ -458,55 +411,41 @@ bool ChartPrivate::loadXmlPlotArea(QXmlStreamReader &reader) bool ChartPrivate::loadXmlPlotAreaElement(QXmlStreamReader &reader) { - if (reader.name() == QLatin1String("layout")) - { - //!ToDo extract attributes + if (reader.name() == QLatin1String("layout")) { + //! ToDo extract attributes layout = readSubTree(reader); - } - else if (reader.name().endsWith(QLatin1String("Chart"))) - { + } else if (reader.name().endsWith(QLatin1String("Chart"))) { // for pieChart, barChart, ... (choose one) - if ( !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 + } else if (reader.name() == QLatin1String("catAx")) // choose one : catAx, dateAx, serAx, valAx { // qDebug() << "loadXmlAxisCatAx()"; loadXmlAxisCatAx(reader); - } - else if (reader.name() == QLatin1String("dateAx")) // choose one : catAx, dateAx, serAx, valAx + } else if (reader.name() == QLatin1String("dateAx")) // choose one : catAx, dateAx, serAx, valAx { // qDebug() << "loadXmlAxisDateAx()"; loadXmlAxisDateAx(reader); - } - else if (reader.name() == QLatin1String("serAx")) // choose one : catAx, dateAx, serAx, valAx + } else if (reader.name() == QLatin1String("serAx")) // choose one : catAx, dateAx, serAx, valAx { // qDebug() << "loadXmlAxisSerAx()"; loadXmlAxisSerAx(reader); - } - else if (reader.name() == QLatin1String("valAx")) // choose one : catAx, dateAx, serAx, valAx + } else if (reader.name() == QLatin1String("valAx")) // choose one : catAx, dateAx, serAx, valAx { // qDebug() << "loadXmlAxisValAx()"; loadXmlAxisValAx(reader); - } - else if (reader.name() == QLatin1String("dTable")) - { - //!ToDo + } else if (reader.name() == QLatin1String("dTable")) { + //! ToDo // dTable "CT_DTable" // reader.skipCurrentElement(); - } - else if (reader.name() == QLatin1String("spPr")) - { - //!ToDo + } else if (reader.name() == QLatin1String("spPr")) { + //! ToDo // spPr "a:CT_ShapeProperties" // reader.skipCurrentElement(); - } - else if (reader.name() == QLatin1String("extLst")) - { - //!ToDo + } else if (reader.name() == QLatin1String("extLst")) { + //! ToDo // extLst "CT_ExtensionList" // reader.skipCurrentElement(); } @@ -516,115 +455,64 @@ bool ChartPrivate::loadXmlPlotAreaElement(QXmlStreamReader &reader) bool ChartPrivate::loadXmlXxxChart(QXmlStreamReader &reader) { - const auto& name = reader.name(); + const auto &name = reader.name(); - if (name == QLatin1String("areaChart")) - { + if (name == QLatin1String("areaChart")) { chartType = Chart::CT_AreaChart; - } - else if (name == QLatin1String("area3DChart")) - { + } else if (name == QLatin1String("area3DChart")) { chartType = Chart::CT_Area3DChart; - } - else if (name == QLatin1String("lineChart")) - { + } else if (name == QLatin1String("lineChart")) { chartType = Chart::CT_LineChart; - } - else if (name == QLatin1String("line3DChart")) - { + } else if (name == QLatin1String("line3DChart")) { chartType = Chart::CT_Line3DChart; - } - else if (name == QLatin1String("stockChart")) - { + } else if (name == QLatin1String("stockChart")) { chartType = Chart::CT_StockChart; - } - else if (name == QLatin1String("radarChart")) - { + } else if (name == QLatin1String("radarChart")) { chartType = Chart::CT_RadarChart; - } - else if (name == QLatin1String("scatterChart")) - { + } else if (name == QLatin1String("scatterChart")) { chartType = Chart::CT_ScatterChart; - } - else if (name == QLatin1String("pieChart")) - { + } else if (name == QLatin1String("pieChart")) { chartType = Chart::CT_PieChart; - } - else if (name == QLatin1String("pie3DChart")) - { + } else if (name == QLatin1String("pie3DChart")) { chartType = Chart::CT_Pie3DChart; - } - else if (name == QLatin1String("doughnutChart")) - { + } else if (name == QLatin1String("doughnutChart")) { chartType = Chart::CT_DoughnutChart; - } - else if (name == QLatin1String("barChart")) - { + } else if (name == QLatin1String("barChart")) { chartType = Chart::CT_BarChart; - } - else if (name == QLatin1String("bar3DChart")) - { + } else if (name == QLatin1String("bar3DChart")) { chartType = Chart::CT_Bar3DChart; - } - else if (name == QLatin1String("ofPieChart")) - { + } else if (name == QLatin1String("ofPieChart")) { chartType = Chart::CT_OfPieChart; - } - else if (name == QLatin1String("surfaceChart")) - { + } else if (name == QLatin1String("surfaceChart")) { chartType = Chart::CT_SurfaceChart; - } - else if (name == QLatin1String("surface3DChart")) - { + } else if (name == QLatin1String("surface3DChart")) { chartType = Chart::CT_Surface3DChart; - } - else if (name == QLatin1String("bubbleChart")) - { + } else if (name == QLatin1String("bubbleChart")) { chartType = Chart::CT_BubbleChart; - } - else - { + } else { qDebug() << "[undefined chart type] " << name; chartType = Chart::CT_NoStatementChart; return false; } - while( !reader.atEnd() ) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if (reader.tokenType() == QXmlStreamReader::StartElement) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { // dev57 - if ( reader.name() == QLatin1String("ser") ) - { + if (reader.name() == QLatin1String("ser")) { loadXmlSer(reader); - } - else if (reader.name() == QLatin1String("varyColors")) - { - } - else if (reader.name() == QLatin1String("barDir")) - { - } - else if (reader.name() == QLatin1String("axId")) - { + } else if (reader.name() == QLatin1String("varyColors")) { + } else if (reader.name() == QLatin1String("barDir")) { + } else if (reader.name() == QLatin1String("axId")) { // - } - else if (reader.name() == QLatin1String("scatterStyle")) - { - } - else if (reader.name() == QLatin1String("holeSize")) - { - } - else - { + } else if (reader.name() == QLatin1String("scatterStyle")) { + } else if (reader.name() == QLatin1String("holeSize")) { + } else { } - } - else if ( reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == name ) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == name) { break; } } @@ -639,63 +527,40 @@ bool ChartPrivate::loadXmlSer(QXmlStreamReader &reader) auto series = std::make_shared(); seriesList.append(series); - while ( !reader.atEnd() && - !(reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == QLatin1String("ser")) ) - { - if (reader.readNextStartElement()) - { - //TODO beide Header noch auswerten RTR 2019.11 - const auto& name = reader.name(); - if ( name == QLatin1String("tx") ) - { - while ( !reader.atEnd() && - !(reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == name)) - { - if (reader.readNextStartElement()) - { + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("ser"))) { + if (reader.readNextStartElement()) { + // TODO beide Header noch auswerten RTR 2019.11 + const auto &name = reader.name(); + if (name == QLatin1String("tx")) { + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == name)) { + if (reader.readNextStartElement()) { if (reader.name() == QLatin1String("strRef")) series->headerV_numRef = loadXmlStrRef(reader); } } - } - else if ( name == QLatin1String("cat") || - name == QLatin1String("xVal") ) - { - while ( !reader.atEnd() && - !(reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == name)) - { - if (reader.readNextStartElement()) - { + } else if (name == QLatin1String("cat") || name == QLatin1String("xVal")) { + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == name)) { + if (reader.readNextStartElement()) { if (reader.name() == QLatin1String("numRef")) series->axDataSource_numRef = loadXmlNumRef(reader); - else - if (reader.name() == QLatin1String("strRef")) + else if (reader.name() == QLatin1String("strRef")) series->headerH_numRef = loadXmlStrRef(reader); } } - } - else if (name == QLatin1String("val") || name == QLatin1String("yVal")) - { - while ( !reader.atEnd() && - !(reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == name)) - { - if (reader.readNextStartElement()) - { + } else if (name == QLatin1String("val") || name == QLatin1String("yVal")) { + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == name)) { + if (reader.readNextStartElement()) { if (reader.name() == QLatin1String("numRef")) series->numberDataSource_numRef = loadXmlNumRef(reader); } } - } - else if (name == QLatin1String("extLst")) - { - while ( !reader.atEnd() && - !(reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == name)) - { + } else if (name == QLatin1String("extLst")) { + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == name)) { reader.readNextStartElement(); } } @@ -705,16 +570,13 @@ bool ChartPrivate::loadXmlSer(QXmlStreamReader &reader) return true; } - QString ChartPrivate::loadXmlNumRef(QXmlStreamReader &reader) { Q_ASSERT(reader.name() == QLatin1String("numRef")); - while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QLatin1String("numRef"))) - { - if (reader.readNextStartElement()) - { + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("numRef"))) { + if (reader.readNextStartElement()) { if (reader.name() == QLatin1String("f")) return reader.readElementText(); } @@ -723,16 +585,13 @@ QString ChartPrivate::loadXmlNumRef(QXmlStreamReader &reader) return QString(); } - QString ChartPrivate::loadXmlStrRef(QXmlStreamReader &reader) { Q_ASSERT(reader.name() == QLatin1String("strRef")); - while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QLatin1String("strRef"))) - { - if (reader.readNextStartElement()) - { + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("strRef"))) { + if (reader.readNextStartElement()) { if (reader.name() == QLatin1String("f")) return reader.readElementText(); } @@ -741,7 +600,6 @@ QString ChartPrivate::loadXmlStrRef(QXmlStreamReader &reader) return QString(); } - void ChartPrivate::saveXmlChart(QXmlStreamWriter &writer) const { //---------------------------------------------------- @@ -759,35 +617,61 @@ void ChartPrivate::saveXmlChart(QXmlStreamWriter &writer) const writer.writeStartElement(QStringLiteral("c:plotArea")); // a little workaround for Start- and EndElement with starting ">" and ending without ">" - writer.device()->write(">"); //layout + writer.device()->write(">"); // layout writer.device()->write(layout.toUtf8()); - writer.device()->write("write("chartTitle = textValue; + this->chartTitle = textValue; return true; } } @@ -891,11 +765,10 @@ bool ChartPrivate::loadXmlChartTitleTxRichP_R(QXmlStreamReader &reader) return false; } - // write 'chart title' void ChartPrivate::saveXmlChartTitle(QXmlStreamWriter &writer) const { - if ( chartTitle.isEmpty() ) + if (chartTitle.isEmpty()) return; writer.writeStartElement(QStringLiteral("c:title")); @@ -912,277 +785,274 @@ void ChartPrivate::saveXmlChartTitle(QXmlStreamWriter &writer) const */ - writer.writeStartElement(QStringLiteral("c:tx")); - /* - - - - - - - - - */ - - writer.writeStartElement(QStringLiteral("c:rich")); - /* - - - - - - - - */ - - writer.writeEmptyElement(QStringLiteral("a:bodyPr")); // - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - writer.writeEmptyElement(QStringLiteral("a:lstStyle")); // - - writer.writeStartElement(QStringLiteral("a:p")); - /* - - - - - - - - */ - - // - writer.writeStartElement(QStringLiteral("a:pPr")); - - writer.writeAttribute(QStringLiteral("lvl"), QStringLiteral("0")); - - // - writer.writeStartElement(QStringLiteral("a:defRPr")); - - writer.writeAttribute(QStringLiteral("b"), QStringLiteral("0")); - - writer.writeEndElement(); // a:defRPr - - writer.writeEndElement(); // a:pPr - - /* - - - - - - - - */ - - writer.writeStartElement(QStringLiteral("a:r")); - /* - - - - - - - */ - - // chart name - writer.writeTextElement(QStringLiteral("a:t"), chartTitle); - - writer.writeEndElement(); // a:r - - writer.writeEndElement(); // a:p - - writer.writeEndElement(); // c:rich - - writer.writeEndElement(); // c:tx - - // - writer.writeStartElement(QStringLiteral("c:overlay")); - writer.writeAttribute(QStringLiteral("val"), QStringLiteral("0")); - writer.writeEndElement(); // c:overlay - - writer.writeEndElement(); // c:title + writer.writeStartElement(QStringLiteral("c:tx")); + /* + + + + + + + + + */ + + writer.writeStartElement(QStringLiteral("c:rich")); + /* + + + + + + */ + + writer.writeEmptyElement(QStringLiteral("a:bodyPr")); // + /* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */ + + writer.writeEmptyElement(QStringLiteral("a:lstStyle")); // + + writer.writeStartElement(QStringLiteral("a:p")); + /* + + + + + + + */ + + // + writer.writeStartElement(QStringLiteral("a:pPr")); + + writer.writeAttribute(QStringLiteral("lvl"), QStringLiteral("0")); + + // + writer.writeStartElement(QStringLiteral("a:defRPr")); + + writer.writeAttribute(QStringLiteral("b"), QStringLiteral("0")); + + writer.writeEndElement(); // a:defRPr + + writer.writeEndElement(); // a:pPr + + /* + + + + + + + + */ + + writer.writeStartElement(QStringLiteral("a:r")); + /* + + + + + + + */ + + // chart name + writer.writeTextElement(QStringLiteral("a:t"), chartTitle); + + writer.writeEndElement(); // a:r + + writer.writeEndElement(); // a:p + + writer.writeEndElement(); // c:rich + + writer.writeEndElement(); // c:tx + + // + writer.writeStartElement(QStringLiteral("c:overlay")); + writer.writeAttribute(QStringLiteral("val"), QStringLiteral("0")); + writer.writeEndElement(); // c:overlay + + writer.writeEndElement(); // c:title } // }} - // write 'chart legend' void ChartPrivate::saveXmlChartLegend(QXmlStreamWriter &writer) const { - if ( legendPos == Chart::None ) + if (legendPos == Chart::None) return; -// -// -// -// + // + // + // + // writer.writeStartElement(QStringLiteral("c:legend")); - writer.writeStartElement(QStringLiteral("c:legendPos")); + writer.writeStartElement(QStringLiteral("c:legendPos")); - QString pos; - switch( legendPos ) - { - //case Chart::ChartAxisPos::Right: - case Chart::Right : - pos = QStringLiteral("r"); - break; - - // case Chart::ChartAxisPos::Left: - case Chart::Left : - pos = QStringLiteral("l"); - break; - - // case Chart::ChartAxisPos::Top: - case Chart::Top : - pos = QStringLiteral("t"); - break; - - // case Chart::ChartAxisPos::Bottom: - case Chart::Bottom : - pos = QStringLiteral("b"); - break; - - default: - pos = QStringLiteral("r"); - break; - } + QString pos; + switch (legendPos) { + // case Chart::ChartAxisPos::Right: + case Chart::Right: + pos = QStringLiteral("r"); + break; - writer.writeAttribute(QStringLiteral("val"), pos); + // case Chart::ChartAxisPos::Left: + case Chart::Left: + pos = QStringLiteral("l"); + break; - writer.writeEndElement(); // c:legendPos + // case Chart::ChartAxisPos::Top: + case Chart::Top: + pos = QStringLiteral("t"); + break; - writer.writeStartElement(QStringLiteral("c:overlay")); + // case Chart::ChartAxisPos::Bottom: + case Chart::Bottom: + pos = QStringLiteral("b"); + break; - if( legendOverlay ) - { - writer.writeAttribute(QStringLiteral("val"), QStringLiteral("1")); - } - else - { - writer.writeAttribute(QStringLiteral("val"), QStringLiteral("0")); - } + default: + pos = QStringLiteral("r"); + break; + } + + writer.writeAttribute(QStringLiteral("val"), pos); + + writer.writeEndElement(); // c:legendPos + + writer.writeStartElement(QStringLiteral("c:overlay")); + + if (legendOverlay) { + writer.writeAttribute(QStringLiteral("val"), QStringLiteral("1")); + } else { + writer.writeAttribute(QStringLiteral("val"), QStringLiteral("0")); + } - writer.writeEndElement(); // c:overlay + writer.writeEndElement(); // c:overlay writer.writeEndElement(); // c:legend } - void ChartPrivate::saveXmlPieChart(QXmlStreamWriter &writer) const { - QString name = chartType == Chart::CT_PieChart ? QStringLiteral("c:pieChart") : QStringLiteral("c:pie3DChart"); + QString name = chartType == Chart::CT_PieChart ? QStringLiteral("c:pieChart") + : QStringLiteral("c:pie3DChart"); writer.writeStartElement(name); - //Do the same behavior as Excel, Pie prefer varyColors + // Do the same behavior as Excel, Pie prefer varyColors writer.writeEmptyElement(QStringLiteral("c:varyColors")); writer.writeAttribute(QStringLiteral("val"), QStringLiteral("1")); - for (int i=0; i(this)->axisList.append( - std::make_shared( XlsxAxis::T_Cat, XlsxAxis::Bottom, 0, 1, axisNames[XlsxAxis::Bottom] )); + if (axisList.isEmpty()) { + const_cast(this)->axisList.append(std::make_shared( + XlsxAxis::T_Cat, XlsxAxis::Bottom, 0, 1, axisNames[XlsxAxis::Bottom])); - const_cast(this)->axisList.append( - std::make_shared( XlsxAxis::T_Val, XlsxAxis::Left, 1, 0, axisNames[XlsxAxis::Left] )); + const_cast(this)->axisList.append(std::make_shared( + XlsxAxis::T_Val, XlsxAxis::Left, 1, 0, axisNames[XlsxAxis::Left])); } - // Note: Bar3D have 2~3 axes // int axisListSize = axisList.size(); // [dev62] // Q_ASSERT( axisListSize == 2 || // ( axisListSize == 3 && chartType == Chart::CT_Bar3DChart ) ); - for ( int i = 0 ; i < axisList.size() ; ++i ) - { + for (int i = 0; i < axisList.size(); ++i) { writer.writeEmptyElement(QStringLiteral("c:axId")); writer.writeAttribute(QStringLiteral("val"), QString::number(axisList[i]->axisId)); } - writer.writeEndElement(); //barChart, bar3DChart + writer.writeEndElement(); // barChart, bar3DChart } void ChartPrivate::saveXmlLineChart(QXmlStreamWriter &writer) const { - QString name = chartType==Chart::CT_LineChart ? QStringLiteral("c:lineChart") : QStringLiteral("c:line3DChart"); + QString name = chartType == Chart::CT_LineChart ? QStringLiteral("c:lineChart") + : QStringLiteral("c:line3DChart"); writer.writeStartElement(name); // writer.writeEmptyElement(QStringLiteral("grouping")); // dev22 - for (int i=0; i(this)->axisList.append(std::make_shared(XlsxAxis::T_Cat, XlsxAxis::Bottom, 0, 1, axisNames[XlsxAxis::Bottom] )); - const_cast(this)->axisList.append(std::make_shared(XlsxAxis::T_Val, XlsxAxis::Left, 1, 0, axisNames[XlsxAxis::Left] )); - if (chartType==Chart::CT_Line3DChart) - const_cast(this)->axisList.append(std::make_shared(XlsxAxis::T_Ser, XlsxAxis::Bottom, 2, 0)); + if (axisList.isEmpty()) { + const_cast(this)->axisList.append(std::make_shared( + XlsxAxis::T_Cat, XlsxAxis::Bottom, 0, 1, axisNames[XlsxAxis::Bottom])); + const_cast(this)->axisList.append(std::make_shared( + XlsxAxis::T_Val, XlsxAxis::Left, 1, 0, axisNames[XlsxAxis::Left])); + if (chartType == Chart::CT_Line3DChart) + const_cast(this)->axisList.append( + std::make_shared(XlsxAxis::T_Ser, XlsxAxis::Bottom, 2, 0)); } - Q_ASSERT((axisList.size()==2||chartType==Chart::CT_LineChart)|| (axisList.size()==3 && chartType==Chart::CT_Line3DChart)); + Q_ASSERT((axisList.size() == 2 || chartType == Chart::CT_LineChart) || + (axisList.size() == 3 && chartType == Chart::CT_Line3DChart)); - for (int i=0; iaxisId)); } - writer.writeEndElement(); //lineChart, line3DChart + writer.writeEndElement(); // lineChart, line3DChart } void ChartPrivate::saveXmlScatterChart(QXmlStreamWriter &writer) const @@ -1193,56 +1063,55 @@ void ChartPrivate::saveXmlScatterChart(QXmlStreamWriter &writer) const writer.writeEmptyElement(QStringLiteral("c:scatterStyle")); - for (int i=0; i(this)->axisList.append( - std::make_shared(XlsxAxis::T_Val, XlsxAxis::Bottom, 0, 1, axisNames[XlsxAxis::Bottom] )); - const_cast(this)->axisList.append( - std::make_shared(XlsxAxis::T_Val, XlsxAxis::Left, 1, 0, axisNames[XlsxAxis::Left] )); + if (axisList.isEmpty()) { + const_cast(this)->axisList.append(std::make_shared( + XlsxAxis::T_Val, XlsxAxis::Bottom, 0, 1, axisNames[XlsxAxis::Bottom])); + const_cast(this)->axisList.append(std::make_shared( + XlsxAxis::T_Val, XlsxAxis::Left, 1, 0, axisNames[XlsxAxis::Left])); } int axisListSize = axisList.size(); Q_ASSERT(axisListSize == 2); - for (int i=0; iaxisId)); } - writer.writeEndElement(); //c:scatterChart + writer.writeEndElement(); // c:scatterChart } void ChartPrivate::saveXmlAreaChart(QXmlStreamWriter &writer) const { - QString name = chartType==Chart::CT_AreaChart ? QStringLiteral("c:areaChart") : QStringLiteral("c:area3DChart"); + QString name = chartType == Chart::CT_AreaChart ? QStringLiteral("c:areaChart") + : QStringLiteral("c:area3DChart"); writer.writeStartElement(name); // writer.writeEmptyElement(QStringLiteral("grouping")); // dev22 - for (int i=0; i(this)->axisList.append(std::make_shared(XlsxAxis::T_Cat, XlsxAxis::Bottom, 0, 1)); - const_cast(this)->axisList.append(std::make_shared(XlsxAxis::T_Val, XlsxAxis::Left, 1, 0)); + if (axisList.isEmpty()) { + const_cast(this)->axisList.append( + std::make_shared(XlsxAxis::T_Cat, XlsxAxis::Bottom, 0, 1)); + const_cast(this)->axisList.append( + std::make_shared(XlsxAxis::T_Val, XlsxAxis::Left, 1, 0)); } - //Note: Area3D have 2~3 axes - Q_ASSERT(axisList.size()==2 || (axisList.size()==3 && chartType==Chart::CT_Area3DChart)); + // Note: Area3D have 2~3 axes + Q_ASSERT(axisList.size() == 2 || (axisList.size() == 3 && chartType == Chart::CT_Area3DChart)); - for (int i=0; iaxisId)); } - writer.writeEndElement(); //lineChart, line3DChart + writer.writeEndElement(); // lineChart, line3DChart } void ChartPrivate::saveXmlDoughnutChart(QXmlStreamWriter &writer) const @@ -1254,7 +1123,7 @@ void ChartPrivate::saveXmlDoughnutChart(QXmlStreamWriter &writer) const writer.writeEmptyElement(QStringLiteral("c:varyColors")); writer.writeAttribute(QStringLiteral("val"), QStringLiteral("1")); - for (int i=0; iswapHeader ) - { + if (ser->swapHeader) { header1 = ser->headerH_numRef; header2 = ser->headerV_numRef; - } - else - { + } else { header1 = ser->headerV_numRef; header2 = ser->headerH_numRef; } - if( !header1.isEmpty() ) - { + if (!header1.isEmpty()) { writer.writeStartElement(QStringLiteral("c:tx")); writer.writeStartElement(QStringLiteral("c:strRef")); writer.writeTextElement(QStringLiteral("c:f"), header1); writer.writeEndElement(); writer.writeEndElement(); } - if( !header2.isEmpty() ) - { + if (!header2.isEmpty()) { writer.writeStartElement(QStringLiteral("c:cat")); writer.writeStartElement(QStringLiteral("c:strRef")); writer.writeTextElement(QStringLiteral("c:f"), header2); @@ -1321,36 +1185,34 @@ void ChartPrivate::saveXmlSer(QXmlStreamWriter &writer, XlsxSeries *ser, int id) } #endif - if (!ser->numberDataSource_numRef.isEmpty()) - { + if (!ser->numberDataSource_numRef.isEmpty()) { if (chartType == Chart::CT_ScatterChart || chartType == Chart::CT_BubbleChart) writer.writeStartElement(QStringLiteral("c:yVal")); else writer.writeStartElement(QStringLiteral("c:val")); writer.writeStartElement(QStringLiteral("c:numRef")); writer.writeTextElement(QStringLiteral("c:f"), ser->numberDataSource_numRef); - writer.writeEndElement();//c:numRef - writer.writeEndElement();//c:val or c:yVal + writer.writeEndElement(); // c:numRef + writer.writeEndElement(); // c:val or c:yVal } - writer.writeEndElement();//c:ser + writer.writeEndElement(); // c:ser } bool ChartPrivate::loadXmlAxisCatAx(QXmlStreamReader &reader) { - auto axis = std::make_shared(); + auto axis = std::make_shared(); axis->type = XlsxAxis::T_Cat; axisList.append(axis); // load EG_AxShared - if ( ! loadXmlAxisEG_AxShared( reader, axis.get() ) ) - { + if (!loadXmlAxisEG_AxShared(reader, axis.get())) { qDebug() << "failed to load EG_AxShared"; return false; } - //!TODO: load element + //! TODO: load element // auto // lblAlgn // lblOffset @@ -1365,18 +1227,17 @@ bool ChartPrivate::loadXmlAxisCatAx(QXmlStreamReader &reader) bool ChartPrivate::loadXmlAxisDateAx(QXmlStreamReader &reader) { - auto axis = std::make_shared(); + auto axis = std::make_shared(); axis->type = XlsxAxis::T_Date; axisList.append(axis); // load EG_AxShared - if ( ! loadXmlAxisEG_AxShared( reader, axis.get() ) ) - { + if (!loadXmlAxisEG_AxShared(reader, axis.get())) { qDebug() << "failed to load EG_AxShared"; return false; } - //!TODO: load element + //! TODO: load element // auto // lblOffset // baseTimeUnit @@ -1392,18 +1253,17 @@ bool ChartPrivate::loadXmlAxisDateAx(QXmlStreamReader &reader) bool ChartPrivate::loadXmlAxisSerAx(QXmlStreamReader &reader) { - auto axis = std::make_shared(); + auto axis = std::make_shared(); axis->type = XlsxAxis::T_Ser; axisList.append(axis); // load EG_AxShared - if ( ! loadXmlAxisEG_AxShared( reader, axis.get() ) ) - { + if (!loadXmlAxisEG_AxShared(reader, axis.get())) { qDebug() << "failed to load EG_AxShared"; return false; } - //!TODO: load element + //! TODO: load element // tickLblSkip // tickMarkSkip // extLst @@ -1415,17 +1275,16 @@ bool ChartPrivate::loadXmlAxisValAx(QXmlStreamReader &reader) { Q_ASSERT(reader.name() == QLatin1String("valAx")); - auto axis = std::make_shared(); + auto axis = std::make_shared(); axis->type = XlsxAxis::T_Val; axisList.append(axis); - if ( ! loadXmlAxisEG_AxShared( reader, axis.get() ) ) - { + if (!loadXmlAxisEG_AxShared(reader, axis.get())) { qDebug() << "failed to load EG_AxShared"; return false; } - //!TODO: load element + //! TODO: load element // crossBetween // majorUnit // minorUnit @@ -1459,110 +1318,82 @@ bool ChartPrivate::loadXmlAxisValAx(QXmlStreamReader &reader) */ -bool ChartPrivate::loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis* axis) +bool ChartPrivate::loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis *axis) { - Q_ASSERT( NULL != axis ); - Q_ASSERT( reader.name().endsWith(QLatin1String("Ax")) ); + Q_ASSERT(NULL != axis); + Q_ASSERT(reader.name().endsWith(QLatin1String("Ax"))); QString name = reader.name().toString(); // - while ( !reader.atEnd() ) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if ( reader.tokenType() == QXmlStreamReader::StartElement ) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { // qDebug() << "[debug]" << QTime::currentTime() << reader.name().toString(); - if ( reader.name() == QLatin1String("axId") ) // mandatory element + if (reader.name() == QLatin1String("axId")) // mandatory element { // dev57 uint axId = reader.attributes().value(QStringLiteral("val")).toUInt(); // for Qt5.1 axis->axisId = axId; - } - else if ( reader.name() == QLatin1String("scaling") ) - { + } else if (reader.name() == QLatin1String("scaling")) { // mandatory element loadXmlAxisEG_AxShared_Scaling(reader, axis); - } - else if ( reader.name() == QLatin1String("delete") ) - { - //!TODO - } - else if ( reader.name() == QLatin1String("axPos") ) - { + } else if (reader.name() == QLatin1String("delete")) { + //! TODO + } else if (reader.name() == QLatin1String("axPos")) { // mandatory element QString axPosVal = reader.attributes().value(QLatin1String("val")).toString(); - if ( axPosVal == QLatin1String("l") ) { axis->axisPos = XlsxAxis::Left; } - else if ( axPosVal == QLatin1String("r") ) { axis->axisPos = XlsxAxis::Right; } - else if ( axPosVal == QLatin1String("t") ) { axis->axisPos = XlsxAxis::Top; } - else if ( axPosVal == QLatin1String("b") ) { axis->axisPos = XlsxAxis::Bottom; } - } - else if ( reader.name() == QLatin1String("majorGridlines") ) - { - //!TODO anything else? + if (axPosVal == QLatin1String("l")) { + axis->axisPos = XlsxAxis::Left; + } else if (axPosVal == QLatin1String("r")) { + axis->axisPos = XlsxAxis::Right; + } else if (axPosVal == QLatin1String("t")) { + axis->axisPos = XlsxAxis::Top; + } else if (axPosVal == QLatin1String("b")) { + axis->axisPos = XlsxAxis::Bottom; + } + } else if (reader.name() == QLatin1String("majorGridlines")) { + //! TODO anything else? majorGridlinesEnabled = true; - } - else if ( reader.name() == QLatin1String("minorGridlines") ) - { - //!TODO anything else? + } else if (reader.name() == QLatin1String("minorGridlines")) { + //! TODO anything else? minorGridlinesEnabled = true; - } - else if ( reader.name() == QLatin1String("title") ) - { + } else if (reader.name() == QLatin1String("title")) { // title - if ( !loadXmlAxisEG_AxShared_Title(reader, axis) ) - { + 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 + } 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 { // dev57 - uint crossAx = reader.attributes().value(QLatin1String("val")).toUInt(); // for Qt5.1 + uint crossAx = + reader.attributes().value(QLatin1String("val")).toUInt(); // for Qt5.1 axis->crossAx = crossAx; - } - else if ( reader.name() == QLatin1String("crosses") ) - { - //!TODO - } - else if ( reader.name() == QLatin1String("crossesAt") ) - { - //!TODO + } else if (reader.name() == QLatin1String("crosses")) { + //! TODO + } else if (reader.name() == QLatin1String("crossesAt")) { + //! TODO } // reader.readNext(); - } - else if ( reader.tokenType() == QXmlStreamReader::EndElement && - reader.name().toString() == name ) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name().toString() == name) { break; } } @@ -1570,26 +1401,19 @@ bool ChartPrivate::loadXmlAxisEG_AxShared(QXmlStreamReader &reader, XlsxAxis* ax return true; } -bool ChartPrivate::loadXmlAxisEG_AxShared_Scaling(QXmlStreamReader &reader, XlsxAxis* axis) +bool ChartPrivate::loadXmlAxisEG_AxShared_Scaling(QXmlStreamReader &reader, XlsxAxis *axis) { Q_UNUSED(axis); Q_ASSERT(reader.name() == QLatin1String("scaling")); - while ( !reader.atEnd() ) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if ( reader.tokenType() == QXmlStreamReader::StartElement ) - { - if ( reader.name() == QLatin1String("orientation") ) - { - } - else - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("orientation")) { + } else { } - } - else if ( reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == QLatin1String("scaling") ) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("scaling")) { break; } } @@ -1634,31 +1458,22 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Scaling(QXmlStreamReader &reader, Xlsx */ -bool ChartPrivate::loadXmlAxisEG_AxShared_Title(QXmlStreamReader &reader, XlsxAxis* axis) +bool ChartPrivate::loadXmlAxisEG_AxShared_Title(QXmlStreamReader &reader, XlsxAxis *axis) { Q_ASSERT(reader.name() == QLatin1String("title")); - while ( !reader.atEnd() ) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if ( reader.tokenType() == QXmlStreamReader::StartElement ) - { - if ( reader.name() == QLatin1String("tx") ) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("tx")) { loadXmlAxisEG_AxShared_Title_Tx(reader, axis); - } - else if ( reader.name() == QLatin1String("overlay") ) - { - //!TODO: load overlay + } else if (reader.name() == QLatin1String("overlay")) { + //! TODO: load overlay loadXmlAxisEG_AxShared_Title_Overlay(reader, axis); + } else { } - else - { - } - } - else if ( reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == QLatin1String("title") ) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("title")) { break; } } @@ -1666,20 +1481,16 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title(QXmlStreamReader &reader, XlsxAx return true; } -bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Overlay(QXmlStreamReader &reader, XlsxAxis* axis) +bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Overlay(QXmlStreamReader &reader, XlsxAxis *axis) { Q_UNUSED(axis); Q_ASSERT(reader.name() == QLatin1String("overlay")); - while ( !reader.atEnd() ) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if ( reader.tokenType() == QXmlStreamReader::StartElement ) - { - } - else if ( reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == QLatin1String("overlay") ) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("overlay")) { break; } } @@ -1687,26 +1498,19 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Overlay(QXmlStreamReader &reader return true; } -bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx(QXmlStreamReader &reader, XlsxAxis* axis) +bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx(QXmlStreamReader &reader, XlsxAxis *axis) { Q_ASSERT(reader.name() == QLatin1String("tx")); - while ( !reader.atEnd() ) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if ( reader.tokenType() == QXmlStreamReader::StartElement ) - { - if ( reader.name() == QLatin1String("rich") ) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("rich")) { loadXmlAxisEG_AxShared_Title_Tx_Rich(reader, axis); + } else { } - else - { - } - } - else if ( reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == QLatin1String("tx") ) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("tx")) { break; } } @@ -1714,26 +1518,19 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx(QXmlStreamReader &reader, Xls return true; } -bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich(QXmlStreamReader &reader, XlsxAxis* axis) +bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich(QXmlStreamReader &reader, XlsxAxis *axis) { Q_ASSERT(reader.name() == QLatin1String("rich")); - while ( !reader.atEnd() ) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if ( reader.tokenType() == QXmlStreamReader::StartElement ) - { - if ( reader.name() == QLatin1String("p") ) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("p")) { loadXmlAxisEG_AxShared_Title_Tx_Rich_P(reader, axis); + } else { } - else - { - } - } - else if ( reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == QLatin1String("rich") ) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("rich")) { break; } } @@ -1741,31 +1538,21 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich(QXmlStreamReader &reader return true; } -bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P(QXmlStreamReader &reader, XlsxAxis* axis) +bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P(QXmlStreamReader &reader, XlsxAxis *axis) { Q_ASSERT(reader.name() == QLatin1String("p")); - while ( !reader.atEnd() ) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if ( reader.tokenType() == QXmlStreamReader::StartElement ) - { - if ( reader.name() == QLatin1String("r") ) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("r")) { loadXmlAxisEG_AxShared_Title_Tx_Rich_P_R(reader, axis); - } - else if ( reader.name() == QLatin1String("pPr") ) - { + } else if (reader.name() == QLatin1String("pPr")) { loadXmlAxisEG_AxShared_Title_Tx_Rich_P_pPr(reader, axis); + } else { } - else - { - - } - } - else if ( reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == QLatin1String("p") ) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("p")) { break; } } @@ -1773,27 +1560,21 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P(QXmlStreamReader &read return true; } -bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P_pPr(QXmlStreamReader &reader, XlsxAxis* axis) +bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P_pPr(QXmlStreamReader &reader, + XlsxAxis *axis) { Q_UNUSED(axis); Q_ASSERT(reader.name() == QLatin1String("pPr")); - while ( !reader.atEnd() ) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if ( reader.tokenType() == QXmlStreamReader::StartElement ) - { - if ( reader.name() == QLatin1String("defRPr") ) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("defRPr")) { reader.readElementText(); + } else { } - else - { - } - } - else if ( reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == QLatin1String("pPr") ) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("pPr")) { break; } } @@ -1801,28 +1582,22 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P_pPr(QXmlStreamReader & return true; } -bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P_R(QXmlStreamReader &reader, XlsxAxis* axis) +bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P_R(QXmlStreamReader &reader, + XlsxAxis *axis) { Q_ASSERT(reader.name() == QLatin1String("r")); - while ( !reader.atEnd() ) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if ( reader.tokenType() == QXmlStreamReader::StartElement ) - { - if ( reader.name() == QLatin1String("t") ) - { - QString strAxisName = reader.readElementText(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("t")) { + QString strAxisName = reader.readElementText(); XlsxAxis::AxisPos axisPos = axis->axisPos; - axis->axisNames[ axisPos ] = strAxisName; - } - else - { + axis->axisNames[axisPos] = strAxisName; + } else { } - } - else if ( reader.tokenType() == QXmlStreamReader::EndElement && - reader.name() == QLatin1String("r") ) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("r")) { break; } } @@ -1849,8 +1624,8 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P_R(QXmlStreamReader &re - - + @@ -1916,42 +1691,48 @@ bool ChartPrivate::loadXmlAxisEG_AxShared_Title_Tx_Rich_P_R(QXmlStreamReader &re void ChartPrivate::saveXmlAxis(QXmlStreamWriter &writer) const { - for ( int i = 0 ; i < axisList.size() ; ++i ) - { - XlsxAxis* axis = axisList[i].get(); - if ( nullptr == axis ) + for (int i = 0; i < axisList.size(); ++i) { + XlsxAxis *axis = axisList[i].get(); + if (nullptr == axis) continue; - if ( axis->type == XlsxAxis::T_Cat ) { saveXmlAxisCatAx( writer, axis ); } - if ( axis->type == XlsxAxis::T_Val ) { saveXmlAxisValAx( writer, axis ); } - if ( axis->type == XlsxAxis::T_Ser ) { saveXmlAxisSerAx( writer, axis ); } - if ( axis->type == XlsxAxis::T_Date ) { saveXmlAxisDateAx( writer, axis ); } + if (axis->type == XlsxAxis::T_Cat) { + saveXmlAxisCatAx(writer, axis); + } + if (axis->type == XlsxAxis::T_Val) { + saveXmlAxisValAx(writer, axis); + } + if (axis->type == XlsxAxis::T_Ser) { + saveXmlAxisSerAx(writer, axis); + } + if (axis->type == XlsxAxis::T_Date) { + saveXmlAxisDateAx(writer, axis); + } } - } -void ChartPrivate::saveXmlAxisCatAx(QXmlStreamWriter &writer, XlsxAxis* axis) const +void ChartPrivate::saveXmlAxisCatAx(QXmlStreamWriter &writer, XlsxAxis *axis) const { -/* - - - - - - - - - - - - -*/ + /* + + + + + + + + + + + + + */ writer.writeStartElement(QStringLiteral("c:catAx")); saveXmlAxisEG_AxShared(writer, axis); // EG_AxShared - //!TODO: write element + //! TODO: write element // auto // lblAlgn // lblOffset @@ -1963,29 +1744,29 @@ void ChartPrivate::saveXmlAxisCatAx(QXmlStreamWriter &writer, XlsxAxis* axis) co writer.writeEndElement(); // c:catAx } -void ChartPrivate::saveXmlAxisDateAx(QXmlStreamWriter &writer, XlsxAxis* axis) const +void ChartPrivate::saveXmlAxisDateAx(QXmlStreamWriter &writer, XlsxAxis *axis) const { -/* - - - - - - - - - - - - - -*/ + /* + + + + + + + + + + + + + + */ writer.writeStartElement(QStringLiteral("c:dateAx")); saveXmlAxisEG_AxShared(writer, axis); // EG_AxShared - //!TODO: write element + //! TODO: write element // auto // lblOffset // baseTimeUnit @@ -1998,24 +1779,24 @@ void ChartPrivate::saveXmlAxisDateAx(QXmlStreamWriter &writer, XlsxAxis* axis) c writer.writeEndElement(); // c:dateAx } -void ChartPrivate::saveXmlAxisSerAx(QXmlStreamWriter &writer, XlsxAxis* axis) const +void ChartPrivate::saveXmlAxisSerAx(QXmlStreamWriter &writer, XlsxAxis *axis) const { -/* - - - - - - - - -*/ + /* + + + + + + + + + */ writer.writeStartElement(QStringLiteral("c:serAx")); saveXmlAxisEG_AxShared(writer, axis); // EG_AxShared - //!TODO: write element + //! TODO: write element // tickLblSkip // tickMarkSkip // extLst @@ -2023,26 +1804,26 @@ void ChartPrivate::saveXmlAxisSerAx(QXmlStreamWriter &writer, XlsxAxis* axis) co writer.writeEndElement(); // c:serAx } -void ChartPrivate::saveXmlAxisValAx(QXmlStreamWriter &writer, XlsxAxis* axis) const +void ChartPrivate::saveXmlAxisValAx(QXmlStreamWriter &writer, XlsxAxis *axis) const { -/* - - - - - - - - - - -*/ + /* + + + + + + + + + + + */ writer.writeStartElement(QStringLiteral("c:valAx")); saveXmlAxisEG_AxShared(writer, axis); // EG_AxShared - //!TODO: write element + //! TODO: write element // crossBetween // majorUnit // minorUnit @@ -2052,7 +1833,7 @@ void ChartPrivate::saveXmlAxisValAx(QXmlStreamWriter &writer, XlsxAxis* axis) co writer.writeEndElement(); // c:valAx } -void ChartPrivate::saveXmlAxisEG_AxShared(QXmlStreamWriter &writer, XlsxAxis* axis) const +void ChartPrivate::saveXmlAxisEG_AxShared(QXmlStreamWriter &writer, XlsxAxis *axis) const { /* @@ -2063,13 +1844,13 @@ void ChartPrivate::saveXmlAxisEG_AxShared(QXmlStreamWriter &writer, XlsxAxis* ax (*) - (***********************) - - - - - - + + (***********************) (*) @@ -2079,38 +1860,35 @@ void ChartPrivate::saveXmlAxisEG_AxShared(QXmlStreamWriter &writer, XlsxAxis* ax */ - writer.writeEmptyElement(QStringLiteral("c:axId")); // 21.2.2.9. axId (Axis ID) (mandatory value) - writer.writeAttribute(QStringLiteral("val"), QString::number(axis->axisId)); + writer.writeEmptyElement( + QStringLiteral("c:axId")); // 21.2.2.9. axId (Axis ID) (mandatory value) + writer.writeAttribute(QStringLiteral("val"), QString::number(axis->axisId)); - writer.writeStartElement(QStringLiteral("c:scaling")); // CT_Scaling (mandatory value) - writer.writeEmptyElement(QStringLiteral("c:orientation")); // CT_Orientation - writer.writeAttribute(QStringLiteral("val"), QStringLiteral("minMax")); // ST_Orientation - writer.writeEndElement(); // c:scaling + writer.writeStartElement(QStringLiteral("c:scaling")); // CT_Scaling (mandatory value) + writer.writeEmptyElement(QStringLiteral("c:orientation")); // CT_Orientation + writer.writeAttribute(QStringLiteral("val"), QStringLiteral("minMax")); // ST_Orientation + writer.writeEndElement(); // c:scaling writer.writeEmptyElement(QStringLiteral("c:axPos")); // axPos CT_AxPos (mandatory value) - QString pos = GetAxisPosString( axis->axisPos ); - if ( !pos.isEmpty() ) - { - writer.writeAttribute(QStringLiteral("val"), pos); // ST_AxPos - } + QString pos = GetAxisPosString(axis->axisPos); + if (!pos.isEmpty()) { + writer.writeAttribute(QStringLiteral("val"), pos); // ST_AxPos + } - if( majorGridlinesEnabled ) - { + if (majorGridlinesEnabled) { writer.writeEmptyElement(QStringLiteral("c:majorGridlines")); } - if( minorGridlinesEnabled ) - { + if (minorGridlinesEnabled) { writer.writeEmptyElement(QStringLiteral("c:minorGridlines")); } saveXmlAxisEG_AxShared_Title(writer, axis); // "c:title" CT_Title writer.writeEmptyElement(QStringLiteral("c:crossAx")); // crossAx (mandatory value) - writer.writeAttribute(QStringLiteral("val"), QString::number(axis->crossAx)); - + writer.writeAttribute(QStringLiteral("val"), QString::number(axis->crossAx)); } -void ChartPrivate::saveXmlAxisEG_AxShared_Title(QXmlStreamWriter &writer, XlsxAxis* axis) const +void ChartPrivate::saveXmlAxisEG_AxShared_Title(QXmlStreamWriter &writer, XlsxAxis *axis) const { // CT_Title @@ -2158,74 +1936,80 @@ void ChartPrivate::saveXmlAxisEG_AxShared_Title(QXmlStreamWriter &writer, XlsxAx writer.writeStartElement(QStringLiteral("c:title")); // CT_Tx {{ - writer.writeStartElement(QStringLiteral("c:tx")); + writer.writeStartElement(QStringLiteral("c:tx")); - writer.writeStartElement(QStringLiteral("c:rich")); // CT_TextBody + writer.writeStartElement(QStringLiteral("c:rich")); // CT_TextBody - writer.writeEmptyElement(QStringLiteral("a:bodyPr")); // CT_TextBodyProperties + writer.writeEmptyElement(QStringLiteral("a:bodyPr")); // CT_TextBodyProperties - writer.writeEmptyElement(QStringLiteral("a:lstStyle")); // CT_TextListStyle + writer.writeEmptyElement(QStringLiteral("a:lstStyle")); // CT_TextListStyle - writer.writeStartElement(QStringLiteral("a:p")); + writer.writeStartElement(QStringLiteral("a:p")); - writer.writeStartElement(QStringLiteral("a:pPr")); - writer.writeAttribute(QStringLiteral("lvl"), QString::number(0)); + writer.writeStartElement(QStringLiteral("a:pPr")); + writer.writeAttribute(QStringLiteral("lvl"), QString::number(0)); - writer.writeStartElement(QStringLiteral("a:defRPr")); - writer.writeAttribute(QStringLiteral("b"), QString::number(0)); - writer.writeEndElement(); // a:defRPr - writer.writeEndElement(); // a:pPr + writer.writeStartElement(QStringLiteral("a:defRPr")); + writer.writeAttribute(QStringLiteral("b"), QString::number(0)); + writer.writeEndElement(); // a:defRPr + writer.writeEndElement(); // a:pPr - writer.writeStartElement(QStringLiteral("a:r")); - QString strAxisName = GetAxisName(axis); - writer.writeTextElement( QStringLiteral("a:t"), strAxisName ); - writer.writeEndElement(); // a:r + writer.writeStartElement(QStringLiteral("a:r")); + QString strAxisName = GetAxisName(axis); + writer.writeTextElement(QStringLiteral("a:t"), strAxisName); + writer.writeEndElement(); // a:r - writer.writeEndElement(); // a:p + writer.writeEndElement(); // a:p - writer.writeEndElement(); // c:rich + writer.writeEndElement(); // c:rich - writer.writeEndElement(); // c:tx - // CT_Tx }} + writer.writeEndElement(); // c:tx + // CT_Tx }} - writer.writeStartElement(QStringLiteral("c:overlay")); - writer.writeAttribute(QStringLiteral("val"), QString::number(0)); // CT_Boolean - writer.writeEndElement(); // c:overlay + writer.writeStartElement(QStringLiteral("c:overlay")); + writer.writeAttribute(QStringLiteral("val"), QString::number(0)); // CT_Boolean + writer.writeEndElement(); // c:overlay writer.writeEndElement(); // c:title - } -QString ChartPrivate::GetAxisPosString( XlsxAxis::AxisPos axisPos ) const +QString ChartPrivate::GetAxisPosString(XlsxAxis::AxisPos axisPos) const { QString pos; - switch ( axisPos ) - { - case XlsxAxis::Top : pos = QStringLiteral("t"); break; - case XlsxAxis::Bottom : pos = QStringLiteral("b"); break; - case XlsxAxis::Left : pos = QStringLiteral("l"); break; - case XlsxAxis::Right : pos = QStringLiteral("r"); break; - default: break; // ?? + switch (axisPos) { + case XlsxAxis::Top: + pos = QStringLiteral("t"); + break; + case XlsxAxis::Bottom: + pos = QStringLiteral("b"); + break; + case XlsxAxis::Left: + pos = QStringLiteral("l"); + break; + case XlsxAxis::Right: + pos = QStringLiteral("r"); + break; + default: + break; // ?? } return pos; } -QString ChartPrivate::GetAxisName(XlsxAxis* axis) const +QString ChartPrivate::GetAxisName(XlsxAxis *axis) const { QString strAxisName; - if ( NULL == axis ) + if (NULL == axis) return strAxisName; - QString pos = GetAxisPosString( axis->axisPos ); // l, t, r, b - if ( pos.isEmpty() ) + QString pos = GetAxisPosString(axis->axisPos); // l, t, r, b + if (pos.isEmpty()) return strAxisName; - strAxisName = axis->axisNames[ axis->axisPos ]; + strAxisName = axis->axisNames[axis->axisPos]; return strAxisName; } - /// /// \brief ChartPrivate::readSubTree /// \param reader @@ -2235,37 +2019,33 @@ QString ChartPrivate::readSubTree(QXmlStreamReader &reader) { QString treeString; QString prefix; - const auto& treeName = reader.name(); + const auto &treeName = reader.name(); - while (!reader.atEnd()) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if (reader.tokenType() == QXmlStreamReader::StartElement) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { prefix = reader.prefix().toString(); treeString += QLatin1String("<") + reader.qualifiedName().toString(); const QXmlStreamAttributes attributes = reader.attributes(); for (const QXmlStreamAttribute &attr : attributes) { - treeString += QLatin1String(" ") + attr.name().toString() + QLatin1String("=\"") + attr.value().toString() + QLatin1String("\""); + treeString += QLatin1String(" ") + attr.name().toString() + QLatin1String("=\"") + + attr.value().toString() + QLatin1String("\""); } treeString += QStringLiteral(">"); - } - else if (reader.tokenType() == QXmlStreamReader::EndElement ) - { - if( reader.name() == treeName) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement) { + if (reader.name() == treeName) { break; } - treeString += QLatin1String(""); + treeString += + QLatin1String(""); } } return treeString; } - /// /// \brief ChartPrivate::loadXmlChartLegend /// \param reader @@ -2276,53 +2056,34 @@ bool ChartPrivate::loadXmlChartLegend(QXmlStreamReader &reader) Q_ASSERT(reader.name() == QLatin1String("legend")); - while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QLatin1String("legend"))) - { - if (reader.readNextStartElement()) - { + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("legend"))) { + if (reader.readNextStartElement()) { if (reader.name() == QLatin1String("legendPos")) // c:legendPos { QString pos = reader.attributes().value(QLatin1String("val")).toString(); - if( pos.compare(QLatin1String("r"), Qt::CaseInsensitive) == 0) - { + if (pos.compare(QLatin1String("r"), Qt::CaseInsensitive) == 0) { // legendPos = Chart::ChartAxisPos::Right; legendPos = Chart::Right; - } - else - if( pos.compare(QLatin1String("l"), Qt::CaseInsensitive) == 0) - { + } else if (pos.compare(QLatin1String("l"), Qt::CaseInsensitive) == 0) { // legendPos = Chart::ChartAxisPos::Left; legendPos = Chart::Left; - } - else - if( pos.compare(QLatin1String("t"), Qt::CaseInsensitive) == 0) - { + } else if (pos.compare(QLatin1String("t"), Qt::CaseInsensitive) == 0) { // legendPos = Chart::ChartAxisPos::Top; legendPos = Chart::Top; - } - else - if( pos.compare(QLatin1String("b"), Qt::CaseInsensitive) == 0) - { + } else if (pos.compare(QLatin1String("b"), Qt::CaseInsensitive) == 0) { // legendPos = Chart::ChartAxisPos::Bottom; legendPos = Chart::Bottom; - } - else - { + } else { // legendPos = Chart::ChartAxisPos::None; legendPos = Chart::None; } - } - else - if (reader.name() == QLatin1String("overlay")) // c:legendPos + } else if (reader.name() == QLatin1String("overlay")) // c:legendPos { QString pos = reader.attributes().value(QLatin1String("val")).toString(); - if( pos.compare(QLatin1String("1"), Qt::CaseInsensitive) == 0 ) - { + if (pos.compare(QLatin1String("1"), Qt::CaseInsensitive) == 0) { legendOverlay = true; - } - else - { + } else { legendOverlay = false; } } diff --git a/QXlsx/source/xlsxchartsheet.cpp b/QXlsx/source/xlsxchartsheet.cpp index 12fdd79c..0674fa30 100644 --- a/QXlsx/source/xlsxchartsheet.cpp +++ b/QXlsx/source/xlsxchartsheet.cpp @@ -1,29 +1,28 @@ // xlsxchartsheet.cpp -#include -#include -#include -#include - #include "xlsxchartsheet.h" + +#include "xlsxchart.h" #include "xlsxchartsheet_p.h" -#include "xlsxworkbook.h" -#include "xlsxutility_p.h" #include "xlsxdrawing_p.h" #include "xlsxdrawinganchor_p.h" -#include "xlsxchart.h" +#include "xlsxutility_p.h" +#include "xlsxworkbook.h" + +#include +#include +#include +#include QT_BEGIN_NAMESPACE_XLSX ChartsheetPrivate::ChartsheetPrivate(Chartsheet *p, Chartsheet::CreateFlag flag) - : AbstractSheetPrivate(p, flag), chart(0) + : AbstractSheetPrivate(p, flag) + , chart(0) { - } -ChartsheetPrivate::~ChartsheetPrivate() -{ -} +ChartsheetPrivate::~ChartsheetPrivate() {} /*! \class Chartsheet @@ -35,15 +34,15 @@ ChartsheetPrivate::~ChartsheetPrivate() * \internal */ Chartsheet::Chartsheet(const QString &name, int id, Workbook *workbook, CreateFlag flag) - : AbstractSheet( name, id, workbook, new ChartsheetPrivate(this, flag) ) + : AbstractSheet(name, id, workbook, new ChartsheetPrivate(this, flag)) { setSheetType(ST_ChartSheet); - if (flag == Chartsheet::F_NewFromScratch) - { + if (flag == Chartsheet::F_NewFromScratch) { d_func()->drawing = std::make_shared(this, flag); - DrawingAbsoluteAnchor *anchor = new DrawingAbsoluteAnchor(drawing(), DrawingAnchor::Picture); + DrawingAbsoluteAnchor *anchor = + new DrawingAbsoluteAnchor(drawing(), DrawingAnchor::Picture); anchor->pos = QPoint(0, 0); anchor->ext = QSize(9293679, 6068786); @@ -64,7 +63,7 @@ Chartsheet::Chartsheet(const QString &name, int id, Workbook *workbook, CreateFl Chartsheet *Chartsheet::copy(const QString &distName, int distId) const { - //:Todo + //: Todo Q_UNUSED(distName) Q_UNUSED(distId) return 0; @@ -73,9 +72,7 @@ Chartsheet *Chartsheet::copy(const QString &distName, int distId) const /*! * Destroys this workssheet. */ -Chartsheet::~Chartsheet() -{ -} +Chartsheet::~Chartsheet() {} /*! * Returns the chart object of the sheet. @@ -95,23 +92,28 @@ void Chartsheet::saveToXmlFile(QIODevice *device) const QXmlStreamWriter writer(device); writer.writeStartDocument(QStringLiteral("1.0"), true); - writer.writeDefaultNamespace(QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main")); - writer.writeNamespace(QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), QStringLiteral("r")); + writer.writeDefaultNamespace( + QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main")); + writer.writeNamespace( + QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), + QStringLiteral("r")); writer.writeStartElement(QStringLiteral("chartsheet")); writer.writeStartElement(QStringLiteral("sheetViews")); writer.writeEmptyElement(QStringLiteral("sheetView")); writer.writeAttribute(QStringLiteral("workbookViewId"), QString::number(0)); writer.writeAttribute(QStringLiteral("zoomToFit"), QStringLiteral("1")); - writer.writeEndElement(); //sheetViews + writer.writeEndElement(); // sheetViews int idx = d->workbook->drawings().indexOf(d->drawing.get()); - d->relationships->addWorksheetRelationship(QStringLiteral("/drawing"), QStringLiteral("../drawings/drawing%1.xml").arg(idx+1)); + d->relationships->addWorksheetRelationship( + QStringLiteral("/drawing"), QStringLiteral("../drawings/drawing%1.xml").arg(idx + 1)); writer.writeEmptyElement(QStringLiteral("drawing")); - writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(d->relationships->count())); + writer.writeAttribute(QStringLiteral("r:id"), + QStringLiteral("rId%1").arg(d->relationships->count())); - writer.writeEndElement();//chartsheet + writer.writeEndElement(); // chartsheet writer.writeEndDocument(); } @@ -124,11 +126,11 @@ bool Chartsheet::loadFromXmlFile(QIODevice *device) reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("drawing")) { - QString rId = reader.attributes().value(QStringLiteral("r:id")).toString(); + QString rId = reader.attributes().value(QStringLiteral("r:id")).toString(); QString name = d->relationships->getRelationshipById(rId).target; const auto parts = splitPath(filePath()); - QString path = QDir::cleanPath(parts.first() + QLatin1String("/") + name); + QString path = QDir::cleanPath(parts.first() + QLatin1String("/") + name); d->drawing = std::make_shared(this, F_LoadFromExists); d->drawing->setFilePath(path); diff --git a/QXlsx/source/xlsxcolor.cpp b/QXlsx/source/xlsxcolor.cpp index 84512b66..1fee05d4 100644 --- a/QXlsx/source/xlsxcolor.cpp +++ b/QXlsx/source/xlsxcolor.cpp @@ -1,14 +1,14 @@ // xlsxcolor.cpp -#include -#include -#include -#include - #include "xlsxcolor_p.h" #include "xlsxstyles_p.h" #include "xlsxutility_p.h" +#include +#include +#include +#include + QT_BEGIN_NAMESPACE_XLSX XlsxColor::XlsxColor(const QColor &color) @@ -18,15 +18,13 @@ XlsxColor::XlsxColor(const QColor &color) } XlsxColor::XlsxColor(const QString &theme, const QString &tint) - :val(QStringList()<= 0x060000 // Qt 6.0 or over = QMetaType::fromType(); #else - = qMetaTypeId() ; + = qMetaTypeId(); #endif return QVariant(cref, this); } - QColor XlsxColor::fromARGBString(const QString &c) { QColor color; @@ -137,15 +134,15 @@ QString XlsxColor::toARGBString(const QColor &c) QDataStream &operator<<(QDataStream &s, const XlsxColor &color) { if (color.isInvalid()) - s<<0; + s << 0; else if (color.isRgbColor()) - s<<1<>(QDataStream &s, XlsxColor &color) { int marker(4); - s>>marker; + s >> marker; if (marker == 0) { color = XlsxColor(); } else if (marker == 1) { QColor c; - s>>c; + s >> c; color = XlsxColor(c); } else if (marker == 2) { int indexed; - s>>indexed; + s >> indexed; color = XlsxColor(indexed); } else if (marker == 3) { QStringList list; - s>>list; + s >> list; color = XlsxColor(list[0], list[1]); } @@ -192,5 +189,4 @@ QDebug operator<<(QDebug dbg, const XlsxColor &c) #endif - QT_END_NAMESPACE_XLSX diff --git a/QXlsx/source/xlsxconditionalformatting.cpp b/QXlsx/source/xlsxconditionalformatting.cpp index 510cc2c0..04fb5c03 100644 --- a/QXlsx/source/xlsxconditionalformatting.cpp +++ b/QXlsx/source/xlsxconditionalformatting.cpp @@ -1,46 +1,55 @@ // xlsxconditionalformatting.cpp -#include -#include -#include -#include - #include "xlsxconditionalformatting.h" -#include "xlsxconditionalformatting_p.h" -#include "xlsxworksheet.h" + #include "xlsxcellrange.h" +#include "xlsxconditionalformatting_p.h" #include "xlsxstyles_p.h" +#include "xlsxworksheet.h" -QT_BEGIN_NAMESPACE_XLSX +#include +#include +#include +#include -ConditionalFormattingPrivate::ConditionalFormattingPrivate() -{ +QT_BEGIN_NAMESPACE_XLSX -} +ConditionalFormattingPrivate::ConditionalFormattingPrivate() {} -ConditionalFormattingPrivate::ConditionalFormattingPrivate(const ConditionalFormattingPrivate &other) - :QSharedData(other) +ConditionalFormattingPrivate::ConditionalFormattingPrivate( + const ConditionalFormattingPrivate &other) + : QSharedData(other) { - } -ConditionalFormattingPrivate::~ConditionalFormattingPrivate() -{ - -} +ConditionalFormattingPrivate::~ConditionalFormattingPrivate() {} -void ConditionalFormattingPrivate::writeCfVo(QXmlStreamWriter &writer, const XlsxCfVoData &cfvo) const +void ConditionalFormattingPrivate::writeCfVo(QXmlStreamWriter &writer, + const XlsxCfVoData &cfvo) const { writer.writeEmptyElement(QStringLiteral("cfvo")); QString type; - switch(cfvo.type) { - case ConditionalFormatting::VOT_Formula: type=QStringLiteral("formula"); break; - case ConditionalFormatting::VOT_Max: type=QStringLiteral("max"); break; - case ConditionalFormatting::VOT_Min: type=QStringLiteral("min"); break; - case ConditionalFormatting::VOT_Num: type=QStringLiteral("num"); break; - case ConditionalFormatting::VOT_Percent: type=QStringLiteral("percent"); break; - case ConditionalFormatting::VOT_Percentile: type=QStringLiteral("percentile"); break; - default: break; + switch (cfvo.type) { + case ConditionalFormatting::VOT_Formula: + type = QStringLiteral("formula"); + break; + case ConditionalFormatting::VOT_Max: + type = QStringLiteral("max"); + break; + case ConditionalFormatting::VOT_Min: + type = QStringLiteral("min"); + break; + case ConditionalFormatting::VOT_Num: + type = QStringLiteral("num"); + break; + case ConditionalFormatting::VOT_Percent: + type = QStringLiteral("percent"); + break; + case ConditionalFormatting::VOT_Percentile: + type = QStringLiteral("percentile"); + break; + default: + break; } writer.writeAttribute(QStringLiteral("type"), type); writer.writeAttribute(QStringLiteral("val"), cfvo.value); @@ -56,7 +65,6 @@ void ConditionalFormattingPrivate::writeCfVo(QXmlStreamWriter &writer, const Xls * The conditional formatting can be applied to a single cell or ranges of cells. */ - /*! \enum ConditionalFormatting::HighlightRuleType @@ -118,18 +126,16 @@ void ConditionalFormattingPrivate::writeCfVo(QXmlStreamWriter &writer, const Xls Construct a conditional formatting object */ ConditionalFormatting::ConditionalFormatting() - :d(new ConditionalFormattingPrivate()) + : d(new ConditionalFormattingPrivate()) { - } /*! Constructs a copy of \a other. */ ConditionalFormatting::ConditionalFormatting(const ConditionalFormatting &other) - :d(other.d) + : d(other.d) { - } /*! @@ -142,20 +148,21 @@ ConditionalFormatting &ConditionalFormatting::operator=(const ConditionalFormatt return *this; } - /*! * Destroy the object. */ -ConditionalFormatting::~ConditionalFormatting() -{ -} +ConditionalFormatting::~ConditionalFormatting() {} /*! * Add a hightlight rule with the given \a type, \a formula1, \a formula2, * \a format and \a stopIfTrue. * Return false if failed. */ -bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const QString &formula1, const QString &formula2, const Format &format, bool stopIfTrue) +bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, + const QString &formula1, + const QString &formula2, + const Format &format, + bool stopIfTrue) { if (format.isEmpty()) return false; @@ -167,68 +174,90 @@ bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("cellIs"); QString op; switch (type) { - case Highlight_Between: op = QStringLiteral("between"); break; - case Highlight_Equal: op = QStringLiteral("equal"); break; - case Highlight_GreaterThan: op = QStringLiteral("greaterThan"); break; - case Highlight_GreaterThanOrEqual: op = QStringLiteral("greaterThanOrEqual"); break; - case Highlight_LessThan: op = QStringLiteral("lessThan"); break; - case Highlight_LessThanOrEqual: op = QStringLiteral("lessThanOrEqual"); break; - case Highlight_NotBetween: op = QStringLiteral("notBetween"); break; - case Highlight_NotEqual: op = QStringLiteral("notEqual"); break; - default: break; + case Highlight_Between: + op = QStringLiteral("between"); + break; + case Highlight_Equal: + op = QStringLiteral("equal"); + break; + case Highlight_GreaterThan: + op = QStringLiteral("greaterThan"); + break; + case Highlight_GreaterThanOrEqual: + op = QStringLiteral("greaterThanOrEqual"); + break; + case Highlight_LessThan: + op = QStringLiteral("lessThan"); + break; + case Highlight_LessThanOrEqual: + op = QStringLiteral("lessThanOrEqual"); + break; + case Highlight_NotBetween: + op = QStringLiteral("notBetween"); + break; + case Highlight_NotEqual: + op = QStringLiteral("notEqual"); + break; + default: + break; } cfRule->attrs[XlsxCfRuleData::A_operator] = op; } else if (type >= Highlight_ContainsText && type <= Highlight_EndsWith) { if (type == Highlight_ContainsText) { - cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsText"); + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsText"); cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("containsText"); - cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("NOT(ISERROR(SEARCH(\"%1\",%2)))").arg(formula1); + cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = + QStringLiteral("NOT(ISERROR(SEARCH(\"%1\",%2)))").arg(formula1); } else if (type == Highlight_NotContainsText) { - cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsText"); + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsText"); cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("notContains"); - cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("ISERROR(SEARCH(\"%2\",%1))").arg(formula1); + cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = + QStringLiteral("ISERROR(SEARCH(\"%2\",%1))").arg(formula1); } else if (type == Highlight_BeginsWith) { - cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("beginsWith"); + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("beginsWith"); cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("beginsWith"); - cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("LEFT(%2,LEN(\"%1\"))=\"%1\"").arg(formula1); + cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = + QStringLiteral("LEFT(%2,LEN(\"%1\"))=\"%1\"").arg(formula1); } else { - cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("endsWith"); + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("endsWith"); cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("endsWith"); - cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("RIGHT(%2,LEN(\"%1\"))=\"%1\"").arg(formula1); + cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = + QStringLiteral("RIGHT(%2,LEN(\"%1\"))=\"%1\"").arg(formula1); } cfRule->attrs[XlsxCfRuleData::A_text] = formula1; - skipFormula = true; + skipFormula = true; } else if (type == Highlight_TimePeriod) { cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("timePeriod"); - //:Todo + //: Todo return false; } else if (type == Highlight_Duplicate) { cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("duplicateValues"); } else if (type == Highlight_Unique) { cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("uniqueValues"); } else if (type == Highlight_Errors) { - cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsErrors"); + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsErrors"); cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("ISERROR(%1)"); - skipFormula = true; + skipFormula = true; } else if (type == Highlight_NoErrors) { - cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsErrors"); + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsErrors"); cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("NOT(ISERROR(%1))"); - skipFormula = true; + skipFormula = true; } else if (type == Highlight_Blanks) { - cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsBlanks"); + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsBlanks"); cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("LEN(TRIM(%1))=0"); - skipFormula = true; + skipFormula = true; } else if (type == Highlight_NoBlanks) { - cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsBlanks"); + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsBlanks"); cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("LEN(TRIM(%1))>0"); - skipFormula = true; + skipFormula = true; } else if (type >= Highlight_Top && type <= Highlight_BottomPercent) { cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("top10"); if (type == Highlight_Bottom || type == Highlight_BottomPercent) cfRule->attrs[XlsxCfRuleData::A_bottom] = QStringLiteral("1"); if (type == Highlight_TopPercent || type == Highlight_BottomPercent) cfRule->attrs[XlsxCfRuleData::A_percent] = QStringLiteral("1"); - cfRule->attrs[XlsxCfRuleData::A_rank] = !formula1.isEmpty() ? formula1 : QStringLiteral("10"); + cfRule->attrs[XlsxCfRuleData::A_rank] = + !formula1.isEmpty() ? formula1 : QStringLiteral("10"); skipFormula = true; } else if (type >= Highlight_AboveAverage && type <= Highlight_BelowStdDev3) { cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("aboveAverage"); @@ -242,7 +271,7 @@ bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const cfRule->attrs[XlsxCfRuleData::A_stdDev] = QStringLiteral("2"); else if (type == Highlight_AboveStdDev3 || type == Highlight_BelowStdDev3) cfRule->attrs[XlsxCfRuleData::A_stdDev] = QStringLiteral("3"); - } else if (type == Highlight_Expression){ + } else if (type == Highlight_Expression) { cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("expression"); } else { return false; @@ -253,9 +282,11 @@ bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const cfRule->attrs[XlsxCfRuleData::A_stopIfTrue] = true; if (!skipFormula) { if (!formula1.isEmpty()) - cfRule->attrs[XlsxCfRuleData::A_formula1] = formula1.startsWith(QLatin1String("=")) ? formula1.mid(1) : formula1; + cfRule->attrs[XlsxCfRuleData::A_formula1] = + formula1.startsWith(QLatin1String("=")) ? formula1.mid(1) : formula1; if (!formula2.isEmpty()) - cfRule->attrs[XlsxCfRuleData::A_formula2] = formula2.startsWith(QLatin1String("=")) ? formula2.mid(1) : formula2; + cfRule->attrs[XlsxCfRuleData::A_formula2] = + formula2.startsWith(QLatin1String("=")) ? formula2.mid(1) : formula2; } d->cfRules.append(cfRule); return true; @@ -266,10 +297,12 @@ bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const * * Add a hightlight rule with the given \a type \a format and \a stopIfTrue. */ -bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const Format &format, bool stopIfTrue) +bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, + const Format &format, + bool stopIfTrue) { - if ((type >= Highlight_AboveAverage && type <= Highlight_BelowStdDev3) - || (type >= Highlight_Duplicate && type <= Highlight_NoErrors)) { + if ((type >= Highlight_AboveAverage && type <= Highlight_BelowStdDev3) || + (type >= Highlight_Duplicate && type <= Highlight_NoErrors)) { return addHighlightCellsRule(type, QString(), QString(), format, stopIfTrue); } @@ -282,7 +315,10 @@ bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const * Add a hightlight rule with the given \a type, \a formula, \a format and \a stopIfTrue. * Return false if failed. */ -bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const QString &formula, const Format &format, bool stopIfTrue) +bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, + const QString &formula, + const Format &format, + bool stopIfTrue) { if (type == Highlight_Between || type == Highlight_NotBetween) return false; @@ -295,11 +331,17 @@ bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const * , \a type2, \a val2, \a showData and \a stopIfTrue. * Return false if failed. */ -bool ConditionalFormatting::addDataBarRule(const QColor &color, ValueObjectType type1, const QString &val1, ValueObjectType type2, const QString &val2, bool showData, bool stopIfTrue) +bool ConditionalFormatting::addDataBarRule(const QColor &color, + ValueObjectType type1, + const QString &val1, + ValueObjectType type2, + const QString &val2, + bool showData, + bool stopIfTrue) { auto cfRule = std::make_shared(); - cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("dataBar"); + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("dataBar"); cfRule->attrs[XlsxCfRuleData::A_color1] = XlsxColor(color); if (stopIfTrue) cfRule->attrs[XlsxCfRuleData::A_stopIfTrue] = true; @@ -321,23 +363,26 @@ bool ConditionalFormatting::addDataBarRule(const QColor &color, ValueObjectType */ bool ConditionalFormatting::addDataBarRule(const QColor &color, bool showData, bool stopIfTrue) { - return addDataBarRule(color, VOT_Min, QStringLiteral("0"), VOT_Max, QStringLiteral("0"), showData, stopIfTrue); + return addDataBarRule( + color, VOT_Min, QStringLiteral("0"), VOT_Max, QStringLiteral("0"), showData, stopIfTrue); } /*! * Add a colorScale rule with the given \a minColor, \a maxColor and \a stopIfTrue. * Return false if failed. */ -bool ConditionalFormatting::add2ColorScaleRule(const QColor &minColor, const QColor &maxColor, bool stopIfTrue) +bool ConditionalFormatting::add2ColorScaleRule(const QColor &minColor, + const QColor &maxColor, + bool stopIfTrue) { ValueObjectType type1 = VOT_Min; ValueObjectType type2 = VOT_Max; - QString val1 = QStringLiteral("0"); - QString val2 = QStringLiteral("0"); + QString val1 = QStringLiteral("0"); + QString val2 = QStringLiteral("0"); auto cfRule = std::make_shared(); - cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("colorScale"); + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("colorScale"); cfRule->attrs[XlsxCfRuleData::A_color1] = XlsxColor(minColor); cfRule->attrs[XlsxCfRuleData::A_color2] = XlsxColor(maxColor); if (stopIfTrue) @@ -356,18 +401,21 @@ bool ConditionalFormatting::add2ColorScaleRule(const QColor &minColor, const QCo * Add a colorScale rule with the given \a minColor, \a midColor, \a maxColor and \a stopIfTrue. * Return false if failed. */ -bool ConditionalFormatting::add3ColorScaleRule(const QColor &minColor, const QColor &midColor, const QColor &maxColor, bool stopIfTrue) +bool ConditionalFormatting::add3ColorScaleRule(const QColor &minColor, + const QColor &midColor, + const QColor &maxColor, + bool stopIfTrue) { ValueObjectType type1 = VOT_Min; ValueObjectType type2 = VOT_Percent; ValueObjectType type3 = VOT_Max; - QString val1 = QStringLiteral("0"); - QString val2 = QStringLiteral("50"); - QString val3 = QStringLiteral("0"); + QString val1 = QStringLiteral("0"); + QString val2 = QStringLiteral("50"); + QString val3 = QStringLiteral("0"); auto cfRule = std::make_shared(); - cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("colorScale"); + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("colorScale"); cfRule->attrs[XlsxCfRuleData::A_color1] = XlsxColor(minColor); cfRule->attrs[XlsxCfRuleData::A_color2] = XlsxColor(midColor); cfRule->attrs[XlsxCfRuleData::A_color3] = XlsxColor(maxColor); @@ -429,7 +477,9 @@ void ConditionalFormatting::addRange(const CellRange &range) d->ranges.append(range); } -bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, XlsxCfRuleData *rule, Styles *styles) +bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, + XlsxCfRuleData *rule, + Styles *styles) { Q_ASSERT(reader.name() == QLatin1String("cfRule")); QXmlStreamAttributes attrs = reader.attributes(); @@ -444,19 +494,19 @@ bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, XlsxCfRu } rule->priority = attrs.value(QLatin1String("priority")).toInt(); if (attrs.value(QLatin1String("stopIfTrue")) == QLatin1String("1")) { - //default is false + // default is false rule->attrs[XlsxCfRuleData::A_stopIfTrue] = QLatin1String("1"); } if (attrs.value(QLatin1String("aboveAverage")) == QLatin1String("0")) { - //default is true + // default is true rule->attrs[XlsxCfRuleData::A_aboveAverage] = QLatin1String("0"); } if (attrs.value(QLatin1String("percent")) == QLatin1String("1")) { - //default is false + // default is false rule->attrs[XlsxCfRuleData::A_percent] = QLatin1String("1"); } if (attrs.value(QLatin1String("bottom")) == QLatin1String("1")) { - //default is false + // default is false rule->attrs[XlsxCfRuleData::A_bottom] = QLatin1String("1"); } if (attrs.hasAttribute(QLatin1String("operator"))) @@ -466,7 +516,8 @@ bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, XlsxCfRu rule->attrs[XlsxCfRuleData::A_text] = attrs.value(QLatin1String("text")).toString(); if (attrs.hasAttribute(QLatin1String("timePeriod"))) - rule->attrs[XlsxCfRuleData::A_timePeriod] = attrs.value(QLatin1String("timePeriod")).toString(); + rule->attrs[XlsxCfRuleData::A_timePeriod] = + attrs.value(QLatin1String("timePeriod")).toString(); if (attrs.hasAttribute(QLatin1String("rank"))) rule->attrs[XlsxCfRuleData::A_rank] = attrs.value(QLatin1String("rank")).toString(); @@ -475,7 +526,7 @@ bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, XlsxCfRu rule->attrs[XlsxCfRuleData::A_stdDev] = attrs.value(QLatin1String("stdDev")).toString(); if (attrs.value(QLatin1String("equalAverage")) == QLatin1String("1")) { - //default is false + // default is false rule->attrs[XlsxCfRuleData::A_equalAverage] = QLatin1String("1"); } @@ -496,8 +547,8 @@ bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, XlsxCfRu readCfColorScale(reader, rule); } } - if (reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QStringLiteral("conditionalFormatting")) { + if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QStringLiteral("conditionalFormatting")) { break; } } @@ -527,8 +578,8 @@ bool ConditionalFormattingPrivate::readCfDataBar(QXmlStreamReader &reader, XlsxC rule->attrs[XlsxCfRuleData::A_color1] = color; } } - if (reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QStringLiteral("dataBar")) { + if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QStringLiteral("dataBar")) { break; } } @@ -563,8 +614,8 @@ bool ConditionalFormattingPrivate::readCfColorScale(QXmlStreamReader &reader, Xl rule->attrs[XlsxCfRuleData::A_color3] = color; } } - if (reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QStringLiteral("colorScale")) { + if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QStringLiteral("colorScale")) { break; } } @@ -590,13 +641,13 @@ bool ConditionalFormattingPrivate::readCfVo(QXmlStreamReader &reader, XlsxCfVoDa t = ConditionalFormatting::VOT_Num; else if (type == QLatin1String("percent")) t = ConditionalFormatting::VOT_Percent; - else //if (type == QLatin1String("percentile")) + else // if (type == QLatin1String("percentile")) t = ConditionalFormatting::VOT_Percentile; - cfvo.type = t; + cfvo.type = t; cfvo.value = attrs.value(QLatin1String("val")).toString(); if (attrs.value(QLatin1String("gte")) == QLatin1String("0")) { - //default is true + // default is true cfvo.gte = false; } return true; @@ -609,8 +660,8 @@ bool ConditionalFormatting::loadFromXml(QXmlStreamReader &reader, Styles *styles d->ranges.clear(); d->cfRules.clear(); QXmlStreamAttributes attrs = reader.attributes(); - const QString sqref = attrs.value(QLatin1String("sqref")).toString(); - const auto sqrefParts = sqref.split(QLatin1Char(' ')); + const QString sqref = attrs.value(QLatin1String("sqref")).toString(); + const auto sqrefParts = sqref.split(QLatin1Char(' ')); for (const QString &range : sqrefParts) { this->addRange(range); } @@ -624,13 +675,12 @@ bool ConditionalFormatting::loadFromXml(QXmlStreamReader &reader, Styles *styles d->cfRules.append(cfRule); } } - if (reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QStringLiteral("conditionalFormatting")) { + if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QStringLiteral("conditionalFormatting")) { break; } } - return true; } @@ -644,12 +694,14 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const } writer.writeAttribute(QStringLiteral("sqref"), sqref.join(QLatin1String(" "))); - for (int i=0; icfRules.size(); ++i) { + for (int i = 0; i < d->cfRules.size(); ++i) { const std::shared_ptr &rule = d->cfRules[i]; writer.writeStartElement(QStringLiteral("cfRule")); - writer.writeAttribute(QStringLiteral("type"), rule->attrs[XlsxCfRuleData::A_type].toString()); + writer.writeAttribute(QStringLiteral("type"), + rule->attrs[XlsxCfRuleData::A_type].toString()); if (rule->dxfFormat.dxfIndexValid()) - writer.writeAttribute(QStringLiteral("dxfId"), QString::number(rule->dxfFormat.dxfIndex())); + writer.writeAttribute(QStringLiteral("dxfId"), + QString::number(rule->dxfFormat.dxfIndex())); writer.writeAttribute(QStringLiteral("priority"), QString::number(rule->priority)); auto it = rule->attrs.constFind(XlsxCfRuleData::A_stopIfTrue); @@ -699,7 +751,7 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const d->writeCfVo(writer, rule->attrs[XlsxCfRuleData::A_cfvo1].value()); d->writeCfVo(writer, rule->attrs[XlsxCfRuleData::A_cfvo2].value()); rule->attrs[XlsxCfRuleData::A_color1].value().saveToXml(writer); - writer.writeEndElement();//dataBar + writer.writeEndElement(); // dataBar } else if (rule->attrs[XlsxCfRuleData::A_type] == QLatin1String("colorScale")) { writer.writeStartElement(QStringLiteral("colorScale")); d->writeCfVo(writer, rule->attrs[XlsxCfRuleData::A_cfvo1].value()); @@ -716,20 +768,21 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const if (it != rule->attrs.constEnd()) it.value().value().saveToXml(writer); - writer.writeEndElement();//colorScale + writer.writeEndElement(); // colorScale } - it = rule->attrs.constFind(XlsxCfRuleData::A_formula1_temp); if (it != rule->attrs.constEnd()) { const auto _ranges = ranges(); - const auto begin = _ranges.begin(); + const auto begin = _ranges.begin(); if (begin != _ranges.end()) { - QString str = begin->toString(); + QString str = begin->toString(); QString startCell = str.mid(0, str.indexOf(u':')); - writer.writeTextElement(QStringLiteral("formula"), it.value().toString().arg(startCell)); + writer.writeTextElement(QStringLiteral("formula"), + it.value().toString().arg(startCell)); } - } else if ((it = rule->attrs.constFind(XlsxCfRuleData::A_formula1)) != rule->attrs.constEnd()) { + } else if ((it = rule->attrs.constFind(XlsxCfRuleData::A_formula1)) != + rule->attrs.constEnd()) { writer.writeTextElement(QStringLiteral("formula"), it.value().toString()); } @@ -741,10 +794,10 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const if (it != rule->attrs.constEnd()) writer.writeTextElement(QStringLiteral("formula"), it.value().toString()); - writer.writeEndElement(); //cfRule + writer.writeEndElement(); // cfRule } - writer.writeEndElement(); //conditionalFormatting + writer.writeEndElement(); // conditionalFormatting return true; } diff --git a/QXlsx/source/xlsxcontenttypes.cpp b/QXlsx/source/xlsxcontenttypes.cpp index e3dd1677..c6233ddb 100644 --- a/QXlsx/source/xlsxcontenttypes.cpp +++ b/QXlsx/source/xlsxcontenttypes.cpp @@ -1,23 +1,24 @@ // xlsxcontenttypes.cpp -#include -#include -#include -#include +#include "xlsxcontenttypes_p.h" + #include #include - -#include "xlsxcontenttypes_p.h" +#include +#include +#include +#include QT_BEGIN_NAMESPACE_XLSX ContentTypes::ContentTypes(CreateFlag flag) - :AbstractOOXmlFile(flag) + : AbstractOOXmlFile(flag) { - m_package_prefix = QStringLiteral("application/vnd.openxmlformats-package."); + m_package_prefix = QStringLiteral("application/vnd.openxmlformats-package."); m_document_prefix = QStringLiteral("application/vnd.openxmlformats-officedocument."); - m_defaults.insert(QStringLiteral("rels"), m_package_prefix + QLatin1String("relationships+xml")); + m_defaults.insert(QStringLiteral("rels"), + m_package_prefix + QLatin1String("relationships+xml")); m_defaults.insert(QStringLiteral("xml"), QStringLiteral("application/xml")); } @@ -33,67 +34,80 @@ void ContentTypes::addOverride(const QString &key, const QString &value) void ContentTypes::addDocPropApp() { - addOverride(QStringLiteral("/docProps/app.xml"), m_document_prefix + QLatin1String("extended-properties+xml")); + addOverride(QStringLiteral("/docProps/app.xml"), + m_document_prefix + QLatin1String("extended-properties+xml")); } void ContentTypes::addDocPropCore() { - addOverride(QStringLiteral("/docProps/core.xml"), m_package_prefix + QLatin1String("core-properties+xml")); + addOverride(QStringLiteral("/docProps/core.xml"), + m_package_prefix + QLatin1String("core-properties+xml")); } void ContentTypes::addStyles() { - addOverride(QStringLiteral("/xl/styles.xml"), m_document_prefix + QLatin1String("spreadsheetml.styles+xml")); + addOverride(QStringLiteral("/xl/styles.xml"), + m_document_prefix + QLatin1String("spreadsheetml.styles+xml")); } void ContentTypes::addTheme() { - addOverride(QStringLiteral("/xl/theme/theme1.xml"), m_document_prefix + QLatin1String("theme+xml")); + addOverride(QStringLiteral("/xl/theme/theme1.xml"), + m_document_prefix + QLatin1String("theme+xml")); } void ContentTypes::addWorkbook() { - addOverride(QStringLiteral("/xl/workbook.xml"), m_document_prefix + QLatin1String("spreadsheetml.sheet.main+xml")); + addOverride(QStringLiteral("/xl/workbook.xml"), + m_document_prefix + QLatin1String("spreadsheetml.sheet.main+xml")); } void ContentTypes::addWorksheetName(const QString &name) { - addOverride(QStringLiteral("/xl/worksheets/%1.xml").arg(name), m_document_prefix + QLatin1String("spreadsheetml.worksheet+xml")); + addOverride(QStringLiteral("/xl/worksheets/%1.xml").arg(name), + m_document_prefix + QLatin1String("spreadsheetml.worksheet+xml")); } void ContentTypes::addChartsheetName(const QString &name) { - addOverride(QStringLiteral("/xl/chartsheets/%1.xml").arg(name), m_document_prefix + QLatin1String("spreadsheetml.chartsheet+xml")); + addOverride(QStringLiteral("/xl/chartsheets/%1.xml").arg(name), + m_document_prefix + QLatin1String("spreadsheetml.chartsheet+xml")); } void ContentTypes::addDrawingName(const QString &name) { - addOverride(QStringLiteral("/xl/drawings/%1.xml").arg(name), m_document_prefix + QLatin1String("drawing+xml")); + addOverride(QStringLiteral("/xl/drawings/%1.xml").arg(name), + m_document_prefix + QLatin1String("drawing+xml")); } void ContentTypes::addChartName(const QString &name) { - addOverride(QStringLiteral("/xl/charts/%1.xml").arg(name), m_document_prefix + QLatin1String("drawingml.chart+xml")); + addOverride(QStringLiteral("/xl/charts/%1.xml").arg(name), + m_document_prefix + QLatin1String("drawingml.chart+xml")); } void ContentTypes::addCommentName(const QString &name) { - addOverride(QStringLiteral("/xl/%1.xml").arg(name), m_document_prefix + QLatin1String("spreadsheetml.comments+xml")); + addOverride(QStringLiteral("/xl/%1.xml").arg(name), + m_document_prefix + QLatin1String("spreadsheetml.comments+xml")); } void ContentTypes::addTableName(const QString &name) { - addOverride(QStringLiteral("/xl/tables/%1.xml").arg(name), m_document_prefix + QLatin1String("spreadsheetml.table+xml")); + addOverride(QStringLiteral("/xl/tables/%1.xml").arg(name), + m_document_prefix + QLatin1String("spreadsheetml.table+xml")); } void ContentTypes::addExternalLinkName(const QString &name) { - addOverride(QStringLiteral("/xl/externalLinks/%1.xml").arg(name), m_document_prefix + QLatin1String("spreadsheetml.externalLink+xml")); + addOverride(QStringLiteral("/xl/externalLinks/%1.xml").arg(name), + m_document_prefix + QLatin1String("spreadsheetml.externalLink+xml")); } void ContentTypes::addSharedString() { - addOverride(QStringLiteral("/xl/sharedStrings.xml"), m_document_prefix + QLatin1String("spreadsheetml.sharedStrings+xml")); + addOverride(QStringLiteral("/xl/sharedStrings.xml"), + m_document_prefix + QLatin1String("spreadsheetml.sharedStrings+xml")); } void ContentTypes::addVmlName() @@ -103,12 +117,13 @@ void ContentTypes::addVmlName() void ContentTypes::addCalcChain() { - addOverride(QStringLiteral("/xl/calcChain.xml"), m_document_prefix + QLatin1String("spreadsheetml.calcChain+xml")); + addOverride(QStringLiteral("/xl/calcChain.xml"), + m_document_prefix + QLatin1String("spreadsheetml.calcChain+xml")); } void ContentTypes::addVbaProject() { - //:TODO + //: TODO addOverride(QStringLiteral("bin"), QStringLiteral("application/vnd.ms-office.vbaProject")); } @@ -123,33 +138,34 @@ void ContentTypes::saveToXmlFile(QIODevice *device) const writer.writeStartDocument(QStringLiteral("1.0"), true); writer.writeStartElement(QStringLiteral("Types")); - writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/package/2006/content-types")); + writer.writeAttribute( + QStringLiteral("xmlns"), + QStringLiteral("http://schemas.openxmlformats.org/package/2006/content-types")); { - QMapIterator it(m_defaults); - while (it.hasNext()) { - it.next(); - writer.writeStartElement(QStringLiteral("Default")); - writer.writeAttribute(QStringLiteral("Extension"), it.key()); - writer.writeAttribute(QStringLiteral("ContentType"), it.value()); - writer.writeEndElement();//Default - } + QMapIterator it(m_defaults); + while (it.hasNext()) { + it.next(); + writer.writeStartElement(QStringLiteral("Default")); + writer.writeAttribute(QStringLiteral("Extension"), it.key()); + writer.writeAttribute(QStringLiteral("ContentType"), it.value()); + writer.writeEndElement(); // Default + } } { - QMapIterator it(m_overrides); - while (it.hasNext()) { - it.next(); - writer.writeStartElement(QStringLiteral("Override")); - writer.writeAttribute(QStringLiteral("PartName"), it.key()); - writer.writeAttribute(QStringLiteral("ContentType"), it.value()); - writer.writeEndElement(); //Override - } + QMapIterator it(m_overrides); + while (it.hasNext()) { + it.next(); + writer.writeStartElement(QStringLiteral("Override")); + writer.writeAttribute(QStringLiteral("PartName"), it.key()); + writer.writeAttribute(QStringLiteral("ContentType"), it.value()); + writer.writeEndElement(); // Override + } } - writer.writeEndElement();//Types + writer.writeEndElement(); // Types writer.writeEndDocument(); - } bool ContentTypes::loadFromXmlFile(QIODevice *device) @@ -163,19 +179,19 @@ bool ContentTypes::loadFromXmlFile(QIODevice *device) if (token == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("Default")) { QXmlStreamAttributes attrs = reader.attributes(); - QString extension = attrs.value(QLatin1String("Extension")).toString(); - QString type = attrs.value(QLatin1String("ContentType")).toString(); + QString extension = attrs.value(QLatin1String("Extension")).toString(); + QString type = attrs.value(QLatin1String("ContentType")).toString(); m_defaults.insert(extension, type); } else if (reader.name() == QLatin1String("Override")) { QXmlStreamAttributes attrs = reader.attributes(); - QString partName = attrs.value(QLatin1String("PartName")).toString(); - QString type = attrs.value(QLatin1String("ContentType")).toString(); + QString partName = attrs.value(QLatin1String("PartName")).toString(); + QString type = attrs.value(QLatin1String("ContentType")).toString(); m_overrides.insert(partName, type); } } if (reader.hasError()) { - qDebug()< -#include -#include - #include "xlsxdatavalidation.h" + +#include "xlsxcellrange.h" #include "xlsxdatavalidation_p.h" #include "xlsxworksheet.h" -#include "xlsxcellrange.h" + +#include +#include +#include QT_BEGIN_NAMESPACE_XLSX DataValidationPrivate::DataValidationPrivate() - :validationType(DataValidation::None), validationOperator(DataValidation::Between) - , errorStyle(DataValidation::Stop), allowBlank(false), isPromptMessageVisible(true) + : validationType(DataValidation::None) + , validationOperator(DataValidation::Between) + , errorStyle(DataValidation::Stop) + , allowBlank(false) + , isPromptMessageVisible(true) , isErrorMessageVisible(true) { - } -DataValidationPrivate::DataValidationPrivate(DataValidation::ValidationType type, DataValidation::ValidationOperator op, const QString &formula1, const QString &formula2, bool allowBlank) - :validationType(type), validationOperator(op) - , errorStyle(DataValidation::Stop), allowBlank(allowBlank), isPromptMessageVisible(true) - , isErrorMessageVisible(true), formula1(formula1), formula2(formula2) +DataValidationPrivate::DataValidationPrivate(DataValidation::ValidationType type, + DataValidation::ValidationOperator op, + const QString &formula1, + const QString &formula2, + bool allowBlank) + : validationType(type) + , validationOperator(op) + , errorStyle(DataValidation::Stop) + , allowBlank(allowBlank) + , isPromptMessageVisible(true) + , isErrorMessageVisible(true) + , formula1(formula1) + , formula2(formula2) { - } DataValidationPrivate::DataValidationPrivate(const DataValidationPrivate &other) - :QSharedData(other) - , validationType(DataValidation::None), validationOperator(DataValidation::Between) - , errorStyle(DataValidation::Stop), allowBlank(false), isPromptMessageVisible(true) + : QSharedData(other) + , validationType(DataValidation::None) + , validationOperator(DataValidation::Between) + , errorStyle(DataValidation::Stop) + , allowBlank(false) + , isPromptMessageVisible(true) , isErrorMessageVisible(true) { - } -DataValidationPrivate::~DataValidationPrivate() -{ - -} +DataValidationPrivate::~DataValidationPrivate() {} /*! * \class DataValidation @@ -61,7 +71,8 @@ DataValidationPrivate::~DataValidationPrivate() * \value Date restricts the cell to date values. * \value Time restricts the cell to time values. * \value TextLength restricts the cell data based on an integer string length. - * \value Custom restricts the cell based on an external Excel formula that returns a true/false value. + * \value Custom restricts the cell based on an external Excel formula that returns a true/false + * value. */ /*! @@ -95,28 +106,29 @@ DataValidationPrivate::~DataValidationPrivate() * Construct a data validation object with the given \a type, \a op, \a formula1 * \a formula2, and \a allowBlank. */ -DataValidation::DataValidation(ValidationType type, ValidationOperator op, const QString &formula1, const QString &formula2, bool allowBlank) - :d(new DataValidationPrivate(type, op, formula1, formula2, allowBlank)) +DataValidation::DataValidation(ValidationType type, + ValidationOperator op, + const QString &formula1, + const QString &formula2, + bool allowBlank) + : d(new DataValidationPrivate(type, op, formula1, formula2, allowBlank)) { - } /*! Construct a data validation object */ DataValidation::DataValidation() - :d(new DataValidationPrivate()) + : d(new DataValidationPrivate()) { - } /*! Constructs a copy of \a other. */ DataValidation::DataValidation(const DataValidation &other) - :d(other.d) + : d(other.d) { - } /*! @@ -128,13 +140,10 @@ DataValidation &DataValidation::operator=(const DataValidation &other) return *this; } - /*! * Destroy the object. */ -DataValidation::~DataValidation() -{ -} +DataValidation::~DataValidation() {} /*! Returns the validation type. @@ -291,7 +300,7 @@ void DataValidation::setFormula2(const QString &formula) */ void DataValidation::setErrorMessage(const QString &error, const QString &title) { - d->errorMessage = error; + d->errorMessage = error; d->errorMessageTitle = title; } @@ -300,7 +309,7 @@ void DataValidation::setErrorMessage(const QString &error, const QString &title) */ void DataValidation::setPromptMessage(const QString &prompt, const QString &title) { - d->promptMessage = prompt; + d->promptMessage = prompt; d->promptMessageTitle = title; } @@ -376,8 +385,7 @@ bool DataValidation::saveToXml(QXmlStreamWriter &writer) const {DataValidation::Date, QStringLiteral("date")}, {DataValidation::Time, QStringLiteral("time")}, {DataValidation::TextLength, QStringLiteral("textLength")}, - {DataValidation::Custom, QStringLiteral("custom")} - }; + {DataValidation::Custom, QStringLiteral("custom")}}; static const QMap opMap = { {DataValidation::Between, QStringLiteral("between")}, @@ -387,14 +395,12 @@ bool DataValidation::saveToXml(QXmlStreamWriter &writer) const {DataValidation::LessThan, QStringLiteral("lessThan")}, {DataValidation::LessThanOrEqual, QStringLiteral("lessThanOrEqual")}, {DataValidation::GreaterThan, QStringLiteral("greaterThan")}, - {DataValidation::GreaterThanOrEqual, QStringLiteral("greaterThanOrEqual")} - }; + {DataValidation::GreaterThanOrEqual, QStringLiteral("greaterThanOrEqual")}}; static const QMap esMap = { {DataValidation::Stop, QStringLiteral("stop")}, {DataValidation::Warning, QStringLiteral("warning")}, - {DataValidation::Information, QStringLiteral("information")} - }; + {DataValidation::Information, QStringLiteral("information")}}; writer.writeStartElement(QStringLiteral("dataValidation")); if (validationType() != DataValidation::None) @@ -431,7 +437,7 @@ bool DataValidation::saveToXml(QXmlStreamWriter &writer) const if (!formula2().isEmpty()) writer.writeTextElement(QStringLiteral("formula2"), formula2()); - writer.writeEndElement(); //dataValidation + writer.writeEndElement(); // dataValidation return true; } @@ -451,8 +457,7 @@ DataValidation DataValidation::loadFromXml(QXmlStreamReader &reader) {QStringLiteral("date"), DataValidation::Date}, {QStringLiteral("time"), DataValidation::Time}, {QStringLiteral("textLength"), DataValidation::TextLength}, - {QStringLiteral("custom"), DataValidation::Custom} - }; + {QStringLiteral("custom"), DataValidation::Custom}}; static const QMap opMap = { {QStringLiteral("between"), DataValidation::Between}, @@ -462,37 +467,36 @@ DataValidation DataValidation::loadFromXml(QXmlStreamReader &reader) {QStringLiteral("lessThan"), DataValidation::LessThan}, {QStringLiteral("lessThanOrEqual"), DataValidation::LessThanOrEqual}, {QStringLiteral("greaterThan"), DataValidation::GreaterThan}, - {QStringLiteral("greaterThanOrEqual"), DataValidation::GreaterThanOrEqual} - }; + {QStringLiteral("greaterThanOrEqual"), DataValidation::GreaterThanOrEqual}}; static const QMap esMap = { {QStringLiteral("stop"), DataValidation::Stop}, {QStringLiteral("warning"), DataValidation::Warning}, - {QStringLiteral("information"), DataValidation::Information} - }; + {QStringLiteral("information"), DataValidation::Information}}; DataValidation validation; QXmlStreamAttributes attrs = reader.attributes(); - QString sqref = attrs.value(QLatin1String("sqref")).toString(); + QString sqref = attrs.value(QLatin1String("sqref")).toString(); const auto sqrefParts = sqref.split(QLatin1Char(' ')); for (const QString &range : sqrefParts) validation.addRange(range); if (attrs.hasAttribute(QLatin1String("type"))) { QString t = attrs.value(QLatin1String("type")).toString(); - auto it = typeMap.constFind(t); + auto it = typeMap.constFind(t); validation.setValidationType(it != typeMap.constEnd() ? it.value() : DataValidation::None); } if (attrs.hasAttribute(QLatin1String("errorStyle"))) { QString es = attrs.value(QLatin1String("errorStyle")).toString(); - auto it = esMap.constFind(es); + auto it = esMap.constFind(es); validation.setErrorStyle(it != esMap.constEnd() ? it.value() : DataValidation::Stop); } if (attrs.hasAttribute(QLatin1String("operator"))) { QString op = attrs.value(QLatin1String("operator")).toString(); - auto it = opMap.constFind(op); - validation.setValidationOperator(it != opMap.constEnd() ? it.value() : DataValidation::Between); + auto it = opMap.constFind(op); + validation.setValidationOperator(it != opMap.constEnd() ? it.value() + : DataValidation::Between); } if (attrs.hasAttribute(QLatin1String("allowBlank"))) { validation.setAllowBlank(true); @@ -511,17 +515,18 @@ DataValidation DataValidation::loadFromXml(QXmlStreamReader &reader) } QString et = attrs.value(QLatin1String("errorTitle")).toString(); - QString e = attrs.value(QLatin1String("error")).toString(); + QString e = attrs.value(QLatin1String("error")).toString(); if (!e.isEmpty() || !et.isEmpty()) validation.setErrorMessage(e, et); QString pt = attrs.value(QLatin1String("promptTitle")).toString(); - QString p = attrs.value(QLatin1String("prompt")).toString(); + QString p = attrs.value(QLatin1String("prompt")).toString(); if (!p.isEmpty() || !pt.isEmpty()) validation.setPromptMessage(p, pt); - //find the end - while(!(reader.name() == QLatin1String("dataValidation") && reader.tokenType() == QXmlStreamReader::EndElement)) { + // find the end + while (!(reader.name() == QLatin1String("dataValidation") && + reader.tokenType() == QXmlStreamReader::EndElement)) { reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("formula1")) { diff --git a/QXlsx/source/xlsxdatetype.cpp b/QXlsx/source/xlsxdatetype.cpp index 6486b6a9..20a804f6 100644 --- a/QXlsx/source/xlsxdatetype.cpp +++ b/QXlsx/source/xlsxdatetype.cpp @@ -1,16 +1,15 @@ // xlsxdatetype.cpp -#include +#include "xlsxdatetype.h" #include "xlsxglobal.h" #include "xlsxutility_p.h" -#include "xlsxdatetype.h" + +#include QT_BEGIN_NAMESPACE_XLSX -DateType::DateType() -{ -} +DateType::DateType() {} /* DateType::DateType(bool is1904) diff --git a/QXlsx/source/xlsxdocpropsapp.cpp b/QXlsx/source/xlsxdocpropsapp.cpp index 01d40a15..9b828602 100644 --- a/QXlsx/source/xlsxdocpropsapp.cpp +++ b/QXlsx/source/xlsxdocpropsapp.cpp @@ -2,18 +2,18 @@ #include "xlsxdocpropsapp_p.h" -#include -#include +#include +#include #include #include -#include #include -#include +#include +#include QT_BEGIN_NAMESPACE_XLSX DocPropsApp::DocPropsApp(CreateFlag flag) - :AbstractOOXmlFile(flag) + : AbstractOOXmlFile(flag) { } @@ -24,14 +24,12 @@ void DocPropsApp::addPartTitle(const QString &title) void DocPropsApp::addHeadingPair(const QString &name, int value) { - m_headingPairsList.append({ name, value }); + m_headingPairsList.append({name, value}); } bool DocPropsApp::setProperty(const QString &name, const QString &value) { - static const QStringList validKeys = { - QStringLiteral("manager"), QStringLiteral("company") - }; + static const QStringList validKeys = {QStringLiteral("manager"), QStringLiteral("company")}; if (!validKeys.contains(name)) return false; @@ -61,11 +59,13 @@ QStringList DocPropsApp::propertyNames() const void DocPropsApp::saveToXmlFile(QIODevice *device) const { QXmlStreamWriter writer(device); - QString vt = QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"); + QString vt = + QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"); writer.writeStartDocument(QStringLiteral("1.0"), true); writer.writeStartElement(QStringLiteral("Properties")); - writer.writeDefaultNamespace(QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties")); + writer.writeDefaultNamespace(QStringLiteral( + "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties")); writer.writeNamespace(vt, QStringLiteral("vt")); writer.writeTextElement(QStringLiteral("Application"), QStringLiteral("Microsoft Excel")); writer.writeTextElement(QStringLiteral("DocSecurity"), QStringLiteral("0")); @@ -73,19 +73,19 @@ void DocPropsApp::saveToXmlFile(QIODevice *device) const writer.writeStartElement(QStringLiteral("HeadingPairs")); writer.writeStartElement(vt, QStringLiteral("vector")); - writer.writeAttribute(QStringLiteral("size"), QString::number(m_headingPairsList.size()*2)); + writer.writeAttribute(QStringLiteral("size"), QString::number(m_headingPairsList.size() * 2)); writer.writeAttribute(QStringLiteral("baseType"), QStringLiteral("variant")); for (const auto &pair : m_headingPairsList) { writer.writeStartElement(vt, QStringLiteral("variant")); writer.writeTextElement(vt, QStringLiteral("lpstr"), pair.first); - writer.writeEndElement(); //vt:variant + writer.writeEndElement(); // vt:variant writer.writeStartElement(vt, QStringLiteral("variant")); writer.writeTextElement(vt, QStringLiteral("i4"), QString::number(pair.second)); - writer.writeEndElement(); //vt:variant + writer.writeEndElement(); // vt:variant } - writer.writeEndElement();//vt:vector - writer.writeEndElement();//HeadingPairs + writer.writeEndElement(); // vt:vector + writer.writeEndElement(); // HeadingPairs writer.writeStartElement(QStringLiteral("TitlesOfParts")); writer.writeStartElement(vt, QStringLiteral("vector")); @@ -93,22 +93,23 @@ void DocPropsApp::saveToXmlFile(QIODevice *device) const writer.writeAttribute(QStringLiteral("baseType"), QStringLiteral("lpstr")); for (const QString &title : m_titlesOfPartsList) writer.writeTextElement(vt, QStringLiteral("lpstr"), title); - writer.writeEndElement();//vt:vector - writer.writeEndElement();//TitlesOfParts + writer.writeEndElement(); // vt:vector + writer.writeEndElement(); // TitlesOfParts auto it = m_properties.constFind(QStringLiteral("manager")); if (it != m_properties.constEnd()) writer.writeTextElement(QStringLiteral("Manager"), it.value()); - //Not like "manager", "company" always exists for Excel generated file. + // Not like "manager", "company" always exists for Excel generated file. it = m_properties.constFind(QStringLiteral("company")); - writer.writeTextElement(QStringLiteral("Company"), it != m_properties.constEnd() ? it.value() : QString()); + writer.writeTextElement(QStringLiteral("Company"), + it != m_properties.constEnd() ? it.value() : QString()); writer.writeTextElement(QStringLiteral("LinksUpToDate"), QStringLiteral("false")); writer.writeTextElement(QStringLiteral("SharedDoc"), QStringLiteral("false")); writer.writeTextElement(QStringLiteral("HyperlinksChanged"), QStringLiteral("false")); writer.writeTextElement(QStringLiteral("AppVersion"), QStringLiteral("12.0000")); - writer.writeEndElement(); //Properties + writer.writeEndElement(); // Properties writer.writeEndDocument(); } @@ -116,21 +117,21 @@ bool DocPropsApp::loadFromXmlFile(QIODevice *device) { QXmlStreamReader reader(device); while (!reader.atEnd()) { - QXmlStreamReader::TokenType token = reader.readNext(); - if (token == QXmlStreamReader::StartElement) { - if (reader.name() == QLatin1String("Properties")) - continue; - - if (reader.name() == QStringLiteral("Manager")) { - setProperty(QStringLiteral("manager"), reader.readElementText()); - } else if (reader.name() == QStringLiteral("Company")) { - setProperty(QStringLiteral("company"), reader.readElementText()); - } - } - - if (reader.hasError()) { - qDebug("Error when read doc props app file."); - } + QXmlStreamReader::TokenType token = reader.readNext(); + if (token == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("Properties")) + continue; + + if (reader.name() == QStringLiteral("Manager")) { + setProperty(QStringLiteral("manager"), reader.readElementText()); + } else if (reader.name() == QStringLiteral("Company")) { + setProperty(QStringLiteral("company"), reader.readElementText()); + } + } + + if (reader.hasError()) { + qDebug("Error when read doc props app file."); + } } return true; } diff --git a/QXlsx/source/xlsxdocpropscore.cpp b/QXlsx/source/xlsxdocpropscore.cpp index b11c8b67..450b8124 100644 --- a/QXlsx/source/xlsxdocpropscore.cpp +++ b/QXlsx/source/xlsxdocpropscore.cpp @@ -1,31 +1,33 @@ // xlsxdocpropscore.cpp -#include -#include -#include -#include -#include +#include "xlsxdocpropscore_p.h" + +#include #include #include -#include - -#include "xlsxdocpropscore_p.h" +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE_XLSX DocPropsCore::DocPropsCore(CreateFlag flag) - :AbstractOOXmlFile(flag) + : AbstractOOXmlFile(flag) { } bool DocPropsCore::setProperty(const QString &name, const QString &value) { - static const QStringList validKeys = { - QStringLiteral("title"), QStringLiteral("subject"), - QStringLiteral("keywords"), QStringLiteral("description"), - QStringLiteral("category"), QStringLiteral("status"), - QStringLiteral("created"), QStringLiteral("creator") - }; + static const QStringList validKeys = {QStringLiteral("title"), + QStringLiteral("subject"), + QStringLiteral("keywords"), + QStringLiteral("description"), + QStringLiteral("category"), + QStringLiteral("status"), + QStringLiteral("created"), + QStringLiteral("creator")}; if (!validKeys.contains(name)) return false; @@ -55,11 +57,12 @@ QStringList DocPropsCore::propertyNames() const void DocPropsCore::saveToXmlFile(QIODevice *device) const { QXmlStreamWriter writer(device); - const QString cp = QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties"); - const QString dc = QStringLiteral("http://purl.org/dc/elements/1.1/"); - const QString dcterms = QStringLiteral("http://purl.org/dc/terms/"); + const QString cp = + QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties"); + const QString dc = QStringLiteral("http://purl.org/dc/elements/1.1/"); + const QString dcterms = QStringLiteral("http://purl.org/dc/terms/"); const QString dcmitype = QStringLiteral("http://purl.org/dc/dcmitype/"); - const QString xsi = QStringLiteral("http://www.w3.org/2001/XMLSchema-instance"); + const QString xsi = QStringLiteral("http://www.w3.org/2001/XMLSchema-instance"); writer.writeStartDocument(QStringLiteral("1.0"), true); writer.writeStartElement(QStringLiteral("cp:coreProperties")); writer.writeNamespace(cp, QStringLiteral("cp")); @@ -77,7 +80,10 @@ void DocPropsCore::saveToXmlFile(QIODevice *device) const writer.writeTextElement(dc, QStringLiteral("subject"), it.value()); it = m_properties.constFind(QStringLiteral("creator")); - writer.writeTextElement(dc, QStringLiteral("creator"), it != m_properties.constEnd() ? it.value() : QStringLiteral("Qt Xlsx Library")); + writer.writeTextElement(dc, + QStringLiteral("creator"), + it != m_properties.constEnd() ? it.value() + : QStringLiteral("Qt Xlsx Library")); it = m_properties.constFind(QStringLiteral("keywords")); if (it != m_properties.constEnd()) @@ -88,18 +94,23 @@ void DocPropsCore::saveToXmlFile(QIODevice *device) const writer.writeTextElement(dc, QStringLiteral("description"), it.value()); it = m_properties.constFind(QStringLiteral("creator")); - writer.writeTextElement(cp, QStringLiteral("lastModifiedBy"), it != m_properties.constEnd() ? it.value() : QStringLiteral("Qt Xlsx Library")); + writer.writeTextElement(cp, + QStringLiteral("lastModifiedBy"), + it != m_properties.constEnd() ? it.value() + : QStringLiteral("Qt Xlsx Library")); writer.writeStartElement(dcterms, QStringLiteral("created")); writer.writeAttribute(xsi, QStringLiteral("type"), QStringLiteral("dcterms:W3CDTF")); it = m_properties.constFind(QStringLiteral("created")); - writer.writeCharacters(it != m_properties.constEnd() ? it.value() : QDateTime::currentDateTime().toString(Qt::ISODate)); - writer.writeEndElement();//dcterms:created + writer.writeCharacters(it != m_properties.constEnd() + ? it.value() + : QDateTime::currentDateTime().toString(Qt::ISODate)); + writer.writeEndElement(); // dcterms:created writer.writeStartElement(dcterms, QStringLiteral("modified")); writer.writeAttribute(xsi, QStringLiteral("type"), QStringLiteral("dcterms:W3CDTF")); writer.writeCharacters(QDateTime::currentDateTime().toString(Qt::ISODate)); - writer.writeEndElement();//dcterms:created + writer.writeEndElement(); // dcterms:created it = m_properties.constFind(QStringLiteral("category")); if (it != m_properties.constEnd()) @@ -109,7 +120,7 @@ void DocPropsCore::saveToXmlFile(QIODevice *device) const if (it != m_properties.constEnd()) writer.writeTextElement(cp, QStringLiteral("contentStatus"), it.value()); - writer.writeEndElement(); //cp:coreProperties + writer.writeEndElement(); // cp:coreProperties writer.writeEndDocument(); } @@ -117,58 +128,41 @@ bool DocPropsCore::loadFromXmlFile(QIODevice *device) { QXmlStreamReader reader(device); - const QString cp = QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties"); - const QString dc = QStringLiteral("http://purl.org/dc/elements/1.1/"); + const QString cp = + QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties"); + const QString dc = QStringLiteral("http://purl.org/dc/elements/1.1/"); const QString dcterms = QStringLiteral("http://purl.org/dc/terms/"); - while (!reader.atEnd()) - { - QXmlStreamReader::TokenType token = reader.readNext(); - - if (token == QXmlStreamReader::StartElement) - { - - const auto& nsUri = reader.namespaceUri(); - const auto& name = reader.name(); - - if (name == QStringLiteral("subject") && nsUri == dc) - { - setProperty(QStringLiteral("subject"), reader.readElementText()); - } - else if (name == QStringLiteral("title") && nsUri == dc) - { - setProperty(QStringLiteral("title"), reader.readElementText()); - } - else if (name == QStringLiteral("creator") && nsUri == dc) - { - setProperty(QStringLiteral("creator"), reader.readElementText()); - } - else if (name == QStringLiteral("description") && nsUri == dc) - { - setProperty(QStringLiteral("description"), reader.readElementText()); - } - else if (name == QStringLiteral("keywords") && nsUri == cp) - { - setProperty(QStringLiteral("keywords"), reader.readElementText()); - } - else if (name == QStringLiteral("created") && nsUri == dcterms) - { - setProperty(QStringLiteral("created"), reader.readElementText()); - } - else if (name == QStringLiteral("category") && nsUri == cp) - { - setProperty(QStringLiteral("category"), reader.readElementText()); - } - else if (name == QStringLiteral("contentStatus") && nsUri == cp) - { - setProperty(QStringLiteral("status"), reader.readElementText()); - } - } - - if (reader.hasError()) - { - qDebug() << "Error when read doc props core file." << reader.errorString(); - } + while (!reader.atEnd()) { + QXmlStreamReader::TokenType token = reader.readNext(); + + if (token == QXmlStreamReader::StartElement) { + + const auto &nsUri = reader.namespaceUri(); + const auto &name = reader.name(); + + if (name == QStringLiteral("subject") && nsUri == dc) { + setProperty(QStringLiteral("subject"), reader.readElementText()); + } else if (name == QStringLiteral("title") && nsUri == dc) { + setProperty(QStringLiteral("title"), reader.readElementText()); + } else if (name == QStringLiteral("creator") && nsUri == dc) { + setProperty(QStringLiteral("creator"), reader.readElementText()); + } else if (name == QStringLiteral("description") && nsUri == dc) { + setProperty(QStringLiteral("description"), reader.readElementText()); + } else if (name == QStringLiteral("keywords") && nsUri == cp) { + setProperty(QStringLiteral("keywords"), reader.readElementText()); + } else if (name == QStringLiteral("created") && nsUri == dcterms) { + setProperty(QStringLiteral("created"), reader.readElementText()); + } else if (name == QStringLiteral("category") && nsUri == cp) { + setProperty(QStringLiteral("category"), reader.readElementText()); + } else if (name == QStringLiteral("contentStatus") && nsUri == cp) { + setProperty(QStringLiteral("status"), reader.readElementText()); + } + } + + if (reader.hasError()) { + qDebug() << "Error when read doc props core file." << reader.errorString(); + } } return true; } diff --git a/QXlsx/source/xlsxdocument.cpp b/QXlsx/source/xlsxdocument.cpp index cf6d898b..8efebb54 100644 --- a/QXlsx/source/xlsxdocument.cpp +++ b/QXlsx/source/xlsxdocument.cpp @@ -1,162 +1,161 @@ // xlsxdocument.cpp -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "xlsxdocument.h" -#include "xlsxdocument_p.h" -#include "xlsxworkbook.h" -#include "xlsxworksheet.h" + +#include "xlsxchart.h" #include "xlsxcontenttypes_p.h" -#include "xlsxrelationships_p.h" -#include "xlsxstyles_p.h" -#include "xlsxtheme_p.h" #include "xlsxdocpropsapp_p.h" #include "xlsxdocpropscore_p.h" +#include "xlsxdocument_p.h" +#include "xlsxdrawing_p.h" +#include "xlsxmediafile_p.h" +#include "xlsxrelationships_p.h" #include "xlsxsharedstrings_p.h" +#include "xlsxstyles_p.h" +#include "xlsxtheme_p.h" #include "xlsxutility_p.h" +#include "xlsxworkbook.h" #include "xlsxworkbook_p.h" -#include "xlsxdrawing_p.h" -#include "xlsxmediafile_p.h" -#include "xlsxchart.h" +#include "xlsxworksheet.h" #include "xlsxzipreader_p.h" #include "xlsxzipwriter_p.h" +#include +#include +#include +#include +#include +#include +#include +#include + /* - From Wikipedia: The Open Packaging Conventions (OPC) is a - container-file technology initially created by Microsoft to store - a combination of XML and non-XML files that together form a single - entity such as an Open XML Paper Specification (OpenXPS) - document. http://en.wikipedia.org/wiki/Open_Packaging_Conventions. - - At its simplest an Excel XLSX file contains the following elements: - - ____ [Content_Types].xml - | - |____ docProps - | |____ app.xml - | |____ core.xml - | - |____ xl - | |____ workbook.xml - | |____ worksheets - | | |____ sheet1.xml - | | - | |____ styles.xml - | | - | |____ theme - | | |____ theme1.xml - | | - | |_____rels - | |____ workbook.xml.rels - | - |_____rels - |____ .rels - - The Packager class coordinates the classes that represent the - elements of the package and writes them into the XLSX file. + From Wikipedia: The Open Packaging Conventions (OPC) is a + container-file technology initially created by Microsoft to store + a combination of XML and non-XML files that together form a single + entity such as an Open XML Paper Specification (OpenXPS) + document. http://en.wikipedia.org/wiki/Open_Packaging_Conventions. + + At its simplest an Excel XLSX file contains the following elements: + + ____ [Content_Types].xml + | + |____ docProps + | |____ app.xml + | |____ core.xml + | + |____ xl + | |____ workbook.xml + | |____ worksheets + | | |____ sheet1.xml + | | + | |____ styles.xml + | | + | |____ theme + | | |____ theme1.xml + | | + | |_____rels + | |____ workbook.xml.rels + | + |_____rels + |____ .rels + + The Packager class coordinates the classes that represent the + elements of the package and writes them into the XLSX file. */ QT_BEGIN_NAMESPACE_XLSX namespace xlsxDocumentCpp { - std::string copyTag(const std::string &sFrom, const std::string &sTo, const std::string &tag) { - const std::string tagToFindStart = "<" + tag; - const std::string tagToFindEnd = ""; - - // search all occurrences of tag in 'sFrom' - std::string sFromData = ""; - size_t startIndex = 0; - while (true) { - std::size_t startPos = sFrom.find(tagToFindStart, startIndex); - if (startPos != std::string::npos) { - std::size_t endPos = sFrom.find(tagToFindEnd, startPos); - std::string tagEndTmp = tagEnd; - if (endPos == std::string::npos) { // second try to find the ending, maybe it is "/>" - endPos = sFrom.find("/>", startPos); - tagEndTmp = "/>"; - } - if (endPos != std::string::npos) { - sFromData += sFrom.substr(startPos, endPos - startPos) + tagEndTmp; - startIndex = endPos + strlen(tagEndTmp.c_str()); - } - else { - break; - } - } - else { - break; - } - } - - std::string sOut = sTo; // copy 'sTo' in the output string - - if (!sFromData.empty()) { // tag found in 'from'? - // search all occurrences of tag in 'sOut' and delete them - int firstPosTag = -1; - while (true) { - std::size_t startPos = sOut.find(tagToFindStart); - if (startPos != std::string::npos) { - std::size_t endPos = sOut.find(tagToFindEnd); - std::string tagEndTmp = tagEnd; - if (endPos == std::string::npos) { // second try to find the ending, maybe it is "/>" - endPos = sOut.find("/>", startPos); - tagEndTmp = "/>"; - } - if (endPos != std::string::npos) { - if (firstPosTag < 0) - firstPosTag = startPos; - std::string stringBefore = sOut.substr(0, startPos); - endPos += strlen(tagEndTmp.c_str()); - std::string stringAfter = sOut.substr(endPos, strlen(sOut.c_str()) - endPos); - sOut = stringBefore + stringAfter; - } - else { - break; - } - } - else { - break; - } - } - - if (firstPosTag == -1) { - // tag not found in 'sTo' file - // try to find a default pos using standard tags - std::vector defaultPos{ "", "" }; - for (unsigned int i = 0; i < defaultPos.size(); ++i) { - std::size_t iDefaultPos = sOut.find(defaultPos[i]); - if (iDefaultPos != std::string::npos) { - firstPosTag = iDefaultPos; - break; - } - } - } - - // add the tag extracted from 'sFrom' in 'sOut' - // add in the position of the first tag found in 'sOut' ('firstPosTag') - if (firstPosTag >= 0) { - std::string stringBefore = sOut.substr(0, firstPosTag); - std::string stringAfter = sOut.substr(firstPosTag, strlen(sOut.c_str()) - firstPosTag); - sOut = stringBefore + sFromData + stringAfter; - } - } - - return sOut; - } -} - -DocumentPrivate::DocumentPrivate(Document *p) : - q_ptr(p), defaultPackageName(QStringLiteral("Book1.xlsx")), - isLoad(false) +std::string copyTag(const std::string &sFrom, const std::string &sTo, const std::string &tag) +{ + const std::string tagToFindStart = "<" + tag; + const std::string tagToFindEnd = ""; + + // search all occurrences of tag in 'sFrom' + std::string sFromData = ""; + size_t startIndex = 0; + while (true) { + std::size_t startPos = sFrom.find(tagToFindStart, startIndex); + if (startPos != std::string::npos) { + std::size_t endPos = sFrom.find(tagToFindEnd, startPos); + std::string tagEndTmp = tagEnd; + if (endPos == std::string::npos) { // second try to find the ending, maybe it is "/>" + endPos = sFrom.find("/>", startPos); + tagEndTmp = "/>"; + } + if (endPos != std::string::npos) { + sFromData += sFrom.substr(startPos, endPos - startPos) + tagEndTmp; + startIndex = endPos + strlen(tagEndTmp.c_str()); + } else { + break; + } + } else { + break; + } + } + + std::string sOut = sTo; // copy 'sTo' in the output string + + if (!sFromData.empty()) { // tag found in 'from'? + // search all occurrences of tag in 'sOut' and delete them + int firstPosTag = -1; + while (true) { + std::size_t startPos = sOut.find(tagToFindStart); + if (startPos != std::string::npos) { + std::size_t endPos = sOut.find(tagToFindEnd); + std::string tagEndTmp = tagEnd; + if (endPos == + std::string::npos) { // second try to find the ending, maybe it is "/>" + endPos = sOut.find("/>", startPos); + tagEndTmp = "/>"; + } + if (endPos != std::string::npos) { + if (firstPosTag < 0) + firstPosTag = startPos; + std::string stringBefore = sOut.substr(0, startPos); + endPos += strlen(tagEndTmp.c_str()); + std::string stringAfter = sOut.substr(endPos, strlen(sOut.c_str()) - endPos); + sOut = stringBefore + stringAfter; + } else { + break; + } + } else { + break; + } + } + + if (firstPosTag == -1) { + // tag not found in 'sTo' file + // try to find a default pos using standard tags + std::vector defaultPos{"", ""}; + for (unsigned int i = 0; i < defaultPos.size(); ++i) { + std::size_t iDefaultPos = sOut.find(defaultPos[i]); + if (iDefaultPos != std::string::npos) { + firstPosTag = iDefaultPos; + break; + } + } + } + + // add the tag extracted from 'sFrom' in 'sOut' + // add in the position of the first tag found in 'sOut' ('firstPosTag') + if (firstPosTag >= 0) { + std::string stringBefore = sOut.substr(0, firstPosTag); + std::string stringAfter = sOut.substr(firstPosTag, strlen(sOut.c_str()) - firstPosTag); + sOut = stringBefore + sFromData + stringAfter; + } + } + + return sOut; +} +} // namespace xlsxDocumentCpp + +DocumentPrivate::DocumentPrivate(Document *p) + : q_ptr(p) + , defaultPackageName(QStringLiteral("Book1.xlsx")) + , isLoad(false) { } @@ -171,361 +170,382 @@ void DocumentPrivate::init() bool DocumentPrivate::loadPackage(QIODevice *device) { - Q_Q(Document); - ZipReader zipReader(device); - QStringList filePaths = zipReader.filePaths(); + Q_Q(Document); + ZipReader zipReader(device); + QStringList filePaths = zipReader.filePaths(); - //Load the Content_Types file - if (!filePaths.contains(QLatin1String("[Content_Types].xml"))) - return false; + // Load the Content_Types file + if (!filePaths.contains(QLatin1String("[Content_Types].xml"))) + return false; contentTypes = std::make_shared(ContentTypes::F_LoadFromExists); - contentTypes->loadFromXmlData(zipReader.fileData(QStringLiteral("[Content_Types].xml"))); - - //Load root rels file - if (!filePaths.contains(QLatin1String("_rels/.rels"))) - return false; - Relationships rootRels; - rootRels.loadFromXmlData(zipReader.fileData(QStringLiteral("_rels/.rels"))); - - //load core property - QList rels_core = rootRels.packageRelationships(QStringLiteral("/metadata/core-properties")); - if (!rels_core.isEmpty()) { - //Get the core property file name if it exists. - //In normal case, this should be "docProps/core.xml" - QString docPropsCore_Name = rels_core[0].target; - - DocPropsCore props(DocPropsCore::F_LoadFromExists); - props.loadFromXmlData(zipReader.fileData(docPropsCore_Name)); + contentTypes->loadFromXmlData(zipReader.fileData(QStringLiteral("[Content_Types].xml"))); + + // Load root rels file + if (!filePaths.contains(QLatin1String("_rels/.rels"))) + return false; + Relationships rootRels; + rootRels.loadFromXmlData(zipReader.fileData(QStringLiteral("_rels/.rels"))); + + // load core property + QList rels_core = + rootRels.packageRelationships(QStringLiteral("/metadata/core-properties")); + if (!rels_core.isEmpty()) { + // Get the core property file name if it exists. + // In normal case, this should be "docProps/core.xml" + QString docPropsCore_Name = rels_core[0].target; + + DocPropsCore props(DocPropsCore::F_LoadFromExists); + props.loadFromXmlData(zipReader.fileData(docPropsCore_Name)); const auto propNames = props.propertyNames(); for (const QString &name : propNames) - q->setDocumentProperty(name, props.property(name)); - } - - //load app property - QList rels_app = rootRels.documentRelationships(QStringLiteral("/extended-properties")); - if (!rels_app.isEmpty()) { - //Get the app property file name if it exists. - //In normal case, this should be "docProps/app.xml" - QString docPropsApp_Name = rels_app[0].target; - - DocPropsApp props(DocPropsApp::F_LoadFromExists); - props.loadFromXmlData(zipReader.fileData(docPropsApp_Name)); + q->setDocumentProperty(name, props.property(name)); + } + + // load app property + QList rels_app = + rootRels.documentRelationships(QStringLiteral("/extended-properties")); + if (!rels_app.isEmpty()) { + // Get the app property file name if it exists. + // In normal case, this should be "docProps/app.xml" + QString docPropsApp_Name = rels_app[0].target; + + DocPropsApp props(DocPropsApp::F_LoadFromExists); + props.loadFromXmlData(zipReader.fileData(docPropsApp_Name)); const auto propNames = props.propertyNames(); for (const QString &name : propNames) - q->setDocumentProperty(name, props.property(name)); - } + q->setDocumentProperty(name, props.property(name)); + } - //load workbook now, Get the workbook file path from the root rels file - //In normal case, this should be "xl/workbook.xml" + // load workbook now, Get the workbook file path from the root rels file + // In normal case, this should be "xl/workbook.xml" workbook = QSharedPointer(new Workbook(Workbook::F_LoadFromExists)); - QList rels_xl = rootRels.documentRelationships(QStringLiteral("/officeDocument")); - if (rels_xl.isEmpty()) - return false; + QList rels_xl = + rootRels.documentRelationships(QStringLiteral("/officeDocument")); + if (rels_xl.isEmpty()) + return false; const QString xlworkbook_Path = rels_xl[0].target; - const auto parts = splitPath(xlworkbook_Path); - const QString xlworkbook_Dir = parts.first(); - const QString relFilePath = getRelFilePath(xlworkbook_Path); + const auto parts = splitPath(xlworkbook_Path); + const QString xlworkbook_Dir = parts.first(); + const QString relFilePath = getRelFilePath(xlworkbook_Path); - workbook->relationships()->loadFromXmlData( zipReader.fileData(relFilePath) ); - workbook->setFilePath(xlworkbook_Path); - workbook->loadFromXmlData(zipReader.fileData(xlworkbook_Path)); + workbook->relationships()->loadFromXmlData(zipReader.fileData(relFilePath)); + workbook->setFilePath(xlworkbook_Path); + workbook->loadFromXmlData(zipReader.fileData(xlworkbook_Path)); - //load styles - QList rels_styles = workbook->relationships()->documentRelationships(QStringLiteral("/styles")); - if (!rels_styles.isEmpty()) { - //In normal case this should be styles.xml which in xl - QString name = rels_styles[0].target; + // load styles + QList rels_styles = + workbook->relationships()->documentRelationships(QStringLiteral("/styles")); + if (!rels_styles.isEmpty()) { + // In normal case this should be styles.xml which in xl + QString name = rels_styles[0].target; // dev34 QString path; - if ( xlworkbook_Dir == QLatin1String(".") ) // root + if (xlworkbook_Dir == QLatin1String(".")) // root { path = name; - } - else - { + } else { path = xlworkbook_Dir + QLatin1String("/") + name; } - QSharedPointer styles (new Styles(Styles::F_LoadFromExists)); - styles->loadFromXmlData(zipReader.fileData(path)); - workbook->d_func()->styles = styles; - } - - //load sharedStrings - QList rels_sharedStrings = workbook->relationships()->documentRelationships(QStringLiteral("/sharedStrings")); - if (!rels_sharedStrings.isEmpty()) { - //In normal case this should be sharedStrings.xml which in xl - QString name = rels_sharedStrings[0].target; - QString path = xlworkbook_Dir + QLatin1String("/") + name; - workbook->d_func()->sharedStrings->loadFromXmlData(zipReader.fileData(path)); - } - - //load theme - QList rels_theme = workbook->relationships()->documentRelationships(QStringLiteral("/theme")); - if (!rels_theme.isEmpty()) { - //In normal case this should be theme/theme1.xml which in xl - QString name = rels_theme[0].target; - QString path = xlworkbook_Dir + QLatin1String("/") + name; - workbook->theme()->loadFromXmlData(zipReader.fileData(path)); - } - - //load sheets - for (int i=0; isheetCount(); ++i) { - AbstractSheet *sheet = workbook->sheet(i); - QString strFilePath = sheet->filePath(); - QString rel_path = getRelFilePath(strFilePath); - //If the .rel file exists, load it. - if (zipReader.filePaths().contains(rel_path)) - sheet->relationships()->loadFromXmlData(zipReader.fileData(rel_path)); - sheet->loadFromXmlData(zipReader.fileData(sheet->filePath())); - } - - //load external links - for (int i=0; id_func()->externalLinks.count(); ++i) { - SimpleOOXmlFile *link = workbook->d_func()->externalLinks[i].data(); - QString rel_path = getRelFilePath(link->filePath()); - //If the .rel file exists, load it. - if (zipReader.filePaths().contains(rel_path)) - link->relationships()->loadFromXmlData(zipReader.fileData(rel_path)); - link->loadFromXmlData(zipReader.fileData(link->filePath())); - } - - //load drawings - for (int i=0; idrawings().size(); ++i) { - Drawing *drawing = workbook->drawings()[i]; - QString rel_path = getRelFilePath(drawing->filePath()); - if (zipReader.filePaths().contains(rel_path)) - drawing->relationships()->loadFromXmlData(zipReader.fileData(rel_path)); - drawing->loadFromXmlData(zipReader.fileData(drawing->filePath())); - } - - //load charts - QList > chartFileToLoad = workbook->chartFiles(); - for (int i=0; i cf = chartFileToLoad[i]; - cf->loadFromXmlData(zipReader.fileData(cf->filePath())); - } - - //load media files + QSharedPointer styles(new Styles(Styles::F_LoadFromExists)); + styles->loadFromXmlData(zipReader.fileData(path)); + workbook->d_func()->styles = styles; + } + + // load sharedStrings + QList rels_sharedStrings = + workbook->relationships()->documentRelationships(QStringLiteral("/sharedStrings")); + if (!rels_sharedStrings.isEmpty()) { + // In normal case this should be sharedStrings.xml which in xl + QString name = rels_sharedStrings[0].target; + QString path = xlworkbook_Dir + QLatin1String("/") + name; + workbook->d_func()->sharedStrings->loadFromXmlData(zipReader.fileData(path)); + } + + // load theme + QList rels_theme = + workbook->relationships()->documentRelationships(QStringLiteral("/theme")); + if (!rels_theme.isEmpty()) { + // In normal case this should be theme/theme1.xml which in xl + QString name = rels_theme[0].target; + QString path = xlworkbook_Dir + QLatin1String("/") + name; + workbook->theme()->loadFromXmlData(zipReader.fileData(path)); + } + + // load sheets + for (int i = 0; i < workbook->sheetCount(); ++i) { + AbstractSheet *sheet = workbook->sheet(i); + QString strFilePath = sheet->filePath(); + QString rel_path = getRelFilePath(strFilePath); + // If the .rel file exists, load it. + if (zipReader.filePaths().contains(rel_path)) + sheet->relationships()->loadFromXmlData(zipReader.fileData(rel_path)); + sheet->loadFromXmlData(zipReader.fileData(sheet->filePath())); + } + + // load external links + for (int i = 0; i < workbook->d_func()->externalLinks.count(); ++i) { + SimpleOOXmlFile *link = workbook->d_func()->externalLinks[i].data(); + QString rel_path = getRelFilePath(link->filePath()); + // If the .rel file exists, load it. + if (zipReader.filePaths().contains(rel_path)) + link->relationships()->loadFromXmlData(zipReader.fileData(rel_path)); + link->loadFromXmlData(zipReader.fileData(link->filePath())); + } + + // load drawings + for (int i = 0; i < workbook->drawings().size(); ++i) { + Drawing *drawing = workbook->drawings()[i]; + QString rel_path = getRelFilePath(drawing->filePath()); + if (zipReader.filePaths().contains(rel_path)) + drawing->relationships()->loadFromXmlData(zipReader.fileData(rel_path)); + drawing->loadFromXmlData(zipReader.fileData(drawing->filePath())); + } + + // load charts + QList> chartFileToLoad = workbook->chartFiles(); + for (int i = 0; i < chartFileToLoad.size(); ++i) { + QSharedPointer cf = chartFileToLoad[i]; + cf->loadFromXmlData(zipReader.fileData(cf->filePath())); + } + + // load media files const auto mediaFileToLoad = workbook->mediaFiles(); for (const auto &mf : mediaFileToLoad) { - const QString path = mf->fileName(); - const QString suffix = path.mid(path.lastIndexOf(QLatin1Char('.'))+1); - mf->set(zipReader.fileData(path), suffix); - } + const QString path = mf->fileName(); + const QString suffix = path.mid(path.lastIndexOf(QLatin1Char('.')) + 1); + mf->set(zipReader.fileData(path), suffix); + } - isLoad = true; - return true; + isLoad = true; + return true; } bool DocumentPrivate::savePackage(QIODevice *device) const { - Q_Q(const Document); + Q_Q(const Document); - ZipWriter zipWriter(device); - if (zipWriter.error()) - return false; + ZipWriter zipWriter(device); + if (zipWriter.error()) + return false; - contentTypes->clearOverrides(); + contentTypes->clearOverrides(); - DocPropsApp docPropsApp(DocPropsApp::F_NewFromScratch); - DocPropsCore docPropsCore(DocPropsCore::F_NewFromScratch); + DocPropsApp docPropsApp(DocPropsApp::F_NewFromScratch); + DocPropsCore docPropsCore(DocPropsCore::F_NewFromScratch); - // save worksheet xml files - QList > worksheets = workbook->getSheetsByTypes(AbstractSheet::ST_WorkSheet); - if (!worksheets.isEmpty()) - docPropsApp.addHeadingPair(QStringLiteral("Worksheets"), worksheets.size()); + // save worksheet xml files + QList> worksheets = + workbook->getSheetsByTypes(AbstractSheet::ST_WorkSheet); + if (!worksheets.isEmpty()) + docPropsApp.addHeadingPair(QStringLiteral("Worksheets"), worksheets.size()); - for (int i = 0 ; i < worksheets.size(); ++i) - { - QSharedPointer sheet = worksheets[i]; - contentTypes->addWorksheetName(QStringLiteral("sheet%1").arg(i+1)); - docPropsApp.addPartTitle(sheet->sheetName()); + for (int i = 0; i < worksheets.size(); ++i) { + QSharedPointer sheet = worksheets[i]; + contentTypes->addWorksheetName(QStringLiteral("sheet%1").arg(i + 1)); + docPropsApp.addPartTitle(sheet->sheetName()); - zipWriter.addFile(QStringLiteral("xl/worksheets/sheet%1.xml").arg(i+1), sheet->saveToXmlData()); + zipWriter.addFile(QStringLiteral("xl/worksheets/sheet%1.xml").arg(i + 1), + sheet->saveToXmlData()); - Relationships *rel = sheet->relationships(); - if (!rel->isEmpty()) - zipWriter.addFile(QStringLiteral("xl/worksheets/_rels/sheet%1.xml.rels").arg(i+1), rel->saveToXmlData()); - } + Relationships *rel = sheet->relationships(); + if (!rel->isEmpty()) + zipWriter.addFile(QStringLiteral("xl/worksheets/_rels/sheet%1.xml.rels").arg(i + 1), + rel->saveToXmlData()); + } - //save chartsheet xml files - QList > chartsheets = workbook->getSheetsByTypes(AbstractSheet::ST_ChartSheet); - if (!chartsheets.isEmpty()) + // save chartsheet xml files + QList> chartsheets = + workbook->getSheetsByTypes(AbstractSheet::ST_ChartSheet); + if (!chartsheets.isEmpty()) docPropsApp.addHeadingPair(QStringLiteral("Chartsheets"), chartsheets.size()); - for (int i=0; i sheet = chartsheets[i]; - contentTypes->addWorksheetName(QStringLiteral("sheet%1").arg(i+1)); - docPropsApp.addPartTitle(sheet->sheetName()); - - zipWriter.addFile(QStringLiteral("xl/chartsheets/sheet%1.xml").arg(i+1), sheet->saveToXmlData()); - Relationships *rel = sheet->relationships(); - if (!rel->isEmpty()) - zipWriter.addFile(QStringLiteral("xl/chartsheets/_rels/sheet%1.xml.rels").arg(i+1), rel->saveToXmlData()); - } - - // save external links xml files - for (int i=0; id_func()->externalLinks.count(); ++i) - { - SimpleOOXmlFile *link = workbook->d_func()->externalLinks[i].data(); - contentTypes->addExternalLinkName(QStringLiteral("externalLink%1").arg(i+1)); - - zipWriter.addFile(QStringLiteral("xl/externalLinks/externalLink%1.xml").arg(i+1), link->saveToXmlData()); - Relationships *rel = link->relationships(); - if (!rel->isEmpty()) - zipWriter.addFile(QStringLiteral("xl/externalLinks/_rels/externalLink%1.xml.rels").arg(i+1), rel->saveToXmlData()); - } - - // save workbook xml file - contentTypes->addWorkbook(); - zipWriter.addFile(QStringLiteral("xl/workbook.xml"), workbook->saveToXmlData()); - zipWriter.addFile(QStringLiteral("xl/_rels/workbook.xml.rels"), workbook->relationships()->saveToXmlData()); - - // save drawing xml files - for (int i=0; idrawings().size(); ++i) - { - contentTypes->addDrawingName(QStringLiteral("drawing%1").arg(i+1)); - - Drawing *drawing = workbook->drawings()[i]; - zipWriter.addFile(QStringLiteral("xl/drawings/drawing%1.xml").arg(i+1), drawing->saveToXmlData()); - if (!drawing->relationships()->isEmpty()) - zipWriter.addFile(QStringLiteral("xl/drawings/_rels/drawing%1.xml.rels").arg(i+1), drawing->relationships()->saveToXmlData()); - } - - // save docProps app/core xml file + for (int i = 0; i < chartsheets.size(); ++i) { + QSharedPointer sheet = chartsheets[i]; + contentTypes->addWorksheetName(QStringLiteral("sheet%1").arg(i + 1)); + docPropsApp.addPartTitle(sheet->sheetName()); + + zipWriter.addFile(QStringLiteral("xl/chartsheets/sheet%1.xml").arg(i + 1), + sheet->saveToXmlData()); + Relationships *rel = sheet->relationships(); + if (!rel->isEmpty()) + zipWriter.addFile(QStringLiteral("xl/chartsheets/_rels/sheet%1.xml.rels").arg(i + 1), + rel->saveToXmlData()); + } + + // save external links xml files + for (int i = 0; i < workbook->d_func()->externalLinks.count(); ++i) { + SimpleOOXmlFile *link = workbook->d_func()->externalLinks[i].data(); + contentTypes->addExternalLinkName(QStringLiteral("externalLink%1").arg(i + 1)); + + zipWriter.addFile(QStringLiteral("xl/externalLinks/externalLink%1.xml").arg(i + 1), + link->saveToXmlData()); + Relationships *rel = link->relationships(); + if (!rel->isEmpty()) + zipWriter.addFile( + QStringLiteral("xl/externalLinks/_rels/externalLink%1.xml.rels").arg(i + 1), + rel->saveToXmlData()); + } + + // save workbook xml file + contentTypes->addWorkbook(); + zipWriter.addFile(QStringLiteral("xl/workbook.xml"), workbook->saveToXmlData()); + zipWriter.addFile(QStringLiteral("xl/_rels/workbook.xml.rels"), + workbook->relationships()->saveToXmlData()); + + // save drawing xml files + for (int i = 0; i < workbook->drawings().size(); ++i) { + contentTypes->addDrawingName(QStringLiteral("drawing%1").arg(i + 1)); + + Drawing *drawing = workbook->drawings()[i]; + zipWriter.addFile(QStringLiteral("xl/drawings/drawing%1.xml").arg(i + 1), + drawing->saveToXmlData()); + if (!drawing->relationships()->isEmpty()) + zipWriter.addFile(QStringLiteral("xl/drawings/_rels/drawing%1.xml.rels").arg(i + 1), + drawing->relationships()->saveToXmlData()); + } + + // save docProps app/core xml file const auto docPropNames = q->documentPropertyNames(); for (const QString &name : docPropNames) { - docPropsApp.setProperty(name, q->documentProperty(name)); - docPropsCore.setProperty(name, q->documentProperty(name)); - } - contentTypes->addDocPropApp(); - contentTypes->addDocPropCore(); - zipWriter.addFile(QStringLiteral("docProps/app.xml"), docPropsApp.saveToXmlData()); - zipWriter.addFile(QStringLiteral("docProps/core.xml"), docPropsCore.saveToXmlData()); - - // save sharedStrings xml file - if (!workbook->sharedStrings()->isEmpty()) { - contentTypes->addSharedString(); - zipWriter.addFile(QStringLiteral("xl/sharedStrings.xml"), workbook->sharedStrings()->saveToXmlData()); - } + docPropsApp.setProperty(name, q->documentProperty(name)); + docPropsCore.setProperty(name, q->documentProperty(name)); + } + contentTypes->addDocPropApp(); + contentTypes->addDocPropCore(); + zipWriter.addFile(QStringLiteral("docProps/app.xml"), docPropsApp.saveToXmlData()); + zipWriter.addFile(QStringLiteral("docProps/core.xml"), docPropsCore.saveToXmlData()); + + // save sharedStrings xml file + if (!workbook->sharedStrings()->isEmpty()) { + contentTypes->addSharedString(); + zipWriter.addFile(QStringLiteral("xl/sharedStrings.xml"), + workbook->sharedStrings()->saveToXmlData()); + } // save calc chain [dev16] contentTypes->addCalcChain(); zipWriter.addFile(QStringLiteral("xl/calcChain.xml"), workbook->styles()->saveToXmlData()); - // save styles xml file - contentTypes->addStyles(); - zipWriter.addFile(QStringLiteral("xl/styles.xml"), workbook->styles()->saveToXmlData()); + // save styles xml file + contentTypes->addStyles(); + zipWriter.addFile(QStringLiteral("xl/styles.xml"), workbook->styles()->saveToXmlData()); - // save theme xml file - contentTypes->addTheme(); - zipWriter.addFile(QStringLiteral("xl/theme/theme1.xml"), workbook->theme()->saveToXmlData()); + // save theme xml file + contentTypes->addTheme(); + zipWriter.addFile(QStringLiteral("xl/theme/theme1.xml"), workbook->theme()->saveToXmlData()); - // save chart xml files - for (int i=0; ichartFiles().size(); ++i) - { - contentTypes->addChartName(QStringLiteral("chart%1").arg(i+1)); - QSharedPointer cf = workbook->chartFiles()[i]; - zipWriter.addFile(QStringLiteral("xl/charts/chart%1.xml").arg(i+1), cf->saveToXmlData()); - } + // save chart xml files + for (int i = 0; i < workbook->chartFiles().size(); ++i) { + contentTypes->addChartName(QStringLiteral("chart%1").arg(i + 1)); + QSharedPointer cf = workbook->chartFiles()[i]; + zipWriter.addFile(QStringLiteral("xl/charts/chart%1.xml").arg(i + 1), cf->saveToXmlData()); + } - // save image files + // save image files const auto mfs = workbook->mediaFiles(); - for (int i=0; i < mfs.size(); ++i) - { + for (int i = 0; i < mfs.size(); ++i) { auto mf = mfs[i]; - if (!mf->mimeType().isEmpty()) - contentTypes->addDefault(mf->suffix(), mf->mimeType()); + if (!mf->mimeType().isEmpty()) + contentTypes->addDefault(mf->suffix(), mf->mimeType()); - zipWriter.addFile(QStringLiteral("xl/media/image%1.%2").arg(i+1).arg(mf->suffix()), mf->contents()); - } + zipWriter.addFile(QStringLiteral("xl/media/image%1.%2").arg(i + 1).arg(mf->suffix()), + mf->contents()); + } - // save root .rels xml file - Relationships rootrels; - rootrels.addDocumentRelationship(QStringLiteral("/officeDocument"), QStringLiteral("xl/workbook.xml")); - rootrels.addPackageRelationship(QStringLiteral("/metadata/core-properties"), QStringLiteral("docProps/core.xml")); - rootrels.addDocumentRelationship(QStringLiteral("/extended-properties"), QStringLiteral("docProps/app.xml")); - zipWriter.addFile(QStringLiteral("_rels/.rels"), rootrels.saveToXmlData()); + // save root .rels xml file + Relationships rootrels; + rootrels.addDocumentRelationship(QStringLiteral("/officeDocument"), + QStringLiteral("xl/workbook.xml")); + rootrels.addPackageRelationship(QStringLiteral("/metadata/core-properties"), + QStringLiteral("docProps/core.xml")); + rootrels.addDocumentRelationship(QStringLiteral("/extended-properties"), + QStringLiteral("docProps/app.xml")); + zipWriter.addFile(QStringLiteral("_rels/.rels"), rootrels.saveToXmlData()); - // save content types xml file - zipWriter.addFile(QStringLiteral("[Content_Types].xml"), contentTypes->saveToXmlData()); + // save content types xml file + zipWriter.addFile(QStringLiteral("[Content_Types].xml"), contentTypes->saveToXmlData()); - zipWriter.close(); - return true; + zipWriter.close(); + return true; } bool DocumentPrivate::copyStyle(const QString &from, const QString &to) { - // create a temp file because the zip writer cannot modify already existing zips - QTemporaryFile tempFile; - tempFile.open(); - tempFile.close(); - QString temFilePath = QFileInfo(tempFile).absoluteFilePath(); + // create a temp file because the zip writer cannot modify already existing zips + QTemporaryFile tempFile; + tempFile.open(); + tempFile.close(); + QString temFilePath = QFileInfo(tempFile).absoluteFilePath(); - ZipWriter temporalZip(temFilePath); + ZipWriter temporalZip(temFilePath); - ZipReader zipReader(from); - QStringList filePaths = zipReader.filePaths(); + ZipReader zipReader(from); + QStringList filePaths = zipReader.filePaths(); QSharedPointer toReader = QSharedPointer(new ZipReader(to)); - QStringList toFilePaths = toReader->filePaths(); + QStringList toFilePaths = toReader->filePaths(); - // copy all files from "to" zip except those related to style - for (int i = 0; i < toFilePaths.size(); i++) { + // copy all files from "to" zip except those related to style + for (int i = 0; i < toFilePaths.size(); i++) { if (toFilePaths[i].contains(QLatin1String("xl/styles"))) { - if (filePaths.contains(toFilePaths[i])) { // style file exist in 'from' as well - // modify style file - std::string fromData = QString::fromUtf8(zipReader.fileData(toFilePaths[i])).toStdString(); - std::string toData = QString::fromUtf8(toReader->fileData(toFilePaths[i])).toStdString(); - // copy default theme style from 'from' to 'to' - toData = xlsxDocumentCpp::copyTag(fromData, toData, "dxfs"); - temporalZip.addFile(toFilePaths.at(i), QString::fromUtf8(toData.c_str()).toUtf8()); - - continue; - } - } + if (filePaths.contains(toFilePaths[i])) { // style file exist in 'from' as well + // modify style file + std::string fromData = + QString::fromUtf8(zipReader.fileData(toFilePaths[i])).toStdString(); + std::string toData = + QString::fromUtf8(toReader->fileData(toFilePaths[i])).toStdString(); + // copy default theme style from 'from' to 'to' + toData = xlsxDocumentCpp::copyTag(fromData, toData, "dxfs"); + temporalZip.addFile(toFilePaths.at(i), QString::fromUtf8(toData.c_str()).toUtf8()); + + continue; + } + } if (toFilePaths[i].contains(QLatin1String("xl/workbook"))) { - if (filePaths.contains(toFilePaths[i])) { // workbook file exist in 'from' as well - // modify workbook file - std::string fromData = QString::fromUtf8(zipReader.fileData(toFilePaths[i])).toStdString(); - std::string toData = QString::fromUtf8(toReader->fileData(toFilePaths[i])).toStdString(); - // copy default theme style from 'from' to 'to' - toData = xlsxDocumentCpp::copyTag(fromData, toData, "workbookPr"); - temporalZip.addFile(toFilePaths.at(i), QString::fromUtf8(toData.c_str()).toUtf8()); - continue; - } - } + if (filePaths.contains(toFilePaths[i])) { // workbook file exist in 'from' as well + // modify workbook file + std::string fromData = + QString::fromUtf8(zipReader.fileData(toFilePaths[i])).toStdString(); + std::string toData = + QString::fromUtf8(toReader->fileData(toFilePaths[i])).toStdString(); + // copy default theme style from 'from' to 'to' + toData = xlsxDocumentCpp::copyTag(fromData, toData, "workbookPr"); + temporalZip.addFile(toFilePaths.at(i), QString::fromUtf8(toData.c_str()).toUtf8()); + continue; + } + } if (toFilePaths[i].contains(QLatin1String("xl/worksheets/sheet"))) { - if (filePaths.contains(toFilePaths[i])) { // sheet file exist in 'from' as well - // modify sheet file - std::string fromData = QString::fromUtf8(zipReader.fileData(toFilePaths[i])).toStdString(); - std::string toData = QString::fromUtf8(toReader->fileData(toFilePaths[i])).toStdString(); - // copy "conditionalFormatting" from 'from' to 'to' - toData = xlsxDocumentCpp::copyTag(fromData, toData, "conditionalFormatting"); - temporalZip.addFile(toFilePaths.at(i), QString::fromUtf8(toData.c_str()).toUtf8()); - continue; - } - } - - QByteArray data = toReader->fileData(toFilePaths.at(i)); - temporalZip.addFile(toFilePaths.at(i), data); - } - - temporalZip.close(); + if (filePaths.contains(toFilePaths[i])) { // sheet file exist in 'from' as well + // modify sheet file + std::string fromData = + QString::fromUtf8(zipReader.fileData(toFilePaths[i])).toStdString(); + std::string toData = + QString::fromUtf8(toReader->fileData(toFilePaths[i])).toStdString(); + // copy "conditionalFormatting" from 'from' to 'to' + toData = xlsxDocumentCpp::copyTag(fromData, toData, "conditionalFormatting"); + temporalZip.addFile(toFilePaths.at(i), QString::fromUtf8(toData.c_str()).toUtf8()); + continue; + } + } + + QByteArray data = toReader->fileData(toFilePaths.at(i)); + temporalZip.addFile(toFilePaths.at(i), data); + } + + temporalZip.close(); toReader.clear(); - tempFile.close(); + tempFile.close(); - QFile::remove(to); - tempFile.copy(to); + QFile::remove(to); + tempFile.copy(to); - return true; + return true; } /*! @@ -539,10 +559,11 @@ bool DocumentPrivate::copyStyle(const QString &from, const QString &to) * Creates a new empty xlsx document. * The \a parent argument is passed to QObject's constructor. */ -Document::Document(QObject *parent) : - QObject(parent), d_ptr(new DocumentPrivate(this)) +Document::Document(QObject *parent) + : QObject(parent) + , d_ptr(new DocumentPrivate(this)) { - d_ptr->init(); + d_ptr->init(); } /*! @@ -550,26 +571,22 @@ Document::Document(QObject *parent) : * Try to open an existing xlsx document named \a name. * The \a parent argument is passed to QObject's constructor. */ -Document::Document(const QString &name, - QObject *parent) : - QObject(parent), - d_ptr(new DocumentPrivate(this)) +Document::Document(const QString &name, QObject *parent) + : QObject(parent) + , d_ptr(new DocumentPrivate(this)) { - d_ptr->packageName = name; + d_ptr->packageName = name; - if (QFile::exists(name)) - { - QFile xlsx(name); - if (xlsx.open(QFile::ReadOnly)) - { - if (! d_ptr->loadPackage(&xlsx)) - { - // NOTICE: failed to load package - } - } - } + if (QFile::exists(name)) { + QFile xlsx(name); + if (xlsx.open(QFile::ReadOnly)) { + if (!d_ptr->loadPackage(&xlsx)) { + // NOTICE: failed to load package + } + } + } - d_ptr->init(); + d_ptr->init(); } /*! @@ -577,29 +594,28 @@ Document::Document(const QString &name, * Try to open an existing xlsx document from \a device. * The \a parent argument is passed to QObject's constructor. */ -Document::Document(QIODevice *device, QObject *parent) : - QObject(parent), d_ptr(new DocumentPrivate(this)) +Document::Document(QIODevice *device, QObject *parent) + : QObject(parent) + , d_ptr(new DocumentPrivate(this)) { - if (device && device->isReadable()) - { - if (!d_ptr->loadPackage(device)) - { - // NOTICE: failed to load package - } - } - d_ptr->init(); + if (device && device->isReadable()) { + if (!d_ptr->loadPackage(device)) { + // NOTICE: failed to load package + } + } + d_ptr->init(); } /*! - \overload + \overload - Write \a value to cell \a row_column with the given \a format. + Write \a value to cell \a row_column with the given \a format. */ bool Document::write(const CellReference &row_column, const QVariant &value, const Format &format) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->write(row_column, value, format); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->write(row_column, value, format); + return false; } /*! @@ -608,34 +624,34 @@ bool Document::write(const CellReference &row_column, const QVariant &value, con */ bool Document::write(int row, int col, const QVariant &value, const Format &format) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->write(row, col, value, format); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->write(row, col, value, format); + return false; } /*! - \overload - Returns the contents of the cell \a cell. + \overload + Returns the contents of the cell \a cell. - \sa cellAt() + \sa cellAt() */ QVariant Document::read(const CellReference &cell) const { - if (Worksheet *sheet = currentWorksheet()) - return sheet->read(cell); - return QVariant(); + if (Worksheet *sheet = currentWorksheet()) + return sheet->read(cell); + return QVariant(); } /*! - Returns the contents of the cell (\a row, \a col). + Returns the contents of the cell (\a row, \a col). - \sa cellAt() + \sa cellAt() */ QVariant Document::read(int row, int col) const { - if (Worksheet *sheet = currentWorksheet()) - return sheet->read(row, col); - return QVariant(); + if (Worksheet *sheet = currentWorksheet()) + return sheet->read(row, col); + return QVariant(); } /*! @@ -644,18 +660,18 @@ QVariant Document::read(int row, int col) const */ int Document::insertImage(int row, int column, const QImage &image) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->insertImage(row, column, image); + if (Worksheet *sheet = currentWorksheet()) + return sheet->insertImage(row, column, image); return 0; } -bool Document::getImage(int imageIndex, QImage& img) +bool Document::getImage(int imageIndex, QImage &img) { if (Worksheet *sheet = currentWorksheet()) return sheet->getImage(imageIndex, img); - return false; + return false; } bool Document::getImage(int row, int col, QImage &img) @@ -663,7 +679,7 @@ bool Document::getImage(int row, int col, QImage &img) if (Worksheet *sheet = currentWorksheet()) return sheet->getImage(row, col, img); - return false; + return false; } uint Document::getImageCount() @@ -674,7 +690,6 @@ uint Document::getImageCount() return 0; } - /*! * Creates an chart with the given \a size and insert it to the current * active worksheet at the position \a row, \a col. @@ -682,9 +697,9 @@ uint Document::getImageCount() */ Chart *Document::insertChart(int row, int col, const QSize &size) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->insertChart(row, col, size); - return 0; + if (Worksheet *sheet = currentWorksheet()) + return sheet->insertChart(row, col, size); + return 0; } /*! @@ -696,9 +711,9 @@ Chart *Document::insertChart(int row, int col, const QSize &size) */ bool Document::mergeCells(const CellRange &range, const Format &format) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->mergeCells(range, format); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->mergeCells(range, format); + return false; } /*! @@ -707,9 +722,9 @@ bool Document::mergeCells(const CellRange &range, const Format &format) */ bool Document::unmergeCells(const CellRange &range) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->unmergeCells(range); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->unmergeCells(range); + return false; } /*! @@ -718,9 +733,9 @@ bool Document::unmergeCells(const CellRange &range) */ bool Document::setColumnWidth(const CellRange &range, double width) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->setColumnWidth(range, width); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->setColumnWidth(range, width); + return false; } /*! @@ -729,9 +744,9 @@ bool Document::setColumnWidth(const CellRange &range, double width) */ bool Document::setColumnFormat(const CellRange &range, const Format &format) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->setColumnFormat(range, format); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->setColumnFormat(range, format); + return false; } /*! @@ -741,9 +756,9 @@ bool Document::setColumnFormat(const CellRange &range, const Format &format) */ bool Document::setColumnHidden(const CellRange &range, bool hidden) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->setColumnWidth(range, hidden); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->setColumnWidth(range, hidden); + return false; } /*! @@ -752,7 +767,7 @@ bool Document::setColumnHidden(const CellRange &range, bool hidden) */ bool Document::setColumnWidth(int column, double width) { - return setColumnWidth(column,column,width); + return setColumnWidth(column, column, width); } /*! @@ -761,7 +776,7 @@ bool Document::setColumnWidth(int column, double width) */ bool Document::setColumnFormat(int column, const Format &format) { - return setColumnFormat(column,column,format); + return setColumnFormat(column, column, format); } /*! @@ -770,7 +785,7 @@ bool Document::setColumnFormat(int column, const Format &format) */ bool Document::setColumnHidden(int column, bool hidden) { - return setColumnHidden(column,column,hidden); + return setColumnHidden(column, column, hidden); } /*! @@ -779,9 +794,9 @@ bool Document::setColumnHidden(int column, bool hidden) */ bool Document::setColumnWidth(int colFirst, int colLast, double width) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->setColumnWidth(colFirst, colLast, width); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->setColumnWidth(colFirst, colLast, width); + return false; } /*! @@ -791,12 +806,11 @@ bool Document::setColumnWidth(int colFirst, int colLast, double width) */ bool Document::setColumnFormat(int colFirst, int colLast, const Format &format) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->setColumnFormat(colFirst, colLast, format); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->setColumnFormat(colFirst, colLast, format); + return false; } - /*! Sets hidden property of columns [\a colFirst, \a colLast] to \a hidden. Columns are 1-indexed. @@ -804,9 +818,9 @@ bool Document::setColumnFormat(int colFirst, int colLast, const Format &format) */ bool Document::setColumnHidden(int colFirst, int colLast, bool hidden) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->setColumnHidden(colFirst, colLast, hidden); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->setColumnHidden(colFirst, colLast, hidden); + return false; } /*! @@ -816,9 +830,9 @@ bool Document::setColumnHidden(int colFirst, int colLast, bool hidden) */ double Document::columnWidth(int column) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->columnWidth(column); - return 0.0; + if (Worksheet *sheet = currentWorksheet()) + return sheet->columnWidth(column); + return 0.0; } /*! @@ -826,9 +840,9 @@ double Document::columnWidth(int column) */ Format Document::columnFormat(int column) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->columnFormat(column); - return Format(); + if (Worksheet *sheet = currentWorksheet()) + return sheet->columnFormat(column); + return Format(); } /*! @@ -836,9 +850,9 @@ Format Document::columnFormat(int column) */ bool Document::isColumnHidden(int column) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->isColumnHidden(column); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->isColumnHidden(column); + return false; } /*! @@ -849,7 +863,7 @@ bool Document::isColumnHidden(int column) */ bool Document::setRowFormat(int row, const Format &format) { - return setRowFormat(row,row, format); + return setRowFormat(row, row, format); } /*! @@ -860,9 +874,9 @@ bool Document::setRowFormat(int row, const Format &format) */ bool Document::setRowFormat(int rowFirst, int rowLast, const Format &format) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->setRowFormat(rowFirst, rowLast, format); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->setRowFormat(rowFirst, rowLast, format); + return false; } /*! @@ -873,7 +887,7 @@ bool Document::setRowFormat(int rowFirst, int rowLast, const Format &format) */ bool Document::setRowHidden(int row, bool hidden) { - return setRowHidden(row,row,hidden); + return setRowHidden(row, row, hidden); } /*! @@ -884,9 +898,9 @@ bool Document::setRowHidden(int row, bool hidden) */ bool Document::setRowHidden(int rowFirst, int rowLast, bool hidden) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->setRowHidden(rowFirst, rowLast, hidden); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->setRowHidden(rowFirst, rowLast, hidden); + return false; } /*! @@ -898,7 +912,7 @@ bool Document::setRowHidden(int rowFirst, int rowLast, bool hidden) */ bool Document::setRowHeight(int row, double height) { - return setRowHeight(row,row,height); + return setRowHeight(row, row, height); } /*! @@ -910,9 +924,9 @@ bool Document::setRowHeight(int row, double height) */ bool Document::setRowHeight(int rowFirst, int rowLast, double height) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->setRowHeight(rowFirst, rowLast, height); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->setRowHeight(rowFirst, rowLast, height); + return false; } /*! @@ -920,9 +934,9 @@ bool Document::setRowHeight(int rowFirst, int rowLast, double height) */ double Document::rowHeight(int row) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->rowHeight(row); - return 0.0; + if (Worksheet *sheet = currentWorksheet()) + return sheet->rowHeight(row); + return 0.0; } /*! @@ -930,9 +944,9 @@ double Document::rowHeight(int row) */ Format Document::rowFormat(int row) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->rowFormat(row); - return Format(); + if (Worksheet *sheet = currentWorksheet()) + return sheet->rowFormat(row); + return Format(); } /*! @@ -940,9 +954,9 @@ Format Document::rowFormat(int row) */ bool Document::isRowHidden(int row) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->isRowHidden(row); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->isRowHidden(row); + return false; } /*! @@ -951,9 +965,9 @@ bool Document::isRowHidden(int row) */ bool Document::groupRows(int rowFirst, int rowLast, bool collapsed) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->groupRows(rowFirst, rowLast, collapsed); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->groupRows(rowFirst, rowLast, collapsed); + return false; } /*! @@ -962,9 +976,9 @@ bool Document::groupRows(int rowFirst, int rowLast, bool collapsed) */ bool Document::groupColumns(int colFirst, int colLast, bool collapsed) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->groupColumns(colFirst, colLast, collapsed); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->groupColumns(colFirst, colLast, collapsed); + return false; } /*! @@ -972,9 +986,9 @@ bool Document::groupColumns(int colFirst, int colLast, bool collapsed) */ bool Document::addDataValidation(const DataValidation &validation) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->addDataValidation(validation); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->addDataValidation(validation); + return false; } /*! @@ -982,9 +996,9 @@ bool Document::addDataValidation(const DataValidation &validation) */ bool Document::addConditionalFormatting(const ConditionalFormatting &cf) { - if (Worksheet *sheet = currentWorksheet()) - return sheet->addConditionalFormatting(cf); - return false; + if (Worksheet *sheet = currentWorksheet()) + return sheet->addConditionalFormatting(cf); + return false; } /*! @@ -996,9 +1010,9 @@ bool Document::addConditionalFormatting(const ConditionalFormatting &cf) */ Cell *Document::cellAt(const CellReference &pos) const { - if (Worksheet *sheet = currentWorksheet()) - return sheet->cellAt(pos); - return 0; + if (Worksheet *sheet = currentWorksheet()) + return sheet->cellAt(pos); + return 0; } /*! @@ -1009,9 +1023,9 @@ Cell *Document::cellAt(const CellReference &pos) const */ Cell *Document::cellAt(int row, int col) const { - if (Worksheet *sheet = currentWorksheet()) - return sheet->cellAt(row, col); - return 0; + if (Worksheet *sheet = currentWorksheet()) + return sheet->cellAt(row, col); + return 0; } /*! @@ -1023,21 +1037,24 @@ Cell *Document::cellAt(int row, int col) const * \param scope The name of one worksheet, or empty which means golbal scope. * \return Return false if the name invalid. */ -bool Document::defineName(const QString &name, const QString &formula, const QString &comment, const QString &scope) +bool Document::defineName(const QString &name, + const QString &formula, + const QString &comment, + const QString &scope) { - Q_D(Document); + Q_D(Document); - return d->workbook->defineName(name, formula, comment, scope); + return d->workbook->defineName(name, formula, comment, scope); } /*! - Return the range that contains cell data. + Return the range that contains cell data. */ CellRange Document::dimension() const { - if (Worksheet *sheet = currentWorksheet()) - return sheet->dimension(); - return CellRange(); + if (Worksheet *sheet = currentWorksheet()) + return sheet->dimension(); + return CellRange(); } /*! @@ -1045,40 +1062,40 @@ CellRange Document::dimension() const */ QString Document::documentProperty(const QString &key) const { - Q_D(const Document); + Q_D(const Document); auto it = d->documentProperties.constFind(key); if (it != d->documentProperties.constEnd()) return it.value(); - else - return QString(); + else + return QString(); } /*! - Set the document properties such as Title, Author etc. + Set the document properties such as Title, Author etc. - The method can be used to set the document properties of the Excel - file created by Qt Xlsx. These properties are visible when you use the - Office Button -> Prepare -> Properties option in Excel and are also - available to external applications that read or index windows files. + The method can be used to set the document properties of the Excel + file created by Qt Xlsx. These properties are visible when you use the + Office Button -> Prepare -> Properties option in Excel and are also + available to external applications that read or index windows files. - The \a property \a key that can be set are: + The \a property \a key that can be set are: - \list - \li title - \li subject - \li creator - \li manager - \li company - \li category - \li keywords - \li description - \li status - \endlist + \list + \li title + \li subject + \li creator + \li manager + \li company + \li category + \li keywords + \li description + \li status + \endlist */ void Document::setDocumentProperty(const QString &key, const QString &property) { - Q_D(Document); - d->documentProperties[key] = property; + Q_D(Document); + d->documentProperties[key] = property; } /*! @@ -1086,8 +1103,8 @@ void Document::setDocumentProperty(const QString &key, const QString &property) */ QStringList Document::documentPropertyNames() const { - Q_D(const Document); - return d->documentProperties.keys(); + Q_D(const Document); + return d->documentProperties.keys(); } /*! @@ -1095,7 +1112,7 @@ QStringList Document::documentPropertyNames() const */ Workbook *Document::workbook() const { - Q_D(const Document); + Q_D(const Document); return d->workbook.data(); } @@ -1104,8 +1121,8 @@ Workbook *Document::workbook() const */ AbstractSheet *Document::sheet(const QString &sheetName) const { - Q_D(const Document); - return d->workbook->sheet(sheetNames().indexOf(sheetName)); + Q_D(const Document); + return d->workbook->sheet(sheetNames().indexOf(sheetName)); } /*! @@ -1114,8 +1131,8 @@ AbstractSheet *Document::sheet(const QString &sheetName) const */ bool Document::addSheet(const QString &name, AbstractSheet::SheetType type) { - Q_D(Document); - return d->workbook->addSheet(name, type); + Q_D(Document); + return d->workbook->addSheet(name, type); } /*! @@ -1124,8 +1141,8 @@ bool Document::addSheet(const QString &name, AbstractSheet::SheetType type) */ bool Document::insertSheet(int index, const QString &name, AbstractSheet::SheetType type) { - Q_D(Document); - return d->workbook->insertSheet(index, name, type); + Q_D(Document); + return d->workbook->insertSheet(index, name, type); } /*! @@ -1134,10 +1151,10 @@ bool Document::insertSheet(int index, const QString &name, AbstractSheet::SheetT */ bool Document::renameSheet(const QString &oldName, const QString &newName) { - Q_D(Document); - if (oldName == newName) - return false; - return d->workbook->renameSheet(sheetNames().indexOf(oldName), newName); + Q_D(Document); + if (oldName == newName) + return false; + return d->workbook->renameSheet(sheetNames().indexOf(oldName), newName); } /*! @@ -1146,10 +1163,10 @@ bool Document::renameSheet(const QString &oldName, const QString &newName) */ bool Document::copySheet(const QString &srcName, const QString &distName) { - Q_D(Document); - if (srcName == distName) - return false; - return d->workbook->copySheet(sheetNames().indexOf(srcName), distName); + Q_D(Document); + if (srcName == distName) + return false; + return d->workbook->copySheet(sheetNames().indexOf(srcName), distName); } /*! @@ -1158,8 +1175,8 @@ bool Document::copySheet(const QString &srcName, const QString &distName) */ bool Document::moveSheet(const QString &srcName, int distIndex) { - Q_D(Document); - return d->workbook->moveSheet(sheetNames().indexOf(srcName), distIndex); + Q_D(Document); + return d->workbook->moveSheet(sheetNames().indexOf(srcName), distIndex); } /*! @@ -1168,8 +1185,8 @@ bool Document::moveSheet(const QString &srcName, int distIndex) */ bool Document::deleteSheet(const QString &name) { - Q_D(Document); - return d->workbook->deleteSheet(sheetNames().indexOf(name)); + Q_D(Document); + return d->workbook->deleteSheet(sheetNames().indexOf(name)); } /*! @@ -1177,9 +1194,9 @@ bool Document::deleteSheet(const QString &name) */ AbstractSheet *Document::currentSheet() const { - Q_D(const Document); + Q_D(const Document); - return d->workbook->activeSheet(); + return d->workbook->activeSheet(); } /*! @@ -1188,11 +1205,11 @@ AbstractSheet *Document::currentSheet() const */ Worksheet *Document::currentWorksheet() const { - AbstractSheet *st = currentSheet(); - if (st && st->sheetType() == AbstractSheet::ST_WorkSheet) - return static_cast(st); - else - return 0; + AbstractSheet *st = currentSheet(); + if (st && st->sheetType() == AbstractSheet::ST_WorkSheet) + return static_cast(st); + else + return 0; } /*! @@ -1201,8 +1218,8 @@ Worksheet *Document::currentWorksheet() const */ bool Document::selectSheet(const QString &name) { - Q_D(Document); - return d->workbook->setActiveSheet(sheetNames().indexOf(name)); + Q_D(Document); + return d->workbook->setActiveSheet(sheetNames().indexOf(name)); } /*! @@ -1211,8 +1228,8 @@ bool Document::selectSheet(const QString &name) */ bool Document::selectSheet(int index) { - Q_D(Document); - return d->workbook->setActiveSheet(index); + Q_D(Document); + return d->workbook->setActiveSheet(index); } /*! @@ -1220,8 +1237,8 @@ bool Document::selectSheet(int index) */ QStringList Document::sheetNames() const { - Q_D(const Document); - return d->workbook->worksheetNames(); + Q_D(const Document); + return d->workbook->worksheetNames(); } /*! @@ -1231,10 +1248,10 @@ QStringList Document::sheetNames() const */ bool Document::save() const { - Q_D(const Document); - QString name = d->packageName.isEmpty() ? d->defaultPackageName : d->packageName; + Q_D(const Document); + QString name = d->packageName.isEmpty() ? d->defaultPackageName : d->packageName; - return saveAs(name); + return saveAs(name); } /*! @@ -1243,10 +1260,10 @@ bool Document::save() const */ bool Document::saveAs(const QString &name) const { - QFile file(name); - if (file.open(QIODevice::WriteOnly)) - return saveAs(&file); - return false; + QFile file(name); + if (file.open(QIODevice::WriteOnly)) + return saveAs(&file); + return false; } /*! @@ -1257,23 +1274,24 @@ bool Document::saveAs(const QString &name) const */ bool Document::saveAs(QIODevice *device) const { - Q_D(const Document); - return d->savePackage(device); + Q_D(const Document); + return d->savePackage(device); } bool Document::isLoadPackage() const { - Q_D(const Document); - return d->isLoad; + Q_D(const Document); + return d->isLoad; } bool Document::load() const { - return isLoadPackage(); + return isLoadPackage(); } -bool Document::copyStyle(const QString &from, const QString &to) { - return DocumentPrivate::copyStyle(from, to); +bool Document::copyStyle(const QString &from, const QString &to) +{ + return DocumentPrivate::copyStyle(from, to); } /*! @@ -1281,75 +1299,72 @@ bool Document::copyStyle(const QString &from, const QString &to) { */ Document::~Document() { - delete d_ptr; + delete d_ptr; } // add by liufeijin 20181025 {{ bool Document::changeimage(int filenoinmidea, QString newfile) { - Q_D(const Document); + Q_D(const Document); QImage newpic(newfile); - + auto mediaFileToLoad = d->workbook->mediaFiles(); - const auto mf = mediaFileToLoad[filenoinmidea]; - - const QString suffix = newfile.mid(newfile.lastIndexOf(QLatin1Char('.'))+1); - QString mimetypemy; - if(QString::compare(QLatin1String("jpg"), suffix, Qt::CaseInsensitive)==0) - mimetypemy=QStringLiteral("image/jpeg"); - if(QString::compare(QLatin1String("bmp"), suffix, Qt::CaseInsensitive)==0) - mimetypemy=QStringLiteral("image/bmp"); - if(QString::compare(QLatin1String("gif"), suffix, Qt::CaseInsensitive)==0) - mimetypemy=QStringLiteral("image/gif"); - if(QString::compare(QLatin1String("png"), suffix, Qt::CaseInsensitive)==0) - mimetypemy=QStringLiteral("image/png"); - - QByteArray ba; - QBuffer buffer(&ba); - buffer.setBuffer(&ba); - buffer.open(QIODevice::WriteOnly); - newpic.save(&buffer,suffix.toLocal8Bit().data()); - - mf->set(ba,suffix,mimetypemy); - mediaFileToLoad[filenoinmidea]=mf; - - return true; + const auto mf = mediaFileToLoad[filenoinmidea]; + + const QString suffix = newfile.mid(newfile.lastIndexOf(QLatin1Char('.')) + 1); + QString mimetypemy; + if (QString::compare(QLatin1String("jpg"), suffix, Qt::CaseInsensitive) == 0) + mimetypemy = QStringLiteral("image/jpeg"); + if (QString::compare(QLatin1String("bmp"), suffix, Qt::CaseInsensitive) == 0) + mimetypemy = QStringLiteral("image/bmp"); + if (QString::compare(QLatin1String("gif"), suffix, Qt::CaseInsensitive) == 0) + mimetypemy = QStringLiteral("image/gif"); + if (QString::compare(QLatin1String("png"), suffix, Qt::CaseInsensitive) == 0) + mimetypemy = QStringLiteral("image/png"); + + QByteArray ba; + QBuffer buffer(&ba); + buffer.setBuffer(&ba); + buffer.open(QIODevice::WriteOnly); + newpic.save(&buffer, suffix.toLocal8Bit().data()); + + mf->set(ba, suffix, mimetypemy); + mediaFileToLoad[filenoinmidea] = mf; + + return true; } // liufeijin }} - /*! Returns map of columns with there maximal width */ QMap Document::getMaximalColumnWidth(int firstRow, int lastRow) { - const int defaultPixelSize = 11; //Default font pixel size of excel? - int maxRows = -1; - int maxCols = -1; + const int defaultPixelSize = 11; // Default font pixel size of excel? + int maxRows = -1; + int maxCols = -1; QMap colWidth; - if (!currentWorksheet()) return colWidth; + if (!currentWorksheet()) + return colWidth; QVector cellLocation = currentWorksheet()->getFullCells(&maxRows, &maxCols); - - for(int i=0; i < cellLocation.size(); i++) - { + + for (int i = 0; i < cellLocation.size(); i++) { int col = cellLocation.at(i).col; int row = cellLocation.at(i).row; - int fs = cellLocation.at(i).cell->format().fontSize(); - if( fs <= 0) - { + int fs = cellLocation.at(i).cell->format().fontSize(); + if (fs <= 0) { fs = defaultPixelSize; } -// QString str = cellLocation.at(i).cell.data()->value().toString(); + // QString str = cellLocation.at(i).cell.data()->value().toString(); QString str = read(row, col).toString(); - double w = str.length() * double(fs) / defaultPixelSize + 1; // width not perfect, but works reasonably well + double w = str.length() * double(fs) / defaultPixelSize + + 1; // width not perfect, but works reasonably well - if( (row >= firstRow) && (row <= lastRow)) - { - if( w > colWidth.value(col)) - { + if ((row >= firstRow) && (row <= lastRow)) { + if (w > colWidth.value(col)) { colWidth.insert(col, int(w)); } } @@ -1358,7 +1373,6 @@ QMap Document::getMaximalColumnWidth(int firstRow, int lastRow) return colWidth; } - /*! Auto ets width in characters of columns with the given \a range. Returns true on success. @@ -1367,16 +1381,14 @@ bool Document::autosizeColumnWidth(const CellRange &range) { bool erg = false; - if( !range.isValid()) - { + if (!range.isValid()) { return false; } const QMap colWidth = getMaximalColumnWidth(range.firstRow(), range.lastRow()); - auto it = colWidth.constBegin(); + auto it = colWidth.constBegin(); while (it != colWidth.constEnd()) { - if( (it.key() >= range.firstColumn()) && (it.key() <= range.lastColumn()) ) - { + if ((it.key() >= range.firstColumn()) && (it.key() <= range.lastColumn())) { erg |= setColumnWidth(it.key(), it.value()); } ++it; @@ -1385,7 +1397,6 @@ bool Document::autosizeColumnWidth(const CellRange &range) return erg; } - /*! Auto sets width in characters \a column . Columns are 1-indexed. Returns true on success. @@ -1395,10 +1406,9 @@ bool Document::autosizeColumnWidth(int column) bool erg = false; const QMap colWidth = getMaximalColumnWidth(); - auto it = colWidth.constBegin(); + auto it = colWidth.constBegin(); while (it != colWidth.constEnd()) { - if( it.key() == column) - { + if (it.key() == column) { erg |= setColumnWidth(it.key(), it.value()); } ++it; @@ -1407,7 +1417,6 @@ bool Document::autosizeColumnWidth(int column) return erg; } - /*! Auto sets width in characters for columns [\a colFirst, \a colLast]. Columns are 1-indexed. Returns true on success. @@ -1419,10 +1428,9 @@ bool Document::autosizeColumnWidth(int colFirst, int colLast) bool erg = false; const QMap colWidth = getMaximalColumnWidth(); - auto it = colWidth.constBegin(); + auto it = colWidth.constBegin(); while (it != colWidth.constEnd()) { - if( (it.key() >= colFirst) && (it.key() <= colLast) ) - { + if ((it.key() >= colFirst) && (it.key() <= colLast)) { erg |= setColumnWidth(it.key(), it.value()); } ++it; @@ -1431,7 +1439,6 @@ bool Document::autosizeColumnWidth(int colFirst, int colLast) return erg; } - /*! Auto sets width in characters for all columns. Returns true on success. @@ -1441,7 +1448,7 @@ bool Document::autosizeColumnWidth(void) bool erg = false; const QMap colWidth = getMaximalColumnWidth(); - auto it = colWidth.constBegin(); + auto it = colWidth.constBegin(); while (it != colWidth.constEnd()) { erg |= setColumnWidth(it.key(), it.value()); ++it; @@ -1450,5 +1457,4 @@ bool Document::autosizeColumnWidth(void) return erg; } - QT_END_NAMESPACE_XLSX diff --git a/QXlsx/source/xlsxdrawing.cpp b/QXlsx/source/xlsxdrawing.cpp index 2675310d..fc37502a 100644 --- a/QXlsx/source/xlsxdrawing.cpp +++ b/QXlsx/source/xlsxdrawing.cpp @@ -1,18 +1,19 @@ // xlsxdrawing.cpp -#include -#include -#include -#include - +#include "xlsxabstractsheet.h" #include "xlsxdrawing_p.h" #include "xlsxdrawinganchor_p.h" -#include "xlsxabstractsheet.h" + +#include +#include +#include +#include QT_BEGIN_NAMESPACE_XLSX Drawing::Drawing(AbstractSheet *sheet, CreateFlag flag) - :AbstractOOXmlFile(flag), sheet(sheet) + : AbstractOOXmlFile(flag) + , sheet(sheet) { workbook = sheet->workbook(); } @@ -30,13 +31,16 @@ void Drawing::saveToXmlFile(QIODevice *device) const writer.writeStartDocument(QStringLiteral("1.0"), true); writer.writeStartElement(QStringLiteral("xdr:wsDr")); - writer.writeAttribute(QStringLiteral("xmlns:xdr"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")); - writer.writeAttribute(QStringLiteral("xmlns:a"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/main")); + writer.writeAttribute( + QStringLiteral("xmlns:xdr"), + QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")); + writer.writeAttribute(QStringLiteral("xmlns:a"), + QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/main")); for (DrawingAnchor *anchor : anchors) anchor->saveToXml(writer); - writer.writeEndElement();//xdr:wsDr + writer.writeEndElement(); // xdr:wsDr writer.writeEndDocument(); } @@ -55,24 +59,20 @@ bool Drawing::loadFromXmlFile(QIODevice *device) QXmlStreamReader reader(device); - while (!reader.atEnd()) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if (reader.tokenType() == QXmlStreamReader::StartElement) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("absoluteAnchor")) // CT_AbsoluteAnchor { - DrawingAbsoluteAnchor * anchor = new DrawingAbsoluteAnchor(this); + DrawingAbsoluteAnchor *anchor = new DrawingAbsoluteAnchor(this); anchor->loadFromXml(reader); - } - else if (reader.name() == QLatin1String("oneCellAnchor")) // CT_OneCellAnchor + } else if (reader.name() == QLatin1String("oneCellAnchor")) // CT_OneCellAnchor { - DrawingOneCellAnchor * anchor = new DrawingOneCellAnchor(this); + DrawingOneCellAnchor *anchor = new DrawingOneCellAnchor(this); anchor->loadFromXml(reader); - } - else if (reader.name() == QLatin1String("twoCellAnchor")) // CT_TwoCellAnchor + } else if (reader.name() == QLatin1String("twoCellAnchor")) // CT_TwoCellAnchor { - DrawingTwoCellAnchor * anchor = new DrawingTwoCellAnchor(this); + DrawingTwoCellAnchor *anchor = new DrawingTwoCellAnchor(this); anchor->loadFromXml(reader); } } diff --git a/QXlsx/source/xlsxdrawinganchor.cpp b/QXlsx/source/xlsxdrawinganchor.cpp index 89d27eb2..e2f108bb 100644 --- a/QXlsx/source/xlsxdrawinganchor.cpp +++ b/QXlsx/source/xlsxdrawinganchor.cpp @@ -1,18 +1,18 @@ // xlsxdrawinganchor.cpp -#include -#include -#include -#include -#include -#include - -#include "xlsxdrawinganchor_p.h" +#include "xlsxchart.h" #include "xlsxdrawing_p.h" +#include "xlsxdrawinganchor_p.h" #include "xlsxmediafile_p.h" -#include "xlsxchart.h" -#include "xlsxworkbook.h" #include "xlsxutility_p.h" +#include "xlsxworkbook.h" + +#include +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE_XLSX @@ -47,19 +47,17 @@ QT_BEGIN_NAMESPACE_XLSX variable and have to be taken into account. */ -//anchor +// anchor DrawingAnchor::DrawingAnchor(Drawing *drawing, ObjectType objectType) - :m_drawing(drawing), m_objectType(objectType) + : m_drawing(drawing) + , m_objectType(objectType) { m_drawing->anchors.append(this); - m_id = m_drawing->anchors.size();//must be unique in one drawing{x}.xml file. + m_id = m_drawing->anchors.size(); // must be unique in one drawing{x}.xml file. } -DrawingAnchor::~DrawingAnchor() -{ - -} +DrawingAnchor::~DrawingAnchor() {} void DrawingAnchor::setObjectPicture(const QImage &img) { @@ -68,7 +66,8 @@ void DrawingAnchor::setObjectPicture(const QImage &img) buffer.open(QIODevice::WriteOnly); img.save(&buffer, "PNG"); - m_pictureFile = std::make_shared(ba, QStringLiteral("png"), QStringLiteral("image/png")); + m_pictureFile = + std::make_shared(ba, QStringLiteral("png"), QStringLiteral("image/png")); m_drawing->workbook->addMediaFile(m_pictureFile); m_objectType = Picture; @@ -76,10 +75,10 @@ void DrawingAnchor::setObjectPicture(const QImage &img) bool DrawingAnchor::getObjectPicture(QImage &img) { - if ( m_pictureFile == nullptr ) + if (m_pictureFile == nullptr) return false; - bool ret = img.loadFromData( m_pictureFile->contents() ); + bool ret = img.loadFromData(m_pictureFile->contents()); return ret; } @@ -91,7 +90,8 @@ void DrawingAnchor::setObjectShape(const QImage &img) buffer.open(QIODevice::WriteOnly); img.save(&buffer, "PNG"); - m_pictureFile = std::make_shared(ba, QStringLiteral("png"), QStringLiteral("image/png")); + m_pictureFile = + std::make_shared(ba, QStringLiteral("png"), QStringLiteral("image/png")); m_drawing->workbook->addMediaFile(m_pictureFile); m_objectType = Shape; @@ -142,35 +142,23 @@ XlsxMarker DrawingAnchor::loadXmlMarker(QXmlStreamReader &reader, const QString { Q_ASSERT(reader.name() == node); - int col = 0; + int col = 0; int colOffset = 0; - int row = 0; + int row = 0; int rowOffset = 0; - while (!reader.atEnd()) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if (reader.tokenType() == QXmlStreamReader::StartElement) - { - if (reader.name() == QLatin1String("col")) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("col")) { col = reader.readElementText().toInt(); - } - else if (reader.name() == QLatin1String("colOff")) - { + } else if (reader.name() == QLatin1String("colOff")) { colOffset = reader.readElementText().toInt(); - } - else if (reader.name() == QLatin1String("row")) - { + } else if (reader.name() == QLatin1String("row")) { row = reader.readElementText().toInt(); - } - else if (reader.name() == QLatin1String("rowOff")) - { + } else if (reader.name() == QLatin1String("rowOff")) { rowOffset = reader.readElementText().toInt(); } - } - else if (reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == node) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == node) { break; } } @@ -200,10 +188,10 @@ void DrawingAnchor::loadXmlObject(QXmlStreamReader &reader) // Shape m_objectType = Shape; - //{{ liufeijin + //{{ liufeijin sp_textlink = reader.attributes().value(QLatin1String("textlink")).toString(); - sp_macro = reader.attributes().value(QLatin1String("macro")).toString(); - //}} + sp_macro = reader.attributes().value(QLatin1String("macro")).toString(); + //}} // // @@ -211,37 +199,36 @@ void DrawingAnchor::loadXmlObject(QXmlStreamReader &reader) // loadXmlObjectShape(reader); // CT_Shape - } - else if (reader.name() == QLatin1String("grpSp")) // + } else if (reader.name() == + QLatin1String("grpSp")) // { - //Group Shape + // Group Shape m_objectType = GroupShape; loadXmlObjectGroupShape(reader); - } - else if (reader.name() == QLatin1String("graphicFrame")) // + } else if (reader.name() == QLatin1String("graphicFrame")) // { - //Graphic Frame + // Graphic Frame m_objectType = GraphicFrame; loadXmlObjectGraphicFrame(reader); - } - else if (reader.name() == QLatin1String("cxnSp")) // + } else if (reader.name() == + QLatin1String("cxnSp")) // { - //Connection Shape + // Connection Shape m_objectType = ConnectionShape; - // {{ liufeijin + // {{ liufeijin cxnSp_macro = reader.attributes().value(QLatin1String("macro")).toString(); - // }} + // }} loadXmlObjectConnectionShape(reader); - } - else if (reader.name() == QLatin1String("pic")) // + } else if (reader.name() == QLatin1String("pic")) // { // Picture m_objectType = Picture; loadXmlObjectPicture(reader); - } - else if (reader.name() == QLatin1String("contentPart")) // + } else if (reader.name() == + QLatin1String("contentPart")) // { // contentPart /// TODO: @@ -251,80 +238,92 @@ void DrawingAnchor::loadXmlObject(QXmlStreamReader &reader) void DrawingAnchor::loadXmlObjectConnectionShape(QXmlStreamReader &reader) { Q_ASSERT(reader.name() == QLatin1String("cxnSp")); - bool hasoffext=false; + bool hasoffext = false; while (!reader.atEnd()) { reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { - if (reader.name() == QLatin1String("cNvPr")){ - xsp_cNvPR_name= reader.attributes().value(QLatin1String("name")).toString(); - xsp_cNvPR_id= reader.attributes().value(QLatin1String("id")).toString(); - }else if(reader.name() == QLatin1String("spPr")){ - xbwMode= reader.attributes().value(QLatin1String("bwMode")).toString(); - }else if(reader.name() == QLatin1String("xfrm")){ - cxnSp_filpV= reader.attributes().value(QLatin1String("flipV")).toString(); - }else if (reader.name() == QLatin1String("off")) { - posTA = loadXmlPos(reader); - hasoffext=true; - } else if (reader.name() == QLatin1String("ext")&&hasoffext) { - extTA = loadXmlExt(reader); - hasoffext=false; - }else if(reader.name() == QLatin1String("prstGeom")){ - xprstGeom_prst= reader.attributes().value(QLatin1String("prst")).toString().trimmed(); - }else if(reader.name() == QLatin1String("ln")){ - xIn_algn= reader.attributes().value(QLatin1String("algn")).toString().trimmed(); - xIn_cmpd= reader.attributes().value(QLatin1String("cmpd")).toString().trimmed(); - xIn_cap= reader.attributes().value(QLatin1String("cap")).toString().trimmed(); - xIn_w= reader.attributes().value(QLatin1String("w")).toString().trimmed(); - }else if(reader.name() == QLatin1String("headEnd")){ - x_headEnd_w= reader.attributes().value(QLatin1String("w")).toString().trimmed(); - x_headEnd_len= reader.attributes().value(QLatin1String("len")).toString().trimmed(); - x_headEnd_tyep= reader.attributes().value(QLatin1String("type")).toString().trimmed(); - }else if(reader.name() == QLatin1String("tailEnd")){ - x_tailEnd_w= reader.attributes().value(QLatin1String("w")).toString().trimmed(); - x_tailEnd_len= reader.attributes().value(QLatin1String("len")).toString().trimmed(); - x_tailEnd_tyep= reader.attributes().value(QLatin1String("type")).toString().trimmed(); - }else if(reader.name() == QLatin1String("lnRef")){ - Style_inref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed(); + if (reader.name() == QLatin1String("cNvPr")) { + xsp_cNvPR_name = reader.attributes().value(QLatin1String("name")).toString(); + xsp_cNvPR_id = reader.attributes().value(QLatin1String("id")).toString(); + } else if (reader.name() == QLatin1String("spPr")) { + xbwMode = reader.attributes().value(QLatin1String("bwMode")).toString(); + } else if (reader.name() == QLatin1String("xfrm")) { + cxnSp_filpV = reader.attributes().value(QLatin1String("flipV")).toString(); + } else if (reader.name() == QLatin1String("off")) { + posTA = loadXmlPos(reader); + hasoffext = true; + } else if (reader.name() == QLatin1String("ext") && hasoffext) { + extTA = loadXmlExt(reader); + hasoffext = false; + } else if (reader.name() == QLatin1String("prstGeom")) { + xprstGeom_prst = + reader.attributes().value(QLatin1String("prst")).toString().trimmed(); + } else if (reader.name() == QLatin1String("ln")) { + xIn_algn = reader.attributes().value(QLatin1String("algn")).toString().trimmed(); + xIn_cmpd = reader.attributes().value(QLatin1String("cmpd")).toString().trimmed(); + xIn_cap = reader.attributes().value(QLatin1String("cap")).toString().trimmed(); + xIn_w = reader.attributes().value(QLatin1String("w")).toString().trimmed(); + } else if (reader.name() == QLatin1String("headEnd")) { + x_headEnd_w = reader.attributes().value(QLatin1String("w")).toString().trimmed(); + x_headEnd_len = + reader.attributes().value(QLatin1String("len")).toString().trimmed(); + x_headEnd_tyep = + reader.attributes().value(QLatin1String("type")).toString().trimmed(); + } else if (reader.name() == QLatin1String("tailEnd")) { + x_tailEnd_w = reader.attributes().value(QLatin1String("w")).toString().trimmed(); + x_tailEnd_len = + reader.attributes().value(QLatin1String("len")).toString().trimmed(); + x_tailEnd_tyep = + reader.attributes().value(QLatin1String("type")).toString().trimmed(); + } else if (reader.name() == QLatin1String("lnRef")) { + Style_inref_idx = + reader.attributes().value(QLatin1String("idx")).toString().trimmed(); reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { - if(reader.name() == QLatin1String("schemeClr")){ - Style_inref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed(); + if (reader.name() == QLatin1String("schemeClr")) { + Style_inref_val = + reader.attributes().value(QLatin1String("val")).toString().trimmed(); } } - }else if(reader.name() == QLatin1String("fillRef")){ - style_fillref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed(); + } else if (reader.name() == QLatin1String("fillRef")) { + style_fillref_idx = + reader.attributes().value(QLatin1String("idx")).toString().trimmed(); reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { - if(reader.name() == QLatin1String("schemeClr")){ - style_fillref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed(); + if (reader.name() == QLatin1String("schemeClr")) { + style_fillref_val = + reader.attributes().value(QLatin1String("val")).toString().trimmed(); } } - }else if(reader.name() == QLatin1String("effectRef")){ - style_effectref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed(); + } else if (reader.name() == QLatin1String("effectRef")) { + style_effectref_idx = + reader.attributes().value(QLatin1String("idx")).toString().trimmed(); reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { - if(reader.name() == QLatin1String("schemeClr")){ - style_effectref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed(); + if (reader.name() == QLatin1String("schemeClr")) { + style_effectref_val = + reader.attributes().value(QLatin1String("val")).toString().trimmed(); } } - }else if(reader.name() == QLatin1String("fontRef")){ - style_forntref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed(); + } else if (reader.name() == QLatin1String("fontRef")) { + style_forntref_idx = + reader.attributes().value(QLatin1String("idx")).toString().trimmed(); reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { - if(reader.name() == QLatin1String("schemeClr")){ - style_forntref_val=reader.attributes().value(QLatin1String("val")).toString().trimmed(); + if (reader.name() == QLatin1String("schemeClr")) { + style_forntref_val = + reader.attributes().value(QLatin1String("val")).toString().trimmed(); } } } - } else if (reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QLatin1String("cxnSp")) { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("cxnSp")) { break; } } return; - } void DrawingAnchor::loadXmlObjectGraphicFrame(QXmlStreamReader &reader) @@ -335,29 +334,30 @@ void DrawingAnchor::loadXmlObjectGraphicFrame(QXmlStreamReader &reader) reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("chart")) { - QString rId = reader.attributes().value(QLatin1String("r:id")).toString(); + QString rId = reader.attributes().value(QLatin1String("r:id")).toString(); QString name = m_drawing->relationships()->getRelationshipById(rId).target; const auto parts = splitPath(m_drawing->filePath()); - QString path = QDir::cleanPath(parts.first() + QLatin1String("/") + name); + QString path = QDir::cleanPath(parts.first() + QLatin1String("/") + name); - bool exist = false; - QList > cfs = m_drawing->workbook->chartFiles(); - for (int i=0; i> cfs = m_drawing->workbook->chartFiles(); + for (int i = 0; i < cfs.size(); ++i) { if (cfs[i]->filePath() == path) { - //already exist - exist = true; + // already exist + exist = true; m_chartFile = cfs[i]; } } if (!exist) { - m_chartFile = QSharedPointer (new Chart(m_drawing->sheet, Chart::F_LoadFromExists)); + m_chartFile = + QSharedPointer(new Chart(m_drawing->sheet, Chart::F_LoadFromExists)); m_chartFile->setFilePath(path); m_drawing->workbook->addChartFile(m_chartFile); } } - } else if (reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QLatin1String("graphicFrame")) { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("graphicFrame")) { break; } } @@ -378,18 +378,18 @@ void DrawingAnchor::loadXmlObjectPicture(QXmlStreamReader &reader) reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("blip")) { - QString rId = reader.attributes().value(QLatin1String("r:embed")).toString(); + QString rId = reader.attributes().value(QLatin1String("r:embed")).toString(); QString name = m_drawing->relationships()->getRelationshipById(rId).target; const auto parts = splitPath(m_drawing->filePath()); - QString path = QDir::cleanPath(parts.first() + QLatin1String("/") + name); + QString path = QDir::cleanPath(parts.first() + QLatin1String("/") + name); - bool exist = false; + bool exist = false; const auto mfs = m_drawing->workbook->mediaFiles(); for (const auto &mf : mfs) { if (mf->fileName() == path) { - //already exist - exist = true; + // already exist + exist = true; m_pictureFile = mf; } } @@ -398,8 +398,8 @@ void DrawingAnchor::loadXmlObjectPicture(QXmlStreamReader &reader) m_drawing->workbook->addMediaFile(m_pictureFile, true); } } - } else if (reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QLatin1String("pic")) { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("pic")) { break; } } @@ -427,41 +427,30 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader) - + */ Q_ASSERT(reader.name() == QLatin1String("sp")); - while (!reader.atEnd()) - { + while (!reader.atEnd()) { reader.readNextStartElement(); // qDebug() << __FUNCTION__ << reader.name().toString(); - if (reader.tokenType() == QXmlStreamReader::StartElement) - { - if (reader.name() == QLatin1String("nvSpPr")) - { - - } - else if (reader.name() == QLatin1String("spPr")) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("nvSpPr")) { - } - else if (reader.name() == QLatin1String("style")) - { + } else if (reader.name() == QLatin1String("spPr")) { - } - else if (reader.name() == QLatin1String("txBody")) - { + } else if (reader.name() == QLatin1String("style")) { + } else if (reader.name() == QLatin1String("txBody")) { } - } - else if (reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QLatin1String("sp")) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("sp")) { break; } } @@ -484,10 +473,9 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader) sp_blip_cstate=reader.attributes().value(QLatin1String("cstate")).toString(); rId=sp_blip_rembed; QString name = m_drawing->relationships()->getRelationshipById(rId).target; - QString path = QDir::cleanPath(splitPath(m_drawing->filePath())[0] + QLatin1String("/") + name); - bool exist = false; - QList > mfs = m_drawing->workbook->mediaFiles(); - for (int i=0; ifilePath())[0] + + QLatin1String("/") + name); bool exist = false; QList > mfs = + m_drawing->workbook->mediaFiles(); for (int i=0; ifileName() == path) { @@ -515,10 +503,12 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader) { // dev24 : fixed for old Qt 5 - rotWithShapeTA = reader.attributes().value(QLatin1String("rotWithShape")).toString().toInt(); - dpiTA = reader.attributes().value(QLatin1String("dpi")).toString().toInt(); + rotWithShapeTA = + reader.attributes().value(QLatin1String("rotWithShape")).toString().toInt(); dpiTA = + reader.attributes().value(QLatin1String("dpi")).toString().toInt(); - // rotWithShapeTA = reader.attributes().value(QLatin1String("rotWithShape")).toInt(); + // rotWithShapeTA = + reader.attributes().value(QLatin1String("rotWithShape")).toInt(); // dpiTA = reader.attributes().value(QLatin1String("dpi")).toInt(); }else if(reader.name() == QLatin1String("cNvPr")) @@ -555,7 +545,8 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader) } else if(reader.name() == QLatin1String("lnRef")) { - Style_inref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed(); + Style_inref_idx= + reader.attributes().value(QLatin1String("idx")).toString().trimmed(); reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { if(reader.name() == QLatin1String("schemeClr")){ @@ -565,7 +556,8 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader) } else if(reader.name() == QLatin1String("fillRef")) { - style_fillref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed(); + style_fillref_idx= + reader.attributes().value(QLatin1String("idx")).toString().trimmed(); reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { @@ -577,7 +569,8 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader) } else if(reader.name() == QLatin1String("effectRef")) { - style_effectref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed(); + style_effectref_idx= + reader.attributes().value(QLatin1String("idx")).toString().trimmed(); reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { if(reader.name() == QLatin1String("schemeClr")){ @@ -587,7 +580,8 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader) } else if(reader.name() == QLatin1String("fontRef")) { - style_forntref_idx= reader.attributes().value(QLatin1String("idx")).toString().trimmed(); + style_forntref_idx= + reader.attributes().value(QLatin1String("idx")).toString().trimmed(); reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { if(reader.name() == QLatin1String("schemeClr")){ @@ -621,12 +615,14 @@ void DrawingAnchor::saveXmlExt(QXmlStreamWriter &writer, const QSize &ext) const writer.writeStartElement(QStringLiteral("xdr:ext")); writer.writeAttribute(QStringLiteral("cx"), QString::number(ext.width())); writer.writeAttribute(QStringLiteral("cy"), QString::number(ext.height())); - writer.writeEndElement(); //xdr:ext + writer.writeEndElement(); // xdr:ext } -void DrawingAnchor::saveXmlMarker(QXmlStreamWriter &writer, const XlsxMarker &marker, const QString &node) const +void DrawingAnchor::saveXmlMarker(QXmlStreamWriter &writer, + const XlsxMarker &marker, + const QString &node) const { - writer.writeStartElement(node); //xdr:from or xdr:to + writer.writeStartElement(node); // xdr:from or xdr:to writer.writeTextElement(QStringLiteral("xdr:col"), QString::number(marker.col())); writer.writeTextElement(QStringLiteral("xdr:colOff"), QString::number(marker.colOff())); writer.writeTextElement(QStringLiteral("xdr:row"), QString::number(marker.row())); @@ -650,109 +646,111 @@ void DrawingAnchor::saveXmlObject(QXmlStreamWriter &writer) const void DrawingAnchor::saveXmlObjectConnectionShape(QXmlStreamWriter &writer) const { - writer.writeStartElement(QStringLiteral("xdr:cxnSp")); ///? + writer.writeStartElement(QStringLiteral("xdr:cxnSp")); ///? writer.writeAttribute(QStringLiteral("macro"), cxnSp_macro); - writer.writeStartElement(QStringLiteral("xdr:nvCxnSpPr")); - writer.writeEmptyElement(QStringLiteral("xdr:cNvPr")); - writer.writeAttribute(QStringLiteral("id"), xsp_cNvPR_id); - writer.writeAttribute(QStringLiteral("name"), xsp_cNvPR_name); - writer.writeEmptyElement(QStringLiteral("xdr:cNvCxnSpPr")); - writer.writeEndElement(); //xdr:nvCxnSpPr + writer.writeStartElement(QStringLiteral("xdr:nvCxnSpPr")); + writer.writeEmptyElement(QStringLiteral("xdr:cNvPr")); + writer.writeAttribute(QStringLiteral("id"), xsp_cNvPR_id); + writer.writeAttribute(QStringLiteral("name"), xsp_cNvPR_name); + writer.writeEmptyElement(QStringLiteral("xdr:cNvCxnSpPr")); + writer.writeEndElement(); // xdr:nvCxnSpPr writer.writeStartElement(QStringLiteral("xdr:spPr")); - if(!xbwMode.isNull()){ - writer.writeAttribute(QStringLiteral("bwMode"), xbwMode); + if (!xbwMode.isNull()) { + writer.writeAttribute(QStringLiteral("bwMode"), xbwMode); } - writer.writeStartElement(QStringLiteral("a:xfrm")); - if(!cxnSp_filpV.isEmpty()){ - writer.writeAttribute(QStringLiteral("flipV"), cxnSp_filpV);} - writer.writeEmptyElement(QStringLiteral("a:off")); - writer.writeAttribute(QStringLiteral("x"), QString::number(posTA.x())); - writer.writeAttribute(QStringLiteral("y"), QString::number(posTA.y())); - writer.writeEmptyElement(QStringLiteral("a:ext")); - writer.writeAttribute(QStringLiteral("cx"), QString::number(extTA.width())); - writer.writeAttribute(QStringLiteral("cy"), QString::number(extTA.height())); - writer.writeEndElement(); //a:xfrm - - writer.writeStartElement(QStringLiteral("a:prstGeom")); - writer.writeAttribute(QStringLiteral("prst"), xprstGeom_prst); - writer.writeEmptyElement(QStringLiteral("a:avLst")); - writer.writeEndElement(); //a:prstGeom - - - writer.writeStartElement(QStringLiteral("a:ln")); - if(!xIn_w.isEmpty()&&!xIn_cap.isEmpty()){ - if(!xIn_w.isEmpty()){ - writer.writeAttribute(QStringLiteral("w"), xIn_w); - } - if(!xIn_cap.isEmpty()){ - writer.writeAttribute(QStringLiteral("cap"), xIn_cap); - } - if(!xIn_cmpd.isEmpty()){ - writer.writeAttribute(QStringLiteral("cmpd"), xIn_cmpd); - } - if(!xIn_algn.isEmpty()){ - writer.writeAttribute(QStringLiteral("algn"), xIn_algn); - } - } - if((!x_headEnd_tyep.isEmpty())||(!x_headEnd_w.isEmpty())||(!x_headEnd_len.isEmpty())){ - writer.writeEmptyElement(QStringLiteral("a:headEnd")); - if(!x_headEnd_tyep.isEmpty()){ - writer.writeAttribute(QStringLiteral("type"),x_headEnd_tyep); - } - if(!x_headEnd_w.isEmpty()){ - writer.writeAttribute(QStringLiteral("w"),x_headEnd_w); - } - if(!x_headEnd_len.isEmpty()){ - writer.writeAttribute(QStringLiteral("len"),x_headEnd_len); - } - } - if((!x_tailEnd_tyep.isEmpty())||(!x_tailEnd_w.isEmpty())||(!x_tailEnd_len.isEmpty())){ - writer.writeEmptyElement(QStringLiteral("a:tailEnd")); - if(!x_tailEnd_tyep.isEmpty()){ - writer.writeAttribute(QStringLiteral("type"),x_tailEnd_tyep);} - if(!x_tailEnd_w.isEmpty()){ - writer.writeAttribute(QStringLiteral("w"),x_tailEnd_w);} - if(!x_tailEnd_len.isEmpty()){ - writer.writeAttribute(QStringLiteral("len"),x_tailEnd_len);} - } - - writer.writeEndElement();//a:ln - - - writer.writeEndElement(); //xdr:spPr - // writer style - - writer.writeStartElement(QStringLiteral("xdr:style"));// style - writer.writeStartElement(QStringLiteral("a:lnRef"));//lnRef - writer.writeAttribute(QStringLiteral("idx"),Style_inref_idx); - writer.writeStartElement(QStringLiteral("a:schemeClr"));//val - writer.writeAttribute(QStringLiteral("val"),Style_inref_val); - writer.writeEndElement(); // val - writer.writeEndElement(); // lnRef - writer.writeStartElement(QStringLiteral("a:fillRef"));//fillRef - writer.writeAttribute(QStringLiteral("idx"),style_fillref_idx); - writer.writeStartElement(QStringLiteral("a:schemeClr"));//val - writer.writeAttribute(QStringLiteral("val"),style_fillref_val); - writer.writeEndElement(); // val - writer.writeEndElement(); // fillRef - writer.writeStartElement(QStringLiteral("a:effectRef"));//effectRef - writer.writeAttribute(QStringLiteral("idx"),style_effectref_idx); - writer.writeStartElement(QStringLiteral("a:schemeClr"));//val - writer.writeAttribute(QStringLiteral("val"),style_effectref_val); - writer.writeEndElement(); // val - writer.writeEndElement(); // effectRef - writer.writeStartElement(QStringLiteral("a:fontRef"));//fontRef - writer.writeAttribute(QStringLiteral("idx"),style_forntref_idx); - writer.writeStartElement(QStringLiteral("a:schemeClr"));//val - writer.writeAttribute(QStringLiteral("val"),style_forntref_val); - writer.writeEndElement(); // val - writer.writeEndElement(); // fontRef - writer.writeEndElement(); // style - - writer.writeEndElement(); //xdr:sp + writer.writeStartElement(QStringLiteral("a:xfrm")); + if (!cxnSp_filpV.isEmpty()) { + writer.writeAttribute(QStringLiteral("flipV"), cxnSp_filpV); + } + writer.writeEmptyElement(QStringLiteral("a:off")); + writer.writeAttribute(QStringLiteral("x"), QString::number(posTA.x())); + writer.writeAttribute(QStringLiteral("y"), QString::number(posTA.y())); + writer.writeEmptyElement(QStringLiteral("a:ext")); + writer.writeAttribute(QStringLiteral("cx"), QString::number(extTA.width())); + writer.writeAttribute(QStringLiteral("cy"), QString::number(extTA.height())); + writer.writeEndElement(); // a:xfrm + + writer.writeStartElement(QStringLiteral("a:prstGeom")); + writer.writeAttribute(QStringLiteral("prst"), xprstGeom_prst); + writer.writeEmptyElement(QStringLiteral("a:avLst")); + writer.writeEndElement(); // a:prstGeom + + writer.writeStartElement(QStringLiteral("a:ln")); + if (!xIn_w.isEmpty() && !xIn_cap.isEmpty()) { + if (!xIn_w.isEmpty()) { + writer.writeAttribute(QStringLiteral("w"), xIn_w); + } + if (!xIn_cap.isEmpty()) { + writer.writeAttribute(QStringLiteral("cap"), xIn_cap); + } + if (!xIn_cmpd.isEmpty()) { + writer.writeAttribute(QStringLiteral("cmpd"), xIn_cmpd); + } + if (!xIn_algn.isEmpty()) { + writer.writeAttribute(QStringLiteral("algn"), xIn_algn); + } + } + if ((!x_headEnd_tyep.isEmpty()) || (!x_headEnd_w.isEmpty()) || (!x_headEnd_len.isEmpty())) { + writer.writeEmptyElement(QStringLiteral("a:headEnd")); + if (!x_headEnd_tyep.isEmpty()) { + writer.writeAttribute(QStringLiteral("type"), x_headEnd_tyep); + } + if (!x_headEnd_w.isEmpty()) { + writer.writeAttribute(QStringLiteral("w"), x_headEnd_w); + } + if (!x_headEnd_len.isEmpty()) { + writer.writeAttribute(QStringLiteral("len"), x_headEnd_len); + } + } + if ((!x_tailEnd_tyep.isEmpty()) || (!x_tailEnd_w.isEmpty()) || (!x_tailEnd_len.isEmpty())) { + writer.writeEmptyElement(QStringLiteral("a:tailEnd")); + if (!x_tailEnd_tyep.isEmpty()) { + writer.writeAttribute(QStringLiteral("type"), x_tailEnd_tyep); + } + if (!x_tailEnd_w.isEmpty()) { + writer.writeAttribute(QStringLiteral("w"), x_tailEnd_w); + } + if (!x_tailEnd_len.isEmpty()) { + writer.writeAttribute(QStringLiteral("len"), x_tailEnd_len); + } + } + + writer.writeEndElement(); // a:ln + + writer.writeEndElement(); // xdr:spPr + // writer style + + writer.writeStartElement(QStringLiteral("xdr:style")); // style + writer.writeStartElement(QStringLiteral("a:lnRef")); // lnRef + writer.writeAttribute(QStringLiteral("idx"), Style_inref_idx); + writer.writeStartElement(QStringLiteral("a:schemeClr")); // val + writer.writeAttribute(QStringLiteral("val"), Style_inref_val); + writer.writeEndElement(); // val + writer.writeEndElement(); // lnRef + writer.writeStartElement(QStringLiteral("a:fillRef")); // fillRef + writer.writeAttribute(QStringLiteral("idx"), style_fillref_idx); + writer.writeStartElement(QStringLiteral("a:schemeClr")); // val + writer.writeAttribute(QStringLiteral("val"), style_fillref_val); + writer.writeEndElement(); // val + writer.writeEndElement(); // fillRef + writer.writeStartElement(QStringLiteral("a:effectRef")); // effectRef + writer.writeAttribute(QStringLiteral("idx"), style_effectref_idx); + writer.writeStartElement(QStringLiteral("a:schemeClr")); // val + writer.writeAttribute(QStringLiteral("val"), style_effectref_val); + writer.writeEndElement(); // val + writer.writeEndElement(); // effectRef + writer.writeStartElement(QStringLiteral("a:fontRef")); // fontRef + writer.writeAttribute(QStringLiteral("idx"), style_forntref_idx); + writer.writeStartElement(QStringLiteral("a:schemeClr")); // val + writer.writeAttribute(QStringLiteral("val"), style_forntref_val); + writer.writeEndElement(); // val + writer.writeEndElement(); // fontRef + writer.writeEndElement(); // style + + writer.writeEndElement(); // xdr:sp } void DrawingAnchor::saveXmlObjectGraphicFrame(QXmlStreamWriter &writer) const @@ -765,26 +763,32 @@ void DrawingAnchor::saveXmlObjectGraphicFrame(QXmlStreamWriter &writer) const writer.writeAttribute(QStringLiteral("id"), QString::number(m_id)); writer.writeAttribute(QStringLiteral("name"), QStringLiteral("Chart %1").arg(m_id)); writer.writeEmptyElement(QStringLiteral("xdr:cNvGraphicFramePr")); - writer.writeEndElement();//xdr:nvGraphicFramePr + writer.writeEndElement(); // xdr:nvGraphicFramePr writer.writeStartElement(QStringLiteral("xdr:xfrm")); - writer.writeEndElement(); //xdr:xfrm + writer.writeEndElement(); // xdr:xfrm writer.writeStartElement(QStringLiteral("a:graphic")); writer.writeStartElement(QStringLiteral("a:graphicData")); - writer.writeAttribute(QStringLiteral("uri"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart")); + writer.writeAttribute(QStringLiteral("uri"), + QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart")); int idx = m_drawing->workbook->chartFiles().indexOf(m_chartFile); - m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/chart"), QStringLiteral("../charts/chart%1.xml").arg(idx+1)); + m_drawing->relationships()->addDocumentRelationship( + QStringLiteral("/chart"), QStringLiteral("../charts/chart%1.xml").arg(idx + 1)); writer.writeEmptyElement(QStringLiteral("c:chart")); - writer.writeAttribute(QStringLiteral("xmlns:c"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart")); - writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); - writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(m_drawing->relationships()->count())); - - writer.writeEndElement(); //a:graphicData - writer.writeEndElement(); //a:graphic - writer.writeEndElement(); //xdr:graphicFrame + writer.writeAttribute(QStringLiteral("xmlns:c"), + QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart")); + writer.writeAttribute( + QStringLiteral("xmlns:r"), + QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); + writer.writeAttribute(QStringLiteral("r:id"), + QStringLiteral("rId%1").arg(m_drawing->relationships()->count())); + + writer.writeEndElement(); // a:graphicData + writer.writeEndElement(); // a:graphic + writer.writeEndElement(); // xdr:graphicFrame } void DrawingAnchor::saveXmlObjectGroupShape(QXmlStreamWriter &writer) const @@ -800,39 +804,43 @@ void DrawingAnchor::saveXmlObjectPicture(QXmlStreamWriter &writer) const writer.writeStartElement(QStringLiteral("xdr:nvPicPr")); writer.writeEmptyElement(QStringLiteral("xdr:cNvPr")); - writer.writeAttribute(QStringLiteral("id"), QString::number(m_id+1)); // liufeijin + writer.writeAttribute(QStringLiteral("id"), QString::number(m_id + 1)); // liufeijin writer.writeAttribute(QStringLiteral("name"), QStringLiteral("Picture %1").arg(m_id)); writer.writeStartElement(QStringLiteral("xdr:cNvPicPr")); writer.writeEmptyElement(QStringLiteral("a:picLocks")); writer.writeAttribute(QStringLiteral("noChangeAspect"), QStringLiteral("1")); - writer.writeEndElement(); //xdr:cNvPicPr + writer.writeEndElement(); // xdr:cNvPicPr - writer.writeEndElement(); //xdr:nvPicPr + writer.writeEndElement(); // xdr:nvPicPr - m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/image"), QStringLiteral("../media/image%1.%2") - .arg(m_pictureFile->index()+1) - .arg(m_pictureFile->suffix())); + m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/image"), + QStringLiteral("../media/image%1.%2") + .arg(m_pictureFile->index() + 1) + .arg(m_pictureFile->suffix())); writer.writeStartElement(QStringLiteral("xdr:blipFill")); writer.writeEmptyElement(QStringLiteral("a:blip")); - writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); - writer.writeAttribute(QStringLiteral("r:embed"), QStringLiteral("rId%1").arg(m_drawing->relationships()->count())); + writer.writeAttribute( + QStringLiteral("xmlns:r"), + QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); + writer.writeAttribute(QStringLiteral("r:embed"), + QStringLiteral("rId%1").arg(m_drawing->relationships()->count())); writer.writeStartElement(QStringLiteral("a:stretch")); writer.writeEmptyElement(QStringLiteral("a:fillRect")); - writer.writeEndElement(); //a:stretch - writer.writeEndElement();//xdr:blipFill + writer.writeEndElement(); // a:stretch + writer.writeEndElement(); // xdr:blipFill writer.writeStartElement(QStringLiteral("xdr:spPr")); writer.writeStartElement(QStringLiteral("a:prstGeom")); writer.writeAttribute(QStringLiteral("prst"), QStringLiteral("rect")); writer.writeEmptyElement(QStringLiteral("a:avLst")); - writer.writeEndElement(); //a:prstGeom + writer.writeEndElement(); // a:prstGeom - writer.writeEndElement(); //xdr:spPr + writer.writeEndElement(); // xdr:spPr - writer.writeEndElement(); //xdr:pic + writer.writeEndElement(); // xdr:pic } int DrawingAnchor::getm_id() @@ -842,142 +850,152 @@ int DrawingAnchor::getm_id() void DrawingAnchor::saveXmlObjectShape(QXmlStreamWriter &writer) const { -//{{ liufeijin - writer.writeStartElement(QStringLiteral("xdr:sp")); //xdr:sp - writer.writeAttribute(QStringLiteral("macro"), sp_macro); - writer.writeAttribute(QStringLiteral("textlink"),sp_textlink); + //{{ liufeijin + writer.writeStartElement(QStringLiteral("xdr:sp")); // xdr:sp + writer.writeAttribute(QStringLiteral("macro"), sp_macro); + writer.writeAttribute(QStringLiteral("textlink"), sp_textlink); - writer.writeStartElement(QStringLiteral("xdr:nvSpPr"));//xdr:nvSpPr + writer.writeStartElement(QStringLiteral("xdr:nvSpPr")); // xdr:nvSpPr - writer.writeStartElement(QStringLiteral("xdr:cNvPr")); - writer.writeAttribute(QStringLiteral("id"), xsp_cNvPR_id); - writer.writeAttribute(QStringLiteral("name"), xsp_cNvPR_name); - writer.writeStartElement(QStringLiteral("a:extLst")); - writer.writeEndElement(); - writer.writeEndElement();//xdr:cNvPr + writer.writeStartElement(QStringLiteral("xdr:cNvPr")); + writer.writeAttribute(QStringLiteral("id"), xsp_cNvPR_id); + writer.writeAttribute(QStringLiteral("name"), xsp_cNvPR_name); + writer.writeStartElement(QStringLiteral("a:extLst")); + writer.writeEndElement(); + writer.writeEndElement(); // xdr:cNvPr - writer.writeEmptyElement(QStringLiteral("xdr:cNvSpPr")); + writer.writeEmptyElement(QStringLiteral("xdr:cNvSpPr")); - writer.writeEndElement(); //xdr:nvSpPr + writer.writeEndElement(); // xdr:nvSpPr writer.writeStartElement(QStringLiteral("xdr:spPr")); - if(!xbwMode.isNull()){ - writer.writeAttribute(QStringLiteral("bwMode"), xbwMode); + if (!xbwMode.isNull()) { + writer.writeAttribute(QStringLiteral("bwMode"), xbwMode); } - writer.writeStartElement(QStringLiteral("a:xfrm")); - writer.writeEmptyElement(QStringLiteral("a:off")); - writer.writeAttribute(QStringLiteral("x"), QString::number(posTA.x())); - writer.writeAttribute(QStringLiteral("y"), QString::number(posTA.y())); - writer.writeEmptyElement(QStringLiteral("a:ext")); - writer.writeAttribute(QStringLiteral("cx"), QString::number(extTA.width())); - writer.writeAttribute(QStringLiteral("cy"), QString::number(extTA.height())); - writer.writeEndElement(); //a:xfrm - - writer.writeStartElement(QStringLiteral("a:prstGeom")); - writer.writeAttribute(QStringLiteral("prst"), xprstGeom_prst); - writer.writeEmptyElement(QStringLiteral("a:avLst")); - writer.writeEndElement(); //a:prstGeom - - if(m_pictureFile){ - m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/image"), QStringLiteral("../media/image%1.%2").arg(m_pictureFile->index()+1).arg(m_pictureFile->suffix())); + writer.writeStartElement(QStringLiteral("a:xfrm")); + writer.writeEmptyElement(QStringLiteral("a:off")); + writer.writeAttribute(QStringLiteral("x"), QString::number(posTA.x())); + writer.writeAttribute(QStringLiteral("y"), QString::number(posTA.y())); + writer.writeEmptyElement(QStringLiteral("a:ext")); + writer.writeAttribute(QStringLiteral("cx"), QString::number(extTA.width())); + writer.writeAttribute(QStringLiteral("cy"), QString::number(extTA.height())); + writer.writeEndElement(); // a:xfrm + + writer.writeStartElement(QStringLiteral("a:prstGeom")); + writer.writeAttribute(QStringLiteral("prst"), xprstGeom_prst); + writer.writeEmptyElement(QStringLiteral("a:avLst")); + writer.writeEndElement(); // a:prstGeom + + if (m_pictureFile) { + m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/image"), + QStringLiteral("../media/image%1.%2") + .arg(m_pictureFile->index() + 1) + .arg(m_pictureFile->suffix())); writer.writeStartElement(QStringLiteral("a:blipFill")); writer.writeAttribute(QStringLiteral("dpi"), QString::number(dpiTA)); - writer.writeAttribute(QStringLiteral("rotWithShape"),QString::number(rotWithShapeTA)); - - writer.writeStartElement(QStringLiteral("a:blip")); - 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 - writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); - if(!sp_blip_cstate.isNull()){ - writer.writeAttribute(QStringLiteral("cstate"), sp_blip_cstate); - } - writer.writeEndElement();//a:blip - writer.writeEmptyElement(QStringLiteral("a:srcRect")); - writer.writeStartElement(QStringLiteral("a:stretch")); - writer.writeEmptyElement(QStringLiteral("a:fillRect")); - writer.writeEndElement(); //a:stretch - writer.writeEndElement();//a:blipFill - } + writer.writeAttribute(QStringLiteral("rotWithShape"), QString::number(rotWithShapeTA)); + + writer.writeStartElement(QStringLiteral("a:blip")); + 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 + writer.writeAttribute( + QStringLiteral("xmlns:r"), + QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); + if (!sp_blip_cstate.isNull()) { + writer.writeAttribute(QStringLiteral("cstate"), sp_blip_cstate); + } + writer.writeEndElement(); // a:blip + writer.writeEmptyElement(QStringLiteral("a:srcRect")); + writer.writeStartElement(QStringLiteral("a:stretch")); + writer.writeEmptyElement(QStringLiteral("a:fillRect")); + writer.writeEndElement(); // a:stretch + writer.writeEndElement(); // a:blipFill + } writer.writeStartElement(QStringLiteral("a:ln")); - if(!xIn_w.isEmpty()&&!xIn_cap.isEmpty()){ - if(!xIn_w.isEmpty()){ - writer.writeAttribute(QStringLiteral("w"), xIn_w); - } - if(!xIn_cap.isEmpty()){ - writer.writeAttribute(QStringLiteral("cap"), xIn_cap); - } - if(!xIn_cmpd.isEmpty()){ - writer.writeAttribute(QStringLiteral("cmpd"), xIn_cmpd); - } - if(!xIn_algn.isEmpty()){ - writer.writeAttribute(QStringLiteral("algn"), xIn_algn); - } - } - if((!x_headEnd_tyep.isEmpty())||(!x_headEnd_w.isEmpty())||(!x_headEnd_len.isEmpty())){ - writer.writeEmptyElement(QStringLiteral("a:headEnd")); - if(!x_headEnd_tyep.isEmpty()){ - writer.writeAttribute(QStringLiteral("type"),x_headEnd_tyep); - } - if(!x_headEnd_w.isEmpty()){ - writer.writeAttribute(QStringLiteral("w"),x_headEnd_w); - } - if(!x_headEnd_len.isEmpty()){ - writer.writeAttribute(QStringLiteral("len"),x_headEnd_len); - } + if (!xIn_w.isEmpty() && !xIn_cap.isEmpty()) { + if (!xIn_w.isEmpty()) { + writer.writeAttribute(QStringLiteral("w"), xIn_w); + } + if (!xIn_cap.isEmpty()) { + writer.writeAttribute(QStringLiteral("cap"), xIn_cap); + } + if (!xIn_cmpd.isEmpty()) { + writer.writeAttribute(QStringLiteral("cmpd"), xIn_cmpd); + } + if (!xIn_algn.isEmpty()) { + writer.writeAttribute(QStringLiteral("algn"), xIn_algn); + } + } + if ((!x_headEnd_tyep.isEmpty()) || (!x_headEnd_w.isEmpty()) || (!x_headEnd_len.isEmpty())) { + writer.writeEmptyElement(QStringLiteral("a:headEnd")); + if (!x_headEnd_tyep.isEmpty()) { + writer.writeAttribute(QStringLiteral("type"), x_headEnd_tyep); } - if((!x_tailEnd_tyep.isEmpty())||(!x_tailEnd_w.isEmpty())||(!x_tailEnd_len.isEmpty())){ - writer.writeEmptyElement(QStringLiteral("a:tailEnd")); - if(!x_tailEnd_tyep.isEmpty()){ - writer.writeAttribute(QStringLiteral("type"),x_tailEnd_tyep);} - if(!x_tailEnd_w.isEmpty()){ - writer.writeAttribute(QStringLiteral("w"),x_tailEnd_w);} - if(!x_tailEnd_len.isEmpty()){ - writer.writeAttribute(QStringLiteral("len"),x_tailEnd_len);} - } - - writer.writeEndElement();//a:ln - - - writer.writeEndElement(); //xdr:spPr - // writer style - - writer.writeStartElement(QStringLiteral("xdr:style"));// style - writer.writeStartElement(QStringLiteral("a:lnRef"));//lnRef - writer.writeAttribute(QStringLiteral("idx"),Style_inref_idx); - writer.writeStartElement(QStringLiteral("a:schemeClr"));//val - writer.writeAttribute(QStringLiteral("val"),Style_inref_val); - writer.writeEndElement(); // val - writer.writeEndElement(); // lnRef - writer.writeStartElement(QStringLiteral("a:fillRef"));//fillRef - writer.writeAttribute(QStringLiteral("idx"),style_fillref_idx); - writer.writeStartElement(QStringLiteral("a:schemeClr"));//val - writer.writeAttribute(QStringLiteral("val"),style_fillref_val); - writer.writeEndElement(); // val - writer.writeEndElement(); // fillRef - writer.writeStartElement(QStringLiteral("a:effectRef"));//effectRef - writer.writeAttribute(QStringLiteral("idx"),style_effectref_idx); - writer.writeStartElement(QStringLiteral("a:schemeClr"));//val - writer.writeAttribute(QStringLiteral("val"),style_effectref_val); - writer.writeEndElement(); // val - writer.writeEndElement(); // effectRef - writer.writeStartElement(QStringLiteral("a:fontRef"));//fontRef - writer.writeAttribute(QStringLiteral("idx"),style_forntref_idx); - writer.writeStartElement(QStringLiteral("a:schemeClr"));//val - writer.writeAttribute(QStringLiteral("val"),style_forntref_val); - writer.writeEndElement(); // val - writer.writeEndElement(); // fontRef - writer.writeEndElement(); // style - - writer.writeEndElement(); //xdr:sp - - //}} liufeijin + if (!x_headEnd_w.isEmpty()) { + writer.writeAttribute(QStringLiteral("w"), x_headEnd_w); + } + if (!x_headEnd_len.isEmpty()) { + writer.writeAttribute(QStringLiteral("len"), x_headEnd_len); + } + } + if ((!x_tailEnd_tyep.isEmpty()) || (!x_tailEnd_w.isEmpty()) || (!x_tailEnd_len.isEmpty())) { + writer.writeEmptyElement(QStringLiteral("a:tailEnd")); + if (!x_tailEnd_tyep.isEmpty()) { + writer.writeAttribute(QStringLiteral("type"), x_tailEnd_tyep); + } + if (!x_tailEnd_w.isEmpty()) { + writer.writeAttribute(QStringLiteral("w"), x_tailEnd_w); + } + if (!x_tailEnd_len.isEmpty()) { + writer.writeAttribute(QStringLiteral("len"), x_tailEnd_len); + } + } + + writer.writeEndElement(); // a:ln + + writer.writeEndElement(); // xdr:spPr + // writer style + + writer.writeStartElement(QStringLiteral("xdr:style")); // style + writer.writeStartElement(QStringLiteral("a:lnRef")); // lnRef + writer.writeAttribute(QStringLiteral("idx"), Style_inref_idx); + writer.writeStartElement(QStringLiteral("a:schemeClr")); // val + writer.writeAttribute(QStringLiteral("val"), Style_inref_val); + writer.writeEndElement(); // val + writer.writeEndElement(); // lnRef + writer.writeStartElement(QStringLiteral("a:fillRef")); // fillRef + writer.writeAttribute(QStringLiteral("idx"), style_fillref_idx); + writer.writeStartElement(QStringLiteral("a:schemeClr")); // val + writer.writeAttribute(QStringLiteral("val"), style_fillref_val); + writer.writeEndElement(); // val + writer.writeEndElement(); // fillRef + writer.writeStartElement(QStringLiteral("a:effectRef")); // effectRef + writer.writeAttribute(QStringLiteral("idx"), style_effectref_idx); + writer.writeStartElement(QStringLiteral("a:schemeClr")); // val + writer.writeAttribute(QStringLiteral("val"), style_effectref_val); + writer.writeEndElement(); // val + writer.writeEndElement(); // effectRef + writer.writeStartElement(QStringLiteral("a:fontRef")); // fontRef + writer.writeAttribute(QStringLiteral("idx"), style_forntref_idx); + writer.writeStartElement(QStringLiteral("a:schemeClr")); // val + writer.writeAttribute(QStringLiteral("val"), style_forntref_val); + writer.writeEndElement(); // val + writer.writeEndElement(); // fontRef + writer.writeEndElement(); // style + + writer.writeEndElement(); // xdr:sp + + //}} liufeijin } -//absolute anchor +// absolute anchor DrawingAbsoluteAnchor::DrawingAbsoluteAnchor(Drawing *drawing, ObjectType objectType) - :DrawingAnchor(drawing, objectType) + : DrawingAnchor(drawing, objectType) { - } // check point @@ -988,22 +1006,15 @@ bool DrawingAbsoluteAnchor::loadFromXml(QXmlStreamReader &reader) while (!reader.atEnd()) { reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { - if (reader.name() == QLatin1String("pos")) - { + if (reader.name() == QLatin1String("pos")) { pos = loadXmlPos(reader); - } - else if (reader.name() == QLatin1String("ext")) - { + } else if (reader.name() == QLatin1String("ext")) { ext = loadXmlExt(reader); - } - else - { + } else { loadXmlObject(reader); } - } - else if (reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QLatin1String("absoluteAnchor")) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("absoluteAnchor")) { break; } } @@ -1019,15 +1030,14 @@ void DrawingAbsoluteAnchor::saveToXml(QXmlStreamWriter &writer) const saveXmlObject(writer); writer.writeEmptyElement(QStringLiteral("xdr:clientData")); - writer.writeEndElement(); //xdr:absoluteAnchor + writer.writeEndElement(); // xdr:absoluteAnchor } -//one cell anchor +// one cell anchor DrawingOneCellAnchor::DrawingOneCellAnchor(Drawing *drawing, ObjectType objectType) - :DrawingAnchor(drawing, objectType) + : DrawingAnchor(drawing, objectType) { - } int DrawingOneCellAnchor::row() const @@ -1045,27 +1055,18 @@ bool DrawingOneCellAnchor::loadFromXml(QXmlStreamReader &reader) { Q_ASSERT(reader.name() == QLatin1String("oneCellAnchor")); - while (!reader.atEnd()) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if (reader.tokenType() == QXmlStreamReader::StartElement) - { - if (reader.name() == QLatin1String("from")) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("from")) { from = loadXmlMarker(reader, QLatin1String("from")); - } - else if (reader.name() == QLatin1String("ext")) - { + } else if (reader.name() == QLatin1String("ext")) { ext = loadXmlExt(reader); - } - else - { + } else { loadXmlObject(reader); } - } - else if (reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QLatin1String("oneCellAnchor")) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("oneCellAnchor")) { break; } } @@ -1082,7 +1083,7 @@ void DrawingOneCellAnchor::saveToXml(QXmlStreamWriter &writer) const saveXmlObject(writer); writer.writeEmptyElement(QStringLiteral("xdr:clientData")); - writer.writeEndElement(); //xdr:oneCellAnchor + writer.writeEndElement(); // xdr:oneCellAnchor } /* @@ -1093,9 +1094,8 @@ void DrawingOneCellAnchor::saveToXml(QXmlStreamWriter &writer) const cells and its extents are in EMU units. */ DrawingTwoCellAnchor::DrawingTwoCellAnchor(Drawing *drawing, ObjectType objectType) - :DrawingAnchor(drawing, objectType) + : DrawingAnchor(drawing, objectType) { - } int DrawingTwoCellAnchor::row() const @@ -1125,31 +1125,23 @@ bool DrawingTwoCellAnchor::loadFromXml(QXmlStreamReader &reader) */ - //{{ liufeijin - QXmlStreamAttributes attrs = reader.attributes(); // for absolute twocell aadd by liufeijin 20181024 + //{{ liufeijin + QXmlStreamAttributes attrs = + reader.attributes(); // for absolute twocell aadd by liufeijin 20181024 editASName = attrs.value(QLatin1String("editAs")).toString(); - //}} + //}} - while (!reader.atEnd()) - { + while (!reader.atEnd()) { reader.readNextStartElement(); - if (reader.tokenType() == QXmlStreamReader::StartElement) - { - if (reader.name() == QLatin1String("from")) - { + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("from")) { from = loadXmlMarker(reader, QLatin1String("from")); - } - else if (reader.name() == QLatin1String("to")) - { + } else if (reader.name() == QLatin1String("to")) { to = loadXmlMarker(reader, QLatin1String("to")); - } - else if (reader.name() == QLatin1String("clientData")) - { + } else if (reader.name() == QLatin1String("clientData")) { // clientData - } - else - { + } else { /* @@ -1167,27 +1159,24 @@ bool DrawingTwoCellAnchor::loadFromXml(QXmlStreamReader &reader) loadXmlObject(reader); } - } - else if (reader.tokenType() == QXmlStreamReader::EndElement - && reader.name() == QLatin1String("twoCellAnchor")) - { + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("twoCellAnchor")) { break; } } return true; } - - void DrawingTwoCellAnchor::saveToXml(QXmlStreamWriter &writer) const +void DrawingTwoCellAnchor::saveToXml(QXmlStreamWriter &writer) const { writer.writeStartElement(QStringLiteral("xdr:twoCellAnchor")); - //{{ liufeijin + //{{ liufeijin // writer.writeAttribute(QStringLiteral("editAs"), QStringLiteral("oneCell")); - if(!editASName.isNull()){ - writer.writeAttribute(QStringLiteral("editAs"), editASName ); //QStringLiteral("oneCell") - } - // }} + if (!editASName.isNull()) { + writer.writeAttribute(QStringLiteral("editAs"), editASName); // QStringLiteral("oneCell") + } + // }} saveXmlMarker(writer, from, QStringLiteral("xdr:from")); saveXmlMarker(writer, to, QStringLiteral("xdr:to")); @@ -1195,9 +1184,7 @@ bool DrawingTwoCellAnchor::loadFromXml(QXmlStreamReader &reader) saveXmlObject(writer); writer.writeEmptyElement(QStringLiteral("xdr:clientData")); - writer.writeEndElement(); //xdr:twoCellAnchor - + writer.writeEndElement(); // xdr:twoCellAnchor } - QT_END_NAMESPACE_XLSX diff --git a/QXlsx/source/xlsxformat.cpp b/QXlsx/source/xlsxformat.cpp index cc506772..13bbc9e2 100644 --- a/QXlsx/source/xlsxformat.cpp +++ b/QXlsx/source/xlsxformat.cpp @@ -1,45 +1,64 @@ // xlsxformat.cpp -#include -#include -#include - #include "xlsxformat.h" -#include "xlsxformat_p.h" + #include "xlsxcolor_p.h" +#include "xlsxformat_p.h" #include "xlsxnumformatparser_p.h" +#include +#include +#include + QT_BEGIN_NAMESPACE_XLSX FormatPrivate::FormatPrivate() - : dirty(true) - , font_dirty(true), font_index_valid(false), font_index(0) - , fill_dirty(true), fill_index_valid(false), fill_index(0) - , border_dirty(true), border_index_valid(false), border_index(0) - , xf_index(-1), xf_indexValid(false) - , is_dxf_fomat(false), dxf_index(-1), dxf_indexValid(false) - , theme(0) + : dirty(true) + , font_dirty(true) + , font_index_valid(false) + , font_index(0) + , fill_dirty(true) + , fill_index_valid(false) + , fill_index(0) + , border_dirty(true) + , border_index_valid(false) + , border_index(0) + , xf_index(-1) + , xf_indexValid(false) + , is_dxf_fomat(false) + , dxf_index(-1) + , dxf_indexValid(false) + , theme(0) { } FormatPrivate::FormatPrivate(const FormatPrivate &other) - : QSharedData(other) - , dirty(other.dirty), formatKey(other.formatKey) - , font_dirty(other.font_dirty), font_index_valid(other.font_index_valid), font_key(other.font_key), font_index(other.font_index) - , fill_dirty(other.fill_dirty), fill_index_valid(other.fill_index_valid), fill_key(other.fill_key), fill_index(other.fill_index) - , border_dirty(other.border_dirty), border_index_valid(other.border_index_valid), border_key(other.border_key), border_index(other.border_index) - , xf_index(other.xf_index), xf_indexValid(other.xf_indexValid) - , is_dxf_fomat(other.is_dxf_fomat), dxf_index(other.dxf_index), dxf_indexValid(other.dxf_indexValid) - , theme(other.theme) - , properties(other.properties) -{ - -} - -FormatPrivate::~FormatPrivate() -{ - -} + : QSharedData(other) + , dirty(other.dirty) + , formatKey(other.formatKey) + , font_dirty(other.font_dirty) + , font_index_valid(other.font_index_valid) + , font_key(other.font_key) + , font_index(other.font_index) + , fill_dirty(other.fill_dirty) + , fill_index_valid(other.fill_index_valid) + , fill_key(other.fill_key) + , fill_index(other.fill_index) + , border_dirty(other.border_dirty) + , border_index_valid(other.border_index_valid) + , border_key(other.border_key) + , border_index(other.border_index) + , xf_index(other.xf_index) + , xf_indexValid(other.xf_indexValid) + , is_dxf_fomat(other.is_dxf_fomat) + , dxf_index(other.dxf_index) + , dxf_indexValid(other.dxf_indexValid) + , theme(other.theme) + , properties(other.properties) +{ +} + +FormatPrivate::~FormatPrivate() {} /*! * \class Format @@ -57,7 +76,6 @@ FormatPrivate::~FormatPrivate() * \value FontScriptSub sub script */ - /*! * \enum Format::FontUnderline * @@ -116,7 +134,7 @@ FormatPrivate::~FormatPrivate() * \value BorderDashDotDot * \value BorderMediumDashDotDot * \value BorderSlantDashDot -*/ + */ /*! * \enum Format::DiagonalBorderType @@ -160,41 +178,38 @@ FormatPrivate::~FormatPrivate() */ Format::Format() { - //The d pointer is initialized with a null pointer + // The d pointer is initialized with a null pointer } /*! Creates a new format with the same attributes as the \a other format. */ Format::Format(const Format &other) - :d(other.d) + : d(other.d) { - } /*! Assigns the \a other format to this format, and returns a reference to this format. */ -Format &Format::operator =(const Format &other) +Format &Format::operator=(const Format &other) { - d = other.d; - return *this; + d = other.d; + return *this; } /*! * Destroys this format. */ -Format::~Format() -{ -} +Format::~Format() {} /*! * Returns the number format identifier. */ int Format::numberFormatIndex() const { - return intProperty(FormatPrivate::P_NumFmt_Id, 0); + return intProperty(FormatPrivate::P_NumFmt_Id, 0); } /*! @@ -204,8 +219,8 @@ int Format::numberFormatIndex() const */ void Format::setNumberFormatIndex(int format) { - setProperty(FormatPrivate::P_NumFmt_Id, format); - clearProperty(FormatPrivate::P_NumFmt_FormatCode); + setProperty(FormatPrivate::P_NumFmt_Id, format); + clearProperty(FormatPrivate::P_NumFmt_FormatCode); } /*! @@ -215,7 +230,7 @@ void Format::setNumberFormatIndex(int format) */ QString Format::numberFormat() const { - return stringProperty(FormatPrivate::P_NumFmt_FormatCode); + return stringProperty(FormatPrivate::P_NumFmt_FormatCode); } /*! @@ -224,10 +239,10 @@ QString Format::numberFormat() const */ void Format::setNumberFormat(const QString &format) { - if (format.isEmpty()) - return; - setProperty(FormatPrivate::P_NumFmt_FormatCode, format); - clearProperty(FormatPrivate::P_NumFmt_Id); //numFmt id must be re-generated. + if (format.isEmpty()) + return; + setProperty(FormatPrivate::P_NumFmt_FormatCode, format); + clearProperty(FormatPrivate::P_NumFmt_Id); // numFmt id must be re-generated. } /*! @@ -235,65 +250,61 @@ void Format::setNumberFormat(const QString &format) */ bool Format::isDateTimeFormat() const { - //NOTICE: + // NOTICE: - if (hasProperty(FormatPrivate::P_NumFmt_FormatCode)) - { - //Custom numFmt, so - //Gauss from the number string - return NumFormatParser::isDateTime(numberFormat()); - } - else if (hasProperty(FormatPrivate::P_NumFmt_Id)) - { - //Non-custom numFmt - int idx = numberFormatIndex(); + if (hasProperty(FormatPrivate::P_NumFmt_FormatCode)) { + // Custom numFmt, so + // Gauss from the number string + return NumFormatParser::isDateTime(numberFormat()); + } else if (hasProperty(FormatPrivate::P_NumFmt_Id)) { + // Non-custom numFmt + int idx = numberFormatIndex(); - //Is built-in date time number id? - if ((idx >= 14 && idx <= 22) || (idx >= 45 && idx <= 47)) - return true; + // Is built-in date time number id? + if ((idx >= 14 && idx <= 22) || (idx >= 45 && idx <= 47)) + return true; - if ((idx >= 27 && idx <= 36) || (idx >= 50 && idx <= 58)) //Used in CHS\CHT\JPN\KOR - return true; - } + if ((idx >= 27 && idx <= 36) || (idx >= 50 && idx <= 58)) // Used in CHS\CHT\JPN\KOR + return true; + } - return false; + return false; } /*! - \internal - Set a custom num \a format with the given \a id. + \internal + Set a custom num \a format with the given \a id. */ void Format::setNumberFormat(int id, const QString &format) { - setProperty(FormatPrivate::P_NumFmt_Id, id); - setProperty(FormatPrivate::P_NumFmt_FormatCode, format); + setProperty(FormatPrivate::P_NumFmt_Id, id); + setProperty(FormatPrivate::P_NumFmt_FormatCode, format); } /*! - \internal - Called by styles to fix the numFmt + \internal + Called by styles to fix the numFmt */ void Format::fixNumberFormat(int id, const QString &format) { - setProperty(FormatPrivate::P_NumFmt_Id, id, 0, false); - setProperty(FormatPrivate::P_NumFmt_FormatCode, format, QString(), false); + setProperty(FormatPrivate::P_NumFmt_Id, id, 0, false); + setProperty(FormatPrivate::P_NumFmt_FormatCode, format, QString(), false); } /*! - \internal - Return true if the format has number format. + \internal + Return true if the format has number format. */ bool Format::hasNumFmtData() const { - if (!d) - return false; + if (!d) + return false; - if ( hasProperty(FormatPrivate::P_NumFmt_Id) || - hasProperty(FormatPrivate::P_NumFmt_FormatCode) ) - { - return true; - } - return false; + if (hasProperty(FormatPrivate::P_NumFmt_Id) || + hasProperty(FormatPrivate::P_NumFmt_FormatCode)) { + return true; + } + return false; } /*! @@ -301,7 +312,7 @@ bool Format::hasNumFmtData() const */ int Format::fontSize() const { - return intProperty(FormatPrivate::P_Font_Size); + return intProperty(FormatPrivate::P_Font_Size); } /*! @@ -309,7 +320,7 @@ int Format::fontSize() const */ void Format::setFontSize(int size) { - setProperty(FormatPrivate::P_Font_Size, size, 0); + setProperty(FormatPrivate::P_Font_Size, size, 0); } /*! @@ -317,7 +328,7 @@ void Format::setFontSize(int size) */ bool Format::fontItalic() const { - return boolProperty(FormatPrivate::P_Font_Italic); + return boolProperty(FormatPrivate::P_Font_Italic); } /*! @@ -325,7 +336,7 @@ bool Format::fontItalic() const */ void Format::setFontItalic(bool italic) { - setProperty(FormatPrivate::P_Font_Italic, italic, false); + setProperty(FormatPrivate::P_Font_Italic, italic, false); } /*! @@ -333,7 +344,7 @@ void Format::setFontItalic(bool italic) */ bool Format::fontStrikeOut() const { - return boolProperty(FormatPrivate::P_Font_StrikeOut); + return boolProperty(FormatPrivate::P_Font_StrikeOut); } /*! @@ -341,7 +352,7 @@ bool Format::fontStrikeOut() const */ void Format::setFontStrikeOut(bool strikeOut) { - setProperty(FormatPrivate::P_Font_StrikeOut, strikeOut, false); + setProperty(FormatPrivate::P_Font_StrikeOut, strikeOut, false); } /*! @@ -349,9 +360,9 @@ void Format::setFontStrikeOut(bool strikeOut) */ QColor Format::fontColor() const { - if (hasProperty(FormatPrivate::P_Font_Color)) - return colorProperty(FormatPrivate::P_Font_Color); - return QColor(); + if (hasProperty(FormatPrivate::P_Font_Color)) + return colorProperty(FormatPrivate::P_Font_Color); + return QColor(); } /*! @@ -359,7 +370,7 @@ QColor Format::fontColor() const */ void Format::setFontColor(const QColor &color) { - setProperty(FormatPrivate::P_Font_Color, XlsxColor(color), XlsxColor()); + setProperty(FormatPrivate::P_Font_Color, XlsxColor(color), XlsxColor()); } /*! @@ -367,7 +378,7 @@ void Format::setFontColor(const QColor &color) */ bool Format::fontBold() const { - return boolProperty(FormatPrivate::P_Font_Bold); + return boolProperty(FormatPrivate::P_Font_Bold); } /*! @@ -375,7 +386,7 @@ bool Format::fontBold() const */ void Format::setFontBold(bool bold) { - setProperty(FormatPrivate::P_Font_Bold, bold, false); + setProperty(FormatPrivate::P_Font_Bold, bold, false); } /*! @@ -383,7 +394,7 @@ void Format::setFontBold(bool bold) */ Format::FontScript Format::fontScript() const { - return static_cast(intProperty(FormatPrivate::P_Font_Script)); + return static_cast(intProperty(FormatPrivate::P_Font_Script)); } /*! @@ -391,7 +402,7 @@ Format::FontScript Format::fontScript() const */ void Format::setFontScript(FontScript script) { - setProperty(FormatPrivate::P_Font_Script, script, FontScriptNormal); + setProperty(FormatPrivate::P_Font_Script, script, FontScriptNormal); } /*! @@ -399,7 +410,7 @@ void Format::setFontScript(FontScript script) */ Format::FontUnderline Format::fontUnderline() const { - return static_cast(intProperty(FormatPrivate::P_Font_Underline)); + return static_cast(intProperty(FormatPrivate::P_Font_Underline)); } /*! @@ -407,7 +418,7 @@ Format::FontUnderline Format::fontUnderline() const */ void Format::setFontUnderline(FontUnderline underline) { - setProperty(FormatPrivate::P_Font_Underline, underline, FontUnderlineNone); + setProperty(FormatPrivate::P_Font_Underline, underline, FontUnderlineNone); } /*! @@ -415,7 +426,7 @@ void Format::setFontUnderline(FontUnderline underline) */ bool Format::fontOutline() const { - return boolProperty(FormatPrivate::P_Font_Outline); + return boolProperty(FormatPrivate::P_Font_Outline); } /*! @@ -423,7 +434,7 @@ bool Format::fontOutline() const */ void Format::setFontOutline(bool outline) { - setProperty(FormatPrivate::P_Font_Outline, outline, false); + setProperty(FormatPrivate::P_Font_Outline, outline, false); } /*! @@ -431,7 +442,7 @@ void Format::setFontOutline(bool outline) */ QString Format::fontName() const { - return stringProperty(FormatPrivate::P_Font_Name, QStringLiteral("Calibri")); + return stringProperty(FormatPrivate::P_Font_Name, QStringLiteral("Calibri")); } /*! @@ -439,7 +450,7 @@ QString Format::fontName() const */ void Format::setFontName(const QString &name) { - setProperty(FormatPrivate::P_Font_Name, name, QStringLiteral("Calibri")); + setProperty(FormatPrivate::P_Font_Name, name, QStringLiteral("Calibri")); } /*! @@ -447,15 +458,15 @@ void Format::setFontName(const QString &name) */ QFont Format::font() const { - QFont font; - font.setFamily(fontName()); - if (fontSize() > 0) - font.setPointSize(fontSize()); - font.setBold(fontBold()); - font.setItalic(fontItalic()); - font.setUnderline(fontUnderline()!=FontUnderlineNone); - font.setStrikeOut(fontStrikeOut()); - return font; + QFont font; + font.setFamily(fontName()); + if (fontSize() > 0) + font.setPointSize(fontSize()); + font.setBold(fontBold()); + font.setItalic(fontItalic()); + font.setUnderline(fontUnderline() != FontUnderlineNone); + font.setStrikeOut(fontStrikeOut()); + return font; } /*! @@ -463,13 +474,13 @@ QFont Format::font() const */ void Format::setFont(const QFont &font) { - setFontName(font.family()); - if (font.pointSize() > 0) - setFontSize(font.pointSize()); - setFontBold(font.bold()); - setFontItalic(font.italic()); - setFontUnderline(font.underline() ? FontUnderlineSingle : FontUnderlineNone); - setFontStrikeOut(font.strikeOut()); + setFontName(font.family()); + if (font.pointSize() > 0) + setFontSize(font.pointSize()); + setFontBold(font.bold()); + setFontItalic(font.italic()); + setFontUnderline(font.underline() ? FontUnderlineSingle : FontUnderlineNone); + setFontStrikeOut(font.strikeOut()); } /*! @@ -479,9 +490,9 @@ void Format::setFont(const QFont &font) */ bool Format::fontIndexValid() const { - if (!hasFontData()) - return false; - return d->font_index_valid; + if (!hasFontData()) + return false; + return d->font_index_valid; } /*! @@ -489,10 +500,10 @@ bool Format::fontIndexValid() const */ int Format::fontIndex() const { - if (fontIndexValid()) - return d->font_index; + if (fontIndexValid()) + return d->font_index; - return 0; + return 0; } /*! @@ -500,8 +511,8 @@ int Format::fontIndex() const */ void Format::setFontIndex(int index) { - d->font_index = index; - d->font_index_valid = true; + d->font_index = index; + d->font_index_valid = true; } /*! @@ -509,39 +520,39 @@ void Format::setFontIndex(int index) */ QByteArray Format::fontKey() const { - if (isEmpty()) - return QByteArray(); + if (isEmpty()) + return QByteArray(); - if (d->font_dirty) { - QByteArray key; - QDataStream stream(&key, QIODevice::WriteOnly); - for (int i=FormatPrivate::P_Font_STARTID; ifont_dirty) { + QByteArray key; + QDataStream stream(&key, QIODevice::WriteOnly); + for (int i = FormatPrivate::P_Font_STARTID; i < FormatPrivate::P_Font_ENDID; ++i) { auto it = d->properties.constFind(i); if (it != d->properties.constEnd()) stream << i << it.value(); - }; + }; - const_cast(this)->d->font_key = key; - const_cast(this)->d->font_dirty = false; - } + const_cast(this)->d->font_key = key; + const_cast(this)->d->font_dirty = false; + } - return d->font_key; + return d->font_key; } /*! - \internal - Return true if the format has font format, otherwise return false. + \internal + Return true if the format has font format, otherwise return false. */ bool Format::hasFontData() const { - if (!d) - return false; + if (!d) + return false; - for (int i=FormatPrivate::P_Font_STARTID; i(intProperty(FormatPrivate::P_Alignment_AlignH, AlignHGeneral)); + return static_cast( + intProperty(FormatPrivate::P_Alignment_AlignH, AlignHGeneral)); } /*! @@ -557,17 +569,18 @@ Format::HorizontalAlignment Format::horizontalAlignment() const */ void Format::setHorizontalAlignment(HorizontalAlignment align) { - if (hasProperty(FormatPrivate::P_Alignment_Indent) - &&(align != AlignHGeneral && align != AlignLeft && align != AlignRight && align != AlignHDistributed)) { - clearProperty(FormatPrivate::P_Alignment_Indent); - } + if (hasProperty(FormatPrivate::P_Alignment_Indent) && + (align != AlignHGeneral && align != AlignLeft && align != AlignRight && + align != AlignHDistributed)) { + clearProperty(FormatPrivate::P_Alignment_Indent); + } - if (hasProperty(FormatPrivate::P_Alignment_ShinkToFit) - && (align == AlignHFill || align == AlignHJustify || align == AlignHDistributed)) { - clearProperty(FormatPrivate::P_Alignment_ShinkToFit); - } + if (hasProperty(FormatPrivate::P_Alignment_ShinkToFit) && + (align == AlignHFill || align == AlignHJustify || align == AlignHDistributed)) { + clearProperty(FormatPrivate::P_Alignment_ShinkToFit); + } - setProperty(FormatPrivate::P_Alignment_AlignH, align, AlignHGeneral); + setProperty(FormatPrivate::P_Alignment_AlignH, align, AlignHGeneral); } /*! @@ -575,7 +588,8 @@ void Format::setHorizontalAlignment(HorizontalAlignment align) */ Format::VerticalAlignment Format::verticalAlignment() const { - return static_cast(intProperty(FormatPrivate::P_Alignment_AlignV, AlignBottom)); + return static_cast( + intProperty(FormatPrivate::P_Alignment_AlignV, AlignBottom)); } /*! @@ -583,7 +597,7 @@ Format::VerticalAlignment Format::verticalAlignment() const */ void Format::setVerticalAlignment(VerticalAlignment align) { - setProperty(FormatPrivate::P_Alignment_AlignV, align, AlignBottom); + setProperty(FormatPrivate::P_Alignment_AlignV, align, AlignBottom); } /*! @@ -591,7 +605,7 @@ void Format::setVerticalAlignment(VerticalAlignment align) */ bool Format::textWrap() const { - return boolProperty(FormatPrivate::P_Alignment_Wrap); + return boolProperty(FormatPrivate::P_Alignment_Wrap); } /*! @@ -599,10 +613,10 @@ bool Format::textWrap() const */ void Format::setTextWrap(bool wrap) { - if (wrap && hasProperty(FormatPrivate::P_Alignment_ShinkToFit)) - clearProperty(FormatPrivate::P_Alignment_ShinkToFit); + if (wrap && hasProperty(FormatPrivate::P_Alignment_ShinkToFit)) + clearProperty(FormatPrivate::P_Alignment_ShinkToFit); - setProperty(FormatPrivate::P_Alignment_Wrap, wrap, false); + setProperty(FormatPrivate::P_Alignment_Wrap, wrap, false); } /*! @@ -610,7 +624,7 @@ void Format::setTextWrap(bool wrap) */ int Format::rotation() const { - return intProperty(FormatPrivate::P_Alignment_Rotation); + return intProperty(FormatPrivate::P_Alignment_Rotation); } /*! @@ -618,7 +632,7 @@ int Format::rotation() const */ void Format::setRotation(int rotation) { - setProperty(FormatPrivate::P_Alignment_Rotation, rotation, 0); + setProperty(FormatPrivate::P_Alignment_Rotation, rotation, 0); } /*! @@ -626,7 +640,7 @@ void Format::setRotation(int rotation) */ int Format::indent() const { - return intProperty(FormatPrivate::P_Alignment_Indent); + return intProperty(FormatPrivate::P_Alignment_Indent); } /*! @@ -634,15 +648,15 @@ int Format::indent() const */ void Format::setIndent(int indent) { - if (indent && hasProperty(FormatPrivate::P_Alignment_AlignH)) { - HorizontalAlignment hl = horizontalAlignment(); + if (indent && hasProperty(FormatPrivate::P_Alignment_AlignH)) { + HorizontalAlignment hl = horizontalAlignment(); - if (hl != AlignHGeneral && hl != AlignLeft && hl!= AlignRight && hl!= AlignHJustify) { - setHorizontalAlignment(AlignLeft); - } - } + if (hl != AlignHGeneral && hl != AlignLeft && hl != AlignRight && hl != AlignHJustify) { + setHorizontalAlignment(AlignLeft); + } + } - setProperty(FormatPrivate::P_Alignment_Indent, indent, 0); + setProperty(FormatPrivate::P_Alignment_Indent, indent, 0); } /*! @@ -650,7 +664,7 @@ void Format::setIndent(int indent) */ bool Format::shrinkToFit() const { - return boolProperty(FormatPrivate::P_Alignment_ShinkToFit); + return boolProperty(FormatPrivate::P_Alignment_ShinkToFit); } /*! @@ -658,16 +672,16 @@ bool Format::shrinkToFit() const */ void Format::setShrinkToFit(bool shink) { - if (shink && hasProperty(FormatPrivate::P_Alignment_Wrap)) - clearProperty(FormatPrivate::P_Alignment_Wrap); + if (shink && hasProperty(FormatPrivate::P_Alignment_Wrap)) + clearProperty(FormatPrivate::P_Alignment_Wrap); - if (shink && hasProperty(FormatPrivate::P_Alignment_AlignH)) { - HorizontalAlignment hl = horizontalAlignment(); - if (hl == AlignHFill || hl == AlignHJustify || hl == AlignHDistributed) - setHorizontalAlignment(AlignLeft); - } + if (shink && hasProperty(FormatPrivate::P_Alignment_AlignH)) { + HorizontalAlignment hl = horizontalAlignment(); + if (hl == AlignHFill || hl == AlignHJustify || hl == AlignHDistributed) + setHorizontalAlignment(AlignLeft); + } - setProperty(FormatPrivate::P_Alignment_ShinkToFit, shink, false); + setProperty(FormatPrivate::P_Alignment_ShinkToFit, shink, false); } /*! @@ -675,14 +689,14 @@ void Format::setShrinkToFit(bool shink) */ bool Format::hasAlignmentData() const { - if (!d) - return false; + if (!d) + return false; - for (int i=FormatPrivate::P_Alignment_STARTID; i(intProperty(FormatPrivate::P_Border_LeftStyle)); + return static_cast(intProperty(FormatPrivate::P_Border_LeftStyle)); } /*! @@ -720,7 +734,7 @@ Format::BorderStyle Format::leftBorderStyle() const */ void Format::setLeftBorderStyle(BorderStyle style) { - setProperty(FormatPrivate::P_Border_LeftStyle, style, BorderNone); + setProperty(FormatPrivate::P_Border_LeftStyle, style, BorderNone); } /*! @@ -728,181 +742,181 @@ void Format::setLeftBorderStyle(BorderStyle style) */ QColor Format::leftBorderColor() const { - return colorProperty(FormatPrivate::P_Border_LeftColor); + return colorProperty(FormatPrivate::P_Border_LeftColor); } /*! - Sets the left border color to the given \a color + Sets the left border color to the given \a color */ void Format::setLeftBorderColor(const QColor &color) { - setProperty(FormatPrivate::P_Border_LeftColor, XlsxColor(color), XlsxColor()); + setProperty(FormatPrivate::P_Border_LeftColor, XlsxColor(color), XlsxColor()); } /*! - Returns the right border style. + Returns the right border style. */ Format::BorderStyle Format::rightBorderStyle() const { - return static_cast(intProperty(FormatPrivate::P_Border_RightStyle)); + return static_cast(intProperty(FormatPrivate::P_Border_RightStyle)); } /*! - Sets the right border style to the given \a style. + Sets the right border style to the given \a style. */ void Format::setRightBorderStyle(BorderStyle style) { - setProperty(FormatPrivate::P_Border_RightStyle, style, BorderNone); + setProperty(FormatPrivate::P_Border_RightStyle, style, BorderNone); } /*! - Returns the right border color. + Returns the right border color. */ QColor Format::rightBorderColor() const { - return colorProperty(FormatPrivate::P_Border_RightColor); + return colorProperty(FormatPrivate::P_Border_RightColor); } /*! - Sets the right border color to the given \a color + Sets the right border color to the given \a color */ void Format::setRightBorderColor(const QColor &color) { - setProperty(FormatPrivate::P_Border_RightColor, XlsxColor(color), XlsxColor()); + setProperty(FormatPrivate::P_Border_RightColor, XlsxColor(color), XlsxColor()); } /*! - Returns the top border style. + Returns the top border style. */ Format::BorderStyle Format::topBorderStyle() const { - return static_cast(intProperty(FormatPrivate::P_Border_TopStyle)); + return static_cast(intProperty(FormatPrivate::P_Border_TopStyle)); } /*! - Sets the top border style to the given \a style. + Sets the top border style to the given \a style. */ void Format::setTopBorderStyle(BorderStyle style) { - setProperty(FormatPrivate::P_Border_TopStyle, style, BorderNone); + setProperty(FormatPrivate::P_Border_TopStyle, style, BorderNone); } /*! - Returns the top border color. + Returns the top border color. */ QColor Format::topBorderColor() const { - return colorProperty(FormatPrivate::P_Border_TopColor); + return colorProperty(FormatPrivate::P_Border_TopColor); } /*! - Sets the top border color to the given \a color. + Sets the top border color to the given \a color. */ void Format::setTopBorderColor(const QColor &color) { - setProperty(FormatPrivate::P_Border_TopColor, XlsxColor(color), XlsxColor()); + setProperty(FormatPrivate::P_Border_TopColor, XlsxColor(color), XlsxColor()); } /*! - Returns the bottom border style. + Returns the bottom border style. */ Format::BorderStyle Format::bottomBorderStyle() const { - return static_cast(intProperty(FormatPrivate::P_Border_BottomStyle)); + return static_cast(intProperty(FormatPrivate::P_Border_BottomStyle)); } /*! - Sets the bottom border style to the given \a style. + Sets the bottom border style to the given \a style. */ void Format::setBottomBorderStyle(BorderStyle style) { - setProperty(FormatPrivate::P_Border_BottomStyle, style, BorderNone); + setProperty(FormatPrivate::P_Border_BottomStyle, style, BorderNone); } /*! - Returns the bottom border color. + Returns the bottom border color. */ QColor Format::bottomBorderColor() const { - return colorProperty(FormatPrivate::P_Border_BottomColor); + return colorProperty(FormatPrivate::P_Border_BottomColor); } /*! - Sets the bottom border color to the given \a color. + Sets the bottom border color to the given \a color. */ void Format::setBottomBorderColor(const QColor &color) { - setProperty(FormatPrivate::P_Border_BottomColor, XlsxColor(color), XlsxColor()); + setProperty(FormatPrivate::P_Border_BottomColor, XlsxColor(color), XlsxColor()); } /*! - Return the diagonla border style. + Return the diagonla border style. */ Format::BorderStyle Format::diagonalBorderStyle() const { - return static_cast(intProperty(FormatPrivate::P_Border_DiagonalStyle)); + return static_cast(intProperty(FormatPrivate::P_Border_DiagonalStyle)); } /*! - Sets the diagonal border style to the given \a style. + Sets the diagonal border style to the given \a style. */ void Format::setDiagonalBorderStyle(BorderStyle style) { - setProperty(FormatPrivate::P_Border_DiagonalStyle, style, BorderNone); + setProperty(FormatPrivate::P_Border_DiagonalStyle, style, BorderNone); } /*! - Returns the diagonal border type. + Returns the diagonal border type. */ Format::DiagonalBorderType Format::diagonalBorderType() const { - return static_cast(intProperty(FormatPrivate::P_Border_DiagonalType)); + return static_cast(intProperty(FormatPrivate::P_Border_DiagonalType)); } /*! - Sets the diagonal border type to the given \a style + Sets the diagonal border type to the given \a style */ void Format::setDiagonalBorderType(DiagonalBorderType style) { - setProperty(FormatPrivate::P_Border_DiagonalType, style, DiagonalBorderNone); + setProperty(FormatPrivate::P_Border_DiagonalType, style, DiagonalBorderNone); } /*! - Returns the diagonal border color. + Returns the diagonal border color. */ QColor Format::diagonalBorderColor() const { - return colorProperty(FormatPrivate::P_Border_DiagonalColor); + return colorProperty(FormatPrivate::P_Border_DiagonalColor); } /*! - Sets the diagonal border color to the given \a color + Sets the diagonal border color to the given \a color */ void Format::setDiagonalBorderColor(const QColor &color) { - setProperty(FormatPrivate::P_Border_DiagonalColor, XlsxColor(color), XlsxColor()); + setProperty(FormatPrivate::P_Border_DiagonalColor, XlsxColor(color), XlsxColor()); } /*! - \internal - Returns whether this format has been set valid border index. + \internal + Returns whether this format has been set valid border index. */ bool Format::borderIndexValid() const { - if (!hasBorderData()) - return false; - return d->border_index_valid; + if (!hasBorderData()) + return false; + return d->border_index_valid; } /*! - \internal - Returns the border index. + \internal + Returns the border index. */ int Format::borderIndex() const { - if (borderIndexValid()) - return d->border_index; - return 0; + if (borderIndexValid()) + return d->border_index; + return 0; } /*! @@ -910,99 +924,99 @@ int Format::borderIndex() const */ void Format::setBorderIndex(int index) { - d->border_index = index; - d->border_index_valid = true; + d->border_index = index; + d->border_index_valid = true; } /*! \internal */ QByteArray Format::borderKey() const { - if (isEmpty()) - return QByteArray(); + if (isEmpty()) + return QByteArray(); - if (d->border_dirty) { - QByteArray key; - QDataStream stream(&key, QIODevice::WriteOnly); - for (int i=FormatPrivate::P_Border_STARTID; iborder_dirty) { + QByteArray key; + QDataStream stream(&key, QIODevice::WriteOnly); + for (int i = FormatPrivate::P_Border_STARTID; i < FormatPrivate::P_Border_ENDID; ++i) { auto it = d->properties.constFind(i); if (it != d->properties.constEnd()) stream << i << it.value(); - }; + }; - const_cast(this)->d->border_key = key; - const_cast(this)->d->border_dirty = false; - } + const_cast(this)->d->border_key = key; + const_cast(this)->d->border_dirty = false; + } - return d->border_key; + return d->border_key; } /*! - \internal - Return true if the format has border format, otherwise return false. + \internal + Return true if the format has border format, otherwise return false. */ bool Format::hasBorderData() const { - if (!d) - return false; + if (!d) + return false; - for (int i=FormatPrivate::P_Border_STARTID; i(intProperty(FormatPrivate::P_Fill_Pattern, PatternNone)); + return static_cast(intProperty(FormatPrivate::P_Fill_Pattern, PatternNone)); } /*! - Sets the fill pattern to the given \a pattern. + Sets the fill pattern to the given \a pattern. */ void Format::setFillPattern(FillPattern pattern) { - setProperty(FormatPrivate::P_Fill_Pattern, pattern, PatternNone); + setProperty(FormatPrivate::P_Fill_Pattern, pattern, PatternNone); } /*! - Returns the foreground color of the pattern. + Returns the foreground color of the pattern. */ QColor Format::patternForegroundColor() const { - return colorProperty(FormatPrivate::P_Fill_FgColor); + return colorProperty(FormatPrivate::P_Fill_FgColor); } /*! - Sets the foreground color of the pattern with the given \a color. + Sets the foreground color of the pattern with the given \a color. */ void Format::setPatternForegroundColor(const QColor &color) { - if (color.isValid() && !hasProperty(FormatPrivate::P_Fill_Pattern)) - setFillPattern(PatternSolid); - setProperty(FormatPrivate::P_Fill_FgColor, XlsxColor(color), XlsxColor()); + if (color.isValid() && !hasProperty(FormatPrivate::P_Fill_Pattern)) + setFillPattern(PatternSolid); + setProperty(FormatPrivate::P_Fill_FgColor, XlsxColor(color), XlsxColor()); } /*! - Returns the background color of the pattern. + Returns the background color of the pattern. */ QColor Format::patternBackgroundColor() const { - return colorProperty(FormatPrivate::P_Fill_BgColor); + return colorProperty(FormatPrivate::P_Fill_BgColor); } /*! - Sets the background color of the pattern with the given \a color. + Sets the background color of the pattern with the given \a color. */ void Format::setPatternBackgroundColor(const QColor &color) { - if (color.isValid() && !hasProperty(FormatPrivate::P_Fill_Pattern)) - setFillPattern(PatternSolid); - setProperty(FormatPrivate::P_Fill_BgColor, XlsxColor(color), XlsxColor()); + if (color.isValid() && !hasProperty(FormatPrivate::P_Fill_Pattern)) + setFillPattern(PatternSolid); + setProperty(FormatPrivate::P_Fill_BgColor, XlsxColor(color), XlsxColor()); } /*! @@ -1010,9 +1024,9 @@ void Format::setPatternBackgroundColor(const QColor &color) */ bool Format::fillIndexValid() const { - if (!hasFillData()) - return false; - return d->fill_index_valid; + if (!hasFillData()) + return false; + return d->fill_index_valid; } /*! @@ -1020,9 +1034,9 @@ bool Format::fillIndexValid() const */ int Format::fillIndex() const { - if (fillIndexValid()) - return d->fill_index; - return 0; + if (fillIndexValid()) + return d->fill_index; + return 0; } /*! @@ -1030,8 +1044,8 @@ int Format::fillIndex() const */ void Format::setFillIndex(int index) { - d->fill_index = index; - d->fill_index_valid = true; + d->fill_index = index; + d->fill_index_valid = true; } /*! @@ -1039,127 +1053,127 @@ void Format::setFillIndex(int index) */ QByteArray Format::fillKey() const { - if (isEmpty()) - return QByteArray(); + if (isEmpty()) + return QByteArray(); - if (d->fill_dirty) { - QByteArray key; - QDataStream stream(&key, QIODevice::WriteOnly); - for (int i=FormatPrivate::P_Fill_STARTID; ifill_dirty) { + QByteArray key; + QDataStream stream(&key, QIODevice::WriteOnly); + for (int i = FormatPrivate::P_Fill_STARTID; i < FormatPrivate::P_Fill_ENDID; ++i) { auto it = d->properties.constFind(i); if (it != d->properties.constEnd()) stream << i << it.value(); - }; + }; - const_cast(this)->d->fill_key = key; - const_cast(this)->d->fill_dirty = false; - } + const_cast(this)->d->fill_key = key; + const_cast(this)->d->fill_dirty = false; + } - return d->fill_key; + return d->fill_key; } /*! - \internal - Return true if the format has fill format, otherwise return false. + \internal + Return true if the format has fill format, otherwise return false. */ bool Format::hasFillData() const { - if (!d) - return false; + if (!d) + return false; - for (int i=FormatPrivate::P_Fill_STARTID; i