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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
/* This file is part of the KDE project
Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at>
Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <kdebug.h>
#include <tqwidget.h>
#include <tqvariant.h>
#include <tqdom.h>
#include <tqtextstream.h>
#include "form.h"
#include "container.h"
#include "objecttree.h"
using namespace KFormDesigner;
/////////////////////////////////////////////////////////////////////////////////////////
///////////////// ObjectTreeItem /////////////
////////////////////////////////////////////////////////////////////////////////////////
ObjectTreeItem::ObjectTreeItem(const TQString &classn, const TQString &name, TQWidget *widget,
Container *parentContainer, Container *container)
: m_enabled(true), m_row(-1), m_col(-1), m_rowspan(-1), m_colspan(-1), m_span(false)
{
m_className = classn;
m_name = name;
m_widget = widget;
m_container = container;
m_eater = new EventEater(widget, parentContainer);
m_parent = 0;
m_subprops = 0;
}
ObjectTreeItem::~ObjectTreeItem()
{
// kdDebug() << "ObjectTreeItem deleted: " << name() << endl;
delete m_subprops;
}
void
ObjectTreeItem::rename(const TQString &name)
{
m_name = name;
}
void
ObjectTreeItem::addChild(ObjectTreeItem *c)
{
m_tqchildren.append(c);
c->setParent(this);
}
void
ObjectTreeItem::removeChild(ObjectTreeItem *c)
{
m_tqchildren.remove(c);
}
void
ObjectTreeItem::addModifiedProperty(const TQCString &property, const TQVariant &oldValue)
{
if(property == "name")
return;
if(!m_props.contains(property)) {
m_props.insert(property, oldValue);
kdDebug() << "ObjectTree::adModProperty(): Added this property in the list: " << property << " oldValue: " << oldValue << endl;
}
}
void
ObjectTreeItem::addSubproperty(const TQCString &property, const TQVariant& value)
{
if (!m_subprops)
m_subprops = new TQMap<TQString, TQVariant>();
if (!m_props.contains(property))
m_subprops->insert( property, value );
}
void
ObjectTreeItem::storeUnknownProperty(TQDomElement &el)
{
if(!el.isNull()) {
TQTextStream ts(m_unknownProps, IO_WriteOnly|IO_Append );
el.save(ts, 0);
}
}
void
ObjectTreeItem::setPixmapName(const TQCString &property, const TQString &name)
{
m_pixmapNames[property] = name;
}
TQString
ObjectTreeItem::pixmapName(const TQCString &property)
{
if(m_pixmapNames.contains(property))
return m_pixmapNames[property];
return TQString();
}
void
ObjectTreeItem::setGridPos(int row, int col, int rowspan, int colspan)
{
m_row = row; m_col = col;
m_rowspan = rowspan;
m_colspan = colspan;
if(colspan || rowspan)
m_span = true;
else
m_span = false;
}
/////////////////////////////////////////////////////////////////////////////////////////
/// ObjectTree /////////
////////////////////////////////////////////////////////////////////////////////////////
ObjectTree::ObjectTree(const TQString &classn, const TQString &name, TQWidget *widget, Container *container)
: ObjectTreeItem(classn, name, widget, container, container)
{
}
ObjectTree::~ObjectTree()
{
// for(ObjectTreeItem *it = tqchildren()->first(); it; it = tqchildren()->next())
// removeItem(it->name());
while (tqchildren()->first()) {
removeItem(tqchildren()->first());
}
}
bool
ObjectTree::rename(const TQString &oldname, const TQString &newname)
{
if(oldname == m_name)
{
ObjectTreeItem::rename(newname);
return true;
}
ObjectTreeItem *it = lookup(oldname);
if(!it)
return false;
it->rename(newname);
m_treeDict.remove(oldname);
m_treeDict.insert(newname, it);
return true;
}
bool
ObjectTree::reparent(const TQString &name, const TQString &newparent)
{
ObjectTreeItem *item = lookup(name);
if(!item) return false;
ObjectTreeItem *parent = lookup(newparent);
if(!parent) return false;
item->parent()->removeChild(item);
parent->addChild(item);
return true;
}
ObjectTreeItem*
ObjectTree::lookup(const TQString &name)
{
if(name == this->name())
return this;
else
return m_treeDict[name];
}
void
ObjectTree::addItem(ObjectTreeItem *parent, ObjectTreeItem *c)
{
m_treeDict.insert(c->name(), c);
if(!parent)
parent = this;
parent->addChild(c);
m_container->form()->emitChildAdded(c);
kdDebug() << "ObjectTree::addItem(): adding " << c->name() << " to " << parent->name() << endl;
}
void
ObjectTree::removeItem(const TQString &name)
{
ObjectTreeItem *c = lookup(name);
removeItem(c);
}
void
ObjectTree::removeItem(ObjectTreeItem *c)
{
if (m_container && m_container->form())
m_container->form()->emitChildRemoved(c);
for(ObjectTreeItem *it = c->tqchildren()->first(); it; it = c->tqchildren()->next())
removeItem(it->name());
m_treeDict.remove(c->name());
c->parent()->removeChild(c);
delete c;
}
TQCString
ObjectTree::generateUniqueName(const TQCString &prefix, bool numberSuffixRequired)
{
/* old way of naming widgets
int appendix = m_names[c] + 1;
TQString name(c);
name.append(TQString::number(appendix));
m_names[c] = appendix;*/
if (!numberSuffixRequired && !lookup(prefix))
return prefix;
TQString name( prefix );
int i = 2; //start from 2, i.e. we have: "widget", "widget2", etc.
while(lookup(name + TQString::number(i)))
i++;
return (name + TQString::number(i)).latin1();
}
|