Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMSUSD-255 Fixes an issue in Layer Editor where Save All icon was not functioning properly. #3222

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 51 additions & 66 deletions lib/usd/ui/layerEditor/saveLayersDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,10 @@ void SaveLayersDialog::buildDialog(const QString& msg1, const QString& msg2)
for (auto iter = _anonLayerInfos.crbegin(); iter != _anonLayerInfos.crend(); ++iter) {
// Note: the row adds itself as a children of the dialog, so it will be deleted
// when the dialog closes.
new SaveLayerPathRow(this, anonLayout, gridRow++, (*iter));
auto saveLayerPathRow = new SaveLayerPathRow(this, anonLayout, gridRow++, (*iter));
// Note: We keep track of the row data so that it can be used when saving layers without
// having to iterate over SaveLayersDialog's entire layout.
_saveLayerPathRows.push_back(saveLayerPathRow);
}

_anonLayersWidget = new QWidget();
Expand Down Expand Up @@ -632,13 +635,8 @@ QString SaveLayersDialog::buildTooltipForLayer(SdfLayerRefPtr layer)

QWidget* SaveLayersDialog::findEntry(SdfLayerRefPtr key)
{
if (!_anonLayersWidget || !_anonLayersWidget->layout()) {
return nullptr;
}

QLayout* anonLayout = _anonLayersWidget->layout();
for (int i = 0, count = anonLayout->count(); i < count; ++i) {
auto row = dynamic_cast<SaveLayerPathRow*>(anonLayout->itemAt(i)->widget());
for (int i = 0, count = _saveLayerPathRows.size(); i < count; ++i) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the order of iteration the same as before, Although in this case it shouldn't matter as it is only picking one item.

auto row = dynamic_cast<SaveLayerPathRow*>(_saveLayerPathRows[i]);
if (row && row->_layerInfo.layer == key) {
return row;
}
Expand All @@ -649,13 +647,8 @@ QWidget* SaveLayersDialog::findEntry(SdfLayerRefPtr key)

void SaveLayersDialog::forEachEntry(const std::function<void(QWidget*)>& func)
{
if (!_anonLayersWidget || !_anonLayersWidget->layout()) {
return;
}

QLayout* anonLayout = _anonLayersWidget->layout();
for (int i = 0, count = anonLayout->count(); i < count; ++i) {
func(anonLayout->itemAt(i)->widget());
for (int i = 0, count = _saveLayerPathRows.size(); i < count; ++i) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, the order of iteration is from top layer to bottom

func(_saveLayerPathRows[i]);
}
}

Expand All @@ -669,41 +662,36 @@ void SaveLayersDialog::onSaveAll()
_problemLayers.clear();
_emptyLayers.clear();

// The anonymous layer section in the dialog can be empty.
if (nullptr != _anonLayersWidget) {
QLayout* anonLayout = _anonLayersWidget->layout();
// Note: must start from the end so that sub-layers are saved before their parent.
for (int count = anonLayout->count(), i = count - 1; i >= 0; --i) {
auto row = dynamic_cast<SaveLayerPathRow*>(anonLayout->itemAt(i)->widget());
if (!row || !row->_layerInfo.layer)
continue;

QString absolutePath = row->getAbsolutePath();
if (!absolutePath.isEmpty()) {
auto sdfLayer = row->_layerInfo.layer;
auto parent = row->_layerInfo.parent;
auto stage = row->_layerInfo.stage;

MayaUsd::utils::PathInfo pathInfo;
pathInfo.absolutePath = absolutePath.toStdString();
pathInfo.savePathAsRelative = row->needToSaveAsRelative();
if (pathInfo.savePathAsRelative && parent._layerParent
&& parent._layerParent->IsAnonymous()) {
pathInfo.customRelativeAnchor = row->calculateParentLayerDir();
}
// Note: must start from the end so that sub-layers are saved before their parent.
for (int count = _saveLayerPathRows.size(), i = count - 1; i >= 0; --i) {
auto row = dynamic_cast<SaveLayerPathRow*>(_saveLayerPathRows[i]);
if (!row || !row->_layerInfo.layer)
continue;

QString absolutePath = row->getAbsolutePath();
if (!absolutePath.isEmpty()) {
auto sdfLayer = row->_layerInfo.layer;
auto parent = row->_layerInfo.parent;
auto stage = row->_layerInfo.stage;

MayaUsd::utils::PathInfo pathInfo;
pathInfo.absolutePath = absolutePath.toStdString();
pathInfo.savePathAsRelative = row->needToSaveAsRelative();
if (pathInfo.savePathAsRelative && parent._layerParent
&& parent._layerParent->IsAnonymous()) {
pathInfo.customRelativeAnchor = row->calculateParentLayerDir();
}

auto newLayer
= MayaUsd::utils::saveAnonymousLayer(stage, sdfLayer, pathInfo, parent);
if (newLayer) {
_newPaths.append(QString::fromStdString(sdfLayer->GetDisplayName()));
_newPaths.append(absolutePath);
} else {
_problemLayers.append(QString::fromStdString(sdfLayer->GetDisplayName()));
_problemLayers.append(absolutePath);
}
auto newLayer = MayaUsd::utils::saveAnonymousLayer(stage, sdfLayer, pathInfo, parent);
if (newLayer) {
_newPaths.append(QString::fromStdString(sdfLayer->GetDisplayName()));
_newPaths.append(absolutePath);
} else {
_emptyLayers.append(row->layerDisplayName());
_problemLayers.append(QString::fromStdString(sdfLayer->GetDisplayName()));
_problemLayers.append(absolutePath);
}
} else {
_emptyLayers.append(row->layerDisplayName());
}
}

Expand All @@ -719,25 +707,22 @@ bool SaveLayersDialog::okToSave()
QMap<QString, int> alreadySeenPaths;
QStringList existingFiles;

// The anonymous layer section in the dialog can be empty.
if (nullptr != _anonLayersWidget) {
QLayout* anonLayout = _anonLayersWidget->layout();
for (int i = 0, count = anonLayout->count(); i < count; ++i) {
auto row = dynamic_cast<SaveLayerPathRow*>(anonLayout->itemAt(i)->widget());
if (nullptr == row)
continue;

QString path = row->getAbsolutePath();
if (!path.isEmpty()) {
if (alreadySeenPaths.count(path) > 0) {
alreadySeenPaths[path] += 1;
} else {
alreadySeenPaths[path] = 1;
}
QFileInfo fInfo(path);
if (fInfo.exists()) {
existingFiles.append(path);
}
for (int count = _saveLayerPathRows.size(), i = count - 1; i >= 0; --i) {
auto row = dynamic_cast<SaveLayerPathRow*>(_saveLayerPathRows[i]);
if (!row || !row->_layerInfo.layer)
continue;

QString path = row->getAbsolutePath();

if (!path.isEmpty()) {
if (alreadySeenPaths.count(path) > 0) {
alreadySeenPaths[path] += 1;
} else {
alreadySeenPaths[path] = 1;
}
QFileInfo fInfo(path);
if (fInfo.exists()) {
existingFiles.append(path);
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions lib/usd/ui/layerEditor/saveLayersDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,17 @@ class SaveLayersDialog : public QDialog
typedef std::unordered_set<SdfLayerRefPtr, TfHash> layerSet;
using LayerInfos = MayaUsd::utils::LayerInfos;

QStringList _newPaths;
QStringList _problemLayers;
QStringList _emptyLayers;
QWidget* _anonLayersWidget { nullptr };
QWidget* _fileLayersWidget { nullptr };
QCheckBox* _allAsRelative { nullptr };
LayerInfos _anonLayerInfos;
layerSet _dirtyFileBackedLayers;
stageLayerMap _stageLayerMap;
SessionState* _sessionState;
QStringList _newPaths;
QStringList _problemLayers;
QStringList _emptyLayers;
QWidget* _anonLayersWidget { nullptr };
QWidget* _fileLayersWidget { nullptr };
QCheckBox* _allAsRelative { nullptr };
LayerInfos _anonLayerInfos;
layerSet _dirtyFileBackedLayers;
stageLayerMap _stageLayerMap;
SessionState* _sessionState;
std::vector<QWidget*> _saveLayerPathRows;
};

}; // namespace UsdLayerEditor
Expand Down