-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadragdroplineedit.cpp
44 lines (36 loc) · 1.28 KB
/
adragdroplineedit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "adragdroplineedit.h"
#include "QListView"
#include <QKeyEvent>
#include <QMimeData>
#include <QDebug>
ADragDropLineEdit::ADragDropLineEdit(QWidget *parent)
: QLineEdit(parent)
{
}
void ADragDropLineEdit::dragEnterEvent(QDragEnterEvent *e)
{
// qDebug()<<"FDragDropLineEdit::dragEnterEvent"<<e->pos();
if(e->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")){
e->acceptProposedAction();
}
}
void ADragDropLineEdit::dropEvent(QDropEvent *e)
{
QByteArray encoded = e->mimeData()->data("application/x-qabstractitemmodeldatalist");
QDataStream strm(&encoded, QIODevice::ReadOnly);
while(!strm.atEnd()){
int row, col;
QMap<int, QVariant> data;
strm >> row >> col >> data;
this->setText(data[0].toString());
//implement move
QListView *qlv = qobject_cast<QListView *>(e->source());
// qDebug()<<"FDragDropLineEdit::dropEvent"<<e->pos()<<e->source()<<data[0].toString()<<qlv;
if (qlv != nullptr)
{
for (int row = qlv->model()->rowCount() - 1; row >=0 ;row--)
if (qlv->model()->index(row, 0).data().toString() == data[0].toString() )
qlv->model()->removeRow(row);
}
}
}