From 19926663f11c1013d0c68ccc92f2a4e236942ce9 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 28 Jun 2024 23:20:04 +0200 Subject: refactor: rewrite KeyMenuAbility --- src/ui/widgets/KeyList.h | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'src/ui/widgets/KeyList.h') diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h index 1893a98a..03b02a0b 100644 --- a/src/ui/widgets/KeyList.h +++ b/src/ui/widgets/KeyList.h @@ -38,18 +38,40 @@ namespace GpgFrontend::UI { * @brief * */ -struct KeyMenuAbility { - using AbilityType = unsigned int; - - static constexpr AbilityType ALL = ~0; ///< - static constexpr AbilityType NONE = 0; ///< - static constexpr AbilityType REFRESH = 1 << 0; ///< - static constexpr AbilityType SYNC_PUBLIC_KEY = 1 << 1; ///< - static constexpr AbilityType UNCHECK_ALL = 1 << 3; ///< - static constexpr AbilityType CHECK_ALL = 1 << 5; ///< - static constexpr AbilityType SEARCH_BAR = 1 << 6; ///< +enum class KeyMenuAbility : unsigned int { + kNONE = 0, + kREFRESH = 1 << 0, + kSYNC_PUBLIC_KEY = 1 << 1, + kUNCHECK_ALL = 1 << 2, + kCHECK_ALL = 1 << 3, + kCOLUMN_FILTER = 1 << 4, + kSEARCH_BAR = 1 << 5, + + kALL = ~0U }; +inline auto operator|(KeyMenuAbility lhs, KeyMenuAbility rhs) + -> KeyMenuAbility { + using T = std::underlying_type_t; + return static_cast(static_cast(lhs) | static_cast(rhs)); +} + +inline auto operator|=(KeyMenuAbility& lhs, KeyMenuAbility rhs) + -> KeyMenuAbility& { + lhs = lhs | rhs; + return lhs; +} + +inline auto operator&(KeyMenuAbility lhs, KeyMenuAbility rhs) -> bool { + using T = std::underlying_type_t; + return (static_cast(lhs) & static_cast(rhs)) != 0; +} + +inline auto operator~(KeyMenuAbility hs) -> KeyMenuAbility { + using T = std::underlying_type_t; + return static_cast(~static_cast(hs)); +} + /** * @brief * @@ -65,7 +87,7 @@ class KeyList : public QWidget { * @param parent */ explicit KeyList( - KeyMenuAbility::AbilityType menu_ability, + KeyMenuAbility menu_ability, GpgKeyTableColumn fixed_column_filter = GpgKeyTableColumn::kALL, QWidget* parent = nullptr); @@ -259,7 +281,7 @@ class KeyList : public QWidget { std::shared_ptr ui_; ///< QMenu* popup_menu_{}; ///< std::function m_action_ = nullptr; ///< - KeyMenuAbility::AbilityType menu_ability_ = KeyMenuAbility::ALL; ///< + KeyMenuAbility menu_ability_ = KeyMenuAbility::kALL; ///< QSharedPointer model_; GpgKeyTableColumn fixed_columns_filter_; GpgKeyTableColumn global_column_filter_; -- cgit v1.2.3