mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-11-30 13:53:01 -08:00
Support moving entries with drag and drop.
This commit is contained in:
1 parent
79b6ff99e4
commit
74ac6c27d7
6 files changed
+98
-18
No files matched your search
@@ -17,6 +17,8 @@
|
||||
|
||||
#include "EntryModel.h"
|
||||
|
||||
#include <QtCore/QMimeData>
|
||||
|
||||
#include "core/Entry.h"
|
||||
#include "core/Group.h"
|
||||
|
||||
@@ -24,6 +26,7 @@ EntryModel::EntryModel(QObject* parent)
|
||||
: QAbstractTableModel(parent)
|
||||
, m_group(0)
|
||||
{
|
||||
setSupportedDragActions(Qt::MoveAction);
|
||||
}
|
||||
|
||||
Entry* EntryModel::entryFromIndex(const QModelIndex& index) const
|
||||
@@ -106,6 +109,49 @@ QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int ro
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::DropActions EntryModel::supportedDropActions() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Qt::ItemFlags EntryModel::flags(const QModelIndex& modelIndex) const
|
||||
{
|
||||
if (!modelIndex.isValid()) {
|
||||
return Qt::NoItemFlags;
|
||||
}
|
||||
else {
|
||||
return QAbstractItemModel::flags(modelIndex) | Qt::ItemIsDragEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
QStringList EntryModel::mimeTypes() const
|
||||
{
|
||||
QStringList types;
|
||||
types << QLatin1String("application/x-keepassx-entry");
|
||||
return types;
|
||||
}
|
||||
|
||||
QMimeData* EntryModel::mimeData(const QModelIndexList& indexes) const
|
||||
{
|
||||
if (indexes.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QMimeData* data = new QMimeData();
|
||||
QByteArray encoded;
|
||||
QDataStream stream(&encoded, QIODevice::WriteOnly);
|
||||
|
||||
for (int i = 0; i < indexes.size(); i++) {
|
||||
if (!indexes[i].isValid()) {
|
||||
continue;
|
||||
}
|
||||
stream << m_group->database()->uuid() << entryFromIndex(indexes[i])->uuid();
|
||||
}
|
||||
|
||||
data->setData(mimeTypes().first(), encoded);
|
||||
return data;
|
||||
}
|
||||
|
||||
void EntryModel::entryAboutToAdd(Entry* entry)
|
||||
{
|
||||
Q_UNUSED(entry);
|
||||
|
||||
Reference in new issue
Block a user