Skip to content

Commit

Permalink
#6107: Update tree model on layer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 25, 2022
1 parent 03c1e07 commit 4856410
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
37 changes: 22 additions & 15 deletions radiant/ui/layers/LayerControlDialog.cpp
Expand Up @@ -30,8 +30,6 @@ namespace
LayerControlDialog::LayerControlDialog() :
TransientWindow(_("Layers"), GlobalMainFrame().getWxTopLevelWindow(), true),
_layersView(nullptr),
_dialogPanel(nullptr),
_controlContainer(nullptr),
_showAllLayers(nullptr),
_hideAllLayers(nullptr),
_rescanSelectionOnIdle(false)
Expand Down Expand Up @@ -87,27 +85,28 @@ void LayerControlDialog::createButtons()
// Show all / hide all buttons
wxBoxSizer* hideShowBox = new wxBoxSizer(wxHORIZONTAL);

_showAllLayers = new wxButton(_dialogPanel, wxID_ANY, _("Show all"));
_hideAllLayers = new wxButton(_dialogPanel, wxID_ANY, _("Hide all"));
_showAllLayers = new wxButton(this, wxID_ANY, _("Show all"));
_hideAllLayers = new wxButton(this, wxID_ANY, _("Hide all"));

_showAllLayers->Bind(wxEVT_BUTTON, &LayerControlDialog::onShowAllLayers, this);
_hideAllLayers->Bind(wxEVT_BUTTON, &LayerControlDialog::onHideAllLayers, this);

// Create layer button
wxButton* createButton = new wxButton(_dialogPanel, wxID_ANY, _("New"));
wxButton* createButton = new wxButton(this, wxID_ANY, _("New"));
createButton->SetBitmap(wxArtProvider::GetBitmap(wxART_PLUS));

wxutil::button::connectToCommand(createButton, "CreateNewLayerDialog");

hideShowBox->Add(_showAllLayers, 1, wxEXPAND | wxTOP, 6);
hideShowBox->Add(_hideAllLayers, 1, wxEXPAND | wxLEFT | wxTOP, 6);

_dialogPanel->GetSizer()->Add(createButton, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 12);
_dialogPanel->GetSizer()->Add(hideShowBox, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 12);
GetSizer()->Add(createButton, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 12);
GetSizer()->Add(hideShowBox, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 12);
}

void LayerControlDialog::clearControls()
{
_layerItemMap.clear();
_layerStore->Clear();
}

Expand All @@ -133,6 +132,8 @@ void LayerControlDialog::refresh()
row[_columns.visible] = layerManager.layerIsVisible(layerID);

row.SendItemAdded();

_layerItemMap.emplace(layerID, row.getItem());
});

#if 0
Expand Down Expand Up @@ -174,13 +175,7 @@ void LayerControlDialog::update()
}

auto& layerSystem = GlobalMapModule().getRoot()->getLayerManager();
#if 0
// Broadcast the update() call
for (const LayerControlPtr& control : _layerControls)
{
control->update();
}
#endif

// Update usage next time round
_rescanSelectionOnIdle = true;

Expand All @@ -190,14 +185,26 @@ void LayerControlDialog::update()

layerSystem.foreachLayer([&](int layerID, const std::string& layerName)
{
if (layerSystem.layerIsVisible(layerID))
auto existingItem = _layerItemMap.find(layerID);

if (existingItem == _layerItemMap.end()) return; // tracking error?

wxutil::TreeModel::Row row(existingItem->second, *_layerStore);

row[_columns.name] = layerName;

if (layerSystem.layerIsVisible(layerID))
{
row[_columns.visible] = true;
numVisible++;
}
else
{
row[_columns.visible] = false;
numHidden++;
}

row.SendItemChanged();
});

#if 0
Expand Down
4 changes: 1 addition & 3 deletions radiant/ui/layers/LayerControlDialog.h
Expand Up @@ -44,9 +44,7 @@ class LayerControlDialog :
TreeColumns _columns;
wxutil::TreeModel::Ptr _layerStore;

wxPanel* _dialogPanel;

wxFlexGridSizer* _controlContainer;
std::map<int, wxDataViewItem> _layerItemMap;

wxButton* _showAllLayers;
wxButton* _hideAllLayers;
Expand Down

0 comments on commit 4856410

Please sign in to comment.