Skip to content

Commit

Permalink
MAYA-107607 - As a user, I'd like to not save a layer when a sublayer…
Browse files Browse the repository at this point in the history
… is anonymous

- Avoid saving a layer that contains sub anonymous layer (Add warning dialog box)
  • Loading branch information
spinell-adsk committed Jan 28, 2021
1 parent 91aac2e commit aa7d2a2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
27 changes: 27 additions & 0 deletions lib/usd/ui/layerEditor/layerTreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,33 @@ void LayerTreeItem::saveEdits()
{
bool shouldSaveEdits = true;

// if the current layer contains anonymous layer(s),
// display a warning and abort the saving operation.
LayerItemVector anonymLayerItems = parentModel()->getAllAnonymousLayers(this);
if (!anonymLayerItems.empty()) {
const MString titleFormat
= StringResources::getAsMString(StringResources::kSaveLayerWarnTitle);
const MString msgFormat
= StringResources::getAsMString(StringResources::kSaveLayerSaveNestedAnonymLayer);

MString title;
title.format(titleFormat, displayName().c_str());

MString nbAnonymLayer;
nbAnonymLayer += static_cast<unsigned int>(anonymLayerItems.size());

MString msg;
msg.format(msgFormat, displayName().c_str(), nbAnonymLayer);

QStringList anonymLayerNames;
for (auto item : anonymLayerItems) {
anonymLayerNames.append(item->displayName().c_str());
}

warningDialog(MQtUtil::toQString(title), MQtUtil::toQString(msg), &anonymLayerNames);
return;
}

// the layer is already saved on disk.
// ask the user a confirmation before overwrite it.
if (!isAnonymous()) {
Expand Down
10 changes: 6 additions & 4 deletions lib/usd/ui/layerEditor/layerTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,12 @@ void layerItemVectorRecurs(
}
}

LayerItemVector LayerTreeModel::getAllItems(ConditionFunc filter) const
LayerItemVector
LayerTreeModel::getAllItems(ConditionFunc filter, const LayerTreeItem* item /* = nullptr*/) const
{

LayerItemVector result;
auto root = invisibleRootItem();
auto root = item ? item : invisibleRootItem();
for (int i = 0, count = root->rowCount(); i < count; i++) {
auto child = dynamic_cast<LayerTreeItem*>(root->child(i));
layerItemVectorRecurs(child, filter, result);
Expand All @@ -399,11 +400,12 @@ LayerItemVector LayerTreeModel::getAllNeedsSavingLayers() const
return getAllItems(filter);
}

LayerItemVector LayerTreeModel::getAllAnonymousLayers() const
LayerItemVector
LayerTreeModel::getAllAnonymousLayers(const LayerTreeItem* item /* = nullptr*/) const
{
auto filter
= [](const LayerTreeItem* item) { return item->isAnonymous() && !item->isSessionLayer(); };
return getAllItems(filter);
return getAllItems(filter, item);
}

void LayerTreeModel::saveStage(QWidget* in_parent)
Expand Down
8 changes: 4 additions & 4 deletions lib/usd/ui/layerEditor/layerTreeModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class LayerTreeModel
LayerTreeItem* layerItemFromIndex(const QModelIndex& index) const;
// gets everything recursivly as an array : used to simplify iteration
typedef bool (*ConditionFunc)(const LayerTreeItem*);
LayerItemVector getAllItems(ConditionFunc filter = [](const LayerTreeItem*) {
return true;
}) const;
LayerItemVector getAllItems(
ConditionFunc filter = [](const LayerTreeItem*) { return true; },
const LayerTreeItem* item = nullptr) const;
// get all the layers that need saving
LayerItemVector getAllNeedsSavingLayers() const;
// get all anonymous layers except the session layer
LayerItemVector getAllAnonymousLayers() const;
LayerItemVector getAllAnonymousLayers(const LayerTreeItem* item = nullptr) const;

// get an appropriate name for a new anonymous layer
std::string findNameForNewAnonymousLayer() const;
Expand Down
2 changes: 2 additions & 0 deletions lib/usd/ui/layerEditor/stringResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const auto kSave { create("kSave", "Save") };
const auto kSaveAll { create("kSaveAll", "Save All") };
const auto kSaveAllEditsInLayerStack { create("kSaveAllEditsInLayerStack", "Save all edits in the Layer Stack")};
const auto kSaveLayer { create("kSaveLayer", "Save Layer") };
const auto kSaveLayerSaveNestedAnonymLayer { create("kSaveLayerSaveNestedAnonymLayer",
"To save ^1s, you must save your ^2s anonymous layer(s) that are nested under it.") };
const auto kSaveLayerWarnTitle { create("kSaveLayerWarnTitle", "Save ^1s") };
const auto kSaveLayerWarnMsg { create("kSaveLayerWarnMsg", "Saving edits to ^1s will overwrite your file.") };
const auto kSaveStage { create("kSaveStage", "Save Stage") };
Expand Down

0 comments on commit aa7d2a2

Please sign in to comment.