|
|
|
@ -23,6 +23,7 @@ |
|
|
|
|
#include "dialogs/EditGroupDlg.h" |
|
|
|
|
|
|
|
|
|
#include <QBrush> |
|
|
|
|
#include <QHeaderView> |
|
|
|
|
|
|
|
|
|
#define INSERT_AREA_WIDTH 4 |
|
|
|
|
|
|
|
|
@ -343,7 +344,7 @@ void KeepassGroupView::dropEvent( QDropEvent * event ){ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void KeepassGroupView::entryDragMoveEvent( QDragMoveEvent * event ){ |
|
|
|
|
void KeepassGroupView::entryDragMoveEvent(QDragMoveEvent* event){ |
|
|
|
|
|
|
|
|
|
GroupViewItem* Item=(GroupViewItem*)itemAt(event->pos()); |
|
|
|
|
if(!Item){ |
|
|
|
@ -378,7 +379,7 @@ void KeepassGroupView::entryDragMoveEvent( QDragMoveEvent * event ){ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void KeepassGroupView::dragMoveEvent( QDragMoveEvent * event ){ |
|
|
|
|
void KeepassGroupView::dragMoveEvent(QDragMoveEvent* event){ |
|
|
|
|
if(DragType==EntryDrag){ |
|
|
|
|
entryDragMoveEvent(event); |
|
|
|
|
return; |
|
|
|
@ -494,11 +495,47 @@ void KeepassGroupView::mouseMoveEvent(QMouseEvent *event){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void KeepassGroupView::OnItemExpanded(QTreeWidgetItem* item){ |
|
|
|
|
dynamic_cast<GroupViewItem*>(item)->GroupHandle->setExpanded(true); |
|
|
|
|
static_cast<GroupViewItem*>(item)->GroupHandle->setExpanded(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void KeepassGroupView::OnItemCollapsed(QTreeWidgetItem* item){ |
|
|
|
|
dynamic_cast<GroupViewItem*>(item)->GroupHandle->setExpanded(false); |
|
|
|
|
static_cast<GroupViewItem*>(item)->GroupHandle->setExpanded(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void KeepassGroupView::OnSort() { |
|
|
|
|
QHash<QTreeWidgetItem*,int> oldIndex; |
|
|
|
|
for (int i=0; i<Items.size(); i++) { |
|
|
|
|
if (Items[i]->parent()) |
|
|
|
|
oldIndex.insert(Items[i], Items[i]->parent()->indexOfChild(Items[i])); |
|
|
|
|
else |
|
|
|
|
oldIndex.insert(Items[i], invisibleRootItem()->indexOfChild(Items[i])); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sortItems(0, Qt::AscendingOrder); |
|
|
|
|
|
|
|
|
|
bool modified = false; |
|
|
|
|
QMutableHashIterator<QTreeWidgetItem*, int> i(oldIndex); |
|
|
|
|
while (i.hasNext()) { |
|
|
|
|
i.next(); |
|
|
|
|
int newIndex; |
|
|
|
|
IGroupHandle* parent; |
|
|
|
|
if (i.key()->parent()) { |
|
|
|
|
newIndex = i.key()->parent()->indexOfChild(i.key()); |
|
|
|
|
parent = static_cast<GroupViewItem*>(i.key()->parent())->GroupHandle; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
newIndex = invisibleRootItem()->indexOfChild(i.key()); |
|
|
|
|
parent = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (newIndex != i.value()) { |
|
|
|
|
db->moveGroup(static_cast<GroupViewItem*>(i.key())->GroupHandle, parent, newIndex); |
|
|
|
|
modified = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (modified) |
|
|
|
|
emit fileModified(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -518,3 +555,21 @@ GroupViewItem::GroupViewItem(QTreeWidgetItem *parent):QTreeWidgetItem(parent){ |
|
|
|
|
GroupViewItem::GroupViewItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding):QTreeWidgetItem(parent,preceding){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool GroupViewItem::operator<(const QTreeWidgetItem& other) const { |
|
|
|
|
const GroupViewItem* otherItem = static_cast<const GroupViewItem*>(&other); |
|
|
|
|
KeepassGroupView* groupView = static_cast<KeepassGroupView*>(treeWidget()); |
|
|
|
|
|
|
|
|
|
// Search result is always at the bottom
|
|
|
|
|
if (this == groupView->SearchResultItem) |
|
|
|
|
return false; |
|
|
|
|
if (otherItem == groupView->SearchResultItem) |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
// Backup group is always at the bottom but above search results
|
|
|
|
|
if (!parent() && text(0).compare("Backup", Qt::CaseInsensitive) == 0) |
|
|
|
|
return false; |
|
|
|
|
if (!otherItem->parent() && otherItem->text(0).compare("Backup", Qt::CaseInsensitive) == 0) |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
return QTreeWidgetItem::operator<(other); |
|
|
|
|
} |
|
|
|
|