~ubuntu-branches/debian/sid/kexi/sid

« back to all changes in this revision

Viewing changes to src/formeditor/events.cpp

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2017-06-24 20:10:10 UTC
  • Revision ID: package-import@ubuntu.com-20170624201010-5lrzd5r2vwthwifp
Tags: upstream-3.0.1.1
ImportĀ upstreamĀ versionĀ 3.0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
#include <QDomDocument>
 
21
 
 
22
#include "events.h"
 
23
 
 
24
using namespace KFormDesigner;
 
25
 
 
26
class Connection::Private
 
27
{
 
28
public:
 
29
    Private(const QString &sender_, const QString &signal_, const QString &receiver_, const QString &slot_);
 
30
    Private()
 
31
    {
 
32
    }
 
33
 
 
34
    ~Private()
 
35
    {
 
36
    }
 
37
 
 
38
    QString sender;
 
39
    QString signal;
 
40
    QString receiver;
 
41
    QString slot;
 
42
};
 
43
 
 
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_)
 
46
 
 
47
{
 
48
 
 
49
}
 
50
 
 
51
Connection::Connection(const QString &sender, const QString &signal,
 
52
                       const QString &receiver, const QString &slot) : d(new Private(sender, signal, receiver, slot))
 
53
{
 
54
}
 
55
 
 
56
Connection::Connection() : d(new Private())
 
57
{
 
58
}
 
59
 
 
60
Connection::~Connection()
 
61
{
 
62
    delete d;
 
63
}
 
64
 
 
65
QString Connection::sender() const
 
66
{
 
67
    return d->sender;
 
68
}
 
69
 
 
70
QString Connection::receiver() const
 
71
{
 
72
    return d->receiver;
 
73
}
 
74
 
 
75
QString Connection::signal() const
 
76
{
 
77
    return d->signal;
 
78
}
 
79
 
 
80
QString Connection::slot() const
 
81
{
 
82
    return d->slot;
 
83
}
 
84
 
 
85
void Connection::setSender(const QString &v)
 
86
{
 
87
    d->sender = v;
 
88
}
 
89
 
 
90
void Connection::setReceiver(const QString &v)
 
91
{
 
92
    d->receiver = v;
 
93
}
 
94
 
 
95
void Connection::setSignal(const QString &v)
 
96
{
 
97
    d->signal = v;
 
98
}
 
99
 
 
100
void Connection::setSlot(const QString &v)
 
101
{
 
102
    d->slot = v;
 
103
}
 
104
///////////////////////////////////////
 
105
 
 
106
ConnectionBuffer::ConnectionBuffer()
 
107
{
 
108
}
 
109
 
 
110
ConnectionBuffer::~ConnectionBuffer()
 
111
{
 
112
}
 
113
 
 
114
void
 
115
ConnectionBuffer::fixName(const QString &oldName, const QString &newName)
 
116
{
 
117
    foreach (Connection *c, *this) {
 
118
        if (c->sender() == oldName)
 
119
            c->setSender(newName);
 
120
        if (c->receiver() == oldName)
 
121
            c->setReceiver(newName);
 
122
    }
 
123
}
 
124
 
 
125
ConnectionBuffer*
 
126
ConnectionBuffer::allConnectionsForWidget(const QString &widget)
 
127
{
 
128
    ConnectionBuffer *list = new ConnectionBuffer();
 
129
    foreach (Connection *c, *this) {
 
130
        if ((c->sender() == widget) || (c->receiver() == widget))
 
131
            list->append(c);
 
132
    }
 
133
 
 
134
    return list;
 
135
}
 
136
 
 
137
void
 
138
ConnectionBuffer::save(QDomNode &parentNode)
 
139
{
 
140
    if (isEmpty())
 
141
        return;
 
142
 
 
143
    QDomDocument domDoc = parentNode.ownerDocument();
 
144
    QDomElement connections;
 
145
    if (!parentNode.firstChildElement("connections").isNull())
 
146
        connections = parentNode.firstChildElement("connections");
 
147
    else
 
148
        connections = domDoc.createElement("connections");
 
149
    parentNode.appendChild(connections);
 
150
 
 
151
    foreach (Connection *c, *this) {
 
152
        QDomElement connection = domDoc.createElement("connection");
 
153
        connection.setAttribute("language", "C++");
 
154
        connections.appendChild(connection);
 
155
 
 
156
        QDomElement sender = domDoc.createElement("sender");
 
157
        connection.appendChild(sender);
 
158
        QDomText senderText = domDoc.createTextNode(c->sender());
 
159
        sender.appendChild(senderText);
 
160
 
 
161
        QDomElement signal = domDoc.createElement("signal");
 
162
        connection.appendChild(signal);
 
163
        QDomText signalText = domDoc.createTextNode(c->signal());
 
164
        signal.appendChild(signalText);
 
165
 
 
166
        QDomElement receiver = domDoc.createElement("receiver");
 
167
        connection.appendChild(receiver);
 
168
        QDomText receiverText = domDoc.createTextNode(c->receiver());
 
169
        receiver.appendChild(receiverText);
 
170
 
 
171
        QDomElement slot = domDoc.createElement("slot");
 
172
        connection.appendChild(slot);
 
173
        QDomText slotText = domDoc.createTextNode(c->slot());
 
174
        slot.appendChild(slotText);
 
175
    }
 
176
}
 
177
 
 
178
void ConnectionBuffer::saveAllConnectionsForWidget(const QString &widget, QDomNode &parentNode)
 
179
{
 
180
    ConnectionBuffer *buff = allConnectionsForWidget(widget);
 
181
    buff->save(parentNode);
 
182
    delete buff;
 
183
}
 
184
 
 
185
void ConnectionBuffer::load(const QDomNode &node)
 
186
{
 
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());
 
193
        append(conn);
 
194
    }
 
195
}
 
196
 
 
197
void
 
198
ConnectionBuffer::removeAllConnectionsForWidget(const QString &widget)
 
199
{
 
200
    ConnectionList toRemove;
 
201
    foreach (Connection *c, *this) {
 
202
        if ((c->sender() == widget) || (c->receiver() == widget)) {
 
203
            toRemove.append(c);
 
204
        }
 
205
    }
 
206
    foreach (Connection *c, toRemove) {
 
207
        removeAll(c);
 
208
    }
 
209
    qDeleteAll(toRemove);
 
210
}