Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
TStringList.h
Go to the documentation of this file.
1#pragma once
2#include <QVector>
3
4namespace sf
5{
6
10template<typename S, typename O = void>
12{
13 public:
18
22 TStringList(bool duplicates, bool sorted);
23
28
35 ssize_t add(const S& text, O* object = nullptr);
36
44 ssize_t addAt(ssize_t index, const S& text, O* object = nullptr);
45
49 void clear();
50
55 void removeAt(ssize_t index);
56
62 void exchange(ssize_t i, ssize_t j);
63
69 ssize_t indexOf(const S& text) const;
70
75 void setSorted(bool flag = true);
76
80 bool isSorted() const;
81
85 ssize_t count() const;
86
92 const S& at(ssize_t index) const;
93
99 void setObject(ssize_t index, O* obj);
100
106 O* objectAt(ssize_t index) const;
107
113
118 void endChange();
119
123 std::function<void(void*)> onChanged;
124
128 std::function<void(void*)> onChanging;
129
130 private:
134 struct Item
135 {
136 S text;
137 O* object;
138 };
139
143 bool find(const S& text, ssize_t& index) const;
144
148 void sort();
149
153 void quickSort(ssize_t left, ssize_t right, std::function<bool(const Item&, const Item&)> comp);
154
158 std::vector<Item> _items;
162 bool _duplicates;
166 bool _sorted;
167
171 bool _changing;
172};
173
174}// namespace sf
175
176// Include all inlined functions and template implementations.
177#include <misc/gen/TStringList.hpp>
String list with optional object association and sorting.
Definition TStringList.h:12
O * objectAt(ssize_t index) const
Gets the associated object at index.
const S & at(ssize_t index) const
Returns the string at index.
void setObject(ssize_t index, O *obj)
Sets the object at index.
ssize_t count() const
Returns the number of items.
void setSorted(bool flag=true)
Sorts the list and sets a flag so the new entries are sorted as well.
ssize_t indexOf(const S &text) const
Returns the index of the string.
std::function< void(void *)> onChanging
Event handler before the list changes.
Definition TStringList.h:128
void exchange(ssize_t i, ssize_t j)
Exchanges two items.
void beginChange()
Prevents calling onChanging and onChanged when modifying. Call this before updating or adding multipl...
bool isSorted() const
Whether the list is sorted.
void endChange()
Prevents calling onChanging and onChanged when modifying. Call this after updating or adding multiple...
std::function< void(void *)> onChanged
Event handler when the list has changed.
Definition TStringList.h:123
ssize_t add(const S &text, O *object=nullptr)
Adds a string to the list.
~TStringList()
Destroys the string list and releases resources.
void removeAt(ssize_t index)
Deletes the item at the given index.
void clear()
Clears all items from the list.
TStringList()
Constructs a list not allowing duplicates by default.
ssize_t addAt(ssize_t index, const S &text, O *object=nullptr)
Inserts a string at the given index but when sorting it is calling add() instead.
TStringList(bool duplicates, bool sorted)
Constructs a list configuring duplicate behavior and sorting.
Definition Application.h:10