mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-11-04 03:30:06 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			81 lines
		
	
	
	
		
			3.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
	
		
			3.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#pragma once
 | 
						|
 | 
						|
#include <scwx/qt/settings/settings_category.hpp>
 | 
						|
#include <scwx/qt/settings/settings_interface_base.hpp>
 | 
						|
 | 
						|
#include <QWidget>
 | 
						|
 | 
						|
#define SCWX_ENUM_MAP_FROM_VALUE(Iterator, ToName)                             \
 | 
						|
   [](const std::string& text) -> std::string                                  \
 | 
						|
   {                                                                           \
 | 
						|
      for (auto enumValue : Iterator)                                          \
 | 
						|
      {                                                                        \
 | 
						|
         const std::string enumName = ToName(enumValue);                       \
 | 
						|
                                                                               \
 | 
						|
         if (boost::iequals(text, enumName))                                   \
 | 
						|
         {                                                                     \
 | 
						|
            /* Return label */                                                 \
 | 
						|
            return enumName;                                                   \
 | 
						|
         }                                                                     \
 | 
						|
      }                                                                        \
 | 
						|
                                                                               \
 | 
						|
      /* Label not found, return unknown */                                    \
 | 
						|
      return "?";                                                              \
 | 
						|
   }
 | 
						|
 | 
						|
#define SCWX_SETTINGS_COMBO_BOX(settingsInterface, comboBox, Iterator, ToName) \
 | 
						|
   for (const auto& enumValue : Iterator)                                      \
 | 
						|
   {                                                                           \
 | 
						|
      comboBox->addItem(QString::fromStdString(ToName(enumValue)));            \
 | 
						|
   }                                                                           \
 | 
						|
                                                                               \
 | 
						|
   settingsInterface.SetMapFromValueFunction(                                  \
 | 
						|
      SCWX_ENUM_MAP_FROM_VALUE(Iterator, ToName));                             \
 | 
						|
   settingsInterface.SetMapToValueFunction(                                    \
 | 
						|
      [](std::string text) -> std::string                                      \
 | 
						|
      {                                                                        \
 | 
						|
         boost::to_lower(text);                                                \
 | 
						|
         return text;                                                          \
 | 
						|
      });                                                                      \
 | 
						|
                                                                               \
 | 
						|
   settingsInterface.SetEditWidget(comboBox);
 | 
						|
 | 
						|
namespace scwx
 | 
						|
{
 | 
						|
namespace qt
 | 
						|
{
 | 
						|
namespace ui
 | 
						|
{
 | 
						|
 | 
						|
class SettingsPageWidget : public QWidget
 | 
						|
{
 | 
						|
   Q_OBJECT
 | 
						|
 | 
						|
public:
 | 
						|
   explicit SettingsPageWidget(QWidget* parent = nullptr);
 | 
						|
   ~SettingsPageWidget();
 | 
						|
 | 
						|
   bool CommitChanges();
 | 
						|
   void DiscardChanges();
 | 
						|
   void ResetToDefault();
 | 
						|
 | 
						|
protected:
 | 
						|
   void AddSettingsInterface(settings::SettingsInterfaceBase* setting);
 | 
						|
 | 
						|
   /**
 | 
						|
    * Commits and resets all settings within a category upon page commit or
 | 
						|
    * reset. The use of SettingsInterface is preferred, as it allows the binding
 | 
						|
    * of widgets to these actions.
 | 
						|
    *
 | 
						|
    * @param [in] category Settings category
 | 
						|
    */
 | 
						|
   void AddSettingsCategory(settings::SettingsCategory* category);
 | 
						|
 | 
						|
private:
 | 
						|
   class Impl;
 | 
						|
   std::shared_ptr<Impl> p;
 | 
						|
};
 | 
						|
 | 
						|
} // namespace ui
 | 
						|
} // namespace qt
 | 
						|
} // namespace scwx
 |