Merge pull request #3065 from shun-iwasawa/fix_crash_on_exporting_xdts

Fix Crash on Exporting XDTS When There are No Columns to be Exported
This commit is contained in:
Rodney 2020-01-27 03:02:13 -06:00 committed by GitHub
commit 1af1ae59bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 9 deletions

View file

@ -20,6 +20,7 @@
#include "tapp.h"
#include "menubarcommandids.h"
#include "xdtsimportpopup.h"
#include "filebrowserpopup.h"
#include <iostream>
#include <QJsonObject>
@ -340,7 +341,12 @@ void XdtsTimeTableItem::build(TXsheet *xsheet, QString name) {
XdtsTimeTableFieldItem field;
field.build(xsheet, m_duration, columnLabels);
m_fields.append(field);
while (columnLabels.last().isEmpty()) columnLabels.removeLast();
while (!columnLabels.isEmpty() && columnLabels.last().isEmpty())
columnLabels.removeLast();
if (columnLabels.isEmpty()) {
m_fields.clear();
return;
}
XdtsTimeTableHeaderItem header;
header.build(columnLabels);
m_timeTableHeaders.append(header);
@ -388,6 +394,7 @@ QStringList XdtsData::getLevelNames() const {
void XdtsData::build(TXsheet *xsheet, QString name) {
XdtsTimeTableItem timeTable;
timeTable.build(xsheet, name);
if (timeTable.isEmpty()) return;
m_timeTables.append(timeTable);
}
@ -511,17 +518,28 @@ void ExportXDTSCommand::execute() {
ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
TFilePath fp = scene->getScenePath().withType("xdts");
if (TSystem::doesExistFileOrLevel(fp)) {
QString question =
QObject::tr("The file %1 already exists.\nDo you want to overwrite it?")
.arg(toQString(fp));
int ret = DVGui::MsgBox(question, QObject::tr("Overwrite"),
QObject::tr("Cancel"), 0);
if (ret == 2 || ret == 0) return;
}
XdtsData xdtsData;
xdtsData.build(xsheet, QString::fromStdString(fp.getName()));
if (xdtsData.isEmpty()) {
DVGui::error(QObject::tr("No columns can be exported."));
return;
}
static GenericSaveFilePopup *savePopup = 0;
if (!savePopup) {
savePopup = new GenericSaveFilePopup(
QObject::tr("Export Exchange Digital Time Sheet (XDTS)"));
savePopup->addFilterType("xdts");
}
if (!scene->isUntitled())
savePopup->setFolder(fp.getParentDir());
else
savePopup->setFolder(
TProjectManager::instance()->getCurrentProject()->getScenesPath());
savePopup->setFilename(fp.withoutParentDir());
fp = savePopup->getPath();
if (fp.isEmpty()) return;
QFile saveFile(fp.getQString());

View file

@ -212,6 +212,10 @@ public:
int getDuration() { return m_duration; }
void build(TXsheet *, QString);
bool isEmpty() {
return m_duration == 0 || m_fields.isEmpty() ||
m_timeTableHeaders.isEmpty();
}
};
// "$schema": "http://json-schema.org/draft-07/schema",
@ -233,6 +237,7 @@ public:
QStringList getLevelNames() const;
XdtsTimeTableItem &timeTable() { return m_timeTables[0]; }
void build(TXsheet *, QString);
bool isEmpty() { return m_timeTables.isEmpty(); }
};
bool loadXdtsScene(ToonzScene *scene, const TFilePath &scenePath);