forked from mrkite/TerraFirma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhilitedialog.cpp
71 lines (60 loc) · 1.82 KB
/
hilitedialog.cpp
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
68
69
70
71
/**
* @Copyright 2015 seancode
*
* Draws and populates the tile hiliting dialog
*/
#include "./hilitedialog.h"
#include "./ui_hilitedialog.h"
HiliteDialog::HiliteDialog(QSharedPointer<World> world, QWidget *parent)
: QDialog(parent), ui(new Ui::HiliteDialog) {
ui->setupUi(this);
ui->treeWidget->setHeaderLabel("Tile");
QHashIterator<int, QSharedPointer<TileInfo>> i(world->info.tiles);
while (i.hasNext()) {
i.next();
auto root = new QTreeWidgetItem(ui->treeWidget);
root->setText(0, i.value()->name);
root->setData(0, Qt::UserRole, QVariant::fromValue(i.value()));
for (auto child : i.value()->variants) {
addChild(child, i.value()->name, root);
}
}
ui->treeWidget->sortItems(0, Qt::AscendingOrder);
}
void HiliteDialog::accept() {
if (!hiliting.isNull())
tagChild(hiliting, false);
if (ui->treeWidget->selectedItems().isEmpty()) {
hiliting.clear();
} else {
auto item = ui->treeWidget->selectedItems().first();
auto variant = item->data(0, Qt::UserRole);
QSharedPointer<TileInfo> tile = variant.value<QSharedPointer<TileInfo>>();
tagChild(tile, true);
hiliting = tile;
}
QDialog::accept();
}
void HiliteDialog::addChild(QSharedPointer<TileInfo> tile, QString name,
QTreeWidgetItem *parent) {
if (tile->name != name) {
auto child = new QTreeWidgetItem;
child->setText(0, tile->name);
child->setData(0, Qt::UserRole, QVariant::fromValue(tile));
parent->addChild(child);
parent = child;
name = tile->name;
}
for (auto child : tile->variants) {
addChild(child, name, parent);
}
}
void HiliteDialog::tagChild(QSharedPointer<TileInfo> tile, bool hilite) {
tile->isHilighting = hilite;
for (auto child : tile->variants) {
tagChild(child, hilite);
}
}
HiliteDialog::~HiliteDialog() {
delete ui;
}