kexi

events.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <qdom.h>
00021 #include <kdebug.h>
00022 
00023 #include "events.h"
00024 
00025 namespace KFormDesigner {
00026 
00027 Connection::Connection(const QString &sender, const QString &signal,
00028      const QString &receiver, const QString &slot)
00029 {
00030     m_sender = sender;
00031     m_signal = signal;
00032     m_receiver = receiver;
00033     m_slot = slot;
00034 }
00035 
00037 
00038 ConnectionBuffer::ConnectionBuffer()
00039 {
00040     setAutoDelete(true);
00041 }
00042 
00043 void
00044 ConnectionBuffer::fixName(const QString &oldName, const QString &newName)
00045 {
00046     for(Connection *c = first(); c; c = next())
00047     {
00048         if(c->sender() == oldName)
00049             c->setSender(newName);
00050         if(c->receiver() == oldName)
00051             c->setReceiver(newName);
00052     }
00053 }
00054 
00055 ConnectionBuffer*
00056 ConnectionBuffer::allConnectionsForWidget(const QString &widget)
00057 {
00058     ConnectionBuffer *list = new ConnectionBuffer();
00059     list->setAutoDelete(false); // or it will delete all our connections
00060     for(Connection *c = first(); c; c = next())
00061     {
00062         if((c->sender() == widget) || (c->receiver() == widget))
00063             list->append(c);
00064     }
00065 
00066     return list;
00067 }
00068 
00069 void
00070 ConnectionBuffer::save(QDomNode &parentNode)
00071 {
00072     if(isEmpty())
00073         return;
00074 
00075     QDomDocument domDoc = parentNode.ownerDocument();
00076     QDomElement connections;
00077     if(!parentNode.namedItem("connections").isNull())
00078         connections = parentNode.namedItem("connections").toElement();
00079     else
00080         connections = domDoc.createElement("connections");
00081     parentNode.appendChild(connections);
00082 
00083     for(Connection *c = first(); c; c = next())
00084     {
00085         QDomElement connection = domDoc.createElement("connection");
00086         connection.setAttribute("language", "C++");
00087         connections.appendChild(connection);
00088 
00089         QDomElement sender = domDoc.createElement("sender");
00090         connection.appendChild(sender);
00091         QDomText senderText = domDoc.createTextNode(c->sender());
00092         sender.appendChild(senderText);
00093 
00094         QDomElement signal = domDoc.createElement("signal");
00095         connection.appendChild(signal);
00096         QDomText signalText = domDoc.createTextNode(c->signal());
00097         signal.appendChild(signalText);
00098 
00099         QDomElement receiver = domDoc.createElement("receiver");
00100         connection.appendChild(receiver);
00101         QDomText receiverText = domDoc.createTextNode(c->receiver());
00102         receiver.appendChild(receiverText);
00103 
00104         QDomElement slot = domDoc.createElement("slot");
00105         connection.appendChild(slot);
00106         QDomText slotText = domDoc.createTextNode(c->slot());
00107         slot.appendChild(slotText);
00108     }
00109 }
00110 
00111 void
00112 ConnectionBuffer::saveAllConnectionsForWidget(const QString &widget, QDomNode parentNode)
00113 {
00114     ConnectionBuffer *buff = allConnectionsForWidget(widget);
00115     buff->save(parentNode);
00116     delete buff;
00117 }
00118 
00119 void
00120 ConnectionBuffer::load(QDomNode node)
00121 {
00122     for(QDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling())
00123     {
00124         Connection *conn = new Connection();
00125         conn->setSender(n.namedItem("sender").toElement().text());
00126         conn->setSignal(n.namedItem("signal").toElement().text());
00127         conn->setReceiver(n.namedItem("receiver").toElement().text());
00128         conn->setSlot(n.namedItem("slot").toElement().text());
00129         append(conn);
00130     }
00131 }
00132 
00133 void
00134 ConnectionBuffer::removeAllConnectionsForWidget(const QString &widget)
00135 {
00136     for(Connection *c = first(); c; c = next())
00137     {
00138         if((c->sender() == widget) || (c->receiver() == widget))
00139             removeRef(c);
00140     }
00141 }
00142 
00143 }
00144 
00145 //#include "events.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys