Skip to content

Commit

Permalink
#5127: TreeModel columns is owned by the ModelTreeView class now. Mov…
Browse files Browse the repository at this point in the history
…e stuff to .cpp file.
  • Loading branch information
codereader committed Jan 3, 2021
1 parent 912b0cc commit 265953d
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 76 deletions.
3 changes: 0 additions & 3 deletions libs/wxutil/dataview/ResourceTreeView.cpp
Expand Up @@ -409,9 +409,6 @@ void ResourceTreeView::_onSetFavourite(bool isFavourite)
TreeModel::Row row(item, *GetModel());

SetFavouriteRecursively(row, isFavourite);

// Store to registry on each change
// TODO: ? _favourites->saveToRegistry();
}

bool ResourceTreeView::IsDirectorySelected()
Expand Down
1 change: 1 addition & 0 deletions radiant/CMakeLists.txt
Expand Up @@ -127,6 +127,7 @@ add_executable(darkradiant
ui/modelexport/ExportCollisionModelDialog.cpp
ui/modelselector/MaterialsList.cpp
ui/modelselector/ModelSelector.cpp
ui/modelselector/ModelTreeView.cpp
ui/mousetool/BindToolDialog.cpp
ui/mousetool/ToolMappingDialog.cpp
ui/ortho/OrthoContextMenu.cpp
Expand Down
2 changes: 2 additions & 0 deletions radiant/ui/modelselector/ModelDataInserter.h
Expand Up @@ -7,6 +7,8 @@
#include "ModelSelector.h"
#include <wx/artprov.h>

#include "ModelTreeView.h"

namespace ui
{

Expand Down
3 changes: 1 addition & 2 deletions radiant/ui/modelselector/ModelPopulator.h
Expand Up @@ -43,8 +43,7 @@ class ModelPopulator final :
public:

// Constructor sets the populator
ModelPopulator(const ModelTreeView::TreeColumns& columns,
wxEvtHandler* finishedHandler) :
ModelPopulator(const ModelTreeView::TreeColumns& columns) :
ThreadedResourceTreePopulator(columns),
_columns(columns),
_count(0),
Expand Down
6 changes: 2 additions & 4 deletions radiant/ui/modelselector/ModelSelector.cpp
@@ -1,6 +1,4 @@
#include "ModelSelector.h"
#include "ModelPopulator.h"
#include "ModelDataInserter.h"

#include "math/Vector3.h"
#include "ifilesystem.h"
Expand Down Expand Up @@ -259,7 +257,7 @@ void ModelSelector::onModelLoaded(const model::ModelNodePtr& modelNode)
// Helper function to create the TreeView
void ModelSelector::setupTreeView(wxWindow* parent)
{
_treeView = new ModelTreeView(parent, _columns);
_treeView = new ModelTreeView(parent);
_treeView->SetMinSize(wxSize(200, 200));

// Get selection and connect the changed callback
Expand All @@ -275,7 +273,7 @@ void ModelSelector::setupTreeView(wxWindow* parent)

void ModelSelector::populateModels()
{
_treeView->Populate(std::make_shared<ModelPopulator>(_columns, _treeView));
_treeView->Populate();
}

void ModelSelector::Populate()
Expand Down
2 changes: 0 additions & 2 deletions radiant/ui/modelselector/ModelSelector.h
Expand Up @@ -54,8 +54,6 @@ class ModelSelector :
private:
wxPanel* _dialogPanel;

ModelTreeView::TreeColumns _columns;

// Model preview widget
wxutil::ModelPreviewPtr _modelPreview;

Expand Down
81 changes: 81 additions & 0 deletions radiant/ui/modelselector/ModelTreeView.cpp
@@ -0,0 +1,81 @@
#include "ModelTreeView.h"

#include "ModelPopulator.h"

namespace ui
{

ModelTreeView::ModelTreeView(wxWindow* parent) :
ResourceTreeView(parent, _columns, wxBORDER_STATIC | wxDV_NO_HEADER),
_showSkins(true)
{
// Single visible column, containing the directory/shader name and the icon
AppendIconTextColumn(
_("Model Path"), _columns.iconAndName.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE,
wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE
);

// Use the TreeModel's full string search function
AddSearchColumn(_columns.iconAndName);
EnableFavouriteManagement(decl::Type::Model);
}

void ModelTreeView::Populate()
{
ResourceTreeView::Populate(std::make_shared<ModelPopulator>(_columns));
}

void ModelTreeView::SetShowSkins(bool showSkins)
{
if (_showSkins == showSkins)
{
return;
}

// Try to keep the selection intact when switching modes
auto previousSelection = GetSelectedFullname();

_showSkins = showSkins;

SetupTreeModelFilter(); // refresh the view

if (!previousSelection.empty())
{
SetSelectedFullname(previousSelection);
}
}

std::string ModelTreeView::GetSelectedModelPath()
{
return GetColumnValue(_columns.modelPath);
}

std::string ModelTreeView::GetSelectedSkin()
{
return GetColumnValue(_columns.skin);
}

bool ModelTreeView::IsTreeModelRowVisible(wxutil::TreeModel::Row& row)
{
if (!_showSkins && row[_columns.isSkin].getBool())
{
return false; // it's a skin, and we shouldn't show it
}

// Pass to the base class
return ResourceTreeView::IsTreeModelRowVisible(row);
}

std::string ModelTreeView::GetColumnValue(const wxutil::TreeModel::Column& column)
{
auto item = GetSelection();

if (!item.IsOk()) return "";

wxutil::TreeModel::Row row(item, *GetModel());

return row[column];
}

}
74 changes: 9 additions & 65 deletions radiant/ui/modelselector/ModelTreeView.h
@@ -1,7 +1,6 @@
#pragma once

#include "wxutil/dataview/ResourceTreeView.h"
#include <wx/artprov.h>

namespace ui
{
Expand Down Expand Up @@ -29,82 +28,27 @@ class ModelTreeView :

private:
bool _showSkins;
const TreeColumns& _columns;
TreeColumns _columns;

wxDataViewItem _progressItem;
wxIcon _modelIcon;

public:
ModelTreeView(wxWindow* parent, const TreeColumns& columns) :
ResourceTreeView(parent, columns, wxBORDER_STATIC | wxDV_NO_HEADER),
_columns(columns),
_showSkins(true)
{
// Single visible column, containing the directory/shader name and the icon
AppendIconTextColumn(
_("Model Path"), _columns.iconAndName.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE,
wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE
);

// Use the TreeModel's full string search function
AddSearchColumn(_columns.iconAndName);
EnableFavouriteManagement(decl::Type::Model);
}

void SetShowSkins(bool showSkins)
{
if (_showSkins == showSkins)
{
return;
}
ModelTreeView(wxWindow* parent);

// Try to keep the selection intact when switching modes
auto previousSelection = GetSelectedFullname();
// Start populating the model tree in the background
void Populate();

_showSkins = showSkins;
void SetShowSkins(bool showSkins);

SetupTreeModelFilter(); // refresh the view

if (!previousSelection.empty())
{
SetSelectedFullname(previousSelection);
}
}

std::string GetSelectedModelPath()
{
return GetColumnValue(_columns.modelPath);
}

std::string GetSelectedSkin()
{
return GetColumnValue(_columns.skin);
}
std::string GetSelectedModelPath();
std::string GetSelectedSkin();

protected:
bool IsTreeModelRowVisible(wxutil::TreeModel::Row& row) override
{
if (!_showSkins && row[_columns.isSkin].getBool())
{
return false; // it's a skin, and we shouldn't show it
}

// Pass to the base class
return ResourceTreeView::IsTreeModelRowVisible(row);
}
bool IsTreeModelRowVisible(wxutil::TreeModel::Row& row) override;

private:
std::string GetColumnValue(const wxutil::TreeModel::Column& column)
{
auto item = GetSelection();

if (!item.IsOk()) return "";

wxutil::TreeModel::Row row(item, *GetModel());

return row[column];
}
std::string GetColumnValue(const wxutil::TreeModel::Column& column);
};

}
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -318,6 +318,7 @@
<ClCompile Include="..\..\radiant\ui\mapinfo\ShaderInfoTab.cpp" />
<ClCompile Include="..\..\radiant\ui\mediabrowser\MediaBrowser.cpp" />
<ClCompile Include="..\..\radiant\ui\modelselector\ModelSelector.cpp" />
<ClCompile Include="..\..\radiant\ui\modelselector\ModelTreeView.cpp" />
<ClCompile Include="..\..\radiant\ui\mousetool\BindToolDialog.cpp" />
<ClCompile Include="..\..\radiant\ui\mousetool\ToolMappingDialog.cpp" />
<ClCompile Include="..\..\radiant\ui\ortho\OrthoContextMenu.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -673,6 +673,9 @@
<ClCompile Include="..\..\radiant\ui\mediabrowser\MediaBrowserTreeView.cpp">
<Filter>src\ui\mediabrowser</Filter>
</ClCompile>
<ClCompile Include="..\..\radiant\ui\modelselector\ModelTreeView.cpp">
<Filter>src\ui\modelselector</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiant\camera\CameraSettings.h">
Expand Down

0 comments on commit 265953d

Please sign in to comment.