LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
flatitemsmodeltypedbase.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
11#include "flatitemsmodelbase.h"
12
13namespace LC::Util
14{
15 template<typename T>
17 {
18 protected:
19 QVector<T> Items_;
20 public:
22
23 void SetItems (QVector<T> items)
24 {
26 Items_ = std::move (items);
28 }
29
30 const QVector<T>& GetItems () const
31 {
32 return Items_;
33 }
34
35 void AddItem (const T& item)
36 {
37 beginInsertRows ({}, Items_.size (), Items_.size ());
38 Items_.push_back (item);
40 }
41
42 void SetItem (int idx, const T& item)
43 {
44 Items_ [idx] = item;
46 index (idx, columnCount ({}) - 1));
47 }
48
49 template<typename F>
50 void EditItem (int idx, F&& editor)
51 {
52 std::invoke (std::forward<F> (editor), Items_ [idx]);
54 index (idx, columnCount ({}) - 1));
55 }
56
57 void RemoveItem (int idx)
58 {
59 beginRemoveRows ({}, idx, idx);
60 Items_.removeAt (idx);
62 }
63 protected:
64 int GetItemsCount () const override
65 {
66 return Items_.size ();
67 }
68 };
69}
QModelIndex index(int row, int col, const QModelIndex &parent={}) const override
int columnCount(const QModelIndex &index={}) const override
FlatItemsModelBase(QStringList headers, QObject *=nullptr)
void SetItem(int idx, const T &item)
const QVector< T > & GetItems() const
Container< T > Filter(const Container< T > &c, F f)
Definition prelude.h:118