23#include <boost/format.hpp>
112 template <
typename T>
113 struct item_cell_choice_type
115 typedef T value_type;
131 item_cell_choice_type<bool>::type::value_type
const*,
132 item_cell_choice_type<int32_t>::type::value_type
const*,
133 item_cell_choice_type<uint32_t>::type::value_type
const*,
134 item_cell_choice_type<int64_t>::type::value_type
const*,
135 item_cell_choice_type<uint64_t>::type::value_type
const*,
136 item_cell_choice_type<float>::type::value_type
const*,
137 item_cell_choice_type<double>::type::value_type
const*,
138 item_cell_choice_type<string>::type::value_type
const*,
139 item_cell_choice_type<void*>::type::value_type
const*,
140 item_cell_choice_type<custom_type>::type::value_type
const*> item_cell_data_variant;
153 template <>
struct classify_item_call_data<item_cell_choice_type<bool>::type::value_type const*> {
static constexpr item_cell_data_category category = item_cell_data_category::ChooseValue; };
154 template <>
struct classify_item_call_data<item_cell_choice_type<int32_t>::type::value_type const*> {
static constexpr item_cell_data_category category = item_cell_data_category::ChooseValue; };
155 template <>
struct classify_item_call_data<item_cell_choice_type<uint32_t>::type::value_type const*> {
static constexpr item_cell_data_category category = item_cell_data_category::ChooseValue; };
156 template <>
struct classify_item_call_data<item_cell_choice_type<int64_t>::type::value_type const*> {
static constexpr item_cell_data_category category = item_cell_data_category::ChooseValue; };
157 template <>
struct classify_item_call_data<item_cell_choice_type<uint64_t>::type::value_type const*> {
static constexpr item_cell_data_category category = item_cell_data_category::ChooseValue; };
158 template <>
struct classify_item_call_data<item_cell_choice_type<float>::type::value_type const*> {
static constexpr item_cell_data_category category = item_cell_data_category::ChooseValue; };
159 template <>
struct classify_item_call_data<item_cell_choice_type<double>::type::value_type const*> {
static constexpr item_cell_data_category category = item_cell_data_category::ChooseValue; };
160 template <>
struct classify_item_call_data<item_cell_choice_type<string>::type::value_type const*> {
static constexpr item_cell_data_category category = item_cell_data_category::ChooseValue; };
164 class item_cell_data :
public item_cell_data_variant
170 template <
typename T,
typename std::enable_if_t<is_alternative_v<T>,
int> = 0>
171 item_cell_data(T
const& aValue) :
172 item_cell_data_variant{ aValue }
175 template <
typename T,
typename std::enable_if_t<is_alternative_v<T>,
int> = 0>
176 item_cell_data(T&& aValue) :
177 item_cell_data_variant{
std::forward<T>(aValue) }
180 item_cell_data(item_cell_data
const& aOther) :
181 item_cell_data_variant{ static_cast<item_cell_data_variant const&>(aOther) }
184 item_cell_data(item_cell_data&& aOther) :
185 item_cell_data_variant{ static_cast<item_cell_data_variant&&>(
std::move(aOther)) }
189 item_cell_data(
char const* aString) :
190 item_cell_data_variant{ string{ aString } }
193 item_cell_data(std::string
const& aString) :
194 item_cell_data_variant{ string{ aString } }
197 item_cell_data(std::string&& aString) :
198 item_cell_data_variant{ string{
std::move(aString) } }
202 item_cell_data& operator=(item_cell_data
const& aOther)
204 item_cell_data_variant::operator=(
static_cast<item_cell_data_variant const&
>(aOther));
207 item_cell_data& operator=(item_cell_data&& aOther)
209 item_cell_data_variant::operator=(
static_cast<item_cell_data_variant&&
>(std::move(aOther)));
212 template <
typename T,
typename std::enable_if_t<is_alternative_v<T>,
int> = 0>
213 item_cell_data& operator=(T
const& aArgument)
215 item_cell_data_variant::operator=(aArgument);
218 template <
typename T,
typename std::enable_if_t<is_alternative_v<T>,
int> = 0>
219 item_cell_data& operator=(T&& aArgument)
221 item_cell_data_variant::operator=(std::forward<T>(aArgument));
225 item_cell_data& operator=(
char const* aString)
227 item_cell_data_variant::operator=(
string{ aString });
230 item_cell_data& operator=(std::string
const& aString)
232 item_cell_data_variant::operator=(
string{ aString });
235 item_cell_data& operator=(std::string&& aString)
237 item_cell_data_variant::operator=(
string{ aString });
243 return std::visit([](
auto&& arg) -> std::string
245 typedef typename std::remove_cv<
typename std::remove_reference<
decltype(arg)>::type>::type type;
246 if constexpr(!std::is_same_v<type, std::monostate> && classify_item_call_data<type>::category == item_cell_data_category::Value)
247 return (boost::basic_format<char>{
"%1%"} % arg).str();
254 struct item_cell_info
257 item_cell_data dataMin;
258 item_cell_data dataMax;
259 item_cell_data dataStep;
262 typedef std::optional<item_cell_info> optional_item_cell_info;
264 class i_item_model :
public i_reference_counted,
public i_property_owner
267 declare_event(column_info_changed, item_model_index::column_type)
274 typedef i_item_model abstract_type;
278 struct wrong_model_type : std::logic_error { wrong_model_type() :
std::logic_error(
"neogfx::i_item_model::wrong_model_type") {} };
279 struct bad_column_index : std::logic_error { bad_column_index() :
std::logic_error(
"neogfx::i_item_model::bad_column_index") {} };
280 struct item_not_found : std::logic_error { item_not_found() :
std::logic_error(
"neogfx::i_item_model::item_not_found") {} };
282 virtual ~i_item_model() =
default;
284 virtual bool is_tree()
const = 0;
285 virtual uint32_t rows()
const = 0;
286 virtual uint32_t columns()
const = 0;
287 virtual uint32_t columns(item_model_index
const& aIndex)
const = 0;
288 virtual std::string
const& column_name(item_model_index::column_type aColumnIndex)
const = 0;
289 virtual void set_column_name(item_model_index::column_type aColumnIndex, std::string
const& aName) = 0;
290 virtual item_data_type column_data_type(item_model_index::column_type aColumnIndex)
const = 0;
291 virtual void set_column_data_type(item_model_index::column_type aColumnIndex, item_data_type aType) = 0;
292 virtual item_cell_data
const& column_min_value(item_model_index::column_type aColumnIndex)
const = 0;
293 virtual void set_column_min_value(item_model_index::column_type aColumnIndex, item_cell_data
const& aValue) = 0;
294 virtual item_cell_data
const& column_max_value(item_model_index::column_type aColumnIndex)
const = 0;
295 virtual void set_column_max_value(item_model_index::column_type aColumnIndex, item_cell_data
const& aValue) = 0;
296 virtual item_cell_data
const& column_step_value(item_model_index::column_type aColumnIndex)
const = 0;
297 virtual void set_column_step_value(item_model_index::column_type aColumnIndex, item_cell_data
const& aValue) = 0;
299 virtual iterator index_to_iterator(item_model_index
const& aIndex) = 0;
300 virtual const_iterator index_to_iterator(item_model_index
const& aIndex)
const = 0;
301 virtual item_model_index iterator_to_index(const_iterator aPosition)
const = 0;
302 virtual iterator begin() = 0;
303 virtual const_iterator begin()
const = 0;
304 virtual iterator end() = 0;
305 virtual const_iterator end()
const = 0;
306 virtual iterator sbegin() = 0;
307 virtual const_iterator sbegin()
const = 0;
308 virtual iterator send() = 0;
309 virtual const_iterator send()
const = 0;
310 virtual bool has_children(const_iterator aParent)
const = 0;
311 virtual bool has_children(item_model_index
const& aParentIndex)
const = 0;
312 virtual bool has_parent(const_iterator aChild)
const = 0;
313 virtual bool has_parent(item_model_index
const& aChildIndex)
const = 0;
314 virtual iterator parent(const_iterator aChild) = 0;
315 virtual const_iterator parent(const_iterator aChild)
const = 0;
316 virtual item_model_index parent(item_model_index
const& aChildIndex)
const = 0;
317 virtual iterator sbegin(const_iterator aParent) = 0;
318 virtual const_iterator sbegin(const_iterator aParent)
const = 0;
319 virtual iterator send(const_iterator aParent) = 0;
320 virtual const_iterator send(const_iterator aParent)
const = 0;
322 virtual bool empty()
const = 0;
323 virtual void reserve(uint32_t aItemCount) = 0;
324 virtual uint32_t capacity()
const = 0;
325 virtual iterator insert_item(const_iterator aPosition, item_cell_data
const& aCellData) = 0;
326 virtual iterator insert_item(item_model_index
const& aIndex, item_cell_data
const& aCellData) = 0;
327 virtual iterator append_item(const_iterator aParent, item_cell_data
const& aCellData) = 0;
328 virtual iterator append_item(item_model_index
const& aIndex, item_cell_data
const& aCellData) = 0;
329 virtual void clear() = 0;
330 virtual iterator
erase(const_iterator aPosition) = 0;
331 virtual iterator
erase(item_model_index
const& aIndex) = 0;
332 virtual void insert_cell_data(const_iterator aPosition, item_model_index::column_type aColumnIndex, item_cell_data
const& aCellData) = 0;
333 virtual void insert_cell_data(item_model_index
const& aIndex, item_cell_data
const& aCellData) = 0;
334 virtual void update_cell_data(const_iterator aPosition, item_model_index::column_type aColumnIndex, item_cell_data
const& aCellData) = 0;
335 virtual void update_cell_data(item_model_index
const& aIndex, item_cell_data
const& aCellData) = 0;
337 virtual const item_cell_info& cell_info(item_model_index
const& aIndex)
const = 0;
338 virtual item_cell_data
const& cell_data(item_model_index
const& aIndex)
const = 0;
#define end_declare_enum(enumName)
#define declare_enum_string(enumName, enumEnumerator)
#define begin_declare_enum(enumName)
constexpr object_type category(object_type aType)
std::string to_string(note const &aNote)
std::optional< item_model_index > optional_item_model_index
plf::hive< element_type, allocator_type >::size_type erase(plf::hive< element_type, allocator_type > &container, const element_type &value)
constexpr decltype(auto) visit(Visitor &&vis, neolib::variant< Types... > &&var)
#define declare_event(declName,...)