Skip to content

Commit

Permalink
#5231: Filter UI is responding to a set of signals now when anything …
Browse files Browse the repository at this point in the history
…changes.

Right now it's not possible to assign shortcuts to the SelectByFilter* set of commands anymore
  • Loading branch information
codereader committed May 6, 2020
1 parent f271e6c commit e3e5d94
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 64 deletions.
16 changes: 10 additions & 6 deletions include/ifilter.h
Expand Up @@ -82,13 +82,17 @@ class Entity;
* The filter system provides a mechanism by which certain objects or materials
* can be hidden from rendered views.
*/
class FilterSystem :
class IFilterSystem :
public RegisterableModule
{
public:

/// Signal emitted when the state of filters has changed
virtual sigc::signal<void> filtersChangedSignal() const = 0;
// Signal emitted when the state of filters has changed,
// filters have been added or removed, or when rules have been altered
virtual sigc::signal<void> filterConfigChangedSignal() const = 0;

// Signal emitted when filters are added, removed or renamed
virtual sigc::signal<void> filterCollectionChangedSignal() const = 0;

/**
* greebo: Updates all the "Filtered" status of all Instances
Expand Down Expand Up @@ -206,11 +210,11 @@ class FilterSystem :
virtual bool setFilterRules(const std::string& filter, const FilterRules& ruleSet) = 0;
};

inline FilterSystem& GlobalFilterSystem()
inline IFilterSystem& GlobalFilterSystem()
{
// Cache the reference locally
static FilterSystem& _filterSystem(
*std::static_pointer_cast<FilterSystem>(
static IFilterSystem& _filterSystem(
*std::static_pointer_cast<IFilterSystem>(
module::GlobalModuleRegistry().getModule(MODULE_FILTERSYSTEM)
)
);
Expand Down
8 changes: 4 additions & 4 deletions libs/wxutil/preview/RenderPreview.cpp
Expand Up @@ -109,9 +109,9 @@ void RenderPreview::setupToolbars(bool enableAnimation)
filterToolbar->Realize();

// Get notified of filter changes
GlobalFilterSystem().filtersChangedSignal().connect(
sigc::mem_fun(this, &RenderPreview::filtersChanged)
);
GlobalFilterSystem().filterConfigChangedSignal().connect(
sigc::mem_fun(this, &RenderPreview::onFilterConfigChanged)
);

wxToolBar* renderToolbar = findNamedObject<wxToolBar>(_mainPanel, "RenderPreviewRenderModeToolbar");

Expand Down Expand Up @@ -166,7 +166,7 @@ void RenderPreview::updateActiveRenderModeButton()
}
}

void RenderPreview::filtersChanged()
void RenderPreview::onFilterConfigChanged()
{
if (!getScene()->root()) return;

Expand Down
2 changes: 1 addition & 1 deletion libs/wxutil/preview/RenderPreview.h
Expand Up @@ -56,7 +56,7 @@ class RenderPreview :
void onStepBackClick(wxCommandEvent& ev);

void onSizeAllocate(wxSizeEvent& ev);
void filtersChanged();
void onFilterConfigChanged();
void onRenderModeChanged(wxCommandEvent& ev);
void onGridButtonClick(wxCommandEvent& ev);

Expand Down
46 changes: 27 additions & 19 deletions radiant/filters/BasicFilterSystem.cpp
Expand Up @@ -16,7 +16,7 @@
namespace filters
{

namespace
namespace
{
// Registry key for .game-defined filters
const std::string RKEY_GAME_FILTERS = "/filtersystem//filter";
Expand Down Expand Up @@ -50,7 +50,7 @@ void BasicFilterSystem::setAllFilterStates(bool state)

updateEvents();

_filtersChangedSignal.emit();
_filterConfigChangedSignal.emit();

// Trigger an immediate scene redraw
GlobalSceneGraph().sceneChanged();
Expand Down Expand Up @@ -330,11 +330,19 @@ void BasicFilterSystem::shutdownModule()
_eventAdapters.clear();
_activeFilters.clear();
_availableFilters.clear();

_filterCollectionChangedSignal.clear();
_filterConfigChangedSignal.clear();
}

sigc::signal<void> BasicFilterSystem::filtersChangedSignal() const
sigc::signal<void> BasicFilterSystem::filterConfigChangedSignal() const
{
return _filtersChangedSignal;
return _filterConfigChangedSignal;
}

sigc::signal<void> BasicFilterSystem::filterCollectionChangedSignal() const
{
return _filterCollectionChangedSignal;
}

void BasicFilterSystem::update()
Expand Down Expand Up @@ -397,7 +405,7 @@ void BasicFilterSystem::setFilterState(const std::string& filter, bool state)
// Update the scenegraph instances
update();

_filtersChangedSignal.emit();
_filterConfigChangedSignal.emit();

// Trigger an immediate scene redraw
GlobalSceneGraph().sceneChanged();
Expand Down Expand Up @@ -442,10 +450,7 @@ bool BasicFilterSystem::addFilter(const std::string& filterName, const FilterRul
// Create the event adapter
ensureEventAdapter(*filter);

// Clear the cache, the rules have changed
_visibilityCache.clear();

_filtersChangedSignal.emit();
_filterCollectionChangedSignal.emit();

return true;
}
Expand All @@ -465,18 +470,20 @@ bool BasicFilterSystem::removeFilter(const std::string& filter)
// Check if the filter was active
auto found = _activeFilters.find(f->first);

if (found != _activeFilters.end())
{
_activeFilters.erase(found);
}

// Now remove the object from the available filters too
_availableFilters.erase(f);

// Clear the cache, the rules have changed
_visibilityCache.clear();
if (found != _activeFilters.end())
{
_activeFilters.erase(found);

// Clear the cache, the rules have changed
_visibilityCache.clear();

_filterConfigChangedSignal.emit();
}

_filtersChangedSignal.emit();
_filterCollectionChangedSignal.emit();

return true;
}
Expand Down Expand Up @@ -541,6 +548,8 @@ bool BasicFilterSystem::renameFilter(const std::string& oldFilterName, const std
// Remove the old filter from the filtertable
_availableFilters.erase(oldFilterName);

_filterCollectionChangedSignal.emit();

return true;
}

Expand Down Expand Up @@ -618,7 +627,7 @@ bool BasicFilterSystem::setFilterRules(const std::string& filter, const FilterRu
// Clear the cache, the ruleset has changed
_visibilityCache.clear();

_filtersChangedSignal.emit();
_filterConfigChangedSignal.emit();

return true;
}
Expand Down Expand Up @@ -669,7 +678,6 @@ const StringSet& BasicFilterSystem::getDependencies() const
{
_dependencies.insert(MODULE_XMLREGISTRY);
_dependencies.insert(MODULE_GAMEMANAGER);
_dependencies.insert(MODULE_EVENTMANAGER);
_dependencies.insert(MODULE_COMMANDSYSTEM);
}

Expand Down
8 changes: 5 additions & 3 deletions radiant/filters/BasicFilterSystem.h
Expand Up @@ -22,7 +22,7 @@ const char* const DESELECT_OBJECTS_BY_FILTER_CMD = "DeselectObjectsByFilter";
/** FilterSystem implementation class.
*/
class BasicFilterSystem :
public FilterSystem
public IFilterSystem
{
private:
// Hashtable of available filters, indexed by name
Expand All @@ -37,7 +37,8 @@ class BasicFilterSystem :
typedef std::map<std::string, bool> StringFlagCache;
StringFlagCache _visibilityCache;

sigc::signal<void> _filtersChangedSignal;
sigc::signal<void> _filterConfigChangedSignal;
sigc::signal<void> _filterCollectionChangedSignal;

typedef std::map<std::string, XmlFilterEventAdapter::Ptr> FilterAdapters;
FilterAdapters _eventAdapters;
Expand Down Expand Up @@ -67,7 +68,8 @@ class BasicFilterSystem :

public:
// FilterSystem implementation
sigc::signal<void> filtersChangedSignal() const override;
sigc::signal<void> filterConfigChangedSignal() const override;
sigc::signal<void> filterCollectionChangedSignal() const override;

// Invoke the InstanceUpateWalker to update the filtered status.
void update() override;
Expand Down
4 changes: 2 additions & 2 deletions radiant/filters/InstanceUpdateWalker.h
Expand Up @@ -48,7 +48,7 @@ class InstanceUpdateWalker :
public scene::NodeVisitor
{
private:
FilterSystem& _filterSystem;
IFilterSystem& _filterSystem;

// Helper visitors to update subgraphs
NodeVisibilityUpdater _hideWalker;
Expand All @@ -60,7 +60,7 @@ class InstanceUpdateWalker :
bool _brushesAreVisible;

public:
InstanceUpdateWalker(FilterSystem& filterSystem) :
InstanceUpdateWalker(IFilterSystem& filterSystem) :
_filterSystem(filterSystem),
_hideWalker(true),
_showWalker(false),
Expand Down
3 changes: 0 additions & 3 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -26,7 +26,6 @@
#include "map/FindMapElements.h"
#include "ui/mapinfo/MapInfoDialog.h"
#include "ui/commandlist/CommandList.h"
#include "ui/filters/editor/FilterDialog.h"
#include "ui/mousetool/ToolMappingDialog.h"
#include "ui/about/AboutDialog.h"
#include "ui/eclasstree/EClassTree.h"
Expand Down Expand Up @@ -147,7 +146,6 @@ void UserInterfaceModule::registerUICommands()
GlobalCommandSystem().addCommand("FindBrush", DoFind);

GlobalCommandSystem().addCommand("MapInfo", MapInfoDialog::ShowDialog);
GlobalCommandSystem().addCommand("EditFiltersDialog", FilterDialog::ShowDialog);
GlobalCommandSystem().addCommand("MouseToolMappingDialog", ToolMappingDialog::ShowDialog);

GlobalCommandSystem().addCommand("FindReplaceTextures", FindAndReplaceShader::ShowDialog);
Expand Down Expand Up @@ -176,7 +174,6 @@ void UserInterfaceModule::registerUICommands()
GlobalEventManager().addCommand("FindBrush", "FindBrush");

GlobalEventManager().addCommand("MapInfo", "MapInfo");
GlobalEventManager().addCommand("EditFiltersDialog", "EditFiltersDialog");
GlobalEventManager().addCommand("MouseToolMappingDialog", "MouseToolMappingDialog");

GlobalEventManager().addCommand("FindReplaceTextures", "FindReplaceTextures");
Expand Down
8 changes: 4 additions & 4 deletions radiant/ui/entitylist/EntityList.cpp
Expand Up @@ -146,7 +146,7 @@ void EntityList::selectionChanged(const scene::INodePtr& node, bool isComponent)
_callbackActive = false;
}

void EntityList::filtersChanged()
void EntityList::onFilterConfigChanged()
{
// Only react to filter changes if we display visible nodes only otherwise
// we don't care
Expand All @@ -166,7 +166,7 @@ void EntityList::_preHide()
_treeModel.disconnectFromSceneGraph();

// Disconnect from the filters-changed signal
_filtersChangedConnection.disconnect();
_filtersConfigChangedConn.disconnect();

// De-register self from the SelectionSystem
GlobalSelectionSystem().removeObserver(this);
Expand All @@ -191,8 +191,8 @@ void EntityList::_preShow()
GlobalSelectionSystem().addObserver(this);

// Get notified when filters are changing
_filtersChangedConnection = GlobalFilterSystem().filtersChangedSignal().connect(
sigc::mem_fun(Instance(), &EntityList::filtersChanged)
_filtersConfigChangedConn = GlobalFilterSystem().filterConfigChangedSignal().connect(
sigc::mem_fun(Instance(), &EntityList::onFilterConfigChanged)
);

_callbackActive = true;
Expand Down
4 changes: 2 additions & 2 deletions radiant/ui/entitylist/EntityList.h
Expand Up @@ -40,7 +40,7 @@ class EntityList :
wxCheckBox* _focusSelected;
wxCheckBox* _visibleOnly;

sigc::connection _filtersChangedConnection;
sigc::connection _filtersConfigChangedConn;

struct DataViewItemLess
{
Expand Down Expand Up @@ -76,7 +76,7 @@ class EntityList :
// Called by the graph tree model
void onTreeViewSelection(const wxDataViewItem& item, bool selected);

void filtersChanged();
void onFilterConfigChanged();

void onRowExpand(wxDataViewEvent& ev);

Expand Down

0 comments on commit e3e5d94

Please sign in to comment.