Merge pull request #2987 from shun-iwasawa/fix_xdts_io

Fix Crash on Loading XDTS and Other Improvements
This commit is contained in:
Rodney 2020-01-07 15:29:36 -06:00 committed by GitHub
commit dd5fb60491
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 5 deletions

View file

@ -2265,13 +2265,15 @@ void BrowserPopupController::openPopup(QStringList filters,
m_browserPopup->initFolder(TFilePath(lastSelectedPath.toStdWString()));
m_browserPopup->setFileMode(isDirectoryOnly);
Qt::WindowFlags flags = m_browserPopup->windowFlags();
bool parentSet = false;
if (parentWidget) {
for (QWidget *pwidget : QApplication::topLevelWidgets()) {
if (pwidget->isWindow() && pwidget->isVisible() &&
pwidget->isAncestorOf(parentWidget)) {
Qt::WindowFlags flags = m_browserPopup->windowFlags();
m_browserPopup->setParent(pwidget);
m_browserPopup->setWindowFlags(flags);
parentSet = true;
break;
}
}
@ -2284,6 +2286,13 @@ void BrowserPopupController::openPopup(QStringList filters,
m_isExecute = true;
else
m_isExecute = false;
// set back the parent to the main window in order to prevent to be
// deleted along with the parent widget
if (parentSet) {
m_browserPopup->setParent(TApp::instance()->getMainWindow());
m_browserPopup->setWindowFlags(flags);
}
}
// codePath is set to true by default

View file

@ -1917,6 +1917,7 @@ bool IoCmd::loadScene(const TFilePath &path, bool updateRecentFile,
scene->getProperties()->getFieldGuideAspectRatio());
IconGenerator::instance()->invalidateSceneIcon();
DvDirModel::instance()->refreshFolder(scenePath.getParentDir());
// set dirty for xdts files since converted tnz is not yet saved
TApp::instance()->getCurrentScene()->setDirtyFlag(isXdts);
History::instance()->addItem(scenePath);
if (updateRecentFile)

View file

@ -65,7 +65,7 @@ XDTSImportPopup::XDTSImportPopup(QStringList levelNames, ToonzScene* scene,
connect(loadButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
addButtonBarWidget(cancelButton, loadButton);
addButtonBarWidget(loadButton, cancelButton);
updateSuggestions(scenePath.getQString());
}
@ -75,8 +75,17 @@ XDTSImportPopup::XDTSImportPopup(QStringList levelNames, ToonzScene* scene,
void XDTSImportPopup::onPathChanged() {
FileField* fileField = dynamic_cast<FileField*>(sender());
if (!fileField) return;
QString levelName = m_fields.key(fileField);
// make the field non-suggestive
m_pathSuggestedLevels.removeAll(m_fields.key(fileField));
m_pathSuggestedLevels.removeAll(levelName);
// if the path is specified under the sub-folder with the same name as the
// level, then try to make suggestions from the parent folder of it
TFilePath fp =
m_scene->decodeFilePath(TFilePath(fileField->getPath())).getParentDir();
if (QDir(fp.getQString()).dirName() == levelName)
updateSuggestions(fp.getQString());
updateSuggestions(fileField->getPath());
}
@ -119,15 +128,39 @@ void XDTSImportPopup::updateSuggestions(const QString samplePath) {
if (fileField->getPath().isEmpty() ||
m_pathSuggestedLevels.contains(levelName)) {
// input suggestion if there is a file with the same level name
bool found = false;
for (TFilePath path : pathSet) {
if (path.getName() == levelName.toStdString()) {
TFilePath codedPath = m_scene->codeFilePath(path);
fileField->setPath(codedPath.getQString());
if (!m_pathSuggestedLevels.contains(levelName))
m_pathSuggestedLevels.append(levelName);
found = true;
break;
}
}
// Not found in the current folder.
// Then check if there is a sub-folder with the same name as the level
// (like foo/A/A.tlv), as CSP exports levels like that.
if (!found && suggestFolder.cd(levelName)) {
TFilePathSet subPathSet;
try {
TSystem::readDirectory(subPathSet, suggestFolder, true);
} catch (...) {
return;
}
for (TFilePath path : subPathSet) {
if (path.getName() == levelName.toStdString()) {
TFilePath codedPath = m_scene->codeFilePath(path);
fileField->setPath(codedPath.getQString());
if (!m_pathSuggestedLevels.contains(levelName))
m_pathSuggestedLevels.append(levelName);
break;
}
}
// back to parent folder
suggestFolder.cdUp();
}
}
++fieldsItr;
}

View file

@ -10,6 +10,9 @@
#include "toonz/txsheethandle.h"
#include "toonz/tscenehandle.h"
#include "toonz/preferences.h"
#include "toonz/sceneproperties.h"
#include "toonz/tstageobject.h"
#include "toutputproperties.h"
#include "toonzqt/menubarcommand.h"
#include "toonzqt/gutil.h"
@ -135,12 +138,19 @@ QVector<int> XdtsFieldTrackItem::getCellNumberTrack() const {
std::sort(frameCellNumbers.begin(), frameCellNumbers.end(), frameLessThan);
QVector<int> cells;
int currentFrame = 0;
int currentFrame = 0;
int initialNumber = 0;
for (QPair<int, int> &frameCellNumber : frameCellNumbers) {
while (currentFrame < frameCellNumber.first) {
cells.append((cells.isEmpty()) ? 0 : cells.last());
cells.append((cells.isEmpty()) ? initialNumber : cells.last());
currentFrame++;
}
// CSP may export negative frame data (although it is not allowed in XDTS
// format specification) so handle such case.
if (frameCellNumber.first < 0) {
initialNumber = frameCellNumber.second;
continue;
}
// ignore sheet symbols for now
int cellNumber = frameCellNumber.second;
if (cellNumber == -1)
@ -417,6 +427,8 @@ bool XdtsIo::loadXdtsScene(ToonzScene *scene, const TFilePath &scenePath) {
scene->setProject(sceneProject.getPointer());
std::string sceneFileName = scenePath.getName() + ".tnz";
scene->setScenePath(scenePath.getParentDir() + sceneFileName);
// set the current scene here in order to use $scenefolder node properly
// in the file browser which opens from XDTSImportPopup
TApp::instance()->getCurrentScene()->setScene(scene);
XDTSImportPopup popup(levelNames, scene, scenePath);
@ -468,9 +480,24 @@ bool XdtsIo::loadXdtsScene(ToonzScene *scene, const TFilePath &scenePath) {
for (; row < duration; row++)
xsh->setCell(row, column, TXshCell(level, TFrameId(lastFid)));
}
TStageObject *pegbar =
xsh->getStageObject(TStageObjectId::ColumnId(column));
if (pegbar) pegbar->setName(levelName.toStdString());
}
xsh->updateFrameCount();
// if the duration is shorter than frame count, then set it both in
// preview range and output range.
if (duration < xsh->getFrameCount()) {
scene->getProperties()->getPreviewProperties()->setRange(0, duration - 1,
1);
scene->getProperties()->getOutputProperties()->setRange(0, duration - 1, 1);
}
// emit signal here for updating the frame slider range of flip console
TApp::instance()->getCurrentScene()->notifySceneChanged();
return true;
}