Make use of clang-format

Change-Id: I71bbf133223931eddb0c7e568cc0b99ecf807fa1
This commit is contained in:
Debao Zhang
2020-03-19 01:33:41 +08:00
parent d013edc9cf
commit 534490e9b2
88 changed files with 2527 additions and 2040 deletions
+23 -24
View File
@@ -10,16 +10,16 @@ int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
//Select a proper locale
//QLocale::setDefault(QLocale(QLocale::English));
// Select a proper locale
// QLocale::setDefault(QLocale(QLocale::English));
Document xlsx;
QDate today(QDate::currentDate());
for (int month=1; month<=12; ++month) {
for (int month = 1; month <= 12; ++month) {
xlsx.addSheet(QLocale().monthName(month));
xlsx.currentWorksheet()->setGridLinesVisible(false);
//the header row
// the header row
Format headerStyle;
headerStyle.setFontSize(48);
headerStyle.setFontColor(Qt::darkBlue);
@@ -29,8 +29,8 @@ int main(int argc, char **argv)
xlsx.write("A1", QString("%1 %2").arg(QLocale().monthName(month)).arg(today.year()));
xlsx.mergeCells("A1:N1", headerStyle);
//header with month titles
for (int day=1; day<=7; ++day) {
// header with month titles
for (int day = 1; day <= 7; ++day) {
Format monthStyle;
monthStyle.setFontSize(12);
monthStyle.setFontColor(Qt::white);
@@ -40,10 +40,10 @@ int main(int argc, char **argv)
monthStyle.setFillPattern(Format::PatternSolid);
monthStyle.setPatternBackgroundColor(Qt::darkBlue);
xlsx.setColumnWidth(day*2-1, day*2-1, 5);
xlsx.setColumnWidth(day*2, day*2, 13);
xlsx.write(2, day*2-1, QLocale().dayName(day));
xlsx.mergeCells(CellRange(2, day*2-1, 2, day*2), monthStyle);
xlsx.setColumnWidth(day * 2 - 1, day * 2 - 1, 5);
xlsx.setColumnWidth(day * 2, day * 2, 13);
xlsx.write(2, day * 2 - 1, QLocale().dayName(day));
xlsx.mergeCells(CellRange(2, day * 2 - 1, 2, day * 2), monthStyle);
}
QColor borderColor = QColor(Qt::gray);
@@ -101,43 +101,42 @@ int main(int argc, char **argv)
greyRightStyle.setBottomBorderColor(borderColor);
int rownum = 3;
for (int day=1; day<=31; ++day) {
for (int day = 1; day <= 31; ++day) {
QDate date(today.year(), month, day);
if (!date.isValid())
break;
xlsx.setRowHeight(rownum, 100);
int dow = date.dayOfWeek();
int colnum = dow*2-1;
int colnum = dow * 2 - 1;
if (dow <= 5) {
xlsx.write(rownum, colnum, day, workdayLeftStyle);
xlsx.write(rownum, colnum+1, QVariant(), workdayRightStyle);
xlsx.write(rownum, colnum + 1, QVariant(), workdayRightStyle);
} else {
xlsx.write(rownum, colnum, day, weekendLeftStyle);
xlsx.write(rownum, colnum+1, QVariant(), weekendRightStyle);
xlsx.write(rownum, colnum + 1, QVariant(), weekendRightStyle);
}
if (day == 1 && dow != 1) {//First day
for (int i=1; i<dow; ++i) {
xlsx.write(rownum, i*2-1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i*2, QVariant(), greyRightStyle);
if (day == 1 && dow != 1) { // First day
for (int i = 1; i < dow; ++i) {
xlsx.write(rownum, i * 2 - 1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i * 2, QVariant(), greyRightStyle);
}
} else if (day == date.daysInMonth() && dow != 7) {//Last day
for (int i=dow+1; i<=7; ++i) {
xlsx.write(rownum, i*2-1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i*2, QVariant(), greyRightStyle);
} else if (day == date.daysInMonth() && dow != 7) { // Last day
for (int i = dow + 1; i <= 7; ++i) {
xlsx.write(rownum, i * 2 - 1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i * 2, QVariant(), greyRightStyle);
}
}
if (dow == 7)
rownum++;
}
}
xlsx.saveAs("Book1.xlsx");
//Make sure that read/write works well.
// Make sure that read/write works well.
Document xlsx2("Book1.xlsx");
xlsx2.saveAs("Book2.xlsx");
+6 -6
View File
@@ -9,10 +9,10 @@ int main()
{
//![0]
Document xlsx;
for (int i=1; i<10; ++i) {
xlsx.write(i, 1, i*i*i); //A1:A9
xlsx.write(i, 2, i*i); //B1:B9
xlsx.write(i, 3, i*i-1); //C1:C9
for (int i = 1; i < 10; ++i) {
xlsx.write(i, 1, i * i * i); // A1:A9
xlsx.write(i, 2, i * i); // B1:B9
xlsx.write(i, 3, i * i - 1); // C1:C9
}
//![0]
@@ -53,14 +53,14 @@ int main()
Chart *scatterChart = xlsx.insertChart(83, 3, QSize(300, 300));
scatterChart->setChartType(Chart::CT_Scatter);
//Will generate three lines.
// Will generate three lines.
scatterChart->addSeries(CellRange("A1:A9"));
scatterChart->addSeries(CellRange("B1:B9"));
scatterChart->addSeries(CellRange("C1:C9"));
Chart *scatterChart_2 = xlsx.insertChart(83, 9, QSize(300, 300));
scatterChart_2->setChartType(Chart::CT_Scatter);
//Will generate two lines.
// Will generate two lines.
scatterChart_2->addSeries(CellRange("A1:C9"));
Chart *doughnutChart = xlsx.insertChart(103, 3, QSize(300, 300));
+3 -3
View File
@@ -10,13 +10,13 @@ int main()
{
//![0]
Document xlsx;
for (int i=1; i<10; ++i)
xlsx.write(i, 1, i*i);
for (int i = 1; i < 10; ++i)
xlsx.write(i, 1, i * i);
//![0]
//![1]
xlsx.addSheet("Chart1", AbstractSheet::ST_ChartSheet);
Chartsheet *sheet = static_cast<Chartsheet*>(xlsx.currentSheet());
Chartsheet *sheet = static_cast<Chartsheet *>(xlsx.currentSheet());
Chart *barChart = sheet->chart();
barChart->setChartType(Chart::CT_Bar);
barChart->addSeries(CellRange("A1:A9"), xlsx.sheet("Sheet1"));
+2 -2
View File
@@ -16,8 +16,8 @@ int main()
xlsx.write("E1", "dataBar", hFmt);
xlsx.write("F1", "colorScale", hFmt);
for (int row=3; row<22; ++row) {
for (int col=2; col<22; ++col)
for (int row = 3; row < 22; ++row) {
for (int col = 2; col < 22; ++col)
xlsx.write(row, col, qrand() % 100);
}
//![0]
+3 -3
View File
@@ -7,10 +7,10 @@ int main()
{
//![0]
Document xlsx;
for (int i=1; i<=10; ++i) {
for (int i = 1; i <= 10; ++i) {
xlsx.write(i, 1, i);
xlsx.write(i, 2, i*i);
xlsx.write(i, 3, i*i*i);
xlsx.write(i, 2, i * i);
xlsx.write(i, 3, i * i * i);
}
//![0]
//![1]
+49 -44
View File
@@ -6,53 +6,58 @@
QTXLSX_USE_NAMESPACE
void writeHorizontalAlignCell(Document &xlsx, const QString &cell, const QString &text, Format::HorizontalAlignment align)
void writeHorizontalAlignCell(Document &xlsx, const QString &cell, const QString &text,
Format::HorizontalAlignment align)
{
Format format;
format.setHorizontalAlignment(align);
format.setBorderStyle(Format::BorderThin);
xlsx.write(cell, text, format);
Format format;
format.setHorizontalAlignment(align);
format.setBorderStyle(Format::BorderThin);
xlsx.write(cell, text, format);
}
void writeVerticalAlignCell(Document &xlsx, const QString &range, const QString &text, Format::VerticalAlignment align)
void writeVerticalAlignCell(Document &xlsx, const QString &range, const QString &text,
Format::VerticalAlignment align)
{
Format format;
format.setVerticalAlignment(align);
format.setBorderStyle(Format::BorderThin);
CellRange r(range);
xlsx.write(r.firstRow(), r.firstColumn(), text);
xlsx.mergeCells(r, format);
Format format;
format.setVerticalAlignment(align);
format.setBorderStyle(Format::BorderThin);
CellRange r(range);
xlsx.write(r.firstRow(), r.firstColumn(), text);
xlsx.mergeCells(r, format);
}
void writeBorderStyleCell(Document &xlsx, const QString &cell, const QString &text, Format::BorderStyle bs)
void writeBorderStyleCell(Document &xlsx, const QString &cell, const QString &text,
Format::BorderStyle bs)
{
Format format;
format.setBorderStyle(bs);
xlsx.write(cell, text, format);
Format format;
format.setBorderStyle(bs);
xlsx.write(cell, text, format);
}
void writeSolidFillCell(Document &xlsx, const QString &cell, const QColor &color)
{
Format format;
format.setPatternBackgroundColor(color);
xlsx.write(cell, QVariant(), format);
Format format;
format.setPatternBackgroundColor(color);
xlsx.write(cell, QVariant(), format);
}
void writePatternFillCell(Document &xlsx, const QString &cell, Format::FillPattern pattern, const QColor &color)
void writePatternFillCell(Document &xlsx, const QString &cell, Format::FillPattern pattern,
const QColor &color)
{
Format format;
format.setPatternForegroundColor(color);
format.setFillPattern(pattern);
xlsx.write(cell, QVariant(), format);
Format format;
format.setPatternForegroundColor(color);
format.setFillPattern(pattern);
xlsx.write(cell, QVariant(), format);
}
void writeBorderAndFontColorCell(Document &xlsx, const QString &cell, const QString &text, const QColor &color)
void writeBorderAndFontColorCell(Document &xlsx, const QString &cell, const QString &text,
const QColor &color)
{
Format format;
format.setBorderStyle(Format::BorderThin);
format.setBorderColor(color);
format.setFontColor(color);
xlsx.write(cell, text, format);
Format format;
format.setBorderStyle(Format::BorderThin);
format.setBorderColor(color);
format.setFontColor(color);
xlsx.write(cell, text, format);
}
void writeFontNameCell(Document &xlsx, const QString &cell, const QString &text)
@@ -93,13 +98,13 @@ int main()
Document xlsx;
//---------------------------------------------------------------
//Create the first sheet (Otherwise, default "Sheet1" will be created)
// Create the first sheet (Otherwise, default "Sheet1" will be created)
xlsx.addSheet("Aligns & Borders");
xlsx.setColumnWidth(2, 20); //Column B
xlsx.setColumnWidth(8, 12); //Column H
xlsx.setColumnWidth(2, 20); // Column B
xlsx.setColumnWidth(8, 12); // Column H
xlsx.currentWorksheet()->setGridLinesVisible(false);
//Alignment
// Alignment
writeHorizontalAlignCell(xlsx, "B3", "AlignLeft", Format::AlignLeft);
writeHorizontalAlignCell(xlsx, "B5", "AlignHCenter", Format::AlignHCenter);
writeHorizontalAlignCell(xlsx, "B7", "AlignRight", Format::AlignRight);
@@ -107,7 +112,7 @@ int main()
writeVerticalAlignCell(xlsx, "F3:F7", "AlignVCenter", Format::AlignVCenter);
writeVerticalAlignCell(xlsx, "H3:H7", "AlignBottom", Format::AlignBottom);
//Border
// Border
writeBorderStyleCell(xlsx, "B13", "BorderMedium", Format::BorderMedium);
writeBorderStyleCell(xlsx, "B15", "BorderDashed", Format::BorderDashed);
writeBorderStyleCell(xlsx, "B17", "BorderDotted", Format::BorderDotted);
@@ -115,7 +120,7 @@ int main()
writeBorderStyleCell(xlsx, "B21", "BorderDouble", Format::BorderDouble);
writeBorderStyleCell(xlsx, "B23", "BorderDashDot", Format::BorderDashDot);
//Fill
// Fill
writeSolidFillCell(xlsx, "D13", Qt::red);
writeSolidFillCell(xlsx, "D15", Qt::blue);
writeSolidFillCell(xlsx, "D17", Qt::yellow);
@@ -137,7 +142,7 @@ int main()
writeBorderAndFontColorCell(xlsx, "H23", "Qt::gray", Qt::gray);
//---------------------------------------------------------------
//Create the second sheet.
// Create the second sheet.
xlsx.addSheet("Fonts");
xlsx.write("B3", "Normal");
@@ -177,7 +182,7 @@ int main()
xlsx.mergeCells("J3:J9");
//---------------------------------------------------------------
//Create the third sheet.
// Create the third sheet.
xlsx.addSheet("Formulas");
xlsx.setColumnWidth(1, 2, 40);
Format rAlign;
@@ -240,7 +245,7 @@ int main()
xlsx.write("B33", "=HYPERLINK(\"http://qt-project.org\")", lAlign);
//---------------------------------------------------------------
//Create the fourth sheet.
// Create the fourth sheet.
xlsx.addSheet("NumFormats");
xlsx.setColumnWidth(2, 40);
writeInternalNumFormatsCell(xlsx, 4, 2.5681, 2);
@@ -258,7 +263,7 @@ int main()
writeCustomNumFormatsCell(xlsx, 16, 60, "[Red][<=100];[Green][>100]");
//---------------------------------------------------------------
//Create the fifth sheet.
// Create the fifth sheet.
xlsx.addSheet("Merging");
Format centerAlign;
centerAlign.setHorizontalAlignment(Format::AlignHCenter);
@@ -271,11 +276,11 @@ int main()
xlsx.mergeCells("E8:F21", centerAlign);
//---------------------------------------------------------------
//Create the fifth sheet.
// Create the fifth sheet.
xlsx.addSheet("Grouping");
qsrand(QDateTime::currentMSecsSinceEpoch());
for (int row=2; row<31; ++row) {
for (int col=1; col<=10; ++col)
for (int row = 2; row < 31; ++row) {
for (int col = 1; col <= 10; ++col)
xlsx.write(row, col, qrand() % 100);
}
xlsx.groupRows(4, 7);
@@ -288,7 +293,7 @@ int main()
xlsx.saveAs("Book1.xlsx");
//Make sure that read/write works well.
// Make sure that read/write works well.
Document xlsx2("Book1.xlsx");
xlsx2.saveAs("Book2.xlsx");
+20 -20
View File
@@ -4,16 +4,16 @@
int main()
{
{
//Create a new .xlsx file.
QXlsx::Document xlsx;
xlsx.write("A1", "Hello Qt!");
xlsx.write("A2", 12345);
xlsx.write("A3", "=44+33");
xlsx.write("A4", true);
xlsx.write("A5", "http://qt-project.org");
xlsx.write("A6", QDate(2013, 12, 27));
xlsx.write("A7", QTime(6, 30));
xlsx.saveAs("Book1.xlsx");
// Create a new .xlsx file.
QXlsx::Document xlsx;
xlsx.write("A1", "Hello Qt!");
xlsx.write("A2", 12345);
xlsx.write("A3", "=44+33");
xlsx.write("A4", true);
xlsx.write("A5", "http://qt-project.org");
xlsx.write("A6", QDate(2013, 12, 27));
xlsx.write("A7", QTime(6, 30));
xlsx.saveAs("Book1.xlsx");
}
//![0]
@@ -21,19 +21,19 @@ int main()
//![0]
//![1]
qDebug()<<xlsx.read("A1");
qDebug()<<xlsx.read("A2");
qDebug()<<xlsx.read("A3");
qDebug()<<xlsx.read("A4");
qDebug()<<xlsx.read("A5");
qDebug()<<xlsx.read("A6");
qDebug()<<xlsx.read("A7");
qDebug() << xlsx.read("A1");
qDebug() << xlsx.read("A2");
qDebug() << xlsx.read("A3");
qDebug() << xlsx.read("A4");
qDebug() << xlsx.read("A5");
qDebug() << xlsx.read("A6");
qDebug() << xlsx.read("A7");
//![1]
//![2]
for (int row=1; row<10; ++row) {
if (QXlsx::Cell *cell=xlsx.cellAt(row, 1))
qDebug()<<cell->value();
for (int row = 1; row < 10; ++row) {
if (QXlsx::Cell *cell = xlsx.cellAt(row, 1))
qDebug() << cell->value();
}
//![2]
+16 -12
View File
@@ -54,24 +54,28 @@ int main()
xlsx.addSheet("ArrayFormula");
Worksheet *sheet = xlsx.currentWorksheet();
for (int row=2; row<20; ++row) {
sheet->write(row, 2, row*2); //B2:B19
sheet->write(row, 3, row*3); //C2:C19
for (int row = 2; row < 20; ++row) {
sheet->write(row, 2, row * 2); // B2:B19
sheet->write(row, 3, row * 3); // C2:C19
}
sheet->writeFormula("D2", CellFormula("B2:B19+C2:C19", "D2:D19", CellFormula::ArrayType));
sheet->writeFormula("E2", CellFormula("=CONCATENATE(\"The total is \",D2:D19,\" units\")", "E2:E19", CellFormula::ArrayType));
sheet->writeFormula("E2",
CellFormula("=CONCATENATE(\"The total is \",D2:D19,\" units\")", "E2:E19",
CellFormula::ArrayType));
//![2]
//![21]
xlsx.addSheet("SharedFormula");
sheet = xlsx.currentWorksheet();
for (int row=2; row<20; ++row) {
sheet->write(row, 2, row*2); //B2:B19
sheet->write(row, 3, row*3); //C2:C19
for (int row = 2; row < 20; ++row) {
sheet->write(row, 2, row * 2); // B2:B19
sheet->write(row, 3, row * 3); // C2:C19
}
sheet->writeFormula("D2", CellFormula("=B2+C2", "D2:D19", CellFormula::SharedType));
sheet->writeFormula("E2", CellFormula("=CONCATENATE(\"The total is \",D2,\" units\")", "E2:E19", CellFormula::SharedType));
sheet->writeFormula("E2",
CellFormula("=CONCATENATE(\"The total is \",D2,\" units\")", "E2:E19",
CellFormula::SharedType));
//![21]
@@ -79,11 +83,11 @@ int main()
xlsx.save();
//![3]
//Make sure that read/write works well.
// Make sure that read/write works well.
Document xlsx2("Book1.xlsx");
Worksheet *sharedFormulaSheet = dynamic_cast<Worksheet*>(xlsx2.sheet("SharedFormula"));
for (int row=2; row<20; ++row) {
qDebug()<<sharedFormulaSheet->read(row, 4);
Worksheet *sharedFormulaSheet = dynamic_cast<Worksheet *>(xlsx2.sheet("SharedFormula"));
for (int row = 2; row < 20; ++row) {
qDebug() << sharedFormulaSheet->read(row, 4);
}
xlsx2.saveAs("Book2.xlsx");
+3 -3
View File
@@ -1,15 +1,15 @@
#include <QtGui>
#include "xlsxdocument.h"
int main(int argc, char** argv)
int main(int argc, char **argv)
{
QGuiApplication(argc, argv);
QXlsx::Document xlsx;
QImage image(40, 30, QImage::Format_RGB32);
image.fill(Qt::green);
for (int i=0; i<10; ++i)
xlsx.insertImage(10*i, 5, image);
for (int i = 0; i < 10; ++i)
xlsx.insertImage(10 * i, 5, image);
xlsx.saveAs("Book1.xlsx");
QXlsx::Document xlsx2("Book1.xlsx");
-1
View File
@@ -23,4 +23,3 @@ int main()
return 0;
}
+11 -11
View File
@@ -2,7 +2,7 @@
#include "xlsxdocument.h"
#include "xlsxformat.h"
int main(int argc, char** argv)
int main(int argc, char **argv)
{
QGuiApplication(argc, argv);
@@ -13,17 +13,17 @@ int main(int argc, char** argv)
header.setFontBold(true);
header.setFontSize(20);
//Custom number formats
// Custom number formats
QStringList numFormats;
numFormats<<"Qt #"
<<"yyyy-mmm-dd"
<<"$ #,##0.00"
<<"[red]0.00";
numFormats << "Qt #"
<< "yyyy-mmm-dd"
<< "$ #,##0.00"
<< "[red]0.00";
xlsx.write(1, 1, "Raw data", header);
xlsx.write(1, 2, "Format", header);
xlsx.write(1, 3, "Shown value", header);
for (int i=0; i<numFormats.size(); ++i) {
int row = i+2;
for (int i = 0; i < numFormats.size(); ++i) {
int row = i + 2;
xlsx.write(row, 1, 100.0);
xlsx.write(row, 2, numFormats[i]);
QXlsx::Format format;
@@ -31,14 +31,14 @@ int main(int argc, char** argv)
xlsx.write(row, 3, 100.0, format);
}
//Builtin number formats
// Builtin number formats
xlsx.addSheet();
xlsx.setColumnWidth(1, 4, 20.0);
xlsx.write(1, 1, "Raw data", header);
xlsx.write(1, 2, "Builtin Format", header);
xlsx.write(1, 3, "Shown value", header);
for (int i=0; i<50; ++i) {
int row = i+2;
for (int i = 0; i < 50; ++i) {
int row = i + 2;
int numFmt = i;
xlsx.write(row, 1, 100.0);
xlsx.write(row, 2, numFmt);
+7 -7
View File
@@ -7,13 +7,13 @@ int main()
QXlsx::Document xlsx;
xlsx.write(1, 2, "Row:0, Col:2 ==> (C1)");
//Set the height of the first row to 50.0(points)
// Set the height of the first row to 50.0(points)
xlsx.setRowHeight(1, 50.0);
//Set the width of the third column to 40.0(chars)
// Set the width of the third column to 40.0(chars)
xlsx.setColumnWidth(3, 3, 40.0);
//Set style for the row 11th.
// Set style for the row 11th.
QXlsx::Format format1;
format1.setFontBold(true);
format1.setFontColor(QColor(Qt::blue));
@@ -23,13 +23,13 @@ int main()
xlsx.setRowFormat(11, format1);
xlsx.setRowHeight(11, 41);
//Set style for the col [9th, 16th)
// Set style for the col [9th, 16th)
QXlsx::Format format2;
format2.setFontBold(true);
format2.setFontColor(QColor(Qt::magenta));
for (int row=12; row<=30; row++)
for (int col=9; col<=15; col++)
xlsx.write(row, col, row+col);
for (int row = 12; row <= 30; row++)
for (int col = 9; col <= 15; col++)
xlsx.write(row, col, row + col);
xlsx.setColumnWidth(9, 16, 5.0);
xlsx.setColumnFormat(9, 16, format2);
+3 -3
View File
@@ -31,9 +31,9 @@ int main()
QXlsx::Format format4;
format4.setFontBold(true);
format4.setFontColor(QColor(Qt::magenta));
for (int row=21; row<=40; row++)
for (int col=9; col<16; col++)
xlsx.write(row, col, row+col);
for (int row = 21; row <= 40; row++)
for (int col = 9; col < 16; col++)
xlsx.write(row, col, row + col);
xlsx.setColumnFormat(9, 16, format4);
xlsx.write("A5", QDate(2013, 8, 29));
+3 -3
View File
@@ -9,8 +9,8 @@ int main()
//![Create a xlsx file]
Document xlsx;
for (int i=1; i<20; ++i) {
for (int j=1; j<15; ++j)
for (int i = 1; i < 20; ++i) {
for (int j = 1; j < 15; ++j)
xlsx.write(i, j, QString("R %1 C %2").arg(i).arg(j));
}
xlsx.addSheet();
@@ -26,7 +26,7 @@ int main()
xlsx.sheet("VeryHiddenSheet")->setSheetState(AbstractSheet::SS_VeryHidden);
xlsx.write("A1", "This sheet is very hidden.");
xlsx.save();//Default name is "Book1.xlsx"
xlsx.save(); // Default name is "Book1.xlsx"
//![Create a xlsx file]
Document xlsx2("Book1.xlsx");
+2 -1
View File
@@ -30,7 +30,8 @@ int main(int argc, char **argv)
QTableView *view = new QTableView(&tabWidget);
view->setModel(new SheetModel(sheet, view));
foreach (CellRange range, sheet->mergedCells())
view->setSpan(range.firstRow()-1, range.firstColumn()-1, range.rowCount(), range.columnCount());
view->setSpan(range.firstRow() - 1, range.firstColumn() - 1, range.rowCount(),
range.columnCount());
tabWidget.addTab(view, sheetName);
}
}
+9 -10
View File
@@ -32,9 +32,8 @@
QT_BEGIN_NAMESPACE_XLSX
SheetModelPrivate::SheetModelPrivate(SheetModel *p)
:q_ptr(p)
: q_ptr(p)
{
}
/*!
@@ -50,7 +49,8 @@ SheetModelPrivate::SheetModelPrivate(SheetModel *p)
* Creates a model object with the given \a sheet and \a parent.
*/
SheetModel::SheetModel(Worksheet *sheet, QObject *parent)
:QAbstractTableModel(parent), d_ptr(new SheetModelPrivate(this))
: QAbstractTableModel(parent)
, d_ptr(new SheetModelPrivate(this))
{
d_ptr->sheet = sheet;
}
@@ -63,14 +63,13 @@ SheetModel::~SheetModel()
delete d_ptr;
}
int SheetModel::rowCount(const QModelIndex &/*parent*/) const
int SheetModel::rowCount(const QModelIndex & /*parent*/) const
{
Q_D(const SheetModel);
return d->sheet->dimension().lastRow();
}
int SheetModel::columnCount(const QModelIndex &/*parent*/) const
int SheetModel::columnCount(const QModelIndex & /*parent*/) const
{
Q_D(const SheetModel);
return d->sheet->dimension().lastColumn();
@@ -90,10 +89,10 @@ QVariant SheetModel::data(const QModelIndex &index, int role) const
if (!index.isValid())
return QVariant();
Cell *cell = d->sheet->cellAt(index.row()+1, index.column()+1);
Cell *cell = d->sheet->cellAt(index.row() + 1, index.column() + 1);
if (!cell)
return QVariant();
QVariant userFriendlyValue = d->sheet->read(index.row()+1, index.column()+1);
QVariant userFriendlyValue = d->sheet->read(index.row() + 1, index.column() + 1);
if (role == Qt::DisplayRole) {
if (cell->isDateTime())
@@ -160,7 +159,7 @@ static 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;
}
@@ -186,7 +185,7 @@ bool SheetModel::setData(const QModelIndex &index, const QVariant &value, int ro
return false;
if (role == Qt::EditRole) {
if (d->sheet->write(index.row()+1, index.column()+1, value) == 0)
if (d->sheet->write(index.row() + 1, index.column() + 1, value) == 0)
return true;
}
+2 -2
View File
@@ -44,7 +44,7 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
Qt::ItemFlags flags(const QModelIndex & index) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
@@ -55,7 +55,7 @@ signals:
public slots:
private:
SheetModelPrivate * const d_ptr;
SheetModelPrivate *const d_ptr;
};
QT_END_NAMESPACE_XLSX