File indexing completed on 2024-05-12 16:39:36
0001 /* This file is part of the KDE project 0002 Copyright (C) 2002, 2003 Joseph Wenninger <jowenn@kde.org> 0003 Copyright (C) 2005 Jarosław Staniek <staniek@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "kexidragobjects.h" 0022 0023 #include <QDataStream> 0024 #include <QStringList> 0025 #include <QDragMoveEvent> 0026 #include <QDomDocument> 0027 #include <QMimeData> 0028 #include <QDebug> 0029 #include <QWidget> 0030 0031 bool KexiFieldDrag::canDecode(QDropEvent *e) 0032 { 0033 return e->mimeData()->hasFormat("kexi/fields"); 0034 } 0035 0036 bool KexiFieldDrag::decode(QDropEvent* e, QString *sourceMimeType, 0037 QString *sourceName, QStringList *fields) 0038 { 0039 Q_ASSERT(sourceMimeType); 0040 Q_ASSERT(sourceName); 0041 Q_ASSERT(fields); 0042 0043 QByteArray payload(e->mimeData()->data("kexi/fields")); 0044 if (payload.isEmpty()) {//try single 0045 return false; 0046 } 0047 e->accept(); 0048 QDataStream stream1(&payload, QIODevice::ReadOnly); 0049 0050 stream1 >> *sourceMimeType; 0051 stream1 >> *sourceName; 0052 stream1 >> *fields; 0053 // qDebug() << "decoded:" << sourceMimeType<<"/"<<sourceName<<"/"<<fields; 0054 return true; 0055 } 0056 0057 // ---------- 0058 0059 KexiDataProviderDrag::KexiDataProviderDrag(const QString& sourceMimeType, const QString& sourceName, 0060 QWidget *parent) 0061 : QDrag(parent) 0062 { 0063 QMimeData *mimedata = new QMimeData(); 0064 QByteArray data; 0065 QDataStream stream1(&data, QIODevice::WriteOnly); 0066 0067 stream1 << sourceMimeType << sourceName; 0068 mimedata->setData("kexi/dataprovider", data); 0069 setMimeData(mimedata); 0070 } 0071 0072 KexiDataProviderDrag::~KexiDataProviderDrag() 0073 { 0074 } 0075 0076 bool KexiDataProviderDrag::canDecode(QDragMoveEvent *e) 0077 { 0078 return e->mimeData()->hasFormat("kexi/dataprovider"); 0079 } 0080 0081 bool KexiDataProviderDrag::decode(QDropEvent* e, QString* sourceMimeType, QString *sourceName) 0082 { 0083 QByteArray payload = e->mimeData()->data("kexidataprovider"); 0084 if (payload.isEmpty()) { 0085 return false; 0086 } 0087 e->accept(); 0088 QDataStream stream1(&payload, QIODevice::ReadOnly); 0089 stream1 >> *sourceMimeType; 0090 stream1 >> *sourceName; 0091 // qDebug() << "decoded:" << sourceMimeType <<"/"<<sourceName; 0092 return true; 0093 }