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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/***************************************************************************
mapslistview.cpp - description
-------------------
begin : Weg Feb 26 2003
copyright : (C) 2003 by Jan SchÃ?fer
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
// KDE
#include <klistview.h>
#include <klocale.h>
#include <kdebug.h>
// locale
#include "mapslistview.h"
MapsListView::MapsListView(QWidget *parent, const char *name)
: QVBox(parent, name) {
_listView = new KListView(this);
_listView->addColumn(i18n("Maps"));
_listView->setFullWidth(true);
_listView->setSelectionMode(QListView::Single);
_listView->setItemsRenameable(true);
connect( _listView, SIGNAL( selectionChanged(QListViewItem*)),
this, SLOT( slotSelectionChanged(QListViewItem*)));
connect( _listView, SIGNAL( itemRenamed(QListViewItem*)),
this, SLOT( slotItemRenamed(QListViewItem*)));
}
MapsListView::~MapsListView() {
}
void MapsListView::addMap(const QString & name = QString::null) {
new QListViewItem(_listView,name);
//kdDebug() << "MapsListView::addMap : Added map '" << name << "'" << endl;
}
void MapsListView::addMaps(QPtrList<MapTag> * maps) {
for (MapTag *tag = maps->first(); tag!=0L; tag=maps->next()) {
addMap(tag->name);
}
}
void MapsListView::selectMap(const QString & name) {
QListViewItem* item = _listView->findItem(name,0);
if (item) {
selectMap(item);
} else
kdWarning() << "MapsListView::selectMap : Couldn't found map '" << name << "'" << endl;
}
void MapsListView::selectMap(QListViewItem* item) {
if (item)
_listView->setSelected(item,true);
}
QString MapsListView::selectedMap() {
QString result;
QListViewItem* item = _listView->selectedItem();
if (item)
result = item->text(0);
else
kdWarning() << "MapsListView::selectedMap : No map selected !" << endl;
return result;
}
void MapsListView::removeMap(const QString & name) {
QListViewItem* item = _listView->findItem(name,0);
if (item) {
_listView->takeItem(item);
_listView->setSelected(_listView->currentItem(),true);
// kdDebug() << "MapsListView::removeMap : Removed map '" << name << "'" << endl;
} else
kdWarning() << "MapsListView::removeMap : Couldn't found map '" << name << "'" << endl;
}
void MapsListView::clear() {
_listView->clear();
}
void MapsListView::slotSelectionChanged(QListViewItem* item) {
QString name = item->text(0);
emit mapSelected(name);
}
void MapsListView::slotItemRenamed(QListViewItem* item) {
QString name = item->text(0);
emit mapRenamed(name);
}
void MapsListView::changeMapName(const QString & oldName, const QString & newName) {
// kdDebug() << "MapsListView::changeMapName : " << oldName << " to " << newName << endl;
QListViewItem* item = _listView->findItem(oldName,0);
if (item) {
item->setText(0,newName);
// kdDebug() << "MapsListView::changeMapName : successful" << endl;
}
else {
kdWarning() << "MapsListView::changeMapName : Chouldn't find map with name '" << oldName << "'" << endl;
}
}
bool MapsListView::nameAlreadyExists(const QString & name) {
// kdDebug() << "MapsListView::nameAlreadyExists : " << name << " ? " << endl;
bool result = false;
QListViewItem* item = 0L;
for(item = _listView->firstChild(); item; item = item->nextSibling()) {
QString otherMap = item->text(0);
if(name == otherMap) {
result = true;
break;
}
}
// kdDebug() << "MapsListView::nameAlreadyExists : " << name << " : " << result << endl;
return result;
}
QStringList MapsListView::getMaps() {
QStringList result;
QListViewItem* item = 0L;
for(item = _listView->firstChild(); item; item = item->nextSibling()) {
QString map = item->text(0);
result << map;
}
return result;
}
QString MapsListView::getUnusedMapName() {
QString result;
QString attempt;
int i=0;
while(result.isEmpty()) {
i++;
attempt = i18n("unnamed");
attempt += QString::number(i);
if (nameAlreadyExists(attempt))
continue;
result = attempt;
}
// kdDebug() << "MapsListView::getUnusedMapName : Found an unused name : '" << result << "'" << endl;
return result;
}
uint MapsListView::count() {
return _listView->childCount();
}
#include "mapslistview.moc"
|