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

« back to all changes in this revision

Viewing changes to src/core/kexidragobjects.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) 2002, 2003 Joseph Wenninger <jowenn@kde.org>
 
3
   Copyright (C) 2005 Jarosław Staniek <staniek@kde.org>
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library General Public
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2 of the License, or (at your option) any later version.
 
9
 
 
10
   This library is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public License
 
16
   along with this library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#include "kexidragobjects.h"
 
22
 
 
23
#include <QDataStream>
 
24
#include <QStringList>
 
25
#include <QDragMoveEvent>
 
26
#include <QDomDocument>
 
27
#include <QMimeData>
 
28
#include <QDebug>
 
29
#include <QWidget>
 
30
 
 
31
bool KexiFieldDrag::canDecode(QDropEvent *e)
 
32
{
 
33
    return e->mimeData()->hasFormat("kexi/fields");
 
34
}
 
35
 
 
36
bool KexiFieldDrag::decode(QDropEvent* e, QString *sourceMimeType,
 
37
                           QString *sourceName, QStringList *fields)
 
38
{
 
39
    Q_ASSERT(sourceMimeType);
 
40
    Q_ASSERT(sourceName);
 
41
    Q_ASSERT(fields);
 
42
 
 
43
    QByteArray payload(e->mimeData()->data("kexi/fields"));
 
44
    if (payload.isEmpty()) {//try single
 
45
        return false;
 
46
    }
 
47
    e->accept();
 
48
    QDataStream stream1(&payload, QIODevice::ReadOnly);
 
49
 
 
50
    stream1 >> *sourceMimeType;
 
51
    stream1 >> *sourceName;
 
52
    stream1 >> *fields;
 
53
// qDebug() << "decoded:" << sourceMimeType<<"/"<<sourceName<<"/"<<fields;
 
54
    return true;
 
55
}
 
56
 
 
57
// ----------
 
58
 
 
59
KexiDataProviderDrag::KexiDataProviderDrag(const QString& sourceMimeType, const QString& sourceName,
 
60
        QWidget *parent)
 
61
        : QDrag(parent)
 
62
{
 
63
    QMimeData *mimedata = new QMimeData();
 
64
    QByteArray data;
 
65
    QDataStream stream1(&data, QIODevice::WriteOnly);
 
66
 
 
67
    stream1 << sourceMimeType << sourceName;
 
68
    mimedata->setData("kexi/dataprovider", data);
 
69
    setMimeData(mimedata);
 
70
}
 
71
 
 
72
KexiDataProviderDrag::~KexiDataProviderDrag()
 
73
{
 
74
}
 
75
 
 
76
bool KexiDataProviderDrag::canDecode(QDragMoveEvent *e)
 
77
{
 
78
    return e->mimeData()->hasFormat("kexi/dataprovider");
 
79
}
 
80
 
 
81
bool KexiDataProviderDrag::decode(QDropEvent* e, QString* sourceMimeType, QString *sourceName)
 
82
{
 
83
    QByteArray payload = e->mimeData()->data("kexidataprovider");
 
84
    if (payload.isEmpty()) {
 
85
        return false;
 
86
    }
 
87
    e->accept();
 
88
    QDataStream stream1(&payload, QIODevice::ReadOnly);
 
89
    stream1 >> *sourceMimeType;
 
90
    stream1 >> *sourceName;
 
91
//  qDebug() << "decoded:" << sourceMimeType <<"/"<<sourceName;
 
92
    return true;
 
93
}