blob: 48b46cc51f3f1a4743a52756d328aac241451322 (
plain) (
blame)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#include "listtostringlisthash.h"
#include "config_builder.h"
#include "common/unused.h"
#include <QListWidget>
ListToStringListHash::ListToStringListHash(CfgEntry* key) :
assignedKey(key)
{
}
bool ListToStringListHash::isConfigForWidget(CfgEntry* key, QWidget* widget)
{
UNUSED(widget);
return (assignedKey == key);
}
void ListToStringListHash::applyConfigToWidget(CfgEntry* key, QWidget* widget, const QVariant& value)
{
UNUSED(key);
QListWidget* list = dynamic_cast<QListWidget*>(widget);
QHash<QString,QListWidgetItem*> itemsByName;
for (int i = 0; i < list->count(); i++)
itemsByName[list->item(i)->text()] = list->item(i);
QHash<QString,QVariant> orderHash = value.toHash();
for (const QString& typeName : itemsByName.keys())
{
if (!orderHash.contains(typeName))
continue;
itemsByName[typeName]->setData(QListWidgetItem::UserType, orderHash[typeName]);
}
}
QVariant ListToStringListHash::getWidgetConfigValue(QWidget* widget, bool& ok)
{
QListWidget* list = dynamic_cast<QListWidget*>(widget);
if (!list)
{
ok = false;
return QVariant();
}
QHash<QString,QVariant> orderHash;
for (int i = 0; i < list->count(); i++)
orderHash[list->item(i)->text()] = list->item(i)->data(QListWidgetItem::UserType);
ok = true;
return orderHash;
}
const char*ListToStringListHash::getModifiedNotifier() const
{
return SIGNAL(itemChanged(QListWidgetItem*));
}
QString ListToStringListHash::getFilterString(QWidget* widget) const
{
QListWidget* list = dynamic_cast<QListWidget*>(widget);
QStringList strList;
for (int i = 0; i < list->count(); i++)
strList += list->item(i)->text() + " " + list->item(i)->data(QListWidgetItem::UserType).toStringList().join(" ");
return strList.join(" ");
}
|