mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-01-19 11:59:45 +01:00
Issue #76: Drag and drop
This commit is contained in:
parent
be0d02bb5c
commit
bf53e7419b
@ -574,8 +574,11 @@ QMimeData* PDFOutlineTreeItemModel::mimeData(const QModelIndexList& indexes) con
|
|||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
QModelIndex index = indexes.front();
|
||||||
|
const PDFOutlineTreeItem* item = static_cast<const PDFOutlineTreeItem*>(index.internalPointer());
|
||||||
|
m_dragDropItem = item->getOutlineItem()->clone();
|
||||||
QDataStream stream(&ba, QDataStream::WriteOnly);
|
QDataStream stream(&ba, QDataStream::WriteOnly);
|
||||||
stream << indexes.front().internalId();
|
stream << reinterpret_cast<quintptr>(m_dragDropItem.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
mimeData->setData(mimeTypes().front(), ba);
|
mimeData->setData(mimeTypes().front(), ba);
|
||||||
@ -605,9 +608,29 @@ bool PDFOutlineTreeItemModel::dropMimeData(const QMimeData* data, Qt::DropAction
|
|||||||
quintptr pointer = 0;
|
quintptr pointer = 0;
|
||||||
stream >> pointer;
|
stream >> pointer;
|
||||||
|
|
||||||
PDFOutlineTreeItem* item = reinterpret_cast<PDFOutlineTreeItem*>(pointer);
|
PDFOutlineItem* item = reinterpret_cast<PDFOutlineItem*>(pointer);
|
||||||
QModelIndex sourceIndex = createIndex(item->getRow(), column, item);
|
if (item == m_dragDropItem.data())
|
||||||
return moveRow(sourceIndex.parent(), sourceIndex.row(), parent, row);
|
{
|
||||||
|
if (row == -1)
|
||||||
|
{
|
||||||
|
row = rowCount(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column == -1)
|
||||||
|
{
|
||||||
|
column = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (insertRow(row, parent))
|
||||||
|
{
|
||||||
|
QModelIndex targetIndex = this->index(row, column, parent);
|
||||||
|
PDFOutlineTreeItem* targetTreeItem = static_cast<PDFOutlineTreeItem*>(targetIndex.internalPointer());
|
||||||
|
*targetTreeItem->getOutlineItem() = *item;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PDFOutlineTreeItemModel::insertRows(int row, int count, const QModelIndex& parent)
|
bool PDFOutlineTreeItemModel::insertRows(int row, int count, const QModelIndex& parent)
|
||||||
@ -695,25 +718,20 @@ bool PDFOutlineTreeItemModel::moveRows(const QModelIndex& sourceParent, int sour
|
|||||||
destinationChild = 0;
|
destinationChild = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signalizace začátku přesunu řádků
|
beginRemoveRows(sourceParent, sourceRow, sourceRow + count - 1);
|
||||||
if (!beginMoveRows(sourceParent, sourceRow, sourceRow + count - 1, destinationParent, destinationChild))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<PDFOutlineTreeItem*> nodesToMove;
|
QList<PDFOutlineTreeItem*> nodesToMove;
|
||||||
for (int i = 0; i < count; ++i)
|
for (int i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
nodesToMove.append(static_cast<PDFOutlineTreeItem*>(sourceNode->takeChild(sourceRow)));
|
nodesToMove.append(static_cast<PDFOutlineTreeItem*>(sourceNode->takeChild(sourceRow)));
|
||||||
}
|
}
|
||||||
|
endRemoveRows();
|
||||||
|
|
||||||
|
beginInsertRows(destinationParent, destinationChild, destinationChild + count - 1);
|
||||||
for (PDFOutlineTreeItem* node : nodesToMove)
|
for (PDFOutlineTreeItem* node : nodesToMove)
|
||||||
{
|
{
|
||||||
destNode->insertCreatedChild(destinationChild++, node);
|
destNode->insertCreatedChild(destinationChild++, node);
|
||||||
}
|
}
|
||||||
|
endInsertRows();
|
||||||
// Signalizace konce přesunu řádků
|
|
||||||
endMoveRows();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -214,6 +214,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
bool m_editable;
|
bool m_editable;
|
||||||
|
mutable QSharedPointer<PDFOutlineItem> m_dragDropItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PDF4QTLIBSHARED_EXPORT PDFSelectableOutlineTreeItemModel : public PDFOutlineTreeItemModel
|
class PDF4QTLIBSHARED_EXPORT PDFSelectableOutlineTreeItemModel : public PDFOutlineTreeItemModel
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2019-2022 Jakub Melka
|
// Copyright (C) 2019-2023 Jakub Melka
|
||||||
//
|
//
|
||||||
// This file is part of PDF4QT.
|
// This file is part of PDF4QT.
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user