LeechCraft 0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
flatitemsmodel.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
12
13namespace LC::Util
14{
15 namespace detail
16 {
17 template<typename T, typename... Ts>
18 QVariant GetFieldImpl (int idx, T& head, Ts&... tail)
19 {
20 if (!idx)
21 return head;
22
23 if constexpr (sizeof... (Ts))
24 return GetFieldImpl (idx - 1, tail...);
25 else
26 throw std::runtime_error { "out of bounds tuple-like access" };
27 }
28
29 template<typename T>
30 QVariant GetField (const T& item, int idx)
31 {
32 auto&& [...elems] = item;
33 return GetFieldImpl (idx, elems...);
34 }
35 }
36
37 template<typename T>
39 {
40 public:
42 protected:
43 QVariant GetData (int row, int col, int role) const override
44 {
45 if (role == this->DataRole)
46 return QVariant::fromValue (this->Items_.at (row));
47
48 if (role != Qt::DisplayRole)
49 return {};
50
51 return detail::GetField (this->Items_.at (row), col);
52 }
53 };
54}
static constexpr auto DataRole
QVariant GetData(int row, int col, int role) const override
QVariant GetFieldImpl(int idx, T &head, Ts &... tail)
QVariant GetField(const T &item, int idx)