-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyproxy.cpp
More file actions
48 lines (44 loc) · 1.25 KB
/
Copy pathmyproxy.cpp
File metadata and controls
48 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "myproxy.h"
MyProxy::MyProxy(QQmlObjectListModel<Item> *model, QObject *parent)
: QObject(parent),
model_(model)
{
}
void MyProxy::test()
{
static int itemNumber = 0;
static QStringList colors {"red", "green", "blue", "magenta", "orange", "gray", "navy"};
static QStringList tags {"Foo", "Bar", "Baz", "Woop"};
if(!itemNumber) itemNumber = model_->count();
switch(qrand() % 8)
{
case 0:
case 4:
// add a new item
model_->append(new Item(QStringLiteral("Item %1").arg(++itemNumber), {}));
break;
case 1:
case 5:
case 6:
// add a tag to an item
if(model_->isEmpty()) test();
else model_->at(qrand() % model_->count())->tags()->append(new Tag(tags[qrand() % tags.count()], colors[qrand() % colors.count()]));
break;
case 2:
case 7:
// remove a tag
if(model_->isEmpty()) test();
else
{
auto t = model_->at(qrand() % model_->count())->tags();
if(t->isEmpty()) test();
else t->remove(qrand() % t->count());
}
break;
case 3:
// remove an item
if(model_->isEmpty()) test();
else model_->remove(qrand() % model_->count());
break;
}
}