Skip to content

Commit

Permalink
#5728: Move list population code to MaterialsList class
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 10, 2021
1 parent c50151d commit 5996983
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
18 changes: 13 additions & 5 deletions radiant/ui/modelselector/MaterialsList.cpp
Expand Up @@ -64,6 +64,19 @@ MaterialsList::MaterialsList(wxWindow* parent, const RenderSystemPtr& renderSyst
);
}

void MaterialsList::updateFromModel(const model::IModel& model)
{
// Add the list of active materials
_store->Clear();

const auto& matList(model.getActiveMaterials());

for (const auto& material : matList)
{
addMaterial(material);
}
}

void MaterialsList::onShaderToggled(wxDataViewEvent& ev)
{
wxDataViewItem item = ev.GetItem();
Expand Down Expand Up @@ -95,11 +108,6 @@ void MaterialsList::onShowShaderDefinition()
view->Destroy();
}

void MaterialsList::clear()
{
_store->Clear();
}

void MaterialsList::addMaterial(const std::string& name)
{
wxutil::TreeModel::Row row = _store->AddItem();
Expand Down
11 changes: 6 additions & 5 deletions radiant/ui/modelselector/MaterialsList.h
@@ -1,5 +1,6 @@
#pragma once

#include "imodel.h"
#include "wxutil/dataview/TreeView.h"
#include "wxutil/dataview/TreeModel.h"
#include "wxutil/menu/PopupMenu.h"
Expand Down Expand Up @@ -49,11 +50,8 @@ class MaterialsList :
*/
MaterialsList(wxWindow* parent, const RenderSystemPtr& renderSystem);

/// Clear all entries
void clear();

/// Add a material
void addMaterial(const std::string& name);
// Populate the table entries using the given model node
void updateFromModel(const model::IModel& model);

/**
* \brief
Expand All @@ -66,6 +64,9 @@ class MaterialsList :
{
return _visibilityChangedSignal;
}

private:
void addMaterial(const std::string& name);
};

}
10 changes: 1 addition & 9 deletions radiant/ui/modelselector/ModelSelector.cpp
Expand Up @@ -261,15 +261,7 @@ void ModelSelector::onModelLoaded(const model::ModelNodePtr& modelNode)
}
}

// Add the list of active materials
_materialsList->clear();

const model::StringList& matList(model.getActiveMaterials());

for (const auto& material : matList)
{
_materialsList->addMaterial(material);
}
_materialsList->updateFromModel(model);
}

// Helper function to create the TreeView
Expand Down

0 comments on commit 5996983

Please sign in to comment.