2018-09-27 17:41:21 +09:00
|
|
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QString>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "ui_MainWindow.h"
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
|
QMainWindow(parent),
|
|
|
|
ui(new Ui::MainWindow)
|
|
|
|
{
|
|
|
|
xlsxDoc = NULL;
|
|
|
|
tabWidget = NULL;
|
|
|
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
tabWidget = new QTabWidget(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
// tabWidget->close();
|
|
|
|
|
|
|
|
delete ui;
|
|
|
|
|
|
|
|
if ( NULL != xlsxDoc )
|
|
|
|
{
|
|
|
|
delete xlsxDoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_action_Quit_triggered()
|
|
|
|
{
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_action_Open_triggered()
|
|
|
|
{
|
2018-09-27 19:08:49 +09:00
|
|
|
// open file dialog
|
2018-09-27 17:41:21 +09:00
|
|
|
QString fileName = QFileDialog::getOpenFileName(this,
|
|
|
|
tr("Open Excel"), ".", tr("Excel Files (*.xlsx)"));
|
|
|
|
|
|
|
|
// tried to load xlsx
|
|
|
|
QXlsx::Document xlsxTmp(fileName);
|
|
|
|
if (!xlsxTmp.isLoadPackage())
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
|
|
|
QString alertMsg = QString("Failed to load file.\n %1").arg(fileName);
|
|
|
|
msgBox.setText(alertMsg);
|
|
|
|
msgBox.exec();
|
|
|
|
return;
|
|
|
|
}
|
2018-09-27 19:08:49 +09:00
|
|
|
|
2018-09-27 19:23:21 +09:00
|
|
|
bool returnLoading = loadXlsx(fileName);
|
|
|
|
}
|
2018-09-27 17:41:21 +09:00
|
|
|
|
2018-09-27 19:23:21 +09:00
|
|
|
bool MainWindow::loadXlsx(QString fileName)
|
|
|
|
{
|
2018-09-27 17:41:21 +09:00
|
|
|
// clear xlsxDoc
|
|
|
|
if ( NULL != xlsxDoc )
|
|
|
|
{
|
|
|
|
delete xlsxDoc;
|
|
|
|
xlsxDoc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// load new xlsx
|
|
|
|
xlsxDoc = new QXlsx::Document(fileName);
|
|
|
|
xlsxDoc->isLoadPackage();
|
|
|
|
|
2018-09-27 19:23:21 +09:00
|
|
|
// clear tab widget
|
2018-09-27 19:04:11 +09:00
|
|
|
tabWidget->clear();
|
|
|
|
// Removes all the pages, but does not delete them.
|
|
|
|
// Calling this function is equivalent to calling removeTab() until the tab widget is empty.
|
|
|
|
//
|
2018-09-27 17:41:21 +09:00
|
|
|
//for ( int ic = 0 ; ic < tabWidget->count() ; ic++ ) {
|
|
|
|
// tabWidget->removeTab( ic );
|
|
|
|
//}
|
|
|
|
|
2018-09-27 19:08:49 +09:00
|
|
|
// TODO: clear sub-items of every tab
|
|
|
|
|
2018-09-27 17:41:21 +09:00
|
|
|
foreach( QString curretnSheetName, xlsxDoc->sheetNames() ) {
|
|
|
|
QXlsx::AbstractSheet* currentSheet = xlsxDoc->sheet( curretnSheetName );
|
2018-09-27 19:04:11 +09:00
|
|
|
if ( NULL == currentSheet )
|
|
|
|
continue;
|
2018-09-27 17:41:21 +09:00
|
|
|
|
2018-09-27 19:08:49 +09:00
|
|
|
// create new tab
|
2018-09-27 19:04:11 +09:00
|
|
|
// XlsxTab* newSheet = new XlsxTab( this, currentSheet );
|
2018-09-27 19:08:49 +09:00
|
|
|
|
2018-09-27 19:04:11 +09:00
|
|
|
// TODO: append to xlsx pointer list
|
2018-09-27 19:08:49 +09:00
|
|
|
|
2018-09-27 19:04:11 +09:00
|
|
|
// tabWidget->addTab( newSheet );
|
2018-09-27 17:41:21 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|