Skip to content

Commit 11bafef

Browse files
committed
Fix broken build
1 parent 9c70496 commit 11bafef

File tree

2 files changed

+30
-48
lines changed

2 files changed

+30
-48
lines changed

QXlsx/source/xlsxdocument.cpp

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -478,14 +478,12 @@ bool DocumentPrivate::saveCsv(QString mainCSVFileName) const
478478
{
479479
Q_Q(const Document);
480480

481-
int sheetIndexNumber = 0;
482-
foreach (QString curretnSheetName, q->sheetNames())
483-
{
481+
int sheetIndexNumber = 0;
482+
const auto sheetNames = q->sheetNames();
483+
for (const auto &curretnSheetName : sheetNames) {
484484

485485
QXlsx::AbstractSheet *currentSheet = q->sheet(curretnSheetName);
486-
487-
if (NULL == currentSheet)
488-
{
486+
if (currentSheet == nullptr) {
489487
continue;
490488
}
491489

@@ -495,72 +493,61 @@ bool DocumentPrivate::saveCsv(QString mainCSVFileName) const
495493

496494
currentSheet->workbook()->setActiveSheet(sheetIndexNumber);
497495

498-
Worksheet *wsheet = (Worksheet *) currentSheet->workbook()->activeSheet();
499-
if (NULL == wsheet)
500-
{
496+
Worksheet *wsheet = static_cast<Worksheet *>(currentSheet->workbook()->activeSheet());
497+
if (wsheet == nullptr) {
501498
continue;
502499
}
503500

504-
QString strSheetName = wsheet->sheetName(); // sheet name
505-
506-
QVector<CellLocation> clList = wsheet->getFullCells(&maxRow, &maxCol);
501+
QString strSheetName = wsheet->sheetName(); // sheet name
507502

508503
QVector<QVector<QString>> cellValues;
509-
for (int rc = 0; rc < maxRow; rc++)
510-
{
504+
for (int rc = 0; rc < maxRow; rc++) {
511505
QVector<QString> tempValue;
512506

513-
for (int cc = 0; cc < maxCol; cc++)
514-
{
515-
tempValue.push_back(QString(""));
507+
for (int cc = 0; cc < maxCol; cc++) {
508+
tempValue.push_back(QString{});
516509
}
517510

518511
cellValues.push_back(tempValue);
519512
}
520513

521-
for (int ic = 0; ic < clList.size(); ++ic)
522-
{
523-
CellLocation cl = clList.at(ic);
524-
514+
const QVector<CellLocation> clList = wsheet->getFullCells(&maxRow, &maxCol);
515+
for (const auto &cl : clList) {
525516
int row = cl.row - 1;
526517
int col = cl.col - 1;
527518

528519
std::shared_ptr<Cell> ptrCell = cl.cell; // cell pointer
529-
QVariant var = ptrCell->value();
530-
QString str = var.toString();
520+
QVariant var = ptrCell->value();
521+
QString str = var.toString();
531522

532523
cellValues[row][col] = str;
533524
}
534525

535526
// TODO:
536527
// (1) save as csv file name (using { mainCSVFileName + strSheetName })
537528

538-
QString csvFileName = mainCSVFileName + QString("_") + strSheetName + QString(".csv");
529+
QString csvFileName = mainCSVFileName + u'_' + strSheetName + QLatin1String(".csv");
539530
QFile csvFile(csvFileName);
540-
if ( ! csvFile.open( QIODevice::WriteOnly ) )
541-
{
531+
if (!csvFile.open(QIODevice::WriteOnly)) {
542532
continue;
543533
}
544534

545535
// (2) save sheet values
546536
// such as A,,B,,,,C,,,D,,
547537

548-
for (int rc = 0; rc < maxRow; rc++)
549-
{
550-
for (int cc = 0; cc < maxCol; cc++)
551-
{
538+
for (int rc = 0; rc < maxRow; rc++) {
539+
for (int cc = 0; cc < maxCol; cc++) {
552540

553541
QString cellData = cellValues[rc][cc];
554542

555-
if ( cellData.size() >= 0 )
556-
{
557-
csvFile.write( cellData.toUtf8() ); // cell data
543+
if (cellData.size() >= 0) {
544+
csvFile.write(cellData.toUtf8()); // cell data
558545
}
559546

560-
csvFile.write( QString(",").toLatin1() ); // delimeter
547+
csvFile.write(","); // delimeter
561548
}
562549

563-
csvFile.write( QString("\n").toLatin1() ); // CR
550+
csvFile.write("\n"); // CR
564551

565552
csvFile.flush();
566553
}
@@ -571,7 +558,6 @@ bool DocumentPrivate::saveCsv(QString mainCSVFileName) const
571558

572559
} // foreach (QString curretnSheetName, q->sheetNames()) ...
573560

574-
575561
return true;
576562
}
577563

@@ -1383,16 +1369,13 @@ bool Document::saveAs(QIODevice *device) const
13831369
return d->savePackage(device);
13841370
}
13851371

1386-
13871372
bool Document::saveAsCsv(const QString mainCSVFileName) const
13881373
{
13891374
Q_D(const Document);
13901375

1391-
return d->saveCsv( mainCSVFileName );
1376+
return d->saveCsv(mainCSVFileName);
13921377
}
13931378

1394-
1395-
13961379
bool Document::isLoadPackage() const
13971380
{
13981381
Q_D(const Document);

QXlsx/source/xlsxworkbook.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -607,19 +607,18 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
607607

608608
AbstractSheet *sheet = addSheet(name, sheetId, type);
609609
sheet->setSheetState(state);
610-
if (relationship.target.startsWith("/")) {
610+
if (relationship.target.startsWith(u'/')) {
611611
QString fullPath = QDir::cleanPath(relationship.target.mid(1));
612612

613613
sheet->setFilePath(fullPath);
614-
}else{
614+
} else {
615615
QString strFilePath = filePath();
616-
617-
// const QString fullPath = QDir::cleanPath(splitPath(strFilePath).constFirst() +
618-
// QLatin1String("/") + relationship.target);
616+
617+
// const QString fullPath = QDir::cleanPath(splitPath(strFilePath).constFirst()
618+
// + QLatin1String("/") + relationship.target);
619619
const auto parts = splitPath(strFilePath);
620-
QString fullPath =
621-
QDir::cleanPath(parts.first() + QLatin1String("/") + relationship.target);
622-
620+
QString fullPath = QDir::cleanPath(parts.first() + u'/' + relationship.target);
621+
623622
sheet->setFilePath(fullPath);
624623
}
625624
} else if (reader.name() == QLatin1String("workbookPr")) {

0 commit comments

Comments
 (0)