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
This commit is contained in:
		
							parent
							
								
									3c4ac74af1
								
							
						
					
					
						commit
						265104133b
					
				| 
						 | 
					@ -825,6 +825,8 @@ if(!Groups.size() || !parent){
 | 
				
			||||||
	return &Groups.back();
 | 
						return &Groups.back();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
else {  int i=Groups.indexOf(*parent)+1;
 | 
					else {  int i=Groups.indexOf(*parent)+1;
 | 
				
			||||||
 | 
						for(i;i<Groups.size();i++)
 | 
				
			||||||
 | 
							if(Groups[i].Level<=parent->Level)break;
 | 
				
			||||||
	Groups.insert(i,group);
 | 
						Groups.insert(i,group);
 | 
				
			||||||
	return &Groups[i];}
 | 
						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 NumSubGroups=0;
 | 
				
			||||||
int GroupIndex=getGroupIndex(group);
 | 
					int GroupIndex=Groups.indexOf(*group);
 | 
				
			||||||
 | 
					int DstIndex;
 | 
				
			||||||
int i;
 | 
					int i;
 | 
				
			||||||
for(i=GroupIndex+1; i<groups.size(); i++){
 | 
					for(i=GroupIndex+1; i<Groups.size(); i++){
 | 
				
			||||||
 if(groups[i].Level <= group->Level) break;
 | 
					 if(Groups[i].Level <= group->Level) break;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
NumSubGroups=i-GroupIndex-1;
 | 
					NumSubGroups=i-GroupIndex-1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int LevelDiff;
 | 
					int LevelDiff;
 | 
				
			||||||
 | 
					QList<CGroup> tmp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(DstGroup)
 | 
					if(DstGroup)
 | 
				
			||||||
 LevelDiff=DstGroup->Level - group->Level;
 | 
					 LevelDiff=DstGroup->Level - group->Level +1;
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
 LevelDiff=-group->Level;
 | 
					 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){
 | 
					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);
 | 
					 CGroup*   addGroup(CGroup* parent);
 | 
				
			||||||
 void      deleteGroup(CGroup* pGroup);
 | 
					 void      deleteGroup(CGroup* pGroup);
 | 
				
			||||||
 void      deleteGroup(unsigned long ID);
 | 
					 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(CGroup* group);
 | 
				
			||||||
 int       getGroupIndex(unsigned long ID);
 | 
					 int       getGroupIndex(unsigned long ID);
 | 
				
			||||||
 | 
					 int	   getNumberOfChilds(CGroup* pGroup);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 void      deleteEntry(CEntry* pEntry);
 | 
					 void      deleteEntry(CEntry* pEntry);
 | 
				
			||||||
 void      moveEntry(CEntry* pEntry,CGroup* pDstGroup);
 | 
					 void      moveEntry(CEntry* pEntry,CGroup* pDstGroup);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,6 +35,7 @@
 | 
				
			||||||
#include "GroupView.h"
 | 
					#include "GroupView.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
KeepassGroupView::KeepassGroupView(QWidget* parent):QTreeWidget(parent){
 | 
					KeepassGroupView::KeepassGroupView(QWidget* parent):QTreeWidget(parent){
 | 
				
			||||||
 | 
					db=0;
 | 
				
			||||||
LastHoverItem=NULL;
 | 
					LastHoverItem=NULL;
 | 
				
			||||||
setHeaderLabels(QStringList()<<tr("Gruppen"));
 | 
					setHeaderLabels(QStringList()<<tr("Gruppen"));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -84,8 +85,14 @@ if(LastHoverItem){
 | 
				
			||||||
  QFont f=LastHoverItem->font(0);
 | 
					  QFont f=LastHoverItem->font(0);
 | 
				
			||||||
  f.setBold(false);
 | 
					  f.setBold(false);
 | 
				
			||||||
  LastHoverItem->setFont(0,f);
 | 
					  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();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue