1
/* This file is part of the KDE project
2
Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
20
#include <QDomDocument>
24
using namespace KFormDesigner;
26
class Connection::Private
29
Private(const QString &sender_, const QString &signal_, const QString &receiver_, const QString &slot_);
44
Connection::Private::Private(const QString &sender_, const QString &signal_, const QString &receiver_, const QString &slot_)
45
:sender(sender_), signal(signal_), receiver(receiver_), slot(slot_)
51
Connection::Connection(const QString &sender, const QString &signal,
52
const QString &receiver, const QString &slot) : d(new Private(sender, signal, receiver, slot))
56
Connection::Connection() : d(new Private())
60
Connection::~Connection()
65
QString Connection::sender() const
70
QString Connection::receiver() const
75
QString Connection::signal() const
80
QString Connection::slot() const
85
void Connection::setSender(const QString &v)
90
void Connection::setReceiver(const QString &v)
95
void Connection::setSignal(const QString &v)
100
void Connection::setSlot(const QString &v)
104
///////////////////////////////////////
106
ConnectionBuffer::ConnectionBuffer()
110
ConnectionBuffer::~ConnectionBuffer()
115
ConnectionBuffer::fixName(const QString &oldName, const QString &newName)
117
foreach (Connection *c, *this) {
118
if (c->sender() == oldName)
119
c->setSender(newName);
120
if (c->receiver() == oldName)
121
c->setReceiver(newName);
126
ConnectionBuffer::allConnectionsForWidget(const QString &widget)
128
ConnectionBuffer *list = new ConnectionBuffer();
129
foreach (Connection *c, *this) {
130
if ((c->sender() == widget) || (c->receiver() == widget))
138
ConnectionBuffer::save(QDomNode &parentNode)
143
QDomDocument domDoc = parentNode.ownerDocument();
144
QDomElement connections;
145
if (!parentNode.firstChildElement("connections").isNull())
146
connections = parentNode.firstChildElement("connections");
148
connections = domDoc.createElement("connections");
149
parentNode.appendChild(connections);
151
foreach (Connection *c, *this) {
152
QDomElement connection = domDoc.createElement("connection");
153
connection.setAttribute("language", "C++");
154
connections.appendChild(connection);
156
QDomElement sender = domDoc.createElement("sender");
157
connection.appendChild(sender);
158
QDomText senderText = domDoc.createTextNode(c->sender());
159
sender.appendChild(senderText);
161
QDomElement signal = domDoc.createElement("signal");
162
connection.appendChild(signal);
163
QDomText signalText = domDoc.createTextNode(c->signal());
164
signal.appendChild(signalText);
166
QDomElement receiver = domDoc.createElement("receiver");
167
connection.appendChild(receiver);
168
QDomText receiverText = domDoc.createTextNode(c->receiver());
169
receiver.appendChild(receiverText);
171
QDomElement slot = domDoc.createElement("slot");
172
connection.appendChild(slot);
173
QDomText slotText = domDoc.createTextNode(c->slot());
174
slot.appendChild(slotText);
178
void ConnectionBuffer::saveAllConnectionsForWidget(const QString &widget, QDomNode &parentNode)
180
ConnectionBuffer *buff = allConnectionsForWidget(widget);
181
buff->save(parentNode);
185
void ConnectionBuffer::load(const QDomNode &node)
187
for (QDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling()) {
188
Connection *conn = new Connection();
189
conn->setSender(n.firstChildElement("sender").text());
190
conn->setSignal(n.firstChildElement("signal").text());
191
conn->setReceiver(n.firstChildElement("receiver").text());
192
conn->setSlot(n.firstChildElement("slot").text());
198
ConnectionBuffer::removeAllConnectionsForWidget(const QString &widget)
200
ConnectionList toRemove;
201
foreach (Connection *c, *this) {
202
if ((c->sender() == widget) || (c->receiver() == widget)) {
206
foreach (Connection *c, toRemove) {
209
qDeleteAll(toRemove);