OpenToonz - An open-source full-featured 2D animation creation software
C
fix crash on exporting xdts
shun-iwasawa10e7dfeeb8dd
diff --git a/toonz/sources/toonz/xdtsio.cpp b/toonz/sources/toonz/xdtsio.cppindex b7f26d12f..4c0c2306b 100644--- a/toonz/sources/toonz/xdtsio.cpp+++ b/toonz/sources/toonz/xdtsio.cpp@@ -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());diff --git a/toonz/sources/toonz/xdtsio.h b/toonz/sources/toonz/xdtsio.hindex d1880a031..436d6c379 100644--- a/toonz/sources/toonz/xdtsio.h+++ b/toonz/sources/toonz/xdtsio.h@@ -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);