drag and drop implementation for group tree hierarchy finished

(TODO: sorting via d'n'd)

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@20 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 18 years ago
parent 3c4ac74af1
commit 265104133b
  1. 53
      src/PwManager.cpp
  2. 3
      src/PwManager.h
  3. 9
      src/lib/GroupView.cpp

@ -825,6 +825,8 @@ if(!Groups.size() || !parent){
return &Groups.back();
}
else { int i=Groups.indexOf(*parent)+1;
for(i;i<Groups.size();i++)
if(Groups[i].Level<=parent->Level)break;
Groups.insert(i,group);
return &Groups[i];}
}
@ -957,28 +959,63 @@ for(int i=0; i<64; i+=2){
}
}
void PwDatabase::moveGroup(CGroup* group, CGroup* DstGroup){
/*
void PwDatabase::moveGroup(CGroup* group, CGroup* DstGroup, int pos){
int NumSubGroups=0;
int GroupIndex=getGroupIndex(group);
int GroupIndex=Groups.indexOf(*group);
int DstIndex;
int i;
for(i=GroupIndex+1; i<groups.size(); i++){
if(groups[i].Level <= group->Level) break;
for(i=GroupIndex+1; i<Groups.size(); i++){
if(Groups[i].Level <= group->Level) break;
}
NumSubGroups=i-GroupIndex-1;
int LevelDiff;
QList<CGroup> tmp;
if(DstGroup)
LevelDiff=DstGroup->Level - group->Level;
LevelDiff=DstGroup->Level - group->Level +1;
else
LevelDiff=-group->Level;
for(i=GroupIndex; i<=GroupIndex+NumSubGroups; i++){
tmp << Groups[i];
tmp.back().Level+=LevelDiff;
}
for(i=0; i<=NumSubGroups; i++)
Groups.removeAt(GroupIndex);
int NumParentSubGroups;
if(DstGroup){
groups.insert(pos, groups[
DstIndex=Groups.indexOf(*DstGroup);
NumParentSubGroups=getNumberOfChilds(DstGroup);}
else{
DstIndex=0;
NumParentSubGroups=Groups.size();}
if(pos==-1)DstIndex+=(NumParentSubGroups+1);
else{ int n=0; //Counter for direct (first-level) childs
for(i=0; i<NumParentSubGroups;i++){
if(n==pos)break;
if(Groups[DstIndex+1+i].Level==DstGroup->Level+1)n++;
}
DstIndex+=n;
}
for(i=NumSubGroups; i>=0; i--)
Groups.insert(DstIndex,tmp[i]);
}
*/
int PwDatabase::getNumberOfChilds(CGroup* group){
if(!group)return Groups.size();
int GroupIndex=Groups.indexOf(*group);
int i;
for(i=GroupIndex+1; i<Groups.size(); i++){
if(Groups[i].Level <= group->Level) break;
}
return (i-GroupIndex-1);
}

@ -57,9 +57,10 @@ public:
CGroup* addGroup(CGroup* parent);
void deleteGroup(CGroup* pGroup);
void deleteGroup(unsigned long ID);
void moveGroup(CGroup* group, CGroup* DstGroup);
void moveGroup(CGroup* group, CGroup* DstGroup, int pos=-1);
int getGroupIndex(CGroup* group);
int getGroupIndex(unsigned long ID);
int getNumberOfChilds(CGroup* pGroup);
void deleteEntry(CEntry* pEntry);
void moveEntry(CEntry* pEntry,CGroup* pDstGroup);

@ -35,6 +35,7 @@
#include "GroupView.h"
KeepassGroupView::KeepassGroupView(QWidget* parent):QTreeWidget(parent){
db=0;
LastHoverItem=NULL;
setHeaderLabels(QStringList()<<tr("Gruppen"));
}
@ -84,8 +85,14 @@ if(LastHoverItem){
QFont f=LastHoverItem->font(0);
f.setBold(false);
LastHoverItem->setFont(0,f);
LastHoverItem=NULL;
}
GroupViewItem* item=(GroupViewItem*)itemAt(event->pos());
if(item)
db->moveGroup(DragItem->pGroup,item->pGroup);
else
db->moveGroup(DragItem->pGroup,NULL);
updateItems();
}