Fix enum class
key in hashed containers
This commit is contained in:
parent
23214ae5cd
commit
ac19ea4507
@ -20,6 +20,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <type_traits>
|
||||
|
||||
#include <gtkmm.h>
|
||||
|
||||
@ -74,6 +75,17 @@ private:
|
||||
MyMutex mutex;
|
||||
};
|
||||
|
||||
struct ScopedEnumHash {
|
||||
template<typename T, typename std::enable_if<std::is_enum<T>::value && !std::is_convertible<T, int>::value, int>::type = 0>
|
||||
size_t operator ()(T val) const noexcept
|
||||
{
|
||||
using type = typename std::underlying_type<T>::type;
|
||||
|
||||
return std::hash<type>{}(static_cast<type>(val));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// TODO: The documentation says gdk_threads_enter and gdk_threads_leave should be replaced
|
||||
// by g_main_context_invoke(), g_idle_add() and related functions, but this will require more extensive changes.
|
||||
// We silence those warnings until then so that we notice the others.
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "toolpanelcoord.h"
|
||||
|
||||
using Tool = ToolPanelCoordinator::Tool;
|
||||
using Favorites = std::unordered_set<Tool, ScopedEnumHash>;
|
||||
|
||||
std::string getToolName(Tool tool)
|
||||
{
|
||||
@ -200,7 +201,7 @@ struct ToolLocationPreference::Impl {
|
||||
void addToolListRowGroup(
|
||||
const std::vector<ToolPanelCoordinator::ToolTree> &tools,
|
||||
const Gtk::TreeIter &parentRowIter,
|
||||
const std::unordered_set<Tool> &favorites);
|
||||
const Favorites &favorites);
|
||||
void favoriteToggled(const Glib::ustring &row_path);
|
||||
Tool getToolFromName(const std::string &name) const;
|
||||
void initFavoritesRows(const std::vector<Tool> &favorites);
|
||||
@ -477,7 +478,7 @@ void ToolLocationPreference::Impl::initFavoritesRows(
|
||||
void ToolLocationPreference::Impl::addToolListRowGroup(
|
||||
const std::vector<ToolPanelCoordinator::ToolTree> &tools,
|
||||
const Gtk::TreeIter &parentRowIter,
|
||||
const std::unordered_set<Tool> &favorites)
|
||||
const Favorites &favorites)
|
||||
{
|
||||
for (const ToolPanelCoordinator::ToolTree &tool : tools) {
|
||||
auto tool_row_iter = toolListModelPtr->append(parentRowIter->children());
|
||||
@ -498,7 +499,7 @@ void ToolLocationPreference::Impl::addToolListRowGroup(
|
||||
void ToolLocationPreference::Impl::initToolListRows(const std::vector<Tool> &favorites)
|
||||
{
|
||||
const auto panel_tools = ToolPanelCoordinator::getDefaultToolLayout();
|
||||
std::unordered_set<Tool> favorites_set;
|
||||
Favorites favorites_set;
|
||||
|
||||
for (const auto &tool : favorites) {
|
||||
favorites_set.insert(tool);
|
||||
|
@ -236,7 +236,7 @@ const std::vector<ToolTree> RAW_PANEL_TOOLS = {
|
||||
},
|
||||
};
|
||||
|
||||
const std::unordered_map<ToolPanelCoordinator::Panel, const std::vector<ToolTree>> PANEL_TOOLS = {
|
||||
const ToolPanelCoordinator::ToolLayout PANEL_TOOLS = {
|
||||
{
|
||||
ToolPanelCoordinator::Panel::EXPOSURE,
|
||||
EXPOSURE_PANEL_TOOLS
|
||||
@ -378,7 +378,7 @@ ToolPanelCoordinator::ToolPanelCoordinator (bool batch) : ipc (nullptr), favorit
|
||||
addfavoritePanel (detailsPanel, dehaze);
|
||||
addfavoritePanel (advancedPanel, wavelet);
|
||||
addfavoritePanel(locallabPanel, locallab);
|
||||
|
||||
|
||||
addfavoritePanel (transformPanel, crop);
|
||||
addfavoritePanel (transformPanel, resize);
|
||||
addPanel (resize->getPackBox(), prsharpening, 2);
|
||||
@ -424,7 +424,7 @@ ToolPanelCoordinator::ToolPanelCoordinator (bool batch) : ipc (nullptr), favorit
|
||||
transformPanelSW = Gtk::manage (new MyScrolledWindow ());
|
||||
rawPanelSW = Gtk::manage (new MyScrolledWindow ());
|
||||
advancedPanelSW = Gtk::manage (new MyScrolledWindow ());
|
||||
locallabPanelSW = Gtk::manage(new MyScrolledWindow());
|
||||
locallabPanelSW = Gtk::manage(new MyScrolledWindow());
|
||||
|
||||
// load panel endings
|
||||
for (int i = 0; i < 8; i++) {
|
||||
@ -455,7 +455,7 @@ ToolPanelCoordinator::ToolPanelCoordinator (bool batch) : ipc (nullptr), favorit
|
||||
|
||||
locallabPanelSW->add(*locallabPanel);
|
||||
locallabPanel->pack_start(*vbPanelEnd[7], Gtk::PACK_SHRINK, 4);
|
||||
|
||||
|
||||
transformPanelSW->add (*transformPanel);
|
||||
transformPanel->pack_start (*vbPanelEnd[4], Gtk::PACK_SHRINK, 4);
|
||||
|
||||
@ -523,7 +523,7 @@ ToolPanelCoordinator::ToolPanelCoordinator (bool batch) : ipc (nullptr), favorit
|
||||
prevPage = toolPanelNotebook->get_nth_page(0);
|
||||
}
|
||||
|
||||
const std::unordered_map<ToolPanelCoordinator::Panel, const std::vector<ToolTree>> ToolPanelCoordinator::getDefaultToolLayout()
|
||||
const ToolPanelCoordinator::ToolLayout& ToolPanelCoordinator::getDefaultToolLayout()
|
||||
{
|
||||
return PANEL_TOOLS;
|
||||
}
|
||||
|
@ -298,13 +298,15 @@ public:
|
||||
std::vector<ToolTree> children;
|
||||
};
|
||||
|
||||
using ToolLayout = std::unordered_map<Panel, const std::vector<ToolTree>, ScopedEnumHash>;
|
||||
|
||||
CoarsePanel* coarse;
|
||||
Gtk::Notebook* toolPanelNotebook;
|
||||
|
||||
ToolPanelCoordinator(bool batch = false);
|
||||
~ToolPanelCoordinator () override;
|
||||
|
||||
static const std::unordered_map<Panel, const std::vector<ToolTree>> getDefaultToolLayout();
|
||||
static const ToolLayout& getDefaultToolLayout();
|
||||
static bool isFavoritable(Tool tool);
|
||||
|
||||
bool getChangedState()
|
||||
|
Loading…
x
Reference in New Issue
Block a user